1 /* 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 1501 2004-11-12 16:36:13Z twisti $
36 #include "jit/powerpc/offsets.h"
39 #define MethodPointer -8
45 #define ExTableSize -32
46 #define ExTableStart -32
48 #define ExEntrySize -16
51 #define ExHandlerPC -12
52 #define ExCatchType -16
70 .globl _asm_calljavafunction
71 .globl _asm_calljavafunction2
72 .globl _asm_calljavafunction2long
73 .globl _asm_calljavafunction2double
74 .globl _asm_call_jit_compiler
77 .globl _asm_handle_nat_exception
78 .globl _asm_handle_exception
79 .globl _asm_check_clinit
80 .globl _asm_builtin_checkarraycast
81 .globl _asm_builtin_aastore
82 .globl _builtin_canstore
83 .globl _builtin_trace_exception
84 .globl _builtin_monitorenter
85 .globl _builtin_monitorexit
88 .globl _builtin_checkarraycast
89 .globl _asm_builtin_monitorenter
90 .globl _asm_builtin_monitorexit
91 .globl _asm_builtin_idiv
92 .globl _asm_builtin_irem
93 .globl _asm_builtin_ldiv
94 .globl _asm_builtin_lrem
95 .globl _asm_cacheflush
96 .globl _asm_initialize_thread_stack
97 .globl _asm_perform_threadswitch
98 .globl _asm_switchstackandcall
99 .globl _asm_criticalsections
100 .globl _asm_getclassvalues_atomic
102 .globl _string_java_lang_NullPointerException
103 .globl _string_java_lang_ArrayIndexOutOfBoundsException
104 .globl _string_java_lang_ArrayStoreException
105 .globl _string_java_lang_ArithmeticException
106 .globl _string_java_lang_ArithmeticException_message
107 .globl _string_java_lang_ClassCastException
109 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
110 .globl _builtin_asm_get_exceptionptrptr
112 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
113 .globl __exceptionptr
116 .globl _builtin_throw_exception
121 .globl _new_classcastexception
122 .globl _new_nullpointerexception
123 .globl _new_arrayindexoutofboundsexception
124 .globl _new_arraystoreexception
125 .globl _new_arithmeticexception
138 .long _builtin_throw_exception
140 builtin_traceexception:
141 .long _builtin_trace_exception
142 builtin_monitorenter:
143 .long _builtin_monitorenter
145 .long _builtin_monitorexit
152 .long _builtin_canstore
153 builtincheckarraycast:
154 .long _builtin_checkarraycast
156 new_classcastexception:
157 .long _new_classcastexception
158 new_nullpointerexception:
159 .long _new_nullpointerexception
160 new_arrayindexoutofboundsexception:
161 .long _new_arrayindexoutofboundsexception
162 new_arraystoreexception:
163 .long _new_arraystoreexception
164 new_arithmeticexception:
165 .long _new_arithmeticexception
168 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
169 builtin_asm_get_exceptionptrptr:
170 .long _builtin_asm_get_exceptionptrptr
172 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
178 /********************* function asm_calljavafunction ***************************
180 * This function calls a Java-method (which possibly needs compilation) *
181 * with up to 4 address parameters. *
183 * This functions calls the JIT-compiler which eventually translates the *
184 * method into machine code. *
187 * javaobject_header *asm_calljavamethod (methodinfo *m, *
188 * void *arg1, void *arg2, void *arg3, void *arg4); *
190 *******************************************************************************/
193 .long 0 /* catch type all */
194 .long calljava_xhandler /* handler pc */
195 .long calljava_xhandler /* end pc */
196 .long _asm_calljavafunction /* start pc */
197 .long 1 /* extable size */
198 .long 0 /* fltsave */
199 .long 0 /* intsave */
202 .long 24 /* frame size */
203 .long 0 /* method pointer (pointer to name) */
204 .long 0 /* padding */
206 _asm_calljavafunction:
241 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
242 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
251 addi pv,itmp1,lo16(_asm_calljavafunction-1b)
281 // addis pv,r31,ha16(builtinthrow-0b)
282 lwz itmp1,lo16(builtinthrow-0b)(r31)
285 b calljava_regrestore
291 .long 0 /* catch type all */
292 .long calljava_xhandler2 /* handler pc */
293 .long calljava_xhandler2 /* end pc */
294 .long _asm_calljavafunction2 /* start pc */
295 .long 1 /* extable size */
296 .long 0 /* fltsave */
297 .long 0 /* intsave */
300 .long 24 /* frame size */
301 .long 0 /* method pointer (pointer to name) */
302 .long 0 /* padding */
304 _asm_calljavafunction2:
305 _asm_calljavafunction2long:
306 _asm_calljavafunction2double:
334 stw r3,36(r1) /* save method pointer for compiler */
336 mr itmp1,r6 /* pointer to arg block */
337 mr itmp2,r4 /* arg count */
340 ble calljava_argsloaded
343 lwz r3,offjniitem+4(itmp1)
345 ble calljava_argsloaded
348 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
350 ble calljava_argsloaded
354 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
356 ble calljava_argsloaded
360 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
362 ble calljava_argsloaded
366 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
367 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
376 addi pv,itmp1,lo16(_asm_calljavafunction2-1b)
378 calljava_regrestore2:
406 // addis pv,r31,ha16(builtinthrow-0b)
407 lwz itmp1,lo16(builtinthrow-0b)(r31)
410 b calljava_regrestore2
413 _asm_call_jit_compiler:
464 // addis pv,r31,ha16(jitcompile-0b)
465 lwz itmp1,lo16(jitcompile-0b)(r31)
511 /********************* function asm_handle_exception ***************************
513 * This function handles an exception. It does not use the usual calling *
514 * conventions. The exception pointer is passed in REG_ITMP1 and the *
515 * pc from the exception raising position is passed in REG_ITMP2. It searches *
516 * the local exception table for a handler. If no one is found, it unwinds *
517 * stacks and continues searching the callers. *
519 * void asm_handle_exception (exceptionptr, exceptionpc); *
521 *******************************************************************************/
523 _asm_handle_nat_exception:
531 bne _asm_handle_exception
536 _asm_handle_exception:
566 lwz r3,0*4(r1) /* exception pointer */
567 lwz r4,MethodPointer(pv) /* method pointer */
568 mr r5,xpc /* exception pc */
570 li r6,0 /* line number */
571 li r7,4 /* set no unwind flag */
576 lwz itmp1,lo16(builtin_traceexception-0b)(itmp1)
578 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
584 lwz xptr,0*4(r1) /* restore xptr */
589 lwz r3,ExTableSize(pv) /* r3 = exception table size */
590 mr. r3,r3 /* if empty table skip */
593 addi r4,pv,ExTableStart /* r4 = start of exception table */
596 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
597 cmplw r5,xpc /* (startpc <= xpc) */
599 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
600 cmplw xpc,r5 /* (xpc < endpc) */
602 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
606 lwz itmp3,offclassloaded(r7)
610 addi r1,r1,-16*4 /* allocate stack */
611 stw r3,7*4(r1) /* save used registers */
612 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
620 mr r3,r7 /* arg1 = exceptionclass */
624 lwz itmp1,lo16(class_load-0b)(itmp1)
639 lwz itmp3,offclasslinked(r7)
641 addi r1,r1,-16*4 /* allocate stack */
645 stw r3,7*4(r1) /* save used registers */
646 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
653 mr r3,r7 /* arg1 = exceptionclass */
657 lwz itmp1,lo16(class_link-0b)(itmp1)
673 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
674 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
675 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
676 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
677 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
679 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
680 cmplw r6,r7 /* xptr is instanceof catchtype */
682 bgt ex_table_cont /* if (false) continue */
685 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
714 addi r4,r4,ExEntrySize
719 mr. r2,r2 /* if here the first time, then */
720 beq ex_already_cleared
721 addi r1,r1,18*4 /* deallocate stack and */
722 li r2,0 /* clear the no unwind flag */
743 lwz itmp1,lo16(builtin_monitorexit-0b)(itmp1)
759 lwz r3,FrameSize(pv) /* r3 = frame size */
760 add r1,r1,r3 /* unwind stack */
761 mr r3,r1 /* r3 = pointer to save area */
762 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
764 bne ex_no_restore /* if (leaf) skip */
765 lwz r4,8(r3) /* restore ra */
768 mflr r4 /* the new xpc is ra */
770 lwz r4,IntSave(pv) /* r4 = saved int register count */
774 addi r5,r5,lo16(ex_int2-ex_int1)
796 addi r5,r5,lo16(ex_flt2-ex_flt1)
826 /********************* asm_check_clinit ****************************************
828 * call static class initializer for PUT/GETSTATIC instructions *
830 *******************************************************************************/
834 lwz itmp2,offclassinit(itmp1)
840 addi r1,r1,-(26*8) /* keep stack 16-bytes aligned */
842 stw r3,4*8(r1) /* save argument registers */
843 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
844 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
866 lwz itmp1,lo16(class_init-0b)(pv)
869 mr itmp1,r3 /* save return value in temp register */
898 mr. itmp1,itmp1 /* check for an exception */
899 beq L_initializererror
905 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
908 addi r1,r1,-4*8 /* preserve linkage area (24 bytes) */
909 lwz itmp1,lo16(builtin_asm_get_exceptionptrptr-0b)(pv)
916 lwz r3,lo16(_exceptionptr-0b)(pv)
919 lwz xptr,0(r3) /* get the exception pointer */
921 stw r0,0(r3) /* clear the exception pointer */
924 b _asm_handle_nat_exception
927 /******************* function asm_builtin_checkarraycast ***********************
929 * Does the cast check and eventually throws an exception *
931 *******************************************************************************/
933 _asm_builtin_checkarraycast:
940 lwz itmp1,lo16(builtincheckarraycast-0b)(pv)
957 lwz itmp1,lo16(new_classcastexception-0b)(pv)
965 b _asm_handle_nat_exception
968 /******************* function asm_builtin_aastore ******************************
970 * Does the cast check and eventually throws an exception *
972 *******************************************************************************/
974 _asm_builtin_aastore:
982 lwz itmp1,offarraysize(r3)
990 // addis pv,r31,ha16(builtincanstore-0b)
991 lwz itmp1,lo16(builtincanstore-0b)(pv)
1001 beq nb_aastore_store
1002 stw itmp2,offobjarrdata(itmp1)
1009 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1017 b _asm_handle_nat_exception
1023 addi r1,r1,-(24+2*4)
1024 lwz itmp1,lo16(new_arrayindexoutofboundsexception-0b)(pv)
1026 mr r3,r4 /* move index into a0 */
1033 b _asm_handle_nat_exception
1039 lwz itmp1,lo16(new_arraystoreexception-0b)(pv)
1047 b _asm_handle_nat_exception
1050 _asm_builtin_monitorenter:
1052 lwz itmp2,lo16(builtin_monitorenter-0b)(pv)
1062 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1068 /* addi xpc,r0,-4 */
1073 b _asm_handle_nat_exception
1076 _asm_builtin_monitorexit:
1078 lwz itmp2,lo16(builtin_monitorexit-0b)(pv)
1088 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1094 /* addi xpc,r0,-4 */
1099 b _asm_handle_nat_exception
1120 addi r1,r1,-(24+2*4)
1121 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1129 b _asm_handle_nat_exception
1147 mullw itmp3,itmp3,r4
1154 addi r1,r1,-(24+2*4)
1155 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1163 b _asm_handle_nat_exception
1170 lwz itmp1,lo16(builtin_ldiv-0b)(pv)
1177 addi r1,r1,-(24+2*4)
1178 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1186 b _asm_handle_nat_exception
1193 lwz itmp1,lo16(builtin_lrem-0b)(pv)
1200 addi r1,r1,-(24+2*4)
1201 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1209 b _asm_handle_nat_exception
1240 _asm_initialize_thread_stack:
1270 lfd f0,lo16(doublezero-0b)(r3)
1296 _asm_perform_threadswitch:
1388 _asm_switchstackandcall:
1406 _asm_getclassvalues_atomic:
1409 lwz r6,offbaseval(r3)
1410 lwz r7,offdiffval(r3)
1411 lwz r8,offbaseval(r4)
1413 stw r6,offcast_super_baseval(r5)
1414 stw r7,offcast_super_diffval(r5)
1415 stw r8,offcast_sub_baseval(r5)
1420 _asm_criticalsections:
1421 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1424 .long _crit_restart1
1427 .long _crit_restart2
1433 * These are local overrides for various environment variables in Emacs.
1434 * Please do not remove this and leave it at the end of the file, where
1435 * Emacs will automagically detect them.
1436 * ---------------------------------------------------------------------
1439 * indent-tabs-mode: t