1 |
|
/* |
2 |
|
* rom_patches.cpp - ROM patches |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig |
4 |
> |
* SheepShaver (C) 1997-2005 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 |
224 |
|
// id = 4711 means "find any ID" |
225 |
|
static uint32 find_rom_resource(uint32 s_type, int16 s_id = 4711, bool cont = false) |
226 |
|
{ |
227 |
< |
uint32 *lp = (uint32 *)(ROMBaseHost + 0x1a); |
228 |
< |
uint32 x = ntohl(*lp); |
229 |
< |
uint8 *bp = (uint8 *)(ROMBaseHost + x + 5); |
230 |
< |
uint32 header_size = *bp; |
227 |
> |
uint32 lp = ROM_BASE + 0x1a; |
228 |
> |
uint32 x = ReadMacInt32(lp); |
229 |
> |
uint32 header_size = ReadMacInt8(ROM_BASE + x + 5); |
230 |
|
|
231 |
|
if (!cont) |
232 |
|
rsrc_ptr = x; |
234 |
|
return 0; |
235 |
|
|
236 |
|
for (;;) { |
237 |
< |
lp = (uint32 *)(ROMBaseHost + rsrc_ptr); |
238 |
< |
rsrc_ptr = ntohl(*lp); |
237 |
> |
lp = ROM_BASE + rsrc_ptr; |
238 |
> |
rsrc_ptr = ReadMacInt32(lp); |
239 |
|
if (rsrc_ptr == 0) |
240 |
|
break; |
241 |
|
|
242 |
|
rsrc_ptr += header_size; |
243 |
|
|
244 |
< |
lp = (uint32 *)(ROMBaseHost + rsrc_ptr + 4); |
245 |
< |
uint32 data = ntohl(*lp); lp++; |
246 |
< |
uint32 type = ntohl(*lp); lp++; |
247 |
< |
int16 id = ntohs(*(int16 *)lp); |
244 |
> |
lp = ROM_BASE + rsrc_ptr + 4; |
245 |
> |
uint32 data = ReadMacInt32(lp); |
246 |
> |
uint32 type = ReadMacInt32(lp + 4); |
247 |
> |
int16 id = ReadMacInt16(lp + 8); |
248 |
|
if (type == s_type && (id == s_id || s_id == 4711)) |
249 |
|
return data; |
250 |
|
} |
258 |
|
|
259 |
|
static uint32 find_rom_trap(uint16 trap) |
260 |
|
{ |
261 |
< |
uint32 *lp = (uint32 *)(ROMBaseHost + 0x22); |
263 |
< |
lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); |
261 |
> |
uint32 lp = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22); |
262 |
|
|
263 |
|
if (trap > 0xa800) |
264 |
< |
return ntohl(lp[trap & 0x3ff]); |
264 |
> |
return ReadMacInt32(lp + 4 * (trap & 0x3ff)); |
265 |
|
else |
266 |
< |
return ntohl(lp[(trap & 0xff) + 0x400]); |
266 |
> |
return ReadMacInt32(lp + 4 * ((trap & 0xff) + 0x400)); |
267 |
|
} |
268 |
|
|
269 |
|
|
1083 |
|
*lp++ = htonl(0x48000000 + 0x36fb00 - base - 8); // b 0x36fb00 (Reset/FC1E opcode) |
1084 |
|
*lp++ = htonl(0x48000000 + 0x36fc00 - base - 12); // FE0A opcode |
1085 |
|
*lp++ = htonl(POWERPC_ILLEGAL); // Interrupt |
1086 |
< |
*lp++ = htonl(POWERPC_ILLEGAL); // ? |
1086 |
> |
*lp++ = htonl(0x48000000 + 0x36fd00 - base - 20); // FE0F opcode |
1087 |
|
*lp++ = htonl(POWERPC_ILLEGAL); |
1088 |
|
*lp++ = htonl(POWERPC_ILLEGAL); |
1089 |
|
*lp++ = htonl(POWERPC_ILLEGAL); |
1252 |
|
*lp++ = htonl(0x50e7deb4); // rlwimi r7,r7,27,$00000020 |
1253 |
|
*lp = htonl(0x4e800020); // blr |
1254 |
|
|
1255 |
+ |
// Extra routine for FE0F opcode (power management) |
1256 |
+ |
lp = (uint32 *)(ROMBaseHost + 0x36fd00); |
1257 |
+ |
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1258 |
+ |
*lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST |
1259 |
+ |
*lp++ = htonl(0x38210001); // addi r1,r1,1 |
1260 |
+ |
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1261 |
+ |
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1262 |
+ |
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1263 |
+ |
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1264 |
+ |
*lp++ = htonl(0x90c10004); // stw r6,$0004(r1) |
1265 |
+ |
*lp++ = htonl(0x80c1065c); // lwz r6,$065c(r1) |
1266 |
+ |
*lp++ = htonl(0x90e6013c); // stw r7,$013c(r6) |
1267 |
+ |
*lp++ = htonl(0x91060144); // stw r8,$0144(r6) |
1268 |
+ |
*lp++ = htonl(0x9126014c); // stw r9,$014c(r6) |
1269 |
+ |
*lp++ = htonl(0x91460154); // stw r10,$0154(r6) |
1270 |
+ |
*lp++ = htonl(0x9166015c); // stw r11,$015c(r6) |
1271 |
+ |
*lp++ = htonl(0x91860164); // stw r12,$0164(r6) |
1272 |
+ |
*lp++ = htonl(0x91a6016c); // stw r13,$016c(r6) |
1273 |
+ |
*lp++ = htonl(0x7da00026); // mfcr r13 |
1274 |
+ |
*lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) |
1275 |
+ |
*lp++ = htonl(0x7d8802a6); // mflr r12 |
1276 |
+ |
*lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 |
1277 |
+ |
*lp++ = htonl(0x81410604); // lwz r10,0x0604(r1) |
1278 |
+ |
*lp++ = htonl(0x7d4803a6); // mtlr r10 |
1279 |
+ |
*lp++ = htonl(0x7d8a6378); // mr r10,r12 |
1280 |
+ |
*lp++ = htonl(0x3d600002); // lis r11,0x0002 |
1281 |
+ |
*lp++ = htonl(0x616bf072); // ori r11,r11,0xf072 (MSR) |
1282 |
+ |
*lp++ = htonl(0x50e7deb4); // rlwimi r7,r7,27,$00000020 |
1283 |
+ |
*lp = htonl(0x4e800020); // blr |
1284 |
+ |
|
1285 |
|
// Patch DR emulator to jump to right address when an interrupt occurs |
1286 |
|
lp = (uint32 *)(ROMBaseHost + 0x370000); |
1287 |
|
while (lp < (uint32 *)(ROMBaseHost + 0x380000)) { |
1410 |
|
*lp++ = htonl(POWERPC_NOP); |
1411 |
|
*lp = htonl(POWERPC_NOP); |
1412 |
|
|
1413 |
+ |
// Disable suspend (FE0F opcode) |
1414 |
+ |
// TODO: really suspend SheepShaver? |
1415 |
+ |
static const uint8 suspend_dat[] = {0x7c, 0x88, 0x68, 0x39, 0x41, 0x9d}; |
1416 |
+ |
if ((base = find_rom_data(0x315000, 0x316000, suspend_dat, sizeof(suspend_dat))) == 0) return false; |
1417 |
+ |
D(bug("suspend %08lx\n", base)); |
1418 |
+ |
lp = (uint32 *)(ROMBaseHost + base + 4); |
1419 |
+ |
*lp = htonl((ntohl(*lp) & 0xffff) | 0x48000000); // bgt -> b |
1420 |
+ |
|
1421 |
|
// Patch trap return routine |
1422 |
|
static const uint8 trap_return_dat[] = {0x80, 0xc1, 0x00, 0x18, 0x80, 0x21, 0x00, 0x04, 0x4c, 0x00, 0x00, 0x64}; |
1423 |
|
if ((base = find_rom_data(0x312000, 0x320000, trap_return_dat, sizeof(trap_return_dat))) == 0) return false; |
1713 |
|
static const uint8 ext_cache_dat[] = {0x4e, 0x7b, 0x00, 0x02}; |
1714 |
|
if ((base = find_rom_data(0x1d0, 0x230, ext_cache_dat, sizeof(ext_cache_dat))) == 0) return false; |
1715 |
|
D(bug("ext_cache %08lx\n", base)); |
1716 |
< |
lp = (uint32 *)(ROMBaseHost + base + 6); |
1717 |
< |
wp = (uint16 *)(ROMBaseHost + ntohl(*lp) + base + 6); |
1716 |
> |
loc = ReadMacInt32(ROM_BASE + base + 6); |
1717 |
> |
wp = (uint16 *)(ROMBaseHost + loc + base + 6); |
1718 |
|
*wp = htons(M68K_RTS); |
1719 |
< |
lp = (uint32 *)(ROMBaseHost + base + 12); |
1720 |
< |
wp = (uint16 *)(ROMBaseHost + ntohl(*lp) + base + 12); |
1719 |
> |
loc = ReadMacInt32(ROM_BASE + base + 12); |
1720 |
> |
wp = (uint16 *)(ROMBaseHost + loc + base + 12); |
1721 |
|
*wp = htons(M68K_RTS); |
1722 |
|
|
1723 |
|
// Fake CPU speed test (SetupTimeK) |
2262 |
|
*wp++ = htons(M68K_JMP); |
2263 |
|
*wp++ = htons((ROM_BASE + put_scrap) >> 16); |
2264 |
|
*wp++ = htons((ROM_BASE + put_scrap) & 0xffff); |
2265 |
< |
lp = (uint32 *)(ROMBaseHost + 0x22); |
2266 |
< |
lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); |
2231 |
< |
lp[0xa9fe & 0x3ff] = htonl(PUT_SCRAP_PATCH_SPACE); |
2265 |
> |
base = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22); |
2266 |
> |
WriteMacInt32(base + 4 * (0xa9fe & 0x3ff), PUT_SCRAP_PATCH_SPACE); |
2267 |
|
|
2268 |
|
// Patch GetScrap() for clipboard exchange with host OS |
2269 |
|
uint32 get_scrap = find_rom_trap(0xa9fd); // GetScrap() |
2272 |
|
*wp++ = htons(M68K_JMP); |
2273 |
|
*wp++ = htons((ROM_BASE + get_scrap) >> 16); |
2274 |
|
*wp++ = htons((ROM_BASE + get_scrap) & 0xffff); |
2275 |
< |
lp = (uint32 *)(ROMBaseHost + 0x22); |
2276 |
< |
lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); |
2242 |
< |
lp[0xa9fd & 0x3ff] = htonl(GET_SCRAP_PATCH_SPACE); |
2275 |
> |
base = ROM_BASE + ReadMacInt32(ROM_BASE + 0x22); |
2276 |
> |
WriteMacInt32(base + 4 * (0xa9fd & 0x3ff), GET_SCRAP_PATCH_SPACE); |
2277 |
|
|
2278 |
|
// Patch SynchIdleTime() |
2279 |
|
if (PrefsFindBool("idlewait")) { |
2340 |
|
SheepArray<SIZEOF_IOParam> pb_var; |
2341 |
|
const uintptr pb = pb_var.addr(); |
2342 |
|
|
2343 |
+ |
#if DISABLE_SCSI |
2344 |
+ |
// Setup fake SCSI Globals |
2345 |
+ |
r.d[0] = 0x1000; |
2346 |
+ |
Execute68kTrap(0xa71e, &r); // NewPtrSysClear() |
2347 |
+ |
uint32 scsi_globals = r.a[0]; |
2348 |
+ |
D(bug("Fake SCSI globals at %08lx\n", scsi_globals)); |
2349 |
+ |
WriteMacInt32(0xc0c, scsi_globals); // Set SCSIGlobals |
2350 |
+ |
#endif |
2351 |
+ |
|
2352 |
|
// Install floppy driver |
2353 |
|
if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) { |
2354 |
|
|
2363 |
|
WriteMacInt16(dce + dCtlFlags, SonyDriverFlags); |
2364 |
|
} |
2365 |
|
|
2323 |
– |
#if DISABLE_SCSI && HAVE_SIGSEGV_SKIP_INSTRUCTION |
2324 |
– |
// Fake SCSIGlobals |
2325 |
– |
WriteMacInt32(0xc0c, SheepMem::ZeroPage()); |
2326 |
– |
#endif |
2327 |
– |
|
2366 |
|
// Open .Sony driver |
2367 |
|
SheepString sony_str("\005.Sony"); |
2368 |
|
WriteMacInt8(pb + ioPermssn, 0); |