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 *******************************************************************************/
80 .long 0 /* catch type all */
81 .long 0 /* exception handler pc */
83 .long 0 /* start pc */
84 .long 1 /* extable size */
85 .long 0 /* line number table start */
86 .long 0 /* line number table size */
91 .long 0 /* frame size */
92 .long 0 /* codeinfo pointer */
95 asm_vm_call_method_int:
96 asm_vm_call_method_long:
97 asm_vm_call_method_float:
98 asm_vm_call_method_double:
100 stw r0,LA_LR_OFFSET(sp)
101 stwu sp,-40*4(sp) /* keep stack 16-byte aligned */
103 stw s0,8*4(sp) /* save used callee saved registers */
105 #if defined(__DARWIN__)
106 stw itmp1,10*4(sp) /* register r11 is callee saved */
108 stw pv,11*4(sp) /* save PV register */
110 stw itmp3,12*4(sp) /* registers r14-r31 are callee saved */
111 stfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
114 #if defined(__DARWIN__)
130 SAVE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
133 mr pv,a0 /* move PV into PV register */
134 mtctr pv /* move PV into branch register */
136 mr t0,a1 /* address of data structure */
137 mr t1,a2 /* stack argument count */
139 mr s0,sp /* save SP */
141 lwz a0,0*8+4(t0) /* we are on big-endian */
159 #if defined(__DARWIN__)
168 beq L_asm_vm_call_method_stack_copy_done
170 slwi t2,t1,3 /* calculate stackframe size (* 8) */
172 sub sp,sp,t2 /* create stackframe */
173 mr t2,sp /* temporary stack pointer */
175 L_asm_vm_call_method_stack_copy_loop:
176 #if defined(__DARWIN__)
177 lwz t3,21*8+0(t0) /* load argument */
180 lwz t3,16*8+0(t0) /* load argument */
183 stw t3,0(t2) /* store argument on stack */
186 addi t0,t0,8 /* load address of next argument */
187 addi t2,t2,8 /* increase stack pointer */
188 addi t1,t1,-1 /* subtract 1 argument */
190 bgt L_asm_vm_call_method_stack_copy_loop
192 L_asm_vm_call_method_stack_copy_done:
196 #if defined(__DARWIN__)
197 addi pv,itmp1,lo16(asm_vm_call_method - 1b)
199 addi pv,itmp1,(asm_vm_call_method - 1b)@l
202 L_asm_vm_call_method_return:
203 mr sp,s0 /* restore the SP */
205 lwz s0,8*4(sp) /* restore used callee saved registers*/
207 #if defined(__DARWIN__)
208 lwz itmp1,10*4(sp) /* register r11 is callee saved */
210 lwz pv,11*4(sp) /* save PV register */
213 lfd ftmp1,14*4(sp) /* registers f14-f31 are callee saved */
216 #if defined(__DARWIN__)
232 RESTORE_TEMPORARY_REGISTERS(18) /* the offset has to be even */
235 lwz r0,40*4+LA_LR_OFFSET(sp)
240 asm_vm_call_method_exception_handler:
242 bl builtin_throw_exception
243 b L_asm_vm_call_method_return
245 asm_vm_call_method_end:
249 /********************* function asm_handle_exception ***************************
251 * This function handles an exception. It does not use the usual calling *
252 * conventions. The exception pointer is passed in REG_ITMP1 and the *
253 * pc from the exception raising position is passed in REG_ITMP2. It searches *
254 * the local exception table for a handler. If no one is found, it unwinds *
255 * stacks and continues searching the callers. *
257 * void asm_handle_exception (exceptionptr, exceptionpc); *
259 *******************************************************************************/
261 asm_handle_nat_exception:
262 L_asm_handle_nat_exception: /* required for PIC code */
263 L_asm_handle_exception_stack_loop:
265 addi sp,sp,-(LA_SIZE+((4+6)*4)) /* allocate stack (+4 for darwin) */
266 stw xptr,LA_SIZE+(4+0)*4(sp) /* save exception pointer */
267 stw xpc,LA_SIZE+(4+1)*4(sp) /* save exception pc */
268 stw r0,LA_SIZE+(4+3)*4(sp) /* save return address */
270 stw itmp3,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag (cleared) */
272 mr a0,r0 /* pass return address */
273 bl md_codegen_get_pv_from_pc /* get PV from RA */
274 stw v0,LA_SIZE+(4+2)*4(sp) /* save data segment pointer */
276 lwz a0,LA_SIZE+(4+0)*4(sp) /* pass xptr */
277 lwz a1,LA_SIZE+(4+1)*4(sp) /* pass xpc */
278 lwz a2,LA_SIZE+(4+2)*4(sp) /* pass PV (v0 == a0) */
279 addi a3,sp,LA_SIZE+((4+6)*4) /* pass Java SP */
281 b L_asm_handle_exception_continue
283 asm_handle_exception:
284 L_asm_handle_exception: /* required for PIC code */
285 addi sp,sp,-(ARG_CNT+TMP_CNT)*8 /* create maybe-leaf stackframe */
287 #if defined(__DARWIN__)
289 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
290 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
293 addi sp,sp,-(LA_SIZE+(4+6)*4) /* allocate stack */
294 stw xptr,LA_SIZE+(4+0)*4(sp) /* save xptr */
295 stw pv,LA_SIZE+(4+2)*4(sp) /* save PV */
296 mflr r0 /* save RA */
297 stw r0,LA_SIZE+(4+3)*4(sp)
298 li t0,1 /* set maybe-leaf flag */
299 stw t0,LA_SIZE+(4+4)*4(sp) /* save maybe-leaf flag */
301 mr a0,xptr /* pass exception pointer */
302 mr a1,xpc /* pass exception pc */
303 mr a2,pv /* pass data segment pointer */
304 addi a3,sp,LA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*4
306 L_asm_handle_exception_continue:
307 bl exceptions_handle_exception
310 beq L_asm_handle_exception_not_catched
312 mr xpc,v0 /* move handlerpc into xpc */
313 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
314 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
315 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
317 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
318 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
321 beq L_asm_handle_exception_no_leaf
323 #if defined(__DARWIN__)
325 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
326 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
329 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
331 L_asm_handle_exception_no_leaf:
332 mtctr xpc /* jump to the handler */
335 L_asm_handle_exception_not_catched:
336 lwz xptr,LA_SIZE+(4+0)*4(sp) /* restore xptr */
337 lwz pv,LA_SIZE+(4+2)*4(sp) /* restore PV */
338 lwz r0,LA_SIZE+(4+3)*4(sp) /* restore RA */
340 lwz t0,LA_SIZE+(4+4)*4(sp) /* get maybe-leaf flag */
341 addi sp,sp,LA_SIZE+(4+6)*4 /* free stack frame */
344 beq L_asm_handle_exception_no_leaf_stack
346 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
347 li t0,0 /* clear the maybe-leaf flag */
349 L_asm_handle_exception_no_leaf_stack:
350 lwz t1,FrameSize(pv) /* get frame size */
351 add t1,sp,t1 /* pointer to save area */
353 lwz t2,IsLeaf(pv) /* is leaf procedure */
355 bne L_asm_handle_exception_no_ra_restore
357 lwz r0,LA_LR_OFFSET(t1) /* restore ra */
360 L_asm_handle_exception_no_ra_restore:
361 mflr xpc /* the new xpc is ra */
362 mr t4,xpc /* save RA */
363 lwz t2,IntSave(pv) /* t2 = saved int register count */
366 mflr t3 /* t3 = current pc */
367 #if defined(__DARWIN__)
368 addi t3,t3,lo16(ex_int2-ex_int1)
370 addi t3,t3,(ex_int2-ex_int1)@l
372 slwi t2,t2,2 /* t2 = register count * 4 */
373 subf t3,t2,t3 /* t3 = IntSave - t2 */
389 subf t1,t2,t1 /* t1 = t1 - register count * 4 */
395 #if defined(__DARWIN__)
396 addi t3,t3,lo16(ex_flt2-ex_flt1)
398 addi t3,t3,(ex_flt2-ex_flt1)@l
400 slwi t2,t2,2 /* t2 = register count * 4 */
401 subf t3,t2,t3 /* t3 = FltSave - t2 */
417 mtlr t4 /* restore RA */
418 lwz t1,FrameSize(pv) /* get frame size */
419 add sp,sp,t1 /* unwind stack */
420 b L_asm_handle_exception_stack_loop
423 /* asm_abstractmethoderror *****************************************************
425 Creates and throws an AbstractMethodError.
427 *******************************************************************************/
429 asm_abstractmethoderror:
431 stw r0,LA_LR_OFFSET(sp)
432 stwu sp,-LA_SIZE_ALIGNED(sp) /* preserve linkage area */
433 addi a0,sp,LA_SIZE_ALIGNED /* pass java sp */
434 mr a1,r0 /* pass exception address */
435 bl exceptions_asm_new_abstractmethoderror
436 lwz r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
437 mtlr r0 /* restore return address */
438 addi sp,sp,LA_SIZE_ALIGNED
440 mr xptr,v0 /* get exception pointer */
441 mr xpc,r0 /* we can't use r0 directly in addi */
442 addi xpc,xpc,-4 /* exception address is ra - 4 */
443 b L_asm_handle_nat_exception
446 /*********************************************************************/
474 /* asm_compare_and_swap ********************************************************
478 *******************************************************************************/
480 asm_compare_and_swap:
493 /* asm_memory_barrier **********************************************************
497 *******************************************************************************/
504 #if defined(__DARWIN__)
506 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
508 L_builtin_throw_exception$stub:
509 .indirect_symbol _builtin_throw_exception
511 bcl 20,31,L00$_builtin_throw_exception
512 L00$_builtin_throw_exception:
514 addis r11,r11,ha16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)
516 lwzu r12,lo16(L_builtin_throw_exception$lazy_ptr - L00$_builtin_throw_exception)(r11)
521 L_builtin_throw_exception$lazy_ptr:
522 .indirect_symbol _builtin_throw_exception
523 .long dyld_stub_binding_helper
526 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
528 L_md_codegen_get_pv_from_pc$stub:
529 .indirect_symbol _md_codegen_get_pv_from_pc
531 bcl 20,31,L00$_md_codegen_get_pv_from_pc
532 L00$_md_codegen_get_pv_from_pc:
534 addis r11,r11,ha16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)
536 lwzu r12,lo16(L_md_codegen_get_pv_from_pc$lazy_ptr - L00$_md_codegen_get_pv_from_pc)(r11)
541 L_md_codegen_get_pv_from_pc$lazy_ptr:
542 .indirect_symbol _md_codegen_get_pv_from_pc
543 .long dyld_stub_binding_helper
546 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
548 L_exceptions_handle_exception$stub:
549 .indirect_symbol _exceptions_handle_exception
551 bcl 20,31,L00$_exceptions_handle_exception
552 L00$_exceptions_handle_exception:
554 addis r11,r11,ha16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)
556 lwzu r12,lo16(L_exceptions_handle_exception$lazy_ptr - L00$_exceptions_handle_exception)(r11)
561 L_exceptions_handle_exception$lazy_ptr:
562 .indirect_symbol _exceptions_handle_exception
563 .long dyld_stub_binding_helper
566 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
568 L_exceptions_asm_new_abstractmethoderror$stub:
569 .indirect_symbol _exceptions_asm_new_abstractmethoderror
571 bcl 20,31,L00$_exceptions_asm_new_abstractmethoderror
572 L00$_exceptions_asm_new_abstractmethoderror:
574 addis r11,r11,ha16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)
576 lwzu r12,lo16(L_exceptions_asm_new_abstractmethoderror$lazy_ptr - L00$_exceptions_asm_new_abstractmethoderror)(r11)
581 L_exceptions_asm_new_abstractmethoderror$lazy_ptr:
582 .indirect_symbol _exceptions_asm_new_abstractmethoderror
583 .long dyld_stub_binding_helper
585 #endif /* defined(__DARWIN__) */
588 /* disable exec-stacks ********************************************************/
590 #if defined(__linux__) && defined(__ELF__)
591 .section .note.GNU-stack,"",%progbits
596 * These are local overrides for various environment variables in Emacs.
597 * Please do not remove this and leave it at the end of the file, where
598 * Emacs will automagically detect them.
599 * ---------------------------------------------------------------------
602 * indent-tabs-mode: t
606 * vim:noexpandtab:sw=4:ts=4: