1 /* src/vm/jit/arm/asmpart.S - Java-C interface functions for ARM
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include <sys/syscall.h>
30 #include "vm/jit/arm/md-asm.h"
32 #include "vm/jit/methodheader.h"
40 /* export functions ***********************************************************/
42 .globl asm_vm_call_method
43 .globl asm_vm_call_method_int
44 .globl asm_vm_call_method_long
45 .globl asm_vm_call_method_float
46 .globl asm_vm_call_method_double
47 .globl asm_vm_call_method_exception_handler
48 .globl asm_vm_call_method_end
50 .globl asm_call_jit_compiler
52 .globl asm_handle_exception
53 .globl asm_handle_nat_exception
55 .globl asm_abstractmethoderror
60 /* asm_vm_call_method **********************************************************
62 This function calls a Java-method (which possibly needs compilation)
63 with up to 4 address parameters.
65 This functions calls the JIT-compiler which eventually translates the
66 method into machine code.
68 *******************************************************************************/
75 .word 0 /* FrameSize */
76 .word 0 /* CodeinfoPointer */
79 asm_vm_call_method_int:
80 asm_vm_call_method_long:
81 /* asm_vm_call_method_float:
82 asm_vm_call_method_double: */
83 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
84 stmfd sp!, {v1} /* V1 is used to remember SP */
85 str a0, [sp, #-4]! /* store methods entrypoint */
87 mov v1, sp /* remember SP */
89 mov itmp1, a1 /* address of data structure */
90 mov itmp3, a2 /* stack argument count */
92 ldr a0, [itmp1], #8 /* load argument registers */
97 cmp itmp3, #0 /* do we have stack arguments? */
98 ble asm_calljava_copyfinish /* no -> do not care :-) */
101 sub sp, sp, itmp3, lsl #3 /* create stackframe for arguments */
102 asm_calljava_copyloop: /* reorder stack arguments! */
103 ldr ip, [itmp1], #4 /* load argument */
104 str ip, [sp, itmp2] /* store argument on stack */
105 add itmp2, itmp2, #4 /* next stackslot */
106 ldr ip, [itmp1], #4 /* load argument */
107 str ip, [sp, itmp2] /* store argument on stack */
108 add itmp2, itmp2, #4 /* next stackslot */
109 subs itmp3, itmp3, #1 /* next argument */
110 bgt asm_calljava_copyloop
112 asm_calljava_copyfinish:
113 mov mptr, v1 /* set method pointer */
115 /* REMEMBER: do the method call just like in java! */
116 ldr ip, [mptr] /* fake virtual function call */
120 sub ip, pc, #(fake - asm_vm_call_method)+8
122 mov sp, v1 /* restore SP */
123 add sp, sp, #4 /* free fake address */
125 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
127 asm_vm_call_method_exception_handler:
128 mov a0, xptr /* exception pointer is arg1 */
129 bl builtin_throw_exception /* throw the exception */
130 mov res1, #0 /* return NULL */
131 mov res2, #0 /* return NULL */
132 mov sp, v1 /* restore SP */
133 add sp, sp, #4 /* free fake address */
135 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
137 asm_vm_call_method_float:
140 asm_vm_call_method_double:
144 asm_vm_call_method_end:
147 /****************** function asm_call_jit_compiler *****************************
149 * Invokes the compiler for untranslated JavaVM methods. *
150 * What this method does: *
151 * - save args and LR *
152 * - fire up jit_compile (pass methodinfo pointer) *
153 * - try to find out where to write back the new method pointer *
154 * - restore args and LR *
155 * - check for exceptions *
156 * - eventually write back new method pointer *
157 * - call jit code (wich will then return to caller) *
159 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
160 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
162 *******************************************************************************/
164 #define MYSTACKSIZE (6*4)
166 asm_call_jit_compiler:
167 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
168 sub sp, sp, #4 /* keep stack 8-byte aligned */
170 mov a0, itmp1 /* pass methodinfo pointer */
171 mov a1, mptr /* pass method pointer */
172 add a2, sp, #MYSTACKSIZE /* pass Java sp */
173 mov a3, lr /* pass Java RA (correct for leafs) */
175 mov itmp1, res1 /* save pointer to new jit-code */
177 tst itmp1,itmp1 /* check for exeption */
178 beq L_asm_call_jit_compiler_exception
180 add sp, sp, #4 /* keep stack 8-byte aligned */
181 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
184 mov pc, ip /* call jit-code */
186 L_asm_call_jit_compiler_exception:
187 bl exceptions_get_and_clear_exception
188 mov xptr, res1 /* get exception */
190 add sp, sp, #4 /* keep stack 8-byte aligned */
191 RESTORE_ARGUMENT_REGISTERS /* load LR */
193 sub xpc, lr, #4 /* xpc = instruction that called us */
194 b asm_handle_nat_exception
197 /********************* function asm_handle_exception ***************************
199 * This function handles an exception. It does not use the usual calling *
200 * conventions. The exception pointer is passed in REG_ITMP1 and the *
201 * pc from the exception raising position is passed in REG_ITMP2. It searches *
202 * the local exception table for a handler. If no one is found, it unwinds *
203 * stacks and continues searching the callers. *
205 * void asm_handle_exception (exceptionptr, exceptionpc); *
207 *******************************************************************************/
209 asm_handle_nat_exception:
210 /*TODO:maybe make a macro out of it!!!*/
211 SAVE_ARGUMENT_REGISTERS
213 bl md_asm_codegen_get_pv_from_pc
215 RESTORE_ARGUMENT_REGISTERS
218 asm_handle_exception:
219 stmfd sp!, {r0 - r3} /* save possible used registers */
220 mov itmp3, #1 /* set maybe-leaf flag */
221 mov a3, #(4*4) /* prepare a3 for handle_exception */
223 asm_handle_exception_loop:
224 stmfd sp!, {ip,lr} /* call exception helper here! */
225 mov a0, xptr /* pass exception pointer */
226 mov a1, xpc /* pass exception pointer */
227 mov a2, ip /* pass data segment pointer */
228 add a3, sp, a3 /* calculate Java sp into a3... */
230 bl exceptions_handle_exception
234 beq asm_handle_exception_not_catched
236 mov xpc, a0 /* move handlerpc into xpc */
237 tst itmp3,itmp3 /* if this is a lead method ... */
238 ldmnefd sp!, {r0 - r3} /* restore argument registers */
240 mov pc, xpc /* jump to handler */
242 asm_handle_exception_not_catched:
243 tst itmp3,itmp3 /* if this is a lead method ... */
244 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
245 movne itmp3, #0 /* remove maybe-leaf flag */
247 ldr a2, [ip, #FrameSize] /* t2 = frame size */
248 add a0, sp, a2 /* t0 = pointer to save area */
249 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
250 tst a1, a1 /* if is leaf ... */
251 ldreq lr, [a0, #-4]! /* ... restore RA */
252 mov xpc, lr /* the new xpc is RA */
254 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
255 rsb a1, a1, #5 /* t1 = count of unsaved registers */
257 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
258 ldr v1, [a0, #-20] /* ... but restore the other ones */
264 add sp, sp, a2 /* unwind stack (using t2) */
265 mov a3, #0 /* prepare a3 for handle_exception */
267 /*TODO:maybe make a macro out of it!!!*/
268 SAVE_ARGUMENT_REGISTERS
270 bl md_asm_codegen_get_pv_from_pc
272 RESTORE_ARGUMENT_REGISTERS
274 b asm_handle_exception_loop
277 /* asm_abstractmethoderror *****************************************************
279 Creates and throws an AbstractMethodError.
281 *******************************************************************************/
283 asm_abstractmethoderror:
284 stmfd sp!, {lr} /* save return address */
285 add a0, sp, #(1*4) /* pass java sp */
286 mov a1, lr /* pass exception address */
287 bl exceptions_asm_new_abstractmethoderror
288 ldmfd sp!, {lr} /* restore return address */
290 mov xptr, res1 /* get exception pointer */
291 sub xpc, lr, #4 /* exception address is ra - 4 */
292 b asm_handle_nat_exception
295 /********************* function asm_cacheflush *********************************
297 * TODO: document me *
299 * void asm_cacheflush(void *p, s4 size); *
301 *******************************************************************************/
303 L___ARM_NR_cacheflush:
305 .word __ARM_NR_cacheflush
311 #if defined(__ARM_EABI__)
312 /* According to EABI, the syscall number should be passed via R7,
313 see "http://wiki.debian.org/ArmEabiPort" for additional details. */
316 ldr r7, L___ARM_NR_cacheflush
321 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
326 swi __ARM_NR_cacheflush
332 /* disable exec-stacks ********************************************************/
334 #if defined(__linux__) && defined(__ELF__)
335 .section .note.GNU-stack,"",%progbits
340 * These are local overrides for various environment variables in Emacs.
341 * Please do not remove this and leave it at the end of the file, where
342 * Emacs will automagically detect them.
343 * ---------------------------------------------------------------------
346 * indent-tabs-mode: t
350 * vim:noexpandtab:sw=4:ts=4: