Back to index

glibc  2.9
ucontext.h
Go to the documentation of this file.
00001 /* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _SYS_UCONTEXT_H
00020 #define _SYS_UCONTEXT_H     1
00021 
00022 #include <features.h>
00023 #include <signal.h>
00024 #include <bits/wordsize.h>
00025 
00026 #if __WORDSIZE == 64
00027 
00028 #define MC_TSTATE    0
00029 #define MC_PC        1
00030 #define MC_NPC              2
00031 #define MC_Y         3
00032 #define MC_G1        4
00033 #define MC_G2        5
00034 #define MC_G3        6
00035 #define MC_G4        7
00036 #define MC_G5        8
00037 #define MC_G6        9
00038 #define MC_G7        10
00039 #define MC_O0        11
00040 #define MC_O1        12
00041 #define MC_O2        13
00042 #define MC_O3        14
00043 #define MC_O4        15
00044 #define MC_O5        16
00045 #define MC_O6        17
00046 #define MC_O7        18
00047 #define MC_NGREG     19
00048 
00049 typedef unsigned long mc_greg_t;
00050 typedef mc_greg_t mc_gregset_t[MC_NGREG];
00051 
00052 #define MC_MAXFPQ    16
00053 struct mc_fq {
00054        unsigned long *mcfq_addr;
00055        unsigned int  mcfq_insn;
00056 };
00057 
00058 struct mc_fpu {
00059        union {
00060               unsigned int  sregs[32];
00061               unsigned long dregs[32];
00062               long double   qregs[16];
00063        } mcfpu_fregs;
00064        unsigned long mcfpu_fsr;
00065        unsigned long mcfpu_fprs;
00066        unsigned long mcfpu_gsr;
00067        struct mc_fq  *mcfpu_fq;
00068        unsigned char mcfpu_qcnt;
00069        unsigned char mcfpu_qentsz;
00070        unsigned char mcfpu_enab;
00071 };
00072 typedef struct mc_fpu mc_fpu_t;
00073 
00074 typedef struct {
00075        mc_gregset_t  mc_gregs;
00076        mc_greg_t     mc_fp;
00077        mc_greg_t     mc_i7;
00078        mc_fpu_t      mc_fpregs;
00079 } mcontext_t;
00080 
00081 typedef struct ucontext {
00082        struct ucontext             *uc_link;
00083        unsigned long        uc_flags;
00084        unsigned long        __uc_sigmask;
00085        mcontext_t           uc_mcontext;
00086        stack_t                     uc_stack;
00087        __sigset_t           uc_sigmask;
00088 } ucontext_t;
00089 
00090 #endif /* __WORDISIZE == 64 */
00091 
00092 /*
00093  * Location of the users' stored registers relative to R0.
00094  * Usage is as an index into a gregset_t array or as u.u_ar0[XX].
00095  */
00096 #define REG_PSR (0)
00097 #define REG_PC  (1)
00098 #define REG_nPC (2)
00099 #define REG_Y   (3)
00100 #define REG_G1  (4)
00101 #define REG_G2  (5)
00102 #define REG_G3  (6)
00103 #define REG_G4  (7)
00104 #define REG_G5  (8)
00105 #define REG_G6  (9)
00106 #define REG_G7  (10)
00107 #define REG_O0  (11)
00108 #define REG_O1  (12)
00109 #define REG_O2  (13)
00110 #define REG_O3  (14)
00111 #define REG_O4  (15)
00112 #define REG_O5  (16)
00113 #define REG_O6  (17)
00114 #define REG_O7  (18)
00115 
00116 /*
00117  * A gregset_t is defined as an array type for compatibility with the reference
00118  * source. This is important due to differences in the way the C language
00119  * treats arrays and structures as parameters.
00120  *
00121  * Note that NGREG is really (sizeof (struct regs) / sizeof (greg_t)),
00122  * but that the ABI defines it absolutely to be 21 (resp. 19).
00123  */
00124 
00125 #if __WORDSIZE == 64
00126 
00127 #define REG_ASI      (19)
00128 #define REG_FPRS (20)
00129 
00130 #define NGREG   21
00131 typedef long greg_t;
00132 
00133 #else /* __WORDSIZE == 32 */
00134 
00135 #define NGREG   19
00136 typedef int greg_t;
00137 
00138 #endif /* __WORDSIZE == 32 */
00139 
00140 typedef greg_t  gregset_t[NGREG];
00141 
00142 /*
00143  * The following structures define how a register window can appear on the
00144  * stack. This structure is available (when required) through the `gwins'
00145  * field of an mcontext (nested within ucontext). SPARC_MAXWINDOW is the
00146  * maximum number of outstanding regiters window defined in the SPARC
00147  * architecture (*not* implementation).
00148  */
00149 #define SPARC_MAXREGWINDOW  31     /* max windows in SPARC arch. */
00150 struct  rwindow
00151   {
00152     greg_t rw_local[8];                   /* locals */
00153     greg_t rw_in[8];               /* ins */
00154   };
00155 
00156 #define rw_fp   rw_in[6]           /* frame pointer */
00157 #define rw_rtn  rw_in[7]           /* return address */
00158 
00159 typedef struct gwindows
00160   {
00161     int            wbcnt;
00162     int           *spbuf[SPARC_MAXREGWINDOW];
00163     struct rwindow wbuf[SPARC_MAXREGWINDOW];
00164   } gwindows_t;
00165 
00166 /*
00167  * Floating point definitions.
00168  */
00169 
00170 #define MAXFPQ       16     /* max # of fpu queue entries currently supported */
00171 
00172 /*
00173  * struct fq defines the minimal format of a floating point instruction queue
00174  * entry. The size of entries in the floating point queue are implementation
00175  * dependent. The union FQu is guarenteed to be the first field in any ABI
00176  * conformant system implementation. Any additional fields provided by an
00177  * implementation should not be used applications designed to be ABI conformant. */
00178 
00179 struct fpq
00180   {
00181     unsigned long *fpq_addr;              /* address */
00182     unsigned long fpq_instr;              /* instruction */
00183   };
00184 
00185 struct fq
00186   {
00187     union                          /* FPU inst/addr queue */
00188       {
00189         double whole;
00190         struct fpq fpq;
00191       } FQu;
00192   };
00193 
00194 #define FPU_REGS_TYPE           unsigned
00195 #define FPU_DREGS_TYPE          unsigned long long
00196 #define V7_FPU_FSR_TYPE         unsigned
00197 #define V9_FPU_FSR_TYPE         unsigned long long
00198 #define V9_FPU_FPRS_TYPE        unsigned
00199 
00200 #if __WORDSIZE == 64
00201 
00202 typedef struct fpu
00203   {
00204     union {                        /* FPU floating point regs */
00205       unsigned              fpu_regs[32]; /* 32 singles */
00206       double            fpu_dregs[16];    /* 32 doubles */
00207       long double    fpu_qregs[16];  /* 16 quads */
00208     } fpu_fr;
00209     struct fq       *fpu_q;        /* ptr to array of FQ entries */
00210     unsigned long   fpu_fsr;              /* FPU status register */
00211     unsigned char   fpu_qcnt;             /* # of entries in saved FQ */
00212     unsigned char   fpu_q_entrysize;      /* # of bytes per FQ entry */
00213     unsigned char   fpu_en;        /* flag signifying fpu in use */
00214   } fpregset_t;
00215 
00216 #else /* __WORDSIZE == 32 */
00217 
00218 typedef struct fpu
00219   {
00220     union {                        /* FPU floating point regs */
00221       unsigned long long fpu_regs[32];    /* 32 singles */
00222       double             fpu_dregs[16];   /* 16 doubles */
00223     } fpu_fr;
00224     struct fq       *fpu_q;        /* ptr to array of FQ entries */
00225     unsigned        fpu_fsr;              /* FPU status register */
00226     unsigned char   fpu_qcnt;             /* # of entries in saved FQ */
00227     unsigned char   fpu_q_entrysize;      /* # of bytes per FQ entry */
00228     unsigned char   fpu_en;        /* flag signifying fpu in use */
00229   } fpregset_t;
00230 
00231 /*
00232  * The following structure is for associating extra register state with
00233  * the ucontext structure and is kept within the uc_mcontext filler area.
00234  *
00235  * If (xrs_id == XRS_ID) then the xrs_ptr field is a valid pointer to
00236  * extra register state. The exact format of the extra register state
00237  * pointed to by xrs_ptr is platform-dependent.
00238  *
00239  * Note: a platform may or may not manage extra register state.
00240  */
00241 typedef struct
00242   {
00243     unsigned int xrs_id;           /* indicates xrs_ptr validity */
00244     void *       xrs_ptr;          /* ptr to extra reg state */
00245   } xrs_t;
00246 
00247 #define XRS_ID       0x78727300           /* the string "xrs" */
00248 
00249 typedef struct
00250   {
00251     gregset_t   gregs;             /* general register set */
00252     gwindows_t  *gwins;            /* POSSIBLE pointer to register windows */
00253     fpregset_t  fpregs;            /* floating point register set */
00254     xrs_t       xrs;        /* POSSIBLE extra register state association */
00255     long        filler[19];
00256   } mcontext_t;
00257 
00258 
00259 /* Userlevel context.  */
00260 typedef struct ucontext
00261   {
00262     unsigned long   uc_flags;
00263     struct ucontext *uc_link;
00264     __sigset_t           uc_sigmask;
00265     stack_t         uc_stack;
00266     mcontext_t      uc_mcontext;
00267   } ucontext_t;
00268 
00269 #endif /* __WORDSIZE == 32 */
00270 #endif /* sys/ucontext.h */