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 8276 2007-08-08 16:09:14Z twisti $
32 #include "vm/jit/arm/md-asm.h"
34 #include "vm/jit/methodheader.h"
42 /* export functions ***********************************************************/
44 .globl asm_vm_call_method
45 .globl asm_vm_call_method_int
46 .globl asm_vm_call_method_long
47 .globl asm_vm_call_method_float
48 .globl asm_vm_call_method_double
49 .globl asm_vm_call_method_exception_handler
50 .globl asm_vm_call_method_end
52 .globl asm_call_jit_compiler
54 .globl asm_handle_exception
55 .globl asm_handle_nat_exception
57 .globl asm_abstractmethoderror
61 #if !defined(ENABLE_THREADS)
63 .word _no_threads_exceptionptr
67 /* asm_vm_call_method **********************************************************
69 This function calls a Java-method (which possibly needs compilation)
70 with up to 4 address parameters.
72 This functions calls the JIT-compiler which eventually translates the
73 method into machine code.
75 *******************************************************************************/
79 .word 0 /* catch type all */
80 .word 0 /* handler pc */
82 .word 0 /* start pc */
83 .word 1 /* extable size */
84 .word 0 /* line number table start */
85 .word 0 /* line number table size */
90 .word 0 /* FrameSize */
91 .word 0 /* CodeinfoPointer */
94 asm_vm_call_method_int:
95 asm_vm_call_method_long:
96 /* asm_vm_call_method_float:
97 asm_vm_call_method_double: */
98 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
99 stmfd sp!, {v1} /* V1 is used to remember SP */
100 str a0, [sp, #-4]! /* store methods entrypoint */
102 mov v1, sp /* remember SP */
104 mov itmp1, a1 /* address of data structure */
105 mov itmp3, a2 /* stack argument count */
107 ldr a0, [itmp1], #8 /* load argument registers */
112 cmp itmp3, #0 /* do we have stack arguments? */
113 ble asm_calljava_copyfinish /* no -> do not care :-) */
116 sub sp, sp, itmp3, lsl #3 /* create stackframe for arguments */
117 asm_calljava_copyloop: /* reorder stack arguments! */
118 ldr ip, [itmp1], #4 /* load argument */
119 str ip, [sp, itmp2] /* store argument on stack */
120 add itmp2, itmp2, #4 /* next stackslot */
121 ldr ip, [itmp1], #4 /* load argument */
122 str ip, [sp, itmp2] /* store argument on stack */
123 add itmp2, itmp2, #4 /* next stackslot */
124 subs itmp3, itmp3, #1 /* next argument */
125 bgt asm_calljava_copyloop
127 asm_calljava_copyfinish:
128 mov mptr, v1 /* set method pointer */
130 /* REMEMBER: do the method call just like in java! */
131 ldr ip, [mptr] /* fake virtual function call */
135 sub ip, pc, #(fake - asm_vm_call_method)+8
137 mov sp, v1 /* restore SP */
138 add sp, sp, #4 /* free fake address */
140 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
142 asm_vm_call_method_exception_handler:
143 mov a0, xptr /* exception pointer is arg1 */
144 bl builtin_throw_exception /* throw the exception */
145 mov res1, #0 /* return NULL */
146 mov res2, #0 /* return NULL */
147 mov sp, v1 /* restore SP */
148 add sp, sp, #4 /* free fake address */
150 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
152 asm_vm_call_method_float:
155 asm_vm_call_method_double:
159 asm_vm_call_method_end:
162 /****************** function asm_call_jit_compiler *****************************
164 * Invokes the compiler for untranslated JavaVM methods. *
165 * What this method does: *
166 * - save args and LR *
167 * - fire up jit_compile (pass methodinfo pointer) *
168 * - try to find out where to write back the new method pointer *
169 * - restore args and LR *
170 * - check for exceptions *
171 * - eventually write back new method pointer *
172 * - call jit code (wich will then return to caller) *
174 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
175 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
177 *******************************************************************************/
179 #define MYSTACKSIZE (6*4)
181 asm_call_jit_compiler:
182 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
183 sub sp, sp, #4 /* keep stack 8-byte aligned */
185 mov a0, itmp1 /* pass methodinfo pointer */
186 mov a1, mptr /* pass method pointer */
187 add a2, sp, #MYSTACKSIZE /* pass Java sp */
188 mov a3, lr /* pass Java RA (correct for leafs) */
190 mov itmp1, res1 /* save pointer to new jit-code */
192 tst itmp1,itmp1 /* check for exeption */
193 beq L_asm_call_jit_compiler_exception
195 add sp, sp, #4 /* keep stack 8-byte aligned */
196 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
199 mov pc, ip /* call jit-code */
201 L_asm_call_jit_compiler_exception:
202 bl exceptions_get_and_clear_exception
203 mov xptr, res1 /* get exception */
205 add sp, sp, #4 /* keep stack 8-byte aligned */
206 RESTORE_ARGUMENT_REGISTERS /* load LR */
208 sub xpc, lr, #4 /* xpc = instruction that called us */
209 b asm_handle_nat_exception
212 /********************* function asm_handle_exception ***************************
214 * This function handles an exception. It does not use the usual calling *
215 * conventions. The exception pointer is passed in REG_ITMP1 and the *
216 * pc from the exception raising position is passed in REG_ITMP2. It searches *
217 * the local exception table for a handler. If no one is found, it unwinds *
218 * stacks and continues searching the callers. *
220 * void asm_handle_exception (exceptionptr, exceptionpc); *
222 *******************************************************************************/
224 asm_handle_nat_exception:
225 /*TODO:maybe make a macro out of it!!!*/
226 SAVE_ARGUMENT_REGISTERS
228 bl md_codegen_get_pv_from_pc
230 RESTORE_ARGUMENT_REGISTERS
233 asm_handle_exception:
234 stmfd sp!, {r0 - r3} /* save possible used registers */
235 mov itmp3, #1 /* set maybe-leaf flag */
236 mov a3, #(4*4) /* prepare a3 for handle_exception */
238 asm_handle_exception_loop:
239 stmfd sp!, {ip,lr} /* call exception helper here! */
240 mov a0, xptr /* pass exception pointer */
241 mov a1, xpc /* pass exception pointer */
242 mov a2, ip /* pass data segment pointer */
243 add a3, sp, a3 /* calculate Java sp into a3... */
245 bl exceptions_handle_exception
249 beq asm_handle_exception_not_catched
251 mov xpc, a0 /* move handlerpc into xpc */
252 tst itmp3,itmp3 /* if this is a lead method ... */
253 ldmnefd sp!, {r0 - r3} /* restore argument registers */
255 mov pc, xpc /* jump to handler */
257 asm_handle_exception_not_catched:
258 tst itmp3,itmp3 /* if this is a lead method ... */
259 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
260 movne itmp3, #0 /* remove maybe-leaf flag */
262 ldr a2, [ip, #FrameSize] /* t2 = frame size */
263 add a0, sp, a2 /* t0 = pointer to save area */
264 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
265 tst a1, a1 /* if is leaf ... */
266 ldreq lr, [a0, #-4]! /* ... restore RA */
267 mov xpc, lr /* the new xpc is RA */
269 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
270 rsb a1, a1, #5 /* t1 = count of unsaved registers */
272 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
273 ldr v1, [a0, #-20] /* ... but restore the other ones */
279 add sp, sp, a2 /* unwind stack (using t2) */
280 mov a3, #0 /* prepare a3 for handle_exception */
282 /*TODO:maybe make a macro out of it!!!*/
283 SAVE_ARGUMENT_REGISTERS
285 bl md_codegen_get_pv_from_pc
287 RESTORE_ARGUMENT_REGISTERS
289 b asm_handle_exception_loop
292 /* asm_abstractmethoderror *****************************************************
294 Creates and throws an AbstractMethodError.
296 *******************************************************************************/
298 asm_abstractmethoderror:
299 stmfd sp!, {lr} /* save return address */
300 add a0, sp, #(1*4) /* pass java sp */
301 mov a1, lr /* pass exception address */
302 bl exceptions_asm_new_abstractmethoderror
303 ldmfd sp!, {lr} /* restore return address */
305 mov xptr, res1 /* get exception pointer */
306 sub xpc, lr, #4 /* exception address is ra - 4 */
307 b asm_handle_nat_exception
310 /********************* function asm_cacheflush *********************************
312 * TODO: document me *
314 * void asm_cacheflush(void *p, s4 size); *
316 *******************************************************************************/
319 .equ sys_cacheflush, 0x9f0002
325 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
326 /* TODO: repeair this! */
327 /* cacheflush is messed up beyond all repair! */
337 /* disable exec-stacks ********************************************************/
339 #if defined(__linux__) && defined(__ELF__)
340 .section .note.GNU-stack,"",%progbits
345 * These are local overrides for various environment variables in Emacs.
346 * Please do not remove this and leave it at the end of the file, where
347 * Emacs will automagically detect them.
348 * ---------------------------------------------------------------------
351 * indent-tabs-mode: t
355 * vim:noexpandtab:sw=4:ts=4: