1 /* $NetBSD: signal.h,v 1.19 2003/04/28 23:16:21 bjh21 Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)signal.h 8.1 (Berkeley) 6/10/93 39 */ 40 41 #ifndef _MIPS_SIGNAL_H_ 42 #define _MIPS_SIGNAL_H_ 43 44 #include <sys/featuretest.h> 45 46 #include <machine/cdefs.h> /* for API selection */ 47 48 #if !defined(__ASSEMBLER__) 49 50 /* 51 * Machine-dependent signal definitions 52 */ 53 54 typedef int sig_atomic_t; 55 56 #if defined(_NETBSD_SOURCE) 57 /* 58 * Information pushed on stack when a signal is delivered. 59 * This is used by the kernel to restore state following 60 * execution of the signal handler. It is also made available 61 * to the handler to allow it to restore state properly if 62 * a non-standard exit is performed. 63 * 64 * sizeof(sigcontext) = 45 * sizeof(int) + 35 * sizeof(mips_reg_t) 65 */ 66 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 67 struct sigcontext13 { 68 int sc_onstack; /* sigstack state to restore */ 69 int sc_mask; /* signal mask to restore (old style) */ 70 mips_reg_t sc_pc; /* pc at time of signal */ 71 mips_reg_t sc_regs[32]; /* processor regs 0 to 31 */ 72 mips_reg_t mullo, mulhi;/* mullo and mulhi registers... */ 73 int sc_fpused; /* fp has been used */ 74 int sc_fpregs[33]; /* fp regs 0 to 31 and csr */ 75 int sc_fpc_eir; /* floating point exception instruction reg */ 76 int sc_xxx[8]; /* XXX reserved */ 77 }; 78 #endif /* __LIBC12_SOURCE__ || _KERNEL */ 79 80 struct sigcontext { 81 int sc_onstack; /* sigstack state to restore */ 82 int __sc_mask13; /* signal mask to restore (old style) */ 83 mips_reg_t sc_pc; /* pc at time of signal */ 84 mips_reg_t sc_regs[32]; /* processor regs 0 to 31 */ 85 mips_reg_t mullo, mulhi;/* mullo and mulhi registers... */ 86 int sc_fpused; /* fp has been used */ 87 int sc_fpregs[33]; /* fp regs 0 to 31 and csr */ 88 int sc_fpc_eir; /* floating point exception instruction reg */ 89 int sc_xxx[8]; /* XXX reserved */ 90 sigset_t sc_mask; /* signal mask to restore (new style) */ 91 }; 92 93 /* 94 * The following macros are used to convert from a ucontext to sigcontext, 95 * and vice-versa. This is for building a sigcontext to deliver to old-style 96 * signal handlers, and converting back (in the event the handler modifies 97 * the context). 98 */ 99 #define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \ 100 do { \ 101 (sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_EPC]; \ 102 memcpy((sc)->sc_regs, (uc)->uc_mcontext.__gregs, \ 103 sizeof((sc)->sc_regs)); \ 104 (sc)->mullo = (uc)->uc_mcontext.__gregs[_REG_MDLO]; \ 105 (sc)->mulhi = (uc)->uc_mcontext.__gregs[_REG_MDHI]; \ 106 \ 107 if ((uc)->uc_flags & _UC_FPU) { \ 108 memcpy(&(sc)->sc_fpregs, \ 109 &(uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs32, \ 110 sizeof((uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs32)); \ 111 (sc)->sc_fpregs[32] = \ 112 (uc)->uc_mcontext.__fpregs.__fp_csr; \ 113 (sc)->sc_fpc_eir = 0; /* XXX */ \ 114 (sc)->sc_fpused = 1; \ 115 } else \ 116 (sc)->sc_fpused = 0; \ 117 } while (/*CONSTCOND*/0) 118 119 #define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \ 120 do { \ 121 (uc)->uc_mcontext.__gregs[_REG_EPC] = (sc)->sc_pc; \ 122 memcpy((uc)->uc_mcontext.__gregs, (sc)->sc_regs, \ 123 sizeof((sc)->sc_regs)); \ 124 (uc)->uc_mcontext.__gregs[_REG_MDLO] = (sc)->mullo; \ 125 (uc)->uc_mcontext.__gregs[_REG_MDHI] = (sc)->mulhi; \ 126 \ 127 if ((sc)->sc_fpused) { \ 128 memcpy(&(uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs32, \ 129 &(sc)->sc_fpregs, \ 130 sizeof((uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs32)); \ 131 (uc)->uc_mcontext.__fpregs.__fp_csr = \ 132 (sc)->sc_fpregs[32]; \ 133 (uc)->uc_flags |= _UC_FPU; \ 134 } else \ 135 (uc)->uc_flags &= ~_UC_FPU; \ 136 } while (/*CONSTCOND*/0) 137 138 #endif /* _NETBSD_SOURCE */ 139 140 #endif /* !_LANGUAGE_ASSEMBLY */ 141 #if !defined(_KERNEL) 142 /* 143 * Hard code these to make people think twice about breaking compatibility. 144 * These macros are generated independently for the kernel. 145 */ 146 #if !defined(_MIPS_BSD_API) || _MIPS_BSD_API == _MIPS_BSD_API_LP32 147 #define _OFFSETOF_SC_REGS 12 148 #define _OFFSETOF_SC_FPREGS 152 149 #define _OFFSETOF_SC_MASK 320 150 #else 151 #define _OFFSETOF_SC_REGS 16 152 #define _OFFSETOF_SC_FPREGS 292 153 #define _OFFSETOF_SC_MASK 460 154 #endif 155 #endif /* !_KERNEL */ 156 #endif /* !_MIPS_SIGNAL_H_ */ 157