234ad92786940c5b309d6d431e2365fac75da4a4
[cacao.git] / src / vm / jit / s390 / disass.c
1 /* src/vm/jit/x86_64/disass.c - wrapper functions for GNU binutils disassembler
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Andreas  Krall
28             Reinhard Grafl
29
30    Changes: Christian Thalinger
31
32    $Id: disass.c 7848 2007-05-01 21:40:26Z pm $
33
34 */
35
36
37 #include "config.h"
38
39 #include <dis-asm.h>
40 #include <stdio.h>
41
42 #include "vm/types.h"
43
44 #include "vm/global.h"
45 #include "vm/jit/disass.h"
46
47
48 /* global variables ***********************************************************/
49
50 /* name table for 16 integer registers */
51
52 char *regs[] = {
53         "r0",
54         "r1",
55         "r2",
56         "r3",
57         "r4",
58         "r5",
59         "r6",
60         "r7",
61     "r8",
62     "r9",
63     "r10",
64     "r11",
65     "r12",
66     "r13",
67     "r14",
68     "r15"
69 };
70
71
72 /* disass_pseudo_instr *********************************************************
73
74    Outputs a disassembler listing of one pseudo instruction instruction on
75    `stdout'.
76         
77    Returns number of bytes consumed or 0 if code does not contain a pseudo 
78    instruction.
79
80    code: pointer to machine code
81
82 *******************************************************************************/
83
84 static s4 disass_pseudo_instr(u1 *code) {
85         switch (code[0]) {
86                 /* Trap */
87                 case 0x02:
88                         snprintf(disass_buf, 512, "ill\t0x%02hhx (pseudo)", code[1]);
89                         return 2;
90                 /* Not recognized */
91                 default:
92                         return 0;
93         }
94 }
95
96 /* disassinstr *****************************************************************
97
98    Outputs a disassembler listing of one machine code instruction on
99    `stdout'.
100
101    code: pointer to machine code
102
103 *******************************************************************************/
104
105 u1 *disassinstr(u1 *code)
106 {
107         s4 seqlen;
108         s4 i;
109
110         if (!disass_initialized) {
111                 INIT_DISASSEMBLE_INFO(info, NULL, disass_printf);
112
113                 /* setting the struct members must be done after
114                    INIT_DISASSEMBLE_INFO */
115
116                 info.mach             = bfd_mach_s390_31;
117                 info.read_memory_func = &disass_buffer_read_memory;
118
119                 disass_initialized = true;
120         }
121
122         printf("0x%08x:   ", (s4) code);
123
124         disass_len = 0;
125
126         seqlen = disass_pseudo_instr(code);
127
128         if (seqlen == 0) {
129                 seqlen = print_insn_s390((bfd_vma) code, &info);
130         }
131
132         for (i = 0; i < seqlen; i++, code++) {
133                 printf("%02x ", *code);
134         }
135         
136         for (; i < 10; i++) {
137                 printf("   ");
138         }
139
140         printf("   %s\n", disass_buf);
141
142         return code;
143 }
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  */