1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/testsh4x86.c Tue Aug 28 08:47:35 2007 +0000
1.5 + * $Id: testsh4x86.c,v 1.1 2007-08-28 08:47:13 nkeynes Exp $
1.7 + * Test cases for the SH4 => x86 translator core. Takes as
1.8 + * input a binary SH4 object (and VMA), generates the
1.9 + * corresponding x86 code, and outputs the disassembly.
1.11 + * Copyright (c) 2005 Nathan Keynes.
1.13 + * This program is free software; you can redistribute it and/or modify
1.14 + * it under the terms of the GNU General Public License as published by
1.15 + * the Free Software Foundation; either version 2 of the License, or
1.16 + * (at your option) any later version.
1.18 + * This program is distributed in the hope that it will be useful,
1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 + * GNU General Public License for more details.
1.25 +#include <stdarg.h>
1.26 +#include <getopt.h>
1.27 +#include "sh4/sh4trans.h"
1.28 +#include <sys/stat.h>
1.29 +#include "sh4/sh4core.h"
1.31 +#define MAX_INS_SIZE 32
1.33 +char *option_list = "s:o:d:h";
1.34 +struct option longopts[1] = { { NULL, 0, 0, 0 } };
1.36 +char *input_file = NULL;
1.37 +char *diff_file = NULL;
1.38 +char *output_file = NULL;
1.39 +uint32_t start_addr = 0x8C010000;
1.46 +int32_t sh4_read_byte( uint32_t addr )
1.48 + return *(uint8_t *)(inbuf+(addr-start_addr));
1.50 +int32_t sh4_read_word( uint32_t addr )
1.52 + return *(uint16_t *)(inbuf+(addr-start_addr));
1.54 +int32_t sh4_read_long( uint32_t addr )
1.56 + return *(uint32_t *)(inbuf+(addr-start_addr));
1.59 +gboolean sh4_execute_instruction( ) { }
1.60 +void sh4_accept_interrupt() {}
1.61 +void sh4_set_breakpoint( uint32_t pc, int type ) { }
1.62 +gboolean sh4_clear_breakpoint( uint32_t pc, int type ) { }
1.63 +int sh4_get_breakpoint( uint32_t pc ) { }
1.64 +void event_execute() {}
1.65 +void TMU_run_slice( uint32_t nanos ) {}
1.66 +void SCIF_run_slice( uint32_t nanos ) {}
1.67 +void sh4_write_byte( uint32_t addr, uint32_t val ) {}
1.68 +void sh4_write_word( uint32_t addr, uint32_t val ) {}
1.69 +void sh4_write_long( uint32_t addr, uint32_t val ) {}
1.73 + fprintf( stderr, "Usage: testsh4x86 [options] <input bin file>\n");
1.74 + fprintf( stderr, "Options:\n");
1.75 + fprintf( stderr, " -d <filename> Diff results against contents of file\n" );
1.76 + fprintf( stderr, " -h Display this help message\n" );
1.77 + fprintf( stderr, " -o <filename> Output disassembly to file [stdout]\n" );
1.78 + fprintf( stderr, " -s <addr> Specify start address of binary [8C010000]\n" );
1.81 +void emit( void *ptr, int level, const gchar *source, const char *msg, ... )
1.84 + va_start( ap, msg );
1.85 + vfprintf( stderr, msg, ap );
1.86 + fprintf( stderr, "\n" );
1.91 +struct sh4_registers sh4r;
1.94 +int main( int argc, char *argv[] )
1.98 + while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
1.101 + diff_file = optarg;
1.104 + output_file = optarg;
1.107 + start_addr = strtoul(optarg, NULL, 0);
1.114 + if( optind < argc ) {
1.115 + input_file = argv[optind++];
1.121 + in = fopen( input_file, "ro" );
1.122 + if( in == NULL ) {
1.123 + perror( "Unable to open input file" );
1.126 + fstat( fileno(in), &st );
1.127 + inbuf = malloc( st.st_size );
1.128 + fread( inbuf, st.st_size, 1, in );
1.129 + outbuf = malloc( st.st_size * MAX_INS_SIZE );
1.130 + xlat_output = outbuf;
1.133 + for( pc = start_addr; pc < start_addr + st.st_size; pc+=2 ) {
1.134 + sh4_x86_translate_instruction( pc );
1.137 + uint32_t buflen = (xlat_output - (uint8_t *)outbuf);
1.138 + x86_disasm_init( outbuf, 0x8c010000, buflen );
1.139 + for( pc = 0x8c010000; pc < 0x8c010000 + buflen; ) {
1.142 + uint32_t pc2 = x86_disasm_instruction( pc, buf, sizeof(buf), op );
1.143 + fprintf( stdout, "%08X: %-20s %s\n", pc, op, buf );