f6c0468f4fba726f0f1cdabe202e12a519ae3c19
[cacao.git] / src / vm / jit / powerpc / disass.c
1 /* jit/powerpc/disass.c - wrapper functions for GNU binutils disassembler
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    Institut f. Computersprachen, TU Wien
5    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6    S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
7    J. Wenninger
8
9    This file is part of CACAO.
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2, or (at
14    your option) any later version.
15
16    This program is distributed in the hope that it will be useful, but
17    WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24    02111-1307, USA.
25
26    Contact: cacao@complang.tuwien.ac.at
27
28    Authors: Andreas  Krall
29             Reinhard Grafl
30
31    Changes: Stefan Ring
32
33    $Id: disass.c 978 2004-03-25 23:45:51Z 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, "0x08%x", 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, s4 pos)
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         int p;
150         disassemble_info info;
151
152         INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
153 /*      info.application_data = code; */
154         printf ("  --- disassembler listing ---\n");
155         for (p = 0; p < len; p += 4, code++) {
156                 myprintf(NULL, "0x%08x:   %08x    ", (s4) code, *code);
157                 print_insn_big_powerpc((bfd_vma) code, &info);
158                 myprintf(NULL, "\n");
159         }
160 }
161
162
163 /*
164  * These are local overrides for various environment variables in Emacs.
165  * Please do not remove this and leave it at the end of the file, where
166  * Emacs will automagically detect them.
167  * ---------------------------------------------------------------------
168  * Local variables:
169  * mode: c
170  * indent-tabs-mode: t
171  * c-basic-offset: 4
172  * tab-width: 4
173  * End:
174  */