Update.
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / x86_64 / sys / ucontext.h
1 /* Copyright (C) 2001, 2002 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, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 #ifndef _SYS_UCONTEXT_H
20 #define _SYS_UCONTEXT_H 1
21
22 #include <features.h>
23 #include <signal.h>
24 #include <bits/wordsize.h>
25
26 /* We need the signal context definitions even if they are not used
27    included in <signal.h>.  */
28 #include <bits/sigcontext.h>
29
30 #if __WORDSIZE == 64
31
32 /* Type for general register.  */
33 typedef long int greg_t;
34
35 /* Number of general registers.  */
36 #define NGREG   21
37
38 /* Container for all general registers.  */
39 typedef greg_t gregset_t[NGREG];
40
41 #ifdef __USE_GNU
42 /* Number of each register in the `gregset_t' array.  */
43 enum
44 {
45   REG_R8 = 0,
46 # define REG_R8         REG_R8
47   REG_R9,
48 # define REG_R9         REG_R9
49   REG_R10,
50 # define REG_R10        REG_R10
51   REG_R11,
52 # define REG_R11        REG_R11
53   REG_R12,
54 # define REG_R12        REG_R12
55   REG_R13,
56 # define REG_R13        REG_R13
57   REG_R14,
58 # define REG_R14        REG_R14
59   REG_R15,
60 # define REG_R15        REG_R15
61   REG_RDI,
62 # define REG_RDI        REG_RDI
63   REG_RSI,
64 # define REG_RSI        REG_RSI
65   REG_RBP,
66 # define REG_RBP        REG_RBP
67   REG_RBX,
68 # define REG_RBX        REG_RBX
69   REG_RDX,
70 # define REG_RDX        REG_RDX
71   REG_RAX,
72 # define REG_RAX        REG_RAX
73   REG_RCX,
74 # define REG_RCX        REG_RCX
75   REG_RSP,
76 # define REG_RSP        REG_RSP
77   REG_RIP,
78 # define REG_RIP        REG_RIP
79   REG_EFL,
80 # define REG_EFL        REG_EFL
81   REG_CSGSFS,           /* Actually short cs, gs, fs, __pad0.  */
82 # define REG_CSGSFS     REG_CSGSFS
83   REG_ERR,
84 # define REG_ERR        REG_ERR
85   REG_TRAPNO
86 # define REG_TRAPNO     REG_TRAPNO
87 };
88 #endif
89
90 struct _libc_fpxreg
91 {
92   unsigned short int significand[4];
93   unsigned short int exponent;
94   unsigned short int padding[3];
95 };
96
97 struct _libc_xmmreg
98 {
99   __uint32_t    element[4];
100 };
101
102 struct _libc_fpstate
103 {
104   /* 64-bit FXSAVE format.  */
105   __uint16_t            cwd;
106   __uint16_t            swd;
107   __uint16_t            ftw;
108   __uint16_t            fop;
109   __uint64_t            rip;
110   __uint64_t            rdp;
111   __uint32_t            mxcsr;
112   __uint32_t            mxcr_mask;
113   struct _libc_fpxreg   _st[8];
114   struct _libc_xmmreg   _xmm[16];
115   __uint32_t            padding[24];
116 };
117
118 /* Structure to describe FPU registers.  */
119 typedef struct _libc_fpstate *fpregset_t;
120
121 /* Context to describe whole processor state.  */
122 typedef struct
123   {
124     gregset_t gregs;
125     /* Note that fpregs is a pointer.  */
126     fpregset_t fpregs;
127     unsigned long __reserved1 [8];
128 } mcontext_t;
129
130 /* Userlevel context.  */
131 typedef struct ucontext
132   {
133     unsigned long int uc_flags;
134     struct ucontext *uc_link;
135     stack_t uc_stack;
136     mcontext_t uc_mcontext;
137     __sigset_t uc_sigmask;
138     struct _libc_fpstate __fpregs_mem;
139   } ucontext_t;
140
141 #else /* __WORDSIZE == 32 */
142
143 /* Type for general register.  */
144 typedef int greg_t;
145
146 /* Number of general registers.  */
147 #define NGREG   19
148
149 /* Container for all general registers.  */
150 typedef greg_t gregset_t[NGREG];
151
152 #ifdef __USE_GNU
153 /* Number of each register is the `gregset_t' array.  */
154 enum
155 {
156   REG_GS = 0,
157 # define REG_GS         REG_GS
158   REG_FS,
159 # define REG_FS         REG_FS
160   REG_ES,
161 # define REG_ES         REG_ES
162   REG_DS,
163 # define REG_DS         REG_DS
164   REG_EDI,
165 # define REG_EDI        REG_EDI
166   REG_ESI,
167 # define REG_ESI        REG_ESI
168   REG_EBP,
169 # define REG_EBP        REG_EBP
170   REG_ESP,
171 # define REG_ESP        REG_ESP
172   REG_EBX,
173 # define REG_EBX        REG_EBX
174   REG_EDX,
175 # define REG_EDX        REG_EDX
176   REG_ECX,
177 # define REG_ECX        REG_ECX
178   REG_EAX,
179 # define REG_EAX        REG_EAX
180   REG_TRAPNO,
181 # define REG_TRAPNO     REG_TRAPNO
182   REG_ERR,
183 # define REG_ERR        REG_ERR
184   REG_EIP,
185 # define REG_EIP        REG_EIP
186   REG_CS,
187 # define REG_CS         REG_CS
188   REG_EFL,
189 # define REG_EFL        REG_EFL
190   REG_UESP,
191 # define REG_UESP       REG_UESP
192   REG_SS
193 # define REG_SS REG_SS
194 };
195 #endif
196
197 /* Definitions taken from the kernel headers.  */
198 struct _libc_fpreg
199 {
200   unsigned short int significand[4];
201   unsigned short int exponent;
202 };
203
204 struct _libc_fpstate
205 {
206   unsigned long int cw;
207   unsigned long int sw;
208   unsigned long int tag;
209   unsigned long int ipoff;
210   unsigned long int cssel;
211   unsigned long int dataoff;
212   unsigned long int datasel;
213   struct _libc_fpreg _st[8];
214   unsigned long int status;
215 };
216
217 /* Structure to describe FPU registers.  */
218 typedef struct _libc_fpstate *fpregset_t;
219
220 /* Context to describe whole processor state.  */
221 typedef struct
222   {
223     gregset_t gregs;
224     /* Due to Linux's history we have to use a pointer here.  The SysV/i386
225        ABI requires a struct with the values.  */
226     fpregset_t fpregs;
227     unsigned long int oldmask;
228     unsigned long int cr2;
229   } mcontext_t;
230
231 /* Userlevel context.  */
232 typedef struct ucontext
233   {
234     unsigned long int uc_flags;
235     struct ucontext *uc_link;
236     stack_t uc_stack;
237     mcontext_t uc_mcontext;
238     __sigset_t uc_sigmask;
239     struct _libc_fpstate __fpregs_mem;
240   } ucontext_t;
241
242 #endif /* __WORDSIZE == 32 */
243
244 #endif /* sys/ucontext.h */