1 /* src/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
31 Changes: Christian Thalinger
33 $Id: asmpart.S 2176 2005-04-01 13:00:34Z twisti $
38 #if defined(__LINUX__)
39 # include <asm/ppc_asm.h>
43 #include "vm/jit/powerpc/offsets.h"
44 #include "vm/jit/powerpc/asmoffsets.h"
59 #if defined(__DARWIN__)
61 /* Defines for darwin's old gnu assembler *************************************/
63 /* internal defines ***********************************************************/
65 #define asm_calljavafunction _asm_calljavafunction
66 #define asm_calljavafunction_int _asm_calljavafunction_int
68 #define asm_calljavafunction2 _asm_calljavafunction2
69 #define asm_calljavafunction2int _asm_calljavafunction2int
70 #define asm_calljavafunction2long _asm_calljavafunction2long
71 #define asm_calljavafunction2float _asm_calljavafunction2float
72 #define asm_calljavafunction2double _asm_calljavafunction2double
74 #define asm_call_jit_compiler _asm_call_jit_compiler
76 #define asm_handle_nat_exception _asm_handle_nat_exception
77 #define asm_handle_exception _asm_handle_exception
78 #define asm_handle_nullptr_exception _asm_handle_nullptr_exception
80 #define asm_check_clinit _asm_check_clinit
82 #define asm_builtin_checkarraycast _asm_builtin_checkarraycast
83 #define asm_builtin_aastore _asm_builtin_aastore
85 #define asm_builtin_monitorenter _asm_builtin_monitorenter
86 #define asm_builtin_monitorexit _asm_builtin_monitorexit
88 #define asm_builtin_idiv _asm_builtin_idiv
89 #define asm_builtin_irem _asm_builtin_irem
90 #define asm_builtin_ldiv _asm_builtin_ldiv
91 #define asm_builtin_lrem _asm_builtin_lrem
93 #define asm_cacheflush _asm_cacheflush
94 #define asm_initialize_thread_stack _asm_initialize_thread_stack
95 #define asm_perform_threadswitch _asm_perform_threadswitch
96 #define asm_switchstackandcall _asm_switchstackandcall
97 #define asm_criticalsections _asm_criticalsections
98 #define asm_getclassvalues_atomic _asm_getclassvalues_atomic
101 /* external defines ***********************************************************/
103 #define builtin_asm_get_exceptionptrptr _builtin_asm_get_exceptionptrptr
104 #define builtin_canstore _builtin_canstore
105 #define builtin_checkarraycast _builtin_checkarraycast
106 #define builtin_ldiv _builtin_ldiv
107 #define builtin_lrem _builtin_lrem
109 #if defined(USE_THREADS)
110 #define builtin_monitorenter _builtin_monitorenter
111 #define builtin_monitorexit _builtin_monitorexit
114 #define builtin_throw_exception _builtin_throw_exception
115 #define builtin_trace_exception _builtin_trace_exception
116 #define class_init _class_init
117 #define link_class _link_class
118 #define load_class_bootstrap _load_class_bootstrap
119 #define jit_compile _jit_compile
120 #define new_arithmeticexception _new_arithmeticexception
121 #define new_arrayindexoutofboundsexception _new_arrayindexoutofboundsexception
122 #define new_arraystoreexception _new_arraystoreexception
123 #define new_classcastexception _new_classcastexception
124 #define new_nullpointerexception _new_nullpointerexception
126 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
128 #define _exceptionptr __exceptionptr
132 .globl __exceptionptr
135 #endif /* defined(__DARWIN__) */
137 #if defined(__DARWIN__)
172 #endif /* defined(__DARWIN__) */
179 .globl asm_calljavafunction
180 .globl asm_calljavafunction_int
182 .globl asm_calljavafunction2
183 .globl asm_calljavafunction2int
184 .globl asm_calljavafunction2long
185 .globl asm_calljavafunction2float
186 .globl asm_calljavafunction2double
188 .globl asm_call_jit_compiler
190 .globl asm_handle_nat_exception
191 .globl asm_handle_exception
192 .globl asm_handle_nullptr_exception
194 .globl asm_check_clinit
196 .globl asm_builtin_checkarraycast
197 .globl asm_builtin_aastore
199 #if defined(USE_THREADS)
200 .globl asm_builtin_monitorenter
201 .globl asm_builtin_monitorexit
204 .globl asm_builtin_idiv
205 .globl asm_builtin_irem
206 .globl asm_builtin_ldiv
207 .globl asm_builtin_lrem
209 .globl asm_cacheflush
210 .globl asm_initialize_thread_stack
211 .globl asm_perform_threadswitch
212 .globl asm_switchstackandcall
213 .globl asm_criticalsections
214 .globl asm_getclassvalues_atomic
217 /********************* function asm_calljavafunction ***************************
219 * This function calls a Java-method (which possibly needs compilation) *
220 * with up to 4 address parameters. *
222 * This functions calls the JIT-compiler which eventually translates the *
223 * method into machine code. *
226 * javaobject_header *asm_calljavamethod (methodinfo *m, *
227 * void *arg1, void *arg2, void *arg3, void *arg4); *
229 *******************************************************************************/
233 .long 0 /* catch type all */
234 .long calljava_xhandler /* handler pc */
235 .long calljava_xhandler /* end pc */
236 .long asm_calljavafunction /* start pc */
237 .long 1 /* extable size */
238 .long 0 /* fltsave */
239 .long 0 /* intsave */
242 .long 24 /* frame size */
243 .long 0 /* method pointer (pointer to name) */
244 .long 0 /* padding */
246 asm_calljavafunction:
247 asm_calljavafunction_int:
283 #if defined(__DARWIN__)
284 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
285 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
287 addi mptr,r31,(asm_call_jit_compiler-0b)@l
298 #if defined(__DARWIN__)
299 addi pv,itmp1,lo16(asm_calljavafunction-1b)
301 addi pv,itmp1,(asm_calljavafunction-1b)@l
332 bl builtin_throw_exception
333 b calljava_regrestore
340 .long 0 /* catch type all */
341 .long calljava_xhandler2 /* handler pc */
342 .long calljava_xhandler2 /* end pc */
343 .long asm_calljavafunction2 /* start pc */
344 .long 1 /* extable size */
345 .long 0 /* fltsave */
346 .long 0 /* intsave */
349 .long 24 /* frame size */
350 .long 0 /* method pointer (pointer to name) */
351 .long 0 /* padding */
353 asm_calljavafunction2:
354 asm_calljavafunction2int:
355 asm_calljavafunction2long:
356 asm_calljavafunction2float:
357 asm_calljavafunction2double:
385 stw r3,36(r1) /* save method pointer for compiler */
386 mr itmp1,r6 /* pointer to arg block */
387 mr itmp2,r4 /* arg count */
390 ble calljava_argsloaded
393 lwz r3,offjniitem+4(itmp1)
395 ble calljava_argsloaded
398 lwz r4,offjniitem+sizejniblock*1+4(itmp1)
400 ble calljava_argsloaded
404 lwz r5,offjniitem+sizejniblock*2+4(itmp1)
406 ble calljava_argsloaded
410 lwz r6,offjniitem+sizejniblock*3+4(itmp1)
412 ble calljava_argsloaded
417 #if defined(__DARWIN__)
418 /* addis mptr,r31,ha16(_asm_call_jit_compiler-0b)*/
419 addi mptr,r31,lo16(asm_call_jit_compiler-0b)
421 addi mptr,r31,(asm_call_jit_compiler-0b)@l
431 #if defined(__DARWIN__)
432 addi pv,itmp1,lo16(asm_calljavafunction2-1b)
434 addi pv,itmp1,(asm_calljavafunction2-1b)@l
437 calljava_regrestore2:
465 bl builtin_throw_exception
466 b calljava_regrestore2
469 asm_call_jit_compiler:
563 /***************** function asm_handle_nullptr_exception ***********************
565 * This behaves the same as asm_handle_exception but calls *
566 * new_nullpointerexception first *
568 *******************************************************************************/
570 asm_handle_nullptr_exception:
573 bl new_nullpointerexception
577 b asm_handle_exception
579 /********************* function asm_handle_exception ***************************
581 * This function handles an exception. It does not use the usual calling *
582 * conventions. The exception pointer is passed in REG_ITMP1 and the *
583 * pc from the exception raising position is passed in REG_ITMP2. It searches *
584 * the local exception table for a handler. If no one is found, it unwinds *
585 * stacks and continues searching the callers. *
587 * void asm_handle_exception (exceptionptr, exceptionpc); *
589 *******************************************************************************/
591 asm_handle_nat_exception:
599 bne asm_handle_exception
604 asm_handle_exception:
634 lwz r3,0*4(r1) /* exception pointer */
635 lwz r4,MethodPointer(pv) /* method pointer */
636 mr r5,xpc /* exception pc */
638 li r6,0 /* line number */
639 li r7,4 /* set no unwind flag */
641 /* XXX no valid stack frame chaining here */
642 addi r1,r1,-(24+5*4) /* 24 linkage area + 5 argument * 4 */
643 bl builtin_trace_exception
648 lwz xptr,0*4(r1) /* restore xptr */
653 lwz r3,ExTableSize(pv) /* r3 = exception table size */
654 mr. r3,r3 /* if empty table skip */
657 addi r4,pv,ExTableStart /* r4 = start of exception table */
660 lwz r5,ExStartPC(r4) /* r5 = exception start pc */
661 cmplw r5,xpc /* (startpc <= xpc) */
663 lwz r5,ExEndPC(r4) /* r5 = exception end pc */
664 cmplw xpc,r5 /* (xpc < endpc) */
666 lwz r7,ExCatchType(r4) /* r7 = exception catch type */
670 lwz itmp3,offclassloaded(r7)
674 /* XXX no valid stack frame chaining here */
675 addi r1,r1,-16*4 /* allocate stack */
676 stw r3,7*4(r1) /* save used registers */
677 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
685 mr r3,r7 /* arg1 = exceptionclass */
686 bl load_class_bootstrap
699 lwz itmp3,offclasslinked(r7)
701 /* XXX no valid stack frame chaining here */
702 addi r1,r1,-16*4 /* allocate stack */
706 stw r3,7*4(r1) /* save used registers */
707 stw r4,8*4(r1) /* 6*4 (linkage) + 1*4 (arg1) + 7*4 (save) */
714 mr r3,r7 /* arg1 = exceptionclass */
729 lwz r6,offobjvftbl(xptr) /* r6 = vftblptr(xptr) */
730 lwz r7,offclassvftbl(r7) /* r7 = vftblptr(catchtype) class (not obj) */
731 lwz r6,offbaseval(r6) /* r6 = baseval(xptr) */
732 lwz r8,offbaseval(r7) /* r8 = baseval(catchtype) */
733 lwz r7,offdiffval(r7) /* r7 = diffval(catchtype) */
735 subf r6,r8,r6 /* r6 = baseval(xptr) - baseval(catchtype) */
736 cmplw r6,r7 /* xptr is instanceof catchtype */
738 bgt ex_table_cont /* if (false) continue */
741 lwz xpc,ExHandlerPC(r4) /* xpc = exception handler pc */
770 addi r4,r4,ExEntrySize
775 mr. r9,r9 /* if here the first time, then */
776 beq ex_already_cleared
777 addi r1,r1,18*4 /* deallocate stack and */
778 li r9,0 /* clear the no unwind flag */
784 #if defined(USE_THREADS)
798 /* XXX no valid stack frame chaining here */
800 bl builtin_monitorexit
814 lwz r3,FrameSize(pv) /* r3 = frame size */
815 add r1,r1,r3 /* unwind stack */
816 mr r3,r1 /* r3 = pointer to save area */
817 lwz r4,IsLeaf(pv) /* r4 = is leaf procedure */
819 bne ex_no_restore /* if (leaf) skip */
820 lwz r4,8(r3) /* restore ra */
823 mflr r4 /* the new xpc is ra */
825 lwz r4,IntSave(pv) /* r4 = saved int register count */
829 #if defined(__DARWIN__)
830 addi r5,r5,lo16(ex_int2-ex_int1)
832 addi r5,r5,(ex_int2-ex_int1)@l
855 #if defined(__DARWIN__)
856 addi r5,r5,lo16(ex_flt2-ex_flt1)
858 addi r5,r5,(ex_flt2-ex_flt1)@l
889 /********************* asm_check_clinit ****************************************
891 * call static class initializer for PUT/GETSTATIC instructions *
893 *******************************************************************************/
896 lwz itmp2,offclassinit(itmp1)
902 stwu r1,-(26*8)(r1) /* keep stack 16-bytes aligned */
904 stw r3,4*8(r1) /* save argument registers */
905 stw r4,5*8(r1) /* preserve linkage area (24 bytes) */
906 stw r5,6*8(r1) /* and 4 bytes (better 8) for 1 argument */
929 mr itmp1,r3 /* save return value in temp register */
958 mr. itmp1,itmp1 /* check for an exception */
959 beq L_initializererror
965 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
968 stwu r1,-4*8(r1) /* preserve linkage area (24 bytes) */
969 bl builtin_asm_get_exceptionptrptr
974 # if defined(__DARWIN__)
975 lwz r3,lo16(_exceptionptr-0b)(pv)
977 lis r3,_exceptionptr@ha
978 addi r3,r3,_exceptionptr@l
982 lwz xptr,0(r3) /* get the exception pointer */
984 stw r0,0(r3) /* clear the exception pointer */
987 b asm_handle_nat_exception
990 /******************* function asm_builtin_checkarraycast ***********************
992 * Does the cast check and eventually throws an exception *
994 *******************************************************************************/
996 asm_builtin_checkarraycast:
1002 bl builtin_checkarraycast
1017 bl new_classcastexception
1023 b asm_handle_nat_exception
1026 /******************* function asm_builtin_aastore ******************************
1028 * Does the cast check and eventually throws an exception *
1030 *******************************************************************************/
1032 asm_builtin_aastore:
1039 lwz itmp1,offarraysize(r3)
1043 bge nb_aastore_bound
1055 beq nb_aastore_store
1056 stw itmp2,offobjarrdata(itmp1)
1063 bl new_nullpointerexception
1069 b asm_handle_nat_exception
1075 stwu r1,-(24+1*4)(r1)
1076 mr r3,r4 /* move index into a0 */
1077 bl new_arrayindexoutofboundsexception
1083 b asm_handle_nat_exception
1089 bl new_arraystoreexception
1095 b asm_handle_nat_exception
1098 #if defined(USE_THREADS)
1099 asm_builtin_monitorenter:
1102 b builtin_monitorenter
1108 bl new_nullpointerexception
1112 /* addi xpc,r0,-4 */
1116 b asm_handle_nat_exception
1119 asm_builtin_monitorexit:
1122 b builtin_monitorexit
1128 bl new_nullpointerexception
1132 /* addi xpc,r0,-4 */
1136 b asm_handle_nat_exception
1158 bl new_arithmeticexception
1164 b asm_handle_nat_exception
1181 mullw itmp3,itmp3,r4
1189 bl new_arithmeticexception
1195 b asm_handle_nat_exception
1207 bl new_arithmeticexception
1213 b asm_handle_nat_exception
1225 bl new_arithmeticexception
1231 b asm_handle_nat_exception
1264 asm_initialize_thread_stack:
1294 #if defined(__DARWIN__)
1295 lfd fr0,lo16(doublezero-0b)(r3)
1297 lfd fr0,(doublezero-0b)@l(r3)
1324 asm_perform_threadswitch:
1416 asm_switchstackandcall:
1434 asm_getclassvalues_atomic:
1437 lwz r6,offbaseval(r3)
1438 lwz r7,offdiffval(r3)
1439 lwz r8,offbaseval(r4)
1441 stw r6,offcast_super_baseval(r5)
1442 stw r7,offcast_super_diffval(r5)
1443 stw r8,offcast_sub_baseval(r5)
1448 asm_criticalsections:
1449 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1452 .long _crit_restart1
1455 .long _crit_restart2
1461 * These are local overrides for various environment variables in Emacs.
1462 * Please do not remove this and leave it at the end of the file, where
1463 * Emacs will automagically detect them.
1464 * ---------------------------------------------------------------------
1467 * indent-tabs-mode: t