Mercurial > repos > blastem
comparison z80_to_x86.c @ 390:561fe3ea3fc8
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
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 08 Jun 2013 11:31:52 -0700 |
parents | 3815ad1e684e |
children | d5f1840273b5 |
comparison
equal
deleted
inserted
replaced
389:3815ad1e684e | 390:561fe3ea3fc8 |
---|---|
1740 uint32_t inst_start = z80_get_instruction_start(context->static_code_map, address); | 1740 uint32_t inst_start = z80_get_instruction_start(context->static_code_map, address); |
1741 if (inst_start != INVALID_INSTRUCTION_START) { | 1741 if (inst_start != INVALID_INSTRUCTION_START) { |
1742 uint8_t * dst = z80_get_native_address(context, inst_start); | 1742 uint8_t * dst = z80_get_native_address(context, inst_start); |
1743 dprintf("patching code at %p for Z80 instruction at %X due to write to %X\n", dst, inst_start, address); | 1743 dprintf("patching code at %p for Z80 instruction at %X due to write to %X\n", dst, inst_start, address); |
1744 dst = mov_ir(dst, inst_start, SCRATCH1, SZ_D); | 1744 dst = mov_ir(dst, inst_start, SCRATCH1, SZ_D); |
1745 dst = jmp(dst, (uint8_t *)z80_retrans_stub); | 1745 dst = call(dst, (uint8_t *)z80_retrans_stub); |
1746 } | 1746 } |
1747 return context; | 1747 return context; |
1748 } | 1748 } |
1749 | 1749 |
1750 uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) | 1750 uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) |
1767 if (opts->deferred) { | 1767 if (opts->deferred) { |
1768 translate_z80_stream(context, opts->deferred->address); | 1768 translate_z80_stream(context, opts->deferred->address); |
1769 } | 1769 } |
1770 } | 1770 } |
1771 | 1771 |
1772 void * z80_retranslate_inst(uint32_t address, z80_context * context) | 1772 void * z80_retranslate_inst(uint32_t address, z80_context * context, uint8_t * orig_start) |
1773 { | 1773 { |
1774 char disbuf[80]; | 1774 char disbuf[80]; |
1775 x86_z80_options * opts = context->options; | 1775 x86_z80_options * opts = context->options; |
1776 uint8_t orig_size = z80_get_native_inst_size(opts, address); | 1776 uint8_t orig_size = z80_get_native_inst_size(opts, address); |
1777 uint8_t * orig_start = z80_get_native_address(context, address); | |
1778 uint32_t orig = address; | 1777 uint32_t orig = address; |
1779 address &= 0x1FFF; | 1778 address &= 0x1FFF; |
1780 uint8_t * dst = opts->cur_code; | 1779 uint8_t * dst = opts->cur_code; |
1781 uint8_t * dst_end = opts->code_end; | 1780 uint8_t * dst_end = opts->code_end; |
1782 uint8_t *after, *inst = context->mem_pointers[0] + address; | 1781 uint8_t *after, *inst = context->mem_pointers[0] + address; |