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 948 2004-03-07 22:12:28Z 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:
830 lda pv,builtin_monitorenter
831 beq a0,nb_monitorenter /* if (null) throw exception */
832 jmp zero,(pv) /* else call builtin_monitorenter */
837 ldq a0,string_java_lang_NullPointerException
838 jsr ra,new_exception_message
844 lda xpc,-4(ra) /* faulting address is return adress - 4*/
845 br asm_handle_nat_exception
846 .end asm_builtin_monitorenter
849 /********************* function asm_builtin_monitorexit ************************
851 * Does null check and calls monitorexit or throws an exception *
853 *******************************************************************************/
855 .ent asm_builtin_monitorexit
856 asm_builtin_monitorexit:
858 lda pv,builtin_monitorexit
859 beq a0,nb_monitorexit /* if (null) throw exception */
860 jmp zero,(pv) /* else call builtin_monitorexit */
865 ldq a0,string_java_lang_NullPointerException
866 jsr ra,new_exception_message
872 lda xpc,-4(ra) /* faulting address is return adress - 4*/
873 br asm_handle_nat_exception
874 .end asm_builtin_monitorexit
877 /************************ function asm_builtin_idiv ****************************
879 * Does null check and calls idiv or throws an exception *
881 *******************************************************************************/
883 .ent asm_builtin_idiv
888 beq a1,nb_idiv /* if (null) throw exception */
889 jmp zero,(pv) /* else call builtin_idiv */
894 ldq a0,string_java_lang_ArithmeticException
895 ldq a1,string_java_lang_ArithmeticException_message
896 jsr ra,new_exception_message
902 lda xpc,-4(ra) /* faulting address is return adress - 4*/
903 br asm_handle_nat_exception
905 .end asm_builtin_idiv
908 /************************ function asm_builtin_ldiv ****************************
910 * Does null check and calls ldiv or throws an exception *
912 *******************************************************************************/
914 .ent asm_builtin_ldiv
919 beq a1,nb_ldiv /* if (null) throw exception */
920 jmp zero,(pv) /* else call builtin_ldiv */
925 ldq a0,string_java_lang_ArithmeticException
926 ldq a1,string_java_lang_ArithmeticException_message
927 jsr ra,new_exception_message
933 lda xpc,-4(ra) /* faulting address is return adress - 4*/
934 br asm_handle_nat_exception
936 .end asm_builtin_ldiv
939 /************************ function asm_builtin_irem ****************************
941 * Does null check and calls irem or throws an exception *
943 *******************************************************************************/
945 .ent asm_builtin_irem
950 beq a1,nb_irem /* if (null) throw exception */
951 jmp zero,(pv) /* else call builtin_irem */
956 ldq a0,string_java_lang_ArithmeticException
957 ldq a1,string_java_lang_ArithmeticException_message
958 jsr ra,new_exception_message
964 lda xpc,-4(ra) /* faulting address is return adress - 4*/
965 br asm_handle_nat_exception
967 .end asm_builtin_irem
970 /************************ function asm_builtin_lrem ****************************
972 * Does null check and calls lrem or throws an exception *
974 *******************************************************************************/
976 .ent asm_builtin_lrem
981 beq a1,nb_lrem /* if (null) throw exception */
982 jmp zero,(pv) /* else call builtin_lrem */
987 ldq a0,string_java_lang_ArithmeticException
988 ldq a1,string_java_lang_ArithmeticException_message
989 jsr ra,new_exception_message
995 lda xpc,-4(ra) /* faulting address is return adress - 4*/
996 br asm_handle_nat_exception
998 .end asm_builtin_lrem
1001 /*********************** function new_builtin_checkcast ************************
1003 * Does the cast check and eventually throws an exception *
1005 *******************************************************************************/
1007 .ent asm_builtin_checkcast
1009 asm_builtin_checkcast:
1011 lda sp,-16(sp) # allocate stack space
1012 stq ra,0(sp) # save return address
1013 stq a0,8(sp) # save object pointer
1014 jsr ra,builtin_checkcast # builtin_checkcast
1016 beq v0,nb_ccast_throw # if (false) throw exception
1017 ldq ra,0(sp) # restore return address
1018 ldq v0,8(sp) # return object pointer
1019 lda sp,16(sp) # free stack space
1023 ldq a0,string_java_lang_ClassCastException
1024 jsr ra,new_exception
1028 ldq ra,0(sp) # restore return address
1029 lda sp,16(sp) # free stack space
1030 lda xpc,-4(ra) # faulting address is return adress - 4
1031 br asm_handle_nat_exception
1033 .end asm_builtin_checkcast
1036 /******************* function asm_builtin_checkarraycast ***********************
1038 * Does the cast check and eventually throws an exception *
1040 *******************************************************************************/
1042 .ent asm_builtin_checkarraycast
1044 asm_builtin_checkarraycast:
1046 lda sp,-16(sp) /* allocate stack space */
1047 stq ra,0(sp) /* save return address */
1048 stq a0,8(sp) /* save object pointer */
1049 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1051 beq v0,nb_carray_throw /* if (false) throw exception */
1052 ldq ra,0(sp) /* restore return address */
1053 ldq v0,8(sp) /* return object pointer */
1054 lda sp,16(sp) /* free stack space */
1058 ldq a0,string_java_lang_ClassCastException
1059 jsr ra,new_exception
1063 ldq ra,0(sp) /* restore return address */
1064 lda sp,16(sp) /* free stack space */
1065 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1066 br asm_handle_nat_exception
1068 .end asm_builtin_checkarraycast
1071 /******************* function asm_builtin_aastore ******************************
1073 * Does the cast check and eventually throws an exception *
1075 *******************************************************************************/
1077 .ent asm_builtin_aastore
1079 asm_builtin_aastore:
1081 beq a0,nb_aastore_null /* if null pointer throw exception */
1082 ldl t0,offarraysize(a0) /* load size */
1083 lda sp,-24(sp) /* allocate stack space */
1084 stq ra,0(sp) /* save return address */
1085 s8addq a1,a0,t1 /* add index*8 to arrayref */
1086 cmpult a1,t0,t0 /* do bound check */
1087 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1088 mov a2,a1 /* object is second argument */
1089 stq t1,8(sp) /* save store position */
1090 stq a1,16(sp) /* save object */
1091 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1093 ldq ra,0(sp) /* restore return address */
1094 ldq a0,8(sp) /* restore store position */
1095 ldq a1,16(sp) /* restore object */
1096 lda sp,24(sp) /* free stack space */
1097 beq v0,nb_aastore_throw /* if (false) throw exception */
1098 stq a1,offobjarrdata(a0) /* store objectptr in array */
1102 subq sp,8,sp /* allocate stack space */
1103 stq ra,0(sp) /* save return address */
1104 ldq a0,string_java_lang_NullPointerException
1105 jsr ra,new_exception
1111 mov ra,xpc /* faulting address is return adress */
1112 br asm_handle_nat_exception
1115 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1116 jsr ra,new_exception_int /* a1 already contains the index */
1120 ldq ra,0(sp) /* restore return address */
1121 lda sp,24(sp) /* free stack space */
1122 mov ra,xpc /* faulting address is return adress */
1123 br asm_handle_nat_exception
1126 subq sp,8,sp /* allocate stack space */
1127 stq ra,0(sp) /* save return address */
1128 ldq a0,string_java_lang_ArrayStoreException
1129 jsr ra,new_exception
1135 mov ra,xpc /* faulting address is return adress */
1136 br asm_handle_nat_exception
1138 .end asm_builtin_aastore
1141 /******************* function asm_initialize_thread_stack **********************
1143 * initialized a thread stack *
1145 *******************************************************************************/
1147 .ent asm_initialize_thread_stack
1149 asm_initialize_thread_stack:
1170 .end asm_initialize_thread_stack
1173 /******************* function asm_perform_threadswitch *************************
1175 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1177 * performs a threadswitch *
1179 *******************************************************************************/
1181 .ent asm_perform_threadswitch
1183 asm_perform_threadswitch:
1224 .end asm_perform_threadswitch
1227 /********************* function asm_switchstackandcall *************************
1229 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1232 * Switches to a new stack, calls a function and switches back. *
1233 * a0 new stack pointer *
1234 * a1 function pointer *
1235 * a2 pointer to variable where stack top should be stored *
1236 * a3 pointer to user data, is passed to the function *
1238 *******************************************************************************/
1241 .ent asm_switchstackandcall
1243 asm_switchstackandcall:
1244 lda a0,-2*8(a0) /* allocate new stack */
1245 stq ra,0(a0) /* save return address on new stack */
1246 stq sp,1*8(a0) /* save old stack pointer on new stack */
1247 stq sp,0(a2) /* save old stack pointer to variable */
1248 mov a0,sp /* switch to new stack */
1250 mov a1,pv /* load function pointer */
1251 mov a3,a0 /* pass pointer */
1252 jmp ra,(pv) /* and call function */
1254 ldq ra,0(sp) /* load return address */
1255 ldq sp,1*8(sp) /* switch to old stack */
1257 jmp zero,(ra) /* return */
1259 .end asm_switchstackandcall
1262 /********************* function asm_getcallingmethod ***************************
1264 * classinfo *asm_getcallingmethodclass (); *
1266 * goes back stack frames to get the calling method *
1272 *******************************************************************************/
1275 .ent asm_getcallingmethod
1277 asm_getcallingmethod:
1278 ldq t3,16(sp) /* load return address of native function */
1279 addq sp,24,t2 /* skip frames of C-Function and nativestub */
1281 /* determine pv (t3) of java-function from ra */
1283 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1285 sra t0,48,t0 /* isolate offset */
1286 addq t0,t3,t4 /* compute update address */
1287 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1288 srl t0,16,t0 /* isolate instruction code */
1289 lda t0,-0x177b(t0) /* test for LDAH */
1291 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1292 sll t0,16,t0 /* compute high offset */
1293 addl t0,0,t0 /* sign extend high offset */
1294 addq t0,t4,t4 /* compute update address */
1297 ldl t0,FrameSize(t4) /* t0 = frame size */
1298 addq t2,t0,t2 /* skip frame of java function */
1299 ldq t3,-8(t2) /* load new ra */
1301 /* determine pv (t3) of java-function from ra */
1303 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1305 sra t0,48,t0 /* isolate offset */
1306 addq t0,t3,t4 /* compute update address */
1307 ldl t0,4(t3) /* load instruction LDAH PV,xxx(PV) */
1308 srl t0,16,t0 /* isolate instruction code */
1309 lda t0,-0x177b(t0) /* test for LDAH */
1311 ldl t0,0(t3) /* load instruction LDA PV,xxx(RA) */
1312 sll t0,16,t0 /* compute high offset */
1313 addl t0,0,t0 /* sign extend high offset */
1314 addq t0,t4,t4 /* compute update address */
1317 ldq v0,MethodPointer(t4) /* */
1319 jmp zero,(ra) /* return */
1321 .end asm_getcallingmethod
1325 * These are local overrides for various environment variables in Emacs.
1326 * Please do not remove this and leave it at the end of the file, where
1327 * Emacs will automagically detect them.
1328 * ---------------------------------------------------------------------
1331 * indent-tabs-mode: t