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