1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22/*	All Rights Reserved	*/
23
24
25/*
26 * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
27 *
28 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
29 * Use is subject to license terms.
30 */
31
32#ifndef	_SYS_REGSET_H
33#define	_SYS_REGSET_H
34
35#include <sys/feature_tests.h>
36
37#if !defined(_ASM)
38#include <sys/int_types.h>
39#endif
40#include <sys/mcontext.h>
41
42#ifdef	__cplusplus
43extern "C" {
44#endif
45
46/*
47 * Location of the users' stored registers relative to R0.
48 * Usage is as an index into a gregset_t array or as u.u_ar0[XX].
49 */
50#if defined(__sparcv9)
51#define	REG_CCR (0)
52#if defined(_SYSCALL32)
53#define	REG_PSR (0)
54#endif /* _SYSCALL32 */
55#else
56#define	REG_PSR (0)
57#endif  /* __sparcv9 */
58
59#define	REG_PC	(1)
60#define	REG_nPC	(2)
61#define	REG_Y	(3)
62#define	REG_G1	(4)
63#define	REG_G2	(5)
64#define	REG_G3	(6)
65#define	REG_G4	(7)
66#define	REG_G5	(8)
67#define	REG_G6	(9)
68#define	REG_G7	(10)
69#define	REG_O0	(11)
70#define	REG_O1	(12)
71#define	REG_O2	(13)
72#define	REG_O3	(14)
73#define	REG_O4	(15)
74#define	REG_O5	(16)
75#define	REG_O6	(17)
76#define	REG_O7	(18)
77#if defined(__sparcv9)
78#define	REG_ASI	(19)
79#define	REG_FPRS (20)
80#endif	/* __sparcv9 */
81
82/* the following defines are for portability */
83#if !defined(__sparcv9)
84#define	REG_PS	REG_PSR
85#endif	/* __sparcv9 */
86#define	REG_SP	REG_O6
87#define	REG_R0	REG_O0
88#define	REG_R1	REG_O1
89
90#ifndef	_ASM
91
92#define	NGREG	_NGREG
93#define	MAXFPQ	_MAXFPQ
94
95/*
96 * The following structures define how a register window can appear on the
97 * stack. This structure is available (when required) through the `gwins'
98 * field of an mcontext (nested within ucontext). SPARC_MAXWINDOW is the
99 * maximum number of outstanding regiters window defined in the SPARC
100 * architecture (*not* implementation).
101 */
102#define	SPARC_MAXREGWINDOW	31	/* max windows in SPARC arch. */
103
104struct	rwindow {
105	greg_t	rw_local[8];		/* locals */
106	greg_t	rw_in[8];		/* ins */
107};
108
109#if defined(_SYSCALL32)
110
111struct rwindow32 {
112	greg32_t rw_local[8];		/* locals */
113	greg32_t rw_in[8];		/* ins */
114};
115
116struct rwindow64 {
117	greg64_t rw_local[8];		/* locals */
118	greg64_t rw_in[8];		/* ins */
119};
120
121#if defined(_KERNEL)
122extern	void	rwindow_nto32(struct rwindow *, struct rwindow32 *);
123extern	void	rwindow_32ton(struct rwindow32 *, struct rwindow *);
124#endif
125
126#endif	/* _SYSCALL32 */
127
128#define	rw_fp	rw_in[6]		/* frame pointer */
129#define	rw_rtn	rw_in[7]		/* return address */
130
131typedef struct _gwindows {
132	int		wbcnt;
133	greg_t		*spbuf[SPARC_MAXREGWINDOW];
134	struct rwindow	wbuf[SPARC_MAXREGWINDOW];
135} gwindows_t;
136
137#if defined(_SYSCALL32)
138
139typedef struct gwindows32 {
140	int32_t		wbcnt;
141	caddr32_t	spbuf[SPARC_MAXREGWINDOW];
142	struct rwindow32 wbuf[SPARC_MAXREGWINDOW];
143} gwindows32_t;
144
145typedef struct gwindows64 {
146	int		wbcnt;
147	greg64_t	*spbuf[SPARC_MAXREGWINDOW];
148	struct rwindow64 wbuf[SPARC_MAXREGWINDOW];
149} gwindows64_t;
150
151#endif	/* _SYSCALL32 */
152
153/*
154 * The following #define's are obsolete and may be removed in a future release.
155 * The corresponding integer types should be used instead (i.e. uint64_t).
156 */
157#define	FPU_REGS_TYPE		uint32_t
158#define	FPU_DREGS_TYPE		uint64_t
159#define	V7_FPU_FSR_TYPE		uint32_t
160#define	V9_FPU_FSR_TYPE		uint64_t
161#define	V9_FPU_FPRS_TYPE	uint32_t
162
163#define	XRS_ID			_XRS_ID
164
165#endif	/* !_ASM */
166
167/*
168 * The version of privregs.h that is used on implementations that run
169 * on processors that support the V9 instruction set is deliberately not
170 * imported here.
171 *
172 * The V9 'struct regs' definition is -not- compatible with either 32-bit
173 * or 64-bit core file contents, nor with the ucontext.  As a result, the
174 * 'regs' structure cannot be used portably by applications, and should
175 * only be used by the kernel implementation.
176 *
177 * The inclusion of the SPARC V7 version of privregs.h allows for some
178 * limited source compatibility with 32-bit applications who expect to use
179 * 'struct regs' to match the content of a 32-bit core file, or a ucontext_t.
180 *
181 * Note that the ucontext_t actually describes the general registers in
182 * terms of the gregset_t data type, as described in mcontex.h.  Note also
183 * that the core file content is defined by core(4) in terms of data types
184 * defined by procfs -- see proc(4).
185 */
186#if !defined(__sparcv9)
187#if !defined(_KERNEL) && !defined(_XPG4_2) || defined(__EXTENSIONS__)
188#include <v7/sys/privregs.h>
189#endif	/* !_KERNEL && !_XPG4_2 || __EXTENSIONS__ */
190#endif	/* __sparcv9 */
191
192#ifdef	__cplusplus
193}
194#endif
195
196#endif	/* _SYS_REGSET_H */
197