1 /* struct ucontext definition, RISC-V version.
2    Copyright (C) 1997-2018 Free Software Foundation, Inc.
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, see
16    <http://www.gnu.org/licenses/>.  */
17 
18 /* Don't rely on this, the interface is currently messed up and may need to
19    be broken to be fixed.  */
20 #ifndef _SYS_UCONTEXT_H
21 #define _SYS_UCONTEXT_H	1
22 
23 #include <features.h>
24 #include <signal.h>
25 #include <bits/sigcontext.h>
26 
27 typedef unsigned long int __riscv_mc_gp_state[32];
28 
29 #ifdef __USE_MISC
30 # define NGREG	32
31 
32 # define REG_PC 0
33 # define REG_RA 1
34 # define REG_SP 2
35 # define REG_TP 4
36 # define REG_S0 8
37 # define REG_S1 9
38 # define REG_A0 10
39 # define REG_S2 18
40 # define REG_NARGS 8
41 
42 typedef unsigned long int greg_t;
43 
44 /* Container for all general registers.  */
45 typedef __riscv_mc_gp_state gregset_t;
46 
47 /* Container for floating-point state.  */
48 typedef union __riscv_mc_fp_state fpregset_t;
49 #endif
50 
51 struct __riscv_mc_f_ext_state
52   {
53     unsigned int __f[32];
54     unsigned int __fcsr;
55   };
56 
57 struct __riscv_mc_d_ext_state
58   {
59     unsigned long long int __f[32];
60     unsigned int __fcsr;
61   };
62 
63 struct __riscv_mc_q_ext_state
64   {
65     unsigned long long int __f[64] __attribute__ ((__aligned__ (16)));
66     unsigned int __fcsr;
67     /* Reserved for expansion of sigcontext structure.  Currently zeroed
68        upon signal, and must be zero upon sigreturn.  */
69     unsigned int __glibc_reserved[3];
70   };
71 
72 union __riscv_mc_fp_state
73   {
74     struct __riscv_mc_f_ext_state __f;
75     struct __riscv_mc_d_ext_state __d;
76     struct __riscv_mc_q_ext_state __q;
77   };
78 
79 typedef struct mcontext_t
80   {
81     __riscv_mc_gp_state __gregs;
82     union  __riscv_mc_fp_state __fpregs;
83   } mcontext_t;
84 
85 /* Userlevel context.  */
86 typedef struct ucontext
87   {
88     unsigned long int  __uc_flags;
89     struct ucontext   *uc_link;
90     stack_t            uc_stack;
91     sigset_t           uc_sigmask;
92     /* There's some padding here to allow sigset_t to be expanded in the
93        future.  Though this is unlikely, other architectures put uc_sigmask
94        at the end of this structure and explicitly state it can be
95        expanded, so we didn't want to box ourselves in here.  */
96     char               __glibc_reserved[1024 / 8 - sizeof (sigset_t)];
97     /* We can't put uc_sigmask at the end of this structure because we need
98        to be able to expand sigcontext in the future.  For example, the
99        vector ISA extension will almost certainly add ISA state.  We want
100        to ensure all user-visible ISA state can be saved and restored via a
101        ucontext, so we're putting this at the end in order to allow for
102        infinite extensibility.  Since we know this will be extended and we
103        assume sigset_t won't be extended an extreme amount, we're
104        prioritizing this.  */
105     mcontext_t uc_mcontext;
106   } ucontext_t;
107 
108 #endif /* sys/ucontext.h */
109