changeset 898:2f1157f00dc6

Z80 core is now slightly less broken
author Michael Pavone <pavone@retrodev.com>
date Thu, 26 Nov 2015 00:10:36 -0800
parents b9564fb88a5a
children 07bfbbbb4b2e
files z80_to_x86.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/z80_to_x86.c	Wed Nov 25 20:32:20 2015 -0800
+++ b/z80_to_x86.c	Thu Nov 26 00:10:36 2015 -0800
@@ -2389,7 +2389,8 @@
 	add_ir(code, 16-sizeof(void *), RSP, SZ_PTR);
 	pop_r(code, RBX); //return address in translated code
 	add_ir(code, 16-sizeof(void *), RSP, SZ_PTR);
-	sub_ir(code, 5, RAX, SZ_PTR); //adjust return address to point to the call that got us here
+	//FIXME: get the right adjustment value for 32-bit
+	sub_ir(code, 9, RAX, SZ_PTR); //adjust return address to point to the call + stack adjust that got us here
 	mov_rrdisp(code, RBX, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR);
 	mov_rrind(code, RAX, options->gen.context_reg, SZ_PTR);
 	restore_callee_save_regs(code);
@@ -2413,8 +2414,13 @@
 	call(code, options->gen.save_context);
 	tmp_stack_off = code->stack_off;
 	//pop return address off the stack and save for resume later
-	pop_rind(code, options->gen.context_reg);
+	//pop_rind(code, options->gen.context_reg);
+	pop_r(code, RAX);
+	//FIXME: get appropriate size for 32-bit
+	add_ir(code, 4, RAX, SZ_PTR);
 	add_ir(code, 16-sizeof(void *), RSP, SZ_PTR);
+	mov_rrind(code, RAX, options->gen.context_reg, SZ_PTR);
+	
 	//restore callee saved registers
 	restore_callee_save_regs(code);
 	//return to caller of z80_run
@@ -2556,6 +2562,7 @@
 	cmp_irdisp(code, 0, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR);
 	code_ptr no_extra = code->cur+1;
 	jcc(code, CC_Z, no_extra);
+	sub_ir(code, 16-sizeof(void *), RSP, SZ_PTR);	
 	push_rdisp(code, options->gen.context_reg, offsetof(z80_context, extra_pc));
 	mov_irdisp(code, 0, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR);
 	*no_extra = code->cur - (no_extra + 1);