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 7678 2007-04-09 17:23:55Z 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
51 .globl asm_vm_call_method_end
53 .globl asm_call_jit_compiler
55 .globl asm_handle_exception
56 .globl asm_handle_nat_exception
58 .globl asm_abstractmethoderror
60 .globl asm_patcher_wrapper
64 .globl asm_getclassvalues_atomic
65 .globl asm_criticalsections
68 #if !defined(ENABLE_THREADS)
70 .word _no_threads_exceptionptr
74 .word asm_call_jit_compiler
77 #if defined(ENABLE_THREADS)
85 /* asm_vm_call_method **********************************************************
87 This function calls a Java-method (which possibly needs compilation)
88 with up to 4 address parameters.
90 This functions calls the JIT-compiler which eventually translates the
91 method into machine code.
93 *******************************************************************************/
97 .word 0 /* catch type all */
98 .word 0 /* handler pc */
100 .word 0 /* start pc */
101 .word 1 /* extable size */
102 .word 0 /* line number table start */
103 .word 0 /* line number table size */
104 .word 0 /* FltSave */
105 .word 0 /* IntSave */
108 .word 0 /* FrameSize */
109 .word 0 /* CodeinfoPointer */
112 asm_vm_call_method_int:
113 asm_vm_call_method_long:
114 /* asm_vm_call_method_float:
115 asm_vm_call_method_double: */
116 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
117 stmfd sp!, {v1} /* V1 is used to recompute SP ... */
118 mov v1, #0 /* ... when using stack arguments */
119 ldr ip, asm_jitcompilerptr
120 str ip, [sp, #-4]! /* store fake address */
121 mov mptr, sp /* set method pointer */
123 mov itmp1, a0 /* pass methodinfo* via ITMP1 */
125 cmp a1, #0 /* do we have arguments? */
126 ble asm_calljava_copyfinish /* no -> do not care :-) */
128 /* REMEMBER: stack space for arguments is reserved here! */
129 /* TODO: we possibly reserve to much here */
130 mov v1, a1, lsl #3 /* how much stack do we alloc? */
131 sub sp, sp, v1 /* allocate stack for arguments! */
133 mov itmp3, #0 /* stack position */
134 asm_calljava_copyloop: /* reorder stack arguments! */
135 #if defined(__ARMEL__)
136 ldr ip, [a2,#offvmargdata] /* get LOW word of argument */
139 ldr ip, [a2,#offvmargtype] /* is it a 2_WORD_TYPE? */
141 ldrne ip, [a2,#offvmargdata + 4] /* yes -> get HIGH word of argument */
142 strne ip, [sp, itmp3]
143 addne itmp3, itmp3, #4
144 #else /* defined(__ARMEB__) */
145 ldr ip, [a2,#offvmargtype + 4] /* get our item type (it is u8) */
146 teq ip, #2 /* is it a TYPE_FLOAT? */
147 ldreq ip, [a2,#offvmargdata] /* yes -> get LOW word of float */
148 streq ip, [sp, itmp3]
149 addeq itmp3, itmp3, #4
150 beq asm_calljava_copydone
151 tst ip, #1 /* is it a 2_WORD_TYPE? */
152 ldrne ip, [a2,#offvmargdata] /* yes -> get HIGH word of argument */
153 strne ip, [sp, itmp3]
154 addne itmp3, itmp3, #4
155 ldr ip, [a2,#offvmargdata + 4] /* get LOW word of argument */
158 asm_calljava_copydone:
160 add a2, a2, #sizevmarg /* next argument block */
162 bgt asm_calljava_copyloop
164 /* REMEMBER: first four args are passed in regs, take them out again */
165 ldmfd sp, {a0, a1, a2, a3} /* load first four args to register */
166 cmp v1, #16 /* do we have four arguments? */
172 asm_calljava_copyfinish:
173 /* REMEMBER: do the method call just like in java! */
174 ldr ip, [mptr] /* fake virtual function call */
178 sub ip, pc, #(fake2 - asm_vm_call_method)+8
180 add sp, sp, v1 /* free stack arguments! */
181 add sp, sp, #4 /* free fake address */
183 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
185 asm_vm_call_method_exception_handler:
186 mov a0, xptr /* exception pointer is arg1 */
187 bl builtin_throw_exception /* throw the exception */
188 mov res1, #0 /* return NULL */
189 mov res2, #0 /* return NULL */
190 add sp, sp, v1 /* free stack arguments! */
191 add sp, sp, #4 /* free fake address */
193 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
195 asm_vm_call_method_float:
198 asm_vm_call_method_double:
200 asm_vm_call_method_end:
204 /****************** function asm_call_jit_compiler *****************************
206 * Invokes the compiler for untranslated JavaVM methods. *
207 * What this method does: *
208 * - save args and LR *
209 * - fire up jit_compile (pass methodinfo pointer) *
210 * - try to find out where to write back the new method pointer *
211 * - restore args and LR *
212 * - check for exceptions *
213 * - eventually write back new method pointer *
214 * - call jit code (wich will then return to caller) *
216 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
217 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
219 *******************************************************************************/
221 #define MYSTACKSIZE (6*4)
223 asm_call_jit_compiler:
224 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
225 sub sp, sp, #4 /* keep stack 8-byte aligned */
227 mov a0, itmp1 /* pass methodinfo pointer */
228 mov a1, mptr /* pass method pointer */
229 add a2, sp, #MYSTACKSIZE /* pass Java sp */
230 mov a3, lr /* pass Java RA (correct for leafs) */
232 mov itmp1, res1 /* save pointer to new jit-code */
234 tst itmp1,itmp1 /* check for exeption */
235 beq L_asm_call_jit_compiler_exception
237 add sp, sp, #4 /* keep stack 8-byte aligned */
238 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
241 mov pc, ip /* call jit-code */
243 L_asm_call_jit_compiler_exception:
244 bl exceptions_get_and_clear_exception
245 mov xptr, res1 /* get exception */
247 add sp, sp, #4 /* keep stack 8-byte aligned */
248 RESTORE_ARGUMENT_REGISTERS /* load LR */
250 sub xpc, lr, #4 /* xpc = instruction that called us */
251 b asm_handle_nat_exception
254 /********************* function asm_handle_exception ***************************
256 * This function handles an exception. It does not use the usual calling *
257 * conventions. The exception pointer is passed in REG_ITMP1 and the *
258 * pc from the exception raising position is passed in REG_ITMP2. It searches *
259 * the local exception table for a handler. If no one is found, it unwinds *
260 * stacks and continues searching the callers. *
262 * void asm_handle_exception (exceptionptr, exceptionpc); *
264 *******************************************************************************/
266 asm_handle_nat_exception:
267 /*TODO:maybe make a macro out of it!!!*/
268 SAVE_ARGUMENT_REGISTERS
270 bl md_codegen_get_pv_from_pc
272 RESTORE_ARGUMENT_REGISTERS
275 asm_handle_exception:
276 stmfd sp!, {r0 - r3} /* save possible used registers */
277 mov itmp3, #1 /* set maybe-leaf flag */
278 mov a3, #(4*4) /* prepare a3 for handle_exception */
280 asm_handle_exception_loop:
281 stmfd sp!, {ip,lr} /* call exception helper here! */
282 mov a0, xptr /* pass exception pointer */
283 mov a1, xpc /* pass exception pointer */
284 mov a2, ip /* pass data segment pointer */
285 add a3, sp, a3 /* calculate Java sp into a3... */
287 bl exceptions_handle_exception
291 beq asm_handle_exception_not_catched
293 mov xpc, a0 /* move handlerpc into xpc */
294 tst itmp3,itmp3 /* if this is a lead method ... */
295 ldmnefd sp!, {r0 - r3} /* restore argument registers */
297 mov pc, xpc /* jump to handler */
299 asm_handle_exception_not_catched:
300 tst itmp3,itmp3 /* if this is a lead method ... */
301 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
302 movne itmp3, #0 /* remove maybe-leaf flag */
304 ldr a2, [ip, #FrameSize] /* t2 = frame size */
305 add a0, sp, a2 /* t0 = pointer to save area */
306 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
307 tst a1, a1 /* if is leaf ... */
308 ldreq lr, [a0, #-4]! /* ... restore RA */
309 mov xpc, lr /* the new xpc is RA */
311 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
312 rsb a1, a1, #5 /* t1 = count of unsaved registers */
314 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
315 ldr v1, [a0, #-20] /* ... but restore the other ones */
321 add sp, sp, a2 /* unwind stack (using t2) */
322 mov a3, #0 /* prepare a3 for handle_exception */
324 /*TODO:maybe make a macro out of it!!!*/
325 SAVE_ARGUMENT_REGISTERS
327 bl md_codegen_get_pv_from_pc
329 RESTORE_ARGUMENT_REGISTERS
331 b asm_handle_exception_loop
334 /* asm_patcher_wrapper *********************************************************
336 * TODO: document me *
338 * Stack layout when calling patcher function: *
339 * 24 saved REG_ITMP3, should be restored ( -4) *
340 * 20 data segment displacement from load instructions ( -8) *
341 * 16 return address into JIT code (patch position) (-12) *
342 * 12 pointer to virtual java_objectheader *
343 * 8 machine code (which is patched back later) *
344 * [ 8 result of patcher function (indicates exception) ] *
345 * 4 unresolved class/method/field reference *
346 * [ 0 patcher function pointer to call ] *
347 * 0 saved IP of caller (caller needs it!) *
349 *******************************************************************************/
351 #define PATCHSTACKSIZE 8*4
354 mov itmp3, sp /* preserve original SP in ITMP3 */
356 SAVE_ARGUMENT_REGISTERS_IP /* save our argument registers & LR */
357 SAVE_FLOAT_REGISTERS /* save our float registers here */
359 mov a0, itmp3 /* pass SP of patcher stub */
360 mov a1, ip /* pass PV */
361 mov a2, lr /* pass RA (correct for leafs) */
363 mov itmp3, res1 /* save return value */
365 RESTORE_FLOAT_REGISTERS /* restore our float registers here */
366 RESTORE_ARGUMENT_REGISTERS_IP /* load our argument registers & LR */
368 tst itmp3, itmp3 /* check for an exception */
369 bne L_asm_patcher_wrapper_exception
371 add sp, sp, #PATCHSTACKSIZE /* remove patcher stack frame */
373 ldr itmp3, [sp, #-8] /* restore ITMP3 for calling method */
374 ldr pc, [sp, #-16] /* jump to new patched code */
376 L_asm_patcher_wrapper_exception:
377 mov xptr, itmp3 /* get exception */
378 ldr xpc, [sp, #16] /* RA is xpc */
380 add sp, sp, #PATCHSTACKSIZE /* remove patcher stack frame */
382 b asm_handle_exception
385 /* asm_abstractmethoderror *****************************************************
387 Creates and throws an AbstractMethodError.
389 *******************************************************************************/
391 asm_abstractmethoderror:
392 stmfd sp!, {lr} /* save return address */
393 add a0, sp, #(1*4) /* pass java sp */
394 mov a1, lr /* pass exception address */
395 bl exceptions_asm_new_abstractmethoderror
396 ldmfd sp!, {lr} /* restore return address */
398 mov xptr, res1 /* get exception pointer */
399 sub xpc, lr, #4 /* exception address is ra - 4 */
400 b asm_handle_nat_exception
403 /********************* function asm_cacheflush *********************************
405 * TODO: document me *
407 * void asm_cacheflush(void *p, s4 size); *
409 *******************************************************************************/
412 .equ sys_cacheflush, 0x9f0002
418 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
419 /* TODO: repeair this! */
420 /* cacheflush is messed up beyond all repair! */
430 /********************* function asm_getclassvalues_atomic *********************/
432 asm_getclassvalues_atomic:
433 stmfd sp!, {r4, r5, r6}
436 ldr r4,[a0,#offbaseval]
437 ldr r5,[a0,#offdiffval]
438 ldr r6,[a1,#offbaseval]
440 str r4,[a2,#offcast_super_baseval]
441 str r5,[a2,#offcast_super_diffval]
442 str r6,[a2,#offcast_sub_baseval]
443 ldmfd sp!, {r4, r5, r6}
447 /* disable exec-stacks ********************************************************/
449 #if defined(__linux__) && defined(__ELF__)
450 .section .note.GNU-stack,"",%progbits
455 * These are local overrides for various environment variables in Emacs.
456 * Please do not remove this and leave it at the end of the file, where
457 * Emacs will automagically detect them.
458 * ---------------------------------------------------------------------
461 * indent-tabs-mode: t
465 * vim:noexpandtab:sw=4:ts=4: