summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2014-02-15 21:25:36 -0800
committerMichael Pavone <pavone@retrodev.com>2014-02-15 21:25:36 -0800
commitebb8d34197bf7908fe78e2692615a41c03d676f6 (patch)
tree96909f547c8db68f1fc3942dc5c3d7e3b1a28c23
parent3a446823ac7a81038464775d1f6f3fb7e76eeb03 (diff)
Generate m68k_start_context at runtime so it can use the generated load_context and save_context
-rw-r--r--m68k_to_x86.c20
-rw-r--r--m68k_to_x86.h3
-rw-r--r--runtime.S19
3 files changed, 21 insertions, 21 deletions
diff --git a/m68k_to_x86.c b/m68k_to_x86.c
index e8bfa4c..3347274 100644
--- a/m68k_to_x86.c
+++ b/m68k_to_x86.c
@@ -42,7 +42,6 @@ void get_sr();
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 remove_breakpoint(m68k_context * context, uint32_t address)
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 @@ void init_x86_68k_opts(x86_68k_options * opts, memmap_chunk * memmap, uint32_t n
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);
diff --git a/m68k_to_x86.h b/m68k_to_x86.h
index 6466d28..751e9d1 100644
--- a/m68k_to_x86.h
+++ b/m68k_to_x86.h
@@ -18,6 +18,8 @@ struct m68kinst;
#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 @@ typedef struct {
uint8_t *trap;
uint8_t *save_context;
uint8_t *load_context;
+ start_fun start_context;
} x86_68k_options;
typedef struct {
diff --git a/runtime.S b/runtime.S
index 36ecfff..febaeec 100644
--- a/runtime.S
+++ b/runtime.S
@@ -264,22 +264,3 @@ m68k_load_context:
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