# HG changeset patch # User Michael Pavone # Date 1420773116 28800 # Node ID a61d33ccea7d4ad6553deaa97bdf08a1e873da72 # Parent 8cb61671777bba84f307e89eb733fb46a82b821f Moved translate_m68k_rte and translate_m68k_reset to m68k_core.c diff -r 8cb61671777b -r a61d33ccea7d m68k_core.c --- a/m68k_core.c Thu Jan 08 09:36:54 2015 -0800 +++ b/m68k_core.c Thu Jan 08 19:11:56 2015 -0800 @@ -503,6 +503,32 @@ native_to_areg(opts, opts->gen.scratch2, 8); } +void translate_m68k_reset(m68k_options *opts, m68kinst *inst) +{ + code_info *code = &opts->gen.code; + call(code, opts->gen.save_context); + call_args(code, (code_ptr)print_regs_exit, 1, opts->gen.context_reg); +} + +void translate_m68k_rte(m68k_options *opts, m68kinst *inst) +{ + code_info *code = &opts->gen.code; + //TODO: Trap if not in system mode + //Read saved SR + areg_to_native(opts, 7, opts->gen.scratch1); + call(code, opts->read_16); + addi_areg(opts, 2, 7); + call(code, opts->set_sr); + //Read saved PC + areg_to_native(opts, 7, opts->gen.scratch1); + call(code, opts->read_32); + addi_areg(opts, 4, 7); + check_user_mode_swap_ssp_usp(opts); + //Get native address, sync components, recalculate integer points and jump to returned address + call(code, opts->native_addr_and_sync); + jmp_r(code, opts->gen.scratch1); +} + code_ptr get_native_address(native_map_slot * native_code_map, uint32_t address) { address &= 0xFFFFFF; diff -r 8cb61671777b -r a61d33ccea7d m68k_core_x86.c --- a/m68k_core_x86.c Thu Jan 08 09:36:54 2015 -0800 +++ b/m68k_core_x86.c Thu Jan 08 19:11:56 2015 -0800 @@ -543,6 +543,17 @@ } } +void check_user_mode_swap_ssp_usp(m68k_options *opts) +{ + code_info * code = &opts->gen.code; + //Check if we've switched to user mode and swap stack pointers if needed + bt_irdisp(code, 5, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); + code_ptr end_off = code->cur + 1; + jcc(code, CC_C, code->cur + 2); + swap_ssp_usp(opts); + *end_off = code->cur - (end_off + 1); +} + void translate_m68k_move(m68k_options * opts, m68kinst * inst) { code_info *code = &opts->gen.code; @@ -2072,37 +2083,6 @@ m68k_save_result(inst, opts); } -void translate_m68k_reset(m68k_options *opts, m68kinst *inst) -{ - code_info *code = &opts->gen.code; - call(code, opts->gen.save_context); - call_args(code, (code_ptr)print_regs_exit, 1, opts->gen.context_reg); -} - -void translate_m68k_rte(m68k_options *opts, m68kinst *inst) -{ - code_info *code = &opts->gen.code; - //TODO: Trap if not in system mode - //Read saved SR - areg_to_native(opts, 7, opts->gen.scratch1); - call(code, opts->read_16); - addi_areg(opts, 2, 7); - call(code, opts->set_sr); - //Read saved PC - areg_to_native(opts, 7, opts->gen.scratch1); - call(code, opts->read_32); - addi_areg(opts, 4, 7); - //Check if we've switched to user mode and swap stack pointers if needed - bt_irdisp(code, 5, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); - code_ptr end_off = code->cur + 1; - jcc(code, CC_C, code->cur + 2); - swap_ssp_usp(opts); - *end_off = code->cur - (end_off+1); - //Get native address, sync components, recalculate integer points and jump to returned address - call(code, opts->native_addr_and_sync); - jmp_r(code, opts->gen.scratch1); -} - void translate_out_of_bounds(code_info *code) { xor_rr(code, RDI, RDI, SZ_D); @@ -2459,11 +2439,7 @@ //set target cycle to sync cycle mov_rdispr(code, opts->gen.context_reg, offsetof(m68k_context, sync_cycle), opts->gen.limit, SZ_D); //swap USP and SSP if not already in supervisor mode - bt_irdisp(code, 5, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); - code_ptr already_supervisor = code->cur + 1; - jcc(code, CC_C, code->cur + 2); - swap_ssp_usp(opts); - *already_supervisor = code->cur - (already_supervisor+1); + check_user_mode_swap_ssp_usp(opts); //save PC subi_areg(opts, 4, 7); areg_to_native(opts, 7, opts->gen.scratch2); @@ -2493,11 +2469,7 @@ opts->trap = code->cur; push_r(code, opts->gen.scratch2); //swap USP and SSP if not already in supervisor mode - bt_irdisp(code, 5, opts->gen.context_reg, offsetof(m68k_context, status), SZ_B); - already_supervisor = code->cur + 1; - jcc(code, CC_C, code->cur + 2); - swap_ssp_usp(opts); - *already_supervisor = code->cur - (already_supervisor+1); + check_user_mode_swap_ssp_usp(opts); //save PC subi_areg(opts, 4, 7); areg_to_native(opts, 7, opts->gen.scratch2); diff -r 8cb61671777b -r a61d33ccea7d m68k_internal.h --- a/m68k_internal.h Thu Jan 08 09:36:54 2015 -0800 +++ b/m68k_internal.h Thu Jan 08 19:11:56 2015 -0800 @@ -31,6 +31,7 @@ void calc_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg); void calc_areg_index_disp8(m68k_options *opts, m68k_op_info *op, uint8_t native_reg); void nop_fill_or_jmp_next(code_info *code, code_ptr old_end, code_ptr next_inst); +void check_user_mode_swap_ssp_usp(m68k_options *opts); //functions implemented in m68k_core.c int8_t native_reg(m68k_op_info * op, m68k_options * opts); @@ -83,8 +84,6 @@ void translate_m68k_move_ccr_sr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op); void translate_m68k_stop(m68k_options *opts, m68kinst *inst); void translate_m68k_move_from_sr(m68k_options *opts, m68kinst *inst, host_ea *src_op, host_ea *dst_op); -void translate_m68k_reset(m68k_options *opts, m68kinst *inst); -void translate_m68k_rte(m68k_options *opts, m68kinst *inst); //flag update bits #define X0 0x0001