comparison m68k_core_x86.c @ 1465:5d41d0574863

Preserve original address when retranslating instructions instead of switching to the lowest alias
author Michael Pavone <pavone@retrodev.com>
date Wed, 13 Sep 2017 21:06:25 -0700
parents aa945f1bdd71
children f2ee46d08b01
comparison
equal deleted inserted replaced
1464:ffe45c5b8390 1465:5d41d0574863
2496 m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context) 2496 m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context)
2497 { 2497 {
2498 m68k_options * options = context->options; 2498 m68k_options * options = context->options;
2499 uint32_t inst_start = get_instruction_start(options, address); 2499 uint32_t inst_start = get_instruction_start(options, address);
2500 while (inst_start && (address - inst_start) < M68K_MAX_INST_SIZE) { 2500 while (inst_start && (address - inst_start) < M68K_MAX_INST_SIZE) {
2501 code_info *code = &options->gen.code;
2502 code_ptr dst = get_native_address(context->options, inst_start); 2501 code_ptr dst = get_native_address(context->options, inst_start);
2503 code_info orig = {dst, dst + 128, 0}; 2502 patch_for_retranslate(&options->gen, dst, options->retrans_stub);
2504 mov_ir(&orig, inst_start, options->gen.scratch2, SZ_D);
2505 jmp(&orig, options->retrans_stub);
2506 inst_start = get_instruction_start(options, inst_start - 2); 2503 inst_start = get_instruction_start(options, inst_start - 2);
2507 } 2504 }
2508 return context; 2505 return context;
2509 } 2506 }
2510 2507
2529 uint32_t start_offset = chunk == start_chunk ? start % NATIVE_CHUNK_SIZE : 0; 2526 uint32_t start_offset = chunk == start_chunk ? start % NATIVE_CHUNK_SIZE : 0;
2530 uint32_t end_offset = chunk == end_chunk ? end % NATIVE_CHUNK_SIZE : NATIVE_CHUNK_SIZE; 2527 uint32_t end_offset = chunk == end_chunk ? end % NATIVE_CHUNK_SIZE : NATIVE_CHUNK_SIZE;
2531 for (uint32_t offset = start_offset; offset < end_offset; offset++) 2528 for (uint32_t offset = start_offset; offset < end_offset; offset++)
2532 { 2529 {
2533 if (native_code_map[chunk].offsets[offset] != INVALID_OFFSET && native_code_map[chunk].offsets[offset] != EXTENSION_WORD) { 2530 if (native_code_map[chunk].offsets[offset] != INVALID_OFFSET && native_code_map[chunk].offsets[offset] != EXTENSION_WORD) {
2534 code_info code; 2531 patch_for_retranslate(&opts->gen, native_code_map[chunk].base + native_code_map[chunk].offsets[offset], opts->retrans_stub);
2532 /*code_info code;
2535 code.cur = native_code_map[chunk].base + native_code_map[chunk].offsets[offset]; 2533 code.cur = native_code_map[chunk].base + native_code_map[chunk].offsets[offset];
2536 code.last = code.cur + 32; 2534 code.last = code.cur + 32;
2537 code.stack_off = 0; 2535 code.stack_off = 0;
2538 mov_ir(&code, chunk * NATIVE_CHUNK_SIZE + offset, opts->gen.scratch2, SZ_D); 2536 mov_ir(&code, chunk * NATIVE_CHUNK_SIZE + offset, opts->gen.scratch2, SZ_D);
2539 jmp(&code, opts->retrans_stub); 2537 jmp(&code, opts->retrans_stub);*/
2540 } 2538 }
2541 } 2539 }
2542 } 2540 }
2543 } 2541 }
2544 } 2542 }
3180 jmp_r(code, opts->gen.scratch1); 3178 jmp_r(code, opts->gen.scratch1);
3181 3179
3182 opts->retrans_stub = code->cur; 3180 opts->retrans_stub = code->cur;
3183 call(code, opts->gen.save_context); 3181 call(code, opts->gen.save_context);
3184 push_r(code, opts->gen.context_reg); 3182 push_r(code, opts->gen.context_reg);
3185 call_args(code,(code_ptr)m68k_retranslate_inst, 2, opts->gen.scratch2, opts->gen.context_reg); 3183 call_args(code,(code_ptr)m68k_retranslate_inst, 2, opts->gen.scratch1, opts->gen.context_reg);
3186 pop_r(code, opts->gen.context_reg); 3184 pop_r(code, opts->gen.context_reg);
3187 mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR); 3185 mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR);
3188 call(code, opts->gen.load_context); 3186 call(code, opts->gen.load_context);
3189 jmp_r(code, opts->gen.scratch1); 3187 jmp_r(code, opts->gen.scratch1);
3190 3188
3223 //jump back to body of translated instruction 3221 //jump back to body of translated instruction
3224 pop_r(code, opts->gen.scratch1); 3222 pop_r(code, opts->gen.scratch1);
3225 add_ir(code, check_int_size - patch_size, opts->gen.scratch1, SZ_PTR); 3223 add_ir(code, check_int_size - patch_size, opts->gen.scratch1, SZ_PTR);
3226 jmp_r(code, opts->gen.scratch1); 3224 jmp_r(code, opts->gen.scratch1);
3227 code->stack_off = tmp_stack_off; 3225 code->stack_off = tmp_stack_off;
3228 } 3226
3227 retranslate_calc(&opts->gen);
3228 }