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 |
|
|
u32 = BusClockSpeed; |
73 |
|
|
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 |
|
|
uint32 reg[2] = {ROM_BASE, ROM_SIZE}; |
81 |
|
|
RegistryPropertyCreate(&aapl_rom, "reg", ®, 8); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
// Create "PowerPC,60x" |
85 |
|
|
RegEntryID power_pc; |
86 |
|
|
char *str; |
87 |
|
|
switch (PVR >> 16) { |
88 |
|
|
case 1: // 601 |
89 |
|
|
str = "PowerPC,601"; |
90 |
|
|
break; |
91 |
|
|
case 3: // 603 |
92 |
|
|
str = "PowerPC,603"; |
93 |
|
|
break; |
94 |
|
|
case 4: // 604 |
95 |
|
|
str = "PowerPC,604"; |
96 |
|
|
break; |
97 |
|
|
case 6: // 603e |
98 |
|
|
str = "PowerPC,603e"; |
99 |
|
|
break; |
100 |
|
|
case 7: // 603ev |
101 |
|
|
str = "PowerPC,603ev"; |
102 |
|
|
break; |
103 |
|
|
case 8: // 750 |
104 |
|
|
str = "PowerPC,750"; |
105 |
|
|
break; |
106 |
|
|
case 9: // 604e |
107 |
|
|
str = "PowerPC,604e"; |
108 |
|
|
break; |
109 |
|
|
case 10: // 604ev5 |
110 |
|
|
str = "PowerPC,604ev"; |
111 |
|
|
break; |
112 |
|
|
case 50: // 821 |
113 |
|
|
str = "PowerPC,821"; |
114 |
|
|
break; |
115 |
|
|
case 80: // 860 |
116 |
|
|
str = "PowerPC,860"; |
117 |
|
|
break; |
118 |
|
|
default: |
119 |
|
|
str = "PowerPC,???"; |
120 |
|
|
break; |
121 |
|
|
} |
122 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, str, &power_pc)) { |
123 |
|
|
u32 = CPUClockSpeed; |
124 |
|
|
RegistryPropertyCreate(&power_pc, "clock-frequency", &u32, 4); |
125 |
|
|
RegistryPropertyCreate(&power_pc, "cpu-version", &PVR, 4); |
126 |
|
|
RegistryPropertyCreateStr(&power_pc, "device_type", "cpu"); |
127 |
|
|
switch (PVR >> 16) { |
128 |
|
|
case 1: // 601 |
129 |
|
|
u32 = 64; |
130 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
131 |
|
|
u32 = 128; |
132 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
133 |
|
|
u32 = 0x8000; |
134 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
135 |
|
|
u32 = 64; |
136 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
137 |
|
|
u32 = 128; |
138 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
139 |
|
|
u32 = 0x8000; |
140 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
141 |
|
|
u32 = 128; |
142 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
143 |
|
|
u32 = 256; |
144 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
145 |
|
|
break; |
146 |
|
|
case 3: // 603 |
147 |
|
|
u32 = 32; |
148 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
149 |
|
|
u32 = 64; |
150 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
151 |
|
|
u32 = 0x2000; |
152 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
153 |
|
|
u32 = 32; |
154 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
155 |
|
|
u32 = 64; |
156 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
157 |
|
|
u32 = 0x2000; |
158 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
159 |
|
|
u32 = 32; |
160 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
161 |
|
|
u32 = 64; |
162 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
163 |
|
|
break; |
164 |
|
|
case 4: // 604 |
165 |
|
|
u32 = 32; |
166 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
167 |
|
|
u32 = 128; |
168 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
169 |
|
|
u32 = 0x4000; |
170 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
171 |
|
|
u32 = 32; |
172 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
173 |
|
|
u32 = 128; |
174 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
175 |
|
|
u32 = 0x4000; |
176 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
177 |
|
|
u32 = 64; |
178 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
179 |
|
|
u32 = 128; |
180 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
181 |
|
|
break; |
182 |
|
|
case 6: // 603e |
183 |
|
|
case 7: // 603ev |
184 |
|
|
u32 = 32; |
185 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
186 |
|
|
u32 = 128; |
187 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
188 |
|
|
u32 = 0x4000; |
189 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
190 |
|
|
u32 = 32; |
191 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
192 |
|
|
u32 = 128; |
193 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
194 |
|
|
u32 = 0x4000; |
195 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
196 |
|
|
u32 = 32; |
197 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
198 |
|
|
u32 = 64; |
199 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
200 |
|
|
break; |
201 |
|
|
case 8: // 750 |
202 |
|
|
u32 = 32; |
203 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
204 |
|
|
u32 = 256; |
205 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
206 |
|
|
u32 = 0x8000; |
207 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
208 |
|
|
u32 = 32; |
209 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
210 |
|
|
u32 = 256; |
211 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
212 |
|
|
u32 = 0x8000; |
213 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
214 |
|
|
u32 = 64; |
215 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
216 |
|
|
u32 = 128; |
217 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
218 |
|
|
break; |
219 |
|
|
case 9: // 604e |
220 |
|
|
case 10: // 604ev5 |
221 |
|
|
u32 = 32; |
222 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
223 |
|
|
u32 = 256; |
224 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
225 |
|
|
u32 = 0x8000; |
226 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
227 |
|
|
u32 = 32; |
228 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
229 |
|
|
u32 = 256; |
230 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
231 |
|
|
u32 = 0x8000; |
232 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
233 |
|
|
u32 = 64; |
234 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
235 |
|
|
u32 = 128; |
236 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
237 |
|
|
break; |
238 |
|
|
default: |
239 |
|
|
break; |
240 |
|
|
} |
241 |
|
|
u32 = 32; |
242 |
|
|
RegistryPropertyCreate(&power_pc, "reservation-granularity", &u32, 4); |
243 |
|
|
uint32 reg[2] = {0, 0}; |
244 |
|
|
RegistryPropertyCreate(&power_pc, "reg", ®, 8); |
245 |
|
|
} |
246 |
|
|
|
247 |
|
|
// Create "memory" |
248 |
|
|
RegEntryID memory; |
249 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "memory", &memory)) { |
250 |
|
|
uint32 reg[2] = {RAMBase, RAMSize}; |
251 |
|
|
RegistryPropertyCreateStr(&memory, "device_type", "memory"); |
252 |
|
|
RegistryPropertyCreate(&memory, "reg", ®, 8); |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
// Create "video" |
256 |
|
|
RegEntryID video; |
257 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "video", &video)) { |
258 |
|
|
RegistryPropertyCreateStr(&video, "AAPL,connector", "monitor"); |
259 |
|
|
RegistryPropertyCreateStr(&video, "device_type", "display"); |
260 |
|
|
RegistryPropertyCreate(&video, "driver,AAPL,MacOS,PowerPC", &video_driver, sizeof(video_driver)); |
261 |
|
|
RegistryPropertyCreateStr(&video, "model", "SheepShaver Video"); |
262 |
|
|
} |
263 |
|
|
|
264 |
|
|
// Create "ethernet" |
265 |
|
|
RegEntryID ethernet; |
266 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "ethernet", ðernet)) { |
267 |
|
|
RegistryPropertyCreateStr(ðernet, "AAPL,connector", "ethernet"); |
268 |
|
|
RegistryPropertyCreateStr(ðernet, "device_type", "network"); |
269 |
|
|
RegistryPropertyCreate(ðernet, "driver,AAPL,MacOS,PowerPC", ðernet_driver, sizeof(ethernet_driver)); |
270 |
|
|
// local-mac-address |
271 |
|
|
// max-frame-size 2048 |
272 |
|
|
} |
273 |
|
|
} |
274 |
|
|
D(bug("done.\n")); |
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
void PatchNameRegistry(void) |
278 |
|
|
{ |
279 |
|
|
// Find RegistryCStrEntryCreate() and RegistryPropertyCreate() TVECTs |
280 |
|
|
rcec_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\027RegistryCStrEntryCreate"); |
281 |
|
|
D(bug("RegistryCStrEntryCreate TVECT at %08x\n", rcec_tvect)); |
282 |
|
|
rpc_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\026RegistryPropertyCreate"); |
283 |
|
|
D(bug("RegistryPropertyCreate TVECT at %08x\n", rpc_tvect)); |
284 |
|
|
if (rcec_tvect == 0 || rpc_tvect == 0) { |
285 |
|
|
ErrorAlert(GetString(STR_NO_NAME_REGISTRY_ERR)); |
286 |
|
|
QuitEmulator(); |
287 |
|
|
} |
288 |
|
|
|
289 |
|
|
// Main routine must be executed in PPC mode |
290 |
gbeauche |
1.2 |
#if EMULATED_PPC |
291 |
|
|
ExecuteNative(NATIVE_PATCH_NAME_REGISTRY); |
292 |
|
|
#else |
293 |
|
|
ExecutePPC(DoPatchNameRegistry); |
294 |
|
|
#endif |
295 |
cebix |
1.1 |
} |