# HG changeset patch # User Michael Pavone # Date 1448525436 28800 # Node ID 2f1157f00dc6d2620155ebaabb8ed3be5690a5f2 # Parent b9564fb88a5a1bc20b789e30d78b7f36f0867562 Z80 core is now slightly less broken diff -r b9564fb88a5a -r 2f1157f00dc6 z80_to_x86.c --- 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);