ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/name_registry.cpp
Revision: 1.3
Committed: 2003-11-20T15:54:10Z (20 years, 5 months ago) by gbeauche
Branch: MAIN
Changes since 1.2: +59 -54 lines
Log Message:
little endian fixes to name registry

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * name_registry.cpp - Name Registry handling
3     *
4     * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
5     *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include <string.h>
22    
23     #include "sysdeps.h"
24     #include "name_registry.h"
25     #include "main.h"
26     #include "macos_util.h"
27     #include "user_strings.h"
28 gbeauche 1.2 #include "emul_op.h"
29 cebix 1.1
30     #define DEBUG 0
31     #include "debug.h"
32    
33    
34     // Function pointers
35     typedef int16 (*rcec_ptr)(const RegEntryID *, const char *, RegEntryID *);
36     static uint32 rcec_tvect = 0;
37     static inline int16 RegistryCStrEntryCreate(const RegEntryID *arg1, const char *arg2, RegEntryID *arg3)
38     {
39     return (int16)CallMacOS3(rcec_ptr, rcec_tvect, arg1, arg2, arg3);
40     }
41     typedef int16 (*rpc_ptr)(const RegEntryID *, const char *, const void *, uint32);
42     static uint32 rpc_tvect = 0;
43     static inline int16 RegistryPropertyCreate(const RegEntryID *arg1, const char *arg2, const void *arg3, uint32 arg4)
44     {
45     return (int16)CallMacOS4(rpc_ptr, rpc_tvect, arg1, arg2, arg3, arg4);
46     }
47     #define RegistryPropertyCreateStr(e,n,s) RegistryPropertyCreate(e,n,s,strlen(s)+1)
48    
49     // Video driver stub
50     static const uint8 video_driver[] = {
51     #include "VideoDriverStub.i"
52     };
53    
54     // Ethernet driver stub
55     static const uint8 ethernet_driver[] = {
56     #include "EthernetDriverStub.i"
57     };
58    
59    
60     /*
61     * Patch Name Registry during startup
62     */
63    
64 gbeauche 1.2 void DoPatchNameRegistry(void)
65 cebix 1.1 {
66     uint32 u32;
67     D(bug("Patching Name Registry..."));
68    
69     // Create "device-tree"
70     RegEntryID device_tree;
71     if (!RegistryCStrEntryCreate(NULL, "Devices:device-tree", &device_tree)) {
72 gbeauche 1.3 u32 = htonl(BusClockSpeed);
73 cebix 1.1 RegistryPropertyCreate(&device_tree, "clock-frequency", &u32, 4);
74     RegistryPropertyCreateStr(&device_tree, "model", "Power Macintosh");
75    
76     // Create "AAPL,ROM"
77     RegEntryID aapl_rom;
78     if (!RegistryCStrEntryCreate(&device_tree, "AAPL,ROM", &aapl_rom)) {
79     RegistryPropertyCreateStr(&aapl_rom, "device_type", "rom");
80 gbeauche 1.3 uint32 reg[2];
81     reg[0] = htonl(ROM_BASE);
82     reg[1] = htonl(ROM_SIZE);
83 cebix 1.1 RegistryPropertyCreate(&aapl_rom, "reg", &reg, 8);
84     }
85    
86     // Create "PowerPC,60x"
87     RegEntryID power_pc;
88     char *str;
89     switch (PVR >> 16) {
90     case 1: // 601
91     str = "PowerPC,601";
92     break;
93     case 3: // 603
94     str = "PowerPC,603";
95     break;
96     case 4: // 604
97     str = "PowerPC,604";
98     break;
99     case 6: // 603e
100     str = "PowerPC,603e";
101     break;
102     case 7: // 603ev
103     str = "PowerPC,603ev";
104     break;
105     case 8: // 750
106     str = "PowerPC,750";
107     break;
108     case 9: // 604e
109     str = "PowerPC,604e";
110     break;
111     case 10: // 604ev5
112     str = "PowerPC,604ev";
113     break;
114     case 50: // 821
115     str = "PowerPC,821";
116     break;
117     case 80: // 860
118     str = "PowerPC,860";
119     break;
120     default:
121     str = "PowerPC,???";
122     break;
123     }
124     if (!RegistryCStrEntryCreate(&device_tree, str, &power_pc)) {
125 gbeauche 1.3 u32 = htonl(CPUClockSpeed);
126 cebix 1.1 RegistryPropertyCreate(&power_pc, "clock-frequency", &u32, 4);
127 gbeauche 1.3 u32 = htonl(PVR);
128     RegistryPropertyCreate(&power_pc, "cpu-version", &u32, 4);
129 cebix 1.1 RegistryPropertyCreateStr(&power_pc, "device_type", "cpu");
130     switch (PVR >> 16) {
131     case 1: // 601
132 gbeauche 1.3 u32 = htonl(64);
133 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
134 gbeauche 1.3 u32 = htonl(128);
135 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
136 gbeauche 1.3 u32 = htonl(0x8000);
137 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
138 gbeauche 1.3 u32 = htonl(64);
139 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
140 gbeauche 1.3 u32 = htonl(128);
141 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
142 gbeauche 1.3 u32 = htonl(0x8000);
143 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
144 gbeauche 1.3 u32 = htonl(128);
145 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
146 gbeauche 1.3 u32 = htonl(256);
147 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
148     break;
149     case 3: // 603
150 gbeauche 1.3 u32 = htonl(32);
151 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
152 gbeauche 1.3 u32 = htonl(64);
153 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
154 gbeauche 1.3 u32 = htonl(0x2000);
155 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
156 gbeauche 1.3 u32 = htonl(32);
157 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
158 gbeauche 1.3 u32 = htonl(64);
159 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
160 gbeauche 1.3 u32 = htonl(0x2000);
161 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
162 gbeauche 1.3 u32 = htonl(32);
163 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
164 gbeauche 1.3 u32 = htonl(64);
165 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
166     break;
167     case 4: // 604
168 gbeauche 1.3 u32 = htonl(32);
169 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
170 gbeauche 1.3 u32 = htonl(128);
171 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
172 gbeauche 1.3 u32 = htonl(0x4000);
173 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
174 gbeauche 1.3 u32 = htonl(32);
175 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
176 gbeauche 1.3 u32 = htonl(128);
177 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
178 gbeauche 1.3 u32 = htonl(0x4000);
179 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
180 gbeauche 1.3 u32 = htonl(64);
181 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
182 gbeauche 1.3 u32 = htonl(128);
183 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
184     break;
185     case 6: // 603e
186     case 7: // 603ev
187 gbeauche 1.3 u32 = htonl(32);
188 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
189 gbeauche 1.3 u32 = htonl(128);
190 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
191 gbeauche 1.3 u32 = htonl(0x4000);
192 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
193 gbeauche 1.3 u32 = htonl(32);
194 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
195 gbeauche 1.3 u32 = htonl(128);
196 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
197 gbeauche 1.3 u32 = htonl(0x4000);
198 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
199 gbeauche 1.3 u32 = htonl(32);
200 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
201 gbeauche 1.3 u32 = htonl(64);
202 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
203     break;
204     case 8: // 750
205 gbeauche 1.3 u32 = htonl(32);
206 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
207 gbeauche 1.3 u32 = htonl(256);
208 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
209 gbeauche 1.3 u32 = htonl(0x8000);
210 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
211 gbeauche 1.3 u32 = htonl(32);
212 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
213 gbeauche 1.3 u32 = htonl(256);
214 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
215 gbeauche 1.3 u32 = htonl(0x8000);
216 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
217 gbeauche 1.3 u32 = htonl(64);
218 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
219 gbeauche 1.3 u32 = htonl(128);
220 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
221     break;
222     case 9: // 604e
223     case 10: // 604ev5
224 gbeauche 1.3 u32 = htonl(32);
225 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4);
226 gbeauche 1.3 u32 = htonl(256);
227 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4);
228 gbeauche 1.3 u32 = htonl(0x8000);
229 cebix 1.1 RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4);
230 gbeauche 1.3 u32 = htonl(32);
231 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4);
232 gbeauche 1.3 u32 = htonl(256);
233 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4);
234 gbeauche 1.3 u32 = htonl(0x8000);
235 cebix 1.1 RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4);
236 gbeauche 1.3 u32 = htonl(64);
237 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4);
238 gbeauche 1.3 u32 = htonl(128);
239 cebix 1.1 RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4);
240     break;
241     default:
242     break;
243     }
244 gbeauche 1.3 u32 = htonl(32);
245 cebix 1.1 RegistryPropertyCreate(&power_pc, "reservation-granularity", &u32, 4);
246     uint32 reg[2] = {0, 0};
247     RegistryPropertyCreate(&power_pc, "reg", &reg, 8);
248     }
249    
250     // Create "memory"
251     RegEntryID memory;
252     if (!RegistryCStrEntryCreate(&device_tree, "memory", &memory)) {
253 gbeauche 1.3 uint32 reg[2];
254     reg[0] = htonl(RAMBase);
255     reg[1] = htonl(RAMSize);
256 cebix 1.1 RegistryPropertyCreateStr(&memory, "device_type", "memory");
257     RegistryPropertyCreate(&memory, "reg", &reg, 8);
258     }
259    
260     // Create "video"
261     RegEntryID video;
262     if (!RegistryCStrEntryCreate(&device_tree, "video", &video)) {
263     RegistryPropertyCreateStr(&video, "AAPL,connector", "monitor");
264     RegistryPropertyCreateStr(&video, "device_type", "display");
265     RegistryPropertyCreate(&video, "driver,AAPL,MacOS,PowerPC", &video_driver, sizeof(video_driver));
266     RegistryPropertyCreateStr(&video, "model", "SheepShaver Video");
267     }
268    
269     // Create "ethernet"
270     RegEntryID ethernet;
271     if (!RegistryCStrEntryCreate(&device_tree, "ethernet", &ethernet)) {
272     RegistryPropertyCreateStr(&ethernet, "AAPL,connector", "ethernet");
273     RegistryPropertyCreateStr(&ethernet, "device_type", "network");
274     RegistryPropertyCreate(&ethernet, "driver,AAPL,MacOS,PowerPC", &ethernet_driver, sizeof(ethernet_driver));
275     // local-mac-address
276     // max-frame-size 2048
277     }
278     }
279     D(bug("done.\n"));
280     }
281    
282     void PatchNameRegistry(void)
283     {
284     // Find RegistryCStrEntryCreate() and RegistryPropertyCreate() TVECTs
285     rcec_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\027RegistryCStrEntryCreate");
286     D(bug("RegistryCStrEntryCreate TVECT at %08x\n", rcec_tvect));
287     rpc_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\026RegistryPropertyCreate");
288     D(bug("RegistryPropertyCreate TVECT at %08x\n", rpc_tvect));
289     if (rcec_tvect == 0 || rpc_tvect == 0) {
290     ErrorAlert(GetString(STR_NO_NAME_REGISTRY_ERR));
291     QuitEmulator();
292     }
293    
294     // Main routine must be executed in PPC mode
295 gbeauche 1.2 #if EMULATED_PPC
296     ExecuteNative(NATIVE_PATCH_NAME_REGISTRY);
297     #else
298     ExecutePPC(DoPatchNameRegistry);
299     #endif
300 cebix 1.1 }