Home | History | Annotate | Download | only in sys
      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	23
     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   REG_OLDMASK,
     88 # define REG_OLDMASK	REG_OLDMASK
     89   REG_CR2
     90 # define REG_CR2	REG_CR2
     91 };
     92 #endif
     93 
     94 struct _libc_fpxreg
     95 {
     96   unsigned short int significand[4];
     97   unsigned short int exponent;
     98   unsigned short int padding[3];
     99 };
    100 
    101 struct _libc_xmmreg
    102 {
    103   __uint32_t	element[4];
    104 };
    105 
    106 struct _libc_fpstate
    107 {
    108   /* 64-bit FXSAVE format.  */
    109   __uint16_t		cwd;
    110   __uint16_t		swd;
    111   __uint16_t		ftw;
    112   __uint16_t		fop;
    113   __uint64_t		rip;
    114   __uint64_t		rdp;
    115   __uint32_t		mxcsr;
    116   __uint32_t		mxcr_mask;
    117   struct _libc_fpxreg	_st[8];
    118   struct _libc_xmmreg	_xmm[16];
    119   __uint32_t		padding[24];
    120 };
    121 
    122 /* Structure to describe FPU registers.  */
    123 typedef struct _libc_fpstate *fpregset_t;
    124 
    125 /* Context to describe whole processor state.  */
    126 typedef struct
    127   {
    128     gregset_t gregs;
    129     /* Note that fpregs is a pointer.  */
    130     fpregset_t fpregs;
    131     unsigned long __reserved1 [8];
    132 } mcontext_t;
    133 
    134 /* Userlevel context.  */
    135 typedef struct ucontext
    136   {
    137     unsigned long int uc_flags;
    138     struct ucontext *uc_link;
    139     stack_t uc_stack;
    140     mcontext_t uc_mcontext;
    141     __sigset_t uc_sigmask;
    142     struct _libc_fpstate __fpregs_mem;
    143   } ucontext_t;
    144 
    145 #else /* __WORDSIZE == 32 */
    146 
    147 /* Type for general register.  */
    148 typedef int greg_t;
    149 
    150 /* Number of general registers.  */
    151 #define NGREG	19
    152 
    153 /* Container for all general registers.  */
    154 typedef greg_t gregset_t[NGREG];
    155 
    156 #ifdef __USE_GNU
    157 /* Number of each register is the `gregset_t' array.  */
    158 enum
    159 {
    160   REG_GS = 0,
    161 # define REG_GS		REG_GS
    162   REG_FS,
    163 # define REG_FS		REG_FS
    164   REG_ES,
    165 # define REG_ES		REG_ES
    166   REG_DS,
    167 # define REG_DS		REG_DS
    168   REG_EDI,
    169 # define REG_EDI	REG_EDI
    170   REG_ESI,
    171 # define REG_ESI	REG_ESI
    172   REG_EBP,
    173 # define REG_EBP	REG_EBP
    174   REG_ESP,
    175 # define REG_ESP	REG_ESP
    176   REG_EBX,
    177 # define REG_EBX	REG_EBX
    178   REG_EDX,
    179 # define REG_EDX	REG_EDX
    180   REG_ECX,
    181 # define REG_ECX	REG_ECX
    182   REG_EAX,
    183 # define REG_EAX	REG_EAX
    184   REG_TRAPNO,
    185 # define REG_TRAPNO	REG_TRAPNO
    186   REG_ERR,
    187 # define REG_ERR	REG_ERR
    188   REG_EIP,
    189 # define REG_EIP	REG_EIP
    190   REG_CS,
    191 # define REG_CS		REG_CS
    192   REG_EFL,
    193 # define REG_EFL	REG_EFL
    194   REG_UESP,
    195 # define REG_UESP	REG_UESP
    196   REG_SS
    197 # define REG_SS	REG_SS
    198 };
    199 #endif
    200 
    201 /* Definitions taken from the kernel headers.  */
    202 struct _libc_fpreg
    203 {
    204   unsigned short int significand[4];
    205   unsigned short int exponent;
    206 };
    207 
    208 struct _libc_fpstate
    209 {
    210   unsigned long int cw;
    211   unsigned long int sw;
    212   unsigned long int tag;
    213   unsigned long int ipoff;
    214   unsigned long int cssel;
    215   unsigned long int dataoff;
    216   unsigned long int datasel;
    217   struct _libc_fpreg _st[8];
    218   unsigned long int status;
    219 };
    220 
    221 /* Structure to describe FPU registers.  */
    222 typedef struct _libc_fpstate *fpregset_t;
    223 
    224 /* Context to describe whole processor state.  */
    225 typedef struct
    226   {
    227     gregset_t gregs;
    228     /* Due to Linux's history we have to use a pointer here.  The SysV/i386
    229        ABI requires a struct with the values.  */
    230     fpregset_t fpregs;
    231     unsigned long int oldmask;
    232     unsigned long int cr2;
    233   } mcontext_t;
    234 
    235 /* Userlevel context.  */
    236 typedef struct ucontext
    237   {
    238     unsigned long int uc_flags;
    239     struct ucontext *uc_link;
    240     stack_t uc_stack;
    241     mcontext_t uc_mcontext;
    242     __sigset_t uc_sigmask;
    243     struct _libc_fpstate __fpregs_mem;
    244   } ucontext_t;
    245 
    246 #endif /* __WORDSIZE == 32 */
    247 
    248 #endif /* sys/ucontext.h */
    249