1 /* $NetBSD: signal.h,v 1.7 2003/04/28 23:16:16 bjh21 Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30 #ifndef _ALPHA_SIGNAL_H_ 31 #define _ALPHA_SIGNAL_H_ 32 33 #include <sys/featuretest.h> 34 35 typedef long sig_atomic_t; 36 37 #if defined(_NETBSD_SOURCE) 38 /* 39 * Information pushed on stack when a signal is delivered. 40 * This is used by the kernel to restore state following 41 * execution of the signal handler. It is also made available 42 * to the handler to allow it to restore state properly if 43 * a non-standard exit is performed. 44 * 45 * Note that sc_regs[] and sc_fpregs[]+sc_fpcr are inline 46 * representations of 'struct reg' and 'struct fpreg', respectively. 47 */ 48 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL) 49 struct sigcontext13 { 50 long sc_onstack; /* sigstack state to restore */ 51 long sc_mask; /* signal mask to restore (old style) */ 52 long sc_pc; /* pc to restore */ 53 long sc_ps; /* ps to restore */ 54 unsigned long sc_regs[32]; /* integer register set (see above) */ 55 #define sc_sp sc_regs[R_SP] 56 long sc_ownedfp; /* fp has been used */ 57 unsigned long sc_fpregs[32]; /* FP register set (see above) */ 58 unsigned long sc_fpcr; /* FP control register (see above) */ 59 unsigned long sc_fp_control; /* FP software control word */ 60 long sc_reserved[2]; /* XXX */ 61 long sc_xxx[8]; /* XXX */ 62 }; 63 #endif /* __LIBC12_SOURCE__ || _KERNEL */ 64 65 struct sigcontext { 66 long sc_onstack; /* sigstack state to restore */ 67 long __sc_mask13; /* signal mask to restore (old style) */ 68 long sc_pc; /* pc to restore */ 69 long sc_ps; /* ps to restore */ 70 unsigned long sc_regs[32]; /* integer register set (see above) */ 71 #define sc_sp sc_regs[R_SP] 72 long sc_ownedfp; /* fp has been used */ 73 unsigned long sc_fpregs[32]; /* FP register set (see above) */ 74 unsigned long sc_fpcr; /* FP control register (see above) */ 75 unsigned long sc_fp_control; /* FP software control word */ 76 long sc_reserved[2]; /* XXX */ 77 long sc_xxx[8]; /* XXX */ 78 sigset_t sc_mask; /* signal mask to restore (new style) */ 79 }; 80 81 /* 82 * The following macros are used to convert from a ucontext to sigcontext, 83 * and vice-versa. This is for building a sigcontext to deliver to old-style 84 * signal handlers, and converting back (in the event the handler modifies 85 * the context). 86 */ 87 #define _MCONTEXT_TO_SIGCONTEXT(uc, sc) \ 88 do { \ 89 (sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \ 90 (sc)->sc_ps = (uc)->uc_mcontext.__gregs[_REG_PS]; \ 91 memcpy(&(sc)->sc_regs, &(uc)->uc_mcontext.__gregs, \ 92 31 * sizeof(unsigned long)); \ 93 if ((uc)->uc_flags & _UC_FPU) { \ 94 (sc)->sc_ownedfp = 1; \ 95 memcpy(&(sc)->sc_fpregs, \ 96 &(uc)->uc_mcontext.__fpregs.__fp_fr, \ 97 31 * sizeof(unsigned long)); \ 98 (sc)->sc_fpcr = (uc)->uc_mcontext.__fpregs.__fp_fpcr; \ 99 /* XXX sc_fp_control */ \ 100 } else \ 101 (sc)->sc_ownedfp = 0; \ 102 } while (/*CONSTCOND*/0) 103 104 #define _SIGCONTEXT_TO_MCONTEXT(sc, uc) \ 105 do { \ 106 (uc)->uc_mcontext.__gregs[_REG_PC] = (sc)->sc_pc; \ 107 (uc)->uc_mcontext.__gregs[_REG_PS] = (sc)->sc_ps; \ 108 memcpy(&(uc)->uc_mcontext.__gregs, &(sc)->sc_regs, \ 109 31 * sizeof(unsigned long)); \ 110 if ((sc)->sc_ownedfp) { \ 111 memcpy(&(uc)->uc_mcontext.__fpregs.__fp_fr, \ 112 &(sc)->sc_fpregs, 31 * sizeof(unsigned long)); \ 113 (sc)->sc_fpcr = (uc)->uc_mcontext.__fpregs.__fp_fpcr; \ 114 /* XXX sc_fp_control */ \ 115 (uc)->uc_flags |= _UC_FPU; \ 116 } \ 117 } while (/*CONSTCOND*/0) 118 119 #endif /* _NETBSD_SOURCE */ 120 #endif /* !_ALPHA_SIGNAL_H_*/ 121