1/* $OpenBSD: sigsetjmp.S,v 1.8 2022/06/10 01:56:02 guenther Exp $ */ 2/* 3 * Copyright (c) 1996 Dale Rahn. All rights reserved. 4 * 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "SYS.h" 28 29#define JMP_sigflag 0x00 30#define JMP_r1 0x04 31#define JMP_r14 0x08 32#define JMP_r15 0x0c 33#define JMP_r16 0x10 34#define JMP_r17 0x14 35#define JMP_r18 0x18 36#define JMP_r19 0x1c 37#define JMP_r20 0x20 38#define JMP_r21 0x24 39#define JMP_r22 0x28 40#define JMP_r23 0x2c 41#define JMP_r24 0x30 42#define JMP_r25 0x34 43#define JMP_r26 0x38 44#define JMP_r27 0x3c 45#define JMP_r28 0x40 46#define JMP_r29 0x44 47#define JMP_r30 0x48 48#define JMP_r31 0x4c 49#define JMP_lr 0x50 50#define JMP_cr 0x54 51#define JMP_ctr 0x58 52#define JMP_xer 0x5c 53#define JMP_sigmask 0x60 54 55 .extern __jmpxor 56 57/* int sigsetjmp(sigjmp_buf env, int savemask) */ 58ENTRY(sigsetjmp) 59 mr 5, 3 /* save jmpbuf addr in r5 */ 60 stw 4, JMP_sigflag(5) 61 or. 4, 4, 4 62 beq 1f 63 li 3, 1 /* how = SIG_BLOCK */ 64 li 4, 0 /* oset = empty */ 65 li 0, SYS_sigprocmask 66 sc 67 stw 3, JMP_sigmask(5) 681: mflr 6 69 bcl 20, 31, 2f 702: mflr 7 71 addis 7, 7, __jmpxor-2b@ha 72 addi 7, 7, __jmpxor-2b@l 73 mtlr 6 74 lwz 0, 0(7) /* xor for r1 */ 75 lwz 7, 4(7) /* xor for lr, overwrite addr */ 76 77 /* r1, r14-r31 */ 78 xor 0, 0, 1 /* use and overwrite the r1 xor */ 79 /* "mflr 6" done at 1: above */ 80 xor 7, 6, 7 /* use and overwrite the lr xor */ 81 stw 7, JMP_lr(5) 82 stw 0, JMP_r1 (5) 83 stw 14, JMP_r14(5) 84 stw 15, JMP_r15(5) 85 stw 16, JMP_r16(5) 86 stw 17, JMP_r17(5) 87 stw 18, JMP_r18(5) 88 stw 19, JMP_r19(5) 89 stw 20, JMP_r20(5) 90 stw 21, JMP_r21(5) 91 stw 22, JMP_r22(5) 92 stw 23, JMP_r23(5) 93 stw 24, JMP_r24(5) 94 stw 25, JMP_r25(5) 95 stw 26, JMP_r26(5) 96 stw 27, JMP_r27(5) 97 stw 28, JMP_r28(5) 98 stw 29, JMP_r29(5) 99 stw 30, JMP_r30(5) 100 stw 31, JMP_r31(5) 101 /* cr, lr, ctr, xer */ 102 mfcr 0 103 stw 0, JMP_cr(5) 104 mfctr 0 105 stw 0, JMP_ctr(5) 106 mfxer 0 107 stw 0, JMP_xer(5) 108 /* f14-f31, fpscr */ 109 li 3, 0 110 blr 111END(sigsetjmp) 112 113 114/* int siglongjmp(sigjmp_buf env, int val) */ 115ENTRY(siglongjmp) 116 mr 5, 3 /* save jmpbuf addr in r5 */ 117 mr 6, 4 /* save val in r6 */ 118 lwz 4, JMP_sigflag(5) /* do we need to restore sigmask? */ 119 or. 4, 4, 4 120 beq 1f 121 122 li 3, 3 /* how = SIG_SETMASK */ 123 lwz 4, JMP_sigmask(5) /* oset from the jmpbuf */ 124 li 0, SYS_sigprocmask 125 sc 126 1271: bcl 20, 31, 2f 1282: mflr 9 129 addis 9, 9, __jmpxor-2b@ha 130 addi 9, 9, __jmpxor-2b@l 131 lwz 8, 0(9) /* xor for r1 */ 132 lwz 9, 4(9) /* xor for lr, overwrite addr */ 133 134 /* r1, r14-r31 */ 135 lwz 0, JMP_r1(5) 136 xor 1, 0, 8 /* use the r1 xor */ 137 lwz 14, JMP_r14(5) 138 lwz 15, JMP_r15(5) 139 lwz 16, JMP_r16(5) 140 lwz 17, JMP_r17(5) 141 lwz 18, JMP_r18(5) 142 lwz 19, JMP_r19(5) 143 lwz 20, JMP_r20(5) 144 lwz 21, JMP_r21(5) 145 lwz 22, JMP_r22(5) 146 lwz 23, JMP_r23(5) 147 lwz 24, JMP_r24(5) 148 lwz 25, JMP_r25(5) 149 lwz 26, JMP_r26(5) 150 lwz 27, JMP_r27(5) 151 lwz 28, JMP_r28(5) 152 lwz 29, JMP_r29(5) 153 lwz 30, JMP_r30(5) 154 lwz 31, JMP_r31(5) 155 /* cr, lr, ctr, xer */ 156 lwz 8, JMP_cr(5) /* overwrite the r1 xor */ 157 mtcr 8 158 lwz 0, JMP_lr(5) 159 xor 0, 0, 9 /* use the lr xor */ 160 mtlr 0 161 lwz 9, JMP_ctr(5) /* overwrite the lr xor */ 162 mtctr 9 163 lwz 0, JMP_xer(5) 164 mtxer 0 165 /* f14-f31, fpscr */ 166 167 /* if r6 == 0, return 1, not 0 */ 168 mr 3, 6 169 cmpwi 6, 0 170 bnelr 171 li 3, 1 172 blr 173END(siglongjmp) 174