xref: /freebsd/sys/x86/include/ucontext.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2003 Peter Wemm
5  * Copyright (c) 1999 Marcel Moolenaar
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer
13  *    in this position and unchanged.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef _X86_UCONTEXT_H_
35 #define	_X86_UCONTEXT_H_
36 
37 #ifdef __i386__
38 /* Keep _MC_* values similar to amd64 */
39 #define	_MC_HASSEGS	0x1
40 #define	_MC_HASBASES	0x2
41 #define	_MC_HASFPXSTATE	0x4
42 #define	_MC_FLAG_MASK	(_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE)
43 
44 typedef struct __mcontext {
45 	/*
46 	 * The definition of mcontext_t must match the layout of
47 	 * struct sigcontext after the sc_mask member.  This is so
48 	 * that we can support sigcontext and ucontext_t at the same
49 	 * time.
50 	 */
51 	__register_t	mc_onstack;	/* XXX - sigcontext compat. */
52 	__register_t	mc_gs;		/* machine state (struct trapframe) */
53 	__register_t	mc_fs;
54 	__register_t	mc_es;
55 	__register_t	mc_ds;
56 	__register_t	mc_edi;
57 	__register_t	mc_esi;
58 	__register_t	mc_ebp;
59 	__register_t	mc_isp;
60 	__register_t	mc_ebx;
61 	__register_t	mc_edx;
62 	__register_t	mc_ecx;
63 	__register_t	mc_eax;
64 	__register_t	mc_trapno;
65 	__register_t	mc_err;
66 	__register_t	mc_eip;
67 	__register_t	mc_cs;
68 	__register_t	mc_eflags;
69 	__register_t	mc_esp;
70 	__register_t	mc_ss;
71 
72 	int	mc_len;			/* sizeof(mcontext_t) */
73 #define	_MC_FPFMT_NODEV		0x10000	/* device not present or configured */
74 #define	_MC_FPFMT_387		0x10001
75 #define	_MC_FPFMT_XMM		0x10002
76 	int	mc_fpformat;
77 #define	_MC_FPOWNED_NONE	0x20000	/* FP state not used */
78 #define	_MC_FPOWNED_FPU		0x20001	/* FP state came from FPU */
79 #define	_MC_FPOWNED_PCB		0x20002	/* FP state came from PCB */
80 	int	mc_ownedfp;
81 	__register_t mc_flags;
82 	/*
83 	 * See <machine/npx.h> for the internals of mc_fpstate[].
84 	 */
85 	int	mc_fpstate[128] __aligned(16);
86 
87 	__register_t mc_fsbase;
88 	__register_t mc_gsbase;
89 
90 	__register_t mc_xfpustate;
91 	__register_t mc_xfpustate_len;
92 
93 	int	mc_spare2[4];
94 } mcontext_t;
95 #endif /* __i386__ */
96 
97 #ifdef __amd64__
98 /*
99  * mc_flags bits. Shall be in sync with TF_XXX.
100  */
101 #define	_MC_HASSEGS	0x1
102 #define	_MC_HASBASES	0x2
103 #define	_MC_HASFPXSTATE	0x4
104 #define	_MC_FLAG_MASK	(_MC_HASSEGS | _MC_HASBASES | _MC_HASFPXSTATE)
105 
106 typedef struct __mcontext {
107 	/*
108 	 * The definition of mcontext_t must match the layout of
109 	 * struct sigcontext after the sc_mask member.  This is so
110 	 * that we can support sigcontext and ucontext_t at the same
111 	 * time.
112 	 */
113 	__register_t	mc_onstack;	/* XXX - sigcontext compat. */
114 	__register_t	mc_rdi;		/* machine state (struct trapframe) */
115 	__register_t	mc_rsi;
116 	__register_t	mc_rdx;
117 	__register_t	mc_rcx;
118 	__register_t	mc_r8;
119 	__register_t	mc_r9;
120 	__register_t	mc_rax;
121 	__register_t	mc_rbx;
122 	__register_t	mc_rbp;
123 	__register_t	mc_r10;
124 	__register_t	mc_r11;
125 	__register_t	mc_r12;
126 	__register_t	mc_r13;
127 	__register_t	mc_r14;
128 	__register_t	mc_r15;
129 	__uint32_t	mc_trapno;
130 	__uint16_t	mc_fs;
131 	__uint16_t	mc_gs;
132 	__register_t	mc_addr;
133 	__uint32_t	mc_flags;
134 	__uint16_t	mc_es;
135 	__uint16_t	mc_ds;
136 	__register_t	mc_err;
137 	__register_t	mc_rip;
138 	__register_t	mc_cs;
139 	__register_t	mc_rflags;
140 	__register_t	mc_rsp;
141 	__register_t	mc_ss;
142 
143 	long	mc_len;			/* sizeof(mcontext_t) */
144 
145 #define	_MC_FPFMT_NODEV		0x10000	/* device not present or configured */
146 #define	_MC_FPFMT_XMM		0x10002
147 	long	mc_fpformat;
148 #define	_MC_FPOWNED_NONE	0x20000	/* FP state not used */
149 #define	_MC_FPOWNED_FPU		0x20001	/* FP state came from FPU */
150 #define	_MC_FPOWNED_PCB		0x20002	/* FP state came from PCB */
151 	long	mc_ownedfp;
152 	/*
153 	 * See <machine/fpu.h> for the internals of mc_fpstate[].
154 	 */
155 	long	mc_fpstate[64] __aligned(16);
156 
157 	__register_t	mc_fsbase;
158 	__register_t	mc_gsbase;
159 
160 	__register_t	mc_xfpustate;
161 	__register_t	mc_xfpustate_len;
162 
163 	long	mc_spare[4];
164 } mcontext_t;
165 #endif /* __amd64__ */
166 
167 #endif /* !_X86_UCONTEXT_H_ */
168