ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/name_registry.cpp
Revision: 1.3
Committed: 2003-11-20T15:54:10Z (20 years, 6 months ago) by gbeauche
Branch: MAIN
Changes since 1.2: +59 -54 lines
Log Message:
little endian fixes to name registry

File Contents

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