revision 365:94cab5ad0ed8
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 365:94cab5ad0ed8 |
parent | 364:d738f6883d4a |
child | 366:6fb0d05152d7 |
author | nkeynes |
date | Tue Sep 04 08:32:10 2007 +0000 (14 years ago) |
Change sh4x86 test to translate/disasm full basic blocks
Add prelim sym-tab support
Add prelim sym-tab support
![]() | src/test/testsh4x86.c | view | annotate | diff | log | |
![]() | src/x86dasm/x86dasm.c | view | annotate | diff | log | |
![]() | src/x86dasm/x86dasm.h | view | annotate | diff | log |
1.1 --- a/src/test/testsh4x86.c Tue Sep 04 08:30:22 2007 +00001.2 +++ b/src/test/testsh4x86.c Tue Sep 04 08:32:10 2007 +00001.3 @@ -1,5 +1,5 @@1.4 /**1.5 - * $Id: testsh4x86.c,v 1.1 2007-08-28 08:47:13 nkeynes Exp $1.6 + * $Id: testsh4x86.c,v 1.2 2007-09-04 08:32:10 nkeynes Exp $1.7 *1.8 * Test cases for the SH4 => x86 translator core. Takes as1.9 * input a binary SH4 object (and VMA), generates the1.10 @@ -21,8 +21,9 @@1.11 #include <stdio.h>1.12 #include <stdarg.h>1.13 #include <getopt.h>1.14 +#include <sys/stat.h>1.15 +#include "x86dasm/x86dasm.h"1.16 #include "sh4/sh4trans.h"1.17 -#include <sys/stat.h>1.18 #include "sh4/sh4core.h"1.20 #define MAX_INS_SIZE 321.21 @@ -34,11 +35,19 @@1.22 char *diff_file = NULL;1.23 char *output_file = NULL;1.24 uint32_t start_addr = 0x8C010000;1.25 -1.26 +uint32_t sh4_cpu_period = 5;1.27 FILE *in;1.29 char *inbuf;1.30 -char *outbuf;1.31 +1.32 +struct x86_symbol local_symbols[] = {1.33 + { "_sh4_read_byte", sh4_read_byte },1.34 + { "_sh4_read_word", sh4_read_word },1.35 + { "_sh4_read_long", sh4_read_long },1.36 + { "_sh4_write_byte", sh4_write_byte },1.37 + { "_sh4_write_word", sh4_write_word },1.38 + { "_sh4_write_long", sh4_write_long }1.39 +};1.41 int32_t sh4_read_byte( uint32_t addr )1.42 {1.43 @@ -64,6 +73,7 @@1.44 void sh4_write_byte( uint32_t addr, uint32_t val ) {}1.45 void sh4_write_word( uint32_t addr, uint32_t val ) {}1.46 void sh4_write_long( uint32_t addr, uint32_t val ) {}1.47 +gboolean sh4_raise_exception( int exc ) {}1.49 void usage()1.50 {1.51 @@ -123,16 +133,13 @@1.52 fstat( fileno(in), &st );1.53 inbuf = malloc( st.st_size );1.54 fread( inbuf, st.st_size, 1, in );1.55 - outbuf = malloc( st.st_size * MAX_INS_SIZE );1.56 - xlat_output = outbuf;1.58 + xlat_cache_init();1.59 uint32_t pc;1.60 - for( pc = start_addr; pc < start_addr + st.st_size; pc+=2 ) {1.61 - sh4_x86_translate_instruction( pc );1.62 - }1.63 -1.64 - uint32_t buflen = (xlat_output - (uint8_t *)outbuf);1.65 - x86_disasm_init( outbuf, 0x8c010000, buflen );1.66 + uint8_t *buf = sh4_translate_basic_block( start_addr );1.67 + uint32_t buflen = xlat_get_block_size(buf);1.68 + x86_disasm_init( buf, 0x8c010000, buflen );1.69 + x86_set_symtab( local_symbols, 6 );1.70 for( pc = 0x8c010000; pc < 0x8c010000 + buflen; ) {1.71 char buf[256];1.72 char op[256];
2.1 --- a/src/x86dasm/x86dasm.c Tue Sep 04 08:30:22 2007 +00002.2 +++ b/src/x86dasm/x86dasm.c Tue Sep 04 08:32:10 2007 +00002.3 @@ -1,5 +1,5 @@2.4 /**2.5 - * $Id: x86dasm.c,v 1.1 2007-08-28 08:46:54 nkeynes Exp $2.6 + * $Id: x86dasm.c,v 1.2 2007-09-04 08:32:10 nkeynes Exp $2.7 *2.8 * Wrapper around i386-dis to supply the same behaviour as the other2.9 * disassembly functions.2.10 @@ -37,6 +37,9 @@2.12 static struct disassemble_info x86_disasm_info;2.14 +static x86_symbol *x86_symtab;2.15 +static int x86_num_symbols = 0;2.16 +2.17 void x86_disasm_init(char *buf, uint32_t vma, int buflen)2.18 {2.19 init_disassemble_info( &x86_disasm_info, NULL, x86_disasm_output );2.20 @@ -46,8 +49,35 @@2.21 x86_disasm_info.buffer = buf;2.22 x86_disasm_info.buffer_vma = vma;2.23 x86_disasm_info.buffer_length = buflen;2.24 + x86_disasm_info.print_address_func = x86_print_address;2.25 }2.27 +void x86_set_symtab( x86_symbol *symtab, int num_symbols )2.28 +{2.29 + x86_symtab = symtab;2.30 + x86_num_symbols = num_symbols;2.31 +}2.32 +2.33 +static const char *x86_find_symbol( bfd_vma memaddr, struct disassemble_info *info )2.34 +{2.35 + int i;2.36 + for( i=0; i<x86_num_symbols; i++ ) {2.37 + if( x86_symtab[i].ptr == (void *)memaddr ) {2.38 + return x86_symtab[i].name;2.39 + }2.40 + }2.41 + return NULL;2.42 +}2.43 +2.44 +static int x86_print_address( bfd_vma memaddr, struct disassemble_info *info )2.45 +{2.46 + const char *sym = x86_find_symbol(memaddr, info);2.47 + info->fprintf_func( info->stream, "%08X", memaddr );2.48 + if( sym != NULL ) {2.49 + info->fprintf_func( info->stream, " <%s>", sym );2.50 + }2.51 + return 0;2.52 +}2.54 uint32_t x86_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode )2.55 {
3.1 --- a/src/x86dasm/x86dasm.h Tue Sep 04 08:30:22 2007 +00003.2 +++ b/src/x86dasm/x86dasm.h Tue Sep 04 08:32:10 2007 +00003.3 @@ -1,5 +1,5 @@3.4 /**3.5 - * $Id: x86dasm.h,v 1.1 2007-08-28 08:46:54 nkeynes Exp $3.6 + * $Id: x86dasm.h,v 1.2 2007-09-04 08:32:10 nkeynes Exp $3.7 *3.8 * Wrapper around i386-dis to supply the same behaviour as the other3.9 * disassembly functions.3.10 @@ -21,4 +21,11 @@3.11 #include "mem.h"3.12 extern const struct cpu_desc_struct x86_cpu_desc;3.14 +typedef struct x86_symbol {3.15 + const char *name;3.16 + void *ptr;3.17 +} x86_symbol;3.18 +3.19 +void x86_set_symtab( x86_symbol *symtab, int num_symbols );3.20 +void x86_disasm_init(char *buf, uint32_t vma, int buflen);3.21 uint32_t x86_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode );
.