1 /* vm/jit/powerpc/asmpart.S - Java-C interface functions for powerpc
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.text; 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
31 $Id: asmpart.S 1709 2004-12-06 15:36:50Z twisti $
36 #include "vm/jit/powerpc/offsets.h"
37 #include "vm/jit/powerpc/asmoffsets.h"
56 .globl _asm_calljavafunction
57 .globl _asm_calljavafunction2
58 .globl _asm_calljavafunction2long
59 .globl _asm_calljavafunction2double
60 .globl _asm_call_jit_compiler
63 .globl _asm_handle_nat_exception
64 .globl _asm_handle_exception
65 .globl _asm_check_clinit
66 .globl _asm_builtin_checkarraycast
67 .globl _asm_builtin_aastore
68 .globl _builtin_canstore
69 .globl _builtin_trace_exception
70 .globl _builtin_monitorenter
71 .globl _builtin_monitorexit
74 .globl _builtin_checkarraycast
75 .globl _asm_builtin_monitorenter
76 .globl _asm_builtin_monitorexit
77 .globl _asm_builtin_idiv
78 .globl _asm_builtin_irem
79 .globl _asm_builtin_ldiv
80 .globl _asm_builtin_lrem
81 .globl _asm_cacheflush
82 .globl _asm_initialize_thread_stack
83 .globl _asm_perform_threadswitch
84 .globl _asm_switchstackandcall
85 .globl _asm_criticalsections
86 .globl _asm_getclassvalues_atomic
88 .globl _string_java_lang_NullPointerException
89 .globl _string_java_lang_ArrayIndexOutOfBoundsException
90 .globl _string_java_lang_ArrayStoreException
91 .globl _string_java_lang_ArithmeticException
92 .globl _string_java_lang_ArithmeticException_message
93 .globl _string_java_lang_ClassCastException
95 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
96 .globl _builtin_asm_get_exceptionptrptr
98 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
102 .globl _builtin_throw_exception
107 .globl _new_classcastexception
108 .globl _new_nullpointerexception
109 .globl _new_arrayindexoutofboundsexception
110 .globl _new_arraystoreexception
111 .globl _new_arithmeticexception
124 .long _builtin_throw_exception
126 builtin_traceexception:
127 .long _builtin_trace_exception
128 builtin_monitorenter:
129 .long _builtin_monitorenter
131 .long _builtin_monitorexit
138 .long _builtin_canstore
139 builtincheckarraycast:
140 .long _builtin_checkarraycast
142 new_classcastexception:
143 .long _new_classcastexception
144 new_nullpointerexception:
145 .long _new_nullpointerexception
146 new_arrayindexoutofboundsexception:
147 .long _new_arrayindexoutofboundsexception
148 new_arraystoreexception:
149 .long _new_arraystoreexception
150 new_arithmeticexception:
151 .long _new_arithmeticexception
154 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
155 builtin_asm_get_exceptionptrptr:
156 .long _builtin_asm_get_exceptionptrptr
158 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
164 /********************* function asm_calljavafunction ***************************
166 * This function calls a Java-method (which possibly needs compilation) *
167 * with up to 4 address parameters. *
169 * This functions calls the JIT-compiler which eventually translates the *
170 * method into machine code. *
173 * javaobject_header *asm_calljavamethod (methodinfo *m, *
174 * void *arg1, void *arg2, void *arg3, void *arg4); *
176 *******************************************************************************/
179 .long 0 /* catch type all */
180 .long calljava_xhandler /* handler pc */
181 .long calljava_xhandler /* end pc */
182 .long _asm_calljavafunction /* start pc */
183 .long 1 /* extable size */
184 .long 0 /* fltsave */
185 .long 0 /* intsave */
188 .long 24 /* frame size */
189 .long 0 /* method pointer (pointer to name) */
190 .long 0 /* padding */
192 _asm_calljavafunction:
227 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
228 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
237 addi pv,itmp1,lo16(_asm_calljavafunction-1b)
267 // addis pv,r31,ha16(builtinthrow-0b)
268 lwz itmp1,lo16(builtinthrow-0b)(r31)
271 b calljava_regrestore
277 .long 0 /* catch type all */
278 .long calljava_xhandler2 /* handler pc */
279 .long calljava_xhandler2 /* end pc */
280 .long _asm_calljavafunction2 /* start pc */
281 .long 1 /* extable size */
282 .long 0 /* fltsave */
283 .long 0 /* intsave */
286 .long 24 /* frame size */
287 .long 0 /* method pointer (pointer to name) */
288 .long 0 /* padding */
290 _asm_calljavafunction2:
291 _asm_calljavafunction2long:
292 _asm_calljavafunction2double:
320 stw r3,36(r1) /* save method pointer for compiler */
322 mr itmp1,r6 /* pointer to arg block */
323 mr itmp2,r4 /* arg count */
326 ble calljava_argsloaded
329 lwz r3,offjniitem+4(itmp1)
331 ble calljava_argsloaded
334 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
336 ble calljava_argsloaded
340 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
342 ble calljava_argsloaded
346 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
348 ble calljava_argsloaded
352 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
353 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
362 addi pv,itmp1,lo16(_asm_calljavafunction2-1b)
364 calljava_regrestore2:
392 // addis pv,r31,ha16(builtinthrow-0b)
393 lwz itmp1,lo16(builtinthrow-0b)(r31)
396 b calljava_regrestore2
399 _asm_call_jit_compiler:
450 // addis pv,r31,ha16(jitcompile-0b)
451 lwz itmp1,lo16(jitcompile-0b)(r31)
497 /********************* function asm_handle_exception ***************************
499 * This function handles an exception. It does not use the usual calling *
500 * conventions. The exception pointer is passed in REG_ITMP1 and the *
501 * pc from the exception raising position is passed in REG_ITMP2. It searches *
502 * the local exception table for a handler. If no one is found, it unwinds *
503 * stacks and continues searching the callers. *
505 * void asm_handle_exception (exceptionptr, exceptionpc); *
507 *******************************************************************************/
509 _asm_handle_nat_exception:
517 bne _asm_handle_exception
522 _asm_handle_exception:
552 lwz r3,0*4(r1) /* exception pointer */
553 lwz r4,MethodPointer(pv) /* method pointer */
554 mr r5,xpc /* exception pc */
556 li r6,0 /* line number */
557 li r7,4 /* set no unwind flag */
562 lwz itmp1,lo16(builtin_traceexception-0b)(itmp1)
564 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
570 lwz xptr,0*4(r1) /* restore xptr */
575 lwz r3,ExTableSize(pv) /* r3 = exception table size */
576 mr. r3,r3 /* if empty table skip */
579 addi r4,pv,ExTableStart /* r4 = start of exception table */
582 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
583 cmplw r5,xpc /* (startpc <= xpc) */
585 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
586 cmplw xpc,r5 /* (xpc < endpc) */
588 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
592 lwz itmp3,offclassloaded(r7)
596 addi r1,r1,-16*4 /* allocate stack */
597 stw r3,7*4(r1) /* save used registers */
598 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
606 mr r3,r7 /* arg1 = exceptionclass */
610 lwz itmp1,lo16(class_load-0b)(itmp1)
625 lwz itmp3,offclasslinked(r7)
627 addi r1,r1,-16*4 /* allocate stack */
631 stw r3,7*4(r1) /* save used registers */
632 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
639 mr r3,r7 /* arg1 = exceptionclass */
643 lwz itmp1,lo16(class_link-0b)(itmp1)
659 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
660 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
661 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
662 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
663 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
665 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
666 cmplw r6,r7 /* xptr is instanceof catchtype */
668 bgt ex_table_cont /* if (false) continue */
671 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
700 addi r4,r4,ExEntrySize
705 mr. r2,r2 /* if here the first time, then */
706 beq ex_already_cleared
707 addi r1,r1,18*4 /* deallocate stack and */
708 li r2,0 /* clear the no unwind flag */
729 lwz itmp1,lo16(builtin_monitorexit-0b)(itmp1)
745 lwz r3,FrameSize(pv) /* r3 = frame size */
746 add r1,r1,r3 /* unwind stack */
747 mr r3,r1 /* r3 = pointer to save area */
748 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
750 bne ex_no_restore /* if (leaf) skip */
751 lwz r4,8(r3) /* restore ra */
754 mflr r4 /* the new xpc is ra */
756 lwz r4,IntSave(pv) /* r4 = saved int register count */
760 addi r5,r5,lo16(ex_int2-ex_int1)
782 addi r5,r5,lo16(ex_flt2-ex_flt1)
812 /********************* asm_check_clinit ****************************************
814 * call static class initializer for PUT/GETSTATIC instructions *
816 *******************************************************************************/
820 lwz itmp2,offclassinit(itmp1)
826 addi r1,r1,-(26*8) /* keep stack 16-bytes aligned */
828 stw r3,4*8(r1) /* save argument registers */
829 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
830 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
852 lwz itmp1,lo16(class_init-0b)(pv)
855 mr itmp1,r3 /* save return value in temp register */
884 mr. itmp1,itmp1 /* check for an exception */
885 beq L_initializererror
891 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
894 addi r1,r1,-4*8 /* preserve linkage area (24 bytes) */
895 lwz itmp1,lo16(builtin_asm_get_exceptionptrptr-0b)(pv)
902 lwz r3,lo16(_exceptionptr-0b)(pv)
905 lwz xptr,0(r3) /* get the exception pointer */
907 stw r0,0(r3) /* clear the exception pointer */
910 b _asm_handle_nat_exception
913 /******************* function asm_builtin_checkarraycast ***********************
915 * Does the cast check and eventually throws an exception *
917 *******************************************************************************/
919 _asm_builtin_checkarraycast:
926 lwz itmp1,lo16(builtincheckarraycast-0b)(pv)
943 lwz itmp1,lo16(new_classcastexception-0b)(pv)
951 b _asm_handle_nat_exception
954 /******************* function asm_builtin_aastore ******************************
956 * Does the cast check and eventually throws an exception *
958 *******************************************************************************/
960 _asm_builtin_aastore:
968 lwz itmp1,offarraysize(r3)
976 // addis pv,r31,ha16(builtincanstore-0b)
977 lwz itmp1,lo16(builtincanstore-0b)(pv)
988 stw itmp2,offobjarrdata(itmp1)
995 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1003 b _asm_handle_nat_exception
1009 addi r1,r1,-(24+2*4)
1010 lwz itmp1,lo16(new_arrayindexoutofboundsexception-0b)(pv)
1012 mr r3,r4 /* move index into a0 */
1019 b _asm_handle_nat_exception
1025 lwz itmp1,lo16(new_arraystoreexception-0b)(pv)
1033 b _asm_handle_nat_exception
1036 _asm_builtin_monitorenter:
1038 lwz itmp2,lo16(builtin_monitorenter-0b)(pv)
1048 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1054 /* addi xpc,r0,-4 */
1059 b _asm_handle_nat_exception
1062 _asm_builtin_monitorexit:
1064 lwz itmp2,lo16(builtin_monitorexit-0b)(pv)
1074 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1080 /* addi xpc,r0,-4 */
1085 b _asm_handle_nat_exception
1106 addi r1,r1,-(24+2*4)
1107 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1115 b _asm_handle_nat_exception
1133 mullw itmp3,itmp3,r4
1140 addi r1,r1,-(24+2*4)
1141 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1149 b _asm_handle_nat_exception
1156 lwz itmp1,lo16(builtin_ldiv-0b)(pv)
1163 addi r1,r1,-(24+2*4)
1164 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1172 b _asm_handle_nat_exception
1179 lwz itmp1,lo16(builtin_lrem-0b)(pv)
1186 addi r1,r1,-(24+2*4)
1187 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1195 b _asm_handle_nat_exception
1226 _asm_initialize_thread_stack:
1256 lfd f0,lo16(doublezero-0b)(r3)
1282 _asm_perform_threadswitch:
1374 _asm_switchstackandcall:
1392 _asm_getclassvalues_atomic:
1395 lwz r6,offbaseval(r3)
1396 lwz r7,offdiffval(r3)
1397 lwz r8,offbaseval(r4)
1399 stw r6,offcast_super_baseval(r5)
1400 stw r7,offcast_super_diffval(r5)
1401 stw r8,offcast_sub_baseval(r5)
1406 _asm_criticalsections:
1407 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1410 .long _crit_restart1
1413 .long _crit_restart2
1419 * These are local overrides for various environment variables in Emacs.
1420 * Please do not remove this and leave it at the end of the file, where
1421 * Emacs will automagically detect them.
1422 * ---------------------------------------------------------------------
1425 * indent-tabs-mode: t