Skip to content

Commit

Permalink
PowerPC disas code
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@107 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
bellard committed Apr 29, 2003
1 parent ae48a07 commit b9adb4a
Show file tree
Hide file tree
Showing 6 changed files with 3,340 additions and 63 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ OBJS+= libqemu.a

LIBOBJS+=thunk.o translate-i386.o op-i386.o exec-i386.o
# NOTE: the disassembler code is only needed for debugging
LIBOBJS+=i386-dis.o dis-buf.o
LIBOBJS+=disas.o ppc-dis.o i386-dis.o dis-buf.o

all: qemu qemu-doc.html

Expand Down Expand Up @@ -96,7 +96,7 @@ test speed: qemu
make -C tests $@

TAGS:
etags *.[ch] i386/*.[ch]
etags *.[ch] tests/*.[ch]

# documentation
qemu-doc.html: qemu-doc.texi
Expand All @@ -109,7 +109,7 @@ Makefile elf.h thunk.c\
elfload.c main.c signal.c thunk.h\
cpu-i386.h qemu.h op-i386.c opc-i386.h syscall-i386.h translate-i386.c\
dis-asm.h gen-i386.h syscall.c\
dis-buf.c i386-dis.c opreg_template.h syscall_defs.h\
dis-buf.c disas.c disas.h ppc-dis.c i386-dis.c opreg_template.h syscall_defs.h\
ppc.ld s390.ld exec-i386.h exec-i386.c path.c configure \
tests/Makefile\
tests/test-i386.c tests/test-i386-shift.h tests/test-i386.h\
Expand Down
1 change: 1 addition & 0 deletions dis-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ extern int print_insn_w65 PARAMS ((bfd_vma, disassemble_info*));
extern int print_insn_d10v PARAMS ((bfd_vma, disassemble_info*));
extern int print_insn_v850 PARAMS ((bfd_vma, disassemble_info*));
extern int print_insn_tic30 PARAMS ((bfd_vma, disassemble_info*));
extern int print_insn_ppc PARAMS ((bfd_vma, disassemble_info*));

#if 0
/* Fetch the disassembler for a given BFD, if that support is available. */
Expand Down
79 changes: 79 additions & 0 deletions disas.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* General "disassemble this chunk" code. Used for debugging. */
#include "dis-asm.h"
#include "disas.h"
#include "elf.h"

/* Filled in by elfload.c. Simplistic, but will do for now. */
unsigned int disas_num_syms;
void *disas_symtab;
const char *disas_strtab;

/* Disassemble this for me please... (debugging). */
void disas(FILE *out, void *code, unsigned long size, enum disas_type type)
{
uint8_t *pc;
int count;
struct disassemble_info disasm_info;
int (*print_insn)(bfd_vma pc, disassemble_info *info);

INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);

disasm_info.buffer = code;
disasm_info.buffer_vma = (unsigned long)code;
disasm_info.buffer_length = size;

if (type == DISAS_TARGET) {
#ifdef WORDS_BIGENDIAN
disasm_info.endian = BFD_ENDIAN_BIG;
#else
disasm_info.endian = BFD_ENDIAN_LITTLE;
#endif
#ifdef __i386__
disasm_info.mach = bfd_mach_i386_i386;
print_insn = print_insn_i386;
#elif defined(__powerpc__)
print_insn = print_insn_ppc;
#else
fprintf(out, "Asm output not supported on this arch\n");
return;
#endif
} else {
/* Currently only source supported in x86. */
disasm_info.endian = BFD_ENDIAN_LITTLE;
if (type == DISAS_I386_I386)
disasm_info.mach = bfd_mach_i386_i386;
else
disasm_info.mach = bfd_mach_i386_i8086;
print_insn = print_insn_i386;
}

for (pc = code; pc < (uint8_t *)code + size; pc += count) {
fprintf(out, "0x%08lx: ", (long)pc);
count = print_insn((long)pc, &disasm_info);
fprintf(out, "\n");
if (count < 0)
break;
}
}

/* Look up symbol for debugging purpose. Returns "" if unknown. */
const char *lookup_symbol(void *orig_addr)
{
unsigned int i;
/* Hack, because we know this is x86. */
Elf32_Sym *sym = disas_symtab;

for (i = 0; i < disas_num_syms; i++) {
if (sym[i].st_shndx == SHN_UNDEF
|| sym[i].st_shndx >= SHN_LORESERVE)
continue;

if (ELF_ST_TYPE(sym[i].st_info) != STT_FUNC)
continue;

if ((long)orig_addr >= sym[i].st_value
&& (long)orig_addr < sym[i].st_value + sym[i].st_size)
return disas_strtab + sym[i].st_name;
}
return "";
}
20 changes: 20 additions & 0 deletions disas.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef _QEMU_DISAS_H
#define _QEMU_DISAS_H

enum disas_type {
DISAS_I386_I386,
DISAS_I386_I8086,
DISAS_TARGET, /* whatever host is. */
};

/* Disassemble this for me please... (debugging). */
void disas(FILE *out, void *code, unsigned long size, enum disas_type type);

/* Look up symbol for debugging purpose. Returns "" if unknown. */
const char *lookup_symbol(void *orig_addr);

/* Filled in by elfload.c. Simplistic, but will do for now. */
extern unsigned int disas_num_syms;
extern void *disas_symtab; /* FIXME: includes are a mess --RR */
extern const char *disas_strtab;
#endif /* _QEMU_DISAS_H */
Loading

0 comments on commit b9adb4a

Please sign in to comment.