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