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 2007 2005-03-06 23:10:47Z stefan $
35 #if defined(__LINUX__)
36 # include <asm/ppc_asm.h>
40 #include "vm/jit/powerpc/offsets.h"
41 #include "vm/jit/powerpc/asmoffsets.h"
56 #if defined(__DARWIN__)
58 /* Defines for darwin's old gnu assembler *************************************/
60 /* internal defines ***********************************************************/
62 #define asm_calljavafunction _asm_calljavafunction
63 #define asm_calljavafunction2 _asm_calljavafunction2
64 #define asm_calljavafunction2int _asm_calljavafunction2int
65 #define asm_calljavafunction2long _asm_calljavafunction2long
66 #define asm_calljavafunction2float _asm_calljavafunction2float
67 #define asm_calljavafunction2double _asm_calljavafunction2double
69 #define asm_call_jit_compiler _asm_call_jit_compiler
71 #define asm_handle_nat_exception _asm_handle_nat_exception
72 #define asm_handle_exception _asm_handle_exception
73 #define asm_handle_nullptr_exception _asm_handle_nullptr_exception
75 #define asm_check_clinit _asm_check_clinit
77 #define asm_builtin_checkarraycast _asm_builtin_checkarraycast
78 #define asm_builtin_aastore _asm_builtin_aastore
80 #define asm_builtin_monitorenter _asm_builtin_monitorenter
81 #define asm_builtin_monitorexit _asm_builtin_monitorexit
83 #define asm_builtin_idiv _asm_builtin_idiv
84 #define asm_builtin_irem _asm_builtin_irem
85 #define asm_builtin_ldiv _asm_builtin_ldiv
86 #define asm_builtin_lrem _asm_builtin_lrem
88 #define asm_cacheflush _asm_cacheflush
89 #define asm_initialize_thread_stack _asm_initialize_thread_stack
90 #define asm_perform_threadswitch _asm_perform_threadswitch
91 #define asm_switchstackandcall _asm_switchstackandcall
92 #define asm_criticalsections _asm_criticalsections
93 #define asm_getclassvalues_atomic _asm_getclassvalues_atomic
96 /* external defines ***********************************************************/
98 #define builtin_asm_get_exceptionptrptr _builtin_asm_get_exceptionptrptr
99 #define builtin_canstore _builtin_canstore
100 #define builtin_checkarraycast _builtin_checkarraycast
101 #define builtin_ldiv _builtin_ldiv
102 #define builtin_lrem _builtin_lrem
104 #if defined(USE_THREADS)
105 #define builtin_monitorenter _builtin_monitorenter
106 #define builtin_monitorexit _builtin_monitorexit
109 #define builtin_throw_exception _builtin_throw_exception
110 #define builtin_trace_exception _builtin_trace_exception
111 #define class_init _class_init
112 #define class_link _class_link
113 #define class_load _class_load
114 #define jit_compile _jit_compile
115 #define new_arithmeticexception _new_arithmeticexception
116 #define new_arrayindexoutofboundsexception _new_arrayindexoutofboundsexception
117 #define new_arraystoreexception _new_arraystoreexception
118 #define new_classcastexception _new_classcastexception
119 #define new_nullpointerexception _new_nullpointerexception
121 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
123 #define _exceptionptr __exceptionptr
127 .globl __exceptionptr
163 #endif /* __DARWIN__ */
170 .globl asm_calljavafunction
172 .globl asm_calljavafunction2
173 .globl asm_calljavafunction2int
174 .globl asm_calljavafunction2long
175 .globl asm_calljavafunction2float
176 .globl asm_calljavafunction2double
178 .globl asm_call_jit_compiler
180 .globl asm_handle_nat_exception
181 .globl asm_handle_exception
182 .globl asm_handle_nullptr_exception
184 .globl asm_check_clinit
186 .globl asm_builtin_checkarraycast
187 .globl asm_builtin_aastore
189 #if defined(USE_THREADS)
190 .globl asm_builtin_monitorenter
191 .globl asm_builtin_monitorexit
194 .globl asm_builtin_idiv
195 .globl asm_builtin_irem
196 .globl asm_builtin_ldiv
197 .globl asm_builtin_lrem
199 .globl asm_cacheflush
200 .globl asm_initialize_thread_stack
201 .globl asm_perform_threadswitch
202 .globl asm_switchstackandcall
203 .globl asm_criticalsections
204 .globl asm_getclassvalues_atomic
207 /********************* function asm_calljavafunction ***************************
209 * This function calls a Java-method (which possibly needs compilation) *
210 * with up to 4 address parameters. *
212 * This functions calls the JIT-compiler which eventually translates the *
213 * method into machine code. *
216 * javaobject_header *asm_calljavamethod (methodinfo *m, *
217 * void *arg1, void *arg2, void *arg3, void *arg4); *
219 *******************************************************************************/
223 .long 0 /* catch type all */
224 .long calljava_xhandler /* handler pc */
225 .long calljava_xhandler /* end pc */
226 .long asm_calljavafunction /* start pc */
227 .long 1 /* extable size */
228 .long 0 /* fltsave */
229 .long 0 /* intsave */
232 .long 24 /* frame size */
233 .long 0 /* method pointer (pointer to name) */
234 .long 0 /* padding */
236 asm_calljavafunction:
272 #if defined(__DARWIN__)
273 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
274 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
276 addi mptr,r31,(asm_call_jit_compiler-0b)@l
287 #if defined(__DARWIN__)
288 addi pv,itmp1,lo16(asm_calljavafunction-1b)
290 addi pv,itmp1,(asm_calljavafunction-1b)@l
321 bl builtin_throw_exception
322 b calljava_regrestore
329 .long 0 /* catch type all */
330 .long calljava_xhandler2 /* handler pc */
331 .long calljava_xhandler2 /* end pc */
332 .long asm_calljavafunction2 /* start pc */
333 .long 1 /* extable size */
334 .long 0 /* fltsave */
335 .long 0 /* intsave */
338 .long 24 /* frame size */
339 .long 0 /* method pointer (pointer to name) */
340 .long 0 /* padding */
342 asm_calljavafunction2:
343 asm_calljavafunction2int:
344 asm_calljavafunction2long:
345 asm_calljavafunction2float:
346 asm_calljavafunction2double:
374 stw r3,36(r1) /* save method pointer for compiler */
375 mr itmp1,r6 /* pointer to arg block */
376 mr itmp2,r4 /* arg count */
379 ble calljava_argsloaded
382 lwz r3,offjniitem+4(itmp1)
384 ble calljava_argsloaded
387 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
389 ble calljava_argsloaded
393 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
395 ble calljava_argsloaded
399 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
401 ble calljava_argsloaded
406 #if defined(__DARWIN__)
407 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
408 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
410 addi mptr,r31,(asm_call_jit_compiler-0b)@l
420 #if defined(__DARWIN__)
421 addi pv,itmp1,lo16(asm_calljavafunction2-1b)
423 addi pv,itmp1,(asm_calljavafunction2-1b)@l
426 calljava_regrestore2:
454 bl builtin_throw_exception
455 b calljava_regrestore2
458 asm_call_jit_compiler:
552 /***************** function asm_handle_nullptr_exception ***********************
554 * This behaves the same as asm_handle_exception but calls *
555 * new_nullpointerexception first *
557 *******************************************************************************/
559 asm_handle_nullptr_exception:
562 bl new_nullpointerexception
566 b asm_handle_exception
568 /********************* function asm_handle_exception ***************************
570 * This function handles an exception. It does not use the usual calling *
571 * conventions. The exception pointer is passed in REG_ITMP1 and the *
572 * pc from the exception raising position is passed in REG_ITMP2. It searches *
573 * the local exception table for a handler. If no one is found, it unwinds *
574 * stacks and continues searching the callers. *
576 * void asm_handle_exception (exceptionptr, exceptionpc); *
578 *******************************************************************************/
580 asm_handle_nat_exception:
588 bne asm_handle_exception
593 asm_handle_exception:
623 lwz r3,0*4(r1) /* exception pointer */
624 lwz r4,MethodPointer(pv) /* method pointer */
625 mr r5,xpc /* exception pc */
627 li r6,0 /* line number */
628 li r7,4 /* set no unwind flag */
630 /* XXX no valid stack frame chaining here */
631 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
632 bl builtin_trace_exception
637 lwz xptr,0*4(r1) /* restore xptr */
642 lwz r3,ExTableSize(pv) /* r3 = exception table size */
643 mr. r3,r3 /* if empty table skip */
646 addi r4,pv,ExTableStart /* r4 = start of exception table */
649 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
650 cmplw r5,xpc /* (startpc <= xpc) */
652 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
653 cmplw xpc,r5 /* (xpc < endpc) */
655 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
659 lwz itmp3,offclassloaded(r7)
663 /* XXX no valid stack frame chaining here */
664 addi r1,r1,-16*4 /* allocate stack */
665 stw r3,7*4(r1) /* save used registers */
666 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
674 mr r3,r7 /* arg1 = exceptionclass */
688 lwz itmp3,offclasslinked(r7)
690 /* XXX no valid stack frame chaining here */
691 addi r1,r1,-16*4 /* allocate stack */
695 stw r3,7*4(r1) /* save used registers */
696 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
703 mr r3,r7 /* arg1 = exceptionclass */
718 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
719 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
720 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
721 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
722 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
724 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
725 cmplw r6,r7 /* xptr is instanceof catchtype */
727 bgt ex_table_cont /* if (false) continue */
730 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
759 addi r4,r4,ExEntrySize
764 mr. r9,r9 /* if here the first time, then */
765 beq ex_already_cleared
766 addi r1,r1,18*4 /* deallocate stack and */
767 li r9,0 /* clear the no unwind flag */
773 #if defined(USE_THREADS)
787 /* XXX no valid stack frame chaining here */
789 bl builtin_monitorexit
803 lwz r3,FrameSize(pv) /* r3 = frame size */
804 add r1,r1,r3 /* unwind stack */
805 mr r3,r1 /* r3 = pointer to save area */
806 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
808 bne ex_no_restore /* if (leaf) skip */
809 lwz r4,8(r3) /* restore ra */
812 mflr r4 /* the new xpc is ra */
814 lwz r4,IntSave(pv) /* r4 = saved int register count */
818 #if defined(__DARWIN__)
819 addi r5,r5,lo16(ex_int2-ex_int1)
821 addi r5,r5,(ex_int2-ex_int1)@l
844 #if defined(__DARWIN__)
845 addi r5,r5,lo16(ex_flt2-ex_flt1)
847 addi r5,r5,(ex_flt2-ex_flt1)@l
878 /********************* asm_check_clinit ****************************************
880 * call static class initializer for PUT/GETSTATIC instructions *
882 *******************************************************************************/
885 lwz itmp2,offclassinit(itmp1)
891 stwu r1,-(26*8)(r1) /* keep stack 16-bytes aligned */
893 stw r3,4*8(r1) /* save argument registers */
894 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
895 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
918 mr itmp1,r3 /* save return value in temp register */
947 mr. itmp1,itmp1 /* check for an exception */
948 beq L_initializererror
954 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
957 stwu r1,-4*8(r1) /* preserve linkage area (24 bytes) */
958 bl builtin_asm_get_exceptionptrptr
963 # if defined(__DARWIN__)
964 lwz r3,lo16(_exceptionptr-0b)(pv)
966 lis r3,_exceptionptr@ha
967 addi r3,r3,_exceptionptr@l
971 lwz xptr,0(r3) /* get the exception pointer */
973 stw r0,0(r3) /* clear the exception pointer */
976 b asm_handle_nat_exception
979 /******************* function asm_builtin_checkarraycast ***********************
981 * Does the cast check and eventually throws an exception *
983 *******************************************************************************/
985 asm_builtin_checkarraycast:
991 bl builtin_checkarraycast
1006 bl new_classcastexception
1012 b asm_handle_nat_exception
1015 /******************* function asm_builtin_aastore ******************************
1017 * Does the cast check and eventually throws an exception *
1019 *******************************************************************************/
1021 asm_builtin_aastore:
1028 lwz itmp1,offarraysize(r3)
1032 bge nb_aastore_bound
1044 beq nb_aastore_store
1045 stw itmp2,offobjarrdata(itmp1)
1052 bl new_nullpointerexception
1058 b asm_handle_nat_exception
1064 stwu r1,-(24+1*4)(r1)
1065 mr r3,r4 /* move index into a0 */
1066 bl new_arrayindexoutofboundsexception
1072 b asm_handle_nat_exception
1078 bl new_arraystoreexception
1084 b asm_handle_nat_exception
1087 #if defined(USE_THREADS)
1088 asm_builtin_monitorenter:
1091 b builtin_monitorenter
1097 bl new_nullpointerexception
1101 /* addi xpc,r0,-4 */
1105 b asm_handle_nat_exception
1108 asm_builtin_monitorexit:
1111 b builtin_monitorexit
1117 bl new_nullpointerexception
1121 /* addi xpc,r0,-4 */
1125 b asm_handle_nat_exception
1147 bl new_arithmeticexception
1153 b asm_handle_nat_exception
1170 mullw itmp3,itmp3,r4
1178 bl new_arithmeticexception
1184 b asm_handle_nat_exception
1196 bl new_arithmeticexception
1202 b asm_handle_nat_exception
1214 bl new_arithmeticexception
1220 b asm_handle_nat_exception
1253 asm_initialize_thread_stack:
1283 #if defined(__DARWIN__)
1284 lfd fr0,lo16(doublezero-0b)(r3)
1286 lfd fr0,(doublezero-0b)@l(r3)
1313 asm_perform_threadswitch:
1405 asm_switchstackandcall:
1423 asm_getclassvalues_atomic:
1426 lwz r6,offbaseval(r3)
1427 lwz r7,offdiffval(r3)
1428 lwz r8,offbaseval(r4)
1430 stw r6,offcast_super_baseval(r5)
1431 stw r7,offcast_super_diffval(r5)
1432 stw r8,offcast_sub_baseval(r5)
1437 asm_criticalsections:
1438 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1441 .long _crit_restart1
1444 .long _crit_restart2
1450 * These are local overrides for various environment variables in Emacs.
1451 * Please do not remove this and leave it at the end of the file, where
1452 * Emacs will automagically detect them.
1453 * ---------------------------------------------------------------------
1456 * indent-tabs-mode: t