Fixes Debian bug #350729
[cacao.git] / src / vm / jit / asmpart.h
1 /* src/vm/jit/asmpart.h - prototypes for machine specfic functions
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: Reinhard Grafl
28             Andreas Krall
29
30    Changes: Christian Thalinger
31
32    $Id: asmpart.h 4392 2006-01-31 15:35:22Z twisti $
33
34 */
35
36
37 #ifndef _ASMPART_H
38 #define _ASMPART_H
39
40 #include "config.h"
41 #include "vm/types.h"
42
43
44 #if defined(USE_THREADS)
45 # if defined(NATIVE_THREADS)
46 #  include "threads/native/threads.h"
47 # else
48 #  include "threads/green/threads.h"
49 # endif
50 #endif
51
52 #include "vm/global.h"
53 #include "vm/linker.h"
54 #include "vm/resolve.h"
55 #include "vm/jit/stacktrace.h"
56
57
58 /* some macros ****************************************************************/
59
60 #if defined(ENABLE_JIT)
61 # if defined(ENABLE_INTRP)
62
63 #  define ASM_CALLJAVAFUNCTION(m,a0,a1,a2,a3) \
64     do { \
65         if (opt_intrp) \
66             (void) intrp_asm_calljavafunction((m), (a0), (a1), (a2), (a3)); \
67         else \
68             (void) asm_calljavafunction((m), (a0), (a1), (a2), (a3)); \
69     } while (0)
70
71 #  define ASM_CALLJAVAFUNCTION_ADR(o,m,a0,a1,a2,a3) \
72     do { \
73         if (opt_intrp) \
74             (o) = intrp_asm_calljavafunction((m), (a0), (a1), (a2), (a3)); \
75         else \
76             (o) = asm_calljavafunction((m), (a0), (a1), (a2), (a3)); \
77     } while (0)
78
79 #  define ASM_CALLJAVAFUNCTION_INT(i,m,a0,a1,a2,a3) \
80     do { \
81         if (opt_intrp) \
82             (i) = intrp_asm_calljavafunction_int((m), (a0), (a1), (a2), (a3)); \
83         else \
84             (i) = asm_calljavafunction_int((m), (a0), (a1), (a2), (a3)); \
85     } while (0)
86
87
88 #  define ASM_CALLJAVAFUNCTION2(m,count,x,callblock) \
89     do { \
90         if (opt_intrp) \
91             (void) intrp_asm_calljavafunction2((m), (count), (x), (callblock)); \
92         else \
93             (void) asm_calljavafunction2((m), (count), (x), (callblock)); \
94     } while (0)
95
96 #  define ASM_CALLJAVAFUNCTION2_ADR(o,m,count,x,callblock) \
97     do { \
98         if (opt_intrp) \
99             (o) = intrp_asm_calljavafunction2((m), (count), (x), (callblock)); \
100         else \
101             (o) = asm_calljavafunction2((m), (count), (x), (callblock)); \
102     } while (0)
103
104 #  define ASM_CALLJAVAFUNCTION2_INT(i,m,count,x,callblock) \
105     do { \
106         if (opt_intrp) \
107             (i) = intrp_asm_calljavafunction2int((m), (count), (x), (callblock)); \
108         else \
109             (i) = asm_calljavafunction2int((m), (count), (x), (callblock)); \
110     } while (0)
111
112 #  define ASM_CALLJAVAFUNCTION2_LONG(l,m,count,x,callblock) \
113     do { \
114         if (opt_intrp) \
115             (l) = intrp_asm_calljavafunction2long((m), (count), (x), (callblock)); \
116         else \
117             (l) = asm_calljavafunction2long((m), (count), (x), (callblock)); \
118     } while (0)
119
120 #  define ASM_CALLJAVAFUNCTION2_FLOAT(f,m,count,x,callblock) \
121     do { \
122         if (opt_intrp) \
123             (f) = intrp_asm_calljavafunction2float((m), (count), (x), (callblock)); \
124         else \
125             (f) = asm_calljavafunction2float((m), (count), (x), (callblock)); \
126     } while (0)
127
128 #  define ASM_CALLJAVAFUNCTION2_DOUBLE(d,m,count,x,callblock) \
129     do { \
130         if (opt_intrp) \
131             (d) = intrp_asm_calljavafunction2double((m), (count), (x), (callblock)); \
132         else \
133             (d) = asm_calljavafunction2double((m), (count), (x), (callblock)); \
134     } while (0)
135
136
137 #  define ASM_GETCLASSVALUES_ATOMIC(super,sub,out) \
138     do { \
139         if (opt_intrp) \
140             intrp_asm_getclassvalues_atomic((super), (sub), (out)); \
141         else \
142             asm_getclassvalues_atomic((super), (sub), (out)); \
143     } while (0)
144
145 # else /* defined(ENABLE_INTRP) */
146
147 #  define ASM_CALLJAVAFUNCTION(m,a0,a1,a2,a3) \
148     (void) asm_calljavafunction((m), (a0), (a1), (a2), (a3))
149
150 #  define ASM_CALLJAVAFUNCTION_ADR(o,m,a0,a1,a2,a3) \
151     (o) = asm_calljavafunction((m), (a0), (a1), (a2), (a3))
152
153 #  define ASM_CALLJAVAFUNCTION_INT(i,m,a0,a1,a2,a3) \
154     (i) = asm_calljavafunction_int((m), (a0), (a1), (a2), (a3))
155
156
157 #  define ASM_CALLJAVAFUNCTION2(m,count,x,callblock) \
158     (void) asm_calljavafunction2((m), (count), (x), (callblock))
159
160 #  define ASM_CALLJAVAFUNCTION2_ADR(o,m,count,x,callblock) \
161     (o) = asm_calljavafunction2((m), (count), (x), (callblock))
162
163 #  define ASM_CALLJAVAFUNCTION2_INT(i,m,count,x,callblock) \
164     (i) = asm_calljavafunction2int((m), (count), (x), (callblock))
165
166 #  define ASM_CALLJAVAFUNCTION2_LONG(l,m,count,x,callblock) \
167     (l) = asm_calljavafunction2long((m), (count), (x), (callblock))
168
169 #  define ASM_CALLJAVAFUNCTION2_FLOAT(f,m,count,x,callblock) \
170     (f) = asm_calljavafunction2float((m), (count), (x), (callblock))
171
172 #  define ASM_CALLJAVAFUNCTION2_DOUBLE(d,m,count,x,callblock) \
173     (d) = asm_calljavafunction2double((m), (count), (x), (callblock))
174
175
176 #  define ASM_GETCLASSVALUES_ATOMIC(super,sub,out) \
177     asm_getclassvalues_atomic((super), (sub), (out))
178
179 # endif /* defined(ENABLE_INTRP) */
180
181 #else /* defined(ENABLE_JIT) */
182
183 # define ASM_CALLJAVAFUNCTION(m,a0,a1,a2,a3) \
184     (void) intrp_asm_calljavafunction((m), (a0), (a1), (a2), (a3))
185
186 # define ASM_CALLJAVAFUNCTION_ADR(o,m,a0,a1,a2,a3) \
187     (o) = intrp_asm_calljavafunction((m), (a0), (a1), (a2), (a3))
188
189 # define ASM_CALLJAVAFUNCTION_INT(i,m,a0,a1,a2,a3) \
190     (i) = intrp_asm_calljavafunction_int((m), (a0), (a1), (a2), (a3))
191
192
193 # define ASM_CALLJAVAFUNCTION2(m,count,x,callblock) \
194     (void) intrp_asm_calljavafunction2((m), (count), (x), (callblock))
195
196 # define ASM_CALLJAVAFUNCTION2_ADR(o,m,count,x,callblock) \
197     (o) = intrp_asm_calljavafunction2((m), (count), (x), (callblock))
198
199 # define ASM_CALLJAVAFUNCTION2_INT(i,m,count,x,callblock) \
200     (i) = intrp_asm_calljavafunction2int((m), (count), (x), (callblock))
201
202 # define ASM_CALLJAVAFUNCTION2_LONG(l,m,count,x,callblock) \
203     (l) = intrp_asm_calljavafunction2long((m), (count), (x), (callblock))
204
205 # define ASM_CALLJAVAFUNCTION2_FLOAT(f,m,count,x,callblock) \
206     (f) = intrp_asm_calljavafunction2float((m), (count), (x), (callblock))
207
208 # define ASM_CALLJAVAFUNCTION2_DOUBLE(d,m,count,x,callblock) \
209     (d) = intrp_asm_calljavafunction2double((m), (count), (x), (callblock))
210
211
212 #  define ASM_GETCLASSVALUES_ATOMIC(super,sub,out) \
213     intrp_asm_getclassvalues_atomic((super), (sub), (out))
214
215 #endif /* defined(ENABLE_JIT) */
216
217
218 typedef struct castinfo castinfo;
219
220 struct castinfo {
221         s4 super_baseval;
222         s4 super_diffval;
223         s4 sub_baseval;
224 };
225
226
227 /* function prototypes ********************************************************/
228
229 /* machine dependent initialization */
230 s4 asm_md_init(void);
231
232 void asm_sync_instruction_cache(void);
233
234
235 /* 
236    invokes the compiler for untranslated JavaVM methods.
237    Register R0 contains a pointer to the method info structure
238    (prepared by createcompilerstub).
239 */
240 void asm_call_jit_compiler(void);
241
242
243 /* 
244    This function calls a Java-method (which possibly needs compilation)
245    with up to 4 parameters. This function calls a Java-method (which
246    possibly needs compilation) with up to 4 parameters.
247 */
248
249 #if defined(ENABLE_JIT)
250 java_objectheader *asm_calljavafunction(methodinfo *m,
251                                                                                 void *arg1, void *arg2,
252                                                                                 void *arg3, void *arg4);
253
254 s4 asm_calljavafunction_int(methodinfo *m,
255                                                         void *arg1, void *arg2,
256                                                         void *arg3, void *arg4);
257 #endif
258
259 #if defined(ENABLE_INTRP)
260 java_objectheader *intrp_asm_calljavafunction(methodinfo *m,
261                                                                                           void *arg1, void *arg2,
262                                                                                           void *arg3, void *arg4);
263
264 s4 intrp_asm_calljavafunction_int(methodinfo *m,
265                                                                   void *arg1, void *arg2,
266                                                                   void *arg3, void *arg4);
267 #endif
268
269
270 /* 
271    This function calls a Java-method (which possibly needs compilation)
272    with up to 4 parameters. This function calls a Java-method (which
273    possibly needs compilation) with up to 4 parameters. 
274    also supports a return value
275 */
276
277 #if defined(ENABLE_JIT)
278 java_objectheader *asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
279                                                                                  jni_callblock *callblock);
280
281 s4 asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
282                                                         jni_callblock *callblock);
283
284 s8 asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
285                                                          jni_callblock *callblock);
286
287 float asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
288                                                                  jni_callblock *callblock);
289
290 double asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
291                                                                    jni_callblock *callblock);
292 #endif
293
294 #if defined(ENABLE_INTRP)
295 java_objectheader *intrp_asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
296                                                                                            jni_callblock *callblock);
297
298 s4 intrp_asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
299                                                                   jni_callblock *callblock);
300
301 s8 intrp_asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
302                                                                    jni_callblock *callblock);
303
304 float intrp_asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
305                                                                            jni_callblock *callblock);
306
307 double intrp_asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
308                                                                                  jni_callblock *callblock);
309 #endif
310
311
312 /* We need these two labels in codegen.inc to add the asm_calljavafunction*'s
313    into the methodtable */
314 #if defined(__I386__) || defined(__X86_64__)
315 void calljava_xhandler(void);
316 void calljava_xhandler2(void);
317 #endif
318
319 /* exception handling functions */
320
321 #if defined(ENABLE_JIT)
322 void asm_handle_exception(void);
323 void asm_handle_nat_exception(void);
324 #endif
325
326 /* wrapper for code patching functions */
327 void asm_wrapper_patcher(void);
328
329 void *asm_switchstackandcall(void *stack, void *func, void **stacktopsave, void * p);
330
331 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
332 extern threadcritnode asm_criticalsections;
333 #endif
334
335
336 #if defined(ENABLE_JIT)
337 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out);
338 #endif
339
340 #if defined(ENABLE_INTRP)
341 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out);
342 #endif
343
344
345 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
346 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
347 u1*  asm_initialize_thread_stack(void *func, u1 *stack);
348 #endif
349
350 /* may be required on some architectures (at least for PowerPC and ARM) */
351 void asm_cacheflush(void *p, s4 size);
352
353 #endif /* _ASMPART_H */
354
355
356 /*
357  * These are local overrides for various environment variables in Emacs.
358  * Please do not remove this and leave it at the end of the file, where
359  * Emacs will automagically detect them.
360  * ---------------------------------------------------------------------
361  * Local variables:
362  * mode: c
363  * indent-tabs-mode: t
364  * c-basic-offset: 4
365  * tab-width: 4
366  * End:
367  */