Blame sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h

Packit 6c4009
/* Copyright (C) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _SYS_UCONTEXT_H
Packit 6c4009
#define _SYS_UCONTEXT_H	1
Packit 6c4009
Packit 6c4009
#include <features.h>
Packit 6c4009
Packit 6c4009
#include <bits/types/sigset_t.h>
Packit 6c4009
#include <bits/types/stack_t.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
# define __ctx(fld) fld
Packit 6c4009
#else
Packit 6c4009
# define __ctx(fld) __ ## fld
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
struct __ctx(pt_regs);
Packit 6c4009
Packit 6c4009
#if __WORDSIZE == 32
Packit 6c4009
Packit 6c4009
/* Number of general registers.  */
Packit 6c4009
# define __NGREG	48
Packit 6c4009
# ifdef __USE_MISC
Packit 6c4009
#  define NGREG	__NGREG
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
/* Container for all general registers.  */
Packit 6c4009
typedef unsigned long gregset_t[__NGREG];
Packit 6c4009
Packit 6c4009
/* Container for floating-point registers and status */
Packit 6c4009
typedef struct _libc_fpstate
Packit 6c4009
{
Packit 6c4009
	double __ctx(fpregs)[32];
Packit 6c4009
	double __ctx(fpscr);
Packit 6c4009
	unsigned int _pad[2];
Packit 6c4009
} fpregset_t;
Packit 6c4009
Packit 6c4009
/* Container for Altivec/VMX registers and status.
Packit 6c4009
   Needs to be aligned on a 16-byte boundary. */
Packit 6c4009
typedef struct _libc_vrstate
Packit 6c4009
{
Packit 6c4009
	unsigned int __ctx(vrregs)[32][4];
Packit 6c4009
	unsigned int __ctx(vrsave);
Packit 6c4009
	unsigned int _pad[2];
Packit 6c4009
	unsigned int __ctx(vscr);
Packit 6c4009
} vrregset_t;
Packit 6c4009
Packit 6c4009
/* Context to describe whole processor state.  */
Packit 6c4009
typedef struct
Packit 6c4009
{
Packit 6c4009
	gregset_t __ctx(gregs);
Packit 6c4009
	fpregset_t __ctx(fpregs);
Packit 6c4009
	vrregset_t __ctx(vrregs) __attribute__((__aligned__(16)));
Packit 6c4009
} mcontext_t;
Packit 6c4009
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
/* For 64-bit kernels with Altivec support, a machine context is exactly
Packit 6c4009
 * a sigcontext.  For older kernel (without Altivec) the sigcontext matches
Packit 6c4009
 * the mcontext upto but not including the v_regs field.  For kernels that
Packit 6c4009
 * don't set AT_HWCAP or return AT_HWCAP without PPC_FEATURE_HAS_ALTIVEC the
Packit 6c4009
 * v_regs field may not exist and should not be referenced.  The v_regd field
Packit 6c4009
 * can be refernced safely only after verifying that PPC_FEATURE_HAS_ALTIVEC
Packit 6c4009
 * is set in AT_HWCAP.  */
Packit 6c4009
Packit 6c4009
/* Number of general registers.  */
Packit 6c4009
# define __NGREG	48	/* includes r0-r31, nip, msr, lr, etc.   */
Packit 6c4009
# define __NFPREG	33	/* includes fp0-fp31 &fpscr.  */
Packit 6c4009
# define __NVRREG	34	/* includes v0-v31, vscr, & vrsave in
Packit 6c4009
				   split vectors */
Packit 6c4009
# ifdef __USE_MISC
Packit 6c4009
#  define NGREG	__NGREG
Packit 6c4009
#  define NFPREG	__NFPREG
Packit 6c4009
#  define NVRREG	__NVRREG
Packit 6c4009
# endif
Packit 6c4009
Packit 6c4009
typedef unsigned long gregset_t[__NGREG];
Packit 6c4009
typedef double fpregset_t[__NFPREG];
Packit 6c4009
Packit 6c4009
/* Container for Altivec/VMX Vector Status and Control Register.  Only 32-bits
Packit 6c4009
   but can only be copied to/from a 128-bit vector register.  So we allocated
Packit 6c4009
   a whole quadword speedup save/restore.  */
Packit 6c4009
typedef struct _libc_vscr
Packit 6c4009
{
Packit 6c4009
	unsigned int __pad[3];
Packit 6c4009
	unsigned int __ctx(vscr_word);
Packit 6c4009
} vscr_t;
Packit 6c4009
Packit 6c4009
/* Container for Altivec/VMX registers and status.
Packit 6c4009
   Must to be aligned on a 16-byte boundary. */
Packit 6c4009
typedef struct _libc_vrstate
Packit 6c4009
{
Packit 6c4009
	unsigned int	__ctx(vrregs)[32][4];
Packit 6c4009
	vscr_t		__ctx(vscr);
Packit 6c4009
	unsigned int	__ctx(vrsave);
Packit 6c4009
	unsigned int	__pad[3];
Packit 6c4009
} vrregset_t  __attribute__((__aligned__(16)));
Packit 6c4009
Packit 6c4009
typedef struct {
Packit 6c4009
	unsigned long	__glibc_reserved[4];
Packit 6c4009
	int		__ctx(signal);
Packit 6c4009
	int		__pad0;
Packit 6c4009
	unsigned long	__ctx(handler);
Packit 6c4009
	unsigned long	__ctx(oldmask);
Packit 6c4009
	struct __ctx(pt_regs)	*__ctx(regs);
Packit 6c4009
	gregset_t	__ctx(gp_regs);
Packit 6c4009
	fpregset_t	__ctx(fp_regs);
Packit 6c4009
/*
Packit 6c4009
 * To maintain compatibility with current implementations the sigcontext is
Packit 6c4009
 * extended by appending a pointer (v_regs) to a quadword type (elf_vrreg_t)
Packit 6c4009
 * followed by an unstructured (vmx_reserve) field of 69 doublewords.  This
Packit 6c4009
 * allows the array of vector registers to be quadword aligned independent of
Packit 6c4009
 * the alignment of the containing sigcontext or ucontext. It is the
Packit 6c4009
 * responsibility of the code setting the sigcontext to set this pointer to
Packit 6c4009
 * either NULL (if this processor does not support the VMX feature) or the
Packit 6c4009
 * address of the first quadword within the allocated (vmx_reserve) area.
Packit 6c4009
 *
Packit 6c4009
 * The pointer (v_regs) of vector type (elf_vrreg_t) is essentually
Packit 6c4009
 * an array of 34 quadword entries.  The entries with
Packit 6c4009
 * indexes 0-31 contain the corresponding vector registers.  The entry with
Packit 6c4009
 * index 32 contains the vscr as the last word (offset 12) within the
Packit 6c4009
 * quadword.  This allows the vscr to be stored as either a quadword (since
Packit 6c4009
 * it must be copied via a vector register to/from storage) or as a word.
Packit 6c4009
 * The entry with index 33 contains the vrsave as the first word (offset 0)
Packit 6c4009
 * within the quadword.
Packit 6c4009
 */
Packit 6c4009
	vrregset_t	*__ctx(v_regs);
Packit 6c4009
	long		__ctx(vmx_reserve)[__NVRREG+__NVRREG+1];
Packit 6c4009
} mcontext_t;
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Userlevel context.  */
Packit 6c4009
typedef struct ucontext_t
Packit 6c4009
  {
Packit 6c4009
    unsigned long int __ctx(uc_flags);
Packit 6c4009
    struct ucontext_t *uc_link;
Packit 6c4009
    stack_t uc_stack;
Packit 6c4009
#if __WORDSIZE == 32
Packit 6c4009
    /*
Packit 6c4009
     * These fields are set up this way to maximize source and
Packit 6c4009
     * binary compatibility with code written for the old
Packit 6c4009
     * ucontext_t definition, which didn't include space for the
Packit 6c4009
     * registers.
Packit 6c4009
     *
Packit 6c4009
     * Different versions of the kernel have stored the registers on
Packit 6c4009
     * signal delivery at different offsets from the ucontext struct.
Packit 6c4009
     * Programs should thus use the uc_mcontext.uc_regs pointer to
Packit 6c4009
     * find where the registers are actually stored.  The registers
Packit 6c4009
     * will be stored within the ucontext_t struct but not necessarily
Packit 6c4009
     * at a fixed address.  As a side-effect, this lets us achieve
Packit 6c4009
     * 16-byte alignment for the register storage space if the
Packit 6c4009
     * Altivec registers are to be saved, without requiring 16-byte
Packit 6c4009
     * alignment on the whole ucontext_t.
Packit 6c4009
     *
Packit 6c4009
     * The uc_mcontext.regs field is included for source compatibility
Packit 6c4009
     * with programs written against the older ucontext_t definition,
Packit 6c4009
     * and its name should therefore not change.  The uc_pad field
Packit 6c4009
     * is for binary compatibility with programs compiled against the
Packit 6c4009
     * old ucontext_t; it ensures that uc_mcontext.regs and uc_sigmask
Packit 6c4009
     * are at the same offset as previously.
Packit 6c4009
     */
Packit 6c4009
    int __glibc_reserved1[7];
Packit 6c4009
    union __ctx(uc_regs_ptr) {
Packit 6c4009
      struct __ctx(pt_regs) *__ctx(regs);
Packit 6c4009
      mcontext_t *__ctx(uc_regs);
Packit 6c4009
    } uc_mcontext;
Packit 6c4009
    sigset_t    uc_sigmask;
Packit 6c4009
    /* last for extensibility */
Packit 6c4009
    char __ctx(uc_reg_space)[sizeof(mcontext_t) + 12];
Packit 6c4009
#else /* 64-bit */
Packit 6c4009
    sigset_t    uc_sigmask;
Packit 6c4009
    mcontext_t  uc_mcontext;  /* last for extensibility */
Packit 6c4009
#endif
Packit 6c4009
  } ucontext_t;
Packit 6c4009
Packit 6c4009
#undef __ctx
Packit 6c4009
Packit 6c4009
#endif /* sys/ucontext.h */