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

Comparing SheepShaver/src/rsrc_patches.cpp (file contents):
Revision 1.8 by gbeauche, 2003-12-27T09:08:51Z vs.
Revision 1.12 by gbeauche, 2004-11-13T14:09:15Z

# Line 1 | Line 1
1   /*
2   *  rsrc_patches.cpp - Resource patches
3   *
4 < *  SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
4 > *  SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 117 | Line 117 | void CheckLoad(uint32 type, int16 id, ui
117          D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %p, size %d\n", type >> 24, (type >> 16) & 0xff, (type >> 8) & 0xff, type & 0xff, type, id, p, size));
118  
119          // Don't modify resources in ROM
120 <        if ((uintptr)p >= ROM_BASE && (uintptr)p <= (ROM_BASE + ROM_SIZE))
120 >        if ((uintptr)p >= (uintptr)ROMBaseHost && (uintptr)p <= (uintptr)(ROMBaseHost + ROM_SIZE))
121                  return;
122  
123          if (type == FOURCC('b','o','o','t') && id == 3) {
# Line 136 | Line 136 | void CheckLoad(uint32 type, int16 id, ui
136                                  // Check when ntrb 17 is installed (for native Resource Manager patch) (7.6, 7.6.1, 8.0, 8.1)
137                                  p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH);
138                                  D(bug(" patch 3 applied\n"));
139 <                        } else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff)) {
139 >                        } else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff) && PM(8,0x245f)) {
140                                  // Check when ntrb 17 is installed (for native Resource Manager patch) (8.5, 8.6)
141                                  p[8] = htons(M68K_EMUL_OP_NTRB_17_PATCH);
142                                  D(bug(" patch 4 applied\n"));
143 +                        } else if (PM(0,0x3f2a) && PM(1,0x0006) && PM(2,0x3f2a) && PM(3,0x0002) && PM(4,0x61ff) && PM(7,0x301f)) {
144 +                                // Check when ntrb 17 is installed (for native Resource Manager patch) (9.0)
145 +                                p[7] = htons(M68K_EMUL_OP_NTRB_17_PATCH4);
146 +                                p[8] = htons(ntohs(p[8]) & 0xf0ff); // bra
147 +                                D(bug(" patch 8 applied\n"));
148                          } else if (PM(0,0x0c39) && PM(1,0x0001) && PM(2,0xf800) && PM(3,0x0008) && PM(4,0x6f00)) {
149                                  // Don't read from 0xf8000008 (8.5 with Zanzibar ROM, 8.6)
150                                  p[0] = htons(M68K_NOP);
# Line 179 | Line 184 | void CheckLoad(uint32 type, int16 id, ui
184                          D(bug(" patch 1 applied\n"));
185                  }
186  
187 +        } else if (type == FOURCC('p','t','c','h') && id == 156) {
188 +                D(bug("ptch 156 found\n"));
189 +                size >>= 1;
190 +                while (size--) {
191 +                        if (PM(0,0x4e56) && PM(1,0xfffa) && PM(2,0x48e7) && PM(3,0x1f18) && PM(4,0x7800) && PM(5,0x267c) && PM(6,0x6900) && PM(7,0x0000)) {
192 +                                // Don't call FE0A opcode (9.0)
193 +                                p[0] = htons(0x7000);           // moveq #0,d0
194 +                                p[1] = htons(M68K_RTS);
195 +                                D(bug(" patch 1 applied\n"));
196 +                                break;
197 +                        }
198 +                        p++;
199 +                }
200 +
201          } else if (type == FOURCC('p','t','c','h') && id == 420) {
202                  D(bug("ptch 420 found\n"));
203                  size >>= 1;
# Line 449 | Line 468 | void CheckLoad(uint32 type, int16 id, ui
468  
469          } else if (type == FOURCC('t','h','n','g')) {
470                  // Collect info about used audio sifters
471 <                uint32 thing = (uintptr)p;
471 >                uint32 thing = Host2MacAddr((uint8 *)p);
472                  uint32 c_type = ReadMacInt32(thing);
473                  uint32 sub_type = ReadMacInt32(thing + 4);
474                  if (c_type == FOURCC('s','d','e','v') && sub_type == FOURCC('s','i','n','g')) {
# Line 507 | Line 526 | void CheckLoad(uint32 type, int16 id, ui
526                          p16[1] = htons(M68K_RTS);
527                          D(bug(" patch 1 applied\n"));
528                  }
529 +
530 +        } else if (type == FOURCC('N','O','b','j') && id == 100) {
531 +                D(bug("NObj 100 found\n"));
532 +
533 +                // Don't access VIA registers in MacBench 5.0
534 +                static const uint8 dat1[] = {0x7c, 0x08, 0x02, 0xa6, 0xbf, 0x01, 0xff, 0xe0, 0x90, 0x01, 0x00, 0x08};
535 +                base = find_rsrc_data((uint8 *)p, size, dat1, sizeof(dat1));
536 +                if (base) {
537 +                        p[(base + 0x00) >> 1] = htons(0x3860);          // li r3,0
538 +                        p[(base + 0x02) >> 1] = htons(0x0000);
539 +                        p[(base + 0x04) >> 1] = htons(0x4e80);          // blr
540 +                        p[(base + 0x06) >> 1] = htons(0x0020);
541 +                        D(bug(" patch 1 applied\n"));
542 +                }
543 +                static const uint8 dat2[] = {0x7c, 0x6c, 0x1b, 0x78, 0x7c, 0x8b, 0x23, 0x78, 0x38, 0xc0, 0x3f, 0xfd};
544 +                base = find_rsrc_data((uint8 *)p, size, dat2, sizeof(dat2));
545 +                if (base) {
546 +                        p[(base + 0x00) >> 1] = htons(0x3860);          // li r3,0
547 +                        p[(base + 0x02) >> 1] = htons(0x0000);
548 +                        p[(base + 0x04) >> 1] = htons(0x4e80);          // blr
549 +                        p[(base + 0x06) >> 1] = htons(0x0020);
550 +                        D(bug(" patch 2 applied\n"));
551 +                }
552          }
553   }
554  
# Line 529 | Line 571 | void check_load_invoc(uint32 type, int16
571                  return;
572          uint32 size = ReadMacInt32(p - 2 * 4) & 0xffffff;
573  
574 <        CheckLoad(type, id, (uint16 *)p, size);
574 >        CheckLoad(type, id, (uint16 *)Mac2HostAddr(p), size);
575   }
576  
577   #ifdef __BEOS__
# Line 714 | Line 756 | void PatchNativeResourceManager(void)
756          uint32 upp = ReadMacInt32(0x1480);
757          if ((upp & 0xffc00000) == ROM_BASE)
758                  return;
759 <        uint32 *tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
760 <        D(bug(" GetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
761 <        *(uint32 *)XLM_RES_LIB_TOC = tvec[1];
762 <        *(uint32 *)XLM_GET_RESOURCE = tvec[0];
759 >        uint32 tvec = ReadMacInt32(upp + 5 * 4);
760 >        D(bug(" GetResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));
761 >        WriteMacInt32(XLM_RES_LIB_TOC, ReadMacInt32(tvec + 4));
762 >        WriteMacInt32(XLM_GET_RESOURCE, ReadMacInt32(tvec));
763   #if EMULATED_PPC
764 <        tvec[0] = htonl(NativeFunction(NATIVE_GET_RESOURCE));
764 >        WriteMacInt32(tvec, NativeFunction(NATIVE_GET_RESOURCE));
765   #else
766   #ifdef __BEOS__
767          uint32 *tvec2 = (uint32 *)get_resource;
768 <        tvec[0] = tvec2[0];
769 <        tvec[1] = tvec2[1];
768 >        WriteMacInt32(tvec, tvec2[0]);
769 >        WriteMacInt32(tvec + 4, tvec2[1]);
770   #else
771 <        tvec[0] = (uint32)get_resource;
771 >        WriteMacInt32(tvec, (uint32)get_resource);
772   #endif
773   #endif
774  
775          // Patch native Get1Resource()
776          upp = ReadMacInt32(0x0e7c);
777 <        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
778 <        D(bug(" Get1Resource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
779 <        *(uint32 *)XLM_GET_1_RESOURCE = tvec[0];
777 >        tvec = ReadMacInt32(upp + 5 * 4);
778 >        D(bug(" Get1Resource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));
779 >        WriteMacInt32(XLM_GET_1_RESOURCE, ReadMacInt32(tvec));
780   #if EMULATED_PPC
781 <        tvec[0] = htonl(NativeFunction(NATIVE_GET_1_RESOURCE));
781 >        WriteMacInt32(tvec, NativeFunction(NATIVE_GET_1_RESOURCE));
782   #else
783   #ifdef __BEOS__
784          tvec2 = (uint32 *)get_1_resource;
785 <        tvec[0] = tvec2[0];
786 <        tvec[1] = tvec2[1];
785 >        WriteMacInt32(tvec, tvec2[0]);
786 >        WriteMacInt32(tvec + 4, tvec2[1]);
787   #else
788 <        tvec[0] = (uint32)get_1_resource;
788 >        WriteMacInt32(tvec, (uint32)get_1_resource);
789   #endif
790   #endif
791  
792          // Patch native GetIndResource()
793          upp = ReadMacInt32(0x1474);
794 <        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
795 <        D(bug(" GetIndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
796 <        *(uint32 *)XLM_GET_IND_RESOURCE = tvec[0];
794 >        tvec = ReadMacInt32(upp + 5 * 4);
795 >        D(bug(" GetIndResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));
796 >        WriteMacInt32(XLM_GET_IND_RESOURCE, ReadMacInt32(tvec));
797   #if EMULATED_PPC
798 <        tvec[0] = htonl(NativeFunction(NATIVE_GET_IND_RESOURCE));
798 >        WriteMacInt32(tvec, NativeFunction(NATIVE_GET_IND_RESOURCE));
799   #else
800   #ifdef __BEOS__
801          tvec2 = (uint32 *)get_ind_resource;
802 <        tvec[0] = tvec2[0];
803 <        tvec[1] = tvec2[1];
802 >        WriteMacInt32(tvec, tvec2[0]);
803 >        WriteMacInt32(tvec + 4, tvec2[1]);
804   #else
805 <        tvec[0] = (uint32)get_ind_resource;
805 >        WriteMacInt32(tvec, (uint32)get_ind_resource);
806   #endif
807   #endif
808  
809          // Patch native Get1IndResource()
810          upp = ReadMacInt32(0x0e38);
811 <        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
812 <        D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
813 <        *(uint32 *)XLM_GET_1_IND_RESOURCE = tvec[0];
811 >        tvec = ReadMacInt32(upp + 5 * 4);
812 >        D(bug(" Get1IndResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));
813 >        WriteMacInt32(XLM_GET_1_IND_RESOURCE, ReadMacInt32(tvec));
814   #if EMULATED_PPC
815 <        tvec[0] = htonl(NativeFunction(NATIVE_GET_1_IND_RESOURCE));
815 >        WriteMacInt32(tvec, NativeFunction(NATIVE_GET_1_IND_RESOURCE));
816   #else
817   #ifdef __BEOS__
818          tvec2 = (uint32 *)get_1_ind_resource;
819 <        tvec[0] = tvec2[0];
820 <        tvec[1] = tvec2[1];
819 >        WriteMacInt32(tvec, tvec2[0]);
820 >        WriteMacInt32(tvec + 4, tvec2[1]);
821   #else
822 <        tvec[0] = (uint32)get_1_ind_resource;
822 >        WriteMacInt32(tvec, (uint32)get_1_ind_resource);
823   #endif
824   #endif
825  
826          // Patch native RGetResource()
827          upp = ReadMacInt32(0x0e30);
828 <        tvec = (uint32 *)ReadMacInt32(upp + 5 * 4);
829 <        D(bug(" RGetResource() entry %08x, TOC %08x\n", ntohl(tvec[0]), ntohl(tvec[1])));
830 <        *(uint32 *)XLM_R_GET_RESOURCE = tvec[0];
828 >        tvec = ReadMacInt32(upp + 5 * 4);
829 >        D(bug(" RGetResource() entry %08x, TOC %08x\n", ReadMacInt32(tvec), ReadMacInt32(tvec + 4)));
830 >        WriteMacInt32(XLM_R_GET_RESOURCE, ReadMacInt32(tvec));
831   #if EMULATED_PPC
832 <        tvec[0] = htonl(NativeFunction(NATIVE_R_GET_RESOURCE));
832 >        WriteMacInt32(tvec, NativeFunction(NATIVE_R_GET_RESOURCE));
833   #else
834   #ifdef __BEOS__
835          tvec2 = (uint32 *)r_get_resource;
836 <        tvec[0] = tvec2[0];
837 <        tvec[1] = tvec2[1];
836 >        WriteMacInt32(tvec, tvec2[0]);
837 >        WriteMacInt32(tvec + 4, tvec2[1]);
838   #else
839 <        tvec[0] = (uint32)r_get_resource;
839 >        WriteMacInt32(tvec, (uint32)r_get_resource);
840   #endif
841   #endif
842   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines