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 2586 2005-06-08 10:56:49Z 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 shl $3,%rbp /* calculate stack size */
244 sub %rbp,%rsp /* stack frame for arguments */
245 mov %rsp,%rbx /* use %rbx as temp sp */
247 sub $sizejniblock,%r14 /* initialize pointer (smaller code) */
248 add $1,%r15 /* initialize argument count */
251 add $sizejniblock,%r14 /* goto next argument block */
252 dec %r15 /* are there any arguments left? */
253 jz L_copy_done /* no test needed after dec */
255 andb $0x02,offjniitemtype(%r14) /* is this a float/double type? */
256 jnz L_stack_handle_float
257 dec %r12 /* arguments assigned to registers */
258 jge L_stack_copy_loop
261 L_stack_handle_float:
262 dec %r13 /* arguments assigned to registers */
263 jge L_stack_copy_loop
266 mov offjniitem(%r14),itmp3 /* copy s8 argument onto stack */
268 add $8,%rbx /* increase sp to next argument */
269 jmp L_stack_copy_loop
272 lea asm_call_jit_compiler,%r11/* %rax still contains method pointer */
273 call *%r11 /* call JIT compiler */
275 add %rbp,%rsp /* remove argument stack frame if any */
277 mov 5*8(%rsp),%r15 /* restore callee saved registers */
283 add $(7*8),%rsp /* free stack space */
287 mov %rax,%rdi /* pass exception pointer */
288 call builtin_throw_exception
290 mov 5*8(%rsp),%r15 /* restore callee saved registers */
296 add $(7*8),%rsp /* free stack space */
297 xor %rax,%rax /* return NULL */
310 mov offjniitem(itmp2),a0
313 mov offjniitem(itmp2),a1
316 mov offjniitem(itmp2),a2
319 mov offjniitem(itmp2),a3
322 mov offjniitem(itmp2),a4
325 mov offjniitem(itmp2),a5
340 movq offjniitem(itmp2),fa0
343 movq offjniitem(itmp2),fa1
346 movq offjniitem(itmp2),fa2
349 movq offjniitem(itmp2),fa3
352 movq offjniitem(itmp2),fa4
355 movq offjniitem(itmp2),fa5
358 movq offjniitem(itmp2),fa6
361 movq offjniitem(itmp2),fa7
365 /****************** function asm_call_jit_compiler *****************************
367 * invokes the compiler for untranslated JavaVM methods. *
369 * Register R0 contains a pointer to the method info structure (prepared *
370 * by createcompilerstub). Using the return address in R26 and the *
371 * offset in the LDA instruction or using the value in methodptr R28 the *
372 * patching address for storing the method address can be computed: *
374 * method address was either loaded using *
376 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
377 * i386_call_reg(REG_ITMP2) *
381 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP2) ; invokevirtual/interface *
382 * i386_mov_membase_reg(REG_ITMP2, OFFSET(, vftbl), REG_ITMP3) *
383 * i386_mov_membase_reg(REG_ITMP3, OFFSET(vftbl, table[0]) + \ *
384 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
385 * i386_call_reg(REG_ITMP1) *
387 * in the static case the method pointer can be computed using the *
388 * return address and the lda function following the jmp instruction *
390 *******************************************************************************/
392 asm_call_jit_compiler:
393 sub $8,%rsp /* keep stack 16-byte aligned */
395 mov %rbx,(%rsp) /* save register */
397 mov 8(%rsp),%r11 /* get return address */
398 mov -1(%r11),%bl /* get function code */
399 cmp $0xd2,%bl /* called with `call *REG_ITMP2' (%r10)? */
400 jne L_not_static_special
402 sub $11,%r11 /* calculate address of immediate */
403 jmp L_call_jit_compile
405 L_not_static_special:
406 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%rax) */
407 jne L_not_virtual_interface
409 sub $7,%r11 /* calculate address of offset */
410 mov (%r11),%r11d /* get offset (32-bit) */
411 add %r10,%r11 /* add base address to get method address */
412 jmp L_call_jit_compile
414 L_not_virtual_interface: /* a call from asm_calljavamethod */
418 mov (%rsp),%rbx /* restore register */
420 sub $(24*8),%rsp /* 8 + 6*8 + 8*8 + 8*8 */
422 mov %r11,0*8(%rsp) /* save address for method pointer */
424 SAVE_ARGUMENT_REGISTERS(1)
426 mov %rax,%rdi /* pass method pointer */
429 mov 0*8(%rsp),%r11 /* restore address for method pointer */
431 RESTORE_ARGUMENT_REGISTERS(1)
434 add $8,%rsp /* keep stack 16-byte aligned */
436 test %rax,%rax /* check for exception */
437 je L_asm_call_jit_compiler_exception
439 test %r11,%r11 /* is address == 0 (asm_calljavamethod) */
442 mov %rax,(%r11) /* and now save the new pointer */
445 jmp *%rax /* ...and now call the new method */
447 L_asm_call_jit_compiler_exception:
448 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
449 call builtin_asm_get_exceptionptrptr
452 lea _exceptionptr,itmp2
454 mov (itmp2),xptr /* get the exception pointer */
455 movl $0,(itmp2) /* clear the exception pointer */
457 pop xpc /* delete return address */
458 sub $5,xpc /* faulting address is ra - 5 */
460 jmp asm_handle_exception
463 /********************* function asm_handle_exception ***************************
465 * This function handles an exception. It does not use the usual calling *
466 * conventions. The exception pointer is passed in REG_ITMP1 and the *
467 * pc from the exception raising position is passed in REG_ITMP2. It searches *
468 * the local exception table for a handler. If no one is found, it unwinds *
469 * stacks and continues searching the callers. *
471 * void asm_handle_exception (exceptionptr, exceptionpc); *
473 *******************************************************************************/
475 asm_handle_nat_exception:
476 add $8,%rsp /* clear return address of native stub*/
478 asm_handle_exception:
480 mov xptr,0*8(%rsp) /* save exception pointer */
481 mov xpc,1*8(%rsp) /* save exception pc */
483 mov xpc,%rdi /* exception pc */
484 call codegen_findmethod
486 mov %rax,2*8(%rsp) /* save data segment pointer */
488 mov 0*8(%rsp),%rax /* restore exception pointer */
489 mov 1*8(%rsp),%r10 /* restore exception pc */
492 mov %rax,%rdi /* exception pointer */
493 mov MethodPointer(itmp3),%rsi /* method pointer */
494 mov xpc,%rdx /* exception pc */
496 mov $1,%r8 /* set noindent flag */
497 call builtin_trace_exception
499 mov 2*8(%rsp),itmp3 /* %r11 = data segment pointer */
500 mov ExTableSize(itmp3),%rcx /* %rcx = exception table size */
501 test %rcx,%rcx /* if empty table skip */
504 lea ExTableStart(itmp3),%rdi /* %rdi = start of exception table */
505 mov 0*8(%rsp),xptr /* get xptr */
508 mov 1*8(%rsp),xpc /* get xpc */
510 mov ExStartPC(%rdi),%rdx /* %rdx = exception start pc */
511 cmp xpc,%rdx /* %rdx = (startpc <= xpc) */
512 jg ex_table_cont /* if (false) continue */
513 mov ExEndPC(%rdi),%rdx /* %rdx = exception end pc */
514 cmp %rdx,xpc /* %rdx = (xpc < endpc) */
515 jge ex_table_cont /* if (false) continue */
516 mov ExCatchType(%rdi),%rdx /* %rdx = exception catch type */
517 test %rdx,%rdx /* NULL catches everything */
520 cmpl $0,offclassloaded(%rdx) /* check if class is loaded */
530 call load_class_bootstrap
539 cmpl $0,offclasslinked(%rdx) /* check if class is linked */
558 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
566 mov offobjvftbl(%rax),%rsi /* %rsi = vftblptr(xptr) */
567 mov offclassvftbl(%rdx),%rdx /* %rdx = vftblptr(catchtype) class (not obj) */
568 mov offbaseval(%rsi),%esi /* %esi = baseval(xptr) */
569 mov offbaseval(%rdx),%r10d /* %r10d = baseval(catchtype) */
570 mov offdiffval(%rdx),%edx /* %edx = diffval(catchtype) */
572 sub %r10d,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
574 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
578 cmp %edx,%esi /* xptr is instanceof catchtype */
582 mov ExHandlerPC(%rdi),xpc /* xpc = exception handler pc */
584 mov 0*8(%rsp),%rax /* restore exception pointer */
585 add $(4*8),%rsp /* free stack frame */
587 jmp *xpc /* jump to the handler */
590 lea ExEntrySize(%rdi),%rdi /* next exception table entry */
591 dec %rcx /* decrement entry counter */
592 test %rcx,%rcx /* if (t0 > 0) next entry */
596 mov 0*8(%rsp),%rax /* restore exception pointer */
597 mov 1*8(%rsp),%r10 /* restore exception pc */
598 mov 2*8(%rsp),%r11 /* restore data segment pointer */
601 mov %rax,%rcx /* save exception pointer */
604 movl IsSync(%r11),%eax /* %rax = SyncOffset */
605 test %rax,%rax /* if zero no monitorexit */
608 #if defined(USE_THREADS)
617 call builtin_monitorexit
626 mov FrameSize(%r11),%eax /* %eax = frame size */
627 add %rax,%rsp /* unwind stack */
628 mov %rsp,%rax /* %rax = pointer to save area */
630 mov IntSave(%r11),%edx /* %edx = saved int register count*/
657 shl $3,%edx /* multiply by 8 bytes */
661 mov FltSave(%r11),%edx /* %edx = saved flt register count*/
684 movq -48(%rax),%xmm10
686 movq -40(%rax),%xmm11
688 movq -32(%rax),%xmm12
690 movq -24(%rax),%xmm13
692 movq -16(%rax),%xmm14
697 pop %r10 /* the new xpc is return address */
698 sub $3,%r10 /* subtract 3 bytes for call */
705 call codegen_findmethod /* get the new data segment ptr */
712 mov %rcx,%rax /* restore saved exception pointer*/
716 mov %rax,0*8(%rsp) /* save exception pointer */
717 mov %r10,1*8(%rsp) /* save exception pc */
718 mov %r11,2*8(%rsp) /* save data segment pointer */
723 /* asm_wrapper_patcher *********************************************************
729 24 pointer to virtual java_objectheader
730 16 machine code (which is patched back later)
731 8 unresolved class/method/field reference
732 0 pointer to patcher function
734 *******************************************************************************/
737 sub $(17*8),%rsp /* stack frame (16-byte aligned) */
739 SAVE_ARGUMENT_REGISTERS(0)
740 SAVE_TEMPORARY_REGISTERS(14)
742 mov itmp1,15*8(%rsp) /* save itmp1 and itmp2 */
743 mov itmp2,16*8(%rsp) /* can be used by some instructions */
745 mov %rsp,a0 /* pass stack pointer */
746 add $(18*8),a0 /* skip patcher function pointer */
747 mov 17*8(%rsp),itmp3 /* get function pointer */
748 call *itmp3 /* call the patcher function */
749 mov v0,itmp3 /* save return value */
751 RESTORE_ARGUMENT_REGISTERS(0)
752 RESTORE_TEMPORARY_REGISTERS(14)
754 mov 15*8(%rsp),itmp1 /* restore itmp1 and itmp2 */
755 mov 16*8(%rsp),itmp2 /* can be used by some instructions */
757 add $((4+17)*8),%rsp /* remove stack frame, keep ra */
759 test itmp3,itmp3 /* exception thrown? */
760 jz L_asm_wrapper_patcher_exception
761 ret /* call new patched code */
763 L_asm_wrapper_patcher_exception:
764 /*stack bottom is xpc and it is directly below the last java stackframe*/
768 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
770 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
771 call builtin_asm_get_exceptionptrptr
774 lea _exceptionptr,itmp2
776 mov (itmp2),a0 /* get the exception pointer */
777 movl $0,(itmp2) /* clear exception pointer */
778 call helper_fillin_stacktrace
782 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
785 pop xpc /* get and remove return address */
786 jmp asm_handle_exception
789 /* asm_builtin_x2x *************************************************************
791 * Wrapper functions for float to int corner cases *
793 *******************************************************************************/
798 SAVE_ARGUMENT_REGISTERS(0)
803 RESTORE_ARGUMENT_REGISTERS(0)
812 SAVE_ARGUMENT_REGISTERS(0)
817 RESTORE_ARGUMENT_REGISTERS(0)
826 SAVE_ARGUMENT_REGISTERS(0)
831 RESTORE_ARGUMENT_REGISTERS(0)
840 SAVE_ARGUMENT_REGISTERS(0)
845 RESTORE_ARGUMENT_REGISTERS(0)
851 /* asm_builtin_arraycheckcast **************************************************
853 Does the cast check and eventually throws an exception.
855 *******************************************************************************/
857 asm_builtin_arraycheckcast:
858 sub $24,%rsp /* keep stack 16-byte aligned */
859 mov %rdi,(%rsp) /* save object pointer */
860 call builtin_arraycheckcast
861 test %rax,%rax /* if (false) throw exception */
863 mov (%rsp),%rax /* return object pointer */
864 add $24,%rsp /* free stack space */
868 /*call new_classcastexception*/
870 pop xpc /* delete return address */
871 sub $3,xpc /* faulting address is ra - 3 */
872 mov string_java_lang_ClassCastException,xptr
873 jmp asm_throw_and_handle_exception
876 /* asm_builtin_aastore *********************************************************
878 Checks if the object can be stored in the given array and stores the
879 address if it's possible. This function can also throw some exceptions.
881 *******************************************************************************/
884 sub $(3*8),%rsp /* allocate stack space */
885 test %rdi,%rdi /* if null pointer throw exception */
888 movl offarraysize(%rdi),%eax /* load size */
889 cmpl %eax,%esi /* do bound check */
890 jae nb_aastore_bound /* if out of bounds throw exception */
892 shl $3,%rsi /* index * 8 */
894 add %rsi,%r10 /* add index * 8 to arrayref */
896 mov %r10,(%rsp) /* save store position */
897 mov %rdx,8(%rsp) /* save object */
899 mov %rdx,%rsi /* object is second argument */
900 call builtin_canstore /* builtin_canstore(arrayref,object) */
901 test %rax,%rax /* if (false) throw exception */
904 mov (%rsp),%r10 /* restore store position */
905 mov 8(%rsp),%rdx /* restore object */
906 mov %rdx,offobjarrdata(%r10)/* store objectptr in array */
907 add $(3*8),%rsp /* free stack space */
912 pop xpc /* delete return address from stack */
913 sub $3,xpc /* faulting address is return adress - 3 */
914 mov string_java_lang_NullPointerException,xptr
915 jmp asm_throw_and_handle_exception
919 push $0 /*directly below return address*/
924 call asm_prepare_native_stackinfo
926 mov itmp1,%rdi /* move index into a0 */
927 call new_arrayindexoutofboundsexception
929 call asm_remove_native_stackinfo
931 pop xpc /* just remove one quadword */
932 pop xpc /* delete return address */
933 sub $3,xpc /* faulting address is return adress - 3 */
934 jmp asm_handle_exception
937 /*call new_arraystoreexception*/
939 pop xpc /* delete return address */
940 sub $3,xpc /* faulting address is return adress - 3 */
941 mov string_java_lang_ArrayStoreException,xptr
942 jmp asm_throw_and_handle_exception
945 /******************* function asm_initialize_thread_stack **********************
947 * initialized a thread stack *
948 * (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), (to)->stackEnd)*
950 *******************************************************************************/
952 asm_initialize_thread_stack:
963 mov %rdi,6*8(%rsi) /* save (u1*) (func) */
964 mov %rsi,%rax /* return restorepoint in %rax */
968 /******************* function asm_perform_threadswitch *************************
970 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
972 * performs a threadswitch *
974 *******************************************************************************/
976 asm_perform_threadswitch:
977 sub $(7*8),%rsp /* allocate stack frame */
986 mov 7*8(%rsp),%rax /* save current return address */
989 mov %rsp,(%rdi) /* first argument **from */
990 mov %rsp,(%rdx) /* third argument **stackTop */
992 mov (%rsi),%rsp /* load new stack pointer */
1001 mov 6*8(%rsp),%rax /* restore return address */
1002 add $(7*8),%rsp /* free stack frame */
1007 /********************* function asm_switchstackandcall *************************
1009 * int asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1012 * Switches to a new stack, calls a function and switches back. *
1013 * a0 (%rdi) new stack pointer *
1014 * a1 (%rsi) function pointer *
1015 * a2 (%rdx) pointer to variable where stack top should be stored *
1016 * a3 (%rcx) pointer to user data, is passed to the function *
1018 *******************************************************************************/
1020 asm_switchstackandcall:
1021 sub $(1*8),%rsp /* keep stack 16-byte aligned */
1022 sub $16,%rdi /* allocate new stack */
1024 mov 8(%rsp),%rax /* save return address on new stack */
1026 mov %rsp,8(%rdi) /* save old stack pointer on new stack*/
1027 mov %rsp,(%rdx) /* save old stack pointer to variable */
1029 mov %rdi,%rsp /* switch to new stack */
1031 mov %rcx,%rdi /* pass pointer */
1032 call *%rsi /* and call function */
1034 mov (%rsp),%r10 /* load return address */
1035 mov 8(%rsp),%rsp /* switch to old stack */
1036 add $(1*8),%rsp /* free stack space */
1037 mov %r10,(%rsp) /* write return adress */
1043 /************************ function asm_prepare_native_stackinfo ****************************
1045 * creates a stackfame for the begin of a native function (either builtin or not ) *
1046 * expected stack at begin of function *
1048 * address of the jit call which invokes the native *
1049 * begin address of stack frame of the java method *
1050 * method pointer or 0 (for built ins) *
1051 * padding for stackframesize 16*n+8 *
1054 * at end of function: *
1056 * address of the jit call which invokes the native *
1057 * begin address of stack frame of the java method *
1058 * method pointer or 0 (for built ins) *
1059 * address of thread specific top of native list *
1060 * old value of thread specific head *
1061 * padding for stackframesize 16*n+8) *
1065 * This thing is less efficient than the original #define (callerside) *
1066 * destroyes REG_ITMP2, keeps REG_ITMP1 *
1067 ********************************************************************************************/
1070 asm_prepare_native_stackinfo:
1071 sub $16,%rsp /*space for the 2 new pointers*/
1075 call builtin_asm_get_stackframeinfo
1088 /************************ function asm_remove _native_stackinfo *******************************************
1090 * removes a stackfame for the begin of a native function (either builtin or not) *
1091 * expected stack at begin of function *
1092 * address of the jit call which invokes the native *
1093 * begin address of stack frame of the java method *
1094 * method pointer or 0 (for built ins) *
1095 * address thread specific top of native list *
1096 * old value of thread specific head *
1100 * at end of function: *
1102 * return adresss of the jit call which invokes the native *
1108 * This thing is less efficient than the original #define (callerside), uses ITMP2,uses ITMP3,keeps ITMP1 *
1109 ***********************************************************************************************************/
1111 asm_remove_native_stackinfo:
1122 asm_throw_and_handle_exception:
1123 push xpc /* the pushed XPC is directly below the java frame*/
1127 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1132 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1137 jmp asm_handle_exception
1138 ret /*should never be reached */
1141 asm_throw_and_handle_hardware_arithmetic_exception:
1144 push $0 /* the pushed XPC is directly below the java frame*/
1147 call asm_prepare_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1149 mov string_java_lang_ArithmeticException_message,%rsi
1150 mov string_java_lang_ArithmeticException,%rdi
1152 call new_exception_message
1154 call asm_remove_native_stackinfo /* be aware of the stack effect and calling convention explained above*/
1158 jmp asm_handle_exception
1159 ret /*should never be reached */
1162 asm_getclassvalues_atomic:
1165 movl offbaseval(a0),itmp1l
1166 movl offdiffval(a0),itmp2l
1167 movl offbaseval(a1),itmp3l
1169 movl itmp1l,offcast_super_baseval(a2)
1170 movl itmp2l,offcast_super_diffval(a2)
1171 movl itmp3l,offcast_sub_baseval(a2)
1176 asm_criticalsections:
1177 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1180 .quad _crit_restart1
1183 .quad _crit_restart2
1189 * These are local overrides for various environment variables in Emacs.
1190 * Please do not remove this and leave it at the end of the file, where
1191 * Emacs will automagically detect them.
1192 * ---------------------------------------------------------------------
1195 * indent-tabs-mode: t