--- SheepShaver/src/rom_patches.cpp 2004/12/12 18:45:44 1.37 +++ SheepShaver/src/rom_patches.cpp 2009/08/18 18:26:10 1.46 @@ -1,7 +1,7 @@ /* * rom_patches.cpp - ROM patches * - * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -224,10 +224,9 @@ static uint32 rsrc_ptr = 0; // id = 4711 means "find any ID" static uint32 find_rom_resource(uint32 s_type, int16 s_id = 4711, bool cont = false) { - uint32 *lp = (uint32 *)(ROMBaseHost + 0x1a); - uint32 x = ntohl(*lp); - uint8 *bp = (uint8 *)(ROMBaseHost + x + 5); - uint32 header_size = *bp; + uint32 lp = ROMBase + 0x1a; + uint32 x = ReadMacInt32(lp); + uint32 header_size = ReadMacInt8(ROMBase + x + 5); if (!cont) rsrc_ptr = x; @@ -235,17 +234,17 @@ static uint32 find_rom_resource(uint32 s return 0; for (;;) { - lp = (uint32 *)(ROMBaseHost + rsrc_ptr); - rsrc_ptr = ntohl(*lp); + lp = ROMBase + rsrc_ptr; + rsrc_ptr = ReadMacInt32(lp); if (rsrc_ptr == 0) break; rsrc_ptr += header_size; - lp = (uint32 *)(ROMBaseHost + rsrc_ptr + 4); - uint32 data = ntohl(*lp); lp++; - uint32 type = ntohl(*lp); lp++; - int16 id = ntohs(*(int16 *)lp); + lp = ROMBase + rsrc_ptr + 4; + uint32 data = ReadMacInt32(lp); + uint32 type = ReadMacInt32(lp + 4); + int16 id = ReadMacInt16(lp + 8); if (type == s_type && (id == s_id || s_id == 4711)) return data; } @@ -259,13 +258,12 @@ static uint32 find_rom_resource(uint32 s static uint32 find_rom_trap(uint16 trap) { - uint32 *lp = (uint32 *)(ROMBaseHost + 0x22); - lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); + uint32 lp = ROMBase + ReadMacInt32(ROMBase + 0x22); if (trap > 0xa800) - return ntohl(lp[trap & 0x3ff]); + return ReadMacInt32(lp + 4 * (trap & 0x3ff)); else - return ntohl(lp[(trap & 0xff) + 0x400]); + return ReadMacInt32(lp + 4 * ((trap & 0xff) + 0x400)); } @@ -761,10 +759,10 @@ static bool patch_nanokernel_boot(void) lp[0x9c >> 2] = htonl(KernelDataAddr); // LA_InfoRecord lp[0xa0 >> 2] = htonl(KernelDataAddr); // LA_KernelData lp[0xa4 >> 2] = htonl(KernelDataAddr + 0x1000); // LA_EmulatorData - lp[0xa8 >> 2] = htonl(ROM_BASE + 0x480000); // LA_DispatchTable - lp[0xac >> 2] = htonl(ROM_BASE + 0x460000); // LA_EmulatorCode + lp[0xa8 >> 2] = htonl(ROMBase + 0x480000); // LA_DispatchTable + lp[0xac >> 2] = htonl(ROMBase + 0x460000); // LA_EmulatorCode lp[0x360 >> 2] = htonl(0); // Physical RAM base (? on NewWorld ROM, this contains -1) - lp[0xfd8 >> 2] = htonl(ROM_BASE + 0x2a); // 68k reset vector + lp[0xfd8 >> 2] = htonl(ROMBase + 0x2a); // 68k reset vector // Skip SR/BAT/SDR init loc = 0x310000; @@ -777,7 +775,7 @@ static bool patch_nanokernel_boot(void) if ((base = find_rom_data(0x3101b0, 0x3105b0, sr_init_dat, sizeof(sr_init_dat))) == 0) return false; D(bug("sr_init %08lx\n", base)); lp = (uint32 *)(ROMBaseHost + loc + 8); - *lp = htonl(0x48000000 | ((base - loc - 8) & 0x3fffffc)); // b ROM_BASE+0x3101b0 + *lp = htonl(0x48000000 | ((base - loc - 8) & 0x3fffffc)); // b ROMBase+0x3101b0 lp = (uint32 *)(ROMBaseHost + base); *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA); // lwz r1,(pointer to Kernel Data) *lp++ = htonl(0x3da0dead); // lis r13,0xdead (start of kernel memory) @@ -1085,7 +1083,7 @@ static bool patch_68k_emul(void) *lp++ = htonl(0x48000000 + 0x36fb00 - base - 8); // b 0x36fb00 (Reset/FC1E opcode) *lp++ = htonl(0x48000000 + 0x36fc00 - base - 12); // FE0A opcode *lp++ = htonl(POWERPC_ILLEGAL); // Interrupt - *lp++ = htonl(POWERPC_ILLEGAL); // ? + *lp++ = htonl(0x48000000 + 0x36fd00 - base - 20); // FE0F opcode *lp++ = htonl(POWERPC_ILLEGAL); *lp++ = htonl(POWERPC_ILLEGAL); *lp++ = htonl(POWERPC_ILLEGAL); @@ -1254,6 +1252,36 @@ static bool patch_68k_emul(void) *lp++ = htonl(0x50e7deb4); // rlwimi r7,r7,27,$00000020 *lp = htonl(0x4e800020); // blr + // Extra routine for FE0F opcode (power management) + lp = (uint32 *)(ROMBaseHost + 0x36fd00); + *lp++ = htonl(0x7c2903a6); // mtctr r1 + *lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST + *lp++ = htonl(0x38210001); // addi r1,r1,1 + *lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST + *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA + *lp++ = htonl(0x90c10018); // stw r6,0x18(r1) + *lp++ = htonl(0x7cc902a6); // mfctr r6 + *lp++ = htonl(0x90c10004); // stw r6,$0004(r1) + *lp++ = htonl(0x80c1065c); // lwz r6,$065c(r1) + *lp++ = htonl(0x90e6013c); // stw r7,$013c(r6) + *lp++ = htonl(0x91060144); // stw r8,$0144(r6) + *lp++ = htonl(0x9126014c); // stw r9,$014c(r6) + *lp++ = htonl(0x91460154); // stw r10,$0154(r6) + *lp++ = htonl(0x9166015c); // stw r11,$015c(r6) + *lp++ = htonl(0x91860164); // stw r12,$0164(r6) + *lp++ = htonl(0x91a6016c); // stw r13,$016c(r6) + *lp++ = htonl(0x7da00026); // mfcr r13 + *lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) + *lp++ = htonl(0x7d8802a6); // mflr r12 + *lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 + *lp++ = htonl(0x81410604); // lwz r10,0x0604(r1) + *lp++ = htonl(0x7d4803a6); // mtlr r10 + *lp++ = htonl(0x7d8a6378); // mr r10,r12 + *lp++ = htonl(0x3d600002); // lis r11,0x0002 + *lp++ = htonl(0x616bf072); // ori r11,r11,0xf072 (MSR) + *lp++ = htonl(0x50e7deb4); // rlwimi r7,r7,27,$00000020 + *lp = htonl(0x4e800020); // blr + // Patch DR emulator to jump to right address when an interrupt occurs lp = (uint32 *)(ROMBaseHost + 0x370000); while (lp < (uint32 *)(ROMBaseHost + 0x380000)) { @@ -1275,8 +1303,8 @@ dr_found: D(bug(" patching absolute branch at %08x\n", loc)); *lp = htonl(0x48000000 + 0xf000 - (loc & 0xffff)); // b DR_CACHE_BASE+0x1f000 lp = (uint32 *)(ROMBaseHost + 0x37f000); - *lp++ = htonl(0x3c000000 + ((ROM_BASE + base) >> 16)); // lis r0,xxx - *lp++ = htonl(0x60000000 + ((ROM_BASE + base) & 0xffff)); // ori r0,r0,xxx + *lp++ = htonl(0x3c000000 + ((ROMBase + base) >> 16)); // lis r0,xxx + *lp++ = htonl(0x60000000 + ((ROMBase + base) & 0xffff)); // ori r0,r0,xxx *lp++ = htonl(0x7c0803a6); // mtlr r0 *lp = htonl(POWERPC_BLR); // blr } @@ -1382,6 +1410,14 @@ static bool patch_nanokernel(void) *lp++ = htonl(POWERPC_NOP); *lp = htonl(POWERPC_NOP); + // Disable suspend (FE0F opcode) + // TODO: really suspend SheepShaver? + static const uint8 suspend_dat[] = {0x7c, 0x88, 0x68, 0x39, 0x41, 0x9d}; + if ((base = find_rom_data(0x315000, 0x316000, suspend_dat, sizeof(suspend_dat))) == 0) return false; + D(bug("suspend %08lx\n", base)); + lp = (uint32 *)(ROMBaseHost + base + 4); + *lp = htonl((ntohl(*lp) & 0xffff) | 0x48000000); // bgt -> b + // Patch trap return routine static const uint8 trap_return_dat[] = {0x80, 0xc1, 0x00, 0x18, 0x80, 0x21, 0x00, 0x04, 0x4c, 0x00, 0x00, 0x64}; if ((base = find_rom_data(0x312000, 0x320000, trap_return_dat, sizeof(trap_return_dat))) == 0) return false; @@ -1392,18 +1428,59 @@ static bool patch_nanokernel(void) while (ntohl(*lp) != 0x7d5a03a6) lp--; *lp++ = htonl(0x7d4903a6); // mtctr r10 *lp++ = htonl(0x7daff120); // mtcr r13 - *lp = htonl(0x48000000 + ((0x318000 - ((uintptr)lp - (uintptr)ROMBaseHost)) & 0x03fffffc)); // b ROM_BASE+0x318000 + *lp = htonl(0x48000000 + ((0x318000 - ((uintptr)lp - (uintptr)ROMBaseHost)) & 0x03fffffc)); // b ROMBase+0x318000 uint32 npc = (uintptr)(lp + 1) - (uintptr)ROMBaseHost; lp = (uint32 *)(ROMBaseHost + 0x318000); *lp++ = htonl(0x81400000 + XLM_IRQ_NEST); // lwz r10,XLM_IRQ_NEST *lp++ = htonl(0x394affff); // subi r10,r10,1 *lp++ = htonl(0x91400000 + XLM_IRQ_NEST); // stw r10,XLM_IRQ_NEST - *lp = htonl(0x48000000 + ((npc - 0x31800c) & 0x03fffffc)); // b ROM_BASE+0x312c2c + *lp = htonl(0x48000000 + ((npc - 0x31800c) & 0x03fffffc)); // b ROMBase+0x312c2c + + // Patch FEOA opcode, selector 0x0A (virtual->physical page index) + static const uint8 fe0a_0a_dat[] = {0x55, 0x23, 0xa3, 0x3e, 0x4b}; + if ((base = find_rom_data(0x314000, 0x318000, fe0a_0a_dat, sizeof(fe0a_0a_dat))) == 0) return false; + loc = rom_powerpc_branch_target(base - 8); + static const uint8 fe0a_dat[] = {0x7e, 0x04, 0x48, 0x40, 0x81, 0xe1, 0x06, 0xb0, 0x54, 0x88, 0x10, 0x3a, 0x40, 0x90}; + if (find_rom_data(loc, 0x318000, fe0a_dat, sizeof(fe0a_dat)) != loc) return false; + D(bug("fe0a_0a %08lx\n", base - 8)); + lp = (uint32 *)(ROMBaseHost + base - 8); + *lp++ = htonl(0x7c832378); // mr r3,r4 + *lp++ = htonl(POWERPC_NOP); + *lp = htonl(POWERPC_NOP); + + // Disable FE0A opcode, selector 0x11 (init page tables?) + static const uint8 fe0a_11_dat[] = {0x56, 0x07, 0x06, 0x74, 0x2c, 0x07, 0x00, 0x60, 0x40}; + if ((base = find_rom_data(0x314000, 0x318000, fe0a_11_dat, sizeof(fe0a_11_dat))) == 0) return false; + loc = rom_powerpc_branch_target(base - 4); + if (find_rom_data(0x314000, 0x318000, fe0a_dat, sizeof(fe0a_dat)) != loc) return false; + D(bug("fe0a_11 %08lx\n", base - 4)); + lp = (uint32 *)(ROMBaseHost + base - 4); + *lp++ = htonl(POWERPC_NOP); + *lp++ = htonl(POWERPC_NOP); + *lp++ = htonl(POWERPC_NOP); + *lp = htonl(ntohl(*lp) | 0x02800000); // bf => ba + + // Patch FE0A opcode to fake a page table entry so that V=P for RAM and ROM + static const uint8 pg_lookup_dat[] = {0x7e, 0x0f, 0x40, 0x6e, 0x81, 0xc1, 0x06, 0xa4, 0x7e, 0x00, 0x71, 0x20}; + if ((base = find_rom_data(0x310000, 0x320000, pg_lookup_dat, sizeof(pg_lookup_dat))) == 0) return false; + D(bug("fe0a_pgtb_lookup %08lx\n", base - 12)); + lp = (uint32 *)(ROMBaseHost + base - 12); + if (ntohl(lp[0]) != 0x81e106b0) // lwz r15,$06b0(r1) + return false; + lp[0] = htonl(0x54906026); // slwi r16,r4,12 + lp[3] = htonl(0x62100121); // ori r16,r16,0x121 + + // Patch FE0A opcode to not write to kernel memory + static const uint8 krnl_write_dat[] = {0x38, 0xe0, 0x00, 0x01, 0x7e, 0x10, 0x38, 0x78, 0x92, 0x0f, 0x00, 0x00}; + if ((base = find_rom_data(0x310000, 0x320000, krnl_write_dat, sizeof(krnl_write_dat))) == 0) return false; + D(bug("fe0a_krnl_write %08lx\n", base)); + lp = (uint32 *)(ROMBaseHost + base); + lp[2] = htonl(POWERPC_NOP); /* // Disable FE0A/FE06 opcodes - lp = (uint32 *)(ROM_BASE + 0x3144ac); + lp = (uint32 *)(ROMBase + 0x3144ac); *lp++ = htonl(POWERPC_NOP); *lp += 8; */ @@ -1677,11 +1754,11 @@ static bool patch_68k(void) static const uint8 ext_cache_dat[] = {0x4e, 0x7b, 0x00, 0x02}; if ((base = find_rom_data(0x1d0, 0x230, ext_cache_dat, sizeof(ext_cache_dat))) == 0) return false; D(bug("ext_cache %08lx\n", base)); - lp = (uint32 *)(ROMBaseHost + base + 6); - wp = (uint16 *)(ROMBaseHost + ntohl(*lp) + base + 6); + loc = ReadMacInt32(ROMBase + base + 6); + wp = (uint16 *)(ROMBaseHost + loc + base + 6); *wp = htons(M68K_RTS); - lp = (uint32 *)(ROMBaseHost + base + 12); - wp = (uint16 *)(ROMBaseHost + ntohl(*lp) + base + 12); + loc = ReadMacInt32(ROMBase + base + 12); + wp = (uint16 *)(ROMBaseHost + loc + base + 12); *wp = htons(M68K_RTS); // Fake CPU speed test (SetupTimeK) @@ -1711,7 +1788,7 @@ static bool patch_68k(void) for (;;) { D(bug(" %08lx\n", (uintptr)lp - (uintptr)ROMBaseHost)); while ((ntohl(*lp) & 0xff000000) == 0xff000000) { - *lp = htonl((ntohl(*lp) & (ROM_SIZE-1)) + ROM_BASE); + *lp = htonl((ntohl(*lp) & (ROM_SIZE-1)) + ROMBase); lp++; } while (!ntohl(*lp)) lp++; @@ -1963,12 +2040,12 @@ static bool patch_68k(void) *lp = htonl(0x38600000); // li r3,0 } - // FIXME: Fake reading from [HpChk]+4 (the callchain reports some function from DriverServicesLib) + // Don't read from MacPgm in WipeOutMACPGMINFOProcPtrs (StdCLib) if (1) { uint32 hpchk_offset = find_rom_resource(FOURCC('n','l','i','b'), 10); static const uint8 hpchk_dat[] = {0x80, 0x80, 0x03, 0x16, 0x94, 0x21, 0xff, 0xb0, 0x83, 0xc4, 0x00, 0x04}; if ((base = find_rom_data(hpchk_offset, hpchk_offset + 0x3000, hpchk_dat, sizeof(hpchk_dat))) == 0) return false; - D(bug("hpchk %08lx\n", base)); + D(bug("macpgm %08lx\n", base)); lp = (uint32 *)(ROMBaseHost + base); *lp = htonl(0x80800000 + XLM_ZERO_PAGE); // lwz r4,(zero page) } @@ -1991,12 +2068,12 @@ static bool patch_68k(void) D(bug("scsi_mgr %08lx\n", base)); wp = (uint16 *)(ROMBaseHost + base); *wp++ = htons(0x21fc); // move.l #xxx,0x624 (SCSIAtomic) - *wp++ = htons((ROM_BASE + base + 18) >> 16); - *wp++ = htons((ROM_BASE + base + 18) & 0xffff); + *wp++ = htons((ROMBase + base + 18) >> 16); + *wp++ = htons((ROMBase + base + 18) & 0xffff); *wp++ = htons(0x0624); *wp++ = htons(0x21fc); // move.l #xxx,0xe54 (SCSIDispatch) - *wp++ = htons((ROM_BASE + base + 22) >> 16); - *wp++ = htons((ROM_BASE + base + 22) & 0xffff); + *wp++ = htons((ROMBase + base + 22) >> 16); + *wp++ = htons((ROMBase + base + 22) & 0xffff); *wp++ = htons(0x0e54); *wp++ = htons(M68K_RTS); *wp++ = htons(M68K_EMUL_OP_SCSI_ATOMIC); @@ -2065,8 +2142,8 @@ static bool patch_68k(void) D(bug("check_load %08lx\n", base)); wp = (uint16 *)(ROMBaseHost + base); *wp++ = htons(M68K_JMP); - *wp++ = htons((ROM_BASE + CHECK_LOAD_PATCH_SPACE) >> 16); - *wp = htons((ROM_BASE + CHECK_LOAD_PATCH_SPACE) & 0xffff); + *wp++ = htons((ROMBase + CHECK_LOAD_PATCH_SPACE) >> 16); + *wp = htons((ROMBase + CHECK_LOAD_PATCH_SPACE) & 0xffff); wp = (uint16 *)(ROMBaseHost + CHECK_LOAD_PATCH_SPACE); *wp++ = htons(0x2f03); // move.l d3,-(a7) *wp++ = htons(0x2078); // move.l $07f0,a0 @@ -2096,19 +2173,19 @@ static bool patch_68k(void) memcpy((void *)(ROMBaseHost + sony_offset + 0x200), cdrom_driver, sizeof(cdrom_driver)); // Install serial drivers - gen_ain_driver( ROM_BASE + sony_offset + 0x300); - gen_aout_driver(ROM_BASE + sony_offset + 0x400); - gen_bin_driver( ROM_BASE + sony_offset + 0x500); - gen_bout_driver(ROM_BASE + sony_offset + 0x600); + gen_ain_driver( ROMBase + sony_offset + 0x300); + gen_aout_driver(ROMBase + sony_offset + 0x400); + gen_bin_driver( ROMBase + sony_offset + 0x500); + gen_bout_driver(ROMBase + sony_offset + 0x600); // Copy icons to ROM - SonyDiskIconAddr = ROM_BASE + sony_offset + 0x800; + SonyDiskIconAddr = ROMBase + sony_offset + 0x800; memcpy(ROMBaseHost + sony_offset + 0x800, SonyDiskIcon, sizeof(SonyDiskIcon)); - SonyDriveIconAddr = ROM_BASE + sony_offset + 0xa00; + SonyDriveIconAddr = ROMBase + sony_offset + 0xa00; memcpy(ROMBaseHost + sony_offset + 0xa00, SonyDriveIcon, sizeof(SonyDriveIcon)); - DiskIconAddr = ROM_BASE + sony_offset + 0xc00; + DiskIconAddr = ROMBase + sony_offset + 0xc00; memcpy(ROMBaseHost + sony_offset + 0xc00, DiskIcon, sizeof(DiskIcon)); - CDROMIconAddr = ROM_BASE + sony_offset + 0xe00; + CDROMIconAddr = ROMBase + sony_offset + 0xe00; memcpy(ROMBaseHost + sony_offset + 0xe00, CDROMIcon, sizeof(CDROMIcon)); // Patch driver install routine @@ -2192,7 +2269,7 @@ static bool patch_68k(void) static const uint8 via_int_dat[] = {0x70, 0x7f, 0xc0, 0x29, 0x1a, 0x00, 0xc0, 0x29, 0x1c, 0x00}; if ((base = find_rom_data(0x13000, 0x1c000, via_int_dat, sizeof(via_int_dat))) == 0) return false; D(bug("via_int %08lx\n", base)); - uint32 level1_int = ROM_BASE + base; + uint32 level1_int = ROMBase + base; wp = (uint16 *)(ROMBaseHost + base); // Level 1 handler *wp++ = htons(0x7002); // moveq #2,d0 (60Hz interrupt) *wp++ = htons(M68K_NOP); @@ -2224,22 +2301,20 @@ static bool patch_68k(void) wp = (uint16 *)(ROMBaseHost + PUT_SCRAP_PATCH_SPACE); *wp++ = htons(M68K_EMUL_OP_PUT_SCRAP); *wp++ = htons(M68K_JMP); - *wp++ = htons((ROM_BASE + put_scrap) >> 16); - *wp++ = htons((ROM_BASE + put_scrap) & 0xffff); - lp = (uint32 *)(ROMBaseHost + 0x22); - lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); - lp[0xa9fe & 0x3ff] = htonl(PUT_SCRAP_PATCH_SPACE); + *wp++ = htons((ROMBase + put_scrap) >> 16); + *wp++ = htons((ROMBase + put_scrap) & 0xffff); + base = ROMBase + ReadMacInt32(ROMBase + 0x22); + WriteMacInt32(base + 4 * (0xa9fe & 0x3ff), PUT_SCRAP_PATCH_SPACE); // Patch GetScrap() for clipboard exchange with host OS uint32 get_scrap = find_rom_trap(0xa9fd); // GetScrap() wp = (uint16 *)(ROMBaseHost + GET_SCRAP_PATCH_SPACE); *wp++ = htons(M68K_EMUL_OP_GET_SCRAP); *wp++ = htons(M68K_JMP); - *wp++ = htons((ROM_BASE + get_scrap) >> 16); - *wp++ = htons((ROM_BASE + get_scrap) & 0xffff); - lp = (uint32 *)(ROMBaseHost + 0x22); - lp = (uint32 *)(ROMBaseHost + ntohl(*lp)); - lp[0xa9fd & 0x3ff] = htonl(GET_SCRAP_PATCH_SPACE); + *wp++ = htons((ROMBase + get_scrap) >> 16); + *wp++ = htons((ROMBase + get_scrap) & 0xffff); + base = ROMBase + ReadMacInt32(ROMBase + 0x22); + WriteMacInt32(base + 4 * (0xa9fd & 0x3ff), GET_SCRAP_PATCH_SPACE); // Patch SynchIdleTime() if (PrefsFindBool("idlewait")) { @@ -2261,7 +2336,7 @@ static bool patch_68k(void) D(bug("Searching for sound components with type sdev in ROM\n")); uint32 thing = find_rom_resource(FOURCC('t','h','n','g')); while (thing) { - thing += ROM_BASE; + thing += ROMBase; D(bug(" found %c%c%c%c %c%c%c%c\n", ReadMacInt8(thing), ReadMacInt8(thing + 1), ReadMacInt8(thing + 2), ReadMacInt8(thing + 3), ReadMacInt8(thing + 4), ReadMacInt8(thing + 5), ReadMacInt8(thing + 6), ReadMacInt8(thing + 7))); if (ReadMacInt32(thing) == FOURCC('s','d','e','v') && ReadMacInt32(thing + 4) == FOURCC('s','i','n','g')) { WriteMacInt32(thing + 4, FOURCC('a','w','g','c')); @@ -2306,25 +2381,29 @@ void InstallDrivers(void) SheepArray pb_var; const uintptr pb = pb_var.addr(); +#if DISABLE_SCSI + // Setup fake SCSI Globals + r.d[0] = 0x1000; + Execute68kTrap(0xa71e, &r); // NewPtrSysClear() + uint32 scsi_globals = r.a[0]; + D(bug("Fake SCSI globals at %08lx\n", scsi_globals)); + WriteMacInt32(0xc0c, scsi_globals); // Set SCSIGlobals +#endif + // Install floppy driver if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) { // Force installation of floppy driver with NewWorld and Gossamer ROMs - r.a[0] = ROM_BASE + sony_offset; + r.a[0] = ROMBase + sony_offset; r.d[0] = (uint32)SonyRefNum; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~SonyRefNum * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() uint32 dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset); WriteMacInt16(dce + dCtlFlags, SonyDriverFlags); } -#if DISABLE_SCSI && HAVE_SIGSEGV_SKIP_INSTRUCTION - // Fake SCSIGlobals - WriteMacInt32(0xc0c, SheepMem::ZeroPage()); -#endif - // Open .Sony driver SheepString sony_str("\005.Sony"); WriteMacInt8(pb + ioPermssn, 0); @@ -2333,13 +2412,13 @@ void InstallDrivers(void) Execute68kTrap(0xa000, &r); // Open() // Install disk driver - r.a[0] = ROM_BASE + sony_offset + 0x100; + r.a[0] = ROMBase + sony_offset + 0x100; r.d[0] = (uint32)DiskRefNum; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~DiskRefNum * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() uint32 dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x100); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x100); WriteMacInt16(dce + dCtlFlags, DiskDriverFlags); // Open disk driver @@ -2352,13 +2431,13 @@ void InstallDrivers(void) if (!PrefsFindBool("nocdrom")) { // Install CD-ROM driver - r.a[0] = ROM_BASE + sony_offset + 0x200; + r.a[0] = ROMBase + sony_offset + 0x200; r.d[0] = (uint32)CDROMRefNum; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~CDROMRefNum * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x200); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x200); WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags); // Open CD-ROM driver @@ -2369,39 +2448,39 @@ void InstallDrivers(void) } // Install serial drivers - r.a[0] = ROM_BASE + sony_offset + 0x300; + r.a[0] = ROMBase + sony_offset + 0x300; r.d[0] = (uint32)-6; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-6) * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x300); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x300); WriteMacInt16(dce + dCtlFlags, 0x4d00); - r.a[0] = ROM_BASE + sony_offset + 0x400; + r.a[0] = ROMBase + sony_offset + 0x400; r.d[0] = (uint32)-7; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-7) * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x400); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x400); WriteMacInt16(dce + dCtlFlags, 0x4e00); - r.a[0] = ROM_BASE + sony_offset + 0x500; + r.a[0] = ROMBase + sony_offset + 0x500; r.d[0] = (uint32)-8; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-8) * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x500); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x500); WriteMacInt16(dce + dCtlFlags, 0x4d00); - r.a[0] = ROM_BASE + sony_offset + 0x600; + r.a[0] = ROMBase + sony_offset + 0x600; r.d[0] = (uint32)-9; Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~(-9) * 4); // Get driver handle from Unit Table Execute68kTrap(0xa029, &r); // HLock() dce = ReadMacInt32(r.a[0]); - WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset + 0x600); + WriteMacInt32(dce + dCtlDriver, ROMBase + sony_offset + 0x600); WriteMacInt16(dce + dCtlFlags, 0x4e00); }