/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829/*30* setjmp and longjmp for MIPS.31*/3233#include <kern/mips/regdefs.h>3435.text36.set noreorder3738/*39* int setjmp(jmp_buf jb);40*41* Save the current state so we can return again from the call later42* if/when longjmp is called. (If the function that called setjmp43* returns before longjmp is called, the results are undefined. We44* only need to save registers, not the whole contents of the stack.)45*/4647.globl setjmp48.type setjmp,@function49.ent setjmp50setjmp:51/*52* jmp_buf is in a0. We need to save s0-s8, sp, and ra in it.53* Don't store more registers without adjusting machine/setjmp.h.54*/5556sw sp, 0(a0) /* save registers */57sw ra, 4(a0)58sw s0, 8(a0)59sw s1, 12(a0)60sw s2, 16(a0)61sw s3, 20(a0)62sw s4, 24(a0)63sw s5, 28(a0)64sw s6, 32(a0)65sw s7, 36(a0)66sw s8, 40(a0)6768j ra /* done */69li v0, 0 /* return 0 (in delay slot) */70.end setjmp717273/*74* void longjmp(jmp_buf jb, int code);75*/76.globl longjmp77.type longjmp,@function78.ent longjmp79longjmp:80/*81* jmp_buf is in a0. Return code is in a1.82* We need to restore s0-s8, sp, and ra from the jmp_buf.83* The return code is forced to 1 if 0 is passed in.84*/8586sltiu t0, a1, 1 /* set t0 to 1 if return code is 0... otherwise 0 */87addu a1, a1, t0 /* update the return code */8889lw sp, 0(a0) /* restore registers */90lw ra, 4(a0)91lw s0, 8(a0)92lw s1, 12(a0)93lw s2, 16(a0)94lw s3, 20(a0)95lw s4, 24(a0)96lw s5, 28(a0)97lw s6, 32(a0)98lw s7, 36(a0)99lw s8, 40(a0)100101j ra /* return, to where setjmp was called from */102move v0, a1 /* set return value */103.end longjmp104105106