1/* $OpenBSD: _setjmp.S,v 1.8 2018/01/08 16:44:32 visa Exp $ */ 2 3/* 4 * Copyright (c) 2002 Opsycon AB (www.opsycon.se / www.opsycon.com) 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Opsycon AB nor the names of its contributors 15 * may be used to endorse or promote products derived from this software 16 * without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 */ 31 32#include "SYS.h" 33#include <machine/regnum.h> 34#include <machine/setjmp.h> 35 36 .globl __jmpxor 37 38/* 39 * _setjmp, _longjmp (not restoring signal state) 40 * 41 * XXX FPSET should probably be taken from SR setting. hmmm... 42 * GPOFF and FRAMESIZE must be the same for both _setjmp and _longjmp! 43 * 44 */ 45 46FRAMESZ= MKFSIZ(0,4) 47GPOFF= FRAMESZ-2*REGSZ 48 49LEAF(_setjmp, FRAMESZ) 50 PTR_SUBU sp, FRAMESZ 51 SETUP_GP64(GPOFF, _setjmp) 52 .set noreorder 53 LI v0, 0xACEDBADE # sigcontext magic number 54 REG_S v0, _JB_REGS+ZERO*REGSZ(a0) 55 REG_S s0, _JB_REGS+S0*REGSZ(a0) 56 REG_S s1, _JB_REGS+S1*REGSZ(a0) 57 REG_S s2, _JB_REGS+S2*REGSZ(a0) 58 REG_S s3, _JB_REGS+S3*REGSZ(a0) 59 REG_S s4, _JB_REGS+S4*REGSZ(a0) 60 REG_S s5, _JB_REGS+S5*REGSZ(a0) 61 REG_S s6, _JB_REGS+S6*REGSZ(a0) 62 REG_S s7, _JB_REGS+S7*REGSZ(a0) 63 REG_S s8, _JB_REGS+S8*REGSZ(a0) 64 LA t0, __jmpxor # load cookie addr 65 REG_L v0, 0(t0) # load gp cookie 66 REG_L v1, GPOFF(sp) 67 xor v0, v0, v1 68 REG_S v0, _JB_REGS+GP*REGSZ(a0) 69 REG_L v0, REGSZ(t0) # load sp cookie over gp cookie 70 PTR_ADDU v1, sp, FRAMESZ 71 xor v0, v0, v1 72 REG_S v0, _JB_REGS+SP*REGSZ(a0) 73 REG_L t0, 2*REGSZ(t0) # load ra cookie over addr 74 xor t0, ra, t0 75 REG_S t0, _JB_PC(a0) 76 cfc1 t0, $31 # overwrite ra cookie 77#if _MIPS_FPSET == 32 78 sdc1 $f20, _JB_FPREGS+((F20-F0)*REGSZ)(a0) 79 sdc1 $f21, _JB_FPREGS+((F21-F0)*REGSZ)(a0) 80 sdc1 $f22, _JB_FPREGS+((F22-F0)*REGSZ)(a0) 81 sdc1 $f23, _JB_FPREGS+((F23-F0)*REGSZ)(a0) 82 sdc1 $f24, _JB_FPREGS+((F24-F0)*REGSZ)(a0) 83 sdc1 $f25, _JB_FPREGS+((F25-F0)*REGSZ)(a0) 84 sdc1 $f26, _JB_FPREGS+((F26-F0)*REGSZ)(a0) 85 sdc1 $f27, _JB_FPREGS+((F27-F0)*REGSZ)(a0) 86 sdc1 $f28, _JB_FPREGS+((F28-F0)*REGSZ)(a0) 87 sdc1 $f29, _JB_FPREGS+((F29-F0)*REGSZ)(a0) 88 sdc1 $f30, _JB_FPREGS+((F30-F0)*REGSZ)(a0) 89 sdc1 $f31, _JB_FPREGS+((F31-F0)*REGSZ)(a0) 90#else 91 swc1 $f20, _JB_FPREGS+((F20-F0)*REGSZ)(a0) 92 swc1 $f21, _JB_FPREGS+((F21-F0)*REGSZ)(a0) 93 swc1 $f22, _JB_FPREGS+((F22-F0)*REGSZ)(a0) 94 swc1 $f23, _JB_FPREGS+((F23-F0)*REGSZ)(a0) 95 swc1 $f24, _JB_FPREGS+((F24-F0)*REGSZ)(a0) 96 swc1 $f25, _JB_FPREGS+((F25-F0)*REGSZ)(a0) 97 swc1 $f26, _JB_FPREGS+((F26-F0)*REGSZ)(a0) 98 swc1 $f27, _JB_FPREGS+((F27-F0)*REGSZ)(a0) 99 swc1 $f28, _JB_FPREGS+((F28-F0)*REGSZ)(a0) 100 swc1 $f29, _JB_FPREGS+((F29-F0)*REGSZ)(a0) 101 swc1 $f30, _JB_FPREGS+((F30-F0)*REGSZ)(a0) 102 swc1 $f31, _JB_FPREGS+((F31-F0)*REGSZ)(a0) 103#endif 104 REG_S t0, _JB_FPREGS+((FSR-F0)*REGSZ)(a0) 105 RESTORE_GP64 106 PTR_ADDU sp, FRAMESZ 107 j ra 108 move v0, zero 109END_STRONG(_setjmp) 110 111LEAF(_longjmp, FRAMESZ) 112 PTR_SUBU sp, FRAMESZ 113 SETUP_GP64(GPOFF, _longjmp) 114 .set noreorder 115 REG_L v0, _JB_REGS+ZERO*REGSZ(a0) 116 bne v0, 0xACEDBADE, botch # jump if error 117 LA v0, __jmpxor # load cookie addr 118 REG_L v1, 2*REGSZ(v0) # load ra cookie 119 REG_L ra, _JB_PC(a0) 120 xor ra, ra, v1 121 REG_L s0, _JB_REGS+S0*REGSZ(a0) 122 REG_L s1, _JB_REGS+S1*REGSZ(a0) 123 REG_L s2, _JB_REGS+S2*REGSZ(a0) 124 REG_L s3, _JB_REGS+S3*REGSZ(a0) 125 REG_L s4, _JB_REGS+S4*REGSZ(a0) 126 REG_L s5, _JB_REGS+S5*REGSZ(a0) 127 REG_L s6, _JB_REGS+S6*REGSZ(a0) 128 REG_L s7, _JB_REGS+S7*REGSZ(a0) 129 REG_L s8, _JB_REGS+S8*REGSZ(a0) 130 REG_L v1, 0(v0) # load gp cookie over ra cookie 131 REG_L gp, _JB_REGS+GP*REGSZ(a0) 132 xor gp, gp, v1 133 REG_L v1, REGSZ(v0) # load sp cookie over gp cookie 134 REG_L sp, _JB_REGS+SP*REGSZ(a0) 135 xor sp, sp, v1 136 REG_L v1, _JB_FPREGS+((FSR-F0)*REGSZ)(a0) # overwrite sp cookie 137 ctc1 v1, $31 138#if _MIPS_FPSET == 32 139 ldc1 $f20, _JB_FPREGS+((F20-F0)*REGSZ)(a0) 140 ldc1 $f21, _JB_FPREGS+((F21-F0)*REGSZ)(a0) 141 ldc1 $f22, _JB_FPREGS+((F22-F0)*REGSZ)(a0) 142 ldc1 $f23, _JB_FPREGS+((F23-F0)*REGSZ)(a0) 143 ldc1 $f24, _JB_FPREGS+((F24-F0)*REGSZ)(a0) 144 ldc1 $f25, _JB_FPREGS+((F25-F0)*REGSZ)(a0) 145 ldc1 $f26, _JB_FPREGS+((F26-F0)*REGSZ)(a0) 146 ldc1 $f27, _JB_FPREGS+((F27-F0)*REGSZ)(a0) 147 ldc1 $f28, _JB_FPREGS+((F28-F0)*REGSZ)(a0) 148 ldc1 $f29, _JB_FPREGS+((F29-F0)*REGSZ)(a0) 149 ldc1 $f30, _JB_FPREGS+((F30-F0)*REGSZ)(a0) 150 ldc1 $f31, _JB_FPREGS+((F31-F0)*REGSZ)(a0) 151#else 152 lwc1 $f20, _JB_FPREGS+((F20-F0)*REGSZ)(a0) 153 lwc1 $f21, _JB_FPREGS+((F21-F0)*REGSZ)(a0) 154 lwc1 $f22, _JB_FPREGS+((F22-F0)*REGSZ)(a0) 155 lwc1 $f23, _JB_FPREGS+((F23-F0)*REGSZ)(a0) 156 lwc1 $f24, _JB_FPREGS+((F24-F0)*REGSZ)(a0) 157 lwc1 $f25, _JB_FPREGS+((F25-F0)*REGSZ)(a0) 158 lwc1 $f26, _JB_FPREGS+((F26-F0)*REGSZ)(a0) 159 lwc1 $f27, _JB_FPREGS+((F27-F0)*REGSZ)(a0) 160 lwc1 $f28, _JB_FPREGS+((F28-F0)*REGSZ)(a0) 161 lwc1 $f29, _JB_FPREGS+((F29-F0)*REGSZ)(a0) 162 lwc1 $f30, _JB_FPREGS+((F30-F0)*REGSZ)(a0) 163 lwc1 $f31, _JB_FPREGS+((F31-F0)*REGSZ)(a0) 164#endif 165 beql a1, zero, 1f 166 li a1, 1 # only executed if branch taken. 1671: 168 j ra 169 move v0, a1 170 171botch: 172 jal _libc_abort 173 nop 174 RESTORE_GP64 175 PTR_ADDU sp, FRAMESZ 176END_STRONG(_longjmp) 177 178