74 |
|
static bool patch_68k(void); |
75 |
|
|
76 |
|
|
77 |
+ |
// Decode LZSS data |
78 |
+ |
static void decode_lzss(const uint8 *src, uint8 *dest, int size) |
79 |
+ |
{ |
80 |
+ |
char dict[0x1000]; |
81 |
+ |
int run_mask = 0, dict_idx = 0xfee; |
82 |
+ |
for (;;) { |
83 |
+ |
if (run_mask < 0x100) { |
84 |
+ |
// Start new run |
85 |
+ |
if (--size < 0) |
86 |
+ |
break; |
87 |
+ |
run_mask = *src++ | 0xff00; |
88 |
+ |
} |
89 |
+ |
bool bit = run_mask & 1; |
90 |
+ |
run_mask >>= 1; |
91 |
+ |
if (bit) { |
92 |
+ |
// Verbatim copy |
93 |
+ |
if (--size < 0) |
94 |
+ |
break; |
95 |
+ |
int c = *src++; |
96 |
+ |
dict[dict_idx++] = c; |
97 |
+ |
*dest++ = c; |
98 |
+ |
dict_idx &= 0xfff; |
99 |
+ |
} else { |
100 |
+ |
// Copy from dictionary |
101 |
+ |
if (--size < 0) |
102 |
+ |
break; |
103 |
+ |
int idx = *src++; |
104 |
+ |
if (--size < 0) |
105 |
+ |
break; |
106 |
+ |
int cnt = *src++; |
107 |
+ |
idx |= (cnt << 4) & 0xf00; |
108 |
+ |
cnt = (cnt & 0x0f) + 3; |
109 |
+ |
while (cnt--) { |
110 |
+ |
char c = dict[idx++]; |
111 |
+ |
dict[dict_idx++] = c; |
112 |
+ |
*dest++ = c; |
113 |
+ |
idx &= 0xfff; |
114 |
+ |
dict_idx &= 0xfff; |
115 |
+ |
} |
116 |
+ |
} |
117 |
+ |
} |
118 |
+ |
} |
119 |
+ |
|
120 |
+ |
// Decode parcels of ROM image (MacOS 9.X and even earlier) |
121 |
+ |
void decode_parcels(const uint8 *src, uint8 *dest, int size) |
122 |
+ |
{ |
123 |
+ |
uint32 parcel_offset = 0x14; |
124 |
+ |
D(bug("Offset Type Name\n")); |
125 |
+ |
while (parcel_offset != 0) { |
126 |
+ |
const uint32 *parcel_data = (uint32 *)(src + parcel_offset); |
127 |
+ |
uint32 next_offset = ntohl(parcel_data[0]); |
128 |
+ |
uint32 parcel_type = ntohl(parcel_data[1]); |
129 |
+ |
D(bug("%08x %c%c%c%c %s\n", parcel_offset, |
130 |
+ |
(parcel_type >> 24) & 0xff, (parcel_type >> 16) & 0xff, |
131 |
+ |
(parcel_type >> 8) & 0xff, parcel_type & 0xff, &parcel_data[6])); |
132 |
+ |
if (parcel_type == FOURCC('r','o','m',' ')) { |
133 |
+ |
uint32 lzss_offset = ntohl(parcel_data[2]); |
134 |
+ |
uint32 lzss_size = ((uint32)src + parcel_offset) - ((uint32)parcel_data + lzss_offset); |
135 |
+ |
decode_lzss((uint8 *)parcel_data + lzss_offset, dest, lzss_size); |
136 |
+ |
} |
137 |
+ |
parcel_offset = next_offset; |
138 |
+ |
} |
139 |
+ |
} |
140 |
+ |
|
141 |
+ |
|
142 |
+ |
/* |
143 |
+ |
* Decode ROM image, 4 MB plain images or NewWorld images |
144 |
+ |
*/ |
145 |
+ |
|
146 |
+ |
bool DecodeROM(uint8 *data, uint32 size) |
147 |
+ |
{ |
148 |
+ |
if (size == ROM_SIZE) { |
149 |
+ |
// Plain ROM image |
150 |
+ |
memcpy((void *)ROM_BASE, data, ROM_SIZE); |
151 |
+ |
return true; |
152 |
+ |
} |
153 |
+ |
else if (strncmp((char *)data, "<CHRP-BOOT>", 11) == 0) { |
154 |
+ |
// CHRP compressed ROM image |
155 |
+ |
uint32 image_offset, image_size; |
156 |
+ |
bool decode_info_ok = false; |
157 |
+ |
|
158 |
+ |
char *s = strstr((char *)data, "constant lzss-offset"); |
159 |
+ |
if (s != NULL) { |
160 |
+ |
// Probably a plain LZSS compressed ROM image |
161 |
+ |
if (sscanf(s - 7, "%06x", &image_offset) == 1) { |
162 |
+ |
s = strstr((char *)data, "constant lzss-size"); |
163 |
+ |
if (s != NULL && (sscanf(s - 7, "%06x", &image_size) == 1)) |
164 |
+ |
decode_info_ok = true; |
165 |
+ |
} |
166 |
+ |
} |
167 |
+ |
else { |
168 |
+ |
// Probably a MacOS 9.2.x ROM image |
169 |
+ |
s = strstr((char *)data, "constant parcels-offset"); |
170 |
+ |
if (s != NULL) { |
171 |
+ |
if (sscanf(s - 7, "%06x", &image_offset) == 1) { |
172 |
+ |
s = strstr((char *)data, "constant parcels-size"); |
173 |
+ |
if (s != NULL && (sscanf(s - 7, "%06x", &image_size) == 1)) |
174 |
+ |
decode_info_ok = true; |
175 |
+ |
} |
176 |
+ |
} |
177 |
+ |
} |
178 |
+ |
|
179 |
+ |
// No valid information to decode the ROM found? |
180 |
+ |
if (!decode_info_ok) |
181 |
+ |
return false; |
182 |
+ |
|
183 |
+ |
// Check signature, this could be a parcels-based ROM image |
184 |
+ |
uint32 rom_signature = ntohl(*(uint32 *)(data + image_offset)); |
185 |
+ |
if (rom_signature == FOURCC('p','r','c','l')) { |
186 |
+ |
D(bug("Offset of parcels data: %08x\n", image_offset)); |
187 |
+ |
D(bug("Size of parcels data: %08x\n", image_size)); |
188 |
+ |
decode_parcels(data + image_offset, (uint8 *)ROM_BASE, image_size); |
189 |
+ |
} |
190 |
+ |
else { |
191 |
+ |
D(bug("Offset of compressed data: %08x\n", image_offset)); |
192 |
+ |
D(bug("Size of compressed data: %08x\n", image_size)); |
193 |
+ |
decode_lzss(data + image_offset, (uint8 *)ROM_BASE, image_size); |
194 |
+ |
} |
195 |
+ |
return true; |
196 |
+ |
} |
197 |
+ |
return false; |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
|
201 |
|
/* |
202 |
|
* Search ROM for byte string, return ROM offset (or 0) |
203 |
|
*/ |
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] = {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}; |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
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, |
925 |
|
lp = (uint32 *)(ROM_BASE + 0x3131f4); |
926 |
|
if (ntohl(*lp) == 0x7e5f42a6) // NewWorld ROM |
927 |
|
*lp = htonl(0x82400000 + XLM_PVR); // lwz r18,(theoretical PVR) |
928 |
+ |
lp = (uint32 *)(ROM_BASE + 0x314600); |
929 |
+ |
if (ntohl(*lp) == 0x7d3f42a6) |
930 |
+ |
*lp = htonl(0x81200000 + XLM_PVR); // lzw r9,(theoritical PVR) |
931 |
|
|
932 |
|
// Don't read SDR1 |
933 |
|
static const uint32 sdr1_ofs[] = {0x174, 0x174, 0x174, 0x17c, 0x19c}; |
1040 |
|
*lp = htonl(POWERPC_ILLEGAL); |
1041 |
|
|
1042 |
|
#if EMULATED_PPC |
1043 |
< |
// Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes |
1043 |
> |
// Install EMUL_RETURN, EXEC_RETURN, EXEC_NATIVE and EMUL_OP opcodes |
1044 |
|
lp = (uint32 *)(ROM_BASE + 0x380000 + (M68K_EMUL_RETURN << 3)); |
1045 |
|
*lp++ = htonl(POWERPC_EMUL_OP); |
1046 |
|
*lp++ = htonl(0x4bf66e80); // b 0x366084 |
1047 |
|
*lp++ = htonl(POWERPC_EMUL_OP | 1); |
1048 |
|
*lp++ = htonl(0x4bf66e78); // b 0x366084 |
1049 |
+ |
*lp++ = htonl(POWERPC_EMUL_OP | 2); |
1050 |
+ |
*lp++ = htonl(0x4bf66e70); // b 0x366084 |
1051 |
|
for (int i=0; i<OP_MAX; i++) { |
1052 |
< |
*lp++ = htonl(POWERPC_EMUL_OP | (i + 2)); |
1053 |
< |
*lp++ = htonl(0x4bf66e70 - i*8); // b 0x366084 |
1052 |
> |
*lp++ = htonl(POWERPC_EMUL_OP | (i + 3)); |
1053 |
> |
*lp++ = htonl(0x4bf66e68 - i*8); // b 0x366084 |
1054 |
|
} |
1055 |
|
#else |
1056 |
|
// Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes |
1059 |
|
*lp++ = htonl(0x4bf705fc); // b 0x36f800 |
1060 |
|
*lp++ = htonl(0x80000000 + XLM_EXEC_RETURN_PROC); // lwz r0,XLM_EXEC_RETURN_PROC |
1061 |
|
*lp++ = htonl(0x4bf705f4); // b 0x36f800 |
1062 |
+ |
*lp++ = htonl(0x00dead00); // Let SheepShaver crash, since |
1063 |
+ |
*lp++ = htonl(0x00beef00); // no native opcode is available |
1064 |
|
for (int i=0; i<OP_MAX; i++) { |
1065 |
|
*lp++ = htonl(0x38a00000 + i); // li r5,OP_* |
1066 |
< |
*lp++ = htonl(0x4bf705f4 - i*8); // b 0x36f808 |
1066 |
> |
*lp++ = htonl(0x4bf705ec - i*8); // b 0x36f808 |
1067 |
|
} |
1068 |
|
|
1069 |
|
// Extra routines for EMUL_RETURN/EXEC_RETURN/EMUL_OP |
1079 |
|
// Extra routine for 68k emulator start |
1080 |
|
lp = (uint32 *)(ROM_BASE + 0x36f900); |
1081 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1082 |
+ |
#if EMULATED_PPC |
1083 |
+ |
*lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT); |
1084 |
+ |
#else |
1085 |
|
*lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST |
1086 |
|
*lp++ = htonl(0x38210001); // addi r1,r1,1 |
1087 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1088 |
+ |
#endif |
1089 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1090 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1091 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1113 |
|
// Extra routine for Mixed Mode |
1114 |
|
lp = (uint32 *)(ROM_BASE + 0x36fa00); |
1115 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1116 |
+ |
#if EMULATED_PPC |
1117 |
+ |
*lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT); |
1118 |
+ |
#else |
1119 |
|
*lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST |
1120 |
|
*lp++ = htonl(0x38210001); // addi r1,r1,1 |
1121 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1122 |
+ |
#endif |
1123 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1124 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1125 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1145 |
|
*lp = htonl(0x4e800020); // blr |
1146 |
|
|
1147 |
|
// Extra routine for Reset/FC1E opcode |
1148 |
< |
lp = (uint32 *)(ROM_BASE + 0x36fc00); |
1148 |
> |
lp = (uint32 *)(ROM_BASE + 0x36fb00); |
1149 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1150 |
+ |
#if EMULATED_PPC |
1151 |
+ |
*lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT); |
1152 |
+ |
#else |
1153 |
|
*lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST |
1154 |
|
*lp++ = htonl(0x38210001); // addi r1,r1,1 |
1155 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1156 |
+ |
#endif |
1157 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1158 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1159 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1170 |
|
*lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) |
1171 |
|
*lp++ = htonl(0x7d8802a6); // mflr r12 |
1172 |
|
*lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 |
1173 |
< |
*lp++ = htonl(0x814105f4); // lwz r10,0x05f8(r1) |
1173 |
> |
*lp++ = htonl(0x814105f8); // lwz r10,0x05f8(r1) |
1174 |
|
*lp++ = htonl(0x7d4803a6); // mtlr r10 |
1175 |
|
*lp++ = htonl(0x7d8a6378); // mr r10,r12 |
1176 |
|
*lp++ = htonl(0x3d600002); // lis r11,0x0002 |
1181 |
|
// Extra routine for FE0A opcode (QuickDraw 3D needs this) |
1182 |
|
lp = (uint32 *)(ROM_BASE + 0x36fc00); |
1183 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1184 |
+ |
#if EMULATED_PPC |
1185 |
+ |
*lp++ = POWERPC_NATIVE_OP(NATIVE_DISABLE_INTERRUPT); |
1186 |
+ |
#else |
1187 |
|
*lp++ = htonl(0x80200000 + XLM_IRQ_NEST); // lwz r1,XLM_IRQ_NEST |
1188 |
|
*lp++ = htonl(0x38210001); // addi r1,r1,1 |
1189 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1190 |
+ |
#endif |
1191 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1192 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1193 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1204 |
|
*lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) |
1205 |
|
*lp++ = htonl(0x7d8802a6); // mflr r12 |
1206 |
|
*lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 |
1207 |
< |
*lp++ = htonl(0x814105f4); // lwz r10,0x05fc(r1) |
1207 |
> |
*lp++ = htonl(0x814105fc); // lwz r10,0x05fc(r1) |
1208 |
|
*lp++ = htonl(0x7d4803a6); // mtlr r10 |
1209 |
|
*lp++ = htonl(0x7d8a6378); // mr r10,r12 |
1210 |
|
*lp++ = htonl(0x3d600002); // lis r11,0x0002 |
1322 |
|
*lp = htonl(POWERPC_BCTR); |
1323 |
|
|
1324 |
|
lp = (uint32 *)(ROM_BASE + 0x318000); |
1325 |
+ |
#if EMULATED_PPC |
1326 |
+ |
*lp++ = POWERPC_NATIVE_OP(NATIVE_ENABLE_INTERRUPT); |
1327 |
+ |
*lp = htonl(0x48000000 + ((xlp - 0x8004) & 0x03fffffc)); // b ROM_BASE+0x312c2c |
1328 |
+ |
#else |
1329 |
|
*lp++ = htonl(0x81400000 + XLM_IRQ_NEST); // lwz r10,XLM_IRQ_NEST |
1330 |
|
*lp++ = htonl(0x394affff); // subi r10,r10,1 |
1331 |
|
*lp++ = htonl(0x91400000 + XLM_IRQ_NEST); // stw r10,XLM_IRQ_NEST |
1332 |
|
*lp = htonl(0x48000000 + ((xlp - 0x800c) & 0x03fffffc)); // b ROM_BASE+0x312c2c |
1333 |
+ |
#endif |
1334 |
+ |
|
1335 |
|
/* |
1336 |
|
// Disable FE0A/FE06 opcodes |
1337 |
|
lp = (uint32 *)(ROM_BASE + 0x3144ac); |
1377 |
|
// Patch UniversalInfo |
1378 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
1379 |
|
static const uint8 univ_info_dat[] = {0x3f, 0xff, 0x04, 0x00}; |
1380 |
< |
if ((base = find_rom_data(0x14000, 0x16000, univ_info_dat, sizeof(univ_info_dat))) == 0) return false; |
1380 |
> |
if ((base = find_rom_data(0x14000, 0x18000, univ_info_dat, sizeof(univ_info_dat))) == 0) return false; |
1381 |
|
D(bug("universal_info %08lx\n", base)); |
1382 |
|
lp = (uint32 *)(ROM_BASE + base - 0x14); |
1383 |
|
lp[0x00 >> 2] = htonl(ADDR_MAP_PATCH_SPACE - (base - 0x14)); |
1755 |
|
|
1756 |
|
// Patch GetCPUSpeed (via 0x27a) (some ROMs have two of them) |
1757 |
|
static const uint8 cpu_speed_dat[] = {0x20, 0x30, 0x81, 0xf2, 0x5f, 0xff, 0xef, 0xd8, 0x00, 0x04, 0x4c, 0x7c}; |
1758 |
< |
if ((base = find_rom_data(0x6000, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; |
1758 |
> |
if ((base = find_rom_data(0x6000, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; |
1759 |
|
D(bug("cpu_speed %08lx\n", base)); |
1760 |
|
wp = (uint16 *)(ROM_BASE + base); |
1761 |
|
*wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 |
1762 |
|
*wp++ = htons(CPUClockSpeed / 1000000); |
1763 |
|
*wp++ = htons(CPUClockSpeed / 1000000); |
1764 |
|
*wp = htons(M68K_RTS); |
1765 |
< |
if ((base = find_rom_data(base, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { |
1765 |
> |
if ((base = find_rom_data(base, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { |
1766 |
|
D(bug("cpu_speed2 %08lx\n", base)); |
1767 |
|
wp = (uint16 *)(ROM_BASE + base); |
1768 |
|
*wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 |
2049 |
|
wp = (uint16 *)(ROM_BASE + base); |
2050 |
|
if (ROMType == ROMTYPE_ZANZIBAR) |
2051 |
|
*wp = htons(M68K_RTS); |
2052 |
< |
else |
2052 |
> |
else if (ntohs(wp[-4]) == 0x61ff) |
2053 |
> |
*wp = htons(M68K_RTS); |
2054 |
> |
else if (ntohs(wp[-2]) == 0x6700) |
2055 |
|
wp[-2] = htons(0x6000); // bra |
2056 |
|
|
2057 |
|
// Patch PowerOff() |
2081 |
|
|
2082 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
2083 |
|
static const uint8 via_int3_dat[] = {0x48, 0xe7, 0xf0, 0xf0, 0x76, 0x01, 0x60, 0x26}; |
2084 |
< |
if ((base = find_rom_data(0x15000, 0x18000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; |
2084 |
> |
if ((base = find_rom_data(0x15000, 0x19000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; |
2085 |
|
D(bug("via_int3 %08lx\n", base)); |
2086 |
|
wp = (uint16 *)(ROM_BASE + base); // CHRP level 1 handler |
2087 |
|
*wp++ = htons(M68K_JMP); |
2173 |
|
M68kRegisters r; |
2174 |
|
uint8 pb[SIZEOF_IOParam]; |
2175 |
|
|
2176 |
+ |
// Install floppy driver |
2177 |
+ |
if (ROMType == ROMTYPE_NEWWORLD) { |
2178 |
+ |
|
2179 |
+ |
// Force installation of floppy driver with NewWorld ROMs |
2180 |
+ |
r.a[0] = ROM_BASE + sony_offset; |
2181 |
+ |
r.d[0] = (uint32)SonyRefNum; |
2182 |
+ |
Execute68kTrap(0xa43d, &r); // DrvrInstallRsrvMem() |
2183 |
+ |
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~SonyRefNum * 4); // Get driver handle from Unit Table |
2184 |
+ |
Execute68kTrap(0xa029, &r); // HLock() |
2185 |
+ |
uint32 dce = ReadMacInt32(r.a[0]); |
2186 |
+ |
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset); |
2187 |
+ |
WriteMacInt16(dce + dCtlFlags, SonyDriverFlags); |
2188 |
+ |
} |
2189 |
+ |
|
2190 |
+ |
#if DISABLE_SCSI && 0 |
2191 |
+ |
// Fake SCSIGlobals |
2192 |
+ |
static const uint8 fake_scsi_globals[32] = {0,}; |
2193 |
+ |
WriteMacInt32(0xc0c, (uint32)fake_scsi_globals); |
2194 |
+ |
#endif |
2195 |
+ |
|
2196 |
|
// Open .Sony driver |
2197 |
|
WriteMacInt8((uint32)pb + ioPermssn, 0); |
2198 |
|
WriteMacInt32((uint32)pb + ioNamePtr, (uint32)"\005.Sony"); |