ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/rom_patches.cpp
(Generate patch)

Comparing SheepShaver/src/rom_patches.cpp (file contents):
Revision 1.4 by gbeauche, 2003-05-17T08:42:34Z vs.
Revision 1.10 by gbeauche, 2003-09-29T22:49:23Z

# Line 447 | Line 447 | static const uint8 cdrom_driver[] = {  //
447          0x4e, 0x75                                                      //  rts
448   };
449  
450 < #ifdef __linux__
450 > #if EMULATED_PPC
451 > #define SERIAL_TRAMPOLINES 1
452 > static uint32 serial_nothing_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_NOTHING)), 0};
453 > static uint32 serial_open_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_OPEN)), 0};
454 > static uint32 serial_prime_in_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_IN)), 0};
455 > static uint32 serial_prime_out_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_OUT)), 0};
456 > static uint32 serial_control_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_CONTROL)), 0};
457 > static uint32 serial_status_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_STATUS)), 0};
458 > static uint32 serial_close_tvect[2] = {tswap32(POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_CLOSE)), 0};
459 > #elif defined(__linux__)
460 > #define SERIAL_TRAMPOLINES 1
461   static uint32 serial_nothing_tvect[2] = {(uint32)SerialNothing, 0};
462   static uint32 serial_open_tvect[2] = {(uint32)SerialOpen, 0};
463   static uint32 serial_prime_in_tvect[2] = {(uint32)SerialPrimeIn, 0};
# Line 464 | Line 474 | static const uint32 ain_driver[] = {   //
474          0x00000000, 0x00000000,
475          0xaafe0700, 0x00000000,
476          0x00000000, 0x00179822,
477 < #ifdef __linux__
477 > #ifdef SERIAL_TRAMPOLINES
478          0x00010004, (uint32)serial_nothing_tvect,
479   #else
480          0x00010004, (uint32)SerialNothing,
# Line 472 | Line 482 | static const uint32 ain_driver[] = {   //
482          0x00000000, 0x00000000,
483          0xaafe0700, 0x00000000,
484          0x00000000, 0x00179822,
485 < #ifdef __linux__
485 > #ifdef SERIAL_TRAMPOLINES
486          0x00010004, (uint32)serial_prime_in_tvect,
487   #else
488          0x00010004, (uint32)SerialPrimeIn,
# Line 480 | Line 490 | static const uint32 ain_driver[] = {   //
490          0x00000000, 0x00000000,
491          0xaafe0700, 0x00000000,
492          0x00000000, 0x00179822,
493 < #ifdef __linux__
493 > #ifdef SERIAL_TRAMPOLINES
494          0x00010004, (uint32)serial_control_tvect,
495   #else
496          0x00010004, (uint32)SerialControl,
# Line 488 | Line 498 | static const uint32 ain_driver[] = {   //
498          0x00000000, 0x00000000,
499          0xaafe0700, 0x00000000,
500          0x00000000, 0x00179822,
501 < #ifdef __linux__
501 > #ifdef SERIAL_TRAMPOLINES
502          0x00010004, (uint32)serial_status_tvect,
503   #else
504          0x00010004, (uint32)SerialStatus,
# Line 496 | Line 506 | static const uint32 ain_driver[] = {   //
506          0x00000000, 0x00000000,
507          0xaafe0700, 0x00000000,
508          0x00000000, 0x00179822,
509 < #ifdef __linux__
509 > #ifdef SERIAL_TRAMPOLINES
510          0x00010004, (uint32)serial_nothing_tvect,
511   #else
512          0x00010004, (uint32)SerialNothing,
# Line 511 | Line 521 | static const uint32 aout_driver[] = {  //
521          0x00000000, 0x00000000,
522          0xaafe0700, 0x00000000,
523          0x00000000, 0x00179822,
524 < #ifdef __linux__
524 > #ifdef SERIAL_TRAMPOLINES
525          0x00010004, (uint32)serial_open_tvect,
526   #else
527          0x00010004, (uint32)SerialOpen,
# Line 519 | Line 529 | static const uint32 aout_driver[] = {  //
529          0x00000000, 0x00000000,
530          0xaafe0700, 0x00000000,
531          0x00000000, 0x00179822,
532 < #ifdef __linux__
532 > #ifdef SERIAL_TRAMPOLINES
533          0x00010004, (uint32)serial_prime_out_tvect,
534   #else
535          0x00010004, (uint32)SerialPrimeOut,
# Line 527 | Line 537 | static const uint32 aout_driver[] = {  //
537          0x00000000, 0x00000000,
538          0xaafe0700, 0x00000000,
539          0x00000000, 0x00179822,
540 < #ifdef __linux__
540 > #ifdef SERIAL_TRAMPOLINES
541          0x00010004, (uint32)serial_control_tvect,
542   #else
543          0x00010004, (uint32)SerialControl,
# Line 535 | Line 545 | static const uint32 aout_driver[] = {  //
545          0x00000000, 0x00000000,
546          0xaafe0700, 0x00000000,
547          0x00000000, 0x00179822,
548 < #ifdef __linux__
548 > #ifdef SERIAL_TRAMPOLINES
549          0x00010004, (uint32)serial_status_tvect,
550   #else
551          0x00010004, (uint32)SerialStatus,
# Line 543 | Line 553 | static const uint32 aout_driver[] = {  //
553          0x00000000, 0x00000000,
554          0xaafe0700, 0x00000000,
555          0x00000000, 0x00179822,
556 < #ifdef __linux__
556 > #ifdef SERIAL_TRAMPOLINES
557          0x00010004, (uint32)serial_close_tvect,
558   #else
559          0x00010004, (uint32)SerialClose,
# Line 558 | Line 568 | static const uint32 bin_driver[] = {   //
568          0x00000000, 0x00000000,
569          0xaafe0700, 0x00000000,
570          0x00000000, 0x00179822,
571 < #ifdef __linux__
571 > #ifdef SERIAL_TRAMPOLINES
572          0x00010004, (uint32)serial_nothing_tvect,
573   #else
574          0x00010004, (uint32)SerialNothing,
# Line 566 | Line 576 | static const uint32 bin_driver[] = {   //
576          0x00000000, 0x00000000,
577          0xaafe0700, 0x00000000,
578          0x00000000, 0x00179822,
579 < #ifdef __linux__
579 > #ifdef SERIAL_TRAMPOLINES
580          0x00010004, (uint32)serial_prime_in_tvect,
581   #else
582          0x00010004, (uint32)SerialPrimeIn,
# Line 574 | Line 584 | static const uint32 bin_driver[] = {   //
584          0x00000000, 0x00000000,
585          0xaafe0700, 0x00000000,
586          0x00000000, 0x00179822,
587 < #ifdef __linux__
587 > #ifdef SERIAL_TRAMPOLINES
588          0x00010004, (uint32)serial_control_tvect,
589   #else
590          0x00010004, (uint32)SerialControl,
# Line 582 | Line 592 | static const uint32 bin_driver[] = {   //
592          0x00000000, 0x00000000,
593          0xaafe0700, 0x00000000,
594          0x00000000, 0x00179822,
595 < #ifdef __linux__
595 > #ifdef SERIAL_TRAMPOLINES
596          0x00010004, (uint32)serial_status_tvect,
597   #else
598          0x00010004, (uint32)SerialStatus,
# Line 590 | Line 600 | static const uint32 bin_driver[] = {   //
600          0x00000000, 0x00000000,
601          0xaafe0700, 0x00000000,
602          0x00000000, 0x00179822,
603 < #ifdef __linux__
603 > #ifdef SERIAL_TRAMPOLINES
604          0x00010004, (uint32)serial_nothing_tvect,
605   #else
606          0x00010004, (uint32)SerialNothing,
# Line 605 | Line 615 | static const uint32 bout_driver[] = {  //
615          0x00000000, 0x00000000,
616          0xaafe0700, 0x00000000,
617          0x00000000, 0x00179822,
618 < #ifdef __linux__
618 > #ifdef SERIAL_TRAMPOLINES
619          0x00010004, (uint32)serial_open_tvect,
620   #else
621          0x00010004, (uint32)SerialOpen,
# Line 613 | Line 623 | static const uint32 bout_driver[] = {  //
623          0x00000000, 0x00000000,
624          0xaafe0700, 0x00000000,
625          0x00000000, 0x00179822,
626 < #ifdef __linux__
626 > #ifdef SERIAL_TRAMPOLINES
627          0x00010004, (uint32)serial_prime_out_tvect,
628   #else
629          0x00010004, (uint32)SerialPrimeOut,
# Line 621 | Line 631 | static const uint32 bout_driver[] = {  //
631          0x00000000, 0x00000000,
632          0xaafe0700, 0x00000000,
633          0x00000000, 0x00179822,
634 < #ifdef __linux__
634 > #ifdef SERIAL_TRAMPOLINES
635          0x00010004, (uint32)serial_control_tvect,
636   #else
637          0x00010004, (uint32)SerialControl,
# Line 629 | Line 639 | static const uint32 bout_driver[] = {  //
639          0x00000000, 0x00000000,
640          0xaafe0700, 0x00000000,
641          0x00000000, 0x00179822,
642 < #ifdef __linux__
642 > #ifdef SERIAL_TRAMPOLINES
643          0x00010004, (uint32)serial_status_tvect,
644   #else
645          0x00010004, (uint32)SerialStatus,
# Line 637 | Line 647 | static const uint32 bout_driver[] = {  //
647          0x00000000, 0x00000000,
648          0xaafe0700, 0x00000000,
649          0x00000000, 0x00179822,
650 < #ifdef __linux__
650 > #ifdef SERIAL_TRAMPOLINES
651          0x00010004, (uint32)serial_close_tvect,
652   #else
653          0x00010004, (uint32)SerialClose,
# Line 669 | Line 679 | static const uint8 adbop_patch[] = {   //
679  
680  
681   /*
682 + *  Copy PowerPC code to ROM image and reverse bytes if necessary
683 + */
684 +
685 + static inline void memcpy_powerpc_code(void *dst, const void *src, size_t len)
686 + {
687 + #ifdef WORDS_BIGENDIAN
688 +        (void)memcpy(dst, src, len);
689 + #else
690 +        uint32 *d = (uint32 *)dst;
691 +        uint32 *s = (uint32 *)src;
692 +        for (int i = 0; i < len/4; i++)
693 +                d[i] = htonl(s[i]);
694 + #endif
695 + }
696 +
697 +
698 + /*
699   *  Install ROM patches (RAMBase and KernelDataAddr must be set)
700   */
701  
# Line 1030 | Line 1057 | static bool patch_68k_emul(void)
1057          *lp = htonl(POWERPC_ILLEGAL);
1058  
1059   #if EMULATED_PPC
1060 <        // Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes
1060 >        // Install EMUL_RETURN, EXEC_RETURN, EXEC_NATIVE and EMUL_OP opcodes
1061          lp = (uint32 *)(ROM_BASE + 0x380000 + (M68K_EMUL_RETURN << 3));
1062          *lp++ = htonl(POWERPC_EMUL_OP);
1063          *lp++ = htonl(0x4bf66e80);                                                      // b    0x366084
1064          *lp++ = htonl(POWERPC_EMUL_OP | 1);
1065          *lp++ = htonl(0x4bf66e78);                                                      // b    0x366084
1066 +        *lp++ = htonl(POWERPC_EMUL_OP | 2);
1067 +        *lp++ = htonl(0x4bf66e70);                                                      // b    0x366084
1068          for (int i=0; i<OP_MAX; i++) {
1069 <                *lp++ = htonl(POWERPC_EMUL_OP | (i + 2));
1070 <                *lp++ = htonl(0x4bf66e70 - i*8);                        // b    0x366084
1069 >                *lp++ = htonl(POWERPC_EMUL_OP | (i + 3));
1070 >                *lp++ = htonl(0x4bf66e68 - i*8);                                // b    0x366084
1071          }
1072   #else
1073          // Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes
# Line 1047 | Line 1076 | static bool patch_68k_emul(void)
1076          *lp++ = htonl(0x4bf705fc);                                                      // b    0x36f800
1077          *lp++ = htonl(0x80000000 + XLM_EXEC_RETURN_PROC);       // lwz  r0,XLM_EXEC_RETURN_PROC
1078          *lp++ = htonl(0x4bf705f4);                                                      // b    0x36f800
1079 +        *lp++ = htonl(0x00dead00);                                                      // Let SheepShaver crash, since
1080 +        *lp++ = htonl(0x00beef00);                                                      // no native opcode is available
1081          for (int i=0; i<OP_MAX; i++) {
1082                  *lp++ = htonl(0x38a00000 + i);                          // li   r5,OP_*
1083 <                *lp++ = htonl(0x4bf705f4 - i*8);                        // b    0x36f808
1083 >                *lp++ = htonl(0x4bf705ec - i*8);                        // b    0x36f808
1084          }
1085  
1086          // Extra routines for EMUL_RETURN/EXEC_RETURN/EMUL_OP
# Line 1065 | Line 1096 | static bool patch_68k_emul(void)
1096          // Extra routine for 68k emulator start
1097          lp = (uint32 *)(ROM_BASE + 0x36f900);
1098          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1099 + #if EMULATED_PPC
1100 +        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1101 + #else
1102          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1103          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
1104          *lp++ = htonl(0x90200000 + XLM_IRQ_NEST);       // stw          r1,XLM_IRQ_NEST
1105 + #endif
1106          *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz              r1,XLM_KERNEL_DATA
1107          *lp++ = htonl(0x90c10018);                                      // stw          r6,0x18(r1)
1108          *lp++ = htonl(0x7cc902a6);                                      // mfctr        r6
# Line 1095 | Line 1130 | static bool patch_68k_emul(void)
1130          // Extra routine for Mixed Mode
1131          lp = (uint32 *)(ROM_BASE + 0x36fa00);
1132          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1133 + #if EMULATED_PPC
1134 +        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1135 + #else
1136          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1137          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
1138          *lp++ = htonl(0x90200000 + XLM_IRQ_NEST);       // stw          r1,XLM_IRQ_NEST
1139 + #endif
1140          *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz              r1,XLM_KERNEL_DATA
1141          *lp++ = htonl(0x90c10018);                                      // stw          r6,0x18(r1)
1142          *lp++ = htonl(0x7cc902a6);                                      // mfctr        r6
# Line 1125 | Line 1164 | static bool patch_68k_emul(void)
1164          // Extra routine for Reset/FC1E opcode
1165          lp = (uint32 *)(ROM_BASE + 0x36fb00);
1166          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1167 + #if EMULATED_PPC
1168 +        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1169 + #else
1170          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1171          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
1172          *lp++ = htonl(0x90200000 + XLM_IRQ_NEST);       // stw          r1,XLM_IRQ_NEST
1173 + #endif
1174          *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz              r1,XLM_KERNEL_DATA
1175          *lp++ = htonl(0x90c10018);                                      // stw          r6,0x18(r1)
1176          *lp++ = htonl(0x7cc902a6);                                      // mfctr        r6
# Line 1155 | Line 1198 | static bool patch_68k_emul(void)
1198          // Extra routine for FE0A opcode (QuickDraw 3D needs this)
1199          lp = (uint32 *)(ROM_BASE + 0x36fc00);
1200          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1201 + #if EMULATED_PPC
1202 +        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1203 + #else
1204          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1205          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
1206          *lp++ = htonl(0x90200000 + XLM_IRQ_NEST);       // stw          r1,XLM_IRQ_NEST
1207 + #endif
1208          *lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz              r1,XLM_KERNEL_DATA
1209          *lp++ = htonl(0x90c10018);                                      // stw          r6,0x18(r1)
1210          *lp++ = htonl(0x7cc902a6);                                      // mfctr        r6
# Line 1292 | Line 1339 | static bool patch_nanokernel(void)
1339          *lp = htonl(POWERPC_BCTR);
1340  
1341          lp = (uint32 *)(ROM_BASE + 0x318000);
1342 + #if EMULATED_PPC
1343 +        *lp++ = POWERPC_NATIVE_OP(NATIVE_ENABLE_INTERRUPT);
1344 +        *lp = htonl(0x48000000 + ((xlp - 0x8004) & 0x03fffffc));        // b            ROM_BASE+0x312c2c
1345 + #else
1346          *lp++ = htonl(0x81400000 + XLM_IRQ_NEST);       // lwz  r10,XLM_IRQ_NEST
1347          *lp++ = htonl(0x394affff);                                      // subi r10,r10,1
1348          *lp++ = htonl(0x91400000 + XLM_IRQ_NEST);       // stw  r10,XLM_IRQ_NEST
1349          *lp = htonl(0x48000000 + ((xlp - 0x800c) & 0x03fffffc));        // b            ROM_BASE+0x312c2c
1350 + #endif
1351 +
1352   /*
1353          // Disable FE0A/FE06 opcodes
1354          lp = (uint32 *)(ROM_BASE + 0x3144ac);
# Line 1930 | Line 1983 | static bool patch_68k(void)
1983          memcpy((void *)(ROM_BASE + sony_offset + 0x200), cdrom_driver, sizeof(cdrom_driver));
1984  
1985          // Install serial drivers
1986 <        memcpy((void *)(ROM_BASE + sony_offset + 0x300), ain_driver, sizeof(ain_driver));
1987 <        memcpy((void *)(ROM_BASE + sony_offset + 0x400), aout_driver, sizeof(aout_driver));
1988 <        memcpy((void *)(ROM_BASE + sony_offset + 0x500), bin_driver, sizeof(bin_driver));
1989 <        memcpy((void *)(ROM_BASE + sony_offset + 0x600), bout_driver, sizeof(bout_driver));
1986 >        memcpy_powerpc_code((void *)(ROM_BASE + sony_offset + 0x300), ain_driver, sizeof(ain_driver));
1987 >        memcpy_powerpc_code((void *)(ROM_BASE + sony_offset + 0x400), aout_driver, sizeof(aout_driver));
1988 >        memcpy_powerpc_code((void *)(ROM_BASE + sony_offset + 0x500), bin_driver, sizeof(bin_driver));
1989 >        memcpy_powerpc_code((void *)(ROM_BASE + sony_offset + 0x600), bout_driver, sizeof(bout_driver));
1990  
1991          // Copy icons to ROM
1992          SonyDiskIconAddr = ROM_BASE + sony_offset + 0x800;
# Line 2013 | Line 2066 | static bool patch_68k(void)
2066          wp = (uint16 *)(ROM_BASE + base);
2067          if (ROMType == ROMTYPE_ZANZIBAR)
2068                  *wp = htons(M68K_RTS);
2069 <        else
2069 >        else if (ntohs(wp[-4]) == 0x61ff)
2070 >                *wp = htons(M68K_RTS);
2071 >        else if (ntohs(wp[-2]) == 0x6700)
2072                  wp[-2] = htons(0x6000); // bra
2073  
2074          // Patch PowerOff()
# Line 2135 | Line 2190 | void InstallDrivers(void)
2190          M68kRegisters r;
2191          uint8 pb[SIZEOF_IOParam];
2192  
2193 +        // Install floppy driver
2194 +        if (ROMType == ROMTYPE_NEWWORLD) {
2195 +
2196 +                // Force installation of floppy driver with NewWorld ROMs
2197 +                r.a[0] = ROM_BASE + sony_offset;
2198 +                r.d[0] = (uint32)SonyRefNum;
2199 +                Execute68kTrap(0xa43d, &r);             // DrvrInstallRsrvMem()
2200 +                r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~SonyRefNum * 4);   // Get driver handle from Unit Table
2201 +                Execute68kTrap(0xa029, &r);             // HLock()
2202 +                uint32 dce = ReadMacInt32(r.a[0]);
2203 +                WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset);
2204 +                WriteMacInt16(dce + dCtlFlags, SonyDriverFlags);
2205 +        }
2206 +
2207 + #if DISABLE_SCSI && 0
2208 +        // Fake SCSIGlobals
2209 +        static const uint8 fake_scsi_globals[32] = {0,};
2210 +        WriteMacInt32(0xc0c, (uint32)fake_scsi_globals);
2211 + #endif
2212 +
2213          // Open .Sony driver
2214          WriteMacInt8((uint32)pb + ioPermssn, 0);
2215          WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\005.Sony");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines