1*83762a71Sderaadt/* $OpenBSD: setjmp.S,v 1.12 2023/12/10 16:45:51 deraadt Exp $ */ 2042d31a2Smickey 3042d31a2Smickey/*- 4042d31a2Smickey * Copyright (c) 1990 The Regents of the University of California. 5042d31a2Smickey * All rights reserved. 6042d31a2Smickey * 7042d31a2Smickey * This code is derived from software contributed to Berkeley by 8042d31a2Smickey * the Systems Programming Group of the University of Utah Computer 9042d31a2Smickey * Science Department. 10042d31a2Smickey * 11042d31a2Smickey * Redistribution and use in source and binary forms, with or without 12042d31a2Smickey * modification, are permitted provided that the following conditions 13042d31a2Smickey * are met: 14042d31a2Smickey * 1. Redistributions of source code must retain the above copyright 15042d31a2Smickey * notice, this list of conditions and the following disclaimer. 16042d31a2Smickey * 2. Redistributions in binary form must reproduce the above copyright 17042d31a2Smickey * notice, this list of conditions and the following disclaimer in the 18042d31a2Smickey * documentation and/or other materials provided with the distribution. 196580fee3Smillert * 3. Neither the name of the University nor the names of its contributors 20042d31a2Smickey * may be used to endorse or promote products derived from this software 21042d31a2Smickey * without specific prior written permission. 22042d31a2Smickey * 23042d31a2Smickey * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24042d31a2Smickey * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25042d31a2Smickey * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26042d31a2Smickey * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27042d31a2Smickey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28042d31a2Smickey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29042d31a2Smickey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30042d31a2Smickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31042d31a2Smickey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32042d31a2Smickey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33042d31a2Smickey * SUCH DAMAGE. 34042d31a2Smickey */ 35042d31a2Smickey 3655e758cbSguenther#include "SYS.h" 3755e758cbSguenther 3855e758cbSguenther .section .openbsd.randomdata,"aw",@progbits 398a57d2a8Sguenther .align 4 4055e758cbSguenther.L__jmpxor 4155e758cbSguenther .zero 4*2 ; (r2/rp, r30/sp) 42042d31a2Smickey 43042d31a2Smickey/* 44042d31a2Smickey * C library -- setjmp, longjmp 45042d31a2Smickey * 46042d31a2Smickey * longjmp(a,v) 47042d31a2Smickey * will generate a "return(v)" from 48042d31a2Smickey * the last call to 49042d31a2Smickey * setjmp(a) 50042d31a2Smickey * by restoring registers from the stack, 51042d31a2Smickey * and a struct sigcontext, see <signal.h> 52042d31a2Smickey */ 53042d31a2Smickey 54042d31a2SmickeyENTRY(sigsetjmp, 64) 55f06eeefaSmickey sub,<> %r0, %arg1, %r0 5655e758cbSguenther b .L_setjmp$dosaves 57042d31a2Smickey stw %arg1, 44(%arg0) ; last of reserved words 58042d31a2Smickey 59042d31a2SmickeyALTENTRY(setjmp) 6055e758cbSguenther copy %arg0, %arg2 ; save jmpbuf in %arg2 61042d31a2Smickey 6255e758cbSguenther ldi 1, %arg0 ; how = SIG_BLOCK 6355e758cbSguenther copy %r0, %arg1 ; set = empty 6455e758cbSguenther stw %rp, HPPA_FRAME_ERP(%sr0,%sp) 6555e758cbSguenther ldil L%SYSCALLGATE, %r1 66*83762a71Sderaadt99: ble 4(%sr7, %r1) 67*83762a71Sderaadt PINSYSCALL(SYS_sigprocmask, 99b) 6855e758cbSguenther ldi SYS_sigprocmask, %t1 6955e758cbSguenther ldw HPPA_FRAME_ERP(%sr0,%sp), %rp 70042d31a2Smickey 7155e758cbSguenther copy %arg2, %arg0 ; restore jmpbuf to %arg0 72042d31a2Smickey stw %ret0, 4(%arg0) ; mask 73042d31a2Smickey 74042d31a2SmickeyALTENTRY(_setjmp) 7555e758cbSguenther.L_setjmp$dosaves 7655e758cbSguenther#ifdef __PIC__ 7755e758cbSguenther addil LT%.L__jmpxor, %r19 7855e758cbSguenther ldw RT%.L__jmpxor(%r1), %t2 7955e758cbSguenther#else 8055e758cbSguenther ldil L%.L__jmpxor, %t1 8155e758cbSguenther ldo R%.L__jmpxor(%t1), %t2 8255e758cbSguenther#endif 8355e758cbSguenther ldw 0(%t2), %t1 ; xor for r2/rp 8455e758cbSguenther ldw 4(%t2), %t2 ; xor for r30/sp, overwrite address 8555e758cbSguenther 8655e758cbSguenther xor %sp, %t2, %t2 8755e758cbSguenther stw %t2, 12(%arg0) ; sc.sc_sp = %sp 8855e758cbSguenther xor %rp, %t1, %t1 8955e758cbSguenther stw %t1, 20(%arg0) ; sc.sc_pcoqh = %rp 9055e758cbSguenther copy %r0, %t1 9155e758cbSguenther copy %r0, %t2 92042d31a2Smickey 93042d31a2Smickey /* We store all callee-saved registers after the sigcontext. */ 94042d31a2Smickey ldo 48(%arg0), %r1 ; offset to after sc 95042d31a2Smickey stwm %r3, 4(%r1) 96042d31a2Smickey stwm %r4, 4(%r1) 97042d31a2Smickey stwm %r5, 4(%r1) 98042d31a2Smickey stwm %r6, 4(%r1) 99042d31a2Smickey stwm %r7, 4(%r1) 100042d31a2Smickey stwm %r8, 4(%r1) 101042d31a2Smickey stwm %r9, 4(%r1) 102042d31a2Smickey stwm %r10, 4(%r1) 103042d31a2Smickey stwm %r11, 4(%r1) 104042d31a2Smickey stwm %r12, 4(%r1) 105042d31a2Smickey stwm %r13, 4(%r1) 106042d31a2Smickey stwm %r14, 4(%r1) 107042d31a2Smickey stwm %r15, 4(%r1) 108042d31a2Smickey stwm %r16, 4(%r1) 109042d31a2Smickey stwm %r17, 4(%r1) 110042d31a2Smickey stwm %r18, 4(%r1) 111042d31a2Smickey 112042d31a2Smickey /* Return 0. */ 113042d31a2Smickey bv %r0(%rp) 114042d31a2Smickey copy %r0, %ret0 11555e758cbSguentherEXIT(sigsetjmp) 11655e758cbSguenther .size _setjmp, . - _setjmp 11755e758cbSguenther .size setjmp, . - setjmp 118042d31a2Smickey 119042d31a2SmickeyENTRY(siglongjmp,64) 120042d31a2Smickey ldw 44(%arg0), %arg2 121f06eeefaSmickey sub,<> %r0, %arg2, %r0 12255e758cbSguenther b .L_longjmp$restores 1236663b7fcSmickey nop 124042d31a2Smickey 125042d31a2SmickeyALTENTRY(longjmp) 12655e758cbSguenther copy %arg1, %arg3 ; save val in %arg3 12755e758cbSguenther copy %arg0, %arg2 ; save jmpbuf in %arg2 128042d31a2Smickey 12955e758cbSguenther ldw 4(%arg0), %arg1 ; set from jumpbuf 13055e758cbSguenther ldi 3, %arg0 ; how = SIG_SETMASK 13155e758cbSguenther stw %rp, HPPA_FRAME_ERP(%sr0,%sp) 13255e758cbSguenther ldil L%SYSCALLGATE, %r1 133*83762a71Sderaadt98: ble 4(%sr7, %r1) 134*83762a71Sderaadt PINSYSCALL(SYS_sigprocmask, 98b) 13555e758cbSguenther ldi SYS_sigprocmask, %t1 13655e758cbSguenther ldw HPPA_FRAME_ERP(%sr0,%sp), %rp 137042d31a2Smickey 13855e758cbSguenther copy %arg2, %arg0 ; restore jmpbuf to %arg0 13955e758cbSguenther copy %arg3, %arg1 ; restore val to %arg1 140042d31a2Smickey 141042d31a2SmickeyALTENTRY(_longjmp) 14255e758cbSguenther.L_longjmp$restores 143042d31a2Smickey /* restore callee-saved registers */ 144042d31a2Smickey ldo 48(%arg0), %r1 145042d31a2Smickey ldwm 4(%r1), %r3 146042d31a2Smickey ldwm 4(%r1), %r4 147042d31a2Smickey ldwm 4(%r1), %r5 148042d31a2Smickey ldwm 4(%r1), %r6 149042d31a2Smickey ldwm 4(%r1), %r7 150042d31a2Smickey ldwm 4(%r1), %r8 151042d31a2Smickey ldwm 4(%r1), %r9 152042d31a2Smickey ldwm 4(%r1), %r10 153042d31a2Smickey ldwm 4(%r1), %r11 154042d31a2Smickey ldwm 4(%r1), %r12 155042d31a2Smickey ldwm 4(%r1), %r13 156042d31a2Smickey ldwm 4(%r1), %r14 157042d31a2Smickey ldwm 4(%r1), %r15 158042d31a2Smickey ldwm 4(%r1), %r16 159042d31a2Smickey ldwm 4(%r1), %r17 160042d31a2Smickey ldwm 4(%r1), %r18 161042d31a2Smickey 162042d31a2Smickey /* restore the rest */ 16355e758cbSguenther#ifdef __PIC__ 16455e758cbSguenther addil LT%.L__jmpxor, %r19 16555e758cbSguenther ldw RT%.L__jmpxor(%r1), %t2 16655e758cbSguenther#else 16755e758cbSguenther ldil L%.L__jmpxor, t1 16855e758cbSguenther ldo R%.L__jmpxor(t1), t2 16955e758cbSguenther#endif 17055e758cbSguenther ldw 0(t2), t1 ; xor for r2/rp 17155e758cbSguenther ldw 4(t2), t2 ; xor for r30/sp, overwrite address 17255e758cbSguenther 17355e758cbSguenther ldw 12(%arg0), %r1 17455e758cbSguenther xor %r1, %t2, %sp 17555e758cbSguenther ldw 20(%arg0), %r1 17655e758cbSguenther xor %r1, %t1, %rp 17755e758cbSguenther copy %r0, %t1 ; overwrite the cookies 17855e758cbSguenther copy %r0, %t2 1792278e7cfSmickey sub,<> %arg1, %r0, %r0 1802278e7cfSmickey ldo 1(%arg1), %arg1 181042d31a2Smickey bv %r0(%rp) 182042d31a2Smickey copy %arg1, %ret0 18355e758cbSguentherEXIT(siglongjmp) 18455e758cbSguenther .size _longjmp, . - _longjmp 18555e758cbSguenther .size longjmp, . - longjmp 186042d31a2Smickey 187042d31a2Smickey .end 188