2 * Copyright (c) 2007-2008 The Hewlett-Packard Development Company
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:
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.
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
24 * Palo Alto, California 94304
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.
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.
58 #ifndef __ARCH_X86_MISCREGS_HH__
59 #define __ARCH_X86_MISCREGS_HH__
61 #include "arch/x86/segmentregs.hh"
62 #include "arch/x86/x86_traits.hh"
63 #include "base/bitunion.hh"
65 //These get defined in some system headers (at least termbits.h). That confuses
66 //things here significantly.
100 // Most of these are invalid.
102 MISCREG_CR0 = MISCREG_CR_BASE,
120 MISCREG_DR_BASE = MISCREG_CR_BASE + NumCRegs,
121 MISCREG_DR0 = MISCREG_DR_BASE,
131 MISCREG_RFLAGS = MISCREG_DR_BASE + NumDRegs,
133 //Register to keep handy values like the CPU mode in.
137 * Model Specific Registers
139 // Time stamp counter
145 MISCREG_SYSENTER_ESP,
146 MISCREG_SYSENTER_EIP,
152 MISCREG_DEBUG_CTL_MSR,
154 MISCREG_LAST_BRANCH_FROM_IP,
155 MISCREG_LAST_BRANCH_TO_IP,
156 MISCREG_LAST_EXCEPTION_FROM_IP,
157 MISCREG_LAST_EXCEPTION_TO_IP,
159 MISCREG_MTRR_PHYS_BASE_BASE,
160 MISCREG_MTRR_PHYS_BASE_0 = MISCREG_MTRR_PHYS_BASE_BASE,
161 MISCREG_MTRR_PHYS_BASE_1,
162 MISCREG_MTRR_PHYS_BASE_2,
163 MISCREG_MTRR_PHYS_BASE_3,
164 MISCREG_MTRR_PHYS_BASE_4,
165 MISCREG_MTRR_PHYS_BASE_5,
166 MISCREG_MTRR_PHYS_BASE_6,
167 MISCREG_MTRR_PHYS_BASE_7,
169 MISCREG_MTRR_PHYS_MASK_BASE,
170 MISCREG_MTRR_PHYS_MASK_0 = MISCREG_MTRR_PHYS_MASK_BASE,
171 MISCREG_MTRR_PHYS_MASK_1,
172 MISCREG_MTRR_PHYS_MASK_2,
173 MISCREG_MTRR_PHYS_MASK_3,
174 MISCREG_MTRR_PHYS_MASK_4,
175 MISCREG_MTRR_PHYS_MASK_5,
176 MISCREG_MTRR_PHYS_MASK_6,
177 MISCREG_MTRR_PHYS_MASK_7,
179 MISCREG_MTRR_FIX_64K_00000,
180 MISCREG_MTRR_FIX_16K_80000,
181 MISCREG_MTRR_FIX_16K_A0000,
182 MISCREG_MTRR_FIX_4K_C0000,
183 MISCREG_MTRR_FIX_4K_C8000,
184 MISCREG_MTRR_FIX_4K_D0000,
185 MISCREG_MTRR_FIX_4K_D8000,
186 MISCREG_MTRR_FIX_4K_E0000,
187 MISCREG_MTRR_FIX_4K_E8000,
188 MISCREG_MTRR_FIX_4K_F0000,
189 MISCREG_MTRR_FIX_4K_F8000,
196 MISCREG_MC0_CTL = MISCREG_MC_CTL_BASE,
205 MISCREG_MC_STATUS_BASE,
206 MISCREG_MC0_STATUS = MISCREG_MC_STATUS_BASE,
215 MISCREG_MC_ADDR_BASE,
216 MISCREG_MC0_ADDR = MISCREG_MC_ADDR_BASE,
225 MISCREG_MC_MISC_BASE,
226 MISCREG_MC0_MISC = MISCREG_MC_MISC_BASE,
235 // Extended feature enable register
244 MISCREG_KERNEL_GS_BASE,
248 MISCREG_PERF_EVT_SEL_BASE,
249 MISCREG_PERF_EVT_SEL0 = MISCREG_PERF_EVT_SEL_BASE,
250 MISCREG_PERF_EVT_SEL1,
251 MISCREG_PERF_EVT_SEL2,
252 MISCREG_PERF_EVT_SEL3,
254 MISCREG_PERF_EVT_CTR_BASE,
255 MISCREG_PERF_EVT_CTR0 = MISCREG_PERF_EVT_CTR_BASE,
256 MISCREG_PERF_EVT_CTR1,
257 MISCREG_PERF_EVT_CTR2,
258 MISCREG_PERF_EVT_CTR3,
262 MISCREG_IORR_BASE_BASE,
263 MISCREG_IORR_BASE0 = MISCREG_IORR_BASE_BASE,
266 MISCREG_IORR_MASK_BASE,
267 MISCREG_IORR_MASK0 = MISCREG_IORR_MASK_BASE,
282 MISCREG_SEG_SEL_BASE,
283 MISCREG_ES = MISCREG_SEG_SEL_BASE,
297 // Hidden segment base field
298 MISCREG_SEG_BASE_BASE = MISCREG_SEG_SEL_BASE + NUM_SEGMENTREGS,
299 MISCREG_ES_BASE = MISCREG_SEG_BASE_BASE,
313 // The effective segment base, ie what is actually added to an
314 // address. In 64 bit mode this can be different from the above,
316 MISCREG_SEG_EFF_BASE_BASE = MISCREG_SEG_BASE_BASE + NUM_SEGMENTREGS,
317 MISCREG_ES_EFF_BASE = MISCREG_SEG_EFF_BASE_BASE,
324 MISCREG_TSL_EFF_BASE,
325 MISCREG_TSG_EFF_BASE,
329 MISCREG_IDTR_EFF_BASE,
331 // Hidden segment limit field
332 MISCREG_SEG_LIMIT_BASE = MISCREG_SEG_EFF_BASE_BASE + NUM_SEGMENTREGS,
333 MISCREG_ES_LIMIT = MISCREG_SEG_LIMIT_BASE,
347 // Hidden segment limit attributes
348 MISCREG_SEG_ATTR_BASE = MISCREG_SEG_LIMIT_BASE + NUM_SEGMENTREGS,
349 MISCREG_ES_ATTR = MISCREG_SEG_ATTR_BASE,
363 // Floating point control registers
365 MISCREG_SEG_ATTR_BASE + NUM_SEGMENTREGS,
367 //XXX Add "Model-Specific Registers"
371 // "Fake" MSRs for internally implemented devices
372 MISCREG_PCI_CONFIG_ADDRESS,
377 static inline MiscRegIndex
378 MISCREG_CR(int index)
380 return (MiscRegIndex)(MISCREG_CR_BASE + index);
383 static inline MiscRegIndex
384 MISCREG_DR(int index)
386 return (MiscRegIndex)(MISCREG_DR_BASE + index);
389 static inline MiscRegIndex
390 MISCREG_MTRR_PHYS_BASE(int index)
392 return (MiscRegIndex)(MISCREG_MTRR_PHYS_BASE_BASE + index);
395 static inline MiscRegIndex
396 MISCREG_MTRR_PHYS_MASK(int index)
398 return (MiscRegIndex)(MISCREG_MTRR_PHYS_MASK_BASE + index);
401 static inline MiscRegIndex
402 MISCREG_MC_CTL(int index)
404 return (MiscRegIndex)(MISCREG_MC_CTL_BASE + index);
407 static inline MiscRegIndex
408 MISCREG_MC_STATUS(int index)
410 return (MiscRegIndex)(MISCREG_MC_STATUS_BASE + index);
413 static inline MiscRegIndex
414 MISCREG_MC_ADDR(int index)
416 return (MiscRegIndex)(MISCREG_MC_ADDR_BASE + index);
419 static inline MiscRegIndex
420 MISCREG_MC_MISC(int index)
422 return (MiscRegIndex)(MISCREG_MC_MISC_BASE + index);
425 static inline MiscRegIndex
426 MISCREG_PERF_EVT_SEL(int index)
428 return (MiscRegIndex)(MISCREG_PERF_EVT_SEL_BASE + index);
431 static inline MiscRegIndex
432 MISCREG_PERF_EVT_CTR(int index)
434 return (MiscRegIndex)(MISCREG_PERF_EVT_CTR_BASE + index);
437 static inline MiscRegIndex
438 MISCREG_IORR_BASE(int index)
440 return (MiscRegIndex)(MISCREG_IORR_BASE_BASE + index);
443 static inline MiscRegIndex
444 MISCREG_IORR_MASK(int index)
446 return (MiscRegIndex)(MISCREG_IORR_MASK_BASE + index);
449 static inline MiscRegIndex
450 MISCREG_SEG_SEL(int index)
452 return (MiscRegIndex)(MISCREG_SEG_SEL_BASE + index);
455 static inline MiscRegIndex
456 MISCREG_SEG_BASE(int index)
458 return (MiscRegIndex)(MISCREG_SEG_BASE_BASE + index);
461 static inline MiscRegIndex
462 MISCREG_SEG_EFF_BASE(int index)
464 return (MiscRegIndex)(MISCREG_SEG_EFF_BASE_BASE + index);
467 static inline MiscRegIndex
468 MISCREG_SEG_LIMIT(int index)
470 return (MiscRegIndex)(MISCREG_SEG_LIMIT_BASE + index);
473 static inline MiscRegIndex
474 MISCREG_SEG_ATTR(int index)
476 return (MiscRegIndex)(MISCREG_SEG_ATTR_BASE + index);
480 * A type to describe the condition code bits of the RFLAGS register,
481 * plus two flags, EZF and ECF, which are only visible to microcode.
483 BitUnion64(CCFlagBits)
492 EndBitUnion(CCFlagBits)
498 Bitfield<21> id; // ID Flag
499 Bitfield<20> vip; // Virtual Interrupt Pending
500 Bitfield<19> vif; // Virtual Interrupt Flag
501 Bitfield<18> ac; // Alignment Check
502 Bitfield<17> vm; // Virtual-8086 Mode
503 Bitfield<16> rf; // Resume Flag
504 Bitfield<14> nt; // Nested Task
505 Bitfield<13, 12> iopl; // I/O Privilege Level
506 Bitfield<11> of; // Overflow Flag
507 Bitfield<10> df; // Direction Flag
508 Bitfield<9> intf; // Interrupt Flag
509 Bitfield<8> tf; // Trap Flag
510 Bitfield<7> sf; // Sign Flag
511 Bitfield<6> zf; // Zero Flag
512 Bitfield<4> af; // Auxiliary Flag
513 Bitfield<2> pf; // Parity Flag
514 Bitfield<0> cf; // Carry Flag
517 BitUnion64(HandyM5Reg)
519 Bitfield<3, 1> submode;
523 Bitfield<9, 8> defOp;
524 Bitfield<11, 10> altOp;
525 Bitfield<13, 12> defAddr;
526 Bitfield<15, 14> altAddr;
527 Bitfield<17, 16> stack;
528 EndBitUnion(HandyM5Reg)
534 Bitfield<31> pg; // Paging
535 Bitfield<30> cd; // Cache Disable
536 Bitfield<29> nw; // Not Writethrough
537 Bitfield<18> am; // Alignment Mask
538 Bitfield<16> wp; // Write Protect
539 Bitfield<5> ne; // Numeric Error
540 Bitfield<4> et; // Extension Type
541 Bitfield<3> ts; // Task Switched
542 Bitfield<2> em; // Emulation
543 Bitfield<1> mp; // Monitor Coprocessor
544 Bitfield<0> pe; // Protection Enabled
547 // Page Fault Virtual Address
549 Bitfield<31, 0> legacy;
553 Bitfield<51, 12> longPdtb; // Long Mode Page-Directory-Table
555 Bitfield<31, 12> pdtb; // Non-PAE Addressing Page-Directory-Table
557 Bitfield<31, 5> paePdtb; // PAE Addressing Page-Directory-Table
559 Bitfield<4> pcd; // Page-Level Cache Disable
560 Bitfield<3> pwt; // Page-Level Writethrough
564 Bitfield<10> osxmmexcpt; // Operating System Unmasked
566 Bitfield<9> osfxsr; // Operating System FXSave/FSRSTOR Support
567 Bitfield<8> pce; // Performance-Monitoring Counter Enable
568 Bitfield<7> pge; // Page-Global Enable
569 Bitfield<6> mce; // Machine Check Enable
570 Bitfield<5> pae; // Physical-Address Extension
571 Bitfield<4> pse; // Page Size Extensions
572 Bitfield<3> de; // Debugging Extensions
573 Bitfield<2> tsd; // Time Stamp Disable
574 Bitfield<1> pvi; // Protected-Mode Virtual Interrupts
575 Bitfield<0> vme; // Virtual-8086 Mode Extensions
579 Bitfield<3, 0> tpr; // Task Priority Register
604 Bitfield<17, 16> rw0;
605 Bitfield<19, 18> len0;
606 Bitfield<21, 20> rw1;
607 Bitfield<23, 22> len1;
608 Bitfield<25, 24> rw2;
609 Bitfield<27, 26> len2;
610 Bitfield<29, 28> rw3;
611 Bitfield<31, 30> len3;
616 Bitfield<7, 0> vcnt; // Variable-Range Register Count
617 Bitfield<8> fix; // Fixed-Range Registers
618 Bitfield<10> wc; // Write-Combining
622 * SYSENTER configuration registers
624 BitUnion64(SysenterCS)
625 Bitfield<15, 0> targetCS;
626 EndBitUnion(SysenterCS)
628 BitUnion64(SysenterESP)
629 Bitfield<31, 0> targetESP;
630 EndBitUnion(SysenterESP)
632 BitUnion64(SysenterEIP)
633 Bitfield<31, 0> targetEIP;
634 EndBitUnion(SysenterEIP)
637 * Global machine check registers
640 Bitfield<7, 0> count; // Number of error reporting register banks
641 Bitfield<8> MCGCP; // MCG_CTL register present.
644 BitUnion64(McgStatus)
645 Bitfield<0> ripv; // Restart-IP valid
646 Bitfield<1> eipv; // Error-IP valid
647 Bitfield<2> mcip; // Machine check in-progress
648 EndBitUnion(McgStatus)
650 BitUnion64(DebugCtlMsr)
651 Bitfield<0> lbr; // Last-branch record
652 Bitfield<1> btf; // Branch single step
653 Bitfield<2> pb0; // Performance monitoring pin control 0
654 Bitfield<3> pb1; // Performance monitoring pin control 1
655 Bitfield<4> pb2; // Performance monitoring pin control 2
656 Bitfield<5> pb3; // Performance monitoring pin control 3
657 /*uint64_t pb(int index)
659 return bits(__data, index + 2);
661 EndBitUnion(DebugCtlMsr)
663 BitUnion64(MtrrPhysBase)
664 Bitfield<7, 0> type; // Default memory type
665 Bitfield<51, 12> physbase; // Range physical base address
666 EndBitUnion(MtrrPhysBase)
668 BitUnion64(MtrrPhysMask)
669 Bitfield<11> valid; // MTRR pair enable
670 Bitfield<51, 12> physmask; // Range physical mask
671 EndBitUnion(MtrrPhysMask)
673 BitUnion64(MtrrFixed)
674 /*uint64_t type(int index)
676 return bits(__data, index * 8 + 7, index * 8);
678 EndBitUnion(MtrrFixed)
681 /*uint64_t pa(int index)
683 return bits(__data, index * 8 + 2, index * 8);
687 BitUnion64(MtrrDefType)
688 Bitfield<7, 0> type; // Default type
689 Bitfield<10> fe; // Fixed range enable
690 Bitfield<11> e; // MTRR enable
691 EndBitUnion(MtrrDefType)
697 Bitfield<15,0> mcaErrorCode;
698 Bitfield<31,16> modelSpecificCode;
699 Bitfield<56,32> otherInfo;
700 Bitfield<57> pcc; // Processor-context corrupt
701 Bitfield<58> addrv; // Error-address register valid
702 Bitfield<59> miscv; // Miscellaneous-error register valid
703 Bitfield<60> en; // Error condition enabled
704 Bitfield<61> uc; // Uncorrected error
705 Bitfield<62> over; // Status register overflow
706 Bitfield<63> val; // Valid
707 EndBitUnion(McStatus)
710 /*uint64_t en(int index)
712 return bits(__data, index);
716 // Extended feature enable register
718 Bitfield<0> sce; // System call extensions
719 Bitfield<8> lme; // Long mode enable
720 Bitfield<10> lma; // Long mode active
721 Bitfield<11> nxe; // No-execute enable
722 Bitfield<12> svme; // Secure virtual machine enable
723 Bitfield<14> ffxsr; // Fast fxsave/fxrstor
727 Bitfield<31,0> targetEip;
728 Bitfield<47,32> syscallCsAndSs;
729 Bitfield<63,48> sysretCsAndSs;
736 BitUnion64(PerfEvtSel)
737 Bitfield<7,0> eventMask;
738 Bitfield<15,8> unitMask;
739 Bitfield<16> usr; // User mode
740 Bitfield<17> os; // Operating-system mode
741 Bitfield<18> e; // Edge detect
742 Bitfield<19> pc; // Pin control
743 Bitfield<20> intEn; // Interrupt enable
744 Bitfield<22> en; // Counter enable
745 Bitfield<23> inv; // Invert mask
746 Bitfield<31,24> counterMask;
747 EndBitUnion(PerfEvtSel)
750 Bitfield<18> mfde; // MtrrFixDramEn
751 Bitfield<19> mfdm; // MtrrFixDramModEn
752 Bitfield<20> mvdm; // MtrrVarDramEn
753 Bitfield<21> tom2; // MtrrTom2En
757 Bitfield<3> wr; // WrMem Enable
758 Bitfield<4> rd; // RdMem Enable
759 Bitfield<51,12> physbase; // Range physical base address
760 EndBitUnion(IorrBase)
763 Bitfield<11> v; // I/O register pair enable (valid)
764 Bitfield<51,12> physmask; // Range physical mask
765 EndBitUnion(IorrMask)
768 Bitfield<51,23> physAddr; // Top of memory physical address
779 EndBitUnion(IgnneMsr)
781 BitUnion64(SmmCtlMsr)
784 Bitfield<2> smiCycle;
786 Bitfield<4> rsmCycle;
787 EndBitUnion(SmmCtlMsr)
792 BitUnion64(SegSelector)
793 // The following bitfield is not defined in the ISA, but it's useful
794 // when checking selectors in larger data types to make sure they
796 Bitfield<63, 3> esi; // Extended selector
797 Bitfield<15, 3> si; // Selector Index
798 Bitfield<2> ti; // Table Indicator
799 Bitfield<1, 0> rpl; // Requestor Privilege Level
800 EndBitUnion(SegSelector)
803 * Segment Descriptors
806 BitUnion64(SegDescriptor)
807 Bitfield<63, 56> baseHigh;
808 Bitfield<39, 16> baseLow;
809 Bitfield<55> g; // Granularity
810 Bitfield<54> d; // Default Operand Size
811 Bitfield<54> b; // Default Operand Size
812 Bitfield<53> l; // Long Attribute Bit
813 Bitfield<52> avl; // Available To Software
814 Bitfield<51, 48> limitHigh;
815 Bitfield<15, 0> limitLow;
816 Bitfield<47> p; // Present
817 Bitfield<46, 45> dpl; // Descriptor Privilege-Level
818 Bitfield<44> s; // System
819 SubBitUnion(type, 43, 40)
820 // Specifies whether this descriptor is for code or data.
821 Bitfield<43> codeOrData;
823 // These bit fields are for code segments
824 Bitfield<42> c; // Conforming
825 Bitfield<41> r; // Readable
827 // These bit fields are for data segments
828 Bitfield<42> e; // Expand-Down
829 Bitfield<41> w; // Writable
831 // This is used for both code and data segments.
832 Bitfield<40> a; // Accessed
834 EndBitUnion(SegDescriptor)
838 Bitfield<2> unusable;
839 Bitfield<3> defaultSize;
840 Bitfield<4> longMode;
842 Bitfield<6> granularity;
844 Bitfield<11, 8> type;
845 Bitfield<12> writable;
846 Bitfield<13> readable;
847 Bitfield<14> expandDown;
851 BitUnion64(GateDescriptor)
852 Bitfield<63, 48> offsetHigh; // Target Code-Segment Offset
853 Bitfield<15, 0> offsetLow; // Target Code-Segment Offset
854 Bitfield<31, 16> selector; // Target Code-Segment Selector
855 Bitfield<47> p; // Present
856 Bitfield<46, 45> dpl; // Descriptor Privilege-Level
857 Bitfield<43, 40> type;
858 Bitfield<36, 32> count; // Parameter Count
859 EndBitUnion(GateDescriptor)
862 * Descriptor-Table Registers
881 * Local APIC Base Register
883 BitUnion64(LocalApicBase)
884 Bitfield<51, 12> base;
887 EndBitUnion(LocalApicBase)
890 #endif // __ARCH_X86_INTREGS_HH__