# HG changeset patch # User Michael Pavone # Date 1392532518 28800 # Node ID a59ac6b4b5b595475796e48f54a396c46bbe1ef3 # Parent 4ca826862174cc3efeb080e86a3de91d3f829d9c Get rid of the native stack option the 68K core. Trying to make it work with code that messes with the stack is not worth the trouble. diff -r 4ca826862174 -r a59ac6b4b5b5 m68k_to_x86.c --- a/m68k_to_x86.c Sat Feb 15 21:25:36 2014 -0800 +++ b/m68k_to_x86.c Sat Feb 15 22:35:18 2014 -0800 @@ -31,7 +31,6 @@ m68k_context * sync_components(m68k_context * context, uint32_t address); void handle_cycle_limit(); -void m68k_modified_ret_addr(); void m68k_native_addr(); void m68k_native_addr_and_sync(); void m68k_invalid(); @@ -1754,9 +1753,6 @@ //TODO: Add cycles in the right place relative to pushing the return address on the stack dst = cycles(dst, 10); dst = mov_ir(dst, after, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -1766,13 +1762,7 @@ //dummy address to be replaced later dest_addr = dst + 256; } - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call(dst, (char *)dest_addr); - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); - } else { - dst = jmp(dst, (char *)dest_addr); - } + dst = jmp(dst, (char *)dest_addr); return dst; } @@ -2080,9 +2070,6 @@ case MODE_AREG_INDIRECT: dst = cycles(dst, BUS*2); dst = mov_ir(dst, inst->address + 2, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2092,20 +2079,11 @@ dst = mov_rdisp8r(dst, CONTEXT, offsetof(m68k_context, aregs) + 4 * inst->src.params.regs.pri, SCRATCH1, SZ_D); } dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } + dst = jmp_r(dst, SCRATCH1); break; case MODE_AREG_DISPLACE: dst = cycles(dst, BUS*2); dst = mov_ir(dst, inst->address + 4, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2116,20 +2094,11 @@ } dst = add_ir(dst, inst->src.params.regs.displacement, SCRATCH1, SZ_D); dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } + dst = jmp_r(dst, SCRATCH1); break; case MODE_AREG_INDEX_DISP8: dst = cycles(dst, BUS*3);//TODO: CHeck that this is correct dst = mov_ir(dst, inst->address + 4, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2173,21 +2142,12 @@ dst = add_ir(dst, inst->src.params.regs.displacement, SCRATCH1, SZ_D); } dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } + dst = jmp_r(dst, SCRATCH1); break; case MODE_PC_DISPLACE: //TODO: Add cycles in the right place relative to pushing the return address on the stack dst = cycles(dst, 10); dst = mov_ir(dst, inst->address + 4, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2199,31 +2159,16 @@ //dummy address to be replaced later, make sure it generates a 4-byte displacement dest_addr = dst + 256; } - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call(dst, (char *)dest_addr); - } else { - dst = jmp(dst, dest_addr); - } + dst = jmp(dst, dest_addr); } else { dst = mov_ir(dst, m68k_addr, SCRATCH1, SZ_D); dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } - } - if (opts->flags & OPT_NATIVE_CALL_STACK) { - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); + dst = jmp_r(dst, SCRATCH1); } break; case MODE_PC_INDEX_DISP8: dst = cycles(dst, BUS*3);//TODO: CHeck that this is correct dst = mov_ir(dst, inst->address + 4, SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2263,22 +2208,13 @@ dst = add_ir(dst, inst->src.params.regs.displacement, SCRATCH1, SZ_D); } dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } + dst = jmp_r(dst, SCRATCH1); break; case MODE_ABSOLUTE: case MODE_ABSOLUTE_SHORT: //TODO: Add cycles in the right place relative to pushing the return address on the stack dst = cycles(dst, inst->src.addr_mode == MODE_ABSOLUTE ? 12 : 10); dst = mov_ir(dst, inst->address + (inst->src.addr_mode == MODE_ABSOLUTE ? 6 : 4), SCRATCH1, SZ_D); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = push_r(dst, SCRATCH1); - } dst = sub_ir(dst, 4, opts->aregs[7], SZ_D); dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D); dst = call(dst, opts->write_32_highfirst); @@ -2290,23 +2226,11 @@ //dummy address to be replaced later, make sure it generates a 4-byte displacement dest_addr = dst + 256; } - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call(dst, (char *)dest_addr); - } else { - dst = jmp(dst, dest_addr); - } + dst = jmp(dst, dest_addr); } else { dst = mov_ir(dst, m68k_addr, SCRATCH1, SZ_D); dst = call(dst, (uint8_t *)m68k_native_addr); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = call_r(dst, SCRATCH1); - } else { - dst = jmp_r(dst, SCRATCH1); - } - } - if (opts->flags & OPT_NATIVE_CALL_STACK) { - //would add_ir(dst, 8, RSP, SZ_Q) be faster here? - dst = pop_r(dst, SCRATCH1); + dst = jmp_r(dst, SCRATCH1); } break; default: @@ -2323,15 +2247,8 @@ dst = mov_rr(dst, opts->aregs[7], SCRATCH1, SZ_D); dst = add_ir(dst, 4, opts->aregs[7], SZ_D); dst = call(dst, opts->read_32); - if (opts->flags & OPT_NATIVE_CALL_STACK) { - dst = cmp_rdisp8r(dst, RSP, 8, SCRATCH1, SZ_D); - dst = jcc(dst, CC_NZ, dst+3); - dst = retn(dst); - dst = jmp(dst, (char *)m68k_modified_ret_addr); - } else { - dst = call(dst, (uint8_t *)m68k_native_addr); - dst = jmp_r(dst, SCRATCH1); - } + dst = call(dst, (uint8_t *)m68k_native_addr); + dst = jmp_r(dst, SCRATCH1); return dst; } diff -r 4ca826862174 -r a59ac6b4b5b5 m68k_to_x86.h --- a/m68k_to_x86.h Sat Feb 15 21:25:36 2014 -0800 +++ b/m68k_to_x86.h Sat Feb 15 22:35:18 2014 -0800 @@ -16,8 +16,6 @@ #define NATIVE_CHUNK_SIZE ((16 * 1024 * 1024 / NATIVE_MAP_CHUNKS)/2) #define MAX_NATIVE_SIZE 255 -#define OPT_NATIVE_CALL_STACK 0x1 - typedef void (*start_fun)(uint8_t * addr, void * context); typedef struct { diff -r 4ca826862174 -r a59ac6b4b5b5 runtime.S --- a/runtime.S Sat Feb 15 21:25:36 2014 -0800 +++ b/runtime.S Sat Feb 15 22:35:18 2014 -0800 @@ -177,12 +177,6 @@ mov %cl, (%rsi) ret - .global m68k_modified_ret_addr -m68k_modified_ret_addr: - add $16, %rsp - call m68k_native_addr - jmp *%rcx - .global m68k_native_addr_and_sync m68k_native_addr_and_sync: call m68k_save_context