ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/mon/src/mon_disass.cpp
(Generate patch)

Comparing mon/src/mon_disass.cpp (file contents):
Revision 1.1 by cebix, 2000-09-25T12:44:34Z vs.
Revision 1.11 by gbeauche, 2007-06-07T09:51:56Z

# Line 1 | Line 1
1   /*
2   *  mon_disass.cpp - Disassemblers
3   *
4 < *  mon (C) 1997-2000 Christian Bauer, Marc Hellwig
4 > *  cxmon (C) 1997-2004 Christian Bauer, Marc Hellwig
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 20 | Line 20
20  
21   #include "sysdeps.h"
22  
23 + #include <assert.h>
24   #include <stdarg.h>
25  
26   #include "mon.h"
27   #include "mon_disass.h"
28 +
29 + #include "mon_atraps.h"
30   #include "mon_lowmem.h"
31  
32  
33 + // Flag: enable MacOS A-Trap and LM globals lookup in 68k disassembler
34 + bool mon_macos_mode = false;
35 +
36 +
37   /*
38   *  GNU disassembler callbacks
39   */
# Line 34 | Line 41
41   extern "C" {
42   #include "disass/dis-asm.h"
43  
44 < int buffer_read_memory(bfd_vma from, bfd_byte *to, int length, struct disassemble_info *info)
44 > int buffer_read_memory(bfd_vma from, bfd_byte *to, unsigned int length, struct disassemble_info *info)
45   {
46          while (length--)
47                  *to++ = mon_read_byte(from++);
# Line 50 | Line 57 | bool lookup_lowmem;
57  
58   void generic_print_address(bfd_vma addr, struct disassemble_info *info)
59   {
60 <        if (lookup_lowmem && ((addr >= 0x100 && addr < 0x400) || (addr >= 0x800 && addr < 0xe00) || (addr >= 0x1e00 && addr < 0x3000))) {
61 <                // Look for address in low memory globals table
62 <                const lowmem_info *p = lowmem;
63 <                while (p->name) {
64 <                        if (addr >= p[0].addr && addr < p[1].addr) {
65 <                                if (addr == p[0].addr)
66 <                                        info->fprintf_func(info->stream, "%s", p->name);
67 <                                else
68 <                                        info->fprintf_func(info->stream, "%s+%d", p->name, addr - p->addr);
69 <                                return;
60 >        if (lookup_lowmem && addr >= 0x100 && addr < 0x3000) {
61 >                if (((addr >= 0x400 && addr < 0x800) || (addr >= 0xe00 && addr < 0x1e00)) && ((addr & 3) == 0)) {
62 >                        // Look for address in A-Trap table
63 >                        uint16 opcode = (addr < 0xe00 ? 0xa000 + (addr - 0x400) / 4 : 0xa800 + (addr - 0xe00) / 4);
64 >                        uint16 mask = (addr < 0xe00 ? 0xf8ff : 0xffff);
65 >                        const atrap_info *p = atraps;
66 >                        while (p->word) {
67 >                                if ((p->word & mask) == opcode) {
68 >                                        info->fprintf_func(info->stream, p->name);
69 >                                        return;
70 >                                }
71 >                                p++;
72 >                        }
73 >                } else {
74 >                        // Look for address in low memory globals table
75 >                        const lowmem_info *p = lowmem;
76 >                        while (p->name) {
77 >                                if (addr >= p[0].addr && addr < p[1].addr) {
78 >                                        if (addr == p[0].addr)
79 >                                                info->fprintf_func(info->stream, "%s", p->name);
80 >                                        else
81 >                                                info->fprintf_func(info->stream, "%s+%d", p->name, addr - p->addr);
82 >                                        return;
83 >                                }
84 >                                p++;
85                          }
64                        p++;
86                  }
87          }
88 <        info->fprintf_func(info->stream, "$%08x", addr);
88 >        if (addr >= UVAL64(0x100000000))
89 >                info->fprintf_func(info->stream, "$%08x%08x", (uint32)(addr >> 32), (uint32)addr);
90 >        else
91 >                info->fprintf_func(info->stream, "$%08x", (uint32)addr);
92   }
93  
94   int generic_symbol_at_address(bfd_vma addr, struct disassemble_info *info)
# Line 72 | Line 96 | int generic_symbol_at_address(bfd_vma ad
96          return 0;
97   }
98  
99 + void print_68k_invalid_opcode(unsigned long opcode, struct disassemble_info *info)
100 + {
101 +        if (mon_macos_mode) {
102 +                // Look for MacOS A-Trap
103 +                const atrap_info *p = atraps;
104 +                while (p->word) {
105 +                        if (p->word == opcode) {
106 +                                info->fprintf_func(info->stream, p->name);
107 +                                return;
108 +                        }
109 +                        p++;
110 +                }
111 +        }
112 +        info->fprintf_func(info->stream, "?");
113 + }
114 +
115   };
116  
117  
# Line 111 | Line 151 | int disass_68k(FILE *f, uint32 adr)
151          INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf);
152  
153          // Disassemble instruction
154 <        lookup_lowmem = true;
154 >        lookup_lowmem = mon_macos_mode;
155          int num = print_insn_m68k(adr, &info);
156 <        if (num >= 2)
157 <                fprintf(f, "%04x ", mon_read_half(adr));
158 <        else
159 <                fprintf(f, "     ");
160 <        if (num >= 4)
161 <                fprintf(f, "%04x ", mon_read_half(adr + 2));
162 <        else
123 <                fprintf(f, "     ");
124 <        if (num >= 6)
125 <                fprintf(f, "%04x ", mon_read_half(adr + 4));
126 <        else
127 <                fprintf(f, "     ");
156 >
157 >        for (int i=0; i<6; i+=2) {
158 >                if (num > i)
159 >                        fprintf(f, "%04x ", mon_read_half(adr + i));
160 >                else
161 >                        fprintf(f, "     ");
162 >        }
163          if (num == 8)
164                  fprintf(f, "%04x\t%s\n", mon_read_half(adr + 6), buf);
165 <        else if (num >= 8)
165 >        else if (num > 8)
166                  fprintf(f, "...\t%s\n", buf);
167          else
168                  fprintf(f, "   \t%s\n", buf);
169 +
170          return num;
171   }
172  
173 < int disass_x86(FILE *f, uint32 adr)
173 > int disass_mips(FILE *f, uint32 adr, int little_endian)
174   {
175          // Initialize info for GDB disassembler
176          disassemble_info info;
# Line 146 | Line 182 | int disass_x86(FILE *f, uint32 adr)
182  
183          // Disassemble instruction
184          lookup_lowmem = false;
185 <        int num = print_insn_i386(adr, &info);
186 <        fprintf(f, "%s\n", buf);
185 >        int num = little_endian ? print_insn_little_mips(adr, &info) : print_insn_big_mips(adr, &info);
186 >
187 >        assert(num == 4);
188 >        for (int i=0; i<4; i++)
189 >                fprintf(f, " %02x", mon_read_byte(adr + i));
190 >
191 >        fprintf(f, "  %s\n", buf);
192 >
193 >        return num;
194 > }
195 >
196 > int disass_x86(FILE *f, uint32 adr, uint32 bits)
197 > {
198 >        // Initialize info for GDB disassembler
199 >        disassemble_info info;
200 >        char buf[1024];
201 >        SFILE sfile = {buf, buf};
202 >        sfile.buffer = buf;
203 >        sfile.current = buf;
204 >        INIT_DISASSEMBLE_INFO(info, (FILE *)&sfile, (fprintf_ftype)mon_sprintf);
205 >        if (bits == 16)
206 >                info.mach = bfd_mach_i386_i8086;
207 >        else if (bits == 64)
208 >                info.mach = bfd_mach_x86_64;
209 >
210 >        // Disassemble instruction
211 >        lookup_lowmem = false;
212 >        int num = print_insn_i386_att(adr, &info);
213 >
214 >        for (int i=0; i<6; i++) {
215 >                if (num > i)
216 >                        fprintf(f, "%02x ", mon_read_byte(adr + i));
217 >                else
218 >                        fprintf(f, "   ");
219 >        }
220 >        if (num == 7)
221 >                fprintf(f, "%02x\t%s\n", mon_read_byte(adr + 7), buf);
222 >        else if (num > 7)
223 >                fprintf(f, "..\t%s\n", buf);
224 >        else
225 >                fprintf(f, "  \t%s\n", buf);
226 >
227          return num;
228   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines