--- BasiliskII/src/rsrc_patches.cpp 2000/09/22 17:17:56 1.6 +++ BasiliskII/src/rsrc_patches.cpp 2004/01/12 15:29:22 1.12 @@ -1,7 +1,7 @@ /* * rsrc_patches.cpp - Resource patches * - * Basilisk II (C) 1997-2000 Christian Bauer + * Basilisk II (C) 1997-2004 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,14 +37,6 @@ #include "debug.h" -#if !EMULATED_68K -// Assembly functions -extern "C" void Scod060Patch1(void); -extern "C" void Scod060Patch2(void); -extern "C" void ThInitFPUPatch(void); -#endif - - /* * Search resource for byte string, return offset (or 0) */ @@ -68,7 +60,7 @@ void CheckLoad(uint32 type, int16 id, ui { uint16 *p16; uint32 base; - D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %08x, size %d\n", (char)(type >> 24), (char)((type >> 16) & 0xff), (char )((type >> 8) & 0xff), (char )(type & 0xff), type, id, p, size)); + D(bug("vCheckLoad %c%c%c%c (%08x) ID %d, data %p, size %d\n", (char)(type >> 24), (char)((type >> 16) & 0xff), (char )((type >> 8) & 0xff), (char )(type & 0xff), type, id, p, size)); if (type == FOURCC('b','o','o','t') && id == 3) { D(bug(" boot 3 found\n")); @@ -84,13 +76,13 @@ void CheckLoad(uint32 type, int16 id, ui } #if !ROM_IS_WRITE_PROTECTED - // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.5, 8.0) + // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.1, 7.5, 8.0) static const uint8 dat2[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00}; base = find_rsrc_data(p, size, dat2, sizeof(dat2)); if (base) { p16 = (uint16 *)(p + base); -#if defined(AMIGA) || defined(__NetBSD__) || defined(USE_SCRATCHMEM_SUBTERFUGE) +#if defined(USE_SCRATCHMEM_SUBTERFUGE) // Set 0x0000 to scratch memory area extern uint8 *ScratchMem; const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); @@ -109,13 +101,13 @@ void CheckLoad(uint32 type, int16 id, ui } else if (type == FOURCC('b','o','o','t') && id == 2) { D(bug(" boot 2 found\n")); - // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.5, 8.0) + // Set fake handle at 0x0000 to some safe place (so broken Mac programs won't write into Mac ROM) (7.1, 7.5, 8.0) static const uint8 dat[] = {0x20, 0x78, 0x02, 0xae, 0xd1, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x21, 0xc8, 0x00, 0x00}; base = find_rsrc_data(p, size, dat, sizeof(dat)); if (base) { p16 = (uint16 *)(p + base); -#if defined(AMIGA) || defined(__NetBSD__) || defined(USE_SCRATCHMEM_SUBTERFUGE) +#if defined(USE_SCRATCHMEM_SUBTERFUGE) // Set 0x0000 to scratch memory area extern uint8 *ScratchMem; const uint32 ScratchMemBase = Host2MacAddr(ScratchMem); @@ -162,7 +154,7 @@ void CheckLoad(uint32 type, int16 id, ui } else if (type == FOURCC('p','t','c','h') && id == 26) { D(bug(" ptch 26 found\n")); - // Trap ABC4 is initialized with absolute ROM address (7.5, 7.6, 7.6.1, 8.0) + // Trap ABC4 is initialized with absolute ROM address (7.1, 7.5, 7.6, 7.6.1, 8.0) static const uint8 dat[] = {0x40, 0x83, 0x36, 0x10}; base = find_rsrc_data(p, size, dat, sizeof(dat)); if (base) { @@ -197,276 +189,18 @@ void CheckLoad(uint32 type, int16 id, ui D(bug(" patch 2 applied\n")); } -#if !EMULATED_68K - } else if (CPUIs68060 && (type == FOURCC('g','p','c','h') && id == 669 || type == FOURCC('l','p','c','h') && id == 63)) { - D(bug(" gpch 669/lpch 63 found\n")); - - static uint16 ThPatchSpace[1024]; // Replacement routines are constructed here - uint16 *q = ThPatchSpace; - uint32 start; - int i; - - // Patch Thread Manager thread switcher for 68060 FPU (7.5, 8.0) - static const uint8 dat[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x18}; - base = find_rsrc_data(p, size, dat, sizeof(dat)); - if (base) { // Skip first routine (no FPU -> no FPU) - - base = find_rsrc_data(p, size - base - 2, dat, sizeof(dat), base + 2); - if (base) { // no FPU -> FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<28; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?) - *q++ = htons(2); - *q++ = htons(0x6712); // beq - *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it) - *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers) - *q++ = htons(0x9000); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr - *q++ = htons(0x8800); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar - *q++ = htons(0x8400); - *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7 - *q++ = htons(0xd0ff); - *q++ = htons(0xf35f); // frestore (sp)+ - *q++ = htons(0x4e75); // rts - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 1 applied\n")); - - static const uint8 dat2[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x28}; - base = find_rsrc_data(p, size, dat2, sizeof(dat2)); - if (base) { // FPU -> FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<4; i++) *q++ = *p16++; - *q++ = htons(0x6736); // beq - *q++ = htons(0xf327); // fsave -(sp) (save FPU state frame) - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?) - *q++ = htons(2); - *q++ = htons(0x6716); // beq - *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers) - *q++ = htons(0xe0ff); - *q++ = htons(0xf227); // fmove.l fpiar,-(sp) - *q++ = htons(0xa400); - *q++ = htons(0xf227); // fmove.l fpsr,-(sp) - *q++ = htons(0xa800); - *q++ = htons(0xf227); // fmove.l fpcr,-(sp) - *q++ = htons(0xb000); - *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag) - *q++ = htons(0xffff); - *q++ = htons(0xffff); - p16 += 9; - for (i=0; i<23; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?) - *q++ = htons(2); - *q++ = htons(0x6712); // beq - *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it) - *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers) - *q++ = htons(0x9000); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr - *q++ = htons(0x8800); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar - *q++ = htons(0x8400); - *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7 - *q++ = htons(0xd0ff); - *q++ = htons(0xf35f); // frestore (sp)+ - *q++ = htons(0x4e75); // rts - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 2 applied\n")); - - base = find_rsrc_data(p, size - base - 2, dat2, sizeof(dat2), base + 2); - if (base) { // FPU -> no FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<4; i++) *q++ = *p16++; - *q++ = htons(0x6736); // beq - *q++ = htons(0xf327); // fsave -(sp) (save FPU state frame) - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?) - *q++ = htons(2); - *q++ = htons(0x6716); // beq - *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers) - *q++ = htons(0xe0ff); - *q++ = htons(0xf227); // fmove.l fpiar,-(sp) - *q++ = htons(0xa400); - *q++ = htons(0xf227); // fmove.l fpsr,-(sp) - *q++ = htons(0xa800); - *q++ = htons(0xf227); // fmove.l fpcr,-(sp) - *q++ = htons(0xb000); - *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag) - *q++ = htons(0xffff); - *q++ = htons(0xffff); - p16 += 9; - for (i=0; i<24; i++) *q++ = *p16++; - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 3 applied\n")); - } - } - } - } - - // Patch Thread Manager thread switcher for 68060 FPU (additional routines under 8.0 for Mixed Mode Manager) - static const uint8 dat3[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x40}; - base = find_rsrc_data(p, size, dat3, sizeof(dat3)); - if (base) { // Skip first routine (no FPU -> no FPU) - - base = find_rsrc_data(p, size - base - 2, dat3, sizeof(dat3), base + 2); - if (base) { // no FPU -> FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<48; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?) - *q++ = htons(2); - *q++ = htons(0x6712); // beq - *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it) - *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers) - *q++ = htons(0x9000); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr - *q++ = htons(0x8800); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar - *q++ = htons(0x8400); - *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7 - *q++ = htons(0xd0ff); - p16 += 7; - for (i=0; i<20; i++) *q++ = *p16++; - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 4 applied\n")); - - static const uint8 dat4[] = {0x22, 0x6f, 0x00, 0x08, 0x20, 0x2f, 0x00, 0x04, 0x67, 0x50}; - base = find_rsrc_data(p, size, dat4, sizeof(dat4)); - if (base) { // FPU -> FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<4; i++) *q++ = *p16++; - *q++ = htons(0x675e); // beq - p16++; - for (i=0; i<21; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?) - *q++ = htons(2); - *q++ = htons(0x6716); // beq - *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers) - *q++ = htons(0xe0ff); - *q++ = htons(0xf227); // fmove.l fpiar,-(sp) - *q++ = htons(0xa400); - *q++ = htons(0xf227); // fmove.l fpsr,-(sp) - *q++ = htons(0xa800); - *q++ = htons(0xf227); // fmove.l fpcr,-(sp) - *q++ = htons(0xb000); - *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag) - *q++ = htons(0xffff); - *q++ = htons(0xffff); - p16 += 7; - for (i=0; i<23; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state or "FPU state saved" flag set?) - *q++ = htons(2); - *q++ = htons(0x6712); // beq - *q++ = htons(0x588f); // addq.l #2,sp (flag set, skip it) - *q++ = htons(0xf21f); // fmove.l (sp)+,fpcr (restore FPU registers) - *q++ = htons(0x9000); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpsr - *q++ = htons(0x8800); - *q++ = htons(0xf21f); // fmove.l (sp)+,fpiar - *q++ = htons(0x8400); - *q++ = htons(0xf21f); // fmovem.x (sp)+,fp0-fp7 - *q++ = htons(0xd0ff); - p16 += 7; - for (i=0; i<20; i++) *q++ = *p16++; - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 5 applied\n")); - - base = find_rsrc_data(p, size - base - 2, dat4, sizeof(dat4), base + 2); - if (base) { // FPU -> no FPU - - p16 = (uint16 *)(p + base); - start = (uint32)q; - for (i=0; i<4; i++) *q++ = *p16++; - *q++ = htons(0x675e); // beq - p16++; - for (i=0; i<21; i++) *q++ = *p16++; - *q++ = htons(0x4a2f); // tst.b 2(sp) (null FPU state?) - *q++ = htons(2); - *q++ = htons(0x6716); // beq - *q++ = htons(0xf227); // fmovem.x fp0-fp7,-(sp) (no, save FPU registers) - *q++ = htons(0xe0ff); - *q++ = htons(0xf227); // fmove.l fpiar,-(sp) - *q++ = htons(0xa400); - *q++ = htons(0xf227); // fmove.l fpsr,-(sp) - *q++ = htons(0xa800); - *q++ = htons(0xf227); // fmove.l fpcr,-(sp) - *q++ = htons(0xb000); - *q++ = htons(0x4879); // pea -1 (push "FPU state saved" flag) - *q++ = htons(0xffff); - *q++ = htons(0xffff); - p16 += 7; - for (i=0; i<42; i++) *q++ = *p16++; - - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons(start >> 16); - *p16 = htons(start & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 6 applied\n")); - } - } - } - } - - FlushCodeCache(ThPatchSpace, 1024); - - // Patch Thread Manager FPU init for 68060 FPU (7.5, 8.0) - static const uint8 dat5[] = {0x4a, 0x28, 0x00, 0xa4, 0x67, 0x0a, 0x4a, 0x2c, 0x00, 0x40}; - base = find_rsrc_data(p, size, dat5, sizeof(dat5)); - if (base) { - p16 = (uint16 *)(p + base + 6); - *p16++ = htons(M68K_JSR); - *p16++ = htons((uint32)ThInitFPUPatch >> 16); - *p16++ = htons((uint32)ThInitFPUPatch & 0xffff); - *p16++ = htons(M68K_NOP); - *p16 = htons(M68K_NOP); - FlushCodeCache(p + base + 6, 10); - D(bug(" patch 7 applied\n")); - } -#endif - } else if (type == FOURCC('g','p','c','h') && id == 750) { D(bug(" gpch 750 found\n")); // Don't use PTEST instruction in BlockMove() (7.5, 7.6, 7.6.1, 8.0) - static const uint8 dat[] = {0xa0, 0x8d, 0x0c, 0x81, 0x00, 0x00, 0x0c, 0x00, 0x65, 0x06, 0x4e, 0x71, 0xf4, 0xf8}; + static const uint8 dat[] = {0x20, 0x5f, 0x22, 0x5f, 0x0c, 0x38, 0x00, 0x04, 0x01, 0x2f}; base = find_rsrc_data(p, size, dat, sizeof(dat)); if (base) { - p16 = (uint16 *)(p + base + 8); - *p16 = htons(M68K_NOP); - FlushCodeCache(p + base + 8, 2); + p16 = (uint16 *)(p + base + 4); + *p16++ = htons(M68K_EMUL_OP_BLOCK_MOVE); + *p16++ = htons(0x7000); + *p16 = htons(M68K_RTS); + FlushCodeCache(p + base + 4, 6); D(bug(" patch 1 applied\n")); } @@ -512,35 +246,6 @@ void CheckLoad(uint32 type, int16 id, ui D(bug(" patch 2 applied\n")); } -#if !EMULATED_68K - } else if (CPUIs68060 && type == FOURCC('s','c','o','d') && (id == -16463 || id == -16464)) { - D(bug(" scod -16463/-16464 found\n")); - - // Correct 68060 FP frame handling in Process Manager task switches (7.1, 7.5, 8.0) - static const uint8 dat[] = {0xf3, 0x27, 0x4a, 0x17}; - base = find_rsrc_data(p, size, dat, sizeof(dat)); - if (base) { - p16 = (uint16 *)(p + base); - *p16++ = htons(M68K_JMP); - *p16++ = htons((uint32)Scod060Patch1 >> 16); - *p16 = htons((uint32)Scod060Patch1 & 0xffff); - FlushCodeCache(p + base, 6); - D(bug(" patch 1 applied\n")); - } - - // Even a null FP frame is 3 longwords on the 68060 (7.1, 7.5, 8.0) - static const uint8 dat2[] = {0xf3, 0x5f, 0x4e, 0x75}; - base = find_rsrc_data(p, size, dat2, sizeof(dat2)); - if (base) { - p16 = (uint16 *)(p + base - 2); - *p16++ = htons(M68K_JMP); - *p16++ = htons((uint32)Scod060Patch2 >> 16); - *p16 = htons((uint32)Scod060Patch2 & 0xffff); - FlushCodeCache(p + base - 2, 6); - D(bug(" patch 2 applied\n")); - } -#endif - } else if (type == FOURCC('t','h','n','g') && id == -16563) { D(bug(" thng -16563 found\n"));