1 /* -*- mode: asm; tab-width: 4 -*- */
2 /****************************** asmpart.S **************************************
4 * It contains the Java-C interface functions for Alpha processors. *
6 * Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst *
8 * See file COPYRIGHT for information on usage and disclaimer of warranties *
10 * Authors: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at *
11 * Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at *
13 * Last Change: 2003/02/17 *
15 *******************************************************************************/
84 /********************* exported functions and variables ***********************/
86 .globl has_no_x_instr_set
87 .globl synchronize_caches
88 .globl asm_calljavamethod
89 .globl asm_calljavafunction
90 .globl asm_calljavafunction2
91 .globl asm_calljavafunction2double
92 .globl asm_calljavafunction2long
93 .globl asm_call_jit_compiler
94 .globl asm_dumpregistersandcall
95 .globl asm_handle_exception
96 .globl asm_handle_nat_exception
97 .globl asm_builtin_checkcast
98 .globl asm_builtin_checkarraycast
99 .globl asm_builtin_aastore
100 .globl asm_builtin_monitorenter
101 .globl asm_builtin_monitorexit
102 .globl asm_builtin_idiv
103 .globl asm_builtin_irem
104 .globl asm_builtin_ldiv
105 .globl asm_builtin_lrem
106 .globl asm_perform_threadswitch
107 .globl asm_initialize_thread_stack
108 .globl asm_switchstackandcall
109 .globl asm_getcallingmethod
110 .globl asm_builtin_trace
111 .globl asm_builtin_exittrace
113 /*************************** imported functions *******************************/
116 .globl builtin_monitorexit
117 .globl builtin_throw_exception
118 .globl builtin_trace_exception
119 .globl class_java_lang_Object
122 /*********************** function has_no_x_instr_set ***************************
124 * determines if the byte support instruction set (21164a and higher) *
127 *******************************************************************************/
129 .ent has_no_x_instr_set
132 .long 0x47e03c20 /* amask 1,v0 */
133 jmp zero,(ra) /* return */
135 .end has_no_x_instr_set
138 /********************* function synchronize_caches ****************************/
140 .ent synchronize_caches
143 call_pal PAL_imb /* synchronise instruction cache */
144 jmp zero,(ra) /* return */
146 .end synchronize_caches
149 /********************* function asm_calljavamethod *****************************
151 * This function calls a Java-method (which possibly needs compilation) *
152 * with up to 4 parameters. *
154 * This functions calls the JIT-compiler which eventually translates the *
155 * method into machine code. *
157 * An possibly throwed exception will be returned to the caller as function *
158 * return value, so the java method cannot return a fucntion value (this *
159 * function usually calls 'main' and '<clinit>' which do not return a *
163 * javaobject_header *asm_calljavamethod (methodinfo *m, *
164 * void *arg1, void *arg2, void *arg3, void *arg4); *
166 *******************************************************************************/
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 .ent asm_calljavamethod
186 .ascii "calljavamethod\0\0"
189 .quad 0 /* catch type all */
190 .quad calljava_xhandler /* handler pc */
191 .quad calljava_xhandler /* end pc */
192 .quad asm_calljavamethod /* start pc */
193 .long 1 /* extable size */
194 .long 0 /* fltsave */
195 .long 0 /* intsave */
198 .long 32 /* frame size */
199 .quad 0 /* method pointer (pointer to name) */
204 lda sp,-32(sp) /* allocate stack space */
205 stq gp,24(sp) /* save global pointer */
206 stq ra,0(sp) /* save return address */
208 stq a0,16(sp) /* save method pointer for compiler */
209 lda v0,16(sp) /* pass pointer to method pointer via v0*/
211 mov a1,a0 /* pass the remaining parameters */
216 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
217 stq $28,8(sp) /* store function address */
218 mov sp,$28 /* set method pointer */
220 ldq pv,8($28) /* method call as in Java */
221 jmp ra,(pv) /* call JIT compiler */
223 lda pv,-64(ra) /* asm_calljavamethod-calljava_jit !!!!!*/
227 ldq ra,0(sp) /* restore return address */
228 ldq gp,24(sp) /* restore global pointer */
229 lda sp,32(sp) /* free stack space */
237 ldq gp,24(sp) /* restore global pointer */
239 jsr ra,builtin_throw_exception
240 ldq ra,0(sp) /* restore return address */
241 lda sp,32(sp) /* free stack space */
243 .end asm_calljavamethod
246 /********************* function asm_calljavafunction ***************************
248 * This function calls a Java-method (which possibly needs compilation) *
249 * with up to 4 address parameters. *
251 * This functions calls the JIT-compiler which eventually translates the *
252 * method into machine code. *
255 * javaobject_header *asm_calljavamethod (methodinfo *m, *
256 * void *arg1, void *arg2, void *arg3, void *arg4); *
258 *******************************************************************************/
260 .ent asm_calljavafunction
263 .ascii "calljavafunction\0\0"
266 .quad 0 /* catch type all */
267 .quad calljava_xhandler2 /* handler pc */
268 .quad calljava_xhandler2 /* end pc */
269 .quad asm_calljavafunction /* start pc */
270 .long 1 /* extable size */
271 .long 0 /* fltsave */
272 .long 0 /* intsave */
275 .long 32 /* frame size */
276 .quad 0 /* method pointer (pointer to name) */
278 asm_calljavafunction:
281 lda sp,-32(sp) /* allocate stack space */
282 stq gp,24(sp) /* save global pointer */
283 stq ra,0(sp) /* save return address */
285 stq a0,16(sp) /* save method pointer for compiler */
286 lda v0,16(sp) /* pass pointer to method pointer via v0*/
288 mov a1,a0 /* pass the remaining parameters */
293 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
294 stq $28,8(sp) /* store function address */
295 mov sp,$28 /* set method pointer */
297 ldq pv,8($28) /* method call as in Java */
298 jmp ra,(pv) /* call JIT compiler */
300 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
304 ldq ra,0(sp) /* restore return address */
305 ldq gp,24(sp) /* restore global pointer */
306 lda sp,32(sp) /* free stack space */
313 ldq gp,24(sp) /* restore global pointer */
315 jsr ra,builtin_throw_exception
316 ldq ra,0(sp) /* restore return address */
317 lda sp,32(sp) /* free stack space */
319 .end asm_calljavafunction
324 .ent asm_calljavafunction2
325 .ent asm_calljavafunction2double
326 .ent asm_calljavafunction2long
329 .ascii "calljavafunction2\0\0"
332 .quad 0 /* catch type all */
333 .quad calljava_xhandler3 /* handler pc */
334 .quad calljava_xhandler3 /* end pc */
335 .quad asm_calljavafunction2 /* start pc */
336 .long 1 /* extable size */
337 .long 0 /* fltsave */
338 .long 1 /* intsave */
341 .long 40 /* frame size */
342 .quad 0 /* method pointer (pointer to name) */
344 asm_calljavafunction2:
347 lda sp,-40(sp) /* allocate stack space */
348 stq ra,0(sp) /* save return address */
350 stq gp,8(sp) /* save global pointer */
352 stq a0,32(sp) /* save method pointer for compiler */
353 mov a3,t0 /* pointer to arg block */
354 mov a1,s6 /* arg count */
356 ble s6,calljava_argsloaded
358 ldq a0,offjniitem(t0)
359 ldt $f16,offjniitem(t0)
360 ble s6,calljava_argsloaded
362 ldq a1,offjniitem+sizejniblock*1(t0)
363 ldt $f17,offjniitem+sizejniblock*1(t0)
364 ble s6,calljava_argsloaded
366 ldq a2,offjniitem+sizejniblock*2(t0)
367 ldt $f18,offjniitem+sizejniblock*2(t0)
368 ble s6,calljava_argsloaded
370 ldq a3,offjniitem+sizejniblock*3(t0)
371 ldt $f19,offjniitem+sizejniblock*3(t0)
372 ble s6,calljava_argsloaded
374 ldq a4,offjniitem+sizejniblock*4(t0)
375 ldt $f20,offjniitem+sizejniblock*4(t0)
376 ble s6,calljava_argsloaded
378 ldq a5,offjniitem+sizejniblock*5(t0)
379 ldt $f21,offjniitem+sizejniblock*5(t0)
382 ble s6,calljava_nocopy
388 ldq t3,offjniitem+sizejniblock*6(t0)
391 lda t0,sizejniblock(t0)
393 bne t1,calljava_copyloop
396 lda v0,32(t4) /* pass pointer to method pointer via v0*/
398 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
399 stq $28,16(t4) /* store function address */
400 lda $28,8(t4) /* set method pointer */
402 ldq pv,8($28) /* method call as in Java */
403 jmp ra,(pv) /* call JIT compiler */
405 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
410 ldq ra,0(sp) /* restore return address */
411 ldq gp,8(sp) /* restore global pointer */
413 lda sp,40(sp) /* free stack space */
421 ldq gp,8(sp) /* restore global pointer */
423 jsr ra,builtin_throw_exception
424 ldq ra,0(sp) /* restore return address */
426 lda sp,40(sp) /* free stack space */
428 .end asm_calljavafunction2
431 /****************** function asm_call_jit_compiler *****************************
433 * invokes the compiler for untranslated JavaVM methods. *
435 * Register R0 contains a pointer to the method info structure (prepared *
436 * by createcompilerstub). Using the return address in R26 and the *
437 * offset in the LDA instruction or using the value in methodptr R28 the *
438 * patching address for storing the method address can be computed: *
440 * method address was either loaded using *
441 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
442 * M_LDA (REG_PV, REG_RA, low) *
443 * M_LDAH(REG_PV, REG_RA, high) ; optional *
445 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
446 * in the static case the method pointer can be computed using the *
447 * return address and the lda function following the jmp instruction *
449 *******************************************************************************/
452 .ent asm_call_jit_compiler
453 asm_call_jit_compiler:
456 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
457 srl t8,16,t8 /* shift right register number $yy */
458 and t8,31,t8 /* isolate register number */
459 subl t8,28,t8 /* test for REG_METHODPTR */
461 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
463 sra t8,48,t8 /* isolate offset */
464 addq t8,ra,$28 /* compute update address */
465 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
466 srl t8,16,t8 /* isolate instruction code */
467 lda t8,-0x177b(t8) /* test for LDAH */
469 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
470 sll t8,16,t8 /* compute high offset */
471 addl t8,0,t8 /* sign extend high offset */
472 addq t8,$28,$28 /* compute update address */
474 lda sp,-14*8(sp) /* reserve stack space */
475 stq a0,0*8(sp) /* save all argument registers */
476 stq a1,1*8(sp) /* they could be used by method */
487 stq $28,12*8(sp) /* save method pointer */
488 stq ra,13*8(sp) /* save return address */
490 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
491 jsr ra,jit_compile /* jit compiler */
494 call_pal PAL_imb /* synchronise instruction cache */
496 ldq a0,0*8(sp) /* load argument registers */
508 ldq $28,12*8(sp) /* load method pointer */
509 ldq ra,13*8(sp) /* load return address */
510 lda sp,14*8(sp) /* deallocate stack area */
512 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
514 sra t8,48,t8 /* isolate offset */
516 addq t8,$28,t8 /* compute update address via method pointer*/
517 stq v0,0(t8) /* save new method address there */
519 mov v0,pv /* load method address into pv */
521 jmp zero,(pv) /* and call method. The method returns */
522 /* directly to the caller (ra). */
524 .end asm_call_jit_compiler
527 /****************** function asm_dumpregistersandcall **************************
529 * This funtion saves all callee saved registers and calls the function *
530 * which is passed as parameter. *
532 * This function is needed by the garbage collector, which needs to access *
533 * all registers which are stored on the stack. Unused registers are *
534 * cleared to avoid interferances with the GC. *
536 * void asm_dumpregistersandcall (functionptr f); *
538 *******************************************************************************/
540 .ent asm_dumpregistersandcall
541 asm_dumpregistersandcall:
542 lda sp,-16*8(sp) /* allocate stack */
543 stq ra,0(sp) /* save return address */
545 stq s0,1*8(sp) /* save all callee saved registers */
546 stq s1,2*8(sp) /* intialize the remaining registers */
561 clr v0 /* intialize the remaining registers */
606 mov a0,pv /* load function pointer */
607 jmp ra,(pv) /* and call function */
609 ldq ra,0(sp) /* load return address */
610 lda sp,16*8(sp) /* deallocate stack */
611 jmp zero,(ra) /* return */
613 .end asm_dumpregistersandcall
616 /********************* function asm_handle_exception ***************************
618 * This function handles an exception. It does not use the usual calling *
619 * conventions. The exception pointer is passed in REG_ITMP1 and the *
620 * pc from the exception raising position is passed in REG_ITMP2. It searches *
621 * the local exception table for a handler. If no one is found, it unwinds *
622 * stacks and continues searching the callers. *
624 * void asm_handle_exception (exceptionptr, exceptionpc); *
626 *******************************************************************************/
628 .ent asm_handle_nat_exception
629 asm_handle_nat_exception:
631 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
633 sra t0,48,t0 /* isolate offset */
634 addq t0,ra,pv /* compute update address */
635 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
636 srl t0,16,t0 /* isolate instruction code */
637 lda t0,-0x177b(t0) /* test for LDAH */
638 bne t0,asm_handle_exception
639 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
640 sll t0,16,t0 /* compute high offset */
641 addl t0,0,t0 /* sign extend high offset */
642 addq t0,pv,pv /* compute update address */
644 .aent asm_handle_exception
645 asm_handle_exception:
647 lda sp,-18*8(sp) /* allocate stack */
648 stq t0,0*8(sp) /* save possible used registers */
649 stq t1,1*8(sp) /* also registers used by trace_exception */
667 lda t3,1(zero) /* set no unwind flag */
669 lda sp,-5*8(sp) /* allocate stack */
670 stq xptr,0*8(sp) /* save used register */
677 ldq a1,MethodPointer(pv)
680 br ra,ex_trace /* set ra for gp loading */
682 ldgp gp,0(ra) /* load gp */
683 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
685 ldq xptr,0*8(sp) /* restore used register */
690 lda sp,5*8(sp) /* deallocate stack */
692 ldl t0,ExTableSize(pv) /* t0 = exception table size */
693 beq t0,empty_table /* if empty table skip */
694 lda t1,ExTableStart(pv) /* t1 = start of exception table */
697 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
698 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
699 beq t2,ex_table_cont /* if (false) continue */
700 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
701 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
702 beq t2,ex_table_cont /* if (false) continue */
703 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
704 beq a1,ex_handle_it /* NULL catches everything */
706 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
707 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
708 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
709 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
710 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
711 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
712 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
713 beq v0,ex_table_cont /* if (false) continue */
717 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
719 beq t3,ex_jump /* if (!(no stack unwinding) skip */
721 ldq t0,0*8(sp) /* restore possible used registers */
722 ldq t1,1*8(sp) /* also registers used by trace_exception */
739 lda sp,18*8(sp) /* deallocate stack */
742 jmp zero,(xpc) /* jump to the handler */
745 lda t1,ExEntrySize(t1) /* next exception table entry */
746 subl t0,1,t0 /* decrement entry counter */
747 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
750 beq t3,ex_already_cleared /* if here the first time, then */
751 lda sp,18*8(sp) /* deallocate stack and */
752 clr t3 /* clear the no unwind flag */
754 ldl t0,IsSync(pv) /* t0 = SyncOffset */
755 beq t0,no_monitor_exit /* if zero no monitorexit */
756 addq sp,t0,t0 /* add stackptr to Offset */
757 ldq a0,-8(t0) /* load monitorexit pointer */
759 lda sp,-7*8(sp) /* allocate stack */
760 stq t0,0*8(sp) /* save used register */
768 br ra,ex_mon_load /* set ra for gp loading */
770 ldgp gp,0(ra) /* load gp */
771 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
773 ldq t0,0*8(sp) /* restore used register */
780 lda sp,7*8(sp) /* deallocate stack */
783 ldl t0,FrameSize(pv) /* t0 = frame size */
784 addq sp,t0,sp /* unwind stack */
785 mov sp,t0 /* t0 = pointer to save area */
786 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
787 bne t1,ex_no_restore /* if (leaf) skip */
788 ldq ra,-8(t0) /* restore ra */
789 lda t0,-8(t0) /* t0-- */
791 mov ra,xpc /* the new xpc is ra */
792 ldl t1,IntSave(pv) /* t1 = saved int register count */
793 br t2,ex_int1 /* t2 = current pc */
795 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
796 negl t1,t1 /* negate register count */
797 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
798 jmp zero,(t2) /* jump to save position */
807 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
809 ldl t1,FltSave(pv) /* t1 = saved flt register count */
810 br t2,ex_flt1 /* t2 = current pc */
812 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
813 negl t1,t1 /* negate register count */
814 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
815 jmp zero,(t2) /* jump to save position */
825 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
827 sra t0,48,t0 /* isolate offset */
828 addq t0,ra,pv /* compute update address */
829 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
830 srl t0,16,t0 /* isolate instruction code */
831 lda t0,-0x177b(t0) /* test for LDAH */
833 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
834 sll t0,16,t0 /* compute high offset */
835 addl t0,0,t0 /* sign extend high offset */
836 addq t0,pv,pv /* compute update address */
839 .end asm_handle_nat_exception
842 /********************* function asm_builtin_monitorenter ***********************
844 * Does null check and calls monitorenter or throws an exception *
846 *******************************************************************************/
848 .ent asm_builtin_monitorenter
849 asm_builtin_monitorenter:
852 lda pv,builtin_monitorenter
853 beq a0,nb_monitorenter /* if (null) throw exception */
854 jmp zero,(pv) /* else call builtin_monitorenter */
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_monitorenter
863 /********************* function asm_builtin_monitorexit ************************
865 * Does null check and calls monitorexit or throws an exception *
867 *******************************************************************************/
869 .ent asm_builtin_monitorexit
870 asm_builtin_monitorexit:
873 lda pv,builtin_monitorexit
874 beq a0,nb_monitorexit /* if (null) throw exception */
875 jmp zero,(pv) /* else call builtin_monitorexit */
878 ldq xptr,proto_java_lang_NullPointerException
879 lda xpc,-4(ra) /* faulting address is return adress - 4*/
880 br asm_handle_nat_exception
881 .end asm_builtin_monitorexit
884 /************************ function asm_builtin_idiv ****************************
886 * Does null check and calls idiv or throws an exception *
888 *******************************************************************************/
890 .ent asm_builtin_idiv
895 beq a1,nb_idiv /* if (null) throw exception */
896 jmp zero,(pv) /* else call builtin_idiv */
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_idiv
905 /************************ function asm_builtin_ldiv ****************************
907 * Does null check and calls ldiv or throws an exception *
909 *******************************************************************************/
911 .ent asm_builtin_ldiv
916 beq a1,nb_ldiv /* if (null) throw exception */
917 jmp zero,(pv) /* else call builtin_ldiv */
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_ldiv
926 /************************ function asm_builtin_irem ****************************
928 * Does null check and calls irem or throws an exception *
930 *******************************************************************************/
932 .ent asm_builtin_irem
937 beq a1,nb_irem /* if (null) throw exception */
938 jmp zero,(pv) /* else call builtin_irem */
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_irem
947 /************************ function asm_builtin_lrem ****************************
949 * Does null check and calls lrem or throws an exception *
951 *******************************************************************************/
953 .ent asm_builtin_lrem
958 beq a1,nb_lrem /* if (null) throw exception */
959 jmp zero,(pv) /* else call builtin_lrem */
962 ldq xptr,proto_java_lang_ArithmeticException
963 lda xpc,-4(ra) /* faulting address is return adress - 4*/
964 br asm_handle_nat_exception
965 .end asm_builtin_lrem
968 /*********************** function new_builtin_checkcast ************************
970 * Does the cast check and eventually throws an exception *
972 *******************************************************************************/
974 .ent asm_builtin_checkcast
975 asm_builtin_checkcast:
978 lda sp,-16(sp) # allocate stack space
979 stq ra,0(sp) # save return address
980 stq a0,8(sp) # save object pointer
981 jsr ra,builtin_checkcast # builtin_checkcast
983 beq v0,nb_ccast_throw # if (false) throw exception
984 ldq ra,0(sp) # restore return address
985 ldq v0,8(sp) # return object pointer
986 lda sp,16(sp) # free stack space
990 ldq xptr,proto_java_lang_ClassCastException
991 ldq ra,0(sp) # restore return address
992 lda sp,16(sp) # free stack space
993 lda xpc,-4(ra) # faulting address is return adress - 4
994 br asm_handle_nat_exception
995 .end asm_builtin_checkcast
998 /******************* function asm_builtin_checkarraycast ***********************
1000 * Does the cast check and eventually throws an exception *
1002 *******************************************************************************/
1004 .ent asm_builtin_checkarraycast
1005 asm_builtin_checkarraycast:
1008 lda sp,-16(sp) /* allocate stack space */
1009 stq ra,0(sp) /* save return address */
1010 stq a0,8(sp) /* save object pointer */
1011 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1013 beq v0,nb_carray_throw /* if (false) throw exception */
1014 ldq ra,0(sp) /* restore return address */
1015 ldq v0,8(sp) /* return object pointer */
1016 lda sp,16(sp) /* free stack space */
1020 ldq xptr,proto_java_lang_ClassCastException
1021 ldq ra,0(sp) /* restore return address */
1022 lda sp,16(sp) /* free stack space */
1023 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1024 br asm_handle_nat_exception
1025 .end asm_builtin_checkarraycast
1028 /******************* function asm_builtin_aastore ******************************
1030 * Does the cast check and eventually throws an exception *
1032 *******************************************************************************/
1034 .ent asm_builtin_aastore
1035 asm_builtin_aastore:
1038 beq a0,nb_aastore_null /* if null pointer throw exception */
1039 ldl t0,offarraysize(a0) /* load size */
1040 lda sp,-24(sp) /* allocate stack space */
1041 stq ra,0(sp) /* save return address */
1042 s8addq a1,a0,t1 /* add index*8 to arrayref */
1043 cmpult a1,t0,t0 /* do bound check */
1044 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1045 mov a2,a1 /* object is second argument */
1046 stq t1,8(sp) /* save store position */
1047 stq a1,16(sp) /* save object */
1048 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1050 ldq ra,0(sp) /* restore return address */
1051 ldq a0,8(sp) /* restore store position */
1052 ldq a1,16(sp) /* restore object */
1053 lda sp,24(sp) /* free stack space */
1054 beq v0,nb_aastore_throw /* if (false) throw exception */
1055 stq a1,offobjarrdata(a0) /* store objectptr in array */
1059 ldq xptr,proto_java_lang_NullPointerException
1060 mov ra,xpc /* faulting address is return adress */
1061 br asm_handle_nat_exception
1064 ldq xptr,proto_java_lang_ArrayIndexOutOfBoundsException
1065 lda sp,24(sp) /* free stack space */
1066 mov ra,xpc /* faulting address is return adress */
1067 br asm_handle_nat_exception
1070 ldq xptr,proto_java_lang_ArrayStoreException
1071 mov ra,xpc /* faulting address is return adress */
1072 br asm_handle_nat_exception
1074 .end asm_builtin_aastore
1077 /******************* function asm_initialize_thread_stack **********************
1079 * initialized a thread stack *
1081 *******************************************************************************/
1083 .ent asm_initialize_thread_stack
1084 asm_initialize_thread_stack:
1105 .end asm_initialize_thread_stack
1108 /******************* function asm_perform_threadswitch *************************
1110 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1112 * performs a threadswitch *
1114 *******************************************************************************/
1116 .ent asm_perform_threadswitch
1117 asm_perform_threadswitch:
1158 .end asm_perform_threadswitch
1161 /********************* function asm_switchstackandcall *************************
1163 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1166 * Switches to a new stack, calls a function and switches back. *
1167 * a0 new stack pointer *
1168 * a1 function pointer *
1169 * a2 pointer to variable where stack top should be stored *
1170 * a3 pointer to user data, is passed to the function *
1172 *******************************************************************************/
1175 .ent asm_switchstackandcall
1176 asm_switchstackandcall:
1177 lda a0,-2*8(a0) /* allocate new stack */
1178 stq ra,0(a0) /* save return address on new stack */
1179 stq sp,1*8(a0) /* save old stack pointer on new stack */
1180 stq sp,0(a2) /* save old stack pointer to variable */
1181 mov a0,sp /* switch to new stack */
1183 mov a1,pv /* load function pointer */
1184 mov a3,a0 /* pass pointer */
1185 jmp ra,(pv) /* and call function */
1187 ldq ra,0(sp) /* load return address */
1188 ldq sp,1*8(sp) /* switch to old stack */
1190 jmp zero,(ra) /* return */
1192 .end asm_switchstackandcall
1195 /********************* function asm_getcallingmethod ***************************
1197 * classinfo *asm_getcallingmethodclass (); *
1199 * goes back stack frames to get the calling method *
1205 *******************************************************************************/
1208 .ent asm_getcallingmethod
1209 asm_getcallingmethod:
1211 ldq t3,16(sp) /* load return address of native function */
1212 addq sp,24,t2 /* skip frames of C-Function and nativestub */
1214 /* determine pv (t3) of java-function from ra */
1216 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1218 sra t0,48,t0 /* isolate offset */
1219 addq t0,t3,t4 /* compute update address */
1220 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1221 srl t0,16,t0 /* isolate instruction code */
1222 lda t0,-0x177b(t0) /* test for LDAH */
1224 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1225 sll t0,16,t0 /* compute high offset */
1226 addl t0,0,t0 /* sign extend high offset */
1227 addq t0,t4,t4 /* compute update address */
1230 ldl t0,FrameSize(t4) /* t0 = frame size */
1231 addq t2,t0,t2 /* skip frame of java function */
1232 ldq t3,-8(t2) /* load new ra */
1234 /* determine pv (t3) of java-function from ra */
1236 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1238 sra t0,48,t0 /* isolate offset */
1239 addq t0,t3,t4 /* compute update address */
1240 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1241 srl t0,16,t0 /* isolate instruction code */
1242 lda t0,-0x177b(t0) /* test for LDAH */
1244 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1245 sll t0,16,t0 /* compute high offset */
1246 addl t0,0,t0 /* sign extend high offset */
1247 addq t0,t4,t4 /* compute update address */
1250 ldq v0,MethodPointer(t4) /* */
1253 jmp zero,(ra) /* return */
1255 .end asm_getcallingmethod
1264 /*********************** function asm_builtin_trace ****************************
1266 * Intended to be called from the native stub. Saves all argument registers *
1267 * and calls builtin_trace_args. *
1269 *******************************************************************************/
1271 .ent asm_builtin_trace
1290 jsr ra,builtin_trace_args
1308 .end asm_builtin_trace
1311 /********************* function asm_builtin_exittrace **************************
1313 * Intended to be called from the native stub. Saves return value and calls *
1314 * builtin_displaymethodstop. *
1316 *******************************************************************************/
1318 .ent asm_builtin_exittrace
1319 asm_builtin_exittrace:
1326 jsr ra,builtin_displaymethodstop
1334 .end asm_builtin_exittrace