changeset 208:3457dc6fd558

Tweaks to make blastem compatible with m68k-tester
author Mike Pavone <pavone@retrodev.com>
date Sat, 26 Jan 2013 01:33:32 -0800
parents c82f65a87a53
children 922b59c09259
files 68kinst.c 68kinst.h Makefile m68k_to_x86.c m68k_to_x86.h runtime.S
diffstat 6 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/68kinst.c	Fri Jan 25 18:39:22 2013 -0800
+++ b/68kinst.c	Sat Jan 26 01:33:32 2013 -0800
@@ -854,6 +854,10 @@
 		decoded->src.params.immed = immed;
 		break;
 	case MOVEQ:
+		if (*istream & 0x100) {
+			decoded->op = M68K_INVALID;
+			return start+1;
+		}
 		decoded->op = M68K_MOVE;
 		decoded->variant = VAR_QUICK;
 		decoded->extra.size = OPSIZE_LONG;
--- a/68kinst.h	Fri Jan 25 18:39:22 2013 -0800
+++ b/68kinst.h	Sat Jan 26 01:33:32 2013 -0800
@@ -170,7 +170,7 @@
 	} params;
 } m68k_op_info;
 
-typedef struct {
+typedef struct m68kinst {
 	uint8_t op;
 	uint8_t variant;
 	union {
--- a/Makefile	Fri Jan 25 18:39:22 2013 -0800
+++ b/Makefile	Sat Jan 26 01:33:32 2013 -0800
@@ -11,6 +11,9 @@
 zdis : zdis.o z80inst.o
 	$(CC) -o zdis zdis.o z80inst.o
 	
+libemu68k.a : 68kinst.o gen_x86.o m68k_to_x86.o runtime.o mem.o
+	ar rcs libemu68k.a 68kinst.o gen_x86.o m68k_to_x86.o runtime.o mem.o
+	
 trans : trans.o 68kinst.o gen_x86.o m68k_to_x86.o runtime.o mem.o
 	$(CC) -o trans trans.o 68kinst.o gen_x86.o m68k_to_x86.o runtime.o mem.o
 
--- a/m68k_to_x86.c	Fri Jan 25 18:39:22 2013 -0800
+++ b/m68k_to_x86.c	Sat Jan 26 01:33:32 2013 -0800
@@ -1,5 +1,6 @@
 #include "gen_x86.h"
 #include "m68k_to_x86.h"
+#include "68kinst.h"
 #include "mem.h"
 #include <stdio.h>
 #include <stddef.h>
@@ -2804,6 +2805,9 @@
 	} else if(inst->op == M68K_MOVEP) {
 		return translate_m68k_movep(dst, inst, opts);
 	} else if(inst->op == M68K_INVALID) {
+		if (inst->src.params.immed == 0x7100) {
+			return retn(dst);
+		}
 		dst = mov_ir(dst, inst->address, SCRATCH1, SZ_D);
 		return call(dst, (uint8_t *)m68k_invalid);
 	} else if(inst->op == M68K_CMP) {
@@ -2962,7 +2966,6 @@
 		break;
 	case M68K_ASL:
 	case M68K_LSL:
-		//TODO: Check overflow flag behavior
 		dst = translate_shift(dst, inst, &src_op, &dst_op, opts, shl_ir, shl_irdisp8, shl_clr, shl_clrdisp8, shr_ir, shr_irdisp8);
 		break;
 	case M68K_ASR:
@@ -3864,6 +3867,9 @@
 				break;
 			}
 			next = m68k_decode(encoded, &instbuf, address);
+			if (instbuf.op == M68K_INVALID) {
+				instbuf.src.params.immed = *encoded;
+			}
 			uint16_t m68k_size = (next-encoded)*2;
 			address += m68k_size;
 			encoded = next;
--- a/m68k_to_x86.h	Fri Jan 25 18:39:22 2013 -0800
+++ b/m68k_to_x86.h	Sat Jan 26 01:33:32 2013 -0800
@@ -2,7 +2,8 @@
 #define M68K_TO_X86_H_
 #include <stdint.h>
 #include <stdio.h>
-#include "68kinst.h"
+//#include "68kinst.h"
+struct m68kinst;
 
 #define NUM_MEM_AREAS 4
 #define NATIVE_MAP_CHUNKS (64*1024)
@@ -56,7 +57,7 @@
 	uint8_t         ram_code_flags[32/8];
 } m68k_context;
 
-uint8_t * translate_m68k(uint8_t * dst, m68kinst * inst, x86_68k_options * opts);
+uint8_t * translate_m68k(uint8_t * dst, struct m68kinst * inst, x86_68k_options * opts);
 uint8_t * translate_m68k_stream(uint32_t address, m68k_context * context);
 void start_68k_context(m68k_context * context, uint32_t address);
 void init_x86_68k_opts(x86_68k_options * opts);
@@ -64,6 +65,7 @@
 void m68k_reset(m68k_context * context);
 void insert_breakpoint(m68k_context * context, uint32_t address, uint8_t * bp_handler);
 void remove_breakpoint(m68k_context * context, uint32_t address);
+m68k_context * m68k_handle_code_write(uint32_t address, m68k_context * context);
 
 #endif //M68K_TO_X86_H_
 
--- a/runtime.S	Fri Jan 25 18:39:22 2013 -0800
+++ b/runtime.S	Sat Jan 26 01:33:32 2013 -0800
@@ -630,5 +630,19 @@
 
 	.global m68k_start_context
 m68k_start_context:
+	push %rbp
+	push %r12
+	push %r13
+	push %r14
+	push %r15
+	
 	call m68k_load_context
-	jmp *%rdi
+	call *%rdi
+	
+	pop %r15
+	pop %r14
+	pop %r13
+	pop %r12
+	pop %rbp
+	
+	ret