xref: /freebsd/sys/x86/include/reg.h (revision d9a42747950146bf03cda7f6e25d219253f8a57a)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2003 Peter Wemm.
5  * Copyright (c) 1990 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * William Jolitz.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	from: @(#)reg.h	5.5 (Berkeley) 1/18/91
36  * $FreeBSD$
37  */
38 
39 #ifndef _MACHINE_REG_H_
40 #define	_MACHINE_REG_H_
41 
42 #include <sys/_types.h>
43 
44 #ifdef __i386__
45 /*
46  * Indices for registers in `struct trapframe' and `struct regs'.
47  *
48  * This interface is deprecated.  In the kernel, it is only used in FPU
49  * emulators to convert from register numbers encoded in instructions to
50  * register values.  Everything else just accesses the relevant struct
51  * members.  In userland, debuggers tend to abuse this interface since
52  * they don't understand that `struct regs' is a struct.  I hope they have
53  * stopped accessing the registers in the trap frame via PT_{READ,WRITE}_U
54  * and we can stop supporting the user area soon.
55  */
56 #define	tFS	(0)
57 #define	tES	(1)
58 #define	tDS	(2)
59 #define	tEDI	(3)
60 #define	tESI	(4)
61 #define	tEBP	(5)
62 #define	tISP	(6)
63 #define	tEBX	(7)
64 #define	tEDX	(8)
65 #define	tECX	(9)
66 #define	tEAX	(10)
67 #define	tERR	(12)
68 #define	tEIP	(13)
69 #define	tCS	(14)
70 #define	tEFLAGS	(15)
71 #define	tESP	(16)
72 #define	tSS	(17)
73 
74 /*
75  * Indices for registers in `struct regs' only.
76  *
77  * Some registers live in the pcb and are only in an "array" with the
78  * other registers in application interfaces that copy all the registers
79  * to or from a `struct regs'.
80  */
81 #define	tGS	(18)
82 #endif /* __i386__ */
83 
84 /* Rename the structs below depending on the machine architecture. */
85 #ifdef	__i386__
86 #define	__reg32		reg
87 #define	__fpreg32	fpreg
88 #define	__dbreg32	dbreg
89 #define	__segbasereg32	segbasereg
90 #else
91 #define	__reg32		reg32
92 #define	__reg64		reg
93 #define	__fpreg32	fpreg32
94 #define	__fpreg64	fpreg
95 #define	__dbreg32	dbreg32
96 #define	__dbreg64	dbreg
97 #define	__segbasereg32	segbasereg32
98 #define	__segbasereg64	segbasereg
99 #define	__HAVE_REG32
100 #endif
101 
102 /*
103  * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS.
104  */
105 struct __reg32 {
106 	__uint32_t	r_fs;
107 	__uint32_t	r_es;
108 	__uint32_t	r_ds;
109 	__uint32_t	r_edi;
110 	__uint32_t	r_esi;
111 	__uint32_t	r_ebp;
112 	__uint32_t	r_isp;
113 	__uint32_t	r_ebx;
114 	__uint32_t	r_edx;
115 	__uint32_t	r_ecx;
116 	__uint32_t	r_eax;
117 	__uint32_t	r_trapno;
118 	__uint32_t	r_err;
119 	__uint32_t	r_eip;
120 	__uint32_t	r_cs;
121 	__uint32_t	r_eflags;
122 	__uint32_t	r_esp;
123 	__uint32_t	r_ss;
124 	__uint32_t	r_gs;
125 };
126 
127 struct __reg64 {
128 	__int64_t	r_r15;
129 	__int64_t	r_r14;
130 	__int64_t	r_r13;
131 	__int64_t	r_r12;
132 	__int64_t	r_r11;
133 	__int64_t	r_r10;
134 	__int64_t	r_r9;
135 	__int64_t	r_r8;
136 	__int64_t	r_rdi;
137 	__int64_t	r_rsi;
138 	__int64_t	r_rbp;
139 	__int64_t	r_rbx;
140 	__int64_t	r_rdx;
141 	__int64_t	r_rcx;
142 	__int64_t	r_rax;
143 	__uint32_t	r_trapno;
144 	__uint16_t	r_fs;
145 	__uint16_t	r_gs;
146 	__uint32_t	r_err;
147 	__uint16_t	r_es;
148 	__uint16_t	r_ds;
149 	__int64_t	r_rip;
150 	__int64_t	r_cs;
151 	__int64_t	r_rflags;
152 	__int64_t	r_rsp;
153 	__int64_t	r_ss;
154 };
155 
156 /*
157  * Register set accessible via /proc/$pid/fpregs.
158  *
159  * XXX should get struct from fpu.h.  Here we give a slightly
160  * simplified struct.  This may be too much detail.  Perhaps
161  * an array of unsigned longs is best.
162  */
163 struct __fpreg32 {
164 	__uint32_t	fpr_env[7];
165 	__uint8_t	fpr_acc[8][10];
166 	__uint32_t	fpr_ex_sw;
167 	__uint8_t	fpr_pad[64];
168 };
169 
170 struct __fpreg64 {
171 	__uint64_t	fpr_env[4];
172 	__uint8_t	fpr_acc[8][16];
173 	__uint8_t	fpr_xacc[16][16];
174 	__uint64_t	fpr_spare[12];
175 };
176 
177 /*
178  * Register set accessible via PT_GETXMMREGS (i386).
179  */
180 struct xmmreg {
181 	/*
182 	 * XXX should get struct from npx.h.  Here we give a slightly
183 	 * simplified struct.  This may be too much detail.  Perhaps
184 	 * an array of unsigned longs is best.
185 	 */
186 	__uint32_t	xmm_env[8];
187 	__uint8_t	xmm_acc[8][16];
188 	__uint8_t	xmm_reg[8][16];
189 	__uint8_t	xmm_pad[224];
190 };
191 
192 /*
193  * Register set accessible via /proc/$pid/dbregs.
194  */
195 struct __dbreg32 {
196 	__uint32_t	dr[8];	/* debug registers */
197 				/* Index 0-3: debug address registers */
198 				/* Index 4-5: reserved */
199 				/* Index 6: debug status */
200 				/* Index 7: debug control */
201 };
202 
203 struct __dbreg64 {
204 	__uint64_t	dr[16];	/* debug registers */
205 				/* Index 0-3: debug address registers */
206 				/* Index 4-5: reserved */
207 				/* Index 6: debug status */
208 				/* Index 7: debug control */
209 				/* Index 8-15: reserved */
210 };
211 
212 #define	DBREG_DR6_RESERVED1	0xffff0ff0
213 #define	DBREG_DR6_BMASK		0x000f
214 #define	DBREG_DR6_B(i)		(1 << (i))
215 #define	DBREG_DR6_BD		0x2000
216 #define	DBREG_DR6_BS		0x4000
217 #define	DBREG_DR6_BT		0x8000
218 
219 #define	DBREG_DR7_RESERVED1	0x0400
220 #define	DBREG_DR7_LOCAL_ENABLE	0x01
221 #define	DBREG_DR7_GLOBAL_ENABLE	0x02
222 #define	DBREG_DR7_LEN_1		0x00	/* 1 byte length          */
223 #define	DBREG_DR7_LEN_2		0x01
224 #define	DBREG_DR7_LEN_4		0x03
225 #define	DBREG_DR7_LEN_8		0x02
226 #define	DBREG_DR7_EXEC		0x00	/* break on execute       */
227 #define	DBREG_DR7_WRONLY	0x01	/* break on write         */
228 #define	DBREG_DR7_RDWR		0x03	/* break on read or write */
229 #define	DBREG_DR7_MASK(i)	\
230 	((__u_register_t)(0xf) << ((i) * 4 + 16) | 0x3 << (i) * 2)
231 #define	DBREG_DR7_SET(i, len, access, enable)				\
232 	((__u_register_t)((len) << 2 | (access)) << ((i) * 4 + 16) | 	\
233 	(enable) << (i) * 2)
234 #define	DBREG_DR7_GD		0x2000
235 #define	DBREG_DR7_ENABLED(d, i)	(((d) & 0x3 << (i) * 2) != 0)
236 #define	DBREG_DR7_ACCESS(d, i)	((d) >> ((i) * 4 + 16) & 0x3)
237 #define	DBREG_DR7_LEN(d, i)	((d) >> ((i) * 4 + 18) & 0x3)
238 
239 #define	DBREG_DRX(d,x)	((d)->dr[(x)])	/* reference dr0 - dr7 by
240 					   register number */
241 
242 /*
243  * Register set accessible via NT_X86_SEGBASES.
244  */
245 struct __segbasereg32 {
246 	__uint32_t	r_fsbase;
247 	__uint32_t	r_gsbase;
248 };
249 
250 struct __segbasereg64 {
251 	__uint64_t	r_fsbase;
252 	__uint64_t	r_gsbase;
253 };
254 
255 #undef __reg32
256 #undef __reg64
257 #undef __fpreg32
258 #undef __fpreg64
259 #undef __dbreg32
260 #undef __dbreg64
261 #undef __segbasereg32
262 #undef __segbasereg64
263 
264 #ifdef _KERNEL
265 /*
266  * XXX these interfaces are MI, so they should be declared in a MI place.
267  */
268 int	fill_frame_regs(struct trapframe *, struct reg *);
269 #endif
270 
271 #endif /* !_MACHINE_REG_H_ */
272