1 /* $NetBSD: mcontext.h,v 1.11 2021/05/24 21:00:12 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Klaus Klein.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _ALPHA_MCONTEXT_H_
33 #define _ALPHA_MCONTEXT_H_
34
35 /*
36 * General register state (important: 0-31 maps to `struct reg')
37 */
38 #define _NGREG 34 /* 0-31, PC, PS */
39 typedef unsigned long __greg_t;
40 typedef __greg_t __gregset_t[_NGREG];
41
42 /* Convenience synonyms */
43 #define _REG_V0 0
44 #define _REG_T0 1
45 #define _REG_T1 2
46 #define _REG_T2 3
47 #define _REG_T3 4
48 #define _REG_T4 5
49 #define _REG_T5 6
50 #define _REG_T6 7
51 #define _REG_T7 8
52 #define _REG_S0 9
53 #define _REG_S1 10
54 #define _REG_S2 11
55 #define _REG_S3 12
56 #define _REG_S4 13
57 #define _REG_S5 14
58 #define _REG_S6 15
59 #define _REG_A0 16
60 #define _REG_A1 17
61 #define _REG_A2 18
62 #define _REG_A3 19
63 #define _REG_A4 20
64 #define _REG_A5 21
65 #define _REG_T8 22
66 #define _REG_T9 23
67 #define _REG_T10 24
68 #define _REG_T11 25
69 #define _REG_RA 26
70 #define _REG_T12 27
71 #define _REG_PV 27
72 #define _REG_AT 28
73 #define _REG_GP 29
74 #define _REG_SP 30
75 #define _REG_UNIQUE 31
76 #define _REG_PC 32
77 #define _REG_PS 33
78
79 /*
80 * Floating point register state (important: maps to `struct fpreg')
81 */
82 typedef struct {
83 union {
84 unsigned long __fp_regs[32];
85 double __fp_dregs[32];
86 } __fp_fr;
87 unsigned long __fp_fpcr;
88 } __fpregset_t;
89
90 typedef struct {
91 __gregset_t __gregs;
92 __fpregset_t __fpregs;
93 } mcontext_t;
94
95 /* Machine-dependent uc_flags */
96 #define _UC_TLSBASE 0x20 /* valid process-unique value in _REG_UNIQUE */
97 #define _UC_SETSTACK 0x00010000
98 #define _UC_CLRSTACK 0x00020000
99
100 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_SP])
101 #define _UC_MACHINE_FP(uc) ((uc)->uc_mcontext.__gregs[_REG_S6])
102 #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
103 #define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_V0])
104
105 #define _UC_MACHINE_SET_PC(uc, pc) _UC_MACHINE_PC(uc) = (pc)
106
107 #if defined(_RTLD_SOURCE) || defined(_LIBC_SOURCE) || \
108 defined(__LIBPTHREAD_SOURCE__)
109 #include <sys/tls.h>
110
111 __BEGIN_DECLS
112 static __inline void *
__lwp_getprivate_fast(void)113 __lwp_getprivate_fast(void)
114 {
115 register void *__tmp __asm("$0");
116
117 __asm volatile("call_pal %1 # PAL_rdunique"
118 : "=r" (__tmp)
119 : "i" (0x009e /* PAL_rdunique */));
120
121 return __tmp;
122 }
123 __END_DECLS
124
125 #endif
126
127 #endif /* !_ALPHA_MCONTEXT_H_ */
128