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 8127 2007-06-21 11:55:56Z michi $
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
60 .globl asm_patcher_wrapper
64 .globl asm_getclassvalues_atomic
65 .globl asm_criticalsections
68 #if !defined(ENABLE_THREADS)
70 .word _no_threads_exceptionptr
74 #if defined(ENABLE_THREADS)
82 /* asm_vm_call_method **********************************************************
84 This function calls a Java-method (which possibly needs compilation)
85 with up to 4 address parameters.
87 This functions calls the JIT-compiler which eventually translates the
88 method into machine code.
90 *******************************************************************************/
94 .word 0 /* catch type all */
95 .word 0 /* handler pc */
97 .word 0 /* start pc */
98 .word 1 /* extable size */
99 .word 0 /* line number table start */
100 .word 0 /* line number table size */
101 .word 0 /* FltSave */
102 .word 0 /* IntSave */
105 .word 0 /* FrameSize */
106 .word 0 /* CodeinfoPointer */
109 asm_vm_call_method_int:
110 asm_vm_call_method_long:
111 /* asm_vm_call_method_float:
112 asm_vm_call_method_double: */
113 SAVE_SCRATCH_REGISTERS /* save our personal scratch regs */
114 stmfd sp!, {v1} /* V1 is used to remember SP */
115 str a0, [sp, #-4]! /* store methods entrypoint */
117 mov v1, sp /* remember SP */
119 mov itmp1, a1 /* address of data structure */
120 mov itmp3, a2 /* stack argument count */
122 ldr a0, [itmp1], #8 /* load argument registers */
127 cmp itmp3, #0 /* do we have stack arguments? */
128 ble asm_calljava_copyfinish /* no -> do not care :-) */
131 sub sp, sp, itmp3, lsl #3 /* create stackframe for arguments */
132 asm_calljava_copyloop: /* reorder stack arguments! */
133 ldr ip, [itmp1], #4 /* load argument */
134 str ip, [sp, itmp2] /* store argument on stack */
135 add itmp2, itmp2, #4 /* next stackslot */
136 ldr ip, [itmp1], #4 /* load argument */
137 str ip, [sp, itmp2] /* store argument on stack */
138 add itmp2, itmp2, #4 /* next stackslot */
139 subs itmp3, itmp3, #1 /* next argument */
140 bgt asm_calljava_copyloop
142 asm_calljava_copyfinish:
143 mov mptr, v1 /* set method pointer */
145 /* REMEMBER: do the method call just like in java! */
146 ldr ip, [mptr] /* fake virtual function call */
150 sub ip, pc, #(fake - asm_vm_call_method)+8
152 mov sp, v1 /* restore SP */
153 add sp, sp, #4 /* free fake address */
155 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
157 asm_vm_call_method_exception_handler:
158 mov a0, xptr /* exception pointer is arg1 */
159 bl builtin_throw_exception /* throw the exception */
160 mov res1, #0 /* return NULL */
161 mov res2, #0 /* return NULL */
162 mov sp, v1 /* restore SP */
163 add sp, sp, #4 /* free fake address */
165 RESTORE_SCRATCH_REGS_AND_RETURN /* return to caller, restore regs */
167 asm_vm_call_method_float:
170 asm_vm_call_method_double:
174 asm_vm_call_method_end:
177 /****************** function asm_call_jit_compiler *****************************
179 * Invokes the compiler for untranslated JavaVM methods. *
180 * What this method does: *
181 * - save args and LR *
182 * - fire up jit_compile (pass methodinfo pointer) *
183 * - try to find out where to write back the new method pointer *
184 * - restore args and LR *
185 * - check for exceptions *
186 * - eventually write back new method pointer *
187 * - call jit code (wich will then return to caller) *
189 * These methods can call us: codegen_compilerstub & asm_calljavafunction *
190 * ATTENTION: use REG_ITMP1 to pass methodinfo pointer to me! *
192 *******************************************************************************/
194 #define MYSTACKSIZE (6*4)
196 asm_call_jit_compiler:
197 SAVE_ARGUMENT_REGISTERS /* save our argument registers & LR */
198 sub sp, sp, #4 /* keep stack 8-byte aligned */
200 mov a0, itmp1 /* pass methodinfo pointer */
201 mov a1, mptr /* pass method pointer */
202 add a2, sp, #MYSTACKSIZE /* pass Java sp */
203 mov a3, lr /* pass Java RA (correct for leafs) */
205 mov itmp1, res1 /* save pointer to new jit-code */
207 tst itmp1,itmp1 /* check for exeption */
208 beq L_asm_call_jit_compiler_exception
210 add sp, sp, #4 /* keep stack 8-byte aligned */
211 RESTORE_ARGUMENT_REGISTERS /* load our argument registers & LR */
214 mov pc, ip /* call jit-code */
216 L_asm_call_jit_compiler_exception:
217 bl exceptions_get_and_clear_exception
218 mov xptr, res1 /* get exception */
220 add sp, sp, #4 /* keep stack 8-byte aligned */
221 RESTORE_ARGUMENT_REGISTERS /* load LR */
223 sub xpc, lr, #4 /* xpc = instruction that called us */
224 b asm_handle_nat_exception
227 /********************* function asm_handle_exception ***************************
229 * This function handles an exception. It does not use the usual calling *
230 * conventions. The exception pointer is passed in REG_ITMP1 and the *
231 * pc from the exception raising position is passed in REG_ITMP2. It searches *
232 * the local exception table for a handler. If no one is found, it unwinds *
233 * stacks and continues searching the callers. *
235 * void asm_handle_exception (exceptionptr, exceptionpc); *
237 *******************************************************************************/
239 asm_handle_nat_exception:
240 /*TODO:maybe make a macro out of it!!!*/
241 SAVE_ARGUMENT_REGISTERS
243 bl md_codegen_get_pv_from_pc
245 RESTORE_ARGUMENT_REGISTERS
248 asm_handle_exception:
249 stmfd sp!, {r0 - r3} /* save possible used registers */
250 mov itmp3, #1 /* set maybe-leaf flag */
251 mov a3, #(4*4) /* prepare a3 for handle_exception */
253 asm_handle_exception_loop:
254 stmfd sp!, {ip,lr} /* call exception helper here! */
255 mov a0, xptr /* pass exception pointer */
256 mov a1, xpc /* pass exception pointer */
257 mov a2, ip /* pass data segment pointer */
258 add a3, sp, a3 /* calculate Java sp into a3... */
260 bl exceptions_handle_exception
264 beq asm_handle_exception_not_catched
266 mov xpc, a0 /* move handlerpc into xpc */
267 tst itmp3,itmp3 /* if this is a lead method ... */
268 ldmnefd sp!, {r0 - r3} /* restore argument registers */
270 mov pc, xpc /* jump to handler */
272 asm_handle_exception_not_catched:
273 tst itmp3,itmp3 /* if this is a lead method ... */
274 addne sp, sp, #(4*4) /* remove maybe-leaf stackframe */
275 movne itmp3, #0 /* remove maybe-leaf flag */
277 ldr a2, [ip, #FrameSize] /* t2 = frame size */
278 add a0, sp, a2 /* t0 = pointer to save area */
279 ldr a1, [ip, #IsLeaf] /* t1 = is leaf procedure */
280 tst a1, a1 /* if is leaf ... */
281 ldreq lr, [a0, #-4]! /* ... restore RA */
282 mov xpc, lr /* the new xpc is RA */
284 ldr a1, [ip, #IntSave] /* t1 = saved int register count */
285 rsb a1, a1, #5 /* t1 = count of unsaved registers */
287 add pc, pc, a1, lsl #2 /* do not load unsaved registers */
288 ldr v1, [a0, #-20] /* ... but restore the other ones */
294 add sp, sp, a2 /* unwind stack (using t2) */
295 mov a3, #0 /* prepare a3 for handle_exception */
297 /*TODO:maybe make a macro out of it!!!*/
298 SAVE_ARGUMENT_REGISTERS
300 bl md_codegen_get_pv_from_pc
302 RESTORE_ARGUMENT_REGISTERS
304 b asm_handle_exception_loop
307 /* asm_patcher_wrapper *********************************************************
309 * TODO: document me *
311 * Stack layout when calling patcher function: *
312 * 28 empty because stack needs to be aligned *
313 * 24 saved REG_ITMP3, should be restored ( -8) *
314 * 20 data segment displacement from load instructions (-12) *
315 * 16 return address into JIT code (patch position) (-16) *
316 * 12 pointer to virtual java_objectheader *
317 * 8 machine code (which is patched back later) *
318 * [ 8 result of patcher function (indicates exception) ] *
319 * 4 unresolved class/method/field reference *
320 * [ 0 patcher function pointer to call ] *
321 * 0 saved IP of caller (caller needs it!) *
323 *******************************************************************************/
325 #define PATCHSTACKSIZE 8*4
328 mov itmp3, sp /* preserve original SP in ITMP3 */
330 SAVE_ARGUMENT_REGISTERS_IP /* save our argument registers & LR */
331 SAVE_FLOAT_REGISTERS /* save our float registers here */
333 mov a0, itmp3 /* pass SP of patcher stub */
334 mov a1, ip /* pass PV */
335 mov a2, lr /* pass RA (correct for leafs) */
337 mov itmp3, res1 /* save return value */
339 RESTORE_FLOAT_REGISTERS /* restore our float registers here */
340 RESTORE_ARGUMENT_REGISTERS_IP /* load our argument registers & LR */
342 add sp, sp, #PATCHSTACKSIZE /* remove patcher stack frame */
344 tst itmp3, itmp3 /* check for an exception */
345 bne L_asm_patcher_wrapper_exception
347 ldr itmp3, [sp, #-8] /* restore ITMP3 for calling method */
348 ldr pc, [sp, #-16] /* jump to new patched code */
350 L_asm_patcher_wrapper_exception:
351 mov xptr, itmp3 /* get exception */
352 ldr xpc, [sp, #-16] /* RA is xpc */
354 /* Note: A normal branch instruction could modify the PV here, */
355 /* so we use this construct instead. */
357 .word asm_handle_exception
360 /* asm_abstractmethoderror *****************************************************
362 Creates and throws an AbstractMethodError.
364 *******************************************************************************/
366 asm_abstractmethoderror:
367 stmfd sp!, {lr} /* save return address */
368 add a0, sp, #(1*4) /* pass java sp */
369 mov a1, lr /* pass exception address */
370 bl exceptions_asm_new_abstractmethoderror
371 ldmfd sp!, {lr} /* restore return address */
373 mov xptr, res1 /* get exception pointer */
374 sub xpc, lr, #4 /* exception address is ra - 4 */
375 b asm_handle_nat_exception
378 /********************* function asm_cacheflush *********************************
380 * TODO: document me *
382 * void asm_cacheflush(void *p, s4 size); *
384 *******************************************************************************/
387 .equ sys_cacheflush, 0x9f0002
393 /* TWISTI: required on iyonix, maybe a linux-2.4 bug */
394 /* TODO: repeair this! */
395 /* cacheflush is messed up beyond all repair! */
405 /********************* function asm_getclassvalues_atomic *********************/
407 asm_getclassvalues_atomic:
408 stmfd sp!, {r4, r5, r6}
411 ldr r4,[a0,#offbaseval]
412 ldr r5,[a0,#offdiffval]
413 ldr r6,[a1,#offbaseval]
415 str r4,[a2,#offcast_super_baseval]
416 str r5,[a2,#offcast_super_diffval]
417 str r6,[a2,#offcast_sub_baseval]
418 ldmfd sp!, {r4, r5, r6}
422 /* disable exec-stacks ********************************************************/
424 #if defined(__linux__) && defined(__ELF__)
425 .section .note.GNU-stack,"",%progbits
430 * These are local overrides for various environment variables in Emacs.
431 * Please do not remove this and leave it at the end of the file, where
432 * Emacs will automagically detect them.
433 * ---------------------------------------------------------------------
436 * indent-tabs-mode: t
440 * vim:noexpandtab:sw=4:ts=4: