From ce66b5ba3a785a49a98c776c40ec170f36cc3326 Mon Sep 17 00:00:00 2001 From: Matthew Laux Date: Thu, 19 Oct 2023 00:14:58 -0500 Subject: [PATCH] successfully generates a "return 0xffff" instruction on 68k and testable on mac --- system6/CMakeLists.txt | 5 +++++ {src => system6}/compiler68k.c | 25 ++++++++++++++++++------- system6/emulator.c | 16 ++++++++-------- system6/emulator.h | 4 ---- test-compiler.sh | 3 +++ 5 files changed, 34 insertions(+), 19 deletions(-) rename {src => system6}/compiler68k.c (88%) create mode 100755 test-compiler.sh diff --git a/system6/CMakeLists.txt b/system6/CMakeLists.txt index 53d87bf..a60846e 100644 --- a/system6/CMakeLists.txt +++ b/system6/CMakeLists.txt @@ -17,3 +17,8 @@ add_application(Emulator lcd_mac.c resources.r ) + +add_application(CompilerTest + compiler68k.c + CONSOLE +) \ No newline at end of file diff --git a/src/compiler68k.c b/system6/compiler68k.c similarity index 88% rename from src/compiler68k.c rename to system6/compiler68k.c index b9e29f7..a0a3202 100644 --- a/src/compiler68k.c +++ b/system6/compiler68k.c @@ -2,8 +2,11 @@ #include #include #include + +#ifdef USE_MPROTECT #include // mprotect #include // getpagesize +#endif // A -> D0 // BC -> D1 @@ -64,13 +67,12 @@ struct basic_block *compile_block(uint16_t src_address, uint8_t *gb_code) } } - bblock->length = 6; - bblock->code[0] = 0xb8; // mov eax, 1234h - bblock->code[1] = 0x34; - bblock->code[2] = 0x12; - bblock->code[3] = 0x00; - bblock->code[4] = 0x00; - bblock->code[5] = 0xc3; // ret + bblock->length = 4; + // bblock->code[0] = 0xc3; + bblock->code[0] = 0x70; // moveq #$ff, d0 + bblock->code[1] = 0xff; + bblock->code[2] = 0x4e; // rts + bblock->code[3] = 0x75; return bblock; } @@ -114,6 +116,7 @@ void run_all(uint8_t *gb_code) } // for testing... +#ifdef USE_MPROTECT page_size = getpagesize(); ret = mprotect( (void *) ((uint64_t) bblock & ~(page_size - 1)), @@ -124,7 +127,13 @@ void run_all(uint8_t *gb_code) perror("mprotect"); exit(0); } +#endif + // __builtin___clear_cache(bblock, bblock + sizeof *bblock); + asm("":::"memory"); jump_target = ((uint16_t (*)()) bblock->code)(); + if (jump_target == 0xffff) { + break; + } } } @@ -152,5 +161,7 @@ int main(int argc, char *argv[]) free(data); } + while(1); + return 0; } \ No newline at end of file diff --git a/system6/emulator.c b/system6/emulator.c index ea1646b..1edde18 100644 --- a/system6/emulator.c +++ b/system6/emulator.c @@ -85,13 +85,13 @@ void Render(void) SetPort(g_wp); // CopyBits(&offscreenBmp, &g_wp->portBits, &offscreenRect, &offscreenRect, srcCopy, NULL); - EraseRect(&g_wp->portRect); - MoveTo(10, 180); - char debug[128]; - double ms = execTime / 600.0; - sprintf(debug, "10000 in %d ticks, %.2f ms per instruction", execTime, ms); - C2PStr(debug); - DrawString(debug); + // EraseRect(&g_wp->portRect); + // MoveTo(10, 180); + // char debug[128]; + // double ms = execTime / 600.0; + // sprintf(debug, "10000 in %d ticks, %.2f ms per instruction", execTime, ms); + // C2PStr(debug); + // DrawString(debug); } // 417 ticks @@ -121,7 +121,7 @@ void StartEmulation(void) emulationOn = 1; } -bool LoadRom(StrFileName fileName, short vRefNum) +bool LoadRom(Str255 fileName, short vRefNum) { int err; short fileNo; diff --git a/system6/emulator.h b/system6/emulator.h index a0a819f..0d8cf37 100644 --- a/system6/emulator.h +++ b/system6/emulator.h @@ -37,8 +37,4 @@ #define EMULATION_PREFERENCES 4 #define EMULATION_KEY_MAPPINGS 5 -typedef unsigned char bool; -#define true 1 -#define false 0 - #endif \ No newline at end of file diff --git a/test-compiler.sh b/test-compiler.sh new file mode 100755 index 0000000..b8bfacc --- /dev/null +++ b/test-compiler.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cc -DUSE_MPROTECT -o compiler system6/compiler68k.c \ No newline at end of file