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 963 2004-03-15 07:37:49Z jowenn $
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 LineNumberTableSize -32
175 #define LineNumberTableStart -40
176 #define ExTableSize -48
177 #define ExTableStart -48
180 #define ExEntrySize -32
183 #define ExHandlerPC -24
184 #define ExCatchType -32
186 #define LineEntrySize -16
191 /********************* function asm_calljavafunction ***************************
193 * This function calls a Java-method (which possibly needs compilation) *
194 * with up to 4 address parameters. *
196 * This functions calls the JIT-compiler which eventually translates the *
197 * method into machine code. *
200 * javaobject_header *asm_calljavafunction (methodinfo *m, *
201 * void *arg1, void *arg2, void *arg3, void *arg4); *
203 *******************************************************************************/
205 .ent asm_calljavafunction
208 .ascii "calljavafunction\0\0"
211 .quad 0 /* catch type all */
212 .quad calljava_xhandler /* handler pc */
213 .quad calljava_xhandler /* end pc */
214 .quad asm_calljavafunction /* start pc */
215 .long 1 /* extable size */
216 .quad 0 /* line number table start */
217 .quad 0 /* line number table size */
218 .long 0 /* fltsave */
219 .long 0 /* intsave */
222 .long 32 /* frame size */
223 .quad 0 /* method pointer (pointer to name) */
225 asm_calljavafunction:
227 lda sp,-32(sp) /* allocate stack space */
228 stq gp,24(sp) /* save global pointer */
229 stq ra,0(sp) /* save return address */
231 stq a0,16(sp) /* save method pointer for compiler */
232 lda v0,16(sp) /* pass pointer to method pointer via v0*/
234 mov a1,a0 /* pass the remaining parameters */
239 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
240 stq $28,8(sp) /* store function address */
241 mov sp,$28 /* set method pointer */
243 ldq pv,8($28) /* method call as in Java */
244 jmp ra,(pv) /* call JIT compiler */
246 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
249 ldq ra,0(sp) /* restore return address */
250 ldq gp,24(sp) /* restore global pointer */
251 lda sp,32(sp) /* free stack space */
257 ldq gp,24(sp) /* restore global pointer */
259 jsr ra,builtin_throw_exception
260 ldq ra,0(sp) /* restore return address */
261 lda sp,32(sp) /* free stack space */
263 .end asm_calljavafunction
268 .ent asm_calljavafunction2
271 .ascii "calljavafunction2\0\0"
274 .quad 0 /* catch type all */
275 .quad calljava_xhandler2 /* handler pc */
276 .quad calljava_xhandler2 /* end pc */
277 .quad asm_calljavafunction2 /* start pc */
278 .long 1 /* extable size */
279 .quad 0 /* line number table start */
280 .quad 0 /* line number table size */
281 .long 0 /* fltsave */
282 .long 1 /* intsave */
285 .long 40 /* frame size */
286 .quad 0 /* method pointer (pointer to name) */
288 asm_calljavafunction2:
289 asm_calljavafunction2double:
290 asm_calljavafunction2long:
292 lda sp,-40(sp) /* allocate stack space */
293 stq ra,0(sp) /* save return address */
295 stq gp,8(sp) /* save global pointer */
297 stq a0,32(sp) /* save method pointer for compiler */
298 mov a3,t0 /* pointer to arg block */
299 mov a1,s6 /* arg count */
301 ble s6,calljava_argsloaded
303 ldq a0,offjniitem(t0)
304 ldt $f16,offjniitem(t0)
305 ble s6,calljava_argsloaded
307 ldq a1,offjniitem+sizejniblock*1(t0)
308 ldt $f17,offjniitem+sizejniblock*1(t0)
309 ble s6,calljava_argsloaded
311 ldq a2,offjniitem+sizejniblock*2(t0)
312 ldt $f18,offjniitem+sizejniblock*2(t0)
313 ble s6,calljava_argsloaded
315 ldq a3,offjniitem+sizejniblock*3(t0)
316 ldt $f19,offjniitem+sizejniblock*3(t0)
317 ble s6,calljava_argsloaded
319 ldq a4,offjniitem+sizejniblock*4(t0)
320 ldt $f20,offjniitem+sizejniblock*4(t0)
321 ble s6,calljava_argsloaded
323 ldq a5,offjniitem+sizejniblock*5(t0)
324 ldt $f21,offjniitem+sizejniblock*5(t0)
327 ble s6,calljava_nocopy
333 ldq t3,offjniitem+sizejniblock*6(t0)
336 lda t0,sizejniblock(t0)
338 bne t1,calljava_copyloop
341 lda v0,32(t4) /* pass pointer to method pointer via v0*/
343 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
344 stq $28,16(t4) /* store function address */
345 lda $28,8(t4) /* set method pointer */
347 ldq pv,8($28) /* method call as in Java */
348 jmp ra,(pv) /* call JIT compiler */
350 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
354 ldq ra,0(sp) /* restore return address */
355 ldq gp,8(sp) /* restore global pointer */
357 lda sp,40(sp) /* free stack space */
364 ldq gp,8(sp) /* restore global pointer */
366 jsr ra,builtin_throw_exception
367 ldq ra,0(sp) /* restore return address */
369 lda sp,40(sp) /* free stack space */
371 .end asm_calljavafunction2
374 /****************** function asm_call_jit_compiler *****************************
376 * invokes the compiler for untranslated JavaVM methods. *
378 * Register R0 contains a pointer to the method info structure (prepared *
379 * by createcompilerstub). Using the return address in R26 and the *
380 * offset in the LDA instruction or using the value in methodptr R28 the *
381 * patching address for storing the method address can be computed: *
383 * method address was either loaded using *
384 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
385 * M_LDA (REG_PV, REG_RA, low) *
386 * M_LDAH(REG_PV, REG_RA, high) ; optional *
388 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
389 * in the static case the method pointer can be computed using the *
390 * return address and the lda function following the jmp instruction *
392 *******************************************************************************/
395 .ent asm_call_jit_compiler
396 asm_call_jit_compiler:
399 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
400 srl t8,16,t8 /* shift right register number $yy */
401 and t8,31,t8 /* isolate register number */
402 subl t8,28,t8 /* test for REG_METHODPTR */
404 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
406 sra t8,48,t8 /* isolate offset */
407 addq t8,ra,$28 /* compute update address */
408 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
409 srl t8,16,t8 /* isolate instruction code */
410 lda t8,-0x177b(t8) /* test for LDAH */
412 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
413 sll t8,16,t8 /* compute high offset */
414 addl t8,0,t8 /* sign extend high offset */
415 addq t8,$28,$28 /* compute update address */
417 lda sp,-14*8(sp) /* reserve stack space */
418 stq a0,0*8(sp) /* save all argument registers */
419 stq a1,1*8(sp) /* they could be used by method */
430 stq $28,12*8(sp) /* save method pointer */
431 stq ra,13*8(sp) /* save return address */
433 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
434 jsr ra,jit_compile /* jit compiler */
437 call_pal PAL_imb /* synchronise instruction cache */
439 ldq a0,0*8(sp) /* load argument registers */
451 ldq $28,12*8(sp) /* load method pointer */
452 ldq ra,13*8(sp) /* load return address */
453 lda sp,14*8(sp) /* deallocate stack area */
455 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
457 sra t8,48,t8 /* isolate offset */
459 addq t8,$28,t8 /* compute update address via method pointer*/
460 stq v0,0(t8) /* save new method address there */
462 mov v0,pv /* load method address into pv */
464 jmp zero,(pv) /* and call method. The method returns */
465 /* directly to the caller (ra). */
467 .end asm_call_jit_compiler
470 /****************** function asm_dumpregistersandcall **************************
472 * This funtion saves all callee saved registers and calls the function *
473 * which is passed as parameter. *
475 * This function is needed by the garbage collector, which needs to access *
476 * all registers which are stored on the stack. Unused registers are *
477 * cleared to avoid interferances with the GC. *
479 * void asm_dumpregistersandcall (functionptr f); *
481 *******************************************************************************/
483 .ent asm_dumpregistersandcall
484 asm_dumpregistersandcall:
485 lda sp,-16*8(sp) /* allocate stack */
486 stq ra,0(sp) /* save return address */
488 stq s0,1*8(sp) /* save all callee saved registers */
489 stq s1,2*8(sp) /* intialize the remaining registers */
504 clr v0 /* intialize the remaining registers */
549 mov a0,pv /* load function pointer */
550 jmp ra,(pv) /* and call function */
552 ldq ra,0(sp) /* load return address */
553 lda sp,16*8(sp) /* deallocate stack */
554 jmp zero,(ra) /* return */
556 .end asm_dumpregistersandcall
559 /********************* function asm_handle_exception ***************************
561 * This function handles an exception. It does not use the usual calling *
562 * conventions. The exception pointer is passed in REG_ITMP1 and the *
563 * pc from the exception raising position is passed in REG_ITMP2. It searches *
564 * the local exception table for a handler. If no one is found, it unwinds *
565 * stacks and continues searching the callers. *
567 * void asm_handle_exception (exceptionptr, exceptionpc); *
569 *******************************************************************************/
571 .ent asm_handle_nat_exception
572 asm_handle_nat_exception:
574 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
576 sra t0,48,t0 /* isolate offset */
577 addq t0,ra,pv /* compute update address */
578 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
579 srl t0,16,t0 /* isolate instruction code */
580 lda t0,-0x177b(t0) /* test for LDAH */
581 bne t0,asm_handle_exception
582 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
583 sll t0,16,t0 /* compute high offset */
584 addl t0,0,t0 /* sign extend high offset */
585 addq t0,pv,pv /* compute update address */
587 .aent asm_handle_exception
588 asm_handle_exception:
590 lda sp,-18*8(sp) /* allocate stack */
591 stq t0,0*8(sp) /* save possible used registers */
592 stq t1,1*8(sp) /* also registers used by trace_exception */
610 lda t3,1(zero) /* set no unwind flag */
612 lda sp,-5*8(sp) /* allocate stack */
613 stq xptr,0*8(sp) /* save used register */
620 ldq a1,MethodPointer(pv)
624 br ra,ex_trace /* set ra for gp loading */
626 ldgp gp,0(ra) /* load gp */
627 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
629 ldq xptr,0*8(sp) /* restore used register */
634 lda sp,5*8(sp) /* deallocate stack */
636 ldl t0,ExTableSize(pv) /* t0 = exception table size */
637 beq t0,empty_table /* if empty table skip */
638 lda t1,ExTableStart(pv) /* t1 = start of exception table */
641 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
642 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
643 beq t2,ex_table_cont /* if (false) continue */
644 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
645 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
646 beq t2,ex_table_cont /* if (false) continue */
647 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
648 beq a1,ex_handle_it /* NULL catches everything */
650 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
651 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
652 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
653 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
654 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
655 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
656 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
657 beq v0,ex_table_cont /* if (false) continue */
661 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
663 beq t3,ex_jump /* if (!(no stack unwinding) skip */
665 ldq t0,0*8(sp) /* restore possible used registers */
666 ldq t1,1*8(sp) /* also registers used by trace_exception */
683 lda sp,18*8(sp) /* deallocate stack */
686 jmp zero,(xpc) /* jump to the handler */
689 lda t1,ExEntrySize(t1) /* next exception table entry */
690 subl t0,1,t0 /* decrement entry counter */
691 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
694 beq t3,ex_already_cleared /* if here the first time, then */
695 lda sp,18*8(sp) /* deallocate stack and */
696 clr t3 /* clear the no unwind flag */
698 ldl t0,IsSync(pv) /* t0 = SyncOffset */
699 beq t0,no_monitor_exit /* if zero no monitorexit */
700 addq sp,t0,t0 /* add stackptr to Offset */
701 ldq a0,-8(t0) /* load monitorexit pointer */
703 lda sp,-7*8(sp) /* allocate stack */
704 stq t0,0*8(sp) /* save used register */
712 br ra,ex_mon_load /* set ra for gp loading */
714 ldgp gp,0(ra) /* load gp */
715 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
717 ldq t0,0*8(sp) /* restore used register */
724 lda sp,7*8(sp) /* deallocate stack */
727 ldl t0,FrameSize(pv) /* t0 = frame size */
728 addq sp,t0,sp /* unwind stack */
729 mov sp,t0 /* t0 = pointer to save area */
730 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
731 bne t1,ex_no_restore /* if (leaf) skip */
732 ldq ra,-8(t0) /* restore ra */
733 lda t0,-8(t0) /* t0-- */
735 mov ra,xpc /* the new xpc is ra */
736 ldl t1,IntSave(pv) /* t1 = saved int register count */
737 br t2,ex_int1 /* t2 = current pc */
739 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
740 negl t1,t1 /* negate register count */
741 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
742 jmp zero,(t2) /* jump to save position */
751 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
753 ldl t1,FltSave(pv) /* t1 = saved flt register count */
754 br t2,ex_flt1 /* t2 = current pc */
756 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
757 negl t1,t1 /* negate register count */
758 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
759 jmp zero,(t2) /* jump to save position */
769 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
771 sra t0,48,t0 /* isolate offset */
772 addq t0,ra,pv /* compute update address */
773 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
774 srl t0,16,t0 /* isolate instruction code */
775 lda t0,-0x177b(t0) /* test for LDAH */
777 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
778 sll t0,16,t0 /* compute high offset */
779 addl t0,0,t0 /* sign extend high offset */
780 addq t0,pv,pv /* compute update address */
783 .end asm_handle_nat_exception
786 /********************* asm_check_clinit ****************************************
788 * Does null check and calls monitorenter or throws an exception *
790 *******************************************************************************/
792 .ent asm_check_clinit
796 ldl itmp2,offclassinit(itmp1)
797 bne itmp2,L_is_initialized
801 stq a0,1*8(sp) /* save argument registers for leaf funcs */
813 ldq a0,1*8(sp) /* restore argument registers */
822 mov ra,itmp1 /* now patch the calling code */
823 subq itmp1,(3*4),itmp1 /* go back 3 instructions */
824 ldah itmp2,-15392(zero) /* br -- 0xc3e0 == -15392 */
825 lda itmp2,4(itmp2) /* jump over 4 instructions */
826 stl itmp2,0(itmp1) /* store the new branch: br +4 */
830 .end asm_check_clinit
833 /********************* function asm_builtin_monitorenter ***********************
835 * Does null check and calls monitorenter or throws an exception *
837 *******************************************************************************/
839 .ent asm_builtin_monitorenter
840 asm_builtin_monitorenter:
842 lda pv,builtin_monitorenter
843 beq a0,nb_monitorenter /* if (null) throw exception */
844 jmp zero,(pv) /* else call builtin_monitorenter */
849 ldq a0,string_java_lang_NullPointerException
850 jsr ra,new_exception_message
856 lda xpc,-4(ra) /* faulting address is return adress - 4*/
857 br asm_handle_nat_exception
858 .end asm_builtin_monitorenter
861 /********************* function asm_builtin_monitorexit ************************
863 * Does null check and calls monitorexit or throws an exception *
865 *******************************************************************************/
867 .ent asm_builtin_monitorexit
868 asm_builtin_monitorexit:
870 lda pv,builtin_monitorexit
871 beq a0,nb_monitorexit /* if (null) throw exception */
872 jmp zero,(pv) /* else call builtin_monitorexit */
877 ldq a0,string_java_lang_NullPointerException
878 jsr ra,new_exception_message
884 lda xpc,-4(ra) /* faulting address is return adress - 4*/
885 br asm_handle_nat_exception
886 .end asm_builtin_monitorexit
889 /************************ function asm_builtin_idiv ****************************
891 * Does null check and calls idiv or throws an exception *
893 *******************************************************************************/
895 .ent asm_builtin_idiv
900 beq a1,nb_idiv /* if (null) throw exception */
901 jmp zero,(pv) /* else call builtin_idiv */
906 ldq a0,string_java_lang_ArithmeticException
907 ldq a1,string_java_lang_ArithmeticException_message
908 jsr ra,new_exception_message
914 lda xpc,-4(ra) /* faulting address is return adress - 4*/
915 br asm_handle_nat_exception
917 .end asm_builtin_idiv
920 /************************ function asm_builtin_ldiv ****************************
922 * Does null check and calls ldiv or throws an exception *
924 *******************************************************************************/
926 .ent asm_builtin_ldiv
931 beq a1,nb_ldiv /* if (null) throw exception */
932 jmp zero,(pv) /* else call builtin_ldiv */
937 ldq a0,string_java_lang_ArithmeticException
938 ldq a1,string_java_lang_ArithmeticException_message
939 jsr ra,new_exception_message
945 lda xpc,-4(ra) /* faulting address is return adress - 4*/
946 br asm_handle_nat_exception
948 .end asm_builtin_ldiv
951 /************************ function asm_builtin_irem ****************************
953 * Does null check and calls irem or throws an exception *
955 *******************************************************************************/
957 .ent asm_builtin_irem
962 beq a1,nb_irem /* if (null) throw exception */
963 jmp zero,(pv) /* else call builtin_irem */
968 ldq a0,string_java_lang_ArithmeticException
969 ldq a1,string_java_lang_ArithmeticException_message
970 jsr ra,new_exception_message
976 lda xpc,-4(ra) /* faulting address is return adress - 4*/
977 br asm_handle_nat_exception
979 .end asm_builtin_irem
982 /************************ function asm_builtin_lrem ****************************
984 * Does null check and calls lrem or throws an exception *
986 *******************************************************************************/
988 .ent asm_builtin_lrem
993 beq a1,nb_lrem /* if (null) throw exception */
994 jmp zero,(pv) /* else call builtin_lrem */
999 ldq a0,string_java_lang_ArithmeticException
1000 ldq a1,string_java_lang_ArithmeticException_message
1001 jsr ra,new_exception_message
1007 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1008 br asm_handle_nat_exception
1010 .end asm_builtin_lrem
1013 /*********************** function new_builtin_checkcast ************************
1015 * Does the cast check and eventually throws an exception *
1017 *******************************************************************************/
1019 .ent asm_builtin_checkcast
1021 asm_builtin_checkcast:
1023 lda sp,-16(sp) # allocate stack space
1024 stq ra,0(sp) # save return address
1025 stq a0,8(sp) # save object pointer
1026 jsr ra,builtin_checkcast # builtin_checkcast
1028 beq v0,nb_ccast_throw # if (false) throw exception
1029 ldq ra,0(sp) # restore return address
1030 ldq v0,8(sp) # return object pointer
1031 lda sp,16(sp) # free stack space
1035 ldq a0,string_java_lang_ClassCastException
1036 jsr ra,new_exception
1040 ldq ra,0(sp) # restore return address
1041 lda sp,16(sp) # free stack space
1042 lda xpc,-4(ra) # faulting address is return adress - 4
1043 br asm_handle_nat_exception
1045 .end asm_builtin_checkcast
1048 /******************* function asm_builtin_checkarraycast ***********************
1050 * Does the cast check and eventually throws an exception *
1052 *******************************************************************************/
1054 .ent asm_builtin_checkarraycast
1056 asm_builtin_checkarraycast:
1058 lda sp,-16(sp) /* allocate stack space */
1059 stq ra,0(sp) /* save return address */
1060 stq a0,8(sp) /* save object pointer */
1061 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1063 beq v0,nb_carray_throw /* if (false) throw exception */
1064 ldq ra,0(sp) /* restore return address */
1065 ldq v0,8(sp) /* return object pointer */
1066 lda sp,16(sp) /* free stack space */
1070 ldq a0,string_java_lang_ClassCastException
1071 jsr ra,new_exception
1075 ldq ra,0(sp) /* restore return address */
1076 lda sp,16(sp) /* free stack space */
1077 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1078 br asm_handle_nat_exception
1080 .end asm_builtin_checkarraycast
1083 /******************* function asm_builtin_aastore ******************************
1085 * Does the cast check and eventually throws an exception *
1087 *******************************************************************************/
1089 .ent asm_builtin_aastore
1091 asm_builtin_aastore:
1093 beq a0,nb_aastore_null /* if null pointer throw exception */
1094 ldl t0,offarraysize(a0) /* load size */
1095 lda sp,-24(sp) /* allocate stack space */
1096 stq ra,0(sp) /* save return address */
1097 s8addq a1,a0,t1 /* add index*8 to arrayref */
1098 cmpult a1,t0,t0 /* do bound check */
1099 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1100 mov a2,a1 /* object is second argument */
1101 stq t1,8(sp) /* save store position */
1102 stq a1,16(sp) /* save object */
1103 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1105 ldq ra,0(sp) /* restore return address */
1106 ldq a0,8(sp) /* restore store position */
1107 ldq a1,16(sp) /* restore object */
1108 lda sp,24(sp) /* free stack space */
1109 beq v0,nb_aastore_throw /* if (false) throw exception */
1110 stq a1,offobjarrdata(a0) /* store objectptr in array */
1114 subq sp,8,sp /* allocate stack space */
1115 stq ra,0(sp) /* save return address */
1116 ldq a0,string_java_lang_NullPointerException
1117 jsr ra,new_exception
1123 mov ra,xpc /* faulting address is return adress */
1124 br asm_handle_nat_exception
1127 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1128 jsr ra,new_exception_int /* a1 already contains the index */
1132 ldq ra,0(sp) /* restore return address */
1133 lda sp,24(sp) /* free stack space */
1134 mov ra,xpc /* faulting address is return adress */
1135 br asm_handle_nat_exception
1138 subq sp,8,sp /* allocate stack space */
1139 stq ra,0(sp) /* save return address */
1140 ldq a0,string_java_lang_ArrayStoreException
1141 jsr ra,new_exception
1147 mov ra,xpc /* faulting address is return adress */
1148 br asm_handle_nat_exception
1150 .end asm_builtin_aastore
1153 /******************* function asm_initialize_thread_stack **********************
1155 * initialized a thread stack *
1157 *******************************************************************************/
1159 .ent asm_initialize_thread_stack
1161 asm_initialize_thread_stack:
1182 .end asm_initialize_thread_stack
1185 /******************* function asm_perform_threadswitch *************************
1187 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1189 * performs a threadswitch *
1191 *******************************************************************************/
1193 .ent asm_perform_threadswitch
1195 asm_perform_threadswitch:
1236 .end asm_perform_threadswitch
1239 /********************* function asm_switchstackandcall *************************
1241 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1244 * Switches to a new stack, calls a function and switches back. *
1245 * a0 new stack pointer *
1246 * a1 function pointer *
1247 * a2 pointer to variable where stack top should be stored *
1248 * a3 pointer to user data, is passed to the function *
1250 *******************************************************************************/
1253 .ent asm_switchstackandcall
1255 asm_switchstackandcall:
1256 lda a0,-2*8(a0) /* allocate new stack */
1257 stq ra,0(a0) /* save return address on new stack */
1258 stq sp,1*8(a0) /* save old stack pointer on new stack */
1259 stq sp,0(a2) /* save old stack pointer to variable */
1260 mov a0,sp /* switch to new stack */
1262 mov a1,pv /* load function pointer */
1263 mov a3,a0 /* pass pointer */
1264 jmp ra,(pv) /* and call function */
1266 ldq ra,0(sp) /* load return address */
1267 ldq sp,1*8(sp) /* switch to old stack */
1269 jmp zero,(ra) /* return */
1271 .end asm_switchstackandcall
1274 /********************* function asm_getcallingmethod ***************************
1276 * classinfo *asm_getcallingmethodclass (); *
1278 * goes back stack frames to get the calling method *
1284 *******************************************************************************/
1287 .ent asm_getcallingmethod
1289 asm_getcallingmethod:
1290 ldq t3,16(sp) /* load return address of native function */
1291 addq sp,24,t2 /* skip frames of C-Function and nativestub */
1293 /* determine pv (t3) of java-function from ra */
1295 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1297 sra t0,48,t0 /* isolate offset */
1298 addq t0,t3,t4 /* compute update address */
1299 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1300 srl t0,16,t0 /* isolate instruction code */
1301 lda t0,-0x177b(t0) /* test for LDAH */
1303 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1304 sll t0,16,t0 /* compute high offset */
1305 addl t0,0,t0 /* sign extend high offset */
1306 addq t0,t4,t4 /* compute update address */
1309 ldl t0,FrameSize(t4) /* t0 = frame size */
1310 addq t2,t0,t2 /* skip frame of java function */
1311 ldq t3,-8(t2) /* load new ra */
1313 /* determine pv (t3) of java-function from ra */
1315 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1317 sra t0,48,t0 /* isolate offset */
1318 addq t0,t3,t4 /* compute update address */
1319 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1320 srl t0,16,t0 /* isolate instruction code */
1321 lda t0,-0x177b(t0) /* test for LDAH */
1323 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1324 sll t0,16,t0 /* compute high offset */
1325 addl t0,0,t0 /* sign extend high offset */
1326 addq t0,t4,t4 /* compute update address */
1329 ldq v0,MethodPointer(t4) /* */
1331 jmp zero,(ra) /* return */
1333 .end asm_getcallingmethod
1337 * These are local overrides for various environment variables in Emacs.
1338 * Please do not remove this and leave it at the end of the file, where
1339 * Emacs will automagically detect them.
1340 * ---------------------------------------------------------------------
1343 * indent-tabs-mode: t