]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/x86/include/reg.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / x86 / include / reg.h
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 #define __HAVE_REG32
95 #endif
96
97 /*
98  * Register set accessible via /proc/$pid/regs and PT_{SET,GET}REGS.
99  */
100 struct __reg32 {
101         __uint32_t      r_fs;
102         __uint32_t      r_es;
103         __uint32_t      r_ds;
104         __uint32_t      r_edi;
105         __uint32_t      r_esi;
106         __uint32_t      r_ebp;
107         __uint32_t      r_isp;
108         __uint32_t      r_ebx;
109         __uint32_t      r_edx;
110         __uint32_t      r_ecx;
111         __uint32_t      r_eax;
112         __uint32_t      r_trapno;
113         __uint32_t      r_err;
114         __uint32_t      r_eip;
115         __uint32_t      r_cs;
116         __uint32_t      r_eflags;
117         __uint32_t      r_esp;
118         __uint32_t      r_ss;
119         __uint32_t      r_gs;
120 };
121
122 struct __reg64 {
123         __int64_t       r_r15;
124         __int64_t       r_r14;
125         __int64_t       r_r13;
126         __int64_t       r_r12;
127         __int64_t       r_r11;
128         __int64_t       r_r10;
129         __int64_t       r_r9;
130         __int64_t       r_r8;
131         __int64_t       r_rdi;
132         __int64_t       r_rsi;
133         __int64_t       r_rbp;
134         __int64_t       r_rbx;
135         __int64_t       r_rdx;
136         __int64_t       r_rcx;
137         __int64_t       r_rax;
138         __uint32_t      r_trapno;
139         __uint16_t      r_fs;
140         __uint16_t      r_gs;
141         __uint32_t      r_err;
142         __uint16_t      r_es;
143         __uint16_t      r_ds;
144         __int64_t       r_rip;
145         __int64_t       r_cs;
146         __int64_t       r_rflags;
147         __int64_t       r_rsp;
148         __int64_t       r_ss;
149 };
150
151 /*
152  * Register set accessible via /proc/$pid/fpregs.
153  *
154  * XXX should get struct from fpu.h.  Here we give a slightly
155  * simplified struct.  This may be too much detail.  Perhaps
156  * an array of unsigned longs is best.
157  */
158 struct __fpreg32 {
159         __uint32_t      fpr_env[7];
160         __uint8_t       fpr_acc[8][10];
161         __uint32_t      fpr_ex_sw;
162         __uint8_t       fpr_pad[64];
163 };
164
165 struct __fpreg64 {
166         __uint64_t      fpr_env[4];
167         __uint8_t       fpr_acc[8][16];
168         __uint8_t       fpr_xacc[16][16];
169         __uint64_t      fpr_spare[12];
170 };
171
172 /*
173  * Register set accessible via PT_GETXMMREGS (i386).
174  */
175 struct xmmreg {
176         /*
177          * XXX should get struct from npx.h.  Here we give a slightly
178          * simplified struct.  This may be too much detail.  Perhaps
179          * an array of unsigned longs is best.
180          */
181         __uint32_t      xmm_env[8];
182         __uint8_t       xmm_acc[8][16];
183         __uint8_t       xmm_reg[8][16];
184         __uint8_t       xmm_pad[224];
185 };
186
187 /*
188  * Register set accessible via /proc/$pid/dbregs.
189  */
190 struct __dbreg32 {
191         __uint32_t      dr[8];  /* debug registers */
192                                 /* Index 0-3: debug address registers */
193                                 /* Index 4-5: reserved */
194                                 /* Index 6: debug status */
195                                 /* Index 7: debug control */
196 };
197
198 struct __dbreg64 {
199         __uint64_t      dr[16]; /* debug registers */
200                                 /* Index 0-3: debug address registers */
201                                 /* Index 4-5: reserved */
202                                 /* Index 6: debug status */
203                                 /* Index 7: debug control */
204                                 /* Index 8-15: reserved */
205 };
206
207 #define DBREG_DR7_LOCAL_ENABLE  0x01
208 #define DBREG_DR7_GLOBAL_ENABLE 0x02
209 #define DBREG_DR7_LEN_1         0x00    /* 1 byte length          */
210 #define DBREG_DR7_LEN_2         0x01
211 #define DBREG_DR7_LEN_4         0x03
212 #define DBREG_DR7_LEN_8         0x02
213 #define DBREG_DR7_EXEC          0x00    /* break on execute       */
214 #define DBREG_DR7_WRONLY        0x01    /* break on write         */
215 #define DBREG_DR7_RDWR          0x03    /* break on read or write */
216 #define DBREG_DR7_MASK(i)       \
217         ((__u_register_t)(0xf) << ((i) * 4 + 16) | 0x3 << (i) * 2)
218 #define DBREG_DR7_SET(i, len, access, enable)                           \
219         ((__u_register_t)((len) << 2 | (access)) << ((i) * 4 + 16) |    \
220         (enable) << (i) * 2)
221 #define DBREG_DR7_GD            0x2000
222 #define DBREG_DR7_ENABLED(d, i) (((d) & 0x3 << (i) * 2) != 0)
223 #define DBREG_DR7_ACCESS(d, i)  ((d) >> ((i) * 4 + 16) & 0x3)
224 #define DBREG_DR7_LEN(d, i)     ((d) >> ((i) * 4 + 18) & 0x3)
225
226 #define DBREG_DRX(d,x)  ((d)->dr[(x)])  /* reference dr0 - dr7 by
227                                            register number */
228
229 #undef __reg32
230 #undef __reg64
231 #undef __fpreg32
232 #undef __fpreg64
233 #undef __dbreg32
234 #undef __dbreg64
235
236 #ifdef _KERNEL
237 /*
238  * XXX these interfaces are MI, so they should be declared in a MI place.
239  */
240 int     fill_regs(struct thread *, struct reg *);
241 int     fill_frame_regs(struct trapframe *, struct reg *);
242 int     set_regs(struct thread *, struct reg *);
243 int     fill_fpregs(struct thread *, struct fpreg *);
244 int     set_fpregs(struct thread *, struct fpreg *);
245 int     fill_dbregs(struct thread *, struct dbreg *);
246 int     set_dbregs(struct thread *, struct dbreg *);
247 #ifdef COMPAT_FREEBSD32
248 int     fill_regs32(struct thread *, struct reg32 *);
249 int     set_regs32(struct thread *, struct reg32 *);
250 int     fill_fpregs32(struct thread *, struct fpreg32 *);
251 int     set_fpregs32(struct thread *, struct fpreg32 *);
252 int     fill_dbregs32(struct thread *, struct dbreg32 *);
253 int     set_dbregs32(struct thread *, struct dbreg32 *);
254 #endif
255 #endif
256
257 #endif /* !_MACHINE_REG_H_ */