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 1683 2004-12-05 21:33:36Z jowenn $
39 #include "vm/jit/alpha/offsets.h"
40 #include "vm/jit/alpha/asmoffsets.h"
107 /********************* exported functions and variables ***********************/
109 .globl has_no_x_instr_set
110 .globl synchronize_caches
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
530 asm_throw_and_handle_arrayindexoutofbounds_exception:
532 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
534 sra t0,48,t0 /* isolate offset */
535 addq t0,ra,pv /* compute update address */
536 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
537 srl t0,16,t0 /* isolate instruction code */
538 lda t0,-0x177b(t0) /* test for LDAH */
539 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
540 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
541 sll t0,16,t0 /* compute high offset */
542 addl t0,0,t0 /* sign extend high offset */
543 addq t0,pv,pv /* compute update address */
545 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
547 lda sp,-6*8(sp) /*prepare stackframe*/
548 stq pv,5*8(sp) /*pv of failure*/
549 stq itmp1,4*8(sp) /*int parameter of the exception*/
550 stq xpc,3*8(sp) /*address of failure */
551 stq t0,2*8(sp) /*store begin of java stack frame*/
552 stq pv,1*8(sp) /*store pv of caller in structure*/
553 stq zero,0*8(sp) /*builtin (invisible function)*/
554 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
557 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
558 ldq a1,6*8(sp) /*int of exception*/
559 jsr ra,new_exception_int
562 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
564 jsr ra,asm_remove_native_stackinfo
570 br asm_handle_exception
572 .end asm_throw_and_handle_arrayindexoutofbounds_exception
574 /**************** function asm_throw_and_handle_arithmetic_exception ***********
576 * This function handles an exception. It does not use the usual calling *
577 * conventions. The exception string is passed in REG_ITMP1 and the *
578 * pc from the exception raising position is passed in REG_ITMP2. *
580 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
582 *******************************************************************************/
584 .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 ldq a0,string_java_lang_ArithmeticException
612 ldq a1,6*8(sp) /*string of exception*/
613 jsr ra,new_exception_message
615 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
617 jsr ra,asm_remove_native_stackinfo
623 br asm_handle_exception
625 .end asm_throw_and_handle_arithmetic_exception
628 /**************** function asm_throw_and_handle_exception **********************
630 * This function handles an exception. It does not use the usual calling *
631 * conventions. The exception class name is passed in REG_ITMP1 and the *
632 * pc from the exception raising position is passed in REG_ITMP2. *
634 * void asm_handle_exception (exceptionclass, exceptionpc); *
636 *******************************************************************************/
637 .ent asm_throw_and_handle_nat_exception
638 asm_throw_and_handle_nat_exception:
640 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
642 sra t0,48,t0 /* isolate offset */
643 addq t0,ra,pv /* compute update address */
644 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
645 srl t0,16,t0 /* isolate instruction code */
646 lda t0,-0x177b(t0) /* test for LDAH */
647 bne t0,asm_throw_and_handle_exception
648 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
649 sll t0,16,t0 /* compute high offset */
650 addl t0,0,t0 /* sign extend high offset */
651 addq t0,pv,pv /* compute update address */
653 .aent asm_throw_and_handle_exception
654 asm_throw_and_handle_exception:
656 lda sp,-6*8(sp) /*prepare stackframe*/
657 stq pv,5*8(sp) /*pv of failure*/
658 stq itmp1,4*8(sp) /*classname of the exception*/
659 stq xpc,3*8(sp) /*address of failure */
660 stq t0,2*8(sp) /*store begin of java stack frame*/
661 stq pv,1*8(sp) /*store pv of caller in structure*/
662 stq zero,0*8(sp) /*builtin (invisible function)*/
663 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
666 ldq a0,6*8(sp) /*classname of exception*/
670 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
672 jsr ra,asm_remove_native_stackinfo
678 br asm_handle_exception
679 .end asm_throw_and_handle_nat_exception
682 /********************* function asm_handle_exception ***************************
684 * This function handles an exception. It does not use the usual calling *
685 * conventions. The exception pointer is passed in REG_ITMP1 and the *
686 * pc from the exception raising position is passed in REG_ITMP2. It searches *
687 * the local exception table for a handler. If no one is found, it unwinds *
688 * stacks and continues searching the callers. *
690 * void asm_handle_exception (exceptionptr, exceptionpc); *
692 *******************************************************************************/
694 .ent asm_handle_nat_exception
695 asm_handle_nat_exception:
696 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
698 sra t0,48,t0 /* isolate offset */
699 addq t0,ra,pv /* compute update address */
700 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
701 srl t0,16,t0 /* isolate instruction code */
702 lda t0,-0x177b(t0) /* test for LDAH */
703 bne t0,asm_handle_exception
704 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
705 sll t0,16,t0 /* compute high offset */
706 addl t0,0,t0 /* sign extend high offset */
707 addq t0,pv,pv /* compute update address */
709 .aent asm_handle_exception
710 asm_handle_exception:
711 lda sp,-18*8(sp) /* allocate stack */
712 stq t0,0*8(sp) /* save possible used registers */
713 stq t1,1*8(sp) /* also registers used by trace_exception */
731 lda t3,1(zero) /* set no unwind flag */
733 lda sp,-5*8(sp) /* allocate stack */
734 stq xptr,0*8(sp) /* save used register */
741 ldq a1,MethodPointer(pv)
746 br ra,ex_trace /* set ra for gp loading */
748 ldgp gp,0(ra) /* load gp */
749 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
751 ldq xptr,0*8(sp) /* restore used register */
756 lda sp,5*8(sp) /* deallocate stack */
758 ldl t0,ExTableSize(pv) /* t0 = exception table size */
759 beq t0,empty_table /* if empty table skip */
761 lda t1,ExTableStart(pv) /* t1 = start of exception table */
764 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
765 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
766 beq t2,ex_table_cont /* if (false) continue */
767 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
768 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
769 beq t2,ex_table_cont /* if (false) continue */
770 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
771 beq a1,ex_handle_it /* NULL catches everything */
773 ldl itmp3,offclassloaded(a1)
774 bne itmp3,L_class_loaded
776 subq sp,8*8,sp /* allocate stack */
777 stq t0,0*8(sp) /* save used register */
788 br ra,L_class_load_ra /* set ra for gp loading */
790 ldgp gp,0(ra) /* load gp */
791 jsr ra,class_load /* class_load(exceptionclass) */
793 ldq t0,0*8(sp) /* restore used register */
801 addq sp,8*8,sp /* deallocate stack */
804 ldl itmp3,offclasslinked(a1)
805 subq sp,8*8,sp /* allocate stack */
807 bne itmp3,L_class_linked
809 stq t0,0*8(sp) /* save used register */
819 br ra,L_class_link_ra /* set ra for gp loading */
821 ldgp gp,0(ra) /* load gp */
822 jsr ra,class_link /* class_load(exceptionclass) */
824 ldq t0,0*8(sp) /* restore used register */
836 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
837 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
838 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
839 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
840 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
842 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
843 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
844 addq sp,8*8,sp /* deallocate stack */
845 beq v0,ex_table_cont /* if (false) continue */
848 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
850 beq t3,ex_jump /* if (!(no stack unwinding) skip */
852 ldq t0,0*8(sp) /* restore possible used registers */
853 ldq t1,1*8(sp) /* also registers used by trace_exception */
870 lda sp,18*8(sp) /* deallocate stack */
873 jmp zero,(xpc) /* jump to the handler */
876 lda t1,ExEntrySize(t1) /* next exception table entry */
877 subl t0,1,t0 /* decrement entry counter */
878 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
881 beq t3,ex_already_cleared /* if here the first time, then */
882 lda sp,18*8(sp) /* deallocate stack and */
883 clr t3 /* clear the no unwind flag */
885 ldl t0,IsSync(pv) /* t0 = SyncOffset */
886 beq t0,no_monitor_exit /* if zero no monitorexit */
887 addq sp,t0,t0 /* add stackptr to Offset */
888 ldq a0,-8(t0) /* load monitorexit pointer */
890 lda sp,-7*8(sp) /* allocate stack */
891 stq t0,0*8(sp) /* save used register */
899 br ra,ex_mon_load /* set ra for gp loading */
901 ldgp gp,0(ra) /* load gp */
902 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
904 ldq t0,0*8(sp) /* restore used register */
911 lda sp,7*8(sp) /* deallocate stack */
914 ldl t0,FrameSize(pv) /* t0 = frame size */
915 addq sp,t0,sp /* unwind stack */
916 mov sp,t0 /* t0 = pointer to save area */
917 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
918 bne t1,ex_no_restore /* if (leaf) skip */
919 ldq ra,-8(t0) /* restore ra */
920 lda t0,-8(t0) /* t0-- */
922 mov ra,xpc /* the new xpc is ra */
923 ldl t1,IntSave(pv) /* t1 = saved int register count */
924 br t2,ex_int1 /* t2 = current pc */
926 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
927 negl t1,t1 /* negate register count */
928 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
929 jmp zero,(t2) /* jump to save position */
938 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
940 ldl t1,FltSave(pv) /* t1 = saved flt register count */
941 br t2,ex_flt1 /* t2 = current pc */
943 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
944 negl t1,t1 /* negate register count */
945 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
946 jmp zero,(t2) /* jump to save position */
956 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
958 sra t0,48,t0 /* isolate offset */
959 addq t0,ra,pv /* compute update address */
960 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
961 srl t0,16,t0 /* isolate instruction code */
962 lda t0,-0x177b(t0) /* test for LDAH */
964 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
965 sll t0,16,t0 /* compute high offset */
966 addl t0,0,t0 /* sign extend high offset */
967 addq t0,pv,pv /* compute update address */
970 .end asm_handle_nat_exception
973 /* asm_check_clinit ************************************************************
979 itmp1: pointer to class
983 0 mcode ; machine code to patch back in
985 *******************************************************************************/
987 .ent asm_check_clinit
990 ldgp gp,0(itmp2) /* function is called via `jsr ra,itmp1' */
992 ldl itmp2,offclassinit(itmp1)
993 bne itmp2,L_is_initialized
997 stq ra,0*8(sp) /* save return address */
998 stq pv,1*8(sp) /* save pv of calling java function */
999 stq a0,2*8(sp) /* save argument registers for leaf */
1000 stq a1,3*8(sp) /* functions and native stub */
1006 mov itmp1,a0 /* move class pointer to a0 */
1010 ldq ra,0*8(sp) /* restore return address */
1011 ldq pv,1*8(sp) /* restore pv of calling java function */
1012 ldq a0,2*8(sp) /* restore argument registers */
1021 beq v0,L_initializererror
1024 subq ra,1*4,ra /* go back 1 instructions */
1025 ldl itmp1,0(sp) /* load machine code from stack */
1026 addq sp,1*8,sp /* remove stack frame */
1027 stl itmp1,0(ra) /* store the machine code */
1029 call_pal PAL_imb /* synchronise instruction cache */
1031 jmp zero,(ra) /* jump to the new code */
1034 addq sp,1*8,sp /* remove stack frame */
1036 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1039 jsr ra,builtin_asm_get_exceptionptrptr
1042 ldq xptr,0(v0) /* get the exception pointer */
1043 stq zero,0(v0) /* clear the exception pointer */
1045 lda itmp3,_exceptionptr
1051 br asm_handle_nat_exception
1053 .end asm_check_clinit
1056 /********************* function asm_builtin_monitorenter ***********************
1058 * Does null check and calls monitorenter or throws an exception *
1060 *******************************************************************************/
1062 .ent asm_builtin_monitorenter
1064 asm_builtin_monitorenter:
1066 lda pv,builtin_monitorenter
1067 beq a0,nb_monitorenter /* if (null) throw exception */
1068 jmp zero,(pv) /* else call builtin_monitorenter */
1072 ldq xptr,string_java_lang_NullPointerException
1073 jmp zero,asm_throw_and_handle_nat_exception
1077 ldq a0,string_java_lang_NullPointerException
1078 jsr ra,new_exception
1084 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1085 br asm_handle_nat_exception
1087 .end asm_builtin_monitorenter
1090 /********************* function asm_builtin_monitorexit ************************
1092 * Does null check and calls monitorexit or throws an exception *
1094 *******************************************************************************/
1096 .ent asm_builtin_monitorexit
1098 asm_builtin_monitorexit:
1100 lda pv,builtin_monitorexit
1101 beq a0,nb_monitorexit /* if (null) throw exception */
1102 jmp zero,(pv) /* else call builtin_monitorexit */
1106 ldq xptr,string_java_lang_NullPointerException
1107 jmp zero,asm_throw_and_handle_nat_exception
1111 ldq a0,string_java_lang_NullPointerException
1112 jsr ra,new_exception
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 ldq a0,string_java_lang_NullPointerException
1292 jsr ra,new_exception
1298 mov ra,xpc /* faulting address is return adress */
1299 br asm_handle_nat_exception
1306 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1308 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1309 jsr ra,new_exception_int /* a1 already contains the index */
1313 ldq ra,0(sp) /* restore return address */
1314 lda sp,24(sp) /* free stack space */
1315 mov ra,xpc /* faulting address is return adress */
1316 br asm_handle_nat_exception
1320 ldq xptr,string_java_lang_ArrayStoreException
1321 jmp zero,asm_throw_and_handle_nat_exception
1323 subq sp,8,sp /* allocate stack space */
1324 stq ra,0(sp) /* save return address */
1325 ldq a0,string_java_lang_ArrayStoreException
1326 jsr ra,new_exception
1332 mov ra,xpc /* faulting address is return adress */
1333 br asm_handle_nat_exception
1335 .end asm_builtin_aastore
1338 /******************* function asm_initialize_thread_stack **********************
1340 * initialized a thread stack *
1342 *******************************************************************************/
1344 .ent asm_initialize_thread_stack
1346 asm_initialize_thread_stack:
1367 .end asm_initialize_thread_stack
1370 /******************* function asm_perform_threadswitch *************************
1372 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1374 * performs a threadswitch *
1376 *******************************************************************************/
1378 .ent asm_perform_threadswitch
1380 asm_perform_threadswitch:
1421 .end asm_perform_threadswitch
1424 /********************* function asm_switchstackandcall *************************
1426 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1429 * Switches to a new stack, calls a function and switches back. *
1430 * a0 new stack pointer *
1431 * a1 function pointer *
1432 * a2 pointer to variable where stack top should be stored *
1433 * a3 pointer to user data, is passed to the function *
1435 *******************************************************************************/
1438 .ent asm_switchstackandcall
1440 asm_switchstackandcall:
1441 lda a0,-2*8(a0) /* allocate new stack */
1442 stq ra,0(a0) /* save return address on new stack */
1443 stq sp,1*8(a0) /* save old stack pointer on new stack */
1444 stq sp,0(a2) /* save old stack pointer to variable */
1445 mov a0,sp /* switch to new stack */
1447 mov a1,pv /* load function pointer */
1448 mov a3,a0 /* pass pointer */
1449 jmp ra,(pv) /* and call function */
1451 ldq ra,0(sp) /* load return address */
1452 ldq sp,1*8(sp) /* switch to old stack */
1454 jmp zero,(ra) /* return */
1456 .end asm_switchstackandcall
1458 .ent asm_getclassvalues_atomic
1460 asm_getclassvalues_atomic:
1463 ldl t0,offbaseval(a0)
1464 ldl t1,offdiffval(a0)
1465 ldl t2,offbaseval(a1)
1467 stl t0,offcast_super_baseval(a2)
1468 stl t1,offcast_super_diffval(a2)
1469 stl t2,offcast_sub_baseval(a2)
1472 .end asm_getclassvalues_atomic
1476 asm_criticalsections:
1477 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1480 .quad _crit_restart1
1483 .quad _crit_restart2
1488 .ent asm_prepare_native_stackinfo
1489 asm_prepare_native_stackinfo:
1492 jsr ra,builtin_asm_get_stackframeinfo
1500 .end asm_prepare_native_stackinfo
1502 .end asm_remove_native_stackinfo
1503 asm_remove_native_stackinfo:
1509 .end asm_prepare_native_stackinfo
1512 * These are local overrides for various environment variables in Emacs.
1513 * Please do not remove this and leave it at the end of the file, where
1514 * Emacs will automagically detect them.
1515 * ---------------------------------------------------------------------
1518 * indent-tabs-mode: t