ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/name_registry.cpp
Revision: 1.15
Committed: 2004-12-19T09:01:04Z (19 years, 11 months ago) by gbeauche
Branch: MAIN
Changes since 1.14: +2 -2 lines
Log Message:
FindLibSymbol() returns an address in MacOS address space. Likewise for
Mac_sysalloc(). i.e. make it return an uint32.

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * name_registry.cpp - Name Registry handling
3     *
4 cebix 1.6 * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
5 cebix 1.1 *
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 gbeauche 1.4 #include "thunks.h"
30 cebix 1.1
31     #define DEBUG 0
32     #include "debug.h"
33    
34    
35     // Function pointers
36     typedef int16 (*rcec_ptr)(const RegEntryID *, const char *, RegEntryID *);
37     static uint32 rcec_tvect = 0;
38 gbeauche 1.13 static inline int16 RegistryCStrEntryCreate(uintptr arg1, const char *arg2, uint32 arg3)
39 cebix 1.1 {
40 gbeauche 1.14 SheepString arg2str(arg2);
41     return (int16)CallMacOS3(rcec_ptr, rcec_tvect, (const RegEntryID *)arg1, arg2str.addr(), arg3);
42 cebix 1.1 }
43     typedef int16 (*rpc_ptr)(const RegEntryID *, const char *, const void *, uint32);
44     static uint32 rpc_tvect = 0;
45 gbeauche 1.13 static inline int16 RegistryPropertyCreate(uintptr arg1, const char *arg2, uintptr arg3, uint32 arg4)
46 cebix 1.1 {
47 gbeauche 1.14 SheepString arg2str(arg2);
48     return (int16)CallMacOS4(rpc_ptr, rpc_tvect, (const RegEntryID *)arg1, arg2str.addr(), (const void *)arg3, arg4);
49     }
50     static inline int16 RegistryPropertyCreateStr(uintptr arg1, const char *arg2, const char *arg3)
51     {
52     SheepString arg3str(arg3);
53     return RegistryPropertyCreate(arg1, arg2, arg3str.addr(), strlen(arg3) + 1);
54 cebix 1.1 }
55    
56     // Video driver stub
57     static const uint8 video_driver[] = {
58     #include "VideoDriverStub.i"
59     };
60    
61     // Ethernet driver stub
62     static const uint8 ethernet_driver[] = {
63     #include "EthernetDriverStub.i"
64     };
65    
66 gbeauche 1.4 // Helper for RegEntryID
67 gbeauche 1.13 typedef SheepArray<sizeof(RegEntryID)> SheepRegEntryID;
68 gbeauche 1.4
69     // Helper for a <uint32, uint32> pair
70     struct SheepPair : public SheepArray<8> {
71     SheepPair(uint32 base, uint32 size) : SheepArray<8>()
72     { WriteMacInt32(addr(), base); WriteMacInt32(addr() + 4, size); }
73     };
74    
75 cebix 1.1
76     /*
77     * Patch Name Registry during startup
78     */
79    
80 gbeauche 1.2 void DoPatchNameRegistry(void)
81 cebix 1.1 {
82 gbeauche 1.4 SheepVar32 u32;
83 cebix 1.1 D(bug("Patching Name Registry..."));
84    
85     // Create "device-tree"
86 gbeauche 1.4 SheepRegEntryID device_tree;
87 gbeauche 1.13 if (!RegistryCStrEntryCreate(0, "Devices:device-tree", device_tree.addr())) {
88 gbeauche 1.4 u32.set_value(BusClockSpeed);
89 gbeauche 1.13 RegistryPropertyCreate(device_tree.addr(), "clock-frequency", u32.addr(), 4);
90     RegistryPropertyCreateStr(device_tree.addr(), "model", "Power Macintosh");
91 cebix 1.1
92     // Create "AAPL,ROM"
93 gbeauche 1.4 SheepRegEntryID aapl_rom;
94 gbeauche 1.13 if (!RegistryCStrEntryCreate(device_tree.addr(), "AAPL,ROM", aapl_rom.addr())) {
95     RegistryPropertyCreateStr(aapl_rom.addr(), "device_type", "rom");
96 gbeauche 1.4 SheepPair reg(ROM_BASE, ROM_SIZE);
97 gbeauche 1.13 RegistryPropertyCreate(aapl_rom.addr(), "reg", reg.addr(), 8);
98 cebix 1.1 }
99    
100     // Create "PowerPC,60x"
101 gbeauche 1.4 SheepRegEntryID power_pc;
102 cebix 1.1 char *str;
103     switch (PVR >> 16) {
104     case 1: // 601
105     str = "PowerPC,601";
106     break;
107     case 3: // 603
108     str = "PowerPC,603";
109     break;
110     case 4: // 604
111     str = "PowerPC,604";
112     break;
113     case 6: // 603e
114     str = "PowerPC,603e";
115     break;
116     case 7: // 603ev
117     str = "PowerPC,603ev";
118     break;
119     case 8: // 750
120     str = "PowerPC,750";
121     break;
122     case 9: // 604e
123     str = "PowerPC,604e";
124     break;
125     case 10: // 604ev5
126     str = "PowerPC,604ev";
127     break;
128     case 50: // 821
129     str = "PowerPC,821";
130     break;
131     case 80: // 860
132     str = "PowerPC,860";
133     break;
134     default:
135     str = "PowerPC,???";
136     break;
137     }
138 gbeauche 1.13 if (!RegistryCStrEntryCreate(device_tree.addr(), str, power_pc.addr())) {
139 gbeauche 1.4 u32.set_value(CPUClockSpeed);
140 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "clock-frequency", u32.addr(), 4);
141 gbeauche 1.9 u32.set_value(BusClockSpeed);
142 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "bus-frequency", u32.addr(), 4);
143 gbeauche 1.12 u32.set_value(TimebaseSpeed);
144 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "timebase-frequency", u32.addr(), 4);
145 gbeauche 1.4 u32.set_value(PVR);
146 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "cpu-version", u32.addr(), 4);
147     RegistryPropertyCreateStr(power_pc.addr(), "device_type", "cpu");
148 cebix 1.1 switch (PVR >> 16) {
149     case 1: // 601
150 gbeauche 1.4 u32.set_value(64);
151 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
152 gbeauche 1.4 u32.set_value(128);
153 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
154 gbeauche 1.4 u32.set_value(0x8000);
155 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
156 gbeauche 1.4 u32.set_value(64);
157 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
158 gbeauche 1.4 u32.set_value(128);
159 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
160 gbeauche 1.4 u32.set_value(0x8000);
161 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
162 gbeauche 1.4 u32.set_value(128);
163 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
164 gbeauche 1.4 u32.set_value(256);
165 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
166 cebix 1.1 break;
167     case 3: // 603
168 gbeauche 1.4 u32.set_value(32);
169 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
170 gbeauche 1.4 u32.set_value(64);
171 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
172 gbeauche 1.4 u32.set_value(0x2000);
173 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
174 gbeauche 1.4 u32.set_value(32);
175 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
176 gbeauche 1.4 u32.set_value(64);
177 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
178 gbeauche 1.4 u32.set_value(0x2000);
179 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
180 gbeauche 1.4 u32.set_value(32);
181 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
182 gbeauche 1.4 u32.set_value(64);
183 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
184 cebix 1.1 break;
185     case 4: // 604
186 gbeauche 1.4 u32.set_value(32);
187 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
188 gbeauche 1.4 u32.set_value(128);
189 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
190 gbeauche 1.4 u32.set_value(0x4000);
191 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
192 gbeauche 1.4 u32.set_value(32);
193 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
194 gbeauche 1.4 u32.set_value(128);
195 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
196 gbeauche 1.4 u32.set_value(0x4000);
197 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
198 gbeauche 1.4 u32.set_value(64);
199 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
200 gbeauche 1.4 u32.set_value(128);
201 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
202 cebix 1.1 break;
203     case 6: // 603e
204     case 7: // 603ev
205 gbeauche 1.4 u32.set_value(32);
206 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
207 gbeauche 1.4 u32.set_value(128);
208 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
209 gbeauche 1.4 u32.set_value(0x4000);
210 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
211 gbeauche 1.4 u32.set_value(32);
212 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
213 gbeauche 1.4 u32.set_value(128);
214 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
215 gbeauche 1.4 u32.set_value(0x4000);
216 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
217 gbeauche 1.4 u32.set_value(32);
218 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
219 gbeauche 1.4 u32.set_value(64);
220 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
221 cebix 1.1 break;
222 gbeauche 1.10 case 8: // 750, 750FX
223     case 0x7000:
224 gbeauche 1.4 u32.set_value(32);
225 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
226 gbeauche 1.4 u32.set_value(256);
227 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
228 gbeauche 1.4 u32.set_value(0x8000);
229 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
230 gbeauche 1.4 u32.set_value(32);
231 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
232 gbeauche 1.4 u32.set_value(256);
233 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
234 gbeauche 1.4 u32.set_value(0x8000);
235 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
236 gbeauche 1.4 u32.set_value(64);
237 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
238 gbeauche 1.4 u32.set_value(128);
239 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
240 cebix 1.1 break;
241     case 9: // 604e
242     case 10: // 604ev5
243 gbeauche 1.4 u32.set_value(32);
244 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
245 gbeauche 1.4 u32.set_value(256);
246 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
247 gbeauche 1.4 u32.set_value(0x8000);
248 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
249 gbeauche 1.4 u32.set_value(32);
250 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
251 gbeauche 1.4 u32.set_value(256);
252 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
253 gbeauche 1.4 u32.set_value(0x8000);
254 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
255 gbeauche 1.4 u32.set_value(64);
256 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
257 gbeauche 1.4 u32.set_value(128);
258 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
259 cebix 1.1 break;
260 gbeauche 1.10 case 12: // 7400, 7410, 7450, 7455, 7457
261 gbeauche 1.8 case 0x800c:
262 gbeauche 1.10 case 0x8000:
263     case 0x8001:
264     case 0x8002:
265 gbeauche 1.7 u32.set_value(32);
266 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
267 gbeauche 1.7 u32.set_value(128);
268 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
269 gbeauche 1.7 u32.set_value(0x8000);
270 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
271 gbeauche 1.7 u32.set_value(32);
272 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
273 gbeauche 1.7 u32.set_value(128);
274 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
275 gbeauche 1.7 u32.set_value(0x8000);
276 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
277 gbeauche 1.7 u32.set_value(64);
278 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
279 gbeauche 1.7 u32.set_value(128);
280 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
281 gbeauche 1.7 break;
282 gbeauche 1.11 case 0x39: // 970
283     u32.set_value(128);
284 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-block-size", u32.addr(), 4);
285 gbeauche 1.11 u32.set_value(128);
286 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-sets", u32.addr(), 4);
287 gbeauche 1.11 u32.set_value(0x8000);
288 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "d-cache-size", u32.addr(), 4);
289 gbeauche 1.11 u32.set_value(128);
290 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-block-size", u32.addr(), 4);
291 gbeauche 1.11 u32.set_value(512);
292 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-sets", u32.addr(), 4);
293 gbeauche 1.11 u32.set_value(0x10000);
294 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "i-cache-size", u32.addr(), 4);
295 gbeauche 1.11 u32.set_value(256);
296 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-sets", u32.addr(), 4);
297 gbeauche 1.11 u32.set_value(0x1000);
298 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "tlb-size", u32.addr(), 4);
299 gbeauche 1.11 break;
300 cebix 1.1 default:
301     break;
302     }
303 gbeauche 1.4 u32.set_value(32);
304 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "reservation-granularity", u32.addr(), 4);
305 gbeauche 1.4 SheepPair reg(0, 0);
306 gbeauche 1.13 RegistryPropertyCreate(power_pc.addr(), "reg", reg.addr(), 8);
307 cebix 1.1 }
308    
309     // Create "memory"
310 gbeauche 1.4 SheepRegEntryID memory;
311 gbeauche 1.13 if (!RegistryCStrEntryCreate(device_tree.addr(), "memory", memory.addr())) {
312 gbeauche 1.4 SheepPair reg(RAMBase, RAMSize);
313 gbeauche 1.13 RegistryPropertyCreateStr(memory.addr(), "device_type", "memory");
314     RegistryPropertyCreate(memory.addr(), "reg", reg.addr(), 8);
315 cebix 1.1 }
316    
317     // Create "video"
318 gbeauche 1.4 SheepRegEntryID video;
319 gbeauche 1.13 if (!RegistryCStrEntryCreate(device_tree.addr(), "video", video.addr())) {
320     RegistryPropertyCreateStr(video.addr(), "AAPL,connector", "monitor");
321     RegistryPropertyCreateStr(video.addr(), "device_type", "display");
322 gbeauche 1.14 SheepArray<sizeof(video_driver)> the_video_driver;
323     Host2Mac_memcpy(the_video_driver.addr(), video_driver, sizeof(video_driver));
324     RegistryPropertyCreate(video.addr(), "driver,AAPL,MacOS,PowerPC", the_video_driver.addr(), sizeof(video_driver));
325 gbeauche 1.13 RegistryPropertyCreateStr(video.addr(), "model", "SheepShaver Video");
326 cebix 1.1 }
327    
328     // Create "ethernet"
329 gbeauche 1.4 SheepRegEntryID ethernet;
330 gbeauche 1.13 if (!RegistryCStrEntryCreate(device_tree.addr(), "ethernet", ethernet.addr())) {
331     RegistryPropertyCreateStr(ethernet.addr(), "AAPL,connector", "ethernet");
332     RegistryPropertyCreateStr(ethernet.addr(), "device_type", "network");
333 gbeauche 1.14 SheepArray<sizeof(ethernet_driver)> the_ethernet_driver;
334     Host2Mac_memcpy(the_ethernet_driver.addr(), ethernet_driver, sizeof(ethernet_driver));
335     RegistryPropertyCreate(ethernet.addr(), "driver,AAPL,MacOS,PowerPC", the_ethernet_driver.addr(), sizeof(ethernet_driver));
336 cebix 1.1 // local-mac-address
337     // max-frame-size 2048
338     }
339     }
340     D(bug("done.\n"));
341     }
342    
343     void PatchNameRegistry(void)
344     {
345     // Find RegistryCStrEntryCreate() and RegistryPropertyCreate() TVECTs
346 gbeauche 1.15 rcec_tvect = FindLibSymbol("\017NameRegistryLib", "\027RegistryCStrEntryCreate");
347 cebix 1.1 D(bug("RegistryCStrEntryCreate TVECT at %08x\n", rcec_tvect));
348 gbeauche 1.15 rpc_tvect = FindLibSymbol("\017NameRegistryLib", "\026RegistryPropertyCreate");
349 cebix 1.1 D(bug("RegistryPropertyCreate TVECT at %08x\n", rpc_tvect));
350     if (rcec_tvect == 0 || rpc_tvect == 0) {
351     ErrorAlert(GetString(STR_NO_NAME_REGISTRY_ERR));
352     QuitEmulator();
353     }
354    
355     // Main routine must be executed in PPC mode
356 gbeauche 1.2 ExecuteNative(NATIVE_PATCH_NAME_REGISTRY);
357 cebix 1.1 }