Path: blob/main/sys/contrib/openzfs/module/lua/setjmp/setjmp_mips.S
48534 views
// SPDX-License-Identifier: BSD-3-Clause1/*2* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20093* The President and Fellows of Harvard College.4* Copyright (c) 2017 MIPS Technologies, Inc.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <asm/asm.h>32#include <asm/regdef.h>3334/*35* setjmp and longjmp for MIPS.36*/3738.text39.set noreorder4041/*42* int setjmp(jmp_buf jb);43*44* Save the current state so we can return again from the call later45* if/when longjmp is called. (If the function that called setjmp46* returns before longjmp is called, the results are undefined. We47* only need to save registers, not the whole contents of the stack.)48*/49LEAF(setjmp)50/*51* jmp_buf is in a0. We need to save s0-s8, sp, gp, and ra in it.52* Don't store more registers without adjusting machine/setjmp.h.53*/5455REG_S sp, 0(a0) /* save registers */56REG_S ra, 1*SZREG(a0)57REG_S gp, 2*SZREG(a0)58REG_S s0, 3*SZREG(a0)59REG_S s1, 4*SZREG(a0)60REG_S s2, 5*SZREG(a0)61REG_S s3, 6*SZREG(a0)62REG_S s4, 7*SZREG(a0)63REG_S s5, 8*SZREG(a0)64REG_S s6, 9*SZREG(a0)65REG_S s7, 10*SZREG(a0)66REG_S s8, 11*SZREG(a0)6768jr ra /* done */69move v0, zero /* return 0 (in delay slot) */70END(setjmp)717273/*74* void longjmp(jmp_buf jb, int code);75*/76LEAF(longjmp)77/*78* jmp_buf is in a0. Return code is in a1.79* We need to restore s0-s8, sp, gp, and ra from the jmp_buf.80* The return code is forced to 1 if 0 is passed in.81*/8283sltiu t0, a1, 1 /* set t0 to 1 if return code is 0... otherwise 0 */84addu a1, a1, t0 /* update the return code */8586REG_L sp, 0(a0) /* restore registers */87REG_L ra, 1*SZREG(a0)88REG_L gp, 2*SZREG(a0)89REG_L s0, 3*SZREG(a0)90REG_L s1, 4*SZREG(a0)91REG_L s2, 5*SZREG(a0)92REG_L s3, 6*SZREG(a0)93REG_L s4, 7*SZREG(a0)94REG_L s5, 8*SZREG(a0)95REG_L s6, 9*SZREG(a0)96REG_L s7, 10*SZREG(a0)97REG_L s8, 11*SZREG(a0)9899jr ra /* return, to where setjmp was called from */100move v0, a1 /* set return value */101END(longjmp)102103#ifdef __ELF__104.section .note.GNU-stack,"",%progbits105#endif106107108