* Updated header: Added 2006. Changed address of FSF. Changed email
[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 4357 2006-01-22 23:33:38Z 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 #if defined(__ALPHA__)
228 /* 
229    determines if the byte support instruction set (21164a and higher)
230    is available.
231 */
232 int has_no_x_instr_set(void);
233 void asm_sync_instruction_cache(void);
234 #endif
235
236
237 /* 
238    invokes the compiler for untranslated JavaVM methods.
239    Register R0 contains a pointer to the method info structure
240    (prepared by createcompilerstub).
241 */
242 void asm_call_jit_compiler(void);
243
244
245 /* 
246    This function calls a Java-method (which possibly needs compilation)
247    with up to 4 parameters. This function calls a Java-method (which
248    possibly needs compilation) with up to 4 parameters.
249 */
250
251 #if defined(ENABLE_JIT)
252 java_objectheader *asm_calljavafunction(methodinfo *m,
253                                                                                 void *arg1, void *arg2,
254                                                                                 void *arg3, void *arg4);
255
256 s4 asm_calljavafunction_int(methodinfo *m,
257                                                         void *arg1, void *arg2,
258                                                         void *arg3, void *arg4);
259 #endif
260
261 #if defined(ENABLE_INTRP)
262 java_objectheader *intrp_asm_calljavafunction(methodinfo *m,
263                                                                                           void *arg1, void *arg2,
264                                                                                           void *arg3, void *arg4);
265
266 s4 intrp_asm_calljavafunction_int(methodinfo *m,
267                                                                   void *arg1, void *arg2,
268                                                                   void *arg3, void *arg4);
269 #endif
270
271
272 /* 
273    This function calls a Java-method (which possibly needs compilation)
274    with up to 4 parameters. This function calls a Java-method (which
275    possibly needs compilation) with up to 4 parameters. 
276    also supports a return value
277 */
278
279 #if defined(ENABLE_JIT)
280 java_objectheader *asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
281                                                                                  jni_callblock *callblock);
282
283 s4 asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
284                                                         jni_callblock *callblock);
285
286 s8 asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
287                                                          jni_callblock *callblock);
288
289 float asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
290                                                                  jni_callblock *callblock);
291
292 double asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
293                                                                    jni_callblock *callblock);
294 #endif
295
296 #if defined(ENABLE_INTRP)
297 java_objectheader *intrp_asm_calljavafunction2(methodinfo *m, u4 count, u4 size,
298                                                                                            jni_callblock *callblock);
299
300 s4 intrp_asm_calljavafunction2int(methodinfo *m, u4 count, u4 size,
301                                                                   jni_callblock *callblock);
302
303 s8 intrp_asm_calljavafunction2long(methodinfo *m, u4 count, u4 size,
304                                                                    jni_callblock *callblock);
305
306 float intrp_asm_calljavafunction2float(methodinfo *m, u4 count, u4 size,
307                                                                            jni_callblock *callblock);
308
309 double intrp_asm_calljavafunction2double(methodinfo *m, u4 count, u4 size,
310                                                                                  jni_callblock *callblock);
311 #endif
312
313
314 /* We need these two labels in codegen.inc to add the asm_calljavafunction*'s
315    into the methodtable */
316 #if defined(__I386__) || defined(__X86_64__)
317 void calljava_xhandler(void);
318 void calljava_xhandler2(void);
319 #endif
320
321 /* exception handling functions */
322
323 #if defined(ENABLE_JIT)
324 void asm_handle_exception(void);
325 void asm_handle_nat_exception(void);
326 #endif
327
328 /* wrapper for code patching functions */
329 void asm_wrapper_patcher(void);
330
331 void *asm_switchstackandcall(void *stack, void *func, void **stacktopsave, void * p);
332
333 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
334 extern threadcritnode asm_criticalsections;
335 #endif
336
337
338 #if defined(ENABLE_JIT)
339 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out);
340 #endif
341
342 #if defined(ENABLE_INTRP)
343 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out);
344 #endif
345
346
347 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
348 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop);
349 u1*  asm_initialize_thread_stack(void *func, u1 *stack);
350 #endif
351
352 /* may be required on some architectures (at least for PowerPC and ARM) */
353 void asm_cacheflush(void *p, s4 size);
354
355 #endif /* _ASMPART_H */
356
357
358 /*
359  * These are local overrides for various environment variables in Emacs.
360  * Please do not remove this and leave it at the end of the file, where
361  * Emacs will automagically detect them.
362  * ---------------------------------------------------------------------
363  * Local variables:
364  * mode: c
365  * indent-tabs-mode: t
366  * c-basic-offset: 4
367  * tab-width: 4
368  * End:
369  */