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