# HG changeset patch # User Mike Pavone # Date 1370716312 25200 # Node ID 561fe3ea3fc82abd4a2032b86d457090fdfd71a7 # Parent 3815ad1e684e374c9ead4212a3aa87de2d1915c8 Use a call instruction to figure out the original native address when retranslating so that it does not get lost when the byte transforms from a instruction word to extension word diff -r 3815ad1e684e -r 561fe3ea3fc8 z80_to_x86.c --- a/z80_to_x86.c Thu Jun 06 08:45:54 2013 -0700 +++ b/z80_to_x86.c Sat Jun 08 11:31:52 2013 -0700 @@ -1742,7 +1742,7 @@ uint8_t * dst = z80_get_native_address(context, inst_start); dprintf("patching code at %p for Z80 instruction at %X due to write to %X\n", dst, inst_start, address); dst = mov_ir(dst, inst_start, SCRATCH1, SZ_D); - dst = jmp(dst, (uint8_t *)z80_retrans_stub); + dst = call(dst, (uint8_t *)z80_retrans_stub); } return context; } @@ -1769,12 +1769,11 @@ } } -void * z80_retranslate_inst(uint32_t address, z80_context * context) +void * z80_retranslate_inst(uint32_t address, z80_context * context, uint8_t * orig_start) { char disbuf[80]; x86_z80_options * opts = context->options; uint8_t orig_size = z80_get_native_inst_size(opts, address); - uint8_t * orig_start = z80_get_native_address(context, address); uint32_t orig = address; address &= 0x1FFF; uint8_t * dst = opts->cur_code; diff -r 3815ad1e684e -r 561fe3ea3fc8 zruntime.S --- a/zruntime.S Thu Jun 06 08:45:54 2013 -0700 +++ b/zruntime.S Sat Jun 08 11:31:52 2013 -0700 @@ -247,8 +247,12 @@ .global z80_retrans_stub z80_retrans_stub: + pop %r14 call z80_save_context + /* adjust for mov and call instructions */ + sub $10, %r14 mov %r13d, %edi + mov %r14, %rdx push %rsi call z80_retranslate_inst pop %rsi