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.8 by gbeauche, 2003-09-28T21:27:33Z vs.
Revision 1.19 by gbeauche, 2003-12-05T12:37:14Z

# Line 40 | Line 40
40   #include "audio_defs.h"
41   #include "serial.h"
42   #include "macos_util.h"
43 + #include "thunks.h"
44  
45   #define DEBUG 0
46   #include "debug.h"
# Line 58 | Line 59
59  
60  
61   // Other ROM addresses
62 < const uint32 CHECK_LOAD_PATCH_SPACE = 0x2f7f00;
63 < const uint32 PUT_SCRAP_PATCH_SPACE = 0x2f7f80;
64 < const uint32 GET_SCRAP_PATCH_SPACE = 0x2f7fc0;
65 < const uint32 ADDR_MAP_PATCH_SPACE = 0x2f8000;
62 > const uint32 CHECK_LOAD_PATCH_SPACE = 0x2fcf00;
63 > const uint32 PUT_SCRAP_PATCH_SPACE = 0x2fcf80;
64 > const uint32 GET_SCRAP_PATCH_SPACE = 0x2fcfc0;
65 > const uint32 ADDR_MAP_PATCH_SPACE = 0x2fd000;
66  
67   // Global variables
68   int ROMType;                            // ROM type
# Line 131 | Line 132 | void decode_parcels(const uint8 *src, ui
132                            (parcel_type >> 8) & 0xff, parcel_type & 0xff, &parcel_data[6]));
133                  if (parcel_type == FOURCC('r','o','m',' ')) {
134                          uint32 lzss_offset  = ntohl(parcel_data[2]);
135 <                        uint32 lzss_size = ((uint32)src + parcel_offset) - ((uint32)parcel_data + lzss_offset);
135 >                        uint32 lzss_size = ((uintptr)src + next_offset) - ((uintptr)parcel_data + lzss_offset);
136                          decode_lzss((uint8 *)parcel_data + lzss_offset, dest, lzss_size);
137                  }
138                  parcel_offset = next_offset;
# Line 447 | Line 448 | static const uint8 cdrom_driver[] = {  //
448          0x4e, 0x75                                                      //  rts
449   };
450  
451 < #if EMULATED_PPC
451 < #define SERIAL_TRAMPOLINES 1
452 < static uint32 serial_nothing_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_NOTHING), 0};
453 < static uint32 serial_open_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_OPEN), 0};
454 < static uint32 serial_prime_in_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_IN), 0};
455 < static uint32 serial_prime_out_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_PRIME_OUT), 0};
456 < static uint32 serial_control_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_CONTROL), 0};
457 < static uint32 serial_status_tvect[2] = {POWERPC_NATIVE_OP_FUNC(NATIVE_SERIAL_STATUS), 0};
458 < static uint32 serial_close_tvect[2] = {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};
464 < static uint32 serial_prime_out_tvect[2] = {(uint32)SerialPrimeOut, 0};
465 < static uint32 serial_control_tvect[2] = {(uint32)SerialControl, 0};
466 < static uint32 serial_status_tvect[2] = {(uint32)SerialStatus, 0};
467 < static uint32 serial_close_tvect[2] = {(uint32)SerialClose, 0};
468 < #endif
451 > static uint32 long_ptr;
452  
453 < static const uint32 ain_driver[] = {    // .AIn driver header
454 <        0x4d000000, 0x00000000,
455 <        0x00200040, 0x00600080,
456 <        0x00a0042e, 0x41496e00,
457 <        0x00000000, 0x00000000,
458 <        0xaafe0700, 0x00000000,
459 <        0x00000000, 0x00179822,
460 < #ifdef SERIAL_TRAMPOLINES
461 <        0x00010004, (uint32)serial_nothing_tvect,
462 < #else
463 <        0x00010004, (uint32)SerialNothing,
464 < #endif
465 <        0x00000000, 0x00000000,
466 <        0xaafe0700, 0x00000000,
467 <        0x00000000, 0x00179822,
468 < #ifdef SERIAL_TRAMPOLINES
469 <        0x00010004, (uint32)serial_prime_in_tvect,
470 < #else
471 <        0x00010004, (uint32)SerialPrimeIn,
472 < #endif
473 <        0x00000000, 0x00000000,
474 <        0xaafe0700, 0x00000000,
475 <        0x00000000, 0x00179822,
476 < #ifdef SERIAL_TRAMPOLINES
477 <        0x00010004, (uint32)serial_control_tvect,
478 < #else
479 <        0x00010004, (uint32)SerialControl,
480 < #endif
481 <        0x00000000, 0x00000000,
482 <        0xaafe0700, 0x00000000,
483 <        0x00000000, 0x00179822,
484 < #ifdef SERIAL_TRAMPOLINES
485 <        0x00010004, (uint32)serial_status_tvect,
486 < #else
487 <        0x00010004, (uint32)SerialStatus,
488 < #endif
489 <        0x00000000, 0x00000000,
490 <        0xaafe0700, 0x00000000,
491 <        0x00000000, 0x00179822,
492 < #ifdef SERIAL_TRAMPOLINES
510 <        0x00010004, (uint32)serial_nothing_tvect,
511 < #else
512 <        0x00010004, (uint32)SerialNothing,
513 < #endif
514 <        0x00000000, 0x00000000,
453 > static void SetLongBase(uint32 addr)
454 > {
455 >        long_ptr = addr;
456 > }
457 >
458 > static void Long(uint32 value)
459 > {
460 >        WriteMacInt32(long_ptr, value);
461 >        long_ptr += 4;
462 > }
463 >
464 > static void gen_ain_driver(uintptr addr)
465 > {
466 >        SetLongBase(addr);
467 >
468 >        // .AIn driver header
469 >        Long(0x4d000000); Long(0x00000000);
470 >        Long(0x00200040); Long(0x00600080);
471 >        Long(0x00a0042e); Long(0x41496e00);
472 >        Long(0x00000000); Long(0x00000000);
473 >        Long(0xaafe0700); Long(0x00000000);
474 >        Long(0x00000000); Long(0x00179822);
475 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_NOTHING));
476 >        Long(0x00000000); Long(0x00000000);
477 >        Long(0xaafe0700); Long(0x00000000);
478 >        Long(0x00000000); Long(0x00179822);
479 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_PRIME_IN));
480 >        Long(0x00000000); Long(0x00000000);
481 >        Long(0xaafe0700); Long(0x00000000);
482 >        Long(0x00000000); Long(0x00179822);
483 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CONTROL));
484 >        Long(0x00000000); Long(0x00000000);
485 >        Long(0xaafe0700); Long(0x00000000);
486 >        Long(0x00000000); Long(0x00179822);
487 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_STATUS));
488 >        Long(0x00000000); Long(0x00000000);
489 >        Long(0xaafe0700); Long(0x00000000);
490 >        Long(0x00000000); Long(0x00179822);
491 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_NOTHING));
492 >        Long(0x00000000); Long(0x00000000);
493   };
494  
495 < static const uint32 aout_driver[] = {   // .AOut driver header
496 <        0x4d000000, 0x00000000,
497 <        0x00200040, 0x00600080,
498 <        0x00a0052e, 0x414f7574,
499 <        0x00000000, 0x00000000,
500 <        0xaafe0700, 0x00000000,
501 <        0x00000000, 0x00179822,
502 < #ifdef SERIAL_TRAMPOLINES
503 <        0x00010004, (uint32)serial_open_tvect,
504 < #else
505 <        0x00010004, (uint32)SerialOpen,
506 < #endif
507 <        0x00000000, 0x00000000,
508 <        0xaafe0700, 0x00000000,
509 <        0x00000000, 0x00179822,
510 < #ifdef SERIAL_TRAMPOLINES
511 <        0x00010004, (uint32)serial_prime_out_tvect,
512 < #else
513 <        0x00010004, (uint32)SerialPrimeOut,
514 < #endif
515 <        0x00000000, 0x00000000,
516 <        0xaafe0700, 0x00000000,
517 <        0x00000000, 0x00179822,
518 < #ifdef SERIAL_TRAMPOLINES
519 <        0x00010004, (uint32)serial_control_tvect,
520 < #else
521 <        0x00010004, (uint32)SerialControl,
522 < #endif
523 <        0x00000000, 0x00000000,
546 <        0xaafe0700, 0x00000000,
547 <        0x00000000, 0x00179822,
548 < #ifdef SERIAL_TRAMPOLINES
549 <        0x00010004, (uint32)serial_status_tvect,
550 < #else
551 <        0x00010004, (uint32)SerialStatus,
552 < #endif
553 <        0x00000000, 0x00000000,
554 <        0xaafe0700, 0x00000000,
555 <        0x00000000, 0x00179822,
556 < #ifdef SERIAL_TRAMPOLINES
557 <        0x00010004, (uint32)serial_close_tvect,
558 < #else
559 <        0x00010004, (uint32)SerialClose,
560 < #endif
561 <        0x00000000, 0x00000000,
495 > static void gen_aout_driver(uintptr addr)
496 > {
497 >        SetLongBase(addr);
498 >
499 >        // .AOut driver header
500 >        Long(0x4d000000); Long(0x00000000);
501 >        Long(0x00200040); Long(0x00600080);
502 >        Long(0x00a0052e); Long(0x414f7574);
503 >        Long(0x00000000); Long(0x00000000);
504 >        Long(0xaafe0700); Long(0x00000000);
505 >        Long(0x00000000); Long(0x00179822);
506 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_OPEN));
507 >        Long(0x00000000); Long(0x00000000);
508 >        Long(0xaafe0700); Long(0x00000000);
509 >        Long(0x00000000); Long(0x00179822);
510 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_PRIME_OUT));
511 >        Long(0x00000000); Long(0x00000000);
512 >        Long(0xaafe0700); Long(0x00000000);
513 >        Long(0x00000000); Long(0x00179822);
514 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CONTROL));
515 >        Long(0x00000000); Long(0x00000000);
516 >        Long(0xaafe0700); Long(0x00000000);
517 >        Long(0x00000000); Long(0x00179822);
518 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_STATUS));
519 >        Long(0x00000000); Long(0x00000000);
520 >        Long(0xaafe0700); Long(0x00000000);
521 >        Long(0x00000000); Long(0x00179822);
522 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CLOSE));
523 >        Long(0x00000000); Long(0x00000000);
524   };
525  
526 < static const uint32 bin_driver[] = {    // .BIn driver header
527 <        0x4d000000, 0x00000000,
528 <        0x00200040, 0x00600080,
529 <        0x00a0042e, 0x42496e00,
530 <        0x00000000, 0x00000000,
531 <        0xaafe0700, 0x00000000,
532 <        0x00000000, 0x00179822,
533 < #ifdef SERIAL_TRAMPOLINES
534 <        0x00010004, (uint32)serial_nothing_tvect,
535 < #else
536 <        0x00010004, (uint32)SerialNothing,
537 < #endif
538 <        0x00000000, 0x00000000,
539 <        0xaafe0700, 0x00000000,
540 <        0x00000000, 0x00179822,
541 < #ifdef SERIAL_TRAMPOLINES
542 <        0x00010004, (uint32)serial_prime_in_tvect,
543 < #else
544 <        0x00010004, (uint32)SerialPrimeIn,
545 < #endif
546 <        0x00000000, 0x00000000,
547 <        0xaafe0700, 0x00000000,
548 <        0x00000000, 0x00179822,
549 < #ifdef SERIAL_TRAMPOLINES
550 <        0x00010004, (uint32)serial_control_tvect,
551 < #else
552 <        0x00010004, (uint32)SerialControl,
553 < #endif
554 <        0x00000000, 0x00000000,
593 <        0xaafe0700, 0x00000000,
594 <        0x00000000, 0x00179822,
595 < #ifdef SERIAL_TRAMPOLINES
596 <        0x00010004, (uint32)serial_status_tvect,
597 < #else
598 <        0x00010004, (uint32)SerialStatus,
599 < #endif
600 <        0x00000000, 0x00000000,
601 <        0xaafe0700, 0x00000000,
602 <        0x00000000, 0x00179822,
603 < #ifdef SERIAL_TRAMPOLINES
604 <        0x00010004, (uint32)serial_nothing_tvect,
605 < #else
606 <        0x00010004, (uint32)SerialNothing,
607 < #endif
608 <        0x00000000, 0x00000000,
526 > static void gen_bin_driver(uintptr addr)
527 > {
528 >        SetLongBase(addr);
529 >
530 >        // .BIn driver header
531 >        Long(0x4d000000); Long(0x00000000);
532 >        Long(0x00200040); Long(0x00600080);
533 >        Long(0x00a0042e); Long(0x42496e00);
534 >        Long(0x00000000); Long(0x00000000);
535 >        Long(0xaafe0700); Long(0x00000000);
536 >        Long(0x00000000); Long(0x00179822);
537 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_NOTHING));
538 >        Long(0x00000000); Long(0x00000000);
539 >        Long(0xaafe0700); Long(0x00000000);
540 >        Long(0x00000000); Long(0x00179822);
541 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_PRIME_IN));
542 >        Long(0x00000000); Long(0x00000000);
543 >        Long(0xaafe0700); Long(0x00000000);
544 >        Long(0x00000000); Long(0x00179822);
545 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CONTROL));
546 >        Long(0x00000000); Long(0x00000000);
547 >        Long(0xaafe0700); Long(0x00000000);
548 >        Long(0x00000000); Long(0x00179822);
549 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_STATUS));
550 >        Long(0x00000000); Long(0x00000000);
551 >        Long(0xaafe0700); Long(0x00000000);
552 >        Long(0x00000000); Long(0x00179822);
553 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_NOTHING));
554 >        Long(0x00000000); Long(0x00000000);
555   };
556  
557 < static const uint32 bout_driver[] = {   // .BOut driver header
558 <        0x4d000000, 0x00000000,
559 <        0x00200040, 0x00600080,
560 <        0x00a0052e, 0x424f7574,
561 <        0x00000000, 0x00000000,
562 <        0xaafe0700, 0x00000000,
563 <        0x00000000, 0x00179822,
564 < #ifdef SERIAL_TRAMPOLINES
565 <        0x00010004, (uint32)serial_open_tvect,
566 < #else
567 <        0x00010004, (uint32)SerialOpen,
568 < #endif
569 <        0x00000000, 0x00000000,
570 <        0xaafe0700, 0x00000000,
571 <        0x00000000, 0x00179822,
572 < #ifdef SERIAL_TRAMPOLINES
573 <        0x00010004, (uint32)serial_prime_out_tvect,
574 < #else
575 <        0x00010004, (uint32)SerialPrimeOut,
576 < #endif
577 <        0x00000000, 0x00000000,
578 <        0xaafe0700, 0x00000000,
579 <        0x00000000, 0x00179822,
580 < #ifdef SERIAL_TRAMPOLINES
581 <        0x00010004, (uint32)serial_control_tvect,
582 < #else
583 <        0x00010004, (uint32)SerialControl,
584 < #endif
585 <        0x00000000, 0x00000000,
640 <        0xaafe0700, 0x00000000,
641 <        0x00000000, 0x00179822,
642 < #ifdef SERIAL_TRAMPOLINES
643 <        0x00010004, (uint32)serial_status_tvect,
644 < #else
645 <        0x00010004, (uint32)SerialStatus,
646 < #endif
647 <        0x00000000, 0x00000000,
648 <        0xaafe0700, 0x00000000,
649 <        0x00000000, 0x00179822,
650 < #ifdef SERIAL_TRAMPOLINES
651 <        0x00010004, (uint32)serial_close_tvect,
652 < #else
653 <        0x00010004, (uint32)SerialClose,
654 < #endif
655 <        0x00000000, 0x00000000,
557 > static void gen_bout_driver(uintptr addr)
558 > {
559 >        SetLongBase(addr);
560 >
561 >        // .BOut driver header
562 >        Long(0x4d000000); Long(0x00000000);
563 >        Long(0x00200040); Long(0x00600080);
564 >        Long(0x00a0052e); Long(0x424f7574);
565 >        Long(0x00000000); Long(0x00000000);
566 >        Long(0xaafe0700); Long(0x00000000);
567 >        Long(0x00000000); Long(0x00179822);
568 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_OPEN));
569 >        Long(0x00000000); Long(0x00000000);
570 >        Long(0xaafe0700); Long(0x00000000);
571 >        Long(0x00000000); Long(0x00179822);
572 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_PRIME_OUT));
573 >        Long(0x00000000); Long(0x00000000);
574 >        Long(0xaafe0700); Long(0x00000000);
575 >        Long(0x00000000); Long(0x00179822);
576 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CONTROL));
577 >        Long(0x00000000); Long(0x00000000);
578 >        Long(0xaafe0700); Long(0x00000000);
579 >        Long(0x00000000); Long(0x00179822);
580 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_STATUS));
581 >        Long(0x00000000); Long(0x00000000);
582 >        Long(0xaafe0700); Long(0x00000000);
583 >        Long(0x00000000); Long(0x00179822);
584 >        Long(0x00010004); Long(NativeTVECT(NATIVE_SERIAL_CLOSE));
585 >        Long(0x00000000); Long(0x00000000);
586   };
587  
588   static const uint8 adbop_patch[] = {    // Call ADBOp() completion procedure
# Line 679 | Line 609 | static const uint8 adbop_patch[] = {   //
609  
610  
611   /*
612 + *  Copy PowerPC code to ROM image and reverse bytes if necessary
613 + */
614 +
615 + static inline void memcpy_powerpc_code(void *dst, const void *src, size_t len)
616 + {
617 + #ifdef WORDS_BIGENDIAN
618 +        (void)memcpy(dst, src, len);
619 + #else
620 +        uint32 *d = (uint32 *)dst;
621 +        uint32 *s = (uint32 *)src;
622 +        for (int i = 0; i < len/4; i++)
623 +                d[i] = htonl(s[i]);
624 + #endif
625 + }
626 +
627 +
628 + /*
629   *  Install ROM patches (RAMBase and KernelDataAddr must be set)
630   */
631  
# Line 701 | Line 648 | bool PatchROM(void)
648                  ROMType = ROMTYPE_ZANZIBAR;
649          else if (!memcmp((void *)(ROM_BASE + 0x30d064), "Boot Gazelle", 12))
650                  ROMType = ROMTYPE_GAZELLE;
651 +        else if (!memcmp((void *)(ROM_BASE + 0x30d064), "Boot Gossamer", 13))
652 +                ROMType = ROMTYPE_GOSSAMER;
653          else if (!memcmp((void *)(ROM_BASE + 0x30d064), "NewWorld", 8))
654                  ROMType = ROMTYPE_NEWWORLD;
655          else
656                  return false;
657  
658 +        // Check that other ROM addresses point to really free regions
659 +        if (ntohl(*(uint32 *)(ROM_BASE + CHECK_LOAD_PATCH_SPACE)) != 0x6b636b63)
660 +                return false;
661 +        if (ntohl(*(uint32 *)(ROM_BASE + PUT_SCRAP_PATCH_SPACE)) != 0x6b636b63)
662 +                return false;
663 +        if (ntohl(*(uint32 *)(ROM_BASE + GET_SCRAP_PATCH_SPACE)) != 0x6b636b63)
664 +                return false;
665 +        if (ntohl(*(uint32 *)(ROM_BASE + ADDR_MAP_PATCH_SPACE)) != 0x6b636b63)
666 +                return false;
667 +
668          // Apply patches
669          if (!patch_nanokernel_boot()) return false;
670          if (!patch_68k_emul()) return false;
# Line 750 | Line 709 | static bool patch_nanokernel_boot(void)
709          lp[0xfd8 >> 2] = htonl(ROM_BASE + 0x2a);                // 68k reset vector
710  
711          // Skip SR/BAT/SDR init
712 <        if (ROMType == ROMTYPE_GAZELLE || ROMType == ROMTYPE_NEWWORLD) {
712 >        if (ROMType == ROMTYPE_GAZELLE || ROMType == ROMTYPE_GOSSAMER || ROMType == ROMTYPE_NEWWORLD) {
713                  lp = (uint32 *)(ROM_BASE + 0x310000);
714                  *lp++ = htonl(POWERPC_NOP);
715                  *lp = htonl(0x38000000);
716          }
717 <        static const uint32 sr_init_loc[] = {0x3101b0, 0x3101b0, 0x3101b0, 0x3101ec, 0x310200};
717 >        static const uint32 sr_init_loc[] = {0x3101b0, 0x3101b0, 0x3101b0, 0x3101ec, 0x3101fc, 0x310200};
718          lp = (uint32 *)(ROM_BASE + 0x310008);
719          *lp = htonl(0x48000000 | (sr_init_loc[ROMType] - 8) & 0xffff);  // b            ROM_BASE+0x3101b0
720          lp = (uint32 *)(ROM_BASE + sr_init_loc[ROMType]);
# Line 765 | Line 724 | static bool patch_nanokernel_boot(void)
724          *lp = htonl(0x3de00010);                // lis  r15,0x0010      (size of kernel memory)
725  
726          // Don't read PVR
727 <        static const uint32 pvr_loc[] = {0x3103b0, 0x3103b4, 0x3103b4, 0x310400, 0x310438};
727 >        static const uint32 pvr_loc[] = {0x3103b0, 0x3103b4, 0x3103b4, 0x310400, 0x310430, 0x310438};
728          lp = (uint32 *)(ROM_BASE + pvr_loc[ROMType]);
729          *lp = htonl(0x81800000 + XLM_PVR);      // lwz  r12,(theoretical PVR)
730  
# Line 913 | Line 872 | static bool patch_nanokernel_boot(void)
872          *lp = htonl(POWERPC_NOP);
873  
874          // Don't read PVR
875 <        static const uint32 pvr_ofs[] = {0x138, 0x138, 0x138, 0x140, 0x148};
875 >        static const uint32 pvr_ofs[] = {0x138, 0x138, 0x138, 0x140, 0x148, 0x148};
876          lp = (uint32 *)(ROM_BASE + loc + pvr_ofs[ROMType]);
877          *lp = htonl(0x82e00000 + XLM_PVR);              // lwz  r23,(theoretical PVR)
878          lp = (uint32 *)(ROM_BASE + loc + 0x170);
879 <        if (ntohl(*lp) == 0x7eff42a6)   // NewWorld ROM
879 >        if (ntohl(*lp) == 0x7eff42a6)   // NewWorld or Gossamer ROM
880                  *lp = htonl(0x82e00000 + XLM_PVR);      // lwz  r23,(theoretical PVR)
881          lp = (uint32 *)(ROM_BASE + 0x313134);
882          if (ntohl(*lp) == 0x7e5f42a6)
# Line 930 | Line 889 | static bool patch_nanokernel_boot(void)
889                  *lp = htonl(0x81200000 + XLM_PVR);      // lzw  r9,(theoritical PVR)
890  
891          // Don't read SDR1
892 <        static const uint32 sdr1_ofs[] = {0x174, 0x174, 0x174, 0x17c, 0x19c};
892 >        static const uint32 sdr1_ofs[] = {0x174, 0x174, 0x174, 0x17c, 0x19c, 0x19c};
893          lp = (uint32 *)(ROM_BASE + loc + sdr1_ofs[ROMType]);
894          *lp++ = htonl(0x3d00dead);              // lis  r8,0xdead               (pointer to page table)
895          *lp++ = htonl(0x3ec0001f);              // lis  r22,0x001f      (size of page table)
896          *lp = htonl(POWERPC_NOP);
897  
898          // Don't clear page table
899 <        static const uint32 pgtb_ofs[] = {0x198, 0x198, 0x198, 0x1a0, 0x1c4};
899 >        static const uint32 pgtb_ofs[] = {0x198, 0x198, 0x198, 0x1a0, 0x1c0, 0x1c4};
900          lp = (uint32 *)(ROM_BASE + loc + pgtb_ofs[ROMType]);
901          *lp = htonl(POWERPC_NOP);
902  
903          // Don't invalidate TLB
904 <        static const uint32 tlb_ofs[] = {0x1a0, 0x1a0, 0x1a0, 0x1a8, 0x1cc};
904 >        static const uint32 tlb_ofs[] = {0x1a0, 0x1a0, 0x1a0, 0x1a8, 0x1c8, 0x1cc};
905          lp = (uint32 *)(ROM_BASE + loc + tlb_ofs[ROMType]);
906          *lp = htonl(POWERPC_NOP);
907  
908          // Don't create RAM descriptor table
909 <        static const uint32 desc_ofs[] = {0x350, 0x350, 0x350, 0x358, 0x37c};
909 >        static const uint32 desc_ofs[] = {0x350, 0x350, 0x350, 0x358, 0x378, 0x37c};
910          lp = (uint32 *)(ROM_BASE + loc + desc_ofs[ROMType]);
911          *lp = htonl(POWERPC_NOP);
912  
913          // Don't load SRs and BATs
914 <        static const uint32 sr_ofs[] = {0x3d8, 0x3d8, 0x3d8, 0x3e0, 0x404};
914 >        static const uint32 sr_ofs[] = {0x3d8, 0x3d8, 0x3d8, 0x3e0, 0x400, 0x404};
915          lp = (uint32 *)(ROM_BASE + loc + sr_ofs[ROMType]);
916          *lp = htonl(POWERPC_NOP);
917  
918          // Don't mess with SRs
919 <        static const uint32 sr2_ofs[] = {0x312118, 0x312118, 0x312118, 0x312118, 0x3121b4};
919 >        static const uint32 sr2_ofs[] = {0x312118, 0x312118, 0x312118, 0x312118, 0x312118, 0x3121b4};
920          lp = (uint32 *)(ROM_BASE + sr2_ofs[ROMType]);
921          *lp = htonl(POWERPC_BLR);
922  
923          // Don't check performance monitor
924 <        static const uint32 pm_ofs[] = {0x313148, 0x313148, 0x313148, 0x313148, 0x313218};
924 >        static const uint32 pm_ofs[] = {0x313148, 0x313148, 0x313148, 0x313148, 0x313158, 0x313218};
925          lp = (uint32 *)(ROM_BASE + pm_ofs[ROMType]);
926          while (ntohl(*lp) != 0x7e58eba6) lp++;
927          *lp++ = htonl(POWERPC_NOP);
# Line 998 | Line 957 | static bool patch_nanokernel_boot(void)
957          *lp++ = htonl(POWERPC_NOP);
958  
959          // Jump to 68k emulator
960 <        static const uint32 jump68k_ofs[] = {0x40c, 0x40c, 0x40c, 0x414, 0x438};
960 >        static const uint32 jump68k_ofs[] = {0x40c, 0x40c, 0x40c, 0x414, 0x434, 0x438};
961          lp = (uint32 *)(ROM_BASE + loc + jump68k_ofs[ROMType]);
962          *lp++ = htonl(0x80610634);              // lwz  r3,0x0634(r1)   (pointer to Emulator Data)
963          *lp++ = htonl(0x8081119c);              // lwz  r4,0x119c(r1)   (pointer to opcode table)
# Line 1019 | Line 978 | static bool patch_68k_emul(void)
978          uint32 base;
979  
980          // Overwrite twi instructions
981 <        static const uint32 twi_loc[] = {0x36e680, 0x36e6c0, 0x36e6c0, 0x36e6c0, 0x36e740};
981 >        static const uint32 twi_loc[] = {0x36e680, 0x36e6c0, 0x36e6c0, 0x36e6c0, 0x36e740, 0x36e740};
982          base = twi_loc[ROMType];
983          lp = (uint32 *)(ROM_BASE + base);
984          *lp++ = htonl(0x48000000 + 0x36f900 - base);            // b 0x36f900 (Emulator start)
# Line 1080 | Line 1039 | static bool patch_68k_emul(void)
1039          lp = (uint32 *)(ROM_BASE + 0x36f900);
1040          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1041   #if EMULATED_PPC
1042 <        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1042 >        *lp++ = htonl(NativeOpcode(NATIVE_DISABLE_INTERRUPT));
1043   #else
1044          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1045          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
# Line 1114 | Line 1073 | static bool patch_68k_emul(void)
1073          lp = (uint32 *)(ROM_BASE + 0x36fa00);
1074          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1075   #if EMULATED_PPC
1076 <        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1076 >        *lp++ = htonl(NativeOpcode(NATIVE_DISABLE_INTERRUPT));
1077   #else
1078          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1079          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
# Line 1148 | Line 1107 | static bool patch_68k_emul(void)
1107          lp = (uint32 *)(ROM_BASE + 0x36fb00);
1108          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1109   #if EMULATED_PPC
1110 <        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1110 >        *lp++ = htonl(NativeOpcode(NATIVE_DISABLE_INTERRUPT));
1111   #else
1112          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1113          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
# Line 1182 | Line 1141 | static bool patch_68k_emul(void)
1141          lp = (uint32 *)(ROM_BASE + 0x36fc00);
1142          *lp++ = htonl(0x7c2903a6);                                      // mtctr        r1
1143   #if EMULATED_PPC
1144 <        *lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT);
1144 >        *lp++ = htonl(NativeOpcode(NATIVE_DISABLE_INTERRUPT));
1145   #else
1146          *lp++ = htonl(0x80200000 + XLM_IRQ_NEST);       // lwz          r1,XLM_IRQ_NEST
1147          *lp++ = htonl(0x38210001);                                      // addi         r1,r1,1
# Line 1323 | Line 1282 | static bool patch_nanokernel(void)
1282  
1283          lp = (uint32 *)(ROM_BASE + 0x318000);
1284   #if EMULATED_PPC
1285 <        *lp++ = POWERPC_NATIVE_OP(NATIVE_ENABLE_INTERRUPT);
1285 >        *lp++ = htonl(NativeOpcode(NATIVE_ENABLE_INTERRUPT));
1286          *lp = htonl(0x48000000 + ((xlp - 0x8004) & 0x03fffffc));        // b            ROM_BASE+0x312c2c
1287   #else
1288          *lp++ = htonl(0x81400000 + XLM_IRQ_NEST);       // lwz  r10,XLM_IRQ_NEST
# Line 1401 | Line 1360 | static bool patch_68k(void)
1360                  lp[0x28 >> 2] = htonl(0x00000861);
1361                  lp[0x58 >> 2] = htonl(0x30200000);
1362                  lp[0x60 >> 2] = htonl(0x0000003d);
1363 +        } else if (ROMType == ROMTYPE_GOSSAMER) {
1364 +                base = 0x12d20;
1365 +                lp = (uint32 *)(ROM_BASE + base - 0x14);
1366 +                lp[0x00 >> 2] = htonl(ADDR_MAP_PATCH_SPACE - (base - 0x14));
1367 +                lp[0x10 >> 2] = htonl(0xcc003d11);              // Make it like the PowerMac 9500 UniversalInfo
1368 +                lp[0x14 >> 2] = htonl(0x3fff0401);
1369 +                lp[0x18 >> 2] = htonl(0x0300001c);
1370 +                lp[0x1c >> 2] = htonl(0x000108c4);
1371 +                lp[0x24 >> 2] = htonl(0xc301bf26);
1372 +                lp[0x28 >> 2] = htonl(0x00000861);
1373 +                lp[0x58 >> 2] = htonl(0x30410000);
1374 +                lp[0x60 >> 2] = htonl(0x0000003d);
1375          }
1376  
1377          // Construct AddrMap for NewWorld ROM
1378 <        if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_ZANZIBAR) {
1378 >        if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_ZANZIBAR || ROMType == ROMTYPE_GOSSAMER) {
1379                  lp = (uint32 *)(ROM_BASE + ADDR_MAP_PATCH_SPACE);
1380                  memset(lp - 10, 0, 0x128);
1381                  lp[-10] = htonl(0x0300001c);
# Line 1530 | Line 1501 | static bool patch_68k(void)
1501                  *wp++ = htons(M68K_EMUL_OP_XPRAM2);
1502                  *wp = htons(0x4ed3);                    // jmp  (a3)
1503  
1504 <                static const uint32 nvram3_loc[] = {0x582f0, 0xa0a0, 0x7e50, 0xa1d0, 0};
1505 <                wp = (uint16 *)(ROM_BASE + nvram3_loc[ROMType]);
1504 >                static const uint8 nvram3_dat[] = {0x4e, 0xd3, 0x06, 0x41, 0x13, 0x00};
1505 >                if ((base = find_rom_data(0x7000, 0xb000, nvram3_dat, sizeof(nvram3_dat))) == 0) return false;
1506 >                D(bug("nvram3 %08lx\n", base));
1507 >                wp = (uint16 *)(ROM_BASE + base + 2);
1508 >                *wp++ = htons(M68K_EMUL_OP_XPRAM3);
1509 >                *wp = htons(0x4ed3);                    // jmp  (a3)
1510 >
1511 >                static const uint32 nvram4_loc[] = {0x582f0, 0xa0a0, 0x7e50, 0xa1d0, 0x538d0, 0};
1512 >                wp = (uint16 *)(ROM_BASE + nvram4_loc[ROMType]);
1513                  *wp++ = htons(0x202f);                  // move.l       4(sp),d0
1514                  *wp++ = htons(0x0004);
1515                  *wp++ = htons(M68K_EMUL_OP_NVRAM1);
# Line 1544 | Line 1522 | static bool patch_68k(void)
1522                          *wp = htons(0x0004);
1523                  }
1524  
1525 <                static const uint32 nvram4_loc[] = {0x58460, 0xa0f0, 0x7f40, 0xa220, 0};
1526 <                wp = (uint16 *)(ROM_BASE + nvram4_loc[ROMType]);
1525 >                static const uint32 nvram5_loc[] = {0x58460, 0xa0f0, 0x7f40, 0xa220, 0x53a20, 0};
1526 >                wp = (uint16 *)(ROM_BASE + nvram5_loc[ROMType]);
1527                  if (ROMType == ROMTYPE_ZANZIBAR || ROMType == ROMTYPE_GAZELLE) {
1528                          *wp++ = htons(0x202f);                  // move.l       4(sp),d0
1529                          *wp++ = htons(0x0004);
# Line 1722 | Line 1700 | static bool patch_68k(void)
1700                  if ((base = find_rom_data(0x13000, 0x20000, gc_mask2_dat, sizeof(gc_mask2_dat))) == 0) return false;
1701                  D(bug("gc_mask2 %08lx\n", base));
1702                  wp = (uint16 *)(ROM_BASE + base);
1703 +                if (ROMType == ROMTYPE_GOSSAMER)
1704 +                        *wp++ = htons(M68K_NOP);
1705                  for (int i=0; i<5; i++) {
1706                          *wp++ = htons(M68K_NOP);
1707                          *wp++ = htons(M68K_NOP);
# Line 1729 | Line 1709 | static bool patch_68k(void)
1709                          *wp++ = htons(M68K_NOP);
1710                          wp += 2;
1711                  }
1712 <                if (ROMType == ROMTYPE_ZANZIBAR) {
1712 >                if (ROMType == ROMTYPE_ZANZIBAR || ROMType == ROMTYPE_GOSSAMER) {
1713                          for (int i=0; i<6; i++) {
1714                                  *wp++ = htons(M68K_NOP);
1715                                  *wp++ = htons(M68K_NOP);
# Line 1802 | Line 1782 | static bool patch_68k(void)
1782          *wp = htons(M68K_RTS);
1783  
1784          // Don't install Time Manager task for 60Hz interrupt (Enable60HzInts, via 0x2b8)
1785 <        if (ROMType == ROMTYPE_NEWWORLD) {
1785 >        if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) {
1786                  static const uint8 tm_task_dat[] = {0x30, 0x3c, 0x4e, 0x2b, 0xa9, 0xc9};
1787 <                if ((base = find_rom_data(0x2e0, 0x320, tm_task_dat, sizeof(tm_task_dat))) == 0) return false;
1787 >                if ((base = find_rom_data(0x2a0, 0x320, tm_task_dat, sizeof(tm_task_dat))) == 0) return false;
1788                  D(bug("tm_task %08lx\n", base));
1789                  wp = (uint16 *)(ROM_BASE + base + 28);
1790                  *wp++ = htons(M68K_NOP);
# Line 1824 | Line 1804 | static bool patch_68k(void)
1804          }
1805  
1806          // Don't read PVR from 0x5fffef80 in DriverServicesLib (via 0x316)
1807 <        if (ROMType != ROMTYPE_NEWWORLD) {
1807 >        if (ROMType != ROMTYPE_NEWWORLD && ROMType != ROMTYPE_GOSSAMER) {
1808                  uint32 dsl_offset = find_rom_resource(FOURCC('n','l','i','b'), -16401);
1809                  if (ROMType == ROMTYPE_ZANZIBAR) {
1810                          static const uint8 dsl_pvr_dat[] = {0x40, 0x82, 0x00, 0x40, 0x38, 0x60, 0xef, 0x80, 0x3c, 0x63, 0x60, 0x00, 0x80, 0x83, 0x00, 0x00, 0x54, 0x84, 0x84, 0x3e};
# Line 1859 | Line 1839 | static bool patch_68k(void)
1839                  *lp = htonl(0x38600000);                // li   r3,0
1840          }
1841  
1842 +        // FIXME: Fake reading from [HpChk]+4 (the callchain reports some function from DriverServicesLib)
1843 +        if (1) {
1844 +                uint32 hpchk_offset = find_rom_resource(FOURCC('n','l','i','b'), 10);
1845 +                static const uint8 hpchk_dat[] = {0x80, 0x80, 0x03, 0x16, 0x94, 0x21, 0xff, 0xb0, 0x83, 0xc4, 0x00, 0x04};
1846 +                if ((base = find_rom_data(hpchk_offset, hpchk_offset + 0x3000, hpchk_dat, sizeof(hpchk_dat))) == 0) return false;
1847 +                D(bug("hpchk %08lx\n", base));
1848 +                lp = (uint32 *)(ROM_BASE + base);
1849 +                *lp = htonl(0x80800000 + XLM_ZERO_PAGE);                // lwz  r4,(zero page)
1850 +        }
1851 +
1852          // Patch Name Registry
1853          static const uint8 name_reg_dat[] = {0x70, 0xff, 0xab, 0xeb};
1854          if ((base = find_rom_data(0x300, 0x380, name_reg_dat, sizeof(name_reg_dat))) == 0) return false;
# Line 1910 | Line 1900 | static bool patch_68k(void)
1900                          D(bug("scsi_var2 %08lx\n", base));
1901                          wp = (uint16 *)(ROM_BASE + base);
1902                          *wp++ = htons(0x7000);  // moveq #0,d0
1903 <                        *wp = htons(M68K_RTS);  // bra
1903 >                        *wp = htons(M68K_RTS);
1904 >                }
1905 >        }
1906 >        else if (ROMType == ROMTYPE_GOSSAMER) {
1907 >                static const uint8 scsi_var_dat[] = {0x70, 0x01, 0xa0, 0x89, 0x4a, 0x6e, 0xfe, 0xac, 0x4f, 0xef, 0x00, 0x10, 0x66, 0x00};
1908 >                if ((base = find_rom_data(0x1d700, 0x1d800, scsi_var_dat, sizeof(scsi_var_dat))) != 0) {
1909 >                        D(bug("scsi_var %08lx\n", base));
1910 >                        wp = (uint16 *)(ROM_BASE + base + 12);
1911 >                        *wp = htons(0x6000);    // bra
1912 >                }
1913 >
1914 >                static const uint8 scsi_var2_dat[] = {0x4e, 0x56, 0xfc, 0x5a, 0x48, 0xe7, 0x1f, 0x38};
1915 >                if ((base = find_rom_data(0x1d900, 0x1da00, scsi_var2_dat, sizeof(scsi_var2_dat))) != 0) {
1916 >                        D(bug("scsi_var2 %08lx\n", base));
1917 >                        wp = (uint16 *)(ROM_BASE + base);
1918 >                        *wp++ = htons(0x7000);  // moveq #0,d0
1919 >                        *wp = htons(M68K_RTS);
1920                  }
1921          }
1922   #endif
# Line 1966 | Line 1972 | static bool patch_68k(void)
1972          memcpy((void *)(ROM_BASE + sony_offset + 0x200), cdrom_driver, sizeof(cdrom_driver));
1973  
1974          // Install serial drivers
1975 <        memcpy((void *)(ROM_BASE + sony_offset + 0x300), ain_driver, sizeof(ain_driver));
1976 <        memcpy((void *)(ROM_BASE + sony_offset + 0x400), aout_driver, sizeof(aout_driver));
1977 <        memcpy((void *)(ROM_BASE + sony_offset + 0x500), bin_driver, sizeof(bin_driver));
1978 <        memcpy((void *)(ROM_BASE + sony_offset + 0x600), bout_driver, sizeof(bout_driver));
1975 >        gen_ain_driver( ROM_BASE + sony_offset + 0x300);
1976 >        gen_aout_driver(ROM_BASE + sony_offset + 0x400);
1977 >        gen_bin_driver( ROM_BASE + sony_offset + 0x500);
1978 >        gen_bout_driver(ROM_BASE + sony_offset + 0x600);
1979  
1980          // Copy icons to ROM
1981          SonyDiskIconAddr = ROM_BASE + sony_offset + 0x800;
# Line 1990 | Line 1996 | static bool patch_68k(void)
1996          *wp = htons(M68K_RTS);
1997  
1998          // Don't install serial drivers from ROM
1999 <        if (ROMType == ROMTYPE_ZANZIBAR || ROMType == ROMTYPE_NEWWORLD) {
1999 >        if (ROMType == ROMTYPE_ZANZIBAR || ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) {
2000                  wp = (uint16 *)(ROM_BASE + find_rom_resource(FOURCC('S','E','R','D'), 0));
2001                  *wp = htons(M68K_RTS);
2002          } else {
# Line 2171 | Line 2177 | void InstallDrivers(void)
2177   {
2178          D(bug("Installing drivers...\n"));
2179          M68kRegisters r;
2180 <        uint8 pb[SIZEOF_IOParam];
2180 >        SheepArray<SIZEOF_IOParam> pb_var;
2181 >        const uintptr pb = pb_var.addr();
2182  
2183          // Install floppy driver
2184 <        if (ROMType == ROMTYPE_NEWWORLD) {
2184 >        if (ROMType == ROMTYPE_NEWWORLD || ROMType == ROMTYPE_GOSSAMER) {
2185  
2186 <                // Force installation of floppy driver with NewWorld ROMs
2186 >                // Force installation of floppy driver with NewWorld and Gossamer ROMs
2187                  r.a[0] = ROM_BASE + sony_offset;
2188                  r.d[0] = (uint32)SonyRefNum;
2189                  Execute68kTrap(0xa43d, &r);             // DrvrInstallRsrvMem()
# Line 2189 | Line 2196 | void InstallDrivers(void)
2196  
2197   #if DISABLE_SCSI && 0
2198          // Fake SCSIGlobals
2199 <        static const uint8 fake_scsi_globals[32] = {0,};
2193 <        WriteMacInt32(0xc0c, (uint32)fake_scsi_globals);
2199 >        WriteMacInt32(0xc0c, SheepMem::ZeroPage());
2200   #endif
2201  
2202          // Open .Sony driver
2203 <        WriteMacInt8((uint32)pb + ioPermssn, 0);
2204 <        WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\005.Sony");
2205 <        r.a[0] = (uint32)pb;
2203 >        SheepString sony_str("\005.Sony");
2204 >        WriteMacInt8(pb + ioPermssn, 0);
2205 >        WriteMacInt32(pb + ioNamePtr, sony_str.addr());
2206 >        r.a[0] = pb;
2207          Execute68kTrap(0xa000, &r);             // Open()
2208  
2209          // Install disk driver
# Line 2210 | Line 2217 | void InstallDrivers(void)
2217          WriteMacInt16(dce + dCtlFlags, DiskDriverFlags);
2218  
2219          // Open disk driver
2220 <        WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\005.Disk");
2221 <        r.a[0] = (uint32)pb;
2220 >        SheepString disk_str("\005.Disk");
2221 >        WriteMacInt32(pb + ioNamePtr, disk_str.addr());
2222 >        r.a[0] = pb;
2223          Execute68kTrap(0xa000, &r);             // Open()
2224  
2225          // Install CD-ROM driver unless nocdrom option given
# Line 2228 | Line 2236 | void InstallDrivers(void)
2236                  WriteMacInt16(dce + dCtlFlags, CDROMDriverFlags);
2237  
2238                  // Open CD-ROM driver
2239 <                WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\010.AppleCD");
2240 <                r.a[0] = (uint32)pb;
2239 >                SheepString apple_cd("\010.AppleCD");
2240 >                WriteMacInt32(pb + ioNamePtr, apple_cd.addr());
2241 >                r.a[0] = pb;
2242                  Execute68kTrap(0xa000, &r);             // Open()
2243          }
2244  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines