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
31 $Id: codegen-common.h 4357 2006-01-22 23:33:38Z twisti $
36 #ifndef _CODEGEN_COMMON_H
37 #define _CODEGEN_COMMON_H
39 /* forward typedefs ***********************************************************/
41 typedef struct codegendata codegendata;
42 typedef struct branchref branchref;
43 typedef struct threadcritnodetemp threadcritnodetemp;
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/inline/inline.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 relys 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 threadcritnodetemp {
79 threadcritnodetemp *next;
87 u1 *mcodebase; /* base pointer of code area */
88 s4 *mcodeend; /* pointer to end of code area */
89 s4 mcodesize; /* complete size of code area (bytes) */
90 u1 *mcodeptr; /* code generation pointer */
92 #if defined(__I386__) || defined(__MIPS__) || defined(__X86_64__) || defined(ENABLE_INTRP)
93 u1 *lastmcodeptr; /* last patcher position of basic block */
96 #if defined(ENABLE_INTRP)
97 u1 *ncodebase; /* base pointer of native code area */
98 s4 ncodesize; /* complete size of native code area */
99 u1 *ncodeptr; /* native code generation pointer */
101 u4 lastinstwithoutdispatch; /* ~0 if there was a dispatch */
103 s4 lastpatcheroffset; /* -1 if current super has no patcher */
104 s4 dynsuperm; /* offsets of start of current dynamic ...*/
105 s4 dynsupern; /* ... superinstruction starts */
106 struct superstart *superstarts; /* list of supers without patchers */
109 u1 *dsegtop; /* pointer to top (end) of data area */
110 s4 dsegsize; /* complete size of data area (bytes) */
111 s4 dseglen; /* used size of data area (bytes) */
112 /* data area grows from top to bottom */
114 jumpref *jumpreferences; /* list of jumptable target addresses */
116 #if defined(__I386__) || defined(__X86_64__) || defined(__XDSPCORE__) || defined(ENABLE_INTRP)
117 dataref *datareferences; /* list of data segment references */
120 branchref *xboundrefs; /* list of bound check branches */
121 branchref *xnullrefs; /* list of null check branches */
122 branchref *xcastrefs; /* list of cast check branches */
123 branchref *xstorerefs; /* list of array store check branches */
124 branchref *xdivrefs; /* list of divide by zero branches */
125 branchref *xexceptionrefs; /* list of exception branches */
128 linenumberref *linenumberreferences; /* list of line numbers and the */
129 /* program counters of their first */
131 s4 linenumbertablesizepos;
132 s4 linenumbertablestartpos;
136 s4 exceptiontablelength; /* exceptiontable length */
137 exceptiontable *exceptiontable; /* the exceptiontable */
139 threadcritnodetemp *threadcrit; /* List of critical code regions */
140 threadcritnodetemp threadcritcurrent;
141 s4 threadcritcount; /* Number of critical regions */
148 /***************** forward references in branch instructions ******************/
151 s4 branchpos; /* patching position in code segment */
152 s4 reg; /* used for ArrayIndexOutOfBounds index reg */
153 branchref *next; /* next element in branchref list */
157 #if defined(__I386__) || defined(__X86_64__) || defined(ENABLE_INTRP) || defined(DISABLE_GC)
158 typedef struct _methodtree_element methodtree_element;
160 struct _methodtree_element {
167 /* function prototypes ********************************************************/
169 void codegen_init(void);
170 void codegen_setup(methodinfo *m, codegendata *cd, t_inlining_globals *e);
172 void codegen_free(methodinfo *m, codegendata *cd);
173 void codegen_close(void);
175 s4 *codegen_increase(codegendata *cd, u1 *mcodeptr);
177 #if defined(ENABLE_INTRP)
178 u1 *codegen_ncode_increase(codegendata *cd, u1 *ncodeptr);
181 void codegen_addreference(codegendata *cd, basicblock *target, void *branchptr);
183 void codegen_addxboundrefs(codegendata *cd, void *branchptr, s4 reg);
184 void codegen_addxcastrefs(codegendata *cd, void *branchptr);
185 void codegen_addxdivrefs(codegendata *cd, void *branchptr);
186 void codegen_addxstorerefs(codegendata *cd, void *branchptr);
187 void codegen_addxnullrefs(codegendata *cd, void *branchptr);
188 void codegen_addxexceptionrefs(codegendata *cd, void *branchptr);
190 void codegen_addpatchref(codegendata *cd, voidptr branchptr,
191 functionptr patcher, voidptr ref, s4 disp);
193 void codegen_insertmethod(u1 *startpc, u1 *endpc);
194 u1 *codegen_findmethod(u1 *pc);
196 void codegen_finish(methodinfo *m, codegendata *cd, s4 mcodelen);
198 u1 *codegen_createnativestub(functionptr f, methodinfo *m);
199 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
201 void codegen_start_native_call(u1 *datasp, u1 *pv, u1 *sp, u1 *ra);
202 void codegen_finish_native_call(u1 *datasp);
204 u1 *createcompilerstub(methodinfo *m);
205 u1 *createnativestub(functionptr f, methodinfo *m, codegendata *cd,
206 registerdata *rd, methoddesc *md);
208 #if defined(ENABLE_INTRP)
209 u1 *intrp_createcompilerstub(methodinfo *m);
210 u1 *intrp_createnativestub(functionptr f, methodinfo *m, codegendata *cd,
211 registerdata *rd, methoddesc *md);
214 void removecompilerstub(u1 *stub);
215 void removenativestub(u1 *stub);
217 s4 reg_of_var(registerdata *rd, stackptr v, s4 tempregnum);
219 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
220 void codegen_threadcritrestart(codegendata *cd, int offset);
221 void codegen_threadcritstart(codegendata *cd, int offset);
222 void codegen_threadcritstop(codegendata *cd, int offset);
225 /* machine dependent functions */
226 u1 *md_codegen_findmethod(u1 *ra);
227 bool codegen(methodinfo *m, codegendata *cd, registerdata *rd);
229 #if defined(ENABLE_INTRP)
230 bool intrp_codegen(methodinfo *m, codegendata *cd, registerdata *rd);
233 #endif /* _CODEGEN_COMMON_H */
237 * These are local overrides for various environment variables in Emacs.
238 * Please do not remove this and leave it at the end of the file, where
239 * Emacs will automagically detect them.
240 * ---------------------------------------------------------------------
243 * indent-tabs-mode: t