1 /* jit/i386/asmpart.S - Java-C interface functions for i386
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Andreas Krall
32 $Id: asmpart.S 1564 2004-11-23 15:55:58Z twisti $
40 /* data segment offsets */
42 #define MethodPointer -4
48 #define LineNumberTableSize -28
49 #define LineNumberTableStart -32
50 #define ExTableSize -36
51 #define ExTableStart -36
53 #define ExEntrySize -16
56 #define ExHandlerPC -12
57 #define ExCatchType -16
60 #define LineEntrySize -8
76 /********************* exported functions and variables ***********************/
78 .globl asm_calljavafunction
79 .globl calljava_xhandler
80 .globl asm_calljavafunction2
81 .globl asm_calljavafunction2long
82 .globl asm_calljavafunction2double
83 .globl calljava_xhandler2
85 .globl asm_call_jit_compiler
86 .globl asm_handle_builtin_exception
87 .globl asm_handle_nat_exception
88 .globl asm_handle_exception
89 .globl asm_check_clinit
90 .globl asm_builtin_checkcast
91 .globl asm_builtin_checkarraycast
92 .globl asm_builtin_newarray
93 .globl asm_builtin_anewarray
94 .globl asm_builtin_newarray_array
95 .globl asm_builtin_aastore
96 .globl asm_builtin_monitorenter
97 .globl asm_builtin_monitorexit
98 .globl asm_builtin_ldiv
99 .globl asm_builtin_lrem
100 .globl asm_builtin_f2i
101 .globl asm_builtin_f2l
102 .globl asm_builtin_d2i
103 .globl asm_builtin_d2l
104 .globl asm_builtin_arrayinstanceof
105 .globl asm_perform_threadswitch
106 .globl asm_initialize_thread_stack
107 .globl asm_switchstackandcall
108 .globl asm_getcallingmethod
109 .globl Java_java_lang_VMSecurityManager_getClassContext
110 .globl Java_java_lang_VMSecurityManager_currentClassLoader
111 .globl asm_builtin_new
112 .globl asm_get_stackTrace
113 .globl asm_criticalsections
114 .globl asm_getclassvalues_atomic
116 /*************************** imported functions *******************************/
119 .globl builtin_monitorexit
120 .globl builtin_throw_exception
121 .globl builtin_trace_exception
122 .globl class_java_lang_Object
123 .globl codegen_findmethod
124 /* .globl codegen_findmethod1*/
125 .globl builtin_asm_createclasscontextarray
126 .globl builtin_asm_getclassloader
127 .globl callgetexceptionptrptr
128 .globl asm_throw_and_handle_exception
129 .globl asm_throw_and_handle_hardware_arithmetic_exception
132 /********************* function asm_calljavafunction ***************************
134 * This function calls a Java-method (which possibly needs compilation) *
135 * with up to 4 address parameters. *
137 * This functions calls the JIT-compiler which eventually translates the *
138 * method into machine code. *
141 * javaobject_header *asm_calljavamethod (methodinfo *m, *
142 * void *arg1, void *arg2, void *arg3, void *arg4); *
144 *******************************************************************************/
147 .ascii "calljavafunction\0\0"
150 .long 0 /* catch type all */
151 .long calljava_xhandler /* handler pc */
152 .long calljava_xhandler /* end pc */
153 .long asm_calljavafunction /* start pc */
154 .long 1 /* extable size */
155 .long 0 /* line number table start */
156 .long 0 /* line number table size */
157 .long 0 /* fltsave */
158 .long 0 /* intsave */
161 .long 32 /* frame size */
162 .long 0 /* method pointer (pointer to name) */
164 asm_calljavafunction:
165 push %ebp /* allocate stack space */
168 push %ebx /* save registers */
172 sub $32,%esp /* pass the remaining parameters */
175 mov %edx,28(%esp) /* convert parms to 8 byte */
191 mov 8(%ebp),%eax /* move function pointer to %eax */
193 lea asm_call_jit_compiler,%edx
194 call *%edx /* call JIT compiler */
197 pop %edi /* restore registers */
204 push %eax /* pass exception pointer */
205 call builtin_throw_exception
209 pop %edi /* restore registers */
216 /********************* function asm_calljavafunction ***************************
218 * This function calls a Java-method (which possibly needs compilation) *
219 * with up to 4 address parameters. *
221 * This functions calls the JIT-compiler which eventually translates the *
222 * method into machine code. *
225 * javaobject_header *asm_calljavafunction2(methodinfo *m, *
226 * u4 count, u4 size, void *callblock); *
228 *******************************************************************************/
231 .ascii "calljavafunction2\0\0"
234 .long 0 /* catch type all */
235 .long calljava_xhandler2 /* handler pc */
236 .long calljava_xhandler2 /* end pc */
237 .long asm_calljavafunction2 /* start pc */
238 .long 1 /* extable size */
239 .long 0 /* line number table start */
240 .long 0 /* line number table size */
241 .long 0 /* fltsave */
242 .long 0 /* intsave */
245 .long 32 /* frame size */
246 .long 0 /* method pointer (pointer to name) */
248 asm_calljavafunction2:
249 asm_calljavafunction2double:
250 asm_calljavafunction2long:
252 mov %esp,%ebp /* save stackptr */
254 push %ebx /* save registers */
258 mov 20(%ebp),%eax /* pointer to arg block */
259 mov 12(%ebp),%ecx /* arg count */
260 test %ecx,%ecx /* maybe we have no args */
261 jle calljava_copydone
263 mov %ecx,%edx /* calculate stack size */
265 mov %edx,%esi /* save in callee saved register */
266 sub %esi,%esp /* stack frame for arguments */
270 mov offjniitem(%eax),%edx
272 mov offjniitem+4(%eax),%edx
275 sub $1,%ecx /* are there any args left? */
277 jle calljava_copydone
279 add $sizejniblock,%eax /* goto next argument block */
280 add $8,%edi /* increase sp to next argument */
281 jmp calljava_copyloop
284 mov 8(%ebp),%eax /* move function pointer to %eax */
286 lea asm_call_jit_compiler,%edx
287 call *%edx /* call JIT compiler */
290 add %esi,%esp /* remove arg stack frame */
291 pop %edi /* restore registers */
298 push %eax /* pass exception pointer */
299 call builtin_throw_exception
302 add %esi,%esp /* remove arg stack frame */
303 pop %edi /* restore registers */
310 /****************** function asm_call_jit_compiler *****************************
312 * invokes the compiler for untranslated JavaVM methods. *
314 * Register R0 contains a pointer to the method info structure (prepared *
315 * by createcompilerstub). Using the return address in R26 and the *
316 * offset in the LDA instruction or using the value in methodptr R28 the *
317 * patching address for storing the method address can be computed: *
319 * method address was either loaded using *
321 * i386_mov_imm_reg(a, REG_ITMP2) ; invokestatic/special *
322 * i386_call_reg(REG_ITMP2) *
326 * i386_mov_membase_reg(REG_SP, 0, REG_ITMP1) ; invokevirtual/interface *
327 * i386_mov_membase_reg(REG_ITMP1, OFFSET(, vftbl), REG_ITMP2) *
328 * i386_mov_membase_reg(REG_ITMP2, OFFSET(vftbl, table[0]) + \ *
329 * sizeof(methodptr) * m->vftblindex, REG_ITMP1) *
330 * i386_call_reg(REG_ITMP1) *
332 * in the static case the method pointer can be computed using the *
333 * return address and the lda function following the jmp instruction *
335 *******************************************************************************/
337 asm_call_jit_compiler:
338 push %ebx /* save register */
341 mov 8(%esp),%ebp /* get return address (2 push) */
342 mov -1(%ebp),%bl /* get function code */
343 cmp $0xd1,%bl /* called with `call *REG_ITMP2' (%ecx)? */
344 jne L_not_static_special
346 sub $6,%ebp /* calculate address of immediate */
347 jmp L_call_jit_compile
349 L_not_static_special:
350 cmp $0xd0,%bl /* called with `call *REG_ITMP1' (%eax) */
351 jne L_not_virtual_interface
353 sub $6,%ebp /* calculate address of offset */
354 mov (%ebp),%ebp /* get offset */
355 add itmp2,%ebp /* add base address to get method address */
356 jmp L_call_jit_compile
358 L_not_virtual_interface: /* a call from asm_calljavafunction */
362 push %ebp /* save address for method pointer */
364 push %eax /* push methodpointer on stack */
368 pop %ebp /* restore address for method pointer */
370 test %eax,%eax /* check for exception */
373 test %ebp,%ebp /* is address == 0 (asm_calljavafunction) */
376 mov %eax,(%ebp) /* and now save the new pointer */
379 pop %ebp /* restore registers */
382 jmp *%eax /* ...and now call the new method */
385 pop %ebp /* restore registers */
388 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
389 call builtin_asm_get_exceptionptrptr
391 mov (%ecx),%eax /* get the exception pointer */
392 movl $0,(%ecx) /* clear the exception pointer */
394 lea _exceptionptr,%ecx
395 mov (%ecx),%eax /* get the exception pointer */
396 movl $0,(%ecx) /* clear the exception pointer */
399 pop %ecx /* delete return address */
400 sub $2,%ecx /* faulting address is return adress - 2 */
402 L_refillinStacktrace:
403 push %ecx /* store fault adress */
404 push %eax /* temporarily save exception pointer*/
405 call builtin_asm_get_stackframeinfo
406 push %eax /* save location of thread specific stack info head pointer */
407 mov (%eax),%ecx /* save old value of pointer*/
409 mov %esp,(%eax) /*store pointer to this structure*/
410 mov 8(%esp),%eax /* get the exception pointer again*/
411 movl $0,8(%esp) /*mark this block as native*/
412 push $0 /*used for the jni_callblock structure*/
413 push %eax /*save eax for later */
414 /* get fillInStackTrace method*/
415 push utf_fillInStackTrace_desc
416 push utf_fillInStackTrace_name
417 mov offobjvftbl(%eax),%ecx
418 mov offclass(%ecx),%eax
420 call class_resolvemethod
428 call asm_calljavafunction2
431 /*remove native stack info */
440 jmp asm_handle_exception
443 /********************* function asm_handle_exception ***************************
445 * This function handles an exception. It does not use the usual calling *
446 * conventions. The exception pointer is passed in REG_ITMP1 and the *
447 * pc from the exception raising position is passed in REG_ITMP2. It searches *
448 * the local exception table for a handler. If no one is found, it unwinds *
449 * stacks and continues searching the callers. *
451 * void asm_handle_exception (exceptionptr, exceptionpc); *
453 *******************************************************************************/
455 asm_handle_nat_exception:
456 add $4,%esp /* clear return address of native stub */
458 asm_handle_exception:
462 push %eax /* exception pointer */
463 push %ecx /* excepiton pc */
465 call asm_get_stackTrace
471 asm_handle_exception_loop:
475 push %eax /* save exception pointer */
476 push %ecx /* save exception pc */
478 call codegen_findmethod /* get the data segment ptr */
482 mov -8(%ebp),%ecx /* could be changed in findmethod */
484 push %edx /* save data segment pointer */
491 mov %eax,(%esp) /* exception pointer */
492 mov MethodPointer(%edx),%eax /* method pointer */
494 mov %ecx,8(%esp) /* exception pc */
495 movl $0,12(%esp) /* line number */
496 movl $1,16(%esp) /* set no unwind flag */
497 call builtin_trace_exception
499 mov -12(%ebp),%esi /* %esi = data segment pointer */
500 mov ExTableSize(%esi),%ecx /* %ecx = exception table size */
501 test %ecx,%ecx /* if empty table skip */
504 lea ExTableStart(%esi),%edi /* %edi = start of exception table*/
505 mov -4(%ebp),%eax /* get xptr */
508 mov -8(%ebp),%edx /* get xpc */
510 mov ExStartPC(%edi),%ebx /* %ebx = exception start pc */
511 cmp %edx,%ebx /* %ebx = (startpc <= xpc) */
512 jg ex_table_cont /* if (false) continue */
513 mov ExEndPC(%edi),%ebx /* %ebx = exception end pc */
514 cmp %ebx,%edx /* %ebx = (xpc < endpc) */
515 jge ex_table_cont /* if (false) continue */
516 mov ExCatchType(%edi),%ebx /* arg1 = exception catch type */
517 test %ebx,%ebx /* NULL catches everything */
520 cmpl $0,offclassloaded(%ebx) /* check if class is loaded */
524 mov %eax,1*4(%esp) /* save not callee saved regs */
527 mov %ebx,0*4(%esp) /* exception class is argument */
536 cmpl $0,offclasslinked(%ebx)
540 mov %eax,1*4(%esp) /* save not callee saved regs */
543 mov %ebx,0*4(%esp) /* exception class is argument */
552 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
560 mov offobjvftbl(%eax),%esi /* %esi = vftblptr(xptr) */
561 mov offclassvftbl(%ebx),%ebx /* %ebx = vftblptr(catchtype) class (not obj) */
562 mov offbaseval(%esi),%esi /* %esi = baseval(xptr) */
563 mov offbaseval(%ebx),%edx /* %edx = baseval(catchtype) */
564 mov offdiffval(%ebx),%ebx /* %ebx = diffval(catchtype) */
566 sub %edx,%esi /* %esi = baseval(xptr) - baseval(catchtype) */
568 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
572 cmp %ebx,%esi /* xptr is instanceof catchtype */
576 mov ExHandlerPC(%edi),%edx
578 pop %edi /* restore registers */
581 add $8,%esp /* suck %ecx, %edx */
582 pop %eax /* restore xptr */
585 jmp *%edx /* jump to exception handler */
588 lea ExEntrySize(%edi),%edi
597 pop %edx /* restore data segment pointer */
602 push %eax /* save exception pointer */
605 mov IsSync(%edx),%eax /* %eax = SyncOffset */
606 test %eax,%eax /* if zero no monitorexit */
610 mov -4(%eax),%eax /* we have the xptr on the stack */
611 push %edx /* save regs */
613 call builtin_monitorexit
615 pop %edx /* restore regs */
619 add FrameSize(%edx),%eax /* %eax = frame size */
620 add $4,%eax /* we have the xptr on the stack */
622 mov IntSave(%edx),%ecx /* %ecx = saved int register count*/
644 shl $3,%ecx /* multiply by 8 bytes */
648 mov FltSave(%edx),%ecx /* %ecx = saved flt register count */
675 pop %eax /* restore exception pointer */
677 mov FrameSize(%edx),%ecx /* %ecx = frame size */
678 add %ecx,%esp /* unwind stack */
680 pop %ecx /* the new xpc is return address */
683 jmp asm_handle_exception_loop
686 /* asm_check_clinit ************************************************************
692 16 ra ; return address of patched call in java machine code
693 12 xmcode ; additional machine code (only for i386 and x86_64)
694 8 mcode ; machine code to patch back in
695 4 class ; pointer to class
696 0 sp ; stack pointer of java stack frame + return address
698 *******************************************************************************/
701 mov 4(%esp),%eax /* get fieldinfo's class pointer */
702 mov offclassinit(%eax),%eax /* get initialized flag */
707 sub $16,%esp /* build stack frame (4 * 4 bytes) */
708 mov %eax,(%esp) /* put classpointer on stack */
709 call builtin_asm_get_stackframeinfo
721 mov 4+4(%esp),itmp1 /* get class pointer */
722 mov itmp1,(%esp) /* store class pointer as a0 */
723 call class_init /* call class_init function */
734 test %eax,%eax /* we had an exception */
735 je L_initializererror
738 mov 16(%esp),itmp1 /* get return address */
739 sub $5,itmp1 /* remove size of `call rel32' */
741 mov 12(%esp),itmp2 /* get xmcode machine code */
742 movb itmp2l,(itmp1) /* patch back in 1 byte */
743 mov 8(%esp),itmp2 /* get mcode machine code */
744 mov itmp2,1(itmp1) /* patch back in 4 bytes */
746 add $(5*4),%esp /* remove stub stack frame incl. ra */
748 jmp *itmp1 /* jump to patched code an execute it */
751 add $(4*4),%esp /* remove stub stack frame */
753 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
754 call builtin_asm_get_exceptionptrptr
756 mov (%ecx),%eax /* get the exception pointer */
757 movl $0,(%ecx) /* clear the exception pointer */
759 lea _exceptionptr,%ecx
760 mov (%ecx),%eax /* get the exception pointer */
761 movl $0,(%ecx) /* clear the exception pointer */
764 pop itmp2 /* get and delete ra */
765 sub $5,itmp2 /* faulting address is ra - 5 */
767 jmp asm_handle_exception
770 /********************* function asm_builtin_monitorenter ***********************
772 * Does null check and calls monitorenter or throws an exception *
774 *******************************************************************************/
776 asm_builtin_monitorenter:
778 je nb_monitorenter /* if (null) throw exception */
779 jmp builtin_monitorenter /* else call builtin_monitorenter */
782 mov string_java_lang_NullPointerException,%eax
785 jmp asm_throw_and_handle_exception
788 push string_java_lang_NullPointerException
792 pop %ecx /* delete return address */
793 sub $2,%ecx /* faulting address is return adress - 2 */
794 jmp asm_handle_exception
797 /********************* function asm_builtin_monitorexit ************************
799 * Does null check and calls monitorexit or throws an exception *
801 *******************************************************************************/
803 asm_builtin_monitorexit:
806 je nb_monitorexit /* if (null) throw exception */
807 push %ecx /* save registers which could be used */
810 call builtin_monitorexit /* else call builtin_monitorenter */
812 pop %edx /* restore registers which could be used */
817 mov string_java_lang_NullPointerException,%eax
820 jmp asm_throw_and_handle_exception
823 push string_java_lang_NullPointerException
827 pop %ecx /* delete return address */
828 sub $2,%ecx /* faulting address is return adress - 2 */
829 jmp asm_handle_exception
832 /************************ function asm_builtin_ldiv ****************************
834 * Does null check and calls ldiv or throws an exception *
836 *******************************************************************************/
841 test %eax,%eax /* if (null) throw exception */
849 jmp asm_throw_and_handle_hardware_arithmetic_exception
851 push string_java_lang_ArithmeticException_message
852 push string_java_lang_ArithmeticException
853 call new_exception_message
856 pop %ecx /* delete return address */
857 sub $2,%ecx /* faulting address is return adress - 2 */
858 jmp asm_handle_exception
861 /************************ function asm_builtin_lrem ****************************
863 * Does null check and calls lrem or throws an exception *
865 *******************************************************************************/
870 test %eax,%eax /* if (null) throw exception */
878 jmp asm_throw_and_handle_hardware_arithmetic_exception
880 push string_java_lang_ArithmeticException_message
881 push string_java_lang_ArithmeticException
882 call new_exception_message
885 pop %ecx /* delete return address */
886 sub $2,%ecx /* faulting address is return adress - 2 */
887 jmp asm_handle_exception
890 /************************ function asm_builtin_x2x *****************************
892 * Wrapper functions for corner cases *
894 *******************************************************************************/
925 /******************* function asm_builtin_checkarraycast ***********************
927 * Does the cast check and eventually throws an exception *
929 *******************************************************************************/
931 asm_builtin_checkarraycast:
932 sub $8,%esp /* build stack frame (2 * 4 bytes) */
934 mov 12(%esp),%eax /* 8 (frame) + 4 (return) */
935 mov %eax,(%esp) /* save object pointer */
940 call builtin_checkarraycast /* builtin_checkarraycast */
942 test %eax,%eax /* if (false) throw exception */
945 mov 12(%esp),%eax /* return object pointer */
951 mov string_java_lang_ClassCastException,%eax
954 jmp asm_throw_and_handle_exception
956 push string_java_lang_ClassCastException
962 pop %ecx /* delete return address */
963 sub $2,%ecx /* faulting address is return adress - 2 */
964 jmp asm_handle_exception
967 /******************* function asm_builtin_newarray *****************************
969 * Does the cast check and eventually throws an exception *
971 *******************************************************************************/
973 asm_builtin_newarray:
974 sub $8,%esp /* build stack frame (2 * 4 bytes) */
982 call builtin_newarray
988 /******************* function asm_builtin_aastore ******************************
990 * Does the cast check and eventually throws an exception *
992 *******************************************************************************/
995 sub $12,%esp /* build stack frame (3 * 4 bytes) */
997 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
998 test %eax,%eax /* if null pointer throw exception */
1001 mov offarraysize(%eax),%edx /* load size */
1002 mov 24(%esp),%ecx /* index */
1003 cmp %edx,%ecx /* do bound check */
1004 jae nb_aastore_bound /* if out of bounds throw exception */
1006 shl $2,%ecx /* index * 4 */
1007 add %eax,%ecx /* add index * 4 to arrayref */
1009 mov %ecx,8(%esp) /* save store position */
1011 mov 16(%esp),%eax /* 12 (frame) + 4 (return) */
1014 mov 32(%esp),%eax /* object is second argument */
1017 call builtin_canstore /* builtin_canstore(arrayref,object) */
1019 test %eax,%eax /* if (false) throw exception */
1024 mov %eax,offobjarrdata(%ecx) /* store objectptr in array */
1031 mov string_java_lang_NullPointerException,%eax
1034 jmp asm_throw_and_handle_exception
1037 push string_java_lang_NullPointerException
1042 pop %ecx /* delete return address */
1043 sub $2,%ecx /* faulting address is return adress - 2 */
1044 jmp asm_handle_exception
1047 push %ecx /* itmp2 contains array index */
1048 call new_arrayindexoutofboundsexception
1052 pop %ecx /* delete return address */
1053 sub $2,%ecx /* faulting address is return adress - 2 */
1054 jmp asm_handle_exception
1059 mov string_java_lang_ArrayStoreException,%eax
1062 jmp asm_throw_and_handle_exception
1065 push string_java_lang_ArrayStoreException
1070 pop %ecx /* delete return address */
1071 sub $2,%ecx /* faulting address is return adress - 2 */
1072 jmp asm_handle_exception
1075 /******************* function asm_builtin_arrayinstanceof **********************
1077 * Does the instanceof check of arrays *
1079 *******************************************************************************/
1081 asm_builtin_arrayinstanceof:
1082 sub $8,%esp /* build stack frame (2 * 4 bytes) */
1090 call builtin_arrayinstanceof
1096 /******************* function asm_initialize_thread_stack **********************
1098 * initialized a thread stack *
1099 * (to)->restorePoint = asm_initialize_thread_stack((u1*)(func), (to)->stackEnd)*
1101 *******************************************************************************/
1103 asm_initialize_thread_stack:
1104 mov 8(%esp),%eax /* (to)->stackEnd */
1105 sub $36,%eax /* 4 bytes * 8 regs + 4 bytes func */
1117 mov 4(%esp),%edx /* save (u1*) (func) */
1120 ret /* return restorepoint in %eax */
1123 /******************* function asm_perform_threadswitch *************************
1125 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1127 * performs a threadswitch *
1129 *******************************************************************************/
1131 asm_perform_threadswitch:
1143 mov 36(%esp),%eax /* save current return address */
1146 mov 40(%esp),%eax /* first argument **from */
1149 mov 48(%esp),%eax /* third argument **stackTop */
1152 mov 44(%esp),%eax /* second argument **to */
1153 mov 0(%eax),%esp /* load new stack pointer */
1159 /* skip stack pointer */
1164 add $32,%esp /* leave return address on stack */
1168 /********************* function asm_switchstackandcall *************************
1170 * int asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1173 * Switches to a new stack, calls a function and switches back. *
1174 * a0 new stack pointer *
1175 * a1 function pointer *
1176 * a2 pointer to variable where stack top should be stored *
1177 * a3 pointer to user data, is passed to the function *
1179 *******************************************************************************/
1181 asm_switchstackandcall:
1182 mov 4(%esp),%edx /* first argument *stack */
1183 sub $8,%edx /* allocate new stack */
1185 mov (%esp),%eax /* save return address on new stack */
1188 mov %esp,4(%edx) /* save old stack pointer on new stack */
1190 mov 12(%esp),%eax /* third argument **stacktopsave */
1191 mov %esp,(%eax) /* save old stack pointer to variable */
1193 mov 8(%esp),%eax /* load function pointer */
1194 mov 16(%esp),%ecx /* fourth argument *p */
1196 mov %edx,%esp /* switch to new stack */
1199 mov %ecx,0(%esp) /* pass pointer */
1200 call *%eax /* and call function */
1203 mov (%esp),%edx /* load return address */
1204 mov 4(%esp),%esp /* switch to old stack */
1209 Java_java_lang_VMSecurityManager_currentClassLoader:
1210 mov cacao_initializing,%eax
1212 jz Java_java_lang_VMSecurityManager_cont
1216 Java_java_lang_VMSecurityManager_cont:
1217 lea builtin_asm_getclassloader,%eax
1218 push %eax /*store collector function pointer*/
1219 jmp getClassContext_begin
1220 Java_java_lang_VMSecurityManager_getClassContext:
1221 lea builtin_asm_createclasscontextarray,%eax
1222 push %eax /*store collector function pointer*/
1223 getClassContext_begin: /*start the real work*/
1227 sub $68,%esp /*64 memory location without overwriting return adress and collector function adress*/
1228 mov %esp,%ebx /*end of allocated memory block for classpointers is the adress of the working data block +4 */
1229 push $0 /*%esp+32 was native*/
1230 push %eax /*%esp+24 blkbegin*/
1231 push %eax /*%esp+20 currentpos*/
1232 push %ebx /*%esp+16 blkend*/
1234 call builtin_asm_get_threadrootmethod
1235 push %eax /*%esp+12*/
1236 movl 104(%esp),%eax /*(stack contains: threadRootMethod,blkend,blkpos,blkbegin,was native, data(64kB),collector,ret,env,class,frame stack info of stub, we want the frame stack info of thestub*/
1239 push %edx /*esp+8*/ /*position of return address of native stub*/
1240 call builtin_asm_get_stackframeinfo
1241 /* movl (%eax),%eax*/ /*TEST*/
1242 push 0(%eax) /*esp+4*/ /*address of frame info block*/
1249 call i386_native_stub_debug
1252 push %edx /*esp+0*/ /*return adress out of native stub*/
1253 call codegen_findmethod /*find calling java method, this one is still to be skipped (==SecurityManager.getClassContext (or .currentClassLoader)*/
1257 movl MethodPointer(%eax),%eax
1259 call temporaryGetClassContextHelper
1261 call traverseStackInfo
1266 movl MethodPointer(%eax),%ebx
1267 movl offclassmethodinfo(%ebx),%ecx
1272 mov 8(%esp),%ebx /*pos of return adress */
1273 add FrameSize(%eax),%ebx
1274 add $4,%ebx /*adress of new return adress (out of Securitymanager.*/
1278 /* by now we have skipped this method call*/
1280 getClassContext_next:
1283 movl %eax,(%esp) /*return adress*/
1285 call codegen_findmethod
1289 add FrameSize(%eax),%ebx
1291 mov %ebx,8(%esp) /*store adress of next return adress*/
1292 getClassContext_nextRetStored:
1294 mov MethodPointer(%eax),%ecx /*get struct methodinfo*/
1297 je getClassContext_nativeCall
1298 /*save class pointer*/
1300 getClassContext_saveClassPointer:
1301 movl 20(%esp),%ebx /*get temporary memory adress in stack*/
1302 movl offclassmethodinfo(%ecx),%edx /* get class pointer of method*/
1303 movl %edx,(%ebx) /*save */
1304 sub $4,%ebx /*calculate next position */
1305 movl %ebx,20(%esp) /* check if the new adress would overwrite our working data */
1307 je getClassContext_incStack
1308 getClassContext_checkLeave:
1310 cmp 12(%esp),%ecx /*check if we reached the toplevel method of our thread*/
1311 je getClassContext_leave /*yes ->leave*/
1315 call temporaryGetClassContextHelper
1319 jmp getClassContext_next /*continue*/
1322 getClassContext_nativeCall:
1324 movl 4(%esp),%eax /*get top most element on stackframe help information stack*/
1326 jz getClassContext_leave
1335 je getClassContext_checkLeave
1336 jmp getClassContext_saveClassPointer
1338 getClassContext_incStack:
1339 /*make another 64 in our temporary storage free and store the workingdata */
1341 subl $40,%esp /*should be 32*/
1353 jmp getClassContext_checkLeave /* continue */
1355 getClassContext_leave:
1358 call temporaryGetClassContextHelper*/
1360 /*call collector function with begin/end of temporary classarray*/
1369 /* free stack memory of this function*/
1375 asm_throw_and_handle_exception:
1376 sub $20,%esp /*build stack frame*/
1377 mov %ecx,16(%esp) /*save eip of problem */
1379 movl $0,12(%esp) /*internal function -> no function description */
1380 call builtin_asm_get_stackframeinfo
1388 /* mov string_java_lang_NullPointerException,%eax
1398 jmp asm_handle_exception
1399 ret /*should never be reached */
1401 asm_throw_and_handle_hardware_arithmetic_exception:
1402 sub $24,%esp /*build stack frame*/
1403 mov %ecx,20(%esp) /*save eip of problem */
1405 movl $0,16(%esp) /*internal function -> no function description */
1406 call builtin_asm_get_stackframeinfo
1414 mov string_java_lang_ArithmeticException,%eax
1416 mov string_java_lang_ArithmeticException_message,%eax
1419 call new_exception_message
1428 jmp asm_handle_exception
1429 ret /*should never be reached */
1432 /*optimize a littlebit */
1436 call i386_native_stub_debug
1440 mov offclassinit(%eax),%ecx /* get initialized flag */
1442 jnz L_builtin_new_noinit
1444 sub $16,%esp /* build stack frame (4 * 4 bytes) */
1449 call builtin_asm_get_stackframeinfo
1466 jmp L_builtin_new_patch
1469 L_builtin_new_noinit:
1474 /*jmp L_builtin_new_patch*/
1476 L_builtin_new_patch:
1477 /*add patching code here */
1478 lea builtin_new,%edx
1480 mov %edx,-6(%ecx) /*patch calling instruction, t directly call builtin_new the next time*/
1488 push %ebp /*(%ebp-4)*/
1491 push %edi /*(%ebp-8)*/
1492 push %esi /*(%ebp-12)*/
1493 push %ebx /*(%ebp-16)*/
1494 call builtin_asm_get_stackframeinfo
1496 pushl 0(%eax) /*(%ebp-20)*/
1498 call builtin_asm_get_threadrootmethod
1499 pushl %eax /*(%ebp-24)*/
1502 asm_get_stackTraceLoop:
1503 call codegen_findmethod
1506 pushl $1 /*no indent*/
1511 get_stackTrace_line:
1512 movl LineNumberTableSize(%esi),%ecx
1513 test %ecx,%ecx /* skip if empty line table */
1514 je get_stackTrace_noLineInfo
1516 movl LineNumberTableStart(%esi),%ebx
1518 get_stackTrace_lineLoop:
1519 cmp %edx,LinePC(%ebx)
1520 jg get_stackTrace_nextLineInfo
1522 pushl LineLine(%ebx)
1523 jmp get_stackTrace_cont
1525 get_stackTrace_nextLineInfo:
1526 lea LineEntrySize(%ebx),%ebx
1530 jne get_stackTrace_lineLoop
1532 get_stackTrace_noLineInfo:
1536 get_stackTrace_cont:
1538 pushl MethodPointer(%esi)
1539 pushl $0 /*8(%ebp)*/ /*exception ptr*/
1540 call builtin_trace_exception
1543 movl MethodPointer(%esi),%eax
1546 je get_stackTrace_nat
1549 je get_stackTrace_leave
1551 mov FrameSize(%esi),%eax
1555 jmp asm_get_stackTraceLoop
1561 je get_stackTrace_leave
1568 jmp asm_get_stackTraceLoop
1570 get_stackTrace_leave:
1576 call builtin_stacktrace_copy
1586 asm_getclassvalues_atomic:
1588 mov 4(%esp),%ecx /* super */
1589 mov 8(%esp),%edx /* sub */
1591 mov offbaseval(%ecx),%eax
1592 mov offdiffval(%ecx),%ecx
1593 mov offbaseval(%edx),%edx
1596 mov 16(%esp),%ebx /* out */
1597 mov %eax,offcast_super_baseval(%ebx)
1598 mov %ecx,offcast_super_diffval(%ebx)
1599 mov %edx,offcast_sub_baseval(%ebx)
1605 asm_criticalsections:
1606 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1609 .long _crit_restart1
1612 .long _crit_restart2
1617 * These are local overrides for various environment variables in Emacs.
1618 * Please do not remove this and leave it at the end of the file, where
1619 * Emacs will automagically detect them.
1620 * ---------------------------------------------------------------------
1623 * indent-tabs-mode: t