CACAO
disass-common.cpp
Go to the documentation of this file.
1 /* src/vm/jit/disass-common.cpp - common 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 */
24 
25 
26 #include "config.h"
27 
28 #include <dis-asm.h>
29 #include <cstdarg>
30 #include <cstdio>
31 
32 #include "vm/types.hpp"
33 
34 #include "mm/memory.hpp"
35 
36 #include "vm/jit/disass.hpp"
37 
38 
39 /* global variables ***********************************************************/
40 
41 #if defined(WITH_BINUTILS_DISASSEMBLER)
42 disassemble_info info;
43 bool disass_initialized = false;
44 #endif
45 
46 
47 /* We need this on i386 and x86_64 since we don't know the byte length
48  of currently printed instructions. 512 bytes should be enough. */
49 
50 #if defined(__I386__) || defined(__X86_64__) || defined(__S390__) || defined(__aarch64__)
51 char disass_buf[512];
52 s4 disass_len;
53 #endif
54 
55 
56 /* disassemble *****************************************************************
57 
58  Outputs a disassembler listing of some machine code on `stdout'.
59 
60  start: pointer to first machine instruction
61  end: pointer after last machine instruction
62 
63 *******************************************************************************/
64 
65 #if defined(ENABLE_JIT)
66 void disassemble(u1 *start, u1 *end)
67 {
68  printf(" --- disassembler listing ---\n");
69 
70  for (; start < end; )
71  start = disassinstr(start);
72 }
73 #endif
74 
75 
76 /* disass_printf ***************************************************************
77 
78  Required by binutils disassembler. This just prints the
79  disassembled instructions to stdout.
80 
81 *******************************************************************************/
82 
83 void disass_printf(PTR p, const char *fmt, ...)
84 {
85  va_list ap;
86 
87  va_start(ap, fmt);
88 
89 #if defined(__I386__) || defined(__X86_64__) || defined(__S390__) || defined(__aarch64__)
90  disass_len += vsprintf(disass_buf + disass_len, fmt, ap);
91 #else
92  vprintf(fmt, ap);
93  fflush(stdout);
94 #endif
95 
96  va_end(ap);
97 }
98 
99 
100 /* buffer_read_memory **********************************************************
101 
102  We need to replace the buffer_read_memory from binutils.
103 
104 *******************************************************************************/
105 
106 int disass_buffer_read_memory(bfd_vma memaddr, bfd_byte *myaddr, unsigned int length, struct disassemble_info *info)
107 {
108  MCOPY(myaddr, (void *) (ptrint) memaddr, u1, length);
109 
110  return 0;
111 }
112 
113 
114 /*
115  * These are local overrides for various environment variables in Emacs.
116  * Please do not remove this and leave it at the end of the file, where
117  * Emacs will automagically detect them.
118  * ---------------------------------------------------------------------
119  * Local variables:
120  * mode: c++
121  * indent-tabs-mode: t
122  * c-basic-offset: 4
123  * tab-width: 4
124  * End:
125  */
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
int32_t s4
Definition: types.hpp:45
void disass_printf(PTR p, const char *fmt,...)
void disassemble(u1 *start, u1 *end)
Definition: disass.cpp:403
#define MCOPY(dest, src, type, num)
Definition: memory.hpp:103
uintptr_t ptrint
Definition: types.hpp:54
const char const void jint length
Definition: jvmti.h:352
#define printf(...)
Definition: ssa2.cpp:40