1 /* src/vm/jit/x86_64/asmpart.S - Java-C interface functions for x86_64
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; 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
30 #include "vm/jit/x86_64/arch.h"
31 #include "vm/jit/x86_64/md-abi.h"
32 #include "vm/jit/x86_64/md-asm.h"
34 #include "vm/jit/abi-asm.h"
35 #include "vm/jit/methodheader.h"
41 /* export functions ***********************************************************/
43 .globl asm_vm_call_method
44 .globl asm_vm_call_method_int
45 .globl asm_vm_call_method_long
46 .globl asm_vm_call_method_float
47 .globl asm_vm_call_method_double
48 .globl asm_vm_call_method_exception_handler
49 .globl asm_vm_call_method_end
51 .globl asm_handle_exception
52 .globl asm_handle_nat_exception
54 .globl asm_abstractmethoderror
56 .globl asm_builtin_f2i
57 .globl asm_builtin_f2l
58 .globl asm_builtin_d2i
59 .globl asm_builtin_d2l
61 .globl asm_compare_and_swap
62 .globl asm_memory_barrier
65 /********************* function asm_calljavafunction ***************************
67 * This function calls a Java-method (which possibly needs compilation) *
68 * with up to 4 address parameters. *
70 * This functions calls the JIT-compiler which eventually translates the *
71 * method into machine code. *
74 * javaobject_header *asm_calljavamethod (methodinfo *m, *
75 * void *arg1, void *arg2, void *arg3, void *arg4); *
77 *******************************************************************************/
81 .quad 0 /* catch type all */
82 .quad 0 /* handler pc */
84 .quad 0 /* start pc */
85 .long 1 /* extable size */
86 .long 0 /* ALIGNMENT PADDING */
87 .quad 0 /* line number table start */
88 .quad 0 /* line number table size */
92 .long 0 /* frame size */
93 .quad 0 /* codeinfo pointer */
96 asm_vm_call_method_int:
97 asm_vm_call_method_long:
98 asm_vm_call_method_float:
99 asm_vm_call_method_double:
100 sub $(7*8),sp /* keep stack 16-byte aligned */
101 mov %rbx,0*8(sp) /* %rbx is not a callee saved in cacao*/
108 mov a0,6*8(sp) /* store method PV */
110 mov sp,s0 /* save stack pointer */
112 mov a1,t0 /* address of data structure */
113 mov a2,itmp1 /* number of stack arguments */
132 je L_asm_vm_call_method_stack_copy_done
135 add $1,itmp2 /* keep stack 16-byte aligned */
136 and $0xfffffffffffffffe,itmp2
137 shl $3,itmp2 /* calculate stack size */
138 sub itmp2,sp /* create stack frame */
139 mov sp,itmp2 /* temporary stack pointer */
141 L_asm_vm_call_method_stack_copy_loop:
142 mov 14*8(t0),itmp3 /* load argument */
143 mov itmp3,0(itmp2) /* store argument on stack */
145 sub $1,itmp1l /* subtract 1 argument */
146 add $8,t0 /* set address of next argument */
147 add $8,itmp2 /* increase SP */
150 jg L_asm_vm_call_method_stack_copy_loop
152 L_asm_vm_call_method_stack_copy_done:
153 lea (6*8-256)(s0),mptr /* We subtract 256 to force the next */
154 /* move instruction to have a 32-bit */
157 mov (0*8+256)(mptr),itmp3 /* load PV */
160 mov s0,sp /* restore SP */
162 L_asm_vm_call_method_return:
163 mov 0*8(sp),%rbx /* restore callee saved registers */
169 add $(7*8),sp /* free stack space */
172 asm_vm_call_method_exception_handler:
173 mov xptr,a0 /* pass exception pointer */
174 call builtin_throw_exception@PLT
175 jmp L_asm_vm_call_method_return
177 asm_vm_call_method_end:
181 /* asm_handle_exception ********************************************************
183 * This function handles an exception. It does not use the usual calling *
184 * conventions. The exception pointer is passed in REG_ITMP1 and the *
185 * pc from the exception raising position is passed in REG_ITMP2. It searches *
186 * the local exception table for a handler. If no one is found, it unwinds *
187 * stacks and continues searching the callers. *
189 *******************************************************************************/
191 asm_handle_nat_exception:
192 add $8,sp /* clear return address of native stub*/
194 asm_handle_exception:
195 L_asm_handle_exception: /* required for PIC code */
196 sub $((ARG_CNT+TMP_CNT)*8),sp /* create maybe-leaf stackframe */
198 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
199 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
201 mov $((ARG_CNT+TMP_CNT)*8),a3 /* prepare a3 for handle_exception */
202 mov $1,t0 /* set maybe-leaf flag */
204 L_asm_handle_exception_stack_loop:
206 mov xptr,0*8(sp) /* save exception pointer */
207 mov xpc,1*8(sp) /* save exception pc */
208 add sp,a3 /* calculate Java sp into a3... */
210 mov a3,3*8(sp) /* ...and save it */
211 mov t0,4*8(sp) /* save maybe-leaf flag */
213 mov xpc,a0 /* exception pc */
214 call codegen_get_pv_from_pc@PLT
215 mov v0,2*8(sp) /* save data segment pointer */
217 mov 0*8(sp),a0 /* pass exception pointer */
218 mov 1*8(sp),a1 /* pass exception pc */
219 mov v0,a2 /* pass data segment pointer */
220 mov 3*8(sp),a3 /* pass Java stack pointer */
221 call exceptions_handle_exception@PLT
224 jz L_asm_handle_exception_not_catched
226 mov v0,xpc /* move handlerpc into xpc */
227 mov 0*8(sp),xptr /* restore exception pointer */
228 mov 4*8(sp),t0 /* get maybe-leaf flag */
229 add $(6*8),sp /* free stack frame */
231 test t0,t0 /* test for maybe-leaf flag */
232 jz L_asm_handle_exception_no_leaf
234 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
235 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
237 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
239 L_asm_handle_exception_no_leaf:
240 jmp *xpc /* jump to the handler */
242 L_asm_handle_exception_not_catched:
243 mov 0*8(sp),xptr /* restore exception pointer */
244 mov 2*8(sp),itmp3 /* restore data segment pointer */
245 mov 4*8(sp),t0 /* get maybe-leaf flag */
249 jz L_asm_handle_exception_no_leaf_stack
251 add $((ARG_CNT+TMP_CNT)*8),sp /* remove maybe-leaf stackframe */
252 xor t0,t0 /* clear the isleaf flags */
254 L_asm_handle_exception_no_leaf_stack:
255 mov FrameSize(itmp3),itmp2l /* get frame size */
256 add sp,itmp2 /* pointer to save area */
258 mov IntSave(itmp3),a0l /* a0l = saved int register count */
281 shl $3,a0l /* multiply by 8 bytes */
286 mov FltSave(itmp3),a0l /* a0l = saved flt register count */
299 movq -5*8(itmp2),%xmm11
301 movq -4*8(itmp2),%xmm12
303 movq -3*8(itmp2),%xmm13
305 movq -2*8(itmp2),%xmm14
307 movq -1*8(itmp2),%xmm15
311 mov FrameSize(itmp3),itmp2l /* get frame size */
312 add itmp2,sp /* unwind stack */
314 /* exception pointer is still set */
315 pop xpc /* the new xpc is return address */
316 sub $3,xpc /* subtract 3 bytes for call */
318 xor a3,a3 /* prepare a3 for handle_exception */
320 jmp L_asm_handle_exception_stack_loop
323 /* asm_abstractmethoderror *****************************************************
325 Creates and throws an AbstractMethodError.
327 *******************************************************************************/
329 asm_abstractmethoderror:
330 mov sp,a0 /* pass java sp */
332 mov 0*8(sp),a1 /* pass exception address */
334 call exceptions_asm_new_abstractmethoderror@PLT
335 /* exception pointer is return value */
336 pop xpc /* get exception address */
337 sub $3,xpc /* exception address is ra - 3 */
338 jmp L_asm_handle_exception
341 /* asm_builtin_x2x *************************************************************
343 * Wrapper functions for float to int corner cases *
345 *******************************************************************************/
350 SAVE_ARGUMENT_REGISTERS(0)
355 RESTORE_ARGUMENT_REGISTERS(0)
364 SAVE_ARGUMENT_REGISTERS(0)
369 RESTORE_ARGUMENT_REGISTERS(0)
378 SAVE_ARGUMENT_REGISTERS(0)
383 RESTORE_ARGUMENT_REGISTERS(0)
392 SAVE_ARGUMENT_REGISTERS(0)
397 RESTORE_ARGUMENT_REGISTERS(0)
403 /* asm_compare_and_swap ********************************************************
405 Does an atomic compare and swap. Required for the lock
408 *******************************************************************************/
410 asm_compare_and_swap:
411 mov a1,v0 /* v0 is %rax */
416 /* asm_memory_barrier **********************************************************
418 A memory barrier for the Java Memory Model.
420 *******************************************************************************/
427 /* disable exec-stacks ********************************************************/
429 #if defined(__linux__) && defined(__ELF__)
430 .section .note.GNU-stack,"",%progbits
435 * These are local overrides for various environment variables in Emacs.
436 * Please do not remove this and leave it at the end of the file, where
437 * Emacs will automagically detect them.
438 * ---------------------------------------------------------------------
441 * indent-tabs-mode: t
445 * vim:noexpandtab:sw=4:ts=4: