1 /* src/vm/jit/powerpc64/asmpart.S - Java-C interface functions for PowerPC64
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
35 #include "vm/jit/abi-asm.h"
36 #include "vm/jit/methodheader.h"
39 /* export functions ***********************************************************/
41 .globl asm_vm_call_method_exception_handler
42 .globl asm_vm_call_method_end
44 .globl asm_handle_nat_exception
45 .globl asm_handle_exception
47 .globl asm_abstractmethoderror
52 /* asm_vm_call_method **********************************************************
54 * This function calls a Java-method (which possibly needs compilation) *
55 * with up to 4 address parameters. *
57 * This functions calls the JIT-compiler which eventually translates the *
58 * method into machine code. *
61 * javaobject_header *asm_calljavamethod (methodinfo *m, *
62 * void *arg1, void *arg2, void *arg3, void *arg4); *
64 *******************************************************************************/
65 /* this is the method header see src/vm/jit/methodheader.h */
69 .quad 0 /* catch type all */
70 .quad 0 /* handler pc */
72 .quad 0 /* start pc */
73 .long 1 /* extable size */
74 .long 0 /* ALIGNMENT PADDING */
75 .quad 0 /* line number table start */
76 .quad 0 /* line number table size */
80 .long 0 /* frame size */
81 .quad 0 /* codeinfo pointer */
85 .globl asm_vm_call_method
86 .globl asm_vm_call_method_int
87 .globl asm_vm_call_method_long
88 .globl asm_vm_call_method_float
89 .globl asm_vm_call_method_double
94 asm_vm_call_method_int:
95 asm_vm_call_method_long:
96 asm_vm_call_method_float:
97 asm_vm_call_method_double:
98 .quad .asm_vm_call_method,.TOC.@tocbase,0
100 .size asm_vm_call_method, 24
101 .type .asm_vm_call_method,@function
102 .globl .asm_vm_call_method
105 .globl asm_vm_call_method
106 asm_vm_call_method_int:
107 .globl asm_vm_call_method_int
108 asm_vm_call_method_long:
109 .globl asm_vm_call_method_long
110 asm_vm_call_method_float:
111 .globl asm_vm_call_method_float
112 asm_vm_call_method_double:
113 .globl asm_vm_call_method_double
117 .asm_vm_call_method_int:
118 .asm_vm_call_method_long:
119 .asm_vm_call_method_float:
120 .asm_vm_call_method_double:
122 std r0,LA_LR_OFFSET(sp)
125 std s0,8*8(sp) /* save used callee saved registers */
126 std a0,9*8(sp) /* save method pointer for compiler */
128 std pv,11*8(sp) /* save PV register */
130 std itmp3,12*8(sp) /* registers r14-r31 are callee saved */
131 stfd ftmp1,13*8(sp) /* registers f14-f31 are callee saved */
135 SAVE_TEMPORARY_REGISTERS(15)
136 mr s0, r1 /* save stack pointer */
138 /* a1 contains a pointer to a unit64_t structure filled with all INT_ARG_REG,
139 followed by ADR_ARG_CNT and FLT_ARG_CNT, afterwards what else needs to be copied onto
141 a2 contains the number of additional stack slots to be copied
172 beq L_stack_copy_done
175 addi t1,t1,20*8 /* before first possible stack slot arg */
176 mr t3,t2 /* argument counter */
177 sldi t2,t2,8 /* calculate size of stack */
178 sub sp,sp,t2 /* increase the stack */
179 mr t2,sp /* t2 points to bottom of stack now */
182 addi t1,t1,8 /* next possible stack slot to copy */
183 mr. t3,t3 /* more stack slots to copy ? */
184 beq L_stack_copy_done
192 mr itmp1, s0 /* fake invokevirtual invocation */
193 addi itmp1, itmp1, 9*8 /* address of methods pv */
199 addi pv,itmp1,(.asm_vm_call_method - 1b)@l
201 L_asm_vm_call_method_return:
202 mr sp,s0 /* restore the function's sp */
204 ld s0,8*8(sp) /* restore used callee saved registers */
206 ld pv,11*8(sp) /* save PV register */
209 lfd ftmp1,13*8(sp) /* registers f14-f31 are callee saved */
212 RESTORE_TEMPORARY_REGISTERS(15)
214 ld r0,40*8+LA_LR_OFFSET(r1)
219 asm_vm_call_method_exception_handler:
221 bl builtin_throw_exception
222 b L_asm_vm_call_method_return
224 asm_vm_call_method_end:
228 /********************* function asm_handle_exception ***************************
230 * This function handles an exception. It does not use the usual calling *
231 * conventions. The exception pointer is passed in REG_ITMP1 and the *
232 * pc from the exception raising position is passed in REG_ITMP2. It searches *
233 * the local exception table for a handler. If no one is found, it unwinds *
234 * stacks and continues searching the callers. *
236 * void asm_handle_exception (exceptionptr, exceptionpc); *
238 *******************************************************************************/
240 asm_handle_nat_exception:
241 L_asm_handle_nat_exception: /* required for PIC code */
242 L_asm_handle_exception_stack_loop:
244 addi sp,sp,-(LA_SIZE+PA_SIZE+((4+6)*8)) /* allocate stack (+4 for darwin) */
245 std xptr,LA_SIZE+PA_SIZE+(4+0)*8(sp) /* save exception pointer */
246 std xpc,LA_SIZE+PA_SIZE+(4+1)*8(sp) /* save exception pc */
247 std r0,LA_SIZE+PA_SIZE+(4+3)*8(sp) /* save return address */
249 std itmp3,LA_SIZE+PA_SIZE+(4+4)*8(sp) /* save maybe-leaf flag (cleared) */
251 mr a0,r0 /* pass return address */
252 bl md_codegen_get_pv_from_pc /* get PV from RA */
253 std v0,LA_SIZE+PA_SIZE+(4+2)*8(sp) /* save data segment pointer */
255 ld a0,LA_SIZE+PA_SIZE+(4+0)*8(sp) /* pass xptr */
256 ld a1,LA_SIZE+PA_SIZE+(4+1)*8(sp) /* pass xpc */
257 ld a2,LA_SIZE+PA_SIZE+(4+2)*8(sp) /* pass PV (v0 == a0) */
258 addi a3,sp,LA_SIZE+PA_SIZE+((4+6)*8) /* pass Java SP */
260 b L_asm_handle_exception_continue
263 asm_handle_exception:
264 L_asm_handle_exception: /* required for PIC code */
265 addi sp,sp,-(ARG_CNT+TMP_CNT)*8 /* create maybe-leaf stackframe */
267 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
268 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
270 addi sp,sp,-(LA_SIZE+PA_SIZE+(4+6)*8) /* allocate stack */
271 std xptr,LA_SIZE+PA_SIZE+(4+0)*8(sp) /* save exception pointer */
272 std pv,LA_SIZE+PA_SIZE+(4+2)*8(sp) /* save data segment pointer */
273 mflr r0 /* save return address */
274 std r0,LA_SIZE+PA_SIZE+(4+3)*8(sp)
276 std t0, LA_SIZE+PA_SIZE+(4+4)*8(sp) /* maybe-leaf flag */
278 mr a0,xptr /* pass exception pointer */
279 mr a1,xpc /* pass exception pc */
280 mr a2,pv /* pass data segment pointer */
281 addi a3,sp,LA_SIZE+PA_SIZE+(ARG_CNT+TMP_CNT)*8+(4+6)*8
284 L_asm_handle_exception_continue:
285 bl exceptions_handle_exception
288 beq L_asm_handle_exception_not_catched
290 mr xpc,v0 /* move handlerpc into xpc */
291 ld xptr,LA_SIZE+PA_SIZE+(4+0)*8(sp) /* restore exception pointer */
292 ld pv,LA_SIZE+PA_SIZE+(4+2)*8(sp) /* restore data segment pointer */
293 ld r0,LA_SIZE+PA_SIZE+(4+3)*8(sp) /* restore return address */
295 ld t0,LA_SIZE+PA_SIZE+(4+4)*8(sp) /* get maybe-leaf flag */
296 addi sp,sp,LA_SIZE+PA_SIZE+(4+6)*8 /* free stack frame */
299 beq L_asm_handle_exception_no_leaf
301 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
302 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
304 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
306 L_asm_handle_exception_no_leaf:
307 mtctr xpc /* jump to the handler */
310 L_asm_handle_exception_not_catched:
311 ld xptr,LA_SIZE+PA_SIZE+(4+0)*8(sp) /* restore exception pointer */
312 ld pv,LA_SIZE+PA_SIZE+(4+2)*8(sp) /* restore data segment pointer */
313 ld r0,LA_SIZE+PA_SIZE+(4+3)*8(sp) /* restore return address */
315 ld t0,LA_SIZE+PA_SIZE+(4+4)*8(sp) /* get maybe-leaf flag */
316 addi sp,sp,LA_SIZE+PA_SIZE+(4+6)*8 /* free stack frame */
319 beq L_asm_handle_exception_no_leaf_stack
321 addi sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
322 li t0,0 /* clear the maybe-leaf flag */
324 L_asm_handle_exception_no_leaf_stack:
325 lwz t1,FrameSize(pv) /* get frame size */
326 add t1,sp,t1 /* pointer to save area */
328 lwz t2,IsLeaf(pv) /* is leaf procedure */
330 bne L_asm_handle_exception_no_ra_restore
332 ld r0,LA_LR_OFFSET(t1) /* restore ra */
335 L_asm_handle_exception_no_ra_restore:
336 mflr xpc /* the new xpc is ra */
337 mr t4,xpc /* save RA */
338 lwz t2,IntSave(pv) /* t1 = saved int register count */
341 mflr t3 /* t3 = current pc */
342 addi t3,t3,(ex_int2-ex_int1)@l
343 slwi t2,t2,2 /* t2 = register count * 4 */
344 subf t3,t2,t3 /* t3 = IntSave - t2 */
359 subf t1,t2,t1 /* t1 = t1 - register count * 4 */
364 addi t3,t3,(ex_flt2-ex_flt1)@l
365 slwi t2,t2,2 /* t2 = register count * 4 */
366 subf t3,t2,t3 /* t3 = FltSave - t2 */
382 mtlr t4 /* restore RA */
384 add sp,sp,t1 /* unwind stack */
385 b L_asm_handle_exception_stack_loop
388 /* asm_abstractmethoderror *****************************************************
390 Creates and throws an AbstractMethodError.
392 *******************************************************************************/
394 asm_abstractmethoderror:
396 std r0,LA_LR_OFFSET(sp)
397 stdu sp,-LA_SIZE_ALIGNED(sp) /* preserve linkage area */
398 addi a0,sp,LA_SIZE_ALIGNED /* pass java sp */
399 mr a1,r0 /* pass exception address */
400 bl exceptions_asm_new_abstractmethoderror
401 ld r0,LA_SIZE_ALIGNED+LA_LR_OFFSET(sp)
402 mtlr r0 /* restore return address */
403 addi sp,sp,LA_SIZE_ALIGNED
405 mr xptr,v0 /* get exception pointer */
406 mr xpc,r0 /* we can't use r0 directly in addi */
407 addi xpc,xpc,-4 /* exception address is ra - 4 */
408 b L_asm_handle_nat_exception
411 /* asm_cacheflush **************************************************************
412 assumes 128 byte cache line size.
413 All registers used may be trashed for fun and profit.
414 *******************************************************************************/
419 .quad .asm_cacheflush,.TOC.@tocbase,0
421 .size asm_cacheflush, 24
422 .type .asm_cacheflush,@function
423 .globl .asm_cacheflush
425 /* construct the AND mask */
426 li r6, 0xffffffffffff8000
427 ori r6,r6,0x000000000000ff80
454 /* disable exec-stacks ********************************************************/
456 #if defined(__linux__) && defined(__ELF__)
457 .section .note.GNU-stack,"",%progbits
462 * These are local overrides for various environment variables in Emacs.
463 * Please do not remove this and leave it at the end of the file, where
464 * Emacs will automagically detect them.
465 * ---------------------------------------------------------------------
468 * indent-tabs-mode: t
472 * vim:noexpandtab:sw=4:ts=4: