* asm_cacheflush: Declaration removed.
[cacao.git] / src / vm / jit / codegen.inc.h
1 /* src/vm/jit/codegen.inc.h - code generation header
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: codegen.inc.h 3177 2005-09-14 18:03:11Z twisti $
32
33 */
34
35
36 #ifndef _CODEGEN_INC_H
37 #define _CODEGEN_INC_H
38
39 /* We typedef these structures before #includes to resolve circular           */
40 /* dependencies.                                                              */
41
42 typedef struct codegendata codegendata;
43 typedef struct branchref branchref;
44 typedef struct jumpref jumpref;
45 typedef struct dataref dataref;
46 typedef struct patchref patchref;
47 typedef struct linenumberref linenumberref;
48 typedef struct threadcritnodetemp threadcritnodetemp;
49
50
51 #include "types.h"
52 #include "vm/global.h"
53 #include "vm/references.h"
54 #include "vm/method.h"
55 #include "vm/jit/jit.h"
56 #include "vm/jit/reg.h"
57 #include "vm/jit/inline/inline.h"
58
59
60 #define MCODEINITSIZE (1<<15)       /* 32 Kbyte code area initialization size */
61 #define DSEGINITSIZE  (1<<12)       /*  4 Kbyte data area initialization size */
62
63 /* Register Pack/Unpack Macros ************************************************/
64
65 #define GET_LOW_REG(a)  (((a) & 0xffff0000) >> 16)
66 #define GET_HIGH_REG(a) ((a) &  0x0000ffff)
67
68 #define PACK_REGS(low,high) \
69         ( ((high) & 0x0000ffff) | (((low) & 0x0000ffff) << 16) )
70
71
72 #if SIZEOF_VOID_P == 8
73 #define dseg_addaddress(cd,value)    dseg_adds8((cd), (s8) (value))
74 #else
75 #define dseg_addaddress(cd,value)    dseg_adds4((cd), (s4) (value))
76 #endif
77
78
79 /************************* critical sections  *********************************/
80
81 struct threadcritnodetemp {
82         threadcritnodetemp *next;
83         s4                  mcodebegin;
84         s4                  mcodeend;
85         s4                  mcoderestart;
86 };
87
88
89 struct codegendata {
90         u1             *mcodebase;      /* base pointer of code area              */
91         s4             *mcodeend;       /* pointer to end of code area            */
92         s4              mcodesize;      /* complete size of code area (bytes)     */
93
94 #if defined(__I386__) || defined(__X86_64__)
95         u1             *mcodeptr;       /* code generation pointer                */
96 #endif
97
98         u1             *dsegtop;        /* pointer to top (end) of data area      */
99         s4              dsegsize;       /* complete size of data area (bytes)     */
100         s4              dseglen;        /* used size of data area (bytes)         */
101                                     /* data area grows from top to bottom     */
102
103         jumpref        *jumpreferences; /* list of jumptable target addresses     */
104         dataref        *datareferences; /* list of data segment references        */
105         branchref      *xboundrefs;     /* list of bound check branches           */
106         branchref      *xcheckarefs;    /* list of array size check branches      */
107         branchref      *xnullrefs;      /* list of null check branches            */
108         branchref      *xcastrefs;      /* list of cast check branches            */
109         branchref      *xstorerefs;     /* list of array store check branches     */
110         branchref      *xdivrefs;       /* list of divide by zero branches        */
111         branchref      *xexceptionrefs; /* list of exception branches             */
112         patchref       *patchrefs;
113
114         linenumberref  *linenumberreferences; /* list of line numbers and the     */
115                                         /* program counters of their first        */
116                                         /* instruction                            */
117         s4              linenumbertablesizepos;
118         s4              linenumbertablestartpos;
119         s4              linenumbertab;
120
121         methodinfo     *method;
122         s4              exceptiontablelength; /* exceptiontable length            */
123         exceptiontable *exceptiontable; /* the exceptiontable                     */
124
125         threadcritnodetemp *threadcrit; /* List of critical code regions          */
126         threadcritnodetemp threadcritcurrent;
127         s4                 threadcritcount; /* Number of critical regions         */
128
129         s4              maxstack;
130         s4              maxlocals;
131 };
132
133
134 /***************** forward references in branch instructions ******************/
135
136 struct branchref {
137         s4         branchpos;       /* patching position in code segment          */
138         s4         reg;             /* used for ArrayIndexOutOfBounds index reg   */
139         branchref *next;            /* next element in branchref list             */
140 };
141
142
143 /******************** forward references in tables  ***************************/
144
145 struct jumpref {
146         s4          tablepos;       /* patching position in data segment          */
147         basicblock *target;         /* target basic block                         */
148         jumpref    *next;           /* next element in jumpref list               */
149 };
150
151
152 struct dataref {
153         u1      *pos;               /* patching position in generated code        */
154         dataref *next;              /* next element in dataref list               */
155 };
156
157
158 struct patchref {
159         s4           branchpos;
160         functionptr  patcher;
161         voidptr      ref;
162         patchref    *next;
163         s4           disp;
164 };
165
166
167 struct linenumberref {
168         s4             tablepos;    /* patching position in data segment          */
169         s4             targetmpc;   /* machine code program counter of first      */
170                                     /* instruction for given line                 */
171         u2             linenumber;  /* line number, used for inserting into the   */
172                                     /* table and for validty checking             */
173         linenumberref *next;        /* next element in linenumberref list         */
174 };
175
176
177 #if defined(__I386__) || defined(__X86_64__) || defined(__INTRP__)
178 typedef struct _methodtree_element methodtree_element;
179
180 struct _methodtree_element {
181         functionptr startpc;
182         functionptr endpc;
183 };
184 #endif
185
186
187 /* function prototypes ********************************************************/
188
189 void codegen_init(void);
190 void codegen_setup(methodinfo *m, codegendata *cd, t_inlining_globals *e);
191 void codegen(methodinfo *m, codegendata *cd, registerdata *rd);
192 void codegen_free(methodinfo *m, codegendata *cd);
193 void codegen_close(void);
194 void codegen_insertmethod(functionptr startpc, functionptr endpc);
195
196 functionptr codegen_findmethod(functionptr pc);
197
198 #if defined(__I386__) || defined(__X86_64__)
199 void codegen_addreference(codegendata *cd, struct basicblock *target, void *branchptr);
200 #endif
201
202 void dseg_display(methodinfo *m, codegendata *cd);
203
204 functionptr codegen_createnativestub(functionptr f, methodinfo *m);
205 void codegen_disassemble_nativestub(methodinfo *m, u1 *start, u1 *end);
206
207 functionptr createcompilerstub(methodinfo *m);
208 functionptr createnativestub(functionptr f, methodinfo *m, codegendata *cd,
209                                                          registerdata *rd, methoddesc *md);
210
211 void removecompilerstub(functionptr stub);
212 void removenativestub(functionptr stub);
213
214 #endif /* _CODEGEN_INC_H */
215
216
217 /*
218  * These are local overrides for various environment variables in Emacs.
219  * Please do not remove this and leave it at the end of the file, where
220  * Emacs will automagically detect them.
221  * ---------------------------------------------------------------------
222  * Local variables:
223  * mode: c
224  * indent-tabs-mode: t
225  * c-basic-offset: 4
226  * tab-width: 4
227  * End:
228  */