xref: /illumos-gate/usr/src/cmd/mdb/intel/mdb/mdb_kreg.h (revision 9c3024a3457d2d1269be18124a1ac69e33000da7)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  * Copyright 2018 Joyent, Inc.
26  */
27 
28 #ifndef	_MDB_KREG_H
29 #define	_MDB_KREG_H
30 
31 #include <sys/kdi_regs.h>
32 #ifndef _ASM
33 #include <sys/types.h>
34 #endif
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifndef _ASM
41 #ifdef __amd64
42 typedef uint64_t kreg_t;
43 #else	/* __amd64 */
44 typedef uint32_t kreg_t;
45 #endif	/* __amd64 */
46 #endif	/* !_ASM */
47 
48 #define	KREG_NGREG	KDIREG_NGREG
49 
50 /*
51  * The order of these registers corresponds to a slightly altered struct regs,
52  * in the order kmdb entry pushes onto the stack.
53  */
54 
55 #ifdef __amd64
56 
57 #define	KREG_SAVFP	KDIREG_SAVFP
58 #define	KREG_SAVPC	KDIREG_SAVPC
59 #define	KREG_RDI	KDIREG_RDI
60 #define	KREG_RSI	KDIREG_RSI
61 #define	KREG_RDX	KDIREG_RDX
62 #define	KREG_RCX	KDIREG_RCX
63 #define	KREG_R8		KDIREG_R8
64 #define	KREG_R9		KDIREG_R9
65 #define	KREG_RAX	KDIREG_RAX
66 #define	KREG_RBX	KDIREG_RBX
67 #define	KREG_RBP	KDIREG_RBP
68 #define	KREG_R10	KDIREG_R10
69 #define	KREG_R11	KDIREG_R11
70 #define	KREG_R12	KDIREG_R12
71 #define	KREG_R13	KDIREG_R13
72 #define	KREG_R14	KDIREG_R14
73 #define	KREG_R15	KDIREG_R15
74 #define	KREG_DS		KDIREG_DS
75 #define	KREG_ES		KDIREG_ES
76 #define	KREG_FS		KDIREG_FS
77 #define	KREG_GS		KDIREG_GS
78 #define	KREG_FSBASE	KDIREG_FSBASE
79 #define	KREG_GSBASE	KDIREG_GSBASE
80 #define	KREG_KGSBASE	KDIREG_KGSBASE
81 #define	KREG_TRAPNO	KDIREG_TRAPNO
82 #define	KREG_ERR	KDIREG_ERR
83 #define	KREG_CR2	KDIREG_CR2
84 #define	KREG_CR3	KDIREG_CR3
85 #define	KREG_RIP	KDIREG_RIP
86 #define	KREG_CS		KDIREG_CS
87 #define	KREG_RFLAGS	KDIREG_RFLAGS
88 #define	KREG_RSP	KDIREG_RSP
89 #define	KREG_SS		KDIREG_SS
90 
91 #define	KREG_PC		KREG_RIP
92 #define	KREG_SP		KREG_RSP
93 #define	KREG_FP		KREG_RBP
94 
95 #define	KREG_EAX	KREG_RAX
96 #define	KREG_EBX	KREG_RBX
97 #define	KREG_ECX	KREG_RCX
98 #define	KREG_EDX	KREG_RDX
99 #define	KREG_ESI	KREG_RSI
100 #define	KREG_EDI	KREG_RDI
101 #define	KREG_EBP	KREG_RBP
102 #define	KREG_ESP	KREG_RSP
103 #define	KREG_EFLAGS	KREG_RFLAGS
104 #define	KREG_EIP	KREG_RIP
105 
106 #else	/* __amd64 */
107 
108 #define	KREG_SAVFP	KDIREG_SAVFP
109 #define	KREG_SAVPC	KDIREG_SAVPC
110 #define	KREG_SS		KDIREG_SS
111 #define	KREG_GS		KDIREG_GS
112 #define	KREG_FS		KDIREG_FS
113 #define	KREG_ES		KDIREG_ES
114 #define	KREG_DS		KDIREG_DS
115 #define	KREG_EDI	KDIREG_EDI
116 #define	KREG_ESI	KDIREG_ESI
117 #define	KREG_EBP	KDIREG_EBP
118 #define	KREG_ESP	KDIREG_ESP
119 #define	KREG_EBX	KDIREG_EBX
120 #define	KREG_EDX	KDIREG_EDX
121 #define	KREG_ECX	KDIREG_ECX
122 #define	KREG_EAX	KDIREG_EAX
123 #define	KREG_TRAPNO	KDIREG_TRAPNO
124 #define	KREG_ERR	KDIREG_ERR
125 #define	KREG_EIP	KDIREG_EIP
126 #define	KREG_CS		KDIREG_CS
127 #define	KREG_EFLAGS	KDIREG_EFLAGS
128 #define	KREG_UESP	KDIREG_UESP
129 
130 #define	KREG_PC		KREG_EIP
131 #define	KREG_SP		KREG_ESP
132 #define	KREG_FP		KREG_EBP
133 
134 #endif	/* __amd64 */
135 
136 #define	KREG_EFLAGS_ID_MASK	0x00200000
137 #define	KREG_EFLAGS_ID_SHIFT	21
138 
139 #define	KREG_EFLAGS_VIP_MASK	0x00100000
140 #define	KREG_EFLAGS_VIP_SHIFT	20
141 
142 #define	KREG_EFLAGS_VIF_MASK	0x00080000
143 #define	KREG_EFLAGS_VIF_SHIFT	19
144 
145 #define	KREG_EFLAGS_AC_MASK	0x00040000
146 #define	KREG_EFLAGS_AC_SHIFT	18
147 
148 #define	KREG_EFLAGS_VM_MASK	0x00020000
149 #define	KREG_EFLAGS_VM_SHIFT	17
150 
151 #define	KREG_EFLAGS_RF_MASK	0x00010000
152 #define	KREG_EFLAGS_RF_SHIFT	16
153 
154 #define	KREG_EFLAGS_NT_MASK	0x00004000
155 #define	KREG_EFLAGS_NT_SHIFT	14
156 
157 #define	KREG_EFLAGS_IOPL_MASK	0x00003000
158 #define	KREG_EFLAGS_IOPL_SHIFT	12
159 
160 #define	KREG_EFLAGS_OF_MASK	0x00000800
161 #define	KREG_EFLAGS_OF_SHIFT	11
162 
163 #define	KREG_EFLAGS_DF_MASK	0x00000400
164 #define	KREG_EFLAGS_DF_SHIFT	10
165 
166 #define	KREG_EFLAGS_IF_MASK	0x00000200
167 #define	KREG_EFLAGS_IF_SHIFT	9
168 
169 #define	KREG_EFLAGS_TF_MASK	0x00000100
170 #define	KREG_EFLAGS_TF_SHIFT	8
171 
172 #define	KREG_EFLAGS_SF_MASK	0x00000080
173 #define	KREG_EFLAGS_SF_SHIFT	7
174 
175 #define	KREG_EFLAGS_ZF_MASK	0x00000040
176 #define	KREG_EFLAGS_ZF_SHIFT	6
177 
178 #define	KREG_EFLAGS_AF_MASK	0x00000010
179 #define	KREG_EFLAGS_AF_SHIFT	4
180 
181 #define	KREG_EFLAGS_PF_MASK	0x00000004
182 #define	KREG_EFLAGS_PF_SHIFT	2
183 
184 #define	KREG_EFLAGS_CF_MASK	0x00000001
185 #define	KREG_EFLAGS_CF_SHIFT	0
186 
187 /* %dr7 */
188 #define	KREG_DRCTL_WP_BASESHIFT	16
189 #define	KREG_DRCTL_WP_INCRSHIFT	4
190 #define	KREG_DRCTL_WP_LENSHIFT	2
191 #define	KREG_DRCTL_WP_LENRWMASK	0xf
192 
193 #define	KREG_DRCTL_WP_EXEC	0
194 #define	KREG_DRCTL_WP_WONLY	1
195 #define	KREG_DRCTL_WP_IORW	2
196 #define	KREG_DRCTL_WP_RW	3
197 
198 #define	KREG_DRCTL_WP_SHIFT(n) \
199 	(KREG_DRCTL_WP_BASESHIFT + KREG_DRCTL_WP_INCRSHIFT * (n))
200 #define	KREG_DRCTL_WP_MASK(n) \
201 	(KREG_DRCTL_WP_LENRWMASK << KREG_DRCTL_WP_SHIFT(n))
202 #define	KREG_DRCTL_WP_LENRW(n, len, rw)	\
203 	((((len) << KREG_DRCTL_WP_LENSHIFT) | (rw)) << KREG_DRCTL_WP_SHIFT(n))
204 
205 #define	KREG_DRCTL_WPEN_INCRSHIFT 2
206 #define	KREG_DRCTL_WPEN_MASK(n) \
207 	(3 << (KREG_DRCTL_WPEN_INCRSHIFT * (n)))
208 #define	KREG_DRCTL_WPEN(n)	KREG_DRCTL_WPEN_MASK(n)
209 
210 /* %dr6 */
211 #define	KREG_DRSTAT_BT_MASK	0x00008000
212 #define	KREG_DRSTAT_BS_MASK	0x00004000
213 #define	KREG_DRSTAT_BD_MASK	0x00002000
214 
215 #define	KREG_DRSTAT_WP_MASK(n)	(1 << (n))
216 
217 #ifdef	__cplusplus
218 }
219 #endif
220 
221 #endif	/* _MDB_KREG_H */
222