1 /* src/vm/jit/arm/asmpart.S - Java-C interface functions for ARM
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: asmpart.S 7356 2007-02-14 11:00:28Z twisti $
32 #include "vm/jit/arm/offsets.h"
33 #include "vm/jit/arm/md-asm.h"
35 #include "vm/jit/methodheader.h"
43 /* export functions ***********************************************************/
45 .globl asm_vm_call_method
46 .globl asm_vm_call_method_int
47 .globl asm_vm_call_method_long
48 .globl asm_vm_call_method_float
49 .globl asm_vm_call_method_double
50 .globl asm_vm_call_method_exception_handler
52 .globl asm_call_jit_compiler
54 .globl asm_handle_exception
55 .globl asm_handle_nat_exception
57 .globl asm_abstractmethoderror
59 .globl asm_patcher_wrapper
63 .globl asm_getclassvalues_atomic
64 .globl asm_criticalsections
67 #if !defined(ENABLE_THREADS)
69 .word _no_threads_exceptionptr
73 .word asm_call_jit_compiler
76 #if defined(ENABLE_THREADS)
84 /* asm_vm_call_method **********************************************************
86 This function calls a Java-method (which possibly needs compilation)
87 with up to 4 address parameters.
89 This functions calls the JIT-compiler which eventually translates the
90 method into machine code.
92 *******************************************************************************/
96 .word 0 /* catch type all */
97 .word 0 /* handler pc */
99 .word 0 /* start pc */
100 .word 1 /* extable size */
101 .word 0 /* line number table start */
102 .word 0 /* line number table size */
103 .word 0 /* FltSave */
104 .word 0 /* IntSave */
107 .word 0 /* FrameSize */
108 .word 0 /* CodeinfoPointer */
111 asm_vm_call_method_int:
112 asm_vm_call_method_long:
113 /* asm_vm_call_method_float:
114 asm_vm_call_method_double: */
115 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
116 stmfd sp!, {v1} /* V1 is used to recompute SP ... */
117 mov v1, #0 /* ... when using stack arguments */
118 ldr ip, asm_jitcompilerptr
119 str ip, [sp, #-4]! /* store fake address */
120 mov mptr, sp /* set method pointer */
122 mov itmp1, a0 /* pass methodinfo* via ITMP1 */
124 cmp a1, #0 /* do we have arguments? */
125 ble asm_calljava_copyfinish /* no -> do not care :-) */
127 /* REMEMBER: stack space for arguments is reserved here! */
128 /* TODO: we possibly reserve to much here */
129 mov v1, a1, lsl #3 /* how much stack do we alloc? */
130 sub sp, sp, v1 /* allocate stack for arguments! */
132 mov itmp3, #0 /* stack position */
133 asm_calljava_copyloop: /* reorder stack arguments! */
134 #if defined(__ARMEL__)
135 ldr ip, [a2,#offvmargdata] /* get LOW word of argument */
138 ldr ip, [a2,#offvmargtype] /* is it a 2_WORD_TYPE? */
140 ldrne ip, [a2,#offvmargdata + 4] /* yes -> get HIGH word of argument */
141 strne ip, [sp, itmp3]
142 addne itmp3, itmp3, #4
143 #else /* defined(__ARMEB__) */
144 ldr ip, [a2,#offvmargtype + 4] /* get our item type (it is u8) */
145 teq ip, #2 /* is it a TYPE_FLOAT? */
146 ldreq ip, [a2,#offvmargdata] /* yes -> get LOW word of float */
147 streq ip, [sp, itmp3]
148 addeq itmp3, itmp3, #4
149 beq asm_calljava_copydone
150 tst ip, #1 /* is it a 2_WORD_TYPE? */
151 ldrne ip, [a2,#offvmargdata] /* yes -> get HIGH word of argument */
152 strne ip, [sp, itmp3]
153 addne itmp3, itmp3, #4
154 ldr ip, [a2,#offvmargdata + 4] /* get LOW word of argument */
157 asm_calljava_copydone:
159 add a2, a2, #sizevmarg /* next argument block */
161 bgt asm_calljava_copyloop
163 /* REMEMBER: first four args are passed in regs, take them out again */
164 ldmfd sp, {a0, a1, a2, a3} /* load first four args to register */
165 cmp v1, #16 /* do we have four arguments? */
171 asm_calljava_copyfinish:
172 /* REMEMBER: do the method call just like in java! */
173 ldr ip, [mptr] /* fake virtual function call */
177 sub ip, pc, #(fake2 - asm_vm_call_method)+8
179 add sp, sp, v1 /* free stack arguments! */
180 add sp, sp, #4 /* free fake address */
182 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
184 asm_vm_call_method_exception_handler:
185 mov a0, xptr /* exception pointer is arg1 */
186 bl builtin_throw_exception /* throw the exception */
187 mov res1, #0 /* return NULL */
188 mov res2, #0 /* return NULL */
189 add sp, sp, v1 /* free stack arguments! */
190 add sp, sp, #4 /* free fake address */
192 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
194 asm_vm_call_method_float:
197 asm_vm_call_method_double:
202 /****************** function asm_call_jit_compiler *****************************
204 * Invokes the compiler for untranslated JavaVM methods. *
205 * What this method does: *
206 * - save args and LR *
207 * - fire up jit_compile (pass methodinfo pointer) *
208 * - try to find out where to write back the new method pointer *
209 * - restore args and LR *
210 * - check for exceptions *
211 * - eventually write back new method pointer *
212 * - call jit code (wich will then return to caller) *
214 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
215 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
217 *******************************************************************************/
219 #define MYSTACKSIZE (6*4)
221 asm_call_jit_compiler:
222 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
223 sub sp, sp, #4 /* keep stack 8-byte aligned */
225 mov a0, itmp1 /* pass methodinfo pointer */
226 mov a1, mptr /* pass method pointer */
227 add a2, sp, #MYSTACKSIZE /* pass Java sp */
228 mov a3, lr /* pass Java RA (correct for leafs) */
230 mov itmp1, res1 /* save pointer to new jit-code */
232 tst itmp1,itmp1 /* check for exeption */
233 beq L_asm_call_jit_compiler_exception
235 add sp, sp, #4 /* keep stack 8-byte aligned */
236 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
239 mov pc, ip /* call jit-code */
241 L_asm_call_jit_compiler_exception:
242 bl exceptions_get_and_clear_exception
243 mov xptr, res1 /* get exception */
245 add sp, sp, #4 /* keep stack 8-byte aligned */
246 RESTORE_ARGUMENT_REGISTERS /* load LR */
248 sub xpc, lr, #4 /* xpc = instruction that called us */
249 b asm_handle_nat_exception
252 /********************* function asm_handle_exception ***************************
254 * This function handles an exception. It does not use the usual calling *
255 * conventions. The exception pointer is passed in REG_ITMP1 and the *
256 * pc from the exception raising position is passed in REG_ITMP2. It searches *
257 * the local exception table for a handler. If no one is found, it unwinds *
258 * stacks and continues searching the callers. *
260 * void asm_handle_exception (exceptionptr, exceptionpc); *
262 *******************************************************************************/
264 asm_handle_nat_exception:
265 /*TODO:maybe make a macro out of it!!!*/
266 SAVE_ARGUMENT_REGISTERS
268 bl md_codegen_get_pv_from_pc
270 RESTORE_ARGUMENT_REGISTERS
273 asm_handle_exception:
274 stmfd sp!, {r0 - r3} /* save possible used registers */
275 mov itmp3, #1 /* set maybe-leaf flag */
276 mov a3, #(4*4) /* prepare a3 for handle_exception */
278 asm_handle_exception_loop:
279 stmfd sp!, {ip,lr} /* call exception helper here! */
280 mov a0, xptr /* pass exception pointer */
281 mov a1, xpc /* pass exception pointer */
282 mov a2, ip /* pass data segment pointer */
283 add a3, sp, a3 /* calculate Java sp into a3... */
285 bl exceptions_handle_exception
289 beq asm_handle_exception_not_catched
291 mov xpc, a0 /* move handlerpc into xpc */
292 tst itmp3,itmp3 /* if this is a lead method ... */
293 ldmnefd sp!, {r0 - r3} /* restore argument registers */
295 mov pc, xpc /* jump to handler */
297 asm_handle_exception_not_catched:
298 tst itmp3,itmp3 /* if this is a lead method ... */
299 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
300 movne itmp3, #0 /* remove maybe-leaf flag */
302 ldr a2, [ip, #FrameSize] /* t2 = frame size */
303 add a0, sp, a2 /* t0 = pointer to save area */
304 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
305 tst a1, a1 /* if is leaf ... */
306 ldreq lr, [a0, #-4]! /* ... restore RA */
307 mov xpc, lr /* the new xpc is RA */
309 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
310 rsb a1, a1, #5 /* t1 = count of unsaved registers */
312 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
313 ldr v1, [a0, #-20] /* ... but restore the other ones */
319 add sp, sp, a2 /* unwind stack (using t2) */
320 mov a3, #0 /* prepare a3 for handle_exception */
322 /*TODO:maybe make a macro out of it!!!*/
323 SAVE_ARGUMENT_REGISTERS
325 bl md_codegen_get_pv_from_pc
327 RESTORE_ARGUMENT_REGISTERS
329 b asm_handle_exception_loop
332 /* asm_patcher_wrapper *********************************************************
334 * TODO: document me *
336 * Stack layout when calling patcher function: *
337 * 24 saved REG_ITMP3, should be restored ( -4) *
338 * 20 data segment displacement from load instructions ( -8) *
339 * 16 return address into JIT code (patch position) (-12) *
340 * 12 pointer to virtual java_objectheader *
341 * 8 machine code (which is patched back later) *
342 * [ 8 result of patcher function (indicates exception) ] *
343 * 4 unresolved class/method/field reference *
344 * [ 0 patcher function pointer to call ] *
345 * 0 saved IP of caller (caller needs it!) *
347 *******************************************************************************/
349 #define PATCHSTACKSIZE 8*4
352 mov itmp3, sp /* preserve original SP in ITMP3 */
354 SAVE_ARGUMENT_REGISTERS_IP /* save our argument registers & LR */
355 SAVE_FLOAT_REGISTERS /* save our float registers here */
357 mov a0, itmp3 /* pass SP of patcher stub */
358 mov a1, ip /* pass PV */
359 mov a2, lr /* pass RA (correct for leafs) */
361 mov itmp3, res1 /* save return value */
363 RESTORE_FLOAT_REGISTERS /* restore our float registers here */
364 RESTORE_ARGUMENT_REGISTERS_IP /* load our argument registers & LR */
366 tst itmp3, itmp3 /* check for an exception */
367 bne L_asm_patcher_wrapper_exception
369 add sp, sp, #PATCHSTACKSIZE /* remove patcher stack frame */
371 ldr itmp3, [sp, #-8] /* restore ITMP3 for calling method */
372 ldr pc, [sp, #-16] /* jump to new patched code */
374 L_asm_patcher_wrapper_exception:
375 mov xptr, itmp3 /* get exception */
376 ldr xpc, [sp, #16] /* RA is xpc */
378 add sp, sp, #PATCHSTACKSIZE /* remove patcher stack frame */
380 b asm_handle_exception
383 /* asm_abstractmethoderror *****************************************************
385 Creates and throws an AbstractMethodError.
387 *******************************************************************************/
389 asm_abstractmethoderror:
390 stmfd sp!, {lr} /* save return address */
391 add a0, sp, #(1*4) /* pass java sp */
392 mov a1, lr /* pass exception address */
393 bl exceptions_asm_new_abstractmethoderror
394 ldmfd sp!, {lr} /* restore return address */
396 mov xptr, res1 /* get exception pointer */
397 sub xpc, lr, #4 /* exception address is ra - 4 */
398 b asm_handle_nat_exception
401 /********************* function asm_cacheflush *********************************
403 * TODO: document me *
405 * void asm_cacheflush(void *p, s4 size); *
407 *******************************************************************************/
410 .equ sys_cacheflush, 0x9f0002
416 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
417 /* TODO: repeair this! */
418 /* cacheflush is messed up beyond all repair! */
428 /********************* function asm_getclassvalues_atomic *********************/
430 asm_getclassvalues_atomic:
431 stmfd sp!, {r4, r5, r6}
434 ldr r4,[a0,#offbaseval]
435 ldr r5,[a0,#offdiffval]
436 ldr r6,[a1,#offbaseval]
438 str r4,[a2,#offcast_super_baseval]
439 str r5,[a2,#offcast_super_diffval]
440 str r6,[a2,#offcast_sub_baseval]
441 ldmfd sp!, {r4, r5, r6}
445 /* Disable exec-stacks, required for Gentoo ***********************************/
447 #if defined(__GCC__) && defined(__ELF__)
448 .section .note.GNU-stack,"",@progbits
453 * These are local overrides for various environment variables in Emacs.
454 * Please do not remove this and leave it at the end of the file, where
455 * Emacs will automagically detect them.
456 * ---------------------------------------------------------------------
459 * indent-tabs-mode: t
463 * vim:noexpandtab:sw=4:ts=4: