1 /* src/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
33 $Id: asmpart.S 2611 2005-06-08 19:43:30Z twisti $
39 #include "vm/jit/alpha/offsets.h"
40 #include "vm/jit/alpha/asmoffsets.h"
41 #include "vm/jit/alpha/md-asm.h"
49 /********************* exported functions and variables ***********************/
51 .globl asm_sync_instruction_cache
52 .globl has_no_x_instr_set
54 .globl asm_calljavafunction
55 .globl asm_calljavafunction_int
57 .globl asm_calljavafunction2
58 .globl asm_calljavafunction2int
59 .globl asm_calljavafunction2long
60 .globl asm_calljavafunction2float
61 .globl asm_calljavafunction2double
63 .globl asm_call_jit_compiler
64 .globl asm_throw_and_handle_exception
65 .globl asm_throw_and_handle_nat_exception
66 .globl asm_throw_and_handle_arithmetic_exception
67 .globl asm_throw_and_handle_arrayindexoutofbounds_exception
68 .globl asm_handle_exception
69 .globl asm_handle_nat_exception
71 .globl asm_wrapper_patcher
73 .globl asm_builtin_arraycheckcast
74 .globl asm_builtin_aastore
76 .globl asm_builtin_idiv
77 .globl asm_builtin_irem
78 .globl asm_builtin_ldiv
79 .globl asm_builtin_lrem
81 .globl asm_perform_threadswitch
82 .globl asm_initialize_thread_stack
83 .globl asm_switchstackandcall
84 .globl asm_criticalsections
85 .globl asm_getclassvalues_atomic
86 .globl asm_prepare_native_stackinfo
87 .globl asm_remove_native_stackinfo
88 .globl asm_refillin_and_handle_exception
91 /* asm_sync_instruction_cache **************************************************
95 *******************************************************************************/
97 .ent asm_sync_instruction_cache
99 asm_sync_instruction_cache:
100 call_pal PAL_imb /* synchronize instruction cache */
103 .end asm_sync_instruction_cache
105 /*********************** function has_no_x_instr_set ***************************
107 * determines if the byte support instruction set (21164a and higher) *
110 *******************************************************************************/
112 .ent has_no_x_instr_set
115 .long 0x47e03c20 /* amask 1,v0 */
116 jmp zero,(ra) /* return */
118 .end has_no_x_instr_set
121 /********************* function asm_calljavafunction ***************************
123 * This function calls a Java-method (which possibly needs compilation) *
124 * with up to 4 address parameters. *
126 * This functions calls the JIT-compiler which eventually translates the *
127 * method into machine code. *
130 * javaobject_header *asm_calljavafunction (methodinfo *m, *
131 * void *arg1, void *arg2, void *arg3, void *arg4); *
133 *******************************************************************************/
135 .ent asm_calljavafunction
138 .ascii "calljavafunction\0\0"
141 .quad 0 /* catch type all */
142 .quad calljava_xhandler /* handler pc */
143 .quad calljava_xhandler /* end pc */
144 .quad asm_calljavafunction /* start pc */
145 .long 1 /* extable size */
146 .long 0 /* PADDING */
147 .quad 0 /* line number table start */
148 .quad 0 /* line number table size */
149 .long 0 /* PADDING */
150 .long 0 /* fltsave */
151 .long 0 /* intsave */
154 .long 32 /* frame size */
155 .quad 0 /* method pointer (pointer to name) */
157 asm_calljavafunction:
158 asm_calljavafunction_int:
160 lda sp,-32(sp) /* allocate stack space */
161 stq gp,24(sp) /* save global pointer */
162 stq ra,0(sp) /* save return address */
164 stq a0,16(sp) /* save method pointer for compiler */
165 lda v0,16(sp) /* pass pointer to method pointer via v0*/
167 mov a1,a0 /* pass the remaining parameters */
172 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
173 stq $28,8(sp) /* store function address */
174 mov sp,$28 /* set method pointer */
176 ldq pv,8($28) /* method call as in Java */
177 jmp ra,(pv) /* call JIT compiler */
179 lda pv,-64(ra) /* asm_calljavafunction-calljava_jit !!!!!*/
182 ldq ra,0(sp) /* restore return address */
183 ldq gp,24(sp) /* restore global pointer */
184 lda sp,32(sp) /* free stack space */
190 ldq gp,24(sp) /* restore global pointer */
192 jsr ra,builtin_throw_exception
193 ldq ra,0(sp) /* restore return address */
194 lda sp,32(sp) /* free stack space */
195 mov zero,v0 /* return NULL */
197 .end asm_calljavafunction
202 .ent asm_calljavafunction2
207 .quad 0 /* catch type all */
208 .quad calljava_xhandler2 /* handler pc */
209 .quad calljava_xhandler2 /* end pc */
210 .quad asm_calljavafunction2 /* start pc */
211 .long 1 /* extable size */
212 .long 0 /* PADDING */
213 .quad 0 /* line number table start */
214 .quad 0 /* line number table size */
215 .long 0 /* PADDING */
216 .long 0 /* fltsave */
217 .long 1 /* intsave */
220 .long 40 /* frame size */
221 .quad 0 /* method pointer (pointer to name) */
223 asm_calljavafunction2:
224 asm_calljavafunction2int:
225 asm_calljavafunction2long:
226 asm_calljavafunction2float:
227 asm_calljavafunction2double:
229 lda sp,-40(sp) /* allocate stack space */
230 stq ra,0(sp) /* save return address */
232 stq gp,8(sp) /* save global pointer */
234 stq a0,32(sp) /* save method pointer for compiler */
235 mov a3,t0 /* pointer to arg block */
236 mov a1,s6 /* arg count */
238 ble s6,calljava_argsloaded
240 ldq a0,offjniitem(t0)
241 ldt $f16,offjniitem(t0)
242 ble s6,calljava_argsloaded
244 ldq a1,offjniitem+sizejniblock*1(t0)
245 ldt $f17,offjniitem+sizejniblock*1(t0)
246 ble s6,calljava_argsloaded
248 ldq a2,offjniitem+sizejniblock*2(t0)
249 ldt $f18,offjniitem+sizejniblock*2(t0)
250 ble s6,calljava_argsloaded
252 ldq a3,offjniitem+sizejniblock*3(t0)
253 ldt $f19,offjniitem+sizejniblock*3(t0)
254 ble s6,calljava_argsloaded
256 ldq a4,offjniitem+sizejniblock*4(t0)
257 ldt $f20,offjniitem+sizejniblock*4(t0)
258 ble s6,calljava_argsloaded
260 ldq a5,offjniitem+sizejniblock*5(t0)
261 ldt $f21,offjniitem+sizejniblock*5(t0)
264 ble s6,calljava_nocopy
270 ldq t3,offjniitem+sizejniblock*6(t0)
273 lda t0,sizejniblock(t0)
275 bne t1,calljava_copyloop
278 lda v0,32(t4) /* pass pointer to method pointer via v0*/
280 lda $28,asm_call_jit_compiler /* fake virtual function call (2 instr) */
281 stq $28,16(t4) /* store function address */
282 lda $28,8(t4) /* set method pointer */
284 ldq pv,8($28) /* method call as in Java */
285 jmp ra,(pv) /* call JIT compiler */
287 lda pv,-200(ra) /* asm_calljavafunction-calljava_jit !!!*/
291 ldq ra,0(sp) /* restore return address */
292 ldq gp,8(sp) /* restore global pointer */
294 lda sp,40(sp) /* free stack space */
301 ldq gp,8(sp) /* restore global pointer */
303 jsr ra,builtin_throw_exception
304 ldq ra,0(sp) /* restore return address */
306 lda sp,40(sp) /* free stack space */
307 mov zero,v0 /* return NULL */
309 .end asm_calljavafunction2
312 /****************** function asm_call_jit_compiler *****************************
314 * invokes the compiler for untranslated JavaVM methods. *
316 * Register R0 contains a pointer to the method info structure (prepared *
317 * by createcompilerstub). Using the return address in R26 and the *
318 * offset in the LDA instruction or using the value in methodptr R28 the *
319 * patching address for storing the method address can be computed: *
321 * method address was either loaded using *
322 * M_LDQ (REG_PV, REG_PV, a) ; invokestatic/special ($27) *
323 * M_LDA (REG_PV, REG_RA, low) *
324 * M_LDAH(REG_PV, REG_RA, high) ; optional *
326 * M_LDQ (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($28) *
327 * in the static case the method pointer can be computed using the *
328 * return address and the lda function following the jmp instruction *
330 *******************************************************************************/
332 .ent asm_call_jit_compiler
334 asm_call_jit_compiler:
336 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
337 srl t8,16,t8 /* shift right register number $yy */
338 and t8,31,t8 /* isolate register number */
339 subl t8,28,t8 /* test for REG_METHODPTR */
341 ldl t8,0(ra) /* load instruction LDA PV,xxx(RA) */
343 sra t8,48,t8 /* isolate offset */
344 addq t8,ra,$28 /* compute update address */
345 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
346 srl t8,16,t8 /* isolate instruction code */
347 lda t8,-0x177b(t8) /* test for LDAH */
349 ldl t8,4(ra) /* load instruction LDAH PV,xxx(PV) */
350 sll t8,16,t8 /* compute high offset */
351 addl t8,0,t8 /* sign extend high offset */
352 addq t8,$28,$28 /* compute update address */
354 lda sp,-14*8(sp) /* reserve stack space */
356 SAVE_ARGUMENT_REGISTERS(0) /* save 6 int/6 float argument registers */
358 stq $28,12*8(sp) /* save method pointer */
359 stq ra,13*8(sp) /* save return address */
361 ldq a0,0(v0) /* pass 'methodinfo' pointer to */
362 jsr ra,jit_compile /* jit compiler */
365 RESTORE_ARGUMENT_REGISTERS(0) /* restore 6 int/6 float argument registers */
367 ldq $28,12*8(sp) /* load method pointer */
368 ldq ra,13*8(sp) /* load return address */
369 lda sp,14*8(sp) /* deallocate stack area */
371 beq v0,asm_call_jit_compiler_exception
373 ldl t8,-8(ra) /* load instruction LDQ PV,xxx($yy) */
375 sra t8,48,t8 /* isolate offset */
377 addq t8,$28,t8 /* compute update address via method pointer*/
378 stq v0,0(t8) /* save new method address there */
380 call_pal PAL_imb /* synchronise instruction cache */
382 mov v0,pv /* load method address into pv */
383 jmp zero,(pv) /* and call method. The method returns */
384 /* directly to the caller (ra). */
386 asm_call_jit_compiler_exception:
387 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
390 jsr ra,builtin_asm_get_exceptionptrptr
396 ldq xptr,0(v0) /* get the exception pointer */
397 stq zero,0(v0) /* clear the exception pointer */
400 br asm_handle_nat_exception
402 .end asm_call_jit_compiler
405 /**************** function asm_refillin_and_handle_exception *******************
407 * This function handles an exception. It does not use the usual calling *
408 * conventions. The exception is passed in REG_ITMP1 and the *
409 * pc from the exception raising position is passed in REG_ITMP2. *
410 * a0 contains the PV of the function causing the problem *
412 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
414 *******************************************************************************/
415 .ent asm_refillin_and_handle_exception
416 asm_refillin_and_handle_exception:
418 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
420 sra t0,48,t0 /* isolate offset */
421 addq t0,ra,pv /* compute update address */
422 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
423 srl t0,16,t0 /* isolate instruction code */
424 lda t0,-0x177b(t0) /* test for LDAH */
425 bne t0, asm_refillin_and_handle_exception_cont
426 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
427 sll t0,16,t0 /* compute high offset */
428 addl t0,0,t0 /* sign extend high offset */
429 addq t0,pv,pv /* compute update address */
431 asm_refillin_and_handle_exception_cont:
434 lda sp,-6*8(sp) /* prepare stackframe*/
435 stq pv,5*8(sp) /* store pv of caller */
436 stq xptr,4*8(sp) /*exception ptr*/
437 stq xpc,3*8(sp) /*address of failure*/
438 stq t0,2*8(sp) /*begin of java stack frame*/
439 stq pv,1*8(sp) /* store pv of caller */
440 stq zero,0*8(sp) /*builtin (invisible) function */
441 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
444 ldq a2,utf_void__java_lang_Throwable
445 ldq a1,utf_fillInStackTrace
447 ldq t1,offobjvftbl(t0)
449 jsr ra,class_resolvemethod
451 /* now we have the method */
456 jsr ra,asm_calljavafunction
460 jsr ra,asm_remove_native_stackinfo
469 br asm_handle_exception
471 .end asm_refillin_and_handle_exception
473 /****** function asm_throw_and_handle_arrayindexoutofbounds_exception **********
475 * This function handles an exception. It does not use the usual calling *
476 * conventions. The integer parameter is passed in REG_ITMP1 and the *
477 * pc from the exception raising position is passed in REG_ITMP2. *
479 * void asm_handle_arithmetic_exception (exceptionclass, exceptionpc); *
481 *******************************************************************************/
483 .ent asm_throw_and_handle_arrayindexoutofbounds_exception
485 asm_throw_and_handle_arrayindexoutofbounds_exception:
488 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
490 sra t0,48,t0 /* isolate offset */
491 addq t0,ra,pv /* compute update address */
492 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
493 srl t0,16,t0 /* isolate instruction code */
494 lda t0,-0x177b(t0) /* test for LDAH */
495 bne t0,asm_throw_and_handle_arrayindexoutofbounds_exception_cont
496 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
497 sll t0,16,t0 /* compute high offset */
498 addl t0,0,t0 /* sign extend high offset */
499 addq t0,pv,pv /* compute update address */
501 asm_throw_and_handle_arrayindexoutofbounds_exception_cont:
503 lda sp,-6*8(sp) /*prepare stackframe*/
504 stq pv,5*8(sp) /*pv of failure*/
505 stq itmp1,4*8(sp) /*int parameter of the exception*/
506 stq xpc,3*8(sp) /*address of failure */
507 stq t0,2*8(sp) /*store begin of java stack frame*/
508 stq pv,1*8(sp) /*store pv of caller in structure*/
509 stq zero,0*8(sp) /*builtin (invisible function)*/
511 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
514 ldq a0,6*8(sp) /*int of exception*/
515 jsr ra,new_arrayindexoutofboundsexception
518 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
520 jsr ra,asm_remove_native_stackinfo
526 br asm_handle_exception
528 .end asm_throw_and_handle_arrayindexoutofbounds_exception
531 /* asm_throw_and_handle_arithmetic_exception ***********************************
535 *******************************************************************************/
537 .ent asm_throw_and_handle_arithmetic_exception
539 asm_throw_and_handle_arithmetic_exception:
540 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
542 sra t0,48,t0 /* isolate offset */
543 addq t0,ra,pv /* compute update address */
544 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
545 srl t0,16,t0 /* isolate instruction code */
546 lda t0,-0x177b(t0) /* test for LDAH */
547 bne t0,asm_throw_and_handle_arithmetic_exception_cont
548 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
549 sll t0,16,t0 /* compute high offset */
550 addl t0,0,t0 /* sign extend high offset */
551 addq t0,pv,pv /* compute update address */
553 asm_throw_and_handle_arithmetic_exception_cont:
555 lda sp,-6*8(sp) /*prepare stackframe*/
556 stq pv,5*8(sp) /*pv of failure*/
557 stq itmp1,4*8(sp) /*exception string of the exception*/
558 stq xpc,3*8(sp) /*address of failure */
559 stq t0,2*8(sp) /*store begin of java stack frame*/
560 stq pv,1*8(sp) /*store pv of caller in structure*/
561 stq zero,0*8(sp) /*builtin (invisible function)*/
562 jsr ra,asm_prepare_native_stackinfo /* puts 2 additional quadwords on stack */
565 jsr ra,new_arithmeticexception
567 mov v0,itmp1 /*itmp1 is not touched in asm_remove_native_stackinfo*/
569 jsr ra,asm_remove_native_stackinfo
575 br asm_handle_exception
577 .end asm_throw_and_handle_arithmetic_exception
580 /* asm_throw_and_handle_exception **********************************************
584 *******************************************************************************/
586 .ent asm_throw_and_handle_nat_exception
588 asm_throw_and_handle_nat_exception:
590 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
592 sra t0,48,t0 /* isolate offset */
593 addq t0,ra,pv /* compute update address */
594 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
595 srl t0,16,t0 /* isolate instruction code */
596 lda t0,-0x177b(t0) /* test for LDAH */
597 bne t0,asm_throw_and_handle_exception
598 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
599 sll t0,16,t0 /* compute high offset */
600 addl t0,0,t0 /* sign extend high offset */
601 addq t0,pv,pv /* compute update address */
603 .aent asm_throw_and_handle_exception
605 asm_throw_and_handle_exception:
607 lda sp,-6*8(sp) /* prepare stackframe */
608 stq pv,5*8(sp) /* pv of failure */
609 stq xptr,4*8(sp) /* classname of the exception */
610 stq xpc,3*8(sp) /* address of failure */
611 stq t0,2*8(sp) /* store begin of java stack frame */
612 stq pv,1*8(sp) /* store pv of caller in structure */
613 stq zero,0*8(sp) /* builtin (invisible function) */
614 /* puts 2 additional quadwords on stack */
616 br ra,L_asm_throw_and_handle_exception_load_gp
617 L_asm_throw_and_handle_exception_load_gp:
618 ldgp gp,0(ra) /* load gp (it's not set correctly in jit) */
620 jsr ra,asm_prepare_native_stackinfo
623 ldq a0,6*8(sp) /* classname of exception */
627 mov v0,xptr /* xptr (itmp1) is not touched in */
628 /* asm_remove_native_stackinfo */
630 jsr ra,asm_remove_native_stackinfo
636 br asm_handle_exception
638 .end asm_throw_and_handle_nat_exception
641 /********************* function asm_handle_exception ***************************
643 * This function handles an exception. It does not use the usual calling *
644 * conventions. The exception pointer is passed in REG_ITMP1 and the *
645 * pc from the exception raising position is passed in REG_ITMP2. It searches *
646 * the local exception table for a handler. If no one is found, it unwinds *
647 * stacks and continues searching the callers. *
649 * void asm_handle_exception (exceptionptr, exceptionpc); *
651 *******************************************************************************/
653 .ent asm_handle_nat_exception
655 asm_handle_nat_exception:
656 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
658 sra t0,48,t0 /* isolate offset */
659 addq t0,ra,pv /* compute update address */
660 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
661 srl t0,16,t0 /* isolate instruction code */
662 lda t0,-0x177b(t0) /* test for LDAH */
663 bne t0,asm_handle_exception
664 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
665 sll t0,16,t0 /* compute high offset */
666 addl t0,0,t0 /* sign extend high offset */
667 addq t0,pv,pv /* compute update address */
669 .aent asm_handle_exception
671 asm_handle_exception:
672 lda sp,-18*8(sp) /* allocate stack */
673 stq t0,0*8(sp) /* save possible used registers */
674 stq t1,1*8(sp) /* also registers used by trace_exception */
692 lda t3,1(zero) /* set no unwind flag */
694 lda sp,-5*8(sp) /* allocate stack */
695 stq xptr,0*8(sp) /* save used register */
702 ldq a1,MethodPointer(pv)
707 br ra,ex_trace /* set ra for gp loading */
709 ldgp gp,0(ra) /* load gp */
710 jsr ra,builtin_trace_exception /* trace_exception(xptr,methodptr) */
712 ldq xptr,0*8(sp) /* restore used register */
717 lda sp,5*8(sp) /* deallocate stack */
719 ldl t0,ExTableSize(pv) /* t0 = exception table size */
720 beq t0,empty_table /* if empty table skip */
722 lda t1,ExTableStart(pv) /* t1 = start of exception table */
725 ldq t2,ExStartPC(t1) /* t2 = exception start pc */
726 cmple t2,xpc,t2 /* t2 = (startpc <= xpc) */
727 beq t2,ex_table_cont /* if (false) continue */
728 ldq t2,ExEndPC(t1) /* t2 = exception end pc */
729 cmplt xpc,t2,t2 /* t2 = (xpc < endpc) */
730 beq t2,ex_table_cont /* if (false) continue */
731 ldq a1,ExCatchType(t1) /* arg1 = exception catch type */
732 beq a1,ex_handle_it /* NULL catches everything */
734 ldl itmp3,offclassloaded(a1)
735 bne itmp3,L_class_loaded
737 subq sp,8*8,sp /* allocate stack */
738 stq t0,0*8(sp) /* save used register */
749 br ra,L_class_load_ra /* set ra for gp loading */
751 ldgp gp,0(ra) /* load gp */
752 jsr ra,load_class_bootstrap
754 ldq t0,0*8(sp) /* restore used register */
762 addq sp,8*8,sp /* deallocate stack */
765 ldl itmp3,offclasslinked(a1)
766 subq sp,8*8,sp /* allocate stack */
768 bne itmp3,L_class_linked
770 stq t0,0*8(sp) /* save used register */
780 br ra,L_class_link_ra /* set ra for gp loading */
782 ldgp gp,0(ra) /* load gp */
785 ldq t0,0*8(sp) /* restore used register */
797 ldq a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
798 ldq a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
799 ldl a0,offbaseval(a0) /* a0 = baseval(xptr) */
800 ldl v0,offbaseval(a1) /* a2 = baseval(catchtype) */
801 ldl a1,offdiffval(a1) /* a1 = diffval(catchtype) */
803 subl a0,v0,a0 /* a0 = baseval(xptr) - baseval(catchtype) */
804 cmpule a0,a1,v0 /* v0 = xptr is instanceof catchtype */
805 addq sp,8*8,sp /* deallocate stack */
806 beq v0,ex_table_cont /* if (false) continue */
809 ldq xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
811 beq t3,ex_jump /* if (!(no stack unwinding) skip */
813 ldq t0,0*8(sp) /* restore possible used registers */
814 ldq t1,1*8(sp) /* also registers used by trace_exception */
831 lda sp,18*8(sp) /* deallocate stack */
834 jmp zero,(xpc) /* jump to the handler */
837 lda t1,ExEntrySize(t1) /* next exception table entry */
838 subl t0,1,t0 /* decrement entry counter */
839 bgt t0,ex_table_loop /* if (t0 > 0) next entry */
842 beq t3,ex_already_cleared /* if here the first time, then */
843 lda sp,18*8(sp) /* deallocate stack and */
844 clr t3 /* clear the no unwind flag */
846 ldl t0,IsSync(pv) /* t0 = SyncOffset */
847 beq t0,no_monitor_exit /* if zero no monitorexit */
849 #if defined(USE_THREADS)
850 addq sp,t0,t0 /* add stackptr to Offset */
851 ldq a0,-8(t0) /* load monitorexit pointer */
853 lda sp,-7*8(sp) /* allocate stack */
854 stq t0,0*8(sp) /* save used register */
862 br ra,ex_mon_load /* set ra for gp loading */
864 ldgp gp,0(ra) /* load gp */
865 jsr ra,builtin_monitorexit/* builtin_monitorexit(objectptr) */
867 ldq t0,0*8(sp) /* restore used register */
874 lda sp,7*8(sp) /* deallocate stack */
878 ldl t0,FrameSize(pv) /* t0 = frame size */
879 addq sp,t0,sp /* unwind stack */
880 mov sp,t0 /* t0 = pointer to save area */
881 ldl t1,IsLeaf(pv) /* t1 = is leaf procedure */
882 bne t1,ex_no_restore /* if (leaf) skip */
883 ldq ra,-8(t0) /* restore ra */
884 lda t0,-8(t0) /* t0-- */
886 mov ra,xpc /* the new xpc is ra */
887 ldl t1,IntSave(pv) /* t1 = saved int register count */
888 br t2,ex_int1 /* t2 = current pc */
890 lda t2,44(t2) /* lda t2,ex_int2-ex_int1(t2) !!!!!!!!!!!!! */
891 negl t1,t1 /* negate register count */
892 s4addq t1,t2,t2 /* t2 = ex_int_sav - 4 * register count */
893 jmp zero,(t2) /* jump to save position */
902 s8addq t1,t0,t0 /* t0 = t0 - 8 * register count */
904 ldl t1,FltSave(pv) /* t1 = saved flt register count */
905 br t2,ex_flt1 /* t2 = current pc */
907 lda t2,48(t2) /* lda t2,ex_flt2-ex_flt1(t2) !!!!!!!!!!!!! */
908 negl t1,t1 /* negate register count */
909 s4addq t1,t2,t2 /* t2 = ex_flt_sav - 4 * register count */
910 jmp zero,(t2) /* jump to save position */
920 ldl t0,0(ra) /* load instruction LDA PV,xxx(RA) */
922 sra t0,48,t0 /* isolate offset */
923 addq t0,ra,pv /* compute update address */
924 ldl t0,4(ra) /* load instruction LDAH PV,xxx(PV) */
925 srl t0,16,t0 /* isolate instruction code */
926 lda t0,-0x177b(t0) /* test for LDAH */
928 ldl t0,4(ra) /* load instruction LDAH PV,xxx(RA) */
929 sll t0,16,t0 /* compute high offset */
930 addl t0,0,t0 /* sign extend high offset */
931 addq t0,pv,pv /* compute update address */
934 .end asm_handle_nat_exception
937 /* asm_wrapper_patcher *********************************************************
942 32 return address into JIT code (patch position)
943 24 pointer to virtual java_objectheader
944 16 machine code (which is patched back later)
945 8 unresolved class/method/field reference
946 0 patcher function pointer to call
948 ATTENTION: itmp3 == gp! But we don't need gp do call the patcher function.
950 *******************************************************************************/
952 .ent asm_wrapper_patcher
955 lda sp,-(12+27+4)*8(sp) /* create stack frame */
957 SAVE_ARGUMENT_REGISTERS(0) /* save 6 int/6 float argument registers */
958 SAVE_TEMPORARY_REGISTERS(12) /* save 11 int/16 float temporary registers */
960 stq itmp1,(12+27+0)*8(sp) /* save itmp1 */
961 stq itmp2,(12+27+1)*8(sp) /* save itmp2 */
962 stq ra,(12+27+2)*8(sp) /* save method return address (for leafs) */
963 stq pv,(12+27+3)*8(sp) /* save pv of calling java function */
965 lda a0,(1+12+27+4)*8(sp) /* pass sp, skip patcher function pointer */
966 ldq pv,(0+12+27+4)*8(sp) /* get function pointer */
967 jmp ra,(pv) /* call the patcher function */
970 RESTORE_ARGUMENT_REGISTERS(0) /* restore 6 int/6 float argument registers */
971 RESTORE_TEMPORARY_REGISTERS(12)/* restore 11 integer temporary registers */
973 ldq itmp1,(12+27+0)*8(sp) /* restore itmp1 */
974 ldq itmp2,(12+27+1)*8(sp) /* restore itmp2 */
975 ldq ra,(12+27+2)*8(sp) /* restore method return address (for leafs)*/
976 ldq pv,(12+27+3)*8(sp) /* restore pv of calling java function */
978 ldq itmp3,(4+12+27+4)*8(sp)/* get return address (into JIT code) */
979 lda sp,(5+12+27+4)*8(sp) /* remove stack frame */
981 beq v0,L_asm_wrapper_patcher_exception
983 jmp zero,(itmp3) /* jump to new patched code */
985 L_asm_wrapper_patcher_exception:
986 mov itmp3,xpc /* return address into JIT code is xpc */
988 br itmp1,L_asm_wrapper_patcher_exception_load_gp
989 L_asm_wrapper_patcher_exception_load_gp:
990 ldgp gp,0(itmp1) /* itmp3 == gp, load the current gp */
992 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
994 stq xpc,0*8(sp) /* save return address (xpc) */
997 jsr ra,builtin_asm_get_exceptionptrptr
998 ldq xpc,0*8(sp) /* restore return address (xpc) */
1003 lda v0,_exceptionptr
1005 ldq xptr,0(v0) /* get the exception pointer */
1006 stq zero,0(v0) /* clear the exception pointer */
1007 br asm_handle_exception /* we have the pv of the calling java func. */
1009 .end asm_wrapper_patcher
1012 /************************ function asm_builtin_idiv ****************************
1014 * Does null check and calls idiv or throws an exception *
1016 *******************************************************************************/
1018 .ent asm_builtin_idiv
1023 beq a1,nb_idiv /* if (null) throw exception */
1024 jmp zero,(pv) /* else call builtin_idiv */
1027 ldq xptr,string_java_lang_ArithmeticException_message
1028 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1029 br asm_throw_and_handle_arithmetic_exception
1031 .end asm_builtin_idiv
1034 /************************ function asm_builtin_ldiv ****************************
1036 * Does null check and calls ldiv or throws an exception *
1038 *******************************************************************************/
1040 .ent asm_builtin_ldiv
1045 beq a1,nb_ldiv /* if (null) throw exception */
1046 jmp zero,(pv) /* else call builtin_ldiv */
1049 ldq xptr,string_java_lang_ArithmeticException_message
1050 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1051 br asm_throw_and_handle_arithmetic_exception
1053 .end asm_builtin_ldiv
1056 /************************ function asm_builtin_irem ****************************
1058 * Does null check and calls irem or throws an exception *
1060 *******************************************************************************/
1062 .ent asm_builtin_irem
1067 beq a1,nb_irem /* if (null) throw exception */
1068 jmp zero,(pv) /* else call builtin_irem */
1071 ldq xptr,string_java_lang_ArithmeticException_message
1072 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1073 br asm_throw_and_handle_arithmetic_exception
1075 .end asm_builtin_irem
1078 /************************ function asm_builtin_lrem ****************************
1080 * Does null check and calls lrem or throws an exception *
1082 *******************************************************************************/
1084 .ent asm_builtin_lrem
1089 beq a1,nb_lrem /* if (null) throw exception */
1090 jmp zero,(pv) /* else call builtin_lrem */
1093 ldq xptr,string_java_lang_ArithmeticException_message
1094 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1095 br asm_throw_and_handle_arithmetic_exception
1097 .end asm_builtin_lrem
1100 /* asm_builtin_arraycheckcast **************************************************
1102 Does the cast check and eventually throws an exception.
1104 *******************************************************************************/
1106 .ent asm_builtin_arraycheckcast
1108 asm_builtin_arraycheckcast:
1110 lda sp,-16(sp) /* allocate stack space */
1111 stq ra,0(sp) /* save return address */
1112 stq a0,8(sp) /* save object pointer */
1113 jsr ra,builtin_arraycheckcast
1115 beq v0,nb_carray_throw /* if (false) throw exception */
1116 ldq ra,0(sp) /* restore return address */
1117 ldq v0,8(sp) /* return object pointer */
1118 lda sp,16(sp) /* free stack space */
1125 ldq xptr,string_java_lang_ClassCastException
1126 jmp zero,asm_throw_and_handle_nat_exception
1128 ldq a0,string_java_lang_ClassCastException
1129 jsr ra,new_exception
1133 ldq ra,0(sp) /* restore return address */
1134 lda sp,16(sp) /* free stack space */
1135 lda xpc,-4(ra) /* faulting address is return adress - 4*/
1136 br asm_handle_nat_exception
1139 .end asm_builtin_arraycheckcast
1142 /******************* function asm_builtin_aastore ******************************
1144 * Does the cast check and eventually throws an exception *
1146 *******************************************************************************/
1148 .ent asm_builtin_aastore
1150 asm_builtin_aastore:
1152 beq a0,nb_aastore_null /* if null pointer throw exception */
1153 ldl t0,offarraysize(a0) /* load size */
1154 lda sp,-24(sp) /* allocate stack space */
1155 stq ra,0(sp) /* save return address */
1156 s8addq a1,a0,t1 /* add index*8 to arrayref */
1157 cmpult a1,t0,t0 /* do bound check */
1158 beq t0,nb_aastore_bound /* if out of bounds throw exception */
1159 mov a2,a1 /* object is second argument */
1160 stq t1,8(sp) /* save store position */
1161 stq a1,16(sp) /* save object */
1162 jsr ra,builtin_canstore /* builtin_canstore(arrayref,object) */
1164 ldq ra,0(sp) /* restore return address */
1165 ldq a0,8(sp) /* restore store position */
1166 ldq a1,16(sp) /* restore object */
1167 lda sp,24(sp) /* free stack space */
1168 beq v0,nb_aastore_throw /* if (false) throw exception */
1169 stq a1,offobjarrdata(a0) /* store objectptr in array */
1173 ldq xptr,string_java_lang_NullPointerException
1175 jmp zero,asm_throw_and_handle_nat_exception
1177 subq sp,8,sp /* allocate stack space */
1178 stq ra,0(sp) /* save return address */
1179 jsr ra,new_nullpointerexception
1185 mov ra,xpc /* faulting address is return adress */
1186 br asm_handle_nat_exception
1193 jmp zero,asm_throw_and_handle_arrayindexoutofbounds_exception
1195 ldq a0,string_java_lang_ArrayIndexOutOfBoundsException
1196 jsr ra,new_exception_int /* a1 already contains the index */
1200 ldq ra,0(sp) /* restore return address */
1201 lda sp,24(sp) /* free stack space */
1202 mov ra,xpc /* faulting address is return adress */
1203 br asm_handle_nat_exception
1207 ldq xptr,string_java_lang_ArrayStoreException
1208 jmp zero,asm_throw_and_handle_nat_exception
1210 subq sp,8,sp /* allocate stack space */
1211 stq ra,0(sp) /* save return address */
1212 jsr ra,new_arraystoreexception
1218 mov ra,xpc /* faulting address is return adress */
1219 br asm_handle_nat_exception
1221 .end asm_builtin_aastore
1224 /******************* function asm_initialize_thread_stack **********************
1226 * initialized a thread stack *
1228 *******************************************************************************/
1230 .ent asm_initialize_thread_stack
1232 asm_initialize_thread_stack:
1253 .end asm_initialize_thread_stack
1256 /******************* function asm_perform_threadswitch *************************
1258 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1260 * performs a threadswitch *
1262 *******************************************************************************/
1264 .ent asm_perform_threadswitch
1266 asm_perform_threadswitch:
1307 .end asm_perform_threadswitch
1310 /********************* function asm_switchstackandcall *************************
1312 * void *asm_switchstackandcall (void *stack, void *func, void **stacktopsave, *
1315 * Switches to a new stack, calls a function and switches back. *
1316 * a0 new stack pointer *
1317 * a1 function pointer *
1318 * a2 pointer to variable where stack top should be stored *
1319 * a3 pointer to user data, is passed to the function *
1321 *******************************************************************************/
1324 .ent asm_switchstackandcall
1326 asm_switchstackandcall:
1327 lda a0,-2*8(a0) /* allocate new stack */
1328 stq ra,0(a0) /* save return address on new stack */
1329 stq sp,1*8(a0) /* save old stack pointer on new stack */
1330 stq sp,0(a2) /* save old stack pointer to variable */
1331 mov a0,sp /* switch to new stack */
1333 mov a1,pv /* load function pointer */
1334 mov a3,a0 /* pass pointer */
1335 jmp ra,(pv) /* and call function */
1337 ldq ra,0(sp) /* load return address */
1338 ldq sp,1*8(sp) /* switch to old stack */
1340 jmp zero,(ra) /* return */
1342 .end asm_switchstackandcall
1344 .ent asm_getclassvalues_atomic
1346 asm_getclassvalues_atomic:
1349 ldl t0,offbaseval(a0)
1350 ldl t1,offdiffval(a0)
1351 ldl t2,offbaseval(a1)
1353 stl t0,offcast_super_baseval(a2)
1354 stl t1,offcast_super_diffval(a2)
1355 stl t2,offcast_sub_baseval(a2)
1358 .end asm_getclassvalues_atomic
1362 asm_criticalsections:
1363 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
1366 .quad _crit_restart1
1369 .quad _crit_restart2
1374 .ent asm_prepare_native_stackinfo
1375 asm_prepare_native_stackinfo:
1378 jsr ra,builtin_asm_get_stackframeinfo
1386 .end asm_prepare_native_stackinfo
1388 .ent asm_remove_native_stackinfo
1389 asm_remove_native_stackinfo:
1395 .end asm_remove_native_stackinfo
1398 * These are local overrides for various environment variables in Emacs.
1399 * Please do not remove this and leave it at the end of the file, where
1400 * Emacs will automagically detect them.
1401 * ---------------------------------------------------------------------
1404 * indent-tabs-mode: t