1 /* jit/alpha/asmpart.S - Java-C interface functions for alpha
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Andreas Krall
31 $Id: asmpart.S 901 2004-01-22 19:06:00Z twisti $
103 /********************* exported functions and variables ***********************/
105 .globl has_no_x_instr_set
106 .globl synchronize_caches
107 .globl asm_calljavafunction
108 .globl asm_calljavafunction2
109 .globl asm_calljavafunction2double
110 .globl asm_calljavafunction2long
111 .globl asm_call_jit_compiler
112 .globl asm_dumpregistersandcall
113 .globl asm_handle_exception
114 .globl asm_handle_nat_exception
115 .globl asm_check_clinit
116 .globl asm_builtin_checkcast
117 .globl asm_builtin_checkarraycast
118 .globl asm_builtin_aastore
119 .globl asm_builtin_monitorenter
120 .globl asm_builtin_monitorexit
121 .globl asm_builtin_idiv
122 .globl asm_builtin_irem
123 .globl asm_builtin_ldiv
124 .globl asm_builtin_lrem
125 .globl asm_perform_threadswitch
126 .globl asm_initialize_thread_stack
127 .globl asm_switchstackandcall
128 .globl asm_getcallingmethod
129 .globl asm_builtin_trace
130 .globl asm_builtin_exittrace
132 /*************************** imported functions *******************************/
135 .globl builtin_monitorexit
136 .globl builtin_throw_exception
137 .globl builtin_trace_exception
138 .globl class_java_lang_Object
141 /*********************** function has_no_x_instr_set ***************************
143 * determines if the byte support instruction set (21164a and higher) *
146 *******************************************************************************/
148 .ent has_no_x_instr_set
151 .long 0x47e03c20 /* amask 1,v0 */
152 jmp zero,(ra) /* return */
154 .end has_no_x_instr_set
157 /********************* function synchronize_caches ****************************/
159 .ent synchronize_caches
162 call_pal PAL_imb /* synchronise instruction cache */
163 jmp zero,(ra) /* return */
165 .end synchronize_caches
168 #define MethodPointer -8
169 #define FrameSize -12
174 #define ExTableSize -32
175 #define ExTableStart -32
177 #define ExEntrySize -32
180 #define ExHandlerPC -24
181 #define ExCatchType -32
183 /********************* function asm_calljavafunction ***************************
185 * This function calls a Java-method (which possibly needs compilation) *
186 * with up to 4 address parameters. *
188 * This functions calls the JIT-compiler which eventually translates the *
189 * method into machine code. *
192 * javaobject_header *asm_calljavafunction (methodinfo *m, *
193 * void *arg1, void *arg2, void *arg3, void *arg4); *
195 *******************************************************************************/
197 .ent asm_calljavafunction
200 .ascii "calljavafunction\0\0"
203 .quad 0 /* catch type all */
204 .quad calljava_xhandler /* handler pc */
205 .quad calljava_xhandler /* end pc */
206 .quad asm_calljavafunction /* start pc */
207 .long 1 /* extable size */
208 .long 0 /* fltsave */
209 .long 0 /* intsave */
212 .long 32 /* frame size */
213 .quad 0 /* method pointer (pointer to name) */
215 asm_calljavafunction:
217 lda sp,-32(sp) /* allocate stack space */
218 stq gp,24(sp) /* save global pointer */
219 stq ra,0(sp) /* save return address */
221 stq a0,16(sp) /* save method pointer for compiler */
222 lda v0,16(sp) /* pass pointer to method pointer via v0*/
224 mov a1,a0 /* pass the remaining parameters */
229 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
230 stq $28,8(sp) /* store function address */
231 mov sp,$28 /* set method pointer */
233 ldq pv,8($28) /* method call as in Java */
234 jmp ra,(pv) /* call JIT compiler */
236 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
239 ldq ra,0(sp) /* restore return address */
240 ldq gp,24(sp) /* restore global pointer */
241 lda sp,32(sp) /* free stack space */
247 ldq gp,24(sp) /* restore global pointer */
249 jsr ra,builtin_throw_exception
250 ldq ra,0(sp) /* restore return address */
251 lda sp,32(sp) /* free stack space */
253 .end asm_calljavafunction
258 .ent asm_calljavafunction2
261 .ascii "calljavafunction2\0\0"
264 .quad 0 /* catch type all */
265 .quad calljava_xhandler2 /* handler pc */
266 .quad calljava_xhandler2 /* end pc */
267 .quad asm_calljavafunction2 /* start pc */
268 .long 1 /* extable size */
269 .long 0 /* fltsave */
270 .long 1 /* intsave */
273 .long 40 /* frame size */
274 .quad 0 /* method pointer (pointer to name) */
276 asm_calljavafunction2:
277 asm_calljavafunction2double:
278 asm_calljavafunction2long:
280 lda sp,-40(sp) /* allocate stack space */
281 stq ra,0(sp) /* save return address */
283 stq gp,8(sp) /* save global pointer */
285 stq a0,32(sp) /* save method pointer for compiler */
286 mov a3,t0 /* pointer to arg block */
287 mov a1,s6 /* arg count */
289 ble s6,calljava_argsloaded
291 ldq a0,offjniitem(t0)
292 ldt $f16,offjniitem(t0)
293 ble s6,calljava_argsloaded
295 ldq a1,offjniitem+sizejniblock*1(t0)
296 ldt $f17,offjniitem+sizejniblock*1(t0)
297 ble s6,calljava_argsloaded
299 ldq a2,offjniitem+sizejniblock*2(t0)
300 ldt $f18,offjniitem+sizejniblock*2(t0)
301 ble s6,calljava_argsloaded
303 ldq a3,offjniitem+sizejniblock*3(t0)
304 ldt $f19,offjniitem+sizejniblock*3(t0)
305 ble s6,calljava_argsloaded
307 ldq a4,offjniitem+sizejniblock*4(t0)
308 ldt $f20,offjniitem+sizejniblock*4(t0)
309 ble s6,calljava_argsloaded
311 ldq a5,offjniitem+sizejniblock*5(t0)
312 ldt $f21,offjniitem+sizejniblock*5(t0)
315 ble s6,calljava_nocopy
321 ldq t3,offjniitem+sizejniblock*6(t0)
324 lda t0,sizejniblock(t0)
326 bne t1,calljava_copyloop
329 lda v0,32(t4) /* pass pointer to method pointer via v0*/
331 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
332 stq $28,16(t4) /* store function address */
333 lda $28,8(t4) /* set method pointer */
335 ldq pv,8($28) /* method call as in Java */
336 jmp ra,(pv) /* call JIT compiler */
338 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
342 ldq ra,0(sp) /* restore return address */
343 ldq gp,8(sp) /* restore global pointer */
345 lda sp,40(sp) /* free stack space */
352 ldq gp,8(sp) /* restore global pointer */
354 jsr ra,builtin_throw_exception
355 ldq ra,0(sp) /* restore return address */
357 lda sp,40(sp) /* free stack space */
359 .end asm_calljavafunction2
362 /****************** function asm_call_jit_compiler *****************************
364 * invokes the compiler for untranslated JavaVM methods. *
366 * Register R0 contains a pointer to the method info structure (prepared *
367 * by createcompilerstub). Using the return address in R26 and the *
368 * offset in the LDA instruction or using the value in methodptr R28 the *
369 * patching address for storing the method address can be computed: *
371 * method address was either loaded using *
372 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
373 * M_LDA (REG_PV, REG_RA, low) *
374 * M_LDAH(REG_PV, REG_RA, high) ; optional *
376 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
377 * in the static case the method pointer can be computed using the *
378 * return address and the lda function following the jmp instruction *
380 *******************************************************************************/
383 .ent asm_call_jit_compiler
384 asm_call_jit_compiler:
387 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
388 srl t8,16,t8 /* shift right register number $yy */
389 and t8,31,t8 /* isolate register number */
390 subl t8,28,t8 /* test for REG_METHODPTR */
392 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
394 sra t8,48,t8 /* isolate offset */
395 addq t8,ra,$28 /* compute update address */
396 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
397 srl t8,16,t8 /* isolate instruction code */
398 lda t8,-0x177b(t8) /* test for LDAH */
400 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
401 sll t8,16,t8 /* compute high offset */
402 addl t8,0,t8 /* sign extend high offset */
403 addq t8,$28,$28 /* compute update address */
405 lda sp,-14*8(sp) /* reserve stack space */
406 stq a0,0*8(sp) /* save all argument registers */
407 stq a1,1*8(sp) /* they could be used by method */
418 stq $28,12*8(sp) /* save method pointer */
419 stq ra,13*8(sp) /* save return address */
421 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
422 jsr ra,jit_compile /* jit compiler */
425 call_pal PAL_imb /* synchronise instruction cache */
427 ldq a0,0*8(sp) /* load argument registers */
439 ldq $28,12*8(sp) /* load method pointer */
440 ldq ra,13*8(sp) /* load return address */
441 lda sp,14*8(sp) /* deallocate stack area */
443 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
445 sra t8,48,t8 /* isolate offset */
447 addq t8,$28,t8 /* compute update address via method pointer*/
448 stq v0,0(t8) /* save new method address there */
450 mov v0,pv /* load method address into pv */
452 jmp zero,(pv) /* and call method. The method returns */
453 /* directly to the caller (ra). */
455 .end asm_call_jit_compiler
458 /****************** function asm_dumpregistersandcall **************************
460 * This funtion saves all callee saved registers and calls the function *
461 * which is passed as parameter. *
463 * This function is needed by the garbage collector, which needs to access *
464 * all registers which are stored on the stack. Unused registers are *
465 * cleared to avoid interferances with the GC. *
467 * void asm_dumpregistersandcall (functionptr f); *
469 *******************************************************************************/
471 .ent asm_dumpregistersandcall
472 asm_dumpregistersandcall:
473 lda sp,-16*8(sp) /* allocate stack */
474 stq ra,0(sp) /* save return address */
476 stq s0,1*8(sp) /* save all callee saved registers */
477 stq s1,2*8(sp) /* intialize the remaining registers */
492 clr v0 /* intialize the remaining registers */
537 mov a0,pv /* load function pointer */
538 jmp ra,(pv) /* and call function */
540 ldq ra,0(sp) /* load return address */
541 lda sp,16*8(sp) /* deallocate stack */
542 jmp zero,(ra) /* return */
544 .end asm_dumpregistersandcall
547 /********************* function asm_handle_exception ***************************
549 * This function handles an exception. It does not use the usual calling *
550 * conventions. The exception pointer is passed in REG_ITMP1 and the *
551 * pc from the exception raising position is passed in REG_ITMP2. It searches *
552 * the local exception table for a handler. If no one is found, it unwinds *
553 * stacks and continues searching the callers. *
555 * void asm_handle_exception (exceptionptr, exceptionpc); *
557 *******************************************************************************/
559 .ent asm_handle_nat_exception
560 asm_handle_nat_exception:
562 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
564 sra t0,48,t0 /* isolate offset */
565 addq t0,ra,pv /* compute update address */
566 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
567 srl t0,16,t0 /* isolate instruction code */
568 lda t0,-0x177b(t0) /* test for LDAH */
569 bne t0,asm_handle_exception
570 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
571 sll t0,16,t0 /* compute high offset */
572 addl t0,0,t0 /* sign extend high offset */
573 addq t0,pv,pv /* compute update address */
575 .aent asm_handle_exception
576 asm_handle_exception:
578 lda sp,-18*8(sp) /* allocate stack */
579 stq t0,0*8(sp) /* save possible used registers */
580 stq t1,1*8(sp) /* also registers used by trace_exception */
598 lda t3,1(zero) /* set no unwind flag */
600 lda sp,-5*8(sp) /* allocate stack */
601 stq xptr,0*8(sp) /* save used register */
608 ldq a1,MethodPointer(pv)
612 br ra,ex_trace /* set ra for gp loading */
614 ldgp gp,0(ra) /* load gp */
615 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
617 ldq xptr,0*8(sp) /* restore used register */
622 lda sp,5*8(sp) /* deallocate stack */
624 ldl t0,ExTableSize(pv) /* t0 = exception table size */
625 beq t0,empty_table /* if empty table skip */
626 lda t1,ExTableStart(pv) /* t1 = start of exception table */
629 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
630 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
631 beq t2,ex_table_cont /* if (false) continue */
632 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
633 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
634 beq t2,ex_table_cont /* if (false) continue */
635 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
636 beq a1,ex_handle_it /* NULL catches everything */
638 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
639 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
640 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
641 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
642 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
643 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
644 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
645 beq v0,ex_table_cont /* if (false) continue */
649 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
651 beq t3,ex_jump /* if (!(no stack unwinding) skip */
653 ldq t0,0*8(sp) /* restore possible used registers */
654 ldq t1,1*8(sp) /* also registers used by trace_exception */
671 lda sp,18*8(sp) /* deallocate stack */
674 jmp zero,(xpc) /* jump to the handler */
677 lda t1,ExEntrySize(t1) /* next exception table entry */
678 subl t0,1,t0 /* decrement entry counter */
679 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
682 beq t3,ex_already_cleared /* if here the first time, then */
683 lda sp,18*8(sp) /* deallocate stack and */
684 clr t3 /* clear the no unwind flag */
686 ldl t0,IsSync(pv) /* t0 = SyncOffset */
687 beq t0,no_monitor_exit /* if zero no monitorexit */
688 addq sp,t0,t0 /* add stackptr to Offset */
689 ldq a0,-8(t0) /* load monitorexit pointer */
691 lda sp,-7*8(sp) /* allocate stack */
692 stq t0,0*8(sp) /* save used register */
700 br ra,ex_mon_load /* set ra for gp loading */
702 ldgp gp,0(ra) /* load gp */
703 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
705 ldq t0,0*8(sp) /* restore used register */
712 lda sp,7*8(sp) /* deallocate stack */
715 ldl t0,FrameSize(pv) /* t0 = frame size */
716 addq sp,t0,sp /* unwind stack */
717 mov sp,t0 /* t0 = pointer to save area */
718 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
719 bne t1,ex_no_restore /* if (leaf) skip */
720 ldq ra,-8(t0) /* restore ra */
721 lda t0,-8(t0) /* t0-- */
723 mov ra,xpc /* the new xpc is ra */
724 ldl t1,IntSave(pv) /* t1 = saved int register count */
725 br t2,ex_int1 /* t2 = current pc */
727 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
728 negl t1,t1 /* negate register count */
729 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
730 jmp zero,(t2) /* jump to save position */
739 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
741 ldl t1,FltSave(pv) /* t1 = saved flt register count */
742 br t2,ex_flt1 /* t2 = current pc */
744 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
745 negl t1,t1 /* negate register count */
746 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
747 jmp zero,(t2) /* jump to save position */
757 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
759 sra t0,48,t0 /* isolate offset */
760 addq t0,ra,pv /* compute update address */
761 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
762 srl t0,16,t0 /* isolate instruction code */
763 lda t0,-0x177b(t0) /* test for LDAH */
765 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
766 sll t0,16,t0 /* compute high offset */
767 addl t0,0,t0 /* sign extend high offset */
768 addq t0,pv,pv /* compute update address */
771 .end asm_handle_nat_exception
774 /********************* asm_check_clinit ****************************************
776 * Does null check and calls monitorenter or throws an exception *
778 *******************************************************************************/
780 .ent asm_check_clinit
784 ldl itmp2,offclassinit(itmp1)
785 bne itmp2,L_is_initialized
789 stq a0,1*8(sp) /* save argument registers for leaf funcs */
801 ldq a0,1*8(sp) /* restore argument registers */
810 mov ra,itmp1 /* now patch the calling code */
811 subq itmp1,(3*4),itmp1 /* go back 3 instructions */
812 ldah itmp2,-15392(zero) /* br -- 0xc3e0 == -15392 */
813 lda itmp2,4(itmp2) /* jump over 4 instructions */
814 stl itmp2,0(itmp1) /* store the new branch: br +4 */
818 .end asm_check_clinit
821 /********************* function asm_builtin_monitorenter ***********************
823 * Does null check and calls monitorenter or throws an exception *
825 *******************************************************************************/
827 .ent asm_builtin_monitorenter
828 asm_builtin_monitorenter:
831 lda pv,builtin_monitorenter
832 beq a0,nb_monitorenter /* if (null) throw exception */
833 jmp zero,(pv) /* else call builtin_monitorenter */
836 ldq xptr,proto_java_lang_NullPointerException
837 lda xpc,-4(ra) /* faulting address is return adress - 4*/
838 br asm_handle_nat_exception
839 .end asm_builtin_monitorenter
842 /********************* function asm_builtin_monitorexit ************************
844 * Does null check and calls monitorexit or throws an exception *
846 *******************************************************************************/
848 .ent asm_builtin_monitorexit
849 asm_builtin_monitorexit:
852 lda pv,builtin_monitorexit
853 beq a0,nb_monitorexit /* if (null) throw exception */
854 jmp zero,(pv) /* else call builtin_monitorexit */
857 ldq xptr,proto_java_lang_NullPointerException
858 lda xpc,-4(ra) /* faulting address is return adress - 4*/
859 br asm_handle_nat_exception
860 .end asm_builtin_monitorexit
863 /************************ function asm_builtin_idiv ****************************
865 * Does null check and calls idiv or throws an exception *
867 *******************************************************************************/
869 .ent asm_builtin_idiv
874 beq a1,nb_idiv /* if (null) throw exception */
875 jmp zero,(pv) /* else call builtin_idiv */
878 ldq xptr,proto_java_lang_ArithmeticException
879 lda xpc,-4(ra) /* faulting address is return adress - 4*/
880 br asm_handle_nat_exception
881 .end asm_builtin_idiv
884 /************************ function asm_builtin_ldiv ****************************
886 * Does null check and calls ldiv or throws an exception *
888 *******************************************************************************/
890 .ent asm_builtin_ldiv
895 beq a1,nb_ldiv /* if (null) throw exception */
896 jmp zero,(pv) /* else call builtin_ldiv */
899 ldq xptr,proto_java_lang_ArithmeticException
900 lda xpc,-4(ra) /* faulting address is return adress - 4*/
901 br asm_handle_nat_exception
902 .end asm_builtin_ldiv
905 /************************ function asm_builtin_irem ****************************
907 * Does null check and calls irem or throws an exception *
909 *******************************************************************************/
911 .ent asm_builtin_irem
916 beq a1,nb_irem /* if (null) throw exception */
917 jmp zero,(pv) /* else call builtin_irem */
920 ldq xptr,proto_java_lang_ArithmeticException
921 lda xpc,-4(ra) /* faulting address is return adress - 4*/
922 br asm_handle_nat_exception
923 .end asm_builtin_irem
926 /************************ function asm_builtin_lrem ****************************
928 * Does null check and calls lrem or throws an exception *
930 *******************************************************************************/
932 .ent asm_builtin_lrem
937 beq a1,nb_lrem /* if (null) throw exception */
938 jmp zero,(pv) /* else call builtin_lrem */
941 ldq xptr,proto_java_lang_ArithmeticException
942 lda xpc,-4(ra) /* faulting address is return adress - 4*/
943 br asm_handle_nat_exception
944 .end asm_builtin_lrem
947 /*********************** function new_builtin_checkcast ************************
949 * Does the cast check and eventually throws an exception *
951 *******************************************************************************/
953 .ent asm_builtin_checkcast
954 asm_builtin_checkcast:
957 lda sp,-16(sp) # allocate stack space
958 stq ra,0(sp) # save return address
959 stq a0,8(sp) # save object pointer
960 jsr ra,builtin_checkcast # builtin_checkcast
962 beq v0,nb_ccast_throw # if (false) throw exception
963 ldq ra,0(sp) # restore return address
964 ldq v0,8(sp) # return object pointer
965 lda sp,16(sp) # free stack space
969 ldq xptr,proto_java_lang_ClassCastException
970 ldq ra,0(sp) # restore return address
971 lda sp,16(sp) # free stack space
972 lda xpc,-4(ra) # faulting address is return adress - 4
973 br asm_handle_nat_exception
974 .end asm_builtin_checkcast
977 /******************* function asm_builtin_checkarraycast ***********************
979 * Does the cast check and eventually throws an exception *
981 *******************************************************************************/
983 .ent asm_builtin_checkarraycast
984 asm_builtin_checkarraycast:
987 lda sp,-16(sp) /* allocate stack space */
988 stq ra,0(sp) /* save return address */
989 stq a0,8(sp) /* save object pointer */
990 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
992 beq v0,nb_carray_throw /* if (false) throw exception */
993 ldq ra,0(sp) /* restore return address */
994 ldq v0,8(sp) /* return object pointer */
995 lda sp,16(sp) /* free stack space */
999 ldq xptr,proto_java_lang_ClassCastException
1000 ldq ra,0(sp) /* restore return address */
1001 lda sp,16(sp) /* free stack space */
1002 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1003 br asm_handle_nat_exception
1004 .end asm_builtin_checkarraycast
1007 /******************* function asm_builtin_aastore ******************************
1009 * Does the cast check and eventually throws an exception *
1011 *******************************************************************************/
1013 .ent asm_builtin_aastore
1014 asm_builtin_aastore:
1017 beq a0,nb_aastore_null /* if null pointer throw exception */
1018 ldl t0,offarraysize(a0) /* load size */
1019 lda sp,-24(sp) /* allocate stack space */
1020 stq ra,0(sp) /* save return address */
1021 s8addq a1,a0,t1 /* add index*8 to arrayref */
1022 cmpult a1,t0,t0 /* do bound check */
1023 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1024 mov a2,a1 /* object is second argument */
1025 stq t1,8(sp) /* save store position */
1026 stq a1,16(sp) /* save object */
1027 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1029 ldq ra,0(sp) /* restore return address */
1030 ldq a0,8(sp) /* restore store position */
1031 ldq a1,16(sp) /* restore object */
1032 lda sp,24(sp) /* free stack space */
1033 beq v0,nb_aastore_throw /* if (false) throw exception */
1034 stq a1,offobjarrdata(a0) /* store objectptr in array */
1038 ldq xptr,proto_java_lang_NullPointerException
1039 mov ra,xpc /* faulting address is return adress */
1040 br asm_handle_nat_exception
1043 ldq xptr,proto_java_lang_ArrayIndexOutOfBoundsException
1044 lda sp,24(sp) /* free stack space */
1045 mov ra,xpc /* faulting address is return adress */
1046 br asm_handle_nat_exception
1049 ldq xptr,proto_java_lang_ArrayStoreException
1050 mov ra,xpc /* faulting address is return adress */
1051 br asm_handle_nat_exception
1053 .end asm_builtin_aastore
1056 /******************* function asm_initialize_thread_stack **********************
1058 * initialized a thread stack *
1060 *******************************************************************************/
1062 .ent asm_initialize_thread_stack
1063 asm_initialize_thread_stack:
1084 .end asm_initialize_thread_stack
1087 /******************* function asm_perform_threadswitch *************************
1089 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1091 * performs a threadswitch *
1093 *******************************************************************************/
1095 .ent asm_perform_threadswitch
1096 asm_perform_threadswitch:
1137 .end asm_perform_threadswitch
1140 /********************* function asm_switchstackandcall *************************
1142 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1145 * Switches to a new stack, calls a function and switches back. *
1146 * a0 new stack pointer *
1147 * a1 function pointer *
1148 * a2 pointer to variable where stack top should be stored *
1149 * a3 pointer to user data, is passed to the function *
1151 *******************************************************************************/
1154 .ent asm_switchstackandcall
1155 asm_switchstackandcall:
1156 lda a0,-2*8(a0) /* allocate new stack */
1157 stq ra,0(a0) /* save return address on new stack */
1158 stq sp,1*8(a0) /* save old stack pointer on new stack */
1159 stq sp,0(a2) /* save old stack pointer to variable */
1160 mov a0,sp /* switch to new stack */
1162 mov a1,pv /* load function pointer */
1163 mov a3,a0 /* pass pointer */
1164 jmp ra,(pv) /* and call function */
1166 ldq ra,0(sp) /* load return address */
1167 ldq sp,1*8(sp) /* switch to old stack */
1169 jmp zero,(ra) /* return */
1171 .end asm_switchstackandcall
1174 /********************* function asm_getcallingmethod ***************************
1176 * classinfo *asm_getcallingmethodclass (); *
1178 * goes back stack frames to get the calling method *
1184 *******************************************************************************/
1187 .ent asm_getcallingmethod
1188 asm_getcallingmethod:
1190 ldq t3,16(sp) /* load return address of native function */
1191 addq sp,24,t2 /* skip frames of C-Function and nativestub */
1193 /* determine pv (t3) of java-function from ra */
1195 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1197 sra t0,48,t0 /* isolate offset */
1198 addq t0,t3,t4 /* compute update address */
1199 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1200 srl t0,16,t0 /* isolate instruction code */
1201 lda t0,-0x177b(t0) /* test for LDAH */
1203 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1204 sll t0,16,t0 /* compute high offset */
1205 addl t0,0,t0 /* sign extend high offset */
1206 addq t0,t4,t4 /* compute update address */
1209 ldl t0,FrameSize(t4) /* t0 = frame size */
1210 addq t2,t0,t2 /* skip frame of java function */
1211 ldq t3,-8(t2) /* load new ra */
1213 /* determine pv (t3) of java-function from ra */
1215 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1217 sra t0,48,t0 /* isolate offset */
1218 addq t0,t3,t4 /* compute update address */
1219 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1220 srl t0,16,t0 /* isolate instruction code */
1221 lda t0,-0x177b(t0) /* test for LDAH */
1223 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1224 sll t0,16,t0 /* compute high offset */
1225 addl t0,0,t0 /* sign extend high offset */
1226 addq t0,t4,t4 /* compute update address */
1229 ldq v0,MethodPointer(t4) /* */
1232 jmp zero,(ra) /* return */
1234 .end asm_getcallingmethod
1238 * These are local overrides for various environment variables in Emacs.
1239 * Please do not remove this and leave it at the end of the file, where
1240 * Emacs will automagically detect them.
1241 * ---------------------------------------------------------------------
1244 * indent-tabs-mode: t