1 /* src/vm/jit/x86_64/asmpart.S - Java-C interface functions for x86_64
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
31 $Id: asmpart.S 2733 2005-06-17 12:18:29Z twisti $
41 #include "vm/jit/x86_64/arch.h"
42 #include "vm/jit/x86_64/asmoffsets.h"
43 #include "vm/jit/x86_64/offsets.h"
49 /********************* exported functions and variables ***********************/
51 .globl asm_calljavafunction
52 .globl asm_calljavafunction_int
54 .globl asm_calljavafunction2
55 .globl asm_calljavafunction2int
56 .globl asm_calljavafunction2long
57 .globl asm_calljavafunction2float
58 .globl asm_calljavafunction2double
60 .globl asm_call_jit_compiler
61 .globl asm_handle_exception
62 .globl asm_handle_nat_exception
64 .globl asm_wrapper_patcher
66 .globl asm_builtin_arraycheckcast
67 .globl asm_builtin_aastore
69 .globl asm_builtin_f2i
70 .globl asm_builtin_f2l
71 .globl asm_builtin_d2i
72 .globl asm_builtin_d2l
74 .globl asm_perform_threadswitch
75 .globl asm_initialize_thread_stack
76 .globl asm_switchstackandcall
77 .globl asm_criticalsections
78 .globl asm_getclassvalues_atomic
80 .globl asm_prepare_native_stackinfo
81 .globl asm_remove_native_stackinfo
82 .globl asm_throw_and_handle_exception
83 .globl asm_throw_and_handle_hardware_arithmetic_exception
86 /********************* function asm_calljavafunction ***************************
88 * This function calls a Java-method (which possibly needs compilation) *
89 * with up to 4 address parameters. *
91 * This functions calls the JIT-compiler which eventually translates the *
92 * method into machine code. *
95 * javaobject_header *asm_calljavamethod (methodinfo *m, *
96 * void *arg1, void *arg2, void *arg3, void *arg4); *
98 *******************************************************************************/
103 .quad 0 /* catch type all */
104 .quad calljava_xhandler /* handler pc */
105 .quad calljava_xhandler /* end pc */
106 .quad asm_calljavafunction /* start pc */
107 .long 1 /* extable size */
109 .quad 0 /* line number table start */
110 .quad 0 /* line number table size */
112 .long 0 /* fltsave */
113 .long 0 /* intsave */
116 .long 8 /* frame size */
117 .quad 0 /* method pointer (pointer to name) */
119 asm_calljavafunction:
120 asm_calljavafunction_int:
121 sub $(3*8),%rsp /* keep stack 16-byte aligned */
123 mov %rbx,1*8(%rsp) /* %rbx is not a callee saved in cacao */
124 mov %rdi,%rax /* move function pointer to %rax */
125 /* compilerstub uses this */
127 mov %rsi,%rdi /* pass remaining parameters */
132 lea asm_call_jit_compiler,%r11
133 call *%r11 /* call JIT compiler */
137 add $(3*8),%rsp /* free stack space */
141 mov %rax,%rdi /* pass exception pointer */
142 call builtin_throw_exception
146 xor %rax,%rax /* return NULL */
150 /********************* function asm_calljavafunction ***************************
152 * This function calls a Java-method (which possibly needs compilation) *
153 * with up to 4 address parameters. *
155 * This functions calls the JIT-compiler which eventually translates the *
156 * method into machine code. *
159 * javaobject_header *asm_calljavamethod (methodinfo *m, *
160 * void *arg1, void *arg2, void *arg3, void *arg4); *
162 *******************************************************************************/
167 .quad 0 /* catch type all */
168 .quad calljava_xhandler2 /* handler pc */
169 .quad calljava_xhandler2 /* end pc */
170 .quad asm_calljavafunction2 /* start pc */
171 .long 1 /* extable size */
173 .quad 0 /* line number table start */
174 .quad 0 /* line number table size */
176 .long 0 /* fltsave */
177 .long 0 /* intsave */
180 .long 24 /* frame size */
181 .quad 0 /* method pointer (pointer to name) */
183 asm_calljavafunction2:
184 asm_calljavafunction2int:
185 asm_calljavafunction2long:
186 asm_calljavafunction2float:
187 asm_calljavafunction2double:
188 sub $(7*8),%rsp /* keep stack 16-byte aligned */
189 mov %rbx,0*8(%rsp) /* %rbx is not a callee saved in cacao */
196 mov %rdi,%rax /* move method pointer for compiler */
197 xor %rbp,%rbp /* set argument stack frame to zero */
199 test %rsi,%rsi /* maybe we have no args... */
202 mov %rsi,itmp3 /* arg count */
203 mov %rcx,itmp2 /* pointer to arg block */
205 mov itmp2,%r14 /* save argument block pointer */
206 mov itmp3,%r15 /* save argument count */
208 sub $sizejniblock,itmp2 /* initialize pointer (smaller code) */
209 add $1,itmp3 /* initialize argument count */
210 xor %r12,%r12 /* initialize integer argument counter */
211 xor %r13,%r13 /* initialize float argument counter */
214 add $sizejniblock,itmp2 /* goto next argument block */
215 dec itmp3 /* argument count - 1 */
216 jz L_register_copy_done
217 andb $0x02,offjniitemtype(itmp2) /* is this a float/double type? */
218 jnz L_register_handle_float /* yes, handle it */
220 cmp $INT_ARG_CNT,%r12 /* are we out of integer argument */
221 je L_register_copy /* register? yes, next loop */
223 lea jumptable_integer,%rbp
224 mov 0(%rbp,%r12,8),%rbx
225 inc %r12 /* integer argument counter + 1 */
228 L_register_handle_float:
229 cmp $FLT_ARG_CNT,%r13 /* are we out of float argument */
230 je L_register_copy /* register? yes, next loop */
232 lea jumptable_float,%rbp
233 mov 0(%rbp,%r13,8),%rbx
234 inc %r13 /* float argument counter + 1 */
237 L_register_copy_done:
238 mov %r15,%rbp /* calculate remaining arguments */
239 sub %r12,%rbp /* - integer arguments in registers */
240 sub %r13,%rbp /* - float arguments in registers */
241 jle L_copy_done /* are all assigned to registers? */
243 and $0xfffffffffffffffe,%rbp /* keep stack 16-byte aligned */
244 shl $3,%rbp /* calculate stack size */
245 sub %rbp,%rsp /* stack frame for arguments */
246 mov %rsp,%rbx /* use %rbx as temp sp */
248 sub $sizejniblock,%r14 /* initialize pointer (smaller code) */
249 add $1,%r15 /* initialize argument count */
252 add $sizejniblock,%r14 /* goto next argument block */
253 dec %r15 /* are there any arguments left? */
254 jz L_copy_done /* no test needed after dec */
256 andb $0x02,offjniitemtype(%r14) /* is this a float/double type? */
257 jnz L_stack_handle_float
258 dec %r12 /* arguments assigned to registers */
259 jge L_stack_copy_loop
262 L_stack_handle_float:
263 dec %r13 /* arguments assigned to registers */
264 jge L_stack_copy_loop
267 mov offjniitem(%r14),itmp3 /* copy s8 argument onto stack */
269 add $8,%rbx /* increase sp to next argument */
270 jmp L_stack_copy_loop
273 lea asm_call_jit_compiler,%r11/* %rax still contains method pointer */
274 call *%r11 /* call JIT compiler */
276 add %rbp,%rsp /* remove argument stack frame if any */
278 mov 5*8(%rsp),%r15 /* restore callee saved registers */
284 add $(7*8),%rsp /* free stack space */
288 mov %rax,%rdi /* pass exception pointer */
289 call builtin_throw_exception
291 mov 5*8(%rsp),%r15 /* restore callee saved registers */
297 add $(7*8),%rsp /* free stack space */
298 xor %rax,%rax /* return NULL */
311 mov offjniitem(itmp2),a0
314 mov offjniitem(itmp2),a1
317 mov offjniitem(itmp2),a2
320 mov offjniitem(itmp2),a3
323 mov offjniitem(itmp2),a4
326 mov offjniitem(itmp2),a5
341 movq offjniitem(itmp2),fa0
344 movq offjniitem(itmp2),fa1
347 movq offjniitem(itmp2),fa2
350 movq offjniitem(itmp2),fa3
353 movq offjniitem(itmp2),fa4
356 movq offjniitem(itmp2),fa5
359 movq offjniitem(itmp2),fa6
362 movq offjniitem(itmp2),fa7
366 /****************** function asm_call_jit_compiler *****************************
368 * invokes the compiler for untranslated JavaVM methods. *
370 * Register R0 contains a pointer to the method info structure (prepared *
371 * by createcompilerstub). Using the return address in R26 and the *
372 * offset in the LDA instruction or using the value in methodptr R28 the *
373 * patching address for storing the method address can be computed: *
375 * method address was either loaded using *
377 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
378 * i386_call_reg(REG_ITMP2) *
382 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP2) ; invokevirtual/interface *
383 * i386_mov_membase_reg(REG_ITMP2, OFFSET(, vftbl), REG_ITMP3) *
384 * i386_mov_membase_reg(REG_ITMP3, OFFSET(vftbl, table[0]) + \ *
385 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
386 * i386_call_reg(REG_ITMP1) *
388 * in the static case the method pointer can be computed using the *
389 * return address and the lda function following the jmp instruction *
391 *******************************************************************************/
393 asm_call_jit_compiler:
394 sub $8,%rsp /* keep stack 16-byte aligned */
396 mov %rbx,(%rsp) /* save register */
398 mov 8(%rsp),%r11 /* get return address */
399 mov -1(%r11),%bl /* get function code */
400 cmp $0xd2,%bl /* called with `call *REG_ITMP2' (%r10)? */
401 jne L_not_static_special
403 sub $11,%r11 /* calculate address of immediate */
404 jmp L_call_jit_compile
406 L_not_static_special:
407 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%rax) */
408 jne L_not_virtual_interface
410 sub $7,%r11 /* calculate address of offset */
411 mov (%r11),%r11d /* get offset (32-bit) */
412 add %r10,%r11 /* add base address to get method address */
413 jmp L_call_jit_compile
415 L_not_virtual_interface: /* a call from asm_calljavamethod */
419 mov (%rsp),%rbx /* restore register */
421 sub $(24*8),%rsp /* 8 + 6*8 + 8*8 + 8*8 */
423 mov %r11,0*8(%rsp) /* save address for method pointer */
425 SAVE_ARGUMENT_REGISTERS(1)
427 mov %rax,%rdi /* pass method pointer */
430 mov 0*8(%rsp),%r11 /* restore address for method pointer */
432 RESTORE_ARGUMENT_REGISTERS(1)
435 add $8,%rsp /* keep stack 16-byte aligned */
437 test %rax,%rax /* check for exception */
438 je L_asm_call_jit_compiler_exception
440 test %r11,%r11 /* is address == 0 (asm_calljavamethod) */
443 mov %rax,(%r11) /* and now save the new pointer */
446 jmp *%rax /* ...and now call the new method */
448 L_asm_call_jit_compiler_exception:
449 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
450 call builtin_asm_get_exceptionptrptr
453 lea _exceptionptr,itmp2
455 mov (itmp2),xptr /* get the exception pointer */
456 movl $0,(itmp2) /* clear the exception pointer */
458 pop xpc /* delete return address */
459 sub $5,xpc /* faulting address is ra - 5 */
461 jmp asm_handle_exception
464 /********************* function asm_handle_exception ***************************
466 * This function handles an exception. It does not use the usual calling *
467 * conventions. The exception pointer is passed in REG_ITMP1 and the *
468 * pc from the exception raising position is passed in REG_ITMP2. It searches *
469 * the local exception table for a handler. If no one is found, it unwinds *
470 * stacks and continues searching the callers. *
472 * void asm_handle_exception (exceptionptr, exceptionpc); *
474 *******************************************************************************/
476 asm_handle_nat_exception:
477 add $8,%rsp /* clear return address of native stub*/
479 asm_handle_exception:
481 mov xptr,0*8(%rsp) /* save exception pointer */
482 mov xpc,1*8(%rsp) /* save exception pc */
484 mov xpc,%rdi /* exception pc */
485 call codegen_findmethod
487 mov %rax,2*8(%rsp) /* save data segment pointer */
489 mov 0*8(%rsp),%rax /* restore exception pointer */
490 mov 1*8(%rsp),%r10 /* restore exception pc */
493 mov %rax,%rdi /* exception pointer */
494 mov MethodPointer(itmp3),%rsi /* method pointer */
495 mov xpc,%rdx /* exception pc */
497 mov $1,%r8 /* set noindent flag */
498 call builtin_trace_exception
500 mov 2*8(%rsp),itmp3 /* %r11 = data segment pointer */
501 mov ExTableSize(itmp3),%rcx /* %rcx = exception table size */
502 test %rcx,%rcx /* if empty table skip */
505 lea ExTableStart(itmp3),%rdi /* %rdi = start of exception table */
506 mov 0*8(%rsp),xptr /* get xptr */
509 mov 1*8(%rsp),xpc /* get xpc */
511 mov ExStartPC(%rdi),%rdx /* %rdx = exception start pc */
512 cmp xpc,%rdx /* %rdx = (startpc <= xpc) */
513 jg ex_table_cont /* if (false) continue */
514 mov ExEndPC(%rdi),%rdx /* %rdx = exception end pc */
515 cmp %rdx,xpc /* %rdx = (xpc < endpc) */
516 jge ex_table_cont /* if (false) continue */
517 mov ExCatchType(%rdi),%rdx /* %rdx = exception catch type */
518 test %rdx,%rdx /* NULL catches everything */
521 cmpl $0,offclassloaded(%rdx) /* check if class is loaded */
531 call load_class_bootstrap
540 cmpl $0,offclasslinked(%rdx) /* check if class is linked */
559 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
567 mov offobjvftbl(%rax),%rsi /* %rsi = vftblptr(xptr) */
568 mov offclassvftbl(%rdx),%rdx /* %rdx = vftblptr(catchtype) class (not obj) */
569 mov offbaseval(%rsi),%esi /* %esi = baseval(xptr) */
570 mov offbaseval(%rdx),%r10d /* %r10d = baseval(catchtype) */
571 mov offdiffval(%rdx),%edx /* %edx = diffval(catchtype) */
573 sub %r10d,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
575 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
579 cmp %edx,%esi /* xptr is instanceof catchtype */
583 mov ExHandlerPC(%rdi),xpc /* xpc = exception handler pc */
585 mov 0*8(%rsp),%rax /* restore exception pointer */
586 add $(4*8),%rsp /* free stack frame */
588 jmp *xpc /* jump to the handler */
591 lea ExEntrySize(%rdi),%rdi /* next exception table entry */
592 dec %rcx /* decrement entry counter */
593 test %rcx,%rcx /* if (t0 > 0) next entry */
597 mov 0*8(%rsp),%rax /* restore exception pointer */
598 mov 1*8(%rsp),%r10 /* restore exception pc */
599 mov 2*8(%rsp),%r11 /* restore data segment pointer */
602 mov %rax,%rcx /* save exception pointer */
605 movl IsSync(%r11),%eax /* %rax = SyncOffset */
606 test %rax,%rax /* if zero no monitorexit */
609 #if defined(USE_THREADS)
618 call builtin_monitorexit
627 mov FrameSize(%r11),%eax /* %eax = frame size */
628 add %rax,%rsp /* unwind stack */
629 mov %rsp,%rax /* %rax = pointer to save area */
631 mov IntSave(%r11),%edx /* %edx = saved int register count*/
658 shl $3,%edx /* multiply by 8 bytes */
662 mov FltSave(%r11),%edx /* %edx = saved flt register count*/
685 movq -48(%rax),%xmm10
687 movq -40(%rax),%xmm11
689 movq -32(%rax),%xmm12
691 movq -24(%rax),%xmm13
693 movq -16(%rax),%xmm14
698 pop %r10 /* the new xpc is return address */
699 sub $3,%r10 /* subtract 3 bytes for call */
706 call codegen_findmethod /* get the new data segment ptr */
713 mov %rcx,%rax /* restore saved exception pointer*/
717 mov %rax,0*8(%rsp) /* save exception pointer */
718 mov %r10,1*8(%rsp) /* save exception pc */
719 mov %r11,2*8(%rsp) /* save data segment pointer */
724 /* asm_wrapper_patcher *********************************************************
730 24 pointer to virtual java_objectheader
731 16 machine code (which is patched back later)
732 8 unresolved class/method/field reference
733 0 pointer to patcher function
735 *******************************************************************************/
738 sub $(17*8),%rsp /* stack frame (16-byte aligned) */
740 SAVE_ARGUMENT_REGISTERS(0)
741 SAVE_TEMPORARY_REGISTERS(14)
743 mov itmp1,15*8(%rsp) /* save itmp1 and itmp2 */
744 mov itmp2,16*8(%rsp) /* can be used by some instructions */
746 mov %rsp,a0 /* pass stack pointer */
747 add $(18*8),a0 /* skip patcher function pointer */
748 mov 17*8(%rsp),itmp3 /* get function pointer */
749 call *itmp3 /* call the patcher function */
750 mov v0,itmp3 /* save return value */
752 RESTORE_ARGUMENT_REGISTERS(0)
753 RESTORE_TEMPORARY_REGISTERS(14)
755 mov 15*8(%rsp),itmp1 /* restore itmp1 and itmp2 */
756 mov 16*8(%rsp),itmp2 /* can be used by some instructions */
758 add $((4+17)*8),%rsp /* remove stack frame, keep ra */
760 test itmp3,itmp3 /* exception thrown? */
761 jz L_asm_wrapper_patcher_exception
762 ret /* call new patched code */
764 L_asm_wrapper_patcher_exception:
765 /*stack bottom is xpc and it is directly below the last java stackframe*/
769 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
771 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
772 call builtin_asm_get_exceptionptrptr
775 lea _exceptionptr,itmp2
777 mov (itmp2),a0 /* get the exception pointer */
778 movl $0,(itmp2) /* clear exception pointer */
779 call helper_fillin_stacktrace
783 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
786 pop xpc /* get and remove return address */
787 jmp asm_handle_exception
790 /* asm_builtin_x2x *************************************************************
792 * Wrapper functions for float to int corner cases *
794 *******************************************************************************/
799 SAVE_ARGUMENT_REGISTERS(0)
804 RESTORE_ARGUMENT_REGISTERS(0)
813 SAVE_ARGUMENT_REGISTERS(0)
818 RESTORE_ARGUMENT_REGISTERS(0)
827 SAVE_ARGUMENT_REGISTERS(0)
832 RESTORE_ARGUMENT_REGISTERS(0)
841 SAVE_ARGUMENT_REGISTERS(0)
846 RESTORE_ARGUMENT_REGISTERS(0)
852 /* asm_builtin_arraycheckcast **************************************************
854 Does the cast check and eventually throws an exception.
856 *******************************************************************************/
858 asm_builtin_arraycheckcast:
859 sub $24,%rsp /* keep stack 16-byte aligned */
860 mov %rdi,(%rsp) /* save object pointer */
861 call builtin_arraycheckcast
862 test %rax,%rax /* if (false) throw exception */
864 mov (%rsp),%rax /* return object pointer */
865 add $24,%rsp /* free stack space */
869 /*call new_classcastexception*/
871 pop xpc /* delete return address */
872 sub $3,xpc /* faulting address is ra - 3 */
873 mov string_java_lang_ClassCastException,xptr
874 jmp asm_throw_and_handle_exception
877 /* asm_builtin_aastore *********************************************************
879 Checks if the object can be stored in the given array and stores the
880 address if it's possible. This function can also throw some exceptions.
882 *******************************************************************************/
885 sub $(3*8),%rsp /* allocate stack space */
886 test %rdi,%rdi /* if null pointer throw exception */
889 movl offarraysize(%rdi),%eax /* load size */
890 cmpl %eax,%esi /* do bound check */
891 jae nb_aastore_bound /* if out of bounds throw exception */
893 shl $3,%rsi /* index * 8 */
895 add %rsi,%r10 /* add index * 8 to arrayref */
897 mov %r10,(%rsp) /* save store position */
898 mov %rdx,8(%rsp) /* save object */
900 mov %rdx,%rsi /* object is second argument */
901 call builtin_canstore /* builtin_canstore(arrayref,object) */
902 test %rax,%rax /* if (false) throw exception */
905 mov (%rsp),%r10 /* restore store position */
906 mov 8(%rsp),%rdx /* restore object */
907 mov %rdx,offobjarrdata(%r10)/* store objectptr in array */
908 add $(3*8),%rsp /* free stack space */
913 pop xpc /* delete return address from stack */
914 sub $3,xpc /* faulting address is return adress - 3 */
915 mov string_java_lang_NullPointerException,xptr
916 jmp asm_throw_and_handle_exception
920 push $0 /*directly below return address*/
925 call asm_prepare_native_stackinfo
927 mov itmp1,%rdi /* move index into a0 */
928 call new_arrayindexoutofboundsexception
930 call asm_remove_native_stackinfo
932 pop xpc /* just remove one quadword */
933 pop xpc /* delete return address */
934 sub $3,xpc /* faulting address is return adress - 3 */
935 jmp asm_handle_exception
938 /*call new_arraystoreexception*/
940 pop xpc /* delete return address */
941 sub $3,xpc /* faulting address is return adress - 3 */
942 mov string_java_lang_ArrayStoreException,xptr
943 jmp asm_throw_and_handle_exception
946 /******************* function asm_initialize_thread_stack **********************
948 * initialized a thread stack *
949 * (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), (to)->stackEnd)*
951 *******************************************************************************/
953 asm_initialize_thread_stack:
964 mov %rdi,6*8(%rsi) /* save (u1*) (func) */
965 mov %rsi,%rax /* return restorepoint in %rax */
969 /******************* function asm_perform_threadswitch *************************
971 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
973 * performs a threadswitch *
975 *******************************************************************************/
977 asm_perform_threadswitch:
978 sub $(7*8),%rsp /* allocate stack frame */
987 mov 7*8(%rsp),%rax /* save current return address */
990 mov %rsp,(%rdi) /* first argument **from */
991 mov %rsp,(%rdx) /* third argument **stackTop */
993 mov (%rsi),%rsp /* load new stack pointer */
1002 mov 6*8(%rsp),%rax /* restore return address */
1003 add $(7*8),%rsp /* free stack frame */
1008 /********************* function asm_switchstackandcall *************************
1010 * int asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1013 * Switches to a new stack, calls a function and switches back. *
1014 * a0 (%rdi) new stack pointer *
1015 * a1 (%rsi) function pointer *
1016 * a2 (%rdx) pointer to variable where stack top should be stored *
1017 * a3 (%rcx) pointer to user data, is passed to the function *
1019 *******************************************************************************/
1021 asm_switchstackandcall:
1022 sub $(1*8),%rsp /* keep stack 16-byte aligned */
1023 sub $16,%rdi /* allocate new stack */
1025 mov 8(%rsp),%rax /* save return address on new stack */
1027 mov %rsp,8(%rdi) /* save old stack pointer on new stack*/
1028 mov %rsp,(%rdx) /* save old stack pointer to variable */
1030 mov %rdi,%rsp /* switch to new stack */
1032 mov %rcx,%rdi /* pass pointer */
1033 call *%rsi /* and call function */
1035 mov (%rsp),%r10 /* load return address */
1036 mov 8(%rsp),%rsp /* switch to old stack */
1037 add $(1*8),%rsp /* free stack space */
1038 mov %r10,(%rsp) /* write return adress */
1044 /************************ function asm_prepare_native_stackinfo ****************************
1046 * creates a stackfame for the begin of a native function (either builtin or not ) *
1047 * expected stack at begin of function *
1049 * address of the jit call which invokes the native *
1050 * begin address of stack frame of the java method *
1051 * method pointer or 0 (for built ins) *
1052 * padding for stackframesize 16*n+8 *
1055 * at end of function: *
1057 * address of the jit call which invokes the native *
1058 * begin address of stack frame of the java method *
1059 * method pointer or 0 (for built ins) *
1060 * address of thread specific top of native list *
1061 * old value of thread specific head *
1062 * padding for stackframesize 16*n+8) *
1066 * This thing is less efficient than the original #define (callerside) *
1067 * destroyes REG_ITMP2, keeps REG_ITMP1 *
1068 ********************************************************************************************/
1071 asm_prepare_native_stackinfo:
1072 sub $16,%rsp /*space for the 2 new pointers*/
1076 call builtin_asm_get_stackframeinfo
1089 /************************ function asm_remove _native_stackinfo *******************************************
1091 * removes a stackfame for the begin of a native function (either builtin or not) *
1092 * expected stack at begin of function *
1093 * address of the jit call which invokes the native *
1094 * begin address of stack frame of the java method *
1095 * method pointer or 0 (for built ins) *
1096 * address thread specific top of native list *
1097 * old value of thread specific head *
1101 * at end of function: *
1103 * return adresss of the jit call which invokes the native *
1109 * This thing is less efficient than the original #define (callerside), uses ITMP2,uses ITMP3,keeps ITMP1 *
1110 ***********************************************************************************************************/
1112 asm_remove_native_stackinfo:
1123 asm_throw_and_handle_exception:
1124 push xpc /* the pushed XPC is directly below the java frame*/
1128 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1133 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1138 jmp asm_handle_exception
1139 ret /*should never be reached */
1142 asm_throw_and_handle_hardware_arithmetic_exception:
1145 push $0 /* the pushed XPC is directly below the java frame*/
1148 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1150 mov string_java_lang_ArithmeticException_message,%rsi
1151 mov string_java_lang_ArithmeticException,%rdi
1153 call new_exception_message
1155 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1159 jmp asm_handle_exception
1160 ret /*should never be reached */
1163 asm_getclassvalues_atomic:
1166 movl offbaseval(a0),itmp1l
1167 movl offdiffval(a0),itmp2l
1168 movl offbaseval(a1),itmp3l
1170 movl itmp1l,offcast_super_baseval(a2)
1171 movl itmp2l,offcast_super_diffval(a2)
1172 movl itmp3l,offcast_sub_baseval(a2)
1177 asm_criticalsections:
1178 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1181 .quad _crit_restart1
1184 .quad _crit_restart2
1190 * These are local overrides for various environment variables in Emacs.
1191 * Please do not remove this and leave it at the end of the file, where
1192 * Emacs will automagically detect them.
1193 * ---------------------------------------------------------------------
1196 * indent-tabs-mode: t