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 1865 2005-01-10 11:21:46Z 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
113 .globl asm_calljavafunction2
114 .globl asm_calljavafunction2int
115 .globl asm_calljavafunction2long
116 .globl asm_calljavafunction2float
117 .globl asm_calljavafunction2double
119 .globl asm_call_jit_compiler
120 .globl asm_throw_and_handle_exception
121 .globl asm_throw_and_handle_nat_exception
122 .globl asm_throw_and_handle_arithmetic_exception
123 .globl asm_throw_and_handle_arrayindexoutofbounds_exception
124 .globl asm_handle_exception
125 .globl asm_handle_nat_exception
126 .globl asm_check_clinit
127 .globl asm_builtin_checkcast
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_builtin_trace
144 .globl asm_builtin_exittrace
145 .globl asm_criticalsections
146 .globl asm_getclassvalues_atomic
147 .globl asm_prepare_native_stackinfo
148 .globl asm_remove_native_stackinfo
149 .globl asm_refillin_and_handle_exception
152 /*********************** function has_no_x_instr_set ***************************
154 * determines if the byte support instruction set (21164a and higher) *
157 *******************************************************************************/
159 .ent has_no_x_instr_set
162 .long 0x47e03c20 /* amask 1,v0 */
163 jmp zero,(ra) /* return */
165 .end has_no_x_instr_set
168 /********************* function asm_calljavafunction ***************************
170 * This function calls a Java-method (which possibly needs compilation) *
171 * with up to 4 address parameters. *
173 * This functions calls the JIT-compiler which eventually translates the *
174 * method into machine code. *
177 * javaobject_header *asm_calljavafunction (methodinfo *m, *
178 * void *arg1, void *arg2, void *arg3, void *arg4); *
180 *******************************************************************************/
182 .ent asm_calljavafunction
185 .ascii "calljavafunction\0\0"
188 .quad 0 /* catch type all */
189 .quad calljava_xhandler /* handler pc */
190 .quad calljava_xhandler /* end pc */
191 .quad asm_calljavafunction /* start pc */
192 .long 1 /* extable size */
193 .long 0 /* PADDING */
194 .quad 0 /* line number table start */
195 .quad 0 /* line number table size */
196 .long 0 /* PADDING */
197 .long 0 /* fltsave */
198 .long 0 /* intsave */
201 .long 32 /* frame size */
202 .quad 0 /* method pointer (pointer to name) */
204 asm_calljavafunction:
206 lda sp,-32(sp) /* allocate stack space */
207 stq gp,24(sp) /* save global pointer */
208 stq ra,0(sp) /* save return address */
210 stq a0,16(sp) /* save method pointer for compiler */
211 lda v0,16(sp) /* pass pointer to method pointer via v0*/
213 mov a1,a0 /* pass the remaining parameters */
218 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
219 stq $28,8(sp) /* store function address */
220 mov sp,$28 /* set method pointer */
222 ldq pv,8($28) /* method call as in Java */
223 jmp ra,(pv) /* call JIT compiler */
225 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
228 ldq ra,0(sp) /* restore return address */
229 ldq gp,24(sp) /* restore global pointer */
230 lda sp,32(sp) /* free stack space */
236 ldq gp,24(sp) /* restore global pointer */
238 jsr ra,builtin_throw_exception
239 ldq ra,0(sp) /* restore return address */
240 lda sp,32(sp) /* free stack space */
242 .end asm_calljavafunction
247 .ent asm_calljavafunction2
252 .quad 0 /* catch type all */
253 .quad calljava_xhandler2 /* handler pc */
254 .quad calljava_xhandler2 /* end pc */
255 .quad asm_calljavafunction2 /* start pc */
256 .long 1 /* extable size */
257 .long 0 /* PADDING */
258 .quad 0 /* line number table start */
259 .quad 0 /* line number table size */
260 .long 0 /* PADDING */
261 .long 0 /* fltsave */
262 .long 1 /* intsave */
265 .long 40 /* frame size */
266 .quad 0 /* method pointer (pointer to name) */
268 asm_calljavafunction2:
269 asm_calljavafunction2int:
270 asm_calljavafunction2long:
271 asm_calljavafunction2float:
272 asm_calljavafunction2double:
274 lda sp,-40(sp) /* allocate stack space */
275 stq ra,0(sp) /* save return address */
277 stq gp,8(sp) /* save global pointer */
279 stq a0,32(sp) /* save method pointer for compiler */
280 mov a3,t0 /* pointer to arg block */
281 mov a1,s6 /* arg count */
283 ble s6,calljava_argsloaded
285 ldq a0,offjniitem(t0)
286 ldt $f16,offjniitem(t0)
287 ble s6,calljava_argsloaded
289 ldq a1,offjniitem+sizejniblock*1(t0)
290 ldt $f17,offjniitem+sizejniblock*1(t0)
291 ble s6,calljava_argsloaded
293 ldq a2,offjniitem+sizejniblock*2(t0)
294 ldt $f18,offjniitem+sizejniblock*2(t0)
295 ble s6,calljava_argsloaded
297 ldq a3,offjniitem+sizejniblock*3(t0)
298 ldt $f19,offjniitem+sizejniblock*3(t0)
299 ble s6,calljava_argsloaded
301 ldq a4,offjniitem+sizejniblock*4(t0)
302 ldt $f20,offjniitem+sizejniblock*4(t0)
303 ble s6,calljava_argsloaded
305 ldq a5,offjniitem+sizejniblock*5(t0)
306 ldt $f21,offjniitem+sizejniblock*5(t0)
309 ble s6,calljava_nocopy
315 ldq t3,offjniitem+sizejniblock*6(t0)
318 lda t0,sizejniblock(t0)
320 bne t1,calljava_copyloop
323 lda v0,32(t4) /* pass pointer to method pointer via v0*/
325 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
326 stq $28,16(t4) /* store function address */
327 lda $28,8(t4) /* set method pointer */
329 ldq pv,8($28) /* method call as in Java */
330 jmp ra,(pv) /* call JIT compiler */
332 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
336 ldq ra,0(sp) /* restore return address */
337 ldq gp,8(sp) /* restore global pointer */
339 lda sp,40(sp) /* free stack space */
346 ldq gp,8(sp) /* restore global pointer */
348 jsr ra,builtin_throw_exception
349 ldq ra,0(sp) /* restore return address */
351 lda sp,40(sp) /* free stack space */
353 .end asm_calljavafunction2
356 /****************** function asm_call_jit_compiler *****************************
358 * invokes the compiler for untranslated JavaVM methods. *
360 * Register R0 contains a pointer to the method info structure (prepared *
361 * by createcompilerstub). Using the return address in R26 and the *
362 * offset in the LDA instruction or using the value in methodptr R28 the *
363 * patching address for storing the method address can be computed: *
365 * method address was either loaded using *
366 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
367 * M_LDA (REG_PV, REG_RA, low) *
368 * M_LDAH(REG_PV, REG_RA, high) ; optional *
370 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
371 * in the static case the method pointer can be computed using the *
372 * return address and the lda function following the jmp instruction *
374 *******************************************************************************/
376 .ent asm_call_jit_compiler
378 asm_call_jit_compiler:
380 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
381 srl t8,16,t8 /* shift right register number $yy */
382 and t8,31,t8 /* isolate register number */
383 subl t8,28,t8 /* test for REG_METHODPTR */
385 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
387 sra t8,48,t8 /* isolate offset */
388 addq t8,ra,$28 /* compute update address */
389 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
390 srl t8,16,t8 /* isolate instruction code */
391 lda t8,-0x177b(t8) /* test for LDAH */
393 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
394 sll t8,16,t8 /* compute high offset */
395 addl t8,0,t8 /* sign extend high offset */
396 addq t8,$28,$28 /* compute update address */
398 lda sp,-14*8(sp) /* reserve stack space */
399 stq a0,0*8(sp) /* save all argument registers */
400 stq a1,1*8(sp) /* they could be used by method */
411 stq $28,12*8(sp) /* save method pointer */
412 stq ra,13*8(sp) /* save return address */
414 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
415 jsr ra,jit_compile /* jit compiler */
418 ldq a0,0*8(sp) /* load argument registers */
430 ldq $28,12*8(sp) /* load method pointer */
431 ldq ra,13*8(sp) /* load return address */
432 lda sp,14*8(sp) /* deallocate stack area */
434 beq v0,asm_call_jit_compiler_exception
436 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
438 sra t8,48,t8 /* isolate offset */
440 addq t8,$28,t8 /* compute update address via method pointer*/
441 stq v0,0(t8) /* save new method address there */
443 call_pal PAL_imb /* synchronise instruction cache */
445 mov v0,pv /* load method address into pv */
446 jmp zero,(pv) /* and call method. The method returns */
447 /* directly to the caller (ra). */
449 asm_call_jit_compiler_exception:
450 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
453 jsr ra,builtin_asm_get_exceptionptrptr
459 ldq xptr,0(v0) /* get the exception pointer */
460 stq zero,0(v0) /* clear the exception pointer */
463 br asm_handle_nat_exception
465 .end asm_call_jit_compiler
468 /**************** function asm_refillin_and_handle_exception *******************
470 * This function handles an exception. It does not use the usual calling *
471 * conventions. The exception is passed in REG_ITMP1 and the *
472 * pc from the exception raising position is passed in REG_ITMP2. *
473 * a0 contains the PV of the function causing the problem *
475 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
477 *******************************************************************************/
478 .ent asm_refillin_and_handle_exception
479 asm_refillin_and_handle_exception:
481 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
483 sra t0,48,t0 /* isolate offset */
484 addq t0,ra,pv /* compute update address */
485 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
486 srl t0,16,t0 /* isolate instruction code */
487 lda t0,-0x177b(t0) /* test for LDAH */
488 bne t0, asm_refillin_and_handle_exception_cont
489 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
490 sll t0,16,t0 /* compute high offset */
491 addl t0,0,t0 /* sign extend high offset */
492 addq t0,pv,pv /* compute update address */
494 asm_refillin_and_handle_exception_cont:
497 lda sp,-6*8(sp) /* prepare stackframe*/
498 stq pv,5*8(sp) /* store pv of caller */
499 stq xptr,4*8(sp) /*exception ptr*/
500 stq xpc,3*8(sp) /*address of failure*/
501 stq t0,2*8(sp) /*begin of java stack frame*/
502 stq pv,1*8(sp) /* store pv of caller */
503 stq zero,0*8(sp) /*builtin (invisible) function */
504 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
507 ldq a2,utf_fillInStackTrace_desc
508 ldq a1,utf_fillInStackTrace_name
510 ldq t1,offobjvftbl(t0)
512 jsr ra,class_resolvemethod
514 /* now we have the method */
519 jsr ra,asm_calljavafunction
523 jsr ra,asm_remove_native_stackinfo
532 br asm_handle_exception
534 .end asm_refillin_and_handle_exception
536 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
538 * This function handles an exception. It does not use the usual calling *
539 * conventions. The integer parameter is passed in REG_ITMP1 and the *
540 * pc from the exception raising position is passed in REG_ITMP2. *
542 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
544 *******************************************************************************/
546 .ent asm_throw_and_handle_arrayindexoutofbounds_exception
548 asm_throw_and_handle_arrayindexoutofbounds_exception:
551 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
553 sra t0,48,t0 /* isolate offset */
554 addq t0,ra,pv /* compute update address */
555 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
556 srl t0,16,t0 /* isolate instruction code */
557 lda t0,-0x177b(t0) /* test for LDAH */
558 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
559 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
560 sll t0,16,t0 /* compute high offset */
561 addl t0,0,t0 /* sign extend high offset */
562 addq t0,pv,pv /* compute update address */
564 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
566 lda sp,-6*8(sp) /*prepare stackframe*/
567 stq pv,5*8(sp) /*pv of failure*/
568 stq itmp1,4*8(sp) /*int parameter of the exception*/
569 stq xpc,3*8(sp) /*address of failure */
570 stq t0,2*8(sp) /*store begin of java stack frame*/
571 stq pv,1*8(sp) /*store pv of caller in structure*/
572 stq zero,0*8(sp) /*builtin (invisible function)*/
574 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
577 ldq a0,6*8(sp) /*int of exception*/
578 jsr ra,new_arrayindexoutofboundsexception
581 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
583 jsr ra,asm_remove_native_stackinfo
589 br asm_handle_exception
591 .end asm_throw_and_handle_arrayindexoutofbounds_exception
594 /* asm_throw_and_handle_arithmetic_exception ***********************************
598 *******************************************************************************/
600 .ent asm_throw_and_handle_arithmetic_exception
602 asm_throw_and_handle_arithmetic_exception:
603 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
605 sra t0,48,t0 /* isolate offset */
606 addq t0,ra,pv /* compute update address */
607 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
608 srl t0,16,t0 /* isolate instruction code */
609 lda t0,-0x177b(t0) /* test for LDAH */
610 bne t0,asm_throw_and_handle_arithmetic_exception_cont
611 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
612 sll t0,16,t0 /* compute high offset */
613 addl t0,0,t0 /* sign extend high offset */
614 addq t0,pv,pv /* compute update address */
616 asm_throw_and_handle_arithmetic_exception_cont:
618 lda sp,-6*8(sp) /*prepare stackframe*/
619 stq pv,5*8(sp) /*pv of failure*/
620 stq itmp1,4*8(sp) /*exception string of the exception*/
621 stq xpc,3*8(sp) /*address of failure */
622 stq t0,2*8(sp) /*store begin of java stack frame*/
623 stq pv,1*8(sp) /*store pv of caller in structure*/
624 stq zero,0*8(sp) /*builtin (invisible function)*/
625 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
628 jsr ra,new_arithmeticexception
630 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
632 jsr ra,asm_remove_native_stackinfo
638 br asm_handle_exception
640 .end asm_throw_and_handle_arithmetic_exception
643 /* asm_throw_and_handle_exception **********************************************
647 *******************************************************************************/
649 .ent asm_throw_and_handle_nat_exception
651 asm_throw_and_handle_nat_exception:
653 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
655 sra t0,48,t0 /* isolate offset */
656 addq t0,ra,pv /* compute update address */
657 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
658 srl t0,16,t0 /* isolate instruction code */
659 lda t0,-0x177b(t0) /* test for LDAH */
660 bne t0,asm_throw_and_handle_exception
661 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
662 sll t0,16,t0 /* compute high offset */
663 addl t0,0,t0 /* sign extend high offset */
664 addq t0,pv,pv /* compute update address */
666 .aent asm_throw_and_handle_exception
668 asm_throw_and_handle_exception:
670 lda sp,-6*8(sp) /* prepare stackframe */
671 stq pv,5*8(sp) /* pv of failure */
672 stq xptr,4*8(sp) /* classname of the exception */
673 stq xpc,3*8(sp) /* address of failure */
674 stq t0,2*8(sp) /* store begin of java stack frame */
675 stq pv,1*8(sp) /* store pv of caller in structure */
676 stq zero,0*8(sp) /* builtin (invisible function) */
677 /* puts 2 additional quadwords on stack */
678 jsr ra,asm_prepare_native_stackinfo
681 ldq a0,6*8(sp) /* classname of exception */
685 mov v0,xptr /* xptr (itmp1) is not touched in */
686 /* asm_remove_native_stackinfo */
688 jsr ra,asm_remove_native_stackinfo
694 br asm_handle_exception
696 .end asm_throw_and_handle_nat_exception
699 /********************* function asm_handle_exception ***************************
701 * This function handles an exception. It does not use the usual calling *
702 * conventions. The exception pointer is passed in REG_ITMP1 and the *
703 * pc from the exception raising position is passed in REG_ITMP2. It searches *
704 * the local exception table for a handler. If no one is found, it unwinds *
705 * stacks and continues searching the callers. *
707 * void asm_handle_exception (exceptionptr, exceptionpc); *
709 *******************************************************************************/
711 .ent asm_handle_nat_exception
713 asm_handle_nat_exception:
714 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
716 sra t0,48,t0 /* isolate offset */
717 addq t0,ra,pv /* compute update address */
718 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
719 srl t0,16,t0 /* isolate instruction code */
720 lda t0,-0x177b(t0) /* test for LDAH */
721 bne t0,asm_handle_exception
722 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
723 sll t0,16,t0 /* compute high offset */
724 addl t0,0,t0 /* sign extend high offset */
725 addq t0,pv,pv /* compute update address */
727 .aent asm_handle_exception
729 asm_handle_exception:
730 lda sp,-18*8(sp) /* allocate stack */
731 stq t0,0*8(sp) /* save possible used registers */
732 stq t1,1*8(sp) /* also registers used by trace_exception */
750 lda t3,1(zero) /* set no unwind flag */
752 lda sp,-5*8(sp) /* allocate stack */
753 stq xptr,0*8(sp) /* save used register */
760 ldq a1,MethodPointer(pv)
765 br ra,ex_trace /* set ra for gp loading */
767 ldgp gp,0(ra) /* load gp */
768 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
770 ldq xptr,0*8(sp) /* restore used register */
775 lda sp,5*8(sp) /* deallocate stack */
777 ldl t0,ExTableSize(pv) /* t0 = exception table size */
778 beq t0,empty_table /* if empty table skip */
780 lda t1,ExTableStart(pv) /* t1 = start of exception table */
783 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
784 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
785 beq t2,ex_table_cont /* if (false) continue */
786 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
787 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
788 beq t2,ex_table_cont /* if (false) continue */
789 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
790 beq a1,ex_handle_it /* NULL catches everything */
792 ldl itmp3,offclassloaded(a1)
793 bne itmp3,L_class_loaded
795 subq sp,8*8,sp /* allocate stack */
796 stq t0,0*8(sp) /* save used register */
807 br ra,L_class_load_ra /* set ra for gp loading */
809 ldgp gp,0(ra) /* load gp */
810 jsr ra,class_load /* class_load(exceptionclass) */
812 ldq t0,0*8(sp) /* restore used register */
820 addq sp,8*8,sp /* deallocate stack */
823 ldl itmp3,offclasslinked(a1)
824 subq sp,8*8,sp /* allocate stack */
826 bne itmp3,L_class_linked
828 stq t0,0*8(sp) /* save used register */
838 br ra,L_class_link_ra /* set ra for gp loading */
840 ldgp gp,0(ra) /* load gp */
841 jsr ra,class_link /* class_load(exceptionclass) */
843 ldq t0,0*8(sp) /* restore used register */
855 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
856 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
857 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
858 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
859 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
861 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
862 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
863 addq sp,8*8,sp /* deallocate stack */
864 beq v0,ex_table_cont /* if (false) continue */
867 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
869 beq t3,ex_jump /* if (!(no stack unwinding) skip */
871 ldq t0,0*8(sp) /* restore possible used registers */
872 ldq t1,1*8(sp) /* also registers used by trace_exception */
889 lda sp,18*8(sp) /* deallocate stack */
892 jmp zero,(xpc) /* jump to the handler */
895 lda t1,ExEntrySize(t1) /* next exception table entry */
896 subl t0,1,t0 /* decrement entry counter */
897 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
900 beq t3,ex_already_cleared /* if here the first time, then */
901 lda sp,18*8(sp) /* deallocate stack and */
902 clr t3 /* clear the no unwind flag */
904 ldl t0,IsSync(pv) /* t0 = SyncOffset */
905 beq t0,no_monitor_exit /* if zero no monitorexit */
907 #if defined(USE_THREADS)
908 addq sp,t0,t0 /* add stackptr to Offset */
909 ldq a0,-8(t0) /* load monitorexit pointer */
911 lda sp,-7*8(sp) /* allocate stack */
912 stq t0,0*8(sp) /* save used register */
920 br ra,ex_mon_load /* set ra for gp loading */
922 ldgp gp,0(ra) /* load gp */
923 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
925 ldq t0,0*8(sp) /* restore used register */
932 lda sp,7*8(sp) /* deallocate stack */
936 ldl t0,FrameSize(pv) /* t0 = frame size */
937 addq sp,t0,sp /* unwind stack */
938 mov sp,t0 /* t0 = pointer to save area */
939 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
940 bne t1,ex_no_restore /* if (leaf) skip */
941 ldq ra,-8(t0) /* restore ra */
942 lda t0,-8(t0) /* t0-- */
944 mov ra,xpc /* the new xpc is ra */
945 ldl t1,IntSave(pv) /* t1 = saved int register count */
946 br t2,ex_int1 /* t2 = current pc */
948 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
949 negl t1,t1 /* negate register count */
950 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
951 jmp zero,(t2) /* jump to save position */
960 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
962 ldl t1,FltSave(pv) /* t1 = saved flt register count */
963 br t2,ex_flt1 /* t2 = current pc */
965 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
966 negl t1,t1 /* negate register count */
967 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
968 jmp zero,(t2) /* jump to save position */
978 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
980 sra t0,48,t0 /* isolate offset */
981 addq t0,ra,pv /* compute update address */
982 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
983 srl t0,16,t0 /* isolate instruction code */
984 lda t0,-0x177b(t0) /* test for LDAH */
986 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
987 sll t0,16,t0 /* compute high offset */
988 addl t0,0,t0 /* sign extend high offset */
989 addq t0,pv,pv /* compute update address */
992 .end asm_handle_nat_exception
995 /* asm_check_clinit ************************************************************
1001 itmp1: pointer to class
1005 0 mcode ; machine code to patch back in
1007 *******************************************************************************/
1009 .ent asm_check_clinit
1012 ldgp gp,0(itmp2) /* function is called via `jsr ra,itmp1' */
1016 stq ra,0*8(sp) /* save return address */
1017 stq pv,1*8(sp) /* save pv of calling java function */
1018 stq a0,2*8(sp) /* save argument registers for leaf */
1019 stq a1,3*8(sp) /* functions and native stub */
1025 ldl itmp2,offclassinit(itmp1)
1026 bne itmp2,L_is_initialized
1028 mov itmp1,a0 /* move class pointer to a0 */
1032 beq v0,L_initializererror
1035 ldq ra,0*8(sp) /* get return address */
1036 subq ra,1*4,ra /* go back 1 instruction */
1037 ldl itmp1,8*8(sp) /* load machine code from stack */
1038 stl itmp1,0(ra) /* store the machine code */
1040 call_pal PAL_imb /* synchronise instruction cache */
1042 ldq ra,0*8(sp) /* restore return address */
1043 ldq pv,1*8(sp) /* restore pv of calling java function */
1044 ldq a0,2*8(sp) /* restore argument registers */
1051 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1053 subq ra,1*4,ra /* go back 1 instruction */
1054 jmp zero,(ra) /* jump to the new code */
1057 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1058 jsr ra,builtin_asm_get_exceptionptrptr
1060 lda v0,_exceptionptr
1062 ldq xptr,0(v0) /* get the exception pointer */
1063 stq zero,0(v0) /* clear the exception pointer */
1065 ldq ra,0*8(sp) /* restore return address */
1066 ldq pv,1*8(sp) /* restore pv of calling java function */
1067 ldq a0,2*8(sp) /* restore argument registers */
1074 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1077 br asm_handle_exception /* we have the pv of the calling java func. */
1079 .end asm_check_clinit
1082 /********************* function asm_builtin_monitorenter ***********************
1084 * Does null check and calls monitorenter or throws an exception *
1086 *******************************************************************************/
1088 #if defined(USE_THREADS)
1089 .ent asm_builtin_monitorenter
1091 asm_builtin_monitorenter:
1093 lda pv,builtin_monitorenter
1094 beq a0,nb_monitorenter /* if (null) throw exception */
1095 jmp zero,(pv) /* else call builtin_monitorenter */
1099 ldq xptr,string_java_lang_NullPointerException
1100 jmp zero,asm_throw_and_handle_nat_exception
1104 jsr ra,new_nullpointerexception
1110 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1111 br asm_handle_nat_exception
1114 .end asm_builtin_monitorenter
1118 /********************* function asm_builtin_monitorexit ************************
1120 * Does null check and calls monitorexit or throws an exception *
1122 *******************************************************************************/
1124 #if defined(USE_THREADS)
1125 .ent asm_builtin_monitorexit
1127 asm_builtin_monitorexit:
1129 lda pv,builtin_monitorexit
1130 beq a0,nb_monitorexit /* if (null) throw exception */
1131 jmp zero,(pv) /* else call builtin_monitorexit */
1135 ldq xptr,string_java_lang_NullPointerException
1136 jmp zero,asm_throw_and_handle_nat_exception
1140 jsr ra,new_nullpointerexception
1146 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1147 br asm_handle_nat_exception
1150 .end asm_builtin_monitorexit
1154 /************************ function asm_builtin_idiv ****************************
1156 * Does null check and calls idiv or throws an exception *
1158 *******************************************************************************/
1160 .ent asm_builtin_idiv
1165 beq a1,nb_idiv /* if (null) throw exception */
1166 jmp zero,(pv) /* else call builtin_idiv */
1169 ldq xptr,string_java_lang_ArithmeticException_message
1170 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1171 br asm_throw_and_handle_arithmetic_exception
1173 .end asm_builtin_idiv
1176 /************************ function asm_builtin_ldiv ****************************
1178 * Does null check and calls ldiv or throws an exception *
1180 *******************************************************************************/
1182 .ent asm_builtin_ldiv
1187 beq a1,nb_ldiv /* if (null) throw exception */
1188 jmp zero,(pv) /* else call builtin_ldiv */
1191 ldq xptr,string_java_lang_ArithmeticException_message
1192 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1193 br asm_throw_and_handle_arithmetic_exception
1195 .end asm_builtin_ldiv
1198 /************************ function asm_builtin_irem ****************************
1200 * Does null check and calls irem or throws an exception *
1202 *******************************************************************************/
1204 .ent asm_builtin_irem
1209 beq a1,nb_irem /* if (null) throw exception */
1210 jmp zero,(pv) /* else call builtin_irem */
1213 ldq xptr,string_java_lang_ArithmeticException_message
1214 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1215 br asm_throw_and_handle_arithmetic_exception
1217 .end asm_builtin_irem
1220 /************************ function asm_builtin_lrem ****************************
1222 * Does null check and calls lrem or throws an exception *
1224 *******************************************************************************/
1226 .ent asm_builtin_lrem
1231 beq a1,nb_lrem /* if (null) throw exception */
1232 jmp zero,(pv) /* else call builtin_lrem */
1235 ldq xptr,string_java_lang_ArithmeticException_message
1236 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1237 br asm_throw_and_handle_arithmetic_exception
1239 .end asm_builtin_lrem
1242 /******************* function asm_builtin_checkarraycast ***********************
1244 * Does the cast check and eventually throws an exception *
1246 *******************************************************************************/
1248 .ent asm_builtin_checkarraycast
1250 asm_builtin_checkarraycast:
1252 lda sp,-16(sp) /* allocate stack space */
1253 stq ra,0(sp) /* save return address */
1254 stq a0,8(sp) /* save object pointer */
1255 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1257 beq v0,nb_carray_throw /* if (false) throw exception */
1258 ldq ra,0(sp) /* restore return address */
1259 ldq v0,8(sp) /* return object pointer */
1260 lda sp,16(sp) /* free stack space */
1267 ldq xptr,string_java_lang_ClassCastException
1268 jmp zero,asm_throw_and_handle_nat_exception
1270 ldq a0,string_java_lang_ClassCastException
1271 jsr ra,new_exception
1275 ldq ra,0(sp) /* restore return address */
1276 lda sp,16(sp) /* free stack space */
1277 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1278 br asm_handle_nat_exception
1281 .end asm_builtin_checkarraycast
1284 /******************* function asm_builtin_aastore ******************************
1286 * Does the cast check and eventually throws an exception *
1288 *******************************************************************************/
1290 .ent asm_builtin_aastore
1292 asm_builtin_aastore:
1294 beq a0,nb_aastore_null /* if null pointer throw exception */
1295 ldl t0,offarraysize(a0) /* load size */
1296 lda sp,-24(sp) /* allocate stack space */
1297 stq ra,0(sp) /* save return address */
1298 s8addq a1,a0,t1 /* add index*8 to arrayref */
1299 cmpult a1,t0,t0 /* do bound check */
1300 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1301 mov a2,a1 /* object is second argument */
1302 stq t1,8(sp) /* save store position */
1303 stq a1,16(sp) /* save object */
1304 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1306 ldq ra,0(sp) /* restore return address */
1307 ldq a0,8(sp) /* restore store position */
1308 ldq a1,16(sp) /* restore object */
1309 lda sp,24(sp) /* free stack space */
1310 beq v0,nb_aastore_throw /* if (false) throw exception */
1311 stq a1,offobjarrdata(a0) /* store objectptr in array */
1315 ldq xptr,string_java_lang_NullPointerException
1317 jmp zero,asm_throw_and_handle_nat_exception
1319 subq sp,8,sp /* allocate stack space */
1320 stq ra,0(sp) /* save return address */
1321 jsr ra,new_nullpointerexception
1327 mov ra,xpc /* faulting address is return adress */
1328 br asm_handle_nat_exception
1335 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1337 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1338 jsr ra,new_exception_int /* a1 already contains the index */
1342 ldq ra,0(sp) /* restore return address */
1343 lda sp,24(sp) /* free stack space */
1344 mov ra,xpc /* faulting address is return adress */
1345 br asm_handle_nat_exception
1349 ldq xptr,string_java_lang_ArrayStoreException
1350 jmp zero,asm_throw_and_handle_nat_exception
1352 subq sp,8,sp /* allocate stack space */
1353 stq ra,0(sp) /* save return address */
1354 jsr ra,new_arraystoreexception
1360 mov ra,xpc /* faulting address is return adress */
1361 br asm_handle_nat_exception
1363 .end asm_builtin_aastore
1366 /******************* function asm_initialize_thread_stack **********************
1368 * initialized a thread stack *
1370 *******************************************************************************/
1372 .ent asm_initialize_thread_stack
1374 asm_initialize_thread_stack:
1395 .end asm_initialize_thread_stack
1398 /******************* function asm_perform_threadswitch *************************
1400 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1402 * performs a threadswitch *
1404 *******************************************************************************/
1406 .ent asm_perform_threadswitch
1408 asm_perform_threadswitch:
1449 .end asm_perform_threadswitch
1452 /********************* function asm_switchstackandcall *************************
1454 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1457 * Switches to a new stack, calls a function and switches back. *
1458 * a0 new stack pointer *
1459 * a1 function pointer *
1460 * a2 pointer to variable where stack top should be stored *
1461 * a3 pointer to user data, is passed to the function *
1463 *******************************************************************************/
1466 .ent asm_switchstackandcall
1468 asm_switchstackandcall:
1469 lda a0,-2*8(a0) /* allocate new stack */
1470 stq ra,0(a0) /* save return address on new stack */
1471 stq sp,1*8(a0) /* save old stack pointer on new stack */
1472 stq sp,0(a2) /* save old stack pointer to variable */
1473 mov a0,sp /* switch to new stack */
1475 mov a1,pv /* load function pointer */
1476 mov a3,a0 /* pass pointer */
1477 jmp ra,(pv) /* and call function */
1479 ldq ra,0(sp) /* load return address */
1480 ldq sp,1*8(sp) /* switch to old stack */
1482 jmp zero,(ra) /* return */
1484 .end asm_switchstackandcall
1486 .ent asm_getclassvalues_atomic
1488 asm_getclassvalues_atomic:
1491 ldl t0,offbaseval(a0)
1492 ldl t1,offdiffval(a0)
1493 ldl t2,offbaseval(a1)
1495 stl t0,offcast_super_baseval(a2)
1496 stl t1,offcast_super_diffval(a2)
1497 stl t2,offcast_sub_baseval(a2)
1500 .end asm_getclassvalues_atomic
1504 asm_criticalsections:
1505 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1508 .quad _crit_restart1
1511 .quad _crit_restart2
1516 .ent asm_prepare_native_stackinfo
1517 asm_prepare_native_stackinfo:
1520 jsr ra,builtin_asm_get_stackframeinfo
1528 .end asm_prepare_native_stackinfo
1530 .ent asm_remove_native_stackinfo
1531 asm_remove_native_stackinfo:
1537 .end asm_remove_native_stackinfo
1540 * These are local overrides for various environment variables in Emacs.
1541 * Please do not remove this and leave it at the end of the file, where
1542 * Emacs will automagically detect them.
1543 * ---------------------------------------------------------------------
1546 * indent-tabs-mode: t