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 |
|
|
|
29 |
|
|
#define DEBUG 0 |
30 |
|
|
#include "debug.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
// Function pointers |
34 |
|
|
typedef int16 (*rcec_ptr)(const RegEntryID *, const char *, RegEntryID *); |
35 |
|
|
static uint32 rcec_tvect = 0; |
36 |
|
|
static inline int16 RegistryCStrEntryCreate(const RegEntryID *arg1, const char *arg2, RegEntryID *arg3) |
37 |
|
|
{ |
38 |
|
|
return (int16)CallMacOS3(rcec_ptr, rcec_tvect, arg1, arg2, arg3); |
39 |
|
|
} |
40 |
|
|
typedef int16 (*rpc_ptr)(const RegEntryID *, const char *, const void *, uint32); |
41 |
|
|
static uint32 rpc_tvect = 0; |
42 |
|
|
static inline int16 RegistryPropertyCreate(const RegEntryID *arg1, const char *arg2, const void *arg3, uint32 arg4) |
43 |
|
|
{ |
44 |
|
|
return (int16)CallMacOS4(rpc_ptr, rpc_tvect, arg1, arg2, arg3, arg4); |
45 |
|
|
} |
46 |
|
|
#define RegistryPropertyCreateStr(e,n,s) RegistryPropertyCreate(e,n,s,strlen(s)+1) |
47 |
|
|
|
48 |
|
|
// Video driver stub |
49 |
|
|
static const uint8 video_driver[] = { |
50 |
|
|
#include "VideoDriverStub.i" |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
// Ethernet driver stub |
54 |
|
|
static const uint8 ethernet_driver[] = { |
55 |
|
|
#include "EthernetDriverStub.i" |
56 |
|
|
}; |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
/* |
60 |
|
|
* Patch Name Registry during startup |
61 |
|
|
*/ |
62 |
|
|
|
63 |
|
|
static void patch_name_registry(void) |
64 |
|
|
{ |
65 |
|
|
uint32 u32; |
66 |
|
|
D(bug("Patching Name Registry...")); |
67 |
|
|
|
68 |
|
|
// Create "device-tree" |
69 |
|
|
RegEntryID device_tree; |
70 |
|
|
if (!RegistryCStrEntryCreate(NULL, "Devices:device-tree", &device_tree)) { |
71 |
|
|
u32 = BusClockSpeed; |
72 |
|
|
RegistryPropertyCreate(&device_tree, "clock-frequency", &u32, 4); |
73 |
|
|
RegistryPropertyCreateStr(&device_tree, "model", "Power Macintosh"); |
74 |
|
|
|
75 |
|
|
// Create "AAPL,ROM" |
76 |
|
|
RegEntryID aapl_rom; |
77 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "AAPL,ROM", &aapl_rom)) { |
78 |
|
|
RegistryPropertyCreateStr(&aapl_rom, "device_type", "rom"); |
79 |
|
|
uint32 reg[2] = {ROM_BASE, ROM_SIZE}; |
80 |
|
|
RegistryPropertyCreate(&aapl_rom, "reg", ®, 8); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
// Create "PowerPC,60x" |
84 |
|
|
RegEntryID power_pc; |
85 |
|
|
char *str; |
86 |
|
|
switch (PVR >> 16) { |
87 |
|
|
case 1: // 601 |
88 |
|
|
str = "PowerPC,601"; |
89 |
|
|
break; |
90 |
|
|
case 3: // 603 |
91 |
|
|
str = "PowerPC,603"; |
92 |
|
|
break; |
93 |
|
|
case 4: // 604 |
94 |
|
|
str = "PowerPC,604"; |
95 |
|
|
break; |
96 |
|
|
case 6: // 603e |
97 |
|
|
str = "PowerPC,603e"; |
98 |
|
|
break; |
99 |
|
|
case 7: // 603ev |
100 |
|
|
str = "PowerPC,603ev"; |
101 |
|
|
break; |
102 |
|
|
case 8: // 750 |
103 |
|
|
str = "PowerPC,750"; |
104 |
|
|
break; |
105 |
|
|
case 9: // 604e |
106 |
|
|
str = "PowerPC,604e"; |
107 |
|
|
break; |
108 |
|
|
case 10: // 604ev5 |
109 |
|
|
str = "PowerPC,604ev"; |
110 |
|
|
break; |
111 |
|
|
case 50: // 821 |
112 |
|
|
str = "PowerPC,821"; |
113 |
|
|
break; |
114 |
|
|
case 80: // 860 |
115 |
|
|
str = "PowerPC,860"; |
116 |
|
|
break; |
117 |
|
|
default: |
118 |
|
|
str = "PowerPC,???"; |
119 |
|
|
break; |
120 |
|
|
} |
121 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, str, &power_pc)) { |
122 |
|
|
u32 = CPUClockSpeed; |
123 |
|
|
RegistryPropertyCreate(&power_pc, "clock-frequency", &u32, 4); |
124 |
|
|
RegistryPropertyCreate(&power_pc, "cpu-version", &PVR, 4); |
125 |
|
|
RegistryPropertyCreateStr(&power_pc, "device_type", "cpu"); |
126 |
|
|
switch (PVR >> 16) { |
127 |
|
|
case 1: // 601 |
128 |
|
|
u32 = 64; |
129 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
130 |
|
|
u32 = 128; |
131 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
132 |
|
|
u32 = 0x8000; |
133 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
134 |
|
|
u32 = 64; |
135 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
136 |
|
|
u32 = 128; |
137 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
138 |
|
|
u32 = 0x8000; |
139 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
140 |
|
|
u32 = 128; |
141 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
142 |
|
|
u32 = 256; |
143 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
144 |
|
|
break; |
145 |
|
|
case 3: // 603 |
146 |
|
|
u32 = 32; |
147 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
148 |
|
|
u32 = 64; |
149 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
150 |
|
|
u32 = 0x2000; |
151 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
152 |
|
|
u32 = 32; |
153 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
154 |
|
|
u32 = 64; |
155 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
156 |
|
|
u32 = 0x2000; |
157 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
158 |
|
|
u32 = 32; |
159 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
160 |
|
|
u32 = 64; |
161 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
162 |
|
|
break; |
163 |
|
|
case 4: // 604 |
164 |
|
|
u32 = 32; |
165 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
166 |
|
|
u32 = 128; |
167 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
168 |
|
|
u32 = 0x4000; |
169 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
170 |
|
|
u32 = 32; |
171 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
172 |
|
|
u32 = 128; |
173 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
174 |
|
|
u32 = 0x4000; |
175 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
176 |
|
|
u32 = 64; |
177 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
178 |
|
|
u32 = 128; |
179 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
180 |
|
|
break; |
181 |
|
|
case 6: // 603e |
182 |
|
|
case 7: // 603ev |
183 |
|
|
u32 = 32; |
184 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
185 |
|
|
u32 = 128; |
186 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
187 |
|
|
u32 = 0x4000; |
188 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
189 |
|
|
u32 = 32; |
190 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
191 |
|
|
u32 = 128; |
192 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
193 |
|
|
u32 = 0x4000; |
194 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
195 |
|
|
u32 = 32; |
196 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
197 |
|
|
u32 = 64; |
198 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
199 |
|
|
break; |
200 |
|
|
case 8: // 750 |
201 |
|
|
u32 = 32; |
202 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
203 |
|
|
u32 = 256; |
204 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
205 |
|
|
u32 = 0x8000; |
206 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
207 |
|
|
u32 = 32; |
208 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
209 |
|
|
u32 = 256; |
210 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
211 |
|
|
u32 = 0x8000; |
212 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
213 |
|
|
u32 = 64; |
214 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
215 |
|
|
u32 = 128; |
216 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
217 |
|
|
break; |
218 |
|
|
case 9: // 604e |
219 |
|
|
case 10: // 604ev5 |
220 |
|
|
u32 = 32; |
221 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-block-size", &u32, 4); |
222 |
|
|
u32 = 256; |
223 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-sets", &u32, 4); |
224 |
|
|
u32 = 0x8000; |
225 |
|
|
RegistryPropertyCreate(&power_pc, "d-cache-size", &u32, 4); |
226 |
|
|
u32 = 32; |
227 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-block-size", &u32, 4); |
228 |
|
|
u32 = 256; |
229 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-sets", &u32, 4); |
230 |
|
|
u32 = 0x8000; |
231 |
|
|
RegistryPropertyCreate(&power_pc, "i-cache-size", &u32, 4); |
232 |
|
|
u32 = 64; |
233 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-sets", &u32, 4); |
234 |
|
|
u32 = 128; |
235 |
|
|
RegistryPropertyCreate(&power_pc, "tlb-size", &u32, 4); |
236 |
|
|
break; |
237 |
|
|
default: |
238 |
|
|
break; |
239 |
|
|
} |
240 |
|
|
u32 = 32; |
241 |
|
|
RegistryPropertyCreate(&power_pc, "reservation-granularity", &u32, 4); |
242 |
|
|
uint32 reg[2] = {0, 0}; |
243 |
|
|
RegistryPropertyCreate(&power_pc, "reg", ®, 8); |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
// Create "memory" |
247 |
|
|
RegEntryID memory; |
248 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "memory", &memory)) { |
249 |
|
|
uint32 reg[2] = {RAMBase, RAMSize}; |
250 |
|
|
RegistryPropertyCreateStr(&memory, "device_type", "memory"); |
251 |
|
|
RegistryPropertyCreate(&memory, "reg", ®, 8); |
252 |
|
|
} |
253 |
|
|
|
254 |
|
|
// Create "video" |
255 |
|
|
RegEntryID video; |
256 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "video", &video)) { |
257 |
|
|
RegistryPropertyCreateStr(&video, "AAPL,connector", "monitor"); |
258 |
|
|
RegistryPropertyCreateStr(&video, "device_type", "display"); |
259 |
|
|
RegistryPropertyCreate(&video, "driver,AAPL,MacOS,PowerPC", &video_driver, sizeof(video_driver)); |
260 |
|
|
RegistryPropertyCreateStr(&video, "model", "SheepShaver Video"); |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
// Create "ethernet" |
264 |
|
|
RegEntryID ethernet; |
265 |
|
|
if (!RegistryCStrEntryCreate(&device_tree, "ethernet", ðernet)) { |
266 |
|
|
RegistryPropertyCreateStr(ðernet, "AAPL,connector", "ethernet"); |
267 |
|
|
RegistryPropertyCreateStr(ðernet, "device_type", "network"); |
268 |
|
|
RegistryPropertyCreate(ðernet, "driver,AAPL,MacOS,PowerPC", ðernet_driver, sizeof(ethernet_driver)); |
269 |
|
|
// local-mac-address |
270 |
|
|
// max-frame-size 2048 |
271 |
|
|
} |
272 |
|
|
} |
273 |
|
|
D(bug("done.\n")); |
274 |
|
|
} |
275 |
|
|
|
276 |
|
|
void PatchNameRegistry(void) |
277 |
|
|
{ |
278 |
|
|
// Find RegistryCStrEntryCreate() and RegistryPropertyCreate() TVECTs |
279 |
|
|
rcec_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\027RegistryCStrEntryCreate"); |
280 |
|
|
D(bug("RegistryCStrEntryCreate TVECT at %08x\n", rcec_tvect)); |
281 |
|
|
rpc_tvect = (uint32)FindLibSymbol("\017NameRegistryLib", "\026RegistryPropertyCreate"); |
282 |
|
|
D(bug("RegistryPropertyCreate TVECT at %08x\n", rpc_tvect)); |
283 |
|
|
if (rcec_tvect == 0 || rpc_tvect == 0) { |
284 |
|
|
ErrorAlert(GetString(STR_NO_NAME_REGISTRY_ERR)); |
285 |
|
|
QuitEmulator(); |
286 |
|
|
} |
287 |
|
|
|
288 |
|
|
// Main routine must be executed in PPC mode |
289 |
|
|
ExecutePPC(patch_name_registry); |
290 |
|
|
} |