162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 262306a36Sopenharmony_ci#ifndef _UAPI_ASM_X86_DEBUGREG_H 362306a36Sopenharmony_ci#define _UAPI_ASM_X86_DEBUGREG_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci/* Indicate the register numbers for a number of the specific 762306a36Sopenharmony_ci debug registers. Registers 0-3 contain the addresses we wish to trap on */ 862306a36Sopenharmony_ci#define DR_FIRSTADDR 0 /* u_debugreg[DR_FIRSTADDR] */ 962306a36Sopenharmony_ci#define DR_LASTADDR 3 /* u_debugreg[DR_LASTADDR] */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#define DR_STATUS 6 /* u_debugreg[DR_STATUS] */ 1262306a36Sopenharmony_ci#define DR_CONTROL 7 /* u_debugreg[DR_CONTROL] */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* Define a few things for the status register. We can use this to determine 1562306a36Sopenharmony_ci which debugging register was responsible for the trap. The other bits 1662306a36Sopenharmony_ci are either reserved or not of interest to us. */ 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* Define reserved bits in DR6 which are always set to 1 */ 1962306a36Sopenharmony_ci#define DR6_RESERVED (0xFFFF0FF0) 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define DR_TRAP0 (0x1) /* db0 */ 2262306a36Sopenharmony_ci#define DR_TRAP1 (0x2) /* db1 */ 2362306a36Sopenharmony_ci#define DR_TRAP2 (0x4) /* db2 */ 2462306a36Sopenharmony_ci#define DR_TRAP3 (0x8) /* db3 */ 2562306a36Sopenharmony_ci#define DR_TRAP_BITS (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define DR_BUS_LOCK (0x800) /* bus_lock */ 2862306a36Sopenharmony_ci#define DR_STEP (0x4000) /* single-step */ 2962306a36Sopenharmony_ci#define DR_SWITCH (0x8000) /* task switch */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/* Now define a bunch of things for manipulating the control register. 3262306a36Sopenharmony_ci The top two bytes of the control register consist of 4 fields of 4 3362306a36Sopenharmony_ci bits - each field corresponds to one of the four debug registers, 3462306a36Sopenharmony_ci and indicates what types of access we trap on, and how large the data 3562306a36Sopenharmony_ci field is that we are looking at */ 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define DR_CONTROL_SHIFT 16 /* Skip this many bits in ctl register */ 3862306a36Sopenharmony_ci#define DR_CONTROL_SIZE 4 /* 4 control bits per register */ 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define DR_RW_EXECUTE (0x0) /* Settings for the access types to trap on */ 4162306a36Sopenharmony_ci#define DR_RW_WRITE (0x1) 4262306a36Sopenharmony_ci#define DR_RW_READ (0x3) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define DR_LEN_1 (0x0) /* Settings for data length to trap on */ 4562306a36Sopenharmony_ci#define DR_LEN_2 (0x4) 4662306a36Sopenharmony_ci#define DR_LEN_4 (0xC) 4762306a36Sopenharmony_ci#define DR_LEN_8 (0x8) 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci/* The low byte to the control register determine which registers are 5062306a36Sopenharmony_ci enabled. There are 4 fields of two bits. One bit is "local", meaning 5162306a36Sopenharmony_ci that the processor will reset the bit after a task switch and the other 5262306a36Sopenharmony_ci is global meaning that we have to explicitly reset the bit. With linux, 5362306a36Sopenharmony_ci you can use either one, since we explicitly zero the register when we enter 5462306a36Sopenharmony_ci kernel mode. */ 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define DR_LOCAL_ENABLE_SHIFT 0 /* Extra shift to the local enable bit */ 5762306a36Sopenharmony_ci#define DR_GLOBAL_ENABLE_SHIFT 1 /* Extra shift to the global enable bit */ 5862306a36Sopenharmony_ci#define DR_LOCAL_ENABLE (0x1) /* Local enable for reg 0 */ 5962306a36Sopenharmony_ci#define DR_GLOBAL_ENABLE (0x2) /* Global enable for reg 0 */ 6062306a36Sopenharmony_ci#define DR_ENABLE_SIZE 2 /* 2 enable bits per register */ 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci#define DR_LOCAL_ENABLE_MASK (0x55) /* Set local bits for all 4 regs */ 6362306a36Sopenharmony_ci#define DR_GLOBAL_ENABLE_MASK (0xAA) /* Set global bits for all 4 regs */ 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* The second byte to the control register has a few special things. 6662306a36Sopenharmony_ci We can slow the instruction pipeline for instructions coming via the 6762306a36Sopenharmony_ci gdt or the ldt if we want to. I am not sure why this is an advantage */ 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#ifdef __i386__ 7062306a36Sopenharmony_ci#define DR_CONTROL_RESERVED (0xFC00) /* Reserved by Intel */ 7162306a36Sopenharmony_ci#else 7262306a36Sopenharmony_ci#define DR_CONTROL_RESERVED (0xFFFFFFFF0000FC00UL) /* Reserved */ 7362306a36Sopenharmony_ci#endif 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci#define DR_LOCAL_SLOWDOWN (0x100) /* Local slow the pipeline */ 7662306a36Sopenharmony_ci#define DR_GLOBAL_SLOWDOWN (0x200) /* Global slow the pipeline */ 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* 7962306a36Sopenharmony_ci * HW breakpoint additions 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#endif /* _UAPI_ASM_X86_DEBUGREG_H */ 83