comparison z80_to_x86.c @ 1131:136b1676109b

Partial fix for Z80 debugger brokeness introduced with stack alignment changes
author Michael Pavone <pavone@retrodev.com>
date Sun, 01 Jan 2017 01:10:44 -0800
parents 8f14767661fa
children 5c8b1c33ca10
comparison
equal deleted inserted replaced
1130:8f14767661fa 1131:136b1676109b
3660 } 3660 }
3661 } 3661 }
3662 3662
3663 uint32_t zbreakpoint_patch(z80_context * context, uint16_t address, code_ptr dst) 3663 uint32_t zbreakpoint_patch(z80_context * context, uint16_t address, code_ptr dst)
3664 { 3664 {
3665 code_info code = {dst, dst+32}; 3665 code_info code = {
3666 dst,
3667 dst+32,
3668 #ifdef X86_64
3669 8
3670 #else
3671 0
3672 #endif
3673 };
3666 mov_ir(&code, address, context->options->gen.scratch1, SZ_W); 3674 mov_ir(&code, address, context->options->gen.scratch1, SZ_W);
3667 call(&code, context->bp_stub); 3675 call(&code, context->bp_stub);
3668 return code.cur-dst; 3676 return code.cur-dst;
3669 } 3677 }
3670 3678
3671 void zcreate_stub(z80_context * context) 3679 void zcreate_stub(z80_context * context)
3672 { 3680 {
3681 //FIXME: Stack offset stuff is still a bit broken
3673 z80_options * opts = context->options; 3682 z80_options * opts = context->options;
3674 code_info *code = &opts->gen.code; 3683 code_info *code = &opts->gen.code;
3675 uint32_t start_stack_off = code->stack_off; 3684 uint32_t start_stack_off = code->stack_off;
3676 check_code_prologue(code); 3685 check_code_prologue(code);
3677 context->bp_stub = code->cur; 3686 context->bp_stub = code->cur;
3678 3687
3679 //Calculate length of prologue 3688 //Calculate length of prologue
3680 check_cycles_int(&opts->gen, 0); 3689 check_cycles_int(&opts->gen, 0);
3681 int check_int_size = code->cur-context->bp_stub; 3690 int check_int_size = code->cur-context->bp_stub;
3682 code->cur = context->bp_stub; 3691 code->cur = context->bp_stub;
3683 3692
3684 //Calculate length of patch 3693 //Calculate length of patch
3685 int patch_size = zbreakpoint_patch(context, 0, code->cur); 3694 int patch_size = zbreakpoint_patch(context, 0, code->cur);
3686 3695
3687 //Save context and call breakpoint handler 3696 #ifdef X86_64
3697 code->stack_off = 8;
3698 #endif
3699 //Save context and call breakpoint handler
3688 call(code, opts->gen.save_context); 3700 call(code, opts->gen.save_context);
3689 push_r(code, opts->gen.scratch1); 3701 push_r(code, opts->gen.scratch1);
3690 call_args_abi(code, context->bp_handler, 2, opts->gen.context_reg, opts->gen.scratch1); 3702 call_args_abi(code, context->bp_handler, 2, opts->gen.context_reg, opts->gen.scratch1);
3691 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR); 3703 mov_rr(code, RAX, opts->gen.context_reg, SZ_PTR);
3692 //Restore context 3704 //Restore context
3693 call(code, opts->gen.load_context); 3705 call(code, opts->gen.load_context);
3694 pop_r(code, opts->gen.scratch1); 3706 pop_r(code, opts->gen.scratch1);
3695 //do prologue stuff 3707 //do prologue stuff
3696 or_rr(code, opts->gen.cycles, opts->gen.cycles, SZ_D); 3708 cmp_ir(code, 1, opts->gen.cycles, SZ_D);
3697 uint8_t * jmp_off = code->cur+1; 3709 uint8_t * jmp_off = code->cur+1;
3698 jcc(code, CC_NS, code->cur + 7); 3710 jcc(code, CC_NS, code->cur + 7);
3699 pop_r(code, opts->gen.scratch1); 3711 pop_r(code, opts->gen.scratch1);
3700 add_ir(code, check_int_size - patch_size, opts->gen.scratch1, SZ_PTR); 3712 add_ir(code, check_int_size - patch_size, opts->gen.scratch1, SZ_PTR);
3701 push_r(code, opts->gen.scratch1); 3713 push_r(code, opts->gen.scratch1);
3730 uint8_t * native = z80_get_native_address(context, address); 3742 uint8_t * native = z80_get_native_address(context, address);
3731 if (native) { 3743 if (native) {
3732 z80_options * opts = context->options; 3744 z80_options * opts = context->options;
3733 code_info tmp_code = opts->gen.code; 3745 code_info tmp_code = opts->gen.code;
3734 opts->gen.code.cur = native; 3746 opts->gen.code.cur = native;
3735 opts->gen.code.last = native + 16; 3747 opts->gen.code.last = native + 128;
3736 check_cycles_int(&opts->gen, address); 3748 check_cycles_int(&opts->gen, address);
3737 opts->gen.code = tmp_code; 3749 opts->gen.code = tmp_code;
3738 } 3750 }
3739 } 3751 }
3740 3752