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