filename | src/test/testsh4x86.c |
changeset | 571:9bc09948d0f2 |
prev | 561:533f6b478071 |
next | 578:5fbe050b0558 |
author | nkeynes |
date | Mon Jan 14 10:23:49 2008 +0000 (16 years ago) |
branch | lxdream-mmu |
permissions | -rw-r--r-- |
last change | Remove asm file and convert to inline (easier to cope with platform conventions) Add breakpoint support Add MMU store-queue support |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
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, breakpoint_type_t type ) { }
68 gboolean sh4_clear_breakpoint( uint32_t pc, breakpoint_type_t 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 void dreamcast_stop() {}
81 sh4addr_t mmu_vma_to_phys_read( sh4vma_t vma ) { return vma & 0x1FFFFFFF; }
82 sh4addr_t mmu_vma_to_phys_write( sh4vma_t vma ) { return vma & 0x1FFFFFFF; }
83 uint32_t sh4_read_sr( void ) { }
84 gboolean sh4_raise_exception( int exc ) {}
85 gboolean sh4_raise_trap( int exc ) {}
86 void sh4_sleep() { }
87 void sh4_fsca( uint32_t angle, float *fr ) { }
88 void sh4_ftrv( float *fv, float *xmtrx ) { }
89 void signsat48(void) { }
90 gboolean gui_error_dialog( const char *fmt, ... ) { }
91 struct sh4_icache_struct sh4_icache;
93 void usage()
94 {
95 fprintf( stderr, "Usage: testsh4x86 [options] <input bin file>\n");
96 fprintf( stderr, "Options:\n");
97 fprintf( stderr, " -d <filename> Diff results against contents of file\n" );
98 fprintf( stderr, " -h Display this help message\n" );
99 fprintf( stderr, " -o <filename> Output disassembly to file [stdout]\n" );
100 fprintf( stderr, " -s <addr> Specify start address of binary [8C010000]\n" );
101 }
103 void emit( void *ptr, int level, const gchar *source, const char *msg, ... )
104 {
105 va_list ap;
106 va_start( ap, msg );
107 vfprintf( stderr, msg, ap );
108 fprintf( stderr, "\n" );
109 va_end(ap);
110 }
113 struct sh4_registers sh4r;
116 int main( int argc, char *argv[] )
117 {
118 struct stat st;
119 int opt;
120 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
121 switch( opt ) {
122 case 'd':
123 diff_file = optarg;
124 break;
125 case 'o':
126 output_file = optarg;
127 break;
128 case 's':
129 start_addr = strtoul(optarg, NULL, 0);
130 break;
131 case 'h':
132 usage();
133 exit(0);
134 }
135 }
136 if( optind < argc ) {
137 input_file = argv[optind++];
138 } else {
139 usage();
140 exit(1);
141 }
143 in = fopen( input_file, "ro" );
144 if( in == NULL ) {
145 perror( "Unable to open input file" );
146 exit(2);
147 }
148 fstat( fileno(in), &st );
149 inbuf = malloc( st.st_size );
150 fread( inbuf, st.st_size, 1, in );
152 xlat_cache_init();
153 uint32_t pc;
154 uint8_t *buf = sh4_translate_basic_block( start_addr );
155 uint32_t buflen = xlat_get_block_size(buf);
156 x86_disasm_init( buf, 0x8c010000, buflen );
157 x86_set_symtab( local_symbols, 6 );
158 for( pc = 0x8c010000; pc < 0x8c010000 + buflen; ) {
159 char buf[256];
160 char op[256];
161 uint32_t pc2 = x86_disasm_instruction( pc, buf, sizeof(buf), op );
162 fprintf( stdout, "%08X: %-20s %s\n", pc, op, buf );
163 pc = pc2;
164 }
165 }
.