static link
[qemu] / disas.c
diff --git a/disas.c b/disas.c
index 2a8a533..d5aa7f3 100644 (file)
--- a/disas.c
+++ b/disas.c
@@ -5,6 +5,9 @@
 #include "elf.h"
 #include <errno.h>
 
+#include "cpu.h"
+#include "exec-all.h"
+
 /* Filled in by elfload.c.  Simplistic, but will do for now. */
 unsigned int disas_num_syms;
 void *disas_symtab;
@@ -19,13 +22,31 @@ buffer_read_memory (memaddr, myaddr, length, info)
      int length;
      struct disassemble_info *info;
 {
-  if (memaddr < info->buffer_vma
-      || memaddr + length > info->buffer_vma + info->buffer_length)
-    /* Out of bounds.  Use EIO because GDB uses it.  */
-    return EIO;
-  memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
-  return 0;
+    if (memaddr < info->buffer_vma
+        || memaddr + length > info->buffer_vma + info->buffer_length)
+        /* Out of bounds.  Use EIO because GDB uses it.  */
+        return EIO;
+    memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
+    return 0;
+}
+
+#if !defined(CONFIG_USER_ONLY)
+/* Get LENGTH bytes from info's buffer, at target address memaddr.
+   Transfer them to myaddr.  */
+static int
+target_read_memory (memaddr, myaddr, length, info)
+     bfd_vma memaddr;
+     bfd_byte *myaddr;
+     int length;
+     struct disassemble_info *info;
+{
+    int i;
+    for(i = 0; i < length; i++) {
+        myaddr[i] = ldub_code((void *)((long)memaddr + i));
+    }
+    return 0;
 }
+#endif
 
 /* Print an error message.  We can assume that this is in response to
    an error return from buffer_read_memory.  */
@@ -42,7 +63,7 @@ perror_memory (status, memaddr, info)
     /* Actually, address between memaddr and memaddr + len was
        out of bounds.  */
     (*info->fprintf_func) (info->stream,
-                          "Address 0x%x is out of bounds.\n", memaddr);
+                          "Address 0x%llx is out of bounds.\n", memaddr);
 }
 
 /* This could be in a separate file, to save miniscule amounts of space
@@ -57,7 +78,7 @@ generic_print_address (addr, info)
      bfd_vma addr;
      struct disassemble_info *info;
 {
-  (*info->fprintf_func) (info->stream, "0x%x", addr);
+  (*info->fprintf_func) (info->stream, "0x%llx", addr);
 }
 
 /* Just return the given address.  */
@@ -92,8 +113,9 @@ bfd_vma bfd_getb32 (const bfd_byte *addr)
   return (bfd_vma) v;
 }
 
-/* Disassemble this for me please... (debugging). */
-void disas(FILE *out, void *code, unsigned long size, enum disas_type type)
+/* Disassemble this for me please... (debugging). 'flags' is only used
+   for i386: non zero means 16 bit code */
+void disas(FILE *out, void *code, unsigned long size, int is_host, int flags)
 {
     uint8_t *pc;
     int count;
@@ -102,11 +124,17 @@ void disas(FILE *out, void *code, unsigned long size, enum disas_type type)
 
     INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
 
+#if !defined(CONFIG_USER_ONLY)
+    if (!is_host) {
+        disasm_info.read_memory_func = target_read_memory;
+    }
+#endif
+
     disasm_info.buffer = code;
     disasm_info.buffer_vma = (unsigned long)code;
     disasm_info.buffer_length = size;
 
-    if (type == DISAS_TARGET) {
+    if (is_host) {
 #ifdef WORDS_BIGENDIAN
        disasm_info.endian = BFD_ENDIAN_BIG;
 #else
@@ -128,13 +156,25 @@ void disas(FILE *out, void *code, unsigned long size, enum disas_type type)
        return;
 #endif
     } else {
-       /* Currently only source supported in x86. */
+#ifdef TARGET_WORDS_BIGENDIAN
+       disasm_info.endian = BFD_ENDIAN_BIG;
+#else
        disasm_info.endian = BFD_ENDIAN_LITTLE;
-       if (type == DISAS_I386_I386)
+#endif
+#if defined(TARGET_I386)
+        if (!flags)
            disasm_info.mach = bfd_mach_i386_i386;
        else
            disasm_info.mach = bfd_mach_i386_i8086;
        print_insn = print_insn_i386;
+#elif defined(TARGET_ARM)
+       print_insn = print_insn_arm;
+#elif defined(TARGET_SPARC)
+       print_insn = print_insn_sparc;
+#else
+       fprintf(out, "Asm output not supported on this arch\n");
+       return;
+#endif
     }
 
     for (pc = code; pc < (uint8_t *)code + size; pc += count) {
@@ -142,7 +182,7 @@ void disas(FILE *out, void *code, unsigned long size, enum disas_type type)
 #ifdef __arm__
         /* since data are included in the code, it is better to
            display code data too */
-        if (type == DISAS_TARGET) {
+        if (is_host) {
             fprintf(out, "%08x  ", (int)bfd_getl32((const bfd_byte *)pc));
         }
 #endif