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 8274 2007-08-08 15:58:17Z 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
62 #if !defined(ENABLE_THREADS)
64 .word _no_threads_exceptionptr
68 /* asm_vm_call_method **********************************************************
70 This function calls a Java-method (which possibly needs compilation)
71 with up to 4 address parameters.
73 This functions calls the JIT-compiler which eventually translates the
74 method into machine code.
76 *******************************************************************************/
80 .word 0 /* catch type all */
81 .word 0 /* handler pc */
83 .word 0 /* start pc */
84 .word 1 /* extable size */
85 .word 0 /* line number table start */
86 .word 0 /* line number table size */
91 .word 0 /* FrameSize */
92 .word 0 /* CodeinfoPointer */
95 asm_vm_call_method_int:
96 asm_vm_call_method_long:
97 /* asm_vm_call_method_float:
98 asm_vm_call_method_double: */
99 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
100 stmfd sp!, {v1} /* V1 is used to remember SP */
101 str a0, [sp, #-4]! /* store methods entrypoint */
103 mov v1, sp /* remember SP */
105 mov itmp1, a1 /* address of data structure */
106 mov itmp3, a2 /* stack argument count */
108 ldr a0, [itmp1], #8 /* load argument registers */
113 cmp itmp3, #0 /* do we have stack arguments? */
114 ble asm_calljava_copyfinish /* no -> do not care :-) */
117 sub sp, sp, itmp3, lsl #3 /* create stackframe for arguments */
118 asm_calljava_copyloop: /* reorder stack arguments! */
119 ldr ip, [itmp1], #4 /* load argument */
120 str ip, [sp, itmp2] /* store argument on stack */
121 add itmp2, itmp2, #4 /* next stackslot */
122 ldr ip, [itmp1], #4 /* load argument */
123 str ip, [sp, itmp2] /* store argument on stack */
124 add itmp2, itmp2, #4 /* next stackslot */
125 subs itmp3, itmp3, #1 /* next argument */
126 bgt asm_calljava_copyloop
128 asm_calljava_copyfinish:
129 mov mptr, v1 /* set method pointer */
131 /* REMEMBER: do the method call just like in java! */
132 ldr ip, [mptr] /* fake virtual function call */
136 sub ip, pc, #(fake - asm_vm_call_method)+8
138 mov sp, v1 /* restore SP */
139 add sp, sp, #4 /* free fake address */
141 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
143 asm_vm_call_method_exception_handler:
144 mov a0, xptr /* exception pointer is arg1 */
145 bl builtin_throw_exception /* throw the exception */
146 mov res1, #0 /* return NULL */
147 mov res2, #0 /* return NULL */
148 mov sp, v1 /* restore SP */
149 add sp, sp, #4 /* free fake address */
151 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
153 asm_vm_call_method_float:
156 asm_vm_call_method_double:
160 asm_vm_call_method_end:
163 /****************** function asm_call_jit_compiler *****************************
165 * Invokes the compiler for untranslated JavaVM methods. *
166 * What this method does: *
167 * - save args and LR *
168 * - fire up jit_compile (pass methodinfo pointer) *
169 * - try to find out where to write back the new method pointer *
170 * - restore args and LR *
171 * - check for exceptions *
172 * - eventually write back new method pointer *
173 * - call jit code (wich will then return to caller) *
175 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
176 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
178 *******************************************************************************/
180 #define MYSTACKSIZE (6*4)
182 asm_call_jit_compiler:
183 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
184 sub sp, sp, #4 /* keep stack 8-byte aligned */
186 mov a0, itmp1 /* pass methodinfo pointer */
187 mov a1, mptr /* pass method pointer */
188 add a2, sp, #MYSTACKSIZE /* pass Java sp */
189 mov a3, lr /* pass Java RA (correct for leafs) */
191 mov itmp1, res1 /* save pointer to new jit-code */
193 tst itmp1,itmp1 /* check for exeption */
194 beq L_asm_call_jit_compiler_exception
196 add sp, sp, #4 /* keep stack 8-byte aligned */
197 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
200 mov pc, ip /* call jit-code */
202 L_asm_call_jit_compiler_exception:
203 bl exceptions_get_and_clear_exception
204 mov xptr, res1 /* get exception */
206 add sp, sp, #4 /* keep stack 8-byte aligned */
207 RESTORE_ARGUMENT_REGISTERS /* load LR */
209 sub xpc, lr, #4 /* xpc = instruction that called us */
210 b asm_handle_nat_exception
213 /********************* function asm_handle_exception ***************************
215 * This function handles an exception. It does not use the usual calling *
216 * conventions. The exception pointer is passed in REG_ITMP1 and the *
217 * pc from the exception raising position is passed in REG_ITMP2. It searches *
218 * the local exception table for a handler. If no one is found, it unwinds *
219 * stacks and continues searching the callers. *
221 * void asm_handle_exception (exceptionptr, exceptionpc); *
223 *******************************************************************************/
225 asm_handle_nat_exception:
226 /*TODO:maybe make a macro out of it!!!*/
227 SAVE_ARGUMENT_REGISTERS
229 bl md_codegen_get_pv_from_pc
231 RESTORE_ARGUMENT_REGISTERS
234 asm_handle_exception:
235 stmfd sp!, {r0 - r3} /* save possible used registers */
236 mov itmp3, #1 /* set maybe-leaf flag */
237 mov a3, #(4*4) /* prepare a3 for handle_exception */
239 asm_handle_exception_loop:
240 stmfd sp!, {ip,lr} /* call exception helper here! */
241 mov a0, xptr /* pass exception pointer */
242 mov a1, xpc /* pass exception pointer */
243 mov a2, ip /* pass data segment pointer */
244 add a3, sp, a3 /* calculate Java sp into a3... */
246 bl exceptions_handle_exception
250 beq asm_handle_exception_not_catched
252 mov xpc, a0 /* move handlerpc into xpc */
253 tst itmp3,itmp3 /* if this is a lead method ... */
254 ldmnefd sp!, {r0 - r3} /* restore argument registers */
256 mov pc, xpc /* jump to handler */
258 asm_handle_exception_not_catched:
259 tst itmp3,itmp3 /* if this is a lead method ... */
260 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
261 movne itmp3, #0 /* remove maybe-leaf flag */
263 ldr a2, [ip, #FrameSize] /* t2 = frame size */
264 add a0, sp, a2 /* t0 = pointer to save area */
265 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
266 tst a1, a1 /* if is leaf ... */
267 ldreq lr, [a0, #-4]! /* ... restore RA */
268 mov xpc, lr /* the new xpc is RA */
270 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
271 rsb a1, a1, #5 /* t1 = count of unsaved registers */
273 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
274 ldr v1, [a0, #-20] /* ... but restore the other ones */
280 add sp, sp, a2 /* unwind stack (using t2) */
281 mov a3, #0 /* prepare a3 for handle_exception */
283 /*TODO:maybe make a macro out of it!!!*/
284 SAVE_ARGUMENT_REGISTERS
286 bl md_codegen_get_pv_from_pc
288 RESTORE_ARGUMENT_REGISTERS
290 b asm_handle_exception_loop
293 /* asm_abstractmethoderror *****************************************************
295 Creates and throws an AbstractMethodError.
297 *******************************************************************************/
299 asm_abstractmethoderror:
300 stmfd sp!, {lr} /* save return address */
301 add a0, sp, #(1*4) /* pass java sp */
302 mov a1, lr /* pass exception address */
303 bl exceptions_asm_new_abstractmethoderror
304 ldmfd sp!, {lr} /* restore return address */
306 mov xptr, res1 /* get exception pointer */
307 sub xpc, lr, #4 /* exception address is ra - 4 */
308 b asm_handle_nat_exception
311 /********************* function asm_cacheflush *********************************
313 * TODO: document me *
315 * void asm_cacheflush(void *p, s4 size); *
317 *******************************************************************************/
320 .equ sys_cacheflush, 0x9f0002
326 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
327 /* TODO: repeair this! */
328 /* cacheflush is messed up beyond all repair! */
338 /* disable exec-stacks ********************************************************/
340 #if defined(__linux__) && defined(__ELF__)
341 .section .note.GNU-stack,"",%progbits
346 * These are local overrides for various environment variables in Emacs.
347 * Please do not remove this and leave it at the end of the file, where
348 * Emacs will automagically detect them.
349 * ---------------------------------------------------------------------
352 * indent-tabs-mode: t
356 * vim:noexpandtab:sw=4:ts=4: