2.5-18.1
[jlayton/glibc.git] / sysdeps / unix / sysv / linux / powerpc / sys / ucontext.h
1 /* Copyright (C) 1998, 1999, 2002, 2004, 2005 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
25 /* We need the signal context definitions even if they are not used
26    included in <signal.h>.  */
27 #include <bits/sigcontext.h>
28
29 #if __WORDSIZE == 32
30
31 /* Number of general registers.  */
32 # define NGREG  48
33
34 /* Container for all general registers.  */
35 typedef unsigned long gregset_t[NGREG];
36
37 /* Container for floating-point registers and status */
38 typedef struct _libc_fpstate
39 {
40         double fpregs[32];
41         double fpscr;
42         unsigned int _pad[2];
43 } fpregset_t;
44
45 /* Container for Altivec/VMX registers and status.
46    Needs to be aligned on a 16-byte boundary. */
47 typedef struct _libc_vrstate
48 {
49         unsigned int vrregs[32][4];
50         unsigned int vrsave;
51         unsigned int _pad[2];
52         unsigned int vscr;
53 } vrregset_t;
54
55 /* Context to describe whole processor state.  */
56 typedef struct
57 {
58         gregset_t gregs;
59         fpregset_t fpregs;
60         vrregset_t vrregs __attribute__((__aligned__(16)));
61 } mcontext_t;
62
63 #else
64
65 /* For 64-bit kernels with Altivec support, a machine context is exactly 
66  * a sigcontext.  For older kernel (without Altivec) the sigcontext matches 
67  * the mcontext upto but not including the v_regs field.  For kernels that 
68  * don't AT_HWCAP or return AT_HWCAP without PPC_FEATURE_HAS_ALTIVEC the 
69  * v_regs field may not exit and should not be referenced.  The v_regd field
70  * can be refernced safely only after verifying that PPC_FEATURE_HAS_ALTIVEC
71  * is set in AT_HWCAP.  */
72     
73 /* Number of general registers.  */
74 # define NGREG  48      /* includes r0-r31, nip, msr, lr, etc.   */
75 # define NFPREG 33      /* includes fp0-fp31 &fpscr.  */
76 # define NVRREG 34      /* includes v0-v31, vscr, & vrsave in split vectors */
77
78 typedef unsigned long gregset_t[NGREG];
79 typedef double fpregset_t[NFPREG];
80
81 /* Container for Altivec/VMX Vector Status and Control Register.  Only 32-bits
82    but can only be copied to/from a 128-bit vector register.  So we allocated 
83    a whole quadword speedup save/restore.  */
84 typedef struct _libc_vscr
85 {
86         unsigned int __pad[3];
87         unsigned int vscr_word;
88 } vscr_t;
89
90 /* Container for Altivec/VMX registers and status.
91    Must to be aligned on a 16-byte boundary. */
92 typedef struct _libc_vrstate
93 {
94         unsigned int    vrregs[32][4];
95         vscr_t          vscr;
96         unsigned int    vrsave;
97         unsigned int    __pad[3];
98 } vrregset_t  __attribute__((__aligned__(16)));
99
100 typedef struct {
101         unsigned long   __unused[4];
102         int             signal;
103         int             __pad0;
104         unsigned long   handler;
105         unsigned long   oldmask;
106         struct pt_regs  *regs;
107         gregset_t       gp_regs;
108         fpregset_t      fp_regs;
109 /*
110  * To maintain compatibility with current implementations the sigcontext is 
111  * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t) 
112  * followed by an unstructured (vmx_reserve) field of 69 doublewords.  This 
113  * allows the array of vector registers to be quadword aligned independent of 
114  * the alignment of the containing sigcontext or ucontext. It is the 
115  * responsibility of the code setting the sigcontext to set this pointer to 
116  * either NULL (if this processor does not support the VMX feature) or the 
117  * address of the first quadword within the allocated (vmx_reserve) area.
118  *
119  * The pointer (v_regs) of vector type (elf_vrreg_t) is essentually  
120  * an array of 34 quadword entries.  The entries with 
121  * indexes 0-31 contain the corresponding vector registers.  The entry with 
122  * index 32 contains the vscr as the last word (offset 12) within the 
123  * quadword.  This allows the vscr to be stored as either a quadword (since 
124  * it must be copied via a vector register to/from storage) or as a word.  
125  * The entry with index 33 contains the vrsave as the first word (offset 0) 
126  * within the quadword.
127  */
128         vrregset_t      *v_regs;
129         long            vmx_reserve[NVRREG+NVRREG+1];
130 } mcontext_t;
131
132 #endif
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 #if __WORDSIZE == 32
141     /*
142      * These fields are set up this way to maximize source and
143      * binary compatibility with code written for the old
144      * ucontext_t definition, which didn't include space for the
145      * registers.
146      *
147      * Different versions of the kernel have stored the registers on
148      * signal delivery at different offsets from the ucontext struct.
149      * Programs should thus use the uc_mcontext.uc_regs pointer to
150      * find where the registers are actually stored.  The registers
151      * will be stored within the ucontext_t struct but not necessarily
152      * at a fixed address.  As a side-effect, this lets us achieve
153      * 16-byte alignment for the register storage space if the
154      * Altivec registers are to be saved, without requiring 16-byte
155      * alignment on the whole ucontext_t.
156      *
157      * The uc_mcontext.regs field is included for source compatibility
158      * with programs written against the older ucontext_t definition,
159      * and its name should therefore not change.  The uc_pad field
160      * is for binary compatibility with programs compiled against the
161      * old ucontext_t; it ensures that uc_mcontext.regs and uc_sigmask
162      * are at the same offset as previously.
163      */
164     int uc_pad[7];
165     union uc_regs_ptr {
166       struct pt_regs *regs;
167       mcontext_t *uc_regs;
168     } uc_mcontext;
169     sigset_t    uc_sigmask;
170     char uc_reg_space[sizeof(mcontext_t) + 12];  /* last for extensibility */
171 #else /* 64-bit */
172     sigset_t    uc_sigmask;
173     mcontext_t  uc_mcontext;  /* last for extensibility */
174 #endif
175   } ucontext_t;
176
177 #endif /* sys/ucontext.h */