1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_DEBUGREG_H
3 #define _ASM_X86_DEBUGREG_H
7 #include <uapi/asm/debugreg.h>
9 DECLARE_PER_CPU(unsigned long, cpu_dr7
);
11 #ifndef CONFIG_PARAVIRT_XXL
13 * These special macros can be used to get or set a debugging register
15 #define get_debugreg(var, register) \
16 (var) = native_get_debugreg(register)
17 #define set_debugreg(value, register) \
18 native_set_debugreg(register, value)
21 static __always_inline
unsigned long native_get_debugreg(int regno
)
23 unsigned long val
= 0; /* Damn you, gcc! */
27 asm("mov %%db0, %0" :"=r" (val
));
30 asm("mov %%db1, %0" :"=r" (val
));
33 asm("mov %%db2, %0" :"=r" (val
));
36 asm("mov %%db3, %0" :"=r" (val
));
39 asm("mov %%db6, %0" :"=r" (val
));
42 asm("mov %%db7, %0" :"=r" (val
));
50 static __always_inline
void native_set_debugreg(int regno
, unsigned long value
)
54 asm("mov %0, %%db0" ::"r" (value
));
57 asm("mov %0, %%db1" ::"r" (value
));
60 asm("mov %0, %%db2" ::"r" (value
));
63 asm("mov %0, %%db3" ::"r" (value
));
66 asm("mov %0, %%db6" ::"r" (value
));
69 asm("mov %0, %%db7" ::"r" (value
));
76 static inline void hw_breakpoint_disable(void)
78 /* Zero the control register for HW Breakpoint */
81 /* Zero-out the individual HW breakpoint address registers */
88 static __always_inline
bool hw_breakpoint_active(void)
90 return __this_cpu_read(cpu_dr7
) & DR_GLOBAL_ENABLE_MASK
;
93 extern void hw_breakpoint_restore(void);
95 static __always_inline
unsigned long local_db_save(void)
99 if (static_cpu_has(X86_FEATURE_HYPERVISOR
) && !hw_breakpoint_active())
102 get_debugreg(dr7
, 7);
103 dr7
&= ~0x400; /* architecturally set bit */
107 * Ensure the compiler doesn't lower the above statements into
108 * the critical section; disabling breakpoints late would not
116 static __always_inline
void local_db_restore(unsigned long dr7
)
119 * Ensure the compiler doesn't raise this statement into
120 * the critical section; enabling breakpoints early would
125 set_debugreg(dr7
, 7);
128 #ifdef CONFIG_CPU_SUP_AMD
129 extern void set_dr_addr_mask(unsigned long mask
, int dr
);
131 static inline void set_dr_addr_mask(unsigned long mask
, int dr
) { }
134 #endif /* _ASM_X86_DEBUGREG_H */