changeset 154:4791c0204410

Small fix for bit instructions
author Mike Pavone <pavone@retrodev.com>
date Fri, 04 Jan 2013 22:51:01 -0800
parents 42c031184e8a
children 94a65fb4e1c7
files 68kinst.c m68k_to_x86.c
diffstat 2 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/68kinst.c	Fri Jan 04 21:47:09 2013 -0800
+++ b/68kinst.c	Fri Jan 04 22:51:01 2013 -0800
@@ -727,10 +727,12 @@
 			decoded->variant = VAR_WORD;
 			immed = *(++istream);
 			immed = sign_extend16(immed);
+#ifdef M68020
 		} else if (immed == 0xFF) {
 			decoded->variant = VAR_LONG;
 			immed = *(++istream) << 16;
 			immed |= *(++istream);
+#endif
 		} else {
 			decoded->variant = VAR_BYTE;
 			immed = sign_extend8(immed);
--- a/m68k_to_x86.c	Fri Jan 04 21:47:09 2013 -0800
+++ b/m68k_to_x86.c	Fri Jan 04 22:51:01 2013 -0800
@@ -347,7 +347,7 @@
 		break;
 	default:
 		m68k_disasm(inst, disasm_buf);
-		printf("%s\naddress mode %d not implemented (src)\n", disasm_buf, inst->src.addr_mode);
+		printf("%X: %s\naddress mode %d not implemented (src)\n", inst->address, disasm_buf, inst->src.addr_mode);
 		exit(1);
 	}
 	return out;
@@ -613,7 +613,7 @@
 		break;
 	default:
 		m68k_disasm(inst, disasm_buf);
-		printf("%s\naddress mode %d not implemented (dst)\n", disasm_buf, inst->dst.addr_mode);
+		printf("%X: %s\naddress mode %d not implemented (dst)\n", inst->address, disasm_buf, inst->dst.addr_mode);
 		exit(1);
 	}
 	return out;
@@ -961,7 +961,7 @@
 		break;
 	default:
 		m68k_disasm(inst, disasm_buf);
-		printf("%s\naddress mode %d not implemented (move dst)\n", disasm_buf, inst->dst.addr_mode);
+		printf("%X: %s\naddress mode %d not implemented (move dst)\n", inst->address, disasm_buf, inst->dst.addr_mode);
 		exit(1);
 	}
 
@@ -1002,7 +1002,7 @@
 			break;
 		default:
 			m68k_disasm(inst, disasm_buf);
-			printf("%s\naddress mode %d not implemented (movem dst)\n", disasm_buf, inst->dst.addr_mode);
+			printf("%X: %s\naddress mode %d not implemented (movem dst)\n", inst->address, disasm_buf, inst->dst.addr_mode);
 			exit(1);
 		}
 		dst = cycles(dst, early_cycles);
@@ -1064,7 +1064,7 @@
 			break;
 		default:
 			m68k_disasm(inst, disasm_buf);
-			printf("%s\naddress mode %d not implemented (movem src)\n", disasm_buf, inst->src.addr_mode);
+			printf("%X: %s\naddress mode %d not implemented (movem src)\n", inst->address, disasm_buf, inst->src.addr_mode);
 			exit(1);
 		}
 		dst = cycles(dst, early_cycles);
@@ -1301,7 +1301,7 @@
 		break;
 	default:
 		m68k_disasm(inst, disasm_buf);
-		printf("%s\naddress mode %d not implemented (lea src)\n", disasm_buf, inst->src.addr_mode);
+		printf("%X: %s\naddress mode %d not implemented (lea src)\n", inst->address, disasm_buf, inst->src.addr_mode);
 		exit(1);
 	}
 	return dst;
@@ -1382,7 +1382,7 @@
 		break;
 	default:
 		m68k_disasm(inst, disasm_buf);
-		printf("%s\naddress mode %d not implemented (lea src)\n", disasm_buf, inst->src.addr_mode);
+		printf("%X: %s\naddress mode %d not implemented (lea src)\n", inst->address, disasm_buf, inst->src.addr_mode);
 		exit(1);
 	}
 	dst = sub_ir(dst, 4, opts->aregs[7], SZ_D);
@@ -1394,7 +1394,7 @@
 uint8_t * translate_m68k_bsr(uint8_t * dst, m68kinst * inst, x86_68k_options * opts)
 {
 	int32_t disp = inst->src.params.immed;
-	uint32_t after = inst->address + 2;
+	uint32_t after = inst->address + (inst->variant == VAR_BYTE ? 2 : 4);
 	//TODO: Add cycles in the right place relative to pushing the return address on the stack
 	dst = cycles(dst, 10);
 	dst = mov_ir(dst, after, SCRATCH1, SZ_D);
@@ -1402,9 +1402,9 @@
 	dst = sub_ir(dst, 4, opts->aregs[7], SZ_D);
 	dst = mov_rr(dst, opts->aregs[7], SCRATCH2, SZ_D);
 	dst = call(dst, (char *)m68k_write_long_highfirst);
-	uint8_t * dest_addr = get_native_address(opts->native_code_map, after + disp);
+	uint8_t * dest_addr = get_native_address(opts->native_code_map, (inst->address+2) + disp);
 	if (!dest_addr) {
-		opts->deferred = defer_address(opts->deferred, after + disp, dst + 1);
+		opts->deferred = defer_address(opts->deferred, (inst->address+2) + disp, dst + 1);
 		//dummy address to be replaced later
 		dest_addr = dst + 5;
 	}
@@ -2321,6 +2321,18 @@
 					src_op.base = SCRATCH1;
 				}
 			}
+			if (dst_op.mode == MODE_REG_DISPLACE8) {
+				if (src_op.base != SCRATCH1 && src_op.base != SCRATCH2) {
+					if (src_op.mode == MODE_REG_DIRECT) {
+						dst = mov_rr(dst, src_op.base, SCRATCH1, SZ_D);
+					} else {
+						dst = mov_rdisp8r(dst, src_op.base, src_op.disp, SCRATCH1, SZ_D);
+						src_op.mode = MODE_REG_DIRECT;
+					}
+					src_op.base = SCRATCH1;
+				}
+				dst = and_ir(dst, 31, SCRATCH1, SZ_D);
+			}
 			if (inst->op == M68K_BTST) {
 				if (dst_op.mode == MODE_REG_DIRECT) {
 					dst = bt_rr(dst, src_op.base, dst_op.base, inst->extra.size);