--- SheepShaver/src/rom_patches.cpp 2003/05/14 22:11:59 1.3 +++ SheepShaver/src/rom_patches.cpp 2003/09/28 21:27:33 1.8 @@ -447,7 +447,17 @@ static const uint8 cdrom_driver[] = { // 0x4e, 0x75 // rts }; -#ifdef __linux__ +#if EMULATED_PPC +#define SERIAL_TRAMPOLINES 1 +static uint32 serial_nothing_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_NOTHING), 0}; +static uint32 serial_open_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_OPEN), 0}; +static uint32 serial_prime_in_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_IN), 0}; +static uint32 serial_prime_out_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_OUT), 0}; +static uint32 serial_control_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_CONTROL), 0}; +static uint32 serial_status_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_STATUS), 0}; +static uint32 serial_close_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_CLOSE), 0}; +#elif defined(__linux__) +#define SERIAL_TRAMPOLINES 1 static uint32 serial_nothing_tvect[2] = {(uint32)SerialNothing, 0}; static uint32 serial_open_tvect[2] = {(uint32)SerialOpen, 0}; static uint32 serial_prime_in_tvect[2] = {(uint32)SerialPrimeIn, 0}; @@ -464,7 +474,7 @@ static const uint32 ain_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_nothing_tvect, #else 0x00010004, (uint32)SerialNothing, @@ -472,7 +482,7 @@ static const uint32 ain_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_prime_in_tvect, #else 0x00010004, (uint32)SerialPrimeIn, @@ -480,7 +490,7 @@ static const uint32 ain_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_control_tvect, #else 0x00010004, (uint32)SerialControl, @@ -488,7 +498,7 @@ static const uint32 ain_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_status_tvect, #else 0x00010004, (uint32)SerialStatus, @@ -496,7 +506,7 @@ static const uint32 ain_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_nothing_tvect, #else 0x00010004, (uint32)SerialNothing, @@ -511,7 +521,7 @@ static const uint32 aout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_open_tvect, #else 0x00010004, (uint32)SerialOpen, @@ -519,7 +529,7 @@ static const uint32 aout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_prime_out_tvect, #else 0x00010004, (uint32)SerialPrimeOut, @@ -527,7 +537,7 @@ static const uint32 aout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_control_tvect, #else 0x00010004, (uint32)SerialControl, @@ -535,7 +545,7 @@ static const uint32 aout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_status_tvect, #else 0x00010004, (uint32)SerialStatus, @@ -543,7 +553,7 @@ static const uint32 aout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_close_tvect, #else 0x00010004, (uint32)SerialClose, @@ -558,7 +568,7 @@ static const uint32 bin_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_nothing_tvect, #else 0x00010004, (uint32)SerialNothing, @@ -566,7 +576,7 @@ static const uint32 bin_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_prime_in_tvect, #else 0x00010004, (uint32)SerialPrimeIn, @@ -574,7 +584,7 @@ static const uint32 bin_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_control_tvect, #else 0x00010004, (uint32)SerialControl, @@ -582,7 +592,7 @@ static const uint32 bin_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_status_tvect, #else 0x00010004, (uint32)SerialStatus, @@ -590,7 +600,7 @@ static const uint32 bin_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_nothing_tvect, #else 0x00010004, (uint32)SerialNothing, @@ -605,7 +615,7 @@ static const uint32 bout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_open_tvect, #else 0x00010004, (uint32)SerialOpen, @@ -613,7 +623,7 @@ static const uint32 bout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_prime_out_tvect, #else 0x00010004, (uint32)SerialPrimeOut, @@ -621,7 +631,7 @@ static const uint32 bout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_control_tvect, #else 0x00010004, (uint32)SerialControl, @@ -629,7 +639,7 @@ static const uint32 bout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_status_tvect, #else 0x00010004, (uint32)SerialStatus, @@ -637,7 +647,7 @@ static const uint32 bout_driver[] = { // 0x00000000, 0x00000000, 0xaafe0700, 0x00000000, 0x00000000, 0x00179822, -#ifdef __linux__ +#ifdef SERIAL_TRAMPOLINES 0x00010004, (uint32)serial_close_tvect, #else 0x00010004, (uint32)SerialClose, @@ -915,6 +925,9 @@ static bool patch_nanokernel_boot(void) lp = (uint32 *)(ROM_BASE + 0x3131f4); if (ntohl(*lp) == 0x7e5f42a6) // NewWorld ROM *lp = htonl(0x82400000 + XLM_PVR); // lwz r18,(theoretical PVR) + lp = (uint32 *)(ROM_BASE + 0x314600); + if (ntohl(*lp) == 0x7d3f42a6) + *lp = htonl(0x81200000 + XLM_PVR); // lzw r9,(theoritical PVR) // Don't read SDR1 static const uint32 sdr1_ofs[] = {0x174, 0x174, 0x174, 0x17c, 0x19c}; @@ -1027,15 +1040,17 @@ static bool patch_68k_emul(void) *lp = htonl(POWERPC_ILLEGAL); #if EMULATED_PPC - // Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes + // Install EMUL_RETURN, EXEC_RETURN, EXEC_NATIVE and EMUL_OP opcodes lp = (uint32 *)(ROM_BASE + 0x380000 + (M68K_EMUL_RETURN << 3)); *lp++ = htonl(POWERPC_EMUL_OP); *lp++ = htonl(0x4bf66e80); // b 0x366084 *lp++ = htonl(POWERPC_EMUL_OP | 1); *lp++ = htonl(0x4bf66e78); // b 0x366084 + *lp++ = htonl(POWERPC_EMUL_OP | 2); + *lp++ = htonl(0x4bf66e70); // b 0x366084 for (int i=0; i> 2] = htonl(ADDR_MAP_PATCH_SPACE - (base - 0x14)); @@ -1716,14 +1755,14 @@ static bool patch_68k(void) // Patch GetCPUSpeed (via 0x27a) (some ROMs have two of them) static const uint8 cpu_speed_dat[] = {0x20, 0x30, 0x81, 0xf2, 0x5f, 0xff, 0xef, 0xd8, 0x00, 0x04, 0x4c, 0x7c}; - if ((base = find_rom_data(0x6000, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; + if ((base = find_rom_data(0x6000, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; D(bug("cpu_speed %08lx\n", base)); wp = (uint16 *)(ROM_BASE + base); *wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 *wp++ = htons(CPUClockSpeed / 1000000); *wp++ = htons(CPUClockSpeed / 1000000); *wp = htons(M68K_RTS); - if ((base = find_rom_data(base, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { + if ((base = find_rom_data(base, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { D(bug("cpu_speed2 %08lx\n", base)); wp = (uint16 *)(ROM_BASE + base); *wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 @@ -2010,7 +2049,9 @@ static bool patch_68k(void) wp = (uint16 *)(ROM_BASE + base); if (ROMType == ROMTYPE_ZANZIBAR) *wp = htons(M68K_RTS); - else + else if (ntohs(wp[-4]) == 0x61ff) + *wp = htons(M68K_RTS); + else if (ntohs(wp[-2]) == 0x6700) wp[-2] = htons(0x6000); // bra // Patch PowerOff() @@ -2040,7 +2081,7 @@ static bool patch_68k(void) if (ROMType == ROMTYPE_NEWWORLD) { static const uint8 via_int3_dat[] = {0x48, 0xe7, 0xf0, 0xf0, 0x76, 0x01, 0x60, 0x26}; - if ((base = find_rom_data(0x15000, 0x18000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; + if ((base = find_rom_data(0x15000, 0x19000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; D(bug("via_int3 %08lx\n", base)); wp = (uint16 *)(ROM_BASE + base); // CHRP level 1 handler *wp++ = htons(M68K_JMP); @@ -2132,6 +2173,26 @@ void InstallDrivers(void) M68kRegisters r; uint8 pb[SIZEOF_IOParam]; + // Install floppy driver + if (ROMType == ROMTYPE_NEWWORLD) { + + // Force installation of floppy driver with NewWorld ROMs + r.a[0] = ROM_BASE + 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); + WriteMacInt16(dce + dCtlFlags, SonyDriverFlags); + } + +#if DISABLE_SCSI && 0 + // Fake SCSIGlobals + static const uint8 fake_scsi_globals[32] = {0,}; + WriteMacInt32(0xc0c, (uint32)fake_scsi_globals); +#endif + // Open .Sony driver WriteMacInt8((uint32)pb + ioPermssn, 0); WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\005.Sony");