1 /* vm/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 Changes: Joseph Wenninger
33 $Id: asmpart.S 1695 2004-12-06 12:31:42Z twisti $
39 #include "vm/jit/alpha/offsets.h"
40 #include "vm/jit/alpha/asmoffsets.h"
108 /********************* exported functions and variables ***********************/
110 .globl has_no_x_instr_set
111 .globl asm_calljavafunction
112 .globl asm_calljavafunction2
113 .globl asm_calljavafunction2double
114 .globl asm_calljavafunction2long
115 .globl asm_call_jit_compiler
116 .globl asm_throw_and_handle_exception
117 .globl asm_throw_and_handle_nat_exception
118 .globl asm_throw_and_handle_arithmetic_exception
119 .globl asm_throw_and_handle_arrayindexoutofbounds_exception
120 .globl asm_handle_exception
121 .globl asm_handle_nat_exception
122 .globl asm_check_clinit
123 .globl asm_builtin_checkcast
124 .globl asm_builtin_checkarraycast
125 .globl asm_builtin_aastore
126 .globl asm_builtin_monitorenter
127 .globl asm_builtin_monitorexit
128 .globl asm_builtin_idiv
129 .globl asm_builtin_irem
130 .globl asm_builtin_ldiv
131 .globl asm_builtin_lrem
132 .globl asm_perform_threadswitch
133 .globl asm_initialize_thread_stack
134 .globl asm_switchstackandcall
135 .globl asm_builtin_trace
136 .globl asm_builtin_exittrace
137 .globl asm_criticalsections
138 .globl asm_getclassvalues_atomic
139 .globl asm_prepare_native_stackinfo
140 .globl asm_remove_native_stackinfo
141 .globl asm_refillin_and_handle_exception
143 /*************************** imported functions *******************************/
146 .globl builtin_monitorexit
147 .globl builtin_throw_exception
148 .globl builtin_trace_exception
149 .globl class_java_lang_Object
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
250 .ascii "calljavafunction2\0\0"
253 .quad 0 /* catch type all */
254 .quad calljava_xhandler2 /* handler pc */
255 .quad calljava_xhandler2 /* end pc */
256 .quad asm_calljavafunction2 /* start pc */
257 .long 1 /* extable size */
258 .long 0 /* PADDING */
259 .quad 0 /* line number table start */
260 .quad 0 /* line number table size */
261 .long 0 /* PADDING */
262 .long 0 /* fltsave */
263 .long 1 /* intsave */
266 .long 40 /* frame size */
267 .quad 0 /* method pointer (pointer to name) */
269 asm_calljavafunction2:
270 asm_calljavafunction2double:
271 asm_calljavafunction2long:
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 *******************************************************************************/
376 .ent asm_call_jit_compiler
377 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 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
436 sra t8,48,t8 /* isolate offset */
438 addq t8,$28,t8 /* compute update address via method pointer*/
439 stq v0,0(t8) /* save new method address there */
441 call_pal PAL_imb /* synchronise instruction cache */
443 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 .end asm_call_jit_compiler
451 /**************** function asm_refillin_and_handle_exception *******************
453 * This function handles an exception. It does not use the usual calling *
454 * conventions. The exception is passed in REG_ITMP1 and the *
455 * pc from the exception raising position is passed in REG_ITMP2. *
456 * a0 contains the PV of the function causing the problem *
458 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
460 *******************************************************************************/
461 .ent asm_refillin_and_handle_exception
462 asm_refillin_and_handle_exception:
464 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
466 sra t0,48,t0 /* isolate offset */
467 addq t0,ra,pv /* compute update address */
468 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
469 srl t0,16,t0 /* isolate instruction code */
470 lda t0,-0x177b(t0) /* test for LDAH */
471 bne t0, asm_refillin_and_handle_exception_cont
472 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
473 sll t0,16,t0 /* compute high offset */
474 addl t0,0,t0 /* sign extend high offset */
475 addq t0,pv,pv /* compute update address */
477 asm_refillin_and_handle_exception_cont:
480 lda sp,-6*8(sp) /* prepare stackframe*/
481 stq pv,5*8(sp) /* store pv of caller */
482 stq xptr,4*8(sp) /*exception ptr*/
483 stq xpc,3*8(sp) /*address of failure*/
484 stq t0,2*8(sp) /*begin of java stack frame*/
485 stq pv,1*8(sp) /* store pv of caller */
486 stq zero,0*8(sp) /*builtin (invisible) function */
487 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
490 ldq a2,utf_fillInStackTrace_desc
491 ldq a1,utf_fillInStackTrace_name
493 ldq t1,offobjvftbl(t0)
495 jsr ra,class_resolvemethod
497 /* now we have the method */
502 jsr ra,asm_calljavafunction
506 jsr ra,asm_remove_native_stackinfo
515 br asm_handle_exception
517 .end asm_refillin_and_handle_exception
519 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
521 * This function handles an exception. It does not use the usual calling *
522 * conventions. The integer parameter is passed in REG_ITMP1 and the *
523 * pc from the exception raising position is passed in REG_ITMP2. *
525 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
527 *******************************************************************************/
529 .ent asm_throw_and_handle_arrayindexoutofbounds_exception
531 asm_throw_and_handle_arrayindexoutofbounds_exception:
534 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
536 sra t0,48,t0 /* isolate offset */
537 addq t0,ra,pv /* compute update address */
538 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
539 srl t0,16,t0 /* isolate instruction code */
540 lda t0,-0x177b(t0) /* test for LDAH */
541 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
542 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
543 sll t0,16,t0 /* compute high offset */
544 addl t0,0,t0 /* sign extend high offset */
545 addq t0,pv,pv /* compute update address */
547 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
549 lda sp,-6*8(sp) /*prepare stackframe*/
550 stq pv,5*8(sp) /*pv of failure*/
551 stq itmp1,4*8(sp) /*int parameter of the exception*/
552 stq xpc,3*8(sp) /*address of failure */
553 stq t0,2*8(sp) /*store begin of java stack frame*/
554 stq pv,1*8(sp) /*store pv of caller in structure*/
555 stq zero,0*8(sp) /*builtin (invisible function)*/
557 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
560 ldq a0,6*8(sp) /*int of exception*/
561 jsr ra,new_arrayindexoutofboundsexception
564 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
566 jsr ra,asm_remove_native_stackinfo
572 br asm_handle_exception
574 .end asm_throw_and_handle_arrayindexoutofbounds_exception
577 /* asm_throw_and_handle_arithmetic_exception ***********************************
581 *******************************************************************************/
583 .ent asm_throw_and_handle_arithmetic_exception
585 asm_throw_and_handle_arithmetic_exception:
586 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
588 sra t0,48,t0 /* isolate offset */
589 addq t0,ra,pv /* compute update address */
590 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
591 srl t0,16,t0 /* isolate instruction code */
592 lda t0,-0x177b(t0) /* test for LDAH */
593 bne t0,asm_throw_and_handle_arithmetic_exception_cont
594 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
595 sll t0,16,t0 /* compute high offset */
596 addl t0,0,t0 /* sign extend high offset */
597 addq t0,pv,pv /* compute update address */
599 asm_throw_and_handle_arithmetic_exception_cont:
601 lda sp,-6*8(sp) /*prepare stackframe*/
602 stq pv,5*8(sp) /*pv of failure*/
603 stq itmp1,4*8(sp) /*exception string of the exception*/
604 stq xpc,3*8(sp) /*address of failure */
605 stq t0,2*8(sp) /*store begin of java stack frame*/
606 stq pv,1*8(sp) /*store pv of caller in structure*/
607 stq zero,0*8(sp) /*builtin (invisible function)*/
608 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
611 jsr ra,new_arithmeticexception
613 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
615 jsr ra,asm_remove_native_stackinfo
621 br asm_handle_exception
623 .end asm_throw_and_handle_arithmetic_exception
626 /**************** function asm_throw_and_handle_exception **********************
628 * This function handles an exception. It does not use the usual calling *
629 * conventions. The exception class name is passed in REG_ITMP1 and the *
630 * pc from the exception raising position is passed in REG_ITMP2. *
632 * void asm_handle_exception (exceptionclass, exceptionpc); *
634 *******************************************************************************/
635 .ent asm_throw_and_handle_nat_exception
636 asm_throw_and_handle_nat_exception:
638 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
640 sra t0,48,t0 /* isolate offset */
641 addq t0,ra,pv /* compute update address */
642 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
643 srl t0,16,t0 /* isolate instruction code */
644 lda t0,-0x177b(t0) /* test for LDAH */
645 bne t0,asm_throw_and_handle_exception
646 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
647 sll t0,16,t0 /* compute high offset */
648 addl t0,0,t0 /* sign extend high offset */
649 addq t0,pv,pv /* compute update address */
651 .aent asm_throw_and_handle_exception
652 asm_throw_and_handle_exception:
654 lda sp,-6*8(sp) /*prepare stackframe*/
655 stq pv,5*8(sp) /*pv of failure*/
656 stq itmp1,4*8(sp) /*classname of the exception*/
657 stq xpc,3*8(sp) /*address of failure */
658 stq t0,2*8(sp) /*store begin of java stack frame*/
659 stq pv,1*8(sp) /*store pv of caller in structure*/
660 stq zero,0*8(sp) /*builtin (invisible function)*/
661 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
664 ldq a0,6*8(sp) /*classname of exception*/
668 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
670 jsr ra,asm_remove_native_stackinfo
676 br asm_handle_exception
677 .end asm_throw_and_handle_nat_exception
680 /********************* function asm_handle_exception ***************************
682 * This function handles an exception. It does not use the usual calling *
683 * conventions. The exception pointer is passed in REG_ITMP1 and the *
684 * pc from the exception raising position is passed in REG_ITMP2. It searches *
685 * the local exception table for a handler. If no one is found, it unwinds *
686 * stacks and continues searching the callers. *
688 * void asm_handle_exception (exceptionptr, exceptionpc); *
690 *******************************************************************************/
692 .ent asm_handle_nat_exception
693 asm_handle_nat_exception:
694 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
696 sra t0,48,t0 /* isolate offset */
697 addq t0,ra,pv /* compute update address */
698 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
699 srl t0,16,t0 /* isolate instruction code */
700 lda t0,-0x177b(t0) /* test for LDAH */
701 bne t0,asm_handle_exception
702 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
703 sll t0,16,t0 /* compute high offset */
704 addl t0,0,t0 /* sign extend high offset */
705 addq t0,pv,pv /* compute update address */
707 .aent asm_handle_exception
708 asm_handle_exception:
709 lda sp,-18*8(sp) /* allocate stack */
710 stq t0,0*8(sp) /* save possible used registers */
711 stq t1,1*8(sp) /* also registers used by trace_exception */
729 lda t3,1(zero) /* set no unwind flag */
731 lda sp,-5*8(sp) /* allocate stack */
732 stq xptr,0*8(sp) /* save used register */
739 ldq a1,MethodPointer(pv)
744 br ra,ex_trace /* set ra for gp loading */
746 ldgp gp,0(ra) /* load gp */
747 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
749 ldq xptr,0*8(sp) /* restore used register */
754 lda sp,5*8(sp) /* deallocate stack */
756 ldl t0,ExTableSize(pv) /* t0 = exception table size */
757 beq t0,empty_table /* if empty table skip */
759 lda t1,ExTableStart(pv) /* t1 = start of exception table */
762 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
763 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
764 beq t2,ex_table_cont /* if (false) continue */
765 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
766 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
767 beq t2,ex_table_cont /* if (false) continue */
768 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
769 beq a1,ex_handle_it /* NULL catches everything */
771 ldl itmp3,offclassloaded(a1)
772 bne itmp3,L_class_loaded
774 subq sp,8*8,sp /* allocate stack */
775 stq t0,0*8(sp) /* save used register */
786 br ra,L_class_load_ra /* set ra for gp loading */
788 ldgp gp,0(ra) /* load gp */
789 jsr ra,class_load /* class_load(exceptionclass) */
791 ldq t0,0*8(sp) /* restore used register */
799 addq sp,8*8,sp /* deallocate stack */
802 ldl itmp3,offclasslinked(a1)
803 subq sp,8*8,sp /* allocate stack */
805 bne itmp3,L_class_linked
807 stq t0,0*8(sp) /* save used register */
817 br ra,L_class_link_ra /* set ra for gp loading */
819 ldgp gp,0(ra) /* load gp */
820 jsr ra,class_link /* class_load(exceptionclass) */
822 ldq t0,0*8(sp) /* restore used register */
834 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
835 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
836 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
837 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
838 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
840 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
841 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
842 addq sp,8*8,sp /* deallocate stack */
843 beq v0,ex_table_cont /* if (false) continue */
846 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
848 beq t3,ex_jump /* if (!(no stack unwinding) skip */
850 ldq t0,0*8(sp) /* restore possible used registers */
851 ldq t1,1*8(sp) /* also registers used by trace_exception */
868 lda sp,18*8(sp) /* deallocate stack */
871 jmp zero,(xpc) /* jump to the handler */
874 lda t1,ExEntrySize(t1) /* next exception table entry */
875 subl t0,1,t0 /* decrement entry counter */
876 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
879 beq t3,ex_already_cleared /* if here the first time, then */
880 lda sp,18*8(sp) /* deallocate stack and */
881 clr t3 /* clear the no unwind flag */
883 ldl t0,IsSync(pv) /* t0 = SyncOffset */
884 beq t0,no_monitor_exit /* if zero no monitorexit */
885 addq sp,t0,t0 /* add stackptr to Offset */
886 ldq a0,-8(t0) /* load monitorexit pointer */
888 lda sp,-7*8(sp) /* allocate stack */
889 stq t0,0*8(sp) /* save used register */
897 br ra,ex_mon_load /* set ra for gp loading */
899 ldgp gp,0(ra) /* load gp */
900 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
902 ldq t0,0*8(sp) /* restore used register */
909 lda sp,7*8(sp) /* deallocate stack */
912 ldl t0,FrameSize(pv) /* t0 = frame size */
913 addq sp,t0,sp /* unwind stack */
914 mov sp,t0 /* t0 = pointer to save area */
915 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
916 bne t1,ex_no_restore /* if (leaf) skip */
917 ldq ra,-8(t0) /* restore ra */
918 lda t0,-8(t0) /* t0-- */
920 mov ra,xpc /* the new xpc is ra */
921 ldl t1,IntSave(pv) /* t1 = saved int register count */
922 br t2,ex_int1 /* t2 = current pc */
924 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
925 negl t1,t1 /* negate register count */
926 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
927 jmp zero,(t2) /* jump to save position */
936 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
938 ldl t1,FltSave(pv) /* t1 = saved flt register count */
939 br t2,ex_flt1 /* t2 = current pc */
941 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
942 negl t1,t1 /* negate register count */
943 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
944 jmp zero,(t2) /* jump to save position */
954 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
956 sra t0,48,t0 /* isolate offset */
957 addq t0,ra,pv /* compute update address */
958 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
959 srl t0,16,t0 /* isolate instruction code */
960 lda t0,-0x177b(t0) /* test for LDAH */
962 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
963 sll t0,16,t0 /* compute high offset */
964 addl t0,0,t0 /* sign extend high offset */
965 addq t0,pv,pv /* compute update address */
968 .end asm_handle_nat_exception
971 /* asm_check_clinit ************************************************************
977 itmp1: pointer to class
981 0 mcode ; machine code to patch back in
983 *******************************************************************************/
985 .ent asm_check_clinit
988 ldgp gp,0(itmp2) /* function is called via `jsr ra,itmp1' */
992 stq ra,0*8(sp) /* save return address */
993 stq pv,1*8(sp) /* save pv of calling java function */
994 stq a0,2*8(sp) /* save argument registers for leaf */
995 stq a1,3*8(sp) /* functions and native stub */
1001 ldl itmp2,offclassinit(itmp1)
1002 bne itmp2,L_is_initialized
1004 mov itmp1,a0 /* move class pointer to a0 */
1008 beq v0,L_initializererror
1011 ldq ra,0*8(sp) /* get return address */
1012 subq ra,1*4,ra /* go back 1 instruction */
1013 ldl itmp1,8*8(sp) /* load machine code from stack */
1014 stl itmp1,0(ra) /* store the machine code */
1016 call_pal PAL_imb /* synchronise instruction cache */
1018 ldq ra,0*8(sp) /* restore return address */
1019 ldq pv,1*8(sp) /* restore pv of calling java function */
1020 ldq a0,2*8(sp) /* restore argument registers */
1027 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1029 subq ra,1*4,ra /* go back 1 instruction */
1030 jmp zero,(ra) /* jump to the new code */
1033 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1034 jsr ra,builtin_asm_get_exceptionptrptr
1036 lda v0,_exceptionptr
1038 ldq xptr,0(v0) /* get the exception pointer */
1039 stq zero,0(v0) /* clear the exception pointer */
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) */
1053 br asm_handle_exception /* we have the pv of the calling java func. */
1055 .end asm_check_clinit
1058 /********************* function asm_builtin_monitorenter ***********************
1060 * Does null check and calls monitorenter or throws an exception *
1062 *******************************************************************************/
1064 .ent asm_builtin_monitorenter
1066 asm_builtin_monitorenter:
1068 lda pv,builtin_monitorenter
1069 beq a0,nb_monitorenter /* if (null) throw exception */
1070 jmp zero,(pv) /* else call builtin_monitorenter */
1074 ldq xptr,string_java_lang_NullPointerException
1075 jmp zero,asm_throw_and_handle_nat_exception
1079 jsr ra,new_nullpointerexception
1085 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1086 br asm_handle_nat_exception
1088 .end asm_builtin_monitorenter
1091 /********************* function asm_builtin_monitorexit ************************
1093 * Does null check and calls monitorexit or throws an exception *
1095 *******************************************************************************/
1097 .ent asm_builtin_monitorexit
1099 asm_builtin_monitorexit:
1101 lda pv,builtin_monitorexit
1102 beq a0,nb_monitorexit /* if (null) throw exception */
1103 jmp zero,(pv) /* else call builtin_monitorexit */
1107 ldq xptr,string_java_lang_NullPointerException
1108 jmp zero,asm_throw_and_handle_nat_exception
1112 jsr ra,new_nullpointerexception
1118 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1119 br asm_handle_nat_exception
1121 .end asm_builtin_monitorexit
1124 /************************ function asm_builtin_idiv ****************************
1126 * Does null check and calls idiv or throws an exception *
1128 *******************************************************************************/
1130 .ent asm_builtin_idiv
1135 beq a1,nb_idiv /* if (null) throw exception */
1136 jmp zero,(pv) /* else call builtin_idiv */
1139 ldq xptr,string_java_lang_ArithmeticException_message
1140 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1141 br asm_throw_and_handle_arithmetic_exception
1143 .end asm_builtin_idiv
1146 /************************ function asm_builtin_ldiv ****************************
1148 * Does null check and calls ldiv or throws an exception *
1150 *******************************************************************************/
1152 .ent asm_builtin_ldiv
1157 beq a1,nb_ldiv /* if (null) throw exception */
1158 jmp zero,(pv) /* else call builtin_ldiv */
1161 ldq xptr,string_java_lang_ArithmeticException_message
1162 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1163 br asm_throw_and_handle_arithmetic_exception
1165 .end asm_builtin_ldiv
1168 /************************ function asm_builtin_irem ****************************
1170 * Does null check and calls irem or throws an exception *
1172 *******************************************************************************/
1174 .ent asm_builtin_irem
1179 beq a1,nb_irem /* if (null) throw exception */
1180 jmp zero,(pv) /* else call builtin_irem */
1183 ldq xptr,string_java_lang_ArithmeticException_message
1184 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1185 br asm_throw_and_handle_arithmetic_exception
1187 .end asm_builtin_irem
1190 /************************ function asm_builtin_lrem ****************************
1192 * Does null check and calls lrem or throws an exception *
1194 *******************************************************************************/
1196 .ent asm_builtin_lrem
1201 beq a1,nb_lrem /* if (null) throw exception */
1202 jmp zero,(pv) /* else call builtin_lrem */
1205 ldq xptr,string_java_lang_ArithmeticException_message
1206 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1207 br asm_throw_and_handle_arithmetic_exception
1209 .end asm_builtin_lrem
1212 /******************* function asm_builtin_checkarraycast ***********************
1214 * Does the cast check and eventually throws an exception *
1216 *******************************************************************************/
1218 .ent asm_builtin_checkarraycast
1220 asm_builtin_checkarraycast:
1222 lda sp,-16(sp) /* allocate stack space */
1223 stq ra,0(sp) /* save return address */
1224 stq a0,8(sp) /* save object pointer */
1225 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1227 beq v0,nb_carray_throw /* if (false) throw exception */
1228 ldq ra,0(sp) /* restore return address */
1229 ldq v0,8(sp) /* return object pointer */
1230 lda sp,16(sp) /* free stack space */
1237 ldq xptr,string_java_lang_ClassCastException
1238 jmp zero,asm_throw_and_handle_nat_exception
1240 ldq a0,string_java_lang_ClassCastException
1241 jsr ra,new_exception
1245 ldq ra,0(sp) /* restore return address */
1246 lda sp,16(sp) /* free stack space */
1247 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1248 br asm_handle_nat_exception
1251 .end asm_builtin_checkarraycast
1254 /******************* function asm_builtin_aastore ******************************
1256 * Does the cast check and eventually throws an exception *
1258 *******************************************************************************/
1260 .ent asm_builtin_aastore
1262 asm_builtin_aastore:
1264 beq a0,nb_aastore_null /* if null pointer throw exception */
1265 ldl t0,offarraysize(a0) /* load size */
1266 lda sp,-24(sp) /* allocate stack space */
1267 stq ra,0(sp) /* save return address */
1268 s8addq a1,a0,t1 /* add index*8 to arrayref */
1269 cmpult a1,t0,t0 /* do bound check */
1270 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1271 mov a2,a1 /* object is second argument */
1272 stq t1,8(sp) /* save store position */
1273 stq a1,16(sp) /* save object */
1274 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1276 ldq ra,0(sp) /* restore return address */
1277 ldq a0,8(sp) /* restore store position */
1278 ldq a1,16(sp) /* restore object */
1279 lda sp,24(sp) /* free stack space */
1280 beq v0,nb_aastore_throw /* if (false) throw exception */
1281 stq a1,offobjarrdata(a0) /* store objectptr in array */
1285 ldq xptr,string_java_lang_NullPointerException
1287 jmp zero,asm_throw_and_handle_nat_exception
1289 subq sp,8,sp /* allocate stack space */
1290 stq ra,0(sp) /* save return address */
1291 jsr ra,new_nullpointerexception
1297 mov ra,xpc /* faulting address is return adress */
1298 br asm_handle_nat_exception
1305 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1307 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1308 jsr ra,new_exception_int /* a1 already contains the index */
1312 ldq ra,0(sp) /* restore return address */
1313 lda sp,24(sp) /* free stack space */
1314 mov ra,xpc /* faulting address is return adress */
1315 br asm_handle_nat_exception
1319 ldq xptr,string_java_lang_ArrayStoreException
1320 jmp zero,asm_throw_and_handle_nat_exception
1322 subq sp,8,sp /* allocate stack space */
1323 stq ra,0(sp) /* save return address */
1324 jsr ra,new_arraystoreexception
1330 mov ra,xpc /* faulting address is return adress */
1331 br asm_handle_nat_exception
1333 .end asm_builtin_aastore
1336 /******************* function asm_initialize_thread_stack **********************
1338 * initialized a thread stack *
1340 *******************************************************************************/
1342 .ent asm_initialize_thread_stack
1344 asm_initialize_thread_stack:
1365 .end asm_initialize_thread_stack
1368 /******************* function asm_perform_threadswitch *************************
1370 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1372 * performs a threadswitch *
1374 *******************************************************************************/
1376 .ent asm_perform_threadswitch
1378 asm_perform_threadswitch:
1419 .end asm_perform_threadswitch
1422 /********************* function asm_switchstackandcall *************************
1424 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1427 * Switches to a new stack, calls a function and switches back. *
1428 * a0 new stack pointer *
1429 * a1 function pointer *
1430 * a2 pointer to variable where stack top should be stored *
1431 * a3 pointer to user data, is passed to the function *
1433 *******************************************************************************/
1436 .ent asm_switchstackandcall
1438 asm_switchstackandcall:
1439 lda a0,-2*8(a0) /* allocate new stack */
1440 stq ra,0(a0) /* save return address on new stack */
1441 stq sp,1*8(a0) /* save old stack pointer on new stack */
1442 stq sp,0(a2) /* save old stack pointer to variable */
1443 mov a0,sp /* switch to new stack */
1445 mov a1,pv /* load function pointer */
1446 mov a3,a0 /* pass pointer */
1447 jmp ra,(pv) /* and call function */
1449 ldq ra,0(sp) /* load return address */
1450 ldq sp,1*8(sp) /* switch to old stack */
1452 jmp zero,(ra) /* return */
1454 .end asm_switchstackandcall
1456 .ent asm_getclassvalues_atomic
1458 asm_getclassvalues_atomic:
1461 ldl t0,offbaseval(a0)
1462 ldl t1,offdiffval(a0)
1463 ldl t2,offbaseval(a1)
1465 stl t0,offcast_super_baseval(a2)
1466 stl t1,offcast_super_diffval(a2)
1467 stl t2,offcast_sub_baseval(a2)
1470 .end asm_getclassvalues_atomic
1474 asm_criticalsections:
1475 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1478 .quad _crit_restart1
1481 .quad _crit_restart2
1486 .ent asm_prepare_native_stackinfo
1487 asm_prepare_native_stackinfo:
1490 jsr ra,builtin_asm_get_stackframeinfo
1498 .end asm_prepare_native_stackinfo
1500 .ent asm_remove_native_stackinfo
1501 asm_remove_native_stackinfo:
1507 .end asm_remove_native_stackinfo
1510 * These are local overrides for various environment variables in Emacs.
1511 * Please do not remove this and leave it at the end of the file, where
1512 * Emacs will automagically detect them.
1513 * ---------------------------------------------------------------------
1516 * indent-tabs-mode: t