* generic_print_address: fixed typo which generated a wrong address
[cacao.git] / src / vm / jit / powerpc / disass.c
1 /* src/vm/jit/powerpc/disass.c - wrapper functions for GNU binutils disassembler
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Andreas  Krall
28             Reinhard Grafl
29
30    Changes: Stefan Ring
31             Christian Thalinger
32
33    $Id: disass.c 2807 2005-06-23 13:51:33Z twisti $
34
35 */
36
37
38 #include <stdarg.h>
39 #include <string.h>
40 #include <assert.h>
41 #include "disass.h"
42 #include "dis-asm.h"
43
44 char *regs[] = {
45         "r0",
46         "r1",
47         "r2",
48         "r3",
49         "r4",
50         "r5",
51         "r6",
52         "r7",
53         "r8",
54         "r9",
55         "r10",
56         "r11",
57         "r12",
58         "r13",
59         "r14",
60         "r15",
61         "r16",
62         "r17",
63         "r18",
64         "r19",
65         "r20",
66         "r21",
67         "r22",
68         "r23",
69         "r24",
70         "r25",
71         "r26",
72         "r27",
73         "r28",
74         "r29",
75         "r30",
76         "r31",
77 };
78
79
80 void myprintf(PTR p, const char *fmt, ...)
81 {
82         va_list ap;
83         va_start(ap, fmt);
84         vprintf(fmt, ap);
85         va_end(ap);
86         fflush(stdout);
87 }
88
89
90 int buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
91 {
92         memcpy(myaddr, (void*) memaddr, length);
93         return 0;
94 }
95
96
97 void perror_memory(int status, bfd_vma memaddr, struct disassemble_info *info)
98 {
99         assert(0);
100 }
101
102
103 void generic_print_address(bfd_vma addr, struct disassemble_info *info)
104 {
105 /*      myprintf(NULL, "0x%x", addr - (u4) info->application_data); */
106         myprintf(NULL, "0x%08x", addr);
107 }
108
109
110 int generic_symbol_at_address(bfd_vma addr, struct disassemble_info *info)
111 {
112         assert(0);
113 }
114
115
116 unsigned long bfd_getb32(void *buf)
117 {
118         return *(unsigned long *) buf;
119 }
120
121
122 unsigned long bfd_getl32(void *buf)
123 {
124         return *(unsigned long *) buf;
125 }
126
127
128 void sprintf_vma(char *buf, bfd_vma disp)
129 {
130         sprintf(buf, "0x%x", disp);
131 }
132
133
134 void disassinstr(s4 *code)
135 {
136         disassemble_info info;
137
138         printf("0x%08x:   %08x    ", (s4) code, *code);
139
140         INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
141 /*      info.application_data = (u4) code - pos; */
142         print_insn_big_powerpc((bfd_vma) code, &info);
143         printf("\n");
144 }
145
146
147 void disassemble(s4 *code, s4 len)
148 {
149         s4 i;
150         disassemble_info info;
151
152         INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
153 /*      info.application_data = code; */
154         printf ("  --- disassembler listing ---\n");
155         for (i = 0; i < len; i += 4, code++)
156                 disassinstr(code);
157 }
158
159
160 /*
161  * These are local overrides for various environment variables in Emacs.
162  * Please do not remove this and leave it at the end of the file, where
163  * Emacs will automagically detect them.
164  * ---------------------------------------------------------------------
165  * Local variables:
166  * mode: c
167  * indent-tabs-mode: t
168  * c-basic-offset: 4
169  * tab-width: 4
170  * End:
171  */