1bc0e913Gordon Ross/*
2bc0e913Gordon Ross * CDDL HEADER START
3bc0e913Gordon Ross *
4bc0e913Gordon Ross * The contents of this file are subject to the terms of the
5bc0e913Gordon Ross * Common Development and Distribution License (the "License").
6bc0e913Gordon Ross * You may not use this file except in compliance with the License.
7bc0e913Gordon Ross *
8bc0e913Gordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9bc0e913Gordon Ross * or http://www.opensolaris.org/os/licensing.
10bc0e913Gordon Ross * See the License for the specific language governing permissions
11bc0e913Gordon Ross * and limitations under the License.
12bc0e913Gordon Ross *
13bc0e913Gordon Ross * When distributing Covered Code, include this CDDL HEADER in each
14bc0e913Gordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15bc0e913Gordon Ross * If applicable, add the following below this CDDL HEADER, with the
16bc0e913Gordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
17bc0e913Gordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
18bc0e913Gordon Ross *
19bc0e913Gordon Ross * CDDL HEADER END
20bc0e913Gordon Ross */
21bc0e913Gordon Ross/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22bc0e913Gordon Ross/*	All Rights Reserved	*/
23bc0e913Gordon Ross
24bc0e913Gordon Ross
25bc0e913Gordon Ross/*
26bc0e913Gordon Ross * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27bc0e913Gordon Ross * Use is subject to license terms.
28bc0e913Gordon Ross *
29bc0e913Gordon Ross * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
30bc0e913Gordon Ross */
31bc0e913Gordon Ross
32bc0e913Gordon Ross/*
33bc0e913Gordon Ross * Essential struct definitions for mcontext_t needed by ucontext.h
34bc0e913Gordon Ross * These were formerly in regset.h, which now includes this file.
35bc0e913Gordon Ross */
36bc0e913Gordon Ross
37bc0e913Gordon Ross#ifndef	_SYS_MCONTEXT_H
38bc0e913Gordon Ross#define	_SYS_MCONTEXT_H
39bc0e913Gordon Ross
40bc0e913Gordon Ross#include <sys/feature_tests.h>
41bc0e913Gordon Ross
42bc0e913Gordon Ross#if !defined(_ASM)
43bc0e913Gordon Ross#include <sys/int_types.h>
44bc0e913Gordon Ross#endif
45bc0e913Gordon Ross
46bc0e913Gordon Ross#ifdef	__cplusplus
47bc0e913Gordon Rossextern "C" {
48bc0e913Gordon Ross#endif
49bc0e913Gordon Ross
50bc0e913Gordon Ross/*
51bc0e913Gordon Ross * A gregset_t is defined as an array type for compatibility with the reference
52bc0e913Gordon Ross * source. This is important due to differences in the way the C language
53bc0e913Gordon Ross * treats arrays and structures as parameters.
54bc0e913Gordon Ross *
55bc0e913Gordon Ross * Note that NGREG is really (sizeof (struct regs) / sizeof (greg_t)),
56bc0e913Gordon Ross * but that the SPARC V8 ABI defines it absolutely to be 19.
57bc0e913Gordon Ross */
58bc0e913Gordon Ross#if defined(__sparcv9)
59bc0e913Gordon Ross#define	_NGREG	21
60bc0e913Gordon Ross#else	/* __sparcv9 */
61bc0e913Gordon Ross#define	_NGREG	19
62bc0e913Gordon Ross#endif	/* __sparcv9 */
63bc0e913Gordon Ross
64bc0e913Gordon Ross#ifndef	_ASM
65bc0e913Gordon Ross
66bc0e913Gordon Ross#if defined(_LP64) || defined(_I32LPx)
67bc0e913Gordon Rosstypedef long	greg_t;
68bc0e913Gordon Ross#else
69bc0e913Gordon Rosstypedef int	greg_t;
70bc0e913Gordon Ross#endif
71bc0e913Gordon Ross
72bc0e913Gordon Ross#if defined(_SYSCALL32)
73bc0e913Gordon Ross
74bc0e913Gordon Rosstypedef int32_t greg32_t;
75bc0e913Gordon Rosstypedef int64_t greg64_t;
76bc0e913Gordon Ross
77bc0e913Gordon Ross#endif	/* _SYSCALL32 */
78bc0e913Gordon Ross
79bc0e913Gordon Rosstypedef greg_t	gregset_t[_NGREG];
80bc0e913Gordon Ross
81bc0e913Gordon Ross#if defined(_SYSCALL32)
82bc0e913Gordon Ross
83bc0e913Gordon Ross#define	_NGREG32	19
84bc0e913Gordon Ross#define	_NGREG64	21
85bc0e913Gordon Ross
86bc0e913Gordon Rosstypedef	greg32_t gregset32_t[_NGREG32];
87bc0e913Gordon Rosstypedef greg64_t gregset64_t[_NGREG64];
88bc0e913Gordon Ross
89bc0e913Gordon Ross#endif	/* _SYSCALL32 */
90bc0e913Gordon Ross
91bc0e913Gordon Ross/*
92bc0e913Gordon Ross * Floating point definitions.
93bc0e913Gordon Ross */
94bc0e913Gordon Ross
95bc0e913Gordon Ross#define	_MAXFPQ	16	/* max # of fpu queue entries currently supported */
96bc0e913Gordon Ross
97bc0e913Gordon Ross/*
98bc0e913Gordon Ross * struct _fq defines the minimal format of a floating point instruction queue
99bc0e913Gordon Ross * entry. The size of entries in the floating point queue are implementation
100bc0e913Gordon Ross * dependent. The union FQu is guarenteed to be the first field in any ABI
101bc0e913Gordon Ross * conformant system implementation. Any additional fields provided by an
102bc0e913Gordon Ross * implementation should not be used applications designed to be ABI conformant.
103bc0e913Gordon Ross */
104bc0e913Gordon Ross
105bc0e913Gordon Rossstruct _fpq {
106bc0e913Gordon Ross	unsigned int *fpq_addr;		/* address */
107bc0e913Gordon Ross	unsigned int fpq_instr;		/* instruction */
108bc0e913Gordon Ross};
109bc0e913Gordon Ross
110bc0e913Gordon Rossstruct _fq {
111bc0e913Gordon Ross	union {				/* FPU inst/addr queue */
112bc0e913Gordon Ross		double whole;
113bc0e913Gordon Ross		struct _fpq fpq;
114bc0e913Gordon Ross	} FQu;
115bc0e913Gordon Ross};
116bc0e913Gordon Ross
117bc0e913Gordon Ross#if defined(_SYSCALL32)
118bc0e913Gordon Ross
119bc0e913Gordon Rossstruct fpq32 {
120bc0e913Gordon Ross	caddr32_t	fpq_addr;	/* address */
121bc0e913Gordon Ross	uint32_t	fpq_instr;	/* instruction */
122bc0e913Gordon Ross};
123bc0e913Gordon Ross
124bc0e913Gordon Rossstruct fq32 {
125bc0e913Gordon Ross	union {				/* FPU inst/addr queue */
126bc0e913Gordon Ross		double whole;
127bc0e913Gordon Ross		struct fpq32 fpq;
128bc0e913Gordon Ross	} FQu;
129bc0e913Gordon Ross};
130bc0e913Gordon Ross
131bc0e913Gordon Ross#endif	/* _SYSCALL32 */
132bc0e913Gordon Ross
133bc0e913Gordon Ross/*
134bc0e913Gordon Ross * struct fpu is the floating point processor state. struct fpu is the sum
135bc0e913Gordon Ross * total of all possible floating point state which includes the state of
136bc0e913Gordon Ross * external floating point hardware, fpa registers, etc..., if it exists.
137bc0e913Gordon Ross *
138bc0e913Gordon Ross * A floating point instuction queue may or may not be associated with
139bc0e913Gordon Ross * the floating point processor state. If a queue does exist, the field
140bc0e913Gordon Ross * fpu_q will point to an array of fpu_qcnt entries where each entry is
141bc0e913Gordon Ross * fpu_q_entrysize long. fpu_q_entry has a lower bound of sizeof (union FQu)
142bc0e913Gordon Ross * and no upper bound. If no floating point queue entries are associated
143bc0e913Gordon Ross * with the processor state, fpu_qcnt will be zeo and fpu_q will be NULL.
144bc0e913Gordon Ross */
145bc0e913Gordon Ross
146bc0e913Gordon Ross#if defined(__sparcv9)
147bc0e913Gordon Ross
148bc0e913Gordon Rossstruct _fpu {
149bc0e913Gordon Ross	union {					/* FPU floating point regs */
150bc0e913Gordon Ross		uint32_t	fpu_regs[32];	/* 32 singles */
151bc0e913Gordon Ross		double		fpu_dregs[32];	/* 32 doubles */
152bc0e913Gordon Ross		long double	fpu_qregs[16];	/* 16 quads */
153bc0e913Gordon Ross	} fpu_fr;
154bc0e913Gordon Ross	struct _fq	*fpu_q;			/* ptr to array of FQ entries */
155bc0e913Gordon Ross	uint64_t	fpu_fsr;		/* FPU status register */
156bc0e913Gordon Ross	uint8_t		fpu_qcnt;		/* # of entries in saved FQ */
157bc0e913Gordon Ross	uint8_t		fpu_q_entrysize;	/* # of bytes per FQ entry */
158bc0e913Gordon Ross	uint8_t		fpu_en;			/* flag specifying fpu in use */
159bc0e913Gordon Ross};
160bc0e913Gordon Ross
161bc0e913Gordon Ross#else	/* __sparcv9 */
162bc0e913Gordon Ross
163bc0e913Gordon Rossstruct _fpu {
164bc0e913Gordon Ross	union {					/* FPU floating point regs */
165bc0e913Gordon Ross		uint32_t	fpu_regs[32];	/* 32 singles */
166bc0e913Gordon Ross		double		fpu_dregs[16];	/* 16 doubles */
167bc0e913Gordon Ross	} fpu_fr;
168bc0e913Gordon Ross	struct _fq	*fpu_q;			/* ptr to array of FQ entries */
169bc0e913Gordon Ross	uint32_t	fpu_fsr;		/* FPU status register */
170bc0e913Gordon Ross	uint8_t		fpu_qcnt;		/* # of entries in saved FQ */
171bc0e913Gordon Ross	uint8_t		fpu_q_entrysize;	/* # of bytes per FQ entry */
172bc0e913Gordon Ross	uint8_t		fpu_en;			/* flag signifying fpu in use */
173bc0e913Gordon Ross};
174bc0e913Gordon Ross
175bc0e913Gordon Ross#endif	/* __sparcv9 */
176bc0e913Gordon Ross
177bc0e913Gordon Rosstypedef struct _fpu	fpregset_t;
178bc0e913Gordon Ross
179bc0e913Gordon Ross#if defined(_SYSCALL32)
180bc0e913Gordon Ross
181bc0e913Gordon Ross/* Kernel view of user sparcv7/v8 fpu structure */
182bc0e913Gordon Ross
183bc0e913Gordon Rossstruct fpu32 {
184bc0e913Gordon Ross	union {					/* FPU floating point regs */
185bc0e913Gordon Ross		uint32_t	fpu_regs[32];	/* 32 singles */
186bc0e913Gordon Ross		double		fpu_dregs[16];	/* 16 doubles */
187bc0e913Gordon Ross	} fpu_fr;
188bc0e913Gordon Ross	caddr32_t	fpu_q;			/* ptr to array of FQ entries */
189bc0e913Gordon Ross	uint32_t	fpu_fsr;		/* FPU status register */
190bc0e913Gordon Ross	uint8_t		fpu_qcnt;		/* # of entries in saved FQ */
191bc0e913Gordon Ross	uint8_t		fpu_q_entrysize;	/* # of bytes per FQ entry */
192bc0e913Gordon Ross	uint8_t		fpu_en;			/* flag signifying fpu in use */
193bc0e913Gordon Ross};
194bc0e913Gordon Ross
195bc0e913Gordon Rosstypedef struct fpu32	fpregset32_t;
196bc0e913Gordon Ross
197bc0e913Gordon Ross#endif	/* _SYSCALL32 */
198bc0e913Gordon Ross
199bc0e913Gordon Ross#if defined(_KERNEL) || defined(_KMDB)
200bc0e913Gordon Ross/*
201bc0e913Gordon Ross * The ABI uses struct fpu, so we use this to describe the kernel's view of the
202bc0e913Gordon Ross * fpu.
203bc0e913Gordon Ross */
204bc0e913Gordon Rosstypedef struct {
205bc0e913Gordon Ross	union _fpu_fr {				/* V9 FPU floating point regs */
206bc0e913Gordon Ross		uint32_t	fpu_regs[32];	/* 32 singles */
207bc0e913Gordon Ross		uint64_t	fpu_dregs[32];	/* 32 doubles */
208bc0e913Gordon Ross		long double	fpu_qregs[16];	/* 16 quads */
209bc0e913Gordon Ross	} fpu_fr;
210bc0e913Gordon Ross	uint64_t	fpu_fsr;		/* FPU status register */
211bc0e913Gordon Ross	uint32_t	 fpu_fprs;		/* fprs register */
212bc0e913Gordon Ross	struct _fq	*fpu_q;
213bc0e913Gordon Ross	uint8_t		fpu_qcnt;
214bc0e913Gordon Ross	uint8_t		fpu_q_entrysize;
215bc0e913Gordon Ross	uint8_t		fpu_en;			/* flag signifying fpu in use */
216bc0e913Gordon Ross} kfpu_t;
217bc0e913Gordon Ross#endif /* _KERNEL || _KMDB */
218bc0e913Gordon Ross
219bc0e913Gordon Ross/*
220bc0e913Gordon Ross * The following structure is for associating extra register state with
221bc0e913Gordon Ross * the ucontext structure and is kept within the uc_mcontext filler area.
222bc0e913Gordon Ross *
223bc0e913Gordon Ross * If (xrs_id == XRS_ID) then the xrs_ptr field is a valid pointer to
224bc0e913Gordon Ross * extra register state. The exact format of the extra register state
225bc0e913Gordon Ross * pointed to by xrs_ptr is platform-dependent.
226bc0e913Gordon Ross *
227bc0e913Gordon Ross * Note: a platform may or may not manage extra register state.
228bc0e913Gordon Ross */
229bc0e913Gordon Rosstypedef struct {
230bc0e913Gordon Ross	unsigned int	xrs_id;		/* indicates xrs_ptr validity */
231bc0e913Gordon Ross	caddr_t		xrs_ptr;	/* ptr to extra reg state */
232bc0e913Gordon Ross} xrs_t;
233bc0e913Gordon Ross
234bc0e913Gordon Ross#define	_XRS_ID			0x78727300	/* the string "xrs" */
235bc0e913Gordon Ross
236bc0e913Gordon Ross#if defined(_SYSCALL32)
237bc0e913Gordon Ross
238bc0e913Gordon Rosstypedef	struct {
239bc0e913Gordon Ross	uint32_t	xrs_id;		/* indicates xrs_ptr validity */
240bc0e913Gordon Ross	caddr32_t	xrs_ptr;	/* ptr to extra reg state */
241bc0e913Gordon Ross} xrs32_t;
242bc0e913Gordon Ross
243bc0e913Gordon Ross#endif	/* _SYSCALL32 */
244bc0e913Gordon Ross
245bc0e913Gordon Ross#if defined(__sparcv9)
246bc0e913Gordon Ross
247bc0e913Gordon Ross/*
248bc0e913Gordon Ross * Ancillary State Registers
249bc0e913Gordon Ross *
250bc0e913Gordon Ross * The SPARC V9 architecture defines 25 ASRs, numbered from 7 through 31.
251bc0e913Gordon Ross * ASRs 16 through 31 are available to user programs, though the meaning
252bc0e913Gordon Ross * and content of these registers is implementation dependent.
253bc0e913Gordon Ross */
254bc0e913Gordon Rosstypedef	int64_t	asrset_t[16];	/* %asr16 - > %asr31 */
255bc0e913Gordon Ross
256bc0e913Gordon Ross#endif	/* __sparcv9 */
257bc0e913Gordon Ross
258bc0e913Gordon Ross/*
259bc0e913Gordon Ross * Structure mcontext defines the complete hardware machine state. If
260bc0e913Gordon Ross * the field `gwins' is non NULL, it points to a save area for register
261bc0e913Gordon Ross * window frames. If `gwins' is NULL, the register windows were saved
262bc0e913Gordon Ross * on the user's stack.
263bc0e913Gordon Ross *
264bc0e913Gordon Ross * The filler of 21 longs is historical (now filler[19] plus the xrs_t
265bc0e913Gordon Ross * field). The value was selected to provide binary compatibility with
266bc0e913Gordon Ross * statically linked ICL binaries. It is in the ABI (do not change). It
267bc0e913Gordon Ross * actually appears in the ABI as a single filler of 44 is in the field
268bc0e913Gordon Ross * uc_filler of struct ucontext. It is split here so that ucontext.h can
269bc0e913Gordon Ross * (hopefully) remain architecture independent.
270bc0e913Gordon Ross *
271bc0e913Gordon Ross * Note that 2 longs of the filler are used to hold extra register state info.
272bc0e913Gordon Ross */
273bc0e913Gordon Rosstypedef struct {
274bc0e913Gordon Ross	gregset_t	gregs;	/* general register set */
275bc0e913Gordon Ross	struct _gwindows *gwins; /* POSSIBLE pointer to register windows */
276bc0e913Gordon Ross	fpregset_t	fpregs;	/* floating point register set */
277bc0e913Gordon Ross	xrs_t		xrs;	/* POSSIBLE extra register state association */
278bc0e913Gordon Ross#if defined(__sparcv9)
279bc0e913Gordon Ross	asrset_t	asrs;		/* ancillary registers */
280bc0e913Gordon Ross	long		filler[4];	/* room for expansion */
281bc0e913Gordon Ross#else	/* __sparcv9 */
282bc0e913Gordon Ross	long		filler[19];
283bc0e913Gordon Ross#endif	/* __sparcv9 */
284bc0e913Gordon Ross} mcontext_t;
285bc0e913Gordon Ross
286bc0e913Gordon Ross#if defined(_SYSCALL32)
287bc0e913Gordon Ross
288bc0e913Gordon Rosstypedef struct {
289bc0e913Gordon Ross	gregset32_t	gregs;	/* general register set */
290bc0e913Gordon Ross	caddr32_t	gwins;	/* POSSIBLE pointer to register windows */
291bc0e913Gordon Ross	fpregset32_t	fpregs;	/* floating point register set */
292bc0e913Gordon Ross	xrs32_t		xrs;	/* POSSIBLE extra register state association */
293bc0e913Gordon Ross	int32_t		filler[19];
294bc0e913Gordon Ross} mcontext32_t;
295bc0e913Gordon Ross
296bc0e913Gordon Ross#endif /* _SYSCALL32 */
297bc0e913Gordon Ross
298bc0e913Gordon Ross#endif	/* _ASM */
299bc0e913Gordon Ross
300bc0e913Gordon Ross#ifdef	__cplusplus
301bc0e913Gordon Ross}
302bc0e913Gordon Ross#endif
303bc0e913Gordon Ross
304bc0e913Gordon Ross#endif	/* _SYS_MCONTEXT_H */