xref: /illumos-gate/usr/src/uts/intel/sys/procfs_isa.h (revision 41e0a469c3dbc14deb2b200f6ca6f6e00b5865d0)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 2023 Oxide Computer Company
29  */
30 
31 #ifndef _SYS_PROCFS_ISA_H
32 #define	_SYS_PROCFS_ISA_H
33 
34 /*
35  * Instruction Set Architecture specific component of <sys/procfs.h>
36  * i386 version
37  */
38 
39 #include <sys/regset.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Possible values of pr_dmodel.
47  * This isn't isa-specific, but it needs to be defined here for other reasons.
48  */
49 #define	PR_MODEL_UNKNOWN 0
50 #define	PR_MODEL_ILP32	1	/* process data model is ILP32 */
51 #define	PR_MODEL_LP64	2	/* process data model is LP64 */
52 
53 /*
54  * To determine whether application is running native.
55  */
56 #if defined(_LP64)
57 #define	PR_MODEL_NATIVE	PR_MODEL_LP64
58 #elif defined(_ILP32)
59 #define	PR_MODEL_NATIVE	PR_MODEL_ILP32
60 #else
61 #error "No DATAMODEL_NATIVE specified"
62 #endif	/* _LP64 || _ILP32 */
63 
64 #if defined(__i386) || defined(__amd64)
65 /*
66  * Holds one i386 or amd64 instruction
67  */
68 typedef	uchar_t instr_t;
69 #endif
70 
71 #define	NPRGREG		_NGREG
72 #define	prgreg_t	greg_t
73 #define	prgregset_t	gregset_t
74 #define	prfpregset	_fpu
75 #define	prfpregset_t	fpregset_t
76 
77 #if defined(_SYSCALL32)
78 /*
79  * kernel view of the ia32 register set
80  */
81 typedef	uchar_t		instr32_t;
82 #if defined(__amd64)
83 #define	NPRGREG32	_NGREG32
84 #define	prgreg32_t	greg32_t
85 #define	prgregset32_t	gregset32_t
86 #define	prfpregset32	fpu32
87 #define	prfpregset32_t	fpregset32_t
88 #else
89 #define	NPRGREG32	_NGREG
90 #define	prgreg32_t	greg_t
91 #define	prgregset32_t	gregset_t
92 #define	prfpregset32	_fpu
93 #define	prfpregset32_t	fpregset_t
94 #endif
95 #endif	/* _SYSCALL32 */
96 
97 #if defined(__amd64)
98 /*
99  * The following defines are for portability (see <sys/regset.h>).
100  */
101 #define	R_PC	REG_RIP
102 #define	R_PS	REG_RFL
103 #define	R_SP	REG_RSP
104 #define	R_FP	REG_RBP
105 #define	R_R0	REG_RAX
106 #define	R_R1	REG_RDX
107 #elif defined(__i386)
108 /*
109  * The following defines are for portability (see <sys/regset.h>).
110  */
111 #define	R_PC	EIP
112 #define	R_PS	EFL
113 #define	R_SP	UESP
114 #define	R_FP	EBP
115 #define	R_R0	EAX
116 #define	R_R1	EDX
117 #endif
118 
119 /*
120  * The x86 xregs structure is a blob of data that contains a header with several
121  * descriptors that describe the region of additional data that corresponds to
122  * it. Effectively this looks like:
123  *
124  * 0  +-----------------+
125  *    | prxregset_hdr_t |
126  *    +-----------------+
127  *    | Info 0 (XCR)    |-------+
128  *    +-----------------+       |
129  *    | Info 1 (XSAVE)  |----------+
130  *    +-----------------+       |  |
131  *           ...                |  |
132  *    +-----------------+       |  |
133  *    | Info n (Hi ZMM) |-------------+
134  *    +-----------------+       |  |  |
135  *    +-----------------+       |  |  |
136  *    | prxregset_xcr_t |<------+  |  |
137  *    +-----------------+          |  |
138  *    +-------------------+        |  |
139  *    | prxregset_xsave_t |<-------+  |
140  *    |                   |           |
141  *    | XMM + xsave       |           |
142  *    +-------------------+           |
143  *           ...                      |
144  *    +---------------------+         |
145  *    | prxregset_hi_zmm_t  |<--------+
146  *    |                     |
147  *    | 1 KiB %zmm16-%zmm31 |
148  *    +---------------------+
149  *
150  * The actual structure size will vary based on the CPU features present. For
151  * more information, see proc(5). When adding structures, please make sure all
152  * structures are multiples of 16 bytes (0x10) so as to ensure alignment.
153  */
154 typedef struct prxregset prxregset_t;
155 
156 #define	PRX_INFO_XCR	0x01
157 #define	PRX_INFO_XSAVE	0x02
158 #define	PRX_INFO_YMM	0x03
159 #define	PRX_INFO_OPMASK	0x04
160 #define	PRX_INFO_ZMM	0x05
161 #define	PRX_INFO_HI_ZMM	0x06
162 
163 typedef struct prxregset_info {
164 	uint32_t pri_type;
165 	uint32_t pri_flags;
166 	uint32_t pri_size;
167 	uint32_t pri_offset;
168 } prxregset_info_t;
169 
170 #define	PR_TYPE_XSAVE	0x01
171 
172 typedef struct prxregset_hdr {
173 	uint32_t	pr_type;
174 	uint32_t	pr_size;
175 	uint32_t	pr_flags;
176 	uint32_t	pr_pad[4];
177 	uint32_t	pr_ninfo;
178 #if defined(_STDC_C99) || defined(__C99FEATURES__)
179 	prxregset_info_t pr_info[];
180 #endif
181 } prxregset_hdr_t;
182 
183 typedef struct prxregset_xcr {
184 	uint64_t	prx_xcr_xcr0;
185 	uint64_t	prx_xcr_xfd;
186 	uint64_t	prx_xcr_pad[2];
187 } prxregset_xcr_t;
188 
189 typedef struct prxregset_xsave {
190 	uint16_t	prx_fx_fcw;
191 	uint16_t	prx_fx_fsw;
192 	uint16_t	prx_fx_fctw;	/* compressed tag word */
193 	uint16_t	prx_fx_fop;
194 #if defined(__amd64)
195 	uint64_t	prx_fx_rip;
196 	uint64_t	prx_fx_rdp;
197 #else
198 	uint32_t	prx_fx_eip;
199 	uint16_t	prx_fx_cs;
200 	uint16_t	__prx_fx_ign0;
201 	uint32_t	prx_fx_dp;
202 	uint16_t	prx_fx_ds;
203 	uint16_t	__prx_fx_ign1;
204 #endif
205 	uint32_t	prx_fx_mxcsr;
206 	uint32_t	prx_fx_mxcsr_mask;
207 	union {
208 		uint16_t prx_fpr_16[5];	/* 80-bits of x87 state */
209 		u_longlong_t prx_fpr_mmx;	/* 64-bit mmx register */
210 		uint32_t _prx__fpr_pad[4];	/* (pad out to 128-bits) */
211 	} fx_st[8];
212 #if defined(__amd64)
213 	upad128_t	prx_fx_xmm[16];	/* 128-bit registers */
214 	upad128_t	__prx_fx_ign2[6];
215 #else
216 	upad128_t	prx_fx_xmm[8];	/* 128-bit registers */
217 	upad128_t	__prx_fx_ign2[14];
218 #endif
219 	uint64_t	prx_xsh_xstate_bv;
220 	uint64_t	prx_xsh_xcomp_bv;
221 	uint64_t	prx_xsh_reserved[6];
222 } prxregset_xsave_t;
223 
224 typedef struct prxregset_ymm {
225 #if defined(__amd64)
226 	upad128_t	prx_ymm[16];
227 #else
228 	upad128_t	prx_ymm[8];
229 	upad128_t	prx_rsvd[8];
230 #endif
231 } prxregset_ymm_t;
232 
233 typedef struct prxregset_opmask {
234 	uint64_t	prx_opmask[8];
235 } prxregset_opmask_t;
236 
237 typedef struct prxregset_zmm {
238 #if defined(__amd64)
239 	upad256_t	prx_zmm[16];
240 #else
241 	upad256_t	prx_zmm[8];
242 	upad256_t	prx_rsvd[8];
243 #endif
244 } prxregset_zmm_t;
245 
246 typedef struct prxregset_hi_zmm {
247 #if defined(__amd64)
248 	upad512_t	prx_hi_zmm[16];
249 #else
250 	upad512_t	prx_rsvd[16];
251 #endif
252 } prxregset_hi_zmm_t;
253 
254 #ifdef	__cplusplus
255 }
256 #endif
257 
258 #endif	/* _SYS_PROCFS_ISA_H */
259