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 967 2004-03-18 14:29:03Z 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 LINE NUMBER STUFF HERE */
175 #define ExTableSize -56
176 #define ExTableStart -56
178 #define ExEntrySize -32
181 #define ExHandlerPC -24
182 #define ExCatchType -32
184 /********************* function asm_calljavafunction ***************************
186 * This function calls a Java-method (which possibly needs compilation) *
187 * with up to 4 address parameters. *
189 * This functions calls the JIT-compiler which eventually translates the *
190 * method into machine code. *
193 * javaobject_header *asm_calljavafunction (methodinfo *m, *
194 * void *arg1, void *arg2, void *arg3, void *arg4); *
196 *******************************************************************************/
198 .ent asm_calljavafunction
201 .ascii "calljavafunction\0\0"
204 .quad 0 /* catch type all */
205 .quad calljava_xhandler /* handler pc */
206 .quad calljava_xhandler /* end pc */
207 .quad asm_calljavafunction /* start pc */
208 .long 1 /* extable size */
209 .long 0 /* PADDING */
210 .quad 0 /* line number table start */
211 .quad 0 /* line number table size */
212 .long 0 /* PADDING */
213 .long 0 /* fltsave */
214 .long 0 /* intsave */
217 .long 32 /* frame size */
218 .quad 0 /* method pointer (pointer to name) */
220 asm_calljavafunction:
222 lda sp,-32(sp) /* allocate stack space */
223 stq gp,24(sp) /* save global pointer */
224 stq ra,0(sp) /* save return address */
226 stq a0,16(sp) /* save method pointer for compiler */
227 lda v0,16(sp) /* pass pointer to method pointer via v0*/
229 mov a1,a0 /* pass the remaining parameters */
234 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
235 stq $28,8(sp) /* store function address */
236 mov sp,$28 /* set method pointer */
238 ldq pv,8($28) /* method call as in Java */
239 jmp ra,(pv) /* call JIT compiler */
241 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
244 ldq ra,0(sp) /* restore return address */
245 ldq gp,24(sp) /* restore global pointer */
246 lda sp,32(sp) /* free stack space */
252 ldq gp,24(sp) /* restore global pointer */
254 jsr ra,builtin_throw_exception
255 ldq ra,0(sp) /* restore return address */
256 lda sp,32(sp) /* free stack space */
258 .end asm_calljavafunction
263 .ent asm_calljavafunction2
266 .ascii "calljavafunction2\0\0"
269 .quad 0 /* catch type all */
270 .quad calljava_xhandler2 /* handler pc */
271 .quad calljava_xhandler2 /* end pc */
272 .quad asm_calljavafunction2 /* start pc */
273 .long 1 /* extable size */
274 .long 0 /* PADDING */
275 .quad 0 /* line number table start */
276 .quad 0 /* line number table size */
277 .long 0 /* PADDING */
278 .long 0 /* fltsave */
279 .long 1 /* intsave */
282 .long 40 /* frame size */
283 .quad 0 /* method pointer (pointer to name) */
285 asm_calljavafunction2:
286 asm_calljavafunction2double:
287 asm_calljavafunction2long:
289 lda sp,-40(sp) /* allocate stack space */
290 stq ra,0(sp) /* save return address */
292 stq gp,8(sp) /* save global pointer */
294 stq a0,32(sp) /* save method pointer for compiler */
295 mov a3,t0 /* pointer to arg block */
296 mov a1,s6 /* arg count */
298 ble s6,calljava_argsloaded
300 ldq a0,offjniitem(t0)
301 ldt $f16,offjniitem(t0)
302 ble s6,calljava_argsloaded
304 ldq a1,offjniitem+sizejniblock*1(t0)
305 ldt $f17,offjniitem+sizejniblock*1(t0)
306 ble s6,calljava_argsloaded
308 ldq a2,offjniitem+sizejniblock*2(t0)
309 ldt $f18,offjniitem+sizejniblock*2(t0)
310 ble s6,calljava_argsloaded
312 ldq a3,offjniitem+sizejniblock*3(t0)
313 ldt $f19,offjniitem+sizejniblock*3(t0)
314 ble s6,calljava_argsloaded
316 ldq a4,offjniitem+sizejniblock*4(t0)
317 ldt $f20,offjniitem+sizejniblock*4(t0)
318 ble s6,calljava_argsloaded
320 ldq a5,offjniitem+sizejniblock*5(t0)
321 ldt $f21,offjniitem+sizejniblock*5(t0)
324 ble s6,calljava_nocopy
330 ldq t3,offjniitem+sizejniblock*6(t0)
333 lda t0,sizejniblock(t0)
335 bne t1,calljava_copyloop
338 lda v0,32(t4) /* pass pointer to method pointer via v0*/
340 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
341 stq $28,16(t4) /* store function address */
342 lda $28,8(t4) /* set method pointer */
344 ldq pv,8($28) /* method call as in Java */
345 jmp ra,(pv) /* call JIT compiler */
347 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
351 ldq ra,0(sp) /* restore return address */
352 ldq gp,8(sp) /* restore global pointer */
354 lda sp,40(sp) /* free stack space */
361 ldq gp,8(sp) /* restore global pointer */
363 jsr ra,builtin_throw_exception
364 ldq ra,0(sp) /* restore return address */
366 lda sp,40(sp) /* free stack space */
368 .end asm_calljavafunction2
371 /****************** function asm_call_jit_compiler *****************************
373 * invokes the compiler for untranslated JavaVM methods. *
375 * Register R0 contains a pointer to the method info structure (prepared *
376 * by createcompilerstub). Using the return address in R26 and the *
377 * offset in the LDA instruction or using the value in methodptr R28 the *
378 * patching address for storing the method address can be computed: *
380 * method address was either loaded using *
381 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
382 * M_LDA (REG_PV, REG_RA, low) *
383 * M_LDAH(REG_PV, REG_RA, high) ; optional *
385 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
386 * in the static case the method pointer can be computed using the *
387 * return address and the lda function following the jmp instruction *
389 *******************************************************************************/
392 .ent asm_call_jit_compiler
393 asm_call_jit_compiler:
396 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
397 srl t8,16,t8 /* shift right register number $yy */
398 and t8,31,t8 /* isolate register number */
399 subl t8,28,t8 /* test for REG_METHODPTR */
401 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
403 sra t8,48,t8 /* isolate offset */
404 addq t8,ra,$28 /* compute update address */
405 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
406 srl t8,16,t8 /* isolate instruction code */
407 lda t8,-0x177b(t8) /* test for LDAH */
409 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
410 sll t8,16,t8 /* compute high offset */
411 addl t8,0,t8 /* sign extend high offset */
412 addq t8,$28,$28 /* compute update address */
414 lda sp,-14*8(sp) /* reserve stack space */
415 stq a0,0*8(sp) /* save all argument registers */
416 stq a1,1*8(sp) /* they could be used by method */
427 stq $28,12*8(sp) /* save method pointer */
428 stq ra,13*8(sp) /* save return address */
430 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
431 jsr ra,jit_compile /* jit compiler */
434 call_pal PAL_imb /* synchronise instruction cache */
436 ldq a0,0*8(sp) /* load argument registers */
448 ldq $28,12*8(sp) /* load method pointer */
449 ldq ra,13*8(sp) /* load return address */
450 lda sp,14*8(sp) /* deallocate stack area */
452 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
454 sra t8,48,t8 /* isolate offset */
456 addq t8,$28,t8 /* compute update address via method pointer*/
457 stq v0,0(t8) /* save new method address there */
459 mov v0,pv /* load method address into pv */
461 jmp zero,(pv) /* and call method. The method returns */
462 /* directly to the caller (ra). */
464 .end asm_call_jit_compiler
467 /****************** function asm_dumpregistersandcall **************************
469 * This funtion saves all callee saved registers and calls the function *
470 * which is passed as parameter. *
472 * This function is needed by the garbage collector, which needs to access *
473 * all registers which are stored on the stack. Unused registers are *
474 * cleared to avoid interferances with the GC. *
476 * void asm_dumpregistersandcall (functionptr f); *
478 *******************************************************************************/
480 .ent asm_dumpregistersandcall
481 asm_dumpregistersandcall:
482 lda sp,-16*8(sp) /* allocate stack */
483 stq ra,0(sp) /* save return address */
485 stq s0,1*8(sp) /* save all callee saved registers */
486 stq s1,2*8(sp) /* intialize the remaining registers */
501 clr v0 /* intialize the remaining registers */
546 mov a0,pv /* load function pointer */
547 jmp ra,(pv) /* and call function */
549 ldq ra,0(sp) /* load return address */
550 lda sp,16*8(sp) /* deallocate stack */
551 jmp zero,(ra) /* return */
553 .end asm_dumpregistersandcall
556 /********************* function asm_handle_exception ***************************
558 * This function handles an exception. It does not use the usual calling *
559 * conventions. The exception pointer is passed in REG_ITMP1 and the *
560 * pc from the exception raising position is passed in REG_ITMP2. It searches *
561 * the local exception table for a handler. If no one is found, it unwinds *
562 * stacks and continues searching the callers. *
564 * void asm_handle_exception (exceptionptr, exceptionpc); *
566 *******************************************************************************/
568 .ent asm_handle_nat_exception
569 asm_handle_nat_exception:
571 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
573 sra t0,48,t0 /* isolate offset */
574 addq t0,ra,pv /* compute update address */
575 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
576 srl t0,16,t0 /* isolate instruction code */
577 lda t0,-0x177b(t0) /* test for LDAH */
578 bne t0,asm_handle_exception
579 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
580 sll t0,16,t0 /* compute high offset */
581 addl t0,0,t0 /* sign extend high offset */
582 addq t0,pv,pv /* compute update address */
584 .aent asm_handle_exception
585 asm_handle_exception:
587 lda sp,-18*8(sp) /* allocate stack */
588 stq t0,0*8(sp) /* save possible used registers */
589 stq t1,1*8(sp) /* also registers used by trace_exception */
607 lda t3,1(zero) /* set no unwind flag */
609 lda sp,-5*8(sp) /* allocate stack */
610 stq xptr,0*8(sp) /* save used register */
617 ldq a1,MethodPointer(pv)
622 br ra,ex_trace /* set ra for gp loading */
624 ldgp gp,0(ra) /* load gp */
625 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
627 ldq xptr,0*8(sp) /* restore used register */
632 lda sp,5*8(sp) /* deallocate stack */
634 ldl t0,ExTableSize(pv) /* t0 = exception table size */
635 beq t0,empty_table /* if empty table skip */
636 lda t1,ExTableStart(pv) /* t1 = start of exception table */
639 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
640 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
641 beq t2,ex_table_cont /* if (false) continue */
642 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
643 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
644 beq t2,ex_table_cont /* if (false) continue */
645 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
646 beq a1,ex_handle_it /* NULL catches everything */
648 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
649 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
650 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
651 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
652 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
653 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
654 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
655 beq v0,ex_table_cont /* if (false) continue */
659 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
661 beq t3,ex_jump /* if (!(no stack unwinding) skip */
663 ldq t0,0*8(sp) /* restore possible used registers */
664 ldq t1,1*8(sp) /* also registers used by trace_exception */
681 lda sp,18*8(sp) /* deallocate stack */
684 jmp zero,(xpc) /* jump to the handler */
687 lda t1,ExEntrySize(t1) /* next exception table entry */
688 subl t0,1,t0 /* decrement entry counter */
689 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
692 beq t3,ex_already_cleared /* if here the first time, then */
693 lda sp,18*8(sp) /* deallocate stack and */
694 clr t3 /* clear the no unwind flag */
696 ldl t0,IsSync(pv) /* t0 = SyncOffset */
697 beq t0,no_monitor_exit /* if zero no monitorexit */
698 addq sp,t0,t0 /* add stackptr to Offset */
699 ldq a0,-8(t0) /* load monitorexit pointer */
701 lda sp,-7*8(sp) /* allocate stack */
702 stq t0,0*8(sp) /* save used register */
710 br ra,ex_mon_load /* set ra for gp loading */
712 ldgp gp,0(ra) /* load gp */
713 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
715 ldq t0,0*8(sp) /* restore used register */
722 lda sp,7*8(sp) /* deallocate stack */
725 ldl t0,FrameSize(pv) /* t0 = frame size */
726 addq sp,t0,sp /* unwind stack */
727 mov sp,t0 /* t0 = pointer to save area */
728 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
729 bne t1,ex_no_restore /* if (leaf) skip */
730 ldq ra,-8(t0) /* restore ra */
731 lda t0,-8(t0) /* t0-- */
733 mov ra,xpc /* the new xpc is ra */
734 ldl t1,IntSave(pv) /* t1 = saved int register count */
735 br t2,ex_int1 /* t2 = current pc */
737 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
738 negl t1,t1 /* negate register count */
739 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
740 jmp zero,(t2) /* jump to save position */
749 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
751 ldl t1,FltSave(pv) /* t1 = saved flt register count */
752 br t2,ex_flt1 /* t2 = current pc */
754 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
755 negl t1,t1 /* negate register count */
756 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
757 jmp zero,(t2) /* jump to save position */
767 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
769 sra t0,48,t0 /* isolate offset */
770 addq t0,ra,pv /* compute update address */
771 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
772 srl t0,16,t0 /* isolate instruction code */
773 lda t0,-0x177b(t0) /* test for LDAH */
775 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
776 sll t0,16,t0 /* compute high offset */
777 addl t0,0,t0 /* sign extend high offset */
778 addq t0,pv,pv /* compute update address */
781 .end asm_handle_nat_exception
784 /********************* asm_check_clinit ****************************************
786 * Does null check and calls monitorenter or throws an exception *
788 *******************************************************************************/
790 .ent asm_check_clinit
794 ldl itmp2,offclassinit(itmp1)
795 bne itmp2,L_is_initialized
799 stq a0,1*8(sp) /* save argument registers for leaf funcs */
811 ldq a0,1*8(sp) /* restore argument registers */
820 mov ra,itmp1 /* now patch the calling code */
821 subq itmp1,(3*4),itmp1 /* go back 3 instructions */
822 ldah itmp2,-15392(zero) /* br -- 0xc3e0 == -15392 */
823 lda itmp2,4(itmp2) /* jump over 4 instructions */
824 stl itmp2,0(itmp1) /* store the new branch: br +4 */
828 .end asm_check_clinit
831 /********************* function asm_builtin_monitorenter ***********************
833 * Does null check and calls monitorenter or throws an exception *
835 *******************************************************************************/
837 .ent asm_builtin_monitorenter
838 asm_builtin_monitorenter:
840 lda pv,builtin_monitorenter
841 beq a0,nb_monitorenter /* if (null) throw exception */
842 jmp zero,(pv) /* else call builtin_monitorenter */
847 ldq a0,string_java_lang_NullPointerException
848 jsr ra,new_exception_message
854 lda xpc,-4(ra) /* faulting address is return adress - 4*/
855 br asm_handle_nat_exception
856 .end asm_builtin_monitorenter
859 /********************* function asm_builtin_monitorexit ************************
861 * Does null check and calls monitorexit or throws an exception *
863 *******************************************************************************/
865 .ent asm_builtin_monitorexit
866 asm_builtin_monitorexit:
868 lda pv,builtin_monitorexit
869 beq a0,nb_monitorexit /* if (null) throw exception */
870 jmp zero,(pv) /* else call builtin_monitorexit */
875 ldq a0,string_java_lang_NullPointerException
876 jsr ra,new_exception_message
882 lda xpc,-4(ra) /* faulting address is return adress - 4*/
883 br asm_handle_nat_exception
884 .end asm_builtin_monitorexit
887 /************************ function asm_builtin_idiv ****************************
889 * Does null check and calls idiv or throws an exception *
891 *******************************************************************************/
893 .ent asm_builtin_idiv
898 beq a1,nb_idiv /* if (null) throw exception */
899 jmp zero,(pv) /* else call builtin_idiv */
904 ldq a0,string_java_lang_ArithmeticException
905 ldq a1,string_java_lang_ArithmeticException_message
906 jsr ra,new_exception_message
912 lda xpc,-4(ra) /* faulting address is return adress - 4*/
913 br asm_handle_nat_exception
915 .end asm_builtin_idiv
918 /************************ function asm_builtin_ldiv ****************************
920 * Does null check and calls ldiv or throws an exception *
922 *******************************************************************************/
924 .ent asm_builtin_ldiv
929 beq a1,nb_ldiv /* if (null) throw exception */
930 jmp zero,(pv) /* else call builtin_ldiv */
935 ldq a0,string_java_lang_ArithmeticException
936 ldq a1,string_java_lang_ArithmeticException_message
937 jsr ra,new_exception_message
943 lda xpc,-4(ra) /* faulting address is return adress - 4*/
944 br asm_handle_nat_exception
946 .end asm_builtin_ldiv
949 /************************ function asm_builtin_irem ****************************
951 * Does null check and calls irem or throws an exception *
953 *******************************************************************************/
955 .ent asm_builtin_irem
960 beq a1,nb_irem /* if (null) throw exception */
961 jmp zero,(pv) /* else call builtin_irem */
966 ldq a0,string_java_lang_ArithmeticException
967 ldq a1,string_java_lang_ArithmeticException_message
968 jsr ra,new_exception_message
974 lda xpc,-4(ra) /* faulting address is return adress - 4*/
975 br asm_handle_nat_exception
977 .end asm_builtin_irem
980 /************************ function asm_builtin_lrem ****************************
982 * Does null check and calls lrem or throws an exception *
984 *******************************************************************************/
986 .ent asm_builtin_lrem
991 beq a1,nb_lrem /* if (null) throw exception */
992 jmp zero,(pv) /* else call builtin_lrem */
997 ldq a0,string_java_lang_ArithmeticException
998 ldq a1,string_java_lang_ArithmeticException_message
999 jsr ra,new_exception_message
1005 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1006 br asm_handle_nat_exception
1008 .end asm_builtin_lrem
1011 /*********************** function new_builtin_checkcast ************************
1013 * Does the cast check and eventually throws an exception *
1015 *******************************************************************************/
1017 .ent asm_builtin_checkcast
1019 asm_builtin_checkcast:
1021 lda sp,-16(sp) # allocate stack space
1022 stq ra,0(sp) # save return address
1023 stq a0,8(sp) # save object pointer
1024 jsr ra,builtin_checkcast # builtin_checkcast
1026 beq v0,nb_ccast_throw # if (false) throw exception
1027 ldq ra,0(sp) # restore return address
1028 ldq v0,8(sp) # return object pointer
1029 lda sp,16(sp) # free stack space
1033 ldq a0,string_java_lang_ClassCastException
1034 jsr ra,new_exception
1038 ldq ra,0(sp) # restore return address
1039 lda sp,16(sp) # free stack space
1040 lda xpc,-4(ra) # faulting address is return adress - 4
1041 br asm_handle_nat_exception
1043 .end asm_builtin_checkcast
1046 /******************* function asm_builtin_checkarraycast ***********************
1048 * Does the cast check and eventually throws an exception *
1050 *******************************************************************************/
1052 .ent asm_builtin_checkarraycast
1054 asm_builtin_checkarraycast:
1056 lda sp,-16(sp) /* allocate stack space */
1057 stq ra,0(sp) /* save return address */
1058 stq a0,8(sp) /* save object pointer */
1059 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1061 beq v0,nb_carray_throw /* if (false) throw exception */
1062 ldq ra,0(sp) /* restore return address */
1063 ldq v0,8(sp) /* return object pointer */
1064 lda sp,16(sp) /* free stack space */
1068 ldq a0,string_java_lang_ClassCastException
1069 jsr ra,new_exception
1073 ldq ra,0(sp) /* restore return address */
1074 lda sp,16(sp) /* free stack space */
1075 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1076 br asm_handle_nat_exception
1078 .end asm_builtin_checkarraycast
1081 /******************* function asm_builtin_aastore ******************************
1083 * Does the cast check and eventually throws an exception *
1085 *******************************************************************************/
1087 .ent asm_builtin_aastore
1089 asm_builtin_aastore:
1091 beq a0,nb_aastore_null /* if null pointer throw exception */
1092 ldl t0,offarraysize(a0) /* load size */
1093 lda sp,-24(sp) /* allocate stack space */
1094 stq ra,0(sp) /* save return address */
1095 s8addq a1,a0,t1 /* add index*8 to arrayref */
1096 cmpult a1,t0,t0 /* do bound check */
1097 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1098 mov a2,a1 /* object is second argument */
1099 stq t1,8(sp) /* save store position */
1100 stq a1,16(sp) /* save object */
1101 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1103 ldq ra,0(sp) /* restore return address */
1104 ldq a0,8(sp) /* restore store position */
1105 ldq a1,16(sp) /* restore object */
1106 lda sp,24(sp) /* free stack space */
1107 beq v0,nb_aastore_throw /* if (false) throw exception */
1108 stq a1,offobjarrdata(a0) /* store objectptr in array */
1112 subq sp,8,sp /* allocate stack space */
1113 stq ra,0(sp) /* save return address */
1114 ldq a0,string_java_lang_NullPointerException
1115 jsr ra,new_exception
1121 mov ra,xpc /* faulting address is return adress */
1122 br asm_handle_nat_exception
1125 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1126 jsr ra,new_exception_int /* a1 already contains the index */
1130 ldq ra,0(sp) /* restore return address */
1131 lda sp,24(sp) /* free stack space */
1132 mov ra,xpc /* faulting address is return adress */
1133 br asm_handle_nat_exception
1136 subq sp,8,sp /* allocate stack space */
1137 stq ra,0(sp) /* save return address */
1138 ldq a0,string_java_lang_ArrayStoreException
1139 jsr ra,new_exception
1145 mov ra,xpc /* faulting address is return adress */
1146 br asm_handle_nat_exception
1148 .end asm_builtin_aastore
1151 /******************* function asm_initialize_thread_stack **********************
1153 * initialized a thread stack *
1155 *******************************************************************************/
1157 .ent asm_initialize_thread_stack
1159 asm_initialize_thread_stack:
1180 .end asm_initialize_thread_stack
1183 /******************* function asm_perform_threadswitch *************************
1185 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1187 * performs a threadswitch *
1189 *******************************************************************************/
1191 .ent asm_perform_threadswitch
1193 asm_perform_threadswitch:
1234 .end asm_perform_threadswitch
1237 /********************* function asm_switchstackandcall *************************
1239 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1242 * Switches to a new stack, calls a function and switches back. *
1243 * a0 new stack pointer *
1244 * a1 function pointer *
1245 * a2 pointer to variable where stack top should be stored *
1246 * a3 pointer to user data, is passed to the function *
1248 *******************************************************************************/
1251 .ent asm_switchstackandcall
1253 asm_switchstackandcall:
1254 lda a0,-2*8(a0) /* allocate new stack */
1255 stq ra,0(a0) /* save return address on new stack */
1256 stq sp,1*8(a0) /* save old stack pointer on new stack */
1257 stq sp,0(a2) /* save old stack pointer to variable */
1258 mov a0,sp /* switch to new stack */
1260 mov a1,pv /* load function pointer */
1261 mov a3,a0 /* pass pointer */
1262 jmp ra,(pv) /* and call function */
1264 ldq ra,0(sp) /* load return address */
1265 ldq sp,1*8(sp) /* switch to old stack */
1267 jmp zero,(ra) /* return */
1269 .end asm_switchstackandcall
1272 /********************* function asm_getcallingmethod ***************************
1274 * classinfo *asm_getcallingmethodclass (); *
1276 * goes back stack frames to get the calling method *
1282 *******************************************************************************/
1285 .ent asm_getcallingmethod
1287 asm_getcallingmethod:
1288 ldq t3,16(sp) /* load return address of native function */
1289 addq sp,24,t2 /* skip frames of C-Function and nativestub */
1291 /* determine pv (t3) of java-function from ra */
1293 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1295 sra t0,48,t0 /* isolate offset */
1296 addq t0,t3,t4 /* compute update address */
1297 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1298 srl t0,16,t0 /* isolate instruction code */
1299 lda t0,-0x177b(t0) /* test for LDAH */
1301 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1302 sll t0,16,t0 /* compute high offset */
1303 addl t0,0,t0 /* sign extend high offset */
1304 addq t0,t4,t4 /* compute update address */
1307 ldl t0,FrameSize(t4) /* t0 = frame size */
1308 addq t2,t0,t2 /* skip frame of java function */
1309 ldq t3,-8(t2) /* load new ra */
1311 /* determine pv (t3) of java-function from ra */
1313 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1315 sra t0,48,t0 /* isolate offset */
1316 addq t0,t3,t4 /* compute update address */
1317 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1318 srl t0,16,t0 /* isolate instruction code */
1319 lda t0,-0x177b(t0) /* test for LDAH */
1321 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1322 sll t0,16,t0 /* compute high offset */
1323 addl t0,0,t0 /* sign extend high offset */
1324 addq t0,t4,t4 /* compute update address */
1327 ldq v0,MethodPointer(t4) /* */
1329 jmp zero,(ra) /* return */
1331 .end asm_getcallingmethod
1335 * These are local overrides for various environment variables in Emacs.
1336 * Please do not remove this and leave it at the end of the file, where
1337 * Emacs will automagically detect them.
1338 * ---------------------------------------------------------------------
1341 * indent-tabs-mode: t