X86: Create a base enum value for indexing into a region of the miscregs.
[gem5.git] / src / arch / x86 / miscregs.hh
1 /*
2 * Copyright (c) 2007 The Hewlett-Packard Development Company
3 * All rights reserved.
4 *
5 * Redistribution and use of this software in source and binary forms,
6 * with or without modification, are permitted provided that the
7 * following conditions are met:
8 *
9 * The software must be used only for Non-Commercial Use which means any
10 * use which is NOT directed to receiving any direct monetary
11 * compensation for, or commercial advantage from such use. Illustrative
12 * examples of non-commercial use are academic research, personal study,
13 * teaching, education and corporate research & development.
14 * Illustrative examples of commercial use are distributing products for
15 * commercial advantage and providing services using the software for
16 * commercial advantage.
17 *
18 * If you wish to use this software or functionality therein that may be
19 * covered by patents for commercial use, please contact:
20 * Director of Intellectual Property Licensing
21 * Office of Strategy and Technology
22 * Hewlett-Packard Company
23 * 1501 Page Mill Road
24 * Palo Alto, California 94304
25 *
26 * Redistributions of source code must retain the above copyright notice,
27 * this list of conditions and the following disclaimer. Redistributions
28 * in binary form must reproduce the above copyright notice, this list of
29 * conditions and the following disclaimer in the documentation and/or
30 * other materials provided with the distribution. Neither the name of
31 * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its
32 * contributors may be used to endorse or promote products derived from
33 * this software without specific prior written permission. No right of
34 * sublicense is granted herewith. Derivatives of the software and
35 * output created using the software may be prepared, but only for
36 * Non-Commercial Uses. Derivatives of the software may be shared with
37 * others provided: (i) the others agree to abide by the list of
38 * conditions herein which includes the Non-Commercial Use restrictions;
39 * and (ii) such Derivatives of the software include the above copyright
40 * notice to acknowledge the contribution from this software where
41 * applicable, this list of conditions and the disclaimer below.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 *
55 * Authors: Gabe Black
56 */
57
58 #ifndef __ARCH_X86_MISCREGS_HH__
59 #define __ARCH_X86_MISCREGS_HH__
60
61 #include "base/bitunion.hh"
62
63 namespace X86ISA
64 {
65 enum CondFlagBit {
66 CFBit = 1 << 0,
67 PFBit = 1 << 2,
68 ECFBit = 1 << 3,
69 AFBit = 1 << 4,
70 EZFBit = 1 << 5,
71 ZFBit = 1 << 6,
72 SFBit = 1 << 7,
73 OFBit = 1 << 11
74 };
75
76 enum MiscRegIndex
77 {
78 // Control registers
79 // Most of these are invalid.
80 MISCREG_CR_BASE,
81 MISCREG_CR0 = MISCREG_CR_BASE,
82 MISCREG_CR1,
83 MISCREG_CR2,
84 MISCREG_CR3,
85 MISCREG_CR4,
86 MISCREG_CR5,
87 MISCREG_CR6,
88 MISCREG_CR7,
89 MISCREG_CR8,
90 MISCREG_CR9,
91 MISCREG_CR10,
92 MISCREG_CR11,
93 MISCREG_CR12,
94 MISCREG_CR13,
95 MISCREG_CR14,
96 MISCREG_CR15,
97
98 // Debug registers
99 MISCREG_DR_BASE,
100 MISCREG_DR0 = MISCREG_DR_BASE,
101 MISCREG_DR1,
102 MISCREG_DR2,
103 MISCREG_DR3,
104 MISCREG_DR4,
105 MISCREG_DR5,
106 MISCREG_DR6,
107 MISCREG_DR7,
108
109 // Flags register
110 MISCREG_RFLAGS,
111
112 // Segment selectors
113 MISCREG_SEG_SEL_BASE,
114 MISCREG_ES = MISCREG_SEG_SEL_BASE,
115 MISCREG_CS,
116 MISCREG_SS,
117 MISCREG_DS,
118 MISCREG_FS,
119 MISCREG_GS,
120
121 // Hidden segment base field
122 MISCREG_SEG_BASE_BASE,
123 MISCREG_ES_BASE = MISCREG_SEG_BASE_BASE,
124 MISCREG_CS_BASE,
125 MISCREG_SS_BASE,
126 MISCREG_DS_BASE,
127 MISCREG_FS_BASE,
128 MISCREG_GS_BASE,
129
130 // Hidden segment limit field
131 MISCREG_SEG_LIMIT_BASE,
132 MISCREG_ES_LIMIT = MISCREG_SEG_LIMIT_BASE,
133 MISCREG_CS_LIMIT,
134 MISCREG_SS_LIMIT,
135 MISCREG_DS_LIMIT,
136 MISCREG_FS_LIMIT,
137 MISCREG_GS_LIMIT,
138
139 // Hidden segment limit attributes
140 MISCREG_SEG_ATTR_BASE,
141 MISCREG_ES_ATTR = MISCREG_SEG_ATTR_BASE,
142 MISCREG_CS_ATTR,
143 MISCREG_SS_ATTR,
144 MISCREG_DS_ATTR,
145 MISCREG_FS_ATTR,
146 MISCREG_GS_ATTR,
147
148 // System segment selectors
149 MISCREG_SYSSEG_SEL_BASE,
150 MISCREG_LDTR = MISCREG_SYSSEG_SEL_BASE,
151 MISCREG_TR,
152
153 // Hidden system segment base field
154 MISCREG_SYSSEG_BASE_BASE,
155 MISCREG_LDTR_BASE = MISCREG_SYSSEG_BASE_BASE,
156 MISCREG_TR_BASE,
157 MISCREG_GDTR_BASE,
158 MISCREG_IDTR_BASE,
159
160 // Hidden system segment limit field
161 MISCREG_SYSSEG_LIMIT_BASE,
162 MISCREG_LDTR_LIMIT = MISCREG_SYSSEG_LIMIT_BASE,
163 MISCREG_TR_LIMIT,
164 MISCREG_GDTR_LIMIT,
165 MISCREG_IDTR_LIMIT,
166
167 // Hidden system segment attribute field
168 MISCREG_SYSSEG_ATTR_BASE,
169 MISCREG_LDTR_ATTR = MISCREG_SYSSEG_ATTR_BASE,
170 MISCREG_TR_ATTR,
171
172 //XXX Add "Model-Specific Registers"
173
174 NUM_MISCREGS
175 };
176
177 /**
178 * A type to describe the condition code bits of the RFLAGS register,
179 * plus two flags, EZF and ECF, which are only visible to microcode.
180 */
181 BitUnion64(CCFlagBits)
182 Bitfield<11> OF;
183 Bitfield<7> SF;
184 Bitfield<6> ZF;
185 Bitfield<5> EZF;
186 Bitfield<4> AF;
187 Bitfield<3> ECF;
188 Bitfield<2> PF;
189 Bitfield<0> CF;
190 EndBitUnion(CCFlagBits)
191
192 /**
193 * RFLAGS
194 */
195 BitUnion64(RFLAGS)
196 Bitfield<21> ID; // ID Flag
197 Bitfield<20> VIP; // Virtual Interrupt Pending
198 Bitfield<19> VIF; // Virtual Interrupt Flag
199 Bitfield<18> AC; // Alignment Check
200 Bitfield<17> VM; // Virtual-8086 Mode
201 Bitfield<16> RF; // Resume Flag
202 Bitfield<14> NT; // Nested Task
203 Bitfield<13, 12> IOPL; // I/O Privilege Level
204 Bitfield<11> OF; // Overflow Flag
205 Bitfield<10> DF; // Direction Flag
206 Bitfield<9> IF; // Interrupt Flag
207 Bitfield<8> TF; // Trap Flag
208 Bitfield<7> SF; // Sign Flag
209 Bitfield<6> ZF; // Zero Flag
210 Bitfield<4> AF; // Auxiliary Flag
211 Bitfield<2> PF; // Parity Flag
212 Bitfield<0> CF; // Carry Flag
213 EndBitUnion(RFLAGS)
214
215 /**
216 * Control registers
217 */
218 BitUnion64(CR0)
219 Bitfield<31> PG; // Paging
220 Bitfield<30> CD; // Cache Disable
221 Bitfield<29> NW; // Not Writethrough
222 Bitfield<18> AM; // Alignment Mask
223 Bitfield<16> WP; // Write Protect
224 Bitfield<5> NE; // Numeric Error
225 Bitfield<4> ET; // Extension Type
226 Bitfield<3> TS; // Task Switched
227 Bitfield<2> EM; // Emulation
228 Bitfield<1> MP; // Monitor Coprocessor
229 Bitfield<0> PE; // Protection Enabled
230 EndBitUnion(CR0)
231
232 // Page Fault Virtual Address
233 BitUnion64(CR2)
234 Bitfield<31, 0> legacy;
235 EndBitUnion(CR2)
236
237 BitUnion64(CR3)
238 Bitfield<51, 12> longPDTB; // Long Mode Page-Directory-Table
239 // Base Address
240 Bitfield<31, 12> PDTB; // Non-PAE Addressing Page-Directory-Table
241 // Base Address
242 Bitfield<31, 5> PAEPDTB; // PAE Addressing Page-Directory-Table
243 // Base Address
244 Bitfield<4> PCD; // Page-Level Cache Disable
245 Bitfield<3> PWT; // Page-Level Writethrough
246 EndBitUnion(CR3)
247
248 BitUnion64(CR4)
249 Bitfield<10> OSXMMEXCPT; // Operating System Unmasked
250 // Exception Support
251 Bitfield<9> OSFXSR; // Operating System FXSave/FSRSTOR Support
252 Bitfield<8> PCE; // Performance-Monitoring Counter Enable
253 Bitfield<7> PGE; // Page-Global Enable
254 Bitfield<6> MCE; // Machine Check Enable
255 Bitfield<5> PAE; // Physical-Address Extension
256 Bitfield<4> PSE; // Page Size Extensions
257 Bitfield<3> DE; // Debugging Extensions
258 Bitfield<2> TSD; // Time Stamp Disable
259 Bitfield<1> PVI; // Protected-Mode Virtual Interrupts
260 Bitfield<0> VME; // Virtual-8086 Mode Extensions
261 EndBitUnion(CR4)
262
263 BitUnion64(CR8)
264 Bitfield<3, 0> TPR; // Task Priority Register
265 EndBitUnion(CR4)
266
267 /**
268 * Segment Selector
269 */
270 BitUnion64(SegSelector)
271 Bitfield<15, 3> SI; // Selector Index
272 Bitfield<2> TI; // Table Indicator
273 Bitfield<1, 0> RPL; // Requestor Privilege Level
274 EndBitUnion(SegSelector)
275
276 /**
277 * Segment Descriptors
278 */
279
280 BitUnion64(SegDescriptor)
281 Bitfield<63, 56> baseHigh;
282 Bitfield<39, 16> baseLow;
283 Bitfield<55> G; // Granularity
284 Bitfield<54> D; // Default Operand Size
285 Bitfield<54> B; // Default Operand Size
286 Bitfield<53> L; // Long Attribute Bit
287 Bitfield<52> AVL; // Available To Software
288 Bitfield<51, 48> limitHigh;
289 Bitfield<15, 0> limitLow;
290 Bitfield<47> P; // Present
291 Bitfield<46, 45> DPL; // Descriptor Privilege-Level
292 Bitfield<44> S; // System
293 SubBitUnion(type, 43, 40)
294 // Specifies whether this descriptor is for code or data.
295 Bitfield<43> codeOrData;
296
297 // These bit fields are for code segments
298 Bitfield<42> C; // Conforming
299 Bitfield<41> R; // Readable
300
301 // These bit fields are for data segments
302 Bitfield<42> E; // Expand-Down
303 Bitfield<41> W; // Writable
304
305 // This is used for both code and data segments.
306 Bitfield<40> A; // Accessed
307 EndSubBitUnion(type)
308 EndBitUnion(SegDescriptor)
309
310 BitUnion64(GateDescriptor)
311 Bitfield<63, 48> offsetHigh; // Target Code-Segment Offset
312 Bitfield<15, 0> offsetLow; // Target Code-Segment Offset
313 Bitfield<31, 16> selector; // Target Code-Segment Selector
314 Bitfield<47> P; // Present
315 Bitfield<46, 45> DPL; // Descriptor Privilege-Level
316 Bitfield<43, 40> type;
317 Bitfield<36, 32> count; // Parameter Count
318 EndBitUnion(GateDescriptor)
319
320 /**
321 * Descriptor-Table Registers
322 */
323 BitUnion64(GDTR)
324 EndBitUnion(GDTR)
325
326 BitUnion64(IDTR)
327 EndBitUnion(IDTR)
328
329 BitUnion64(LDTR)
330 EndBitUnion(LDTR)
331
332 /**
333 * Task Register
334 */
335 BitUnion64(TR)
336 EndBitUnion(TR)
337 };
338
339 #endif // __ARCH_X86_INTREGS_HH__