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" |
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 |
125 |
|
D(bug("Offset Type Name\n")); |
126 |
|
while (parcel_offset != 0) { |
127 |
|
const uint32 *parcel_data = (uint32 *)(src + parcel_offset); |
128 |
< |
parcel_offset = ntohl(parcel_data[0]); |
128 |
> |
uint32 next_offset = ntohl(parcel_data[0]); |
129 |
|
uint32 parcel_type = ntohl(parcel_data[1]); |
130 |
|
D(bug("%08x %c%c%c%c %s\n", parcel_offset, |
131 |
|
(parcel_type >> 24) & 0xff, (parcel_type >> 16) & 0xff, |
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; |
139 |
|
} |
140 |
|
} |
141 |
|
|
448 |
|
0x4e, 0x75 // rts |
449 |
|
}; |
450 |
|
|
451 |
< |
#ifdef __linux__ |
450 |
< |
static uint32 serial_nothing_tvect[2] = {(uint32)SerialNothing, 0}; |
451 |
< |
static uint32 serial_open_tvect[2] = {(uint32)SerialOpen, 0}; |
452 |
< |
static uint32 serial_prime_in_tvect[2] = {(uint32)SerialPrimeIn, 0}; |
453 |
< |
static uint32 serial_prime_out_tvect[2] = {(uint32)SerialPrimeOut, 0}; |
454 |
< |
static uint32 serial_control_tvect[2] = {(uint32)SerialControl, 0}; |
455 |
< |
static uint32 serial_status_tvect[2] = {(uint32)SerialStatus, 0}; |
456 |
< |
static uint32 serial_close_tvect[2] = {(uint32)SerialClose, 0}; |
457 |
< |
#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 __linux__ |
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 __linux__ |
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 __linux__ |
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 __linux__ |
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 __linux__ |
499 |
< |
0x00010004, (uint32)serial_nothing_tvect, |
500 |
< |
#else |
501 |
< |
0x00010004, (uint32)SerialNothing, |
502 |
< |
#endif |
503 |
< |
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 __linux__ |
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 __linux__ |
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 __linux__ |
519 |
< |
0x00010004, (uint32)serial_control_tvect, |
520 |
< |
#else |
521 |
< |
0x00010004, (uint32)SerialControl, |
522 |
< |
#endif |
523 |
< |
0x00000000, 0x00000000, |
535 |
< |
0xaafe0700, 0x00000000, |
536 |
< |
0x00000000, 0x00179822, |
537 |
< |
#ifdef __linux__ |
538 |
< |
0x00010004, (uint32)serial_status_tvect, |
539 |
< |
#else |
540 |
< |
0x00010004, (uint32)SerialStatus, |
541 |
< |
#endif |
542 |
< |
0x00000000, 0x00000000, |
543 |
< |
0xaafe0700, 0x00000000, |
544 |
< |
0x00000000, 0x00179822, |
545 |
< |
#ifdef __linux__ |
546 |
< |
0x00010004, (uint32)serial_close_tvect, |
547 |
< |
#else |
548 |
< |
0x00010004, (uint32)SerialClose, |
549 |
< |
#endif |
550 |
< |
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 __linux__ |
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 __linux__ |
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 __linux__ |
550 |
< |
0x00010004, (uint32)serial_control_tvect, |
551 |
< |
#else |
552 |
< |
0x00010004, (uint32)SerialControl, |
553 |
< |
#endif |
554 |
< |
0x00000000, 0x00000000, |
582 |
< |
0xaafe0700, 0x00000000, |
583 |
< |
0x00000000, 0x00179822, |
584 |
< |
#ifdef __linux__ |
585 |
< |
0x00010004, (uint32)serial_status_tvect, |
586 |
< |
#else |
587 |
< |
0x00010004, (uint32)SerialStatus, |
588 |
< |
#endif |
589 |
< |
0x00000000, 0x00000000, |
590 |
< |
0xaafe0700, 0x00000000, |
591 |
< |
0x00000000, 0x00179822, |
592 |
< |
#ifdef __linux__ |
593 |
< |
0x00010004, (uint32)serial_nothing_tvect, |
594 |
< |
#else |
595 |
< |
0x00010004, (uint32)SerialNothing, |
596 |
< |
#endif |
597 |
< |
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 __linux__ |
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 __linux__ |
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 __linux__ |
581 |
< |
0x00010004, (uint32)serial_control_tvect, |
582 |
< |
#else |
583 |
< |
0x00010004, (uint32)SerialControl, |
584 |
< |
#endif |
585 |
< |
0x00000000, 0x00000000, |
629 |
< |
0xaafe0700, 0x00000000, |
630 |
< |
0x00000000, 0x00179822, |
631 |
< |
#ifdef __linux__ |
632 |
< |
0x00010004, (uint32)serial_status_tvect, |
633 |
< |
#else |
634 |
< |
0x00010004, (uint32)SerialStatus, |
635 |
< |
#endif |
636 |
< |
0x00000000, 0x00000000, |
637 |
< |
0xaafe0700, 0x00000000, |
638 |
< |
0x00000000, 0x00179822, |
639 |
< |
#ifdef __linux__ |
640 |
< |
0x00010004, (uint32)serial_close_tvect, |
641 |
< |
#else |
642 |
< |
0x00010004, (uint32)SerialClose, |
643 |
< |
#endif |
644 |
< |
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 |
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 |
|
|
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; |
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]); |
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 |
|
|
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) |
884 |
|
lp = (uint32 *)(ROM_BASE + 0x3131f4); |
885 |
|
if (ntohl(*lp) == 0x7e5f42a6) // NewWorld ROM |
886 |
|
*lp = htonl(0x82400000 + XLM_PVR); // lwz r18,(theoretical PVR) |
887 |
+ |
lp = (uint32 *)(ROM_BASE + 0x314600); |
888 |
+ |
if (ntohl(*lp) == 0x7d3f42a6) |
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); |
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) |
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) |
999 |
|
*lp = htonl(POWERPC_ILLEGAL); |
1000 |
|
|
1001 |
|
#if EMULATED_PPC |
1002 |
< |
// Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes |
1002 |
> |
// Install EMUL_RETURN, EXEC_RETURN, EXEC_NATIVE and EMUL_OP opcodes |
1003 |
|
lp = (uint32 *)(ROM_BASE + 0x380000 + (M68K_EMUL_RETURN << 3)); |
1004 |
|
*lp++ = htonl(POWERPC_EMUL_OP); |
1005 |
|
*lp++ = htonl(0x4bf66e80); // b 0x366084 |
1006 |
|
*lp++ = htonl(POWERPC_EMUL_OP | 1); |
1007 |
|
*lp++ = htonl(0x4bf66e78); // b 0x366084 |
1008 |
+ |
*lp++ = htonl(POWERPC_EMUL_OP | 2); |
1009 |
+ |
*lp++ = htonl(0x4bf66e70); // b 0x366084 |
1010 |
|
for (int i=0; i<OP_MAX; i++) { |
1011 |
< |
*lp++ = htonl(POWERPC_EMUL_OP | (i + 2)); |
1012 |
< |
*lp++ = htonl(0x4bf66e70 - i*8); // b 0x366084 |
1011 |
> |
*lp++ = htonl(POWERPC_EMUL_OP | (i + 3)); |
1012 |
> |
*lp++ = htonl(0x4bf66e68 - i*8); // b 0x366084 |
1013 |
|
} |
1014 |
|
#else |
1015 |
|
// Install EMUL_RETURN, EXEC_RETURN and EMUL_OP opcodes |
1018 |
|
*lp++ = htonl(0x4bf705fc); // b 0x36f800 |
1019 |
|
*lp++ = htonl(0x80000000 + XLM_EXEC_RETURN_PROC); // lwz r0,XLM_EXEC_RETURN_PROC |
1020 |
|
*lp++ = htonl(0x4bf705f4); // b 0x36f800 |
1021 |
+ |
*lp++ = htonl(0x00dead00); // Let SheepShaver crash, since |
1022 |
+ |
*lp++ = htonl(0x00beef00); // no native opcode is available |
1023 |
|
for (int i=0; i<OP_MAX; i++) { |
1024 |
|
*lp++ = htonl(0x38a00000 + i); // li r5,OP_* |
1025 |
< |
*lp++ = htonl(0x4bf705f4 - i*8); // b 0x36f808 |
1025 |
> |
*lp++ = htonl(0x4bf705ec - i*8); // b 0x36f808 |
1026 |
|
} |
1027 |
|
|
1028 |
|
// Extra routines for EMUL_RETURN/EXEC_RETURN/EMUL_OP |
1038 |
|
// Extra routine for 68k emulator start |
1039 |
|
lp = (uint32 *)(ROM_BASE + 0x36f900); |
1040 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1041 |
+ |
#if EMULATED_PPC |
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 |
1046 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1047 |
+ |
#endif |
1048 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1049 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1050 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1072 |
|
// Extra routine for Mixed Mode |
1073 |
|
lp = (uint32 *)(ROM_BASE + 0x36fa00); |
1074 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1075 |
+ |
#if EMULATED_PPC |
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 |
1080 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1081 |
+ |
#endif |
1082 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1083 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1084 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1104 |
|
*lp = htonl(0x4e800020); // blr |
1105 |
|
|
1106 |
|
// Extra routine for Reset/FC1E opcode |
1107 |
< |
lp = (uint32 *)(ROM_BASE + 0x36fc00); |
1107 |
> |
lp = (uint32 *)(ROM_BASE + 0x36fb00); |
1108 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1109 |
+ |
#if EMULATED_PPC |
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 |
1114 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1115 |
+ |
#endif |
1116 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1117 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1118 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1129 |
|
*lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) |
1130 |
|
*lp++ = htonl(0x7d8802a6); // mflr r12 |
1131 |
|
*lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 |
1132 |
< |
*lp++ = htonl(0x814105f4); // lwz r10,0x05f8(r1) |
1132 |
> |
*lp++ = htonl(0x814105f8); // lwz r10,0x05f8(r1) |
1133 |
|
*lp++ = htonl(0x7d4803a6); // mtlr r10 |
1134 |
|
*lp++ = htonl(0x7d8a6378); // mr r10,r12 |
1135 |
|
*lp++ = htonl(0x3d600002); // lis r11,0x0002 |
1140 |
|
// Extra routine for FE0A opcode (QuickDraw 3D needs this) |
1141 |
|
lp = (uint32 *)(ROM_BASE + 0x36fc00); |
1142 |
|
*lp++ = htonl(0x7c2903a6); // mtctr r1 |
1143 |
+ |
#if EMULATED_PPC |
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 |
1148 |
|
*lp++ = htonl(0x90200000 + XLM_IRQ_NEST); // stw r1,XLM_IRQ_NEST |
1149 |
+ |
#endif |
1150 |
|
*lp++ = htonl(0x80200000 + XLM_KERNEL_DATA);// lwz r1,XLM_KERNEL_DATA |
1151 |
|
*lp++ = htonl(0x90c10018); // stw r6,0x18(r1) |
1152 |
|
*lp++ = htonl(0x7cc902a6); // mfctr r6 |
1163 |
|
*lp++ = htonl(0x80e10660); // lwz r7,$0660(r1) |
1164 |
|
*lp++ = htonl(0x7d8802a6); // mflr r12 |
1165 |
|
*lp++ = htonl(0x50e74001); // rlwimi. r7,r7,8,$80000000 |
1166 |
< |
*lp++ = htonl(0x814105f4); // lwz r10,0x05fc(r1) |
1166 |
> |
*lp++ = htonl(0x814105fc); // lwz r10,0x05fc(r1) |
1167 |
|
*lp++ = htonl(0x7d4803a6); // mtlr r10 |
1168 |
|
*lp++ = htonl(0x7d8a6378); // mr r10,r12 |
1169 |
|
*lp++ = htonl(0x3d600002); // lis r11,0x0002 |
1281 |
|
*lp = htonl(POWERPC_BCTR); |
1282 |
|
|
1283 |
|
lp = (uint32 *)(ROM_BASE + 0x318000); |
1284 |
+ |
#if EMULATED_PPC |
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 |
1289 |
|
*lp++ = htonl(0x394affff); // subi r10,r10,1 |
1290 |
|
*lp++ = htonl(0x91400000 + XLM_IRQ_NEST); // stw r10,XLM_IRQ_NEST |
1291 |
|
*lp = htonl(0x48000000 + ((xlp - 0x800c) & 0x03fffffc)); // b ROM_BASE+0x312c2c |
1292 |
+ |
#endif |
1293 |
+ |
|
1294 |
|
/* |
1295 |
|
// Disable FE0A/FE06 opcodes |
1296 |
|
lp = (uint32 *)(ROM_BASE + 0x3144ac); |
1336 |
|
// Patch UniversalInfo |
1337 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
1338 |
|
static const uint8 univ_info_dat[] = {0x3f, 0xff, 0x04, 0x00}; |
1339 |
< |
if ((base = find_rom_data(0x14000, 0x16000, univ_info_dat, sizeof(univ_info_dat))) == 0) return false; |
1339 |
> |
if ((base = find_rom_data(0x14000, 0x18000, univ_info_dat, sizeof(univ_info_dat))) == 0) return false; |
1340 |
|
D(bug("universal_info %08lx\n", base)); |
1341 |
|
lp = (uint32 *)(ROM_BASE + base - 0x14); |
1342 |
|
lp[0x00 >> 2] = htonl(ADDR_MAP_PATCH_SPACE - (base - 0x14)); |
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); |
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); |
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); |
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); |
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); |
1735 |
|
|
1736 |
|
// Patch GetCPUSpeed (via 0x27a) (some ROMs have two of them) |
1737 |
|
static const uint8 cpu_speed_dat[] = {0x20, 0x30, 0x81, 0xf2, 0x5f, 0xff, 0xef, 0xd8, 0x00, 0x04, 0x4c, 0x7c}; |
1738 |
< |
if ((base = find_rom_data(0x6000, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; |
1738 |
> |
if ((base = find_rom_data(0x6000, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) == 0) return false; |
1739 |
|
D(bug("cpu_speed %08lx\n", base)); |
1740 |
|
wp = (uint16 *)(ROM_BASE + base); |
1741 |
|
*wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 |
1742 |
|
*wp++ = htons(CPUClockSpeed / 1000000); |
1743 |
|
*wp++ = htons(CPUClockSpeed / 1000000); |
1744 |
|
*wp = htons(M68K_RTS); |
1745 |
< |
if ((base = find_rom_data(base, 0x9000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { |
1745 |
> |
if ((base = find_rom_data(base, 0xa000, cpu_speed_dat, sizeof(cpu_speed_dat))) != 0) { |
1746 |
|
D(bug("cpu_speed2 %08lx\n", base)); |
1747 |
|
wp = (uint16 *)(ROM_BASE + base); |
1748 |
|
*wp++ = htons(0x203c); // move.l #(MHz<<16)|MHz,d0 |
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); |
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}; |
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; |
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 |
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; |
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 { |
2055 |
|
wp = (uint16 *)(ROM_BASE + base); |
2056 |
|
if (ROMType == ROMTYPE_ZANZIBAR) |
2057 |
|
*wp = htons(M68K_RTS); |
2058 |
< |
else |
2058 |
> |
else if (ntohs(wp[-4]) == 0x61ff) |
2059 |
> |
*wp = htons(M68K_RTS); |
2060 |
> |
else if (ntohs(wp[-2]) == 0x6700) |
2061 |
|
wp[-2] = htons(0x6000); // bra |
2062 |
|
|
2063 |
|
// Patch PowerOff() |
2087 |
|
|
2088 |
|
if (ROMType == ROMTYPE_NEWWORLD) { |
2089 |
|
static const uint8 via_int3_dat[] = {0x48, 0xe7, 0xf0, 0xf0, 0x76, 0x01, 0x60, 0x26}; |
2090 |
< |
if ((base = find_rom_data(0x15000, 0x18000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; |
2090 |
> |
if ((base = find_rom_data(0x15000, 0x19000, via_int3_dat, sizeof(via_int3_dat))) == 0) return false; |
2091 |
|
D(bug("via_int3 %08lx\n", base)); |
2092 |
|
wp = (uint16 *)(ROM_BASE + base); // CHRP level 1 handler |
2093 |
|
*wp++ = htons(M68K_JMP); |
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 || ROMType == ROMTYPE_GOSSAMER) { |
2185 |
> |
|
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() |
2190 |
> |
r.a[0] = ReadMacInt32(ReadMacInt32(0x11c) + ~SonyRefNum * 4); // Get driver handle from Unit Table |
2191 |
> |
Execute68kTrap(0xa029, &r); // HLock() |
2192 |
> |
uint32 dce = ReadMacInt32(r.a[0]); |
2193 |
> |
WriteMacInt32(dce + dCtlDriver, ROM_BASE + sony_offset); |
2194 |
> |
WriteMacInt16(dce + dCtlFlags, SonyDriverFlags); |
2195 |
> |
} |
2196 |
> |
|
2197 |
> |
#if DISABLE_SCSI && 0 |
2198 |
> |
// Fake SCSIGlobals |
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 |
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 |
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 |
|
|