mcontext.h revision 1.3 1 /* $NetBSD: mcontext.h,v 1.3 2003/10/08 22:43:01 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _SPARC_MCONTEXT_H_
40 #define _SPARC_MCONTEXT_H_
41
42 /*
43 * Layout of mcontext_t according the System V Application Binary Interface,
44 * Edition 4.1, SPARC Processor ABI Supplement and updated for SPARC v9.
45 */
46
47 #ifdef __arch64__
48 #define _NGREG 21 /* %ccr, pc, npc, %g1-7, %o0-7, %asi, %fprs */
49 #else
50 #define _NGREG 19 /* %psr, pc, npc, %g1-7, %o0-7 */
51 #endif
52 typedef long int __greg_t;
53 typedef __greg_t __gregset_t[_NGREG];
54
55 /* Offsets into gregset_t, for convenience. */
56 #ifdef __arch64__
57 #define _REG_CCR 0
58 #else
59 #define _REG_PSR 0
60 #endif
61 #define _REG_PC 1
62 #define _REG_nPC 2
63 #define _REG_Y 3
64 #define _REG_G1 4
65 #define _REG_G2 5
66 #define _REG_G3 6
67 #define _REG_G4 7
68 #define _REG_G5 8
69 #define _REG_G6 9
70 #define _REG_G7 10
71 #define _REG_O0 11
72 #define _REG_O1 12
73 #define _REG_O2 13
74 #define _REG_O3 14
75 #define _REG_O4 15
76 #define _REG_O5 16
77 #define _REG_O6 17
78 #define _REG_O7 18
79 #ifdef __arch64__
80 #define _REG_ASI 19
81 #define _REG_FPRS 20
82 #endif
83
84
85 #define _SPARC_MAXREGWINDOW 31
86
87 /* Layout of a register window. */
88 typedef struct {
89 __greg_t __rw_local[8]; /* %l0-7 */
90 __greg_t __rw_in[8]; /* %i0-7 */
91 } __rwindow_t;
92
93 /* Description of available register windows. */
94 typedef struct {
95 int __wbcnt;
96 __greg_t * __spbuf[_SPARC_MAXREGWINDOW];
97 __rwindow_t __wbuf[_SPARC_MAXREGWINDOW];
98 } __gwindows_t;
99
100 /* FPU address queue */
101 struct __fpq {
102 unsigned int * __fpq_addr; /* address */
103 unsigned int __fpq_instr; /* instruction */
104 };
105
106 struct __fq {
107 union {
108 double __whole;
109 struct __fpq __fpq;
110 } _FQu;
111 };
112
113 /* FPU state description */
114 typedef struct {
115 union {
116 unsigned int __fpu_regs[32];
117 #ifdef __arch64__
118 double __fpu_dregs[32];
119 long double __fpu_qregs[16];
120 #else
121 double __fpu_dregs[16];
122 #endif
123 } __fpu_fr; /* FPR contents */
124 struct __fq * __fpu_q; /* pointer to FPU insn queue */
125 unsigned long __fpu_fsr; /* %fsr */
126 unsigned char __fpu_qcnt; /* # entries in __fpu_q */
127 unsigned char __fpu_q_entrysize; /* size of a __fpu_q entry */
128 unsigned char __fpu_en; /* this context valid? */
129 } __fpregset_t;
130
131 /* `Extra Register State'(?) */
132 typedef struct {
133 unsigned int __xrs_id; /* See below */
134 char * __xrs_ptr; /* points into filler area */
135 } __xrs_t;
136
137 #define _XRS_ID 0x78727300 /* 'xrs\0' */
138
139 #ifdef __arch64__
140 /* Ancillary State Registers, 16-31 are available to user programs */
141 typedef long __asrset_t[16]; /* %asr16-31 */
142 #endif
143
144 typedef struct {
145 __gregset_t __gregs; /* GPR state */
146 __gwindows_t * __gwins; /* may point to register windows */
147 __fpregset_t __fpregs; /* FPU state, if any */
148 __xrs_t __xrs; /* may indicate extra reg state */
149 #ifdef __arch64__
150 __asrset_t __asrs; /* ASR state */
151 #endif
152 #ifdef __arch64__
153 long int __filler[4];
154 #else
155 long int __filler[19];
156 #endif
157 } mcontext_t;
158
159 #ifdef __arch64__
160 #define _UC_MACHINE_PAD 4 /* Padding appended to ucontext_t */
161 #define _UC_MACHINE_SP(uc) (((uc)->uc_mcontext.__gregs[_REG_O6])+0x7ff)
162 #else
163 #define _UC_MACHINE_PAD 23 /* Padding appended to ucontext_t */
164 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6])
165 #endif
166 #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC])
167 #define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_O0])
168
169 #define _UC_MACHINE_SET_PC(uc, pc) \
170 do { \
171 (uc)->uc_mcontext.__gregs[_REG_PC] = (pc); \
172 (uc)->uc_mcontext.__gregs[_REG_nPC] = (pc) + 4; \
173 } while (/*CONSTCOND*/0)
174
175 #endif /* !_SPARC_MCONTEXT_H_ */
176