xref: /illumos-gate/usr/src/uts/intel/sys/debugreg.h (revision 9c3024a3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
28 /*	  All Rights Reserved	*/
29 /*
30  * Copyright (c) 2018, Joyent, Inc.  All rights reserved.
31  */
32 
33 #ifndef	_SYS_DEBUGREG_H
34 #define	_SYS_DEBUGREG_H
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * Specify masks for accessing the i386 debug registers.
42  */
43 
44 /*
45  * The debug registers are found in an array (debugreg) in the u block.
46  * On the i386, there are 4 registers to specify linear addresses.
47  * dr4 and dr5 are reserved.
48  */
49 #define	DR_FIRSTADDR	0	/* u.u_debugreg[DR_FIRSTADDR] */
50 #define	DR_LASTADDR	3	/* u.u_debugreg[DR_LASTADDR]  */
51 
52 /*
53  * The debug status is found in dr6 after a debug trap.
54  */
55 #define	DR_STATUS	6	/* u.u_debugreg[DR_STATUS] */
56 #define	DR_TRAP0	0x1	/* Trap from debug register #0 */
57 #define	DR_TRAP1	0x2	/* Trap from debug register #1 */
58 #define	DR_TRAP2	0x4	/* Trap from debug register #2 */
59 #define	DR_TRAP3	0x8	/* Trap from debug register #3 */
60 #define	DR_ICEALSO	0x2000	/* Flag bit reserved for in-circuit-emulator */
61 #define	DR_SINGLESTEP	0x4000	/* Trap resulting from the single-step flag */
62 #define	DR_TASKSWITCH	0x8000	/* Trap resulting from a task-switch */
63 #define	DR_IN_RTM	0x10000	/* Trap inside an RTM region */
64 
65 /*
66  * dr7 controls the rest of the debug registers.
67  * use shifts and masks because arrays of fields tend to get aligned.
68  * For example,
69  *    dr7 & DR_LOCAL_ENABLE_MASK
70  *    dr7 >> (DR_LOCAL_ENABLE_SHIFT + r# * DR_ENABLE_SIZE) & 0x1
71  *    dr7 >> (DR_CONTROL_SHIFT + r# * DR_CONTROL_SIZE) & DR_RW_MASK
72  * Note that the GLOBAL bits below and always turned off by the kernel.
73  */
74 #define	DR_CONTROL		7	/* u.u_debugreg[DR_CONTROL] */
75 #define	DR_LOCAL_ENABLE_MASK	0x55	/* Enable all 4 regs for ldt addrs */
76 #define	DR_GLOBAL_ENABLE_MASK	0xAA	/* Enable all 4 regs for gdt addrs */
77 #define	DR_CONTROL_RESERVED	0xFC00	/* Bits reserved by Intel */
78 #define	DR_LOCAL_SLOWDOWN	0x100	/* Slow the pipeline for ldt addrs */
79 #define	DR_GLOBAL_SLOWDOWN	0x200	/* Slow the pipeline for gdt addrs */
80 #define	DR_RTM			0x800	/* Restricted Transactional Memory */
81 #define	DR_GENERAL_DETECT	0x2000	/* General Detect Enable */
82 
83 #define	DR_LOCAL_ENABLE_SHIFT	0	/* Additional shift: local enable  */
84 #define	DR_GLOBAL_ENABLE_SHIFT	1	/* Additional shift: global enable */
85 #define	DR_ENABLE_SIZE		2	/* 2 enable bits per register  */
86 
87 #define	DR_TRAPS	(DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3)
88 #define	DR_ENABLE0	0x03	/* Local or Global enable of trap 0 */
89 #define	DR_ENABLE1	0x0C	/* Local or Global enable of trap 1 */
90 #define	DR_ENABLE2	0x30	/* Local or Global enable of trap 2 */
91 #define	DR_ENABLE3	0xC0	/* Local or Global enable of trap 3 */
92 
93 #define	DR_CONTROL_SHIFT	16	/* Shift to register control bits */
94 #define	DR_CONTROL_SIZE		4	/* 4 control bits per register */
95 #define	DR_RW_MASK		0x3	/* Two bits specify r/w access */
96 #define	DR_RW_EXECUTE		0x0	/* Settings for the read/write mask */
97 #define	DR_RW_WRITE		0x1
98 #define	DR_RW_IO_RW		0x2	/* I/O space on Pentium and beyond */
99 #define	DR_RW_READ		0x3
100 #define	DR_LEN_MASK		0xC	/* Two bits specify data length */
101 #define	DR_LEN_1		0x0	/* Settings for data length */
102 #define	DR_LEN_2		0x4
103 #define	DR_LEN_4		0xC
104 #define	DR_LEN_8		0x8
105 
106 #ifdef	__cplusplus
107 }
108 #endif
109 
110 #endif	/* _SYS_DEBUGREG_H */
111