ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/name_registry.cpp
Revision: 1.13
Committed: 2004-11-13T14:09:15Z (19 years, 6 months ago) by gbeauche
Branch: MAIN
Changes since 1.12: +96 -100 lines
Log Message:
Implement Direct Addressing mode similarly to Basilisk II. This is to get
SheepShaver working on OSes that don't support maipping of Low Memory globals
at 0x00000000, e.g. Windows.

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