1 /* src/vm/jit/powerpc/asmpart.S - Java-C interface functions for PowerPC
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.text; 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
33 #include "vm/jit/abi-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
50 .globl asm_vm_call_method_exception_handler
51 .globl asm_vm_call_method_end
53 .globl asm_handle_nat_exception
54 .globl asm_handle_exception
56 .globl asm_abstractmethoderror
61 /* asm_vm_call_method **********************************************************
63 * This function calls a Java-method (which possibly needs compilation) *
64 * with up to 4 address parameters. *
66 * This functions calls the JIT-compiler which eventually translates the *
67 * method into machine code. *
70 * javaobject_header *asm_calljavamethod (methodinfo *m, *
71 * void *arg1, void *arg2, void *arg3, void *arg4); *
73 *******************************************************************************/
80 .long 0 /* frame size */
81 .long 0 /* codeinfo pointer */
84 asm_vm_call_method_int:
85 asm_vm_call_method_long:
86 asm_vm_call_method_float:
87 asm_vm_call_method_double:
89 stw r0,LA_LR_OFFSET(sp)
90 stwu sp,-40*4(sp) /* keep stack 16-byte aligned */
92 stw s0,8*4(sp) /* save used callee saved registers */
94 #if defined(__DARWIN__)
95 stw itmp1,10*4(sp) /* register r11 is callee saved */
97 stw pv,11*4(sp) /* save PV register */
99 stw itmp3,12*4(sp) /* registers r14-r31 are callee saved */
100 stfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
103 #if defined(__DARWIN__)
119 SAVE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
122 mr pv,a0 /* move PV into PV register */
123 mtctr pv /* move PV into branch register */
125 mr t0,a1 /* address of data structure */
126 mr t1,a2 /* stack argument count */
128 mr s0,sp /* save SP */
130 lwz a0,0*8+4(t0) /* we are on big-endian */
148 #if defined(__DARWIN__)
157 beq L_asm_vm_call_method_stack_copy_done
159 slwi t2,t1,3 /* calculate stackframe size (* 8) */
161 sub sp,sp,t2 /* create stackframe */
162 mr t2,sp /* temporary stack pointer */
164 L_asm_vm_call_method_stack_copy_loop:
165 #if defined(__DARWIN__)
166 lwz t3,21*8+0(t0) /* load argument */
169 lwz t3,16*8+0(t0) /* load argument */
172 stw t3,0(t2) /* store argument on stack */
175 addi t0,t0,8 /* load address of next argument */
176 addi t2,t2,8 /* increase stack pointer */
177 addi t1,t1,-1 /* subtract 1 argument */
179 bgt L_asm_vm_call_method_stack_copy_loop
181 L_asm_vm_call_method_stack_copy_done:
185 #if defined(__DARWIN__)
186 addi pv,itmp1,lo16(asm_vm_call_method - 1b)
188 addi pv,itmp1,(asm_vm_call_method - 1b)@l
191 L_asm_vm_call_method_return:
192 mr sp,s0 /* restore the SP */
194 lwz s0,8*4(sp) /* restore used callee saved registers*/
196 #if defined(__DARWIN__)
197 lwz itmp1,10*4(sp) /* register r11 is callee saved */
199 lwz pv,11*4(sp) /* save PV register */
202 lfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
205 #if defined(__DARWIN__)
221 RESTORE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
224 lwz r0,40*4+LA_LR_OFFSET(sp)
229 asm_vm_call_method_exception_handler:
231 bl builtin_throw_exception
232 b L_asm_vm_call_method_return
234 asm_vm_call_method_end:
238 /********************* function asm_handle_exception ***************************
240 * This function handles an exception. It does not use the usual calling *
241 * conventions. The exception pointer is passed in REG_ITMP1 and the *
242 * pc from the exception raising position is passed in REG_ITMP2. It searches *
243 * the local exception table for a handler. If no one is found, it unwinds *
244 * stacks and continues searching the callers. *
246 * void asm_handle_exception (exceptionptr, exceptionpc); *
248 *******************************************************************************/
250 asm_handle_nat_exception:
251 L_asm_handle_nat_exception: /* required for PIC code */
252 L_asm_handle_exception_stack_loop:
254 addi sp,sp,-(LA_SIZE+((4+6)*4)) /* allocate stack (+4 for darwin) */
255 stw xptr,LA_SIZE+(4+0)*4(sp) /* save exception pointer */
256 stw xpc,LA_SIZE+(4+1)*4(sp) /* save exception pc */
257 stw r0,LA_SIZE+(4+3)*4(sp) /* save return address */
259 stw itmp3,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag (cleared) */
261 mr a0,r0 /* pass return address */
262 bl md_asm_codegen_get_pv_from_pc /* get PV from RA */
263 stw v0,LA_SIZE+(4+2)*4(sp) /* save data segment pointer */
265 lwz a0,LA_SIZE+(4+0)*4(sp) /* pass xptr */
266 lwz a1,LA_SIZE+(4+1)*4(sp) /* pass xpc */
267 lwz a2,LA_SIZE+(4+2)*4(sp) /* pass PV (v0 == a0) */
268 addi a3,sp,LA_SIZE+((4+6)*4) /* pass Java SP */
270 b L_asm_handle_exception_continue
272 asm_handle_exception:
273 L_asm_handle_exception: /* required for PIC code */
274 addi sp,sp,-(ARG_CNT+TMP_CNT)*8 /* create maybe-leaf stackframe */
276 #if defined(__DARWIN__)
278 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
279 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
282 addi sp,sp,-(LA_SIZE+(4+6)*4) /* allocate stack */
283 stw xptr,LA_SIZE+(4+0)*4(sp) /* save xptr */
284 stw pv,LA_SIZE+(4+2)*4(sp) /* save PV */
285 mflr r0 /* save RA */
286 stw r0,LA_SIZE+(4+3)*4(sp)
287 li t0,1 /* set maybe-leaf flag */
288 stw t0,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag */
290 mr a0,xptr /* pass exception pointer */
291 mr a1,xpc /* pass exception pc */
292 mr a2,pv /* pass data segment pointer */
293 addi a3,sp,LA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*4
295 L_asm_handle_exception_continue:
296 bl exceptions_handle_exception
299 beq L_asm_handle_exception_not_catched
301 mr xpc,v0 /* move handlerpc into xpc */
302 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
303 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
304 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
306 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
307 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
310 beq L_asm_handle_exception_no_leaf
312 #if defined(__DARWIN__)
314 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
315 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
318 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
320 L_asm_handle_exception_no_leaf:
321 mtctr xpc /* jump to the handler */
324 L_asm_handle_exception_not_catched:
325 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
326 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
327 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
329 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
330 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
333 beq L_asm_handle_exception_no_leaf_stack
335 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
336 li t0,0 /* clear the maybe-leaf flag */
338 L_asm_handle_exception_no_leaf_stack:
339 lwz t1,FrameSize(pv) /* get frame size */
340 add t1,sp,t1 /* pointer to save area */
342 lwz t2,IsLeaf(pv) /* is leaf procedure */
344 bne L_asm_handle_exception_no_ra_restore
346 lwz r0,LA_LR_OFFSET(t1) /* restore ra */
349 L_asm_handle_exception_no_ra_restore:
350 mflr xpc /* the new xpc is ra */
351 mr t4,xpc /* save RA */
352 lwz t2,IntSave(pv) /* t2 = saved int register count */
355 mflr t3 /* t3 = current pc */
356 #if defined(__DARWIN__)
357 addi t3,t3,lo16(ex_int2-ex_int1)
359 addi t3,t3,(ex_int2-ex_int1)@l
361 slwi t2,t2,2 /* t2 = register count * 4 */
362 subf t3,t2,t3 /* t3 = IntSave - t2 */
378 subf t1,t2,t1 /* t1 = t1 - register count * 4 */
384 #if defined(__DARWIN__)
385 addi t3,t3,lo16(ex_flt2-ex_flt1)
387 addi t3,t3,(ex_flt2-ex_flt1)@l
389 slwi t2,t2,2 /* t2 = register count * 4 */
390 subf t3,t2,t3 /* t3 = FltSave - t2 */
406 mtlr t4 /* restore RA */
407 lwz t1,FrameSize(pv) /* get frame size */
408 add sp,sp,t1 /* unwind stack */
409 b L_asm_handle_exception_stack_loop
412 /* asm_abstractmethoderror *****************************************************
414 Creates and throws an AbstractMethodError.
416 *******************************************************************************/
418 asm_abstractmethoderror:
420 stw r0,LA_LR_OFFSET(sp)
421 stwu sp,-LA_SIZE_ALIGNED(sp) /* preserve linkage area */
422 addi a0,sp,LA_SIZE_ALIGNED /* pass java sp */
423 mr a1,r0 /* pass exception address */
424 bl exceptions_asm_new_abstractmethoderror
425 lwz r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
426 mtlr r0 /* restore return address */
427 addi sp,sp,LA_SIZE_ALIGNED
429 mr xptr,v0 /* get exception pointer */
430 mr xpc,r0 /* we can't use r0 directly in addi */
431 addi xpc,xpc,-4 /* exception address is ra - 4 */
432 b L_asm_handle_nat_exception
435 /*********************************************************************/
463 #if defined(__DARWIN__)
465 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
467 L_builtin_throw_exception$stub:
468 .indirect_symbol _builtin_throw_exception
470 bcl 20,31,L00$_builtin_throw_exception
471 L00$_builtin_throw_exception:
473 addis r11,r11,ha16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)
475 lwzu r12,lo16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)(r11)
480 L_builtin_throw_exception$lazy_ptr:
481 .indirect_symbol _builtin_throw_exception
482 .long dyld_stub_binding_helper
485 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
487 L_md_asm_codegen_get_pv_from_pc$stub:
488 .indirect_symbol _md_asm_codegen_get_pv_from_pc
490 bcl 20,31,L00$_md_asm_codegen_get_pv_from_pc
491 L00$_md_asm_codegen_get_pv_from_pc:
493 addis r11,r11,ha16(L_md_asm_codegen_get_pv_from_pc$lazy_ptr - L00$_md_asm_codegen_get_pv_from_pc)
495 lwzu r12,lo16(L_md_asm_codegen_get_pv_from_pc$lazy_ptr - L00$_md_asm_codegen_get_pv_from_pc)(r11)
500 L_md_asm_codegen_get_pv_from_pc$lazy_ptr:
501 .indirect_symbol _md_asm_codegen_get_pv_from_pc
502 .long dyld_stub_binding_helper
505 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
507 L_exceptions_handle_exception$stub:
508 .indirect_symbol _exceptions_handle_exception
510 bcl 20,31,L00$_exceptions_handle_exception
511 L00$_exceptions_handle_exception:
513 addis r11,r11,ha16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)
515 lwzu r12,lo16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)(r11)
520 L_exceptions_handle_exception$lazy_ptr:
521 .indirect_symbol _exceptions_handle_exception
522 .long dyld_stub_binding_helper
525 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
527 L_exceptions_asm_new_abstractmethoderror$stub:
528 .indirect_symbol _exceptions_asm_new_abstractmethoderror
530 bcl 20,31,L00$_exceptions_asm_new_abstractmethoderror
531 L00$_exceptions_asm_new_abstractmethoderror:
533 addis r11,r11,ha16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)
535 lwzu r12,lo16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)(r11)
540 L_exceptions_asm_new_abstractmethoderror$lazy_ptr:
541 .indirect_symbol _exceptions_asm_new_abstractmethoderror
542 .long dyld_stub_binding_helper
544 #endif /* defined(__DARWIN__) */
547 /* disable exec-stacks ********************************************************/
549 #if defined(__linux__) && defined(__ELF__)
550 .section .note.GNU-stack,"",%progbits
555 * These are local overrides for various environment variables in Emacs.
556 * Please do not remove this and leave it at the end of the file, where
557 * Emacs will automagically detect them.
558 * ---------------------------------------------------------------------
561 * indent-tabs-mode: t
565 * vim:noexpandtab:sw=4:ts=4: