1 1.3 thorpej /* $NetBSD: compat_setjmp.S,v 1.3 2021/05/25 00:14:41 thorpej Exp $ */ 2 1.1 drochner 3 1.1 drochner /* 4 1.1 drochner * Copyright (c) 1994, 1995 Carnegie-Mellon University. 5 1.1 drochner * All rights reserved. 6 1.1 drochner * 7 1.1 drochner * Author: Chris G. Demetriou 8 1.1 drochner * 9 1.1 drochner * Permission to use, copy, modify and distribute this software and 10 1.1 drochner * its documentation is hereby granted, provided that both the copyright 11 1.1 drochner * notice and this permission notice appear in all copies of the 12 1.1 drochner * software, derivative works or modified versions, and any portions 13 1.1 drochner * thereof, and that both notices appear in supporting documentation. 14 1.1 drochner * 15 1.1 drochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 1.1 drochner * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 1.1 drochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 1.1 drochner * 19 1.1 drochner * Carnegie Mellon requests users of this software to return to 20 1.1 drochner * 21 1.1 drochner * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 22 1.1 drochner * School of Computer Science 23 1.1 drochner * Carnegie Mellon University 24 1.1 drochner * Pittsburgh PA 15213-3890 25 1.1 drochner * 26 1.1 drochner * any improvements or extensions that they make and grant Carnegie the 27 1.1 drochner * rights to redistribute these changes. 28 1.1 drochner */ 29 1.1 drochner 30 1.1 drochner #include <machine/asm.h> 31 1.1 drochner 32 1.1 drochner /* 33 1.1 drochner * C library -- setjmp, longjmp 34 1.1 drochner * 35 1.1 drochner * longjmp(a,v) 36 1.1 drochner * will generate a "return(v)" from 37 1.1 drochner * the last call to 38 1.1 drochner * setjmp(a) 39 1.1 drochner * by restoring registers from the stack, 40 1.1 drochner * and the previous signal state. 41 1.1 drochner */ 42 1.1 drochner 43 1.1 drochner .set noreorder 44 1.1 drochner 45 1.1 drochner LEAF(setjmp, 1) 46 1.1 drochner LDGP(pv) 47 1.1 drochner stq ra, (2 * 8)(a0) /* sc_pc = return address */ 48 1.1 drochner stq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 49 1.1 drochner stq s1, ((10 + 4) * 8)(a0) 50 1.1 drochner stq s2, ((11 + 4) * 8)(a0) 51 1.1 drochner stq s3, ((12 + 4) * 8)(a0) 52 1.1 drochner stq s4, ((13 + 4) * 8)(a0) 53 1.1 drochner stq s5, ((14 + 4) * 8)(a0) 54 1.1 drochner stq s6, ((15 + 4) * 8)(a0) 55 1.1 drochner stq ra, ((26 + 4) * 8)(a0) 56 1.1 drochner stq sp, ((30 + 4) * 8)(a0) 57 1.1 drochner 58 1.1 drochner /* 59 1.1 drochner * get signal information 60 1.1 drochner */ 61 1.1 drochner mov a0, s0 /* squirrel away ptr to sc */ 62 1.1 drochner 63 1.1 drochner /* see what's blocked */ 64 1.1 drochner mov zero, a0 65 1.1 drochner CALL(sigblock) /* see what's blocked */ 66 1.1 drochner stq v0, (1 * 8)(s0) /* and remember it in sc_mask */ 67 1.1 drochner 68 1.1 drochner lda sp, -24(sp) /* sizeof struct sigaltstack */ 69 1.1 drochner mov zero, a0 70 1.1 drochner mov sp, a1 71 1.1 drochner CALL(__sigaltstack14) 72 1.1 drochner ldl t0, 16(sp) /* offset of ss_flags */ 73 1.1 drochner lda sp, 24(sp) /* sizeof struct sigaltstack */ 74 1.1 drochner ldq ra, ((26 + 4) * 8)(s0) /* restore return address */ 75 1.1 drochner blt v0, botch /* check for error */ 76 1.1 drochner and t0, 0x1, t0 /* get SA_ONSTACK flag */ 77 1.1 drochner stq t0, (0 * 8)(s0) /* and save it in sc_onstack */ 78 1.1 drochner /* 79 1.1 drochner * Restore old s0 and a0, and continue saving registers 80 1.1 drochner */ 81 1.1 drochner mov s0, a0 82 1.1 drochner ldq s0, (( 9 + 4) * 8)(a0) 83 1.1 drochner 84 1.2 christos ldq t0, magic /* sigcontext magic number */ 85 1.1 drochner stq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 86 1.1 drochner /* Too bad we can't check if we actually used FP */ 87 1.1 drochner ldiq t0, 1 88 1.1 drochner stq t0, (36 * 8)(a0) /* say we've used FP. */ 89 1.1 drochner stt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 90 1.1 drochner stt fs1, ((3 + 37) * 8)(a0) 91 1.1 drochner stt fs2, ((4 + 37) * 8)(a0) 92 1.1 drochner stt fs3, ((5 + 37) * 8)(a0) 93 1.1 drochner stt fs4, ((6 + 37) * 8)(a0) 94 1.1 drochner stt fs5, ((7 + 37) * 8)(a0) 95 1.1 drochner stt fs6, ((8 + 37) * 8)(a0) 96 1.1 drochner stt fs7, ((9 + 37) * 8)(a0) 97 1.1 drochner mf_fpcr ft0 /* get FP control reg */ 98 1.1 drochner stt ft0, (69 * 8)(a0) /* and store it in sc_fpcr */ 99 1.1 drochner stq zero, (70 * 8)(a0) /* FP software control XXX */ 100 1.1 drochner stq zero, (71 * 8)(a0) /* sc_reserved[0] */ 101 1.1 drochner stq zero, (72 * 8)(a0) /* sc_reserved[1] */ 102 1.1 drochner stq zero, (73 * 8)(a0) /* sc_xxx[0] */ 103 1.1 drochner stq zero, (74 * 8)(a0) /* sc_xxx[1] */ 104 1.1 drochner stq zero, (75 * 8)(a0) /* sc_xxx[2] */ 105 1.1 drochner stq zero, (76 * 8)(a0) /* sc_xxx[3] */ 106 1.1 drochner stq zero, (77 * 8)(a0) /* sc_xxx[4] */ 107 1.1 drochner stq zero, (78 * 8)(a0) /* sc_xxx[5] */ 108 1.1 drochner stq zero, (79 * 8)(a0) /* sc_xxx[6] */ 109 1.1 drochner stq zero, (80 * 8)(a0) /* sc_xxx[7] */ 110 1.1 drochner 111 1.1 drochner mov zero, v0 /* return zero */ 112 1.1 drochner RET 113 1.1 drochner END(setjmp) 114 1.1 drochner 115 1.1 drochner LEAF(longjmp, 2) 116 1.1 drochner LDGP(pv) 117 1.3 thorpej bne a1, 1f /* val != 0, just go */ 118 1.3 thorpej ldiq a1, 1 /* val = 1 otherwise */ 119 1.3 thorpej 1: stq a1, (( 0 + 4) * 8)(a0) /* save return value */ 120 1.1 drochner CALL(sigreturn) /* use sigreturn to return */ 121 1.1 drochner 122 1.1 drochner botch: 123 1.1 drochner CALL(longjmperror) 124 1.1 drochner CALL(abort) 125 1.1 drochner RET /* "can't" get here... */ 126 1.2 christos magic: 127 1.2 christos .quad 0xacedbade /* sigcontext magic number */ 128 1.1 drochner END(longjmp) 129