1 /* vm/jit/alpha/asmpart.S - Java-C interface functions for alpha
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Joseph Wenninger
32 $Id: asmpart.S 2164 2005-03-30 20:18:51Z twisti $
38 #include "vm/jit/alpha/offsets.h"
39 #include "vm/jit/alpha/asmoffsets.h"
107 /********************* exported functions and variables ***********************/
109 .globl has_no_x_instr_set
111 .globl asm_calljavafunction
112 .globl asm_calljavafunction_int
114 .globl asm_calljavafunction2
115 .globl asm_calljavafunction2int
116 .globl asm_calljavafunction2long
117 .globl asm_calljavafunction2float
118 .globl asm_calljavafunction2double
120 .globl asm_call_jit_compiler
121 .globl asm_throw_and_handle_exception
122 .globl asm_throw_and_handle_nat_exception
123 .globl asm_throw_and_handle_arithmetic_exception
124 .globl asm_throw_and_handle_arrayindexoutofbounds_exception
125 .globl asm_handle_exception
126 .globl asm_handle_nat_exception
127 .globl asm_check_clinit
128 .globl asm_builtin_checkarraycast
129 .globl asm_builtin_aastore
131 #if defined(USE_THREADS)
132 .globl asm_builtin_monitorenter
133 .globl asm_builtin_monitorexit
136 .globl asm_builtin_idiv
137 .globl asm_builtin_irem
138 .globl asm_builtin_ldiv
139 .globl asm_builtin_lrem
140 .globl asm_perform_threadswitch
141 .globl asm_initialize_thread_stack
142 .globl asm_switchstackandcall
143 .globl asm_criticalsections
144 .globl asm_getclassvalues_atomic
145 .globl asm_prepare_native_stackinfo
146 .globl asm_remove_native_stackinfo
147 .globl asm_refillin_and_handle_exception
150 /*********************** function has_no_x_instr_set ***************************
152 * determines if the byte support instruction set (21164a and higher) *
155 *******************************************************************************/
157 .ent has_no_x_instr_set
160 .long 0x47e03c20 /* amask 1,v0 */
161 jmp zero,(ra) /* return */
163 .end has_no_x_instr_set
166 /********************* function asm_calljavafunction ***************************
168 * This function calls a Java-method (which possibly needs compilation) *
169 * with up to 4 address parameters. *
171 * This functions calls the JIT-compiler which eventually translates the *
172 * method into machine code. *
175 * javaobject_header *asm_calljavafunction (methodinfo *m, *
176 * void *arg1, void *arg2, void *arg3, void *arg4); *
178 *******************************************************************************/
180 .ent asm_calljavafunction
183 .ascii "calljavafunction\0\0"
186 .quad 0 /* catch type all */
187 .quad calljava_xhandler /* handler pc */
188 .quad calljava_xhandler /* end pc */
189 .quad asm_calljavafunction /* start pc */
190 .long 1 /* extable size */
191 .long 0 /* PADDING */
192 .quad 0 /* line number table start */
193 .quad 0 /* line number table size */
194 .long 0 /* PADDING */
195 .long 0 /* fltsave */
196 .long 0 /* intsave */
199 .long 32 /* frame size */
200 .quad 0 /* method pointer (pointer to name) */
202 asm_calljavafunction:
203 asm_calljavafunction_int:
205 lda sp,-32(sp) /* allocate stack space */
206 stq gp,24(sp) /* save global pointer */
207 stq ra,0(sp) /* save return address */
209 stq a0,16(sp) /* save method pointer for compiler */
210 lda v0,16(sp) /* pass pointer to method pointer via v0*/
212 mov a1,a0 /* pass the remaining parameters */
217 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
218 stq $28,8(sp) /* store function address */
219 mov sp,$28 /* set method pointer */
221 ldq pv,8($28) /* method call as in Java */
222 jmp ra,(pv) /* call JIT compiler */
224 lda pv,-64(ra) /* asm_calljavafunction-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 */
235 ldq gp,24(sp) /* restore global pointer */
237 jsr ra,builtin_throw_exception
238 ldq ra,0(sp) /* restore return address */
239 lda sp,32(sp) /* free stack space */
241 .end asm_calljavafunction
246 .ent asm_calljavafunction2
251 .quad 0 /* catch type all */
252 .quad calljava_xhandler2 /* handler pc */
253 .quad calljava_xhandler2 /* end pc */
254 .quad asm_calljavafunction2 /* start pc */
255 .long 1 /* extable size */
256 .long 0 /* PADDING */
257 .quad 0 /* line number table start */
258 .quad 0 /* line number table size */
259 .long 0 /* PADDING */
260 .long 0 /* fltsave */
261 .long 1 /* intsave */
264 .long 40 /* frame size */
265 .quad 0 /* method pointer (pointer to name) */
267 asm_calljavafunction2:
268 asm_calljavafunction2int:
269 asm_calljavafunction2long:
270 asm_calljavafunction2float:
271 asm_calljavafunction2double:
273 lda sp,-40(sp) /* allocate stack space */
274 stq ra,0(sp) /* save return address */
276 stq gp,8(sp) /* save global pointer */
278 stq a0,32(sp) /* save method pointer for compiler */
279 mov a3,t0 /* pointer to arg block */
280 mov a1,s6 /* arg count */
282 ble s6,calljava_argsloaded
284 ldq a0,offjniitem(t0)
285 ldt $f16,offjniitem(t0)
286 ble s6,calljava_argsloaded
288 ldq a1,offjniitem+sizejniblock*1(t0)
289 ldt $f17,offjniitem+sizejniblock*1(t0)
290 ble s6,calljava_argsloaded
292 ldq a2,offjniitem+sizejniblock*2(t0)
293 ldt $f18,offjniitem+sizejniblock*2(t0)
294 ble s6,calljava_argsloaded
296 ldq a3,offjniitem+sizejniblock*3(t0)
297 ldt $f19,offjniitem+sizejniblock*3(t0)
298 ble s6,calljava_argsloaded
300 ldq a4,offjniitem+sizejniblock*4(t0)
301 ldt $f20,offjniitem+sizejniblock*4(t0)
302 ble s6,calljava_argsloaded
304 ldq a5,offjniitem+sizejniblock*5(t0)
305 ldt $f21,offjniitem+sizejniblock*5(t0)
308 ble s6,calljava_nocopy
314 ldq t3,offjniitem+sizejniblock*6(t0)
317 lda t0,sizejniblock(t0)
319 bne t1,calljava_copyloop
322 lda v0,32(t4) /* pass pointer to method pointer via v0*/
324 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
325 stq $28,16(t4) /* store function address */
326 lda $28,8(t4) /* set method pointer */
328 ldq pv,8($28) /* method call as in Java */
329 jmp ra,(pv) /* call JIT compiler */
331 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
335 ldq ra,0(sp) /* restore return address */
336 ldq gp,8(sp) /* restore global pointer */
338 lda sp,40(sp) /* free stack space */
345 ldq gp,8(sp) /* restore global pointer */
347 jsr ra,builtin_throw_exception
348 ldq ra,0(sp) /* restore return address */
350 lda sp,40(sp) /* free stack space */
352 .end asm_calljavafunction2
355 /****************** function asm_call_jit_compiler *****************************
357 * invokes the compiler for untranslated JavaVM methods. *
359 * Register R0 contains a pointer to the method info structure (prepared *
360 * by createcompilerstub). Using the return address in R26 and the *
361 * offset in the LDA instruction or using the value in methodptr R28 the *
362 * patching address for storing the method address can be computed: *
364 * method address was either loaded using *
365 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
366 * M_LDA (REG_PV, REG_RA, low) *
367 * M_LDAH(REG_PV, REG_RA, high) ; optional *
369 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
370 * in the static case the method pointer can be computed using the *
371 * return address and the lda function following the jmp instruction *
373 *******************************************************************************/
375 .ent asm_call_jit_compiler
377 asm_call_jit_compiler:
379 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
380 srl t8,16,t8 /* shift right register number $yy */
381 and t8,31,t8 /* isolate register number */
382 subl t8,28,t8 /* test for REG_METHODPTR */
384 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
386 sra t8,48,t8 /* isolate offset */
387 addq t8,ra,$28 /* compute update address */
388 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
389 srl t8,16,t8 /* isolate instruction code */
390 lda t8,-0x177b(t8) /* test for LDAH */
392 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
393 sll t8,16,t8 /* compute high offset */
394 addl t8,0,t8 /* sign extend high offset */
395 addq t8,$28,$28 /* compute update address */
397 lda sp,-14*8(sp) /* reserve stack space */
398 stq a0,0*8(sp) /* save all argument registers */
399 stq a1,1*8(sp) /* they could be used by method */
410 stq $28,12*8(sp) /* save method pointer */
411 stq ra,13*8(sp) /* save return address */
413 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
414 jsr ra,jit_compile /* jit compiler */
417 ldq a0,0*8(sp) /* load argument registers */
429 ldq $28,12*8(sp) /* load method pointer */
430 ldq ra,13*8(sp) /* load return address */
431 lda sp,14*8(sp) /* deallocate stack area */
433 beq v0,asm_call_jit_compiler_exception
435 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
437 sra t8,48,t8 /* isolate offset */
439 addq t8,$28,t8 /* compute update address via method pointer*/
440 stq v0,0(t8) /* save new method address there */
442 call_pal PAL_imb /* synchronise instruction cache */
444 mov v0,pv /* load method address into pv */
445 jmp zero,(pv) /* and call method. The method returns */
446 /* directly to the caller (ra). */
448 asm_call_jit_compiler_exception:
449 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
452 jsr ra,builtin_asm_get_exceptionptrptr
458 ldq xptr,0(v0) /* get the exception pointer */
459 stq zero,0(v0) /* clear the exception pointer */
462 br asm_handle_nat_exception
464 .end asm_call_jit_compiler
467 /**************** function asm_refillin_and_handle_exception *******************
469 * This function handles an exception. It does not use the usual calling *
470 * conventions. The exception is passed in REG_ITMP1 and the *
471 * pc from the exception raising position is passed in REG_ITMP2. *
472 * a0 contains the PV of the function causing the problem *
474 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
476 *******************************************************************************/
477 .ent asm_refillin_and_handle_exception
478 asm_refillin_and_handle_exception:
480 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
482 sra t0,48,t0 /* isolate offset */
483 addq t0,ra,pv /* compute update address */
484 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
485 srl t0,16,t0 /* isolate instruction code */
486 lda t0,-0x177b(t0) /* test for LDAH */
487 bne t0, asm_refillin_and_handle_exception_cont
488 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
489 sll t0,16,t0 /* compute high offset */
490 addl t0,0,t0 /* sign extend high offset */
491 addq t0,pv,pv /* compute update address */
493 asm_refillin_and_handle_exception_cont:
496 lda sp,-6*8(sp) /* prepare stackframe*/
497 stq pv,5*8(sp) /* store pv of caller */
498 stq xptr,4*8(sp) /*exception ptr*/
499 stq xpc,3*8(sp) /*address of failure*/
500 stq t0,2*8(sp) /*begin of java stack frame*/
501 stq pv,1*8(sp) /* store pv of caller */
502 stq zero,0*8(sp) /*builtin (invisible) function */
503 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
506 ldq a2,utf_void__java_lang_Throwable
507 ldq a1,utf_fillInStackTrace
509 ldq t1,offobjvftbl(t0)
511 jsr ra,class_resolvemethod
513 /* now we have the method */
518 jsr ra,asm_calljavafunction
522 jsr ra,asm_remove_native_stackinfo
531 br asm_handle_exception
533 .end asm_refillin_and_handle_exception
535 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
537 * This function handles an exception. It does not use the usual calling *
538 * conventions. The integer parameter is passed in REG_ITMP1 and the *
539 * pc from the exception raising position is passed in REG_ITMP2. *
541 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
543 *******************************************************************************/
545 .ent asm_throw_and_handle_arrayindexoutofbounds_exception
547 asm_throw_and_handle_arrayindexoutofbounds_exception:
550 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
552 sra t0,48,t0 /* isolate offset */
553 addq t0,ra,pv /* compute update address */
554 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
555 srl t0,16,t0 /* isolate instruction code */
556 lda t0,-0x177b(t0) /* test for LDAH */
557 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
558 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
559 sll t0,16,t0 /* compute high offset */
560 addl t0,0,t0 /* sign extend high offset */
561 addq t0,pv,pv /* compute update address */
563 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
565 lda sp,-6*8(sp) /*prepare stackframe*/
566 stq pv,5*8(sp) /*pv of failure*/
567 stq itmp1,4*8(sp) /*int parameter of the exception*/
568 stq xpc,3*8(sp) /*address of failure */
569 stq t0,2*8(sp) /*store begin of java stack frame*/
570 stq pv,1*8(sp) /*store pv of caller in structure*/
571 stq zero,0*8(sp) /*builtin (invisible function)*/
573 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
576 ldq a0,6*8(sp) /*int of exception*/
577 jsr ra,new_arrayindexoutofboundsexception
580 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
582 jsr ra,asm_remove_native_stackinfo
588 br asm_handle_exception
590 .end asm_throw_and_handle_arrayindexoutofbounds_exception
593 /* asm_throw_and_handle_arithmetic_exception ***********************************
597 *******************************************************************************/
599 .ent asm_throw_and_handle_arithmetic_exception
601 asm_throw_and_handle_arithmetic_exception:
602 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
604 sra t0,48,t0 /* isolate offset */
605 addq t0,ra,pv /* compute update address */
606 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
607 srl t0,16,t0 /* isolate instruction code */
608 lda t0,-0x177b(t0) /* test for LDAH */
609 bne t0,asm_throw_and_handle_arithmetic_exception_cont
610 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
611 sll t0,16,t0 /* compute high offset */
612 addl t0,0,t0 /* sign extend high offset */
613 addq t0,pv,pv /* compute update address */
615 asm_throw_and_handle_arithmetic_exception_cont:
617 lda sp,-6*8(sp) /*prepare stackframe*/
618 stq pv,5*8(sp) /*pv of failure*/
619 stq itmp1,4*8(sp) /*exception string of the exception*/
620 stq xpc,3*8(sp) /*address of failure */
621 stq t0,2*8(sp) /*store begin of java stack frame*/
622 stq pv,1*8(sp) /*store pv of caller in structure*/
623 stq zero,0*8(sp) /*builtin (invisible function)*/
624 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
627 jsr ra,new_arithmeticexception
629 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
631 jsr ra,asm_remove_native_stackinfo
637 br asm_handle_exception
639 .end asm_throw_and_handle_arithmetic_exception
642 /* asm_throw_and_handle_exception **********************************************
646 *******************************************************************************/
648 .ent asm_throw_and_handle_nat_exception
650 asm_throw_and_handle_nat_exception:
652 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
654 sra t0,48,t0 /* isolate offset */
655 addq t0,ra,pv /* compute update address */
656 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
657 srl t0,16,t0 /* isolate instruction code */
658 lda t0,-0x177b(t0) /* test for LDAH */
659 bne t0,asm_throw_and_handle_exception
660 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
661 sll t0,16,t0 /* compute high offset */
662 addl t0,0,t0 /* sign extend high offset */
663 addq t0,pv,pv /* compute update address */
665 .aent asm_throw_and_handle_exception
667 asm_throw_and_handle_exception:
669 lda sp,-6*8(sp) /* prepare stackframe */
670 stq pv,5*8(sp) /* pv of failure */
671 stq xptr,4*8(sp) /* classname of the exception */
672 stq xpc,3*8(sp) /* address of failure */
673 stq t0,2*8(sp) /* store begin of java stack frame */
674 stq pv,1*8(sp) /* store pv of caller in structure */
675 stq zero,0*8(sp) /* builtin (invisible function) */
676 /* puts 2 additional quadwords on stack */
677 jsr ra,asm_prepare_native_stackinfo
680 ldq a0,6*8(sp) /* classname of exception */
684 mov v0,xptr /* xptr (itmp1) is not touched in */
685 /* asm_remove_native_stackinfo */
687 jsr ra,asm_remove_native_stackinfo
693 br asm_handle_exception
695 .end asm_throw_and_handle_nat_exception
698 /********************* function asm_handle_exception ***************************
700 * This function handles an exception. It does not use the usual calling *
701 * conventions. The exception pointer is passed in REG_ITMP1 and the *
702 * pc from the exception raising position is passed in REG_ITMP2. It searches *
703 * the local exception table for a handler. If no one is found, it unwinds *
704 * stacks and continues searching the callers. *
706 * void asm_handle_exception (exceptionptr, exceptionpc); *
708 *******************************************************************************/
710 .ent asm_handle_nat_exception
712 asm_handle_nat_exception:
713 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
715 sra t0,48,t0 /* isolate offset */
716 addq t0,ra,pv /* compute update address */
717 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
718 srl t0,16,t0 /* isolate instruction code */
719 lda t0,-0x177b(t0) /* test for LDAH */
720 bne t0,asm_handle_exception
721 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
722 sll t0,16,t0 /* compute high offset */
723 addl t0,0,t0 /* sign extend high offset */
724 addq t0,pv,pv /* compute update address */
726 .aent asm_handle_exception
728 asm_handle_exception:
729 lda sp,-18*8(sp) /* allocate stack */
730 stq t0,0*8(sp) /* save possible used registers */
731 stq t1,1*8(sp) /* also registers used by trace_exception */
749 lda t3,1(zero) /* set no unwind flag */
751 lda sp,-5*8(sp) /* allocate stack */
752 stq xptr,0*8(sp) /* save used register */
759 ldq a1,MethodPointer(pv)
764 br ra,ex_trace /* set ra for gp loading */
766 ldgp gp,0(ra) /* load gp */
767 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
769 ldq xptr,0*8(sp) /* restore used register */
774 lda sp,5*8(sp) /* deallocate stack */
776 ldl t0,ExTableSize(pv) /* t0 = exception table size */
777 beq t0,empty_table /* if empty table skip */
779 lda t1,ExTableStart(pv) /* t1 = start of exception table */
782 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
783 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
784 beq t2,ex_table_cont /* if (false) continue */
785 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
786 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
787 beq t2,ex_table_cont /* if (false) continue */
788 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
789 beq a1,ex_handle_it /* NULL catches everything */
791 ldl itmp3,offclassloaded(a1)
792 bne itmp3,L_class_loaded
794 subq sp,8*8,sp /* allocate stack */
795 stq t0,0*8(sp) /* save used register */
806 br ra,L_class_load_ra /* set ra for gp loading */
808 ldgp gp,0(ra) /* load gp */
809 jsr ra,load_class_bootstrap
811 ldq t0,0*8(sp) /* restore used register */
819 addq sp,8*8,sp /* deallocate stack */
822 ldl itmp3,offclasslinked(a1)
823 subq sp,8*8,sp /* allocate stack */
825 bne itmp3,L_class_linked
827 stq t0,0*8(sp) /* save used register */
837 br ra,L_class_link_ra /* set ra for gp loading */
839 ldgp gp,0(ra) /* load gp */
842 ldq t0,0*8(sp) /* restore used register */
854 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
855 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
856 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
857 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
858 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
860 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
861 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
862 addq sp,8*8,sp /* deallocate stack */
863 beq v0,ex_table_cont /* if (false) continue */
866 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
868 beq t3,ex_jump /* if (!(no stack unwinding) skip */
870 ldq t0,0*8(sp) /* restore possible used registers */
871 ldq t1,1*8(sp) /* also registers used by trace_exception */
888 lda sp,18*8(sp) /* deallocate stack */
891 jmp zero,(xpc) /* jump to the handler */
894 lda t1,ExEntrySize(t1) /* next exception table entry */
895 subl t0,1,t0 /* decrement entry counter */
896 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
899 beq t3,ex_already_cleared /* if here the first time, then */
900 lda sp,18*8(sp) /* deallocate stack and */
901 clr t3 /* clear the no unwind flag */
903 ldl t0,IsSync(pv) /* t0 = SyncOffset */
904 beq t0,no_monitor_exit /* if zero no monitorexit */
906 #if defined(USE_THREADS)
907 addq sp,t0,t0 /* add stackptr to Offset */
908 ldq a0,-8(t0) /* load monitorexit pointer */
910 lda sp,-7*8(sp) /* allocate stack */
911 stq t0,0*8(sp) /* save used register */
919 br ra,ex_mon_load /* set ra for gp loading */
921 ldgp gp,0(ra) /* load gp */
922 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
924 ldq t0,0*8(sp) /* restore used register */
931 lda sp,7*8(sp) /* deallocate stack */
935 ldl t0,FrameSize(pv) /* t0 = frame size */
936 addq sp,t0,sp /* unwind stack */
937 mov sp,t0 /* t0 = pointer to save area */
938 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
939 bne t1,ex_no_restore /* if (leaf) skip */
940 ldq ra,-8(t0) /* restore ra */
941 lda t0,-8(t0) /* t0-- */
943 mov ra,xpc /* the new xpc is ra */
944 ldl t1,IntSave(pv) /* t1 = saved int register count */
945 br t2,ex_int1 /* t2 = current pc */
947 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
948 negl t1,t1 /* negate register count */
949 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
950 jmp zero,(t2) /* jump to save position */
959 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
961 ldl t1,FltSave(pv) /* t1 = saved flt register count */
962 br t2,ex_flt1 /* t2 = current pc */
964 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
965 negl t1,t1 /* negate register count */
966 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
967 jmp zero,(t2) /* jump to save position */
977 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
979 sra t0,48,t0 /* isolate offset */
980 addq t0,ra,pv /* compute update address */
981 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
982 srl t0,16,t0 /* isolate instruction code */
983 lda t0,-0x177b(t0) /* test for LDAH */
985 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
986 sll t0,16,t0 /* compute high offset */
987 addl t0,0,t0 /* sign extend high offset */
988 addq t0,pv,pv /* compute update address */
991 .end asm_handle_nat_exception
994 /* asm_check_clinit ************************************************************
1000 itmp1: pointer to class
1004 0 mcode ; machine code to patch back in
1006 *******************************************************************************/
1008 .ent asm_check_clinit
1011 ldgp gp,0(itmp2) /* function is called via `jsr ra,itmp1' */
1015 stq ra,0*8(sp) /* save return address */
1016 stq pv,1*8(sp) /* save pv of calling java function */
1017 stq a0,2*8(sp) /* save argument registers for leaf */
1018 stq a1,3*8(sp) /* functions and native stub */
1024 ldl itmp2,offclassinit(itmp1)
1025 bne itmp2,L_is_initialized
1027 mov itmp1,a0 /* move class pointer to a0 */
1031 beq v0,L_initializererror
1034 ldq ra,0*8(sp) /* get return address */
1035 subq ra,1*4,ra /* go back 1 instruction */
1036 ldl itmp1,8*8(sp) /* load machine code from stack */
1037 stl itmp1,0(ra) /* store the machine code */
1039 call_pal PAL_imb /* synchronise instruction cache */
1041 ldq ra,0*8(sp) /* restore return address */
1042 ldq pv,1*8(sp) /* restore pv of calling java function */
1043 ldq a0,2*8(sp) /* restore argument registers */
1050 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1052 subq ra,1*4,ra /* go back 1 instruction */
1053 jmp zero,(ra) /* jump to the new code */
1056 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1057 jsr ra,builtin_asm_get_exceptionptrptr
1059 lda v0,_exceptionptr
1061 ldq xptr,0(v0) /* get the exception pointer */
1062 stq zero,0(v0) /* clear the exception pointer */
1064 ldq ra,0*8(sp) /* restore return address */
1065 ldq pv,1*8(sp) /* restore pv of calling java function */
1066 ldq a0,2*8(sp) /* restore argument registers */
1073 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1076 br asm_handle_exception /* we have the pv of the calling java func. */
1078 .end asm_check_clinit
1081 /********************* function asm_builtin_monitorenter ***********************
1083 * Does null check and calls monitorenter or throws an exception *
1085 *******************************************************************************/
1087 #if defined(USE_THREADS)
1088 .ent asm_builtin_monitorenter
1090 asm_builtin_monitorenter:
1092 lda pv,builtin_monitorenter
1093 beq a0,nb_monitorenter /* if (null) throw exception */
1094 jmp zero,(pv) /* else call builtin_monitorenter */
1098 ldq xptr,string_java_lang_NullPointerException
1099 jmp zero,asm_throw_and_handle_nat_exception
1103 jsr ra,new_nullpointerexception
1109 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1110 br asm_handle_nat_exception
1113 .end asm_builtin_monitorenter
1117 /********************* function asm_builtin_monitorexit ************************
1119 * Does null check and calls monitorexit or throws an exception *
1121 *******************************************************************************/
1123 #if defined(USE_THREADS)
1124 .ent asm_builtin_monitorexit
1126 asm_builtin_monitorexit:
1128 lda pv,builtin_monitorexit
1129 beq a0,nb_monitorexit /* if (null) throw exception */
1130 jmp zero,(pv) /* else call builtin_monitorexit */
1134 ldq xptr,string_java_lang_NullPointerException
1135 jmp zero,asm_throw_and_handle_nat_exception
1139 jsr ra,new_nullpointerexception
1145 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1146 br asm_handle_nat_exception
1149 .end asm_builtin_monitorexit
1153 /************************ function asm_builtin_idiv ****************************
1155 * Does null check and calls idiv or throws an exception *
1157 *******************************************************************************/
1159 .ent asm_builtin_idiv
1164 beq a1,nb_idiv /* if (null) throw exception */
1165 jmp zero,(pv) /* else call builtin_idiv */
1168 ldq xptr,string_java_lang_ArithmeticException_message
1169 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1170 br asm_throw_and_handle_arithmetic_exception
1172 .end asm_builtin_idiv
1175 /************************ function asm_builtin_ldiv ****************************
1177 * Does null check and calls ldiv or throws an exception *
1179 *******************************************************************************/
1181 .ent asm_builtin_ldiv
1186 beq a1,nb_ldiv /* if (null) throw exception */
1187 jmp zero,(pv) /* else call builtin_ldiv */
1190 ldq xptr,string_java_lang_ArithmeticException_message
1191 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1192 br asm_throw_and_handle_arithmetic_exception
1194 .end asm_builtin_ldiv
1197 /************************ function asm_builtin_irem ****************************
1199 * Does null check and calls irem or throws an exception *
1201 *******************************************************************************/
1203 .ent asm_builtin_irem
1208 beq a1,nb_irem /* if (null) throw exception */
1209 jmp zero,(pv) /* else call builtin_irem */
1212 ldq xptr,string_java_lang_ArithmeticException_message
1213 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1214 br asm_throw_and_handle_arithmetic_exception
1216 .end asm_builtin_irem
1219 /************************ function asm_builtin_lrem ****************************
1221 * Does null check and calls lrem or throws an exception *
1223 *******************************************************************************/
1225 .ent asm_builtin_lrem
1230 beq a1,nb_lrem /* if (null) throw exception */
1231 jmp zero,(pv) /* else call builtin_lrem */
1234 ldq xptr,string_java_lang_ArithmeticException_message
1235 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1236 br asm_throw_and_handle_arithmetic_exception
1238 .end asm_builtin_lrem
1241 /******************* function asm_builtin_checkarraycast ***********************
1243 * Does the cast check and eventually throws an exception *
1245 *******************************************************************************/
1247 .ent asm_builtin_checkarraycast
1249 asm_builtin_checkarraycast:
1251 lda sp,-16(sp) /* allocate stack space */
1252 stq ra,0(sp) /* save return address */
1253 stq a0,8(sp) /* save object pointer */
1254 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1256 beq v0,nb_carray_throw /* if (false) throw exception */
1257 ldq ra,0(sp) /* restore return address */
1258 ldq v0,8(sp) /* return object pointer */
1259 lda sp,16(sp) /* free stack space */
1266 ldq xptr,string_java_lang_ClassCastException
1267 jmp zero,asm_throw_and_handle_nat_exception
1269 ldq a0,string_java_lang_ClassCastException
1270 jsr ra,new_exception
1274 ldq ra,0(sp) /* restore return address */
1275 lda sp,16(sp) /* free stack space */
1276 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1277 br asm_handle_nat_exception
1280 .end asm_builtin_checkarraycast
1283 /******************* function asm_builtin_aastore ******************************
1285 * Does the cast check and eventually throws an exception *
1287 *******************************************************************************/
1289 .ent asm_builtin_aastore
1291 asm_builtin_aastore:
1293 beq a0,nb_aastore_null /* if null pointer throw exception */
1294 ldl t0,offarraysize(a0) /* load size */
1295 lda sp,-24(sp) /* allocate stack space */
1296 stq ra,0(sp) /* save return address */
1297 s8addq a1,a0,t1 /* add index*8 to arrayref */
1298 cmpult a1,t0,t0 /* do bound check */
1299 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1300 mov a2,a1 /* object is second argument */
1301 stq t1,8(sp) /* save store position */
1302 stq a1,16(sp) /* save object */
1303 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1305 ldq ra,0(sp) /* restore return address */
1306 ldq a0,8(sp) /* restore store position */
1307 ldq a1,16(sp) /* restore object */
1308 lda sp,24(sp) /* free stack space */
1309 beq v0,nb_aastore_throw /* if (false) throw exception */
1310 stq a1,offobjarrdata(a0) /* store objectptr in array */
1314 ldq xptr,string_java_lang_NullPointerException
1316 jmp zero,asm_throw_and_handle_nat_exception
1318 subq sp,8,sp /* allocate stack space */
1319 stq ra,0(sp) /* save return address */
1320 jsr ra,new_nullpointerexception
1326 mov ra,xpc /* faulting address is return adress */
1327 br asm_handle_nat_exception
1334 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1336 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1337 jsr ra,new_exception_int /* a1 already contains the index */
1341 ldq ra,0(sp) /* restore return address */
1342 lda sp,24(sp) /* free stack space */
1343 mov ra,xpc /* faulting address is return adress */
1344 br asm_handle_nat_exception
1348 ldq xptr,string_java_lang_ArrayStoreException
1349 jmp zero,asm_throw_and_handle_nat_exception
1351 subq sp,8,sp /* allocate stack space */
1352 stq ra,0(sp) /* save return address */
1353 jsr ra,new_arraystoreexception
1359 mov ra,xpc /* faulting address is return adress */
1360 br asm_handle_nat_exception
1362 .end asm_builtin_aastore
1365 /******************* function asm_initialize_thread_stack **********************
1367 * initialized a thread stack *
1369 *******************************************************************************/
1371 .ent asm_initialize_thread_stack
1373 asm_initialize_thread_stack:
1394 .end asm_initialize_thread_stack
1397 /******************* function asm_perform_threadswitch *************************
1399 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1401 * performs a threadswitch *
1403 *******************************************************************************/
1405 .ent asm_perform_threadswitch
1407 asm_perform_threadswitch:
1448 .end asm_perform_threadswitch
1451 /********************* function asm_switchstackandcall *************************
1453 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1456 * Switches to a new stack, calls a function and switches back. *
1457 * a0 new stack pointer *
1458 * a1 function pointer *
1459 * a2 pointer to variable where stack top should be stored *
1460 * a3 pointer to user data, is passed to the function *
1462 *******************************************************************************/
1465 .ent asm_switchstackandcall
1467 asm_switchstackandcall:
1468 lda a0,-2*8(a0) /* allocate new stack */
1469 stq ra,0(a0) /* save return address on new stack */
1470 stq sp,1*8(a0) /* save old stack pointer on new stack */
1471 stq sp,0(a2) /* save old stack pointer to variable */
1472 mov a0,sp /* switch to new stack */
1474 mov a1,pv /* load function pointer */
1475 mov a3,a0 /* pass pointer */
1476 jmp ra,(pv) /* and call function */
1478 ldq ra,0(sp) /* load return address */
1479 ldq sp,1*8(sp) /* switch to old stack */
1481 jmp zero,(ra) /* return */
1483 .end asm_switchstackandcall
1485 .ent asm_getclassvalues_atomic
1487 asm_getclassvalues_atomic:
1490 ldl t0,offbaseval(a0)
1491 ldl t1,offdiffval(a0)
1492 ldl t2,offbaseval(a1)
1494 stl t0,offcast_super_baseval(a2)
1495 stl t1,offcast_super_diffval(a2)
1496 stl t2,offcast_sub_baseval(a2)
1499 .end asm_getclassvalues_atomic
1503 asm_criticalsections:
1504 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1507 .quad _crit_restart1
1510 .quad _crit_restart2
1515 .ent asm_prepare_native_stackinfo
1516 asm_prepare_native_stackinfo:
1519 jsr ra,builtin_asm_get_stackframeinfo
1527 .end asm_prepare_native_stackinfo
1529 .ent asm_remove_native_stackinfo
1530 asm_remove_native_stackinfo:
1536 .end asm_remove_native_stackinfo
1539 * These are local overrides for various environment variables in Emacs.
1540 * Please do not remove this and leave it at the end of the file, where
1541 * Emacs will automagically detect them.
1542 * ---------------------------------------------------------------------
1545 * indent-tabs-mode: t