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 1763 2004-12-15 16:14:57Z twisti $
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_calljavafunction2long _asm_calljavafunction2long
65 #define asm_calljavafunction2double _asm_calljavafunction2double
67 #define asm_call_jit_compiler _asm_call_jit_compiler
69 #define asm_handle_nat_exception _asm_handle_nat_exception
70 #define asm_handle_exception _asm_handle_exception
72 #define asm_check_clinit _asm_check_clinit
74 #define asm_builtin_checkarraycast _asm_builtin_checkarraycast
75 #define asm_builtin_aastore _asm_builtin_aastore
77 #define asm_builtin_monitorenter _asm_builtin_monitorenter
78 #define asm_builtin_monitorexit _asm_builtin_monitorexit
80 #define asm_builtin_idiv _asm_builtin_idiv
81 #define asm_builtin_irem _asm_builtin_irem
82 #define asm_builtin_ldiv _asm_builtin_ldiv
83 #define asm_builtin_lrem _asm_builtin_lrem
85 #define asm_cacheflush _asm_cacheflush
86 #define asm_initialize_thread_stack _asm_initialize_thread_stack
87 #define asm_perform_threadswitch _asm_perform_threadswitch
88 #define asm_switchstackandcall _asm_switchstackandcall
89 #define asm_criticalsections _asm_criticalsections
90 #define asm_getclassvalues_atomic _asm_getclassvalues_atomic
93 /* external defines ***********************************************************/
95 #define builtin_asm_get_exceptionptrptr _builtin_asm_get_exceptionptrptr
96 #define builtin_canstore _builtin_canstore
97 #define builtin_checkarraycast _builtin_checkarraycast
98 #define builtin_ldiv _builtin_ldiv
99 #define builtin_lrem _builtin_lrem
100 #define builtin_monitorenter _builtin_monitorenter
101 #define builtin_monitorexit _builtin_monitorexit
102 #define builtin_throw_exception _builtin_throw_exception
103 #define builtin_trace_exception _builtin_trace_exception
104 #define class_init _class_init
105 #define class_link _class_link
106 #define class_load _class_load
107 #define jit_compile _jit_compile
108 #define new_arithmeticexception _new_arithmeticexception
109 #define new_arrayindexoutofboundsexception _new_arrayindexoutofboundsexception
110 #define new_arraystoreexception _new_arraystoreexception
111 #define new_classcastexception _new_classcastexception
112 #define new_nullpointerexception _new_nullpointerexception
147 #endif /* __DARWIN__ */
154 .globl asm_calljavafunction
155 .globl asm_calljavafunction2
156 .globl asm_calljavafunction2long
157 .globl asm_calljavafunction2double
159 .globl asm_call_jit_compiler
161 .globl asm_handle_nat_exception
162 .globl asm_handle_exception
164 .globl asm_check_clinit
166 .globl asm_builtin_checkarraycast
167 .globl asm_builtin_aastore
169 .globl asm_builtin_monitorenter
170 .globl asm_builtin_monitorexit
172 .globl asm_builtin_idiv
173 .globl asm_builtin_irem
174 .globl asm_builtin_ldiv
175 .globl asm_builtin_lrem
177 .globl asm_cacheflush
178 .globl asm_initialize_thread_stack
179 .globl asm_perform_threadswitch
180 .globl asm_switchstackandcall
181 .globl asm_criticalsections
182 .globl asm_getclassvalues_atomic
185 /********************* function asm_calljavafunction ***************************
187 * This function calls a Java-method (which possibly needs compilation) *
188 * with up to 4 address parameters. *
190 * This functions calls the JIT-compiler which eventually translates the *
191 * method into machine code. *
194 * javaobject_header *asm_calljavamethod (methodinfo *m, *
195 * void *arg1, void *arg2, void *arg3, void *arg4); *
197 *******************************************************************************/
201 .long 0 /* catch type all */
202 .long calljava_xhandler /* handler pc */
203 .long calljava_xhandler /* end pc */
204 .long asm_calljavafunction /* start pc */
205 .long 1 /* extable size */
206 .long 0 /* fltsave */
207 .long 0 /* intsave */
210 .long 24 /* frame size */
211 .long 0 /* method pointer (pointer to name) */
212 .long 0 /* padding */
214 asm_calljavafunction:
250 #if defined(__DARWIN__)
251 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
252 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
254 addi mptr,r31,(asm_call_jit_compiler-0b)@l
265 #if defined(__DARWIN__)
266 addi pv,itmp1,lo16(asm_calljavafunction-1b)
268 addi pv,itmp1,(asm_calljavafunction-1b)@l
299 bl builtin_throw_exception
300 b calljava_regrestore
307 .long 0 /* catch type all */
308 .long calljava_xhandler2 /* handler pc */
309 .long calljava_xhandler2 /* end pc */
310 .long asm_calljavafunction2 /* start pc */
311 .long 1 /* extable size */
312 .long 0 /* fltsave */
313 .long 0 /* intsave */
316 .long 24 /* frame size */
317 .long 0 /* method pointer (pointer to name) */
318 .long 0 /* padding */
320 asm_calljavafunction2:
321 asm_calljavafunction2long:
322 asm_calljavafunction2double:
350 stw r3,36(r1) /* save method pointer for compiler */
352 mr itmp1,r6 /* pointer to arg block */
353 mr itmp2,r4 /* arg count */
356 ble calljava_argsloaded
359 lwz r3,offjniitem+4(itmp1)
361 ble calljava_argsloaded
364 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
366 ble calljava_argsloaded
370 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
372 ble calljava_argsloaded
376 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
378 ble calljava_argsloaded
382 #if defined(__DARWIN__)
383 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
384 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
386 addi mptr,r31,(asm_call_jit_compiler-0b)@l
396 #if defined(__DARWIN__)
397 addi pv,itmp1,lo16(asm_calljavafunction2-1b)
399 addi pv,itmp1,(asm_calljavafunction2-1b)@l
402 calljava_regrestore2:
430 bl builtin_throw_exception
431 b calljava_regrestore2
434 asm_call_jit_compiler:
527 /********************* function asm_handle_exception ***************************
529 * This function handles an exception. It does not use the usual calling *
530 * conventions. The exception pointer is passed in REG_ITMP1 and the *
531 * pc from the exception raising position is passed in REG_ITMP2. It searches *
532 * the local exception table for a handler. If no one is found, it unwinds *
533 * stacks and continues searching the callers. *
535 * void asm_handle_exception (exceptionptr, exceptionpc); *
537 *******************************************************************************/
539 asm_handle_nat_exception:
547 bne asm_handle_exception
552 asm_handle_exception:
582 lwz r3,0*4(r1) /* exception pointer */
583 lwz r4,MethodPointer(pv) /* method pointer */
584 mr r5,xpc /* exception pc */
586 li r6,0 /* line number */
587 li r7,4 /* set no unwind flag */
589 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
590 bl builtin_trace_exception
595 lwz xptr,0*4(r1) /* restore xptr */
600 lwz r3,ExTableSize(pv) /* r3 = exception table size */
601 mr. r3,r3 /* if empty table skip */
604 addi r4,pv,ExTableStart /* r4 = start of exception table */
607 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
608 cmplw r5,xpc /* (startpc <= xpc) */
610 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
611 cmplw xpc,r5 /* (xpc < endpc) */
613 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
617 lwz itmp3,offclassloaded(r7)
621 addi r1,r1,-16*4 /* allocate stack */
622 stw r3,7*4(r1) /* save used registers */
623 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
631 mr r3,r7 /* arg1 = exceptionclass */
645 lwz itmp3,offclasslinked(r7)
647 addi r1,r1,-16*4 /* allocate stack */
651 stw r3,7*4(r1) /* save used registers */
652 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
659 mr r3,r7 /* arg1 = exceptionclass */
674 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
675 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
676 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
677 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
678 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
680 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
681 cmplw r6,r7 /* xptr is instanceof catchtype */
683 bgt ex_table_cont /* if (false) continue */
686 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
715 addi r4,r4,ExEntrySize
720 mr. r2,r2 /* if here the first time, then */
721 beq ex_already_cleared
722 addi r1,r1,18*4 /* deallocate stack and */
723 li r2,0 /* clear the no unwind flag */
742 bl builtin_monitorexit
755 lwz r3,FrameSize(pv) /* r3 = frame size */
756 add r1,r1,r3 /* unwind stack */
757 mr r3,r1 /* r3 = pointer to save area */
758 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
760 bne ex_no_restore /* if (leaf) skip */
761 lwz r4,8(r3) /* restore ra */
764 mflr r4 /* the new xpc is ra */
766 lwz r4,IntSave(pv) /* r4 = saved int register count */
770 #if defined(__DARWIN__)
771 addi r5,r5,lo16(ex_int2-ex_int1)
773 addi r5,r5,(ex_int2-ex_int1)@l
796 #if defined(__DARWIN__)
797 addi r5,r5,lo16(ex_flt2-ex_flt1)
799 addi r5,r5,(ex_flt2-ex_flt1)@l
830 /********************* asm_check_clinit ****************************************
832 * call static class initializer for PUT/GETSTATIC instructions *
834 *******************************************************************************/
837 lwz itmp2,offclassinit(itmp1)
843 addi r1,r1,-(26*8) /* keep stack 16-bytes aligned */
845 stw r3,4*8(r1) /* save argument registers */
846 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
847 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
870 mr itmp1,r3 /* save return value in temp register */
899 mr. itmp1,itmp1 /* check for an exception */
900 beq L_initializererror
906 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
909 addi r1,r1,-4*8 /* preserve linkage area (24 bytes) */
910 bl builtin_asm_get_exceptionptrptr
915 #if defined(__DARWIN__)
916 lwz r3,lo16(_exceptionptr-0b)(pv)
918 lis r3,_exceptionptr@ha
919 addi r3,r3,_exceptionptr@l
923 lwz xptr,0(r3) /* get the exception pointer */
925 stw r0,0(r3) /* clear the exception pointer */
928 b asm_handle_nat_exception
931 /******************* function asm_builtin_checkarraycast ***********************
933 * Does the cast check and eventually throws an exception *
935 *******************************************************************************/
937 asm_builtin_checkarraycast:
943 bl builtin_checkarraycast
958 bl new_classcastexception
964 b asm_handle_nat_exception
967 /******************* function asm_builtin_aastore ******************************
969 * Does the cast check and eventually throws an exception *
971 *******************************************************************************/
980 lwz itmp1,offarraysize(r3)
997 stw itmp2,offobjarrdata(itmp1)
1004 bl new_nullpointerexception
1010 b asm_handle_nat_exception
1016 addi r1,r1,-(24+1*4)
1017 mr r3,r4 /* move index into a0 */
1018 bl new_arrayindexoutofboundsexception
1024 b asm_handle_nat_exception
1030 bl new_arraystoreexception
1036 b asm_handle_nat_exception
1039 asm_builtin_monitorenter:
1042 b builtin_monitorenter
1048 bl new_nullpointerexception
1052 /* addi xpc,r0,-4 */
1056 b asm_handle_nat_exception
1059 asm_builtin_monitorexit:
1062 b builtin_monitorexit
1068 bl new_nullpointerexception
1072 /* addi xpc,r0,-4 */
1076 b asm_handle_nat_exception
1097 bl new_arithmeticexception
1103 b asm_handle_nat_exception
1120 mullw itmp3,itmp3,r4
1128 bl new_arithmeticexception
1134 b asm_handle_nat_exception
1146 bl new_arithmeticexception
1152 b asm_handle_nat_exception
1164 bl new_arithmeticexception
1170 b asm_handle_nat_exception
1201 asm_initialize_thread_stack:
1231 #if defined(__DARWIN__)
1232 lfd fr0,lo16(doublezero-0b)(r3)
1234 lfd fr0,(doublezero-0b)@l(r3)
1261 asm_perform_threadswitch:
1353 asm_switchstackandcall:
1371 asm_getclassvalues_atomic:
1374 lwz r6,offbaseval(r3)
1375 lwz r7,offdiffval(r3)
1376 lwz r8,offbaseval(r4)
1378 stw r6,offcast_super_baseval(r5)
1379 stw r7,offcast_super_diffval(r5)
1380 stw r8,offcast_sub_baseval(r5)
1385 asm_criticalsections:
1386 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1389 .long _crit_restart1
1392 .long _crit_restart2
1398 * These are local overrides for various environment variables in Emacs.
1399 * Please do not remove this and leave it at the end of the file, where
1400 * Emacs will automagically detect them.
1401 * ---------------------------------------------------------------------
1404 * indent-tabs-mode: t