1 /* src/vm/jit/x86_64/asmpart.S - Java-C interface functions for x86_64
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 #include "vm/jit/x86_64/arch.h"
29 #include "vm/jit/x86_64/md-abi.h"
30 #include "vm/jit/x86_64/md-asm.h"
32 #include "vm/jit/abi-asm.h"
33 #include "vm/jit/methodheader.h"
39 /* export functions ***********************************************************/
41 .globl asm_vm_call_method
42 .globl asm_vm_call_method_int
43 .globl asm_vm_call_method_long
44 .globl asm_vm_call_method_float
45 .globl asm_vm_call_method_double
46 .globl asm_vm_call_method_exception_handler
47 .globl asm_vm_call_method_end
49 .globl asm_handle_exception
50 .globl asm_handle_nat_exception
52 .globl asm_abstractmethoderror
54 .globl asm_builtin_f2i
55 .globl asm_builtin_f2l
56 .globl asm_builtin_d2i
57 .globl asm_builtin_d2l
60 /********************* function asm_calljavafunction ***************************
62 * This function calls a Java-method (which possibly needs compilation) *
63 * with up to 4 address parameters. *
65 * This functions calls the JIT-compiler which eventually translates the *
66 * method into machine code. *
69 * javaobject_header *asm_calljavamethod (methodinfo *m, *
70 * void *arg1, void *arg2, void *arg3, void *arg4); *
72 *******************************************************************************/
79 .long 0 /* frame size */
80 .quad 0 /* codeinfo pointer */
83 asm_vm_call_method_int:
84 asm_vm_call_method_long:
85 asm_vm_call_method_float:
86 asm_vm_call_method_double:
87 sub $(7*8),sp /* keep stack 16-byte aligned */
88 mov %rbx,0*8(sp) /* %rbx is not a callee saved in cacao*/
95 mov a0,6*8(sp) /* store method PV */
97 mov sp,s0 /* save stack pointer */
99 mov a1,t0 /* address of data structure */
100 mov a2,itmp1 /* number of stack arguments */
119 je L_asm_vm_call_method_stack_copy_done
122 add $1,itmp2 /* keep stack 16-byte aligned */
123 and $0xfffffffffffffffe,itmp2
124 shl $3,itmp2 /* calculate stack size */
125 sub itmp2,sp /* create stack frame */
126 mov sp,itmp2 /* temporary stack pointer */
128 L_asm_vm_call_method_stack_copy_loop:
129 mov 14*8(t0),itmp3 /* load argument */
130 mov itmp3,0(itmp2) /* store argument on stack */
132 sub $1,itmp1l /* subtract 1 argument */
133 add $8,t0 /* set address of next argument */
134 add $8,itmp2 /* increase SP */
137 jg L_asm_vm_call_method_stack_copy_loop
139 L_asm_vm_call_method_stack_copy_done:
140 lea (6*8-256)(s0),mptr /* We subtract 256 to force the next */
141 /* move instruction to have a 32-bit */
144 mov (0*8+256)(mptr),itmp3 /* load PV */
147 L_asm_vm_call_method_return:
148 mov s0,sp /* restore SP */
150 mov 0*8(sp),%rbx /* restore callee saved registers */
156 add $(7*8),sp /* free stack space */
159 asm_vm_call_method_exception_handler:
160 mov xptr,a0 /* pass exception pointer */
161 call builtin_throw_exception@PLT
162 jmp L_asm_vm_call_method_return
164 asm_vm_call_method_end:
168 /* asm_handle_exception ********************************************************
170 * This function handles an exception. It does not use the usual calling *
171 * conventions. The exception pointer is passed in REG_ITMP1 and the *
172 * pc from the exception raising position is passed in REG_ITMP2. It searches *
173 * the local exception table for a handler. If no one is found, it unwinds *
174 * stacks and continues searching the callers. *
176 *******************************************************************************/
178 asm_handle_nat_exception:
179 add $8,sp /* clear return address of native stub*/
181 asm_handle_exception:
182 L_asm_handle_exception: /* required for PIC code */
183 sub $((ARG_CNT+TMP_CNT)*8),sp /* create maybe-leaf stackframe */
185 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
186 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
188 mov $((ARG_CNT+TMP_CNT)*8),a3 /* prepare a3 for handle_exception */
189 mov $1,t0 /* set maybe-leaf flag */
191 L_asm_handle_exception_stack_loop:
193 mov xptr,0*8(sp) /* save exception pointer */
194 mov xpc,1*8(sp) /* save exception pc */
195 add sp,a3 /* calculate Java sp into a3... */
197 mov a3,3*8(sp) /* ...and save it */
198 mov t0,4*8(sp) /* save maybe-leaf flag */
200 mov xpc,a0 /* exception pc */
201 call methodtree_find@PLT
202 mov v0,2*8(sp) /* save data segment pointer */
204 mov 0*8(sp),a0 /* pass exception pointer */
205 mov 1*8(sp),a1 /* pass exception pc */
206 mov v0,a2 /* pass data segment pointer */
207 mov 3*8(sp),a3 /* pass Java stack pointer */
208 call exceptions_handle_exception@PLT
211 jz L_asm_handle_exception_not_catched
213 mov v0,xpc /* move handlerpc into xpc */
214 mov 0*8(sp),xptr /* restore exception pointer */
215 mov 4*8(sp),t0 /* get maybe-leaf flag */
216 add $(6*8),sp /* free stack frame */
218 test t0,t0 /* test for maybe-leaf flag */
219 jz L_asm_handle_exception_no_leaf
221 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
222 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
224 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
226 L_asm_handle_exception_no_leaf:
227 jmp *xpc /* jump to the handler */
229 L_asm_handle_exception_not_catched:
230 mov 0*8(sp),xptr /* restore exception pointer */
231 mov 2*8(sp),itmp3 /* restore data segment pointer */
232 mov 4*8(sp),t0 /* get maybe-leaf flag */
236 jz L_asm_handle_exception_no_leaf_stack
238 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
239 xor t0,t0 /* clear the isleaf flags */
241 L_asm_handle_exception_no_leaf_stack:
242 mov FrameSize(itmp3),itmp2l /* get frame size */
243 add sp,itmp2 /* pointer to save area */
245 mov IntSave(itmp3),a0l /* a0l = saved int register count */
268 shl $3,a0l /* multiply by 8 bytes */
273 mov FltSave(itmp3),a0l /* a0l = saved flt register count */
286 movq -5*8(itmp2),%xmm11
288 movq -4*8(itmp2),%xmm12
290 movq -3*8(itmp2),%xmm13
292 movq -2*8(itmp2),%xmm14
294 movq -1*8(itmp2),%xmm15
298 mov FrameSize(itmp3),itmp2l /* get frame size */
299 add itmp2,sp /* unwind stack */
301 /* exception pointer is still set */
302 pop xpc /* the new xpc is return address */
303 sub $3,xpc /* subtract 3 bytes for call */
305 xor a3,a3 /* prepare a3 for handle_exception */
307 jmp L_asm_handle_exception_stack_loop
310 /* asm_abstractmethoderror *****************************************************
312 Creates and throws an AbstractMethodError.
314 *******************************************************************************/
316 asm_abstractmethoderror:
317 mov sp,a0 /* pass java sp */
319 mov 0*8(sp),a1 /* pass exception address */
321 call exceptions_asm_new_abstractmethoderror@PLT
322 /* exception pointer is return value */
323 pop xpc /* get exception address */
324 sub $3,xpc /* exception address is ra - 3 */
325 jmp L_asm_handle_exception
328 /* asm_builtin_x2x *************************************************************
330 * Wrapper functions for float to int corner cases *
332 *******************************************************************************/
337 SAVE_ARGUMENT_REGISTERS(0)
342 RESTORE_ARGUMENT_REGISTERS(0)
351 SAVE_ARGUMENT_REGISTERS(0)
356 RESTORE_ARGUMENT_REGISTERS(0)
365 SAVE_ARGUMENT_REGISTERS(0)
370 RESTORE_ARGUMENT_REGISTERS(0)
379 SAVE_ARGUMENT_REGISTERS(0)
384 RESTORE_ARGUMENT_REGISTERS(0)
390 /* disable exec-stacks ********************************************************/
392 #if defined(__linux__) && defined(__ELF__)
393 .section .note.GNU-stack,"",%progbits
398 * These are local overrides for various environment variables in Emacs.
399 * Please do not remove this and leave it at the end of the file, where
400 * Emacs will automagically detect them.
401 * ---------------------------------------------------------------------
404 * indent-tabs-mode: t
408 * vim:noexpandtab:sw=4:ts=4: