xref: /netbsd-src/sys/arch/mips/include/mcontext.h (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: mcontext.h,v 1.11 2009/12/14 00:46:04 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Klaus Klein, and by Jason R. Thorpe of Wasabi Systems, Inc.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _MIPS_MCONTEXT_H_
33 #define _MIPS_MCONTEXT_H_
34 
35 /*
36  * General register state
37  */
38 #define _NGREG		37	/* R0-R31, MDLO, MDHI, CAUSE, PC, SR */
39 
40 #define _REG_R0		0
41 #define _REG_AT		1
42 #define _REG_V0		2
43 #define _REG_V1		3
44 #define _REG_A0		4
45 #define _REG_A1		5
46 #define _REG_A2		6
47 #define _REG_A3		7
48 #define _REG_T0		8
49 #define _REG_T1		9
50 #define _REG_T2		10
51 #define _REG_T3		11
52 #define _REG_T4		12
53 #define _REG_T5		13
54 #define _REG_T6		14
55 #define _REG_T7		15
56 #define _REG_S0		16
57 #define _REG_S1		17
58 #define _REG_S2		18
59 #define _REG_S3		19
60 #define _REG_S4		20
61 #define _REG_S5		21
62 #define _REG_S6		22
63 #define _REG_S7		23
64 #define _REG_T8		24
65 #define _REG_T9		25
66 #define _REG_K0		26
67 #define _REG_K1		27
68 #define _REG_GP		28
69 #define _REG_SP		29
70 #define _REG_S8		30
71 #define _REG_RA		31
72 
73 /* XXX: The following conflict with <mips/regnum.h> */
74 #define _REG_MDLO	32
75 #define _REG_MDHI	33
76 #define _REG_CAUSE	34
77 #define _REG_EPC	35
78 #define _REG_SR		36
79 
80 #ifndef __ASSEMBLER__
81 
82 /* Make sure this is signed; we need pointers to be sign-extended. */
83 #if defined(__mips_n32)
84 typedef	long long	__greg_t;
85 #else
86 typedef	long		__greg_t;
87 #endif /* __mips_n32 */
88 
89 typedef	__greg_t	__gregset_t[_NGREG];
90 
91 /*
92  * For the O32/O64 ABI, there are 16 doubles, one at each even FP reg
93  * number.  The FP registers themselves are 32-bits.
94  *
95  * For 64-bit ABIs (include N32), each FP register is a 64-bit double.
96  */
97 typedef	__greg_t	__freg_t;
98 
99 /*
100  * Floating point register state
101  */
102 struct __fpregset_nabi {
103 	union {
104 		double	__fp64_dregs[32];
105 		__freg_t __fp_regs[32];
106 	} __fp_r;
107 	__greg_t	__fp_csr;
108 };
109 struct __fpregset_oabi {
110 	union {
111 		double	__fp_dregs[16];
112 		float	__fp_fregs[32];
113 		__int32_t __fp_regs[32];
114 	} __fp_r;
115 	unsigned int	__fp_csr;
116 	unsigned int	__fp_pad;
117 };
118 
119 #if __mips_n32 || __mips_n64
120 typedef struct __fpregset_nabi __fpregset_t;
121 #else
122 typedef struct __fpregset_oabi __fpregset_t;
123 #endif
124 
125 typedef struct {
126 	__gregset_t	__gregs;
127 	__fpregset_t	__fpregs;
128 } mcontext_t;
129 
130 #if defined(_KERNEL) && defined(_LP64)
131 typedef	__int32_t	__greg32_t;
132 typedef __greg32_t	__gregset32_t[_NGREG];
133 
134 typedef struct {
135 	__gregset32_t		__gregs;
136 	struct __fpregset_oabi	__fpregs;
137 } mcontext_o32_t;
138 
139 typedef struct {
140 	__gregset_t		__gregs;
141 	struct __fpregset_nabi	__fpregs;
142 } mcontext32_t;
143 
144 #endif /* _KERNEL && _LP64 */
145 
146 #endif /* !__ASSEMBLER__ */
147 
148 #define _UC_MACHINE_PAD	16	/* Padding appended to ucontext_t */
149 
150 #define	_UC_SETSTACK	0x00010000
151 #define	_UC_CLRSTACK	0x00020000
152 
153 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_SP])
154 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_EPC])
155 #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_V0])
156 
157 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
158 
159 #define _UC_MACHINE32_SP(uc)	_UC_MACHINE_SP(uc)
160 #define _UC_MACHINE32_PC(uc)	_UC_MACHINE_PC(uc)
161 #define _UC_MACHINE32_INTRV(uc)	_UC_MACHINE_INTRV(uc)
162 
163 #define	_UC_MACHINE32_SET_PC(uc, pc)	_UC_MACHINE_PC((uc), (pc))
164 
165 #endif	/* _MIPS_MCONTEXT_H_ */
166