diff m68k_core_x86.c @ 1228:2e6dcb5c11a2

WIP support for XBAND mapper hardware
author Michael Pavone <pavone@retrodev.com>
date Thu, 23 Feb 2017 00:08:37 -0800
parents 4399044adbef
children 462d9770d467
line wrap: on
line diff
--- a/m68k_core_x86.c	Thu Feb 23 00:08:17 2017 -0800
+++ b/m68k_core_x86.c	Thu Feb 23 00:08:37 2017 -0800
@@ -2309,6 +2309,7 @@
 void translate_out_of_bounds(m68k_options *opts, uint32_t address)
 {
 	code_info *code = &opts->gen.code;
+	check_cycles_int(&opts->gen, address);
 	mov_ir(code, address, opts->gen.scratch1, SZ_D);
 	call_args(code, (code_ptr)m68k_out_of_bounds_execution, 1, opts->gen.scratch1);
 }
@@ -2340,23 +2341,47 @@
 		code_ptr dst = get_native_address(context->options, inst_start);
 		code_info orig = {dst, dst + 128, 0};
 		mov_ir(&orig, inst_start, options->gen.scratch2, SZ_D);
-
-		if (!options->retrans_stub) {
-			options->retrans_stub = code->cur;
-			call(code, options->gen.save_context);
-			push_r(code, options->gen.context_reg);
-			call_args(code,(code_ptr)m68k_retranslate_inst, 2, options->gen.scratch2, options->gen.context_reg);
-			pop_r(code, options->gen.context_reg);
-			mov_rr(code, RAX, options->gen.scratch1, SZ_PTR);
-			call(code, options->gen.load_context);
-			jmp_r(code, options->gen.scratch1);
-		}
 		jmp(&orig, options->retrans_stub);
 		inst_start = get_instruction_start(options, inst_start - 2);
 	}
 	return context;
 }
 
+void m68k_invalidate_code_range(m68k_context *context, uint32_t start, uint32_t end)
+{
+	m68k_options *opts = context->options;
+	native_map_slot *native_code_map = opts->gen.native_code_map;
+	memmap_chunk const *mem_chunk = find_map_chunk(start, &opts->gen, 0, NULL);
+	if (mem_chunk) {
+		//calculate the lowest alias for this address
+		start = mem_chunk->start + ((start - mem_chunk->start) & mem_chunk->mask);
+	}
+	mem_chunk = find_map_chunk(end, &opts->gen, 0, NULL);
+	if (mem_chunk) {
+		//calculate the lowest alias for this address
+		end = mem_chunk->start + ((end - mem_chunk->start) & mem_chunk->mask);
+	}
+	uint32_t start_chunk = start / NATIVE_CHUNK_SIZE, end_chunk = end / NATIVE_CHUNK_SIZE;
+	for (uint32_t chunk = start_chunk; chunk <= end_chunk; chunk++)
+	{
+		if (native_code_map[chunk].base) {
+			uint32_t start_offset = chunk == start_chunk ? start % NATIVE_CHUNK_SIZE : 0;
+			uint32_t end_offset = chunk == end_chunk ? end % NATIVE_CHUNK_SIZE : NATIVE_CHUNK_SIZE;
+			for (uint32_t offset = start_offset; offset < end_offset; offset++)
+			{
+				if (native_code_map[chunk].offsets[offset] != INVALID_OFFSET && native_code_map[chunk].offsets[offset] != EXTENSION_WORD) {
+					code_info code;
+					code.cur = native_code_map[chunk].base + native_code_map[chunk].offsets[offset];
+					code.last = code.cur + 32;
+					code.stack_off = 0;
+					mov_ir(&code, chunk * NATIVE_CHUNK_SIZE + offset, opts->gen.scratch2, SZ_D);
+					jmp(&code, opts->retrans_stub);
+				}
+			}
+		}
+	}
+}
+
 void insert_breakpoint(m68k_context * context, uint32_t address, m68k_debug_handler bp_handler)
 {
 	static code_ptr bp_stub = NULL;
@@ -2948,4 +2973,13 @@
 	call(code, opts->native_addr_and_sync);
 	cycles(&opts->gen, 18);
 	jmp_r(code, opts->gen.scratch1);
+	
+	opts->retrans_stub = code->cur;
+	call(code, opts->gen.save_context);
+	push_r(code, opts->gen.context_reg);
+	call_args(code,(code_ptr)m68k_retranslate_inst, 2, opts->gen.scratch2, opts->gen.context_reg);
+	pop_r(code, opts->gen.context_reg);
+	mov_rr(code, RAX, opts->gen.scratch1, SZ_PTR);
+	call(code, opts->gen.load_context);
+	jmp_r(code, opts->gen.scratch1);
 }