comparison m68k_core_x86.c @ 587:55c5b0f913ce

Made m68k_retranslate_inst host-cpu generic and moved it to m68k_core.c
author Michael Pavone <pavone@retrodev.com>
date Fri, 07 Mar 2014 23:26:46 -0800
parents aa35ccb90aa9
children 963d5901f583
comparison
equal deleted inserted replaced
586:aa35ccb90aa9 587:55c5b0f913ce
2179 } 2179 }
2180 2180
2181 void check_code_prologue(code_info *code) 2181 void check_code_prologue(code_info *code)
2182 { 2182 {
2183 check_alloc_code(code, MAX_INST_LEN*4); 2183 check_alloc_code(code, MAX_INST_LEN*4);
2184 } 2184 };
2185 2185
2186 void * m68k_retranslate_inst(uint32_t address, m68k_context * context) 2186 void nop_fill_or_jmp_next(code_info *code, code_ptr old_end, code_ptr next_inst)
2187 { 2187 {
2188 m68k_options * opts = context->options; 2188 if (next_inst == old_end && next_inst - code->cur < 2) {
2189 code_info *code = &opts->gen.code; 2189 while (code->cur < old_end) {
2190 uint8_t orig_size = get_native_inst_size(opts, address); 2190 *(code->cur++) = 0x90; //NOP
2191 code_ptr orig_start = get_native_address(context->native_code_map, address); 2191 }
2192 uint32_t orig = address; 2192 } else {
2193 code_info orig_code; 2193 jmp(code, next_inst);
2194 orig_code.cur = orig_start;
2195 orig_code.last = orig_start + orig_size + 5;
2196 address &= 0xFFFF;
2197 uint16_t *after, *inst = context->mem_pointers[1] + address/2;
2198 m68kinst instbuf;
2199 after = m68k_decode(inst, &instbuf, orig);
2200 if (orig_size != MAX_NATIVE_SIZE) {
2201 deferred_addr * orig_deferred = opts->gen.deferred;
2202
2203 //make sure the beginning of the code for an instruction is contiguous
2204 check_alloc_code(code, MAX_INST_LEN*4);
2205 code_ptr native_start = code->cur;
2206 translate_m68k(opts, &instbuf);
2207 code_ptr native_end = code->cur;
2208 uint8_t is_terminal = m68k_is_terminal(&instbuf);
2209 if ((native_end - native_start) <= orig_size) {
2210 code_ptr native_next;
2211 if (!is_terminal) {
2212 native_next = get_native_address(context->native_code_map, orig + (after-inst)*2);
2213 }
2214 if (is_terminal || (native_next && ((native_next == orig_start + orig_size) || (orig_size - (native_end - native_start)) > 5))) {
2215 remove_deferred_until(&opts->gen.deferred, orig_deferred);
2216 code_info tmp;
2217 tmp.cur = code->cur;
2218 tmp.last = code->last;
2219 code->cur = orig_code.cur;
2220 code->last = orig_code.last;
2221 translate_m68k(opts, &instbuf);
2222 native_end = orig_code.cur = code->cur;
2223 code->cur = tmp.cur;
2224 code->last = tmp.last;
2225 if (!is_terminal) {
2226 if (native_next == orig_start + orig_size && (native_next-native_end) < 2) {
2227 while (orig_code.cur < orig_start + orig_size) {
2228 *(orig_code.cur++) = 0x90; //NOP
2229 }
2230 } else {
2231 jmp(&orig_code, native_next);
2232 }
2233 }
2234 m68k_handle_deferred(context);
2235 return orig_start;
2236 }
2237 }
2238
2239 map_native_address(context, instbuf.address, native_start, (after-inst)*2, MAX_NATIVE_SIZE);
2240
2241 jmp(&orig_code, native_start);
2242 if (!m68k_is_terminal(&instbuf)) {
2243 code_ptr native_end = code->cur;
2244 code->cur = native_start + MAX_NATIVE_SIZE;
2245 code_ptr rest = get_native_address_trans(context, orig + (after-inst)*2);
2246 code_ptr tmp = code->cur;
2247 code->cur = native_end;
2248 jmp(code, rest);
2249 code->cur = tmp;
2250 } else {
2251 code->cur = native_start + MAX_NATIVE_SIZE;
2252 }
2253 m68k_handle_deferred(context);
2254 return native_start;
2255 } else {
2256 code_info tmp;
2257 tmp.cur = code->cur;
2258 tmp.last = code->last;
2259 code->cur = orig_code.cur;
2260 code->last = orig_code.last;
2261 translate_m68k(opts, &instbuf);
2262 if (!m68k_is_terminal(&instbuf)) {
2263 jmp(code, get_native_address_trans(context, orig + (after-inst)*2));
2264 }
2265 code->cur = tmp.cur;
2266 code->last = tmp.last;
2267 m68k_handle_deferred(context);
2268 return orig_start;
2269 } 2194 }
2270 } 2195 }
2271 2196
2272 m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context) 2197 m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context)
2273 { 2198 {