comparison z80_to_x86.c @ 657:92ce5ea5ffc9

Use call_args and call_args_abi in Z80 core
author Michael Pavone <pavone@retrodev.com>
date Thu, 01 Jan 2015 20:07:47 -0800
parents a18e3923481e
children 759c38bf97f8
comparison
equal deleted inserted replaced
656:24ccfd70133a 657:92ce5ea5ffc9
873 //TODO: Implement half-carry flag 873 //TODO: Implement half-carry flag
874 break; 874 break;
875 case Z80_NOP: 875 case Z80_NOP:
876 if (inst->immed == 42) { 876 if (inst->immed == 42) {
877 call(code, opts->gen.save_context); 877 call(code, opts->gen.save_context);
878 mov_rr(code, opts->gen.context_reg, RDI, SZ_Q); 878 call_args(code, (code_ptr)z80_print_regs_exit, 1, opts->gen.context_reg);
879 jmp(code, (uint8_t *)z80_print_regs_exit);
880 } else { 879 } else {
881 cycles(&opts->gen, 4 * inst->immed); 880 cycles(&opts->gen, 4 * inst->immed);
882 } 881 }
883 break; 882 break;
884 case Z80_HALT: { 883 case Z80_HALT: {
1673 //back out the base 3 cycles from a read here 1672 //back out the base 3 cycles from a read here
1674 //not quite perfect, but it will have to do for now 1673 //not quite perfect, but it will have to do for now
1675 cycles(&opts->gen, -3); 1674 cycles(&opts->gen, -3);
1676 check_cycles_int(&opts->gen, address); 1675 check_cycles_int(&opts->gen, address);
1677 call(code, opts->gen.save_context); 1676 call(code, opts->gen.save_context);
1678 mov_rr(code, opts->gen.scratch1, RDI, SZ_B);
1679 mov_irdisp(code, address, opts->gen.context_reg, offsetof(z80_context, pc), SZ_W); 1677 mov_irdisp(code, address, opts->gen.context_reg, offsetof(z80_context, pc), SZ_W);
1680 push_r(code, opts->gen.context_reg); 1678 push_r(code, opts->gen.context_reg);
1681 call(code, (code_ptr)z80_interp_handler); 1679 call_args(code, (code_ptr)z80_interp_handler, 2, opts->gen.scratch1, opts->gen.scratch2);
1682 mov_rr(code, RAX, opts->gen.scratch1, SZ_Q); 1680 mov_rr(code, RAX, opts->gen.scratch1, SZ_Q);
1683 pop_r(code, opts->gen.context_reg); 1681 pop_r(code, opts->gen.context_reg);
1684 call(code, opts->gen.load_context); 1682 call(code, opts->gen.load_context);
1685 jmp_r(code, opts->gen.scratch1); 1683 jmp_r(code, opts->gen.scratch1);
1686 stub.last = code->cur; 1684 stub.last = code->cur;
2047 retn(code); 2045 retn(code);
2048 2046
2049 options->native_addr = code->cur; 2047 options->native_addr = code->cur;
2050 call(code, options->gen.save_context); 2048 call(code, options->gen.save_context);
2051 push_r(code, options->gen.context_reg); 2049 push_r(code, options->gen.context_reg);
2052 mov_rr(code, options->gen.context_reg, RDI, SZ_PTR); 2050 movzx_rr(code, options->gen.scratch1, options->gen.scratch1, SZ_W, SZ_D);
2053 movzx_rr(code, options->gen.scratch1, RSI, SZ_W, SZ_D); 2051 call_args(code, (code_ptr)z80_get_native_address_trans, 2, options->gen.context_reg, options->gen.scratch1);
2054 call(code, (code_ptr)z80_get_native_address_trans);
2055 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR); 2052 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR);
2056 pop_r(code, options->gen.context_reg); 2053 pop_r(code, options->gen.context_reg);
2057 call(code, options->gen.load_context); 2054 call(code, options->gen.load_context);
2058 retn(code); 2055 retn(code);
2059 2056
2153 2150
2154 options->read_16 = code->cur; 2151 options->read_16 = code->cur;
2155 cycles(&options->gen, 3); 2152 cycles(&options->gen, 3);
2156 check_cycles(&options->gen); 2153 check_cycles(&options->gen);
2157 //TODO: figure out how to handle the extra wait state for word reads to bank area 2154 //TODO: figure out how to handle the extra wait state for word reads to bank area
2158 //may also need special handling to avoid too much stack depth when acces is blocked 2155 //may also need special handling to avoid too much stack depth when access is blocked
2159 push_r(code, options->gen.scratch1); 2156 push_r(code, options->gen.scratch1);
2160 call(code, options->read_8_noinc); 2157 call(code, options->read_8_noinc);
2161 mov_rr(code, options->gen.scratch1, options->gen.scratch2, SZ_B); 2158 mov_rr(code, options->gen.scratch1, options->gen.scratch2, SZ_B);
2162 pop_r(code, options->gen.scratch1); 2159 pop_r(code, options->gen.scratch1);
2163 add_ir(code, 1, options->gen.scratch1, SZ_W); 2160 add_ir(code, 1, options->gen.scratch1, SZ_W);
2204 //pop return address 2201 //pop return address
2205 pop_r(code, options->gen.scratch2); 2202 pop_r(code, options->gen.scratch2);
2206 call(code, options->gen.save_context); 2203 call(code, options->gen.save_context);
2207 //adjust pointer before move and call instructions that got us here 2204 //adjust pointer before move and call instructions that got us here
2208 sub_ir(code, 11, options->gen.scratch2, SZ_PTR); 2205 sub_ir(code, 11, options->gen.scratch2, SZ_PTR);
2209 mov_rr(code, options->gen.scratch1, RDI, SZ_D);
2210 mov_rr(code, options->gen.scratch2, RDX, SZ_PTR);
2211 push_r(code, options->gen.context_reg); 2206 push_r(code, options->gen.context_reg);
2212 call(code, (code_ptr)z80_retranslate_inst); 2207 call_args(code, (code_ptr)z80_retranslate_inst, 3, options->gen.scratch1, options->gen.context_reg, options->gen.scratch2);
2213 pop_r(code, options->gen.context_reg); 2208 pop_r(code, options->gen.context_reg);
2214 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR); 2209 mov_rr(code, RAX, options->gen.scratch1, SZ_PTR);
2215 call(code, options->gen.load_context); 2210 call(code, options->gen.load_context);
2216 jmp_r(code, options->gen.scratch1); 2211 jmp_r(code, options->gen.scratch1);
2217 2212
2289 int patch_size = zbreakpoint_patch(context, 0, code->cur); 2284 int patch_size = zbreakpoint_patch(context, 0, code->cur);
2290 2285
2291 //Save context and call breakpoint handler 2286 //Save context and call breakpoint handler
2292 call(code, opts->gen.save_context); 2287 call(code, opts->gen.save_context);
2293 push_r(code, opts->gen.scratch1); 2288 push_r(code, opts->gen.scratch1);
2294 mov_rr(code, opts->gen.context_reg, RDI, SZ_Q); 2289 call_args_abi(code, context->bp_handler, 2, opts->gen.context_reg, opts->gen.scratch1);
2295 mov_rr(code, opts->gen.scratch1, RSI, SZ_W);
2296 call(code, context->bp_handler);
2297 mov_rr(code, RAX, opts->gen.context_reg, SZ_Q); 2290 mov_rr(code, RAX, opts->gen.context_reg, SZ_Q);
2298 //Restore context 2291 //Restore context
2299 call(code, opts->gen.load_context); 2292 call(code, opts->gen.load_context);
2300 pop_r(code, opts->gen.scratch1); 2293 pop_r(code, opts->gen.scratch1);
2301 //do prologue stuff 2294 //do prologue stuff