comparison z80_to_x86.c @ 665:d0943769353b

Added functions to gen_x86 for saving and restoring callee save registers to better abstract over ABI differences between x86 and x86-64
author Michael Pavone <pavone@retrodev.com>
date Fri, 02 Jan 2015 13:14:09 -0800
parents bca748422bf0
children b68039895627
comparison
equal deleted inserted replaced
664:bca748422bf0 665:d0943769353b
2050 pop_r(code, RAX); //return address in read/write func 2050 pop_r(code, RAX); //return address in read/write func
2051 pop_r(code, RBX); //return address in translated code 2051 pop_r(code, RBX); //return address in translated code
2052 sub_ir(code, 5, RAX, SZ_PTR); //adjust return address to point to the call that got us here 2052 sub_ir(code, 5, RAX, SZ_PTR); //adjust return address to point to the call that got us here
2053 mov_rrdisp(code, RBX, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR); 2053 mov_rrdisp(code, RBX, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR);
2054 mov_rrind(code, RAX, options->gen.context_reg, SZ_PTR); 2054 mov_rrind(code, RAX, options->gen.context_reg, SZ_PTR);
2055 //restore callee saved registers 2055 restore_callee_save_regs(code);
2056 pop_r(code, R15);
2057 pop_r(code, R14);
2058 pop_r(code, R13);
2059 pop_r(code, R12);
2060 pop_r(code, RBP);
2061 pop_r(code, RBX);
2062 *no_sync = code->cur - (no_sync + 1); 2056 *no_sync = code->cur - (no_sync + 1);
2063 //return to caller of z80_run 2057 //return to caller of z80_run
2064 retn(code); 2058 retn(code);
2065 2059
2066 options->gen.handle_code_write = (code_ptr)z80_handle_code_write; 2060 options->gen.handle_code_write = (code_ptr)z80_handle_code_write;
2102 pop_r(code, options->gen.scratch2); 2096 pop_r(code, options->gen.scratch2);
2103 //TODO: Support interrupt mode 0 and 2 2097 //TODO: Support interrupt mode 0 and 2
2104 mov_ir(code, 0x38, options->gen.scratch1, SZ_W); 2098 mov_ir(code, 0x38, options->gen.scratch1, SZ_W);
2105 call(code, options->native_addr); 2099 call(code, options->native_addr);
2106 mov_rrind(code, options->gen.scratch1, options->gen.context_reg, SZ_PTR); 2100 mov_rrind(code, options->gen.scratch1, options->gen.context_reg, SZ_PTR);
2107 //restore callee saved registers 2101 restore_callee_save_regs(code);
2108 pop_r(code, R15);
2109 pop_r(code, R14);
2110 pop_r(code, R13);
2111 pop_r(code, R12);
2112 pop_r(code, RBP);
2113 pop_r(code, RBX);
2114 //return to caller of z80_run to sync 2102 //return to caller of z80_run to sync
2115 retn(code); 2103 retn(code);
2116 *skip_int = code->cur - (skip_int+1); 2104 *skip_int = code->cur - (skip_int+1);
2117 cmp_rdispr(code, options->gen.context_reg, offsetof(z80_context, sync_cycle), options->gen.cycles, SZ_D); 2105 cmp_rdispr(code, options->gen.context_reg, offsetof(z80_context, sync_cycle), options->gen.cycles, SZ_D);
2118 code_ptr skip_sync = code->cur + 1; 2106 code_ptr skip_sync = code->cur + 1;
2119 jcc(code, CC_B, skip_sync); 2107 jcc(code, CC_B, skip_sync);
2120 options->do_sync = code->cur; 2108 options->do_sync = code->cur;
2121 call(code, options->gen.save_context); 2109 call(code, options->gen.save_context);
2122 pop_rind(code, options->gen.context_reg); 2110 pop_rind(code, options->gen.context_reg);
2123 //restore callee saved registers 2111 //restore callee saved registers
2124 pop_r(code, R15); 2112 restore_callee_save_regs(code);
2125 pop_r(code, R14);
2126 pop_r(code, R13);
2127 pop_r(code, R12);
2128 pop_r(code, RBP);
2129 pop_r(code, RBX);
2130 //return to caller of z80_run 2113 //return to caller of z80_run
2131 *skip_sync = code->cur - (skip_sync+1); 2114 *skip_sync = code->cur - (skip_sync+1);
2132 retn(code); 2115 retn(code);
2133 2116
2134 options->read_io = code->cur; 2117 options->read_io = code->cur;
2205 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR); 2188 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR);
2206 call(code, options->gen.load_context); 2189 call(code, options->gen.load_context);
2207 jmp_r(code, options->gen.scratch1); 2190 jmp_r(code, options->gen.scratch1);
2208 2191
2209 options->run = (z80_run_fun)code->cur; 2192 options->run = (z80_run_fun)code->cur;
2210 //save callee save registers 2193 save_callee_save_regs(code);
2211 push_r(code, RBX);
2212 push_r(code, RBP);
2213 push_r(code, R12);
2214 push_r(code, R13);
2215 push_r(code, R14);
2216 push_r(code, R15);
2217 mov_rr(code, RDI, options->gen.context_reg, SZ_PTR); 2194 mov_rr(code, RDI, options->gen.context_reg, SZ_PTR);
2218 call(code, options->load_context_scratch); 2195 call(code, options->load_context_scratch);
2219 cmp_irdisp(code, 0, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR); 2196 cmp_irdisp(code, 0, options->gen.context_reg, offsetof(z80_context, extra_pc), SZ_PTR);
2220 code_ptr no_extra = code->cur+1; 2197 code_ptr no_extra = code->cur+1;
2221 jcc(code, CC_Z, no_extra); 2198 jcc(code, CC_Z, no_extra);