Search
lxdream.org :: lxdream/src/x86dasm/x86dasm.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/x86dasm/x86dasm.c
changeset 365:94cab5ad0ed8
prev362:dc40e2064dc4
next376:8c7587af5a5d
author nkeynes
date Tue Sep 04 08:32:10 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Change sh4x86 test to translate/disasm full basic blocks
Add prelim sym-tab support
file annotate diff log raw
1.1 --- a/src/x86dasm/x86dasm.c Tue Aug 28 08:46:54 2007 +0000
1.2 +++ b/src/x86dasm/x86dasm.c Tue Sep 04 08:32:10 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: x86dasm.c,v 1.1 2007-08-28 08:46:54 nkeynes Exp $
1.6 + * $Id: x86dasm.c,v 1.2 2007-09-04 08:32:10 nkeynes Exp $
1.7 *
1.8 * Wrapper around i386-dis to supply the same behaviour as the other
1.9 * disassembly functions.
1.10 @@ -37,6 +37,9 @@
1.11
1.12 static struct disassemble_info x86_disasm_info;
1.13
1.14 +static x86_symbol *x86_symtab;
1.15 +static int x86_num_symbols = 0;
1.16 +
1.17 void x86_disasm_init(char *buf, uint32_t vma, int buflen)
1.18 {
1.19 init_disassemble_info( &x86_disasm_info, NULL, x86_disasm_output );
1.20 @@ -46,8 +49,35 @@
1.21 x86_disasm_info.buffer = buf;
1.22 x86_disasm_info.buffer_vma = vma;
1.23 x86_disasm_info.buffer_length = buflen;
1.24 + x86_disasm_info.print_address_func = x86_print_address;
1.25 }
1.26
1.27 +void x86_set_symtab( x86_symbol *symtab, int num_symbols )
1.28 +{
1.29 + x86_symtab = symtab;
1.30 + x86_num_symbols = num_symbols;
1.31 +}
1.32 +
1.33 +static const char *x86_find_symbol( bfd_vma memaddr, struct disassemble_info *info )
1.34 +{
1.35 + int i;
1.36 + for( i=0; i<x86_num_symbols; i++ ) {
1.37 + if( x86_symtab[i].ptr == (void *)memaddr ) {
1.38 + return x86_symtab[i].name;
1.39 + }
1.40 + }
1.41 + return NULL;
1.42 +}
1.43 +
1.44 +static int x86_print_address( bfd_vma memaddr, struct disassemble_info *info )
1.45 +{
1.46 + const char *sym = x86_find_symbol(memaddr, info);
1.47 + info->fprintf_func( info->stream, "%08X", memaddr );
1.48 + if( sym != NULL ) {
1.49 + info->fprintf_func( info->stream, " <%s>", sym );
1.50 + }
1.51 + return 0;
1.52 +}
1.53
1.54 uint32_t x86_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode )
1.55 {
.