1 /* vm/jit/powerpc/asmpart.S - Java-C interface functions for powerpc
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.text; 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
30 $Id: asmpart.S 1735 2004-12-07 14:33:27Z twisti $
35 #include "vm/jit/powerpc/offsets.h"
36 #include "vm/jit/powerpc/asmoffsets.h"
55 .globl _asm_calljavafunction
56 .globl _asm_calljavafunction2
57 .globl _asm_calljavafunction2long
58 .globl _asm_calljavafunction2double
59 .globl _asm_call_jit_compiler
62 .globl _asm_handle_nat_exception
63 .globl _asm_handle_exception
64 .globl _asm_check_clinit
65 .globl _asm_builtin_checkarraycast
66 .globl _asm_builtin_aastore
67 .globl _builtin_canstore
68 .globl _builtin_trace_exception
69 .globl _builtin_monitorenter
70 .globl _builtin_monitorexit
73 .globl _builtin_checkarraycast
74 .globl _asm_builtin_monitorenter
75 .globl _asm_builtin_monitorexit
76 .globl _asm_builtin_idiv
77 .globl _asm_builtin_irem
78 .globl _asm_builtin_ldiv
79 .globl _asm_builtin_lrem
80 .globl _asm_cacheflush
81 .globl _asm_initialize_thread_stack
82 .globl _asm_perform_threadswitch
83 .globl _asm_switchstackandcall
84 .globl _asm_criticalsections
85 .globl _asm_getclassvalues_atomic
87 .globl _string_java_lang_NullPointerException
88 .globl _string_java_lang_ArrayIndexOutOfBoundsException
89 .globl _string_java_lang_ArrayStoreException
90 .globl _string_java_lang_ArithmeticException
91 .globl _string_java_lang_ArithmeticException_message
92 .globl _string_java_lang_ClassCastException
94 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
95 .globl _builtin_asm_get_exceptionptrptr
97 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
101 .globl _builtin_throw_exception
106 .globl _new_classcastexception
107 .globl _new_nullpointerexception
108 .globl _new_arrayindexoutofboundsexception
109 .globl _new_arraystoreexception
110 .globl _new_arithmeticexception
123 .long _builtin_throw_exception
125 builtin_traceexception:
126 .long _builtin_trace_exception
127 builtin_monitorenter:
128 .long _builtin_monitorenter
130 .long _builtin_monitorexit
137 .long _builtin_canstore
138 builtincheckarraycast:
139 .long _builtin_checkarraycast
141 new_classcastexception:
142 .long _new_classcastexception
143 new_nullpointerexception:
144 .long _new_nullpointerexception
145 new_arrayindexoutofboundsexception:
146 .long _new_arrayindexoutofboundsexception
147 new_arraystoreexception:
148 .long _new_arraystoreexception
149 new_arithmeticexception:
150 .long _new_arithmeticexception
153 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
154 builtin_asm_get_exceptionptrptr:
155 .long _builtin_asm_get_exceptionptrptr
157 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
163 /********************* function asm_calljavafunction ***************************
165 * This function calls a Java-method (which possibly needs compilation) *
166 * with up to 4 address parameters. *
168 * This functions calls the JIT-compiler which eventually translates the *
169 * method into machine code. *
172 * javaobject_header *asm_calljavamethod (methodinfo *m, *
173 * void *arg1, void *arg2, void *arg3, void *arg4); *
175 *******************************************************************************/
178 .long 0 /* catch type all */
179 .long calljava_xhandler /* handler pc */
180 .long calljava_xhandler /* end pc */
181 .long _asm_calljavafunction /* start pc */
182 .long 1 /* extable size */
183 .long 0 /* fltsave */
184 .long 0 /* intsave */
187 .long 24 /* frame size */
188 .long 0 /* method pointer (pointer to name) */
189 .long 0 /* padding */
191 _asm_calljavafunction:
226 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
227 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
236 addi pv,itmp1,lo16(_asm_calljavafunction-1b)
266 // addis pv,r31,ha16(builtinthrow-0b)
267 lwz itmp1,lo16(builtinthrow-0b)(r31)
270 b calljava_regrestore
276 .long 0 /* catch type all */
277 .long calljava_xhandler2 /* handler pc */
278 .long calljava_xhandler2 /* end pc */
279 .long _asm_calljavafunction2 /* start pc */
280 .long 1 /* extable size */
281 .long 0 /* fltsave */
282 .long 0 /* intsave */
285 .long 24 /* frame size */
286 .long 0 /* method pointer (pointer to name) */
287 .long 0 /* padding */
289 _asm_calljavafunction2:
290 _asm_calljavafunction2long:
291 _asm_calljavafunction2double:
319 stw r3,36(r1) /* save method pointer for compiler */
321 mr itmp1,r6 /* pointer to arg block */
322 mr itmp2,r4 /* arg count */
325 ble calljava_argsloaded
328 lwz r3,offjniitem+4(itmp1)
330 ble calljava_argsloaded
333 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
335 ble calljava_argsloaded
339 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
341 ble calljava_argsloaded
345 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
347 ble calljava_argsloaded
351 // addis mptr,r31,ha16(_asm_call_jit_compiler-0b)
352 addi mptr,r31,lo16(_asm_call_jit_compiler-0b)
361 addi pv,itmp1,lo16(_asm_calljavafunction2-1b)
363 calljava_regrestore2:
391 // addis pv,r31,ha16(builtinthrow-0b)
392 lwz itmp1,lo16(builtinthrow-0b)(r31)
395 b calljava_regrestore2
398 _asm_call_jit_compiler:
449 // addis pv,r31,ha16(jitcompile-0b)
450 lwz itmp1,lo16(jitcompile-0b)(r31)
496 /********************* function asm_handle_exception ***************************
498 * This function handles an exception. It does not use the usual calling *
499 * conventions. The exception pointer is passed in REG_ITMP1 and the *
500 * pc from the exception raising position is passed in REG_ITMP2. It searches *
501 * the local exception table for a handler. If no one is found, it unwinds *
502 * stacks and continues searching the callers. *
504 * void asm_handle_exception (exceptionptr, exceptionpc); *
506 *******************************************************************************/
508 _asm_handle_nat_exception:
516 bne _asm_handle_exception
521 _asm_handle_exception:
551 lwz r3,0*4(r1) /* exception pointer */
552 lwz r4,MethodPointer(pv) /* method pointer */
553 mr r5,xpc /* exception pc */
555 li r6,0 /* line number */
556 li r7,4 /* set no unwind flag */
561 lwz itmp1,lo16(builtin_traceexception-0b)(itmp1)
563 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
569 lwz xptr,0*4(r1) /* restore xptr */
574 lwz r3,ExTableSize(pv) /* r3 = exception table size */
575 mr. r3,r3 /* if empty table skip */
578 addi r4,pv,ExTableStart /* r4 = start of exception table */
581 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
582 cmplw r5,xpc /* (startpc <= xpc) */
584 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
585 cmplw xpc,r5 /* (xpc < endpc) */
587 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
591 lwz itmp3,offclassloaded(r7)
595 addi r1,r1,-16*4 /* allocate stack */
596 stw r3,7*4(r1) /* save used registers */
597 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
605 mr r3,r7 /* arg1 = exceptionclass */
609 lwz itmp1,lo16(class_load-0b)(itmp1)
624 lwz itmp3,offclasslinked(r7)
626 addi r1,r1,-16*4 /* allocate stack */
630 stw r3,7*4(r1) /* save used registers */
631 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
638 mr r3,r7 /* arg1 = exceptionclass */
642 lwz itmp1,lo16(class_link-0b)(itmp1)
658 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
659 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
660 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
661 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
662 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
664 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
665 cmplw r6,r7 /* xptr is instanceof catchtype */
667 bgt ex_table_cont /* if (false) continue */
670 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
699 addi r4,r4,ExEntrySize
704 mr. r2,r2 /* if here the first time, then */
705 beq ex_already_cleared
706 addi r1,r1,18*4 /* deallocate stack and */
707 li r2,0 /* clear the no unwind flag */
728 lwz itmp1,lo16(builtin_monitorexit-0b)(itmp1)
744 lwz r3,FrameSize(pv) /* r3 = frame size */
745 add r1,r1,r3 /* unwind stack */
746 mr r3,r1 /* r3 = pointer to save area */
747 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
749 bne ex_no_restore /* if (leaf) skip */
750 lwz r4,8(r3) /* restore ra */
753 mflr r4 /* the new xpc is ra */
755 lwz r4,IntSave(pv) /* r4 = saved int register count */
759 addi r5,r5,lo16(ex_int2-ex_int1)
781 addi r5,r5,lo16(ex_flt2-ex_flt1)
811 /********************* asm_check_clinit ****************************************
813 * call static class initializer for PUT/GETSTATIC instructions *
815 *******************************************************************************/
819 lwz itmp2,offclassinit(itmp1)
825 addi r1,r1,-(26*8) /* keep stack 16-bytes aligned */
827 stw r3,4*8(r1) /* save argument registers */
828 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
829 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
851 lwz itmp1,lo16(class_init-0b)(pv)
854 mr itmp1,r3 /* save return value in temp register */
883 mr. itmp1,itmp1 /* check for an exception */
884 beq L_initializererror
890 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
893 addi r1,r1,-4*8 /* preserve linkage area (24 bytes) */
894 lwz itmp1,lo16(builtin_asm_get_exceptionptrptr-0b)(pv)
901 lwz r3,lo16(_exceptionptr-0b)(pv)
904 lwz xptr,0(r3) /* get the exception pointer */
906 stw r0,0(r3) /* clear the exception pointer */
909 b _asm_handle_nat_exception
912 /******************* function asm_builtin_checkarraycast ***********************
914 * Does the cast check and eventually throws an exception *
916 *******************************************************************************/
918 _asm_builtin_checkarraycast:
925 lwz itmp1,lo16(builtincheckarraycast-0b)(pv)
942 lwz itmp1,lo16(new_classcastexception-0b)(pv)
950 b _asm_handle_nat_exception
953 /******************* function asm_builtin_aastore ******************************
955 * Does the cast check and eventually throws an exception *
957 *******************************************************************************/
959 _asm_builtin_aastore:
967 lwz itmp1,offarraysize(r3)
975 // addis pv,r31,ha16(builtincanstore-0b)
976 lwz itmp1,lo16(builtincanstore-0b)(pv)
987 stw itmp2,offobjarrdata(itmp1)
994 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1002 b _asm_handle_nat_exception
1008 addi r1,r1,-(24+2*4)
1009 lwz itmp1,lo16(new_arrayindexoutofboundsexception-0b)(pv)
1011 mr r3,r4 /* move index into a0 */
1018 b _asm_handle_nat_exception
1024 lwz itmp1,lo16(new_arraystoreexception-0b)(pv)
1032 b _asm_handle_nat_exception
1035 _asm_builtin_monitorenter:
1037 lwz itmp2,lo16(builtin_monitorenter-0b)(pv)
1047 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1053 /* addi xpc,r0,-4 */
1058 b _asm_handle_nat_exception
1061 _asm_builtin_monitorexit:
1063 lwz itmp2,lo16(builtin_monitorexit-0b)(pv)
1073 lwz itmp1,lo16(new_nullpointerexception-0b)(pv)
1079 /* addi xpc,r0,-4 */
1084 b _asm_handle_nat_exception
1105 addi r1,r1,-(24+2*4)
1106 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1114 b _asm_handle_nat_exception
1132 mullw itmp3,itmp3,r4
1139 addi r1,r1,-(24+2*4)
1140 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1148 b _asm_handle_nat_exception
1155 lwz itmp1,lo16(builtin_ldiv-0b)(pv)
1162 addi r1,r1,-(24+2*4)
1163 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1171 b _asm_handle_nat_exception
1178 lwz itmp1,lo16(builtin_lrem-0b)(pv)
1185 addi r1,r1,-(24+2*4)
1186 lwz itmp1,lo16(new_arithmeticexception-0b)(pv)
1194 b _asm_handle_nat_exception
1225 _asm_initialize_thread_stack:
1255 lfd f0,lo16(doublezero-0b)(r3)
1281 _asm_perform_threadswitch:
1373 _asm_switchstackandcall:
1391 _asm_getclassvalues_atomic:
1394 lwz r6,offbaseval(r3)
1395 lwz r7,offdiffval(r3)
1396 lwz r8,offbaseval(r4)
1398 stw r6,offcast_super_baseval(r5)
1399 stw r7,offcast_super_diffval(r5)
1400 stw r8,offcast_sub_baseval(r5)
1405 _asm_criticalsections:
1406 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1409 .long _crit_restart1
1412 .long _crit_restart2
1418 * These are local overrides for various environment variables in Emacs.
1419 * Please do not remove this and leave it at the end of the file, where
1420 * Emacs will automagically detect them.
1421 * ---------------------------------------------------------------------
1424 * indent-tabs-mode: t