Xen Test Framework
x86-dbg-reg.h
Go to the documentation of this file.
1
7#ifndef XTF_X86_DBG_REG_H
8#define XTF_X86_DBG_REG_H
9
10#include <xtf/macro_magic.h>
11
12/*
13 * DR6 status bits.
14 */
15#define X86_DR6_B0 (1u << 0) /* Breakpoint 0 triggered */
16#define X86_DR6_B1 (1u << 1) /* Breakpoint 1 triggered */
17#define X86_DR6_B2 (1u << 2) /* Breakpoint 2 triggered */
18#define X86_DR6_B3 (1u << 3) /* Breakpoint 3 triggered */
19#define X86_DR6_BD (1u << 13) /* Debug register accessed */
20#define X86_DR6_BS (1u << 14) /* Single step */
21#define X86_DR6_BT (1u << 15) /* Task switch */
22#define X86_DR6_RTM (1u << 16) /* #DB/#BP in RTM region */
23
24#define X86_DR6_DEFAULT 0xffff0ff0
25
26/*
27 * DR7 unique control bits.
28 */
29#define X86_DR7_LE (1u << 8) /* Local Exact Breakpoints */
30#define X86_DR7_GE (1u << 9) /* Global Exact Breakpoints */
31#define X86_DR7_RTM (1u << 11) /* Debugging in RTM regions */
32#define X86_DR7_GD (1u << 13) /* General Detect */
33
34#define X86_DR7_DEFAULT 0x00000400
35
36/*
37 * DR7 common control bits. Intended for use with the DR7_SYM() helper.
38 */
39#define X86_DR7_0_L (1u << 0)
40#define X86_DR7_1_L (1u << 2)
41#define X86_DR7_2_L (1u << 4)
42#define X86_DR7_3_L (1u << 6)
43
44#define X86_DR7_0_G (1u << 1)
45#define X86_DR7_1_G (1u << 3)
46#define X86_DR7_2_G (1u << 5)
47#define X86_DR7_3_G (1u << 7)
48
49#define X86_DR7_0_X (0u << 16)
50#define X86_DR7_0_W (1u << 16)
51#define X86_DR7_0_IO (2u << 16)
52#define X86_DR7_0_RW (3u << 16)
53
54#define X86_DR7_0_8 (0u << 18)
55#define X86_DR7_0_16 (1u << 18)
56#define X86_DR7_0_64 (2u << 18)
57#define X86_DR7_0_32 (3u << 18)
58
59#define X86_DR7_1_X (0u << 20)
60#define X86_DR7_1_W (1u << 20)
61#define X86_DR7_1_IO (2u << 20)
62#define X86_DR7_1_RW (3u << 20)
63
64#define X86_DR7_1_8 (0u << 22)
65#define X86_DR7_1_16 (1u << 22)
66#define X86_DR7_1_64 (2u << 22)
67#define X86_DR7_1_32 (3u << 22)
68
69#define X86_DR7_2_X (0u << 24)
70#define X86_DR7_2_W (1u << 24)
71#define X86_DR7_2_IO (2u << 24)
72#define X86_DR7_2_RW (3u << 24)
73
74#define X86_DR7_2_8 (0u << 26)
75#define X86_DR7_2_16 (1u << 26)
76#define X86_DR7_2_64 (2u << 26)
77#define X86_DR7_2_32 (3u << 26)
78
79#define X86_DR7_3_X (0u << 28)
80#define X86_DR7_3_W (1u << 28)
81#define X86_DR7_3_IO (2u << 28)
82#define X86_DR7_3_RW (3u << 28)
83
84#define X86_DR7_3_8 (0u << 30)
85#define X86_DR7_3_16 (1u << 30)
86#define X86_DR7_3_64 (2u << 30)
87#define X86_DR7_3_32 (3u << 30)
88
100#define DR7_SYM(bp, ...) TOK_OR(X86_DR7_ ## bp ## _, ##__VA_ARGS__)
101
102static inline unsigned long read_dr0(void)
103{
104 unsigned long val;
105
106 asm volatile ("mov %%dr0, %0" : "=r" (val));
107
108 return val;
109}
110
111static inline void write_dr0(unsigned long linear)
112{
113 asm volatile ("mov %0, %%dr0" :: "r" (linear));
114}
115
116static inline unsigned long read_dr1(void)
117{
118 unsigned long val;
119
120 asm volatile ("mov %%dr1, %0" : "=r" (val));
121
122 return val;
123}
124
125static inline void write_dr1(unsigned long linear)
126{
127 asm volatile ("mov %0, %%dr1" :: "r" (linear));
128}
129
130static inline unsigned long read_dr2(void)
131{
132 unsigned long val;
133
134 asm volatile ("mov %%dr2, %0" : "=r" (val));
135
136 return val;
137}
138
139static inline void write_dr2(unsigned long linear)
140{
141 asm volatile ("mov %0, %%dr2" :: "r" (linear));
142}
143
144static inline unsigned long read_dr3(void)
145{
146 unsigned long val;
147
148 asm volatile ("mov %%dr3, %0" : "=r" (val));
149
150 return val;
151}
152
153static inline void write_dr3(unsigned long linear)
154{
155 asm volatile ("mov %0, %%dr3" :: "r" (linear));
156}
157
158static inline unsigned long read_dr6(void)
159{
160 unsigned long val;
161
162 asm volatile ("mov %%dr6, %0" : "=r" (val));
163
164 return val;
165}
166
167static inline void write_dr6(unsigned long val)
168{
169 asm volatile ("mov %0, %%dr6" :: "r" (val));
170}
171
172static inline unsigned long read_dr7(void)
173{
174 unsigned long val;
175
176 asm volatile ("mov %%dr7, %0" : "=r" (val));
177
178 return val;
179}
180
181static inline void write_dr7(unsigned long val)
182{
183 asm volatile ("mov %0, %%dr7" :: "r" (val));
184}
185
186#endif /* XTF_X86_DBG_REG_H */
187
188/*
189 * Local variables:
190 * mode: C
191 * c-file-style: "BSD"
192 * c-basic-offset: 4
193 * tab-width: 4
194 * indent-tabs-mode: nil
195 * End:
196 */
Varadic macro helpers - Here be many dragons.
static unsigned long read_dr3(void)
Definition: x86-dbg-reg.h:144
static void write_dr0(unsigned long linear)
Definition: x86-dbg-reg.h:111
static unsigned long read_dr6(void)
Definition: x86-dbg-reg.h:158
static unsigned long read_dr7(void)
Definition: x86-dbg-reg.h:172
static void write_dr1(unsigned long linear)
Definition: x86-dbg-reg.h:125
static void write_dr3(unsigned long linear)
Definition: x86-dbg-reg.h:153
static unsigned long read_dr1(void)
Definition: x86-dbg-reg.h:116
static void write_dr7(unsigned long val)
Definition: x86-dbg-reg.h:181
static void write_dr2(unsigned long linear)
Definition: x86-dbg-reg.h:139
static unsigned long read_dr2(void)
Definition: x86-dbg-reg.h:130
static void write_dr6(unsigned long val)
Definition: x86-dbg-reg.h:167
static unsigned long read_dr0(void)
Definition: x86-dbg-reg.h:102