1 /* src/vm/jit/x86_64/disass.c - wrapper functions for GNU binutils disassembler
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
32 $Id: disass.c 2855 2005-06-28 18:32:46Z twisti $
39 #include "mm/memory.h"
40 #include "vm/jit/x86_64/dis-asm.h"
41 #include "vm/jit/x86_64/types.h"
44 /* global variables ***********************************************************/
50 /* name table for 16 integer registers */
72 void myprintf(PTR p, const char *fmt, ...)
76 mylen += vsprintf(mylinebuf + mylen, fmt, ap);
81 int buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
84 *myaddr = *((u1 *) memaddr);
87 MCOPY(myaddr, (void *) memaddr, u1, length);
94 /* disassinstr *****************************************************************
96 Outputs a disassembler listing of one machine code instruction on
99 code: pointer to machine code
101 *******************************************************************************/
103 int disassinstr(u1 *code)
105 static disassemble_info info;
106 static int dis_initialized;
110 if (!dis_initialized) {
111 INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
112 info.mach = bfd_mach_x86_64;
116 printf("0x%016lx: ", (s8) code);
118 seqlen = print_insn_i386((bfd_vma) code, &info);
120 for (i = 0; i < seqlen; i++) {
121 printf("%02x ", *(code++));
124 for (; i < 10; i++) {
128 printf(" %s\n", mylinebuf);
134 /* disassemble *****************************************************************
136 Outputs a disassembler listing of some machine code on `stdout'.
138 code: pointer to first instruction
141 *******************************************************************************/
143 void disassemble(u1 *code, s4 len)
147 disassemble_info info;
149 INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
150 info.mach = bfd_mach_x86_64;
152 printf(" --- disassembler listing ---\n");
153 for (i = 0; i < len; ) {
154 seqlen = disassinstr(code);
162 * These are local overrides for various environment variables in Emacs.
163 * Please do not remove this and leave it at the end of the file, where
164 * Emacs will automagically detect them.
165 * ---------------------------------------------------------------------
168 * indent-tabs-mode: t