# HG changeset patch # User nkeynes # Date 1188894730 0 # Node ID 94cab5ad0ed8755e915ce098b65e861e426ce38f # Parent d738f6883d4a57c4e4c93d155b2c7cbda29d0991 Change sh4x86 test to translate/disasm full basic blocks Add prelim sym-tab support --- a/src/test/testsh4x86.c Tue Sep 04 08:30:22 2007 +0000 +++ b/src/test/testsh4x86.c Tue Sep 04 08:32:10 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: testsh4x86.c,v 1.1 2007-08-28 08:47:13 nkeynes Exp $ + * $Id: testsh4x86.c,v 1.2 2007-09-04 08:32:10 nkeynes Exp $ * * Test cases for the SH4 => x86 translator core. Takes as * input a binary SH4 object (and VMA), generates the @@ -21,8 +21,9 @@ #include #include #include +#include +#include "x86dasm/x86dasm.h" #include "sh4/sh4trans.h" -#include #include "sh4/sh4core.h" #define MAX_INS_SIZE 32 @@ -34,11 +35,19 @@ char *diff_file = NULL; char *output_file = NULL; uint32_t start_addr = 0x8C010000; - +uint32_t sh4_cpu_period = 5; FILE *in; char *inbuf; -char *outbuf; + +struct x86_symbol local_symbols[] = { + { "_sh4_read_byte", sh4_read_byte }, + { "_sh4_read_word", sh4_read_word }, + { "_sh4_read_long", sh4_read_long }, + { "_sh4_write_byte", sh4_write_byte }, + { "_sh4_write_word", sh4_write_word }, + { "_sh4_write_long", sh4_write_long } +}; int32_t sh4_read_byte( uint32_t addr ) { @@ -64,6 +73,7 @@ void sh4_write_byte( uint32_t addr, uint32_t val ) {} void sh4_write_word( uint32_t addr, uint32_t val ) {} void sh4_write_long( uint32_t addr, uint32_t val ) {} +gboolean sh4_raise_exception( int exc ) {} void usage() { @@ -123,16 +133,13 @@ fstat( fileno(in), &st ); inbuf = malloc( st.st_size ); fread( inbuf, st.st_size, 1, in ); - outbuf = malloc( st.st_size * MAX_INS_SIZE ); - xlat_output = outbuf; + xlat_cache_init(); uint32_t pc; - for( pc = start_addr; pc < start_addr + st.st_size; pc+=2 ) { - sh4_x86_translate_instruction( pc ); - } - - uint32_t buflen = (xlat_output - (uint8_t *)outbuf); - x86_disasm_init( outbuf, 0x8c010000, buflen ); + uint8_t *buf = sh4_translate_basic_block( start_addr ); + uint32_t buflen = xlat_get_block_size(buf); + x86_disasm_init( buf, 0x8c010000, buflen ); + x86_set_symtab( local_symbols, 6 ); for( pc = 0x8c010000; pc < 0x8c010000 + buflen; ) { char buf[256]; char op[256]; --- a/src/x86dasm/x86dasm.c Tue Sep 04 08:30:22 2007 +0000 +++ b/src/x86dasm/x86dasm.c Tue Sep 04 08:32:10 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: x86dasm.c,v 1.1 2007-08-28 08:46:54 nkeynes Exp $ + * $Id: x86dasm.c,v 1.2 2007-09-04 08:32:10 nkeynes Exp $ * * Wrapper around i386-dis to supply the same behaviour as the other * disassembly functions. @@ -37,6 +37,9 @@ static struct disassemble_info x86_disasm_info; +static x86_symbol *x86_symtab; +static int x86_num_symbols = 0; + void x86_disasm_init(char *buf, uint32_t vma, int buflen) { init_disassemble_info( &x86_disasm_info, NULL, x86_disasm_output ); @@ -46,8 +49,35 @@ x86_disasm_info.buffer = buf; x86_disasm_info.buffer_vma = vma; x86_disasm_info.buffer_length = buflen; + x86_disasm_info.print_address_func = x86_print_address; } +void x86_set_symtab( x86_symbol *symtab, int num_symbols ) +{ + x86_symtab = symtab; + x86_num_symbols = num_symbols; +} + +static const char *x86_find_symbol( bfd_vma memaddr, struct disassemble_info *info ) +{ + int i; + for( i=0; ifprintf_func( info->stream, "%08X", memaddr ); + if( sym != NULL ) { + info->fprintf_func( info->stream, " <%s>", sym ); + } + return 0; +} uint32_t x86_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode ) { --- a/src/x86dasm/x86dasm.h Tue Sep 04 08:30:22 2007 +0000 +++ b/src/x86dasm/x86dasm.h Tue Sep 04 08:32:10 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: x86dasm.h,v 1.1 2007-08-28 08:46:54 nkeynes Exp $ + * $Id: x86dasm.h,v 1.2 2007-09-04 08:32:10 nkeynes Exp $ * * Wrapper around i386-dis to supply the same behaviour as the other * disassembly functions. @@ -21,4 +21,11 @@ #include "mem.h" extern const struct cpu_desc_struct x86_cpu_desc; +typedef struct x86_symbol { + const char *name; + void *ptr; +} x86_symbol; + +void x86_set_symtab( x86_symbol *symtab, int num_symbols ); +void x86_disasm_init(char *buf, uint32_t vma, int buflen); uint32_t x86_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode );