1 /* jit/mips/asmpart.S - Java-C interface functions for mips
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
30 $Id: asmpart.S 1007 2004-03-31 19:16:23Z twisti $
127 #define aaddiu daddiu
134 #define MethodPointer -8
135 #define FrameSize -12
140 #define ExTableSize -32
141 #define ExTableStart -32
143 #define ExEntrySize -32
146 #define ExHandlerPC -24
147 #define ExCatchType -32
154 /********************* exported functions and variables ***********************/
156 .globl asm_calljavafunction
157 .globl asm_calljavafunction2
158 .globl asm_calljavafunction2long
159 .globl asm_calljavafunction2double
160 .globl asm_call_jit_compiler
161 .globl asm_dumpregistersandcall
162 .globl asm_handle_exception
163 .globl asm_handle_nat_exception
164 .globl asm_check_clinit
165 .globl asm_builtin_checkarraycast
166 .globl asm_builtin_checkcast
167 .globl asm_builtin_aastore
168 .globl asm_builtin_monitorenter
169 .globl asm_builtin_monitorexit
170 .globl asm_builtin_idiv
171 .globl asm_builtin_irem
172 .globl asm_builtin_ldiv
173 .globl asm_builtin_lrem
174 .globl asm_perform_threadswitch
175 .globl asm_initialize_thread_stack
176 .globl asm_switchstackandcall
177 .globl asm_builtin_trace
178 .globl asm_builtin_exittrace
181 /*************************** imported functions *******************************/
184 .globl builtin_monitorexit
185 .globl builtin_throw_exception
186 .globl builtin_trace_exception
187 .globl class_java_lang_Object
190 /********************* function asm_calljavafunction ****************************
192 * This function calls a Java-method (which possibly needs compilation) *
193 * with up to 4 address parameters. *
195 * This functions calls the JIT-compiler which eventually translates the *
196 * method into machine code. *
198 * A possibly throwed exception will be returned to the caller as function *
199 * return value, so the java method cannot return a fucntion value (this *
200 * function usually calls 'main' and '<clinit>' which do not return a *
204 * javaobject_header *asm_calljavafunction (methodinfo *m, *
205 * void *arg1, void *arg2, void *arg3, void *arg4); *
207 *******************************************************************************/
209 .ent asm_calljavafunction
212 .ascii "calljavafunction\0\0"
215 .quad 0 /* catch type all */
216 .quad calljava_xhandler /* handler pc */
217 .quad calljava_xhandler /* end pc */
218 .quad asm_calljavafunction /* start pc */
219 .long 1 /* extable size */
220 .long 0 /* fltsave */
221 .long 0 /* intsave */
224 .long 80 /* frame size */
225 .quad 0 /* method pointer (pointer to name) */
227 asm_calljavafunction:
228 aaddiu sp,sp,-10*8 /* allocate stack space */
229 sd ra,0(sp) /* save return address */
233 sd pv,3*8(sp) /* procedure vector */
239 sdc1 fss0,4*8(sp) /* save non JavaABI saved flt registers */
245 sd a0,2*8(sp) /* save method pointer for compiler */
246 aaddiu itmp1,sp,16 /* pass pointer to methodptr via itmp1 */
248 move a0,a1 /* pass the remaining parameters */
253 ala mptr,asm_call_jit_compiler/* fake virtual function call (2 instr) */
254 ast mptr,1*8(sp) /* store function address */
255 move mptr,sp /* set method pointer */
259 ald pv,1*8(mptr) /* method call as in Java */
260 jalr pv /* call JIT compiler */
262 aaddiu pv,ra,-23*4 /* recompute procedure vector */
264 move v0,zero /* clear return value (exception ptr) */
270 ld ra,0(sp) /* restore return address */
271 ld pv,3*8(sp) /* restore procedure vector */
273 ldc1 fss0,4*8(sp) /* restore non JavaABI saved flt regs */
280 aaddiu sp,sp,10*8 /* free stack space */
286 jal builtin_throw_exception
289 .end asm_calljavafunction
292 .ent asm_calljavafunction2
295 .ascii "calljavafunction2\0\0"
298 .quad 0 /* catch type all */
299 .quad calljava_xhandler2 /* handler pc */
300 .quad calljava_xhandler2 /* end pc */
301 .quad asm_calljavafunction2 /* start pc */
302 .long 1 /* extable size */
303 .long 0 /* fltsave */
304 .long 1 /* intsave */
307 .long 96 /* frame size */
308 .quad 0 /* method pointer (pointer to name) */
310 asm_calljavafunction2:
311 asm_calljavafunction2double:
312 asm_calljavafunction2long:
313 aaddiu sp,sp,-12*8 /* allocate stack space (only 11 needed)*/
314 sd ra,0(sp) /* save return address */
318 sd pv,1*8(sp) /* procedure vector */
325 sdc1 fss0,5*8(sp) /* save non JavaABI saved flt registers */
331 sd a0,4*8(sp) /* save method pointer for compiler */
335 blez s7,calljava_argsloaded
336 ald a0,offjniitem(t0)
337 ldc1 fa0,offjniitem(t0)
339 blez s7,calljava_argsloaded
341 ald a1,offjniitem+sizejniblock*1(t0)
342 ldc1 fa1,offjniitem+sizejniblock*1(t0)
344 blez s7,calljava_argsloaded
346 ald a2,offjniitem+sizejniblock*2(t0)
347 ldc1 fa2,offjniitem+sizejniblock*2(t0)
349 blez s7,calljava_argsloaded
351 ald a3,offjniitem+sizejniblock*3(t0)
352 ldc1 fa3,offjniitem+sizejniblock*3(t0)
354 blez s7,calljava_argsloaded
356 ald a4,offjniitem+sizejniblock*4(t0)
357 ldc1 fa4,offjniitem+sizejniblock*4(t0)
359 blez s7,calljava_argsloaded
361 ald a5,offjniitem+sizejniblock*5(t0)
362 ldc1 fa5,offjniitem+sizejniblock*5(t0)
364 blez s7,calljava_argsloaded
366 ald a6,offjniitem+sizejniblock*6(t0)
367 ldc1 fa6,offjniitem+sizejniblock*6(t0)
369 blez s7,calljava_argsloaded
371 ald a7,offjniitem+sizejniblock*7(t0)
372 ldc1 fa7,offjniitem+sizejniblock*7(t0)
377 blez s7,calljava_nocopy
384 ald t3,offjniitem+sizejniblock*8(t0)
387 ala t0,sizejniblock(t0)
389 bnez t1,calljava_copyloop
392 ala itmp1,32(t4) /* pass pointer to methodptr via itmp1 */
394 ala mptr,asm_call_jit_compiler/* fake virtual function call (2 instr) */
395 ast mptr,16(sp) /* store function address */
396 ala mptr,8(t4) /* set method pointer */
400 ald pv,8(mptr) /* method call as in Java */
401 jalr pv /* call JIT compiler */
403 aaddiu pv,ra,-76*4 /* recompute procedure vector */
406 ld ra,0(sp) /* restore return address */
407 ld pv,8(sp) /* restore procedure vector */
410 ldc1 fss0,5*8(sp) /* restore non JavaABI saved flt regs */
417 aaddiu sp,sp,12*8 /* free stack space */
425 jal builtin_throw_exception
428 .end asm_calljavafunction2
431 /****************** function asm_call_jit_compiler *****************************
433 * invokes the compiler for untranslated JavaVM methods. *
435 * Register REG_ITEMP1 contains a pointer to the method info structure *
436 * (prepared by createcompilerstub). Using the return address in R31 and the *
437 * offset in the LDA instruction or using the value in methodptr R25 the *
438 * patching address for storing the method address can be computed: *
440 * method address was either loaded using *
441 * M_ALD (REG_PV, REG_PV, a) ; invokestatic/special ($28) *
442 * M_JSR (REG_RA, REG_PV); *
444 * M_LDA (REG_PV, REG_RA, val) *
446 * M_ALD (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($25) *
447 * M_JSR (REG_RA, REG_PV); *
449 * in the static case the method pointer can be computed using the *
450 * return address and the lda function following the jmp instruction *
452 *******************************************************************************/
455 .ent asm_call_jit_compiler
456 asm_call_jit_compiler:
458 lw t0,-12(ra) /* load instruction LD PV,xxx($y) */
459 srl t0,t0,21 /* shift right register number $y */
460 and t0,t0,31 /* isolate register number */
461 addiu t0,t0,-mptrreg /* test for REG_METHODPTR */
464 lw t0,0(ra) /* load instruction LDA PV,xxx(RA) */
466 sra t0,t0,16 /* isolate offset */
467 aaddu mptr,t0,ra /* compute update address */
471 aaddiu sp,sp,-18*8 /* allocate stack space */
472 sd a0,0*8(sp) /* save all argument registers */
473 sd a1,1*8(sp) /* they could be used by method */
488 sd mptr,16*8(sp) /* save method pointer */
489 sd ra,17*8(sp) /* save return address */
491 ald a0,0(itmp1) /* pass 'methodinfo' pointer to */
492 jal jit_compile /* jit compiler */
494 ld a0,0*8(sp) /* restore argument registers */
495 ld a1,1*8(sp) /* they could be used by method */
510 ld mptr,16*8(sp) /* restore method pointer */
511 ld ra,17*8(sp) /* restore return address */
512 aaddiu sp,sp,18*8 /* deallocate stack area */
514 lw t0,-12(ra) /* load instruction LDQ PV,xxx($yy) */
516 sra t0,t0,16 /* isolate offset */
518 aaddu t0,t0,mptr /* compute update address via method pointer*/
519 ast v0,0(t0) /* save new method address there */
521 move pv,v0 /* move method address into pv */
523 jr pv /* and call method. The method returns */
524 /* directly to the caller (ra). */
526 .end asm_call_jit_compiler
529 /********************* function asm_handle_exception ***************************
531 * This function handles an exception. It does not use the usual calling *
532 * conventions. The exception pointer is passed in REG_ITMP1 and the *
533 * pc from the exception raising position is passed in REG_ITMP2. It searches *
534 * the local exception table for a handler. If no one is found, it unwinds *
535 * stacks and continues searching the callers. *
537 * void asm_handle_exception (exceptionptr, exceptionpc); *
539 *******************************************************************************/
541 .ent asm_handle_nat_exception
542 asm_handle_nat_exception:
543 lw t0,0(ra) /* load instruction LDA PV,xxx(RA) */
545 sra t0,t0,16 /* isolate offset */
546 aaddu pv,t0,ra /* compute update address */
548 .aent asm_handle_exception
549 asm_handle_exception:
550 aaddiu sp,sp,-14*8 /* allocate stack */
551 sd v0,0*8(sp) /* save possible used registers */
552 sd t0,1*8(sp) /* also registers used by trace_exception */
566 addu t3,zero,1 /* set no unwind flag */
568 aaddiu sp,sp,-6*8 /* allocate stack */
569 sd xptr,0*8(sp) /* save used registers */
576 ald a1,MethodPointer(pv)
581 jal builtin_trace_exception /* trace_exception(xptr,methodptr) */
583 ld xptr,0*8(sp) /* restore used register */
588 aaddiu sp,sp,6*8 /* deallocate stack */
590 lw t0,ExTableSize(pv) /* t0 = exception table size */
591 beqz t0,empty_table /* if empty table skip */
592 aaddiu t1,pv,ExTableStart /* t1 = start of exception table */
595 ald t2,ExStartPC(t1) /* t2 = exception start pc */
596 slt t2,xpc,t2 /* t2 = (xpc < startpc) */
597 bnez t2,ex_table_cont /* if (true) continue */
598 ald t2,ExEndPC(t1) /* t2 = exception end pc */
599 slt t2,xpc,t2 /* t2 = (xpc < endpc) */
600 beqz t2,ex_table_cont /* if (false) continue */
601 ald a1,ExCatchType(t1) /* arg1 = exception catch type */
602 beqz a1,ex_handle_it /* NULL catches everything */
604 ald a0,offobjvftbl(xptr) /* a0 = vftblptr(xptr) */
605 ald a1,offclassvftbl(a1) /* a1 = vftblptr(catchtype) class (not obj) */
606 lw a0,offbaseval(a0) /* a0 = baseval(xptr) */
607 lw v0,offbaseval(a1) /* a2 = baseval(catchtype) */
608 lw a1,offdiffval(a1) /* a1 = diffval(catchtype) */
609 subu a0,a0,v0 /* a0 = baseval(xptr) - baseval(catchtype) */
610 sltu v0,a1,a0 /* v0 = xptr is instanceof catchtype */
611 bnez v0,ex_table_cont /* if (false) continue */
614 ald xpc,ExHandlerPC(t1) /* xpc = exception handler pc */
616 beqz t3,ex_jump /* if (!(no stack unwinding) skip */
618 ld v0,0*8(sp) /* restore possible used registers */
619 ld t0,1*8(sp) /* also registers used by trace_exception */
633 aaddiu sp,sp,14*8 /* deallocate stack */
636 jr xpc /* jump to the handler */
639 aaddiu t1,t1,ExEntrySize /* next exception table entry */
640 addiu t0,t0,-1 /* decrement entry counter */
641 bgtz t0,ex_table_loop /* if (t0 > 0) next entry */
644 beqz t3,ex_already_cleared /* if here the first time, then */
645 aaddiu sp,sp,14*8 /* deallocate stack and */
646 move t3,zero /* clear the no unwind flag */
648 lw t0,IsSync(pv) /* t0 = SyncOffset */
649 beqz t0,no_monitor_exit /* if zero no monitorexit */
650 aaddu t0,sp,t0 /* add stackptr to Offset */
651 ald a0,-8(t0) /* load monitorexit pointer */
653 aaddiu sp,sp,-8*8 /* allocate stack */
654 sd t0,0*8(sp) /* save used register */
662 jal builtin_monitorexit /* builtin_monitorexit(objectptr) */
664 ld t0,0*8(sp) /* restore used register */
671 aaddiu sp,sp,8*8 /* deallocate stack */
674 lw t0,FrameSize(pv) /* t0 = frame size */
675 aaddu sp,sp,t0 /* unwind stack */
676 move t0,sp /* t0 = pointer to save area */
677 lw t1,IsLeaf(pv) /* t1 = is leaf procedure */
678 bnez t1,ex_no_restore /* if (leaf) skip */
679 ld ra,-8(t0) /* restore ra */
680 aaddiu t0,t0,-8 /* t0-- */
682 move xpc,ra /* the new xpc is ra */
683 lw t1,IntSave(pv) /* t1 = saved int register count */
684 ala t2,ex_int2 /* t2 = current pc */
685 sll t1,t1,2 /* t1 = register count * 4 */
686 asubu t2,t2,t1 /* t2 = ex_int_sav - 4 * register count */
687 jr t2 /* jump to save position */
697 sll t1,t1,1 /* t1 = register count * 4 * 2 */
698 asubu t0,t0,t1 /* t0 = t0 - 8 * register count */
700 lw t1,FltSave(pv) /* t1 = saved flt register count */
701 ala t2,ex_flt2 /* t2 = current pc */
702 sll t1,t1,2 /* t1 = register count * 4 */
703 asubu t2,t2,t1 /* t2 = ex_int_sav - 4 * register count */
704 jr t2 /* jump to save position */
710 lw t0,0(ra) /* load instruction LDA PV,xxx(RA) */
712 sra t0,t0,16 /* isolate offset */
713 aaddu pv,t0,ra /* compute update address */
716 .end asm_handle_nat_exception
719 /********************* asm_check_clinit ****************************************
721 * Checks if class is initialized. If not, do it right now. *
723 *******************************************************************************/
725 .ent asm_check_clinit
728 lw itmp2,offclassinit(itmp1)
729 bnez itmp2,L_is_initialized
733 sd a0,1*8(sp) /* save argument registers for leaf funcs */
754 ld a0,1*8(sp) /* restore argument registers */
773 move itmp1,ra /* now patch the calling code */
774 daddiu itmp1,itmp1,-4*4 /* go back 4 instructions */
775 lui itmp2,0x1000 /* b */
776 daddiu itmp2,itmp2,3 /* jump over 3 instructions */
777 sw itmp2,0(itmp1) /* store the new branch: br +3 */
778 sw zero,4(itmp1) /* and a nop delay slot */
782 .end asm_check_clinit
785 /********************* function asm_builtin_monitorenter ***********************
787 * Does null check and calls monitorenter or throws an exception *
789 *******************************************************************************/
791 .ent asm_builtin_monitorenter
793 asm_builtin_monitorenter:
794 beqz a0,nb_monitorenter /* if (null) throw exception */
795 ala t9,builtin_monitorenter /* else call builtin_monitorenter */
801 ald a0,string_java_lang_NullPointerException
807 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
808 b asm_handle_nat_exception
810 .end asm_builtin_monitorenter
813 /********************* function asm_builtin_monitorexit ************************
815 * Does null check and calls monitorexit or throws an exception *
817 *******************************************************************************/
819 .ent asm_builtin_monitorexit
821 asm_builtin_monitorexit:
822 beqz a0,nb_monitorexit /* if (null) throw exception */
823 ala t9,builtin_monitorexit /* else call builtin_monitorexit */
829 ald a0,string_java_lang_NullPointerException
835 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
836 b asm_handle_nat_exception
838 .end asm_builtin_monitorexit
841 /************************ function asm_builtin_idiv ****************************
843 * Does null check and calls idiv or throws an exception *
845 *******************************************************************************/
847 .ent asm_builtin_idiv
850 beqz a1,nb_idiv /* if (null) throw exception */
851 ala itmp3,builtin_idiv /* else call builtin_idiv */
857 ald a0,string_java_lang_ArithmeticException
858 ald a1,string_java_lang_ArithmeticException_message
859 jal new_exception_message
864 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
865 b asm_handle_nat_exception
867 .end asm_builtin_idiv
870 /************************ function asm_builtin_ldiv ****************************
872 * Does null check and calls ldiv or throws an exception *
874 *******************************************************************************/
876 .ent asm_builtin_ldiv
879 beqz a1,nb_ldiv /* if (null) throw exception */
880 ala itmp3,builtin_ldiv /* else call builtin_ldiv */
886 ald a0,string_java_lang_ArithmeticException
887 ald a1,string_java_lang_ArithmeticException_message
888 jal new_exception_message
893 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
894 b asm_handle_nat_exception
896 .end asm_builtin_ldiv
899 /************************ function asm_builtin_irem ****************************
901 * Does null check and calls irem or throws an exception *
903 *******************************************************************************/
905 .ent asm_builtin_irem
908 beqz a1,nb_irem /* if (null) throw exception */
909 ala t9,builtin_irem /* else call builtin_irem */
915 ald a0,string_java_lang_ArithmeticException
916 ald a1,string_java_lang_ArithmeticException_message
917 jal new_exception_message
922 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
923 b asm_handle_nat_exception
925 .end asm_builtin_irem
928 /************************ function asm_builtin_lrem ****************************
930 * Does null check and calls lrem or throws an exception *
932 *******************************************************************************/
934 .ent asm_builtin_lrem
937 beqz a1,nb_lrem /* if (null) throw exception */
938 ala t9,builtin_lrem /* else call builtin_lrem */
944 ald a0,string_java_lang_ArithmeticException
945 ald a1,string_java_lang_ArithmeticException_message
946 jal new_exception_message
951 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
952 b asm_handle_nat_exception
954 .end asm_builtin_lrem
957 /******************* function asm_builtin_checkarraycast ***********************
959 * Does the cast check and eventually throws an exception *
961 *******************************************************************************/
963 .ent asm_builtin_checkarraycast
965 asm_builtin_checkarraycast:
966 aaddiu sp,sp,-16 /* allocate stack space */
967 sd ra,0(sp) /* save return address */
968 sd a0,8(sp) /* save object pointer */
969 jal builtin_checkarraycast /* builtin_checkarraycast */
970 beqz v0,nb_carray_throw /* if (false) throw exception */
971 ld ra,0(sp) /* restore return address */
972 ld v0,8(sp) /* return object pointer */
973 aaddiu sp,sp,16 /* deallocate stack */
977 ald a0,string_java_lang_ClassCastException
981 ld ra,0(sp) /* restore return address */
982 aaddiu sp,sp,16 /* free stack space */
983 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
984 b asm_handle_nat_exception
986 .end asm_builtin_checkarraycast
989 /********************* function asm_builtin_checkcast **************************
991 * Does the cast check and eventually throws an exception *
993 *******************************************************************************/
995 .ent asm_builtin_checkcast
997 asm_builtin_checkcast:
998 aaddiu sp,sp,-16 /* allocate stack space */
999 sd ra,0(sp) /* save return address */
1000 sd a0,8(sp) /* save object pointer */
1001 jal builtin_checkcast /* builtin_checkcast */
1002 beqz v0,nb_ccast_throw /* if (false) throw exception */
1003 ld ra,0(sp) /* restore return address */
1004 ld v0,8(sp) /* return object pointer */
1005 aaddiu sp,sp,16 /* deallocate stack */
1009 ald a0,string_java_lang_ClassCastException
1013 ld ra,0(sp) /* restore return address */
1014 aaddiu sp,sp,16 /* free stack space */
1015 aaddiu xpc,ra,-4 /* faulting address is return adress - 4*/
1016 b asm_handle_nat_exception
1018 .end asm_builtin_checkcast
1021 /******************* function asm_builtin_aastore ******************************
1023 * Does the cast check and eventually throws an exception *
1024 * a0 = arrayref, a1 = index, a2 = value *
1026 *******************************************************************************/
1028 .ent asm_builtin_aastore
1030 asm_builtin_aastore:
1031 beqz a0,nb_aastore_null /* if null pointer throw exception */
1032 lw t0,offarraysize(a0) /* load size */
1033 aaddiu sp,sp,-32 /* allocate stack space */
1034 sd ra,0(sp) /* save return address */
1035 asll t1,a1,ashift /* add index*8 to arrayref */
1036 aaddu t1,a0,t1 /* add index * ashift to arrayref */
1037 sltu t0,a1,t0 /* do bound check */
1038 beqz t0,nb_aastore_bound /* if out of bounds throw exception */
1039 move a1,a2 /* object is second argument */
1040 sd t1,8(sp) /* save store position */
1041 sd a1,16(sp) /* save object */
1042 jal builtin_canstore /* builtin_canstore(arrayref,object) */
1043 ld ra,0(sp) /* restore return address */
1044 ld a0,8(sp) /* restore store position */
1045 ld a1,16(sp) /* restore object */
1046 aaddiu sp,sp,32 /* free stack space */
1047 beqz v0,nb_aastore_store /* if (false) throw exception */
1048 ast a1,offobjarrdata(a0) /* store objectptr in array */
1054 ald a0,string_java_lang_NullPointerException
1060 move xpc,ra /* faulting address is return adress */
1061 b asm_handle_nat_exception
1066 ald a0,string_java_lang_ArrayIndexOutOfBoundsException
1067 jal new_exception_int /* a1 already contains the index */
1072 aaddiu sp,sp,32 /* free stack space */
1073 move xpc,ra /* faulting address is return adress */
1074 b asm_handle_nat_exception
1079 ald a0,string_java_lang_ArrayStoreException
1085 move xpc,ra /* faulting address is return adress */
1086 b asm_handle_nat_exception
1088 .end asm_builtin_aastore
1091 /******************* function asm_initialize_thread_stack **********************
1093 * u1* asm_initialize_thread_stack (void *func, u1 *stack); *
1095 * initialize a thread stack *
1097 *******************************************************************************/
1099 .ent asm_initialize_thread_stack
1101 asm_initialize_thread_stack:
1102 aaddiu a1,a1,-14*8 /* allocate save area */
1103 sd zero, 0*8(a1) /* s0 initalize thread area */
1104 sd zero, 1*8(a1) /* s1 */
1105 sd zero, 2*8(a1) /* s2 */
1106 sd zero, 3*8(a1) /* s3 */
1107 sd zero, 4*8(a1) /* s4 */
1108 sd zero, 5*8(a1) /* s5 */
1109 sd zero, 6*8(a1) /* s6 */
1110 sd zero, 7*8(a1) /* s7 */
1111 sd zero, 8*8(a1) /* s8 */
1112 sd zero, 9*8(a1) /* fs0 */
1113 sd zero,10*8(a1) /* fs1 */
1114 sd zero,11*8(a1) /* fs2 */
1115 sd zero,12*8(a1) /* fs3 */
1120 .end asm_initialize_thread_stack
1123 /******************* function asm_perform_threadswitch *************************
1125 * void asm_perform_threadswitch (u1 **from, u1 **to, u1 **stackTop); *
1127 * performs a threadswitch *
1129 *******************************************************************************/
1131 .ent asm_perform_threadswitch
1133 asm_perform_threadswitch:
1134 aaddiu sp,sp,-14*8 /* allocate new stack */
1135 sd s0, 0*8(sp) /* save saved registers of old thread */
1149 ast sp,0(a0) /* save old stack pointer */
1150 ast sp,0(a2) /* stackTop = old stack pointer */
1151 ald sp,0(a1) /* load new stack pointer */
1152 ld s0, 0*8(sp) /* load saved registers of new thread */
1166 aaddiu sp,sp,14*8 /* deallocate new stack */
1170 .end asm_perform_threadswitch
1173 /********************* function asm_switchstackandcall *************************
1175 * void asm_switchstackandcall (void *stack, void *func, void **stacktopsave); *
1177 * Switches to a new stack, calls a function and switches back. *
1178 * a0 new stack pointer *
1179 * a1 function pointer *
1180 * a2 pointer to variable where stack top should be stored *
1182 *******************************************************************************/
1184 .ent asm_switchstackandcall
1186 asm_switchstackandcall:
1187 aaddiu a0,a0,-16 /* allocate new stack */
1188 sd ra,0(a0) /* save return address on new stack */
1189 sd sp,8(a0) /* save old stack pointer on new stack */
1190 sd sp,0(a2) /* save old stack pointer to variable */
1191 move sp,a0 /* switch to new stack */
1195 jalr itmp3 /* and call function */
1197 ld ra,0(sp) /* load return address */
1198 ld sp,8(sp) /* switch to old stack */
1202 .end asm_switchstackandcall
1206 * These are local overrides for various environment variables in Emacs.
1207 * Please do not remove this and leave it at the end of the file, where
1208 * Emacs will automagically detect them.
1209 * ---------------------------------------------------------------------
1212 * indent-tabs-mode: t