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
59 .globl asm_get_cycle_count
62 /********************* function asm_calljavafunction ***************************
64 * This function calls a Java-method (which possibly needs compilation) *
65 * with up to 4 address parameters. *
67 * This functions calls the JIT-compiler which eventually translates the *
68 * method into machine code. *
71 * javaobject_header *asm_calljavamethod (methodinfo *m, *
72 * void *arg1, void *arg2, void *arg3, void *arg4); *
74 *******************************************************************************/
81 .long 0 /* frame size */
82 .quad 0 /* codeinfo pointer */
85 asm_vm_call_method_int:
86 asm_vm_call_method_long:
87 asm_vm_call_method_float:
88 asm_vm_call_method_double:
89 sub $(7*8),sp /* keep stack 16-byte aligned */
90 mov %rbx,0*8(sp) /* %rbx is not a callee saved in cacao*/
97 mov a0,6*8(sp) /* store method PV */
99 mov sp,s0 /* save stack pointer */
101 mov a1,t0 /* address of data structure */
102 mov a2,itmp1 /* number of stack arguments */
121 je L_asm_vm_call_method_stack_copy_done
124 add $1,itmp2 /* keep stack 16-byte aligned */
125 and $0xfffffffffffffffe,itmp2
126 shl $3,itmp2 /* calculate stack size */
127 sub itmp2,sp /* create stack frame */
128 mov sp,itmp2 /* temporary stack pointer */
130 L_asm_vm_call_method_stack_copy_loop:
131 mov 14*8(t0),itmp3 /* load argument */
132 mov itmp3,0(itmp2) /* store argument on stack */
134 sub $1,itmp1l /* subtract 1 argument */
135 add $8,t0 /* set address of next argument */
136 add $8,itmp2 /* increase SP */
139 jg L_asm_vm_call_method_stack_copy_loop
141 L_asm_vm_call_method_stack_copy_done:
142 lea (6*8-256)(s0),mptr /* We subtract 256 to force the next */
143 /* move instruction to have a 32-bit */
146 mov (0*8+256)(mptr),itmp3 /* load PV */
149 L_asm_vm_call_method_return:
150 mov s0,sp /* restore SP */
152 mov 0*8(sp),%rbx /* restore callee saved registers */
158 add $(7*8),sp /* free stack space */
161 asm_vm_call_method_exception_handler:
162 mov xptr,a0 /* pass exception pointer */
163 call builtin_throw_exception@PLT
164 jmp L_asm_vm_call_method_return
166 asm_vm_call_method_end:
170 /* asm_handle_exception ********************************************************
172 * This function handles an exception. It does not use the usual calling *
173 * conventions. The exception pointer is passed in REG_ITMP1 and the *
174 * pc from the exception raising position is passed in REG_ITMP2. It searches *
175 * the local exception table for a handler. If no one is found, it unwinds *
176 * stacks and continues searching the callers. *
178 *******************************************************************************/
180 asm_handle_nat_exception:
181 add $8,sp /* clear return address of native stub*/
183 asm_handle_exception:
184 L_asm_handle_exception: /* required for PIC code */
185 sub $((ARG_CNT+TMP_CNT)*8),sp /* create maybe-leaf stackframe */
187 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
188 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
190 mov $((ARG_CNT+TMP_CNT)*8),a3 /* prepare a3 for handle_exception */
191 mov $1,t0 /* set maybe-leaf flag */
193 L_asm_handle_exception_stack_loop:
195 mov xptr,0*8(sp) /* save exception pointer */
196 mov xpc,1*8(sp) /* save exception pc */
197 add sp,a3 /* calculate Java sp into a3... */
199 mov a3,3*8(sp) /* ...and save it */
200 mov t0,4*8(sp) /* save maybe-leaf flag */
202 mov xpc,a0 /* exception pc */
203 call methodtree_find@PLT
204 mov v0,2*8(sp) /* save data segment pointer */
206 mov 0*8(sp),a0 /* pass exception pointer */
207 mov 1*8(sp),a1 /* pass exception pc */
208 mov v0,a2 /* pass data segment pointer */
209 mov 3*8(sp),a3 /* pass Java stack pointer */
210 call exceptions_handle_exception@PLT
213 jz L_asm_handle_exception_not_catched
215 mov v0,xpc /* move handlerpc into xpc */
216 mov 0*8(sp),xptr /* restore exception pointer */
217 mov 4*8(sp),t0 /* get maybe-leaf flag */
218 add $(6*8),sp /* free stack frame */
220 test t0,t0 /* test for maybe-leaf flag */
221 jz L_asm_handle_exception_no_leaf
223 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
224 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
226 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
228 L_asm_handle_exception_no_leaf:
229 jmp *xpc /* jump to the handler */
231 L_asm_handle_exception_not_catched:
232 mov 0*8(sp),xptr /* restore exception pointer */
233 mov 2*8(sp),itmp3 /* restore data segment pointer */
234 mov 4*8(sp),t0 /* get maybe-leaf flag */
238 jz L_asm_handle_exception_no_leaf_stack
240 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
241 xor t0,t0 /* clear the isleaf flags */
243 L_asm_handle_exception_no_leaf_stack:
244 mov FrameSize(itmp3),itmp2l /* get frame size */
245 add sp,itmp2 /* pointer to save area */
247 mov IntSave(itmp3),a0l /* a0l = saved int register count */
270 shl $3,a0l /* multiply by 8 bytes */
275 mov FltSave(itmp3),a0l /* a0l = saved flt register count */
288 movq -5*8(itmp2),%xmm11
290 movq -4*8(itmp2),%xmm12
292 movq -3*8(itmp2),%xmm13
294 movq -2*8(itmp2),%xmm14
296 movq -1*8(itmp2),%xmm15
300 mov FrameSize(itmp3),itmp2l /* get frame size */
301 add itmp2,sp /* unwind stack */
303 /* exception pointer is still set */
304 pop xpc /* the new xpc is return address */
305 sub $3,xpc /* subtract 3 bytes for call */
307 xor a3,a3 /* prepare a3 for handle_exception */
309 jmp L_asm_handle_exception_stack_loop
312 /* asm_abstractmethoderror *****************************************************
314 Creates and throws an AbstractMethodError.
316 *******************************************************************************/
318 asm_abstractmethoderror:
319 mov sp,a0 /* pass java sp */
321 mov 0*8(sp),a1 /* pass exception address */
323 call exceptions_asm_new_abstractmethoderror@PLT
324 /* exception pointer is return value */
325 pop xpc /* get exception address */
326 sub $3,xpc /* exception address is ra - 3 */
327 jmp L_asm_handle_exception
330 /* asm_builtin_x2x *************************************************************
332 * Wrapper functions for float to int corner cases *
334 *******************************************************************************/
339 SAVE_ARGUMENT_REGISTERS(0)
344 RESTORE_ARGUMENT_REGISTERS(0)
353 SAVE_ARGUMENT_REGISTERS(0)
358 RESTORE_ARGUMENT_REGISTERS(0)
367 SAVE_ARGUMENT_REGISTERS(0)
372 RESTORE_ARGUMENT_REGISTERS(0)
381 SAVE_ARGUMENT_REGISTERS(0)
386 RESTORE_ARGUMENT_REGISTERS(0)
392 /* asm_get_cycle_count *********************************************************
394 Get the current time-stamp counter from the CPU.
396 *******************************************************************************/
406 /* disable exec-stacks ********************************************************/
408 #if defined(__linux__) && defined(__ELF__)
409 .section .note.GNU-stack,"",%progbits
414 * These are local overrides for various environment variables in Emacs.
415 * Please do not remove this and leave it at the end of the file, where
416 * Emacs will automagically detect them.
417 * ---------------------------------------------------------------------
420 * indent-tabs-mode: t
424 * vim:noexpandtab:sw=4:ts=4: