changeset 540:4ca826862174

Generate m68k_start_context at runtime so it can use the generated load_context and save_context
author Michael Pavone <pavone@retrodev.com>
date Sat, 15 Feb 2014 21:25:36 -0800
parents c2716b502a81
children a59ac6b4b5b5
files m68k_to_x86.c m68k_to_x86.h runtime.S
diffstat 3 files changed, 21 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/m68k_to_x86.c	Fri Feb 14 19:56:18 2014 -0800
+++ b/m68k_to_x86.c	Sat Feb 15 21:25:36 2014 -0800
@@ -42,7 +42,6 @@
 void do_sync();
 void bcd_add();
 void bcd_sub();
-void m68k_start_context(uint8_t * addr, m68k_context * context);
 void debug_print_sr();
 
 uint8_t * cycles(uint8_t * dst, uint32_t num)
@@ -4168,7 +4167,8 @@
 void start_68k_context(m68k_context * context, uint32_t address)
 {
 	uint8_t * addr = get_native_address_trans(context, address);
-	m68k_start_context(addr, context);
+	x86_68k_options * options = context->options;
+	options->start_context(addr, context);
 }
 
 void m68k_reset(m68k_context * context)
@@ -4456,6 +4456,22 @@
 	dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, target_cycle), LIMIT, SZ_D);
 	dst = retn(dst);
 
+	opts->start_context = (start_fun)dst;
+	dst = push_r(dst, RBP);
+	dst = push_r(dst, R12);
+	dst = push_r(dst, R13);
+	dst = push_r(dst, R14);
+	dst = push_r(dst, R15);
+	dst = call(dst, opts->load_context);
+	dst = call_r(dst, RDI);
+	dst = call(dst, opts->save_context);
+	dst = pop_r(dst, R15);
+	dst = pop_r(dst, R14);
+	dst = pop_r(dst, R13);
+	dst = pop_r(dst, R12);
+	dst = pop_r(dst, RBP);
+	dst = retn(dst);
+
 	opts->cur_code = dst;
 
 	opts->read_16 = gen_mem_fun(opts, memmap, num_chunks, READ_16);
--- a/m68k_to_x86.h	Fri Feb 14 19:56:18 2014 -0800
+++ b/m68k_to_x86.h	Sat Feb 15 21:25:36 2014 -0800
@@ -18,6 +18,8 @@
 
 #define OPT_NATIVE_CALL_STACK 0x1
 
+typedef void (*start_fun)(uint8_t * addr, void * context);
+
 typedef struct {
 	uint32_t        flags;
 	int8_t          dregs[8];
@@ -40,6 +42,7 @@
 	uint8_t         *trap;
 	uint8_t			*save_context;
 	uint8_t			*load_context;
+	start_fun       start_context;
 } x86_68k_options;
 
 typedef struct {
--- a/runtime.S	Fri Feb 14 19:56:18 2014 -0800
+++ b/runtime.S	Sat Feb 15 21:25:36 2014 -0800
@@ -264,22 +264,3 @@
 	mov 80(%rsi), %eax /* current cycle count */
 	ret
 
-	.global m68k_start_context
-m68k_start_context:
-	push %rbp
-	push %r12
-	push %r13
-	push %r14
-	push %r15
-
-	call m68k_load_context
-	call *%rdi
-	call m68k_save_context
-
-	pop %r15
-	pop %r14
-	pop %r13
-	pop %r12
-	pop %rbp
-
-	ret