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