CACAO
disass.cpp
Go to the documentation of this file.
1 /* src/vm/jit/i386/disass.cpp - wrapper functions for GNU binutils disassembler
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23  Contact: cacao@cacaojvm.org
24 
25  Authors: Andreas Krall
26  Reinhard Grafl
27 
28  Changes: Christian Thalinger
29 
30 */
31 
32 
33 #include "config.h"
34 
35 #include <assert.h>
36 #include <dis-asm.h>
37 #include <stdarg.h>
38 
39 #include "vm/types.hpp"
40 
41 #include "vm/global.hpp"
42 #include "vm/jit/disass.hpp"
43 
44 
45 /* disassinstr *****************************************************************
46 
47  Outputs a disassembler listing of one machine code instruction on
48  'stdout'.
49 
50  code: instructions machine code
51 
52 *******************************************************************************/
53 
54 u1 *disassinstr(u1 *code)
55 {
56  s4 seqlen;
57  s4 i;
58 
59  if (!disass_initialized) {
60  INIT_DISASSEMBLE_INFO(info, NULL, disass_printf);
61 
62  /* setting the struct members must be done after
63  INIT_DISASSEMBLE_INFO */
64 
65  info.mach = bfd_mach_i386_i386;
66  info.read_memory_func = &disass_buffer_read_memory;
67 
68  disass_initialized = 1;
69  }
70 
71  printf("0x%08x: ", (s4) code);
72 
73  disass_len = 0;
74 
75  seqlen = print_insn_i386((bfd_vma) (ptrint) code, &info);
76 
77  for (i = 0; i < seqlen; i++, code++) {
78  printf("%02x ", *code);
79  }
80 
81  for (; i < 8; i++) {
82  printf(" ");
83  }
84 
85  printf(" %s\n", disass_buf);
86 
87  return code;
88 }
89 
90 
91 /*
92  * These are local overrides for various environment variables in Emacs.
93  * Please do not remove this and leave it at the end of the file, where
94  * Emacs will automagically detect them.
95  * ---------------------------------------------------------------------
96  * Local variables:
97  * mode: c++
98  * indent-tabs-mode: t
99  * c-basic-offset: 4
100  * tab-width: 4
101  * End:
102  */
int disass_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
u1 * disassinstr(u1 *code)
Definition: disass.cpp:48
uint8_t u1
Definition: types.hpp:40
MIIterator i
int32_t s4
Definition: types.hpp:45
void disass_printf(PTR p, const char *fmt,...)
uintptr_t ptrint
Definition: types.hpp:54
#define printf(...)
Definition: ssa2.cpp:40