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