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