Search
lxdream.org :: lxdream/src/test/testsh4x86.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testsh4x86.c
changeset 550:a27e31340147
prev515:5e5bb1dd369e
next561:533f6b478071
next586:2a3ba82cf243
author nkeynes
date Thu Dec 06 10:43:30 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Add support for the MMIO side of the TLB (and LDTLB)
view annotate diff log raw
     1 /**
     2  * $Id: testsh4x86.c,v 1.6 2007-11-08 10:49:16 nkeynes Exp $
     3  *
     4  * Test cases for the SH4 => x86 translator core. Takes as
     5  * input a binary SH4 object (and VMA), generates the
     6  * corresponding x86 code, and outputs the disassembly.
     7  *
     8  * Copyright (c) 2005 Nathan Keynes.
     9  *
    10  * This program is free software; you can redistribute it and/or modify
    11  * it under the terms of the GNU General Public License as published by
    12  * the Free Software Foundation; either version 2 of the License, or
    13  * (at your option) any later version.
    14  *
    15  * This program is distributed in the hope that it will be useful,
    16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    18  * GNU General Public License for more details.
    19  */
    21 #include <stdio.h>
    22 #include <stdarg.h>
    23 #include <getopt.h>
    24 #include <sys/stat.h>
    25 #include "x86dasm/x86dasm.h"
    26 #include "sh4/sh4trans.h"
    27 #include "sh4/sh4core.h"
    29 #define MAX_INS_SIZE 32
    31 char *option_list = "s:o:d:h";
    32 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    34 char *input_file = NULL;
    35 char *diff_file = NULL;
    36 char *output_file = NULL;
    37 uint32_t start_addr = 0x8C010000;
    38 uint32_t sh4_cpu_period = 5;
    39 FILE *in;
    41 char *inbuf;
    43 struct x86_symbol local_symbols[] = {
    44     { "_sh4_read_byte", sh4_read_byte },
    45     { "_sh4_read_word", sh4_read_word },
    46     { "_sh4_read_long", sh4_read_long },
    47     { "_sh4_write_byte", sh4_write_byte },
    48     { "_sh4_write_word", sh4_write_word },
    49     { "_sh4_write_long", sh4_write_long }
    50 };
    52 int32_t sh4_read_byte( uint32_t addr ) 
    53 {
    54     return *(uint8_t *)(inbuf+(addr-start_addr));
    55 }
    56 int32_t sh4_read_word( uint32_t addr ) 
    57 {
    58     return *(uint16_t *)(inbuf+(addr-start_addr));
    59 }
    60 int32_t sh4_read_long( uint32_t addr ) 
    61 {
    62     return *(uint32_t *)(inbuf+(addr-start_addr));
    63 }
    64 // Stubs
    65 gboolean sh4_execute_instruction( ) { }
    66 void sh4_accept_interrupt() {}
    67 void sh4_set_breakpoint( uint32_t pc, int type ) { }
    68 gboolean sh4_clear_breakpoint( uint32_t pc, int type ) { }
    69 int sh4_get_breakpoint( uint32_t pc ) { }
    70 void event_execute() {}
    71 void TMU_run_slice( uint32_t nanos ) {}
    72 void SCIF_run_slice( uint32_t nanos ) {}
    73 void MMU_ldtlb(void) {}
    74 void sh4_write_byte( uint32_t addr, uint32_t val ) {}
    75 void sh4_write_word( uint32_t addr, uint32_t val ) {}
    76 void sh4_write_long( uint32_t addr, uint32_t val ) {}
    77 void sh4_flush_store_queue( uint32_t addr ) {}
    78 void sh4_write_sr( uint32_t val ) { }
    79 void syscall_invoke( uint32_t val ) { }
    80 uint32_t sh4_read_sr( void ) { }
    81 gboolean sh4_raise_exception( int exc ) {}
    82 gboolean sh4_raise_trap( int exc ) {}
    83 void sh4_sleep() { }
    84 void sh4_fsca( uint32_t angle, float *fr ) { }
    85 void sh4_ftrv( float *fv, float *xmtrx ) { }
    86 void signsat48(void) { }
    87 uint16_t *sh4_icache = NULL;
    88 uint32_t sh4_icache_addr = 0;
    89 gboolean gui_error_dialog( const char *fmt, ... ) { }
    92 void usage()
    93 {
    94     fprintf( stderr, "Usage: testsh4x86 [options] <input bin file>\n");
    95     fprintf( stderr, "Options:\n");
    96     fprintf( stderr, "  -d <filename>  Diff results against contents of file\n" );
    97     fprintf( stderr, "  -h             Display this help message\n" );
    98     fprintf( stderr, "  -o <filename>  Output disassembly to file [stdout]\n" );
    99     fprintf( stderr, "  -s <addr>      Specify start address of binary [8C010000]\n" );
   100 }
   102 void emit( void *ptr, int level, const gchar *source, const char *msg, ... )
   103 {
   104     va_list ap;
   105     va_start( ap, msg );
   106     vfprintf( stderr, msg, ap );
   107     fprintf( stderr, "\n" );
   108     va_end(ap);
   109 }
   112 struct sh4_registers sh4r;
   115 int main( int argc, char *argv[] )
   116 {
   117     struct stat st;
   118     int opt;
   119     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
   120 	switch( opt ) {
   121 	case 'd':
   122 	    diff_file = optarg;
   123 	    break;
   124 	case 'o':
   125 	    output_file = optarg;
   126 	    break;
   127 	case 's':
   128 	    start_addr = strtoul(optarg, NULL, 0);
   129 	    break;
   130 	case 'h':
   131 	    usage();
   132 	    exit(0);
   133 	}
   134     }
   135     if( optind < argc ) {
   136 	input_file = argv[optind++];
   137     } else {
   138 	usage();
   139 	exit(1);
   140     }
   142     in = fopen( input_file, "ro" );
   143     if( in == NULL ) {
   144 	perror( "Unable to open input file" );
   145 	exit(2);
   146     }
   147     fstat( fileno(in), &st );
   148     inbuf = malloc( st.st_size );
   149     fread( inbuf, st.st_size, 1, in );
   151     xlat_cache_init();
   152     uint32_t pc;
   153     uint8_t *buf = sh4_translate_basic_block( start_addr );
   154     uint32_t buflen = xlat_get_block_size(buf);
   155     x86_disasm_init( buf, 0x8c010000, buflen );
   156     x86_set_symtab( local_symbols, 6 );
   157     for( pc = 0x8c010000; pc < 0x8c010000 + buflen;  ) {
   158 	char buf[256];
   159 	char op[256];
   160 	uint32_t pc2 = x86_disasm_instruction( pc, buf, sizeof(buf), op );
   161 	fprintf( stdout, "%08X: %-20s %s\n", pc, op, buf );
   162 	pc = pc2;
   163     }
   164 }
.