--- BasiliskII/src/rom_patches.cpp 1999/10/22 15:08:12 1.7 +++ BasiliskII/src/rom_patches.cpp 2000/04/10 18:52:26 1.13 @@ -1,7 +1,7 @@ /* * rom_patches.cpp - ROM patches * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2000 Christian Bauer * * 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 @@ -38,18 +38,15 @@ #include "debug.h" -// Breakpoint -//#define M68K_BREAKPOINT 0x2310 // CritError -//#define M68K_BREAKPOINT 0x1d10 // BootMe - // Global variables -uint32 UniversalInfo; // ROM offset of UniversalInfo -uint32 PutScrapPatch; // Mac address of PutScrap() patch +uint32 UniversalInfo; // ROM offset of UniversalInfo +uint32 PutScrapPatch; // Mac address of PutScrap() patch +uint32 ROMBreakpoint = 0; // ROM offset of breakpoint (0 = disabled, 0x2310 = CritError) +bool PrintROMInfo = false; // Flag: print ROM information in PatchROM() static uint32 sony_offset; // ROM offset of .Sony driver static uint32 serd_offset; // ROM offset of SERD resource (serial drivers) static uint32 microseconds_offset; // ROM offset of Microseconds() replacement routine -static uint32 memory_dispatch_offset; // ROM offset of MemoryDispatch() replacement routine // Prototypes uint16 ROMVersion; @@ -84,6 +81,8 @@ static uint32 find_rom_resource(uint32 s if (!cont) rsrc_ptr = x; + else + rsrc_ptr = ReadMacInt32(ROMBaseMac + rsrc_ptr + 8); for (;;) { lp = ROMBaseMac + rsrc_ptr; @@ -142,6 +141,161 @@ again: /* + * Print ROM information to stream, + */ + +static void list_rom_resources(void) +{ + printf("ROM Resources:\n"); + printf("Offset\t Type\tID\tSize\tName\n"); + printf("------------------------------------------------\n"); + + uint32 lp = ROMBaseMac + ReadMacInt32(ROMBaseMac + 0x1a); + uint32 rsrc_ptr = ReadMacInt32(lp); + + for (;;) { + lp = ROMBaseMac + rsrc_ptr; + uint32 data = ReadMacInt32(lp + 12); + + char name[32]; + int name_len = ReadMacInt8(lp + 23), i; + for (i=0; i= 0; i++) + if (MacDesc[i].id == id + 6) { + name = MacDesc[i].name; + break; + } + + printf("%08x %02x\t%04x\t%04x\t%s\n", info - ROMBaseMac, id, hwcfg, rom85, name); +} + +static void list_universal_infos(void) +{ + uint32 ofs = 0x3000; + for (int i=0; i<0x2000; i+=2, ofs+=2) + if (ReadMacInt32(ROMBaseMac + ofs) == 0xdc000505) { + ofs -= 16; + uint32 q; + for (q=ofs; q > 0 && ReadMacInt32(ROMBaseMac + q) != ofs - q; q-=4) ; + if (q > 0) { + printf("Universal Table at %08x:\n", q); + printf("Offset\t ID\tHWCfg\tROM85\tModel\n"); + printf("------------------------------------------------\n"); + while (ofs = ReadMacInt32(ROMBaseMac + q)) { + print_universal_info(ROMBaseMac + ofs + q); + q += 4; + } + } + break; + } + printf("\n"); +} + +static void print_rom_info(void) +{ + printf("\nROM Info:\n"); + printf("Checksum : %08x\n", ReadMacInt32(ROMBaseMac)); + printf("Version : %04x\n", ROMVersion); + printf("Sub Version : %04x\n", ReadMacInt16(ROMBaseMac + 18)); + printf("Resource Map: %08x\n", ReadMacInt32(ROMBaseMac + 26)); + printf("Trap Tables : %08x\n\n", ReadMacInt32(ROMBaseMac + 34)); + if (ROMVersion == ROM_VERSION_32) { + list_rom_resources(); + list_universal_infos(); + } +} + + +/* * Driver stubs */ @@ -642,12 +796,6 @@ void InstallSERD(void) void PatchAfterStartup(void) { - // Install MemoryDispatch() replacement routine - M68kRegisters r; - r.a[0] = ROMBaseMac + memory_dispatch_offset; - r.d[0] = 0xa05c; - Execute68kTrap(0xa247, &r); // SetOSTrapAddress() - #if SUPPORTS_EXTFS // Install external file system InstallExtFS(); @@ -1157,13 +1305,20 @@ static bool patch_rom_32(void) *wp++ = htons(M68K_NOP); *wp = htons(M68K_NOP); - // Fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) - static const uint8 fix_memsize_dat[] = {0x4e, 0x75}; - if ((base = find_rom_data(0x490, 0x4b0, fix_memsize_dat, sizeof(fix_memsize_dat))) == 0) return false; - D(bug("fix_memsize %08lx\n", base)); - wp = (uint16 *)(ROMBaseHost + base); + // Compute boot stack pointer and fix logical/physical RAM size (CompBootStack) (must be done after InitMemMgr!) + wp = (uint16 *)(ROMBaseHost + 0x490); + *wp++ = htons(0x2038); // move.l $10c,d0 + *wp++ = htons(0x010c); + *wp++ = htons(0xd0b8); // add.l $2a6,d0 + *wp++ = htons(0x02a6); + *wp++ = htons(0xe288); // lsr.l #1,d0 + *wp++ = htons(0x0880); // bclr #0,d0 + *wp++ = htons(0x0000); + *wp++ = htons(0x0440); // subi.w #$400,d0 + *wp++ = htons(0x0400); + *wp++ = htons(0x2040); // move.l d0,a0 *wp++ = htons(M68K_EMUL_OP_FIX_MEMSIZE); - *wp = htons(M68K_RTS); + *wp++ = htons(M68K_RTS); static const uint8 fix_memsize2_dat[] = {0x22, 0x30, 0x81, 0xe2, 0x0d, 0xdc, 0xff, 0xba, 0xd2, 0xb0, 0x81, 0xe2, 0x0d, 0xdc, 0xff, 0xec, 0x21, 0xc1, 0x1e, 0xf8}; base = find_rom_data(0x4c000, 0x4c080, fix_memsize2_dat, sizeof(fix_memsize2_dat)); @@ -1296,6 +1451,15 @@ static bool patch_rom_32(void) } } + // Don't set MemoryDispatch() to unimplemented trap + static const uint8 memdisp_dat[] = {0x30, 0x3c, 0xa8, 0x9f, 0xa7, 0x46, 0x30, 0x3c, 0xa0, 0x5c, 0xa2, 0x47}; + base = find_rom_data(0x4f100, 0x4f180, memdisp_dat, sizeof(memdisp_dat)); + D(bug("memdisp %08lx\n", base)); + if (base) { // ROM15/22/23/26/27/32 + wp = (uint16 *)(ROMBaseHost + base + 10); + *wp = htons(M68K_NOP); + } + // Patch .EDisk driver (don't scan for EDisks in the area ROMBase..0xe00000) uint32 edisk_offset = find_rom_resource('DRVR', 51); if (edisk_offset) { @@ -1397,12 +1561,6 @@ static bool patch_rom_32(void) *wp++ = htons(base >> 16); *wp = htons(base & 0xffff); - // Install MemoryDispatch() replacement routine (activated in PatchAfterStartup()) - memory_dispatch_offset = sony_offset + 0xc20; - wp = (uint16 *)(ROMBaseHost + memory_dispatch_offset); - *wp++ = htons(M68K_EMUL_OP_MEMORY_DISPATCH); - *wp = htons(M68K_RTS); - #if EMULATED_68K // Replace BlockMove() wp = (uint16 *)(ROMBaseHost + find_rom_trap(0xa02e)); // BlockMove() @@ -1411,6 +1569,11 @@ static bool patch_rom_32(void) *wp = htons(M68K_RTS); #endif + // Look for double PACK 4 resources + if ((base = find_rom_resource('PACK', 4)) == 0) return false; + if ((base = find_rom_resource('PACK', 4, true)) == 0 && FPUType == 0) + printf("WARNING: This ROM seems to require an FPU\n"); + // Patch VIA interrupt handler wp = (uint16 *)(ROMBaseHost + 0x9bc4); // Level 1 handler *wp++ = htons(0x7002); // moveq #2,d0 (always 60Hz interrupt) @@ -1428,11 +1591,9 @@ static bool patch_rom_32(void) bool PatchROM(void) { - // Print ROM info - D(bug("ROM Info:\n")); - D(bug("Checksum: %08lx\n", ReadMacInt32(ROMBaseMac))); - D(bug("Version: %04x\n", ROMVersion)); - D(bug("Sub Version: %04x\n", ReadMacInt16(ROMBaseMac + 18))); + // Print some information about the ROM + if (PrintROMInfo) + print_rom_info(); // Patch ROM depending on version switch (ROMVersion) { @@ -1448,11 +1609,11 @@ bool PatchROM(void) return false; } -#ifdef M68K_BREAKPOINT // Install breakpoint - uint16 *wp = (uint16 *)(ROMBaseHost + M68K_BREAKPOINT); - *wp = htons(M68K_EMUL_BREAK); -#endif + if (ROMBreakpoint) { + uint16 *wp = (uint16 *)(ROMBaseHost + ROMBreakpoint); + *wp = htons(M68K_EMUL_BREAK); + } // Clear caches as we loaded and patched code FlushCodeCache(ROMBaseHost, ROMSize);