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
60 .globl asm_compare_and_swap
61 .globl asm_memory_barrier
64 /* asm_vm_call_method **********************************************************
66 * This function calls a Java-method (which possibly needs compilation) *
67 * with up to 4 address parameters. *
69 * This functions calls the JIT-compiler which eventually translates the *
70 * method into machine code. *
73 * javaobject_header *asm_calljavamethod (methodinfo *m, *
74 * void *arg1, void *arg2, void *arg3, void *arg4); *
76 *******************************************************************************/
83 .long 0 /* frame size */
84 .long 0 /* codeinfo pointer */
87 asm_vm_call_method_int:
88 asm_vm_call_method_long:
89 asm_vm_call_method_float:
90 asm_vm_call_method_double:
92 stw r0,LA_LR_OFFSET(sp)
93 stwu sp,-40*4(sp) /* keep stack 16-byte aligned */
95 stw s0,8*4(sp) /* save used callee saved registers */
97 #if defined(__DARWIN__)
98 stw itmp1,10*4(sp) /* register r11 is callee saved */
100 stw pv,11*4(sp) /* save PV register */
102 stw itmp3,12*4(sp) /* registers r14-r31 are callee saved */
103 stfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
106 #if defined(__DARWIN__)
122 SAVE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
125 mr pv,a0 /* move PV into PV register */
126 mtctr pv /* move PV into branch register */
128 mr t0,a1 /* address of data structure */
129 mr t1,a2 /* stack argument count */
131 mr s0,sp /* save SP */
133 lwz a0,0*8+4(t0) /* we are on big-endian */
151 #if defined(__DARWIN__)
160 beq L_asm_vm_call_method_stack_copy_done
162 slwi t2,t1,3 /* calculate stackframe size (* 8) */
164 sub sp,sp,t2 /* create stackframe */
165 mr t2,sp /* temporary stack pointer */
167 L_asm_vm_call_method_stack_copy_loop:
168 #if defined(__DARWIN__)
169 lwz t3,21*8+0(t0) /* load argument */
172 lwz t3,16*8+0(t0) /* load argument */
175 stw t3,0(t2) /* store argument on stack */
178 addi t0,t0,8 /* load address of next argument */
179 addi t2,t2,8 /* increase stack pointer */
180 addi t1,t1,-1 /* subtract 1 argument */
182 bgt L_asm_vm_call_method_stack_copy_loop
184 L_asm_vm_call_method_stack_copy_done:
188 #if defined(__DARWIN__)
189 addi pv,itmp1,lo16(asm_vm_call_method - 1b)
191 addi pv,itmp1,(asm_vm_call_method - 1b)@l
194 L_asm_vm_call_method_return:
195 mr sp,s0 /* restore the SP */
197 lwz s0,8*4(sp) /* restore used callee saved registers*/
199 #if defined(__DARWIN__)
200 lwz itmp1,10*4(sp) /* register r11 is callee saved */
202 lwz pv,11*4(sp) /* save PV register */
205 lfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
208 #if defined(__DARWIN__)
224 RESTORE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
227 lwz r0,40*4+LA_LR_OFFSET(sp)
232 asm_vm_call_method_exception_handler:
234 bl builtin_throw_exception
235 b L_asm_vm_call_method_return
237 asm_vm_call_method_end:
241 /********************* function asm_handle_exception ***************************
243 * This function handles an exception. It does not use the usual calling *
244 * conventions. The exception pointer is passed in REG_ITMP1 and the *
245 * pc from the exception raising position is passed in REG_ITMP2. It searches *
246 * the local exception table for a handler. If no one is found, it unwinds *
247 * stacks and continues searching the callers. *
249 * void asm_handle_exception (exceptionptr, exceptionpc); *
251 *******************************************************************************/
253 asm_handle_nat_exception:
254 L_asm_handle_nat_exception: /* required for PIC code */
255 L_asm_handle_exception_stack_loop:
257 addi sp,sp,-(LA_SIZE+((4+6)*4)) /* allocate stack (+4 for darwin) */
258 stw xptr,LA_SIZE+(4+0)*4(sp) /* save exception pointer */
259 stw xpc,LA_SIZE+(4+1)*4(sp) /* save exception pc */
260 stw r0,LA_SIZE+(4+3)*4(sp) /* save return address */
262 stw itmp3,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag (cleared) */
264 mr a0,r0 /* pass return address */
265 bl md_asm_codegen_get_pv_from_pc /* get PV from RA */
266 stw v0,LA_SIZE+(4+2)*4(sp) /* save data segment pointer */
268 lwz a0,LA_SIZE+(4+0)*4(sp) /* pass xptr */
269 lwz a1,LA_SIZE+(4+1)*4(sp) /* pass xpc */
270 lwz a2,LA_SIZE+(4+2)*4(sp) /* pass PV (v0 == a0) */
271 addi a3,sp,LA_SIZE+((4+6)*4) /* pass Java SP */
273 b L_asm_handle_exception_continue
275 asm_handle_exception:
276 L_asm_handle_exception: /* required for PIC code */
277 addi sp,sp,-(ARG_CNT+TMP_CNT)*8 /* create maybe-leaf stackframe */
279 #if defined(__DARWIN__)
281 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
282 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
285 addi sp,sp,-(LA_SIZE+(4+6)*4) /* allocate stack */
286 stw xptr,LA_SIZE+(4+0)*4(sp) /* save xptr */
287 stw pv,LA_SIZE+(4+2)*4(sp) /* save PV */
288 mflr r0 /* save RA */
289 stw r0,LA_SIZE+(4+3)*4(sp)
290 li t0,1 /* set maybe-leaf flag */
291 stw t0,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag */
293 mr a0,xptr /* pass exception pointer */
294 mr a1,xpc /* pass exception pc */
295 mr a2,pv /* pass data segment pointer */
296 addi a3,sp,LA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*4
298 L_asm_handle_exception_continue:
299 bl exceptions_handle_exception
302 beq L_asm_handle_exception_not_catched
304 mr xpc,v0 /* move handlerpc into xpc */
305 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
306 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
307 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
309 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
310 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
313 beq L_asm_handle_exception_no_leaf
315 #if defined(__DARWIN__)
317 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
318 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
321 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
323 L_asm_handle_exception_no_leaf:
324 mtctr xpc /* jump to the handler */
327 L_asm_handle_exception_not_catched:
328 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
329 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
330 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
332 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
333 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
336 beq L_asm_handle_exception_no_leaf_stack
338 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
339 li t0,0 /* clear the maybe-leaf flag */
341 L_asm_handle_exception_no_leaf_stack:
342 lwz t1,FrameSize(pv) /* get frame size */
343 add t1,sp,t1 /* pointer to save area */
345 lwz t2,IsLeaf(pv) /* is leaf procedure */
347 bne L_asm_handle_exception_no_ra_restore
349 lwz r0,LA_LR_OFFSET(t1) /* restore ra */
352 L_asm_handle_exception_no_ra_restore:
353 mflr xpc /* the new xpc is ra */
354 mr t4,xpc /* save RA */
355 lwz t2,IntSave(pv) /* t2 = saved int register count */
358 mflr t3 /* t3 = current pc */
359 #if defined(__DARWIN__)
360 addi t3,t3,lo16(ex_int2-ex_int1)
362 addi t3,t3,(ex_int2-ex_int1)@l
364 slwi t2,t2,2 /* t2 = register count * 4 */
365 subf t3,t2,t3 /* t3 = IntSave - t2 */
381 subf t1,t2,t1 /* t1 = t1 - register count * 4 */
387 #if defined(__DARWIN__)
388 addi t3,t3,lo16(ex_flt2-ex_flt1)
390 addi t3,t3,(ex_flt2-ex_flt1)@l
392 slwi t2,t2,2 /* t2 = register count * 4 */
393 subf t3,t2,t3 /* t3 = FltSave - t2 */
409 mtlr t4 /* restore RA */
410 lwz t1,FrameSize(pv) /* get frame size */
411 add sp,sp,t1 /* unwind stack */
412 b L_asm_handle_exception_stack_loop
415 /* asm_abstractmethoderror *****************************************************
417 Creates and throws an AbstractMethodError.
419 *******************************************************************************/
421 asm_abstractmethoderror:
423 stw r0,LA_LR_OFFSET(sp)
424 stwu sp,-LA_SIZE_ALIGNED(sp) /* preserve linkage area */
425 addi a0,sp,LA_SIZE_ALIGNED /* pass java sp */
426 mr a1,r0 /* pass exception address */
427 bl exceptions_asm_new_abstractmethoderror
428 lwz r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
429 mtlr r0 /* restore return address */
430 addi sp,sp,LA_SIZE_ALIGNED
432 mr xptr,v0 /* get exception pointer */
433 mr xpc,r0 /* we can't use r0 directly in addi */
434 addi xpc,xpc,-4 /* exception address is ra - 4 */
435 b L_asm_handle_nat_exception
438 /*********************************************************************/
466 /* asm_compare_and_swap ********************************************************
470 *******************************************************************************/
472 asm_compare_and_swap:
485 /* asm_memory_barrier **********************************************************
489 *******************************************************************************/
496 #if defined(__DARWIN__)
498 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
500 L_builtin_throw_exception$stub:
501 .indirect_symbol _builtin_throw_exception
503 bcl 20,31,L00$_builtin_throw_exception
504 L00$_builtin_throw_exception:
506 addis r11,r11,ha16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)
508 lwzu r12,lo16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)(r11)
513 L_builtin_throw_exception$lazy_ptr:
514 .indirect_symbol _builtin_throw_exception
515 .long dyld_stub_binding_helper
518 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
520 L_md_asm_codegen_get_pv_from_pc$stub:
521 .indirect_symbol _md_asm_codegen_get_pv_from_pc
523 bcl 20,31,L00$_md_asm_codegen_get_pv_from_pc
524 L00$_md_asm_codegen_get_pv_from_pc:
526 addis r11,r11,ha16(L_md_asm_codegen_get_pv_from_pc$lazy_ptr - L00$_md_asm_codegen_get_pv_from_pc)
528 lwzu r12,lo16(L_md_asm_codegen_get_pv_from_pc$lazy_ptr - L00$_md_asm_codegen_get_pv_from_pc)(r11)
533 L_md_asm_codegen_get_pv_from_pc$lazy_ptr:
534 .indirect_symbol _md_asm_codegen_get_pv_from_pc
535 .long dyld_stub_binding_helper
538 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
540 L_exceptions_handle_exception$stub:
541 .indirect_symbol _exceptions_handle_exception
543 bcl 20,31,L00$_exceptions_handle_exception
544 L00$_exceptions_handle_exception:
546 addis r11,r11,ha16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)
548 lwzu r12,lo16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)(r11)
553 L_exceptions_handle_exception$lazy_ptr:
554 .indirect_symbol _exceptions_handle_exception
555 .long dyld_stub_binding_helper
558 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
560 L_exceptions_asm_new_abstractmethoderror$stub:
561 .indirect_symbol _exceptions_asm_new_abstractmethoderror
563 bcl 20,31,L00$_exceptions_asm_new_abstractmethoderror
564 L00$_exceptions_asm_new_abstractmethoderror:
566 addis r11,r11,ha16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)
568 lwzu r12,lo16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)(r11)
573 L_exceptions_asm_new_abstractmethoderror$lazy_ptr:
574 .indirect_symbol _exceptions_asm_new_abstractmethoderror
575 .long dyld_stub_binding_helper
577 #endif /* defined(__DARWIN__) */
580 /* disable exec-stacks ********************************************************/
582 #if defined(__linux__) && defined(__ELF__)
583 .section .note.GNU-stack,"",%progbits
588 * These are local overrides for various environment variables in Emacs.
589 * Please do not remove this and leave it at the end of the file, where
590 * Emacs will automagically detect them.
591 * ---------------------------------------------------------------------
594 * indent-tabs-mode: t
598 * vim:noexpandtab:sw=4:ts=4: