changeset 543:915a1cb98bac

Generate retrans_stub at runtime so it can use the generated save/load_context functions
author Michael Pavone <pavone@retrodev.com>
date Sun, 16 Feb 2014 18:17:59 -0800
parents 5d57fd8b44f8
children 8a26567852b7
files m68k_to_x86.c m68k_to_x86.h runtime.S
diffstat 3 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/m68k_to_x86.c	Sun Feb 16 16:50:10 2014 -0800
+++ b/m68k_to_x86.c	Sun Feb 16 18:17:59 2014 -0800
@@ -34,7 +34,6 @@
 void m68k_native_addr();
 void m68k_native_addr_and_sync();
 void m68k_invalid();
-void m68k_retrans_stub();
 void set_sr();
 void set_ccr();
 void get_sr();
@@ -4016,7 +4015,24 @@
 	if (inst_start) {
 		uint8_t * dst = get_native_address(context->native_code_map, inst_start);
 		dst = mov_ir(dst, inst_start, SCRATCH2, SZ_D);
-		dst = jmp(dst, (uint8_t *)m68k_retrans_stub);
+		x86_68k_options * options = context->options;
+		if (!options->retrans_stub) {
+			if (options->code_end - options->cur_code < 32) {
+				size_t size = 1024*1024;
+				options->cur_code = alloc_code(&size);
+				options->code_end = options->cur_code + size;
+			}
+			uint8_t * rdst = options->retrans_stub = options->cur_code;
+			rdst = call(rdst, options->save_context);
+			rdst = push_r(rdst, CONTEXT);
+			rdst = call(rdst, (uint8_t *)m68k_retranslate_inst);
+			rdst = pop_r(rdst, CONTEXT);
+			rdst = mov_rr(rdst, RAX, SCRATCH1, SZ_Q);
+			rdst = call(rdst, options->load_context);
+			rdst = jmp_r(rdst, SCRATCH1);
+			options->cur_code = rdst;
+		}
+		dst = jmp(dst, options->retrans_stub);
 	}
 	return context;
 }
--- a/m68k_to_x86.h	Sun Feb 16 16:50:10 2014 -0800
+++ b/m68k_to_x86.h	Sun Feb 16 18:17:59 2014 -0800
@@ -41,6 +41,7 @@
 	uint8_t			*save_context;
 	uint8_t			*load_context;
 	start_fun       start_context;
+	uint8_t         *retrans_stub;
 } x86_68k_options;
 
 typedef struct {
--- a/runtime.S	Sun Feb 16 16:50:10 2014 -0800
+++ b/runtime.S	Sun Feb 16 18:17:59 2014 -0800
@@ -185,16 +185,6 @@
 	call m68k_load_context
 	ret
 
-	.global m68k_retrans_stub
-m68k_retrans_stub:
-	call m68k_save_context
-	push %rsi
-	call m68k_retranslate_inst
-	pop %rsi
-	mov %rax, %rcx
-	call m68k_load_context
-	jmp *%rcx
-
 	.global m68k_save_context
 m68k_save_context:
 	mov %bl, 1(%rsi) /* N Flag */