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