1af170c50SDavid Howells #ifndef _UAPI_ASM_X86_SIGCONTEXT_H
2af170c50SDavid Howells #define _UAPI_ASM_X86_SIGCONTEXT_H
3af170c50SDavid Howells 
4af170c50SDavid Howells #include <linux/compiler.h>
5af170c50SDavid Howells #include <linux/types.h>
6af170c50SDavid Howells 
7af170c50SDavid Howells #define FP_XSTATE_MAGIC1	0x46505853U
8af170c50SDavid Howells #define FP_XSTATE_MAGIC2	0x46505845U
9af170c50SDavid Howells #define FP_XSTATE_MAGIC2_SIZE	sizeof(FP_XSTATE_MAGIC2)
10af170c50SDavid Howells 
11af170c50SDavid Howells /*
12af170c50SDavid Howells  * bytes 464..511 in the current 512byte layout of fxsave/fxrstor frame
13af170c50SDavid Howells  * are reserved for SW usage. On cpu's supporting xsave/xrstor, these bytes
14af170c50SDavid Howells  * are used to extended the fpstate pointer in the sigcontext, which now
15af170c50SDavid Howells  * includes the extended state information along with fpstate information.
16af170c50SDavid Howells  *
17af170c50SDavid Howells  * Presence of FP_XSTATE_MAGIC1 at the beginning of this SW reserved
18af170c50SDavid Howells  * area and FP_XSTATE_MAGIC2 at the end of memory layout
19af170c50SDavid Howells  * (extended_size - FP_XSTATE_MAGIC2_SIZE) indicates the presence of the
20af170c50SDavid Howells  * extended state information in the memory layout pointed by the fpstate
21af170c50SDavid Howells  * pointer in sigcontext.
22af170c50SDavid Howells  */
23af170c50SDavid Howells struct _fpx_sw_bytes {
24af170c50SDavid Howells 	__u32 magic1;		/* FP_XSTATE_MAGIC1 */
25af170c50SDavid Howells 	__u32 extended_size;	/* total size of the layout referred by
26af170c50SDavid Howells 				 * fpstate pointer in the sigcontext.
27af170c50SDavid Howells 				 */
28400e4b20SIngo Molnar 	__u64 xfeatures;
29af170c50SDavid Howells 				/* feature bit mask (including fp/sse/extended
30af170c50SDavid Howells 				 * state) that is present in the memory
31af170c50SDavid Howells 				 * layout.
32af170c50SDavid Howells 				 */
33af170c50SDavid Howells 	__u32 xstate_size;	/* actual xsave state size, based on the
34af170c50SDavid Howells 				 * features saved in the layout.
35af170c50SDavid Howells 				 * 'extended_size' will be greater than
36af170c50SDavid Howells 				 * 'xstate_size'.
37af170c50SDavid Howells 				 */
38af170c50SDavid Howells 	__u32 padding[7];	/*  for future use. */
39af170c50SDavid Howells };
40af170c50SDavid Howells 
41af170c50SDavid Howells #ifdef __i386__
42af170c50SDavid Howells /*
43af170c50SDavid Howells  * As documented in the iBCS2 standard..
44af170c50SDavid Howells  *
45af170c50SDavid Howells  * The first part of "struct _fpstate" is just the normal i387
46af170c50SDavid Howells  * hardware setup, the extra "status" word is used to save the
47af170c50SDavid Howells  * coprocessor status word before entering the handler.
48af170c50SDavid Howells  *
49af170c50SDavid Howells  * Pentium III FXSR, SSE support
50af170c50SDavid Howells  *	Gareth Hughes <gareth@valinux.com>, May 2000
51af170c50SDavid Howells  *
52af170c50SDavid Howells  * The FPU state data structure has had to grow to accommodate the
53af170c50SDavid Howells  * extended FPU state required by the Streaming SIMD Extensions.
54af170c50SDavid Howells  * There is no documented standard to accomplish this at the moment.
55af170c50SDavid Howells  */
56af170c50SDavid Howells struct _fpreg {
57af170c50SDavid Howells 	unsigned short significand[4];
58af170c50SDavid Howells 	unsigned short exponent;
59af170c50SDavid Howells };
60af170c50SDavid Howells 
61af170c50SDavid Howells struct _fpxreg {
62af170c50SDavid Howells 	unsigned short significand[4];
63af170c50SDavid Howells 	unsigned short exponent;
64af170c50SDavid Howells 	unsigned short padding[3];
65af170c50SDavid Howells };
66af170c50SDavid Howells 
67af170c50SDavid Howells struct _xmmreg {
68af170c50SDavid Howells 	unsigned long element[4];
69af170c50SDavid Howells };
70af170c50SDavid Howells 
71af170c50SDavid Howells struct _fpstate {
72af170c50SDavid Howells 	/* Regular FPU environment */
73af170c50SDavid Howells 	unsigned long	cw;
74af170c50SDavid Howells 	unsigned long	sw;
75af170c50SDavid Howells 	unsigned long	tag;
76af170c50SDavid Howells 	unsigned long	ipoff;
77af170c50SDavid Howells 	unsigned long	cssel;
78af170c50SDavid Howells 	unsigned long	dataoff;
79af170c50SDavid Howells 	unsigned long	datasel;
80af170c50SDavid Howells 	struct _fpreg	_st[8];
81af170c50SDavid Howells 	unsigned short	status;
82af170c50SDavid Howells 	unsigned short	magic;		/* 0xffff = regular FPU data only */
83af170c50SDavid Howells 
84af170c50SDavid Howells 	/* FXSR FPU environment */
85af170c50SDavid Howells 	unsigned long	_fxsr_env[6];	/* FXSR FPU env is ignored */
86af170c50SDavid Howells 	unsigned long	mxcsr;
87af170c50SDavid Howells 	unsigned long	reserved;
88af170c50SDavid Howells 	struct _fpxreg	_fxsr_st[8];	/* FXSR FPU reg data is ignored */
89af170c50SDavid Howells 	struct _xmmreg	_xmm[8];
90af170c50SDavid Howells 	unsigned long	padding1[44];
91af170c50SDavid Howells 
92af170c50SDavid Howells 	union {
93af170c50SDavid Howells 		unsigned long	padding2[12];
94af170c50SDavid Howells 		struct _fpx_sw_bytes sw_reserved; /* represents the extended
95af170c50SDavid Howells 						   * state info */
96af170c50SDavid Howells 	};
97af170c50SDavid Howells };
98af170c50SDavid Howells 
99af170c50SDavid Howells #define X86_FXSR_MAGIC		0x0000
100af170c50SDavid Howells 
101af170c50SDavid Howells #ifndef __KERNEL__
102af170c50SDavid Howells /*
103af170c50SDavid Howells  * User-space might still rely on the old definition:
104af170c50SDavid Howells  */
105af170c50SDavid Howells struct sigcontext {
106af170c50SDavid Howells 	unsigned short gs, __gsh;
107af170c50SDavid Howells 	unsigned short fs, __fsh;
108af170c50SDavid Howells 	unsigned short es, __esh;
109af170c50SDavid Howells 	unsigned short ds, __dsh;
110af170c50SDavid Howells 	unsigned long edi;
111af170c50SDavid Howells 	unsigned long esi;
112af170c50SDavid Howells 	unsigned long ebp;
113af170c50SDavid Howells 	unsigned long esp;
114af170c50SDavid Howells 	unsigned long ebx;
115af170c50SDavid Howells 	unsigned long edx;
116af170c50SDavid Howells 	unsigned long ecx;
117af170c50SDavid Howells 	unsigned long eax;
118af170c50SDavid Howells 	unsigned long trapno;
119af170c50SDavid Howells 	unsigned long err;
120af170c50SDavid Howells 	unsigned long eip;
121af170c50SDavid Howells 	unsigned short cs, __csh;
122af170c50SDavid Howells 	unsigned long eflags;
123af170c50SDavid Howells 	unsigned long esp_at_signal;
124af170c50SDavid Howells 	unsigned short ss, __ssh;
125af170c50SDavid Howells 	struct _fpstate __user *fpstate;
126af170c50SDavid Howells 	unsigned long oldmask;
127af170c50SDavid Howells 	unsigned long cr2;
128af170c50SDavid Howells };
129af170c50SDavid Howells #endif /* !__KERNEL__ */
130af170c50SDavid Howells 
131af170c50SDavid Howells #else /* __i386__ */
132af170c50SDavid Howells 
133af170c50SDavid Howells /* FXSAVE frame */
134af170c50SDavid Howells /* Note: reserved1/2 may someday contain valuable data. Always save/restore
135af170c50SDavid Howells    them when you change signal frames. */
136af170c50SDavid Howells struct _fpstate {
137af170c50SDavid Howells 	__u16	cwd;
138af170c50SDavid Howells 	__u16	swd;
139af170c50SDavid Howells 	__u16	twd;		/* Note this is not the same as the
140af170c50SDavid Howells 				   32bit/x87/FSAVE twd */
141af170c50SDavid Howells 	__u16	fop;
142af170c50SDavid Howells 	__u64	rip;
143af170c50SDavid Howells 	__u64	rdp;
144af170c50SDavid Howells 	__u32	mxcsr;
145af170c50SDavid Howells 	__u32	mxcsr_mask;
146af170c50SDavid Howells 	__u32	st_space[32];	/* 8*16 bytes for each FP-reg */
147af170c50SDavid Howells 	__u32	xmm_space[64];	/* 16*16 bytes for each XMM-reg  */
148af170c50SDavid Howells 	__u32	reserved2[12];
149af170c50SDavid Howells 	union {
150af170c50SDavid Howells 		__u32	reserved3[12];
151af170c50SDavid Howells 		struct _fpx_sw_bytes sw_reserved; /* represents the extended
152af170c50SDavid Howells 						   * state information */
153af170c50SDavid Howells 	};
154af170c50SDavid Howells };
155af170c50SDavid Howells 
156af170c50SDavid Howells #ifndef __KERNEL__
157af170c50SDavid Howells /*
158af170c50SDavid Howells  * User-space might still rely on the old definition:
159af170c50SDavid Howells  */
160af170c50SDavid Howells struct sigcontext {
161af170c50SDavid Howells 	__u64 r8;
162af170c50SDavid Howells 	__u64 r9;
163af170c50SDavid Howells 	__u64 r10;
164af170c50SDavid Howells 	__u64 r11;
165af170c50SDavid Howells 	__u64 r12;
166af170c50SDavid Howells 	__u64 r13;
167af170c50SDavid Howells 	__u64 r14;
168af170c50SDavid Howells 	__u64 r15;
169af170c50SDavid Howells 	__u64 rdi;
170af170c50SDavid Howells 	__u64 rsi;
171af170c50SDavid Howells 	__u64 rbp;
172af170c50SDavid Howells 	__u64 rbx;
173af170c50SDavid Howells 	__u64 rdx;
174af170c50SDavid Howells 	__u64 rax;
175af170c50SDavid Howells 	__u64 rcx;
176af170c50SDavid Howells 	__u64 rsp;
177af170c50SDavid Howells 	__u64 rip;
178af170c50SDavid Howells 	__u64 eflags;		/* RFLAGS */
179af170c50SDavid Howells 	__u16 cs;
180ed596cdeSLinus Torvalds 	__u16 gs;
181ed596cdeSLinus Torvalds 	__u16 fs;
182ed596cdeSLinus Torvalds 	__u16 __pad0;
183af170c50SDavid Howells 	__u64 err;
184af170c50SDavid Howells 	__u64 trapno;
185af170c50SDavid Howells 	__u64 oldmask;
186af170c50SDavid Howells 	__u64 cr2;
187af170c50SDavid Howells 	struct _fpstate __user *fpstate;	/* zero when no FPU context */
188af170c50SDavid Howells #ifdef __ILP32__
189af170c50SDavid Howells 	__u32 __fpstate_pad;
190af170c50SDavid Howells #endif
191af170c50SDavid Howells 	__u64 reserved1[8];
192af170c50SDavid Howells };
193af170c50SDavid Howells #endif /* !__KERNEL__ */
194af170c50SDavid Howells 
195af170c50SDavid Howells #endif /* !__i386__ */
196af170c50SDavid Howells 
1973a54450bSIngo Molnar struct _header {
198400e4b20SIngo Molnar 	__u64 xfeatures;
199af170c50SDavid Howells 	__u64 reserved1[2];
200af170c50SDavid Howells 	__u64 reserved2[5];
201af170c50SDavid Howells };
202af170c50SDavid Howells 
203af170c50SDavid Howells struct _ymmh_state {
204af170c50SDavid Howells 	/* 16 * 16 bytes for each YMMH-reg */
205af170c50SDavid Howells 	__u32 ymmh_space[64];
206af170c50SDavid Howells };
207af170c50SDavid Howells 
208af170c50SDavid Howells /*
209af170c50SDavid Howells  * Extended state pointed by the fpstate pointer in the sigcontext.
210af170c50SDavid Howells  * In addition to the fpstate, information encoded in the xstate_hdr
211af170c50SDavid Howells  * indicates the presence of other extended state information
212af170c50SDavid Howells  * supported by the processor and OS.
213af170c50SDavid Howells  */
214af170c50SDavid Howells struct _xstate {
215af170c50SDavid Howells 	struct _fpstate fpstate;
2163a54450bSIngo Molnar 	struct _header xstate_hdr;
217af170c50SDavid Howells 	struct _ymmh_state ymmh;
218af170c50SDavid Howells 	/* new processor state extensions go here */
219af170c50SDavid Howells };
220af170c50SDavid Howells 
221af170c50SDavid Howells #endif /* _UAPI_ASM_X86_SIGCONTEXT_H */
222