1 /* src/vm/jit/codegen-common.h - architecture independent code generator stuff
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
29 Changes: Christian Ullrich
32 $Id: codegen-common.h 5186 2006-07-28 13:24:43Z twisti $
37 #ifndef _CODEGEN_COMMON_H
38 #define _CODEGEN_COMMON_H
40 /* forward typedefs ***********************************************************/
42 typedef struct codegendata codegendata;
43 typedef struct codegen_critical_section_t codegen_critical_section_t;
49 #include "vm/global.h"
50 #include "vm/references.h"
51 #include "vm/method.h"
52 #include "vm/jit/dseg.h"
53 #include "vm/jit/jit.h"
54 #include "vm/jit/reg.h"
55 #include "vm/jit/code.h"
58 #define MCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
59 #define DSEGINITSIZE (1<<12) /* 4 Kbyte data area initialization size */
61 #define NCODEINITSIZE (1<<15) /* 32 Kbyte code area initialization size */
64 /* Register Pack/Unpack Macros ************************************************/
66 /* ATTENTION: Don't change the order where low and high bits are
67 stored! At least mips32 relies in one case on that order. */
69 #define PACK_REGS(low,high) \
70 ( (((high) & 0x0000ffff) << 16) | ((low) & 0x0000ffff) )
72 #define GET_LOW_REG(a) ((a) & 0x0000ffff)
73 #define GET_HIGH_REG(a) (((a) & 0xffff0000) >> 16)
76 /************************* critical sections *********************************/
78 struct codegen_critical_section_t {
79 codegen_critical_section_t *next;
87 u1 *mcodebase; /* base pointer of code area */
88 u1 *mcodeend; /* pointer to end of code area */
89 s4 mcodesize; /* complete size of code area (bytes) */
90 u1 *mcodeptr; /* code generation pointer */
91 u1 *lastmcodeptr; /* last patcher position of basic block */
93 #if defined(ENABLE_INTRP)
94 u1 *ncodebase; /* base pointer of native code area */
95 s4 ncodesize; /* complete size of native code area */
96 u1 *ncodeptr; /* native code generation pointer */
98 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
100 s4 lastpatcheroffset; /* -1 if current super has no patcher */
101 s4 dynsuperm; /* offsets of start of current dynamic ...*/
102 s4 dynsupern; /* ... superinstruction starts */
103 struct superstart *superstarts; /* list of supers without patchers */
106 dsegentry *dseg; /* chain of data segment entries */
107 s4 dseglen; /* used size of data area (bytes) */
108 /* data area grows from top to bottom */
110 jumpref *jumpreferences; /* list of jumptable target addresses */
112 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP)
113 dataref *datareferences; /* list of data segment references */
116 exceptionref *exceptionrefs; /* list of exception branches */
119 linenumberref *linenumberreferences; /* list of line numbers and the */
120 /* program counters of their first */
122 s4 linenumbertablesizepos;
123 s4 linenumbertablestartpos;
127 s4 exceptiontablelength; /* exceptiontable length */
128 exceptiontable *exceptiontable; /* the exceptiontable */
130 codegen_critical_section_t *threadcrit; /* List of critical code regions */
131 codegen_critical_section_t threadcritcurrent;
132 s4 threadcritcount; /* Number of critical regions */
139 /* methodtree_element *********************************************************/
141 typedef struct methodtree_element methodtree_element;
143 struct methodtree_element {
149 /* function prototypes ********************************************************/
151 void codegen_init(void);
152 void codegen_setup(jitdata *jd);
154 void codegen_close(void);
156 void codegen_increase(codegendata *cd);
158 #if defined(ENABLE_INTRP)
159 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
162 void codegen_addreference(codegendata *cd, basicblock *target);
164 void codegen_add_arithmeticexception_ref(codegendata *cd);
165 void codegen_add_arrayindexoutofboundsexception_ref(codegendata *cd, s4 reg);
166 void codegen_add_arraystoreexception_ref(codegendata *cd);
167 void codegen_add_classcastexception_ref(codegendata *cd, s4 reg);
168 void codegen_add_nullpointerexception_ref(codegendata *cd);
169 void codegen_add_fillinstacktrace_ref(codegendata *cd);
172 void codegen_addpatchref(codegendata *cd, functionptr patcher, voidptr ref,
175 void codegen_insertmethod(u1 *startpc, u1 *endpc);
176 u1 *codegen_findmethod(u1 *pc);
177 u1 *codegen_get_pv_from_pc_nocheck(u1 *pc);
179 void codegen_finish(jitdata *jd);
181 codeinfo *codegen_createnativestub(functionptr f, methodinfo *m);
182 #if defined(ENABLE_DISASSEMBLER)
183 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
186 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
187 java_objectheader *codegen_finish_native_call(u1 *datasp);
189 u1 *createcompilerstub(methodinfo *m);
190 u1 *createnativestub(functionptr f, jitdata *jd, methoddesc *nmd);
192 #if defined(ENABLE_INTRP)
193 u1 *intrp_createcompilerstub(methodinfo *m);
194 u1 *intrp_createnativestub(functionptr f, jitdata *jd, methoddesc *md);
197 void removecompilerstub(u1 *stub);
198 void removenativestub(u1 *stub);
200 s4 codegen_reg_of_var(registerdata *rd, u2 opcode, stackptr v, s4 tempregnum);
202 #if defined(ENABLE_THREADS)
203 void codegen_threadcritrestart(codegendata *cd, int offset);
204 void codegen_threadcritstart(codegendata *cd, int offset);
205 void codegen_threadcritstop(codegendata *cd, int offset);
208 /* machine dependent functions */
209 u1 *md_codegen_findmethod(u1 *ra);
211 bool codegen(jitdata *jd);
213 #if defined(ENABLE_INTRP)
214 bool intrp_codegen(jitdata *jd);
217 #endif /* _CODEGEN_COMMON_H */
221 * These are local overrides for various environment variables in Emacs.
222 * Please do not remove this and leave it at the end of the file, where
223 * Emacs will automagically detect them.
224 * ---------------------------------------------------------------------
227 * indent-tabs-mode: t
231 * vim:noexpandtab:sw=4:ts=4: