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_end:
140 /****************** function asm_call_jit_compiler *****************************
142 * Invokes the compiler for untranslated JavaVM methods. *
143 * What this method does: *
144 * - save args and LR *
145 * - fire up jit_compile (pass methodinfo pointer) *
146 * - try to find out where to write back the new method pointer *
147 * - restore args and LR *
148 * - check for exceptions *
149 * - eventually write back new method pointer *
150 * - call jit code (wich will then return to caller) *
152 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
153 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
155 *******************************************************************************/
157 #define MYSTACKSIZE (6*4)
159 asm_call_jit_compiler:
160 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
161 sub sp, sp, #4 /* keep stack 8-byte aligned */
163 mov a0, itmp1 /* pass methodinfo pointer */
164 mov a1, mptr /* pass method pointer */
165 add a2, sp, #MYSTACKSIZE /* pass Java sp */
166 mov a3, lr /* pass Java RA (correct for leafs) */
168 mov itmp1, res1 /* save pointer to new jit-code */
170 tst itmp1,itmp1 /* check for exeption */
171 beq L_asm_call_jit_compiler_exception
173 add sp, sp, #4 /* keep stack 8-byte aligned */
174 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
177 mov pc, ip /* call jit-code */
179 L_asm_call_jit_compiler_exception:
180 bl exceptions_get_and_clear_exception
181 mov xptr, res1 /* get exception */
183 add sp, sp, #4 /* keep stack 8-byte aligned */
184 RESTORE_ARGUMENT_REGISTERS /* load LR */
186 sub xpc, lr, #4 /* xpc = instruction that called us */
187 b asm_handle_nat_exception
190 /********************* function asm_handle_exception ***************************
192 * This function handles an exception. It does not use the usual calling *
193 * conventions. The exception pointer is passed in REG_ITMP1 and the *
194 * pc from the exception raising position is passed in REG_ITMP2. It searches *
195 * the local exception table for a handler. If no one is found, it unwinds *
196 * stacks and continues searching the callers. *
198 * void asm_handle_exception (exceptionptr, exceptionpc); *
200 *******************************************************************************/
202 asm_handle_nat_exception:
203 /*TODO:maybe make a macro out of it!!!*/
204 SAVE_ARGUMENT_REGISTERS
206 bl md_asm_codegen_get_pv_from_pc
208 RESTORE_ARGUMENT_REGISTERS
211 asm_handle_exception:
212 stmfd sp!, {r0 - r3} /* save possible used registers */
213 mov itmp3, #1 /* set maybe-leaf flag */
214 mov a3, #(4*4) /* prepare a3 for handle_exception */
216 asm_handle_exception_loop:
217 stmfd sp!, {ip,lr} /* call exception helper here! */
218 mov a0, xptr /* pass exception pointer */
219 mov a1, xpc /* pass exception pointer */
220 mov a2, ip /* pass data segment pointer */
221 add a3, sp, a3 /* calculate Java sp into a3... */
223 bl exceptions_handle_exception
227 beq asm_handle_exception_not_catched
229 mov xpc, a0 /* move handlerpc into xpc */
230 tst itmp3,itmp3 /* if this is a lead method ... */
231 ldmnefd sp!, {r0 - r3} /* restore argument registers */
233 mov pc, xpc /* jump to handler */
235 asm_handle_exception_not_catched:
236 tst itmp3,itmp3 /* if this is a lead method ... */
237 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
238 movne itmp3, #0 /* remove maybe-leaf flag */
240 ldr a2, [ip, #FrameSize] /* t2 = frame size */
241 add a0, sp, a2 /* t0 = pointer to save area */
242 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
243 tst a1, a1 /* if is leaf ... */
244 ldreq lr, [a0, #-4]! /* ... restore RA */
245 mov xpc, lr /* the new xpc is RA */
247 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
248 rsb a1, a1, #5 /* t1 = count of unsaved registers */
250 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
251 ldr v1, [a0, #-20] /* ... but restore the other ones */
257 add sp, sp, a2 /* unwind stack (using t2) */
258 mov a3, #0 /* prepare a3 for handle_exception */
260 /*TODO:maybe make a macro out of it!!!*/
261 SAVE_ARGUMENT_REGISTERS
263 bl md_asm_codegen_get_pv_from_pc
265 RESTORE_ARGUMENT_REGISTERS
267 b asm_handle_exception_loop
270 /* asm_abstractmethoderror *****************************************************
272 Creates and throws an AbstractMethodError.
274 *******************************************************************************/
276 asm_abstractmethoderror:
277 stmfd sp!, {lr} /* save return address */
278 add a0, sp, #(1*4) /* pass java sp */
279 mov a1, lr /* pass exception address */
280 bl exceptions_asm_new_abstractmethoderror
281 ldmfd sp!, {lr} /* restore return address */
283 mov xptr, res1 /* get exception pointer */
284 sub xpc, lr, #4 /* exception address is ra - 4 */
285 b asm_handle_nat_exception
288 /********************* function asm_cacheflush *********************************
290 * TODO: document me *
292 * void asm_cacheflush(void *p, s4 size); *
294 *******************************************************************************/
296 L___ARM_NR_cacheflush:
298 .word __ARM_NR_cacheflush
304 #if defined(__ARM_EABI__)
305 /* According to EABI, the syscall number should be passed via R7,
306 see "http://wiki.debian.org/ArmEabiPort" for additional details. */
309 ldr r7, L___ARM_NR_cacheflush
314 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
319 swi __ARM_NR_cacheflush
325 /* disable exec-stacks ********************************************************/
327 #if defined(__linux__) && defined(__ELF__)
328 .section .note.GNU-stack,"",%progbits
333 * These are local overrides for various environment variables in Emacs.
334 * Please do not remove this and leave it at the end of the file, where
335 * Emacs will automagically detect them.
336 * ---------------------------------------------------------------------
339 * indent-tabs-mode: t
343 * vim:noexpandtab:sw=4:ts=4: