xref: /netbsd-src/sys/arch/arm/include/signal.h (revision b8c616269f5ebf18ab2e35cb8099d683130a177c)
1 /*	$NetBSD: signal.h,v 1.2 2003/01/17 22:28:48 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1996 Mark Brinicombe.
5  * Copyright (c) 1994 Brini.
6  * All rights reserved.
7  *
8  * This code is derived from software written for Brini by Mark Brinicombe
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 Brini.
21  * 4. The name of the company nor the name of the author may be used to
22  *    endorse or promote products derived from this software without specific
23  *    prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * RiscBSD kernel project
38  *
39  * signal.h
40  *
41  * Architecture dependant signal types and structures
42  *
43  * Created      : 30/09/94
44  */
45 
46 #ifndef _ARM32_SIGNAL_H_
47 #define _ARM32_SIGNAL_H_
48 
49 #ifndef _LOCORE
50 typedef int sig_atomic_t;
51 #endif
52 
53 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \
54     !defined(_XOPEN_SOURCE)
55 #ifndef _LOCORE
56 /*
57  * Information pushed on stack when a signal is delivered.
58  * This is used by the kernel to restore state following
59  * execution of the signal handler.  It is also made available
60  * to the handler to allow it to restore state properly if
61  * a non-standard exit is performed.
62  */
63 
64 #if defined(__LIBC12_SOURCE__) || defined(_KERNEL)
65 struct sigcontext13 {
66 	int	sc_onstack;		/* sigstack state to restore */
67 	int	sc_mask;		/* signal mask to restore (old style) */
68 
69 	unsigned int sc_spsr;
70 	unsigned int sc_r0;
71 	unsigned int sc_r1;
72 	unsigned int sc_r2;
73 	unsigned int sc_r3;
74 	unsigned int sc_r4;
75 	unsigned int sc_r5;
76 	unsigned int sc_r6;
77 	unsigned int sc_r7;
78 	unsigned int sc_r8;
79 	unsigned int sc_r9;
80 	unsigned int sc_r10;
81 	unsigned int sc_r11;
82 	unsigned int sc_r12;
83 	unsigned int sc_usr_sp;
84 	unsigned int sc_usr_lr;
85 	unsigned int sc_svc_lr;
86 	unsigned int sc_pc;
87 };
88 #endif /* __LIBC12_SOURCE__ || _KERNEL */
89 
90 struct sigcontext {
91 	int	sc_onstack;		/* sigstack state to restore */
92 	int	__sc_mask13;		/* signal mask to restore (old style) */
93 
94 	unsigned int sc_spsr;
95 	unsigned int sc_r0;
96 	unsigned int sc_r1;
97 	unsigned int sc_r2;
98 	unsigned int sc_r3;
99 	unsigned int sc_r4;
100 	unsigned int sc_r5;
101 	unsigned int sc_r6;
102 	unsigned int sc_r7;
103 	unsigned int sc_r8;
104 	unsigned int sc_r9;
105 	unsigned int sc_r10;
106 	unsigned int sc_r11;
107 	unsigned int sc_r12;
108 	unsigned int sc_usr_sp;
109 	unsigned int sc_usr_lr;
110 	unsigned int sc_svc_lr;
111 	unsigned int sc_pc;
112 
113 	sigset_t sc_mask;		/* signal mask to restore (new style) */
114 };
115 
116 /*
117  * The following macros are used to convert from a ucontext to sigcontext,
118  * and vice-versa.  This is for building a sigcontext to deliver to old-style
119  * signal handlers, and converting back (in the event the handler modifies
120  * the context).
121  */
122 #define	_MCONTEXT_TO_SIGCONTEXT(uc, sc)					\
123 do {									\
124 	(sc)->sc_spsr = (uc)->uc_mcontext.__gregs[_REG_CPSR];		\
125 	memcpy(&(sc)->sc_r0, (uc)->uc_mcontext.__gregs,			\
126 	    15 * sizeof(unsigned int));					\
127 	(sc)->sc_svc_lr = 0;		/* XXX */			\
128 	(sc)->sc_pc = (uc)->uc_mcontext.__gregs[_REG_PC];		\
129 } while (/*CONSTCOND*/0)
130 
131 #define	_SIGCONTEXT_TO_MCONTEXT(sc, uc)					\
132 do {									\
133 	(uc)->uc_mcontext.__gregs[_REG_CPSR] = (sc)->sc_spsr;		\
134 	memcpy((uc)->uc_mcontext.__gregs, &(sc)->sc_r0,			\
135 	    15 * sizeof(unsigned int));					\
136 	(uc)->uc_mcontext.__gregs[_REG_PC] = (sc)->sc_pc;		\
137 } while (/*CONSTCOND*/0)
138 
139 #endif /* !_LOCORE */
140 
141 /* Signals codes */
142 
143 /*
144  * SIGFPE codes
145  *
146  * see ieeefp.h for definition of FP exception codes
147  */
148 
149 #define SIG_CODE_FPE_CODE_MASK	0x00000f00	/* Mask for exception code */
150 #define SIG_CODE_FPE_CODE_SHIFT	8		/* Shift for exception code */
151 #define SIG_CODE_FPE_TYPE_MASK	0x000000ff	/* Mask for specific code */
152 
153 /*
154  * SIGILL codes
155  *
156  * the signal code is the instruction that raised the signal
157  */
158 
159 /*
160  * SIGBUS and SIGSEGV codes
161  *
162  * The signal code is combination of the fault address and the fault code.
163  *
164  * The fault code is the coproc #15 fault status code
165  *
166  * The exception to this is a SIGBUS or SIGSEGV from a prefetch abort.
167  * In this case the fault status code is not valid so the TYPE_MASK
168  * should be treated as undefined (in practice it is the bottom 4 bits
169  * of the fault address).
170  */
171 
172 #define SIG_CODE_BUS_ADDR_MASK	0xfffffff0
173 #define SIG_CODE_BUS_TYPE_MASK	0x0000000f
174 #define SIG_CODE_SEGV_ADDR_MASK	SIG_CODE_BUS_ADDR_MASK
175 #define SIG_CODE_SEGV_TYPE_MASK	SIG_CODE_BUS_TYPE_MASK
176 
177 #endif	/* !_ANSI_SOURCE && !_POSIX_C_SOURCE && !_XOPEN_SOURCE */
178 #endif	/* !_ARM_SIGNAL_H_ */
179 
180 /* End of signal.h */
181