successfully generates a "return 0xffff" instruction on 68k and testable on mac

This commit is contained in:
Matthew Laux 2023-10-19 00:14:58 -05:00
parent d69a3b35f1
commit ce66b5ba3a
5 changed files with 34 additions and 19 deletions

View File

@ -17,3 +17,8 @@ add_application(Emulator
lcd_mac.c lcd_mac.c
resources.r resources.r
) )
add_application(CompilerTest
compiler68k.c
CONSOLE
)

View File

@ -2,8 +2,11 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef USE_MPROTECT
#include <sys/mman.h> // mprotect #include <sys/mman.h> // mprotect
#include <unistd.h> // getpagesize #include <unistd.h> // getpagesize
#endif
// A -> D0 // A -> D0
// BC -> D1 // BC -> D1
@ -64,13 +67,12 @@ struct basic_block *compile_block(uint16_t src_address, uint8_t *gb_code)
} }
} }
bblock->length = 6; bblock->length = 4;
bblock->code[0] = 0xb8; // mov eax, 1234h // bblock->code[0] = 0xc3;
bblock->code[1] = 0x34; bblock->code[0] = 0x70; // moveq #$ff, d0
bblock->code[2] = 0x12; bblock->code[1] = 0xff;
bblock->code[3] = 0x00; bblock->code[2] = 0x4e; // rts
bblock->code[4] = 0x00; bblock->code[3] = 0x75;
bblock->code[5] = 0xc3; // ret
return bblock; return bblock;
} }
@ -114,6 +116,7 @@ void run_all(uint8_t *gb_code)
} }
// for testing... // for testing...
#ifdef USE_MPROTECT
page_size = getpagesize(); page_size = getpagesize();
ret = mprotect( ret = mprotect(
(void *) ((uint64_t) bblock & ~(page_size - 1)), (void *) ((uint64_t) bblock & ~(page_size - 1)),
@ -124,7 +127,13 @@ void run_all(uint8_t *gb_code)
perror("mprotect"); perror("mprotect");
exit(0); exit(0);
} }
#endif
// __builtin___clear_cache(bblock, bblock + sizeof *bblock);
asm("":::"memory");
jump_target = ((uint16_t (*)()) bblock->code)(); jump_target = ((uint16_t (*)()) bblock->code)();
if (jump_target == 0xffff) {
break;
}
} }
} }
@ -152,5 +161,7 @@ int main(int argc, char *argv[])
free(data); free(data);
} }
while(1);
return 0; return 0;
} }

View File

@ -85,13 +85,13 @@ void Render(void)
SetPort(g_wp); SetPort(g_wp);
// CopyBits(&offscreenBmp, &g_wp->portBits, &offscreenRect, &offscreenRect, srcCopy, NULL); // CopyBits(&offscreenBmp, &g_wp->portBits, &offscreenRect, &offscreenRect, srcCopy, NULL);
EraseRect(&g_wp->portRect); // EraseRect(&g_wp->portRect);
MoveTo(10, 180); // MoveTo(10, 180);
char debug[128]; // char debug[128];
double ms = execTime / 600.0; // double ms = execTime / 600.0;
sprintf(debug, "10000 in %d ticks, %.2f ms per instruction", execTime, ms); // sprintf(debug, "10000 in %d ticks, %.2f ms per instruction", execTime, ms);
C2PStr(debug); // C2PStr(debug);
DrawString(debug); // DrawString(debug);
} }
// 417 ticks // 417 ticks
@ -121,7 +121,7 @@ void StartEmulation(void)
emulationOn = 1; emulationOn = 1;
} }
bool LoadRom(StrFileName fileName, short vRefNum) bool LoadRom(Str255 fileName, short vRefNum)
{ {
int err; int err;
short fileNo; short fileNo;

View File

@ -37,8 +37,4 @@
#define EMULATION_PREFERENCES 4 #define EMULATION_PREFERENCES 4
#define EMULATION_KEY_MAPPINGS 5 #define EMULATION_KEY_MAPPINGS 5
typedef unsigned char bool;
#define true 1
#define false 0
#endif #endif

3
test-compiler.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
cc -DUSE_MPROTECT -o compiler system6/compiler68k.c