18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci#ifndef _UAPI_ASM_X86_DEBUGREG_H 38c2ecf20Sopenharmony_ci#define _UAPI_ASM_X86_DEBUGREG_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* Indicate the register numbers for a number of the specific 78c2ecf20Sopenharmony_ci debug registers. Registers 0-3 contain the addresses we wish to trap on */ 88c2ecf20Sopenharmony_ci#define DR_FIRSTADDR 0 /* u_debugreg[DR_FIRSTADDR] */ 98c2ecf20Sopenharmony_ci#define DR_LASTADDR 3 /* u_debugreg[DR_LASTADDR] */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define DR_STATUS 6 /* u_debugreg[DR_STATUS] */ 128c2ecf20Sopenharmony_ci#define DR_CONTROL 7 /* u_debugreg[DR_CONTROL] */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* Define a few things for the status register. We can use this to determine 158c2ecf20Sopenharmony_ci which debugging register was responsible for the trap. The other bits 168c2ecf20Sopenharmony_ci are either reserved or not of interest to us. */ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* Define reserved bits in DR6 which are always set to 1 */ 198c2ecf20Sopenharmony_ci#define DR6_RESERVED (0xFFFF0FF0) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#define DR_TRAP0 (0x1) /* db0 */ 228c2ecf20Sopenharmony_ci#define DR_TRAP1 (0x2) /* db1 */ 238c2ecf20Sopenharmony_ci#define DR_TRAP2 (0x4) /* db2 */ 248c2ecf20Sopenharmony_ci#define DR_TRAP3 (0x8) /* db3 */ 258c2ecf20Sopenharmony_ci#define DR_TRAP_BITS (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define DR_STEP (0x4000) /* single-step */ 288c2ecf20Sopenharmony_ci#define DR_SWITCH (0x8000) /* task switch */ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* Now define a bunch of things for manipulating the control register. 318c2ecf20Sopenharmony_ci The top two bytes of the control register consist of 4 fields of 4 328c2ecf20Sopenharmony_ci bits - each field corresponds to one of the four debug registers, 338c2ecf20Sopenharmony_ci and indicates what types of access we trap on, and how large the data 348c2ecf20Sopenharmony_ci field is that we are looking at */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define DR_CONTROL_SHIFT 16 /* Skip this many bits in ctl register */ 378c2ecf20Sopenharmony_ci#define DR_CONTROL_SIZE 4 /* 4 control bits per register */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define DR_RW_EXECUTE (0x0) /* Settings for the access types to trap on */ 408c2ecf20Sopenharmony_ci#define DR_RW_WRITE (0x1) 418c2ecf20Sopenharmony_ci#define DR_RW_READ (0x3) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define DR_LEN_1 (0x0) /* Settings for data length to trap on */ 448c2ecf20Sopenharmony_ci#define DR_LEN_2 (0x4) 458c2ecf20Sopenharmony_ci#define DR_LEN_4 (0xC) 468c2ecf20Sopenharmony_ci#define DR_LEN_8 (0x8) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci/* The low byte to the control register determine which registers are 498c2ecf20Sopenharmony_ci enabled. There are 4 fields of two bits. One bit is "local", meaning 508c2ecf20Sopenharmony_ci that the processor will reset the bit after a task switch and the other 518c2ecf20Sopenharmony_ci is global meaning that we have to explicitly reset the bit. With linux, 528c2ecf20Sopenharmony_ci you can use either one, since we explicitly zero the register when we enter 538c2ecf20Sopenharmony_ci kernel mode. */ 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit */ 568c2ecf20Sopenharmony_ci#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit */ 578c2ecf20Sopenharmony_ci#define DR_LOCAL_ENABLE (0x1) /* Local enable for reg 0 */ 588c2ecf20Sopenharmony_ci#define DR_GLOBAL_ENABLE (0x2) /* Global enable for reg 0 */ 598c2ecf20Sopenharmony_ci#define DR_ENABLE_SIZE 2 /* 2 enable bits per register */ 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define DR_LOCAL_ENABLE_MASK (0x55) /* Set local bits for all 4 regs */ 628c2ecf20Sopenharmony_ci#define DR_GLOBAL_ENABLE_MASK (0xAA) /* Set global bits for all 4 regs */ 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* The second byte to the control register has a few special things. 658c2ecf20Sopenharmony_ci We can slow the instruction pipeline for instructions coming via the 668c2ecf20Sopenharmony_ci gdt or the ldt if we want to. I am not sure why this is an advantage */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#ifdef __i386__ 698c2ecf20Sopenharmony_ci#define DR_CONTROL_RESERVED (0xFC00) /* Reserved by Intel */ 708c2ecf20Sopenharmony_ci#else 718c2ecf20Sopenharmony_ci#define DR_CONTROL_RESERVED (0xFFFFFFFF0000FC00UL) /* Reserved */ 728c2ecf20Sopenharmony_ci#endif 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define DR_LOCAL_SLOWDOWN (0x100) /* Local slow the pipeline */ 758c2ecf20Sopenharmony_ci#define DR_GLOBAL_SLOWDOWN (0x200) /* Global slow the pipeline */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* 788c2ecf20Sopenharmony_ci * HW breakpoint additions 798c2ecf20Sopenharmony_ci */ 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#endif /* _UAPI_ASM_X86_DEBUGREG_H */ 82