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 1735 2004-12-07 14:33:27Z 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
110 .globl asm_calljavafunction
111 .globl asm_calljavafunction2
112 .globl asm_calljavafunction2double
113 .globl asm_calljavafunction2long
114 .globl asm_call_jit_compiler
115 .globl asm_throw_and_handle_exception
116 .globl asm_throw_and_handle_nat_exception
117 .globl asm_throw_and_handle_arithmetic_exception
118 .globl asm_throw_and_handle_arrayindexoutofbounds_exception
119 .globl asm_handle_exception
120 .globl asm_handle_nat_exception
121 .globl asm_check_clinit
122 .globl asm_builtin_checkcast
123 .globl asm_builtin_checkarraycast
124 .globl asm_builtin_aastore
125 .globl asm_builtin_monitorenter
126 .globl asm_builtin_monitorexit
127 .globl asm_builtin_idiv
128 .globl asm_builtin_irem
129 .globl asm_builtin_ldiv
130 .globl asm_builtin_lrem
131 .globl asm_perform_threadswitch
132 .globl asm_initialize_thread_stack
133 .globl asm_switchstackandcall
134 .globl asm_builtin_trace
135 .globl asm_builtin_exittrace
136 .globl asm_criticalsections
137 .globl asm_getclassvalues_atomic
138 .globl asm_prepare_native_stackinfo
139 .globl asm_remove_native_stackinfo
140 .globl asm_refillin_and_handle_exception
142 /*************************** imported functions *******************************/
145 .globl builtin_monitorexit
146 .globl builtin_throw_exception
147 .globl builtin_trace_exception
148 .globl class_java_lang_Object
151 /*********************** function has_no_x_instr_set ***************************
153 * determines if the byte support instruction set (21164a and higher) *
156 *******************************************************************************/
158 .ent has_no_x_instr_set
161 .long 0x47e03c20 /* amask 1,v0 */
162 jmp zero,(ra) /* return */
164 .end has_no_x_instr_set
167 /********************* function asm_calljavafunction ***************************
169 * This function calls a Java-method (which possibly needs compilation) *
170 * with up to 4 address parameters. *
172 * This functions calls the JIT-compiler which eventually translates the *
173 * method into machine code. *
176 * javaobject_header *asm_calljavafunction (methodinfo *m, *
177 * void *arg1, void *arg2, void *arg3, void *arg4); *
179 *******************************************************************************/
181 .ent asm_calljavafunction
184 .ascii "calljavafunction\0\0"
187 .quad 0 /* catch type all */
188 .quad calljava_xhandler /* handler pc */
189 .quad calljava_xhandler /* end pc */
190 .quad asm_calljavafunction /* start pc */
191 .long 1 /* extable size */
192 .long 0 /* PADDING */
193 .quad 0 /* line number table start */
194 .quad 0 /* line number table size */
195 .long 0 /* PADDING */
196 .long 0 /* fltsave */
197 .long 0 /* intsave */
200 .long 32 /* frame size */
201 .quad 0 /* method pointer (pointer to name) */
203 asm_calljavafunction:
205 lda sp,-32(sp) /* allocate stack space */
206 stq gp,24(sp) /* save global pointer */
207 stq ra,0(sp) /* save return address */
209 stq a0,16(sp) /* save method pointer for compiler */
210 lda v0,16(sp) /* pass pointer to method pointer via v0*/
212 mov a1,a0 /* pass the remaining parameters */
217 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
218 stq $28,8(sp) /* store function address */
219 mov sp,$28 /* set method pointer */
221 ldq pv,8($28) /* method call as in Java */
222 jmp ra,(pv) /* call JIT compiler */
224 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
227 ldq ra,0(sp) /* restore return address */
228 ldq gp,24(sp) /* restore global pointer */
229 lda sp,32(sp) /* free stack space */
235 ldq gp,24(sp) /* restore global pointer */
237 jsr ra,builtin_throw_exception
238 ldq ra,0(sp) /* restore return address */
239 lda sp,32(sp) /* free stack space */
241 .end asm_calljavafunction
246 .ent asm_calljavafunction2
249 .ascii "calljavafunction2\0\0"
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_calljavafunction2double:
270 asm_calljavafunction2long:
272 lda sp,-40(sp) /* allocate stack space */
273 stq ra,0(sp) /* save return address */
275 stq gp,8(sp) /* save global pointer */
277 stq a0,32(sp) /* save method pointer for compiler */
278 mov a3,t0 /* pointer to arg block */
279 mov a1,s6 /* arg count */
281 ble s6,calljava_argsloaded
283 ldq a0,offjniitem(t0)
284 ldt $f16,offjniitem(t0)
285 ble s6,calljava_argsloaded
287 ldq a1,offjniitem+sizejniblock*1(t0)
288 ldt $f17,offjniitem+sizejniblock*1(t0)
289 ble s6,calljava_argsloaded
291 ldq a2,offjniitem+sizejniblock*2(t0)
292 ldt $f18,offjniitem+sizejniblock*2(t0)
293 ble s6,calljava_argsloaded
295 ldq a3,offjniitem+sizejniblock*3(t0)
296 ldt $f19,offjniitem+sizejniblock*3(t0)
297 ble s6,calljava_argsloaded
299 ldq a4,offjniitem+sizejniblock*4(t0)
300 ldt $f20,offjniitem+sizejniblock*4(t0)
301 ble s6,calljava_argsloaded
303 ldq a5,offjniitem+sizejniblock*5(t0)
304 ldt $f21,offjniitem+sizejniblock*5(t0)
307 ble s6,calljava_nocopy
313 ldq t3,offjniitem+sizejniblock*6(t0)
316 lda t0,sizejniblock(t0)
318 bne t1,calljava_copyloop
321 lda v0,32(t4) /* pass pointer to method pointer via v0*/
323 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
324 stq $28,16(t4) /* store function address */
325 lda $28,8(t4) /* set method pointer */
327 ldq pv,8($28) /* method call as in Java */
328 jmp ra,(pv) /* call JIT compiler */
330 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
334 ldq ra,0(sp) /* restore return address */
335 ldq gp,8(sp) /* restore global pointer */
337 lda sp,40(sp) /* free stack space */
344 ldq gp,8(sp) /* restore global pointer */
346 jsr ra,builtin_throw_exception
347 ldq ra,0(sp) /* restore return address */
349 lda sp,40(sp) /* free stack space */
351 .end asm_calljavafunction2
354 /****************** function asm_call_jit_compiler *****************************
356 * invokes the compiler for untranslated JavaVM methods. *
358 * Register R0 contains a pointer to the method info structure (prepared *
359 * by createcompilerstub). Using the return address in R26 and the *
360 * offset in the LDA instruction or using the value in methodptr R28 the *
361 * patching address for storing the method address can be computed: *
363 * method address was either loaded using *
364 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
365 * M_LDA (REG_PV, REG_RA, low) *
366 * M_LDAH(REG_PV, REG_RA, high) ; optional *
368 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
369 * in the static case the method pointer can be computed using the *
370 * return address and the lda function following the jmp instruction *
372 *******************************************************************************/
375 .ent asm_call_jit_compiler
376 asm_call_jit_compiler:
379 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
380 srl t8,16,t8 /* shift right register number $yy */
381 and t8,31,t8 /* isolate register number */
382 subl t8,28,t8 /* test for REG_METHODPTR */
384 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
386 sra t8,48,t8 /* isolate offset */
387 addq t8,ra,$28 /* compute update address */
388 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
389 srl t8,16,t8 /* isolate instruction code */
390 lda t8,-0x177b(t8) /* test for LDAH */
392 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
393 sll t8,16,t8 /* compute high offset */
394 addl t8,0,t8 /* sign extend high offset */
395 addq t8,$28,$28 /* compute update address */
397 lda sp,-14*8(sp) /* reserve stack space */
398 stq a0,0*8(sp) /* save all argument registers */
399 stq a1,1*8(sp) /* they could be used by method */
410 stq $28,12*8(sp) /* save method pointer */
411 stq ra,13*8(sp) /* save return address */
413 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
414 jsr ra,jit_compile /* jit compiler */
417 ldq a0,0*8(sp) /* load argument registers */
429 ldq $28,12*8(sp) /* load method pointer */
430 ldq ra,13*8(sp) /* load return address */
431 lda sp,14*8(sp) /* deallocate stack area */
433 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
435 sra t8,48,t8 /* isolate offset */
437 addq t8,$28,t8 /* compute update address via method pointer*/
438 stq v0,0(t8) /* save new method address there */
440 call_pal PAL_imb /* synchronise instruction cache */
442 mov v0,pv /* load method address into pv */
444 jmp zero,(pv) /* and call method. The method returns */
445 /* directly to the caller (ra). */
447 .end asm_call_jit_compiler
450 /**************** function asm_refillin_and_handle_exception *******************
452 * This function handles an exception. It does not use the usual calling *
453 * conventions. The exception is passed in REG_ITMP1 and the *
454 * pc from the exception raising position is passed in REG_ITMP2. *
455 * a0 contains the PV of the function causing the problem *
457 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
459 *******************************************************************************/
460 .ent asm_refillin_and_handle_exception
461 asm_refillin_and_handle_exception:
463 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
465 sra t0,48,t0 /* isolate offset */
466 addq t0,ra,pv /* compute update address */
467 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
468 srl t0,16,t0 /* isolate instruction code */
469 lda t0,-0x177b(t0) /* test for LDAH */
470 bne t0, asm_refillin_and_handle_exception_cont
471 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
472 sll t0,16,t0 /* compute high offset */
473 addl t0,0,t0 /* sign extend high offset */
474 addq t0,pv,pv /* compute update address */
476 asm_refillin_and_handle_exception_cont:
479 lda sp,-6*8(sp) /* prepare stackframe*/
480 stq pv,5*8(sp) /* store pv of caller */
481 stq xptr,4*8(sp) /*exception ptr*/
482 stq xpc,3*8(sp) /*address of failure*/
483 stq t0,2*8(sp) /*begin of java stack frame*/
484 stq pv,1*8(sp) /* store pv of caller */
485 stq zero,0*8(sp) /*builtin (invisible) function */
486 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
489 ldq a2,utf_fillInStackTrace_desc
490 ldq a1,utf_fillInStackTrace_name
492 ldq t1,offobjvftbl(t0)
494 jsr ra,class_resolvemethod
496 /* now we have the method */
501 jsr ra,asm_calljavafunction
505 jsr ra,asm_remove_native_stackinfo
514 br asm_handle_exception
516 .end asm_refillin_and_handle_exception
518 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
520 * This function handles an exception. It does not use the usual calling *
521 * conventions. The integer parameter is passed in REG_ITMP1 and the *
522 * pc from the exception raising position is passed in REG_ITMP2. *
524 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
526 *******************************************************************************/
528 .ent asm_throw_and_handle_arrayindexoutofbounds_exception
530 asm_throw_and_handle_arrayindexoutofbounds_exception:
533 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
535 sra t0,48,t0 /* isolate offset */
536 addq t0,ra,pv /* compute update address */
537 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
538 srl t0,16,t0 /* isolate instruction code */
539 lda t0,-0x177b(t0) /* test for LDAH */
540 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
541 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
542 sll t0,16,t0 /* compute high offset */
543 addl t0,0,t0 /* sign extend high offset */
544 addq t0,pv,pv /* compute update address */
546 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
548 lda sp,-6*8(sp) /*prepare stackframe*/
549 stq pv,5*8(sp) /*pv of failure*/
550 stq itmp1,4*8(sp) /*int parameter of the exception*/
551 stq xpc,3*8(sp) /*address of failure */
552 stq t0,2*8(sp) /*store begin of java stack frame*/
553 stq pv,1*8(sp) /*store pv of caller in structure*/
554 stq zero,0*8(sp) /*builtin (invisible function)*/
556 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
559 ldq a0,6*8(sp) /*int of exception*/
560 jsr ra,new_arrayindexoutofboundsexception
563 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
565 jsr ra,asm_remove_native_stackinfo
571 br asm_handle_exception
573 .end asm_throw_and_handle_arrayindexoutofbounds_exception
576 /* asm_throw_and_handle_arithmetic_exception ***********************************
580 *******************************************************************************/
582 .ent asm_throw_and_handle_arithmetic_exception
584 asm_throw_and_handle_arithmetic_exception:
585 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
587 sra t0,48,t0 /* isolate offset */
588 addq t0,ra,pv /* compute update address */
589 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
590 srl t0,16,t0 /* isolate instruction code */
591 lda t0,-0x177b(t0) /* test for LDAH */
592 bne t0,asm_throw_and_handle_arithmetic_exception_cont
593 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
594 sll t0,16,t0 /* compute high offset */
595 addl t0,0,t0 /* sign extend high offset */
596 addq t0,pv,pv /* compute update address */
598 asm_throw_and_handle_arithmetic_exception_cont:
600 lda sp,-6*8(sp) /*prepare stackframe*/
601 stq pv,5*8(sp) /*pv of failure*/
602 stq itmp1,4*8(sp) /*exception string of the exception*/
603 stq xpc,3*8(sp) /*address of failure */
604 stq t0,2*8(sp) /*store begin of java stack frame*/
605 stq pv,1*8(sp) /*store pv of caller in structure*/
606 stq zero,0*8(sp) /*builtin (invisible function)*/
607 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
610 jsr ra,new_arithmeticexception
612 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
614 jsr ra,asm_remove_native_stackinfo
620 br asm_handle_exception
622 .end asm_throw_and_handle_arithmetic_exception
625 /**************** function asm_throw_and_handle_exception **********************
627 * This function handles an exception. It does not use the usual calling *
628 * conventions. The exception class name is passed in REG_ITMP1 and the *
629 * pc from the exception raising position is passed in REG_ITMP2. *
631 * void asm_handle_exception (exceptionclass, exceptionpc); *
633 *******************************************************************************/
634 .ent asm_throw_and_handle_nat_exception
635 asm_throw_and_handle_nat_exception:
637 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
639 sra t0,48,t0 /* isolate offset */
640 addq t0,ra,pv /* compute update address */
641 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
642 srl t0,16,t0 /* isolate instruction code */
643 lda t0,-0x177b(t0) /* test for LDAH */
644 bne t0,asm_throw_and_handle_exception
645 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
646 sll t0,16,t0 /* compute high offset */
647 addl t0,0,t0 /* sign extend high offset */
648 addq t0,pv,pv /* compute update address */
650 .aent asm_throw_and_handle_exception
651 asm_throw_and_handle_exception:
653 lda sp,-6*8(sp) /*prepare stackframe*/
654 stq pv,5*8(sp) /*pv of failure*/
655 stq itmp1,4*8(sp) /*classname of the exception*/
656 stq xpc,3*8(sp) /*address of failure */
657 stq t0,2*8(sp) /*store begin of java stack frame*/
658 stq pv,1*8(sp) /*store pv of caller in structure*/
659 stq zero,0*8(sp) /*builtin (invisible function)*/
660 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
663 ldq a0,6*8(sp) /*classname of exception*/
667 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
669 jsr ra,asm_remove_native_stackinfo
675 br asm_handle_exception
676 .end asm_throw_and_handle_nat_exception
679 /********************* function asm_handle_exception ***************************
681 * This function handles an exception. It does not use the usual calling *
682 * conventions. The exception pointer is passed in REG_ITMP1 and the *
683 * pc from the exception raising position is passed in REG_ITMP2. It searches *
684 * the local exception table for a handler. If no one is found, it unwinds *
685 * stacks and continues searching the callers. *
687 * void asm_handle_exception (exceptionptr, exceptionpc); *
689 *******************************************************************************/
691 .ent asm_handle_nat_exception
692 asm_handle_nat_exception:
693 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
695 sra t0,48,t0 /* isolate offset */
696 addq t0,ra,pv /* compute update address */
697 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
698 srl t0,16,t0 /* isolate instruction code */
699 lda t0,-0x177b(t0) /* test for LDAH */
700 bne t0,asm_handle_exception
701 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
702 sll t0,16,t0 /* compute high offset */
703 addl t0,0,t0 /* sign extend high offset */
704 addq t0,pv,pv /* compute update address */
706 .aent asm_handle_exception
707 asm_handle_exception:
708 lda sp,-18*8(sp) /* allocate stack */
709 stq t0,0*8(sp) /* save possible used registers */
710 stq t1,1*8(sp) /* also registers used by trace_exception */
728 lda t3,1(zero) /* set no unwind flag */
730 lda sp,-5*8(sp) /* allocate stack */
731 stq xptr,0*8(sp) /* save used register */
738 ldq a1,MethodPointer(pv)
743 br ra,ex_trace /* set ra for gp loading */
745 ldgp gp,0(ra) /* load gp */
746 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
748 ldq xptr,0*8(sp) /* restore used register */
753 lda sp,5*8(sp) /* deallocate stack */
755 ldl t0,ExTableSize(pv) /* t0 = exception table size */
756 beq t0,empty_table /* if empty table skip */
758 lda t1,ExTableStart(pv) /* t1 = start of exception table */
761 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
762 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
763 beq t2,ex_table_cont /* if (false) continue */
764 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
765 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
766 beq t2,ex_table_cont /* if (false) continue */
767 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
768 beq a1,ex_handle_it /* NULL catches everything */
770 ldl itmp3,offclassloaded(a1)
771 bne itmp3,L_class_loaded
773 subq sp,8*8,sp /* allocate stack */
774 stq t0,0*8(sp) /* save used register */
785 br ra,L_class_load_ra /* set ra for gp loading */
787 ldgp gp,0(ra) /* load gp */
788 jsr ra,class_load /* class_load(exceptionclass) */
790 ldq t0,0*8(sp) /* restore used register */
798 addq sp,8*8,sp /* deallocate stack */
801 ldl itmp3,offclasslinked(a1)
802 subq sp,8*8,sp /* allocate stack */
804 bne itmp3,L_class_linked
806 stq t0,0*8(sp) /* save used register */
816 br ra,L_class_link_ra /* set ra for gp loading */
818 ldgp gp,0(ra) /* load gp */
819 jsr ra,class_link /* class_load(exceptionclass) */
821 ldq t0,0*8(sp) /* restore used register */
833 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
834 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
835 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
836 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
837 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
839 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
840 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
841 addq sp,8*8,sp /* deallocate stack */
842 beq v0,ex_table_cont /* if (false) continue */
845 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
847 beq t3,ex_jump /* if (!(no stack unwinding) skip */
849 ldq t0,0*8(sp) /* restore possible used registers */
850 ldq t1,1*8(sp) /* also registers used by trace_exception */
867 lda sp,18*8(sp) /* deallocate stack */
870 jmp zero,(xpc) /* jump to the handler */
873 lda t1,ExEntrySize(t1) /* next exception table entry */
874 subl t0,1,t0 /* decrement entry counter */
875 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
878 beq t3,ex_already_cleared /* if here the first time, then */
879 lda sp,18*8(sp) /* deallocate stack and */
880 clr t3 /* clear the no unwind flag */
882 ldl t0,IsSync(pv) /* t0 = SyncOffset */
883 beq t0,no_monitor_exit /* if zero no monitorexit */
884 addq sp,t0,t0 /* add stackptr to Offset */
885 ldq a0,-8(t0) /* load monitorexit pointer */
887 lda sp,-7*8(sp) /* allocate stack */
888 stq t0,0*8(sp) /* save used register */
896 br ra,ex_mon_load /* set ra for gp loading */
898 ldgp gp,0(ra) /* load gp */
899 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
901 ldq t0,0*8(sp) /* restore used register */
908 lda sp,7*8(sp) /* deallocate stack */
911 ldl t0,FrameSize(pv) /* t0 = frame size */
912 addq sp,t0,sp /* unwind stack */
913 mov sp,t0 /* t0 = pointer to save area */
914 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
915 bne t1,ex_no_restore /* if (leaf) skip */
916 ldq ra,-8(t0) /* restore ra */
917 lda t0,-8(t0) /* t0-- */
919 mov ra,xpc /* the new xpc is ra */
920 ldl t1,IntSave(pv) /* t1 = saved int register count */
921 br t2,ex_int1 /* t2 = current pc */
923 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
924 negl t1,t1 /* negate register count */
925 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
926 jmp zero,(t2) /* jump to save position */
935 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
937 ldl t1,FltSave(pv) /* t1 = saved flt register count */
938 br t2,ex_flt1 /* t2 = current pc */
940 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
941 negl t1,t1 /* negate register count */
942 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
943 jmp zero,(t2) /* jump to save position */
953 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
955 sra t0,48,t0 /* isolate offset */
956 addq t0,ra,pv /* compute update address */
957 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
958 srl t0,16,t0 /* isolate instruction code */
959 lda t0,-0x177b(t0) /* test for LDAH */
961 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
962 sll t0,16,t0 /* compute high offset */
963 addl t0,0,t0 /* sign extend high offset */
964 addq t0,pv,pv /* compute update address */
967 .end asm_handle_nat_exception
970 /* asm_check_clinit ************************************************************
976 itmp1: pointer to class
980 0 mcode ; machine code to patch back in
982 *******************************************************************************/
984 .ent asm_check_clinit
987 ldgp gp,0(itmp2) /* function is called via `jsr ra,itmp1' */
991 stq ra,0*8(sp) /* save return address */
992 stq pv,1*8(sp) /* save pv of calling java function */
993 stq a0,2*8(sp) /* save argument registers for leaf */
994 stq a1,3*8(sp) /* functions and native stub */
1000 ldl itmp2,offclassinit(itmp1)
1001 bne itmp2,L_is_initialized
1003 mov itmp1,a0 /* move class pointer to a0 */
1007 beq v0,L_initializererror
1010 ldq ra,0*8(sp) /* get return address */
1011 subq ra,1*4,ra /* go back 1 instruction */
1012 ldl itmp1,8*8(sp) /* load machine code from stack */
1013 stl itmp1,0(ra) /* store the machine code */
1015 call_pal PAL_imb /* synchronise instruction cache */
1017 ldq ra,0*8(sp) /* restore return address */
1018 ldq pv,1*8(sp) /* restore pv of calling java function */
1019 ldq a0,2*8(sp) /* restore argument registers */
1026 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1028 subq ra,1*4,ra /* go back 1 instruction */
1029 jmp zero,(ra) /* jump to the new code */
1032 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1033 jsr ra,builtin_asm_get_exceptionptrptr
1035 lda v0,_exceptionptr
1037 ldq xptr,0(v0) /* get the exception pointer */
1038 stq zero,0(v0) /* clear the exception pointer */
1040 ldq ra,0*8(sp) /* restore return address */
1041 ldq pv,1*8(sp) /* restore pv of calling java function */
1042 ldq a0,2*8(sp) /* restore argument registers */
1049 addq sp,(8+1)*8,sp /* remove stack frame (+1 for machine code) */
1052 br asm_handle_exception /* we have the pv of the calling java func. */
1054 .end asm_check_clinit
1057 /********************* function asm_builtin_monitorenter ***********************
1059 * Does null check and calls monitorenter or throws an exception *
1061 *******************************************************************************/
1063 .ent asm_builtin_monitorenter
1065 asm_builtin_monitorenter:
1067 lda pv,builtin_monitorenter
1068 beq a0,nb_monitorenter /* if (null) throw exception */
1069 jmp zero,(pv) /* else call builtin_monitorenter */
1073 ldq xptr,string_java_lang_NullPointerException
1074 jmp zero,asm_throw_and_handle_nat_exception
1078 jsr ra,new_nullpointerexception
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 jsr ra,new_nullpointerexception
1117 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1118 br asm_handle_nat_exception
1120 .end asm_builtin_monitorexit
1123 /************************ function asm_builtin_idiv ****************************
1125 * Does null check and calls idiv or throws an exception *
1127 *******************************************************************************/
1129 .ent asm_builtin_idiv
1134 beq a1,nb_idiv /* if (null) throw exception */
1135 jmp zero,(pv) /* else call builtin_idiv */
1138 ldq xptr,string_java_lang_ArithmeticException_message
1139 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1140 br asm_throw_and_handle_arithmetic_exception
1142 .end asm_builtin_idiv
1145 /************************ function asm_builtin_ldiv ****************************
1147 * Does null check and calls ldiv or throws an exception *
1149 *******************************************************************************/
1151 .ent asm_builtin_ldiv
1156 beq a1,nb_ldiv /* if (null) throw exception */
1157 jmp zero,(pv) /* else call builtin_ldiv */
1160 ldq xptr,string_java_lang_ArithmeticException_message
1161 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1162 br asm_throw_and_handle_arithmetic_exception
1164 .end asm_builtin_ldiv
1167 /************************ function asm_builtin_irem ****************************
1169 * Does null check and calls irem or throws an exception *
1171 *******************************************************************************/
1173 .ent asm_builtin_irem
1178 beq a1,nb_irem /* if (null) throw exception */
1179 jmp zero,(pv) /* else call builtin_irem */
1182 ldq xptr,string_java_lang_ArithmeticException_message
1183 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1184 br asm_throw_and_handle_arithmetic_exception
1186 .end asm_builtin_irem
1189 /************************ function asm_builtin_lrem ****************************
1191 * Does null check and calls lrem or throws an exception *
1193 *******************************************************************************/
1195 .ent asm_builtin_lrem
1200 beq a1,nb_lrem /* if (null) throw exception */
1201 jmp zero,(pv) /* else call builtin_lrem */
1204 ldq xptr,string_java_lang_ArithmeticException_message
1205 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1206 br asm_throw_and_handle_arithmetic_exception
1208 .end asm_builtin_lrem
1211 /******************* function asm_builtin_checkarraycast ***********************
1213 * Does the cast check and eventually throws an exception *
1215 *******************************************************************************/
1217 .ent asm_builtin_checkarraycast
1219 asm_builtin_checkarraycast:
1221 lda sp,-16(sp) /* allocate stack space */
1222 stq ra,0(sp) /* save return address */
1223 stq a0,8(sp) /* save object pointer */
1224 jsr ra,builtin_checkarraycast /* builtin_checkarraycast */
1226 beq v0,nb_carray_throw /* if (false) throw exception */
1227 ldq ra,0(sp) /* restore return address */
1228 ldq v0,8(sp) /* return object pointer */
1229 lda sp,16(sp) /* free stack space */
1236 ldq xptr,string_java_lang_ClassCastException
1237 jmp zero,asm_throw_and_handle_nat_exception
1239 ldq a0,string_java_lang_ClassCastException
1240 jsr ra,new_exception
1244 ldq ra,0(sp) /* restore return address */
1245 lda sp,16(sp) /* free stack space */
1246 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1247 br asm_handle_nat_exception
1250 .end asm_builtin_checkarraycast
1253 /******************* function asm_builtin_aastore ******************************
1255 * Does the cast check and eventually throws an exception *
1257 *******************************************************************************/
1259 .ent asm_builtin_aastore
1261 asm_builtin_aastore:
1263 beq a0,nb_aastore_null /* if null pointer throw exception */
1264 ldl t0,offarraysize(a0) /* load size */
1265 lda sp,-24(sp) /* allocate stack space */
1266 stq ra,0(sp) /* save return address */
1267 s8addq a1,a0,t1 /* add index*8 to arrayref */
1268 cmpult a1,t0,t0 /* do bound check */
1269 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1270 mov a2,a1 /* object is second argument */
1271 stq t1,8(sp) /* save store position */
1272 stq a1,16(sp) /* save object */
1273 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1275 ldq ra,0(sp) /* restore return address */
1276 ldq a0,8(sp) /* restore store position */
1277 ldq a1,16(sp) /* restore object */
1278 lda sp,24(sp) /* free stack space */
1279 beq v0,nb_aastore_throw /* if (false) throw exception */
1280 stq a1,offobjarrdata(a0) /* store objectptr in array */
1284 ldq xptr,string_java_lang_NullPointerException
1286 jmp zero,asm_throw_and_handle_nat_exception
1288 subq sp,8,sp /* allocate stack space */
1289 stq ra,0(sp) /* save return address */
1290 jsr ra,new_nullpointerexception
1296 mov ra,xpc /* faulting address is return adress */
1297 br asm_handle_nat_exception
1304 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1306 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1307 jsr ra,new_exception_int /* a1 already contains the index */
1311 ldq ra,0(sp) /* restore return address */
1312 lda sp,24(sp) /* free stack space */
1313 mov ra,xpc /* faulting address is return adress */
1314 br asm_handle_nat_exception
1318 ldq xptr,string_java_lang_ArrayStoreException
1319 jmp zero,asm_throw_and_handle_nat_exception
1321 subq sp,8,sp /* allocate stack space */
1322 stq ra,0(sp) /* save return address */
1323 jsr ra,new_arraystoreexception
1329 mov ra,xpc /* faulting address is return adress */
1330 br asm_handle_nat_exception
1332 .end asm_builtin_aastore
1335 /******************* function asm_initialize_thread_stack **********************
1337 * initialized a thread stack *
1339 *******************************************************************************/
1341 .ent asm_initialize_thread_stack
1343 asm_initialize_thread_stack:
1364 .end asm_initialize_thread_stack
1367 /******************* function asm_perform_threadswitch *************************
1369 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1371 * performs a threadswitch *
1373 *******************************************************************************/
1375 .ent asm_perform_threadswitch
1377 asm_perform_threadswitch:
1418 .end asm_perform_threadswitch
1421 /********************* function asm_switchstackandcall *************************
1423 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1426 * Switches to a new stack, calls a function and switches back. *
1427 * a0 new stack pointer *
1428 * a1 function pointer *
1429 * a2 pointer to variable where stack top should be stored *
1430 * a3 pointer to user data, is passed to the function *
1432 *******************************************************************************/
1435 .ent asm_switchstackandcall
1437 asm_switchstackandcall:
1438 lda a0,-2*8(a0) /* allocate new stack */
1439 stq ra,0(a0) /* save return address on new stack */
1440 stq sp,1*8(a0) /* save old stack pointer on new stack */
1441 stq sp,0(a2) /* save old stack pointer to variable */
1442 mov a0,sp /* switch to new stack */
1444 mov a1,pv /* load function pointer */
1445 mov a3,a0 /* pass pointer */
1446 jmp ra,(pv) /* and call function */
1448 ldq ra,0(sp) /* load return address */
1449 ldq sp,1*8(sp) /* switch to old stack */
1451 jmp zero,(ra) /* return */
1453 .end asm_switchstackandcall
1455 .ent asm_getclassvalues_atomic
1457 asm_getclassvalues_atomic:
1460 ldl t0,offbaseval(a0)
1461 ldl t1,offdiffval(a0)
1462 ldl t2,offbaseval(a1)
1464 stl t0,offcast_super_baseval(a2)
1465 stl t1,offcast_super_diffval(a2)
1466 stl t2,offcast_sub_baseval(a2)
1469 .end asm_getclassvalues_atomic
1473 asm_criticalsections:
1474 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1477 .quad _crit_restart1
1480 .quad _crit_restart2
1485 .ent asm_prepare_native_stackinfo
1486 asm_prepare_native_stackinfo:
1489 jsr ra,builtin_asm_get_stackframeinfo
1497 .end asm_prepare_native_stackinfo
1499 .ent asm_remove_native_stackinfo
1500 asm_remove_native_stackinfo:
1506 .end asm_remove_native_stackinfo
1509 * These are local overrides for various environment variables in Emacs.
1510 * Please do not remove this and leave it at the end of the file, where
1511 * Emacs will automagically detect them.
1512 * ---------------------------------------------------------------------
1515 * indent-tabs-mode: t