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 1941 2005-02-14 20:25:40Z 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 */
376 mr itmp1,r6 /* pointer to arg block */
377 mr itmp2,r4 /* arg count */
380 ble calljava_argsloaded
383 lwz r3,offjniitem+4(itmp1)
385 ble calljava_argsloaded
388 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
390 ble calljava_argsloaded
394 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
396 ble calljava_argsloaded
400 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
402 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:
551 /***************** function asm_handle_nullptr_exception ***********************
553 * This behaves the same as asm_handle_exception but calls *
554 * new_nullpointerexception first *
556 *******************************************************************************/
558 asm_handle_nullptr_exception:
561 bl new_nullpointerexception
565 b asm_handle_exception
567 /********************* function asm_handle_exception ***************************
569 * This function handles an exception. It does not use the usual calling *
570 * conventions. The exception pointer is passed in REG_ITMP1 and the *
571 * pc from the exception raising position is passed in REG_ITMP2. It searches *
572 * the local exception table for a handler. If no one is found, it unwinds *
573 * stacks and continues searching the callers. *
575 * void asm_handle_exception (exceptionptr, exceptionpc); *
577 *******************************************************************************/
579 asm_handle_nat_exception:
587 bne asm_handle_exception
592 asm_handle_exception:
622 lwz r3,0*4(r1) /* exception pointer */
623 lwz r4,MethodPointer(pv) /* method pointer */
624 mr r5,xpc /* exception pc */
626 li r6,0 /* line number */
627 li r7,4 /* set no unwind flag */
629 /* XXX no valid stack frame chaining here */
630 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
631 bl builtin_trace_exception
636 lwz xptr,0*4(r1) /* restore xptr */
641 lwz r3,ExTableSize(pv) /* r3 = exception table size */
642 mr. r3,r3 /* if empty table skip */
645 addi r4,pv,ExTableStart /* r4 = start of exception table */
648 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
649 cmplw r5,xpc /* (startpc <= xpc) */
651 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
652 cmplw xpc,r5 /* (xpc < endpc) */
654 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
658 lwz itmp3,offclassloaded(r7)
662 /* XXX no valid stack frame chaining here */
663 addi r1,r1,-16*4 /* allocate stack */
664 stw r3,7*4(r1) /* save used registers */
665 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
673 mr r3,r7 /* arg1 = exceptionclass */
687 lwz itmp3,offclasslinked(r7)
689 /* XXX no valid stack frame chaining here */
690 addi r1,r1,-16*4 /* allocate stack */
694 stw r3,7*4(r1) /* save used registers */
695 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
702 mr r3,r7 /* arg1 = exceptionclass */
717 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
718 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
719 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
720 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
721 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
723 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
724 cmplw r6,r7 /* xptr is instanceof catchtype */
726 bgt ex_table_cont /* if (false) continue */
729 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
758 addi r4,r4,ExEntrySize
763 mr. r2,r2 /* if here the first time, then */
764 beq ex_already_cleared
765 addi r1,r1,18*4 /* deallocate stack and */
766 li r2,0 /* clear the no unwind flag */
772 #if defined(USE_THREADS)
786 /* XXX no valid stack frame chaining here */
788 bl builtin_monitorexit
802 lwz r3,FrameSize(pv) /* r3 = frame size */
803 add r1,r1,r3 /* unwind stack */
804 mr r3,r1 /* r3 = pointer to save area */
805 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
807 bne ex_no_restore /* if (leaf) skip */
808 lwz r4,8(r3) /* restore ra */
811 mflr r4 /* the new xpc is ra */
813 lwz r4,IntSave(pv) /* r4 = saved int register count */
817 #if defined(__DARWIN__)
818 addi r5,r5,lo16(ex_int2-ex_int1)
820 addi r5,r5,(ex_int2-ex_int1)@l
843 #if defined(__DARWIN__)
844 addi r5,r5,lo16(ex_flt2-ex_flt1)
846 addi r5,r5,(ex_flt2-ex_flt1)@l
877 /********************* asm_check_clinit ****************************************
879 * call static class initializer for PUT/GETSTATIC instructions *
881 *******************************************************************************/
884 lwz itmp2,offclassinit(itmp1)
890 stwu r1,-(26*8)(r1) /* keep stack 16-bytes aligned */
892 stw r3,4*8(r1) /* save argument registers */
893 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
894 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
917 mr itmp1,r3 /* save return value in temp register */
946 mr. itmp1,itmp1 /* check for an exception */
947 beq L_initializererror
953 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
956 stwu r1,-4*8(r1) /* preserve linkage area (24 bytes) */
957 bl builtin_asm_get_exceptionptrptr
962 # if defined(__DARWIN__)
963 lwz r3,lo16(_exceptionptr-0b)(pv)
965 lis r3,_exceptionptr@ha
966 addi r3,r3,_exceptionptr@l
970 lwz xptr,0(r3) /* get the exception pointer */
972 stw r0,0(r3) /* clear the exception pointer */
975 b asm_handle_nat_exception
978 /******************* function asm_builtin_checkarraycast ***********************
980 * Does the cast check and eventually throws an exception *
982 *******************************************************************************/
984 asm_builtin_checkarraycast:
990 bl builtin_checkarraycast
1005 bl new_classcastexception
1011 b asm_handle_nat_exception
1014 /******************* function asm_builtin_aastore ******************************
1016 * Does the cast check and eventually throws an exception *
1018 *******************************************************************************/
1020 asm_builtin_aastore:
1027 lwz itmp1,offarraysize(r3)
1031 bge nb_aastore_bound
1043 beq nb_aastore_store
1044 stw itmp2,offobjarrdata(itmp1)
1051 bl new_nullpointerexception
1057 b asm_handle_nat_exception
1063 stwu r1,-(24+1*4)(r1)
1064 mr r3,r4 /* move index into a0 */
1065 bl new_arrayindexoutofboundsexception
1071 b asm_handle_nat_exception
1077 bl new_arraystoreexception
1083 b asm_handle_nat_exception
1086 #if defined(USE_THREADS)
1087 asm_builtin_monitorenter:
1090 b builtin_monitorenter
1096 bl new_nullpointerexception
1100 /* addi xpc,r0,-4 */
1104 b asm_handle_nat_exception
1107 asm_builtin_monitorexit:
1110 b builtin_monitorexit
1116 bl new_nullpointerexception
1120 /* addi xpc,r0,-4 */
1124 b asm_handle_nat_exception
1146 bl new_arithmeticexception
1152 b asm_handle_nat_exception
1169 mullw itmp3,itmp3,r4
1177 bl new_arithmeticexception
1183 b asm_handle_nat_exception
1195 bl new_arithmeticexception
1201 b asm_handle_nat_exception
1213 bl new_arithmeticexception
1219 b asm_handle_nat_exception
1252 asm_initialize_thread_stack:
1282 #if defined(__DARWIN__)
1283 lfd fr0,lo16(doublezero-0b)(r3)
1285 lfd fr0,(doublezero-0b)@l(r3)
1312 asm_perform_threadswitch:
1404 asm_switchstackandcall:
1422 asm_getclassvalues_atomic:
1425 lwz r6,offbaseval(r3)
1426 lwz r7,offdiffval(r3)
1427 lwz r8,offbaseval(r4)
1429 stw r6,offcast_super_baseval(r5)
1430 stw r7,offcast_super_diffval(r5)
1431 stw r8,offcast_sub_baseval(r5)
1436 asm_criticalsections:
1437 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1440 .long _crit_restart1
1443 .long _crit_restart2
1449 * These are local overrides for various environment variables in Emacs.
1450 * Please do not remove this and leave it at the end of the file, where
1451 * Emacs will automagically detect them.
1452 * ---------------------------------------------------------------------
1455 * indent-tabs-mode: t