1/* Copyright (C) 2001-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_UCONTEXT_H
19#define _SYS_UCONTEXT_H 1
20
21#include <features.h>
22#include <signal.h>
23
24/* We need the signal context definitions even if they are not used
25 included in <signal.h>. */
26#include <bits/sigcontext.h>
27
28#ifdef __x86_64__
29
30/* Type for general register. */
31__extension__ typedef long long int greg_t;
32
33/* Number of general registers. */
34#define NGREG 23
35
36/* Container for all general registers. */
37typedef greg_t gregset_t[NGREG];
38
39#ifdef __USE_GNU
40/* Number of each register in the `gregset_t' array. */
41enum
42{
43 REG_R8 = 0,
44# define REG_R8 REG_R8
45 REG_R9,
46# define REG_R9 REG_R9
47 REG_R10,
48# define REG_R10 REG_R10
49 REG_R11,
50# define REG_R11 REG_R11
51 REG_R12,
52# define REG_R12 REG_R12
53 REG_R13,
54# define REG_R13 REG_R13
55 REG_R14,
56# define REG_R14 REG_R14
57 REG_R15,
58# define REG_R15 REG_R15
59 REG_RDI,
60# define REG_RDI REG_RDI
61 REG_RSI,
62# define REG_RSI REG_RSI
63 REG_RBP,
64# define REG_RBP REG_RBP
65 REG_RBX,
66# define REG_RBX REG_RBX
67 REG_RDX,
68# define REG_RDX REG_RDX
69 REG_RAX,
70# define REG_RAX REG_RAX
71 REG_RCX,
72# define REG_RCX REG_RCX
73 REG_RSP,
74# define REG_RSP REG_RSP
75 REG_RIP,
76# define REG_RIP REG_RIP
77 REG_EFL,
78# define REG_EFL REG_EFL
79 REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
80# define REG_CSGSFS REG_CSGSFS
81 REG_ERR,
82# define REG_ERR REG_ERR
83 REG_TRAPNO,
84# define REG_TRAPNO REG_TRAPNO
85 REG_OLDMASK,
86# define REG_OLDMASK REG_OLDMASK
87 REG_CR2
88# define REG_CR2 REG_CR2
89};
90#endif
91
92struct _libc_fpxreg
93{
94 unsigned short int significand[4];
95 unsigned short int exponent;
96 unsigned short int padding[3];
97};
98
99struct _libc_xmmreg
100{
101 __uint32_t element[4];
102};
103
104struct _libc_fpstate
105{
106 /* 64-bit FXSAVE format. */
107 __uint16_t cwd;
108 __uint16_t swd;
109 __uint16_t ftw;
110 __uint16_t fop;
111 __uint64_t rip;
112 __uint64_t rdp;
113 __uint32_t mxcsr;
114 __uint32_t mxcr_mask;
115 struct _libc_fpxreg _st[8];
116 struct _libc_xmmreg _xmm[16];
117 __uint32_t padding[24];
118};
119
120/* Structure to describe FPU registers. */
121typedef struct _libc_fpstate *fpregset_t;
122
123/* Context to describe whole processor state. */
124typedef struct
125 {
126 gregset_t gregs;
127 /* Note that fpregs is a pointer. */
128 fpregset_t fpregs;
129 __extension__ unsigned long long __reserved1 [8];
130} mcontext_t;
131
132/* Userlevel context. */
133typedef struct ucontext
134 {
135 unsigned long int uc_flags;
136 struct ucontext *uc_link;
137 stack_t uc_stack;
138 mcontext_t uc_mcontext;
139 __sigset_t uc_sigmask;
140 struct _libc_fpstate __fpregs_mem;
141 } ucontext_t;
142
143#else /* !__x86_64__ */
144
145/* Type for general register. */
146typedef int greg_t;
147
148/* Number of general registers. */
149#define NGREG 19
150
151/* Container for all general registers. */
152typedef greg_t gregset_t[NGREG];
153
154#ifdef __USE_GNU
155/* Number of each register is the `gregset_t' array. */
156enum
157{
158 REG_GS = 0,
159# define REG_GS REG_GS
160 REG_FS,
161# define REG_FS REG_FS
162 REG_ES,
163# define REG_ES REG_ES
164 REG_DS,
165# define REG_DS REG_DS
166 REG_EDI,
167# define REG_EDI REG_EDI
168 REG_ESI,
169# define REG_ESI REG_ESI
170 REG_EBP,
171# define REG_EBP REG_EBP
172 REG_ESP,
173# define REG_ESP REG_ESP
174 REG_EBX,
175# define REG_EBX REG_EBX
176 REG_EDX,
177# define REG_EDX REG_EDX
178 REG_ECX,
179# define REG_ECX REG_ECX
180 REG_EAX,
181# define REG_EAX REG_EAX
182 REG_TRAPNO,
183# define REG_TRAPNO REG_TRAPNO
184 REG_ERR,
185# define REG_ERR REG_ERR
186 REG_EIP,
187# define REG_EIP REG_EIP
188 REG_CS,
189# define REG_CS REG_CS
190 REG_EFL,
191# define REG_EFL REG_EFL
192 REG_UESP,
193# define REG_UESP REG_UESP
194 REG_SS
195# define REG_SS REG_SS
196};
197#endif
198
199/* Definitions taken from the kernel headers. */
200struct _libc_fpreg
201{
202 unsigned short int significand[4];
203 unsigned short int exponent;
204};
205
206struct _libc_fpstate
207{
208 unsigned long int cw;
209 unsigned long int sw;
210 unsigned long int tag;
211 unsigned long int ipoff;
212 unsigned long int cssel;
213 unsigned long int dataoff;
214 unsigned long int datasel;
215 struct _libc_fpreg _st[8];
216 unsigned long int status;
217};
218
219/* Structure to describe FPU registers. */
220typedef struct _libc_fpstate *fpregset_t;
221
222/* Context to describe whole processor state. */
223typedef struct
224 {
225 gregset_t gregs;
226 /* Due to Linux's history we have to use a pointer here. The SysV/i386
227 ABI requires a struct with the values. */
228 fpregset_t fpregs;
229 unsigned long int oldmask;
230 unsigned long int cr2;
231 } mcontext_t;
232
233/* Userlevel context. */
234typedef struct ucontext
235 {
236 unsigned long int uc_flags;
237 struct ucontext *uc_link;
238 stack_t uc_stack;
239 mcontext_t uc_mcontext;
240 __sigset_t uc_sigmask;
241 struct _libc_fpstate __fpregs_mem;
242 } ucontext_t;
243
244#endif /* !__x86_64__ */
245
246#endif /* sys/ucontext.h */
247