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
30 #include <sys/syscall.h>
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
62 /* asm_vm_call_method **********************************************************
64 This function calls a Java-method (which possibly needs compilation)
65 with up to 4 address parameters.
67 This functions calls the JIT-compiler which eventually translates the
68 method into machine code.
70 *******************************************************************************/
74 .word 0 /* line number table start */
75 .word 0 /* line number table size */
79 .word 0 /* FrameSize */
80 .word 0 /* CodeinfoPointer */
83 asm_vm_call_method_int:
84 asm_vm_call_method_long:
85 /* asm_vm_call_method_float:
86 asm_vm_call_method_double: */
87 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
88 stmfd sp!, {v1} /* V1 is used to remember SP */
89 str a0, [sp, #-4]! /* store methods entrypoint */
91 mov v1, sp /* remember SP */
93 mov itmp1, a1 /* address of data structure */
94 mov itmp3, a2 /* stack argument count */
96 ldr a0, [itmp1], #8 /* load argument registers */
101 cmp itmp3, #0 /* do we have stack arguments? */
102 ble asm_calljava_copyfinish /* no -> do not care :-) */
105 sub sp, sp, itmp3, lsl #3 /* create stackframe for arguments */
106 asm_calljava_copyloop: /* reorder stack arguments! */
107 ldr ip, [itmp1], #4 /* load argument */
108 str ip, [sp, itmp2] /* store argument on stack */
109 add itmp2, itmp2, #4 /* next stackslot */
110 ldr ip, [itmp1], #4 /* load argument */
111 str ip, [sp, itmp2] /* store argument on stack */
112 add itmp2, itmp2, #4 /* next stackslot */
113 subs itmp3, itmp3, #1 /* next argument */
114 bgt asm_calljava_copyloop
116 asm_calljava_copyfinish:
117 mov mptr, v1 /* set method pointer */
119 /* REMEMBER: do the method call just like in java! */
120 ldr ip, [mptr] /* fake virtual function call */
124 sub ip, pc, #(fake - asm_vm_call_method)+8
126 mov sp, v1 /* restore SP */
127 add sp, sp, #4 /* free fake address */
129 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
131 asm_vm_call_method_exception_handler:
132 mov a0, xptr /* exception pointer is arg1 */
133 bl builtin_throw_exception /* throw the exception */
134 mov res1, #0 /* return NULL */
135 mov res2, #0 /* return NULL */
136 mov sp, v1 /* restore SP */
137 add sp, sp, #4 /* free fake address */
139 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
141 asm_vm_call_method_float:
144 asm_vm_call_method_double:
148 asm_vm_call_method_end:
151 /****************** function asm_call_jit_compiler *****************************
153 * Invokes the compiler for untranslated JavaVM methods. *
154 * What this method does: *
155 * - save args and LR *
156 * - fire up jit_compile (pass methodinfo pointer) *
157 * - try to find out where to write back the new method pointer *
158 * - restore args and LR *
159 * - check for exceptions *
160 * - eventually write back new method pointer *
161 * - call jit code (wich will then return to caller) *
163 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
164 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
166 *******************************************************************************/
168 #define MYSTACKSIZE (6*4)
170 asm_call_jit_compiler:
171 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
172 sub sp, sp, #4 /* keep stack 8-byte aligned */
174 mov a0, itmp1 /* pass methodinfo pointer */
175 mov a1, mptr /* pass method pointer */
176 add a2, sp, #MYSTACKSIZE /* pass Java sp */
177 mov a3, lr /* pass Java RA (correct for leafs) */
179 mov itmp1, res1 /* save pointer to new jit-code */
181 tst itmp1,itmp1 /* check for exeption */
182 beq L_asm_call_jit_compiler_exception
184 add sp, sp, #4 /* keep stack 8-byte aligned */
185 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
188 mov pc, ip /* call jit-code */
190 L_asm_call_jit_compiler_exception:
191 bl exceptions_get_and_clear_exception
192 mov xptr, res1 /* get exception */
194 add sp, sp, #4 /* keep stack 8-byte aligned */
195 RESTORE_ARGUMENT_REGISTERS /* load LR */
197 sub xpc, lr, #4 /* xpc = instruction that called us */
198 b asm_handle_nat_exception
201 /********************* function asm_handle_exception ***************************
203 * This function handles an exception. It does not use the usual calling *
204 * conventions. The exception pointer is passed in REG_ITMP1 and the *
205 * pc from the exception raising position is passed in REG_ITMP2. It searches *
206 * the local exception table for a handler. If no one is found, it unwinds *
207 * stacks and continues searching the callers. *
209 * void asm_handle_exception (exceptionptr, exceptionpc); *
211 *******************************************************************************/
213 asm_handle_nat_exception:
214 /*TODO:maybe make a macro out of it!!!*/
215 SAVE_ARGUMENT_REGISTERS
217 bl md_codegen_get_pv_from_pc
219 RESTORE_ARGUMENT_REGISTERS
222 asm_handle_exception:
223 stmfd sp!, {r0 - r3} /* save possible used registers */
224 mov itmp3, #1 /* set maybe-leaf flag */
225 mov a3, #(4*4) /* prepare a3 for handle_exception */
227 asm_handle_exception_loop:
228 stmfd sp!, {ip,lr} /* call exception helper here! */
229 mov a0, xptr /* pass exception pointer */
230 mov a1, xpc /* pass exception pointer */
231 mov a2, ip /* pass data segment pointer */
232 add a3, sp, a3 /* calculate Java sp into a3... */
234 bl exceptions_handle_exception
238 beq asm_handle_exception_not_catched
240 mov xpc, a0 /* move handlerpc into xpc */
241 tst itmp3,itmp3 /* if this is a lead method ... */
242 ldmnefd sp!, {r0 - r3} /* restore argument registers */
244 mov pc, xpc /* jump to handler */
246 asm_handle_exception_not_catched:
247 tst itmp3,itmp3 /* if this is a lead method ... */
248 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
249 movne itmp3, #0 /* remove maybe-leaf flag */
251 ldr a2, [ip, #FrameSize] /* t2 = frame size */
252 add a0, sp, a2 /* t0 = pointer to save area */
253 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
254 tst a1, a1 /* if is leaf ... */
255 ldreq lr, [a0, #-4]! /* ... restore RA */
256 mov xpc, lr /* the new xpc is RA */
258 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
259 rsb a1, a1, #5 /* t1 = count of unsaved registers */
261 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
262 ldr v1, [a0, #-20] /* ... but restore the other ones */
268 add sp, sp, a2 /* unwind stack (using t2) */
269 mov a3, #0 /* prepare a3 for handle_exception */
271 /*TODO:maybe make a macro out of it!!!*/
272 SAVE_ARGUMENT_REGISTERS
274 bl md_codegen_get_pv_from_pc
276 RESTORE_ARGUMENT_REGISTERS
278 b asm_handle_exception_loop
281 /* asm_abstractmethoderror *****************************************************
283 Creates and throws an AbstractMethodError.
285 *******************************************************************************/
287 asm_abstractmethoderror:
288 stmfd sp!, {lr} /* save return address */
289 add a0, sp, #(1*4) /* pass java sp */
290 mov a1, lr /* pass exception address */
291 bl exceptions_asm_new_abstractmethoderror
292 ldmfd sp!, {lr} /* restore return address */
294 mov xptr, res1 /* get exception pointer */
295 sub xpc, lr, #4 /* exception address is ra - 4 */
296 b asm_handle_nat_exception
299 /********************* function asm_cacheflush *********************************
301 * TODO: document me *
303 * void asm_cacheflush(void *p, s4 size); *
305 *******************************************************************************/
307 .equ sys_cacheflush,__ARM_NR_cacheflush /* syscall number for cache flushing */
313 #if defined(__ARM_EABI__)
314 /* According to EABI, the syscall number should be passed via R7,
315 see "http://wiki.debian.org/ArmEabiPort" for additional details. */
319 add r7, r7, #0x000002
323 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
330 #if defined(__ARM_EABI__)
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: