summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2014-02-18 21:37:31 -0800
committerMichael Pavone <pavone@retrodev.com>2014-02-18 21:37:31 -0800
commitc2366d61ff6e228cb3242993d457ff115cd98c91 (patch)
treed14bfc4716ac2579100486649b087884b8cc9aba
parent9b5ed199e364fb84165a2616434849f63226b8d0 (diff)
Initial work on the x86-32 target
-rw-r--r--Makefile26
-rw-r--r--blastem.c11
-rw-r--r--debug.c6
-rw-r--r--gdb_remote.c2
-rw-r--r--m68k_to_x86.c37
5 files changed, 66 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index d9e142e..cfa28c0 100644
--- a/Makefile
+++ b/Makefile
@@ -3,11 +3,11 @@ LIBS=sdl
else
LIBS=sdl glew gl
endif
-LDFLAGS=-lm `pkg-config --libs $(LIBS)`
+LDFLAGS:=-lm $(shell pkg-config --libs $(LIBS))
ifdef DEBUG
-CFLAGS=-ggdb -std=gnu99 `pkg-config --cflags-only-I $(LIBS)` -Wreturn-type -Werror=return-type
+CFLAGS:=-ggdb -std=gnu99 $(shell pkg-config --cflags-only-I $(LIBS)) -Wreturn-type -Werror=return-type
else
-CFLAGS=-O2 -std=gnu99 `pkg-config --cflags-only-I $(LIBS)` -Wreturn-type -Werror=return-type
+CFLAGS:=-O2 -std=gnu99 $(shell pkg-config --cflags-only-I $(LIBS)) -Wreturn-type -Werror=return-type
endif
ifdef PROFILE
@@ -18,16 +18,32 @@ ifdef NOGL
CFLAGS+= -DDISABLE_OPENGL
endif
+ifndef CPU
+CPU:=$(shell uname -m)
+endif
+
TRANSOBJS=gen_x86.o x86_backend.o mem.o
M68KOBJS=68kinst.o m68k_to_x86.o runtime.o
Z80OBJS=z80inst.o z80_to_x86.o zruntime.o
AUDIOOBJS=ym2612.o psg.o wave.o
CONFIGOBJS=config.o tern.o util.o
+MAINOBJS=blastem.o debug.o gdb_remote.o vdp.o render_sdl.o io.o $(CONFIGOBJS) gst.o $(M68KOBJS) $(TRANSOBJS) $(AUDIOOBJS)
+
+ifeq ($(CPU),x86_64)
+CFLAGS+=-DX86_64
+MAINOBJS+= $(Z80OBJS)
+else
+ifeq ($(CPU),i686)
+CFLAGS+=-DX86_32
+endif
+endif
+
+
all : dis zdis stateview vgmplay blastem
-blastem : blastem.o debug.o gdb_remote.o vdp.o render_sdl.o io.o $(CONFIGOBJS) gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS)
- $(CC) -ggdb -o blastem blastem.o debug.o gdb_remote.o vdp.o render_sdl.o io.o $(CONFIGOBJS) gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS) $(LDFLAGS)
+blastem : $(MAINOBJS)
+ $(CC) -ggdb -o blastem $(MAINOBJS) $(LDFLAGS)
dis : dis.o 68kinst.o
$(CC) -o dis dis.o 68kinst.o
diff --git a/blastem.c b/blastem.c
index c4072e3..d3b48d2 100644
--- a/blastem.c
+++ b/blastem.c
@@ -182,6 +182,7 @@ uint8_t new_busack = 0;
void sync_z80(z80_context * z_context, uint32_t mclks)
{
+#ifdef X86_64
if (z80_enabled && !reset && !busreq) {
genesis_context * gen = z_context->system;
z_context->sync_cycle = mclks / MCLKS_PER_Z80;
@@ -201,7 +202,9 @@ void sync_z80(z80_context * z_context, uint32_t mclks)
dprintf("Z80 ran to cycle %d\n", z_context->current_cycle);
}
}
- } else {
+ } else
+#endif
+ {
z_context->current_cycle = mclks / MCLKS_PER_Z80;
}
}
@@ -469,7 +472,9 @@ m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value
location &= 0x7FFF;
if (location < 0x4000) {
z80_ram[location & 0x1FFF] = value;
+#ifdef X86_64
z80_handle_code_write(location & 0x1FFF, gen->z80);
+#endif
} else if (location < 0x6000) {
sync_sound(gen, context->current_cycle * MCLKS_PER_68K);
if (location & 1) {
@@ -986,7 +991,9 @@ void init_run_cpu(genesis_context * gen, FILE * address_log, char * statefile, u
insert_breakpoint(&context, pc, debugger);
}
adjust_int_cycle(gen->m68k, gen->vdp);
+#ifdef X86_64
gen->z80->native_pc = z80_get_native_address_trans(gen->z80, gen->z80->pc);
+#endif
start_68k_context(&context, pc);
} else {
if (debugger) {
@@ -1231,8 +1238,10 @@ int main(int argc, char ** argv)
z80_context z_context;
x86_z80_options z_opts;
+#ifdef X86_64
init_x86_z80_opts(&z_opts);
init_z80_context(&z_context, &z_opts);
+#endif
z_context.system = &gen;
z_context.mem_pointers[0] = z80_ram;
diff --git a/debug.c b/debug.c
index aa0cb7f..b3d1aca 100644
--- a/debug.c
+++ b/debug.c
@@ -82,6 +82,8 @@ void strip_nl(char * buf)
}
}
+#ifdef X86_64
+
void zdebugger_print(z80_context * context, char format_char, char * param)
{
uint32_t value;
@@ -460,6 +462,8 @@ z80_context * zdebugger(z80_context * context, uint16_t address)
return context;
}
+#endif
+
m68k_context * debugger(m68k_context * context, uint32_t address)
{
static char last_cmd[1024];
@@ -701,6 +705,7 @@ m68k_context * debugger(m68k_context * context, uint32_t address)
}
break;
}
+#ifdef X86_64
case 'z': {
genesis_context * gen = context->system;
//Z80 debug commands
@@ -731,6 +736,7 @@ m68k_context * debugger(m68k_context * context, uint32_t address)
}
break;
}
+#endif
case 'q':
puts("Quitting");
exit(0);
diff --git a/gdb_remote.c b/gdb_remote.c
index bf4d0f6..11070f8 100644
--- a/gdb_remote.c
+++ b/gdb_remote.c
@@ -145,7 +145,9 @@ void write_byte(m68k_context * context, uint32_t address, uint8_t value)
} else if (address >= 0xA00000 && address < 0xA04000) {
z80_ram[address & 0x1FFF] = value;
genesis_context * gen = context->system;
+#ifdef X86_64
z80_handle_code_write(address & 0x1FFF, gen->z80);
+#endif
return;
} else {
return;
diff --git a/m68k_to_x86.c b/m68k_to_x86.c
index aef8116..6f1826f 100644
--- a/m68k_to_x86.c
+++ b/m68k_to_x86.c
@@ -15,18 +15,18 @@
#define BUS 4
#define PREDEC_PENALTY 2
+
#define CYCLES RAX
#define LIMIT RBP
+#define CONTEXT RSI
#define SCRATCH1 RCX
+
+#ifdef X86_64
#define SCRATCH2 RDI
-#define CONTEXT RSI
+#else
+#define SCRATCH2 RBX
+#endif
-/*
-#define FLAG_N RBX
-#define FLAG_V BH
-#define FLAG_Z RDX
-#define FLAG_C DH
-*/
enum {
FLAG_X,
FLAG_N,
@@ -4380,7 +4380,9 @@ uint8_t * gen_mem_fun(x86_68k_options * opts, memmap_chunk * memmap, uint32_t nu
dst = jcc(dst, CC_NZ, dst+2);
dst = call(dst, opts->save_context);
if (is_write) {
- //SCRATCH2 is RDI, so no need to move it there
+ if (SCRATCH2 != RDI) {
+ dst = mov_rr(dst, SCRATCH2, RDI, SZ_D);
+ }
dst = mov_rr(dst, SCRATCH1, RDX, size);
} else {
dst = push_r(dst, CONTEXT);
@@ -4483,7 +4485,9 @@ uint8_t * gen_mem_fun(x86_68k_options * opts, memmap_chunk * memmap, uint32_t nu
} else if (cfun) {
dst = call(dst, opts->save_context);
if (is_write) {
- //SCRATCH2 is RDI, so no need to move it there
+ if (SCRATCH2 != RDI) {
+ dst = mov_rr(dst, SCRATCH2, RDI, SZ_D);
+ }
dst = mov_rr(dst, SCRATCH1, RDX, size);
} else {
dst = push_r(dst, CONTEXT);
@@ -4536,6 +4540,7 @@ void init_x86_68k_opts(x86_68k_options * opts, memmap_chunk * memmap, uint32_t n
memset(opts, 0, sizeof(*opts));
for (int i = 0; i < 8; i++)
opts->dregs[i] = opts->aregs[i] = -1;
+#ifdef X86_64
opts->dregs[0] = R10;
opts->dregs[1] = R11;
opts->dregs[2] = R12;
@@ -4550,6 +4555,15 @@ void init_x86_68k_opts(x86_68k_options * opts, memmap_chunk * memmap, uint32_t n
opts->flag_regs[2] = RDX;
opts->flag_regs[3] = BH;
opts->flag_regs[4] = DH;
+#else
+ opts->dregs[0] = RDX;
+ opts->aregs[7] = RDI;
+
+ for (int i = 0; i < 5; i++)
+ opts->flag_regs[i] = -1;
+#endif
+
+
opts->native_code_map = malloc(sizeof(native_map_slot) * NATIVE_MAP_CHUNKS);
memset(opts->native_code_map, 0, sizeof(native_map_slot) * NATIVE_MAP_CHUNKS);
opts->deferred = NULL;
@@ -4597,6 +4611,9 @@ void init_x86_68k_opts(x86_68k_options * opts, memmap_chunk * memmap, uint32_t n
dst = retn(dst);
opts->start_context = (start_fun)dst;
+ if (SCRATCH2 != RDI) {
+ dst = mov_rr(dst, RDI, SCRATCH2, SZ_Q);
+ }
//save callee save registers
dst = push_r(dst, RBP);
dst = push_r(dst, R12);
@@ -4604,7 +4621,7 @@ void init_x86_68k_opts(x86_68k_options * opts, memmap_chunk * memmap, uint32_t n
dst = push_r(dst, R14);
dst = push_r(dst, R15);
dst = call(dst, opts->load_context);
- dst = call_r(dst, RDI);
+ dst = call_r(dst, SCRATCH2);
dst = call(dst, opts->save_context);
//restore callee save registers
dst = pop_r(dst, R15);