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