1 /* 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 1735 2004-12-07 14:33:27Z twisti $
39 #include "mm/memory.h"
40 #include "vm/jit/x86_64/dis-asm.h"
41 #include "vm/jit/x86_64/types.h"
51 /* 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 /* function disassinstr ********************************************************
96 outputs a disassembler listing of one machine code instruction on 'stdout'
97 c: instructions machine code
98 pos: instructions address relative to method start
100 *******************************************************************************/
102 int disassinstr(u1 *code, int pos)
104 static disassemble_info info;
105 static int dis_initialized;
109 if (!dis_initialized) {
110 INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
111 info.mach = bfd_mach_x86_64;
115 printf("0x%016lx: ", (s8) code);
117 seqlen = print_insn_i386((bfd_vma) code, &info);
119 for (i = 0; i < seqlen; i++) {
120 printf("%02x ", *(code++));
123 for (; i < 10; i++) {
127 printf(" %s\n", mylinebuf);
133 /* function disassemble ********************************************************
135 outputs a disassembler listing of some machine code on 'stdout'
136 code: pointer to first instruction
137 len: code size (number of instructions * 4)
139 *******************************************************************************/
141 void disassemble(u1 *code, int len)
146 disassemble_info info;
148 INIT_DISASSEMBLE_INFO(info, NULL, myprintf);
149 info.mach = bfd_mach_x86_64;
151 printf(" --- disassembler listing ---\n");
152 for (p = 0; p < len;) {
153 printf("0x%016lx: ", (s8) code);
156 seqlen = print_insn_i386((bfd_vma) code, &info);
159 for (i = 0; i < seqlen; i++) {
160 printf("%02x ", *(code++));
163 for (; i < 10; i++) {
167 printf(" %s\n", mylinebuf);
173 * These are local overrides for various environment variables in Emacs.
174 * Please do not remove this and leave it at the end of the file, where
175 * Emacs will automagically detect them.
176 * ---------------------------------------------------------------------
179 * indent-tabs-mode: t