changeset 197:7c227a8ec53d

Add instruction address logging to translator and support for reading an address log to the disassembler
author Mike Pavone <pavone@retrodev.com>
date Thu, 17 Jan 2013 20:00:07 -0800
parents f8955d33486d
children 209a37eed3e7
files 68kinst.c blastem.c dis.c m68k_to_x86.c m68k_to_x86.h
diffstat 5 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/68kinst.c	Thu Jan 17 08:19:29 2013 -0800
+++ b/68kinst.c	Thu Jan 17 20:00:07 2013 -0800
@@ -448,7 +448,7 @@
 			return start+1;
 		}
 		istream = m68k_decode_op_ex(istream, opmode, reg, decoded->extra.size, &(decoded->dst));
-		if (!istream) {
+		if (!istream || decoded->dst.addr_mode == MODE_IMMEDIATE) {
 			decoded->op = M68K_INVALID;
 			return start+1;
 		}
--- a/blastem.c	Thu Jan 17 08:19:29 2013 -0800
+++ b/blastem.c	Thu Jan 17 20:00:07 2013 -0800
@@ -803,12 +803,16 @@
 	int width = -1;
 	int height = -1;
 	int debug = 0;
+	FILE *address_log = NULL;
 	for (int i = 2; i < argc; i++) {
 		if (argv[i][0] == '-') {
 			switch(argv[i][1]) {
 			case 'd':
 				debug = 1;
 				break;
+			case 'l':
+				address_log = fopen("address.log", "w");
+				break;
 			default:
 				fprintf(stderr, "Unrecognized switch %s\n", argv[i]);
 				return 1;
@@ -828,6 +832,7 @@
 	vdp_context v_context;
 	
 	init_x86_68k_opts(&opts);
+	opts.address_log = address_log;
 	init_68k_context(&context, opts.native_code_map, &opts);
 	init_vdp_context(&v_context);
 	context.next_context = &v_context;
--- a/dis.c	Thu Jan 17 08:19:29 2013 -0800
+++ b/dis.c	Thu Jan 17 20:00:07 2013 -0800
@@ -82,6 +82,7 @@
 	deferred *def = NULL, *tmpd;
 	for(uint8_t opt = 2; opt < argc; ++opt) {
 		if (argv[opt][0] == '-') {
+			FILE * address_log;
 			switch (argv[opt][1])
 			{
 			case 'l':
@@ -93,6 +94,26 @@
 			case 'o':
 				only = 1;
 				break;
+			case 'f':
+				opt++;
+				if (opt >= argc) {
+					fputs("-f must be followed by a filename\n", stderr);
+					exit(1);
+				}
+				address_log = fopen(argv[opt], "r");
+				if (!address_log) {
+					fprintf(stderr, "Failed to open %s for reading\n", argv[opt]);
+					exit(1);
+				}
+				while (fgets(disbuf, sizeof(disbuf), address_log)) {
+				 	if (disbuf[0]) {
+						uint32_t address = strtol(disbuf, NULL, 16);
+						if (address) {
+							def = defer(address, def);
+							reference(address);
+						}
+					}
+				}
 			}
 		} else {
 			uint32_t address = strtol(argv[opt], NULL, 16);
--- a/m68k_to_x86.c	Thu Jan 17 08:19:29 2013 -0800
+++ b/m68k_to_x86.c	Thu Jan 17 20:00:07 2013 -0800
@@ -3782,6 +3782,9 @@
 		exit(1);
 	}
 	do {
+		if (opts->address_log) {
+			fprintf(opts->address_log, "%X\n", address);
+		}
 		do {
 			if (dst_end-dst < MAX_NATIVE_SIZE) {
 				if (dst_end-dst < 5) {
--- a/m68k_to_x86.h	Thu Jan 17 08:19:29 2013 -0800
+++ b/m68k_to_x86.h	Thu Jan 17 20:00:07 2013 -0800
@@ -1,4 +1,5 @@
 #include <stdint.h>
+#include <stdio.h>
 #include "68kinst.h"
 
 #define NUM_MEM_AREAS 4
@@ -30,6 +31,7 @@
 	uint8_t         *cur_code;
 	uint8_t         *code_end;
 	uint8_t         **ram_inst_sizes;
+	FILE            *address_log;
 } x86_68k_options;
 
 typedef struct {