Commit c6105c0a042ba0ecb59038f9f2edab8aa4322baf

Authored by bellard
1 parent 93a40ea9

added correct memory access code for system emulation


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@407 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 33 additions and 6 deletions
@@ -5,6 +5,9 @@ @@ -5,6 +5,9 @@
5 #include "elf.h" 5 #include "elf.h"
6 #include <errno.h> 6 #include <errno.h>
7 7
  8 +#include "cpu.h"
  9 +#include "exec-all.h"
  10 +
8 /* Filled in by elfload.c. Simplistic, but will do for now. */ 11 /* Filled in by elfload.c. Simplistic, but will do for now. */
9 unsigned int disas_num_syms; 12 unsigned int disas_num_syms;
10 void *disas_symtab; 13 void *disas_symtab;
@@ -19,14 +22,32 @@ buffer_read_memory (memaddr, myaddr, length, info) @@ -19,14 +22,32 @@ buffer_read_memory (memaddr, myaddr, length, info)
19 int length; 22 int length;
20 struct disassemble_info *info; 23 struct disassemble_info *info;
21 { 24 {
22 - if (memaddr < info->buffer_vma  
23 - || memaddr + length > info->buffer_vma + info->buffer_length)  
24 - /* Out of bounds. Use EIO because GDB uses it. */  
25 - return EIO;  
26 - memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);  
27 - return 0; 25 + if (memaddr < info->buffer_vma
  26 + || memaddr + length > info->buffer_vma + info->buffer_length)
  27 + /* Out of bounds. Use EIO because GDB uses it. */
  28 + return EIO;
  29 + memcpy (myaddr, info->buffer + (memaddr - info->buffer_vma), length);
  30 + return 0;
28 } 31 }
29 32
  33 +#if !defined(CONFIG_USER_ONLY)
  34 +/* Get LENGTH bytes from info's buffer, at target address memaddr.
  35 + Transfer them to myaddr. */
  36 +static int
  37 +target_read_memory (memaddr, myaddr, length, info)
  38 + bfd_vma memaddr;
  39 + bfd_byte *myaddr;
  40 + int length;
  41 + struct disassemble_info *info;
  42 +{
  43 + int i;
  44 + for(i = 0; i < length; i++) {
  45 + myaddr[i] = ldub_code((void *)((long)memaddr));
  46 + }
  47 + return 0;
  48 +}
  49 +#endif
  50 +
30 /* Print an error message. We can assume that this is in response to 51 /* Print an error message. We can assume that this is in response to
31 an error return from buffer_read_memory. */ 52 an error return from buffer_read_memory. */
32 void 53 void
@@ -103,6 +124,12 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags) @@ -103,6 +124,12 @@ void disas(FILE *out, void *code, unsigned long size, int is_host, int flags)
103 124
104 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf); 125 INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
105 126
  127 +#if !defined(CONFIG_USER_ONLY)
  128 + if (!is_host) {
  129 + disasm_info.read_memory_func = target_read_memory;
  130 + }
  131 +#endif
  132 +
106 disasm_info.buffer = code; 133 disasm_info.buffer = code;
107 disasm_info.buffer_vma = (unsigned long)code; 134 disasm_info.buffer_vma = (unsigned long)code;
108 disasm_info.buffer_length = size; 135 disasm_info.buffer_length = size;