* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / jit / x86_64 / 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 4357 2006-01-22 23:33:38Z twisti $
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         "rax",
54         "rcx",
55         "rdx",
56         "rbx",
57         "rsp",
58         "rbp",
59         "rsi",
60         "rdi",
61     "r8",
62     "r9",
63     "r10",
64     "r11",
65     "r12",
66     "r13",
67     "r14",
68     "r15"
69 };
70
71
72 /* disassinstr *****************************************************************
73
74    Outputs a disassembler listing of one machine code instruction on
75    `stdout'.
76
77    code: pointer to machine code
78
79 *******************************************************************************/
80
81 u1 *disassinstr(u1 *code)
82 {
83         s4 seqlen;
84         s4 i;
85
86         if (!disass_initialized) {
87                 INIT_DISASSEMBLE_INFO(info, NULL, disass_printf);
88
89                 /* setting the struct members must be done after
90                    INIT_DISASSEMBLE_INFO */
91
92                 info.mach             = bfd_mach_x86_64;
93                 info.read_memory_func = &disass_buffer_read_memory;
94
95                 disass_initialized = true;
96         }
97
98         printf("0x%016lx:   ", (s8) code);
99
100         disass_len = 0;
101
102         seqlen = print_insn_i386((bfd_vma) code, &info);
103
104         for (i = 0; i < seqlen; i++, code++) {
105                 printf("%02x ", *code);
106         }
107         
108         for (; i < 10; i++) {
109                 printf("   ");
110         }
111
112         printf("   %s\n", disass_buf);
113
114         return code;
115 }
116
117
118 /*
119  * These are local overrides for various environment variables in Emacs.
120  * Please do not remove this and leave it at the end of the file, where
121  * Emacs will automagically detect them.
122  * ---------------------------------------------------------------------
123  * Local variables:
124  * mode: c
125  * indent-tabs-mode: t
126  * c-basic-offset: 4
127  * tab-width: 4
128  * End:
129  */