EN
Intel logo
Official user manual

Intel 253668-032US

806 pages·5.7 MB·Webcam·PDF·ENDEFRITNLJA
Intel 253668-032US
Table of Contents 825 sections Chapter 1 About This Manual · 1.1 Processors Covered in this Manual · 1.2 Overview of The SYSTEM PROGRAMMING GUIDE · 1.3 Notational Conventions · … ShowHide
Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 1 of the Intel 253668-032US user manual — Intel® 64 and IA-32 Architectures
Page 1 · click to enlarge
Page 1

Intel® 64 and IA-32 Architectures

Software Developer’s Manual

Volume 3A: System Programming Guide, Part 1

NOTE: The Intel® 64 and IA-32 Architectures Software Developer's Manual consists of five volumes: Basic Architecture, Order Number 253665; Instruction Set Reference A-M, Order Number 253666; Instruction Set Reference N-Z, Order Number 253667; System Programming Guide, Part 1, Order Number 253668; System Programming Guide, Part 2, Order Number 253669. Refer to all five volumes when evaluating your design needs.

Order Number253668-032US

September 2009

Page 2 of the Intel 253668-032US user manual
Page 2 · click to enlarge
Page 2

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR IN TENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITU ATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "un defined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The Intel® 64 architecture processors may contain design defects or errors known as errata. Current char acterized errata are available on request.

Intel® Hyper-Threading Technology requires a computer system with an Intel® processor supporting Hyper- Threading Technology and an Intel® HT Technology enabled chipset, BIOS and operating system. Performance will vary depending on the specific hardware and software you use. For more information, see http://www.intel.com/technology/hyperthread/index.htm including details on which processors support Intel HT Technology.

Intel® Virtualization Technology requires a computer system with an enabled Intel® processor, BIOS, virtual machine monitor (VMM) and for some uses, certain platform software enabled for it. Functionality, perfor mance or other benefits will vary depending on hardware and software configurations. Intel® Virtualization Technology-enabled BIOS and VMM applications are currently in development.

64-bit computing on Intel architecture requires a computer system with a processor, chipset, BIOS, oper ating system, device drivers and applications enabled for Intel® 64 architecture. Processors will not operate (including 32-bit operation) without an Intel® 64 architecture-enabled BIOS. Performance will vary depend ing on your hardware and software configurations. Consult with your system vendor for more information.

Enabling Execute Disable Bit functionality requires a PC with a processor with Execute Disable Bit capability and a supporting operating system. Check with your PC manufacturer on whether your system delivers Ex ecute Disable Bit functionality.

Intel, Pentium, Intel Xeon, Intel NetBurst, Intel Core, Intel Core Solo, Intel Core Duo, Intel Core 2 Duo, Intel Core 2 Extreme, Intel Pentium D, Itanium, Intel SpeedStep, MMX, Intel Atom, and VTune are trade marks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other coun tries.

*Other names and brands may be claimed as the property of others.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an ordering number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or by visiting Intel’s website at http://www.intel.com

Copyright © 1997-2009 Intel Corporation

ii Vol. 3A

Page 3 of the Intel 253668-032US user manual — PAGE
Page 3 · click to enlarge
Page 3

CONTENTS

PAGE

CHAPTER 1 ABOUT THIS MANUAL 1.1 PROCESSORS COVERED IN THIS MANUAL 1-1 1.2 OVERVIEW OF THE SYSTEM PROGRAMMING GUIDE 1-3 1.3 NOTATIONAL CONVENTIONS 1-6 1.3.1 Bit and Byte Order 1-6 1.3.2 Reserved Bits and Software Compatibility 1-7 1.3.3 Instruction Operands 1-8 1.3.4 Hexadecimal and Binary Numbers 1-8 1.3.5 Segmented Addressing 1-8 1.3.6 Syntax for CPUID, CR, and MSR Values 1-9 1.3.7 Exceptions 1-10 1.4 RELATED LITERATURE 1-11

CHAPTER 2 SYSTEM ARCHITECTURE OVERVIEW 2.1 OVERVIEW OF THE SYSTEM-LEVEL ARCHITECTURE 2-2 2.1.1 Global and Local Descriptor Tables 2-5 2.1.1.1 Global and Local Descriptor Tables in IA-32e Mode 2-5 2.1.2 System Segments, Segment Descriptors, and Gates 2-5 2.1.2.1 Gates in IA-32e Mode 2-6 2.1.3 Task-State Segments and Task Gates 2-6 2.1.3.1 Task-State Segments in IA-32e Mode 2-7 2.1.4 Interrupt and Exception Handling 2-7 2.1.4.1 Interrupt and Exception Handling IA-32e Mode 2-7 2.1.5 Memory Management 2-8 2.1.5.1 Memory Management in IA-32e Mode 2-8 2.1.6 System Registers 2-9 2.1.6.1 System Registers in IA-32e Mode 2-9 2.1.7 Other System Resources 2-10 2.2 MODES OF OPERATION 2-10 2.3 SYSTEM FLAGS AND FIELDS IN THE EFLAGS REGISTER 2-12 2.3.1 System Flags and Fields in IA-32e Mode 2-15 2.4 MEMORY-MANAGEMENT REGISTERS 2-15 2.4.1 Global Descriptor Table Register (GDTR) 2-16 2.4.2 Local Descriptor Table Register (LDTR) 2-16 2.4.3 IDTR Interrupt Descriptor Table Register 2-17 2.4.4 Task Register (TR) 2-17 2.5 CONTROL REGISTERS 2-17 2.5.1 CPUID Qualification of Control Register Flags 2-26 2.6 EXTENDED CONTROL REGISTERS (INCLUDING THE XFEATURE_ENABLED_MASK REGISTER) 2-26 2.7 SYSTEM INSTRUCTION SUMMARY 2-27 2.7.1 Loading and Storing System Registers 2-29 2.7.2 Verifying of Access Privileges 2-30 2.7.3 Loading and Storing Debug Registers 2-31 2.7.4 Invalidating Caches and TLBs 2-31

Vol. 3A iii

Page 4 of the Intel 253668-032US user manual — Table of contents
Page 4 · click to enlarge
Page 4

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 5 of the Intel 253668-032US user manual — PAGE
Page 5 · click to enlarge
Page 5

CONTENTS

PAGE

4.9.3 Caching Paging-Related Information about Memory Typing 4-38 4.10 CACHING TRANSLATION INFORMATION 4-38 4.10.1 Translation Lookaside Buffers (TLBs)4-39 4.10.1.1 Page Numbers, Page Frames, and Page Offsets 4-39 4.10.1.2 Caching Translations in TLBs 4-40 4.10.1.3 Details of TLB Use 4-40 4.10.1.4 Global Pages 4-41 4.10.2 Paging-Structure Caches 4-41 4.10.2.1 Caches for Paging Structures4-41 4.10.2.2 Using the Paging-Structure Caches to Translate Linear Addresses 4-44 4.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entry4-45 4.10.3 Invalidation of TLBs and Paging-Structure Caches4-46 4.10.3.1 Operations that Invalidate TLBs and Paging-Structure Caches 4-46 4.10.3.2 Recommended Invalidation 4-47 4.10.3.3 Optional Invalidation 4-48 4.10.4 Propagation of Paging-Structure Changes to Multiple Processors4-49 4.11 INTERACTIONS WITH VIRTUAL-MACHINE EXTENSIONS (VMX) 4-51 4.11.1 VMX Transitions 4-51 4.11.2 VMX Support for Address Translation 4-51 4.12 USING PAGING FOR VIRTUAL MEMORY 4-52 4.13 MAPPING SEGMENTS TO PAGES 4-52

CHAPTER 5 PROTECTION 5.1 ENABLING AND DISABLING SEGMENT AND PAGE PROTECTION 5-1 5.2 FIELDS AND FLAGS USED FOR SEGMENT-LEVEL AND PAGE-LEVEL PROTECTION 5-2 5.2.1 Code Segment Descriptor in 64-bit Mode 5-5 5.3 LIMIT CHECKING 5-6 5.3.1 Limit Checking in 64-bit Mode 5-7 5.4 TYPE CHECKING 5-7 5.4.1 Null Segment Selector Checking 5-9 5.4.1.1 NULL Segment Checking in 64-bit Mode 5-9 5.5 PRIVILEGE LEVELS 5-9 5.6 PRIVILEGE LEVEL CHECKING WHEN ACCESSING DATA SEGMENTS 5-11 5.6.1 Accessing Data in Code Segments 5-14 5.7 PRIVILEGE LEVEL CHECKING WHEN LOADING THE SS REGISTER 5-14 5.8 PRIVILEGE LEVEL CHECKING WHEN TRANSFERRING PROGRAM CONTROL BETWEEN CODE SEGMENTS 5-14 5.8.1 Direct Calls or Jumps to Code Segments 5-15 5.8.1.1 Accessing Nonconforming Code Segments 5-16 5.8.1.2 Accessing Conforming Code Segments 5-17 5.8.2 Gate Descriptors 5-18 5.8.3 Call Gates 5-19 5.8.3.1 IA-32e Mode Call Gates 5-20 5.8.4 Accessing a Code Segment Through a Call Gate 5-22 5.8.5 Stack Switching 5-25 5.8.5.1 Stack Switching in 64-bit Mode 5-28 5.8.6 Returning from a Called Procedure 5-28 5.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructions 5-30

Vol. 3A v

Page 6 of the Intel 253668-032US user manual — Table of contents
Page 6 · click to enlarge
Page 6

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 7 of the Intel 253668-032US user manual — PAGE
Page 7 · click to enlarge
Page 7

CONTENTS

PAGE

6.14 EXCEPTION AND INTERRUPT HANDLING IN 64-BIT MODE 6-22 6.14.1 64-Bit Mode IDT 6-23 6.14.2 64-Bit Mode Stack Frame 6-24 6.14.3 IRET in IA-32e Mode 6-25 6.14.4 Stack Switching in IA-32e Mode 6-25 6.14.5 Interrupt Stack Table 6-26 6.15 EXCEPTION AND INTERRUPT REFERENCE 6-27

Interrupt 0—Divide Error Exception (#DE) 6-28 Interrupt 1—Debug Exception (#DB) 6-29 Interrupt 2—NMI Interrupt 6-30 Interrupt 3—Breakpoint Exception (#BP) 6-31 Interrupt 4—Overflow Exception (#OF) 6-32 Interrupt 5—BOUND Range Exceeded Exception (#BR) 6-33 Interrupt 6—Invalid Opcode Exception (#UD) 6-34 Interrupt 7—Device Not Available Exception (#NM) 6-36 Interrupt 8—Double Fault Exception (#DF) 6-38 Interrupt 9—Coprocessor Segment Overrun 6-41 Interrupt 10—Invalid TSS Exception (#TS) 6-42 Interrupt 11—Segment Not Present (#NP) 6-46 Interrupt 12—Stack Fault Exception (#SS) 6-48 Interrupt 13—General Protection Exception (#GP) 6-50 Interrupt 14—Page-Fault Exception (#PF) 6-54 Interrupt 16—x87 FPU Floating-Point Error (#MF) 6-58 Interrupt 17—Alignment Check Exception (#AC) 6-60 Interrupt 18—Machine-Check Exception (#MC) 6-62 Interrupt 19—SIMD Floating-Point Exception (#XM) 6-64 Interrupts 32 to 255—User Defined Interrupts 6-67

CHAPTER 7 TASK MANAGEMENT 7.1 TASK MANAGEMENT OVERVIEW 7-1 7.1.1 Task Structure 7-1 7.1.2 Task State 7-2 7.1.3 Executing a Task 7-3 7.2 TASK MANAGEMENT DATA STRUCTURES 7-4 7.2.1 Task-State Segment (TSS) 7-4 7.2.2 TSS Descriptor 7-7 7.2.3 TSS Descriptor in 64-bit mode 7-8 7.2.4 Task Register 7-9 7.2.5 Task-Gate Descriptor 7-11 7.3 TASK SWITCHING 7-12 7.4 TASK LINKING 7-16 7.4.1 Use of Busy Flag To Prevent Recursive Task Switching 7-18 7.4.2 Modifying Task Linkages 7-18 7.5 TASK ADDRESS SPACE 7-19 7.5.1 Mapping Tasks to the Linear and Physical Address Spaces 7-19 7.5.2 Task Logical Address Space 7-20 7.6 16-BIT TASK-STATE SEGMENT (TSS) 7-21 7.7 TASK MANAGEMENT IN 64-BIT MODE 7-22

Vol. 3A vii

Page 8 of the Intel 253668-032US user manual — Table of contents
Page 8 · click to enlarge
Page 8

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 9 of the Intel 253668-032US user manual — PAGE
Page 9 · click to enlarge
Page 9

CONTENTS

PAGE

8.7.9 Memory Ordering 8-42 8.7.10 Serializing Instructions 8-42 8.7.11 MICROCODE UPDATE Resources 8-43 8.7.12 Self Modifying Code 8-43 8.7.13 Implementation-Specific Intel HT Technology Facilities 8-43 8.7.13.1 Processor Caches 8-43 8.7.13.2 Processor Translation Lookaside Buffers (TLBs) 8-44 8.7.13.3 Thermal Monitor 8-44 8.7.13.4 External Signal Compatibility 8-45 8.8 MULTI-CORE ARCHITECTURE 8-46 8.8.1 Logical Processor Support 8-46 8.8.2 Memory Type Range Registers (MTRR) 8-46 8.8.3 Performance Monitoring Counters 8-47 8.8.4 IA32_MISC_ENABLE MSR 8-47 8.8.5 MICROCODE UPDATE Resources 8-47 8.9 PROGRAMMING CONSIDERATIONS FOR HARDWARE MULTI-THREADING CAPABLE PROCESSORS 8-47 8.9.1 Hierarchical Mapping of Shared Resources 8-48 8.9.2 Hierarchical Mapping of CPUID Extended Topology Leaf 8-50 8.9.3 Hierarchical ID of Logical Processors in an MP System 8-51 8.9.3.1 Hierarchical ID of Logical Processors with x2APIC ID 8-53 8.9.4 Algorithm for Three-Level Mappings of APIC_ID 8-54 8.9.5 Identifying Topological Relationships in a MP System 8-60 8.10 MANAGEMENT OF IDLE AND BLOCKED CONDITIONS 8-64 8.10.1 HLT Instruction 8-64 8.10.2 PAUSE Instruction 8-65 8.10.3 Detecting Support MONITOR/MWAIT Instruction 8-65 8.10.4 MONITOR/MWAIT Instruction 8-66 8.10.5 Monitor/Mwait Address Range Determination 8-67 8.10.6 Required Operating System Support 8-68 8.10.6.1 Use the PAUSE Instruction in Spin-Wait Loops 8-68 8.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loops 8-69 8.10.6.3 Halt Idle Logical Processors 8-71 8.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loops 8-71 8.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resources 8-72 8.10.6.6 Eliminate Execution-Based Timing Loops 8-72 8.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memory 8-73

CHAPTER 9 PROCESSOR MANAGEMENT AND INITIALIZATION 9.1 INITIALIZATION OVERVIEW 9-1 9.1.1 Processor State After Reset 9-2 9.1.2 Processor Built-In Self-Test (BIST) 9-2 9.1.3 Model and Stepping Information 9-5 9.1.4 First Instruction Executed 9-6 9.2 X87 FPU INITIALIZATION 9-6 9.2.1 Configuring the x87 FPU Environment 9-6 9.2.2 Setting the Processor for x87 FPU Software Emulation 9-7 9.3 CACHE ENABLING 9-8 9.4 MODEL-SPECIFIC REGISTERS (MSRS) 9-9

Vol. 3A ix

Page 10 of the Intel 253668-032US user manual — Table of contents
Page 10 · click to enlarge
Page 10

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 11 of the Intel 253668-032US user manual — CONTENTS
Page 11 · click to enlarge
Page 11

CONTENTS

PAGE CHAPTER 10 ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) 10.1 LOCAL AND I/O APIC OVERVIEW 10-1 10.2 SYSTEM BUS VS. APIC BUS 10-5 10.3 THE INTEL® 82489DX EXTERNAL APIC, THE APIC, THE XAPIC, AND THE X2APIC 10-5 10.4 LOCAL APIC 10-6 10.4.1 The Local APIC Block Diagram 10-6 10.4.2 Presence of the Local APIC 10-10 10.4.3 Enabling or Disabling the Local APIC 10-10 10.4.4 Local APIC Status and Location 10-11 10.4.5 Relocating the Local APIC Registers 10-12 10.4.6 Local APIC ID 10-12 10.4.7 Local APIC State 10-13 10.4.7.1 Local APIC State After Power-Up or Reset 10-14 10.4.7.2 Local APIC State After It Has Been Software Disabled 10-14 10.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State) 10-15 10.4.7.4 Local APIC State After It Receives an INIT-Deassert IPI 10-15 10.4.8 Local APIC Version Register 10-15 10.5 EXTENDED XAPIC (X2APIC) 10-16 10.5.1 DETECTING AND ENABLING x2APIC 10-16 10.5.1.1 Instructions to Access APIC Registers 10-17 10.5.1.2 APIC Register Address Space 10-18 10.5.1.3 Reserved Bit Checking 10-21 10.5.2 x2APIC Register Availability 10-22 10.5.3 MSR Access in x2APIC Mode 10-22 10.5.4 VM-exit Controls for MSRs and x2APIC Registers 10-22 10.5.5 Directed EOI with x2APIC Mode 10-23 10.5.6 x2APIC State Transitions 10-24 10.5.6.1 x2APIC States 10-24 x2APIC After RESET 10-26 x2APIC Transitions From x2APIC Mode 10-27 x2APIC Transitions From Disabled Mode 10-27 State Changes From xAPIC Mode to x2APIC Mode 10-27 10.5.7 System Software Transitions 10-27 10.5.8 CPUID Extensions And Topology Enumeration 10-28 10.5.8.1 Consistency of APIC IDs and CPUID 10-29 10.6 HANDLING LOCAL INTERRUPTS 10-30 10.6.1 Local Vector Table 10-30 10.6.2 Valid Interrupt Vectors 10-33 10.6.3 Error Handling 10-34 10.6.3.1 x2APIC Differences in Error Handling 10-35 10.6.4 APIC Timer 10-36 10.6.5 Local Interrupt Acceptance 10-38 10.7 ISSUING INTERPROCESSOR INTERRUPTS 10-38 10.7.1 Interrupt Command Register (ICR) 10-38 10.7.1.1 ICR Operation in x2APIC Mode 10-44 10.7.2 Determining IPI Destination 10-46 10.7.2.1 Physical Destination Mode 10-46 10.7.2.2 Logical Destination Mode 10-47 10.7.2.3 Logical Destination Mode in x2APIC Mode 10-49

Vol. 3A xi

Page 12 of the Intel 253668-032US user manual — Table of contents
Page 12 · click to enlarge
Page 12

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 13 of the Intel 253668-032US user manual — PAGE
Page 13 · click to enlarge
Page 13

CONTENTS

PAGE

11.11 MEMORY TYPE RANGE REGISTERS (MTRRS) 11-30 11.11.1 MTRR Feature Identification 11-32 11.11.2 Setting Memory Ranges with MTRRs 11-33 11.11.2.1 IA32_MTRR_DEF_TYPE MSR 11-33 11.11.2.2 Fixed Range MTRRs 11-34 11.11.2.3 Variable Range MTRRs 11-34 11.11.2.4 System-Management Range Register Interface 11-37 11.11.3 Example Base and Mask Calculations 11-38 11.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Support11-40 11.11.4 Range Size and Alignment Requirement 11-41 11.11.4.1 MTRR Precedences 11-41 11.11.5 MTRR Initialization 11-41 11.11.6 Remapping Memory Types 11-42 11.11.7 MTRR Maintenance Programming Interface 11-42 11.11.7.1 MemTypeGet() Function 11-42 11.11.7.2 MemTypeSet() Function 11-44 11.11.8 MTRR Considerations in MP Systems 11-46 11.11.9 Large Page Size Considerations 11-47 11.12 PAGE ATTRIBUTE TABLE (PAT) 11-48 11.12.1 Detecting Support for the PAT Feature 11-48 11.12.2 IA32_PAT MSR 11-49 11.12.3 Selecting a Memory Type from the PAT 11-50 11.12.4 Programming the PAT 11-50 11.12.5 PAT Compatibility with Earlier IA-32 Processors 11-52

CHAPTER 12 INTEL® MMX™ TECHNOLOGY SYSTEM PROGRAMMING 12.1 EMULATION OF THE MMX INSTRUCTION SET 12-1 12.2 THE MMX STATE AND MMX REGISTER ALIASING 12-1 12.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Word 12-3 12.3 SAVING AND RESTORING THE MMX STATE AND REGISTERS 12-4 12.4 SAVING MMX STATE ON TASK OR CONTEXT SWITCHES 12-5 12.5 EXCEPTIONS THAT CAN OCCUR WHEN EXECUTING MMX INSTRUCTIONS 12-5 12.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptions 12-6 12.6 DEBUGGING MMX CODE 12-6

CHAPTER 13 SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR EXTENDED STATES 13.1 PROVIDING OPERATING SYSTEM SUPPORT FOR SSE/SSE2/SSE3/SSSE3/SSE4 EXTENSIONS 13-1 13.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensions . . 13-2 13.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Support 13-2 13.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructions 13-3 13.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensions 13-3 13.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructions 13-5 13.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM) 13-7

Vol. 3A xiii

Page 14 of the Intel 253668-032US user manual — Table of contents
Page 14 · click to enlarge
Page 14

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 15 of the Intel 253668-032US user manual — PAGE
Page 15 · click to enlarge
Page 15

CONTENTS

PAGE

15.3 MACHINE-CHECK MSRS 15-2 15.3.1 Machine-Check Global Control MSRs 15-3 15.3.1.1 IA32_MCG_CAP MSR 15-3 15.3.1.2 IA32_MCG_STATUS MSR 15-5 15.3.1.3 IA32_MCG_CTL MSR 15-6 15.3.2 Error-Reporting Register Banks 15-6 15.3.2.1 IA32_MCi_CTL MSRs 15-6 15.3.2.2 IA32_MCi_STATUS MSRS 15-7 15.3.2.3 IA32_MCi_ADDR MSRs 15-11 15.3.2.4 IA32_MCi_MISC MSRs 15-12 15.3.2.5 IA32_MCi_CTL2 MSRs 15-13 15.3.2.6 IA32_MCG Extended Machine Check State MSRs 15-15 15.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecture 15-17 15.4 ENHANCED CACHE ERROR REPORTING 15-18 15.5 CORRECTED MACHINE CHECK ERROR INTERRUPT 15-18 15.5.1 CMCI Local APIC Interface 15-19 15.5.2 System Software Recommendation for Managing CMCI and Machine Check Resources . 15-21 15.5.2.1 CMCI Initialization 15-21 15.5.2.2 CMCI Threshold Management 15-22 15.5.2.3 CMCI Interrupt Handler 15-23 15.6 RECOVERY OF UNCORRECTED RECOVERABLE (UCR) ERRORS 15-23 15.6.1 Detection of Software Error Recovery Support 15-24 15.6.2 UCR Error Reporting and Logging 15-24 15.6.3 UCR Error Classification 15-25 15.6.4 UCR Error Overwrite Rules 15-27 15.7 MACHINE-CHECK AVAILABILITY 15-28 15.8 MACHINE-CHECK INITIALIZATION 15-28 15.9 INTERPRETING THE MCA ERROR CODES 15-29 15.9.1 Simple Error Codes 15-30 15.9.2 Compound Error Codes 15-31 15.9.2.1 Correction Report Filtering (F) Bit 15-31 15.9.2.2 Transaction Type (TT) Sub-Field 15-32 15.9.2.3 Level (LL) Sub-Field 15-32 15.9.2.4 Request (RRRR) Sub-Field 15-32 15.9.2.5 Bus and Interconnect Errors 15-33 15.9.2.6 Memory Controller Errors 15-34 15.9.3 Architecturally Defined UCR Errors 15-34 15.9.3.1 Architecturally Defined SRAO Errors 15-34 15.9.3.2 Architecturally Defined SRAR Errors 15-36 15.9.4 Multiple MCA Errors 15-38 15.9.5 Machine-Check Error Codes Interpretation 15-39 15.10 GUIDELINES FOR WRITING MACHINE-CHECK SOFTWARE 15-39 15.10.1 Machine-Check Exception Handler 15-40 15.10.2 Pentium Processor Machine-Check Exception Handling 15-41 15.10.3 Logging Correctable Machine-Check Errors 15-42 15.10.4 Machine-Check Software Handler Guidelines for Error Recovery 15-44 15.10.4.1 Machine-Check Exception Handler for Error Recovery 15-44 15.10.4.2 Corrected Machine-Check Handler for Error Recovery 15-50

Vol. 3A xv

Page 16 of the Intel 253668-032US user manual — Table of contents
Page 16 · click to enlarge
Page 16

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 17 of the Intel 253668-032US user manual — PAGE
Page 17 · click to enlarge
Page 17

CONTENTS

PAGE

16.9 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (PENTIUM M PROCESSORS) 16-43 16.10 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (P6 FAMILY PROCESSORS) 16-45 16.10.1 DEBUGCTLMSR Register 16-45 16.10.2 Last Branch and Last Exception MSRs 16-46 16.10.3 Monitoring Branches, Exceptions, and Interrupts 16-47 16.11 TIME-STAMP COUNTER 16-48 16.11.1 Invariant TSC 16-49 16.11.2 IA32_TSC_AUX Register and RDTSCP Support 16-50

CHAPTER 17 8086 EMULATION 17.1 REAL-ADDRESS MODE 17-1 17.1.1 Address Translation in Real-Address Mode 17-3 17.1.2 Registers Supported in Real-Address Mode 17-4 17.1.3 Instructions Supported in Real-Address Mode 17-4 17.1.4 Interrupt and Exception Handling 17-6 17.2 VIRTUAL-8086 MODE 17-8 17.2.1 Enabling Virtual-8086 Mode 17-9 17.2.2 Structure of a Virtual-8086 Task 17-9 17.2.3 Paging of Virtual-8086 Tasks 17-10 17.2.4 Protection within a Virtual-8086 Task 17-11 17.2.5 Entering Virtual-8086 Mode 17-11 17.2.6 Leaving Virtual-8086 Mode 17-14 17.2.7 Sensitive Instructions 17-15 17.2.8 Virtual-8086 Mode I/O 17-15 17.2.8.1 I/O-Port-Mapped I/O 17-15 17.2.8.2 Memory-Mapped I/O 17-16 17.2.8.3 Special I/O Buffers 17-16 17.3 INTERRUPT AND EXCEPTION HANDLING IN VIRTUAL-8086 MODE 17-16 17.3.1 Class 1—Hardware Interrupt and Exception Handling in Virtual-8086 Mode 17-18 17.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gate 17-18 17.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handler 17-20 17.3.1.3 Handling an Interrupt or Exception Through a Task Gate 17-21 17.3.2 Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism 17-22 17.3.3 Class 3—Software Interrupt Handling in Virtual-8086 Mode 17-24 17.3.3.1 Method 1: Software Interrupt Handling 17-27 17.3.3.2 Methods 2 and 3: Software Interrupt Handling 17-28 17.3.3.3 Method 4: Software Interrupt Handling 17-28 17.3.3.4 Method 5: Software Interrupt Handling 17-28 17.3.3.5 Method 6: Software Interrupt Handling 17-29 17.4 PROTECTED-MODE VIRTUAL INTERRUPTS 17-30

Vol. 3A xvii

Page 18 of the Intel 253668-032US user manual — Table of contents
Page 18 · click to enlarge
Page 18

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 19 of the Intel 253668-032US user manual — PAGE
Page 19 · click to enlarge
Page 19

CONTENTS

PAGE

19.18.6.3 Numeric Underflow Exception (#U) 19-14 19.18.6.4 Exception Precedence 19-14 19.18.6.5 CS and EIP For FPU Exceptions 19-14 19.18.6.6 FPU Error Signals 19-14 19.18.6.7 Assertion of the FERR# Pin 19-15 19.18.6.8 Invalid Operation Exception On Denormals 19-15 19.18.6.9 Alignment Check Exceptions (#AC) 19-16 19.18.6.10 Segment Not Present Exception During FLDENV 19-16 19.18.6.11 Device Not Available Exception (#NM) 19-16 19.18.6.12 Coprocessor Segment Overrun Exception 19-16 19.18.6.13 General Protection Exception (#GP) 19-16 19.18.6.14 Floating-Point Error Exception (#MF) 19-16 19.18.7 Changes to Floating-Point Instructions 19-17 19.18.7.1 FDIV, FPREM, and FSQRT Instructions 19-17 19.18.7.2 FSCALE Instruction 19-17 19.18.7.3 FPREM1 Instruction 19-17 19.18.7.4 FPREM Instruction 19-17 19.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructions 19-17 19.18.7.6 FPTAN Instruction 19-18 19.18.7.7 Stack Overflow 19-18 19.18.7.8 FSIN, FCOS, and FSINCOS Instructions 19-18 19.18.7.9 FPATAN Instruction 19-18 19.18.7.10 F2XM1 Instruction 19-18 19.18.7.11 FLD Instruction 19-18 19.18.7.12 FXTRACT Instruction 19-19 19.18.7.13 Load Constant Instructions 19-19 19.18.7.14 FSETPM Instruction 19-19 19.18.7.15 FXAM Instruction 19-20 19.18.7.16 FSAVE and FSTENV Instructions 19-20 19.18.8 Transcendental Instructions 19-20 19.18.9 Obsolete Instructions 19-20 19.18.10 WAIT/FWAIT Prefix Differences 19-21 19.18.11 Operands Split Across Segments and/or Pages 19-21 19.18.12 FPU Instruction Synchronization 19-21 19.19 SERIALIZING INSTRUCTIONS 19-21 19.20 FPU AND MATH COPROCESSOR INITIALIZATION 19-22 19.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initialization 19-22 19.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initialization 19-22 19.21 CONTROL REGISTERS 19-24 19.22 MEMORY MANAGEMENT FACILITIES 19-25 19.22.1 New Memory Management Control Flags 19-25 19.22.1.1 Physical Memory Addressing Extension 19-25 19.22.1.2 Global Pages 19-26 19.22.1.3 Larger Page Sizes 19-26 19.22.2 CD and NW Cache Control Flags 19-26 19.22.3 Descriptor Types and Contents 19-26 19.22.4 Changes in Segment Descriptor Loads 19-27 19.23 DEBUG FACILITIES 19-27 19.23.1 Differences in Debug Register DR6 19-27 19.23.2 Differences in Debug Register DR7 19-27 19.23.3 Debug Registers DR4 and DR5 19-27 19.24 RECOGNITION OF BREAKPOINTS 19-28

Vol. 3A xix

Page 20 of the Intel 253668-032US user manual — Table of contents
Page 20 · click to enlarge
Page 20

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 21 of the Intel 253668-032US user manual — PAGE
Page 21 · click to enlarge
Page 21

CONTENTS

PAGE

20.5 VIRTUAL-MACHINE CONTROL STRUCTURE 20-3 20.6 DISCOVERING SUPPORT FOR VMX 20-3 20.7 ENABLING AND ENTERING VMX OPERATION 20-4 20.8 RESTRICTIONS ON VMX OPERATION 20-5

CHAPTER 21 VIRTUAL-MACHINE CONTROL STRUCTURES 21.1 OVERVIEW 21-1 21.2 FORMAT OF THE VMCS REGION 21-2 21.3 ORGANIZATION OF VMCS DATA 21-3 21.4 GUEST-STATE AREA 21-3 21.4.1 Guest Register State 21-3 21.4.2 Guest Non-Register State 21-6 21.5 HOST-STATE AREA 21-9 21.6 VM-EXECUTION CONTROL FIELDS 21-10 21.6.1 Pin-Based VM-Execution Controls 21-10 21.6.2 Processor-Based VM-Execution Controls 21-11 21.6.3 Exception Bitmap 21-15 21.6.4 I/O-Bitmap Addresses 21-15 21.6.5 Time-Stamp Counter Offset 21-16 21.6.6 Guest/Host Masks and Read Shadows for CR0 and CR4 21-16 21.6.7 CR3-Target Controls 21-16 21.6.8 Controls for APIC Accesses 21-17 21.6.9 MSR-Bitmap Address 21-18 21.6.10 Executive-VMCS Pointer 21-19 21.6.11 Extended-Page-Table Pointer (EPTP) 21-19 21.6.12 Virtual-Processor Identifier (VPID) 21-19 21.6.13 Controls for PAUSE-Loop Exiting 21-20 21.7 VM-EXIT CONTROL FIELDS 21-20 21.7.1 VM-Exit Controls 21-20 21.7.2 VM-Exit Controls for MSRs 21-22 21.8 VM-ENTRY CONTROL FIELDS 21-23 21.8.1 VM-Entry Controls 21-23 21.8.2 VM-Entry Controls for MSRs 21-24 21.8.3 VM-Entry Controls for Event Injection 21-24 21.9 VM-EXIT INFORMATION FIELDS 21-26 21.9.1 Basic VM-Exit Information 21-26 21.9.2 Information for VM Exits Due to Vectored Events 21-27 21.9.3 Information for VM Exits That Occur During Event Delivery 21-28 21.9.4 Information for VM Exits Due to Instruction Execution 21-29 21.9.5 VM-Instruction Error Field 21-29 21.10 SOFTWARE ACCESS TO THE VMCS AND RELATED STRUCTURES 21-30 21.10.1 Software Access to the Virtual-Machine Control Structure 21-30 21.10.2 VMREAD, VMWRITE, and Encodings of VMCS Fields 21-31 21.10.3 Software Access to Related Structures 21-33 21.10.4 VMXON Region 21-33 21.11 USING VMCLEAR TO INITIALIZE A VMCS REGION 21-34

Vol. 3A xxi

Page 22 of the Intel 253668-032US user manual — Table of contents
Page 22 · click to enlarge
Page 22

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 23 of the Intel 253668-032US user manual — PAGE
Page 23 · click to enlarge
Page 23

CONTENTS

PAGE

23.3.1.3 Checks on Guest Descriptor-Table Registers 23-15 23.3.1.4 Checks on Guest RIP and RFLAGS 23-15 23.3.1.5 Checks on Guest Non-Register State 23-16 23.3.1.6 Checks on Guest Page-Directory-Pointer-Table Entries 23-18 23.3.2 Loading Guest State 23-19 23.3.2.1 Loading Guest Control Registers, Debug Registers, and MSRs 23-19 23.3.2.2 Loading Guest Segment Registers and Descriptor-Table Registers 23-21 23.3.2.3 Loading Guest RIP, RSP, and RFLAGS 23-22 23.3.2.4 Loading Page-Directory-Pointer-Table Entries 23-22 23.3.2.5 Updating Non-Register State 23-23 23.3.3 Clearing Address-Range Monitoring 23-23 23.4 LOADING MSRS 23-23 23.5 EVENT INJECTION 23-24 23.5.1 Vectored-Event Injection 23-24 23.5.1.1 Details of Vectored-Event Injection 23-25 23.5.1.2 VM Exits During Event Injection 23-27 23.5.1.3 Event Injection for VM Entries to Real-Address Mode 23-28 23.5.2 Injection of Pending MTF VM Exits 23-28 23.6 SPECIAL FEATURES OF VM ENTRY 23-28 23.6.1 Interruptibility State 23-29 23.6.2 Activity State 23-30 23.6.3 Delivery of Pending Debug Exceptions after VM Entry 23-31 23.6.4 VMX-Preemption Timer 23-32 23.6.5 Interrupt-Window Exiting 23-32 23.6.6 NMI-Window Exiting 23-32 23.6.7 VM Exits Induced by the TPR Shadow 23-33 23.6.8 Pending MTF VM Exits 23-34 23.6.9 VM Entries and Advanced Debugging Features 23-34 23.7 VM-ENTRY FAILURES DURING OR AFTER LOADING GUEST STATE 23-34 23.8 MACHINE CHECKS DURING VM ENTRY 23-35

CHAPTER 24 VM EXITS 24.1 ARCHITECTURAL STATE BEFORE A VM EXIT 24-1 24.2 RECORDING VM-EXIT INFORMATION AND UPDATING VM-ENTRY CONTROL FIELDS. . . 24-5 24.2.1 Basic VM-Exit Information 24-5 24.2.2 Information for VM Exits Due to Vectored Events 24-14 24.2.3 Information for VM Exits During Event Delivery 24-15 24.2.4 Information for VM Exits Due to Instruction Execution 24-17 24.3 SAVING GUEST STATE 24-26 24.3.1 Saving Control Registers, Debug Registers, and MSRs 24-27 24.3.2 Saving Segment Registers and Descriptor-Table Registers 24-27 24.3.3 Saving RIP, RSP, and RFLAGS 24-28 24.3.4 Saving Non-Register State 24-30 24.4 SAVING MSRS 24-32 24.5 LOADING HOST STATE 24-33 24.5.1 Loading Host Control Registers, Debug Registers, MSRs 24-33 24.5.2 Loading Host Segment and Descriptor-Table Registers 24-34 24.5.3 Loading Host RIP, RSP, and RFLAGS 24-36 24.5.4 Checking and Loading Host Page-Directory-Pointer-Table Entries 24-36 24.5.5 Updating Non-Register State 24-37

Vol. 3A xxiii

Page 24 of the Intel 253668-032US user manual — Table of contents
Page 24 · click to enlarge
Page 24

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 25 of the Intel 253668-032US user manual — PAGE
Page 25 · click to enlarge
Page 25

CONTENTS

PAGE

26.11 SMBASE RELOCATION 26-19 26.11.1 Relocating SMRAM to an Address Above 1 MByte 26-20 26.12 I/O INSTRUCTION RESTART 26-20 26.12.1 Back-to-Back SMI Interrupts When I/O Instruction Restart Is Being Used 26-22 26.13 SMM MULTIPLE-PROCESSOR CONSIDERATIONS 26-22 26.14 DEFAULT TREATMENT OF SMIS AND SMM WITH VMX OPERATION AND SMX OPERATION . 26-23 26.14.1 Default Treatment of SMI Delivery 26-23 26.14.2 Default Treatment of RSM 26-24 26.14.3 Protection of CR4.VMXE in SMM 26-26 26.15 DUAL-MONITOR TREATMENT OF SMIs AND SMM 26-26 26.15.1 Dual-Monitor Treatment Overview 26-26 26.15.2 SMM VM Exits 26-27 26.15.2.1 Architectural State Before a VM Exit 26-27 26.15.2.2 Updating the Current-VMCS and Executive-VMCS Pointers 26-27 26.15.2.3 Recording VM-Exit Information 26-28 26.15.2.4 Saving Guest State 26-29 26.15.2.5 Updating Non-Register State 26-29 26.15.3 Operation of an SMM Monitor 26-30 26.15.4 VM Entries that Return from SMM 26-30 26.15.4.1 Checks on the Executive-VMCS Pointer Field 26-30 26.15.4.2 Checks on VM-Execution Control Fields 26-31 26.15.4.3 Checks on VM-Entry Control Fields 26-31 26.15.4.4 Checks on the Guest State Area 26-32 26.15.4.5 Loading Guest State 26-32 26.15.4.6 VMX-Preemption Timer 26-32 26.15.4.7 Updating the Current-VMCS and SMM-Transfer VMCS Pointers 26-33 26.15.4.8 VM Exits Induced by VM Entry 26-33 26.15.4.9 SMI Blocking 26-33 26.15.4.10 Failures of VM Entries That Return from SMM 26-34 26.15.5 Enabling the Dual-Monitor Treatment 26-34 26.15.6 Activating the Dual-Monitor Treatment 26-36 26.15.6.1 Initial Checks 26-36 26.15.6.2 MSEG Checking 26-38 26.15.6.3 Updating the Current-VMCS and Executive-VMCS Pointers 26-38 26.15.6.4 Loading Host State 26-38 26.15.6.5 Loading MSRs 26-40 26.15.7 Deactivating the Dual-Monitor Treatment 26-40 26.16 SMI AND PROCESSOR EXTENDED STATE MANAGEMENT 26-41

CHAPTER 27 VIRTUAL-MACHINE MONITOR PROGRAMMING CONSIDERATIONS 27.1 VMX SYSTEM PROGRAMMING OVERVIEW 27-1 27.2 SUPPORTING PROCESSOR OPERATING MODES IN GUEST ENVIRONMENTS 27-1 27.2.1 Emulating Guest Execution 27-2 27.3 MANAGING VMCS REGIONS AND POINTERS 27-2 27.4 USING VMX INSTRUCTIONS 27-5 27.5 VMM SETUP & TEAR DOWN 27-5 27.5.1 Algorithms for Determining VMX Capabilities 27-6 27.6 PREPARATION AND LAUNCHING A VIRTUAL MACHINE 27-9 27.7 HANDLING OF VM EXITS 27-11

Vol. 3A xxv

Page 26 of the Intel 253668-032US user manual — Table of contents
Page 26 · click to enlarge
Page 26

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 27 of the Intel 253668-032US user manual — CONTENTS
Page 27 · click to enlarge
Page 27

CONTENTS

PAGE CHAPTER 29 HANDLING BOUNDARY CONDITIONS IN A VIRTUAL MACHINE MONITOR 29.1 OVERVIEW 29-1 29.2 INTERRUPT HANDLING IN VMX OPERATION 29-1 29.3 EXTERNAL INTERRUPT VIRTUALIZATION 29-3 29.3.1 Virtualization of Interrupt Vector Space 29-4 29.3.2 Control of Platform Interrupts 29-5 29.3.2.1 PIC Virtualization 29-6 29.3.2.2 xAPIC Virtualization 29-6 29.3.2.3 Local APIC Virtualization 29-6 29.3.2.4 I/O APIC Virtualization 29-7 29.3.2.5 Virtualization of Message Signaled Interrupts 29-8 29.3.3 Examples of Handling of External Interrupts 29-8 29.3.3.1 Guest Setup 29-8 29.3.3.2 Processor Treatment of External Interrupt 29-9 29.3.3.3 Processing of External Interrupts by VMM 29-9 29.3.3.4 Generation of Virtual Interrupt Events by VMM 29-10 29.4 ERROR HANDLING BY VMM 29-11 29.4.1 VM-Exit Failures 29-11 29.4.2 Machine Check Considerations 29-12 29.4.3 MCA Error Handling Guidelines for VMM 29-13 29.4.3.1 VMM Error Handling Strategies 29-13 29.4.3.2 Basic VMM MCA error recovery handling 29-14 29.4.3.3 Implementation Considerations for the Basic Model 29-14 29.4.3.4 MCA Virtualization 29-15 29.4.3.5 Implementation Considerations for the MCA Virtualization Model 29-15 29.5 HANDLING ACTIVITY STATES BY VMM 29-15

CHAPTER 30 PERFORMANCE MONITORING 30.1 PERFORMANCE MONITORING OVERVIEW 30-1 30.2 ARCHITECTURAL PERFORMANCE MONITORING 30-2 30.2.1 Architectural Performance Monitoring Version 1 30-3 30.2.1.1 Architectural Performance Monitoring Version 1 Facilities 30-4 30.2.2 Additional Architectural Performance Monitoring Extensions 30-6 30.2.2.1 Architectural Performance Monitoring Version 2 Facilities 30-6 30.2.2.2 Architectural Performance Monitoring Version 3 Facilities 30-10 30.2.3 Pre-defined Architectural Performance Events 30-12 30.3 PERFORMANCE MONITORING (INTEL® CORE™ SOLO AND INTEL® CORE™ DUO PROCESSORS) 30-14 30.4 PERFORMANCE MONITORING (PROCESSORS BASED ON INTEL® CORE™ MICROARCHITECTURE) 30-16 30.4.1 Fixed-function Performance Counters 30-18 30.4.2 Global Counter Control Facilities 30-19 30.4.3 At-Retirement Events 30-21 30.4.4 Precise Event Based Sampling (PEBS) 30-22 30.4.4.1 Setting up the PEBS Buffer 30-23 30.4.4.2 PEBS Record Format 30-23 30.4.4.3 Writing a PEBS Interrupt Service Routine 30-23

Vol. 3A xxvii

Page 28 of the Intel 253668-032US user manual — Table of contents
Page 28 · click to enlarge
Page 28

Table of contents

Chapter 1 About This Manualp.451.1 Processors Covered in this Manualp.451.2 Overview of The SYSTEM PROGRAMMING GUIDEp.471.3 Notational Conventionsp.501.3.1 Bit and Byte Orderp.501.3.2 Reserved Bits and Software Compatibilityp.511.3.3 Instruction Operandsp.521.3.4 Hexadecimal and Binary Numbersp.521.3.5 Segmented Addressingp.521.3.6 Syntax for CPUID, CR, and MSR Valuesp.531.3.7 Exceptionsp.541.4 Related Literaturep.55Chapter 2 System Architecture Overviewp.572.1 Overview of the System-Level Architecturep.582.1.1 Global and Local Descriptor Tablesp.612.1.1.1 Global and Local Descriptor Tables in IA-32e Modep.612.1.2 System Segments, Segment Descriptors, and Gatesp.612.1.2.1 Gates in IA-32e Modep.622.1.3 Task-State Segments and Task Gatesp.622.1.3.1 Task-State Segments in IA-32e Modep.632.1.4 Interrupt and Exception Handlingp.632.1.4.1 Interrupt and Exception Handling IA-32e Modep.632.1.5 Memory Managementp.642.1.5.1 Memory Management in IA-32e Modep.642.1.6 System Registersp.652.1.6.1 System Registers in IA-32e Modep.652.1.7 Other System Resourcesp.662.2 Modes of Operationp.662.3 System Flags and Fields in the EFLAGS Registerp.682.3.1 System Flags and Fields in IA-32e Modep.712.4 Memory-Management Registersp.712.4.1 Global Descriptor Table Register (GDTR)p.722.4.2 Local Descriptor Table Register (LDTR)p.722.4.3 IDTR Interrupt Descriptor Table Registerp.732.4.4 Task Register (TR)p.732.5 Control Registersp.732.5.1 CPUID Qualification of Control Register Flagsp.822.6 Extended Control Registers (including the XFEATURE_ENABLED_MASK Register)p.822.7 System Instruction Summaryp.832.7.1 Loading and Storing System Registersp.852.7.2 Verifying of Access Privilegesp.862.7.3 Loading and Storing Debug Registersp.872.7.4 Invalidating Caches and TLBsp.872.7.5 Controlling the Processorp.872.7.6 Reading Performance-Monitoring and Time-Stamp Countersp.882.7.6.1 Reading Counters in 64-Bit Modep.892.7.7 Reading and Writing Model-Specific Registersp.892.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Modep.902.7.8 Enabling Processor Extended Statesp.90Chapter 3 Protected-Mode Memory Managementp.913.1 Memory Management Overviewp.913.2 Using Segmentsp.933.2.1 Basic Flat Modelp.933.2.2 Protected Flat Modelp.943.2.3 Multi-Segment Modelp.953.2.4 Segmentation in IA-32e Modep.963.2.5 Paging and Segmentationp.973.3 Physical Address Spacep.973.3.1 Intel® 64 Processors and Physical Address Spacep.983.4 Logical and Linear Addressesp.983.4.1 Logical Address Translation in IA-32e Modep.993.4.2 Segment Selectorsp.993.4.3 Segment Registersp.1003.4.4 Segment Loading Instructions in IA-32e Modep.1023.4.5 Segment Descriptorsp.1033.4.5.1 Codeand Data-Segment Descriptor Typesp.1063.5 System Descriptor Typesp.1083.5.1 Segment Descriptor Tablesp.1103.5.2 Segment Descriptor Tables in IA-32e Modep.112Chapter 4 Pagingp.1134.1 Paging Modes and Control Bitsp.1134.1.1 Three Paging Modesp.1144.1.2 Paging-Mode Enablingp.1154.1.3 Paging-Mode Modifiersp.1174.1.4 Enumeration of Paging Features by CPUIDp.1184.2 Hierarchical Paging Structures: an Overviewp.1194.3 32-Bit Pagingp.1204.4 PAE Pagingp.1274.4.1 PDPTE Registersp.1284.4.2 Linear-Address Translation with PAE Pagingp.1294.5 IA-32e Pagingp.1354.6 Access Rightsp.1444.7 Page-Fault Exceptionsp.1464.8 Accessed and Dirty Flagsp.1484.9 Paging and Memory Typingp.1494.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)p.1494.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)p.1494.9.3 Caching Paging-Related Information about Memory Typingp.1504.10 Caching Translation Informationp.1504.10.1 Translation Lookaside Buffers (TLBs)p.1514.10.1.1 Page Numbers, Page Frames, and Page Offsetsp.1514.10.1.2 Caching Translations in TLBsp.1524.10.1.3 Details of TLB Usep.1524.10.1.4 Global Pagesp.1534.10.2 Paging-Structure Cachesp.1534.10.2.1 Caches for Paging Structuresp.1534.10.2.2 Using the Paging-Structure Caches to Translate Linear Addressesp.1564.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entryp.1574.10.3 Invalidation of TLBs and Paging-Structure Cachesp.1584.10.3.1 Operations that Invalidate TLBs and Paging-Structure Cachesp.1584.10.3.2 Recommended Invalidationp.1594.10.3.3 Optional Invalidationp.1604.10.4 Propagation of Paging-Structure Changes to Multiple Processorsp.1614.11 Interactions with Virtual-Machine Extensions (VMX)p.1634.11.1 VMX Transitionsp.1634.11.2 VMX Support for Address Translationp.1634.12 Using Paging for Virtual Memoryp.1644.13 Mapping Segments to Pagesp.164Chapter 5 Protectionp.1675.1 Enabling and Disabling Segment and Page Protectionp.1675.2 Fields and Flags Used for Segment-Level and Page-Level Protectionp.1685.2.1 Code Segment Descriptor in 64-bit Modep.1715.3 Limit Checkingp.1725.3.1 Limit Checking in 64-bit Modep.1735.4 Type Checkingp.1735.4.1 Null Segment Selector Checkingp.1755.4.1.1 NULL Segment Checking in 64-bit Modep.1755.5 Privilege Levelsp.1755.6 Privilege Level Checking When Accessing Data Segmentsp.1775.6.1 Accessing Data in Code Segmentsp.1795.7 Privilege Level Checking When Loading the SS Registerp.1805.8 Privilege Level Checking When Transferring Program Control Between Code Segmentsp.1805.8.1 Direct Calls or Jumps to Code Segmentsp.1815.8.1.1 Accessing Nonconforming Code Segmentsp.1825.8.1.2 Accessing Conforming Code Segmentsp.1835.8.2 Gate Descriptorsp.1845.8.3 Call Gatesp.1855.8.3.1 IA-32e Mode Call Gatesp.1865.8.4 Accessing a Code Segment Through a Call Gatep.1885.8.5 Stack Switchingp.1915.8.5.1 Stack Switching in 64-bit Modep.1945.8.6 Returning from a Called Procedurep.1945.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructionsp.1965.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Modep.1975.8.8 Fast System Calls in 64-bit Modep.1985.9 Privileged Instructionsp.1995.10 Pointer Validationp.2005.10.1 Checking Access Rights (LAR Instruction)p.2015.10.2 Checking Read/Write Rights (VERR and VERW Instructions)p.2025.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)p.2025.10.4 Checking Caller Access Privileges (ARPL Instruction)p.2035.10.5 Checking Alignmentp.2055.11 Page-Level Protectionp.2055.11.1 Page-Protection Flagsp.2065.11.2 Restricting Addressable Domainp.2065.11.3 Page Typep.2065.11.4 Combining Protection of Both Levels of Page Tablesp.2075.11.5 Overrides to Page Protectionp.2075.12 Combining Page and Segment Protectionp.2075.13 Page-Level Protection and Execute-Disable Bitp.2095.13.1 Detecting and Enabling the Execute-Disable Capabilityp.2095.13.2 Execute-Disable Page Protectionp.2105.13.3 Reserved Bit Checkingp.2115.13.4 Exception Handlingp.213Chapter 6 Interrupt and Exception Handlingp.2156.1 Interrupt and Exception Overviewp.2156.2 Exception and Interrupt Vectorsp.2166.3 Sources of Interruptsp.2166.3.1 External Interruptsp.2166.3.2 Maskable Hardware Interruptsp.2186.3.3 Software-Generated Interruptsp.2196.4 Sources of Exceptionsp.2196.4.1 Program-Error Exceptionsp.2196.4.2 Software-Generated Exceptionsp.2206.4.3 Machine-Check Exceptionsp.2206.5 Exception Classificationsp.2206.6 Program or Task Restartp.2216.7 NonMaskable Interrupt (NMI)p.2226.7.1 Handling Multiple NMIsp.2236.8 Enabling and Disabling Interruptsp.2236.8.1 Masking Maskable Hardware Interruptsp.2236.8.2 Masking Instruction Breakpointsp.2246.8.3 Masking Exceptions and Interrupts When Switching Stacksp.2256.9 Priority Among Simultaneous Exceptions and Interruptsp.2256.10 Interrupt Descriptor Table (IDT)p.2266.11 IDT Descriptorsp.2286.12 Exception and Interrupt Handlingp.2296.12.1 Exceptionor Interrupt-Handler Proceduresp.2306.12.1.1 Protection of Exceptionand Interrupt-Handler Proceduresp.2326.12.1.2 Flag Usage By Exceptionor Interrupt-Handler Procedurep.2336.12.2 Interrupt Tasksp.2346.13 Error Codep.2356.14 Exception and Interrupt Handling in 64-bit Modep.2366.14.1 64-Bit Mode IDTp.2376.14.2 64-Bit Mode Stack Framep.2386.14.3 IRET in IA-32e Modep.2396.14.4 Stack Switching in IA-32e Modep.2396.14.5 Interrupt Stack Tablep.2406.15 Exception and Interrupt Referencep.241Interrupt 0-Divide Error Exception (#DE)p.242Interrupt 1-Debug Exception (#DB)p.243Interrupt 2-NMI Interruptp.244Interrupt 3-Breakpoint Exception (#BP)p.245Interrupt 4-Overflow Exception (#OF)p.246Interrupt 5-BOUND Range Exceeded Exception (#BR)p.247Interrupt 6-Invalid Opcode Exception (#UD)p.248Interrupt 7-Device Not Available Exception (#NM)p.250Interrupt 8-Double Fault Exception (#DF)p.252Interrupt 9-Coprocessor Segment Overrunp.255Interrupt 10-Invalid TSS Exception (#TS)p.256Interrupt 11-Segment Not Present (#NP)p.260Interrupt 12-Stack Fault Exception (#SS)p.262Interrupt 13-General Protection Exception (#GP)p.264Interrupt 14-Page-Fault Exception (#PF)p.268Interrupt 16-x87 FPU Floating-Point Error (#MF)p.272Interrupt 17-Alignment Check Exception (#AC)p.274Interrupt 18-Machine-Check Exception (#MC)p.276Interrupt 19-SIMD Floating-Point Exception (#XM)p.278Interrupts 32 to 255-User Defined Interruptsp.281Chapter 7 Task Managementp.2837.1 Task Management Overviewp.2837.1.1 Task Structurep.2837.1.2 Task Statep.2847.1.3 Executing a Taskp.2857.2 Task Management Data Structuresp.2867.2.1 Task-State Segment (TSS)p.2867.2.2 TSS Descriptorp.2897.2.3 TSS Descriptor in 64-bit modep.2907.2.4 Task Registerp.2917.2.5 Task-Gate Descriptorp.2937.3 Task Switchingp.2947.4 Task Linkingp.2987.4.1 Use of Busy Flag To Prevent Recursive Task Switchingp.3007.4.2 Modifying Task Linkagesp.3007.5 Task Address Spacep.3017.5.1 Mapping Tasks to the Linear and Physical Address Spacesp.3017.5.2 Task Logical Address Spacep.3027.6 16-Bit Task-State Segment (TSS)p.3037.7 Task Management in 64-bit Modep.304Chapter 8 Multiple-Processor Managementp.3078.1 Locked Atomic Operationsp.3088.1.1 Guaranteed Atomic Operationsp.3098.1.2 Bus Lockingp.3098.1.2.1 Automatic Lockingp.3108.1.2.2 Software Controlled Bus Lockingp.3118.1.3 Handling Selfand Cross-Modifying Codep.3128.1.4 Effects of a LOCK Operation on Internal Processor Cachesp.3138.2 Memory Orderingp.3148.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processorsp.3148.2.2 Memory Ordering in P6 and More Recent Processor Familiesp.3158.2.3 Examples Illustrating the Memory-Ordering Principlesp.3178.2.3.1 Assumptions, Terminology, and Notationp.3178.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operationsp.3188.2.3.3 Stores Are Not Reordered With Earlier Loadsp.3198.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locationsp.3198.2.3.5 Intra-Processor Forwarding Is Allowedp.3208.2.3.6 Stores Are Transitively Visiblep.3218.2.3.7 Stores Are Seen in a Consistent Order by Other Processorsp.3218.2.3.8 Locked Instructions Have a Total Orderp.3228.2.3.9 Loads and Stores Are Not Reordered with Locked Instructionsp.3228.2.4 Out-of-Order Stores For String Operationsp.3248.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memoryp.3248.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operationsp.3258.2.5 Strengthening or Weakening the Memory-Ordering Modelp.3288.3 Serializing Instructionsp.3308.4 Multiple-Processor (MP) Initializationp.3328.4.1 BSP and AP Processorsp.3338.4.2 MP Initialization Protocol Requirements and Restrictionsp.3338.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processorsp.3348.4.4 MP Initialization Examplep.3358.4.4.1 Typical BSP Initialization Sequencep.3368.4.4.2 Typical AP Initialization Sequencep.3388.4.5 Identifying Logical Processors in an MP Systemp.3398.5 Intel® Hyper-Threading Technology and Intel® Multi-Core Technologyp.3418.6 Detecting Hardware Multi-Threading Support and Topologyp.3418.6.1 Initializing Processors Supporting Hyper-Threading Technologyp.3428.6.2 Initializing Multi-Core Processorsp.3438.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threadingp.3438.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threadingp.3438.7 Intel® Hyper-Threading Technology Architecturep.3448.7.1 State of the Logical Processorsp.3458.7.2 APIC Functionalityp.3468.7.3 Memory Type Range Registers (MTRR)p.3468.7.4 Page Attribute Table (PAT)p.3478.7.5 Machine Check Architecturep.3478.7.6 Debug Registers and Extensionsp.3478.7.7 Performance Monitoring Countersp.3488.7.8 IA32_MISC_ENABLE MSRp.3488.7.9 Memory Orderingp.3488.7.10 Serializing Instructionsp.3488.7.11 MICROCODE UPDATE Resourcesp.3498.7.12 Self Modifying Codep.3498.7.13 Implementation-Specific Intel HT Technology Facilitiesp.3498.7.13.1 Processor Cachesp.3498.7.13.2 Processor Translation Lookaside Buffers (TLBs)p.3508.7.13.3 Thermal Monitorp.3508.7.13.4 External Signal Compatibilityp.3518.8 Multi-Core Architecturep.3528.8.1 Logical Processor Supportp.3528.8.2 Memory Type Range Registers (MTRR)p.3528.8.3 Performance Monitoring Countersp.3538.8.4 IA32_MISC_ENABLE MSRp.3538.8.5 MICROCODE UPDATE Resourcesp.3538.9 Programming Considerations for Hardware Multi-Threading Capable Processorsp.3538.9.1 Hierarchical Mapping of Shared Resourcesp.3548.9.2 Hierarchical Mapping of CPUID Extended Topology Leafp.3568.9.3 Hierarchical ID of Logical Processors in an MP Systemp.3578.9.3.1 Hierarchical ID of Logical Processors with x2APIC IDp.3598.9.4 Algorithm for Three-Level Mappings of APIC_IDp.3608.9.5 Identifying Topological Relationships in a MP Systemp.3668.10 Management of Idle and Blocked Conditionsp.3708.10.1 HLT Instructionp.3708.10.2 PAUSE Instructionp.3718.10.3 Detecting Support MONITOR/MWAIT Instructionp.3718.10.4 MONITOR/MWAIT Instructionp.3728.10.5 Monitor/Mwait Address Range Determinationp.3738.10.6 Required Operating System Supportp.3748.10.6.1 Use the PAUSE Instruction in Spin-Wait Loopsp.3748.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loopsp.3758.10.6.3 Halt Idle Logical Processorsp.3778.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loopsp.3778.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resourcesp.3788.10.6.6 Eliminate Execution-Based Timing Loopsp.3788.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memoryp.379Chapter 9 Processor Management and Initializationp.3819.1 Initialization Overviewp.3819.1.1 Processor State After Resetp.3829.1.2 Processor Built-In Self-Test (BIST)p.3829.1.3 Model and Stepping Informationp.3859.1.4 First Instruction Executedp.3869.2 x87 FPU Initializationp.3869.2.1 Configuring the x87 FPU Environmentp.3869.2.2 Setting the Processor for x87 FPU Software Emulationp.3879.3 Cache Enablingp.3889.4 Model-Specific Registers (MSRs)p.3899.5 Memory Type Range Registers (MTRRs)p.3899.6 Initializing SSE/SSE2/SSE3/SSSE3 Extensionsp.3909.7 Software Initialization for Real-Address Mode Operationp.3909.7.1 Real-Address Mode IDTp.3919.7.2 NMI Interrupt Handlingp.3919.8 Software Initialization for Protected-Mode Operationp.3919.8.1 Protected-Mode System Data Structuresp.3929.8.2 Initializing Protected-Mode Exceptions and Interruptsp.3939.8.3 Initializing Pagingp.3939.8.4 Initializing Multitaskingp.3949.8.5 Initializing IA-32e Modep.3949.8.5.1 IA-32e Mode System Data Structuresp.3959.8.5.2 IA-32e Mode Interrupts and Exceptionsp.3959.8.5.3 64-bit Mode and Compatibility Mode Operationp.3969.8.5.4 Switching Out of IA-32e Mode Operationp.3969.9 Mode Switchingp.3979.9.1 Switching to Protected Modep.3979.9.2 Switching Back to Real-Address Modep.3989.10 Initialization and Mode Switching Examplep.3999.10.1 Assembler Usagep.4029.10.2 STARTUP.ASM Listingp.4039.10.3 MAIN.ASM Source Codep.4139.10.4 Supporting Filesp.4149.11 Microcode Update Facilitiesp.4169.11.1 Microcode Updatep.4179.11.2 Optional Extended Signature Tablep.4219.11.3 Processor Identificationp.4219.11.4 Platform Identificationp.4229.11.5 Microcode Update Checksump.4249.11.6 Microcode Update Loaderp.4259.11.6.1 Hard Resets in Update Loadingp.4269.11.6.2 Update in a Multiprocessor Systemp.4269.11.6.3 Update in a System Supporting Intel Hyper-Threading Technologyp.4269.11.6.4 Update in a System Supporting Dual-Core Technologyp.4269.11.6.5 Update Loader Enhancementsp.4279.11.7 Update Signature and Verificationp.4279.11.7.1 Determining the Signaturep.4289.11.7.2 Authenticating the Updatep.4289.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specificationsp.4299.11.8.1 Responsibilities of the BIOSp.4299.11.8.2 Responsibilities of the Calling Programp.4329.11.8.3 Microcode Update Functionsp.4359.11.8.4 INT 15H-based Interfacep.4359.11.8.5 Function 00H-Presence Testp.4369.11.8.6 Function 01H-Write Microcode Update Datap.4379.11.8.7 Function 02H-Microcode Update Controlp.4429.11.8.8 Function 03H-Read Microcode Update Datap.4439.11.8.9 Return Codesp.444Chapter 10 Advanced Programmable Interrupt Controller (APIC)p.44710.1 Local and I/O APIC Overviewp.44710.2 System Bus Vs. APIC Busp.45110.3 the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APICp.45110.4 Local APICp.45210.4.1 The Local APIC Block Diagramp.45210.4.2 Presence of the Local APICp.45610.4.3 Enabling or Disabling the Local APICp.45610.4.4 Local APIC Status and Locationp.45710.4.5 Relocating the Local APIC Registersp.45810.4.6 Local APIC IDp.45810.4.7 Local APIC Statep.45910.4.7.1 Local APIC State After Power-Up or Resetp.46010.4.7.2 Local APIC State After It Has Been Software Disabledp.46010.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)p.46110.4.7.4 Local APIC State After It Receives an INIT-Deassert IPIp.46110.4.8 Local APIC Version Registerp.46110.5 Extended XAPIC (x2APIC)p.46210.5.1 DETECTING AND ENABLING x2APICp.46210.5.1.1 Instructions to Access APIC Registersp.46310.5.1.2 APIC Register Address Spacep.46410.5.1.3 Reserved Bit Checkingp.46710.5.2 x2APIC Register Availabilityp.46810.5.3 MSR Access in x2APIC Modep.46810.5.4 VM-exit Controls for MSRs and x2APIC Registersp.46810.5.5 Directed EOI with x2APIC Modep.46910.5.6 x2APIC State Transitionsp.47010.5.6.1 x2APIC Statesp.470x2APIC After RESETp.472x2APIC Transitions From x2APIC Modep.473x2APIC Transitions From Disabled Modep.473State Changes From xAPIC Mode to x2APIC Modep.47310.5.7 System Software Transitionsp.47310.5.8 CPUID Extensions And Topology Enumerationp.47410.5.8.1 Consistency of APIC IDs and CPUIDp.47510.6 Handling Local Interruptsp.47610.6.1 Local Vector Tablep.47610.6.2 Valid Interrupt Vectorsp.47910.6.3 Error Handlingp.48010.6.3.1 x2APIC Differences in Error Handlingp.48110.6.4 APIC Timerp.48210.6.5 Local Interrupt Acceptancep.48410.7 Issuing Interprocessor Interruptsp.48410.7.1 Interrupt Command Register (ICR)p.48410.7.1.1 ICR Operation in x2APIC Modep.49010.7.2 Determining IPI Destinationp.49210.7.2.1 Physical Destination Modep.49210.7.2.2 Logical Destination Modep.49310.7.2.3 Logical Destination Mode in x2APIC Modep.49510.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC IDp.49610.7.2.5 Broadcast/Self Delivery Modep.49710.7.2.6 Lowest Priority Delivery Modep.49710.7.3 IPI Delivery and Acceptancep.49810.7.4 SELF IPI Registerp.49810.8 System and APIC Bus Arbitrationp.49910.9 Handling Interruptsp.50010.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processorsp.50010.9.2 Interrupt Handling with the P6 Family and Pentium Processorsp.50110.9.3 Interrupt, Task, and Processor Priorityp.50310.9.3.1 Task and Processor Prioritiesp.50410.9.4 Interrupt Acceptance for Fixed Interruptsp.50510.9.5 Signaling Interrupt Servicing Completionp.50710.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Modep.50710.9.6 Task Priority in IA-32e Modep.50710.9.6.1 Interaction of Task Priorities between CR8 and APICp.50810.10 Spurious Interruptp.50910.11 APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors)p.51010.11.1 Bus Message Formatsp.51110.12 Message Signalled Interruptsp.51110.12.1 Message Address Register Formatp.51210.12.2 Message Data Register Formatp.513Chapter 11 Memory Cache Controlp.51511.1 Internal Caches, TLBs, and Buffersp.51511.2 Caching Terminologyp.52111.3 Methods of Caching Availablep.52211.3.1 Buffering of Write Combining Memory Locationsp.52511.3.2 Choosing a Memory Typep.52611.3.3 Code Fetches in Uncacheable Memoryp.52711.4 Cache Control Protocolp.52711.5 Cache Controlp.52811.5.1 Cache Control Registers and Bitsp.52911.5.2 Precedence of Cache Controlsp.53411.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processorsp.53411.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Familiesp.53611.5.2.3 Writing Values Across Pages with Different Memory Typesp.53711.5.3 Preventing Cachingp.53811.5.4 Disabling and Enabling the L3 Cachep.53911.5.5 Cache Management Instructionsp.53911.5.6 L1 Data Cache Context Modep.54011.5.6.1 Adaptive Modep.54011.5.6.2 Shared Modep.54011.6 Self-Modifying Codep.54111.7 Implicit Caching (Pentium 4, Intel Xeon, and P6 Family Processors)p.54111.8 Explicit Cachingp.54211.9 Invalidating the Translation Lookaside Buffers (TLBs)p.54311.10 Store Bufferp.54311.11 Memory Type Range Registers (MTRRs)p.54411.11.1 MTRR Feature Identificationp.54611.11.2 Setting Memory Ranges with MTRRsp.54711.11.2.1 IA32_MTRR_DEF_TYPE MSRp.54711.11.2.2 Fixed Range MTRRsp.54811.11.2.3 Variable Range MTRRsp.54811.11.2.4 System-Management Range Register Interfacep.55111.11.3 Example Base and Mask Calculationsp.55211.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Supportp.55411.11.4 Range Size and Alignment Requirementp.55511.11.4.1 MTRR Precedencesp.55511.11.5 MTRR Initializationp.55511.11.6 Remapping Memory Typesp.55611.11.7 MTRR Maintenance Programming Interfacep.55611.11.7.1 MemTypeGet() Functionp.55611.11.7.2 MemTypeSet() Functionp.55811.11.8 MTRR Considerations in MP Systemsp.56011.11.9 Large Page Size Considerationsp.56111.12 Page Attribute Table (PAT)p.56211.12.1 Detecting Support for the PAT Featurep.56211.12.2 IA32_PAT MSRp.56311.12.3 Selecting a Memory Type from the PATp.56411.12.4 Programming the PATp.56411.12.5 PAT Compatibility with Earlier IA-32 Processorsp.566Chapter 12 Intel® MMX™ Technology System Programmingp.56712.1 Emulation of the MMX Instruction Setp.56712.2 The MMX State and MMX Register Aliasingp.56712.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Wordp.56912.3 Saving and Restoring the MMX State and Registersp.57012.4 Saving MMX State on Task or Context Switchesp.57112.5 EXCEPTIONS That Can Occur When Executing MMX Instructionsp.57112.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptionsp.57212.6 Debugging MMX Codep.572Chapter 13 System Programming For Instruction Set Extensions And Processor Extended Statesp.57513.1 Providing Operating System Support for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57513.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57613.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Supportp.57613.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructionsp.57713.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.57713.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructionsp.57913.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)p.58113.1.6.1 Numeric Error flag and IGNNE#p.58213.2 Emulation of SSE/SSE2/SSE3/SSSE3/SSE4 Extensionsp.58213.3 Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 Statep.58213.4 Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switchesp.58313.5 Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switchesp.58313.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 Statep.58413.6 XSAVE/XRSTOR and Processor Extended state managementp.58613.6.1 XSAVE Headerp.58713.7 Interoperability of XSAVE/XRSTOR and FXSAVE/FXRSTORp.58913.8 Detection, Enumeration, Enabling Processor Extended State Supportp.59113.8.1 Application Programming Model and Processor Extended Statesp.592Chapter 14 Power and Thermal Managementp.59514.1 Enhanced Intel Speedstep® Technologyp.59514.1.1 Software Interface For Initiating Performance State Transitionsp.59514.2 P-State Hardware Coordinationp.59614.3 System Software Considerations and Opportunistic processor Performance operationp.59814.3.1 Intel Dynamic Accelerationp.59814.3.2 System Software Interfaces for Opportunistic Processor Performance Operationp.59814.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operationp.59914.3.2.2 OS Control of Opportunistic Processor Performance Operationp.59914.3.2.3 Required Changes to OS Power Management P-state Policyp.60014.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)p.60114.3.3 Intel Turbo Boost Technologyp.60214.3.4 Performance and Energy Bias Hint supportp.60214.4 MWAIT Extensions for Advanced Power Managementp.60314.5 Thermal Monitoring and Protectionp.60414.5.1 Catastrophic Shutdown Detectorp.60614.5.2 Thermal Monitorp.60614.5.2.1 Thermal Monitor 1p.60614.5.2.2 Thermal Monitor 2p.60614.5.2.3 Two Methods for Enabling TM2p.60714.5.2.4 Performance State Transitions and Thermal Monitoringp.60814.5.2.5 Thermal Status Informationp.60814.5.2.6 Adaptive Thermal Monitorp.61014.5.3 Software Controlled Clock Modulationp.61014.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilitiesp.61214.5.5 On Die Digital Thermal Sensorsp.61214.5.5.1 Digital Thermal Sensor Enumerationp.61214.5.5.2 Reading the Digital Sensorp.613Chapter 15 Machine-Check Architecturep.61715.1 Machine-Check Architecturep.61715.2 Compatibility with Pentium Processorp.61815.3 Machine-Check MSRsp.61815.3.1 Machine-Check Global Control MSRsp.61915.3.1.1 IA32_MCG_CAP MSRp.61915.3.1.2 IA32_MCG_STATUS MSRp.62115.3.1.3 IA32_MCG_CTL MSRp.62215.3.2 Error-Reporting Register Banksp.62215.3.2.1 IA32_MCi_CTL MSRsp.62215.3.2.2 IA32_MCi_STATUS MSRSp.62315.3.2.3 IA32_MCi_ADDR MSRsp.62715.3.2.4 IA32_MCi_MISC MSRsp.62815.3.2.5 IA32_MCi_CTL2 MSRsp.62915.3.2.6 IA32_MCG Extended Machine Check State MSRsp.63115.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecturep.63315.4 Enhanced Cache Error reportingp.63415.5 Corrected Machine Check Error Interruptp.63415.5.1 CMCI Local APIC Interfacep.63515.5.2 System Software Recommendation for Managing CMCI and Machine Check Resourcesp.63715.5.2.1 CMCI Initializationp.63715.5.2.2 CMCI Threshold Managementp.63815.5.2.3 CMCI Interrupt Handlerp.63915.6 Recovery of Uncorrected Recoverable (UCR) Errorsp.63915.6.1 Detection of Software Error Recovery Supportp.64015.6.2 UCR Error Reporting and Loggingp.64015.6.3 UCR Error Classificationp.64115.6.4 UCR Error Overwrite Rulesp.64315.7 Machine-Check Availabilityp.64415.8 Machine-Check Initializationp.64415.9 Interpreting the MCA Error Codesp.64515.9.1 Simple Error Codesp.64615.9.2 Compound Error Codesp.64715.9.2.1 Correction Report Filtering (F) Bitp.64715.9.2.2 Transaction Type (TT) Sub-Fieldp.64815.9.2.3 Level (LL) Sub-Fieldp.64815.9.2.4 Request (RRRR) Sub-Fieldp.64815.9.2.5 Bus and Interconnect Errorsp.64915.9.2.6 Memory Controller Errorsp.65015.9.3 Architecturally Defined UCR Errorsp.65015.9.3.1 Architecturally Defined SRAO Errorsp.65015.9.3.2 Architecturally Defined SRAR Errorsp.65215.9.4 Multiple MCA Errorsp.65415.9.5 Machine-Check Error Codes Interpretationp.65515.10 Guidelines for Writing Machine-Check Softwarep.65515.10.1 Machine-Check Exception Handlerp.65615.10.2 Pentium Processor Machine-Check Exception Handlingp.65715.10.3 Logging Correctable Machine-Check Errorsp.65815.10.4 Machine-Check Software Handler Guidelines for Error Recoveryp.66015.10.4.1 Machine-Check Exception Handler for Error Recoveryp.66015.10.4.2 Corrected Machine-Check Handler for Error Recoveryp.666Chapter 16 Debugging, Profiling Branches and TimeStamp Counterp.66916.1 Overview of Debug Support Facilitiesp.66916.2 Debug Registersp.67016.2.1 Debug Address Registers (DR0-DR3)p.67216.2.2 Debug Registers DR4 and DR5p.67216.2.3 Debug Status Register (DR6)p.67216.2.4 Debug Control Register (DR7)p.67316.2.5 Breakpoint Field Recognitionp.67416.2.6 Debug Registers and Intel® 64 Processorsp.67616.3 Debug Exceptionsp.67716.3.1 Debug Exception (#DB)-Interrupt Vector 1p.67716.3.1.1 Instruction-Breakpoint Exception Conditionp.67816.3.1.2 Data Memory and I/O Breakpoint Exception Conditionsp.68016.3.1.3 General-Detect Exception Conditionp.68016.3.1.4 Single-Step Exception Conditionp.68016.3.1.5 Task-Switch Exception Conditionp.68116.3.2 Breakpoint Exception (#BP)-Interrupt Vector 3p.68116.4 Last Branch, Interrupt, and Exception Recording Overviewp.68216.4.1 IA32_DEBUGCTL MSRp.68216.4.2 Monitoring Branches, Exceptions, and Interruptsp.68416.4.3 Single-Stepping on Branches, Exceptions, and Interruptsp.68416.4.4 Branch Trace Messagesp.68516.4.5 Branch Trace Store (BTS)p.68516.4.6 CPL-Qualified Branch Trace Mechanismp.68616.4.7 Freezing LBR and Performance Counters on PMIp.68616.4.8 LBR Stackp.68716.4.8.1 LBR Stack and Intel® 64 Processorsp.68816.4.8.2 LBR Stack and IA-32 Processorsp.68816.4.8.3 Last Exception Records and Intel 64 Architecturep.68916.4.9 BTS and DS Save Areap.68916.4.9.1 DS Save Area and IA-32e Mode Operationp.69316.4.9.2 Setting Up the DS Save Areap.69616.4.9.3 Setting Up the BTS Bufferp.69716.4.9.4 Setting Up CPL-Qualified BTSp.69816.4.9.5 Writing the DS Interrupt Service Routinep.69916.5 Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)p.70016.5.1 LBR Stackp.70116.6 Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)p.70116.6.1 LBR Stackp.70216.6.2 Filtering of Last Branch Recordsp.70316.7 Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)p.70416.7.1 MSR_DEBUGCTLA MSRp.70516.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecturep.70616.7.3 Last Exception Recordsp.70816.8 Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)p.70916.9 Last Branch, Interrupt, and Exception Recording (Pentium M Processors)p.71116.10 Last Branch, Interrupt, and Exception Recording (P6 Family Processors)p.71316.10.1 DEBUGCTLMSR Registerp.71316.10.2 Last Branch and Last Exception MSRsp.71416.10.3 Monitoring Branches, Exceptions, and Interruptsp.71516.11 Time-Stamp Counterp.71616.11.1 Invariant TSCp.71716.11.2 IA32_TSC_AUX Register and RDTSCP Supportp.718Chapter 17 8086 Emulationp.71917.1 Real-Address Modep.71917.1.1 Address Translation in Real-Address Modep.72117.1.2 Registers Supported in Real-Address Modep.72217.1.3 Instructions Supported in Real-Address Modep.72217.1.4 Interrupt and Exception Handlingp.72417.2 Virtual-8086 Modep.72617.2.1 Enabling Virtual-8086 Modep.72717.2.2 Structure of a Virtual-8086 Taskp.72717.2.3 Paging of Virtual-8086 Tasksp.72817.2.4 Protection within a Virtual-8086 Taskp.72917.2.5 Entering Virtual-8086 Modep.72917.2.6 Leaving Virtual-8086 Modep.73217.2.7 Sensitive Instructionsp.73317.2.8 Virtual-8086 Mode I/Op.73317.2.8.1 I/O-Port-Mapped I/Op.73317.2.8.2 Memory-Mapped I/Op.73417.2.8.3 Special I/O Buffersp.73417.3 Interrupt and Exception Handling in Virtual-8086 Modep.73417.3.1 Class 1-Hardware Interrupt and Exception Handling in Virtual-8086 Modep.73617.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gatep.73617.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handlerp.73817.3.1.3 Handling an Interrupt or Exception Through a Task Gatep.73917.3.2 Class 2-Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanismp.74017.3.3 Class 3-Software Interrupt Handling in Virtual-8086 Modep.74217.3.3.1 Method 1: Software Interrupt Handlingp.74517.3.3.2 Methods 2 and 3: Software Interrupt Handlingp.74617.3.3.3 Method 4: Software Interrupt Handlingp.74617.3.3.4 Method 5: Software Interrupt Handlingp.74617.3.3.5 Method 6: Software Interrupt Handlingp.74717.4 Protected-Mode Virtual Interruptsp.748Chapter 18 Mixing 16-Bit and 32-Bit Codep.75118.1 Defining 16-Bit and 32-Bit Program Modulesp.75218.2 Mixing 16-Bit and 32-Bit Operations Within a Code Segmentp.75218.3 Sharing Data Among Mixed-Size Code Segmentsp.75418.4 Transferring Control Among Mixed-Size Code Segmentsp.75418.4.1 Code-Segment Pointer Sizep.75518.4.2 Stack Management for Control Transferp.75518.4.2.1 Controlling the Operand-Size Attribute For a Callp.75718.4.2.2 Passing Parameters With a Gatep.75818.4.3 Interrupt Control Transfersp.75818.4.4 Parameter Translationp.75818.4.5 Writing Interface Proceduresp.759Chapter 19 Architecture Compatibilityp.76119.1 Processor Families and Categoriesp.76119.2 Reserved Bitsp.76219.3 Enabling New Functions and Modesp.76219.4 Detecting the Presence of New Features Through Softwarep.76319.5 Intel MMX Technologyp.76319.6 Streaming SIMD Extensions (SSE)p.76319.7 Streaming SIMD Extensions 2 (SSE2)p.76419.8 Streaming SIMD Extensions 3 (SSE3)p.76419.9 Additional Streaming SIMD Extensionsp.76419.10 Intel Hyper-Threading Technologyp.76519.11 Multi-Core Technologyp.76519.12 Specific Features of Dual-Core Processorp.76519.13 New Instructions In the Pentium and Later IA-32 Processorsp.76519.13.1 Instructions Added Prior to the Pentium Processorp.76619.14 Obsolete Instructionsp.76719.15 Undefined Opcodesp.76719.16 New Flags in the EFLAGS Registerp.76719.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processorsp.76819.17 Stack Operationsp.76819.17.1 PUSH SPp.76819.17.2 EFLAGS Pushed on the Stackp.76919.18 x87 FPUp.76919.18.1 Control Register CR0 Flagsp.76919.18.2 x87 FPU Status Wordp.77019.18.2.1 Condition Code Flags (C0 through C3)p.77019.18.2.2 Stack Fault Flagp.77119.18.3 x87 FPU Control Wordp.77119.18.4 x87 FPU Tag Wordp.77119.18.5 Data Typesp.77219.18.5.1 NaNsp.77219.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formatsp.77219.18.6 Floating-Point Exceptionsp.77319.18.6.1 Denormal Operand Exception (#D)p.77319.18.6.2 Numeric Overflow Exception (#O)p.77319.18.6.3 Numeric Underflow Exception (#U)p.77419.18.6.4 Exception Precedencep.77419.18.6.5 CS and EIP For FPU Exceptionsp.77419.18.6.6 FPU Error Signalsp.77419.18.6.7 Assertion of the FERR# Pinp.77519.18.6.8 Invalid Operation Exception On Denormalsp.77519.18.6.9 Alignment Check Exceptions (#AC)p.77619.18.6.10 Segment Not Present Exception During FLDENVp.77619.18.6.11 Device Not Available Exception (#NM)p.77619.18.6.12 Coprocessor Segment Overrun Exceptionp.77619.18.6.13 General Protection Exception (#GP)p.77619.18.6.14 Floating-Point Error Exception (#MF)p.77619.18.7 Changes to Floating-Point Instructionsp.77719.18.7.1 FDIV, FPREM, and FSQRT Instructionsp.77719.18.7.2 FSCALE Instructionp.77719.18.7.3 FPREM1 Instructionp.77719.18.7.4 FPREM Instructionp.77719.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructionsp.77719.18.7.6 FPTAN Instructionp.77819.18.7.7 Stack Overflowp.77819.18.7.8 FSIN, FCOS, and FSINCOS Instructionsp.77819.18.7.9 FPATAN Instructionp.77819.18.7.10 F2XM1 Instructionp.77819.18.7.11 FLD Instructionp.77819.18.7.12 FXTRACT Instructionp.77919.18.7.13 Load Constant Instructionsp.77919.18.7.14 FSETPM Instructionp.77919.18.7.15 FXAM Instructionp.78019.18.7.16 FSAVE and FSTENV Instructionsp.78019.18.8 Transcendental Instructionsp.78019.18.9 Obsolete Instructionsp.78019.18.10 WAIT/FWAIT Prefix Differencesp.78119.18.11 Operands Split Across Segments and/or Pagesp.78119.18.12 FPU Instruction Synchronizationp.78119.19 Serializing Instructionsp.78119.20 FPU and Math Coprocessor Initializationp.78219.20.1 Intel® 387 and Intel® 287 Math Coprocessor Initializationp.78219.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initializationp.78219.21 Control Registersp.78419.22 Memory Management Facilitiesp.78519.22.1 New Memory Management Control Flagsp.78519.22.1.1 Physical Memory Addressing Extensionp.78519.22.1.2 Global Pagesp.78619.22.1.3 Larger Page Sizesp.78619.22.2 CD and NW Cache Control Flagsp.78619.22.3 Descriptor Types and Contentsp.78619.22.4 Changes in Segment Descriptor Loadsp.78719.23 Debug Facilitiesp.78719.23.1 Differences in Debug Register DR6p.78719.23.2 Differences in Debug Register DR7p.78719.23.3 Debug Registers DR4 and DR5p.78719.24 Recognition of Breakpointsp.78819.25 Exceptions and/or Exception Conditionsp.78819.25.1 Machine-Check Architecturep.79019.25.2 Priority OF Exceptionsp.79019.26 Interruptsp.79019.26.1 Interrupt Propagation Delayp.79019.26.2 NMI Interruptsp.79019.26.3 IDT Limitp.79119.27 Advanced Programmable Interrupt Controller (APIC)p.79119.27.1 Software Visible Differences Between the Local APIC and the 82489DXp.79119.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processorsp.79219.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processorsp.79219.28 Task Switching and TSsp.79219.28.1 P6 Family and Pentium Processor TSSp.79319.28.2 TSS Selector Writesp.79319.28.3 Order of Reads/Writes to the TSSp.79319.28.4 Using A 16-Bit TSS with 32-Bit Constructsp.79319.28.5 Differences in I/O Map Base Addressesp.79319.29 Cache Managementp.79419.29.1 Self-Modifying Code with Cache Enabledp.79519.29.2 Disabling the L3 Cachep.79619.30 Pagingp.79619.30.1 Large Pagesp.79619.30.2 PCD and PWT Flagsp.79619.30.3 Enabling and Disabling Pagingp.79719.31 Stack Operationsp.79719.31.1 Selector Pushes and Popsp.79719.31.2 Error Code Pushesp.79819.31.3 Fault Handling Effects on the Stackp.79819.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gatep.79819.32 Mixing 16and 32-Bit Segmentsp.79919.33 Segment and Address Wraparoundp.79919.33.1 Segment Wraparoundp.80019.34 Store Buffers and Memory Orderingp.80019.35 Bus Lockingp.80219.36 Bus Holdp.80219.37 Model-Specific Extensions to the IA-32p.80219.37.1 Model-Specific Registersp.80319.37.2 RDMSR and WRMSR Instructionsp.80319.37.3 Memory Type Range Registersp.80319.37.4 Machine-Check Exception and Architecturep.80419.37.5 Performance-Monitoring Countersp.80419.38 Two Ways to Run Intel 286 Processor Tasksp.805
Page 29 of the Intel 253668-032US user manual — PAGE
Page 29 · click to enlarge
Page 29

CONTENTS

PAGE

30.10.3 Incrementing the Time-Stamp Counter 30-77 30.10.4 Non-Halted Reference Clockticks 30-77 30.10.5 Cycle Counting and Opportunistic Processor Operation 30-77 30.11 PERFORMANCE MONITORING, BRANCH PROFILING AND SYSTEM EVENTS 30-78 30.12 PERFORMANCE MONITORING AND DUAL-CORE TECHNOLOGY 30-79 30.13 PERFORMANCE MONITORING ON 64-BIT INTEL XEON PROCESSOR MP WITH UP TO 8- MBYTE L3 CACHE 30-79 30.14 PERFORMANCE MONITORING ON L3 AND CACHING BUS CONTROLLER SUB-SYSTEMS . 30- 84 30.14.1 Overview of Performance Monitoring with L3/Caching Bus Controller 30-86 30.14.2 GBSQ Event Interface 30-87 30.14.3 GSNPQ Event Interface 30-89 30.14.4 FSB Event Interface 30-91 30.14.4.1 FSB Sub-Event Mask Interface 30-92 30.14.5 Common Event Control Interface 30-93 30.15 PERFORMANCE MONITORING (P6 FAMILY PROCESSOR) 30-93 30.15.1 PerfEvtSel0 and PerfEvtSel1 MSRs 30-94 30.15.2 PerfCtr0 and PerfCtr1 MSRs 30-96 30.15.3 Starting and Stopping the Performance-Monitoring Counters 30-96 30.15.4 Event and Time-Stamp Monitoring Software 30-97 30.15.5 Monitoring Counter Overflow 30-97 30.16 PERFORMANCE MONITORING (PENTIUM PROCESSORS) 30-98 30.16.1 Control and Event Select Register (CESR) 30-98 30.16.2 Use of the Performance-Monitoring Pins 30-100 30.16.3 Events Counted 30-100

APPENDIX A PERFORMANCE-MONITORING EVENTS A.1 ARCHITECTURAL PERFORMANCE-MONITORING EVENTS A-1 A.2 PERFORMANCE MONITORING EVENTS FOR INTEL® CORE™I7 PROCESSOR FAMILY. . A-2 A.3 PERFORMANCE MONITORING EVENTS FOR NEXT GENERATION INTEL® PROCESSOR (CODENAMED WESTMERE) A-57 A.4 PERFORMANCE MONITORING EVENTS FOR INTEL® XEON® PROCESSOR 5200, 5400 SERIES AND INTEL® CORE™2 EXTREME PROCESSORS QX 9000 SERIES A-87 A.5 PERFORMANCE MONITORING EVENTS FOR INTEL® XEON® PROCESSOR 3000, 3200, 5100, 5300 SERIES AND INTEL® CORE™2 DUO PROCESSORS A-88 A.6 PERFORMANCE MONITORING EVENTS FOR INTEL® ATOM™ PROCESSORS A-133 A.7 PERFORMANCE MONITORING EVENTS FOR INTEL® CORE™ SOLO AND INTEL® CORE™

DUO PROCESSORS A-156 A.8 PENTIUM 4 AND INTEL XEON PROCESSOR PERFORMANCE-MONITORING EVENTS. . . A-165 A.9 PERFORMANCE MONITORING EVENTS FOR INTEL® PENTIUM® M PROCESSORS A-214 A.10 P6 FAMILY PROCESSOR PERFORMANCE-MONITORING EVENTS A-217 A.11 PENTIUM PROCESSOR PERFORMANCE- MONITORING EVENTS A-235

APPENDIX B MODEL-SPECIFIC REGISTERS (MSRS) B.1 ARCHITECTURAL MSRS B-2 B.2 MSRS IN THE INTEL® CORE™ 2 PROCESSOR FAMILY B-37

Vol. 3A xxix

Page 30 of the Intel 253668-032US user manual — PAGE
Page 30 · click to enlarge
Page 30

CONTENTS

PAGE

B.3 MSRS IN THE INTEL® ATOM™ PROCESSOR FAMILY B-58 B.4 MSRS IN THE INTEL® MICROARCHITECTURE (NEHALEM) B-73 B.5 MSRS IN THE PENTIUM® 4 AND INTEL® XEON® PROCESSORS B-96 B.5.1 MSRs Unique to Intel Xeon Processor MP with L3 Cache B-136 B.6 MSRS IN INTEL® CORE™ SOLO AND INTEL® CORE™ DUO PROCESSORS B-139 B.7 MSRS IN THE PENTIUM M PROCESSOR B-152 B.8 MSRS IN THE P6 FAMILY PROCESSORS B-162 B.9 MSRS IN PENTIUM PROCESSORS B-174

APPENDIX C MP INITIALIZATION FOR P6 FAMILY PROCESSORS C.1 OVERVIEW OF THE MP INITIALIZATION PROCESS FOR P6 FAMILY PROCESSORS C-1 C.2 MP INITIALIZATION PROTOCOL ALGORITHM C-2 C.2.1 Error Detection and Handling During the MP Initialization Protocol C-4

APPENDIX D PROGRAMMING THE LINT0 AND LINT1 INPUTS D.1 CONSTANTS D-1 D.2 LINT[0:1] PINS PROGRAMMING PROCEDURE D-1

APPENDIX E INTERPRETING MACHINE-CHECK ERROR CODES E.1 INCREMENTAL DECODING INFORMATION: PROCESSOR FAMILY 06H MACHINE ERROR CODES FOR MACHINE CHECK E-1 E.2 INCREMENTAL DECODING INFORMATION: INTEL CORE 2 PROCESSOR FAMILY MACHINE ERROR CODES FOR MACHINE CHECK E-5 E.2.1 Model-Specific Machine Check Error Codes for Intel Xeon Processor 7400 Series E-9 E.2.1.1 Processor Machine Check Status Register Incremental MCA Error Code Definition E-9 E.2.2 Intel Xeon Processor 7400 Model Specific Error Code Field E-10 E.2.2.1 Processor Model Specific Error Code Field Type B: Bus and Interconnect Error E-10 E.2.2.2 Processor Model Specific Error Code Field Type C: Cache Bus Controller Error E-10 E.3 INCREMENTAL DECODING INFORMATION: PROCESSOR FAMILY WITH CPUID DISPLAYFAMILY_DISPLAYMODEL SIGNATURE 06_1AH, MACHINE ERROR CODES FOR MACHINE CHECK E-11 E.3.1 QPI Machine Check Errors E-12 E.3.2 Internal Machine Check Errors E-13 E.3.3 Memory Controller Errors E-14 E.4 INCREMENTAL DECODING INFORMATION: PROCESSOR FAMILY 0FH MACHINE ERROR CODES FOR MACHINE CHECK E-15 E.4.1 Model-Specific Machine Check Error Codes for Intel Xeon Processor MP 7100 Series. . E- 16 E.4.1.1 Processor Machine Check Status Register MCA Error Code Definition E-18 E.4.2 Other_Info Field (all MCA Error Types) E-19

xxx Vol. 3A

Page 31 of the Intel 253668-032US user manual — PAGE
Page 31 · click to enlarge
Page 31

CONTENTS

PAGE

E.4.3 Processor Model Specific Error Code Field E-21 E.4.3.1 MCA Error Type A: L3 ErrorE-21 E.4.3.2 Processor Model Specific Error Code Field Type B: Bus and Interconnect Error E-21 E.4.3.3 Processor Model Specific Error Code Field Type C: Cache Bus Controller Error E-23

APPENDIX F APIC BUS MESSAGE FORMATS F.1 BUS MESSAGE FORMATS F-1 F.2 EOI MESSAGE F-1 F.2.1 Short Message F-2 F.2.2 Non-focused Lowest Priority Message F-3 F.2.3 APIC Bus Status Cycles F-5

APPENDIX G VMX CAPABILITY REPORTING FACILITY G.1 BASIC VMX INFORMATION G-1 G.2 RESERVED CONTROLS AND DEFAULT SETTINGS G-2 G.3 VM-EXECUTION CONTROLS G-3 G.3.1 Pin-Based VM-Execution Controls G-3 G.3.2 Primary Processor-Based VM-Execution Controls G-4 G.3.3 Secondary Processor-Based VM-Execution Controls G-5 G.4 VM-EXIT CONTROLS G-6 G.5 VM-ENTRY CONTROLS G-7 G.6 MISCELLANEOUS DATA G-7 G.7 VMX-FIXED BITS IN CR0 G-8 G.8 VMX-FIXED BITS IN CR4 G-9 G.9 VMCS ENUMERATION G-9 G.10 VPID AND EPT CAPABILITIES G-9

APPENDIX H FIELD ENCODING IN VMCS H.1 16-BIT FIELDS H-1 H.1.1 16-Bit Control Field H-1 H.1.2 16-Bit Guest-State Fields H-1 H.1.3 16-Bit Host-State Fields H-2 H.2 64-BIT FIELDS H-2 H.2.1 64-Bit Control Fields H-3 H.2.2 64-Bit Read-Only Data Field H-4 H.2.3 64-Bit Guest-State Fields H-4 H.2.4 64-Bit Host-State Fields H-5 H.3 32-BIT FIELDS H-6 H.3.1 32-Bit Control Fields H-6 H.3.2 32-Bit Read-Only Data Fields H-7 H.3.3 32-Bit Guest-State Fields H-7 H.3.4 32-Bit Host-State Field H-9 H.4 NATURAL-WIDTH FIELDS H-9 H.4.1 Natural-Width Control Fields H-9

Vol. 3A xxxi

Page 32 of the Intel 253668-032US user manual — APPENDIX I VMX BASIC EXIT REASONS
Page 32 · click to enlarge
Page 32

CONTENTS

PAGE

H.4.2 Natural-Width Read-Only Data Fields H-10 H.4.3 Natural-Width Guest-State Fields H-10 H.4.4 Natural-Width Host-State Fields H-11

APPENDIX I VMX BASIC EXIT REASONS

xxxii Vol. 3A

Page 33 of the Intel 253668-032US user manual — PAGE FIGURES
Page 33 · click to enlarge
Page 33

CONTENTS

PAGE FIGURES

Figure 1-1. Bit and Byte Order 1-7 Figure 1-2. Syntax for CPUID, CR, and MSR Data Presentation 1-10 Figure 2-1. IA-32 System-Level Registers and Data Structures 2-3 Figure 2-2. System-Level Registers and Data Structures in IA-32e Mode 2-4 Figure 2-3. Transitions Among the Processor’s Operating Modes 2-11 Figure 2-4. System Flags in the EFLAGS Register 2-13 Figure 2-5. Memory Management Registers 2-16 Figure 2-6. Control Registers 2-19 Figure 2-7. XFEATURE_ENABLED_MASK Register (XCR0) 2-26 Figure 3-1. Segmentation and Paging 3-2 Figure 3-2. Flat Model 3-4 Figure 3-3. Protected Flat Model 3-4 Figure 3-4. Multi-Segment Model 3-6 Figure 3-5. Logical Address to Linear Address Translation 3-9 Figure 3-6. Segment Selector 3-10 Figure 3-7. Segment Registers 3-11 Figure 3-8. Segment Descriptor 3-13 Figure 3-9. Segment Descriptor When Segment-Present Flag Is Clear 3-15 Figure 3-10. Global and Local Descriptor Tables 3-20 Figure 3-11. Pseudo-Descriptor Formats 3-22 Figure 4-1. Enabling and Changing Paging Modes 4-4 Figure 4-2. Linear-Address Translation to a 4-KByte Page using 32-Bit Paging 4-10 Figure 4-3. Linear-Address Translation to a 4-MByte Page using 32-Bit Paging 4-11 Figure 4-4. Formats of CR3 and Paging-Structure Entries with 32-Bit Paging 4-15 Figure 4-5. Linear-Address Translation to a 4-KByte Page using PAE Paging 4-18 Figure 4-6. Linear-Address Translation to a 2-MByte Page using PAE Paging 4-18 Figure 4-7. Formats of CR3 and Paging-Structure Entries with PAE Paging 4-23 Figure 4-8. Linear-Address Translation to a 4-KByte Page using IA-32e Paging 4-25 Figure 4-9. Linear-Address Translation to a 2-MByte Page using IA-32e Paging 4-26 Figure 4-10. Formats of CR3 and Paging-Structure Entries with IA-32e Paging 4-33 Figure 4-11. Page-Fault Error Code 4-35 Figure 4-12. Memory Management Convention That Assigns a Page Table to Each Segment 4-53 Figure 5-1. Descriptor Fields Used for Protection 5-4 Figure 5-2. Descriptor Fields with Flags used in IA-32e Mode 5-6 Figure 5-3. Protection Rings 5-10 Figure 5-4. Privilege Check for Data Access 5-12 Figure 5-5. Examples of Accessing Data Segments From Various Privilege Levels 5-13 Figure 5-6. Privilege Check for Control Transfer Without Using a Gate 5-15 Figure 5-7. Examples of Accessing Conforming and Nonconforming Code Segments From Various Privilege Levels 5-17 Figure 5-8. Call-Gate Descriptor 5-19 Figure 5-9. Call-Gate Descriptor in IA-32e Mode 5-21 Figure 5-10. Call-Gate Mechanism 5-22 Figure 5-11. Privilege Check for Control Transfer with Call Gate 5-23 Figure 5-12. Example of Accessing Call Gates At Various Privilege Levels 5-25 Figure 5-13. Stack Switching During an Interprivilege-Level Call 5-27 Figure 5-14. MSRs Used by SYSCALL and SYSRET 5-33 Figure 5-15. Use of RPL to Weaken Privilege Level of Called Procedure 5-38 Figure 6-1. Relationship of the IDTR and IDT 6-14

Vol. 3A xxxiii

Page 34 of the Intel 253668-032US user manual — PAGE
Page 34 · click to enlarge
Page 34

CONTENTS

PAGE

Figure 6-2. IDT Gate Descriptors 6-15 Figure 6-3. Interrupt Procedure Call 6-16 Figure 6-4. Stack Usage on Transfers to Interrupt and Exception-Handling Routines 6-18 Figure 6-5. Interrupt Task Switch 6-21 Figure 6-6. Error Code 6-22 Figure 6-7. 64-Bit IDT Gate Descriptors 6-23 Figure 6-8. IA-32e Mode Stack Usage After Privilege Level Change 6-26 Figure 6-9. Page-Fault Error Code 6-55 Figure 7-1. Structure of a Task 7-2 Figure 7-2. 32-Bit Task-State Segment (TSS) 7-5 Figure 7-3. TSS Descriptor 7-7 Figure 7-4. Format of TSS and LDT Descriptors in 64-bit Mode 7-9 Figure 7-5. Task Register 7-10 Figure 7-6. Task-Gate Descriptor 7-11 Figure 7-7. Task Gates Referencing the Same Task 7-12 Figure 7-8. Nested Tasks 7-17 Figure 7-9. Overlapping Linear-to-Physical Mappings 7-20 Figure 7-10. 16-Bit TSS Format 7-22 Figure 7-11. 64-Bit TSS Format 7-24 Figure 8-1. Example of Write Ordering in Multiple-Processor Systems 8-10 Figure 8-2. Interpretation of APIC ID in Early MP Systems 8-34 Figure 8-3. Local APICs and I/O APIC in MP System Supporting Intel HT Technology 8-38 Figure 8-4. IA-32 Processor with Two Logical Processors Supporting Intel HT Technology . 8-39 Figure 8-5. Generalized Four level Interpretation of the APIC ID 8-49 Figure 8-6. Conceptual Five-level Topology and 32-bit APIC ID Composition 8-49 Figure 8-7. Topological Relationships between Hierarchical IDs in a Hypothetical MP Platform.8- 52 Figure 9-1. Contents of CR0 Register after Reset 9-5 Figure 9-2. Version Information in the EDX Register after Reset 9-5 Figure 9-3. Processor State After Reset 9-21 Figure 9-4. Constructing Temporary GDT and Switching to Protected Mode (Lines 162-172 of List File) 9-31 Figure 9-5. Moving the GDT, IDT, and TSS from ROM to RAM (Lines 196-261 of List File). . . 9-32 Figure 9-6. Task Switching (Lines 282-296 of List File) 9-33 Figure 9-7. Applying Microcode Updates 9-37 Figure 9-8. Microcode Update Write Operation Flow [1] 9-60 Figure 9-9. Microcode Update Write Operation Flow [2] 9-61 Figure 10-1. Relationship of Local APIC and I/O APIC In Single-Processor Systems 10-3 Figure 10-2. Local APICs and I/O APIC When Intel Xeon Processors Are Used in Multiple- Processor Systems 10-4 Figure 10-3. Local APICs and I/O APIC When P6 Family Processors Are Used in Multiple-Processor Systems 10-4 Figure 10-4. Local APIC Structure 10-7 Figure 10-5. IA32_APIC_BASE MSR (APIC_BASE_MSR in P6 Family) 10-12 Figure 10-6. Local APIC ID Register 10-13 Figure 10-7. Local APIC Version Register 10-16 Figure 10-8. IA32_APIC_BASE MSR Supporting x2APIC 10-17 Figure 10-9. Spurious Interrupt Vector Register (SVR) of x2APIC 10-24 Figure 10-10. Local APIC Version Register of x2APIC 10-24 Figure 10-11. Local x2APIC State Transitions with IA32_APIC_BASE, INIT, and RESET 10-26 Figure 10-12. Local Vector Table (LVT) 10-31 Figure 10-13. Error Status Register (ESR) 10-34

xxxiv Vol. 3A

Page 35 of the Intel 253668-032US user manual — PAGE
Page 35 · click to enlarge
Page 35

CONTENTS

PAGE

Figure 10-14. Error Status Register (ESR) in x2APIC Mode 10-36 Figure 10-15. Divide Configuration Register 10-37 Figure 10-16. Initial Count and Current Count Registers 10-37 Figure 10-17. Interrupt Command Register (ICR) 10-39 Figure 10-18. Interrupt Command Register (ICR) in x2APIC Mode 10-45 Figure 10-19. Logical Destination Register (LDR) 10-47 Figure 10-20. Destination Format Register (DFR) 10-48 Figure 10-21. Logical Destination Register in x2APIC Mode 10-49 Figure 10-22. Arbitration Priority Register (APR) 10-51 Figure 10-23. SELF IPI register 10-53 Figure 10-24. Interrupt Acceptance Flow Chart for the Local APIC (Pentium 4 and Intel Xeon Processors) 10-54 Figure 10-25. Interrupt Acceptance Flow Chart for the Local APIC (P6 Family and Pentium Processors) 10-56 Figure 10-26. Task Priority Register (TPR) 10-58 Figure 10-27. Processor Priority Register (PPR) 10-59 Figure 10-28. IRR, ISR and TMR Registers 10-60 Figure 10-29. EOI Register 10-61 Figure 10-30. CR8 Register 10-62 Figure 10-31. Spurious-Interrupt Vector Register (SVR) 10-64 Figure 10-32. Layout of the MSI Message Address Register 10-66 Figure 10-33. Layout of the MSI Message Data Register 10-67 Figure 11-1. Cache Structure of the Pentium 4 and Intel Xeon Processors 11-1 Figure 11-2. Cache Structure of the Intel Core i7 Processors 11-2 Figure 11-3. Cache-Control Registers and Bits Available in Intel 64 and IA-32 Processors . . 11-16 Figure 11-4. Mapping Physical Memory With MTRRs 11-31 Figure 11-5. IA32_MTRRCAP Register 11-32 Figure 11-6. IA32_MTRR_DEF_TYPE MSR 11-33 Figure 11-7. IA32_MTRR_PHYSBASEn and IA32_MTRR_PHYSMASKn Variable-Range Register Pair 11-36 Figure 11-8. IA32_SMRR_PHYSBASE and IA32_SMRR_PHYSMASK SMRR Pair 11-38 Figure 11-9. IA32_PAT MSR 11-49 Figure 12-1. Mapping of MMX Registers to Floating-Point Registers 12-2 Figure 12-2. Mapping of MMX Registers to x87 FPU Data Register Stack 12-7 Figure 13-1. Example of Saving the x87 FPU, MMX, SSE, SSE2, SSE3, and SSSE3 State During an Operating-System Controlled Task Switch 13-11 Figure 13-2. Future Layout of XSAVE/XRSTOR Area and XSTATE_BV with Five Sets of Processor State Extensions 13-14 Figure 13-3. OS Enabling of Processor Extended State Support 13-17 Figure 13-4. Application Detection of New Instruction Extensions and Processor Extended State 13-19 Figure 14-1. IA32_MPERF MSR and IA32_APERF MSR for P-state Coordination 14-2 Figure 14-2. IA32_PERF_CTL Register 14-6 Figure 14-3. Periodic Query of Activity Ratio of Opportunistic Processor Operation 14-7 Figure 14-4. IA32_ENERGY_PERF_BIAS Register 14-9 Figure 14-5. Processor Modulation Through Stop-Clock Mechanism 14-11 Figure 14-6. MSR_THERM2_CTL Register On Processors with CPUID Family/Model/Stepping Signature Encoded as 0x69n or 0x6Dn 14-13 Figure 14-7. MSR_THERM2_CTL Register for Supporting TM2 14-14 Figure 14-8. IA32_THERM_STATUS MSR 14-15 Figure 14-9. IA32_THERM_INTERRUPT MSR 14-15 Figure 14-10. IA32_CLOCK_MODULATION MSR 14-17

Vol. 3A xxxv

Page 36 of the Intel 253668-032US user manual — PAGE
Page 36 · click to enlarge
Page 36

CONTENTS

PAGE

Figure 14-11. IA32_THERM_STATUS Register 14-19 Figure 14-12. IA32_THERM_INTERRUPT Register 14-21 Figure 15-1. Machine-Check MSRs 15-3 Figure 15-2. IA32_MCG_CAP Register 15-4 Figure 15-3. IA32_MCG_STATUS Register 15-5 Figure 15-4. IA32_MCi_CTL Register 15-6 Figure 15-5. IA32_MCi_STATUS Register 15-8 Figure 15-6. IA32_MCi_ADDR MSR 15-12 Figure 15-7. UCR Support in IA32_MCi_MISC Register 15-13 Figure 15-8. IA32_MCi_CTL2 Register 15-14 Figure 15-9. CMCI Behavior 15-19 Figure 15-10. Local APIC CMCI LVT Register 15-20 Figure 16-1. Debug Registers 16-3 Figure 16-2. DR6/DR7 Layout on Processors Supporting Intel 64 Technology 16-9 Figure 16-3. IA32_DEBUGCTL MSR for Processors based on Intel Core microarchitecture 16-15 Figure 16-4. 64-bit Address Layout of LBR MSR 16-20 Figure 16-5. DS Save Area 16-23 Figure 16-6. 32-bit Branch Trace Record Format 16-24 Figure 16-7. PEBS Record Format 16-25 Figure 16-8. IA-32e Mode DS Save Area 16-26 Figure 16-9. 64-bit Branch Trace Record Format 16-27 Figure 16-10. 64-bit PEBS Record Format 16-27 Figure 16-11. IA32_DEBUGCTL MSR for Processors based on Intel microarchitecture (Nehalem) 16-34 Figure 16-12. MSR_DEBUGCTLA MSR for Pentium 4 and Intel Xeon Processors 16-38 Figure 16-13. LBR MSR Branch Record Layout for the Pentium 4 and Intel Xeon Processor Family 16-40 Figure 16-14. IA32_DEBUGCTL MSR for Intel Core Solo and Intel Core Duo Processors 16-42 Figure 16-15. LBR Branch Record Layout for the Intel Core Solo and Intel Core Duo Processor 16-43 Figure 16-16. MSR_DEBUGCTLB MSR for Pentium M Processors 16-44 Figure 16-17. LBR Branch Record Layout for the Pentium M Processor 16-45 Figure 16-18. DEBUGCTLMSR Register (P6 Family Processors) 16-46 Figure 17-1. Real-Address Mode Address Translation 17-4 Figure 17-2. Interrupt Vector Table in Real-Address Mode 17-7 Figure 17-3. Entering and Leaving Virtual-8086 Mode 17-13 Figure 17-4. Privilege Level 0 Stack After Interrupt or Exception in Virtual-8086 Mode 17-19 Figure 17-5. Software Interrupt Redirection Bit Map in TSS 17-27 Figure 18-1. Stack after Far 16- and 32-Bit Calls 18-6 Figure 19-1. I/O Map Base Address Differences 19-34 Figure 20-1. Interaction of a Virtual-Machine Monitor and Guests 20-3 Figure 25-1. Formats of EPTP and EPT Paging-Structure Entries 25-10 Figure 26-1. SMRAM Usage 26-6 Figure 26-2. SMM Revision Identifier 26-18 Figure 26-3. Auto HALT Restart Field 26-19 Figure 26-4. SMBASE Relocation Field 26-20 Figure 26-5. I/O Instruction Restart Field 26-21 Figure 27-1. VMX Transitions and States of VMCS in a Logical Processor 27-4 Figure 28-1. Virtual TLB Scheme 28-7

xxxvi Vol. 3A

Page 37 of the Intel 253668-032US user manual — PAGE
Page 37 · click to enlarge
Page 37

CONTENTS

PAGE

Figure 29-1. Host External Interrupts and Guest Virtual Interrupts 29-5 Figure 30-1. Layout of IA32_PERFEVTSELx MSRs 30-4 Figure 30-2. Layout of IA32_FIXED_CTR_CTRL MSR 30-7 Figure 30-3. Layout of IA32_PERF_GLOBAL_CTRL MSR 30-8 Figure 30-4. Layout of IA32_PERF_GLOBAL_STATUS MSR 30-9 Figure 30-5. Layout of IA32_PERF_GLOBAL_OVF_CTRL MSR 30-9 Figure 30-6. Layout of IA32_PERFEVTSELx MSRs Supporting Architectural Performance Monitoring Version 3 30-10 Figure 30-7. Layout of IA32_FIXED_CTR_CTRL MSR Supporting Architectural Performance Monitoring Version 3 30-11 Figure 30-8. Layout of Global Performance Monitoring Control MSR 30-12 Figure 30-9. Layout of MSR_PERF_FIXED_CTR_CTRL MSR 30-19 Figure 30-10. Layout of MSR_PERF_GLOBAL_CTRL MSR 30-20 Figure 30-11. Layout of MSR_PERF_GLOBAL_STATUS MSR 30-20 Figure 30-12. Layout of MSR_PERF_GLOBAL_OVF_CTRL MSR 30-21 Figure 30-13. Layout of IA32_PEBS_ENABLE MSR 30-28 Figure 30-14. PEBS Programming Environment 30-30 Figure 30-15. Layout of MSR_PEBS_LD_LAT MSR 30-34 Figure 30-16. Layout of MSR_OFFCORE_RSP_0 and MSR_OFFCORE_RSP_1 to Configure Off-core Response Events 30-35 Figure 30-17. Layout of MSR_UNCORE_PERF_GLOBAL_CTRL MSR 30-38 Figure 30-18. Layout of MSR_UNCORE_PERF_GLOBAL_STATUS MSR 30-39 Figure 30-19. Layout of MSR_UNCORE_PERF_GLOBAL_OVF_CTRL MSR 30-39 Figure 30-20. Layout of MSR_UNCORE_PERFEVTSELx MSRs 30-40 Figure 30-21. Layout of MSR_UNCORE_FIXED_CTR_CTRL MSR 30-41 Figure 30-22. Layout of MSR_UNCORE_ADDR_OPCODE_MATCH MSR 30-42 Figure 30-23. Event Selection Control Register (ESCR) for Pentium 4 and Intel Xeon Processors without Intel HT Technology Support 30-49 Figure 30-24. Performance Counter (Pentium 4 and Intel Xeon Processors) 30-51 Figure 30-25. Counter Configuration Control Register (CCCR) 30-52 Figure 30-26. Effects of Edge Filtering 30-58 Figure 30-27. Event Selection Control Register (ESCR) for the Pentium 4 Processor, Intel Xeon Processor and Intel Xeon Processor MP Supporting Hyper-Threading Technology30- 69 Figure 30-28. Counter Configuration Control Register (CCCR) 30-71 Figure 30-29. Layout of IA32_PERF_CAPABILITIES MSR 30-79 Figure 30-30. Block Diagram of 64-bit Intel Xeon Processor MP with 8-MByte L3 30-80 Figure 30-31. MSR_IFSB_IBUSQx, Addresses: 107CCH and 107CDH 30-81 Figure 30-32. MSR_IFSB_ISNPQx, Addresses: 107CEH and 107CFH 30-82 Figure 30-33. MSR_EFSB_DRDYx, Addresses: 107D0H and 107D1H 30-83 Figure 30-34. MSR_IFSB_CTL6, Address: 107D2H; MSR_IFSB_CNTR7, Address: 107D3H 30-84 Figure 30-35. Block Diagram of Intel Xeon Processor 7400 Series 30-85 Figure 30-36. Block Diagram of Intel Xeon Processor 7100 Series 30-86 Figure 30-37. MSR_EMON_L3_CTR_CTL0/1, Addresses: 107CCH/107CDH 30-88 Figure 30-38. MSR_EMON_L3_CTR_CTL2/3, Addresses: 107CEH/107CFH 30-91 Figure 30-39. MSR_EMON_L3_CTR_CTL4/5/6/7, Addresses: 107D0H-107D3H 30-92 Figure 30-40. PerfEvtSel0 and PerfEvtSel1 MSRs 30-95 Figure 30-41. CESR MSR (Pentium Processor Only) 30-99 Figure C-1. MP System With Multiple Pentium III Processors C-3

Vol. 3A xxxvii

Page 38 of the Intel 253668-032US user manual — PAGE TABLES
Page 38 · click to enlarge
Page 38

CONTENTS

PAGE TABLES

Table 2-1. Action Taken By x87 FPU Instructions for Different Combinations of EM, MP, and TS2-21 Table 2-2. Summary of System Instructions 2-27 Table 3-1. Code- and Data-Segment Types 3-17 Table 3-2. System-Segment and Gate-Descriptor Types 3-19 Table 4-1. Properties of Different Paging Modes 4-3 Table 4-3. Use of CR3 with 32-Bit Paging 4-9 Table 4-2. Paging Structures in the Different Paging Modes 4-9 Table 4-4. Format of a 32-Bit Page-Directory Entry that Maps a 4-MByte Page 4-12 Table 4-5. Format of a 32-Bit Page-Directory Entry that References a Page Table 4-13 Table 4-6. Format of a 32-Bit Page-Table Entry that Maps a 4-KByte Page 4-14 Table 4-7. Use of CR3 with PAE Paging 4-16 Table 4-8. Format of an PAE Page-Directory-Pointer-Table Entry (PDPTE) 4-17 Table 4-9. Format of a PAE Page-Directory Entry that Maps a 2-MByte Page 4-20 Table 4-10. Format of a PAE Page-Directory Entry that References a Page Table 4-21 Table 4-11. Format of a PAE Page-Table Entry that Maps a 4-KByte Page 4-22 Table 4-12. Use of CR3 with IA-32e Paging 4-24 Table 4-13. Format of an IA-32e PML4 Entry (PML4E) that References a Page-Directory-Pointer Table4-27 Table 4-15. Format of an IA-32e Page-Directory Entry that Maps a 2-MByte Page 4-28 Table 4-14. Format of an IA-32e Page-Directory-Pointer-Table Entry (PDPTE) that References a Page Directory4-28 Table 4-16. Format of an IA-32e Page-Directory Entry that References a Page Table 4-30 Table 4-17. Format of an IA-32e Page-Table Entry that Maps a 4-KByte Page 4-31 Table 5-1. Privilege Check Rules for Call Gates 5-23 Table 5-2. 64-Bit-Mode Stack Layout After CALLF with CPL Change 5-28 Table 5-3. Combined Page-Directory and Page-Table Protection 5-42 Table 5-4. Extended Feature Enable MSR (IA32_EFER) 5-43 Table 5-5. IA-32e Mode Page Level Protection Matrix with Execute-Disable Bit Capability5-44 Table 5-6. Legacy PAE-Enabled 4-KByte Page Level Protection Matrix with Execute-Disable Bit Capability5-45 Table 5-7. Legacy PAE-Enabled 2-MByte Page Level Protection with Execute-Disable Bit Capability5-45 Table 5-8. IA-32e Mode Page Level Protection Matrix with Execute-Disable Bit Capability Enabled5-46 Table 5-9. Reserved Bit Checking WIth Execute-Disable Bit Capability Not Enabled 5-47 Table 6-1. Protected-Mode Exceptions and Interrupts 6-3 Table 6-2. Priority Among Simultaneous Exceptions and Interrupts 6-11 Table 6-3. Debug Exception Conditions and Corresponding Exception Classes 6-29 Table 6-4. Interrupt and Exception Classes 6-38 Table 6-5. Conditions for Generating a Double Fault 6-39 Table 6-6. Invalid TSS Conditions 6-42 Table 6-7. Alignment Requirements by Data Type 6-60 Table 6-8. SIMD Floating-Point Exceptions Priority 6-65 Table 7-1. Exception Conditions Checked During a Task Switch 7-15 Table 7-2. Effect of a Task Switch on Busy Flag, NT Flag, Previous Task Link Field, and TS Flag7-17 Table 8-1. Initial APIC IDs for the Logical Processors in a System that has Four Intel Xeon MP Processors Supporting Intel Hyper-Threading Technology18-52

xxxviii Vol. 3A

Page 39 of the Intel 253668-032US user manual — PAGE
Page 39 · click to enlarge
Page 39

CONTENTS

PAGE

Table 8-2. Initial APIC IDs for the Logical Processors in a System that has Two Physical Processors Supporting Dual-Core and Intel Hyper-Threading Technology8-53 Table 8-3. Example of Possible x2APIC ID Assignment in a System that has Two Physical Processors Supporting x2APIC and Intel Hyper-Threading Technology8-53 Table 9-1. IA-32 Processor States Following Power-up, Reset, or INIT 9-2 Table 9-2. Recommended Settings of EM and MP Flags on IA-32 Processors 9-7 Table 9-3. Software Emulation Settings of EM, MP, and NE Flags 9-8 Table 9-4. Main Initialization Steps in STARTUP.ASM Source Listing 9-21 Table 9-5. Relationship Between BLD Item and ASM Source File 9-35 Table 9-6. Microcode Update Field Definitions 9-38 Table 9-7. Microcode Update Format 9-40 Table 9-8. Extended Processor Signature Table Header Structure 9-41 Table 9-9. Processor Signature Structure 9-41 Table 9-10. Processor Flags 9-43 Table 9-11. Microcode Update Signature 9-48 Table 9-12. Microcode Update Functions 9-55 Table 9-13. Parameters for the Presence Test 9-56 Table 9-14. Parameters for the Write Update Data Function 9-57 Table 9-15. Parameters for the Control Update Sub-function 9-62 Table 9-17. Parameters for the Read Microcode Update Data Function 9-63 Table 9-16. Mnemonic Values 9-63 Table 9-18. Return Code Definitions 9-65 Table 10-1 Local APIC Register Address Map 10-8 Table 10-2. x2APIC Operating Mode Configurations 10-17 Table 10-3. Local APIC Register Address Map Supported by x2APIC 10-18 Table 10-4. MSR/MMIO Interface of a Local x2APIC in Different Modes of Operation 10-22 Table 10-5. ESR Flags 10-35 Table 10-6 Valid Combinations for the Pentium 4 and Intel Xeon Processors’ Local xAPIC Interrupt Command Register10-42 Table 10-7 Valid Combinations for the P6 Family Processors’ Local APIC Interrupt Command Register10-43 Table 11-1. Characteristics of the Caches, TLBs, Store Buffer, and Write Combining Buffer in Intel 64 and IA-32 Processors11-2 Table 11-2. Memory Types and Their Properties 11-9 Table 11-3. Methods of Caching Available in Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4, Intel Xeon, P6 Family, and Pentium Processors11-10 Table 11-4. MESI Cache Line States 11-14 Table 11-5. Cache Operating Modes 11-17 Table 11-6. Effective Page-Level Memory Type for Pentium Pro and Pentium II Processors11-21 Table 11-7. Effective Page-Level Memory Types for Pentium III and More Recent Processor Families11-22 Table 11-8. Memory Types That Can Be Encoded in MTRRs 11-30 Table 11-9. Address Mapping for Fixed-Range MTRRs 11-35 Table 11-10. Memory Types That Can Be Encoded With PAT 11-49 Table 11-11. Selection of PAT Entries with PAT, PCD, and PWT Flags 11-50 Table 11-12. Memory Type Setting of PAT Entries Following a Power-up or Reset 11-50 Table 12-1. Action Taken By MMX Instructions for Different Combinations of EM, MP and TS12-1 Table 12-2. Effects of MMX Instructions on x87 FPU State 12-3 Table 12-3. Effect of the MMX, x87 FPU, and FXSAVE/FXRSTOR Instructions on the x87 FPU Tag Word12-4

Vol. 3A xxxix

Page 40 of the Intel 253668-032US user manual — PAGE
Page 40 · click to enlarge
Page 40

CONTENTS

PAGE

Table 13-1. Action Taken for Combinations of OSFXSR, OSXMMEXCPT, SSE, SSE2, SSE3, EM, MP, and TS113-4 Table 13-2. Action Taken for Combinations of OSFXSR, SSSE3, SSE4, EM, and TS 13-5 Table 13-3. XSAVE Header Format 13-14 Table 13-4. XRSTOR Action on MXCSR, x87 FPU, XMM Register 13-16 Table 13-5. XSAVE Action on MXCSR, x87 FPU, XMM Register 13-16 Table 14-1. On-Demand Clock Modulation Duty Cycle Field Encoding 14-17 Table 15-1. Bits 54:53 in IA32_MCi_STATUS MSRs when IA32_MCG_CAP[11] = 1 and UC = 015-9 Table 15-2. Overwrite Rules for Enabled Errors 15-11 Table 15-3. Address Mode in IA32_MCi_MISC[8:6] 15-13 Table 15-4. Extended Machine Check State MSRs in Processors Without Support for Intel 64 Architecture15-15 Table 15-5. Extended Machine Check State MSRs In Processors With Support For Intel 64 Architecture15-16 Table 15-6. MC Error Classifications 15-26 Table 15-7. Overwrite Rules for UC, CE, and UCR Errors 15-27 Table 15-8. IA32_MCi_Status [15:0] Simple Error Code Encoding 15-30 Table 15-9. IA32_MCi_Status [15:0] Compound Error Code Encoding 15-31 Table 15-10. Encoding for TT (Transaction Type) Sub-Field 15-32 Table 15-11. Level Encoding for LL (Memory Hierarchy Level) Sub-Field 15-32 Table 15-12. Encoding of Request (RRRR) Sub-Field 15-33 Table 15-13. Encodings of PP, T, and II Sub-Fields 15-33 Table 15-14. Encodings of MMM and CCCC Sub-Fields 15-34 Table 15-15. MCA Compound Error Code Encoding for SRAO Errors 15-35 Table 15-16. IA32_MCi_STATUS Values for SRAO Errors 15-35 Table 15-17. IA32_MCG_STATUS Flag Indication for SRAO Errors 15-36 Table 15-18. MCA Compound Error Code Encoding for SRAR Errors 15-36 Table 15-19. IA32_MCi_STATUS Values for SRAR Errors 15-37 Table 15-20. IA32_MCG_STATUS Flag Indication for SRAR Errors 15-37 Table 16-1. Breakpoint Examples 16-7 Table 16-2. Debug Exception Conditions 16-10 Table 16-3. LBR Stack Size and TOS Pointer Range 16-19 Table 16-4. IA32_DEBUGCTL Flag Encodings 16-29 Table 16-5. CPL-Qualified Branch Trace Store Encodings 16-30 Table 16-6. IA32_LASTBRACH_x_FROM_IP 16-35 Table 16-7. IA32_LASTBRACH_x_TO_IP 16-35 Table 16-8. LBR Stack Size and TOS Pointer Range 16-35 Table 16-9. MSR_LBR_SELECT 16-35 Table 16-10. LBR MSR Stack Size and TOS Pointer Range for the Pentium® 4 and the Intel® Xeon® Processor Family16-39 Table 17-1. Real-Address Mode Exceptions and Interrupts 17-8 Table 17-2. Software Interrupt Handling Methods While in Virtual-8086 Mode 17-26 Table 18-1. Characteristics of 16-Bit and 32-Bit Program Modules 18-1 Table 19-1. New Instruction in the Pentium Processor and Later IA-32 Processors19-6 Table 19-2. Recommended Values of the EM, MP, and NE Flags for Intel486 SX Microprocessor/Intel 487 SX Math Coprocessor System19-22 Table 19-3. EM and MP Flag Interpretation 19-23 Table 21-1. Format of the VMCS Region 21-2 Table 21-2. Format of Access Rights 21-5 Table 21-3. Format of Interruptibility State 21-7

xl Vol. 3A

Page 41 of the Intel 253668-032US user manual — PAGE
Page 41 · click to enlarge
Page 41

CONTENTS

PAGE

Table 21-4. Format of Pending-Debug-Exceptions 21-8 Table 21-5. Definitions of Pin-Based VM-Execution Controls 21-11 Table 21-6. Definitions of Primary Processor-Based VM-Execution Controls 21-12 Table 21-7. Definitions of Secondary Processor-Based VM-Execution Controls 21-14 Table 21-8. Format of Extended-Page-Table Pointer 21-19 Table 21-9. Definitions of VM-Exit Controls 21-20 Table 21-10. Format of an MSR Entry 21-22 Table 21-11. Definitions of VM-Entry Controls 21-23 Table 21-12. Format of the VM-Entry Interruption-Information Field 21-24 Table 21-13. Format of Exit Reason 21-26 Table 21-14. Format of the VM-Exit Interruption-Information Field 21-27 Table 21-15. Format of the IDT-Vectoring Information Field 21-28 Table 21-16. Structure of VMCS Component Encoding 21-31 Table 24-1. Exit Qualification for Debug Exceptions 24-6 Table 24-2. Exit Qualification for Task Switch 24-6 Table 24-3. Exit Qualification for Control-Register Accesses 24-8 Table 24-4. Exit Qualification for MOV DR 24-9 Table 24-5. Exit Qualification for I/O Instructions 24-9 Table 24-6. Exit Qualification for APIC-Access VM Exits from Linear Accesses and Guest-Physical Accesses24-10 Table 24-7. Exit Qualification for EPT Violations 24-11 Table 24-8. Format of the VM-Exit Instruction-Information Field as Used for INS and OUTS . . 24- 18 Table 24-9. Format of the VM-Exit Instruction-Information Field as Used for LIDT, LGDT, SIDT, or SGDT24-19 Table 24-10. Format of the VM-Exit Instruction-Information Field as Used for LLDT, LTR, SLDT, and STR24-21 Table 24-11. Format of the VM-Exit Instruction-Information Field as Used for VMCLEAR, VMPTRLD, VMPTRST, and VMXON24-22 Table 24-12. Format of the VM-Exit Instruction-Information Field as Used for VMREAD and VMWRITE24-23 Table 24-13. Format of the VM-Exit Instruction-Information Field as Used for INVEPT and INVVPID 24-25 Table 25-1. Format of an EPT PML4 Entry (PML4E) 25-5 Table 25-2. Format of an EPT Page-Directory-Pointer-Table Entry (PDPTE) that References an EPT Page Directory25-6 Table 25-3. Format of an EPT Page-Directory Entry (PDE) that Maps a 2-MByte Page 25-7 Table 25-4. Format of an EPT Page-Directory Entry (PDE) that References an EPT Page Table . . 25-8 Table 25-5. Format of an EPT Page-Table Entry 25-9 Table 26-1. SMRAM State Save Map 26-6 Table 26-2. Processor Signatures and 64-bit SMRAM State Save Map Format 26-9 Table 26-3. SMRAM State Save Map for Intel 64 Architecture 26-9 Table 26-4. Processor Register Initialization in SMM 26-13 Table 26-5. I/O Instruction Information in the SMM State Save Map 26-16 Table 26-6. I/O Instruction Type Encodings 26-17 Table 26-7. Auto HALT Restart Flag Values 26-19 Table 26-8. I/O Instruction Restart Field Values 26-21 Table 26-9. Exit Qualification for SMIs That Arrive Immediately After the Retirement of an I/O Instruction26-28 Table 26-10. Format of MSEG Header 26-35 Table 27-1. Operating Modes for Host and Guest Environments 27-18

Vol. 3A xli

Page 42 of the Intel 253668-032US user manual — PAGE
Page 42 · click to enlarge
Page 42

CONTENTS

PAGE

Table 30-1. UMask and Event Select Encodings for Pre-Defined Architectural Performance Events30-13 Table 30-2. Core Specificity Encoding within a Non-Architectural Umask 30-15 Table 30-3. Agent Specificity Encoding within a Non-Architectural Umask 30-15 Table 30-4. HW Prefetch Qualification Encoding within a Non-Architectural Umask 30-16 Table 30-5. MESI Qualification Definitions within a Non-Architectural Umask 30-16 Table 30-6. Bus Snoop Qualification Definitions within a Non-Architectural Umask 30-17 Table 30-7. Snoop Type Qualification Definitions within a Non-Architectural Umask 30-17 Table 30-8. Association of Fixed-Function Performance Counters with Architectural Performance Events30-18 Table 30-10. PEBS Performance Events for Intel Core Microarchitecture 30-22 Table 30-9. At-Retirement Performance Events for Intel Core Microarchitecture 30-22 Table 30-11. Requirements to Program PEBS 30-24 Table 30-12. PEBS Record Format for Intel Core i7 Processor Family 30-28 Table 30-13. Data Source Encoding for Load Latency Record 30-33 Table 30-14. Off-Core Response Event Encoding 30-35 Table 30-15. MSR_OFFCORE_RSP_Z Bit Field Definition 30-35 Table 30-16. Opcode Field Encoding for MSR_UNCORE_ADDR_OPCODE_MATCH 30-42 Table 30-17. Performance Counter MSRs and Associated CCCR and ESCR MSRs (Pentium 4 and Intel Xeon Processors)30-45 Table 30-18. Event Example 30-54 Table 30-19. CCR Names and Bit Positions 30-60 Table 30-20. Effect of Logical Processor and CPL Qualification for Logical-Processor-Specific (TS) Events30-73 Table 30-21. Effect of Logical Processor and CPL Qualification for Non-logical-Processor-specific (TI) Events30-74 Table A-1. Architectural Performance Events A-2 Table A-2. Non-Architectural Performance Events In the Processor Core for Intel Core i7 Processor and Intel Xeon Processor 5500 SeriesA-2 Table A-3. Non-Architectural Performance Events In the Processor Uncore for Intel Core i7 Processor and Intel Xeon Processor 5500 SeriesA-35 Table A-4. Non-Architectural Performance Events In Next Generation Processor Core (Codenamed Westmere)A-58 Table A-5. Non-Architectural Performance Events for Processors based on Enhanced Intel Core MicroarchitectureA-88 Table A-6. Fixed-Function Performance Counter and Pre-defined Performance EventsA-89 Table A-7. Non-Architectural Performance Events in Processors Based on Intel Core MicroarchitectureA-90 Table A-8. Non-Architectural Performance Events for Intel Atom Processors A-133 Table A-9. Non-Architectural Performance Events in Intel Core Solo and Intel Core Duo ProcessorsA-156 Table A-10. Performance Monitoring Events Supported by Intel NetBurst Microarchitecture for Non-Retirement CountingA-165 Table A-11. Performance Monitoring Events For Intel NetBurst Microarchitecture for At-Retirement CountingA-197 Table A-12. Intel NetBurst Microarchitecture Model-Specific Performance Monitoring Events (For Model Encoding 3, 4 or 6)A-204 Table A-14. List of Metrics Available for Execution Tagging (For Execution Event Only)A-205 Table A-13. List of Metrics Available for Front_end Tagging (For Front_end Event Only)A-205

xlii Vol. 3A

Page 43 of the Intel 253668-032US user manual — PAGE
Page 43 · click to enlarge
Page 43

CONTENTS

PAGE

Table A-15. List of Metrics Available for Replay Tagging (For Replay Event Only)A-206 Table A-16. Event Mask Qualification for Logical Processors A-208 Table A-17. Performance Monitoring Events on Intel® Pentium® M ProcessorsA-214 Table A-18. Performance Monitoring Events Modified on Intel® Pentium® M Processors . . A-216 Table A-19. Events That Can Be Counted with the P6 Family Performance- Monitoring CountersA-218 Table A-20. Events That Can Be Counted with Pentium Processor Performance-Monitoring CountersA-235 Table B-1. CPUID Signature Values of DisplayFamily_DisplayModel B-1 Table B-2. IA-32 Architectural MSRs B-3 Table B-3. MSRs in Processors Based on Intel Core Microarchitecture B-38 Table B-4. MSRs in Intel Atom Processor Family B-58 Table B-5. MSRs in Processors Based on Intel Microarchitecture (Nehalem) B-73 Table B-6. MSRs in the Pentium 4 and Intel Xeon Processors B-96 Table B-7. MSRs Unique to 64-bit Intel Xeon Processor MP with Up to an 8 MB L3 CacheB-136 Table B-8. MSRs Unique to Intel Xeon Processor 7100 Series B-138 Table B-9. MSRs in Intel Core Solo, Intel Core Duo Processors, and Dual-Core Intel Xeon Processor LVB-139 Table B-10. MSRs in Pentium M Processors B-153 Table B-11. MSRs in the P6 Family Processors B-162 Table B-12. MSRs in the Pentium Processor B-174 Table C-1. Boot Phase IPI Message Format C-2 Table E-1. CPUID DisplayFamily_DisplayModel Signatures for Family 6 E-1 Table E-2. Incremental Decoding Information: Processor Family 06H Machine Error Codes For Machine CheckE-2 Table E-3. CPUID DisplayFamily_DisplayModel Signatures for Processors Based on Intel Core MicroarchitectureE-5 Table E-4. Incremental Bus Error Codes of Machine Check for Processors Based on Intel Core MicroarchitectureE-6 Table E-5. Incremental MCA Error Code Types for Intel Xeon Processor 7400 E-9 Table E-6. Type B Bus and Interconnect Error Codes E-10 Table E-7. Type C Cache Bus Controller Error Codes E-10 Table E-8. QPI Machine Check Error codes for IA32_MC0_STATUS and IA32_MC1_STATUSE-12 Table E-9. QPI Machine Check Error codes for IA32_MC0_MISC and IA32_MC1_MISC E-13 Table E-10. Machine Check Error codes for IA32_MC7_STATUS E-13 Table E-11. Incremental Memory Controller Error Codes of Machine Check for IA32_MC8_STATUS E-14 Table E-12. Incremental Memory Controller Error Codes of Machine Check for IA32_MC8_MISC E- 15 Table E-13. Incremental Decoding Information: Processor Family 0FH Machine Error Codes For Machine CheckE-15 Table E-14. MCi_STATUS Register Bit Definition E-17 Table E-15. Incremental MCA Error Code for Intel Xeon Processor MP 7100 E-18 Table E-16. Other Information Field Bit Definition E-20 Table E-17. Type A: L3 Error Codes E-21 Table E-18. Type B Bus and Interconnect Error Codes E-22 Table E-19. Type C Cache Bus Controller Error Codes E-23 Table E-20. Decoding Family 0FH Machine Check Codes for Cache Hierarchy Errors E-24 Table F-1. EOI Message (14 Cycles) F-1

Vol. 3A xliii

Page 44 of the Intel 253668-032US user manual — PAGE
Page 44 · click to enlarge
Page 44

CONTENTS

PAGE

Table F-2. Short Message (21 Cycles) F-2 Table F-3. Non-Focused Lowest Priority Message (34 Cycles) F-3 Table F-4. APIC Bus Status Cycles Interpretation F-5 Table G-1. Memory Types Used For VMCS Access G-2 Table H-1. Encoding for 32-Bit Control Fields (0000_00xx_xxxx_xxx0B) H-1 Table H-2. Encodings for 16-Bit Guest-State Fields (0000_10xx_xxxx_xxx0B) H-1 Table H-3. Encodings for 16-Bit Host-State Fields (0000_11xx_xxxx_xxx0B) H-2 Table H-4. Encodings for 64-Bit Control Fields (0010_00xx_xxxx_xxxAb) H-3 Table H-5. Encodings for 64-Bit Read-Only Data Field (0010_01xx_xxxx_xxxAb) H-4 Table H-6. Encodings for 64-Bit Guest-State Fields (0010_10xx_xxxx_xxxAb) H-4 Table H-7. Encodings for 64-Bit Host-State Fields (0010_11xx_xxxx_xxxAb) H-5 Table H-8. Encodings for 32-Bit Control Fields (0100_00xx_xxxx_xxx0B) H-6 Table H-9. Encodings for 32-Bit Read-Only Data Fields (0100_01xx_xxxx_xxx0B) H-7 Table H-10. Encodings for 32-Bit Guest-State Fields (0100_10xx_xxxx_xxx0B)H-7 Table H-11. Encoding for 32-Bit Host-State Field (0100_11xx_xxxx_xxx0B) H-9 Table H-12. Encodings for Natural-Width Control Fields (0110_00xx_xxxx_xxx0B) H-9 Table H-13. Encodings for Natural-Width Read-Only Data Fields (0110_01xx_xxxx_xxx0B)H-10 Table H-14. Encodings for Natural-Width Guest-State Fields (0110_10xx_xxxx_xxx0B) . . . H-10 Table H-15. Encodings for Natural-Width Host-State Fields (0110_11xx_xxxx_xxx0B) H-11 Table I-1. Basic Exit Reasons I-1

xliv Vol. 3A

Page 45 of the Intel 253668-032US user manual — 1.1 PROCESSORS COVERED IN THIS MANUAL
Page 45 · click to enlarge
Page 45

CHAPTER 1 ABOUT THIS MANUAL

  • The Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A: System Programming Guide, Part 1 (order number 253668) and the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3B: System Programming Guide, Part 2 (order number 253669) are part of a set that describes the architecture and programming environment of Intel 64 and IA-32 Architecture processors. The other volumes in this set are:
  • Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1 : Basic Architecture (order number 253665).
  • Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B: Instruction Set Reference (order numbers 253666 and 253667).

The Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, describes the basic architecture and programming environment of Intel 64 and IA-32 processors. The Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B, describe the instruction set of the processor and the opcode struc ture. These volumes apply to application programmers and to programmers who write operating systems or executives. The Intel® 64 and IA-32 Architectures Soft ware Developer’s Manual, Volumes 3A & 3B, describe the operating-system support environment of Intel 64 and IA-32 processors. These volumes target operating- system and BIOS designers. In addition, Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3B, addresses the programming environment for classes of software that host operating systems.

1.1 PROCESSORS COVERED IN THIS MANUAL

  • This manual set includes information pertaining primarily to the most recent Intel ® 64 and IA-32 processors, which include:
  • Pentium ® processors
  • P6 family processors
  • Pentium ® 4 processors
  • Pentium ® M processors
  • Intel ® Xeon ® processors
  • Pentium ® D processors
  • Pentium ® processor Extreme Editions
  • 64-bit Intel ® Xeon ® processors
  • Intel ® Core™ Duo processor
  • Intel ® Core™ Solo processor
Page 46 of the Intel 253668-032US user manual — ABOUT THIS MANUAL
Page 46 · click to enlarge
Page 46

ABOUT THIS MANUAL

  • Dual-Core Intel ® Xeon ® processor LV
  • Intel ® Core™2 Duo processor
  • Intel ® Core™2 Quad processor Q6000 series
  • Intel ® Xeon ® processor 3000, 3200 series
  • Intel ® Xeon ® processor 5000 series
  • Intel ® Xeon ® processor 5100, 5300 series
  • Intel ® Core™2 Extreme processor X7000 and X6800 series
  • Intel ® Core™2 Extreme QX6000 series
  • Intel ® Xeon ® processor 7100 series
  • Intel ® Pentium ® Dual-Core processor
  • Intel ® Xeon ® processor 7200, 7300 series
  • Intel ® Core™2 Extreme QX9000 series
  • Intel ® Xeon ® processor 5200, 5400, 7400 series
  • Intel ® Core TM 2 Extreme processor QX9000 and X9000 series
  • Intel ® Core TM 2 Quad processor Q9000 series
  • Intel ® Core TM 2 Duo processor E8000, T9000 series
  • Intel ® Atom TM processor family
  • Intel ® Core TM i7 processor
  • Intel ® Core TM i5 processor

P6 family processors are IA-32 processors based on the P6 family microarchitecture. This includes the Pentium® Pro, Pentium® II, Pentium® III, and Pentium® III Xeon® processors.

The Pentium® 4, Pentium® D, and Pentium® processor Extreme Editions are based on the Intel NetBurst® microarchitecture. Most early Intel® Xeon® processors are based on the Intel NetBurst® microarchitecture. Intel Xeon processor 5000, 7100 series are based on the Intel NetBurst® microarchitecture.

The Intel® Core™ Duo, Intel® Core™ Solo and dual-core Intel® Xeon® processor LV are based on an improved Pentium® M processor microarchitecture.

The Intel® Xeon® processor 3000, 3200, 5100, 5300, 7200, and 7300 series, Intel® Pentium® dual-core, Intel® Core™2 Duo, Intel® Core™2 Quad and Intel® Core™2 Extreme processors are based on Intel® Core™ microarchitecture.

The Intel® Xeon® processor 5200, 5400, 7400 series, Intel® CoreTM2 Quad processor Q9000 series, and Intel® CoreTM2 Extreme processors QX9000, X9000 series, Intel® CoreTM2 processor E8000 series are based on Enhanced Intel® CoreTM microarchitec ture.

The Intel® AtomTM processor family is based on the Intel® AtomTM microarchitecture and supports Intel 64 architecture.

Page 47 of the Intel 253668-032US user manual — 1.2 OVERVIEW OF THE SYSTEM PROGRAMMING GUIDE
Page 47 · click to enlarge
Page 47

ABOUT THIS MANUAL

The Intel® CoreTM i7 processor and the Intel® CoreTM i5 processor are based on the Intel® microarchitecture (Nehalem) and support Intel 64 architecture.

Processors based on the Next Generation Intel Processor, codenamed Westmere, support Intel 64 architecture.

P6 family, Pentium® M, Intel® Core™ Solo, Intel® Core™ Duo processors, dual-core Intel® Xeon® processor LV, and early generations of Pentium 4 and Intel Xeon processors support IA-32 architecture. The Intel® AtomTM processor Z5xx series support IA-32 architecture.

The Intel® Xeon® processor 3000, 3200, 5000, 5100, 5200, 5300, 5400, 7100, 7200, 7300, 7400 series, Intel® Core™2 Duo, Intel® Core™2 Extreme processors, Intel Core 2 Quad processors, Pentium® D processors, Pentium® Dual-Core processor, newer generations of Pentium 4 and Intel Xeon processor family support Intel® 64 architecture.

IA-32 architecture is the instruction set architecture and programming environment for Intel's 32-bit microprocessors. Intel® 64 architecture is the instruction set archi tecture and programming environment which is a superset of and compatible with IA-32 architecture.

1.2 OVERVIEW OF THE SYSTEM PROGRAMMING GUIDE

A description of this manual’s content follows:

Chapter 1 — About This Manual. Gives an overview of all five volumes of the Intel® 64 and IA-32 Architectures Software Developer’s Manual. It also describes the notational conventions in these manuals and lists related Intel manuals and documentation of interest to programmers and hardware designers.

Chapter 2 — System Architecture Overview. Describes the modes of operation used by Intel 64 and IA-32 processors and the mechanisms provided by the architec tures to support operating systems and executives, including the system-oriented registers and data structures and the system-oriented instructions. The steps neces sary for switching between real-address and protected modes are also identified.

Chapter 3 — Protected-Mode Memory Management. Describes the data struc tures, registers, and instructions that support segmentation and paging. The chapter explains how they can be used to implement a “flat” (unsegmented) memory model or a segmented memory model.

Chapter 4 — Paging. Describes the paging modes supported by Intel 64 and IA-32 processors.

Chapter 5 — Protection. Describes the support for page and segment protection provided in the Intel 64 and IA-32 architectures. This chapter also explains the implementation of privilege rules, stack switching, pointer validation, user and supervisor modes.

Page 48 of the Intel 253668-032US user manual — ABOUT THIS MANUAL
Page 48 · click to enlarge
Page 48

ABOUT THIS MANUAL

Chapter 6 — Interrupt and Exception Handling. Describes the basic interrupt mechanisms defined in the Intel 64 and IA-32 architectures, shows how interrupts and exceptions relate to protection, and describes how the architecture handles each exception type. Reference information for each exception is given at the end of this chapter.

Chapter 7 — Task Management. Describes mechanisms the Intel 64 and IA-32 architectures provide to support multitasking and inter-task protection.

Chapter 8 — Multiple-Processor Management. Describes the instructions and flags that support multiple processors with shared memory, memory ordering, and Intel® Hyper-Threading Technology.

Chapter 9 — Processor Management and Initialization. Defines the state of an Intel 64 or IA-32 processor after reset initialization. This chapter also explains how to set up an Intel 64 or IA-32 processor for real-address mode operation and protected- mode operation, and how to switch between modes.

Chapter 10 — Advanced Programmable Interrupt Controller (APIC). Describes the programming interface to the local APIC and gives an overview of the interface between the local APIC and the I/O APIC.

Chapter 11 — Memory Cache Control. Describes the general concept of caching and the caching mechanisms supported by the Intel 64 or IA-32 architectures. This chapter also describes the memory type range registers (MTRRs) and how they can be used to map memory types of physical memory. Information on using the new cache control and memory streaming instructions introduced with the Pentium III, Pentium 4, and Intel Xeon processors is also given.

Chapter 12 — Intel® MMX™ Technology System Programming. Describes those aspects of the Intel® MMX™ technology that must be handled and considered at the system programming level, including: task switching, exception handling, and compatibility with existing system environments.

Chapter 13 — System Programming For Instruction Set Extensions And Processor Extended States. Describes the operating system requirements to support SSE/SSE2/SSE3/SSSE3/SSE4 extensions, including task switching, excep tion handling, and compatibility with existing system environments. The latter part of this chapter describes the extensible framework of operating system requirements to support processor extended states. Processor extended state may be required by instruction set extensions beyond those of SSE/SSE2/SSE3/SSSE3/SSE4 extensions.

Chapter 14 — Power and Thermal Management. Describes facilities of Intel 64 and IA-32 architecture used for power management and thermal monitoring.

Chapter 15 — Machine-Check Architecture. Describes the machine-check architecture and machine-check exception mechanism found in the Pentium 4, Intel Xeon, and P6 family processors. Additionally, a signaling mechanism for software to respond to hardware corrected machine check error is covered.

Page 49 of the Intel 253668-032US user manual — ABOUT THIS MANUAL
Page 49 · click to enlarge
Page 49

ABOUT THIS MANUAL

Chapter 16 — Debugging, Branch Profiles and Time-Stamp Counter. Describes the debugging registers and other debug mechanism provided in Intel 64 or IA-32 processors. This chapter also describes the time-stamp counter.

Chapter 17 — 8086 Emulation. Describes the real-address and virtual-8086 modes of the IA-32 architecture.

Chapter 18 — Mixing 16-Bit and 32-Bit Code. Describes how to mix 16-bit and 32-bit code modules within the same program or task.

Chapter 19 — IA-32 Architecture Compatibility. Describes architectural compatibility among IA-32 processors.

Chapter 20 — Introduction to Virtual-Machine Extensions. Describes the basic elements of virtual machine architecture and the virtual-machine extensions for Intel 64 and IA-32 Architectures.

Chapter 21 — Virtual-Machine Control Structures. Describes components that manage VMX operation. These include the working-VMCS pointer and the control ling-VMCS pointer.

Chapter 22— VMX Non-Root Operation. Describes the operation of a VMX non- root operation. Processor operation in VMX non-root mode can be restricted programmatically such that certain operations, events or conditions can cause the processor to transfer control from the guest (running in VMX non-root mode) to the monitor software (running in VMX root mode).

Chapter 23 — VM Entries. Describes VM entries. VM entry transitions the processor from the VMM running in VMX root-mode to a VM running in VMX non-root mode. VM-Entry is performed by the execution of VMLAUNCH or VMRESUME instructions.

Chapter 24 — VM Exits. Describes VM exits. Certain events, operations or situa tions while the processor is in VMX non-root operation may cause VM-exit transitions. In addition, VM exits can also occur on failed VM entries.

Chapter 25 — VMX Support for Address Translation. Describes virtual-machine extensions that support address translation and the virtualization of physical memory.

Chapter 26 — System Management Mode. Describes Intel 64 and IA-32 architec tures’ system management mode (SMM) facilities.

Chapter 27 — Virtual-Machine Monitoring Programming Considerations. Describes programming considerations for VMMs. VMMs manage virtual machines (VMs).

Chapter 28 — Virtualization of System Resources. Describes the virtualization of the system resources. These include: debugging facilities, address translation, physical memory, and microcode update facilities.

Chapter 29 — Handling Boundary Conditions in a Virtual Machine Monitor. Describes what a VMM must consider when handling exceptions, interrupts, error conditions, and transitions between activity states.

Page 50 of the Intel 253668-032US user manual — 1.3.1 Bit and Byte Order
Page 50 · click to enlarge
Page 50

ABOUT THIS MANUAL

Chapter 30 — Performance Monitoring. Describes the Intel 64 and IA-32 archi tectures’ facilities for monitoring performance.

Appendix A — Performance-Monitoring Events. Lists architectural performance events. Non-architectural performance events (i.e. model-specific events) are listed for each generation of microarchitecture.

Appendix B — Model-Specific Registers (MSRs). Lists the MSRs available in the Pentium processors, the P6 family processors, the Pentium 4, Intel Xeon, Intel Core Solo, Intel Core Duo processors, and Intel Core 2 processor family and describes their functions.

Appendix C — MP Initialization For P6 Family Processors. Gives an example of how to use of the MP protocol to boot P6 family processors in n MP system.

Appendix D — Programming the LINT0 and LINT1 Inputs. Gives an example of how to program the LINT0 and LINT1 pins for specific interrupt vectors.

Appendix E — Interpreting Machine-Check Error Codes. Gives an example of how to interpret the error codes for a machine-check error that occurred on a P6 family processor.

Appendix F — APIC Bus Message Formats. Describes the message formats for messages transmitted on the APIC bus for P6 family and Pentium processors.

Appendix G — VMX Capability Reporting Facility. Describes the VMX capability MSRs. Support for specific VMX features is determined by reading capability MSRs.

Appendix H — Field Encoding in VMCS. Enumerates all fields in the VMCS and their encodings. Fields are grouped by width (16-bit, 32-bit, etc.) and type (guest- state, host-state, etc.).

Appendix I — VM Basic Exit Reasons. Describes the 32-bit fields that encode reasons for a VM exit. Examples of exit reasons include, but are not limited to: soft ware interrupts, processor exceptions, software traps, NMIs, external interrupts, and triple faults.

1.3 NOTATIONAL CONVENTIONS

This manual uses specific notation for data-structure formats, for symbolic represen tation of instructions, and for hexadecimal and binary numbers. A review of this notation makes the manual easier to read.

1.3.1 Bit and Byte Order

In illustrations of data structures in memory, smaller addresses appear toward the bottom of the figure; addresses increase toward the top. Bit positions are numbered from right to left. The numerical value of a set bit is equal to two raised to the power of the bit position. Intel 64 and IA-32 processors are “little endian” machines; this

Page 51 of the Intel 253668-032US user manual — NOTE
Page 51 · click to enlarge
Page 51

ABOUT THIS MANUAL

means the bytes of a word are numbered starting from the least significant byte. Figure 1-1 illustrates these conventions.

1.3.2 Reserved Bits and Software Compatibility

  • In many register and memory layout descriptions, certain bits are marked as reserved . When bits are marked as reserved, it is essential for compatibility with future processors that software treat these bits as having a future, though unknown, effect. The behavior of reserved bits should be regarded as not only undefined, but unpredictable. Software should follow these guidelines in dealing with reserved bits:
  • Do not depend on the states of any reserved bits when testing the values of registers which contain such bits. Mask out the reserved bits before testing.
  • Do not depend on the states of any reserved bits when storing to memory or to a register.
  • Do not depend on the ability to retain information written into any reserved bits.
  • When loading a register, always load the reserved bits with the values indicated in the documentation, if any, or reload them with values previously read from the same register.

NOTE

Avoid any software dependence upon the state of reserved bits in Intel 64 and IA-32 registers. Depending upon the values of reserved register bits will make software dependent upon the unspecified manner in which the processor handles these bits. Programs that depend upon reserved values risk incompatibility with future processors.

31 24 23 16 15 8 7 0 Address

Bit offset 28 24 20 16 12 8 4 0 Address

Byte 1 Byte 2 Byte 0

Figure 1-1. Bit and Byte Order

Show 5 more labels / short text on this page
Data Structure · Highest · Lowest · Byte 3 · Byte Offset
Page 52 of the Intel 253668-032US user manual — 1.3.5 Segmented Addressing
Page 52 · click to enlarge
Page 52

ABOUT THIS MANUAL

1.3.3 Instruction Operands

When instructions are represented symbolically, a subset of assembly language is used. In this subset, an instruction has the following format:

labelmnemonic argument1, argument2, argument3
  • where:
  • A label is an identifier which is followed by a colon.
  • A mnemonic is a reserved name for a class of instruction opcodes which have the same function.
  • The operands argument1 , argument2 , and argument3 are optional. There may be from zero to three operands, depending on the opcode. When present, they take the form of either literals or identifiers for data items. Operand identifiers are either reserved names of registers or are assumed to be assigned to data items declared in another part of the program (which may not be shown in the example).

When two operands are present in an arithmetic or logical instruction, the right operand is the source and the left operand is the destination.

For example:

LOADREG: MOV EAX, SUBTOTAL

In this example LOADREG is a label, MOV is the mnemonic identifier of an opcode, EAX is the destination operand, and SUBTOTAL is the source operand. Some assembly languages put the source and destination in reverse order.

1.3.4 Hexadecimal and Binary Numbers

Base 16 (hexadecimal) numbers are represented by a string of hexadecimal digits followed by the character H (for example, F82EH). A hexadecimal digit is a character from the following set: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.

Base 2 (binary) numbers are represented by a string of 1s and 0s, sometimes followed by the character B (for example, 1010B). The “B” designation is only used in situations where confusion as to the type of number might arise.

1.3.5 Segmented Addressing

The processor uses byte addressing. This means memory is organized and accessed as a sequence of bytes. Whether one or more bytes are being accessed, a byte address is used to locate the byte or bytes memory. The range of memory that can be addressed is called an address space.

The processor also supports segmented addressing. This is a form of addressing where a program may have many independent address spaces, called segments.

Page 53 of the Intel 253668-032US user manual — CS:EIP
Page 53 · click to enlarge
Page 53

ABOUT THIS MANUAL

For example, a program can keep its code (instructions) and stack in separate segments. Code addresses would always refer to the code space, and stack addresses would always refer to the stack space. The following notation is used to specify a byte address within a segment:

Segment-register:Byte-address

For example, the following segment address identifies the byte at address FF79H in the segment pointed by the DS register:

DS:FF79H

The following segment address identifies an instruction address in the code segment. The CS register points to the code segment and the EIP register contains the address of the instruction.

CS:EIP

1.3.6 Syntax for CPUID, CR, and MSR Values

Obtain feature flags, status, and system information by using the CPUID instruction, by checking control register bits, and by reading model-specific registers. We are moving toward a single syntax to represent this type of information. See Figure 1-2.

Page 54 of the Intel 253668-032US user manual — 1.3.7 Exceptions
Page 54 · click to enlarge
Page 54

ABOUT THIS MANUAL

6\QWD[5HSUHVHQWDWLRQIRU&38,',QSXWDQG2XWSXW

&38,'+ (&;66(>ELW@

,QSXWYDOXHIRU($;GHILQHVRXWSXW 127( 6RPHOHDYHVUHTXLUHLQSXWYDOXHVIRU ($;DQG(&;,IRQO\RQHYDOXHLVSUHVHQW ($;LVLPSOLHG

2XWSXWUHJLVWHUDQGIHDWXUHIODJRU ILHOGQDPHZLWKELWSRVLWLRQ V

9DOXH RUUDQJH RIRXWSXW

)RU&RQWURO5HJLVWHU9DOXHV

&526);65>ELW @

([DPSOH&5QDPH

)HDWXUHIODJRUILHOGQDPH

ZLWKELWSRVLWLRQ V

9DOXH RUUDQJH RIRXWSXW

)RU0RGHO6SHFLILF5HJLVWHU9DOXHV

,$B0,6&B(1$%/(6(1$%/()23&2'(>ELW@

([DPSOH065QDPH

)HDWXUHIODJRUILHOGQDPHZLWKELWSRVLWLRQ V

9DOXH RUUDQJH RIRXWSXW

Figure 1-2. Syntax for CPUID, CR, and MSR Data Presentation

1.3.7 Exceptions

An exception is an event that typically occurs when an instruction causes an error. For example, an attempt to divide by zero generates an exception. However, some exceptions, such as breakpoints, occur under other conditions. Some types of excep tions may provide error codes. An error code reports additional information about the error. An example of the notation used to show an exception and error code is shown below:

20 · #PF(fault code)

Page 55 of the Intel 253668-032US user manual — http://developer.intel.com/products/processor/manuals/index.htm • Intel ® Virtualization Technology for Directed I/O, Rev 1.2 specification
Page 55 · click to enlarge
Page 55

ABOUT THIS MANUAL

This example refers to a page-fault exception under conditions where an error code naming a type of fault is reported. Under some conditions, exceptions which produce error codes may not be able to report an accurate code. In this case, the error code is zero, as shown below for a general-protection exception:

#GP(0)

1.4 RELATED LITERATURE

Literature related to Intel 64 and IA-32 processors is listed on-line at:

http://developer.intel.com/products/processor/index.htm

Some of the documents listed at this web site can be viewed on-line; others can be ordered. The literature available is listed by Intel processor and then by the following literature types: applications notes, data sheets, manuals, papers, and specification updates.

  • See also:
  • The data sheet for a particular Intel 64 or IA-32 processor
  • The specification update for a particular Intel 64 or IA-32 processor
  • Intel ® C++ Compiler documentation and online help <a href="http://www.intel.com/cd/software/products/asmo-na/eng/index.htm" rel="nofollow noopener" target="_blank">http://www.intel.com/cd/software/products/asmo-na/eng/index.htm</a>
  • Intel ® Fortran Compiler documentation and online help <a href="http://www.intel.com/cd/software/products/asmo-na/eng/index.htm" rel="nofollow noopener" target="_blank">http://www.intel.com/cd/software/products/asmo-na/eng/index.htm</a>
  • Intel ® VTune™ Performance Analyzer documentation and online help <a href="http://www.intel.com/cd/software/products/asmo-na/eng/index.htm" rel="nofollow noopener" target="_blank">http://www.intel.com/cd/software/products/asmo-na/eng/index.htm</a>
  • Intel ® 64 and IA-32 Architectures Software Developer’s Manual (in five volumes) <a href="http://developer.intel.com/products/processor/manuals/index.htm" rel="nofollow noopener" target="_blank">http://developer.intel.com/products/processor/manuals/index.htm</a>
  • Intel ® 64 and IA-32 Architectures Optimization Reference Manual <a href="http://developer.intel.com/products/processor/manuals/index.htm" rel="nofollow noopener" target="_blank">http://developer.intel.com/products/processor/manuals/index.htm</a>
  • Intel ® Processor Identification with the CPUID Instruction, AP-485 <a href="http://www.intel.com/design/processor/applnots/241618.htm" rel="nofollow noopener" target="_blank">http://www.intel.com/design/processor/applnots/241618.htm</a>
  • Intel ® 64 Architecture Memory Ordering White Paper, <a href="http://developer.intel.com/products/processor/manuals/index.htm" rel="nofollow noopener" target="_blank">http://developer.intel.com/products/processor/manuals/index.htm</a>
  • Intel ® 64 Architecture x2APIC Specification:

http://developer.intel.com/products/processor/manuals/index.htm • Intel ® Virtualization Technology for Directed I/O, Rev 1.2 specification

http://download.intel.com/technology/computing/vptech/Intel(r)_VT_for_Direct_I O.pdf

Page 56 of the Intel 253668-032US user manual — http://developer.intel.com/products/processor/manuals/index.htm • Intel ® multi-core technology:
Page 56 · click to enlarge
Page 56

ABOUT THIS MANUAL

  • Intel ® 64 Architecture Processor Topology Enumeration:
  • <a href="http://softwarecommunity.intel.com/articles/eng/3887.htm" rel="nofollow noopener" target="_blank">http://softwarecommunity.intel.com/articles/eng/3887.htm</a>
  • Intel ® Trusted Execution Technology Measured Launched Environment Programming Guide, <a href="http://www.intel.com/technology/security/index.htm" rel="nofollow noopener" target="_blank">http://www.intel.com/technology/security/index.htm</a>
  • Developing Multi-threaded Applications: A Platform Consistent Approach <a href="http://cachewww.intel.com/cd/00/00/05/15/51534_developing_multithreaded_applications.pdf" rel="nofollow noopener" target="_blank">http://cachewww.intel.com/cd/00/00/05/15/51534_developing_multithreaded_applications.pdf</a>
  • Using Spin-Loops on Intel Pentium 4 Processor and Intel Xeon Processor MP <a href="http://www3.intel.com/cd/ids/developer/asmona/eng/dc/threading/knowledgebase/19083.htm" rel="nofollow noopener" target="_blank">http://www3.intel.com/cd/ids/developer/asmona/eng/dc/threading/knowledgebase/19083.htm</a>

More relevant links are: • Software network link:

http://softwarecommunity.intel.com/isn/home/ • Developer centers:

http://www.intel.com/cd/ids/developer/asmo-na/eng/dc/index.htm • Processor support general link:

http://www.intel.com/support/processors/ • Software products and packages:

http://www.intel.com/cd/software/products/asmo-na/eng/index.htm • Intel® 64 and IA-32 processor manuals (printed or PDF downloads):

http://developer.intel.com/products/processor/manuals/index.htm • Intel ® multi-core technology:

http://developer.intel.com/multi-core/index.htm • Intel ® Hyper-Threading Technology (Intel ® HT Technology):

http://developer.intel.com/technology/hyperthread/

Page 57 of the Intel 253668-032US user manual — CHAPTER 2 SYSTEM ARCHITECTURE OVERVIEW
Page 57 · click to enlarge
Page 57

CHAPTER 2 SYSTEM ARCHITECTURE OVERVIEW

IA-32 architecture (beginning with the Intel386 processor family) provides extensive support for operating-system and system-development software. This support offers multiple modes of operation, which include: • Real mode, protected mode, virtual 8086 mode, and system management mode. These are sometimes referred to as legacy modes.

  • Intel 64 architecture supports almost all the system programming facilities available in IA-32 architecture and extends them to a new operating mode (IA-32e mode) that supports a 64-bit programming environment. IA-32e mode allows software to operate in one of two sub-modes:
  • 64-bit mode supports 64-bit OS and 64-bit applications
  • Compatibility mode allows most legacy software to run; it co-exists with 64-bit applications under a 64-bit OS.
  • The IA-32 system-level architecture and includes features to assist in the following operations:
  • Memory management
  • Protection of software modules
  • Multitasking
  • Exception and interrupt handling
  • Multiprocessing
  • Cache management
  • Hardware resource and power management
  • Debugging and performance monitoring

This chapter provides a description of each part of this architecture. It also describes the system registers that are used to set up and control the processor at the system level and gives a brief overview of the processor’s system-level (operating system) instructions.

Many features of the system-level architectural are used only by system program mers. However, application programmers may need to read this chapter and the following chapters in order to create a reliable and secure environment for applica tion programs.

This overview and most subsequent chapters of this book focus on protected-mode operation of the IA-32 architecture. IA-32e mode operation of the Intel 64 architec ture, as it differs from protected mode operation, is also described.

All Intel 64 and IA-32 processors enter real-address mode following a power-up or reset (see Chapter 9, “Processor Management and Initialization”). Software then

Page 58 of the Intel 253668-032US user manual — 2.1 OVERVIEW OF THE SYSTEM-LEVEL ARCHITECTURE
Page 58 · click to enlarge
Page 58

SYSTEM ARCHITECTURE OVERVIEW

initiates the switch from real-address mode to protected mode. If IA-32e mode oper ation is desired, software also initiates a switch from protected mode to IA-32e mode.

2.1 OVERVIEW OF THE SYSTEM-LEVEL ARCHITECTURE

System-level architecture consists of a set of registers, data structures, and instruc tions designed to support basic system-level operations such as memory manage ment, interrupt and exception handling, task management, and control of multiple processors.

Figure 2-1 provides a summary of system registers and data structures that applies to 32-bit modes. System registers and data structures that apply to IA-32e mode are shown in Figure 2-2.

Page 59 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 59 · click to enlarge
Page 59

SYSTEM ARCHITECTURE OVERVIEW

Intel 253668-032US — SYSTEM ARCHITECTURE OVERVIEW diagram (page 59)
Fig. 1

Figure 2-1. IA-32 System-Level Registers and Data Structures

Page 60 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 60 · click to enlarge
Page 60

SYSTEM ARCHITECTURE OVERVIEW

Intel 253668-032US — SYSTEM ARCHITECTURE OVERVIEW diagram (page 60)
Fig. 2

Figure 2-2. System-Level Registers and Data Structures in IA-32e Mode

Page 61 of the Intel 253668-032US user manual — 2.1.2 System Segments, Segment Descriptors, and Gates
Page 61 · click to enlarge
Page 61

SYSTEM ARCHITECTURE OVERVIEW

2.1.1 Global and Local Descriptor Tables

When operating in protected mode, all memory accesses pass through either the global descriptor table (GDT) or an optional local descriptor table (LDT) as shown in Figure 2-1. These tables contain entries called segment descriptors. Segment descriptors provide the base address of segments well as access rights, type, and usage information.

Each segment descriptor has an associated segment selector. A segment selector provides the software that uses it with an index into the GDT or LDT (the offset of its associated segment descriptor), a global/local flag (determines whether the selector points to the GDT or the LDT), and access rights information.

To access a byte in a segment, a segment selector and an offset must be supplied. The segment selector provides access to the segment descriptor for the segment (in the GDT or LDT). From the segment descriptor, the processor obtains the base address of the segment in the linear address space. The offset then provides the location of the byte relative to the base address. This mechanism can be used to access any valid code, data, or stack segment, provided the segment is accessible from the current privilege level (CPL) at which the processor is operating. The CPL is defined as the protection level of the currently executing code segment.

See Figure 2-1. The solid arrows in the figure indicate a linear address, dashed lines indicate a segment selector, and the dotted arrows indicate a physical address. For simplicity, many of the segment selectors are shown as direct pointers to a segment. However, the actual path from a segment selector to its associated segment is always through a GDT or LDT.

The linear address of the base of the GDT is contained in the GDT register (GDTR); the linear address of the LDT is contained in the LDT register (LDTR).

2.1.1.1 Global and Local Descriptor Tables in IA-32e Mode

GDTR and LDTR registers are expanded to 64-bits wide in both IA-32e sub-modes (64-bit mode and compatibility mode). For more information: see Section 3.5.2, “Segment Descriptor Tables in IA-32e Mode.”

Global and local descriptor tables are expanded in 64-bit mode to support 64-bit base addresses, (16-byte LDT descriptors hold a 64-bit base address and various attributes). In compatibility mode, descriptors are not expanded.

2.1.2 System Segments, Segment Descriptors, and Gates

Besides code, data, and stack segments that make up the execution environment of a program or procedure, the architecture defines two system segments: the task- state segment (TSS) and the LDT. The GDT is not considered a segment because it is not accessed by means of a segment selector and segment descriptor. TSSs and LDTs have segment descriptors defined for them.

Page 62 of the Intel 253668-032US user manual — 2.1.3 Task-State Segments and Task Gates
Page 62 · click to enlarge
Page 62

SYSTEM ARCHITECTURE OVERVIEW

The architecture also defines a set of special descriptors called gates (call gates, interrupt gates, trap gates, and task gates). These provide protected gateways to system procedures and handlers that may operate at a different privilege level than application programs and most procedures. For example, a CALL to a call gate can provide access to a procedure in a code segment that is at the same or a numerically lower privilege level (more privileged) than the current code segment. To access a procedure through a call gate, the calling procedure1 supplies the selector for the call gate. The processor then performs an access rights check on the call gate, comparing the CPL with the privilege level of the call gate and the destination code segment pointed to by the call gate.

If access to the destination code segment is allowed, the processor gets the segment selector for the destination code segment and an offset into that code segment from the call gate. If the call requires a change in privilege level, the processor also switches to the stack for the targeted privilege level. The segment selector for the new stack is obtained from the TSS for the currently running task. Gates also facili tate transitions between 16-bit and 32-bit code segments, and vice versa.

2.1.2.1 Gates in IA-32e Mode

In IA-32e mode, the following descriptors are 16-byte descriptors (expanded to allow a 64-bit base): LDT descriptors, 64-bit TSSs, call gates, interrupt gates, and trap gates.

Call gates facilitate transitions between 64-bit mode and compatibility mode. Task gates are not supported in IA-32e mode. On privilege level changes, stack segment selectors are not read from the TSS. Instead, they are set to NULL.

2.1.3 Task-State Segments and Task Gates

The TSS (see Figure 2-1) defines the state of the execution environment for a task. It includes the state of general-purpose registers, segment registers, the EFLAGS register, the EIP register, and segment selectors with stack pointers for three stack segments (one stack for each privilege level). The TSS also includes the segment selector for the LDT associated with the task and the base address of the paging- structure hierarchy.

All program execution in protected mode happens within the context of a task (called the current task). The segment selector for the TSS for the current task is stored in the task register. The simplest method for switching to a task is to make a call or jump to the new task. Here, the segment selector for the TSS of the new task is given in the CALL or JMP instruction. In switching tasks, the processor performs the following actions:

1. Stores the state of the current task in the current TSS.
1. The word “procedure” is commonly used in this document as a general term for a logical unit or block of code (such as a program, procedure, function, or routine).
Page 63 of the Intel 253668-032US user manual — 2.1.4 Interrupt and Exception Handling
Page 63 · click to enlarge
Page 63

SYSTEM ARCHITECTURE OVERVIEW

2. Loads the task register with the segment selector for the new task.
3. Accesses the new TSS through a segment descriptor in the GDT.
4. Loads the state of the new task from the new TSS into the general-purpose registers, the segment registers, the LDTR, control register CR3 (base address of the paging-structure hierarchy), the EFLAGS register, and the EIP register.
5. Begins execution of the new task.

A task can also be accessed through a task gate. A task gate is similar to a call gate, except that it provides access (through a segment selector) to a TSS rather than a code segment.

2.1.3.1 Task-State Segments in IA-32e Mode

Hardware task switches are not supported in IA-32e mode. However, TSSs continue to exist. The base address of a TSS is specified by its descriptor.

  • A 64-bit TSS holds the following information that is important to 64-bit operation:
  • Stack pointer addresses for each privilege level
  • Pointer addresses for the interrupt stack table
  • Offset address of the IO-permission bitmap (from the TSS base)

The task register is expanded to hold 64-bit base addresses in IA-32e mode. See also: Section 7.7, “Task Management in 64-bit Mode.”

2.1.4 Interrupt and Exception Handling

External interrupts, software interrupts and exceptions are handled through the interrupt descriptor table (IDT). The IDT stores a collection of gate descriptors that provide access to interrupt and exception handlers. Like the GDT, the IDT is not a segment. The linear address for the base of the IDT is contained in the IDT register (IDTR).

Gate descriptors in the IDT can be interrupt, trap, or task gate descriptors. To access an interrupt or exception handler, the processor first receives an interrupt vector (interrupt number) from internal hardware, an external interrupt controller, or from software by means of an INT, INTO, INT 3, or BOUND instruction. The interrupt vector provides an index into the IDT. If the selected gate descriptor is an interrupt gate or a trap gate, the associated handler procedure is accessed in a manner similar to calling a procedure through a call gate. If the descriptor is a task gate, the handler is accessed through a task switch.

2.1.4.1 Interrupt and Exception Handling IA-32e Mode

In IA-32e mode, interrupt descriptors are expanded to 16 bytes to support 64-bit base addresses. This is true for 64-bit mode and compatibility mode.

Page 64 of the Intel 253668-032US user manual — 2.1.5 Memory Management
Page 64 · click to enlarge
Page 64

SYSTEM ARCHITECTURE OVERVIEW

The IDTR register is expanded to hold a 64-bit base address. Task gates are not supported.

2.1.5 Memory Management

System architecture supports either direct physical addressing of memory or virtual memory (through paging). When physical addressing is used, a linear address is treated as a physical address. When paging is used: all code, data, stack, and system segments (including the GDT and IDT) can be paged with only the most recently accessed pages being held in physical memory.

The location of pages (sometimes called page frames) in physical memory is contained in the paging structures. These structures reside in physical memory (see Figure 2-1 for the case of 32-bit paging).

The base physical address of the paging-structure hierarchy is contained in control register CR3. The entries in the paging structures determine the physical address of the base of a page frame, access rights and memory management information.

To use this paging mechanism, a linear address is broken into parts. The parts provide separate offsets into the paging structures and the page frame. A system can have a single hierarchy of paging structures or several. For example, each task can have its own hierarchy.

2.1.5.1 Memory Management in IA-32e Mode

  • In IA-32e mode, physical memory pages are managed by a set of system data struc tures. In compatibility mode and 64-bit mode, four levels of system data structures are used. These include:
  • The page map level 4 (PML4) — An entry in a PML4 table contains the physical address of the base of a page directory pointer table, access rights, and memory management information. The base physical address of the PML4 is stored in CR3.
  • A set of page directory pointer tables — An entry in a page directory pointer table contains the physical address of the base of a page directory table, access rights, and memory management information.
  • Sets of page directories — An entry in a page directory table contains the physical address of the base of a page table, access rights, and memory management information.
  • Sets of page tables — An entry in a page table contains the physical address of a page frame, access rights, and memory management information.
Page 65 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 65 · click to enlarge
Page 65

SYSTEM ARCHITECTURE OVERVIEW

2.1.6 System Registers

  • To assist in initializing the processor and controlling system operations, the system architecture provides system flags in the EFLAGS register and several system registers:
  • The system flags and IOPL field in the EFLAGS register control task and mode switching, interrupt handling, instruction tracing, and access rights. See also: Section 2.3, “System Flags and Fields in the EFLAGS Register.”
  • The control registers (CR0, CR2, CR3, and CR4) contain a variety of flags and data fields for controlling system-level operations. Other flags in these registers are used to indicate support for specific processor capabilities within the operating system or executive. See also: Section 2.5, “Control Registers.”
  • The debug registers (not shown in Figure 2-1) allow the setting of breakpoints for use in debugging programs and systems software. See also: Chapter 16, “Debugging, Profiling Branches and Time-Stamp Counter.”
  • The GDTR, LDTR, and IDTR registers contain the linear addresses and sizes (limits) of their respective tables. See also: Section 2.4, “Memory-Management Registers.”
  • The task register contains the linear address and size of the TSS for the current task. See also: Section 2.4, “Memory-Management Registers.”
  • Model-specific registers (not shown in Figure 2-1).

The model-specific registers (MSRs) are a group of registers available primarily to operating-system or executive procedures (that is, code running at privilege level 0). These registers control items such as the debug extensions, the performance-moni toring counters, the machine- check architecture, and the memory type ranges (MTRRs).

The number and function of these registers varies among different members of the Intel 64 and IA-32 processor families. See also: Section 9.4, “Model-Specific Regis ters (MSRs),” and Appendix B, “Model-Specific Registers (MSRs).”

Most systems restrict access to system registers (other than the EFLAGS register) by application programs. Systems can be designed, however, where all programs and procedures run at the most privileged level (privilege level 0). In such a case, appli cation programs would be allowed to modify the system registers.

2.1.6.1 System Registers in IA-32e Mode

In IA-32e mode, the four system-descriptor-table registers (GDTR, IDTR, LDTR, and TR) are expanded in hardware to hold 64-bit base addresses. EFLAGS becomes the 64-bit RFLAGS register. CR0-CR4 are expanded to 64 bits. CR8 becomes available. CR8 provides read-write access to the task priority register (TPR) so that the oper ating system can control the priority classes of external interrupts.

In 64-bit mode, debug registers DR0–DR7 are 64 bits. In compatibility mode, address-matching in DR0-DR3 is also done at 64-bit granularity.

Page 66 of the Intel 253668-032US user manual — 2.2 MODES OF OPERATION
Page 66 · click to enlarge
Page 66

SYSTEM ARCHITECTURE OVERVIEW

  • On systems that support IA-32e mode, the extended feature enable register (IA32_EFER) is available. This model-specific register controls activation of IA-32e mode and other IA-32e mode operations. In addition, there are several modelspecific registers that govern IA-32e mode instructions:
  • IA32_KernelGSbase — Used by SWAPGS instruction.
  • IA32_LSTAR — Used by SYSCALL instruction.
  • IA32_SYSCALL_FLAG_MASK — Used by SYSCALL instruction.
  • IA32_STAR_CS — Used by SYSCALL and SYSRET instruction.

2.1.7 Other System Resources

  • Besides the system registers and data structures described in the previous sections, system architecture provides the following additional resources:
  • Operating system instructions (see also: Section 2.7, “System Instruction Summary”).
  • Performance-monitoring counters (not shown in Figure 2-1).
  • Internal caches and buffers (not shown in Figure 2-1).

Performance-monitoring counters are event counters that can be programmed to count processor events such as the number of instructions decoded, the number of interrupts received, or the number of cache loads. See also: Section 20, “Introduc tion to Virtual-Machine Extensions.”

The processor provides several internal caches and buffers. The caches are used to store both data and instructions. The buffers are used to store things like decoded addresses to system and application segments and write operations waiting to be performed. See also: Chapter 11, “Memory Cache Control.”

2.2 MODES OF OPERATION

  • The IA-32 supports three operating modes and one quasi-operating mode:
  • Protected mode — This is the native operating mode of the processor. It provides a rich set of architectural features, flexibility, high performance and backward compatibility to existing software base.
  • Real-address mode — This operating mode provides the programming environment of the Intel 8086 processor, with a few extensions (such as the ability to switch to protected or system management mode).
  • System management mode (SMM) — SMM is a standard architectural feature in all IA-32 processors, beginning with the Intel386 SL processor. This mode provides an operating system or executive with a transparent mechanism for implementing power management and OEM differentiation features. SMM is entered through activation of an external system interrupt pin (SMI#), which generates a system management interrupt (SMI). In SMM, the processor switches to a separate address space while saving the context of the currently
Page 67 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 67 · click to enlarge
Page 67

SYSTEM ARCHITECTURE OVERVIEW

running program or task. SMM-specific code may then be executed transparently. Upon returning from SMM, the processor is placed back into its state prior to the SMI. • Virtual-8086 mode — In protected mode, the processor supports a quasi- operating mode known as virtual-8086 mode. This mode allows the processor execute 8086 software in a protected, multitasking environment.

Intel 64 architecture supports all operating modes of IA-32 architecture and IA-32e modes: • IA-32e mode — In IA-32e mode, the processor supports two sub-modes: compatibility mode and 64-bit mode. 64-bit mode provides 64-bit linear addressing and support for physical address space larger than 64 GBytes. Compatibility mode allows most legacy protected-mode applications to run unchanged.

Figure 2-3 shows how the processor moves between operating modes.

Intel 253668-032US — SYSTEM ARCHITECTURE OVERVIEW diagram (page 67)
Fig. 3

Figure 2-3. Transitions Among the Processor’s Operating Modes

The processor is placed in real-address mode following power-up or a reset. The PE flag in control register CR0 then controls whether the processor is operating in real- address or protected mode. See also: Section 9.9, “Mode Switching.” and Section 4.1.2, “Paging-Mode Enabling.”

Page 68 of the Intel 253668-032US user manual — 2.3 SYSTEM FLAGS AND FIELDS IN THE EFLAGS REGISTER
Page 68 · click to enlarge
Page 68

SYSTEM ARCHITECTURE OVERVIEW

The VM flag in the EFLAGS register determines whether the processor is operating in protected mode or virtual-8086 mode. Transitions between protected mode and virtual-8086 mode are generally carried out as part of a task switch or a return from an interrupt or exception handler. See also: Section 17.2.5, “Entering Virtual-8086 Mode.”

The LMA bit (IA32_EFER.LMA.LMA[bit 10]) determines whether the processor is operating in IA-32e mode. When running in IA-32e mode, 64-bit or compatibility sub-mode operation is determined by CS.L bit of the code segment. The processor enters into IA-32e mode from protected mode by enabling paging and setting the LME bit (IA32_EFER.LME[bit 8]). See also: Chapter 9, “Processor Management and Initialization.”

The processor switches to SMM whenever it receives an SMI while the processor is in real-address, protected, virtual-8086, or IA-32e modes. Upon execution of the RSM instruction, the processor always returns to the mode it was in when the SMI occurred.

2.3 SYSTEM FLAGS AND FIELDS IN THE EFLAGS REGISTER

The system flags and IOPL field of the EFLAGS register control I/O, maskable hard ware interrupts, debugging, task switching, and the virtual-8086 mode (see Figure 2-4). Only privileged code (typically operating system or executive code) should be allowed to modify these bits.

The system flags and IOPL are:

TF Trap (bit 8) — Set to enable single-step mode for debugging; clear to disable single-step mode. In single-step mode, the processor generates a debug exception after each instruction. This allows the execution state of a program to be inspected after each instruction. If an application program sets the TF flag using a POPF, POPFD, or IRET instruction, a debug exception is generated after the instruction that follows the POPF, POPFD, or IRET.

Page 69 of the Intel 253668-032US user manual — R F I D
Page 69 · click to enlarge
Page 69

SYSTEM ARCHITECTURE OVERVIEW

31 22 21 20 19 18 17 16

15 13 14 12 11 10 9 8 7 6 5 4 3 2 1 0

Z F N T 0 0 V

I O P L

Reserved (set to 0)

R F I D

I P

I F

A C

V M

0 C F A F

O F

P F 1 D F

I F

T F

S F

ID — Identification Flag VIP — Virtual Interrupt Pending

VIF — Virtual Interrupt Flag

AC — Alignment Check

VM — Virtual-8086 Mode RF — Resume Flag NT — Nested Task Flag IOPL— I/O Privilege Level IF — Interrupt Enable Flag

TF — Trap Flag

Figure 2-4. System Flags in the EFLAGS Register

IF Interrupt enable (bit 9) — Controls the response of the processor to maskable hardware interrupt requests (see also: Section 6.3.2, “Maskable Hardware Interrupts”). The flag is set to respond to maskable hardware interrupts; cleared to inhibit maskable hardware interrupts. The IF flag does not affect the generation of exceptions or nonmaskable interrupts (NMI interrupts). The CPL, IOPL, and the state of the VME flag in control register CR4 determine whether the IF flag can be modified by the CLI, STI, POPF, POPFD, and IRET.

IOPL I/O privilege level field (bits 12 and 13) — Indicates the I/O privilege level (IOPL) of the currently running program or task. The CPL of the currently running program or task must be less than or equal to the IOPL to access the I/O address space. This field can only be modified by the POPF and IRET instructions when operating at a CPL of 0.

The IOPL is also one of the mechanisms that controls the modification of the IF flag and the handling of interrupts in virtual-8086 mode when virtual mode extensions are in effect (when CR4.VME = 1). See also: Chapter 13, “Input/Output,” in the Intel® 64 and IA-32 Architectures Software Devel oper’s Manual, Volume 1.

NT Nested task (bit 14) — Controls the chaining of interrupted and called tasks. The processor sets this flag on calls to a task initiated with a CALL instruction, an interrupt, or an exception. It examines and modifies this flag on returns from a task initiated with the IRET instruction. The flag can be explicitly set or cleared with the POPF/POPFD instructions; however,

Reserved

Page 70 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 70 · click to enlarge
Page 70

SYSTEM ARCHITECTURE OVERVIEW

changing to the state of this flag can generate unexpected exceptions in application programs.

See alsoSection 7.4, “Task Linking.”

RF Resume (bit 16) — Controls the processor’s response to instruction-break point conditions. When set, this flag temporarily disables debug exceptions (#DB) from being generated for instruction breakpoints (although other exception conditions can cause an exception to be generated). When clear, instruction breakpoints will generate debug exceptions.

The primary function of the RF flag is to allow the restarting of an instruction following a debug exception that was caused by an instruction breakpoint condition. Here, debug software must set this flag in the EFLAGS image on the stack just prior to returning to the interrupted program with IRETD (to prevent the instruction breakpoint from causing another debug exception). The processor then automatically clears this flag after the instruction returned to has been successfully executed, enabling instruction breakpoint faults again.

See alsoSection 16.3.1.1, “Instruction-Breakpoint Exception Condition.”

VM Virtual-8086 mode (bit 17) — Set to enable virtual-8086 mode; clear to return to protected mode.

See alsoSection 17.2.1, “Enabling Virtual-8086 Mode.”

AC Alignment check (bit 18) — Set this flag and the AM flag in control register CR0 to enable alignment checking of memory references; clear the AC flag and/or the AM flag to disable alignment checking. An alignment-check exception is generated when reference is made to an unaligned operand, such as a word at an odd byte address or a doubleword at an address which is not an integral multiple of four. Alignment-check exceptions are generated only in user mode (privilege level 3). Memory references that default to priv ilege level 0, such as segment descriptor loads, do not generate this excep tion even when caused by instructions executed in user-mode.

The alignment-check exception can be used to check alignment of data. This is useful when exchanging data with processors which require all data to be aligned. The alignment-check exception can also be used by interpreters to flag some pointers as special by misaligning the pointer. This eliminates overhead of checking each pointer and only handles the special pointer when used.

VIF Virtual Interrupt (bit 19) — Contains a virtual image of the IF flag. This flag is used in conjunction with the VIP flag. The processor only recognizes the VIF flag when either the VME flag or the PVI flag in control register CR4 is set and the IOPL is less than 3. (The VME flag enables the virtual-8086 mode extensions; the PVI flag enables the protected-mode virtual interrupts.)

See alsoSection 17.3.3.5, “Method 6: Software Interrupt Handling,” and Section 17.4, “Protected-Mode Virtual Interrupts.”
Page 71 of the Intel 253668-032US user manual — 2.4 MEMORY-MANAGEMENT REGISTERS
Page 71 · click to enlarge
Page 71

SYSTEM ARCHITECTURE OVERVIEW

VIP Virtual interrupt pending (bit 20) — Set by software to indicate that an interrupt is pending; cleared to indicate that no interrupt is pending. This flag is used in conjunction with the VIF flag. The processor reads this flag but never modifies it. The processor only recognizes the VIP flag when either the VME flag or the PVI flag in control register CR4 is set and the IOPL is less than 3. The VME flag enables the virtual-8086 mode extensions; the PVI flag enables the protected-mode virtual interrupts.

See Section 17.3.3.5, “Method 6Software Interrupt Handling,” and Section 17.4, “Protected-Mode Virtual Interrupts.”

ID Identification (bit 21). — The ability of a program or procedure to set or clear this flag indicates support for the CPUID instruction.

2.3.1 System Flags and Fields in IA-32e Mode

In 64-bit mode, the RFLAGS register expands to 64 bits with the upper 32 bits reserved. System flags in RFLAGS (64-bit mode) or EFLAGS (compatibility mode) are shown in Figure 2-4.

In IA-32e mode, the processor does not allow the VM bit to be set because virtual- 8086 mode is not supported (attempts to set the bit are ignored). Also, the processor will not set the NT bit. The processor does, however, allow software to set the NT bit (note that an IRET causes a general protection fault in IA-32e mode if the NT bit is set).

In IA-32e mode, the SYSCALL/SYSRET instructions have a programmable method of specifying which bits are cleared in RFLAGS/EFLAGS. These instructions save/restore EFLAGS/RFLAGS.

2.4 MEMORY-MANAGEMENT REGISTERS

The processor provides four memory-management registers (GDTR, LDTR, IDTR, and TR) that specify the locations of the data structures which control segmented memory management (see Figure 2-5). Special instructions are provided for loading and storing these registers.

Page 72 of the Intel 253668-032US user manual — 2.4.2 Local Descriptor Table Register (LDTR)
Page 72 · click to enlarge
Page 72

SYSTEM ARCHITECTURE OVERVIEW

GDTR

32(64)-bit Linear Base Address 16-Bit Table Limit

IDTR

32(64)-bit Linear Base Address

Segment Descriptor Registers (Automatically Loaded)

Seg. Sel.

32(64)-bit Linear Base Address Segment Limit

32(64)-bit Linear Base Address Segment Limit Register

LDTR

Seg. Sel.

Figure 2-5. Memory Management Registers

2.4.1 Global Descriptor Table Register (GDTR)

The GDTR register holds the base address (32 bits in protected mode; 64 bits in IA-32e mode) and the 16-bit table limit for the GDT. The base address specifies the linear address of byte 0 of the GDT; the table limit specifies the number of bytes in the table.

The LGDT and SGDT instructions load and store the GDTR register, respectively. On power up or reset of the processor, the base address is set to the default value of 0 and the limit is set to 0FFFFH. A new base address must be loaded into the GDTR as part of the processor initialization process for protected-mode operation.

See alsoSection 3.5.1, “Segment Descriptor Tables.”

2.4.2 Local Descriptor Table Register (LDTR)

The LDTR register holds the 16-bit segment selector, base address (32 bits in protected mode; 64 bits in IA-32e mode), segment limit, and descriptor attributes for the LDT. The base address specifies the linear address of byte 0 of the LDT segment; the segment limit specifies the number of bytes in the segment. See also: Section 3.5.1, “Segment Descriptor Tables.”

The LLDT and SLDT instructions load and store the segment selector part of the LDTR register, respectively. The segment that contains the LDT must have a segment descriptor in the GDT. When the LLDT instruction loads a segment selector in the LDTR: the base address, limit, and descriptor attributes from the LDT descriptor are automatically loaded in the LDTR.

When a task switch occurs, the LDTR is automatically loaded with the segment selector and descriptor for the LDT for the new task. The contents of the LDTR are not automatically saved prior to writing the new LDT information into the register.

On power up or reset of the processor, the segment selector and base address are set to the default value of 0 and the limit is set to 0FFFFH.

Show 6 more labels / short text on this page
System Table Registers · 0 47(79) · 16-Bit Table Limit · System Segment · Attributes Registers · 0 Task
Page 73 of the Intel 253668-032US user manual — 2.5 CONTROL REGISTERS
Page 73 · click to enlarge
Page 73

SYSTEM ARCHITECTURE OVERVIEW

2.4.3 IDTR Interrupt Descriptor Table Register

The IDTR register holds the base address (32 bits in protected mode; 64 bits in IA-32e mode) and 16-bit table limit for the IDT. The base address specifies the linear address of byte 0 of the IDT; the table limit specifies the number of bytes in the table. The LIDT and SIDT instructions load and store the IDTR register, respectively. On power up or reset of the processor, the base address is set to the default value of 0 and the limit is set to 0FFFFH. The base address and limit in the register can then be changed as part of the processor initialization process.

See alsoSection 6.10, “Interrupt Descriptor Table (IDT).”

2.4.4 Task Register (TR)

The task register holds the 16-bit segment selector, base address (32 bits in protected mode; 64 bits in IA-32e mode), segment limit, and descriptor attributes for the TSS of the current task. The selector references the TSS descriptor in the GDT. The base address specifies the linear address of byte 0 of the TSS; the segment limit specifies the number of bytes in the TSS. See also: Section 7.2.4, “Task Register.”

The LTR and STR instructions load and store the segment selector part of the task register, respectively. When the LTR instruction loads a segment selector in the task register, the base address, limit, and descriptor attributes from the TSS descriptor are automatically loaded into the task register. On power up or reset of the processor, the base address is set to the default value of 0 and the limit is set to 0FFFFH.

When a task switch occurs, the task register is automatically loaded with the segment selector and descriptor for the TSS for the new task. The contents of the task register are not automatically saved prior to writing the new TSS information into the register.

2.5 CONTROL REGISTERS

Control registers (CR0, CR1, CR2, CR3, and CR4; see Figure 2-6) determine oper ating mode of the processor and the characteristics of the currently executing task. These registers are 32 bits in all 32-bit modes and compatibility mode.

  • In 64-bit mode, control registers are expanded to 64 bits. The MOV CRn instructions are used to manipulate the register bits. Operand-size prefixes for these instructions are ignored. The following is also true:
  • Bits 63:32 of CR0 and CR4 are reserved and must be written with zeros. Writing a nonzero value to any of the upper 32 bits results in a general-protection exception, #GP(0).
  • All 64 bits of CR2 are writable by software.
  • Bits 51:40 of CR3 are reserved and must be 0.
Page 74 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 74 · click to enlarge
Page 74

SYSTEM ARCHITECTURE OVERVIEW

  • The MOV CRn instructions do not check that addresses written to CR2 and CR3 are within the linear-address or physical-address limitations of the implemen tation.
  • Register CR8 is available in 64-bit mode only.
  • The control registers are summarized below, and each architecturally defined control field in these control registers are described individually. In Figure 2-6, the width of the register in 64-bit mode is indicated in parenthesis (except for CR0).
  • CR0 — Contains system control flags that control operating mode and states of the processor.
  • CR1 — Reserved.
  • CR2 — Contains the page-fault linear address (the linear address that caused a page fault).
  • CR3 — Contains the physical address of the base of the paging-structure hierarchy and two flags (PCD and PWT). Only the most-significant bits (less the lower 12 bits) of the base address are specified; the lower 12 bits of the address are assumed to be 0. The first paging structure must thus be aligned to a page (4-KByte) boundary. The PCD and PWT flags control caching of that paging structure in the processor’s internal data caches (they do not control TLB caching of page-directory information).

When using the physical address extension, the CR3 register contains the base address of the page-directory-pointer table In IA-32e mode, the CR3 register contains the base address of the PML4 table.

  • See also: Chapter 4, “Paging.”
  • CR4 — Contains a group of flags that enable several architectural extensions, and indicate operating system or executive support for specific processor capabil ities. The control registers can be read and loaded (or modified) using the moveto-or-from-control-registers forms of the MOV instruction. In protected mode, the MOV instructions allow the control registers to be read or loaded (at privilege level 0 only). This restriction means that application programs or operatingsystem procedures (running at privilege levels 1, 2, or 3) are prevented from reading or loading the control registers.
  • CR8 — Provides read and write access to the Task Priority Register (TPR). It specifies the priority threshold value that operating systems use to control the priority class of external interrupts allowed to interrupt the processor. This register is available only in 64-bit mode. However, interrupt filtering continues to apply in compatibility mode.
Page 75 of the Intel 253668-032US user manual — N W P G
Page 75 · click to enlarge
Page 75

SYSTEM ARCHITECTURE OVERVIEW

31(63) 9 8 7 6 5 4 3 2 1 0

13 12 11 10

E X M S

V M X E

P C E

P G E

M C E

P A E

P S E

T S D

P V

V M E

Reserved (set to 0)

D E

CR4

OSXSAVE

OSFXSR OSXMMEXCPT

31(63) 12 11 5 4 3 2

P C D

P W

CR3

T

(PDBR)

CR2

CR1

31 29 30 28 19 18 17 16 15 6 5 4 3 2 1 0

N W P G

C D

P A M

W

M P T S N E

E T

P E E M

CR0

Figure 2-6. Control Registers

When loading a control register, reserved bits should always be set to the values previously read. The flags in control registers are:

PG Paging (bit 31 of CR0) — Enables paging when set; disables paging when clear. When paging is disabled, all linear addresses are treated as physical addresses. The PG flag has no effect if the PE flag (bit 0 of register CR0) is not also set; setting the PG flag when the PE flag is clear causes a general- protection exception (#GP). See also: Chapter 4, “Paging.”

On Intel 64 processors, enabling and disabling IA-32e mode operation also requires modifying CR0.PG.

CD Cache Disable (bit 30 of CR0) — When the CD and NW flags are clear, caching of memory locations for the whole of physical memory in the processor’s internal (and external) caches is enabled. When the CD flag is set, caching is restricted as described in Table 11-5. To prevent the processor from accessing and updating its caches, the CD flag must be set and the caches must be invalidated so that no cache hits can occur.

Show 5 more labels / short text on this page
Page-Directory Base · 31(63) 0 · Page-Fault Linear Address · 31(63) 0 · Reserved
Page 76 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 76 · click to enlarge
Page 76

SYSTEM ARCHITECTURE OVERVIEW

See alsoSection 11.5.3, “Preventing Caching,” and Section 11.5, “Cache Control.”

NW Not Write-through (bit 29 of CR0) — When the NW and CD flags are clear, write-back (for Pentium 4, Intel Xeon, P6 family, and Pentium proces sors) or write-through (for Intel486 processors) is enabled for writes that hit the cache and invalidation cycles are enabled. See Table 11-5 for detailed information about the affect of the NW flag on caching for other settings of the CD and NW flags.

AM Alignment Mask (bit 18 of CR0) — Enables automatic alignment checking when set; disables alignment checking when clear. Alignment checking is performed only when the AM flag is set, the AC flag in the EFLAGS register is set, CPL is 3, and the processor is operating in either protected or virtual- 8086 mode.

WP Write Protect (bit 16 of CR0) — When set, inhibits supervisor-level proce dures from writing into read-only pages; when clear, allows supervisor-level procedures to write into read-only pages (regardless of the U/S bit setting; see Section 4.1.3 and Section 4.6). This flag facilitates implementation of the copy-on-write method of creating a new process (forking) used by operating systems such as UNIX.

NE Numeric Error (bit 5 of CR0) — Enables the native (internal) mechanism for reporting x87 FPU errors when set; enables the PC-style x87 FPU error reporting mechanism when clear. When the NE flag is clear and the IGNNE# input is asserted, x87 FPU errors are ignored. When the NE flag is clear and the IGNNE# input is deasserted, an unmasked x87 FPU error causes the processor to assert the FERR# pin to generate an external interrupt and to stop instruction execution immediately before executing the next waiting floating-point instruction or WAIT/FWAIT instruction.

The FERR# pin is intended to drive an input to an external interrupt controller (the FERR# pin emulates the ERROR# pin of the Intel 287 and Intel 387 DX math coprocessors). The NE flag, IGNNE# pin, and FERR# pin are used with external logic to implement PC-style error reporting. Using FERR# and IGNNE# to handle floating-point exceptions is deprecated by modern operating systems; this non-native approach also limits newer processors to operate with one logical processor active.

See also: “Software Exception Handling” in Chapter 8, “Programming with the x87 FPU,” and Appendix A, “EFLAGS Cross-Reference,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1.

ET Extension Type (bit 4 of CR0) — Reserved in the Pentium 4, Intel Xeon, P6 family, and Pentium processors. In the Pentium 4, Intel Xeon, and P6 family processors, this flag is hardcoded to 1. In the Intel386 and Intel486 proces sors, this flag indicates support of Intel 387 DX math coprocessor instruc tions when set.

TS Task Switched (bit 3 of CR0) — Allows the saving of the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 context on a task switch to be

Page 77 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 77 · click to enlarge
Page 77

SYSTEM ARCHITECTURE OVERVIEW

  • delayed until an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed by the new task. The processor sets this flag on every task switch and tests it when executing x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions.
  • If the TS flag is set and the EM flag (bit 2 of CR0) is clear, a device-notavailable exception (#NM) is raised prior to the execution of any x87 FPU/MMX/SSE/ SSE2/SSE3/SSSE3/SSE4 instruction; with the exception of PAUSE, PREFETCH h , SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32, and POPCNT. See the paragraph below for the special case of the WAIT/FWAIT instructions.
  • If the TS flag is set and the MP flag (bit 1 of CR0) and EM flag are clear, an #NM exception is not raised prior to the execution of an x87 FPU WAIT/FWAIT instruction.
  • If the EM flag is set, the setting of the TS flag has no affect on the execution of x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions.

Table 2-1 shows the actions taken when the processor encounters an x87 FPU instruction based on the settings of the TS, EM, and MP flags. Table 12-1 and 13-1 show the actions taken when the processor encounters an MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction.

The processor does not automatically save the context of the x87 FPU, XMM, and MXCSR registers on a task switch. Instead, it sets the TS flag, which causes the processor to raise an #NM exception whenever it encounters an x87 FPU/MMX/SSE /SSE2/SSE3/SSSE3/SSE4 instruction in the instruction stream for the new task (with the exception of the instructions listed above).

The fault handler for the #NM exception can then be used to clear the TS flag (with the CLTS instruction) and save the context of the x87 FPU, XMM, and MXCSR regis ters. If the task never encounters an x87 FPU/MMX/SSE/SSE2/SSE3//SSSE3/SSE4 instruction; the x87 FPU/MMX/SSE/SSE2/ SSE3/SSSE3/SSE4 context is never saved.

Table 2-1. Action Taken By x87 FPU Instructions for Different

Combinations of EM, MP, and TS

CR0 Flags x87 FPU Instruction Type

EM MP TS Floating-Point WAIT/FWAIT

0 0 0 Execute Execute.

0 0 1 #NM Exception Execute.

0 1 0 Execute Execute.

0 1 1 #NM Exception #NM exception.

1 0 0 #NM Exception Execute.

1 0 1 #NM Exception Execute.

1 1 0 #NM Exception Execute.

Page 78 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 78 · click to enlarge
Page 78

SYSTEM ARCHITECTURE OVERVIEW

Table 2-1. Action Taken By x87 FPU Instructions for Different

Combinations of EM, MP, and TS

CR0 Flags x87 FPU Instruction Type

1 1 1 #NM Exception #NM exception.

EM Emulation (bit 2 of CR0) — Indicates that the processor does not have an internal or external x87 FPU when set; indicates an x87 FPU is present when clear. This flag also affects the execution of MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instructions.

When the EM flag is set, execution of an x87 FPU instruction generates a device-not-available exception (#NM). This flag must be set when the processor does not have an internal x87 FPU or is not connected to an external math coprocessor. Setting this flag forces all floating-point instruc tions to be handled by software emulation. Table 9-2 shows the recom mended setting of this flag, depending on the IA-32 processor and x87 FPU or math coprocessor present in the system. Table 2-1 shows the interaction of the EM, MP, and TS flags.

Also, when the EM flag is set, execution of an MMX instruction causes an invalid-opcode exception (#UD) to be generated (see Table 12-1). Thus, if an IA-32 or Intel 64 processor incorporates MMX technology, the EM flag must be set to 0 to enable execution of MMX instructions.

Similarly for SSE/SSE2/SSE3/SSSE3/SSE4 extensions, when the EM flag is set, execution of most SSE/SSE2/SSE3/SSSE3/SSE4 instructions causes an invalid opcode exception (#UD) to be generated (see Table 13-1). If an IA-32 or Intel 64 processor incorporates the SSE/SSE2/SSE3/SSSE3/SSE4 exten sions, the EM flag must be set to 0 to enable execution of these extensions. SSE/SSE2/SSE3/SSSE3/SSE4 instructions not affected by the EM flag include: PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32, and POPCNT.

MP Monitor Coprocessor (bit 1 of CR0). — Controls the interaction of the WAIT (or FWAIT) instruction with the TS flag (bit 3 of CR0). If the MP flag is set, a WAIT instruction generates a device-not-available exception (#NM) if the TS flag is also set. If the MP flag is clear, the WAIT instruction ignores the setting of the TS flag. Table 9-2 shows the recommended setting of this flag, depending on the IA-32 processor and x87 FPU or math coprocessor present in the system. Table 2-1 shows the interaction of the MP, EM, and TS flags.

PE Protection Enable (bit 0 of CR0) — Enables protected mode when set; enables real-address mode when clear. This flag does not enable paging directly. It only enables segment-level protection. To enable paging, both the PE and PG flags must be set.

See alsoSection 9.9, “Mode Switching.”

PCD Page-level Cache Disable (bit 4 of CR3) — Controls caching of the first paging structure of the current paging-structure hierarchy. When the PCD

Page 79 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 79 · click to enlarge
Page 79

SYSTEM ARCHITECTURE OVERVIEW

flag is set, caching of the page-directory is prevented; when the flag is clear, the page-directory can be cached. This flag affects only the processor’s internal caches (both L1 and L2, when present). The processor ignores this flag if paging is not used (the PG flag in register CR0 is clear) or the CD (cache disable) flag in CR0 is set.

See also: Chapter 11, “Memory Cache Control” (for more about the use of the PCD flag) and Section 4.9, “Paging and Memory Typing” (for a discussion of a companion PCD flag in page-directory and page-table entries).

PWT Page-level Write-Through (bit 3 of CR3) — Controls the write-through or write-back caching policy of the first paging structure of the current paging- structure hierarchy. When the PWT flag is set, write-through caching is enabled; when the flag is clear, write-back caching is enabled. This flag affects only internal caches (both L1 and L2, when present). The processor ignores this flag if paging is not used (the PG flag in register CR0 is clear) or the CD (cache disable) flag in CR0 is set.

See also: Section 11.5, “Cache Control” (for more information about the use of this flag), and Section 4.9, “Paging and Memory Typing” (for a discussion of a companion PCD flag in the page-directory and page-table entries).

VME Virtual-8086 Mode Extensions (bit 0 of CR4) — Enables interrupt- and exception-handling extensions in virtual-8086 mode when set; disables the extensions when clear. Use of the virtual mode extensions can improve the performance of virtual-8086 applications by eliminating the overhead of calling the virtual-8086 monitor to handle interrupts and exceptions that occur while executing an 8086 program and, instead, redirecting the inter rupts and exceptions back to the 8086 program’s handlers. It also provides hardware support for a virtual interrupt flag (VIF) to improve reliability of running 8086 programs in multitasking and multiple-processor environ ments.

See alsoSection 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode.”

PVI Protected-Mode Virtual Interrupts (bit 1 of CR4) — Enables hardware support for a virtual interrupt flag (VIF) in protected mode when set; disables the VIF flag in protected mode when clear.

See alsoSection 17.4, “Protected-Mode Virtual Interrupts.”

TSD Time Stamp Disable (bit 2 of CR4) — Restricts the execution of the RDTSC instruction (including RDTSCP instruction if CPUID.80000001H:EDX[27] = 1) to procedures running at privilege level 0 when set; allows RDTSC instruction (including RDTSCP instruction if CPUID.80000001H:EDX[27] = 1) to be executed at any privilege level when clear.

DE Debugging Extensions (bit 3 of CR4) — References to debug registers DR4 and DR5 cause an undefined opcode (#UD) exception to be generated

Page 80 of the Intel 253668-032US user manual — OSFXSR
Page 80 · click to enlarge
Page 80

SYSTEM ARCHITECTURE OVERVIEW

when set; when clear, processor aliases references to registers DR4 and DR5 for compatibility with software written to run on earlier IA-32 processors.

See alsoSection 16.2.2, “Debug Registers DR4 and DR5.”

PSE Page Size Extensions (bit 4 of CR4) — Enables 4-MByte pages with 32-bit paging when set; restricts 32-bit paging to pages to 4 KBytes when clear.

See alsoSection 4.3, “32-Bit Paging.”

PAE Physical Address Extension (bit 5 of CR4) — When set, enables paging to produce physical addresses with more than 32 bits. When clear, restricts physical addresses to 32 bits. PAE must be set before entering IA-32e mode.

See alsoChapter 4, “Paging.”

MCE Machine-Check Enable (bit 6 of CR4) — Enables the machine-check exception when set; disables the machine-check exception when clear.

See alsoChapter 15, “Machine-Check Architecture.”

PGE Page Global Enable (bit 7 of CR4) — (Introduced in the P6 family proces sors.) Enables the global page feature when set; disables the global page feature when clear. The global page feature allows frequently used or shared pages to be marked as global to all users (done with the global flag, bit 8, in a page-directory or page-table entry). Global pages are not flushed from the translation-lookaside buffer (TLB) on a task switch or a write to register CR3.

When enabling the global page feature, paging must be enabled (by setting the PG flag in control register CR0) before the PGE flag is set. Reversing this sequence may affect program correctness, and processor performance will be impacted.

See alsoSection 4.10, “Caching Translation Information.”

PCE Performance-Monitoring Counter Enable (bit 8 of CR4) — Enables execution of the RDPMC instruction for programs or procedures running at any protection level when set; RDPMC instruction can be executed only at protection level 0 when clear.

OSFXSR

Operating System Support for FXSAVE and FXRSTOR instructions (bit 9 of CR4) — When set, this flag: (1) indicates to software that the oper ating system supports the use of the FXSAVE and FXRSTOR instructions, (2) enables the FXSAVE and FXRSTOR instructions to save and restore the contents of the XMM and MXCSR registers along with the contents of the x87 FPU and MMX registers, and (3) enables the processor to execute SSE/SSE2/SSE3/SSSE3/SSE4 instructions, with the exception of the PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32, and POPCNT.

If this flag is clear, the FXSAVE and FXRSTOR instructions will save and restore the contents of the x87 FPU and MMX instructions, but they may not save and restore the contents of the XMM and MXCSR registers. Also, the

Page 81 of the Intel 253668-032US user manual — OSXSAVE
Page 81 · click to enlarge
Page 81

SYSTEM ARCHITECTURE OVERVIEW

processor will generate an invalid opcode exception (#UD) if it attempts to execute any SSE/SSE2/SSE3and instruction, with the exception of PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, CLFLUSH, CRC32, and POPCNT. The operating system or executive must explicitly set this flag.

NOTE

CPUID feature flags FXSR indicates availability of the FXSAVE/FXRSTOR instructions. The OSFXSR bit provides operating system software with a means of enabling FXSAVE/FXRSTOR to save/restore the contents of the X87 FPU, XMM and MXCSR registers. Consequently OSFXSR bit indicates that the operating system provides context switch support for SSE/SSE2/SSE3/SSSE3/SSE4.

OSXMMEXCPT

Operating System Support for Unmasked SIMD Floating-Point Excep tions (bit 10 of CR4) — When set, indicates that the operating system supports the handling of unmasked SIMD floating-point exceptions through an exception handler that is invoked when a SIMD floating-point exception (#XF) is generated. SIMD floating-point exceptions are only generated by SSE/SSE2/SSE3/SSE4.1 SIMD floating-point instructions.

The operating system or executive must explicitly set this flag. If this flag is not set, the processor will generate an invalid opcode exception (#UD) whenever it detects an unmasked SIMD floating-point exception.

VMXE

VMX-Enable Bit (bit 13 of CR4) — Enables VMX operation when set. See Chapter 20, “Introduction to Virtual-Machine Extensions.”

SMXE

SMX-Enable Bit (bit 14 of CR4) — Enables SMX operation when set. See Chapter 6, “Safer Mode Extensions Reference” of Intel® 64 and IA-32 Archi tectures Software Developer’s Manual, Volume 2B.

OSXSAVE

XSAVE and Processor Extended States-Enable Bit (bit 18 of CR4) — When set, this flag: (1) indicates (via CPUID.01H:ECX.OSXSAVE[bit 27]) that the operating system supports the use of the XGETBV, XSAVE and XRSTOR instructions by general software; (2) enables the XSAVE and XRSTOR instructions to save and restore the x87 FPU state (including MMX registers), the SSE state (XMM registers and MXCSR), along with other processor extended states enabled in the XFEATURE_ENABLED_MASK register (XCR0); (3) enables the processor to execute XGETBV and XSETBV instructions in order to read and write XCR0. See Section 2.6 and Chapter 13, “System Programming for Instruction Set Extensions and Processor Extended States”.

TPL Task Priority Level (bit 3:0 of CR8) — This sets the threshold value corre sponding to the highest-priority interrupt to be blocked. A value of 0 means

Page 82 of the Intel 253668-032US user manual — 2.6 EXTENDED CONTROL REGISTERS (INCLUDING THE XFEATURE_ENABLED_MASK REGISTER)
Page 82 · click to enlarge
Page 82

SYSTEM ARCHITECTURE OVERVIEW

all interrupts are enabled. This field is available in 64-bit mode. A value of 15 means all interrupts will be disabled.

2.5.1 CPUID Qualification of Control Register Flags

The VME, PVI, TSD, DE, PSE, PAE, MCE, PGE, PCE, OSFXSR, and OSXMMEXCPT flags in control register CR4 are model specific. All of these flags (except the PCE flag) can be qualified with the CPUID instruction to determine if they are implemented on the processor before they are used.

The CR8 register is available on processors that support Intel 64 architecture.

2.6 EXTENDED CONTROL REGISTERS (INCLUDING THE XFEATURE_ENABLED_MASK REGISTER)

If CPUID.01H:ECX.XSAVE[bit 26] is 1, the processor supports one or more extended control registers (XCRs). Currently, the only such register defined is XCR0, the XFEATURE_ENABLED_MASK register. This register specifies the set of processor states that the operating system enables on that processor, e.g. x87 FPU States, SSE states, and other processor extended states that Intel 64 architecture may introduce in the future. The OS programs XCR0 to reflect the features it supports.

Reserved for XCR0 bit vector expansion Reserved / Future processor extended states

x87 FPU/MMX state (must be 1)

Reserved (must be 0)

Figure 2-7. XFEATURE_ENABLED_MASK Register (XCR0)

Software can access XCR0 only if CR4.OSXSAVE[bit 18] = 1. (This bit is also readable as CPUID.01H:ECX.OSXSAVE[bit 27].) The layout of XCR0 is architected to allow software to use CPUID leaf function 0DH to enumerate the set of bits that the processor supports in XCR0 (see CPUID instruction in Intel® 64 and IA-32 Architec tures Software Developer’s Manual, Volume 2A). Each processor state (X87 FPU

SSE state

Page 83 of the Intel 253668-032US user manual — 2.7 SYSTEM INSTRUCTION SUMMARY
Page 83 · click to enlarge
Page 83

SYSTEM ARCHITECTURE OVERVIEW

state, SSE state, or a future processor extended state) is represented by a bit in XCR0. The OS can enable future processor extended states in a forward manner by specifying the appropriate bit mask value using the XSETBV instruction according to the results of the CPUID leaf 0DH.

With the exception of bit 63, each bit in the XFEATURE_ENABLED_MASK register (XCR0) corresponds to a subset of the processor states. XCR0 thus provides space for up to 63 sets of processor state extensions. Bit 63 of XCR0 is reserved for future expansion and will not represent a processor extended state.

  • Currently, the XFEATURE_ENABLED_MASK register (XCR0) has two processor states defined, with up to 61 bits reserved for future processor extended states:
  • XCR0.X87 (bit 0): If 1, indicates x87 FPU state (including MMX register states) is supported in the processor. Bit 0 must be 1. An attempt to write 0 causes a #GP exception.
  • XCR0.SSE (bit 1): If 1, indicates MXCSR and XMM registers (XMM0-XMM15 in 64bit mode, otherwise XMM0-XMM7) are supported by XSAVE/XRESTOR in the processor.

Any attempt to set a reserved bit (as determined by the contents of EAX and EDX after executing CPUID with EAX=0DH, ECX= 0H) in the XFEATURE_ENABLED_MASK register for a given processor will result in a #GP exception. An attempt to write 0 to XFEATURE_ENABLED_MASK.x87 (bit 0) will result in a #GP exception.

If a bit in the XFEATURE_ENABLED_MASK register is 1, XSAVE instruction can selec tively (in conjunction with a save mask) save a partial or full set of processor states to memory (See XSAVE instruction in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B).

After reset all bits (except bit 0) in the XFEATURE_ENABLED_MASK register (XCR0) are cleared to zero. XCR0[0] is set to 1.

2.7 SYSTEM INSTRUCTION SUMMARY

System instructions handle system-level functions such as loading system registers, managing the cache, managing interrupts, or setting up the debug registers. Many of these instructions can be executed only by operating-system or executive proce dures (that is, procedures running at privilege level 0). Others can be executed at any privilege level and are thus available to application programs.

Table 2-2 lists the system instructions and indicates whether they are available and useful for application programs. These instructions are described in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B.

Table 2-2. Summary of System Instructions

LLDT Load LDT Register No Yes

Show 4 more labels / short text on this page
Instruction · Description · Useful to Application? · Protected from Application?
Page 84 of the Intel 253668-032US user manual — SYSTEM ARCHITECTURE OVERVIEW
Page 84 · click to enlarge
Page 84

SYSTEM ARCHITECTURE OVERVIEW

Table 2-2. Summary of System Instructions (Contd.)

SLDT Store LDT Register No No

LGDT Load GDT Register No Yes

SGDT Store GDT Register No No

LTR Load Task Register No Yes

STR Store Task Register No No

LIDT Load IDT Register No Yes

SIDT Store IDT Register No No

MOV CRn Load and store control registers No Yes

SMSW Store MSW Yes No

LMSW Load MSW No Yes

CLTS Clear TS flag in CR0 No Yes

ARPL Adjust RPL Yes1, 5 No

LAR Load Access Rights Yes No

LSL Load Segment Limit Yes No

VERR Verify for Reading Yes No

VERW Verify for Writing Yes No

MOV DRn Load and store debug registers No Yes

INVD Invalidate cache, no writeback No Yes

WBINVD Invalidate cache, with writeback No Yes

INVLPG Invalidate TLB entry No Yes

HLT Halt Processor No Yes

LOCK (Prefix) Bus Lock Yes No

RSM Return from system management mode

RDMSR3 Read Model-Specific Registers No Yes

WRMSR3 Write Model-Specific Registers No Yes

RDPMC4 Read Performance-Monitoring Counter

RDTSC3 Read Time-Stamp Counter Yes Yes2

RDTSCP7 Read Serialized Time-Stamp Counter Yes Yes2

Show 6 more labels / short text on this page
Instruction · Description · Useful to Application? · Protected from Application? · No Yes · Yes Yes2
Page 85 of the Intel 253668-032US user manual — 2.7.1 Loading and Storing System Registers
Page 85 · click to enlarge
Page 85

SYSTEM ARCHITECTURE OVERVIEW

Table 2-2. Summary of System Instructions (Contd.)

XGETBV Return the state of the the XFEATURE_ENABLED_MASK register

XSETBV Enable one or more processor extended states

NOTES: 1. Useful to application programs running at a CPL of 1 or 2. 2. The TSD and PCE flags in control register CR4 control access to these instructions by application programs running at a CPL of 3. 3. These instructions were introduced into the IA-32 Architecture with the Pentium processor. 4. This instruction was introduced into the IA-32 Architecture with the Pentium Pro processor and the Pentium processor with MMX technology. 5. This instruction is not supported in 64-bit mode. 6. Application uses XGETBV to query which set of processor extended states are enabled. 7. RDTSCP is introduced in Intel Core i7 processor.

2.7.1 Loading and Storing System Registers

  • The GDTR, LDTR, IDTR, and TR registers each have a load and store instruction for loading data into and storing data from the register:
  • LGDT (Load GDTR Register) — Loads the GDT base address and limit from memory into the GDTR register.
  • SGDT (Store GDTR Register) — Stores the GDT base address and limit from the GDTR register into memory.
  • LIDT (Load IDTR Register) — Loads the IDT base address and limit from memory into the IDTR register.
  • SIDT (Load IDTR Register — Stores the IDT base address and limit from the IDTR register into memory.
  • LLDT (Load LDT Register) — Loads the LDT segment selector and segment descriptor from memory into the LDTR. (The segment selector operand can also be located in a general-purpose register.)
  • SLDT (Store LDT Register) — Stores the LDT segment selector from the LDTR register into memory or a general-purpose register.
  • LTR (Load Task Register) — Loads segment selector and segment descriptor for a TSS from memory into the task register. (The segment selector operand can also be located in a general-purpose register.)
  • STR (Store Task Register) — Stores the segment selector for the current task TSS from the task register into memory or a general-purpose register.
Show 6 more labels / short text on this page
Instruction · Description · Useful to Application? · Protected from Application? · Yes No · No6 Yes
Page 86 of the Intel 253668-032US user manual — 2.7.2 Verifying of Access Privileges
Page 86 · click to enlarge
Page 86

SYSTEM ARCHITECTURE OVERVIEW

The LMSW (load machine status word) and SMSW (store machine status word) instructions operate on bits 0 through 15 of control register CR0. These instructions are provided for compatibility with the 16-bit Intel 286 processor. Programs written to run on 32-bit IA-32 processors should not use these instructions. Instead, they should access the control register CR0 using the MOV instruction.

The CLTS (clear TS flag in CR0) instruction is provided for use in handling a device-not-available exception (#NM) that occurs when the processor attempts to execute a floating-point instruction when the TS flag is set. This instruction allows the TS flag to be cleared after the x87 FPU context has been saved, preventing further #NM exceptions. See Section 2.5, “Control Registers,” for more information on the TS flag.

The control registers (CR0, CR1, CR2, CR3, CR4, and CR8) are loaded using the MOV instruction. The instruction loads a control register from a general-purpose register or stores the content of a control register in a general-purpose register.

2.7.2 Verifying of Access Privileges

The processor provides several instructions for examining segment selectors and segment descriptors to determine if access to their associated segments is allowed. These instructions duplicate some of the automatic access rights and type checking done by the processor, thus allowing operating-system or executive software to prevent exceptions from being generated.

The ARPL (adjust RPL) instruction adjusts the RPL (requestor privilege level) of a segment selector to match that of the program or procedure that supplied the segment selector. See Section 5.10.4, “Checking Caller Access Privileges (ARPL Instruction),” for a detailed explanation of the function and use of this instruction. Note that ARPL is not supported in 64-bit mode.

The LAR (load access rights) instruction verifies the accessibility of a speci fied segment and loads access rights information from the segment’s segment descriptor into a general-purpose register. Software can then examine the access rights to determine if the segment type is compatible with its intended use. See Section 5.10.1, “Checking Access Rights (LAR Instruction),” for a detailed explanation of the function and use of this instruction.

The LSL (load segment limit) instruction verifies the accessibility of a speci fied segment and loads the segment limit from the segment’s segment descriptor into a general-purpose register. Software can then compare the segment limit with an offset into the segment to determine whether the offset lies within the segment. See Section 5.10.3, “Checking That the Pointer Offset Is Within Limits (LSL Instruction),” for a detailed explanation of the function and use of this instruction.

The VERR (verify for reading) and VERW (verify for writing) instructions verify if a selected segment is readable or writable, respectively, at a given CPL. See Section 5.10.2, “Checking Read/Write Rights (VERR and VERW

Page 87 of the Intel 253668-032US user manual — 2.7.5 Controlling the Processor
Page 87 · click to enlarge
Page 87

SYSTEM ARCHITECTURE OVERVIEW

Instructions),” for a detailed explanation of the function and use of this instruction.

2.7.3 Loading and Storing Debug Registers

Internal debugging facilities in the processor are controlled by a set of 8 debug regis ters (DR0-DR7). The MOV instruction allows setup data to be loaded to and stored from these registers.

On processors that support Intel 64 architecture, debug registers DR0-DR7 are 64 bits. In 32-bit modes and compatibility mode, writes to a debug register fill the upper 32 bits with zeros. Reads return the lower 32 bits. In 64-bit mode, the upper 32 bits of DR6-DR7 are reserved and must be written with zeros. Writing one to any of the upper 32 bits causes an exception, #GP(0).

In 64-bit mode, MOV DRn instructions read or write all 64 bits of a debug register (operand-size prefixes are ignored). All 64 bits of DR0-DR3 are writable by software. However, MOV DRn instructions do not check that addresses written to DR0-DR3 are in the limits of the implementation. Address matching is supported only on valid addresses generated by the processor implementation.

2.7.4 Invalidating Caches and TLBs

The processor provides several instructions for use in explicitly invalidating its caches and TLB entries. The INVD (invalidate cache with no writeback) instruction invali dates all data and instruction entries in the internal caches and sends a signal to the external caches indicating that they should be also be invalidated.

The WBINVD (invalidate cache with writeback) instruction performs the same func tion as the INVD instruction, except that it writes back modified lines in its internal caches to memory before it invalidates the caches. After invalidating the internal caches, WBINVD signals external caches to write back modified data and invalidate their contents.

The INVLPG (invalidate TLB entry) instruction invalidates (flushes) the TLB entry for a specified page.

2.7.5 Controlling the Processor

The HLT (halt processor) instruction stops the processor until an enabled interrupt (such as NMI or SMI, which are normally enabled), a debug exception, the BINIT# signal, the INIT# signal, or the RESET# signal is received. The processor generates a special bus cycle to indicate that the halt mode has been entered.

Hardware may respond to this signal in a number of ways. An indicator light on the front panel may be turned on. An NMI interrupt for recording diagnostic information may be generated. Reset initialization may be invoked (note that the BINIT# pin was

Page 88 of the Intel 253668-032US user manual — 2.7.6 Reading Performance-Monitoring and Time-Stamp Counters
Page 88 · click to enlarge
Page 88

SYSTEM ARCHITECTURE OVERVIEW

introduced with the Pentium Pro processor). If any non-wake events are pending during shutdown, they will be handled after the wake event from shutdown is processed (for example, A20M# interrupts).

  • The LOCK prefix invokes a locked (atomic) read-modify-write operation when modi fying a memory operand. This mechanism is used to allow reliable communications between processors in multiprocessor systems, as described below:
  • In the Pentium processor and earlier IA-32 processors, the LOCK prefix causes the processor to assert the LOCK# signal during the instruction. This always causes an explicit bus lock to occur.
  • In the Pentium 4, Intel Xeon, and P6 family processors, the locking operation is handled with either a cache lock or bus lock. If a memory access is cacheable and affects only a single cache line, a cache lock is invoked and the system bus and the actual memory location in system memory are not locked during the operation. Here, other Pentium 4, Intel Xeon, or P6 family processors on the bus write-back any modified data and invalidate their caches as necessary to maintain system memory coherency. If the memory access is not cacheable and/or it crosses a cache line boundary, the processor’s LOCK# signal is asserted and the processor does not respond to requests for bus control during the locked operation.

The RSM (return from SMM) instruction restores the processor (from a context dump) to the state it was in prior to an system management mode (SMM) interrupt.

2.7.6 Reading Performance-Monitoring and Time-Stamp Counters

The RDPMC (read performance-monitoring counter) and RDTSC (read time-stamp counter) instructions allow application programs to read the processor’s perfor mance-monitoring and time-stamp counters, respectively. Processors based on Intel NetBurst microarchitecture have eighteen 40-bit performance-monitoring counters; P6 family processors have two 40-bit counters. Intel Atom processors and most of the processors based on the Intel Core microarchitecture support two types of performance monitoring counters: two programmable performance counters similar to those available in the P6 family, and three fixed-function performance monitoring counters.

The programmable performance counters can support counting either the occurrence or duration of events. Events that can be monitored on programmable counters generally are model specific (except for architectural performance events enumer ated by CPUID leaf 0AH); they may include the number of instructions decoded, interrupts received, or the number of cache loads. Individual counters can be set up to monitor different events. Use the system instruction WRMSR to set up values in IA32_PERFEVTSEL0/1 (for Intel Atom, Intel Core 2, Intel Core Duo, and Intel Pentium M processors), in one of the 45 ESCRs and one of the 18 CCCR MSRs (for Pentium 4 and Intel Xeon processors); or in the PerfEvtSel0 or the PerfEvtSel1 MSR (for the P6 family processors). The RDPMC instruction loads the current count from the selected counter into the EDX:EAX registers.

Page 89 of the Intel 253668-032US user manual — 2.7.7 Reading and Writing Model-Specific Registers
Page 89 · click to enlarge
Page 89

SYSTEM ARCHITECTURE OVERVIEW

Fixed-function performance counters record only specific events that are defined in Chapter 20, “Introduction to Virtual-Machine Extensions”, and the width/number of fixed-function counters are enumerated by CPUID leaf 0AH.

The time-stamp counter is a model-specific 64-bit counter that is reset to zero each time the processor is reset. If not reset, the counter will increment ~9.5 x 1016

times per year when the processor is operating at a clock rate of 3GHz. At this clock frequency, it would take over 190 years for the counter to wrap around. The RDTSC instruction loads the current count of the time-stamp counter into the EDX:EAX registers.

See Section 30.1, “Performance Monitoring Overview,” and Section 16.11, “Time- Stamp Counter,” for more information about the performance monitoring and time- stamp counters.

The RDTSC instruction was introduced into the IA-32 architecture with the Pentium processor. The RDPMC instruction was introduced into the IA-32 architecture with the Pentium Pro processor and the Pentium processor with MMX technology. Earlier Pentium processors have two performance-monitoring counters, but they can be read only with the RDMSR instruction, and only at privilege level 0.

2.7.6.1 Reading Counters in 64-Bit Mode

In 64-bit mode, RDTSC operates the same as in protected mode. The count in the time-stamp counter is stored in EDX:EAX (or RDX[31:0]:RAX[31:0] with RDX[63:32]:RAX[63:32] cleared).

RDPMC requires an index to specify the offset of the performance-monitoring counter. In 64-bit mode for Pentium 4 or Intel Xeon processor families, the index is specified in ECX[30:0]. The current count of the performance-monitoring counter is stored in EDX:EAX (or RDX[31:0]:RAX[31:0] with RDX[63:32]:RAX[63:32] cleared).

2.7.7 Reading and Writing Model-Specific Registers

The RDMSR (read model-specific register) and WRMSR (write model-specific register) instructions allow a processor’s 64-bit model-specific registers (MSRs) to be read and written, respectively. The MSR to be read or written is specified by the value in the ECX register. RDMSR reads the value from the specified MSR to the EDX:EAX registers; WRMSR writes the value in the EDX:EAX registers to the specified MSR. RDMSR and WRMSR were introduced into the IA-32 architecture with the Pentium processor.

See Section 9.4, “Model-Specific Registers (MSRs),” for more information.

Page 90 of the Intel 253668-032US user manual — 2.7.8 Enabling Processor Extended States
Page 90 · click to enlarge
Page 90

SYSTEM ARCHITECTURE OVERVIEW

2.7.7.1 Reading and Writing Model-Specific Registers in 64-Bit Mode

RDMSR and WRMSR require an index to specify the address of an MSR. In 64-bit mode, the index is 32 bits; it is specified using ECX.

2.7.8 Enabling Processor Extended States

The XSETBV instruction is required to enable OS support of individual processor extended states in the XFEATURE_ENABLED_MASK register (see Section 2.6).

Page 91 of the Intel 253668-032US user manual — 3.1 MEMORY MANAGEMENT OVERVIEW
Page 91 · click to enlarge
Page 91

CHAPTER 3 PROTECTED-MODE MEMORY MANAGEMENT

This chapter describes the Intel 64 and IA-32 architecture’s protected-mode memory management facilities, including the physical memory requirements, segmentation mechanism, and paging mechanism.

See also: Chapter 5, “Protection” (for a description of the processor’s protection mechanism) and Chapter 17, “8086 Emulation” (for a description of memory addressing protection in real-address and virtual-8086 modes).

3.1 MEMORY MANAGEMENT OVERVIEW

The memory management facilities of the IA-32 architecture are divided into two parts: segmentation and paging. Segmentation provides a mechanism of isolating individual code, data, and stack modules so that multiple programs (or tasks) can run on the same processor without interfering with one another. Paging provides a mechanism for implementing a conventional demand-paged, virtual-memory system where sections of a program’s execution environment are mapped into physical memory as needed. Paging can also be used to provide isolation between multiple tasks. When operating in protected mode, some form of segmentation must be used. There is no mode bit to disable segmentation. The use of paging, however, is optional.

These two mechanisms (segmentation and paging) can be configured to support simple single-program (or single-task) systems, multitasking systems, or multiple- processor systems that used shared memory.

As shown in Figure 3-1, segmentation provides a mechanism for dividing the processor’s addressable memory space (called the linear address space) into smaller protected address spaces called segments. Segments can be used to hold the code, data, and stack for a program or to hold system data structures (such as a TSS or LDT). If more than one program (or task) is running on a processor, each program can be assigned its own set of segments. The processor then enforces the boundaries between these segments and insures that one program does not interfere with the execution of another program by writing into the other program’s segments. The segmentation mechanism also allows typing of segments so that the operations that may be performed on a particular type of segment can be restricted.

All the segments in a system are contained in the processor’s linear address space. To locate a byte in a particular segment, a logical address (also called a far pointer) must be provided. A logical address consists of a segment selector and an offset. The segment selector is a unique identifier for a segment. Among other things it provides an offset into a descriptor table (such as the global descriptor table, GDT) to a data structure called a segment descriptor. Each segment has a segment descriptor, which specifies the size of the segment, the access rights and privilege level for the

Page 92 of the Intel 253668-032US user manual — PROTECTED-MODE MEMORY MANAGEMENT
Page 92 · click to enlarge
Page 92

PROTECTED-MODE MEMORY MANAGEMENT

segment, the segment type, and the location of the first byte of the segment in the linear address space (called the base address of the segment). The offset part of the logical address is added to the base address for the segment to locate a byte within the segment. The base address plus the offset thus forms a linear address in the processor’s linear address space.

Intel 253668-032US — PROTECTED-MODE MEMORY MANAGEMENT diagram (page 92)
Fig. 4

Figure 3-1. Segmentation and Paging

If paging is not used, the linear address space of the processor is mapped directly into the physical address space of processor. The physical address space is defined as the range of addresses that the processor can generate on its address bus.

Because multitasking computing systems commonly define a linear address space much larger than it is economically feasible to contain all at once in physical memory, some method of “virtualizing” the linear address space is needed. This virtualization of the linear address space is handled through the processor’s paging mechanism.

Paging supports a “virtual memory” environment where a large linear address space is simulated with a small amount of physical memory (RAM and ROM) and some disk

Page 93 of the Intel 253668-032US user manual — 3.2.1 Basic Flat Model
Page 93 · click to enlarge
Page 93

PROTECTED-MODE MEMORY MANAGEMENT

storage. When using paging, each segment is divided into pages (typically 4 KBytes each in size), which are stored either in physical memory or on the disk. The oper ating system or executive maintains a page directory and a set of page tables to keep track of the pages. When a program (or task) attempts to access an address location in the linear address space, the processor uses the page directory and page tables to translate the linear address into a physical address and then performs the requested operation (read or write) on the memory location.

If the page being accessed is not currently in physical memory, the processor inter rupts execution of the program (by generating a page-fault exception). The oper ating system or executive then reads the page into physical memory from the disk and continues executing the program.

When paging is implemented properly in the operating-system or executive, the swapping of pages between physical memory and the disk is transparent to the correct execution of a program. Even programs written for 16-bit IA-32 processors can be paged (transparently) when they are run in virtual-8086 mode.

3.2 USING SEGMENTS

The segmentation mechanism supported by the IA-32 architecture can be used to implement a wide variety of system designs. These designs range from flat models that make only minimal use of segmentation to protect programs to multi- segmented models that employ segmentation to create a robust operating environ ment in which multiple programs and tasks can be executed reliably.

The following sections give several examples of how segmentation can be employed in a system to improve memory management performance and reliability.

3.2.1 Basic Flat Model

The simplest memory model for a system is the basic “flat model,” in which the oper ating system and application programs have access to a continuous, unsegmented address space. To the greatest extent possible, this basic flat model hides the segmentation mechanism of the architecture from both the system designer and the application programmer.

To implement a basic flat memory model with the IA-32 architecture, at least two segment descriptors must be created, one for referencing a code segment and one for referencing a data segment (see Figure 3-2). Both of these segments, however, are mapped to the entire linear address space: that is, both segment descriptors have the same base address value of 0 and the same segment limit of 4 GBytes. By setting the segment limit to 4 GBytes, the segmentation mechanism is kept from generating exceptions for out of limit memory references, even if no physical memory resides at a particular address. ROM (EPROM) is generally located at the top of the physical address space, because the processor begins execution at

Page 94 of the Intel 253668-032US user manual — 3.2.2 Protected Flat Model
Page 94 · click to enlarge
Page 94

PROTECTED-MODE MEMORY MANAGEMENT

FFFF_FFF0H. RAM (DRAM) is placed at the bottom of the address space because the initial base address for the DS data segment after reset initialization is 0.

3.2.2 Protected Flat Model

The protected flat model is similar to the basic flat model, except the segment limits are set to include only the range of addresses for which physical memory actually exists (see Figure 3-3). A general-protection exception (#GP) is then generated on any attempt to access nonexistent memory. This model provides a minimum level of hardware protection against some kinds of program bugs.

Intel 253668-032US — 3.2.2 Protected Flat Model diagram (page 94)
Fig. 5 · 3.2.2 Protected Flat Model

Figure 3-2. Flat Model

Intel 253668-032US — 3.2.2 Protected Flat Model diagram (page 94)
Fig. 6 · 3.2.2 Protected Flat Model

Figure 3-3. Protected Flat Model

Page 95 of the Intel 253668-032US user manual — 3.2.3 Multi-Segment Model
Page 95 · click to enlarge
Page 95

PROTECTED-MODE MEMORY MANAGEMENT

More complexity can be added to this protected flat model to provide more protec tion. For example, for the paging mechanism to provide isolation between user and supervisor code and data, four segments need to be defined: code and data segments at privilege level 3 for the user, and code and data segments at privilege level 0 for the supervisor. Usually these segments all overlay each other and start at address 0 in the linear address space. This flat segmentation model along with a simple paging structure can protect the operating system from applications, and by adding a separate paging structure for each task or process, it can also protect appli cations from each other. Similar designs are used by several popular multitasking operating systems.

3.2.3 Multi-Segment Model

A multi-segment model (such as the one shown in Figure 3-4) uses the full capabili ties of the segmentation mechanism to provided hardware enforced protection of code, data structures, and programs and tasks. Here, each program (or task) is given its own table of segment descriptors and its own segments. The segments can be completely private to their assigned programs or shared among programs. Access to all segments and to the execution environments of individual programs running on the system is controlled by hardware.

Page 96 of the Intel 253668-032US user manual — 3.2.4 Segmentation in IA-32e Mode
Page 96 · click to enlarge
Page 96

PROTECTED-MODE MEMORY MANAGEMENT

Intel 253668-032US — PROTECTED-MODE MEMORY MANAGEMENT diagram (page 96)
Fig. 7

Figure 3-4. Multi-Segment Model

Access checks can be used to protect not only against referencing an address outside the limit of a segment, but also against performing disallowed operations in certain segments. For example, since code segments are designated as read-only segments, hardware can be used to prevent writes into code segments. The access rights infor mation created for segments can also be used to set up protection rings or levels. Protection levels can be used to protect operating-system procedures from unautho rized access by application programs.

3.2.4 Segmentation in IA-32e Mode

In IA-32e mode of Intel 64 architecture, the effects of segmentation depend on whether the processor is running in compatibility mode or 64-bit mode. In compati bility mode, segmentation functions just as it does using legacy 16-bit or 32-bit protected mode semantics.

Page 97 of the Intel 253668-032US user manual — 3.3 PHYSICAL ADDRESS SPACE
Page 97 · click to enlarge
Page 97

PROTECTED-MODE MEMORY MANAGEMENT

In 64-bit mode, segmentation is generally (but not completely) disabled, creating a flat 64-bit linear-address space. The processor treats the segment base of CS, DS, ES, SS as zero, creating a linear address that is equal to the effective address. The FS and GS segments are exceptions. These segment registers (which hold the segment base) can be used as an additional base registers in linear address calculations. They facilitate addressing local data and certain operating system data structures.

3.2.5 Paging and Segmentation

Paging can be used with any of the segmentation models described in Figures 3-2, 3-3, and 3-4. The processor’s paging mechanism divides the linear address space (into which segments are mapped) into pages (as shown in Figure 3-1). These linear- address-space pages are then mapped to pages in the physical address space. The paging mechanism offers several page-level protection facilities that can be used with or instead of the segment-protection facilities. For example, it lets read-write protection be enforced on a page-by-page basis. The paging mechanism also provides two-level user-supervisor protection that can also be specified on a page- by-page basis.

3.3 PHYSICAL ADDRESS SPACE

In protected mode, the IA-32 architecture provides a normal physical address space of 4 GBytes (232

bytes). This is the address space that the processor can address on its address bus. This address space is flat (unsegmented), with addresses ranging continuously from 0 to FFFFFFFFH. This physical address space can be mapped to read-write memory, read-only memory, and memory mapped I/O. The memory mapping facilities described in this chapter can be used to divide this physical memory up into segments and/or pages.

  • Starting with the Pentium Pro processor, the IA-32 architecture also supports an extension of the physical address space to 2 36 bytes (64 GBytes); with a maximum physical address of FFFFFFFFFH. This extension is invoked in either of two ways:
  • Using the physical address extension (PAE) flag, located in bit 5 of control register CR4.
  • Using the 36-bit page size extension (PSE-36) feature (introduced in the Pentium III processors).

Physical address support has since been extended beyond 36 bits. See Chapter 4, “Paging” for more information about 36-bit physical addressing.

Page 98 of the Intel 253668-032US user manual — 3.4 LOGICAL AND LINEAR ADDRESSES
Page 98 · click to enlarge
Page 98

PROTECTED-MODE MEMORY MANAGEMENT

3.3.1 Intel ® 64 Processors and Physical Address Space

On processors that support Intel 64 architecture (CPUID.80000001:EDX[29] = 1), the size of the physical address range is implementation-specific and indicated by CPUID.80000008H:EAX[bits 7-0].

For the format of information returned in EAX, see “CPUID—CPU Identification” in Chapter 3 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A. See also: Chapter 4, “Paging.”

3.4 LOGICAL AND LINEAR ADDRESSES

At the system-architecture level in protected mode, the processor uses two stages of address translation to arrive at a physical address: logical-address translation and linear address space paging.

Even with the minimum use of segments, every byte in the processor’s address space is accessed with a logical address. A logical address consists of a 16-bit segment selector and a 32-bit offset (see Figure 3-5). The segment selector identi fies the segment the byte is located in and the offset specifies the location of the byte in the segment relative to the base address of the segment.

The processor translates every logical address into a linear address. A linear address is a 32-bit address in the processor’s linear address space. Like the physical address space, the linear address space is a flat (unsegmented), 232-byte address space, with addresses ranging from 0 to FFFFFFFFH. The linear address space contains all the segments and system tables defined for a system.

To translate a logical address into a linear address, the processor does the following:

1. Uses the offset in the segment selector to locate the segment descriptor for the segment in the GDT or LDT and reads it into the processor. (This step is needed only when a new segment selector is loaded into a segment register.)
2. Examines the segment descriptor to check the access rights and range of the segment to insure that the segment is accessible and that the offset is within the limits of the segment.
3. Adds the base address of the segment from the segment descriptor to the offset to form a linear address.
Page 99 of the Intel 253668-032US user manual — 3.4.2 Segment Selectors
Page 99 · click to enlarge
Page 99

PROTECTED-MODE MEMORY MANAGEMENT

0 15 Logical Address

31(63) Seg. Selector

Figure 3-5. Logical Address to Linear Address Translation

If paging is not used, the processor maps the linear address directly to a physical address (that is, the linear address goes out on the processor’s address bus). If the linear address space is paged, a second level of address translation is used to trans late the linear address into a physical address.

See alsoChapter 4, “Paging.”

3.4.1 Logical Address Translation in IA-32e Mode

In IA-32e mode, an Intel 64 processor uses the steps described above to translate a logical address to a linear address. In 64-bit mode, the offset and base address of the segment are 64-bits instead of 32 bits. The linear address format is also 64 bits wide and is subject to the canonical form requirement.

Each code segment descriptor provides an L bit. This bit allows a code segment to execute 64-bit code or legacy 32-bit code by code segment.

3.4.2 Segment Selectors

A segment selector is a 16-bit identifier for a segment (see Figure 3-6). It does not point directly to the segment, but instead points to the segment descriptor that defines the segment. A segment selector contains the following items:

Index (Bits 3 through 15) — Selects one of 8192 descriptors in the GDT or LDT. The processor multiplies the index value by 8 (the number of bytes in a segment descriptor) and adds the result to the base address of the GDT or LDT (from the GDTR or LDTR register, respectively).

Show 7 more labels / short text on this page
Offset (Effective Address) · Descriptor Table · Segment Descriptor · Base Address · + · 0 31(63) · Linear Address
Page 100 of the Intel 253668-032US user manual — 3.4.3 Segment Registers
Page 100 · click to enlarge
Page 100

PROTECTED-MODE MEMORY MANAGEMENT

TI (table indicator) flag

(Bit 2) — Specifies the descriptor table to use: clearing this flag selects the GDT; setting this flag selects the current LDT.

15 3 2 1 0 T

RPL

Table Indicator 0 = GDT 1 = LDT Requested Privilege Level (RPL)

Figure 3-6. Segment Selector

Requested Privilege Level (RPL)

(Bits 0 and 1) — Specifies the privilege level of the selector. The priv ilege level can range from 0 to 3, with 0 being the most privileged level. See Section 5.5, “Privilege Levels”, for a description of the rela tionship of the RPL to the CPL of the executing program (or task) and the descriptor privilege level (DPL) of the descriptor the segment selector points to.

The first entry of the GDT is not used by the processor. A segment selector that points to this entry of the GDT (that is, a segment selector with an index of 0 and the TI flag set to 0) is used as a “null segment selector.” The processor does not generate an exception when a segment register (other than the CS or SS registers) is loaded with a null selector. It does, however, generate an exception when a segment register holding a null selector is used to access memory. A null selector can be used to initialize unused segment registers. Loading the CS or SS register with a null segment selector causes a general-protection exception (#GP) to be generated.

Segment selectors are visible to application programs as part of a pointer variable, but the values of selectors are usually assigned or modified by link editors or linking loaders, not application programs.

3.4.3 Segment Registers

To reduce address translation time and coding complexity, the processor provides registers for holding up to 6 segment selectors (see Figure 3-7). Each of these segment registers support a specific kind of memory reference (code, stack, or data). For virtually any kind of program execution to take place, at least the code- segment (CS), data-segment (DS), and stack-segment (SS) registers must be loaded with valid segment selectors. The processor also provides three additional data-segment registers (ES, FS, and GS), which can be used to make additional data segments available to the currently executing program (or task).

I Index

Page 101 of the Intel 253668-032US user manual — CS
Page 101 · click to enlarge
Page 101

PROTECTED-MODE MEMORY MANAGEMENT

For a program to access a segment, the segment selector for the segment must have been loaded in one of the segment registers. So, although a system can define thou sands of segments, only 6 can be available for immediate use. Other segments can be made available by loading their segment selectors into these registers during program execution.

Visible Part Hidden Part

Segment Selector Base Address, Limit, Access Information

CS

SS

DS

ES

FS

GS

Figure 3-7. Segment Registers

Every segment register has a “visible” part and a “hidden” part. (The hidden part is sometimes referred to as a “descriptor cache” or a “shadow register.”) When a segment selector is loaded into the visible part of a segment register, the processor also loads the hidden part of the segment register with the base address, segment limit, and access control information from the segment descriptor pointed to by the segment selector. The information cached in the segment register (visible and hidden) allows the processor to translate addresses without taking extra bus cycles to read the base address and limit from the segment descriptor. In systems in which multiple processors have access to the same descriptor tables, it is the responsibility of software to reload the segment registers when the descriptor tables are modified. If this is not done, an old segment descriptor cached in a segment register might be used after its memory-resident version has been modified.

Two kinds of load instructions are provided for loading the segment registers:

1. Direct load instructions such as the MOV, POP, LDS, LES, LSS, LGS, and LFS instructions. These instructions explicitly reference the segment registers.
2. Implied load instructions such as the far pointer versions of the CALL, JMP, and RET instructions, the SYSENTER and SYSEXIT instructions, and the IRET, INT n , INTO and INT3 instructions. These instructions change the contents of the CS register (and sometimes other segment registers) as an incidental part of their operation.

The MOV instruction can also be used to store visible part of a segment register in a general-purpose register.

Page 102 of the Intel 253668-032US user manual — PROTECTED-MODE MEMORY MANAGEMENT
Page 102 · click to enlarge
Page 102

PROTECTED-MODE MEMORY MANAGEMENT

3.4.4 Segment Loading Instructions in IA-32e Mode

Because ES, DS, and SS segment registers are not used in 64-bit mode, their fields (base, limit, and attribute) in segment descriptor registers are ignored. Some forms of segment load instructions are also invalid (for example, LDS, POP ES). Address calculations that reference the ES, DS, or SS segments are treated as if the segment base is zero.

The processor checks that all linear-address references are in canonical form instead of performing limit checks. Mode switching does not change the contents of the segment registers or the associated descriptor registers. These registers are also not changed during 64-bit mode execution, unless explicit segment loads are performed.

In order to set up compatibility mode for an application, segment-load instructions (MOV to Sreg, POP Sreg) work normally in 64-bit mode. An entry is read from the system descriptor table (GDT or LDT) and is loaded in the hidden portion of the segment descriptor register. The descriptor-register base, limit, and attribute fields are all loaded. However, the contents of the data and stack segment selector and the descriptor registers are ignored.

When FS and GS segment overrides are used in 64-bit mode, their respective base addresses are used in the linear address calculation: (FS or GS).base + index + displacement. FS.base and GS.base are then expanded to the full linear-address size supported by the implementation. The resulting effective address calculation can wrap across positive and negative addresses; the resulting linear address must be canonical.

In 64-bit mode, memory accesses using FS-segment and GS-segment overrides are not checked for a runtime limit nor subjected to attribute-checking. Normal segment loads (MOV to Sreg and POP Sreg) into FS and GS load a standard 32-bit base value in the hidden portion of the segment descriptor register. The base address bits above the standard 32 bits are cleared to 0 to allow consistency for implementations that use less than 64 bits.

The hidden descriptor register fields for FS.base and GS.base are physically mapped to MSRs in order to load all address bits supported by a 64-bit implementation. Soft ware with CPL = 0 (privileged software) can load all supported linear-address bits into FS.base or GS.base using WRMSR. Addresses written into the 64-bit FS.base and GS.base registers must be in canonical form. A WRMSR instruction that attempts to write a non-canonical address to those registers causes a #GP fault.

When in compatibility mode, FS and GS overrides operate as defined by 32-bit mode behavior regardless of the value loaded into the upper 32 linear-address bits of the hidden descriptor register base field. Compatibility mode ignores the upper 32 bits when calculating an effective address.

A new 64-bit mode instruction, SWAPGS, can be used to load GS base. SWAPGS exchanges the kernel data structure pointer from the IA32_KernelGSbase MSR with the GS base register. The kernel can then use the GS prefix on normal memory refer ences to access the kernel data structures. An attempt to write a non-canonical value (using WRMSR) to the IA32_KernelGSBase MSR causes a #GP fault.

Page 103 of the Intel 253668-032US user manual — / B
Page 103 · click to enlarge
Page 103

PROTECTED-MODE MEMORY MANAGEMENT

3.4.5 Segment Descriptors

A segment descriptor is a data structure in a GDT or LDT that provides the processor with the size and location of a segment, as well as access control and status informa tion. Segment descriptors are typically created by compilers, linkers, loaders, or the operating system or executive, but not application programs. Figure 3-8 illustrates the general descriptor format for all types of segment descriptors.

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

Base 23:16 D

A V L

Seg. Limit 19:16

D P L

P Base 31:24 G

/ B

Type S L 4

31 16 15 0

Base Address 15:00 Segment Limit 15:00 0

L — 64-bit code segment (IA-32e mode only)

AVL — Available for use by system software BASE — Segment base address D/B — Default operation size (0 = 16-bit segment; 1 = 32-bit segment)

DPL — Descriptor privilege level

G — Granularity LIMIT — Segment Limit P — Segment present S — Descriptor type (0 = system; 1 = code or data) TYPE — Segment type

Figure 3-8. Segment Descriptor

The flags and fields in a segment descriptor are as follows:

Specifies the size of the segment. The processor puts together the two segment limit fields to form a 20-bit value. The processor inter prets the segment limit in one of two ways, depending on the setting of the G (granularity) flag:

  • If the granularity flag is clear, the segment size can range from 1 byte to 1 MByte, in byte increments.
  • If the granularity flag is set, the segment size can range from 4 KBytes to 4 GBytes, in 4-KByte increments.

The processor uses the segment limit in two different ways, depending on whether the segment is an expand-up or an expand- down segment. See Section 3.4.5.1, “Code- and Data-Segment Descriptor Types”, for more information about segment types. For expand-up segments, the offset in a logical address can range from 0

Segment limit field

Page 104 of the Intel 253668-032US user manual — PROTECTED-MODE MEMORY MANAGEMENT
Page 104 · click to enlarge
Page 104

PROTECTED-MODE MEMORY MANAGEMENT

to the segment limit. Offsets greater than the segment limit generate general-protection exceptions (#GP). For expand-down segments, the segment limit has the reverse function; the offset can range from the segment limit to FFFFFFFFH or FFFFH, depending on the setting of the B flag. Offsets less than the segment limit generate general- protection exceptions. Decreasing the value in the segment limit field for an expand-down segment allocates new memory at the bottom of the segment's address space, rather than at the top. IA-32 architec ture stacks always grow downwards, making this mechanism conve nient for expandable stacks.

Defines the location of byte 0 of the segment within the 4-GByte linear address space. The processor puts together the three base address fields to form a single 32-bit value. Segment base addresses should be aligned to 16-byte boundaries. Although 16-byte alignment is not required, this alignment allows programs to maximize perfor mance by aligning code and data on 16-byte boundaries.

Type field Indicates the segment or gate type and specifies the kinds of access that can be made to the segment and the direction of growth. The interpretation of this field depends on whether the descriptor type flag specifies an application (code or data) descriptor or a system descriptor. The encoding of the type field is different for code, data, and system descriptors (see Figure 5-1). See Section 3.4.5.1, “Code- and Data-Segment Descriptor Types”, for a description of how this field is used to specify code and data-segment types.

S (descriptor type) flag

Specifies whether the segment descriptor is for a system segment (S flag is clear) or a code or data segment (S flag is set).

DPL (descriptor privilege level) field

Specifies the privilege level of the segment. The privilege level can range from 0 to 3, with 0 being the most privileged level. The DPL is used to control access to the segment. See Section 5.5, “Privilege Levels”, for a description of the relationship of the DPL to the CPL of the executing code segment and the RPL of a segment selector.

Indicates whether the segment is present in memory (set) or not present (clear). If this flag is clear, the processor generates a segment-not-present exception (#NP) when a segment selector that points to the segment descriptor is loaded into a segment register. Memory management software can use this flag to control which segments are actually loaded into physical memory at a given time. It offers a control in addition to paging for managing virtual memory.

Figure 3-9 shows the format of a segment descriptor when the segment-present flag is clear. When this flag is clear, the operating system or executive is free to use the locations marked “Available” to

Base address fields · P (segment-present) flag

Page 105 of the Intel 253668-032US user manual — D P L
Page 105 · click to enlarge
Page 105

PROTECTED-MODE MEMORY MANAGEMENT

store its own data, such as information regarding the whereabouts of the missing segment.

D/B (default operation size/default stack pointer size and/or upper bound)

flag Performs different functions depending on whether the segment descriptor is an executable code segment, an expand-down data segment, or a stack segment. (This flag should always be set to 1 for 32-bit code and data segments and to 0 for 16-bit code and data segments.)

  • Executable code segment. The flag is called the D flag and it indicates the default length for effective addresses and operands referenced by instructions in the segment. If the flag is set, 32-bit addresses and 32-bit or 8-bit operands are assumed; if it is clear, 16-bit addresses and 16-bit or 8-bit operands are assumed. The instruction prefix 66H can be used to select an operand size other than the default, and the prefix 67H can be used select an address size other than the default.
  • Stack segment (data segment pointed to by the SS register). The flag is called the B (big) flag and it specifies the size of the stack pointer used for implicit stack operations (such as pushes, pops, and calls). If the flag is set, a 32-bit stack pointer is used, which is stored in the 32-bit ESP register; if the flag is clear, a 16-bit stack pointer is used, which is stored in the 16-bit SP register. If the stack segment is set up to be an expand-down data segment (described in the next paragraph), the B flag also specifies the upper bound of the stack segment.
  • Expand-down data segment. The flag is called the B flag and it specifies the upper bound of the segment. If the flag is set, the upper bound is FFFFFFFFH (4 GBytes); if the flag is clear, the upper bound is FFFFH (64 KBytes).

31 16 15 13 14 12 11 8 7 0

D P L

Figure 3-9. Segment Descriptor When Segment-Present Flag Is Clear

Show 4 more labels / short text on this page
0 Available · Type S 4 · Available · Available 0
Page 106 of the Intel 253668-032US user manual — PROTECTED-MODE MEMORY MANAGEMENT
Page 106 · click to enlarge
Page 106

PROTECTED-MODE MEMORY MANAGEMENT

Determines the scaling of the segment limit field. When the granularity flag is clear, the segment limit is interpreted in byte units; when flag is set, the segment limit is interpreted in 4-KByte units. (This flag does not affect the granularity of the base address; it is always byte granular.) When the granularity flag is set, the twelve least significant bits of an offset are not tested when checking the offset against the segment limit. For example, when the granularity flag is set, a limit of 0 results in valid offsets from 0 to 4095.

L (64-bit code segment) flag

In IA-32e mode, bit 21 of the second doubleword of the segment descriptor indicates whether a code segment contains native 64-bit code. A value of 1 indicates instructions in this code segment are executed in 64-bit mode. A value of 0 indicates the instructions in this code segment are executed in compatibility mode. If L-bit is set, then D-bit must be cleared. When not in IA-32e mode or for non-code segments, bit 21 is reserved and should always be set to 0.

Available and reserved bits

Bit 20 of the second doubleword of the segment descriptor is available for use by system software.

3.4.5.1 Code- and Data-Segment Descriptor Types

When the S (descriptor type) flag in a segment descriptor is set, the descriptor is for either a code or a data segment. The highest order bit of the type field (bit 11 of the second double word of the segment descriptor) then determines whether the descriptor is for a data segment (clear) or a code segment (set).

For data segments, the three low-order bits of the type field (bits 8, 9, and 10) are interpreted as accessed (A), write-enable (W), and expansion-direction (E). See Table 3-1 for a description of the encoding of the bits in the type field for code and data segments. Data segments can be read-only or read/write segments, depending on the setting of the write-enable bit.

G (granularity) flag

Page 107 of the Intel 253668-032US user manual — C R A
Page 107 · click to enlarge
Page 107

PROTECTED-MODE MEMORY MANAGEMENT

Table 3-1. Code- and Data-Segment Types

Decimal 11 10 E

9 W

8 A

0 Data Read-Only

1 0 0 0 1 Data Read-Only, accessed

2 0 0 1 0 Data Read/Write

3 0 0 1 1 Data Read/Write, accessed

4 0 1 0 0 Data Read-Only, expand-down

5 0 1 0 1 Data Read-Only, expand-down, accessed

6 0 1 1 0 Data Read/Write, expand-down

7 0 1 1 1 Data Read/Write, expand-down, accessed

C R A

8 1 0 0 0 Code Execute-Only

9 1 0 0 1 Code Execute-Only, accessed

10 1 0 1 0 Code Execute/Read

11 1 0 1 1 Code Execute/Read, accessed

12 1 1 0 0 Code Execute-Only, conforming

13 1 1 0 1 Code Execute-Only, conforming, accessed

14 1 1 1 0 Code Execute/Read, conforming

15 1 Code Execute/Read, conforming, accessed

Stack segments are data segments which must be read/write segments. Loading the SS register with a segment selector for a nonwritable data segment generates a general-protection exception (#GP). If the size of a stack segment needs to be changed dynamically, the stack segment can be an expand-down data segment (expansion-direction flag set). Here, dynamically changing the segment limit causes stack space to be added to the bottom of the stack. If the size of a stack segment is intended to remain static, the stack segment may be either an expand-up or expand- down type.

The accessed bit indicates whether the segment has been accessed since the last time the operating-system or executive cleared the bit. The processor sets this bit whenever it loads a segment selector for the segment into a segment register, assuming that the type of memory that contains the segment descriptor supports processor writes. The bit remains set until explicitly cleared. This bit can be used both for virtual memory management and for debugging.

Type Field Descriptor · Description · Type

Page 108 of the Intel 253668-032US user manual — 3.5 SYSTEM DESCRIPTOR TYPES
Page 108 · click to enlarge
Page 108

PROTECTED-MODE MEMORY MANAGEMENT

For code segments, the three low-order bits of the type field are interpreted as accessed (A), read enable (R), and conforming (C). Code segments can be execute- only or execute/read, depending on the setting of the read-enable bit. An execute/read segment might be used when constants or other static data have been placed with instruction code in a ROM. Here, data can be read from the code segment either by using an instruction with a CS override prefix or by loading a segment selector for the code segment in a data-segment register (the DS, ES, FS, or GS registers). In protected mode, code segments are not writable.

Code segments can be either conforming or nonconforming. A transfer of execution into a more-privileged conforming segment allows execution to continue at the current privilege level. A transfer into a nonconforming segment at a different privi lege level results in a general-protection exception (#GP), unless a call gate or task gate is used (see Section 5.8.1, “Direct Calls or Jumps to Code Segments”, for more information on conforming and nonconforming code segments). System utilities that do not access protected facilities and handlers for some types of exceptions (such as, divide error or overflow) may be loaded in conforming code segments. Utilities that need to be protected from less privileged programs and procedures should be placed in nonconforming code segments.

NOTE

Execution cannot be transferred by a call or a jump to a less- privileged (numerically higher privilege level) code segment, regardless of whether the target segment is a conforming or noncon forming code segment. Attempting such an execution transfer will result in a general-protection exception.

All data segments are nonconforming, meaning that they cannot be accessed by less privileged programs or procedures (code executing at numerically high privilege levels). Unlike code segments, however, data segments can be accessed by more privileged programs or procedures (code executing at numerically lower privilege levels) without using a special access gate.

If the segment descriptors in the GDT or an LDT are placed in ROM, the processor can enter an indefinite loop if software or the processor attempts to update (write to) the ROM-based segment descriptors. To prevent this problem, set the accessed bits for all segment descriptors placed in a ROM. Also, remove operating-system or executive code that attempts to modify segment descriptors located in ROM.

3.5 SYSTEM DESCRIPTOR TYPES

When the S (descriptor type) flag in a segment descriptor is clear, the descriptor type is a system descriptor. The processor recognizes the following types of system descriptors: • Local descriptor-table (LDT) segment descriptor.

Page 109 of the Intel 253668-032US user manual — 2 0 0 1 0 LDT LDT
Page 109 · click to enlarge
Page 109

PROTECTED-MODE MEMORY MANAGEMENT

  • Task-state segment (TSS) descriptor.
  • Call-gate descriptor.
  • Interrupt-gate descriptor.
  • Trap-gate descriptor.
  • Task-gate descriptor.

These descriptor types fall into two categories: system-segment descriptors and gate descriptors. System-segment descriptors point to system segments (LDT and TSS segments). Gate descriptors are in themselves “gates,” which hold pointers to proce dure entry points in code segments (call, interrupt, and trap gates) or which hold segment selectors for TSS’s (task gates).

Table 3-2 shows the encoding of the type field for system-segment descriptors and gate descriptors. Note that system descriptors in IA-32e mode are 16 bytes instead of 8 bytes.

Table 3-2. System-Segment and Gate-Descriptor Types

Decimal 11 10 9 8 32-Bit Mode IA-32e Mode

0 Reserved Upper 8 byte of an 16- byte descriptor

1 0 0 0 1 16-bit TSS (Available) Reserved

2 0 0 1 0 LDT LDT

3 0 0 1 1 16-bit TSS (Busy) Reserved

4 0 1 0 0 16-bit Call Gate Reserved

5 0 1 0 1 Task Gate Reserved

6 0 1 1 0 16-bit Interrupt Gate Reserved

7 0 16-bit Trap Gate Reserved

8 1 0 0 0 Reserved Reserved

9 1 0 0 1 32-bit TSS (Available) 64-bit TSS (Available)

10 1 0 1 0 Reserved Reserved

11 1 0 1 1 32-bit TSS (Busy) 64-bit TSS (Busy)

12 1 1 0 0 32-bit Call Gate 64-bit Call Gate

13 1 1 0 1 Reserved Reserved

14 1 1 1 0 32-bit Interrupt Gate 64-bit Interrupt Gate

15 1 32-bit Trap Gate 64-bit Trap Gate

Type Field Description

Page 110 of the Intel 253668-032US user manual — 3.5.1 Segment Descriptor Tables
Page 110 · click to enlarge
Page 110

PROTECTED-MODE MEMORY MANAGEMENT

See also: Section 3.5.1, “Segment Descriptor Tables”, and Section 7.2.2, “TSS Descriptor” (for more information on the system-segment descriptors); see Section 5.8.3, “Call Gates”, Section 6.11, “IDT Descriptors”, and Section 7.2.5, “Task-Gate Descriptor” (for more information on the gate descriptors).

3.5.1 Segment Descriptor Tables

  • A segment descriptor table is an array of segment descriptors (see Figure 3-10). A descriptor table is variable in length and can contain up to 8192 (2 13 ) 8-byte descrip tors. There are two kinds of descriptor tables:
  • The global descriptor table (GDT)
  • The local descriptor tables (LDT)
Intel 253668-032US — 3.5.1 Segment Descriptor Tables diagram (page 110)
Fig. 8 · 3.5.1 Segment Descriptor Tables

Figure 3-10. Global and Local Descriptor Tables

Page 111 of the Intel 253668-032US user manual — PROTECTED-MODE MEMORY MANAGEMENT
Page 111 · click to enlarge
Page 111

PROTECTED-MODE MEMORY MANAGEMENT

Each system must have one GDT defined, which may be used for all programs and tasks in the system. Optionally, one or more LDTs can be defined. For example, an LDT can be defined for each separate task being run, or some or all tasks can share the same LDT.

The GDT is not a segment itself; instead, it is a data structure in linear address space. The base linear address and limit of the GDT must be loaded into the GDTR register (see Section 2.4, “Memory-Management Registers”). The base addresses of the GDT should be aligned on an eight-byte boundary to yield the best processor perfor mance. The limit value for the GDT is expressed in bytes. As with segments, the limit value is added to the base address to get the address of the last valid byte. A limit value of 0 results in exactly one valid byte. Because segment descriptors are always 8 bytes long, the GDT limit should always be one less than an integral multiple of eight (that is, 8N – 1).

The first descriptor in the GDT is not used by the processor. A segment selector to this “null descriptor” does not generate an exception when loaded into a data- segment register (DS, ES, FS, or GS), but it always generates a general-protection exception (#GP) when an attempt is made to access memory using the descriptor. By initializing the segment registers with this segment selector, accidental reference to unused segment registers can be guaranteed to generate an exception.

The LDT is located in a system segment of the LDT type. The GDT must contain a segment descriptor for the LDT segment. If the system supports multiple LDTs, each must have a separate segment selector and segment descriptor in the GDT. The segment descriptor for an LDT can be located anywhere in the GDT. See Section 3.5, “System Descriptor Types”, information on the LDT segment-descriptor type.

An LDT is accessed with its segment selector. To eliminate address translations when accessing the LDT, the segment selector, base linear address, limit, and access rights of the LDT are stored in the LDTR register (see Section 2.4, “Memory-Management Registers”).

When the GDTR register is stored (using the SGDT instruction), a 48-bit “pseudo- descriptor” is stored in memory (see top diagram in Figure 3-11). To avoid alignment check faults in user mode (privilege level 3), the pseudo-descriptor should be located at an odd word address (that is, address MOD 4 is equal to 2). This causes the processor to store an aligned word, followed by an aligned doubleword. User-mode programs normally do not store pseudo-descriptors, but the possibility of generating an alignment check fault can be avoided by aligning pseudo-descriptors in this way. The same alignment should be used when storing the IDTR register using the SIDT instruction. When storing the LDTR or task register (using the SLTR or STR instruc tion, respectively), the pseudo-descriptor should be located at a doubleword address (that is, address MOD 4 is equal to 0).

Page 112 of the Intel 253668-032US user manual — 3.5.2 Segment Descriptor Tables in IA-32e Mode
Page 112 · click to enlarge
Page 112

PROTECTED-MODE MEMORY MANAGEMENT

0 32-bit Base Address Limit 47 15 16

0 64-bit Base Address Limit 79 15 16

Figure 3-11. Pseudo-Descriptor Formats

3.5.2 Segment Descriptor Tables in IA-32e Mode

In IA-32e mode, a segment descriptor table can contain up to 8192 (213) 8-byte descriptors. An entry in the segment descriptor table can be 8 bytes. System descrip tors are expanded to 16 bytes (occupying the space of two entries).

GDTR and LDTR registers are expanded to hold 64-bit base address. The corre sponding pseudo-descriptor is 80 bits. (see the bottom diagram in Figure 3-11).

The following system descriptors expand to 16 bytes:

— Call gate descriptors (see Section 5.8.3.1, “IA-32e Mode Call Gates”)

— IDT gate descriptors (see Section 6.14.1, “64-Bit Mode IDT”)

— LDT and TSS descriptors (see Section 7.2.3, “TSS Descriptor in 64-bit mode”).

Page 113 of the Intel 253668-032US user manual — 4.1 PAGING MODES AND CONTROL BITS
Page 113 · click to enlarge
Page 113

CHAPTER 4

PAGING

Chapter 3 explains how segmentation converts logical addresses to linear addresses. Paging (or linear-address translation) is the process of translating linear addresses so that they can be used to access memory or I/O devices. Paging translates each linear address to a physical address and determines, for each translation, what accesses to the linear address are allowed (the address’s access rights) and the type of caching used for such accesses (the address’s memory type).

Intel-64 processors support three different paging modes. These modes are identi- fied and defined in Section 4.1. Section 4.2 gives an overview of the translation mechanism that is used in all modes. Section 4.3, Section 4.4, and Section 4.5 discuss the three paging modes in detail.

Section 4.6 details how paging determines and uses access rights. Section 4.7 discusses exceptions that may be generated by paging (page-fault exceptions). Section 4.8 considers data which the processor writes in response to linear-address accesses (accessed and dirty flags).

Section 4.9 describes how paging determines the memory types used for accesses to linear addresses. Section 4.10 provides details of how a processor may cache infor- mation about linear-address translation. Section 4.11 outlines interactions between paging and certain VMX features. Section 4.12 gives an overview of how paging can be used to implement virtual memory.

4.1 PAGING MODES AND CONTROL BITS

  • Paging behavior is controlled by the following control bits:
  • The WP and PG flags in control register CR0 (bit 16 and bit 31, respectively).
  • The PSE, PAE, and PGE flags in control register CR4 (bit 4, bit 5, and bit 7, respectively).
  • The LME and NXE flags in the IA32_EFER MSR (bit 8 and bit 11, respectively).

Software enables paging by using the MOV to CR0 instruction to set CR0.PG. Before doing so, software should ensure that control register CR3 contains the physical address of the first paging structure that the processor will use for linear-address translation (see Section 4.2) and that structure is initialized as desired. See Table 4-3, Table 4-7, and Table 4-12 for the use of CR3 in the different paging modes.

Section 4.1.1 describes how the values of CR0.PG, CR4.PAE, and IA32_EFER.LME determine whether paging is in use and, if so, which of three paging modes is in use. Section 4.1.2 explains how to manage these bits to establish or make changes in

Page 114 of the Intel 253668-032US user manual — 4.1.1 Three Paging Modes
Page 114 · click to enlarge
Page 114

PAGING

paging modes. Section 4.1.3 discusses how CR0.WP, CR4.PSE, CR4.PGE, and IA32_EFER.NXE modify the operation of the different paging modes.

4.1.1 Three Paging Modes

If CR0.PG = 0, paging is not used. The logical processor treats all linear addresses as if they were physical addresses. CR4.PAE and IA32_EFER.LME are ignored by the processor, as are CR0.WP, CR4.PSE, and CR4.PGE, and IA32_EFER.NXE.

  • Paging is enabled if CR0.PG = 1. Paging can be enabled only if protection is enabled (CR0.PE = 1). If paging is enabled, one of three paging modes is used. The values of CR4.PAE and IA32_EFER.LME determine which paging mode is used:
  • If CR0.PG = 1 and CR4.PAE = 0, 32-bit paging is used. 32-bit paging is detailed in Section 4.3. 32-bit paging uses CR0.WP, CR4.PSE, and CR4.PGE as described in Section 4.1.3.
  • If CR0.PG = 1, CR4.PAE = 1, and IA32_EFER.LME = 0, PAE paging is used. PAE paging is detailed in Section 4.4. PAE paging uses CR0.WP, CR4.PGE, and IA32_EFER.NXE as described in Section 4.1.3.
  • If CR0.PG = 1, CR4.PAE = 1, and IA32_EFER.LME = 1, IA-32e paging is used. 1 IA-32e paging is detailed in Section 4.5. IA-32e paging uses CR0.WP, CR4.PGE, and IA32_EFER.NXE as described in Section 4.1.3. IA-32e paging is available only on processors that support the Intel 64 architecture.
  • The three paging modes differ with regard to the following details:
  • Linear-address width. The size of the linear addresses that can be translated.
  • Physical-address width. The size of the physical addresses produced by paging.
  • Page size. The granularity at which linear addresses are translated. Linear addresses on the same page are translated to corresponding physical addresses on the same page.
  • Support for execute-disable access rights. In some paging modes, software can be prevented from fetching instructions from pages that are otherwise readable.

Table 4-1 illustrates the key differences between the three paging modes.

Because they are used only if IA32_EFER.LME = 0, 32-bit paging and PAE paging is used only in legacy protected mode. Because legacy protected mode cannot produce

1. The LMA flag in the IA32_EFER MSR (bit 10) is a status bit that indicates whether the logical processor is in IA-32e mode (and thus using IA-32e paging). The processor always sets IA32_EFER.LMA to CR0.PG & IA32_EFER.LME. Software cannot directly modify IA32_EFER.LMA; an execution of WRMSR to the IA32_EFER MSR ignores bit 10 of its source operand.
Page 115 of the Intel 253668-032US user manual — 4.1.2 Paging-Mode Enabling
Page 115 · click to enlarge
Page 115

PAGING

Table 4-1. Properties of Different Paging Modes

Paging Mode CR0.PG CR4.PAE LME in IA32_EFER

None 0 N/A N/A 32 32 N/A No

32-bit 1 0 02 32 Up to 403 4-KByte 4-MByte4 No

PAE 1 1 0 32 Up to 52 4-KByte 2-MByte Yes5

IA-32e 1 1 2 48 Up to 52 4-KByte 2-MByte Yes5

NOTES: 1. The physical-address width is always bounded by MAXPHYADDR; see Section 4.1.4. 2. The processor ensures that IA32_EFER.LME must be 0 if CR0.PG = 1 and CR4.PAE = 0. 3. 32-bit paging supports physical-address widths of more than 32 bits only for 4-MByte pages and only if the PSE-36 mechanism is supported; see Section 4.1.4 and Section 4.3. 4. 4-MByte pages are used with 32-bit paging only if CR4.PSE = 1; see Section 4.3. 5. Execute-disable access rights are applied only if IA32_EFER.NXE = 1; see Section 4.6.

linear addresses larger than 32 bits, 32-bit paging and PAE paging translate 32-bit linear addresses.

  • Because it is used only if IA32_EFER.LME = 1, IA-32e paging is used only in IA-32e mode. (In fact, it is the use of IA-32e paging that defines IA-32e mode.) IA-32e mode has two sub-modes:
  • Compatibility mode. This mode uses only 32-bit linear addresses. IA-32e paging treats bits 47:32 of such an address as all 0.
  • 64-bit mode. While this mode produces 64-bit linear addresses, the processor ensures that bits 63:47 of such an address are identical. 1 IA-32e paging does not use bits 63:48 of such addresses.

4.1.2 Paging-Mode Enabling

If CR0.PG = 1, a logical processor is in one of three paging modes, depending on the values of CR4.PAE and IA32_EFER.LME. Figure 4-1 illustrates how software can

1. Such an address is called canonical. Use of a non-canonical linear address in 64-bit mode produces a general-protection exception (#GP(0)); the processor does not attempt to translate noncanonical linear addresses using IA-32e paging.
Show 4 more labels / short text on this page
Linear- Address Width · Physical- Address Width1 · Supports Execute- Disable? · Page Size(s)
Page 116 of the Intel 253668-032US user manual — #GP
Page 116 · click to enlarge
Page 116

PAGING

enable these modes and make transitions between them. The following items identify certain limitations and other details:

#GP

#GP

Intel 253668-032US — #GP diagram (page 116)
Fig. 9

PG = 0 PAE = 0 LME = 0

PG = 1 PAE = 0 LME = 0

PG = 0 PAE = 0 LME = 1

PG = 0 PAE = 1 LME = 0

PG = 0 PAE = 1 LME = 1

Figure 4-1. Enabling and Changing Paging Modes

  • IA32_EFER.LME cannot be modified while paging is enabled (CR0.PG = 1). Attempts to do so using WRMSR cause a general-protection exception (#GP(0)).
  • Paging cannot be enabled (by setting CR0.PG to 1) while CR4.PAE = 0 and IA32_EFER.LME = 1. Attempts to do so using MOV to CR0 cause a generalprotection exception (#GP(0)).
  • CR4.PAE cannot be cleared while IA-32e paging is active (CR0.PG = 1 and IA32_EFER.LME = 1). Attempts to do so using MOV to CR4 cause a generalprotection exception (#GP(0)).
Page 117 of the Intel 253668-032US user manual — 4.1.3 Paging-Mode Modifiers
Page 117 · click to enlarge
Page 117

PAGING

  • Software can always disable paging by clearing CR0.PG with MOV to CR0.
  • Software can make transitions between 32-bit paging and PAE paging by changing the value of CR4.PAE with MOV to CR4.
  • Software cannot make transitions directly between IA-32e paging and either of the other two paging modes. It must first disable paging (by clearing CR0.PG with MOV to CR0), then set CR4.PAE and IA32_EFER.LME to the desired values (with MOV to CR4 and WRMSR), and then re-enable paging (by setting CR0.PG with MOV to CR0). As noted earlier, an attempt to clear either CR4.PAE or IA32_EFER.LME cause a general-protection exception (#GP(0)).
  • VMX transitions allow transitions between paging modes that are not possible using MOV to CR or WRMSR. This is because VMX transitions can load CR0, CR4, and IA32_EFER in one operation. See Section 4.11.1.

4.1.3 Paging-Mode Modifiers

  • Details of how each paging mode operates are determined by the following control bits:
  • The WP flag in CR0 (bit 16).
  • The PSE and PGE flags in CR4 (bit 4 and bit 7, respectively).
  • The NXE flag in the IA32_EFER MSR (bit 11).

CR0.WP allows pages to be protected from supervisor-mode writes. If CR0.WP = 0, software operating with CPL < 3 (supervisor mode) can write to linear addresses with read-only access rights; if CR0.WP = 1, it cannot. (Software operating with CPL = 3 — user mode — cannot write to linear addresses with read-only access rights, regardless of the value of CR0.WP.) Section 4.6 explains how access rights are deter- mined.

CR4.PSE enables 4-MByte pages for 32-bit paging. If CR4.PSE = 0, 32-bit paging can use only 4-KByte pages; if CR4.PSE = 1, 32-bit paging can use both 4-KByte pages and 4-MByte pages. See Section 4.3 for more information. (PAE paging and IA-32e paging can use multiple page sizes regardless of the value of CR4.PSE.)

CR4.PGE enables global pages. If CR4.PGE = 0, no translations are shared across address spaces; if CR4.PGE = 1, specified translations may be shared across address spaces. See Section 4.10.1.4 for more information.

IA32_EFER.NXE enables execute-disable access rights for PAE paging and IA-32e paging. If IA32_EFER.NXE = 0, software may fetch instructions from any linear address that paging allows the software to read; if IA32_EFER.NXE = 1, instructions fetches can be prevented from specified linear addresses (even if data reads from the addresses are allowed). Section 4.6 explains how access rights are determined. (32- bit paging always allows software to fetch instructions from any linear address that may be read; IA32_EFER.NXE has no effect with 32-bit paging. Software that wants to limit instruction fetches from readable pages must use either PAE paging or IA-32e paging.)

Page 118 of the Intel 253668-032US user manual — PAGING
Page 118 · click to enlarge
Page 118

PAGING

4.1.4 Enumeration of Paging Features by CPUID

  • Software can discover support for different paging features using the CPUID instruction:
  • PSE: page-size extensions for 32-bit paging. If CPUID.01H:EDX.PSE [bit 3] = 1, CR4.PSE may be set to 1, enabling support for 4-MByte pages with 32-bit paging (see Section 4.3).
  • PAE: physical-address extension. If CPUID.01H:EDX.PAE [bit 6] = 1, CR4.PAE may be set to 1, enabling PAE paging (this setting is also required for IA-32e paging).
  • PGE: global-page support. If CPUID.01H:EDX.PGE [bit 13] = 1, CR4.PGE may be set to 1, enabling the global-page feature (see Section 4.10.1.4).
  • PAT: page-attribute table. If CPUID.01H:EDX.PAT [bit 16] = 1, the 8-entry page-attribute table (PAT) is supported. When the PAT is supported, three bits in certain paging-structure entries select a memory type (used to determine type of caching used) from the PAT (see Section 4.9).
  • PSE-36: 36-Bit page size extension. If CPUID.01H:EDX.PSE-36 [bit 17] = 1, the PSE-36 mechanism is supported, indicating that translations using 4-MByte pages with 32-bit paging may produce physical addresses with more than 32 bits (see Section 4.3).
  • NX: execute disable. If CPUID.80000001H:EDX.NX [bit 20] = 1, IA32_EFER.NXE may be set to 1, allowing PAE paging and IA-32e paging to disable execute access to selected pages (see Section 4.6). (Processors that do not support CPUID function 80000001H do not allow IA32_EFER.NXE to be set to 1.)
  • LM: IA-32e mode support. If CPUID.80000001H:EDX.LM [bit 29] = 1, IA32_EFER.LME may be set to 1, enabling IA-32e paging. (Processors that do not support CPUID function 80000001H do not allow IA32_EFER.LME to be set to 1.)
  • CPUID.80000008H:EAX[7:0] reports the physical-address width supported by the processor. (For processors that do not support CPUID function 80000008H, the width is generally 36 if CPUID.01H:EDX.PAE [bit 6] = 1 and 32 otherwise.) This width is referred to as MAXPHYADDR. MAXPHYADDR is at most 52.
  • CPUID.80000008H:EAX[15:8] reports the linear-address width supported by the processor. Generally, this value is 48 if CPUID.80000001H:EDX.LM [bit 29] = 1 and 32 otherwise. (Processors that do not support CPUID function 80000008H, support a linear-address width of 32.)
Page 119 of the Intel 253668-032US user manual — PAGING
Page 119 · click to enlarge
Page 119

PAGING

4.2 HIERARCHICAL PAGING STRUCTURES: AN OVERVIEW

All three paging modes translate linear addresses use hierarchical paging struc- tures. This section provides an overview of their operation. Section 4.3, Section 4.4, and Section 4.5 provide details for the three paging modes.

Every paging structure is 4096 Bytes in size and comprises a number of individual entries. With 32-bit paging, each entry is 32 bits (4 bytes); there are thus 1024 entries in each structure. With PAE paging and IA-32e paging, each entry is 64 bits (8 bytes); there are thus 512 entries in each structure. (PAE paging includes one exception, a paging structure that is 32 bytes in size, containing 4 64-bit entries.)

The processor uses the upper portion of a linear address to identify a series of paging-structure entries. The last of these entries identifies the physical address of the region to which the linear address translates (called the page frame). The lower portion of the linear address (called the page offset) identifies the specific address within that region to which the linear address translates.

Each paging-structure entry contains a physical address, which is either the address of another paging structure or the address of a page frame. In the first case, the entry is said to reference the other paging structure; in the latter, the entry is said to map a page.

The first paging structure used for any translation is located at the physical address in CR3. A linear address is translated using the following iterative procedure. A portion of the linear address (initially the uppermost bits) select an entry in a paging structure (initially the one located using CR3). If that entry references another paging structure, the process continues with that paging structure and with the portion of the linear address immediately below that just used. If instead the entry maps a page, the process completes: the physical address in the entry is that of the page frame and the remaining lower portion of the linear address is the page offset.

  • The following items give an example for each of the three paging modes (each example locates a 4-KByte page frame):
  • With 32-bit paging, each paging structure comprises 1024 = 2 10 entries. For this reason, the translation process uses 10 bits at a time from a 32-bit linear address. Bits 31:22 identify the first paging-structure entry and bits 21:12 identify a second. The latter identifies the page frame. Bits 11:0 of the linear address are the page offset within the 4-KByte page frame. (See Figure 4-2 for an illustration.)
  • With PAE paging, the first paging structure comprises only 4 = 2 2 entries. Translation thus begins by using bits 31:30 from a 32-bit linear address to identify the first paging-structure entry. Other paging structures comprise 512 =2 9 entries, so the process continues by using 9 bits at a time. Bits 29:21 identify a second paging-structure entry and bits 20:12 identify a third. This last identifies the page frame. (See Figure 4-5 for an illustration.)
  • With IA-32e paging, each paging structure comprises 512 = 2 9 entries and translation uses 9 bits at a time from a 48-bit linear address. Bits 47:39 identify the first paging-structure entry, bits 38:30 identify a second, bits 29:21 a third,
Page 120 of the Intel 253668-032US user manual — 4.3 32-BIT PAGING
Page 120 · click to enlarge
Page 120

PAGING

and bits 20:12 identify a fourth. Again, the last identifies the page frame. (See Figure 4-8 for an illustration.)

The translation process in each of the examples above completes by identifying a page frame. However, the paging structures may be configured so that translation terminates before doing so. This occurs if process encounters a paging-structure entry that is marked “not present” (because its P flag — bit 0 — is clear) or in which a reserved bit is set. In this case, there is no translation for the linear address; an access to that address causes a page-fault exception (see Section 4.7).

  • In the examples above, a paging-structure entry maps a page with 4-KByte page frame when only 12 bits remain in the linear address; entries identified earlier always reference other paging structures. That may not apply in other cases. The following items identify when an entry maps a page and when it references another paging structure:
  • If more than 12 bits remain in the linear address, bit 7 (PS — page size) of the current paging-structure entry is consulted. If the bit is 0, the entry references another paging structure; if the bit is 1, the entry maps a page.
  • If only 12 bits remain in the linear address, the current paging-structure entry always maps a page (bit 7 is used for other purposes).

If a paging-structure entry maps a page when more than 12 bits remain in the linear address, the entry identifies a page frame larger than 4 KBytes. For example, 32-bit paging uses the upper 10 bits of a linear address to locate the first paging-structure entry; 22 bits remain. If that entry maps a page, the page frame is 222 Bytes = 4 MBytes. 32-bit paging supports 4-MByte pages if CR4.PSE = 1. PAE paging and IA-32e paging support 2-MByte pages (regardless of the value of CR4.PSE).

Paging structures are given different names based their uses in the translation process. Table 4-2 gives the names of the different paging structures. It also provides, for each structure, the source of the physical address used to locate it (CR3 or a different paging-structure entry); the bits in the linear address used to select an entry from the structure; and details of about whether and how such an entry can map a page.

4.3 32-BIT PAGING

A logical processor uses 32-bit paging if CR0.PG = 1 and CR4.PAE = 0. 32-bit paging translates 32-bit linear addresses to 40-bit physical addresses.1 Although 40 bits

1. Bits in the range 39:32 are 0 in any physical address used by 32-bit paging except those used to map 4-MByte pages. If the processor does not support the PSE-36 mechanism, this is true also for physical addresses used to map 4-MByte pages. If the processor does support the PSE-36 mechanism and MAXPHYADDR < 40, bits in the range 39:MAXPHYADDR are 0 in any physical address used to map a 4-MByte page. (The corresponding bits are reserved in PDEs.) See Section 4.1.4 for how to determine MAXPHYADDR and whether the PSE-36 mechanism is supported.

Page 121 of the Intel 253668-032US user manual — PAGING
Page 121 · click to enlarge
Page 121

PAGING

Table 4-2. Paging Structures in the Different Paging Modes

Physical Address of Structure

Entry Name Paging Mode

IA-32e CR3 47:39 N/A (PS must be 0)

PAE CR3 31:30 N/A (PS must be 0) IA-32e PML4E 38:30

32-bit CR3 31:22 4-MByte page if PS=11

PAE, IA-32e PDPTE 29:21 2-MByte page if PS=1

21:12 4-KByte page

PAE, IA-32e 20:12 4-KByte page

corresponds to 1 TByte, linear addresses are limited to 32 bits; at most 4 GBytes of linear-address space may be accessed at any given time.

32-bit paging uses a hierarchy of paging structures to produce a translation for a linear address. CR3 is used to locate the first paging-structure, the page directory. Table 4-3 illustrates how CR3 is used with 32-bit paging.

Table 4-3. Use of CR3 with 32-Bit Paging

2:0 Ignored

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page directory during linear-address translation (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page directory during linear-address translation (see Section 4.9)

11:5 Ignored

Show 12 more labels / short text on this page
Bits Selecting Entry · Paging Structure · Page Mapping · 32-bit, PAE N/A · PML4 table PML4E · 32-bit N/A · Page-directory- pointer table PDPTE · Page directory PDE · 32-bit PDE · Page table PTE · Bit Position(s) · Contents
Page 122 of the Intel 253668-032US user manual — PTE
Page 122 · click to enlarge
Page 122

PAGING

Table 4-3. Use of CR3 with 32-Bit Paging (Contd.)

31:12 Physical address of the 4-KByte aligned page directory used for linear-address translation

63:32 Ignored (these bits exist only on processors supporting the Intel-64 architecture)

32-bit paging may map linear addresses to either 4-KByte pages or 4-MByte pages. Figure 4-2 illustrates the translation process when it uses a 4-KByte page; Figure 4-3 covers the case of a 4-MByte page. The following items describe the 32-bit paging process in more detail as well has how the page size is determined:

31 21 11 12 22 Linear Address

0 Directory Table Offset

PTE

CR3

Figure 4-2. Linear-Address Translation to a 4-KByte Page using 32-Bit Paging

  • A 4-KByte naturally aligned page directory is located at the physical address specified in bits 31:12 of CR3 (see Table 4-3). A page directory comprises 1024 32-bit entries (PDEs). A PDE is selected using the physical address defined as follows:

— Bits 39:32 are all 0.

— Bits 31:12 are from CR3.

— Bits 11:2 are bits 31:22 of the linear address.

— Bits 1:0 are 0.

Show 7 more labels / short text on this page
Bit Position(s) · Contents · 4-KByte Page · Page Table · Physical Address · Page Directory · PDE with PS=0
Page 123 of the Intel 253668-032US user manual — CR3
Page 123 · click to enlarge
Page 123

PAGING

31 21 22 Linear Address

CR3

Figure 4-3. Linear-Address Translation to a 4-MByte Page using 32-Bit Paging

Because a PDE is identified using bits 31:22 of the linear address, it controls access to a 4-Mbyte region of the linear-address space. Use of the PDE depends on CR.PSE and the PDE’s PS flag (bit 7): • If CR4.PSE = 1 and the PDE’s PS flag is 1, the PDE maps a 4-MByte page (see Table 4-4). The final physical address is computed as follows:

— Bits 39:32 are bits 20:13 of the PDE.

— Bits 31:22 are bits 31:22 of the PDE.1

— Bits 21:0 are from the original linear address. • If CR4.PSE = 0 or the PDE’s PS flag is 0, a 4-KByte naturally aligned page table is located at the physical address specified in bits 31:12 of the PDE (see Table 4-5). A page table comprises 1024 32-bit entries (PTEs). A PTE is selected using the physical address defined as follows:

— Bits 39:32 are all 0.

— Bits 31:12 are from the PDE.

— Bits 11:2 are bits 21:12 of the linear address.

— Bits 1:0 are 0. • Because a PTE is identified using bits 31:12 of the linear address, every PTE maps a 4-KByte page (see Table 4-6). The final physical address is computed as follows:

— Bits 39:32 are all 0.

1. The upper bits in the final physical address do not all come from corresponding positions in the PDE; the physical-address bits in the PDE are not all contiguous.
Show 5 more labels / short text on this page
0 Directory Offset · 4-MByte Page · Page Directory · Physical Address · PDE with PS=1
Page 124 of the Intel 253668-032US user manual — PAGING
Page 124 · click to enlarge
Page 124

PAGING

Table 4-4. Format of a 32-Bit Page-Directory Entry that Maps a 4-MByte Page

0 (P) Present; must be 1 to map a 4-MByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 4-MByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 4-MByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 4-MByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 4-MByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 4-MByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 4-MByte page referenced by this entry (see Section 4.8)

7 (PS) Page size; must be 1 (otherwise, this entry references a page table; see Table 4-5)

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

12 (PAT) If the PAT is supported, indirectly determines the memory type used to access the 4-MByte page referenced by this entry (see Section 4.9); otherwise, reserved (must be 0)1

M–20:13 Bits M–1:32 of physical address of the 4-MByte page referenced by this entry2

21:M–19 Reserved (must be 0)

31:22 Bits 31:22 of physical address of the 4-MByte page referenced by this entry

NOTES: 1. See Section 4.1.4 for how to determine whether the PAT is supported. 2. If the PSE-36 mechanism is not supported, M is 32, and this row does not apply. If the PSE-36 mechanism is supported, M is the minimum of 40 and MAXPHYADDR (this row does not apply if MAXPHYADDR = 32). See Section 4.1.4 for how to determine MAXPHYADDR and whether the PSE-36 mechanism is supported.

— Bits 31:12 are from the PTE.

Bit Position(s) · Contents

Page 125 of the Intel 253668-032US user manual — PAGING
Page 125 · click to enlarge
Page 125

PAGING

Table 4-5. Format of a 32-Bit Page-Directory Entry that References a Page Table

0 (P) Present; must be 1 to reference a page table

1 (R/W) Read/write; if 0, writes may not be allowed to the 4-MByte region controlled by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 4-MByte region controlled by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether this entry has been used for linear-address translation (see Section 4.8)

7 (PS) If CR4.PSE = 1, must be 0 (otherwise, this entry maps a 4-MByte page; see Table 4-4); otherwise, ignored

11:8 Ignored

31:12 Physical address of 4-KByte aligned page table referenced by this entry

— Bits 11:0 are from the original linear address.

If a paging-structure entry’s P flag (bit 0) is 0 or if the entry sets any reserved bit, the entry is used neither to reference another paging-structure entry nor to map a page. A reference using a linear address whose translation would use such a paging-struc- ture entry causes a page-fault exception (see Section 4.7).

With 32-bit paging, there are reserved bits only if CR4.PSE = 1: • If the P flag and the PS flag (bit 7) of a PDE are both 1, the bits reserved depend on MAXPHYADDR whether the PSE-36 mechanism is supported:1

— If the PSE-36 mechanism is not supported, bits 21:13 are reserved.

— If the PSE-36 mechanism is supported, bits 21:M–19 are reserved, where M is the minimum of 40 and MAXPHYADDR. • If the PAT is not supported:2

1. See Section 1.1.5 for how to determine MAXPHYADDR and whether the PSE-36 mechanism is supported.
2. See Section 4.1.4 for how to determine whether the PAT is supported.

Bit Position(s) · Contents · 6 Ignored

Page 126 of the Intel 253668-032US user manual — PAGING
Page 126 · click to enlarge
Page 126

PAGING

Table 4-6. Format of a 32-Bit Page-Table Entry that Maps a 4-KByte Page

0 (P) Present; must be 1 to map a 4-KByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 4-KByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 4-KByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 4-KByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 4-KByte page referenced by this entry (see Section 4.8)

7 (PAT) If the PAT is supported, indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9); otherwise, reserved (must be 0)1

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

31:12 Physical address of the 4-KByte page referenced by this entry

— If the P flag of a PTE is 1, bit 7 is reserved.

— If the P flag and the PS flag of a PDE are both 1, bit 12 is reserved.

(If CR4.PSE = 0, no bits are reserved with 32-bit paging.)

A reference using a linear address that is successfully translated to a physical address is performed only if allowed by the access rights of the translation; see Section 4.6.

Figure 4-4 gives a summary of the formats of CR3 and the paging-structure entries with 32-bit paging. For the paging structure entries, it identifies separately the format of entries that map pages, those that reference other paging structures, and

Bit Position(s) · Contents

Page 127 of the Intel 253668-032US user manual — 4.4 PAE PAGING
Page 127 · click to enlarge
Page 127

PAGING

those that do neither because they are “not present”; bit 0 (P) and bit 7 (PS) are highlighted because they determine how such an entry is used.

31302928272625242322212019181716151413121110 9 8 7 6 5 4 3 2 1 0

P C D

P W

Address of page directory1

T

Bits 39:32

P A T

P C D

P W

U

R

1 PDE4MB page

Bits 31:22 of address

Reserved (must be 0)

Ignored G 1 D A

/ S

/ W

of 2MB page frame

T

Address of page table Ignored 0 I g n

P C D

P W

U

R

1 PDEpage table

A

/ S

/ W

T

Ignored 0 PDE:

P A T

P C D

P W

U

R

1 PTE4KB page

Address of 4KB page frame Ignored G

D A

/ S

/ W

T

Ignored 0 PTE:

Figure 4-4. Formats of CR3 and Paging-Structure Entries with 32-Bit Paging

2. This example illustrates a processor in which MAXPHYADDR is 36. If this value is larger or smaller, the number of bits reserved in positions 20:13 of a PDE mapping a 4-MByte will change.

4.4 PAE PAGING

A logical processor uses PAE paging if CR0.PG = 1, CR4.PAE = 1, and IA32_EFER.LME = 0. PAE paging translates 32-bit linear addresses to 52-bit physical addresses.1 Although 52 bits corresponds to 4 PBytes, linear addresses are limited to 32 bits; at most 4 GBytes of linear-address space may be accessed at any given time.

With PAE paging, a logical processor maintains a set of four (4) PDPTE registers, which are loaded from an address in CR3. Linear address are translated using 4 hier- archies of in-memory paging structures, each located using one of the PDPTE regis-

1. If MAXPHYADDR < 52, bits in the range 51:MAXPHYADDR will be 0 in any physical address used by PAE paging. (The corresponding bits are reserved in the paging-structure entries.) See Section 4.1.4 for how to determine MAXPHYADDR.
Show 5 more labels / short text on this page
Ignored · Ignored CR3 · of address2 · not present · not present
Page 128 of the Intel 253668-032US user manual — 4.4.1 PDPTE Registers
Page 128 · click to enlarge
Page 128

PAGING

ters. (This is different from the other paging modes, in which there is one hierarchy referenced by CR3.)

Section 4.4.1 discusses the PDPTE registers. Section 4.4.2 describes linear-address translation with PAE paging.

4.4.1 PDPTE Registers

When PAE paging is used, CR3 references the base of a 32-Byte page-directory- pointer table. Table 4-7 illustrates how CR3 is used with PAE paging.

Table 4-7. Use of CR3 with PAE Paging

4:0 Ignored

31:5 Physical address of the 32-Byte aligned page-directory-pointer table used for linear-address translation

63:32 Ignored (these bits exist only on processors supporting the Intel-64 architecture)

  • The page-directory-pointer-table comprises four (4) 64-bit entries called PDPTEs. Each PDPTE controls access to a 1-GByte region of the linear-address space. Corresponding to the PDPTEs, the logical processor maintains a set of four (4) internal, non-architectural PDPTE registers, called PDPTE0, PDPTE1, PDPTE2, and PDPTE3. The logical processor loads these registers from the PDPTEs in memory as part of certain executions the MOV to CR instruction:
  • If an execution MOV to CR0 or MOV to CR4 causes the logical processor to transition from either no paging or 32-bit paging to PAE paging (see Section 4.1.2), the PDPTEs are loaded from the address in CR3.
  • If MOV to CR3 is executed while the logical processor is using PAE paging, the PDPTEs are loaded from the address being loaded into CR3.
  • If PAE paging is in use and a task switch changes the value of CR3, the PDPTEs are loaded from the address in the new CR3 value.
  • Certain VMX transitions load the PDPTE registers. See Section 4.11.1.

Unless the caches are disabled, the processor uses the WB memory type to load the PDPTEs from memory.1

1. Older IA-32 processors used the UC memory type when loading the PDPTEs. This behavior is model-specific and not architectural.

Bit Position(s) · Contents

Page 129 of the Intel 253668-032US user manual — 4.4.2 Linear-Address Translation with PAE Paging
Page 129 · click to enlarge
Page 129

PAGING

Table 4-8 gives the format of a PDPTE. If any of the PDPTEs sets both the P flag

Table 4-8. Format of an PAE Page-Directory-Pointer-Table Entry (PDPTE)

0 (P) Present; must be 1 to reference a page directory

2:1 Reserved (must be 0)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page directory referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page directory referenced by this entry (see Section 4.9)

8:5 Reserved (must be 0)

11:9 Ignored

M–1:12 Physical address of 4-KByte aligned page directory referenced by this entry1

63:M Reserved (must be 0)

(bit 0) and any reserved bit, the MOV to CR instruction causes a general-protection exception (#GP(0)) and the PDPTEs are not loaded.1 As show in Table 4-8, bits 2:1, 8:5, and 63:MAXPHYADDR are reserved in the PDPTEs.

4.4.2 Linear-Address Translation with PAE Paging

PAE paging may map linear addresses to either 4-KByte pages or 2-MByte pages. Figure 4-5 illustrates the translation process when it produces a 4-KByte page; Figure 4-6 covers the case of a 2-MByte page. The following items describe the PAE paging process in more detail as well has how the page size is determined: • Bits 31:30 of the linear address select a PDPTE register (see Section 4.4.1); this is PDPTEi, where i is the value of bits 31:30.2 Because a PDPTE register is identified using bits 31:30 of the linear address, it controls access to a 1-GByte region of the linear-address space. If the P flag (bit 0) of PDPTEi is 0, the

1. On some processors, reserved bits are checked even in PDPTEs in which the P flag (bit 0) is 0.
2. With PAE paging, the processor does not use CR3 when translating a linear address (as it does the other paging modes). It does not access the PDPTEs in the page-directory-pointer table during linear-address translation.

Bit Position(s) · Contents

Page 130 of the Intel 253668-032US user manual — PAGING
Page 130 · click to enlarge
Page 130

PAGING

Intel 253668-032US — PAGING diagram (page 130)
Fig. 10

Figure 4-5. Linear-Address Translation to a 4-KByte Page using PAE Paging

Intel 253668-032US — PAGING diagram (page 130)
Fig. 11

Figure 4-6. Linear-Address Translation to a 2-MByte Page using PAE Paging

processor ignores bits 63:1, and there is no mapping for the 1-GByte region controlled by PDPTEi. A reference using a linear address in this region causes a page-fault exception (see Section 4.7). • If the P flag of PDPTEi is 1, 4-KByte naturally aligned page directory is located at the physical address specified in bits 51:12 of PDPTEi (see Table 4-8 in Section

Page 131 of the Intel 253668-032US user manual — PAGING
Page 131 · click to enlarge
Page 131

PAGING

4.4.1) A page directory comprises 512 64-bit entries (PDEs). A PDE is selected using the physical address defined as follows:

— Bits 51:12 are from PDPTEi.

— Bits 11:3 are bits 29:21 of the linear address.

— Bits 2:0 are 0.

Because a PDE is identified using bits 31:21 of the linear address, it controls access to a 2-Mbyte region of the linear-address space. Use of the PDE depends on its PS flag (bit 7): • If the PDE’s PS flag is 1, the PDE maps a 2-MByte page (see Table 4-9). The final physical address is computed as follows:

— Bits 51:21 are from the PDE.

— Bits 20:0 are from the original linear address. • If the PDE’s PS flag is 0, a 4-KByte naturally aligned page table is located at the physical address specified in bits 51:12 of the PDE (see Table 4-10). A page directory comprises 512 64-bit entries (PTEs). A PTE is selected using the physical address defined as follows:

— Bits 51:12 are from the PDE.

— Bits 11:3 are bits 20:12 of the linear address.

— Bits 2:0 are 0. • Because a PTE is identified using bits 31:12 of the linear address, every PTE maps a 4-KByte page (see Table 4-11). The final physical address is computed as follows:

— Bits 51:12 are from the PTE.

— Bits 11:0 are from the original linear address.

If the P flag (bit 0) of a PDE or a PTE is 0 or if a PDE or a PTE sets any reserved bit, the entry is used neither to reference another paging-structure entry nor to map a page. A reference using a linear address whose translation would use such a paging- structure entry causes a page-fault exception (see Section 4.7).

  • The following bits are reserved with PAE paging:
  • If the P flag (bit 0) of a PDE or a PTE is 1, bits 62:MAXPHYADDR are reserved.
  • If the P flag and the PS flag (bit 7) of a PDE are both 1, bits 20:13 are reserved.
  • If IA32_EFER.NXE = 0 and the P flag of a PDE or a PTE is 1, the XD flag (bit 63) is reserved.
  • If the PAT is not supported: 1

— If the P flag of a PTE is 1, bit 7 is reserved.

— If the P flag and the PS flag of a PDE are both 1, bit 12 is reserved.

1. See Section 4.1.4 for how to determine whether the PAT is supported.
Page 132 of the Intel 253668-032US user manual — PAGING
Page 132 · click to enlarge
Page 132

PAGING

Table 4-9. Format of a PAE Page-Directory Entry that Maps a 2-MByte Page

0 (P) Present; must be 1 to map a 2-MByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 2-MByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 2-MByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 2-MByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 2-MByte page referenced by this entry (see Section 4.8)

7 (PS) Page size; must be 1 (otherwise, this entry references a page table; see Table 4-10)

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

12 (PAT) If the PAT is supported, indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9); otherwise, reserved (must be 0)1

20:13 Reserved (must be 0)

M–1:21 Physical address of the 2-MByte page referenced by this entry

62:M Reserved (must be 0)

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 2-MByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

Bit Position(s) · Contents

Page 133 of the Intel 253668-032US user manual — PAGING
Page 133 · click to enlarge
Page 133

PAGING

Table 4-10. Format of a PAE Page-Directory Entry that References a Page Table

0 (P) Present; must be 1 to reference a page table

1 (R/W) Read/write; if 0, writes may not be allowed to the 2-MByte region controlled by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 2-MByte region controlled by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether this entry has been used for linear-address translation (see Section 4.8)

7 (PS) Page size; must be 0 (otherwise, this entry maps a 2-MByte page; see Table 4-9)

11:8 Ignored

M–1:12 Physical address of 4-KByte aligned page table referenced by this entry

62:M Reserved (must be 0)

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 2-MByte region controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

A reference using a linear address that is successfully translated to a physical address is performed only if allowed by the access rights of the translation; see Section 4.6.

Figure 4-7 gives a summary of the formats of CR3 and the paging-structure entries with PAE paging. For the paging structure entries, it identifies separately the format of entries that map pages, those that reference other paging structures, and those

Bit Position(s) · Contents · 6 Ignored

Page 134 of the Intel 253668-032US user manual — PAGING
Page 134 · click to enlarge
Page 134

PAGING

Table 4-11. Format of a PAE Page-Table Entry that Maps a 4-KByte Page

0 (P) Present; must be 1 to map a 4-KByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 4-KByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 4-KByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 4-KByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 4-KByte page referenced by this entry (see Section 4.8)

7 (PAT) If the PAT is supported, indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9); otherwise, reserved (must be 0)1

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

M–1:12 Physical address of the 4-KByte page referenced by this entry

62:M Reserved (must be 0)

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 4-KByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

Bit Position(s) · Contents

Page 135 of the Intel 253668-032US user manual — 4.5 IA-32E PAGING
Page 135 · click to enlarge
Page 135

PAGING

that do neither because they are “not present”; bit 0 (P) and bit 7 (PS) are high- lighted because they determine how a paging-structure entry is used.

6 3 6 2 6 1 6 0 5 9 5 8 5 7 5 6 5 5 5 4 5 3 5 2 5 1 M1

M-1 3 2 3 1 3 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0

Address of page-directory-pointer table Ignored CR3

P C D

P W

Address of page directory Ign. Rsvd.

Rs vd 1 PDPTE:

T

Ignored 0 PDTPE:

P A T

P C D

P W

U

R

1 PDE2MB page

X D Ignored Rsvd. Address of 2MB page frame Reserved

Ign. G 1 D A

/ S

/ W

T

X D Ignored Rsvd. Address of page table Ign. 0 I g n

P C D

P W

U

R

1 PDEpage table

A

/ S

/ W

T

Ignored 0 PDE:

P A T

P C D

P W

U

R

1 PTE4KB page

X D Ignored Rsvd. Address of 4KB page frame Ign. G

D A

/ S

/ W

T

Ignored 0 PTE:

Figure 4-7. Formats of CR3 and Paging-Structure Entries with PAE Paging

2. CR3 has 64 bits only on processors supporting the Intel-64 architecture. These bits are ignored with PAE paging.
3. Reserved fields must be 0.

4.5 IA-32E PAGING

A logical processor uses IA-32e paging if CR0.PG = 1, CR4.PAE = 1, and IA32_EFER.LME = 1. With IA-32e paging, linear address are translated using a hier- archy of in-memory paging structures located using the contents of CR3. IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.1 Although 52

Show 6 more labels / short text on this page
Ignored2 · Reserved3 · present · not present · not present · not present
Page 136 of the Intel 253668-032US user manual — PAGING
Page 136 · click to enlarge
Page 136

PAGING

bits corresponds to 4 PBytes, linear addresses are limited to 48 bits; at most 256 TBytes of linear-address space may be accessed at any given time.

IA-32e paging uses a hierarchy of paging structures to produce a translation for a linear address. CR3 is used to locate the first paging-structure, the PML4 table. Table 4-12 illustrates how CR3 is used with IA-32e paging.

Table 4-12. Use of CR3 with IA-32e Paging

2:0 Ignored

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the PML4 table during linear-address translation (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the PML4 table during linear-address translation (see Section 4.9)

11:5 Ignored

M–1:12 Physical address of the 4-KByte aligned PML4 table used for linear-address translation1

63:M Reserved (must be 0)

IA-32e paging may map linear addresses to either 4-KByte pages or 2-MByte pages. Figure 4-8 illustrates the translation process when it produces a 4-KByte page; Figure 4-9 covers the case of a 2-MByte page. The following items describe the IA-32e paging process in more detail as well has how the page size is determined: • A 4-KByte naturally aligned PML4 table is located at the physical address specified in bits 51:12 of CR3 (see Table 4-12). A PML4 table comprises 512 64- bit entries (PML4Es). A PML4E is selected using the physical address defined as follows:

— Bits 51:12 are from CR3.

— Bits 11:3 are bits 47:39 of the linear address.

— Bits 2:0 are all 0.

Because a PML4E is identified using bits 47:39 of the linear address, it controls access to a 512-GByte region of the linear-address space.

1. If MAXPHYADDR < 52, bits in the range 51:MAXPHYADDR will be 0 in any physical address used by IA-32e paging. (The corresponding bits are reserved in the paging-structure entries.) See Section 4.1.4 for how to determine MAXPHYADDR.

Bit Position(s) · Contents

Page 137 of the Intel 253668-032US user manual — PAGING
Page 137 · click to enlarge
Page 137

PAGING

Intel 253668-032US — PAGING diagram (page 137)
Fig. 12

Figure 4-8. Linear-Address Translation to a 4-KByte Page using IA-32e Paging

  • A 4-KByte naturally aligned page-directory-pointer table is located at the physical address specified in bits 51:12 of the PML4E (see Table 4-13). A pagedirectory-pointer table comprises 512 64-bit entries (PDPTEs). A PDPTE is selected using the physical address defined as follows:

— Bits 51:12 are from the PML4E.

— Bits 11:3 are bits 38:30 of the linear address.

— Bits 2:0 are all 0.

Because a PDPTE is identified using bits 47:30 of the linear address, it controls access to a 1-GByte region of the linear-address space. • A 4-KByte naturally aligned page directory is located at the physical address specified in bits 51:12 of the PDPTE (see Table 4-14). A page directory comprises 512 64-bit entries (PDEs). A PDE is selected using the physical address defined as follows:

— Bits 51:12 are from the PDPTE.

— Bits 11:3 are bits 29:21 of the linear address.

— Bits 2:0 are all 0.

Page 138 of the Intel 253668-032US user manual — PAGING
Page 138 · click to enlarge
Page 138

PAGING

Intel 253668-032US — PAGING diagram (page 138)
Fig. 13

Figure 4-9. Linear-Address Translation to a 2-MByte Page using IA-32e Paging

Because a PDE is identified using bits 47:21 of the linear address, it controls access to a 2-MByte region of the linear-address space. Use of the PDE depends on its PS flag (bit 7):

Page 139 of the Intel 253668-032US user manual — PAGING
Page 139 · click to enlarge
Page 139

PAGING

Table 4-13. Format of an IA-32e PML4 Entry (PML4E) that References a Page-

0 (P) Present; must be 1 to reference a page-directory-pointer table

1 (R/W) Read/write; if 0, writes may not be allowed to the 512-GByte region controlled by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 512-GByte region controlled by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page-directory-pointer table referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page-directory-pointer table referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether this entry has been used for linear-address translation (see Section 4.8)

7 (PS) Reserved (must be 0)

11:8 Ignored

M–1:12 Physical address of 4-KByte aligned page-directory-pointer table referenced by this entry

51:M Reserved (must be 0)

62:52 Ignored

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 512-GByte region controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

Show 4 more labels / short text on this page
Directory-Pointer Table · Bit Position(s) · Contents · 6 Ignored
Page 140 of the Intel 253668-032US user manual — PAGING
Page 140 · click to enlarge
Page 140

PAGING

Table 4-14. Format of an IA-32e Page-Directory-Pointer-Table Entry (PDPTE) that

References a Page Directory

0 (P) Present; must be 1 to reference a page directory

1 (R/W) Read/write; if 0, writes may not be allowed to the 1-GByte region controlled by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 1-GByte region controlled by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page directory referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page directory referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether this entry has been used for linear-address translation (see Section 4.8)

7 (PS) Reserved (must be 0)

11:8 Ignored

M–1:12 Physical address of 4-KByte aligned page directory referenced by this entry

51:M Reserved (must be 0)

62:52 Ignored

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 1-GByte region controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

  • If the PDE’s PS flag is 1, the PDE maps a 2-MByte page (see Table 4-15). The final physical address is computed as follows:

Table 4-15. Format of an IA-32e Page-Directory Entry that Maps a 2-MByte Page

0 (P) Present; must be 1 to map a 2-MByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 2-MByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

Show 5 more labels / short text on this page
Bit Position(s) · Contents · 6 Ignored · Bit Position(s) · Contents
Page 141 of the Intel 253668-032US user manual — PAGING
Page 141 · click to enlarge
Page 141

PAGING

Table 4-15. Format of an IA-32e Page-Directory Entry that Maps a 2-MByte Page

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 2-MByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 2-MByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 2-MByte page referenced by this entry (see Section 4.8)

7 (PS) Page size; must be 1 (otherwise, this entry references a page table; see Table 4-16)

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

12 (PAT) Indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)1

20:13 Reserved (must be 0)

M–1:21 Physical address of the 2-MByte page referenced by this entry

51:M Reserved (must be 0)

62:52 Ignored

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 2-MByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

— Bits 51:21 are from the PDE.

— Bits 20:0 are from the original linear address. • If the PDE’s PS flag is 0, a 4-KByte naturally aligned page table is located at the physical address specified in bits 51:12 of the PDE (see Table 4-16). A page table

Bit Position(s) · Contents

Page 142 of the Intel 253668-032US user manual — PAGING
Page 142 · click to enlarge
Page 142

PAGING

comprises 512 64-bit entries (PTEs). A PTE is selected using the physical address defined as follows:

Table 4-16. Format of an IA-32e Page-Directory Entry that References a Page Table

0 (P) Present; must be 1 to reference a page table

1 (R/W) Read/write; if 0, writes may not be allowed to the 2-MByte region controlled by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 2-MByte region controlled by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the page table referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether this entry has been used for linear-address translation (see Section 4.8)

7 (PS) Page size; must be 0 (otherwise, this entry maps a 2-MByte page; see Table 4-15)

11:8 Ignored

M–1:12 Physical address of 4-KByte aligned page table referenced by this entry

51:M Reserved (must be 0)

62:52 Ignored

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 2-MByte region controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

— Bits 51:12 are from the PDE.

— Bits 11:3 are bits 20:12 of the linear address.

— Bits 2:0 are all 0. • Because a PTE is identified using bits 47:12 of the linear address, every PTE maps a 4-KByte page (see Table 4-17). The final physical address is computed as follows:

— Bits 51:12 are from the PTE.

Bit Position(s) · Contents · 6 Ignored

Page 143 of the Intel 253668-032US user manual — PAGING
Page 143 · click to enlarge
Page 143

PAGING

Table 4-17. Format of an IA-32e Page-Table Entry that Maps a 4-KByte Page

0 (P) Present; must be 1 to map a 4-KByte page

1 (R/W) Read/write; if 0, writes may not be allowed to the 4-KByte page referenced by this entry (depends on CPL and CR0.WP; see Section 4.6)

2 (U/S) User/supervisor; if 0, accesses with CPL=3 are not allowed to the 4-KByte page referenced by this entry (see Section 4.6)

3 (PWT) Page-level write-through; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

4 (PCD) Page-level cache disable; indirectly determines the memory type used to access the 4-KByte page referenced by this entry (see Section 4.9)

5 (A) Accessed; indicates whether software has accessed the 4-KByte page referenced by this entry (see Section 4.8)

6 (D) Dirty; indicates whether software has written to the 4-KByte page referenced by this entry (see Section 4.8)

7 (PAT) Indirectly determines the memory type used to access the 2-MByte page referenced by this entry (see Section 4.9)

8 (G) Global; if CR4.PGE = 1, determines whether the translation is global (see Section 4.10); ignored otherwise

11:9 Ignored

M–1:12 Physical address of the 4-KByte page referenced by this entry

51:M Reserved (must be 0)

62:52 Ignored

63 (XD) If IA32_EFER.NXE = 1, execute-disable (if 1, instruction fetches are not allowed from the 4-KByte page controlled by this entry; see Section 4.6); otherwise, reserved (must be 0)

— Bits 11:0 are from the original linear address.

If a paging-structure entry’s P flag (bit 0) is 0 or if the entry sets any reserved bit, the entry is used neither to reference another paging-structure entry nor to map a page. A reference using a linear address whose translation would use such a paging-struc- ture entry causes a page-fault exception (see Section 4.7).

The following bits are reserved with IA-32e paging: • If the P flag of a paging-structure entry is 1, bits 51:MAXPHYADDR are reserved.

Bit Position(s) · Contents

Page 144 of the Intel 253668-032US user manual — 4.6 ACCESS RIGHTS
Page 144 · click to enlarge
Page 144

PAGING

  • If the P flag of a PML4E or a PDPTE is 1, the PS flag is reserved.
  • If the P flag and the PS flag of a PDE are both 1, bits 20:13 are reserved.
  • If IA32_EFER.NXE = 0 and the P flag of a paging-structure entry is 1, the XD flag (bit 63) is reserved.

A reference using a linear address that is successfully translated to a physical address is performed only if allowed by the access rights of the translation; see Section 4.6.

Figure 4-10 gives a summary of the formats of CR3 and the IA-32e paging-structure entries. For the paging structure entries, it identifies separately the format of entries that map pages, those that reference other paging structures, and those that do neither because they are “not present”; bit 0 (P) and bit 7 (PS) are highlighted because they determine how a paging-structure entry is used.

4.6 ACCESS RIGHTS

There is a translation for a linear address if the processes described in Section 4.3, Section 4.4.2, and Section 4.5 (depending upon the paging mode) completes and produces a physical address. The accesses permitted by a translation is determined by the access rights specified by the paging-structure entries controlling the transla- tion.1 The following items detail how paging determines access rights: • For accesses in supervisor mode (CPL < 3):

— Data reads. Data may be read from any linear address with a valid translation.

  • — Data writes.
  • If CR0.WP = 0, data may be written to any linear address with a valid translation.
  • If CR0.WP = 1, data may be written to any linear address with a valid translation for which the R/W flag (bit 1) is 1 in every paging-structure entry controlling the translation.
  • — Instruction fetches.
  • For 32-bit paging or if IA32_EFER.NXE = 0, instructions may be fetched from any linear address with a valid translation.
  • For PAE paging or IA-32e paging with IA32_EFER.NXE = 1, instructions may be fetched from any linear address with a valid translation for which the XD flag (bit 63) is 0 in every paging-structure entry controlling the translation.
  • For accesses in user mode (CPL = 3):
1. With PAE paging, the PDPTEs do not determine access rights.
Page 145 of the Intel 253668-032US user manual — PAGING
Page 145 · click to enlarge
Page 145

PAGING

Intel 253668-032US — PAGING diagram (page 145)
Fig. 14

6 3 6 2 6 1 6 0 5 9 5 8 5 7 5 6 5 5 5 4 5 3 5 2 5 1 M1 M-1 3 2 3 1 3 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 3 2 1 0

X D Ignored Rsvd. Address of page-directory-pointer table Ign.

X D Ignored Rsvd. Address of page directory Ign.

X D Ignored Rsvd. Address of 2MB page frame Reserved

X D Ignored Rsvd. Address of page table Ign. 0 I g n

X D Ignored Rsvd. Address of 4KB page frame Ign. G

Figure 4-10. Formats of CR3 and Paging-Structure Entries with IA-32e Paging

— Data reads. Data may be read from any linear address with a valid translation for which the U/S flag (bit 2) is 1 in every paging-structure entry controlling the trans- lation.

— Data writes. Data may be written to any linear address with a valid translation for which

Page 146 of the Intel 253668-032US user manual — 4.7 PAGE-FAULT EXCEPTIONS
Page 146 · click to enlarge
Page 146

PAGING

both the R/W flag and the U/S flag are 1 in every paging-structure entry controlling the translation.

  • — Instruction fetches.
  • For 32-bit paging or if IA32_EFER.NXE = 0, instructions may be fetched from any linear address with a valid translation for which the U/S flag is 1 in every paging-structure entry controlling the translation.
  • For PAE paging or IA-32e paging with IA32_EFER.NXE = 1, instructions may be fetched from any linear address with a valid translation for which the U/S flag is 1 and the XD flag is 0 in every paging-structure entry controlling the translation.

A processor may cache information from the paging-structure entries in TLBs and paging-structure caches (see Section 4.10). These structures may include informa- tion about access rights. The processor may enforce access rights based on the TLBs and paging-structure caches instead of on the paging structures in memory.

This fact implies that, if software modifies a paging-structure entry to change access rights, the processor might not use that change for a subsequent access to an affected linear address (see Section 4.10.3.3). See Section 4.10.3.2 for how soft- ware can ensure that the processor uses the modified access rights.

4.7 PAGE-FAULT EXCEPTIONS

Accesses using linear addresses may cause page-fault exceptions (#PF; exception 14). An access to a linear address may cause page-fault exception for either of two reasons: (1) there is no valid translation for the linear address; or (2) there is a valid translation for the linear address, but its access rights do not permit the access.

As noted in Section 4.3, Section 4.4.2, and Section 4.5, there is no valid translation for a linear address if the translation process for that address would use a paging- structure entry in which the P flag (bit 0) is 0 or one that sets a reserved bit. If there is a valid translation for a linear address, its access rights are determined as specified in Section 4.6.

  • Figure 4-11 illustrates the error code that the processor provides on delivery of a page-fault exception. The following items explain how the bits in the error code describe the nature of the page-fault exception:
  • P flag (bit 0). This flag is 0 if there is no valid translation for the linear address because the P flag was 0 in one of the paging-structure entries used to translate that address.
  • W/R (bit 1). If the access causing the page-fault exception was a write, this flag is 1; otherwise, it is 0. This flag describes the access causing the page-fault exception, not the access rights specified by paging.
  • U/S (bit 2). If a supervisor-mode (CPL < 3) access caused the page-fault exception, this flag
Page 147 of the Intel 253668-032US user manual — RSVD 0 1
Page 147 · click to enlarge
Page 147

PAGING

1 2 3 4

I/D

P W/R U/S RSVD

P 0 1

The fault was caused by a non-present page. The fault was caused by a page-level protection violation.

W/R 0 1

The access causing the fault was a read. The access causing the fault was a write.

U/S 0

The access causing the fault originated when the processor

was executing in supervisor mode. The access causing the fault originated when the processor

was executing in user mode.

RSVD 0 1

The fault was not caused by reserved bit violation. The fault was caused by a reserved bit set to 1 in some

paging-structure entry.

I/D 0 The fault was not caused by an instruction fetch. 1 The fault was caused by an instruction fetch.

Figure 4-11. Page-Fault Error Code

is 1; it is 0 if a user-mode (CPL = 3) access did so. This flag describes the access causing the page-fault exception, not the access rights specified by paging. • RSVD flag (bit 3). This flag is 1 if there is no valid translation for the linear address because a reserved bit was set in one of the paging-structure entries used to translate that address. (Because reserved bits are not checked in a paging-structure entry whose P flag is 0, bit 3 of the error code can be set only if bit 0 is also set.)

Bits reserved in the paging-structure entries are reserved for future functionality. Software developers should be aware that such bits may be used in the future and that a paging-structure entry that causes a page-fault exception on one processor might not do so in the future. • I/D flag (bit 4). Use of this flag depends on the settings of CR4.PAE and IA32_EFER.NXE:

— CR4.PAE = 0 (32-bit paging is in use) or IA32_EFER.NXE= 0. This flag is 0.

— CR4.PAE = 1 (either PAE paging or IA-32e paging is in use) and IA32_EFER.NXE= 1. If the access causing the page-fault exception was an instruction fetch, this flag is 1; otherwise, it is 0. This flag describes the access causing the page- fault exception, not the access rights specified by paging.

Reserved

Page 148 of the Intel 253668-032US user manual — NOTE
Page 148 · click to enlarge
Page 148

PAGING

Page-fault exceptions occur only due to an attempt to use a linear address. Failures to load the PDPTE registers with PAE paging (see Section 4.4.1) cause general- protection exceptions (#GP(0)) and not page-fault exceptions.

4.8 ACCESSED AND DIRTY FLAGS

For any paging-structure entry that is used during linear-address translation, bit 5 is the accessed flag.1 For paging-structure entries that map a page (as opposed to referencing another paging structure), bit 6 is the dirty flag. These flags are provided for use by memory-management software to manage the transfer of pages and paging structures into and out of physical memory.

Whenever the processor uses a paging-structure entry as part of linear-address translation, it sets the accessed flag in that entry (if it is not already set).

Whenever there is a write to a linear address, the processor sets the dirty flag (if it is not already set) in the paging-structure entry that identifies the final physical address for the linear address (either a PTE or a PDE in which the PS flag is 1).

Memory-management software may clear these flags when a page or a paging struc- ture is initially loaded into physical memory. These flags are “sticky,” meaning that, once set, the processor does not clear them; only software can clear them.

A processor may cache information from the paging-structure entries in TLBs and paging-structure caches (see Section 4.10). This fact implies that, if software changes an accessed flag or a dirty flag from 1 to 0, the processor might not set the corresponding bit in memory on a subsequent access using an affected linear address (see Section 4.10.3.3). See Section 4.10.3.2 for how software can ensure that these bits are updated as desired.

NOTE

The accesses used by the processor to set these flags may or may not be exposed to the processor’s self-modifying code detection logic. If the processor is executing code from the same memory area that is being used for the paging structures, the setting of these flags may or may not result in an immediate change to the executing code stream.

1. With PAE paging, the PDPTEs are not used during linear-address translation but only to load the PDPTE registers for some executions of the MOV CR instruction (see Section 4.4.1). For this reason, the PDPTEs do not contain accessed flags with PAE paging.
Page 149 of the Intel 253668-032US user manual — NOTE
Page 149 · click to enlarge
Page 149

PAGING

4.9 PAGING AND MEMORY TYPING

The memory type of a memory access refers to the type of caching used for that access. Chapter 11, “Memory Cache Control” provides many details regarding memory typing in the Intel-64 and IA-32 architectures. This section describes how paging contributes to the determination of memory typing.

The way in which paging contributes to memory typing depends on whether the processor supports the Page Attribute Table (PAT; see Section 11.12).1 Section 4.9.1 and Section 4.9.2 explain how paging contributes to memory typing depending on whether the PAT is supported.

4.9.1 Paging and Memory Typing When the PAT is Not Supported (Pentium Pro and Pentium II Processors)

NOTE

The PAT is supported on all processors that support IA-32e paging. Thus, this section applies only to 32-bit paging and PAE paging.

If the PAT is not supported, paging contributes to memory typing in conjunction with the memory-type range registers (MTRRs) as specified in Table 11-6 in Section 11.5.2.1.

  • For any access to a physical address, the table combines the memory type specified for that physical address by the MTRRs with a PCD value and a PWT value. The latter two values are determined as follows:
  • For an access to a PDE with 32-bit paging, the PCD and PWT values come from CR3.
  • For an access to a PDE with PAE paging, the PCD and PWT values come from the relevant PDPTE register.
  • For an access to a PTE, the PCD and PWT values come from the relevant PDE.
  • For an access to the physical address that is the translation of a linear address, the PCD and PWT values come from the relevant PTE (if the translation uses a 4KByte page) or the relevant PDE (otherwise).

4.9.2 Paging and Memory Typing When the PAT is Supported (Pentium III and More Recent Processor Families)

If the PAT is supported, paging contributes to memory typing in conjunction with the PAT and the memory-type range registers (MTRRs) as specified in Table 11-7 in Section 11.5.2.2.

1. The PAT is supported on Pentium III and more recent processor families. See Section 4.1.4 for how to determine whether the PAT is supported.
Page 150 of the Intel 253668-032US user manual — 4.10 CACHING TRANSLATION INFORMATION
Page 150 · click to enlarge
Page 150

PAGING

The PAT is a 64-bit MSR (IA32_PAT; MSR index 277H) comprising eight (8) 8-bit entries (entry i comprises bits 8i+7:8i of the MSR).

  • For any access to a physical address, the table combines the memory type specified for that physical address by the MTRRs with a memory type selected from the PAT. Table 11-11 in Section 11.12.3 specifies how a memory type is selected from the PAT. Specifically, it comes from entry i of the PAT, where i is defined as follows:
  • For an access to an entry in a paging structure whose address is in CR3 (e.g., the PML4 table with IA-32e paging), i = 2*PCD+PWT, where the PCD and PWT values come from CR3.
  • For an access to a PDE with PAE paging, i = 2*PCD+PWT, where the PCD and PWT values come from the relevant PDPTE register.
  • For an access to a paging-structure entry X whose address is in another pagingstructure entry Y, i = 2*PCD+PWT, where the PCD and PWT values come from Y.
  • For an access to the physical address that is the translation of a linear address, i = 4*PAT+2*PCD+PWT, where the PAT, PCD, and PWT values come from the relevant PTE (if the translation uses a 4-KByte page) or the relevant PDE (if the translation uses a 2-MByte page or a 4-MByte page).

4.9.3 Caching Paging-Related Information about Memory Typing

A processor may cache information from the paging-structure entries in TLBs and paging-structure caches (see Section 4.10). These structures may include informa- tion about memory typing. The processor may memory-typing information from the TLBs and paging-structure caches instead of from the paging structures in memory.

This fact implies that, if software modifies a paging-structure entry to change the memory-typing bits, the processor might not use that change for a subsequent translation using that entry or for access to an affected linear address. See Section 4.10.3.2 for how software can ensure that the processor uses the modified memory typing.

4.10 CACHING TRANSLATION INFORMATION

The Intel-64 and IA-32 architectures may accelerate the address-translation process by caching data from the paging structures on the processor. Because the processor does not ensure that the data that it caches are always consistent with the structures in memory, it is important for software developers to understand how and when the processor may cache such data. They should also understand what actions software can take to remove cached data that may be inconsistent and when it should do so. This section provides software developers information about the relevant processor operation.

Section 4.10.1 and Section 4.10.2 describe how the processor may cache informa- tion in translation lookaside buffers (TLBs) and paging-structure caches, respec-

Page 151 of the Intel 253668-032US user manual — 4.10.1 Translation Lookaside Buffers (TLBs)
Page 151 · click to enlarge
Page 151

PAGING

tively. Section 4.10.3 explains how software can remove inconsistent cached information by invalidating portions of the TLBs and paging-structure caches. Section 4.10.4 describes special considerations for multiprocessor systems.

4.10.1 Translation Lookaside Buffers (TLBs)

A processor may cache information about the translation of linear addresses in trans- lation lookaside buffers (TLBs). In general, TLBs contain entries that map page numbers to page frames; these terms are defined in Section 4.10.1.1. Section 4.10.1.2 describes how information may be cached in TLBs, and Section 4.10.1.3 gives details of TLB usage. Section 4.10.1.4 explains the global-page feature, which allows software to indicate that certain translations should receive special treatment when cached in the TLBs.

4.10.1.1 Page Numbers, Page Frames, and Page Offsets

Section 4.3, Section 4.4.2, and Section 4.5 give details of how the different paging modes translate linear addresses to physical addresses. Specifically, the upper bits of a linear address (called the page number) determine the upper bits of the physical address (called the page frame); the lower bits of the linear address (called the page offset) determine the lower bits of the physical address. The boundary between the page number and the page offset is determined by the page size. Specifically: • 32-bit paging:

— If the translation does not use a PTE (because CR4.PSE = 1 and the PS flag is 1 in the PDE used), the page size is 4 MBytes and the page number comprises bits 31:22 of the linear address.

— If the translation does use a PTE, the page size is 4 KBytes and the page number comprises bits 31:12 of the linear address. • PAE paging:

— If the translation does not use a PTE (because the PS flag is 1 in the PDE used), the page size is 2 MBytes and the page number comprises bits 31:21 of the linear address.

— If the translation does uses a PTE, the page size is 4 KBytes and the page number comprises bits 31:12 of the linear address. • IA-32e paging:

— If the translation does not uses a PTE (because the PS flag is 1 in the PDE used), the page size is 2 MBytes and the page number comprises bits 47:21 of the linear address.

— If the translation does use a PTE, the page size is 4 KBytes and the page number comprises bits 47:12 of the linear address.

Page 152 of the Intel 253668-032US user manual — PAGING
Page 152 · click to enlarge
Page 152

PAGING

4.10.1.2 Caching Translations in TLBs

  • The processor may accelerate the paging process by caching individual translations in translation lookaside buffers ( TLBs ). Each entry in a TLB is an individual translation. Each translation is referenced by a page number. It contains the following information from the paging-structure entries used to translate linear addresses with the page number:
  • The physical address corresponding to the page number (the page frame).
  • The access rights from the paging-structure entries used to translate linear addresses with the page number (see Section 4.6):

— The logical-AND of the R/W flags.

— The logical-AND of the U/S flags.

— The logical-OR of the XD flags (necessary only if IA32_EFER.NXE = 1). • Attributes from a paging-structure entry that identifies the final page frame for the page number (either a PTE or a PDE in which the PS flag is 1):

— The dirty flag (see Section 4.8).

— The memory type (see Section 4.9).

(TLB entries may contain other information as well. A processor may implement multiple TLBs, and some of these may be for special purposes, e.g., only for instruc- tion fetches. Such special-purpose TLBs may not contain some of this information if it is not necessary. For example, a TLB used only for instruction fetches need not contain information about the R/W and dirty flags.)

Processors need not implement any TLBs. Processors that do implement TLBs may invalidate any TLB entry at any time. Software should not rely on the existence of TLBs or on the retention of TLB entries.

4.10.1.3 Details of TLB Use

Because the TLBs cache only valid translations, there can be a TLB entry for a page number only if the P flag is 1 and the reserved bits are 0 in each of the paging-struc- ture entries used to translate that page number. In addition, the processor does not cache a translation for a page number unless the accessed flag is 1 in each of the paging-structure entries used during translation; before caching a translation, the processor sets any of these accessed flags that is not already 1.

The processor may cache translations required for prefetches and for accesses that are a result of speculative execution that would never actually occur in the executed code path.

If the page number of a linear address corresponds to a TLB entry, the processor may use that TLB entry to determine the page frame, access rights, and other attributes for accesses to that linear address. In this case, the processor may not actually consult the paging structures in memory. The processor may retain a TLB entry unmodified even if software subsequently modifies the relevant paging-structure

Page 153 of the Intel 253668-032US user manual — 4.10.2 Paging-Structure Caches
Page 153 · click to enlarge
Page 153

PAGING

entries in memory. See Section 4.10.3.2 for how software can ensure that the processor uses the modified paging-structure entries.

If the paging structures specify a translation using a page larger than 4 KBytes, some processors may choose to cache multiple smaller-page TLB entries for that transla- tion. Each such TLB entry would be associated with a page number corresponding to the smaller page size (e.g., bits 47:12 of a linear address with IA-32e paging), even though part of that page number (e.g., bits 20:12) are part of the offset with respect to the page specified by the paging structures. The upper bits of the physical address in such a TLB entry are derived from the physical address in the PDE used to create the translation, while the lower bits come from the linear address of the access for which the translation is created. There is no way for software to be aware that multiple translations for smaller pages have been used for a large page.

If software modifies the paging structures so that the page size used for a 4-KByte range of linear addresses changes, the TLBs may subsequently contain multiple translations for the address range (one for each page size). A reference to a linear address in the address range may use either translation. Which translation is used may vary from one execution to another, and the choice may be implementation- specific.

4.10.1.4 Global Pages

The Intel-64 and IA-32 architectures also allow for global pages when the PGE flag (bit 7) is 1 in CR4. If the G flag (bit 8) is 1 in a paging-structure entry that maps a page (either a PTE or a PDE in which the PS flag is 1), any TLB entry cached for a linear address using that paging-structure entry is considered to be global. Because the G flag is used only in paging-structure entries that map a page, and because information from such entries are not cached in the paging-structure caches, the global-page feature does not affect the behavior of the paging-structure caches.

4.10.2 Paging-Structure Caches

In addition to the TLBs, a processor may cache other information about the paging structures in memory.

4.10.2.1 Caches for Paging Structures

A processor may support any or of all the following paging-structure caches: • PML4 cache (IA-32e paging only). Each PML4-cache entry is referenced by a 9- bit value and is used for linear addresses for which bits 47:39 have that value. The entry contains information from the PML4E used to translate such linear addresses:

— The physical address from the PML4E (the address of the page-directory- pointer table).

Page 154 of the Intel 253668-032US user manual — PAGING
Page 154 · click to enlarge
Page 154

PAGING

— The value of the R/W flag of the PML4E.

— The value of the U/S flag of the PML4E.

— The value of the XD flag of the PML4E.

— The values of the PCD and PWT flags of the PML4E.

The following items detail how a processor may use the PML4 cache:

— If the processor has a PML4-cache entry for a linear address, it may use that entry when translating the linear address (instead of the PML4E in memory).

— The processor does not create a PML4-cache entry unless the P flag is 1 and all reserved bits are 0 in the PML4E in memory.

— The processor does not create a PML4-cache entry unless the accessed flag is 1 in the PML4E in memory; before caching a translation, the processor sets the accessed flag if it is not already 1.

— The processor may create a PML4-cache entry even if there are no transla- tions for any linear address that might use that entry (e.g., because the P flags are 0 in all entries in the referenced page-directory-pointer table).

— If the processor creates a PML4-cache entry, the processor may retain it unmodified even if software subsequently modifies the corresponding PML4E in memory. • PDPTE cache (IA-32e paging only).1 Each PDPTE-cache entry is referenced by an 18-bit value and is used for linear addresses for which bits 47:30 have that value. The entry contains information from the PML4E and PDPTE used to translate such linear addresses:

— The physical address from the PDPTE (the address of the page directory).

— The logical-AND of the R/W flags in the PML4E and the PDPTE.

— The logical-AND of the U/S flags in the PML4E and the PDPTE.

— The logical-OR of the XD flags in the PML4E and the PDPTE.

— The values of the PCD and PWT flags of the PDPTE.

The following items detail how a processor may use the PDPTE cache:

— If the processor has a PDPTE-cache entry for a linear address, it may use that entry when translating the linear address (instead of the PML4E and the PDPTE in memory).

— The processor does not create a PDPTE-cache entry unless the P flag is 1 and the reserved bits are 0 in the PML4E and the PDPTE in memory.

— The processor does not create a PDPTE-cache entry unless the accessed flags are 1 in the PML4E and the PDPTE in memory; before caching a translation, the processor sets any accessed flags that are not already 1.

1. With PAE paging, the PDPTEs are stored in internal, non-architectural registers. The operation of these registers is described in Section 4.4.1 and differs from that described here.
Page 155 of the Intel 253668-032US user manual — PAGING
Page 155 · click to enlarge
Page 155

PAGING

— The processor may create a PDPTE-cache entry even if there are no transla- tions for any linear address that might use that entry.

— If the processor creates a PDPTE-cache entry, the processor may retain it unmodified even if software subsequently modifies the corresponding PML4E or PDPTE in memory. • PDE cache. The use of the PDE cache depends on the paging mode:

— For 32-bit paging, each PDE-cache entry is referenced by a 10-bit value and is used for linear addresses for which bits 31:22 have that value.

— For PAE paging, each PDE-cache entry is referenced by an 11-bit value and is used for linear addresses for which bits 31:21 have that value.

— For IA-32e paging, each PDE-cache entry is referenced by a 27-bit value and is used for linear addresses for which bits 47:21 have that value.

A PDE-cache entry contains information from the PML4E, PDPTE, and PDE used to translate the relevant linear addresses (for 32-bit paging and PAE paging, only the PDE applies):

— The physical address from the PDE (the address of the page table). (No PDE- cache entry is created for a PDE that maps a page.)

— The logical-AND of the R/W flags in the PML4E, PDPTE, and PDE.

— The logical-AND of the U/S flags in the PML4E, PDPTE, and PDE.

— The logical-OR of the XD flags in the PML4E, PDPTE, and PDE.

— The values of the PCD and PWT flags of the PDE.

The following items detail how a processor may use the PDE cache (references below to PML4Es and PDPTEs apply on to IA-32e paging):

— If the processor has a PDE-cache entry for a linear address, it may use that entry when translating the linear address (instead of the PML4E, the PDPTE, and the PDE in memory).

— The processor does not create a PDE-cache entry unless the P flag is 1, the PS flag is 0, and the reserved bits are 0 in the PML4E, the PDPTE, and the PDE in memory.

— The processor does not create a PDE-cache entry unless the accessed flag is 1 in the PML4E, the PDPTE, and the PDE in memory; before caching a trans- lation, the processor sets any accessed flags that are not already 1.

— The processor may create a PDE-cache entry even if there are no translations for any linear address that might use that entry.

— If the processor creates a PDE-cache entry, the processor may retain it unmodified even if software subsequently modifies the corresponding PML4E, the PDPTE, or the PDE in memory.

Information from a paging-structure entry can be included in entries in the paging- structure caches for other paging-structure entries referenced by the original entry.

Page 156 of the Intel 253668-032US user manual — PAGING
Page 156 · click to enlarge
Page 156

PAGING

For example, if the R/W flag is 0 in a PML4E, then the R/W flag will be 0 in any PDPTE- cache entry for a PDPTE from the page-directory-pointer table referenced by that PML4E. This is because the R/W flag of each such PDPTE-cache entry is the logical- AND of the R/W flags in the appropriate PML4E and PDPTE.

The paging-structure caches contain information only from paging-structure entries that reference other paging structures (and not those that map pages). Because the G flag is not used in such paging-structure entries, the global-page feature does not affect the behavior of the paging-structure caches.

The processor may create entries in paging-structure caches for translations required for prefetches and for accesses that are a result of speculative execution that would never actually occur in the executed code path.

A processor may or may not implement any of the paging-structure caches. Software should rely on neither their presence nor their absence. The processor may invalidate entries in these caches at any time. Because the processor may create the cache entries at the time of translation and not update them following subsequent modifi- cations to the paging structures in memory, software should take care to invalidate the cache entries appropriately when causing such modifications. The invalidation of TLBs and the paging-structure caches is described in Section 4.10.3.

4.10.2.2 Using the Paging-Structure Caches to Translate Linear Addresses

  • When a linear address is accessed, the processor uses a procedure such as the following to determine the physical address to which it translates and whether the access should be allowed:
  • If the processor finds a TLB entry for the page number of the linear address, it may use the physical address, access rights, and other attributes from that entry.
  • If the processor does not find a TLB entry, it may use the upper bits of the linear address to select an entry from the PDE cache (Section 4.10.2.1 indicates which bits are used in each paging mode). It can then use that entry to complete the translation process (locating a PTE, etc.) as if it had traversed the PDE (and, for IA-32e paging, the PDPTE and PML4) corresponding to the PDE-cache entry.
  • The following items apply when IA-32e paging is used:

— If the processor does not find a TLB entry or a PDE-cache entry, it may use bits 47:30 of the linear address to select an entry from the PDPTE cache. It can then use that entry to complete the translation process (locating a PDE, etc.) as if it had traversed the PDPTE and the PML4 corresponding to the PDPTE-cache entry.

— If the processor does not find a TLB entry, a PDE-cache entry, or a PDPTE- cache entry, it may use bits 47:39 of the linear address to select an entry from the PML4 cache. It can then use that entry to complete the translation process (locating a PDPTE, etc.) as if it had traversed the corresponding PML4.

Page 157 of the Intel 253668-032US user manual — PAGING
Page 157 · click to enlarge
Page 157

PAGING

(Any of the above steps would be skipped if the processor does not support the cache in question.)

If the processor does not find a TLB or paging-structure-cache entry for the linear address, it uses the linear address to traverse the entire paging-structure hierarchy, as described in Section 4.3, Section 4.4.2, and Section 4.5.

4.10.2.3 Multiple Cached Entries for a Single Paging-Structure Entry

Note that multiple cached entries (in the paging-structure caches or TLBs) may contain information derived from a single paging-structure entry. The following items give some examples for IA-32e paging: • Suppose that two PML4Es contain the same physical address and thus reference the same page-directory-pointer table. Any PDPTE in that table may result in two PDPTE-cache entries, each associated with a different set of linear addresses. Specifically, suppose that the n1

th entries in the PML4 table contain the same physical address. This implies that the physical address in the mth PDPTE in the page-directory-pointer table would appear in the PDPTE-cache entries associated with both p1 and p2, where (p1 » 9) = n1, (p2 » 9) = n2, and (p1 & 1FFH) = (p2 & 1FFH) = m. This is because both PDPTE-cache entries use the same PDPTE, one resulting from a reference from the n1

th and n2

th PML4E and one from the n2

th PML4E. • Suppose that the first PML4E (i.e., the one in position 0) contains the physical address X in CR3 (the physical address of the PML4 table). This implies the following:

— Any PML4-cache entry associated with linear addresses with 0 in bits 47:39 contains address X.

— Any PDPTE-cache entry associated with linear addresses with 0 in bits 47:30 contains address X. This is because the translation for a linear address for which the value of bits 47:30 is 0 uses the value of bits 47:39 (0) to locate a page-directory-pointer table at address X (the address of the PML4 table). It then uses the value of bits 38:30 (also 0) to find address X again and to store that address in the PDPTE-cache entry.

— Any PDE-cache entry associated with linear addresses with 0 in bits 47:21 contains address X for similar reasons.

— Any TLB entry for page number 0 (associated with linear addresses with 0 in bits 47:12) translates to page frame X » 12 for similar reasons.

The same PML4E contributes its address X to all these cache entries because the self-referencing nature of the entry causes it to be used as a PML4E, a PDPTE, a PDE, and a PTE.

Page 158 of the Intel 253668-032US user manual — PAGING
Page 158 · click to enlarge
Page 158

PAGING

4.10.3 Invalidation of TLBs and Paging-Structure Caches

As noted in Section 4.10.1 and Section 4.10.2, the processor may create entries in the TLBs and the paging-structure caches when linear addresses are translated, and it may retain these entries even after the paging structures used to create them have been modified. To ensure that linear-address translation uses the modified paging structures, software should take action to invalidate any cached entries that may contain information that has since been modified.

4.10.3.1 Operations that Invalidate TLBs and Paging-Structure Caches

  • It is recommended that software use the following instructions to invalidate entries in the TLBs and the paging-structure caches:
  • INVLPG. This instruction takes a single operand, which is a linear address. The instruction invalidates any TLB entries with a page number corresponding to the linear address, including those for global pages (see Section 4.10.1.4). 1 INVLPG also invalidates all entries in all paging-structure caches regardless of the linear addresses to which they correspond.
  • MOV to CR3. This instruction invalidates all TLB entries except those for global pages. It also invalidates all entries in all paging-structure caches.
  • MOV to CR4. If this instruction changes value of the PGE flag (bit 7) of CR4, it invalidates all TLB entries and all entries in all paging-structure caches. This includes global TLB entries because (1) if CR4.PGE is changing from 0 to 1, there were no global TLB entries before the execution; and (2) if CR4.PGE is changing from 1 to 0, there will be no global TLB entries after the execution.
  • Task switch. If a task switch changes the value of CR3, it invalidates all TLB entries except those for global pages. It also invalidates all entries in all pagingstructure caches.
  • VMX transitions. See Section 4.11.1.
  • The processor is always free to invalidate additional entries in the TLBs and pagingstructure caches. The following are some examples:
  • INVLPG may invalidate TLB entries for pages other than the one corresponding to its linear-address operand.
  • MOV to CR3 may invalidate TLB entries for global pages.
  • On a processor supporting Hyper-Threading Technology, invalidations performed on one logical processor may invalidate entries in the TLBs and paging-structure caches used by other logical processors.

(Other instructions and operations may invalidate entries in the TLBs and the paging- structure caches, but the instructions identified above are recommended.)

1. Even if the paging structures map the linear address using a page larger than 4 KBytes and there are multiple TLB entries for that page (see Section 4.10.1), the instruction invalidates all of them.
Page 159 of the Intel 253668-032US user manual — PAGING
Page 159 · click to enlarge
Page 159

PAGING

In addition to the instructions identified above, page faults invalidate entries in the TLBs and paging-structure caches. In particular, a page-fault exception resulting from an attempt to use a linear address will invalidate any PML4-cache, PDPTE- cache, and PDE-cache entries that would be used for that linear address as well as any TLB entry for that address's page number.1 These invalidations ensure that the page-fault exception will not recur (if the faulting instruction is re-executed) if it would not be caused by the contents of the paging structures in memory (and if, therefore, it resulted from cached entries that were not invalidated after the paging structures were modified in memory).

As noted in Section 4.10.1, some processors may choose to cache multiple smaller- page TLB entries for a translation specified by the paging structures to use a page larger than 4 KBytes. There is no way for software to be aware that multiple transla- tions for smaller pages have been used for a large page. The INVLPG instruction and page faults provide the same assurances that they provide when a single TLB entry is used: they invalidate all TLB entries corresponding to the translation specified by the paging structures.

4.10.3.2 Recommended Invalidation

  • The following items provide some recommendations regarding when software should perform invalidations:
  • If software modifies a paging-structure entry that identifies the final page frame for a page number (either a PTE or a PDE in which the PS flag is 1), it should execute INVLPG for any linear address with a page number whose translation uses that PTE. 2 (If the paging-structure entry may be used in the translation of different page numbers — see Section 4.10.2.3 — software should execute INVLPG for linear addresses with each of those page numbers; alternatively, it could use MOV to CR3 or MOV to CR4.)
  • If software modifies a paging-structure entry that references another paging structure, it may use one of the following approaches depending upon the types and number of translations controlled by the modified entry:

— Execute INVLPG for linear addresses with each of the page numbers with translations that would use the entry. However, if no page numbers that would use the entry have translations (e.g., because the P flags are 0 in all entries in the paging structure referenced by the modified entry), it remains necessary to execute INVLPG at least once.

— Execute MOV to CR3 if the modified entry controls no global pages.

— Execute MOV to CR4 to modify CR4.PGE.

1. Unlike INVLPG, page faults need not invalidate all entries in the paging-structure caches, only those that would be used to translate the faulting linear address.
2. One execution of INVLPG is sufficient even for a page with size greater than 4 KBytes.
Page 160 of the Intel 253668-032US user manual — PAGING
Page 160 · click to enlarge
Page 160

PAGING

  • If software using PAE paging modifies a PDPTE, it should reload CR3 with the register’s current value to ensure that the modified PDPTE is loaded into the corresponding PDPTE register (see Section 4.4.1).
  • If the nature of the paging structures is such that a single entry may be used for multiple purposes (see Section 4.10.2.3), software should perform invalidations for all of these purposes. For example, if a single entry might serve as both a PDE and PTE, it may be necessary to execute INVLPG with two (or more) linear addresses, one that uses the entry as a PDE and one that uses it as a PTE. (Alternatively, software could use MOV to CR3 or MOV to CR4.)
  • As noted in Section 4.10.1, the TLBs may subsequently contain multiple translations for the address range if software modifies the paging structures so that the page size used for a 4-KByte range of linear addresses changes. A reference to a linear address in the address range may use either translation.

Software wishing to prevent this uncertainty should not write to a paging- structure entry in a way that would change, for any linear address, both the page size and either the page frame, access rights, or other attributes. It can instead use the following algorithm: first clear the P flag in the relevant paging-structure entry (e.g., PDE); then invalidate any translations for the affected linear addresses (see Section 4.10.3.2); and then modify the relevant paging-structure entry to set the P flag and establish modified translation(s) for the new page size.

4.10.3.3 Optional Invalidation

  • The following items describe cases in which software may choose not to invalidate and the potential consequences of that choice:
  • If a paging-structure entry is modified to change the P flag from 0 to 1, no invalidation is necessary. This is because no TLB entry or paging-structure cache entry is created with information from a paging-structure entry in which the P flag is 0. 1
  • If a paging-structure entry is modified to change the accessed flag from 0 to 1, no invalidation is necessary (assuming that an invalidation was performed the last time the accessed flag was changed from 1 to 0). This is because no TLB entry or paging-structure cache entry is created with information from a pagingstructure entry in which the accessed flag is 0.
  • If a paging-structure entry is modified to change the R/W flag from 0 to 1, failure to perform an invalidation may result in a “spurious” page-fault exception (e.g., in response to an attempted write access) but no other adverse behavior. Such an exception will occur at most once for each affected linear address (see Section 4.10.3.1).
  • If a paging-structure entry is modified to change the U/S flag from 0 to 1, failure to perform an invalidation may result in a “spurious” page-fault exception (e.g.,
1. If it is also the case that no invalidation was performed the last time the P flag was changed from 1 to 0, the processor may use a TLB entry or paging-structure cache entry that was created when the P flag had earlier been 1.
Page 161 of the Intel 253668-032US user manual — 4.10.4 Propagation of Paging-Structure Changes to Multiple Processors
Page 161 · click to enlarge
Page 161

PAGING

  • in response to an attempted user-mode access) but no other adverse behavior. Such an exception will occur at most once for each affected linear address (see Section 4.10.3.1).
  • If a paging-structure entry is modified to change the XD flag from 1 to 0, failure to perform an invalidation may result in a “spurious” page-fault exception (e.g., in response to an attempted instruction fetch) but no other adverse behavior. Such an exception will occur at most once for each affected linear address (see Section 4.10.3.1).
  • If a paging-structure entry is modified to change the accessed flag from 1 to 0, failure to perform an invalidation may result in the processor not setting that bit in response to a subsequent access to a linear address whose translation uses the entry. Software cannot interpret the bit being clear as an indication that such an access has not occurred.
  • If software modifies a paging-structure entry that identifies the final physical address for a linear address (either a PTE or a PDE in which the PS flag is 1) to change the dirty flag from 1 to 0, failure to perform an invalidation may result in the processor not setting that bit in response to a subsequent write to a linear address whose translation uses the entry. Software cannot interpret the bit being clear as an indication that such a write has not occurred.
  • The read of a paging-structure entry in translating an address being used to fetch an instruction may appear to execute before an earlier write to that pagingstructure entry if there is no serializing instruction between the write and the instruction fetch. Note that the invalidating instructions identified in Section 4.10.3.1 are all serializing instructions.
  • Section 4.10.2.3 describes situations in which a single paging-structure entry may contain information cached in multiple entries in the paging-structure caches. Because all entries in these caches are invalidated by any execution of INVLPG, it is not necessary to follow the modification of such a paging-structure entry by executing INVLPG multiple times solely for the purpose of invalidating these multiple cached entries. (It may be necessary to do so to invalidate multiple TLB entries.)

4.10.4 Propagation of Paging-Structure Changes to Multiple Processors

As noted in Section 4.10.3, software that modifies a paging-structure entry may need to invalidate entries in the TLBs and paging-structure caches that were derived from the modified entry before it was modified. In a system containing more than one logical processor, software must account for the fact that there may be entries in the TLBs and paging-structure caches of logical processors other than the one used to modify the paging-structure entry. The process of propagating the changes to a paging-structure entry is commonly referred to as “TLB shootdown.”

TLB shootdown can be done using memory-based semaphores and/or interprocessor interrupts (IPI). The following items describe a simple but inefficient example of a

Page 162 of the Intel 253668-032US user manual — PAGING
Page 162 · click to enlarge
Page 162

PAGING

TLB shootdown algorithm for processors supporting the Intel-64 and IA-32 architec- tures:

1. Begin barrier: Stop all but one logical processor; that is, cause all but one to execute the HLT instruction or to enter a spin loop.
2. Allow the active logical processor to change the necessary paging-structure entries.
3. Allow all logical processors to perform invalidations appropriate to the modifications to the paging-structure entries.
4. Allow all logical processors to resume normal operation.
  • Alternative, performance-optimized, TLB shootdown algorithms may be developed; however, software developers must take care to ensure that the following conditions are met:
  • All logical processors that are using the paging structures that are being modified must participate and perform appropriate invalidations after the modifications are made.
  • If the modifications to the paging-structure entries are made before the barrier or if there is no barrier, the operating system must ensure one of the following: (1) that the affected linear-address range is not used between the time of modification and the time of invalidation; or (2) that it is prepared to deal with the consequences of the affected linear-address range being used during that period. For example, if the operating system does not allow pages being freed to be reallocated for another purpose until after the required invalidations, writes to those pages by errant software will not unexpectedly modify memory that is in use.
  • Software must be prepared to deal with reads, instruction fetches, and prefetch requests to the affected linear-address range that are a result of speculative execution that would never actually occur in the executed code path.

When multiple logical processors are using the same linear-address space at the same time, they must coordinate before any request to modify the paging-structure entries that control that linear-address space. In these cases, the barrier in the TLB shootdown routine may not be required. For example, when freeing a range of linear addresses, some other mechanism can assure no logical processor is using that range before the request to free it is made. In this case, a logical processor freeing the range can clear the P flags in the PTEs associated with the range, free the phys- ical page frames associated with the range, and then signal the other logical proces- sors using that linear-address space to perform the necessary invalidations. All the affected logical processors must complete their invalidations before the linear- address range and the physical page frames previously associated with that range can be reallocated.

Page 163 of the Intel 253668-032US user manual — 4.11.2 VMX Support for Address Translation
Page 163 · click to enlarge
Page 163

PAGING

4.11 INTERACTIONS WITH VIRTUAL-MACHINE EXTENSIONS (VMX)

The architecture for virtual-machine extensions (VMX) includes features that interact with paging. Section 4.11.1 discusses ways in which VMX-specific control transfers, called VMX transitions specially affect paging. Section 4.11.2 gives an overview of VMX features specifically designed to support address translation.

4.11.1 VMX Transitions

The VMX architecture defines two control transfers called VM entries and VM exits; collectively, these are called VMX transitions. VM entries and VM exits are described in detail in Chapter 23 and Chapter 24, respectively, in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3B. The following items identify paging-related details: • VMX transitions modify the CR0 and CR4 registers and the IA32_EFER MSR concurrently. For this reason, they allow transitions between paging modes that would not otherwise be possible:

— VM entries allow transitions from IA-32e paging directly to either 32-bit paging or PAE paging.

— VM exits allow transitions from either 32-bit paging or PAE paging directly to IA-32e paging. • VMX transitions that result in PAE paging load the PDPTE registers (see Section 4.4.1) as follows:

— VM entries load the PDPTE registers either from the physical address being loaded into CR3 or from the virtual-machine control structure (VMCS); see Section 23.3.2.4.

— VM exits load the PDPTE registers from the physical address being loaded into CR3; see Section 24.5.4. • VMX transitions invalidate the TLBs and paging-structure caches based on certain control settings. See Section 23.3.2.5 and Section 24.5.5.

4.11.2 VMX Support for Address Translation

Chapter 25, “VMX Support for Address Translation,” in the Intel® 64 and IA-32 Archi- tectures Software Developer’s Manual, Volume 3B describe two features of the virtual-machine extensions (VMX) that interact directly with paging. These are virtual-processor identifiers (VPIDs) and the extended page table mechanism (EPT).

VPIDs provide a way for software to identify to the processor the address spaces for different “virtual processors.” The processor may use this identification to maintain

Page 164 of the Intel 253668-032US user manual — 4.13 MAPPING SEGMENTS TO PAGES
Page 164 · click to enlarge
Page 164

PAGING

concurrently information for multiple address spaces in its TLBs and paging-structure caches. See Section 25.1 for details.

When EPT is in use, the addresses in the paging-structures are not used as physical addresses to access memory and memory-mapped I/O. Instead, they are treated as guest-physical addresses and are translated through a set of EPT paging structures to produce physical addresses. EPT can also specify its own access rights and memory typing; these are used on conjunction with those specified in this chapter. See Section 25.2 for more information.

Both VPIDs and EPT may change the way that a processor maintains information in TLBs and paging structure caches and the ways in which software can manage that information. Some of the behaviors documented in Section 4.10 may change. See Section 25.3 for details.

4.12 USING PAGING FOR VIRTUAL MEMORY

With paging, portions of the linear-address space need not be mapped to the phys- ical-address space; data for the unmapped addresses can be stored externally (e.g., on disk). This method of mapping the linear-address space is referred to as virtual memory or demand-paged virtual memory.

Paging divides the linear address space into fixed-size pages that can be mapped into the physical-address space and/or external storage. When a program (or task) refer- ences a linear address, the processor uses paging to translate the linear address into a corresponding physical address if such an address is defined.

If the page containing the linear address is not currently mapped into the physical- address space, the processor generates a page-fault exception as described in Section 4.7. The handler for page-fault exceptions typically directs the operating system or executive to load data for the unmapped page from external storage into physical memory (perhaps writing a different page from physical memory out to external storage in the process) and to map it using paging (by updating the paging structures). When the page has been loaded into physical memory, a return from the exception handler causes the instruction that generated the exception to be restarted.

Paging differs from segmentation through its use of fixed-size pages. Unlike segments, which usually are the same size as the code or data structures they hold, pages have a fixed size. If segmentation is the only form of address translation used, a data structure present in physical memory will have all of its parts in memory. If paging is used, a data structure can be partly in memory and partly in disk storage.

4.13 MAPPING SEGMENTS TO PAGES

The segmentation and paging mechanisms provide in the support a wide variety of approaches to memory management. When segmentation and paging are combined,

Page 165 of the Intel 253668-032US user manual — PAGING
Page 165 · click to enlarge
Page 165

PAGING

segments can be mapped to pages in several ways. To implement a flat (unseg- mented) addressing environment, for example, all the code, data, and stack modules can be mapped to one or more large segments (up to 4-GBytes) that share same range of linear addresses (see Figure 3-2 in Section 3.2.2). Here, segments are essentially invisible to applications and the operating-system or executive. If paging is used, the paging mechanism can map a single linear-address space (contained in a single segment) into virtual memory. Alternatively, each program (or task) can have its own large linear-address space (contained in its own segment), which is mapped into virtual memory through its own paging structures.

Segments can be smaller than the size of a page. If one of these segments is placed in a page which is not shared with another segment, the extra memory is wasted. For example, a small data structure, such as a 1-Byte semaphore, occupies 4 KBytes if it is placed in a page by itself. If many semaphores are used, it is more efficient to pack them into a single page.

The Intel-64 and IA-32 architectures do not enforce correspondence between the boundaries of pages and segments. A page can contain the end of one segment and the beginning of another. Similarly, a segment can contain the end of one page and the beginning of another.

Memory-management software may be simpler and more efficient if it enforces some alignment between page and segment boundaries. For example, if a segment which can fit in one page is placed in two pages, there may be twice as much paging over- head to support access to that segment.

One approach to combining paging and segmentation that simplifies memory- management software is to give each segment its own page table, as shown in Figure 4-12. This convention gives the segment a single entry in the page directory, and this entry provides the access control information for paging the entire segment.

Intel 253668-032US — PAGING diagram (page 165)
Fig. 15

Figure 4-12. Memory Management Convention That Assigns a Page Table

to Each Segment

Page 166 of the Intel 253668-032US user manual — PAGING
Page 166 · click to enlarge
Page 166

PAGING

Page 167 of the Intel 253668-032US user manual — 5.1 ENABLING AND DISABLING SEGMENT AND PAGE PROTECTION
Page 167 · click to enlarge
Page 167

CHAPTER 5 PROTECTION

In protected mode, the Intel 64 and IA-32 architectures provide a protection mecha nism that operates at both the segment level and the page level. This protection mechanism provides the ability to limit access to certain segments or pages based on privilege levels (four privilege levels for segments and two privilege levels for pages). For example, critical operating-system code and data can be protected by placing them in more privileged segments than those that contain applications code. The processor’s protection mechanism will then prevent application code from accessing the operating-system code and data in any but a controlled, defined manner.

Segment and page protection can be used at all stages of software development to assist in localizing and detecting design problems and bugs. It can also be incorpo rated into end-products to offer added robustness to operating systems, utilities soft ware, and applications software.

  • When the protection mechanism is used, each memory reference is checked to verify that it satisfies various protection checks. All checks are made before the memory cycle is started; any violation results in an exception. Because checks are performed in parallel with address translation, there is no performance penalty. The protection checks that are performed fall into the following categories:
  • Limit checks.
  • Type checks.
  • Privilege level checks.
  • Restriction of addressable domain.
  • Restriction of procedure entry-points.
  • Restriction of instruction set.

All protection violation results in an exception being generated. See Chapter 6, “Interrupt and Exception Handling,” for an explanation of the exception mechanism. This chapter describes the protection mechanism and the violations which lead to exceptions.

The following sections describe the protection mechanism available in protected mode. See Chapter 17, “8086 Emulation,” for information on protection in real- address and virtual-8086 mode.

5.1 ENABLING AND DISABLING SEGMENT AND PAGE PROTECTION

Setting the PE flag in register CR0 causes the processor to switch to protected mode, which in turn enables the segment-protection mechanism. Once in protected mode,

Page 168 of the Intel 253668-032US user manual — 5.2 FIELDS AND FLAGS USED FOR SEGMENT-LEVEL AND PAGE-LEVEL PROTECTION
Page 168 · click to enlarge
Page 168

PROTECTION

there is no control bit for turning the protection mechanism on or off. The part of the segment-protection mechanism that is based on privilege levels can essentially be disabled while still in protected mode by assigning a privilege level of 0 (most privi leged) to all segment selectors and segment descriptors. This action disables the privilege level protection barriers between segments, but other protection checks such as limit checking and type checking are still carried out.

  • Page-level protection is automatically enabled when paging is enabled (by setting the PG flag in register CR0). Here again there is no mode bit for turning off page-level protection once paging is enabled. However, page-level protection can be disabled by performing the following operations:
  • Clear the WP flag in control register CR0.
  • Set the read/write (R/W) and user/supervisor (U/S) flags for each page-directory and page-table entry.

This action makes each page a writable, user page, which in effect disables page- level protection.

5.2 FIELDS AND FLAGS USED FOR SEGMENT-LEVEL AND PAGE-LEVEL PROTECTION

  • The processor’s protection mechanism uses the following fields and flags in the system data structures to control access to segments and pages:
  • Descriptor type (S) flag — (Bit 12 in the second doubleword of a segment descriptor.) Determines if the segment descriptor is for a system segment or a code or data segment.
  • Type field — (Bits 8 through 11 in the second doubleword of a segment descriptor.) Determines the type of code, data, or system segment.
  • Limit field — (Bits 0 through 15 of the first doubleword and bits 16 through 19 of the second doubleword of a segment descriptor.) Determines the size of the segment, along with the G flag and E flag (for data segments).
  • G flag — (Bit 23 in the second doubleword of a segment descriptor.) Determines the size of the segment, along with the limit field and E flag (for data segments).
  • E flag — (Bit 10 in the second doubleword of a data-segment descriptor.) Determines the size of the segment, along with the limit field and G flag.
  • Descriptor privilege level (DPL) field — (Bits 13 and 14 in the second doubleword of a segment descriptor.) Determines the privilege level of the segment.
  • Requested privilege level (RPL) field — (Bits 0 and 1 of any segment selector.) Specifies the requested privilege level of a segment selector.
  • Current privilege level (CPL) field — (Bits 0 and 1 of the CS segment register.) Indicates the privilege level of the currently executing program or
Page 169 of the Intel 253668-032US user manual — PROTECTION
Page 169 · click to enlarge
Page 169

PROTECTION

  • procedure. The term current privilege level (CPL) refers to the setting of this field.
  • User/supervisor (U/S) flag — (Bit 2 of paging-structure entries.) Determines the type of page: user or supervisor.
  • Read/write (R/W) flag — (Bit 1 of paging-structure entries.) Determines the type of access allowed to a page: read-only or read/write.
  • Execute-disable (XD) flag — (Bit 63 of certain paging-structure entries.) Determines the type of access allowed to a page: executable or not-executable.

Figure 5-1 shows the location of the various fields and flags in the data, code, and system- segment descriptors; Figure 3-6 shows the location of the RPL (or CPL) field in a segment selector (or the CS register); and Chapter 4 identifies the locations of the U/S, R/W, and XD flags in the paging-structure entries.

Page 170 of the Intel 253668-032US user manual — B C D DPL
Page 170 · click to enlarge
Page 170

PROTECTION

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

Limit 19:16 B

Base 23:16 A V L

D P L

P Base 31:24 G

A W E 0

31 16 15 0

Base Address 15:00 Segment Limit 15:00 0

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

Limit 19:16 D

Base 23:16 A V L

D P L

P Base 31:24 G

A R C 1

31 16 15 0

Base Address 15:00 Segment Limit 15:00 0

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

D P L

P Base 31:24 G

Limit 19:16

Base 23:16

31 16 15 0

Base Address 15:00 Segment Limit 15:00 0

A

E G R LIMIT W P

Expansion Direction Granularity Readable Segment Limit Writable Present

AVL Available to Sys. Programmer’s

B C D DPL

Big Conforming Default Descriptor Privilege Level

Figure 5-1. Descriptor Fields Used for Protection

Many different styles of protection schemes can be implemented with these fields and flags. When the operating system creates a descriptor, it places values in these fields and flags in keeping with the particular protection style chosen for an operating system or executive. Application program do not generally access or modify these fields and flags.

Show 8 more labels / short text on this page
Data-Segment Descriptor · Type · Code-Segment Descriptor · Type · System-Segment Descriptor · Type 0 4 · Accessed · Reserved
Page 171 of the Intel 253668-032US user manual — 5.2.1 Code Segment Descriptor in 64-bit Mode
Page 171 · click to enlarge
Page 171

PROTECTION

The following sections describe how the processor uses these fields and flags to perform the various categories of checks described in the introduction to this chapter.

5.2.1 Code Segment Descriptor in 64-bit Mode

Code segments continue to exist in 64-bit mode even though, for address calcula tions, the segment base is treated as zero. Some code-segment (CS) descriptor content (the base address and limit fields) is ignored; the remaining fields function normally (except for the readable bit in the type field).

Code segment descriptors and selectors are needed in IA-32e mode to establish the processor’s operating mode and execution privilege-level. The usage is as follows: • IA-32e mode uses a previously unused bit in the CS descriptor. Bit 53 is defined as the 64-bit (L) flag and is used to select between 64-bit mode and compatibility mode when IA-32e mode is active (IA32_EFER.LMA = 1). See Figure 5-2.

— If CS.L = 0 and IA-32e mode is active, the processor is running in compati bility mode. In this case, CS.D selects the default size for data and addresses. If CS.D = 0, the default data and address size is 16 bits. If CS.D = 1, the default data and address size is 32 bits.

— If CS.L = 1 and IA-32e mode is active, the only valid setting is CS.D = 0. This setting indicates a default operand size of 32 bits and a default address size of 64 bits. The CS.L = 1 and CS.D = 1 bit combination is reserved for future use and a #GP fault will be generated on an attempt to use a code segment with these bits set in IA-32e mode. • In IA-32e mode, the CS descriptor’s DPL is used for execution privilege checks (as in legacy 32-bit mode).

Page 172 of the Intel 253668-032US user manual — 5.3 LIMIT CHECKING
Page 172 · click to enlarge
Page 172

PROTECTION

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

A V L D

D P L

P G

A R C 1

A

Granularity Readable AVL Available to Sys. Programmer’s

G R

C D DPL

Conforming Default Descriptor Privilege Level

Figure 5-2. Descriptor Fields with Flags used in IA-32e Mode

5.3 LIMIT CHECKING

The limit field of a segment descriptor prevents programs or procedures from addressing memory locations outside the segment. The effective value of the limit depends on the setting of the G (granularity) flag (see Figure 5-1). For data segments, the limit also depends on the E (expansion direction) flag and the B (default stack pointer size and/or upper bound) flag. The E flag is one of the bits in the type field when the segment descriptor is for a data-segment type.

When the G flag is clear (byte granularity), the effective limit is the value of the 20-bit limit field in the segment descriptor. Here, the limit ranges from 0 to FFFFFH (1 MByte). When the G flag is set (4-KByte page granularity), the processor scales the value in the limit field by a factor of 212 (4 KBytes). In this case, the effective limit ranges from FFFH (4 KBytes) to FFFFFFFFH (4 GBytes). Note that when scaling is used (G flag is set), the lower 12 bits of a segment offset (address) are not checked against the limit; for example, note that if the segment limit is 0, offsets 0 through FFFH are still valid.

  • For all types of segments except expand-down data segments, the effective limit is the last address that is allowed to be accessed in the segment, which is one less than the size, in bytes, of the segment. The processor causes a general-protection excep tion any time an attempt is made to access the following addresses in a segment:
  • A byte at an offset greater than the effective limit
  • A word at an offset greater than the (effective-limit – 1)
Show 5 more labels / short text on this page
Code-Segment Descriptor · Type · Accessed · P Present · L 64-Bit Flag
Page 173 of the Intel 253668-032US user manual — 5.4 TYPE CHECKING
Page 173 · click to enlarge
Page 173

PROTECTION

  • A doubleword at an offset greater than the (effective-limit – 3)
  • A quadword at an offset greater than the (effective-limit – 7)

For expand-down data segments, the segment limit has the same function but is interpreted differently. Here, the effective limit specifies the last address that is not allowed to be accessed within the segment; the range of valid offsets is from (effec tive-limit + 1) to FFFFFFFFH if the B flag is set and from (effective-limit + 1) to FFFFH if the B flag is clear. An expand-down segment has maximum size when the segment limit is 0.

Limit checking catches programming errors such as runaway code, runaway subscripts, and invalid pointer calculations. These errors are detected when they occur, so identification of the cause is easier. Without limit checking, these errors could overwrite code or data in another segment.

In addition to checking segment limits, the processor also checks descriptor table limits. The GDTR and IDTR registers contain 16-bit limit values that the processor uses to prevent programs from selecting a segment descriptors outside the respec tive descriptor tables. The LDTR and task registers contain 32-bit segment limit value (read from the segment descriptors for the current LDT and TSS, respectively). The processor uses these segment limits to prevent accesses beyond the bounds of the current LDT and TSS. See Section 3.5.1, “Segment Descriptor Tables,” for more infor mation on the GDT and LDT limit fields; see Section 6.10, “Interrupt Descriptor Table (IDT),” for more information on the IDT limit field; and see Section 7.2.4, “Task Register,” for more information on the TSS segment limit field.

5.3.1 Limit Checking in 64-bit Mode

In 64-bit mode, the processor does not perform runtime limit checking on code or data segments. However, the processor does check descriptor-table limits.

5.4 TYPE CHECKING

  • Segment descriptors contain type information in two places:
  • The S (descriptor type) flag.
  • The type field.

The processor uses this information to detect programming errors that result in an attempt to use a segment or gate in an incorrect or unintended manner.

The S flag indicates whether a descriptor is a system type or a code or data type. The type field provides 4 additional bits for use in defining various types of code, data, and system descriptors. Table 3-1 shows the encoding of the type field for code and data descriptors; Table 3-2 shows the encoding of the field for system descriptors.

Page 174 of the Intel 253668-032US user manual — PROTECTION
Page 174 · click to enlarge
Page 174

PROTECTION

The processor examines type information at various times while operating on segment selectors and segment descriptors. The following list gives examples of typical operations where type checking is performed (this list is not exhaustive): • When a segment selector is loaded into a segment register — Certain segment registers can contain only certain descriptor types, for example:

— The CS register only can be loaded with a selector for a code segment.

— Segment selectors for code segments that are not readable or for system segments cannot be loaded into data-segment registers (DS, ES, FS, and GS).

— Only segment selectors of writable data segments can be loaded into the SS register. • When a segment selector is loaded into the LDTR or task register — For example:

— The LDTR can only be loaded with a selector for an LDT.

— The task register can only be loaded with a segment selector for a TSS. • When instructions access segments whose descriptors are already loaded into segment registers — Certain segments can be used by instruc tions only in certain predefined ways, for example:

— No instruction may write into an executable segment.

— No instruction may write into a data segment if it is not writable.

— No instruction may read an executable segment unless the readable flag is set. • When an instruction operand contains a segment selector — Certain instructions can access segments or gates of only a particular type, for example:

— A far CALL or far JMP instruction can only access a segment descriptor for a conforming code segment, nonconforming code segment, call gate, task gate, or TSS.

— The LLDT instruction must reference a segment descriptor for an LDT.

— The LTR instruction must reference a segment descriptor for a TSS.

— The LAR instruction must reference a segment or gate descriptor for an LDT, TSS, call gate, task gate, code segment, or data segment.

— The LSL instruction must reference a segment descriptor for a LDT, TSS, code segment, or data segment.

— IDT entries must be interrupt, trap, or task gates. • During certain internal operations — For example:

— On a far call or far jump (executed with a far CALL or far JMP instruction), the processor determines the type of control transfer to be carried out (call or jump to another code segment, a call or jump through a gate, or a task switch) by checking the type field in the segment (or gate) descriptor pointed to by the segment (or gate) selector given as an operand in the CALL or JMP

Page 175 of the Intel 253668-032US user manual — 5.5 PRIVILEGE LEVELS
Page 175 · click to enlarge
Page 175

PROTECTION

instruction. If the descriptor type is for a code segment or call gate, a call or jump to another code segment is indicated; if the descriptor type is for a TSS or task gate, a task switch is indicated.

— On a call or jump through a call gate (or on an interrupt- or exception-handler call through a trap or interrupt gate), the processor automatically checks that the segment descriptor being pointed to by the gate is for a code segment.

— On a call or jump to a new task through a task gate (or on an interrupt- or exception-handler call to a new task through a task gate), the processor automatically checks that the segment descriptor being pointed to by the task gate is for a TSS.

— On a call or jump to a new task by a direct reference to a TSS, the processor automatically checks that the segment descriptor being pointed to by the CALL or JMP instruction is for a TSS.

— On return from a nested task (initiated by an IRET instruction), the processor checks that the previous task link field in the current TSS points to a TSS.

5.4.1 Null Segment Selector Checking

Attempting to load a null segment selector (see Section 3.4.2, “Segment Selectors”) into the CS or SS segment register generates a general-protection exception (#GP). A null segment selector can be loaded into the DS, ES, FS, or GS register, but any attempt to access a segment through one of these registers when it is loaded with a null segment selector results in a #GP exception being generated. Loading unused data-segment registers with a null segment selector is a useful method of detecting accesses to unused segment registers and/or preventing unwanted accesses to data segments.

5.4.1.1 NULL Segment Checking in 64-bit Mode

In 64-bit mode, the processor does not perform runtime checking on NULL segment selectors. The processor does not cause a #GP fault when an attempt is made to access memory where the referenced segment register has a NULL segment selector.

5.5 PRIVILEGE LEVELS

The processor’s segment-protection mechanism recognizes 4 privilege levels, numbered from 0 to 3. The greater numbers mean lesser privileges. Figure 5-3 shows how these levels of privilege can be interpreted as rings of protection.

The center (reserved for the most privileged code, data, and stacks) is used for the segments containing the critical software, usually the kernel of an operating system. Outer rings are used for less critical software. (Systems that use only 2 of the 4 possible privilege levels should use levels 0 and 3.)

Page 176 of the Intel 253668-032US user manual — PROTECTION
Page 176 · click to enlarge
Page 176

PROTECTION

Figure 5-3. Protection Rings

The processor uses privilege levels to prevent a program or task operating at a lesser privilege level from accessing a segment with a greater privilege, except under controlled situations. When the processor detects a privilege level violation, it gener ates a general-protection exception (#GP).

  • To carry out privilege-level checks between code segments and data segments, the processor recognizes the following three types of privilege levels:
  • Current privilege level (CPL) — The CPL is the privilege level of the currently executing program or task. It is stored in bits 0 and 1 of the CS and SS segment registers. Normally, the CPL is equal to the privilege level of the code segment from which instructions are being fetched. The processor changes the CPL when program control is transferred to a code segment with a different privilege level. The CPL is treated slightly differently when accessing conforming code segments. Conforming code segments can be accessed from any privilege level that is equal to or numerically greater (less privileged) than the DPL of the conforming code segment. Also, the CPL is not changed when the processor accesses a conforming code segment that has a different privilege level than the CPL.
  • Descriptor privilege level (DPL) — The DPL is the privilege level of a segment or gate. It is stored in the DPL field of the segment or gate descriptor for the segment or gate. When the currently executing code segment attempts to access a segment or gate, the DPL of the segment or gate is compared to the CPL and RPL of the segment or gate selector (as described later in this section). The DPL is interpreted differently, depending on the type of segment or gate being accessed:

— Data segment — The DPL indicates the numerically highest privilege level that a program or task can have to be allowed to access the segment. For

Show 11 more labels / short text on this page
Protection Rings · Operating · System · Kernel · Level 0 · Operating System · Services · Level 1 · Level 2 · Applications · Level 3
Page 177 of the Intel 253668-032US user manual — 5.6 PRIVILEGE LEVEL CHECKING WHEN ACCESSING DATA SEGMENTS
Page 177 · click to enlarge
Page 177

PROTECTION

example, if the DPL of a data segment is 1, only programs running at a CPL of 0 or 1 can access the segment.

— Nonconforming code segment (without using a call gate) — The DPL indicates the privilege level that a program or task must be at to access the segment. For example, if the DPL of a nonconforming code segment is 0, only programs running at a CPL of 0 can access the segment.

— Call gate — The DPL indicates the numerically highest privilege level that the currently executing program or task can be at and still be able to access the call gate. (This is the same access rule as for a data segment.)

— Conforming code segment and nonconforming code segment accessed through a call gate — The DPL indicates the numerically lowest privilege level that a program or task can have to be allowed to access the segment. For example, if the DPL of a conforming code segment is 2, programs running at a CPL of 0 or 1 cannot access the segment.

— TSS — The DPL indicates the numerically highest privilege level that the currently executing program or task can be at and still be able to access the TSS. (This is the same access rule as for a data segment.) • Requested privilege level (RPL) — The RPL is an override privilege level that is assigned to segment selectors. It is stored in bits 0 and 1 of the segment selector. The processor checks the RPL along with the CPL to determine if access to a segment is allowed. Even if the program or task requesting access to a segment has sufficient privilege to access the segment, access is denied if the RPL is not of sufficient privilege level. That is, if the RPL of a segment selector is numerically greater than the CPL, the RPL overrides the CPL, and vice versa. The RPL can be used to insure that privileged code does not access a segment on behalf of an application program unless the program itself has access privileges for that segment. See Section 5.10.4, “Checking Caller Access Privileges (ARPL Instruction),” for a detailed description of the purpose and typical use of the RPL.

Privilege levels are checked when the segment selector of a segment descriptor is loaded into a segment register. The checks used for data access differ from those used for transfers of program control among code segments; therefore, the two kinds of accesses are considered separately in the following sections.

5.6 PRIVILEGE LEVEL CHECKING WHEN ACCESSING DATA SEGMENTS

To access operands in a data segment, the segment selector for the data segment must be loaded into the data-segment registers (DS, ES, FS, or GS) or into the stack- segment register (SS). (Segment registers can be loaded with the MOV, POP, LDS, LES, LFS, LGS, and LSS instructions.) Before the processor loads a segment selector into a segment register, it performs a privilege check (see Figure 5-4) by comparing the privilege levels of the currently running program or task (the CPL), the RPL of the segment selector, and the DPL of the segment’s segment descriptor. The processor

Page 178 of the Intel 253668-032US user manual — RPL
Page 178 · click to enlarge
Page 178

PROTECTION

loads the segment selector into the segment register if the DPL is numerically greater than or equal to both the CPL and the RPL. Otherwise, a general-protection fault is generated and the segment register is not loaded.

CPL

Segment Selector For Data Segment

RPL

DPL

Figure 5-4. Privilege Check for Data Access

Figure 5-5 shows four procedures (located in codes segments A, B, C, and D), each running at different privilege levels and each attempting to access the same data segment.

1. The procedure in code segment A is able to access data segment E using segment selector E1, because the CPL of code segment A and the RPL of segment selector E1 are equal to the DPL of data segment E.
2. The procedure in code segment B is able to access data segment E using segment selector E2, because the CPL of code segment B and the RPL of segment selector E2 are both numerically lower than (more privileged) than the DPL of data segment E. A code segment B procedure can also access data segment E using segment selector E1.

3. The procedure in code segment C is not able to access data segment E using segment selector E3 (dotted line), because the CPL of code segment C and the RPL of segment selector E3 are both numerically greater than (less privileged) than the DPL of data segment E. Even if a code segment C procedure were to use segment selector E1 or E2, such that the RPL would be acceptable, it still could not access data segment E because its CPL is not privileged enough.

4. The procedure in code segment D should be able to access data segment E because code segment D’s CPL is numerically less than the DPL of data segment E. However, the RPL of segment selector E3 (which the code segment D procedure is using to access data segment E) is numerically greater than the DPL of data segment E, so access is not allowed. If the code segment D procedure were to use segment selector E1 or E2 to access the data segment, access would be allowed.

CS Register · Check Data-Segment Descriptor · Privilege

Page 179 of the Intel 253668-032US user manual — 5.6.1 Accessing Data in Code Segments
Page 179 · click to enlarge
Page 179

PROTECTION

Intel 253668-032US — PROTECTION diagram (page 179)
Fig. 16

Figure 5-5. Examples of Accessing Data Segments From Various Privilege Levels

As demonstrated in the previous examples, the addressable domain of a program or task varies as its CPL changes. When the CPL is 0, data segments at all privilege levels are accessible; when the CPL is 1, only data segments at privilege levels 1 through 3 are accessible; when the CPL is 3, only data segments at privilege level 3 are accessible.

The RPL of a segment selector can always override the addressable domain of a program or task. When properly used, RPLs can prevent problems caused by acci dental (or intensional) use of segment selectors for privileged data segments by less privileged programs or procedures.

It is important to note that the RPL of a segment selector for a data segment is under software control. For example, an application program running at a CPL of 3 can set the RPL for a data- segment selector to 0. With the RPL set to 0, only the CPL checks, not the RPL checks, will provide protection against deliberate, direct attempts to violate privilege-level security for the data segment. To prevent these types of privi lege-level-check violations, a program or procedure can check access privileges whenever it receives a data-segment selector from another procedure (see Section 5.10.4, “Checking Caller Access Privileges (ARPL Instruction)”).

5.6.1 Accessing Data in Code Segments

In some instances it may be desirable to access data structures that are contained in a code segment. The following methods of accessing data in code segments are possible:

Page 180 of the Intel 253668-032US user manual — 5.8 PRIVILEGE LEVEL CHECKING WHEN TRANSFERRING PROGRAM CONTROL BETWEEN CODE SEGMENTS
Page 180 · click to enlarge
Page 180

PROTECTION

  • Load a data-segment register with a segment selector for a nonconforming, readable, code segment.
  • Load a data-segment register with a segment selector for a conforming, readable, code segment.
  • Use a code-segment override prefix (CS) to read a readable, code segment whose selector is already loaded in the CS register.

The same rules for accessing data segments apply to method 1. Method 2 is always valid because the privilege level of a conforming code segment is effectively the same as the CPL, regardless of its DPL. Method 3 is always valid because the DPL of the code segment selected by the CS register is the same as the CPL.

5.7 PRIVILEGE LEVEL CHECKING WHEN LOADING THE SS REGISTER

Privilege level checking also occurs when the SS register is loaded with the segment selector for a stack segment. Here all privilege levels related to the stack segment must match the CPL; that is, the CPL, the RPL of the stack-segment selector, and the DPL of the stack-segment descriptor must be the same. If the RPL and DPL are not equal to the CPL, a general-protection exception (#GP) is generated.

5.8 PRIVILEGE LEVEL CHECKING WHEN TRANSFERRING PROGRAM CONTROL BETWEEN CODE SEGMENTS

To transfer program control from one code segment to another, the segment selector for the destination code segment must be loaded into the code-segment register (CS). As part of this loading process, the processor examines the segment descriptor for the destination code segment and performs various limit, type, and privilege checks. If these checks are successful, the CS register is loaded, program control is transferred to the new code segment, and program execution begins at the instruc tion pointed to by the EIP register.

Program control transfers are carried out with the JMP, CALL, RET, SYSENTER, SYSEXIT, INT n, and IRET instructions, as well as by the exception and interrupt mechanisms. Exceptions, interrupts, and the IRET instruction are special cases discussed in Chapter 6, “Interrupt and Exception Handling.” This chapter discusses only the JMP, CALL, RET, SYSENTER, and SYSEXIT instructions.

  • A JMP or CALL instruction can reference another code segment in any of four ways:
  • The target operand contains the segment selector for the target code segment.
  • The target operand points to a call-gate descriptor, which contains the segment selector for the target code segment.
Page 181 of the Intel 253668-032US user manual — DPL
Page 181 · click to enlarge
Page 181

PROTECTION

  • The target operand points to a TSS, which contains the segment selector for the target code segment.
  • The target operand points to a task gate, which points to a TSS, which in turn contains the segment selector for the target code segment.

The following sections describe first two types of references. See Section 7.3, “Task Switching,” for information on transferring program control through a task gate and/or TSS.

The SYSENTER and SYSEXIT instructions are special instructions for making fast calls to and returns from operating system or executive procedures. These instructions are discussed briefly in Section 5.8.7, “Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructions.”

5.8.1 Direct Calls or Jumps to Code Segments

The near forms of the JMP, CALL, and RET instructions transfer program control within the current code segment, so privilege-level checks are not performed. The far forms of the JMP, CALL, and RET instructions transfer control to other code segments, so the processor does perform privilege-level checks.

When transferring program control to another code segment without going through a call gate, the processor examines four kinds of privilege level and type information (see Figure 5-6): • The CPL. (Here, the CPL is the privilege level of the calling code segment; that is, the code segment that contains the procedure that is making the call or jump.)

CPL

Segment Selector For Code Segment

RPL

Destination Code Segment Descriptor

DPL

Figure 5-6. Privilege Check for Control Transfer Without Using a Gate

  • The DPL of the segment descriptor for the destination code segment that contains the called procedure.

CS Register · Privilege · Check

Page 182 of the Intel 253668-032US user manual — PROTECTION
Page 182 · click to enlarge
Page 182

PROTECTION

  • The RPL of the segment selector of the destination code segment.
  • The conforming (C) flag in the segment descriptor for the destination code segment, which determines whether the segment is a conforming (C flag is set) or nonconforming (C flag is clear) code segment. See Section 3.4.5.1, “Codeand Data-Segment Descriptor Types,” for more information about this flag.

The rules that the processor uses to check the CPL, RPL, and DPL depends on the setting of the C flag, as described in the following sections.

5.8.1.1 Accessing Nonconforming Code Segments

  • When accessing nonconforming code segments, the CPL of the calling procedure must be equal to the DPL of the destination code segment; otherwise, the processor generates a general-protection exception (#GP). For example in Figure 5-7:
  • Code segment C is a nonconforming code segment. A procedure in code segment A can call a procedure in code segment C (using segment selector C1) because they are at the same privilege level (CPL of code segment A is equal to the DPL of code segment C).
  • A procedure in code segment B cannot call a procedure in code segment C (using segment selector C2 or C1) because the two code segments are at different privilege levels.
Page 183 of the Intel 253668-032US user manual — PROTECTION
Page 183 · click to enlarge
Page 183

PROTECTION

Intel 253668-032US — PROTECTION diagram (page 183)
Fig. 17

Figure 5-7. Examples of Accessing Conforming and Nonconforming Code Segments

From Various Privilege Levels

The RPL of the segment selector that points to a nonconforming code segment has a limited effect on the privilege check. The RPL must be numerically less than or equal to the CPL of the calling procedure for a successful control transfer to occur. So, in the example in Figure 5-7, the RPLs of segment selectors C1 and C2 could legally be set to 0, 1, or 2, but not to 3.

When the segment selector of a nonconforming code segment is loaded into the CS register, the privilege level field is not changed; that is, it remains at the CPL (which is the privilege level of the calling procedure). This is true, even if the RPL of the segment selector is different from the CPL.

5.8.1.2 Accessing Conforming Code Segments

When accessing conforming code segments, the CPL of the calling procedure may be numerically equal to or greater than (less privileged) the DPL of the destination code segment; the processor generates a general-protection exception (#GP) only if the CPL is less than the DPL. (The segment selector RPL for the destination code segment is not checked if the segment is a conforming code segment.)

Page 184 of the Intel 253668-032US user manual — 5.8.2 Gate Descriptors
Page 184 · click to enlarge
Page 184

PROTECTION

In the example in Figure 5-7, code segment D is a conforming code segment. There fore, calling procedures in both code segment A and B can access code segment D (using either segment selector D1 or D2, respectively), because they both have CPLs that are greater than or equal to the DPL of the conforming code segment. For conforming code segments, the DPL represents the numerically lowest priv ilege level that a calling procedure may be at to successfully make a call to the code segment.

(Note that segments selectors D1 and D2 are identical except for their respective RPLs. But since RPLs are not checked when accessing conforming code segments, the two segment selectors are essentially interchangeable.)

When program control is transferred to a conforming code segment, the CPL does not change, even if the DPL of the destination code segment is less than the CPL. This situation is the only one where the CPL may be different from the DPL of the current code segment. Also, since the CPL does not change, no stack switch occurs.

Conforming segments are used for code modules such as math libraries and excep tion handlers, which support applications but do not require access to protected system facilities. These modules are part of the operating system or executive soft ware, but they can be executed at numerically higher privilege levels (less privileged levels). Keeping the CPL at the level of a calling code segment when switching to a conforming code segment prevents an application program from accessing noncon forming code segments while at the privilege level (DPL) of a conforming code segment and thus prevents it from accessing more privileged data.

Most code segments are nonconforming. For these segments, program control can be transferred only to code segments at the same level of privilege, unless the transfer is carried out through a call gate, as described in the following sections.

5.8.2 Gate Descriptors

  • To provide controlled access to code segments with different privilege levels, the processor provides special set of descriptors called gate descriptors. There are four kinds of gate descriptors:
  • Call gates
  • Trap gates
  • Interrupt gates
  • Task gates

Task gates are used for task switching and are discussed in Chapter 7, “Task Manage ment”. Trap and interrupt gates are special kinds of call gates used for calling excep tion and interrupt handlers. The are described in Chapter 6, “Interrupt and Exception Handling.” This chapter is concerned only with call gates.

Page 185 of the Intel 253668-032US user manual — P DPL
Page 185 · click to enlarge
Page 185

PROTECTION

5.8.3 Call Gates

Call gates facilitate controlled transfers of program control between different privi lege levels. They are typically used only in operating systems or executives that use the privilege-level protection mechanism. Call gates are also useful for transferring program control between 16-bit and 32-bit code segments, as described in Section 18.4, “Transferring Control Among Mixed-Size Code Segments.”

  • Figure 5-8 shows the format of a call-gate descriptor. A call-gate descriptor may reside in the GDT or in an LDT, but not in the interrupt descriptor table (IDT). It performs six functions:
  • It specifies the code segment to be accessed.
  • It defines an entry point for a procedure in the specified code segment.
  • It specifies the privilege level required for a caller trying to access the procedure.

31 16 15 13 14 12 11 8 7 0

D P L

Param.

P Offset in Segment 31:16

0 0 1 1

31 16 15 0

Segment Selector Offset in Segment 15:00 0

P DPL

Gate Valid Descriptor Privilege Level

Figure 5-8. Call-Gate Descriptor

  • If a stack switch occurs, it specifies the number of optional parameters to be copied between stacks.
  • It defines the size of values to be pushed onto the target stack: 16-bit gates force 16-bit pushes and 32-bit gates force 32-bit pushes.
  • It specifies whether the call-gate descriptor is valid.

The segment selector field in a call gate specifies the code segment to be accessed. The offset field specifies the entry point in the code segment. This entry point is generally to the first instruction of a specific procedure. The DPL field indicates the privilege level of the call gate, which in turn is the privilege level required to access the selected procedure through the gate. The P flag indicates whether the call-gate descriptor is valid. (The presence of the code segment to which the gate points is indicated by the P flag in the code segment’s descriptor.) The parameter count field indicates the number of parameters to copy from the calling procedures stack to the new stack if a stack switch occurs (see Section 5.8.5, “Stack Switching”). The param eter count specifies the number of words for 16-bit call gates and doublewords for 32-bit call gates.

Type · Count

Page 186 of the Intel 253668-032US user manual — PROTECTION
Page 186 · click to enlarge
Page 186

PROTECTION

Note that the P flag in a gate descriptor is normally always set to 1. If it is set to 0, a not present (#NP) exception is generated when a program attempts to access the descriptor. The operating system can use the P flag for special purposes. For example, it could be used to track the number of times the gate is used. Here, the P flag is initially set to 0 causing a trap to the not-present exception handler. The exception handler then increments a counter and sets the P flag to 1, so that on returning from the handler, the gate descriptor will be valid.

5.8.3.1 IA-32e Mode Call Gates

  • Call-gate descriptors in 32-bit mode provide a 32-bit offset for the instruction pointer (EIP); 64-bit extensions double the size of 32-bit mode call gates in order to store 64-bit instruction pointers (RIP). See Figure 5-9:
  • The first eight bytes (bytes 7:0) of a 64-bit mode call gate are similar but not identical to legacy 32-bit mode call gates. The parameter-copy-count field has been removed.
  • Bytes 11:8 hold the upper 32 bits of the target-segment offset in canonical form. A general-protection exception (#GP) is generated if software attempts to use a call gate with a target offset that is not in canonical form.
  • 16-byte descriptors may reside in the same descriptor table with 16-bit and 32-bit descriptors. A type field, used for consistency checking, is defined in bits 12:8 of the 64-bit descriptor’s highest dword (cleared to zero). A generalprotection exception (#GP) results if an attempt is made to access the upper half of a 64-bit mode descriptor as a 32-bit mode descriptor.
Page 187 of the Intel 253668-032US user manual — P DPL
Page 187 · click to enlarge
Page 187

PROTECTION

13 12 11 10 9 8 7

0

Offset in Segment 63:31 8

31 8 7 0

16 15 14 13 12 11

P Offset in Segment 31:16

D P L

0 0 1 1

31 16 15 0

Segment Selector Offset in Segment 15:00 0

P DPL

Gate Valid Descriptor Privilege Level

Figure 5-9. Call-Gate Descriptor in IA-32e Mode

  • Target code segments referenced by a 64-bit call gate must be 64-bit code segments (CS.L = 1, CS.D = 0). If not, the reference generates a generalprotection exception, #GP (CS selector).
  • Only 64-bit mode call gates can be referenced in IA-32e mode (64-bit mode and compatibility mode). The legacy 32-bit mode call gate type (0CH) is redefined in IA-32e mode as a 64-bit call-gate type; no 32-bit call-gate type exists in IA-32e mode.
  • If a far call references a 16-bit call gate type (04H) in IA-32e mode, a generalprotection exception (#GP) is generated.
  • When a call references a 64-bit mode call gate, actions taken are identical to those taken in 32-bit mode, with the following exceptions:
  • Stack pushes are made in eight-byte increments.
  • A 64-bit RIP is pushed onto the stack.
  • Parameter copying is not performed.

Use a matching far-return instruction size for correct operation (returns from 64-bit calls must be performed with a 64-bit operand-size return to process the stack correctly).

Reserved Reserved Type · Type

Page 188 of the Intel 253668-032US user manual — +
Page 188 · click to enlarge
Page 188

PROTECTION

5.8.4 Accessing a Code Segment Through a Call Gate

To access a call gate, a far pointer to the gate is provided as a target operand in a CALL or JMP instruction. The segment selector from this pointer identifies the call gate (see Figure 5-10); the offset from the pointer is required, but not used or checked by the processor. (The offset can be set to any value.)

When the processor has accessed the call gate, it uses the segment selector from the call gate to locate the segment descriptor for the destination code segment. (This segment descriptor can be in the GDT or the LDT.) It then combines the base address from the code-segment descriptor with the offset from the call gate to form the linear address of the procedure entry point in the code segment.

  • As shown in Figure 5-11, four different privilege levels are used to check the validity of a program control transfer through a call gate:
  • The CPL (current privilege level).
  • The RPL (requestor's privilege level) of the call gate’s selector.
  • The DPL (descriptor privilege level) of the call gate descriptor.
  • The DPL of the segment descriptor of the destination code segment.

The C flag (conforming) in the segment descriptor for the destination code segment is also checked.

Far Pointer to Call Gate

Required but not used by processor

+

Figure 5-10. Call-Gate Mechanism

Show 11 more labels / short text on this page
Offset Segment Selector · Descriptor Table · Offset · Call-Gate Descriptor · Segment Selector · Offset · Base · Base · Code-Segment Descriptor · Base · Procedure Entry Point
Page 189 of the Intel 253668-032US user manual — DPL
Page 189 · click to enlarge
Page 189

PROTECTION

CPL

RPL

Check Call Gate (Descriptor)

DPL

DPL

Figure 5-11. Privilege Check for Control Transfer with Call Gate

The privilege checking rules are different depending on whether the control transfer was initiated with a CALL or a JMP instruction, as shown in Table 5-1.

Table 5-1. Privilege Check Rules for Call Gates

Instruction Privilege Check Rules

CALL CPL ≤ call gate DPL; RPL ≤ call gate DPL

Destination conforming code segment DPL ≤ CPL

Destination nonconforming code segment DPL ≤ CPL

JMP CPL ≤ call gate DPL; RPL ≤ call gate DPL

Destination conforming code segment DPL ≤ CPL

Destination nonconforming code segment DPL = CPL

The DPL field of the call-gate descriptor specifies the numerically highest privilege level from which a calling procedure can access the call gate; that is, to access a call gate, the CPL of a calling procedure must be equal to or less than the DPL of the call gate. For example, in Figure 5-15, call gate A has a DPL of 3. So calling procedures at all CPLs (0 through 3) can access this call gate, which includes calling procedures in code segments A, B, and C. Call gate B has a DPL of 2, so only calling procedures at a CPL or 0, 1, or 2 can access call gate B, which includes calling procedures in code

Show 5 more labels / short text on this page
CS Register · Call-Gate Selector · Privilege · Destination Code- · Segment Descriptor
Page 190 of the Intel 253668-032US user manual — PROTECTION
Page 190 · click to enlarge
Page 190

PROTECTION

segments B and C. The dotted line shows that a calling procedure in code segment A cannot access call gate B.

The RPL of the segment selector to a call gate must satisfy the same test as the CPL of the calling procedure; that is, the RPL must be less than or equal to the DPL of the call gate. In the example in Figure 5-15, a calling procedure in code segment C can access call gate B using gate selector B2 or B1, but it could not use gate selector B3 to access call gate B.

If the privilege checks between the calling procedure and call gate are successful, the processor then checks the DPL of the code-segment descriptor against the CPL of the calling procedure. Here, the privilege check rules vary between CALL and JMP instructions. Only CALL instructions can use call gates to transfer program control to more privileged (numerically lower privilege level) nonconforming code segments; that is, to nonconforming code segments with a DPL less than the CPL. A JMP instruc tion can use a call gate only to transfer program control to a nonconforming code segment with a DPL equal to the CPL. CALL and JMP instruction can both transfer program control to a more privileged conforming code segment; that is, to a conforming code segment with a DPL less than or equal to the CPL.

If a call is made to a more privileged (numerically lower privilege level) noncon forming destination code segment, the CPL is lowered to the DPL of the destination code segment and a stack switch occurs (see Section 5.8.5, “Stack Switching”). If a call or jump is made to a more privileged conforming destination code segment, the CPL is not changed and no stack switch occurs.

Page 191 of the Intel 253668-032US user manual — 5.8.5 Stack Switching
Page 191 · click to enlarge
Page 191

PROTECTION

Intel 253668-032US — PROTECTION diagram (page 191)
Fig. 18

Figure 5-12. Example of Accessing Call Gates At Various Privilege Levels

Call gates allow a single code segment to have procedures that can be accessed at different privilege levels. For example, an operating system located in a code segment may have some services which are intended to be used by both the oper ating system and application software (such as procedures for handling character I/O). Call gates for these procedures can be set up that allow access at all privilege levels (0 through 3). More privileged call gates (with DPLs of 0 or 1) can then be set up for other operating system services that are intended to be used only by the oper ating system (such as procedures that initialize device drivers).

5.8.5 Stack Switching

Whenever a call gate is used to transfer program control to a more privileged nonconforming code segment (that is, when the DPL of the nonconforming destina tion code segment is less than the CPL), the processor automatically switches to the stack for the destination code segment’s privilege level. This stack switching is carried out to prevent more privileged procedures from crashing due to insufficient stack space. It also prevents less privileged procedures from interfering (by accident or intent) with more privileged procedures through a shared stack.

Page 192 of the Intel 253668-032US user manual — PROTECTION
Page 192 · click to enlarge
Page 192

PROTECTION

Each task must define up to 4 stacks: one for applications code (running at privilege level 3) and one for each of the privilege levels 2, 1, and 0 that are used. (If only two privilege levels are used [3 and 0], then only two stacks must be defined.) Each of these stacks is located in a separate segment and is identified with a segment selector and an offset into the stack segment (a stack pointer).

The segment selector and stack pointer for the privilege level 3 stack is located in the SS and ESP registers, respectively, when privilege-level-3 code is being executed and is automatically stored on the called procedure’s stack when a stack switch occurs.

Pointers to the privilege level 0, 1, and 2 stacks are stored in the TSS for the currently running task (see Figure 7-2). Each of these pointers consists of a segment selector and a stack pointer (loaded into the ESP register). These initial pointers are strictly read-only values. The processor does not change them while the task is running. They are used only to create new stacks when calls are made to more privileged levels (numerically lower privilege levels). These stacks are disposed of when a return is made from the called procedure. The next time the procedure is called, a new stack is created using the initial stack pointer. (The TSS does not specify a stack for privilege level 3 because the processor does not allow a transfer of program control from a procedure running at a CPL of 0, 1, or 2 to a procedure running at a CPL of 3, except on a return.)

  • The operating system is responsible for creating stacks and stack-segment descrip tors for all the privilege levels to be used and for loading initial pointers for these stacks into the TSS. Each stack must be read/write accessible (as specified in the type field of its segment descriptor) and must contain enough space (as specified in the limit field) to hold the following items:
  • The contents of the SS, ESP, CS, and EIP registers for the calling procedure.
  • The parameters and temporary variables required by the called procedure.
  • The EFLAGS register and error code, when implicit calls are made to an exception or interrupt handler.

The stack will need to require enough space to contain many frames of these items, because procedures often call other procedures, and an operating system may support nesting of multiple interrupts. Each stack should be large enough to allow for the worst case nesting scenario at its privilege level.

(If the operating system does not use the processor’s multitasking mechanism, it still must create at least one TSS for this stack-related purpose.)

When a procedure call through a call gate results in a change in privilege level, the processor performs the following steps to switch stacks and begin execution of the called procedure at a new privilege level:

1. Uses the DPL of the destination code segment (the new CPL) to select a pointer to the new stack (segment selector and stack pointer) from the TSS.
2. Reads the segment selector and stack pointer for the stack to be switched to from the current TSS. Any limit violations detected while reading the stack-segment selector, stack pointer, or stack-segment descriptor cause an invalid TSS (#TS) exception to be generated.
Page 193 of the Intel 253668-032US user manual — ESP
Page 193 · click to enlarge
Page 193

PROTECTION

3. Checks the stack-segment descriptor for the proper privileges and type and generates an invalid TSS (#TS) exception if violations are detected.
4. Temporarily saves the current values of the SS and ESP registers.
5. Loads the segment selector and stack pointer for the new stack in the SS and ESP registers.
6. Pushes the temporarily saved values for the SS and ESP registers (for the calling procedure) onto the new stack (see Figure 5-13).
7. Copies the number of parameter specified in the parameter count field of the call gate from the calling procedure’s stack to the new stack. If the count is 0, no parameters are copied.
8. Pushes the return instruction pointer (the current contents of the CS and EIP registers) onto the new stack.
9. Loads the segment selector for the new code segment and the new instruction pointer from the call gate into the CS and EIP registers, respectively, and begins execution of the called procedure.

See the description of the CALL instruction in Chapter 3, Instruction Set Reference, in the IA-32 Intel Architecture Software Developer’s Manual, Volume 2, for a detailed description of the privilege level checks and other protection checks that the processor performs on a far call through a call gate.

ESP

ESP

Figure 5-13. Stack Switching During an Interprivilege-Level Call

The parameter count field in a call gate specifies the number of data items (up to 31) that the processor should copy from the calling procedure’s stack to the stack of the called procedure. If more than 31 data items need to be passed to the called proce

Show 12 more labels / short text on this page
Calling Procedure’s Stack · Called Procedure’s Stack · Calling SS · Parameter 1 · Calling ESP · Parameter 2 · Parameter 1 · Parameter 3 · Parameter 2 · Parameter 3 · Calling CS · Calling EIP
Page 194 of the Intel 253668-032US user manual — 5.8.6 Returning from a Called Procedure
Page 194 · click to enlarge
Page 194

PROTECTION

dure, one of the parameters can be a pointer to a data structure, or the saved contents of the SS and ESP registers may be used to access parameters in the old stack space. The size of the data items passed to the called procedure depends on the call gate size, as described in Section 5.8.3, “Call Gates.”

5.8.5.1 Stack Switching in 64-bit Mode

Although protection-check rules for call gates are unchanged from 32-bit mode, stack-switch changes in 64-bit mode are different.

When stacks are switched as part of a 64-bit mode privilege-level change through a call gate, a new SS (stack segment) descriptor is not loaded; 64-bit mode only loads an inner-level RSP from the TSS. The new SS is forced to NULL and the SS selector’s RPL field is forced to the new CPL. The new SS is set to NULL in order to handle nested far transfers (CALLF, INTn, interrupts and exceptions). The old SS and RSP are saved on the new stack.

On a subsequent RETF, the old SS is popped from the stack and loaded into the SS register. See Table 5-2.

Table 5-2. 64-Bit-Mode Stack Layout After CALLF with CPL Change

32-bit Mode IA-32e mode

Old SS Selector +12 +24 Old SS Selector

Old ESP +8 +16 Old RSP

CS Selector +4 +8 Old CS Selector

EIP 0 ESP RSP 0 RIP

< 4 Bytes > < 8 Bytes >

In 64-bit mode, stack operations resulting from a privilege-level-changing far call or far return are eight-bytes wide and change the RSP by eight. The mode does not support the automatic parameter-copy feature found in 32-bit mode. The call-gate count field is ignored. Software can access the old stack, if necessary, by referencing the old stack-segment selector and stack pointer saved on the new process stack.

In 64-bit mode, RETF is allowed to load a NULL SS under certain conditions. If the target mode is 64-bit mode and the target CPL< >3, IRET allows SS to be loaded with a NULL selector. If the called procedure itself is interrupted, the NULL SS is pushed on the stack frame. On the subsequent RETF, the NULL SS on the stack acts as a flag to tell the processor not to load a new SS descriptor.

5.8.6 Returning from a Called Procedure

The RET instruction can be used to perform a near return, a far return at the same privilege level, and a far return to a different privilege level. This instruction is

Page 195 of the Intel 253668-032US user manual — PROTECTION
Page 195 · click to enlarge
Page 195

PROTECTION

intended to execute returns from procedures that were called with a CALL instruc tion. It does not support returns from a JMP instruction, because the JMP instruction does not save a return instruction pointer on the stack.

A near return only transfers program control within the current code segment; there fore, the processor performs only a limit check. When the processor pops the return instruction pointer from the stack into the EIP register, it checks that the pointer does not exceed the limit of the current code segment.

On a far return at the same privilege level, the processor pops both a segment selector for the code segment being returned to and a return instruction pointer from the stack. Under normal conditions, these pointers should be valid, because they were pushed on the stack by the CALL instruction. However, the processor performs privilege checks to detect situations where the current procedure might have altered the pointer or failed to maintain the stack properly.

A far return that requires a privilege-level change is only allowed when returning to a less privileged level (that is, the DPL of the return code segment is numerically greater than the CPL). The processor uses the RPL field from the CS register value saved for the calling procedure (see Figure 5-13) to determine if a return to a numer ically higher privilege level is required. If the RPL is numerically greater (less privi leged) than the CPL, a return across privilege levels occurs.

The processor performs the following steps when performing a far return to a calling procedure (see Figures 6-2 and 6-4 in the Intel® 64 and IA-32 Architectures Soft ware Developer’s Manual, Volume 1, for an illustration of the stack contents prior to and after a return):

1. Checks the RPL field of the saved CS register value to determine if a privilege level change is required on the return.
2. Loads the CS and EIP registers with the values on the called procedure’s stack. (Type and privilege level checks are performed on the code-segment descriptor and RPL of the codesegment selector.)

3. (If the RET instruction includes a parameter count operand and the return requires a privilege level change.) Adds the parameter count (in bytes obtained from the RET instruction) to the current ESP register value (after popping the CS and EIP values), to step past the parameters on the called procedure’s stack. The resulting value in the ESP register points to the saved SS and ESP values for the calling procedure’s stack. (Note that the byte count in the RET instruction must be chosen to match the parameter count in the call gate that the calling procedure referenced when it made the original call multiplied by the size of the parameters.)

4. (If the return requires a privilege level change.) Loads the SS and ESP registers with the saved SS and ESP values and switches back to the calling procedure’s stack. The SS and ESP values for the called procedure’s stack are discarded. Any limit violations detected while loading the stack-segment selector or stack pointer cause a general-protection exception (#GP) to be generated. The new stack-segment descriptor is also checked for type and privilege violations.
Page 196 of the Intel 253668-032US user manual — PROTECTION
Page 196 · click to enlarge
Page 196

PROTECTION

5. (If the RET instruction includes a parameter count operand.) Adds the parameter count (in bytes obtained from the RET instruction) to the current ESP register value, to step past the parameters on the calling procedure’s stack. The resulting ESP value is not checked against the limit of the stack segment. If the ESP value is beyond the limit, that fact is not recognized until the next stack operation.
6. (If the return requires a privilege level change.) Checks the contents of the DS, ES, FS, and GS segment registers. If any of these registers refer to segments whose DPL is less than the new CPL (excluding conforming code segments), the segment register is loaded with a null segment selector.

See the description of the RET instruction in Chapter 4 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B, for a detailed description of the privilege level checks and other protection checks that the processor performs on a far return.

5.8.7 Performing Fast Calls to System Procedures with the SYSENTER and SYSEXIT Instructions

The SYSENTER and SYSEXIT instructions were introduced into the IA-32 architecture in the Pentium II processors for the purpose of providing a fast (low overhead) mech anism for calling operating system or executive procedures. SYSENTER is intended for use by user code running at privilege level 3 to access operating system or exec utive procedures running at privilege level 0. SYSEXIT is intended for use by privilege level 0 operating system or executive procedures for fast returns to privilege level 3 user code. SYSENTER can be executed from privilege levels 3, 2, 1, or 0; SYSEXIT can only be executed from privilege level 0.

The SYSENTER and SYSEXIT instructions are companion instructions, but they do not constitute a call/return pair. This is because SYSENTER does not save any state infor mation for use by SYSEXIT on a return.

The target instruction and stack pointer for these instructions are not specified through instruction operands. Instead, they are specified through parameters entered in MSRs and general-purpose registers.

  • For SYSENTER, target fields are generated using the following sources:
  • Target code segment — Reads this from IA32_SYSENTER_CS.
  • Target instruction — Reads this from IA32_SYSENTER_EIP.
  • Stack segment — Computed by adding 8 to the value in IA32_SYSENTER_CS.
  • Stack pointer — Reads this from the IA32_SYSENTER_ESP.
  • For SYSEXIT, target fields are generated using the following sources:
  • Target code segment — Computed by adding 16 to the value in the IA32_SYSENTER_CS.
  • Target instruction — Reads this from EDX.
Page 197 of the Intel 253668-032US user manual — PROTECTION
Page 197 · click to enlarge
Page 197

PROTECTION

  • Stack segment — Computed by adding 24 to the value in IA32_SYSENTER_CS.
  • Stack pointer — Reads this from ECX.

The SYSENTER and SYSEXIT instructions preform “fast” calls and returns because they force the processor into a predefined privilege level 0 state when SYSENTER is executed and into a predefined privilege level 3 state when SYSEXIT is executed. By forcing predefined and consistent processor states, the number of privilege checks ordinarily required to perform a far call to another privilege levels are greatly reduced. Also, by predefining the target context state in MSRs and general-purpose registers eliminates all memory accesses except when fetching the target code.

Any additional state that needs to be saved to allow a return to the calling procedure must be saved explicitly by the calling procedure or be predefined through program ming conventions.

5.8.7.1 SYSENTER and SYSEXIT Instructions in IA-32e Mode

For Intel 64 processors, the SYSENTER and SYSEXIT instructions are enhanced to allow fast system calls from user code running at privilege level 3 (in compatibility mode or 64-bit mode) to 64-bit executive procedures running at privilege level 0. IA32_SYSENTER_EIP MSR and IA32_SYSENTER_ESP MSR are expanded to hold 64-bit addresses. If IA-32e mode is inactive, only the lower 32-bit addresses stored in these MSRs are used. If 64-bit mode is active, addresses stored in IA32_SYSENTER_EIP and IA32_SYSENTER_ESP must be canonical. Note that, in 64-bit mode, IA32_SYSENTER_CS must not contain a NULL selector.

  • When SYSENTER transfers control, the following fields are generated and bits set:
  • Target code segment — Reads non-NULL selector from IA32_SYSENTER_CS.
  • New CS attributes — CS base = 0, CS limit = FFFFFFFFH.
  • Target instruction — Reads 64-bit canonical address from IA32_SYSENTER_EIP.
  • Stack segment — Computed by adding 8 to the value from IA32_SYSENTER_CS.
  • Stack pointer — Reads 64-bit canonical address from IA32_SYSENTER_ESP.
  • New SS attributes — SS base = 0, SS limit = FFFFFFFFH.
  • When the SYSEXIT instruction transfers control to 64-bit mode user code using REX.W, the following fields are generated and bits set:
  • Target code segment — Computed by adding 32 to the value in IA32_SYSENTER_CS.
  • New CS attributes — L-bit = 1 (go to 64-bit mode).
  • Target instruction — Reads 64-bit canonical address in RDX.
  • Stack segment — Computed by adding 40 to the value of IA32_SYSENTER_CS.
  • Stack pointer — Update RSP using 64-bit canonical address in RCX.
Page 198 of the Intel 253668-032US user manual — 5.8.8 Fast System Calls in 64-bit Mode
Page 198 · click to enlarge
Page 198

PROTECTION

  • When SYSEXIT transfers control to compatibility mode user code when the operand size attribute is 32 bits, the following fields are generated and bits set:
  • Target code segment — Computed by adding 16 to the value in IA32_SYSENTER_CS.
  • New CS attributes — L-bit = 0 (go to compatibility mode).
  • Target instruction — Fetch the target instruction from 32-bit address in EDX.
  • Stack segment — Computed by adding 24 to the value in IA32_SYSENTER_CS.
  • Stack pointer — Update ESP from 32-bit address in ECX.

5.8.8 Fast System Calls in 64-bit Mode

The SYSCALL and SYSRET instructions are designed for operating systems that use a flat memory model (segmentation is not used). The instructions, along with SYSENTER and SYSEXIT, are suited for IA-32e mode operation. SYSCALL and SYSRET, however, are not supported in compatibility mode. Use CPUID to check if SYSCALL and SYSRET are available (CPUID.80000001H.EDX[bit 11] = 1).

SYSCALL is intended for use by user code running at privilege level 3 to access oper ating system or executive procedures running at privilege level 0. SYSRET is intended for use by privilege level 0 operating system or executive procedures for fast returns to privilege level 3 user code.

Stack pointers for SYSCALL/SYSRET are not specified through model specific regis ters. The clearing of bits in RFLAGS is programmable rather than fixed. SYSCALL/SYSRET save and restore the RFLAGS register.

  • For SYSCALL, the processor saves the RIP of the instruction in RCX and gets the priv ilege level 0 target instruction and stack pointer from:
  • Target code segment — Reads a non-NULL selector from IA32_STAR[47:32].
  • Target instruction — Reads a 64-bit canonical address from IA32_LSTAR.
  • Stack segment — Computed by adding 8 to the value in IA32_STAR[47:32].
  • System flags — The processor uses a mask derived from IA32_FMASK to perform a logical-AND operation with the lower 32-bits of RFLAGS. The result is saved into R11. The mask is the complement of the value supplied by privileged executives using the IA32_FMASK MSR.
  • When SYSRET transfers control to 64-bit mode user code using REX.W, the processor gets the privilege level 3 target instruction and stack pointer from:
  • Target code segment — Reads a non-NULL selector from IA32_STAR[63:48] + 16.
  • Target instruction — Copies the value in RCX into RIP.
  • Stack segment — IA32_STAR[63:48] + 8.
  • EFLAGS — Loaded from R11.
Page 199 of the Intel 253668-032US user manual — 5.9 PRIVILEGED INSTRUCTIONS
Page 199 · click to enlarge
Page 199

PROTECTION

  • When SYSRET transfers control to 32-bit mode user code using a 32-bit operand size, the processor gets the privilege level 3 target instruction and stack pointer from:
  • Target code segment — Reads a non-NULL selector from IA32_STAR[63:48].
  • Target instruction — Copies the value in ECX into EIP.
  • Stack segment — IA32_STAR[63:48] + 8.
  • EFLAGS — Loaded from R11.

It is the responsibility of the OS to ensure the descriptors in the GDT/LDT correspond to the selectors loaded by SYSCALL/SYSRET (consistent with the base, limit, and attribute values forced by the instructions).

Any address written to IA32_LSTAR is first checked by WRMSR to ensure canonical form. If an address is not canonical, an exception is generated (#GP).

See Figure 5-14 for the layout of IA32_STAR, IA32_LSTAR and IA32_FMASK.

SYSCALL EFLAGS Mask Reserved

IA32_FMASK

Target RIP for 64-bit Mode Calling Program

IA32_LSTAR

63 32 31 0

SYSRET CS and SS SYSCALL CS and SS

IA32_STAR

Figure 5-14. MSRs Used by SYSCALL and SYSRET

5.9 PRIVILEGED INSTRUCTIONS

Some of the system instructions (called “privileged instructions”) are protected from use by application programs. The privileged instructions control system functions (such as the loading of system registers). They can be executed only when the CPL is 0 (most privileged). If one of these instructions is executed when the CPL is not 0, a

Reserved

Page 200 of the Intel 253668-032US user manual — 5.10 POINTER VALIDATION
Page 200 · click to enlarge
Page 200

PROTECTION

  • general-protection exception (#GP) is generated. The following system instructions are privileged instructions:
  • LGDT — Load GDT register.
  • LLDT — Load LDT register.
  • LTR — Load task register.
  • LIDT — Load IDT register.
  • MOV (control registers) — Load and store control registers.
  • LMSW — Load machine status word.
  • CLTS — Clear task-switched flag in register CR0.
  • MOV (debug registers) — Load and store debug registers.
  • INVD — Invalidate cache, without writeback.
  • WBINVD — Invalidate cache, with writeback.
  • INVLPG —Invalidate TLB entry.
  • HLT— Halt processor.
  • RDMSR — Read Model-Specific Registers.
  • WRMSR —Write Model-Specific Registers.
  • RDPMC — Read Performance-Monitoring Counter.
  • RDTSC — Read Time-Stamp Counter.

Some of the privileged instructions are available only in the more recent families of Intel 64 and IA-32 processors (see Section 19.13, “New Instructions In the Pentium and Later IA-32 Processors”).

The PCE and TSD flags in register CR4 (bits 4 and 2, respectively) enable the RDPMC and RDTSC instructions, respectively, to be executed at any CPL.

5.10 POINTER VALIDATION

When operating in protected mode, the processor validates all pointers to enforce protection between segments and maintain isolation between privilege levels. Pointer validation consists of the following checks:

1. Checking access rights to determine if the segment type is compatible with its use.
2. Checking read/write rights.
3. Checking if the pointer offset exceeds the segment limit.
4. Checking if the supplier of the pointer is allowed to access the segment.
5. Checking the offset alignment.
Page 201 of the Intel 253668-032US user manual — 5.10.1 Checking Access Rights (LAR Instruction)
Page 201 · click to enlarge
Page 201

PROTECTION

The processor automatically performs first, second, and third checks during instruc tion execution. Software must explicitly request the fourth check by issuing an ARPL instruction. The fifth check (offset alignment) is performed automatically at privilege level 3 if alignment checking is turned on. Offset alignment does not affect isolation of privilege levels.

5.10.1 Checking Access Rights (LAR Instruction)

When the processor accesses a segment using a far pointer, it performs an access rights check on the segment descriptor pointed to by the far pointer. This check is performed to determine if type and privilege level (DPL) of the segment descriptor are compatible with the operation to be performed. For example, when making a far call in protected mode, the segment-descriptor type must be for a conforming or nonconforming code segment, a call gate, a task gate, or a TSS. Then, if the call is to a nonconforming code segment, the DPL of the code segment must be equal to the CPL, and the RPL of the code segment’s segment selector must be less than or equal to the DPL. If type or privilege level are found to be incompatible, the appropriate exception is generated.

To prevent type incompatibility exceptions from being generated, software can check the access rights of a segment descriptor using the LAR (load access rights) instruc tion. The LAR instruction specifies the segment selector for the segment descriptor whose access rights are to be checked and a destination register. The instruction then performs the following operations:

1. Check that the segment selector is not null.
2. Checks that the segment selector points to a segment descriptor that is within the descriptor table limit (GDT or LDT).
3. Checks that the segment descriptor is a code, data, LDT, call gate, task gate, or TSS segment-descriptor type.
4. If the segment is not a conforming code segment, checks if the segment descriptor is visible at the CPL (that is, if the CPL and the RPL of the segment selector are less than or equal to the DPL).
5. If the privilege level and type checks pass, loads the second doubleword of the segment descriptor into the destination register (masked by the value 00FXFF00H, where X indicates that the corresponding 4 bits are undefined) and sets the ZF flag in the EFLAGS register. If the segment selector is not visible at the current privilege level or is an invalid type for the LAR instruction, the instruction does not modify the destination register and clears the ZF flag.

Once loaded in the destination register, software can preform additional checks on the access rights information.

Page 202 of the Intel 253668-032US user manual — 5.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)
Page 202 · click to enlarge
Page 202

PROTECTION

5.10.2 Checking Read/Write Rights (VERR and VERW Instructions)

When the processor accesses any code or data segment it checks the read/write priv ileges assigned to the segment to verify that the intended read or write operation is allowed. Software can check read/write rights using the VERR (verify for reading) and VERW (verify for writing) instructions. Both these instructions specify the segment selector for the segment being checked. The instructions then perform the following operations:

1. Check that the segment selector is not null.
2. Checks that the segment selector points to a segment descriptor that is within the descriptor table limit (GDT or LDT).
3. Checks that the segment descriptor is a code or data-segment descriptor type.
4. If the segment is not a conforming code segment, checks if the segment descriptor is visible at the CPL (that is, if the CPL and the RPL of the segment selector are less than or equal to the DPL).
5. Checks that the segment is readable (for the VERR instruction) or writable (for the VERW) instruction.

The VERR instruction sets the ZF flag in the EFLAGS register if the segment is visible at the CPL and readable; the VERW sets the ZF flag if the segment is visible and writ able. (Code segments are never writable.) The ZF flag is cleared if any of these checks fail.

5.10.3 Checking That the Pointer Offset Is Within Limits (LSL Instruction)

When the processor accesses any segment it performs a limit check to insure that the offset is within the limit of the segment. Software can perform this limit check using the LSL (load segment limit) instruction. Like the LAR instruction, the LSL instruction specifies the segment selector for the segment descriptor whose limit is to be checked and a destination register. The instruction then performs the following oper ations:

1. Check that the segment selector is not null.
2. Checks that the segment selector points to a segment descriptor that is within the descriptor table limit (GDT or LDT).
3. Checks that the segment descriptor is a code, data, LDT, or TSS segmentdescriptor type.
4. If the segment is not a conforming code segment, checks if the segment descriptor is visible at the CPL (that is, if the CPL and the RPL of the segment selector less than or equal to the DPL).
5. If the privilege level and type checks pass, loads the unscrambled limit (the limit scaled according to the setting of the G flag in the segment descriptor) into the
Page 203 of the Intel 253668-032US user manual — 5.10.4 Checking Caller Access Privileges (ARPL Instruction)
Page 203 · click to enlarge
Page 203

PROTECTION

destination register and sets the ZF flag in the EFLAGS register. If the segment selector is not visible at the current privilege level or is an invalid type for the LSL instruction, the instruction does not modify the destination register and clears the ZF flag.

Once loaded in the destination register, software can compare the segment limit with the offset of a pointer.

5.10.4 Checking Caller Access Privileges (ARPL Instruction)

The requestor’s privilege level (RPL) field of a segment selector is intended to carry the privilege level of a calling procedure (the calling procedure’s CPL) to a called procedure. The called procedure then uses the RPL to determine if access to a segment is allowed. The RPL is said to “weaken” the privilege level of the called procedure to that of the RPL.

Operating-system procedures typically use the RPL to prevent less privileged appli cation programs from accessing data located in more privileged segments. When an operating-system procedure (the called procedure) receives a segment selector from an application program (the calling procedure), it sets the segment selector’s RPL to the privilege level of the calling procedure. Then, when the operating system uses the segment selector to access its associated segment, the processor performs priv ilege checks using the calling procedure’s privilege level (stored in the RPL) rather than the numerically lower privilege level (the CPL) of the operating-system proce dure. The RPL thus insures that the operating system does not access a segment on behalf of an application program unless that program itself has access to the segment.

Figure 5-15 shows an example of how the processor uses the RPL field. In this example, an application program (located in code segment A) possesses a segment selector (segment selector D1) that points to a privileged data structure (that is, a data structure located in a data segment D at privilege level 0).

The application program cannot access data segment D, because it does not have sufficient privilege, but the operating system (located in code segment C) can. So, in an attempt to access data segment D, the application program executes a call to the operating system and passes segment selector D1 to the operating system as a parameter on the stack. Before passing the segment selector, the (well behaved) application program sets the RPL of the segment selector to its current privilege level (which in this example is 3). If the operating system attempts to access data segment D using segment selector D1, the processor compares the CPL (which is now 0 following the call), the RPL of segment selector D1, and the DPL of data segment D (which is 0). Since the RPL is greater than the DPL, access to data segment D is denied. The processor’s protection mechanism thus protects data segment D from access by the operating system, because application program’s priv ilege level (represented by the RPL of segment selector B) is greater than the DPL of data segment D.

Page 204 of the Intel 253668-032US user manual — PROTECTION
Page 204 · click to enlarge
Page 204

PROTECTION

Intel 253668-032US — PROTECTION diagram (page 204)
Fig. 19

Figure 5-15. Use of RPL to Weaken Privilege Level of Called Procedure

Now assume that instead of setting the RPL of the segment selector to 3, the appli cation program sets the RPL to 0 (segment selector D2). The operating system can now access data segment D, because its CPL and the RPL of segment selector D2 are both equal to the DPL of data segment D.

Because the application program is able to change the RPL of a segment selector to any value, it can potentially use a procedure operating at a numerically lower privi lege level to access a protected data structure. This ability to lower the RPL of a segment selector breaches the processor’s protection mechanism.

Because a called procedure cannot rely on the calling procedure to set the RPL correctly, operating-system procedures (executing at numerically lower privilege- levels) that receive segment selectors from numerically higher privilege-level proce dures need to test the RPL of the segment selector to determine if it is at the appro priate level. The ARPL (adjust requested privilege level) instruction is provided for this purpose. This instruction adjusts the RPL of one segment selector to match that of another segment selector.

Page 205 of the Intel 253668-032US user manual — 5.11 PAGE-LEVEL PROTECTION
Page 205 · click to enlarge
Page 205

PROTECTION

The example in Figure 5-15 demonstrates how the ARPL instruction is intended to be used. When the operating-system receives segment selector D2 from the application program, it uses the ARPL instruction to compare the RPL of the segment selector with the privilege level of the application program (represented by the code-segment selector pushed onto the stack). If the RPL is less than application program’s privi lege level, the ARPL instruction changes the RPL of the segment selector to match the privilege level of the application program (segment selector D1). Using this instruc tion thus prevents a procedure running at a numerically higher privilege level from accessing numerically lower privilege-level (more privileged) segments by lowering the RPL of a segment selector.

Note that the privilege level of the application program can be determined by reading the RPL field of the segment selector for the application-program’s code segment. This segment selector is stored on the stack as part of the call to the operating system. The operating system can copy the segment selector from the stack into a register for use as an operand for the ARPL instruction.

5.10.5 Checking Alignment

When the CPL is 3, alignment of memory references can be checked by setting the AM flag in the CR0 register and the AC flag in the EFLAGS register. Unaligned memory references generate alignment exceptions (#AC). The processor does not generate alignment exceptions when operating at privilege level 0, 1, or 2. See Table 6-7 for a description of the alignment requirements when alignment checking is enabled.

5.11 PAGE-LEVEL PROTECTION

Page-level protection can be used alone or applied to segments. When page-level protection is used with the flat memory model, it allows supervisor code and data (the operating system or executive) to be protected from user code and data (appli cation programs). It also allows pages containing code to be write protected. When the segment- and page-level protection are combined, page-level read/write protec tion allows more protection granularity within segments.

With page-level protection (as with segment-level protection) each memory refer ence is checked to verify that protection checks are satisfied. All checks are made before the memory cycle is started, and any violation prevents the cycle from starting and results in a page-fault exception being generated. Because checks are performed in parallel with address translation, there is no performance penalty.

  • The processor performs two page-level protection checks:
  • Restriction of addressable domain (supervisor and user modes).
  • Page type (read only or read/write).

Violations of either of these checks results in a page-fault exception being generated. See Chapter 6, “Interrupt 14—Page-Fault Exception (#PF),” for an explanation of the

Page 206 of the Intel 253668-032US user manual — 5.11.3 Page Type
Page 206 · click to enlarge
Page 206

PROTECTION

page-fault exception mechanism. This chapter describes the protection violations which lead to page-fault exceptions.

5.11.1 Page-Protection Flags

Protection information for pages is contained in two flags in a paging-structure entry (see Chapter 4): the read/write flag (bit 1) and the user/supervisor flag (bit 2). The protection checks use the flags in all paging structures.

5.11.2 Restricting Addressable Domain

  • The page-level protection mechanism allows restricting access to pages based on two privilege levels:
  • Supervisor mode (U/S flag is 0)—(Most privileged) For the operating system or executive, other system software (such as device drivers), and protected system data (such as page tables).
  • User mode (U/S flag is 1)—(Least privileged) For application code and data.

The segment privilege levels map to the page privilege levels as follows. If the processor is currently operating at a CPL of 0, 1, or 2, it is in supervisor mode; if it is operating at a CPL of 3, it is in user mode. When the processor is in supervisor mode, it can access all pages; when in user mode, it can access only user-level pages. (Note that the WP flag in control register CR0 modifies the supervisor permissions, as described in Section 5.11.3, “Page Type.”)

Note that to use the page-level protection mechanism, code and data segments must be set up for at least two segment-based privilege levels: level 0 for supervisor code and data segments and level 3 for user code and data segments. (In this model, the stacks are placed in the data segments.) To minimize the use of segments, a flat memory model can be used (see Section 3.2.1, “Basic Flat Model”).

Here, the user and supervisor code and data segments all begin at address zero in the linear address space and overlay each other. With this arrangement, operating- system code (running at the supervisor level) and application code (running at the user level) can execute as if there are no segments. Protection between operating- system and application code and data is provided by the processor’s page-level protection mechanism.

5.11.3 Page Type

  • The page-level protection mechanism recognizes two page types:
  • Read-only access (R/W flag is 0).
  • Read/write access (R/W flag is 1).
Page 207 of the Intel 253668-032US user manual — 5.12 COMBINING PAGE AND SEGMENT PROTECTION
Page 207 · click to enlarge
Page 207

PROTECTION

When the processor is in supervisor mode and the WP flag in register CR0 is clear (its state following reset initialization), all pages are both readable and writable (write- protection is ignored). When the processor is in user mode, it can write only to user- mode pages that are read/write accessible. User-mode pages which are read/write or read-only are readable; supervisor-mode pages are neither readable nor writable from user mode. A page-fault exception is generated on any attempt to violate the protection rules.

Starting with the P6 family, Intel processors allow user-mode pages to be write- protected against supervisor-mode access. Setting CR0.WP = 1 enables supervisor- mode sensitivity to write protected pages. If CR0.WP = 1, read-only pages are not writable from any privilege level. This supervisor write-protect feature is useful for implementing a “copy-on-write” strategy used by some operating systems, such as UNIX*, for task creation (also called forking or spawning). When a new task is created, it is possible to copy the entire address space of the parent task. This gives the child task a complete, duplicate set of the parent's segments and pages. An alter native copy-on-write strategy saves memory space and time by mapping the child's segments and pages to the same segments and pages used by the parent task. A private copy of a page gets created only when one of the tasks writes to the page. By using the WP flag and marking the shared pages as read-only, the supervisor can detect an attempt to write to a page, and can copy the page at that time.

5.11.4 Combining Protection of Both Levels of Page Tables

For any one page, the protection attributes of its page-directory entry (first-level page table) may differ from those of its page-table entry (second-level page table). The processor checks the protection for a page in both its page-directory and the page-table entries. Table 5-3 shows the protection provided by the possible combina tions of protection attributes when the WP flag is clear.

5.11.5 Overrides to Page Protection

  • The following types of memory accesses are checked as if they are privilege-level 0 accesses, regardless of the CPL at which the processor is currently operating:
  • Access to segment descriptors in the GDT, LDT, or IDT.
  • Access to an inner-privilege-level stack during an inter-privilege-level call or a call to in exception or interrupt handler, when a change of privilege level occurs.

5.12 COMBINING PAGE AND SEGMENT PROTECTION

When paging is enabled, the processor evaluates segment protection first, then evaluates page protection. If the processor detects a protection violation at either the segment level or the page level, the memory access is not carried out and an

Page 208 of the Intel 253668-032US user manual — PROTECTION
Page 208 · click to enlarge
Page 208

PROTECTION

exception is generated. If an exception is generated by segmentation, no paging exception is generated.

Page-level protections cannot be used to override segment-level protection. For example, a code segment is by definition not writable. If a code segment is paged, setting the R/W flag for the pages to read-write does not make the pages writable. Attempts to write into the pages will be blocked by segment-level protection checks.

Page-level protection can be used to enhance segment-level protection. For example, if a large read-write data segment is paged, the page-protection mecha nism can be used to write-protect individual pages.

Table 5-3. Combined Page-Directory and Page-Table Protection

Page-Directory Entry Page-Table Entry Combined Effect

Privilege Access Type Privilege Access Type Privilege Access Type

User Read-Only User Read-Only User Read-Only

User Read-Only User Read-Write User Read-Only

User Read-Write User Read-Only User Read-Only

User Read-Write User Read-Write User Read/Write

User Read-Only Supervisor Read-Only Supervisor Read/Write*

User Read-Only Supervisor Read-Write Supervisor Read/Write*

User Read-Write Supervisor Read-Only Supervisor Read/Write*

User Read-Write Supervisor Read-Write Supervisor Read/Write

Supervisor Read-Only User Read-Only Supervisor Read/Write*

Supervisor Read-Only User Read-Write Supervisor Read/Write*

Supervisor Read-Write User Read-Only Supervisor Read/Write*

Supervisor Read-Write User Read-Write Supervisor Read/Write

Supervisor Read-Only Supervisor Read-Only Supervisor Read/Write*

Supervisor Read-Only Supervisor Read-Write Supervisor Read/Write*

Supervisor Read-Write Supervisor Read-Only Supervisor Read/Write*

Supervisor Read-Write Supervisor Read-Write Supervisor Read/Write

Page 209 of the Intel 253668-032US user manual — 5.13.1 Detecting and Enabling the Execute-Disable Capability
Page 209 · click to enlarge
Page 209

PROTECTION

5.13 PAGE-LEVEL PROTECTION AND EXECUTE-DISABLE BIT

In addition to page-level protection offered by the U/S and R/W flags, paging struc tures used with PAE paging and IA-32e paging (see Chapter 4) provide the execute- disable bit. This bit offers additional protection for data pages.

  • An Intel 64 or IA-32 processor with the execute-disable bit capability can prevent data pages from being used by malicious software to execute code. This capability is provided in:
  • 32-bit protected mode with PAE enabled.
  • IA-32e mode.

While the execute-disable bit capability does not introduce new instructions, it does require operating systems to use a PAE-enabled environment and establish a page- granular protection policy for memory pages.

If the execute-disable bit of a memory page is set, that page can be used only as data. An attempt to execute code from a memory page with the execute-disable bit set causes a page-fault exception.

The execute-disable capability is supported only with PAE paging and IA-32e paging. It is not supported with 32-bit paging. Existing page-level protection mechanisms (see Section 5.11, “Page-Level Protection”) continue to apply to memory pages inde pendent of the execute-disable setting.

5.13.1 Detecting and Enabling the Execute-Disable Capability

Software can detect the presence of the execute-disable capability using the CPUID instruction. CPUID.80000001H:EDX.NX [bit 20] = 1 indicates the capability is avail able.

If the capability is available, software can enable it by setting IA32_EFER.NXE[bit 11] to 1. IA32_EFER is available if CPUID.80000001H.EDX[bit 20 or 29] = 1.

If the execute-disable capability is not available, a write to set IA32_EFER.NXE produces a #GP exception. See Table 5-4.

Table 5-4. Extended Feature Enable MSR (IA32_EFER)

63:12 11 10 9 8 7:1 0

Reserved Execute- disable bit enable (NXE)

IA-32e mode active (LMA)

IA-32e mode enable (LME)

Reserve d · Reserve d · SysCall enable (SCE)

Page 210 of the Intel 253668-032US user manual — PML4 PDP PDE PTE
Page 210 · click to enlarge
Page 210

PROTECTION

5.13.2 Execute-Disable Page Protection

The execute-disable bit in the paging structures enhances page protection for data pages. Instructions cannot be fetched from a memory page if IA32_EFER.NXE =1 and the execute-disable bit is set in any of the paging-structure entries used to map the page. Table 5-5 lists the valid usage of a page in relation to the value of execute- disable bit (bit 63) of the corresponding entry in each level of the paging structures. Execute-disable protection can be activated using the execute-disable bit at any level of the paging structure, irrespective of the corresponding entry in other levels. When execute-disable protection is not activated, the page can be used as code or data.

Table 5-5. IA-32e Mode Page Level Protection Matrix

with Execute-Disable Bit Capability Execute Disable Bit Value (Bit 63) Valid Usage

PML4 PDP PDE PTE

Bit 63 = 1 * * * Data

* Bit 63 = 1 * * Data

* * Bit 63 = 1 * Data

* * * Bit 63 = 1 Data

Bit 63 = 0 Bit 63 = 0 Bit 63 = 0 Bit 63 = 0 Data/Code

In legacy PAE-enabled mode, Table 5-6 and Table 5-7 show the effect of setting the execute-disable bit for code and data pages.

Page 211 of the Intel 253668-032US user manual — 5.13.3 Reserved Bit Checking
Page 211 · click to enlarge
Page 211

PROTECTION

Table 5-6. Legacy PAE-Enabled 4-KByte Page Level Protection Matrix

with Execute-Disable Bit Capability Execute Disable Bit Value (Bit 63) Valid Usage

PDE PTE

Bit 63 = 1 * Data

* Bit 63 = 1 Data

Bit 63 = 0 Bit 63 = 0 Data/Code

Table 5-7. Legacy PAE-Enabled 2-MByte Page Level Protection

with Execute-Disable Bit Capability Execute Disable Bit Value (Bit 63) Valid Usage

PDE

Bit 63 = 1 Data

Bit 63 = 0 Data/Code

5.13.3 Reserved Bit Checking

The processor enforces reserved bit checking in paging data structure entries. The bits being checked varies with paging mode and may vary with the size of physical address space.

  • Table 5-8 shows the reserved bits that are checked when the execute disable bit capability is enabled (CR4.PAE = 1 and IA32_EFER.NXE = 1). Table 5-8 and Table show the following paging modes:
  • Non-PAE 4-KByte paging: 4-KByte-page only paging (CR4.PAE = 0, CR4.PSE = 0).
  • PSE36: 4-KByte and 4-MByte pages (CR4.PAE = 0, CR4.PSE = 1).
  • PAE: 4-KByte and 2-MByte pages (CR4.PAE = 1, CR4.PSE = X).

The reserved bit checking depends on the physical address size supported by the implementation, which is reported in CPUID.80000008H. See the table note.

Page 212 of the Intel 253668-032US user manual — PROTECTION
Page 212 · click to enlarge
Page 212

PROTECTION

Table 5-8. IA-32e Mode Page Level Protection Matrix with Execute-Disable Bit

Capability Enabled Mode Paging Mode Check Bits

32-bit 4-KByte paging (non-PAE) No reserved bits checked

PSE36 - PDE, 4-MByte page Bit [21]

PSE36 - PDE, 4-KByte page No reserved bits checked

PSE36 - PTE No reserved bits checked

PAE - PDP table entry Bits [63:MAXPHYADDR] & [8:5] & [2:1] *

PAE - PDE, 2-MByte page Bits [62:MAXPHYADDR] & [20:13] *

PAE - PDE, 4-KByte page Bits [62:MAXPHYADDR] *

PAE - PTE Bits [62:MAXPHYADDR] *

64-bit PML4E Bits [51:MAXPHYADDR] *

PDPTE Bits [51:MAXPHYADDR] *

PDE, 2-MByte page Bits [51:MAXPHYADDR] & [20:13] *

PDE, 4-KByte page Bits [51:MAXPHYADDR] *

PTE Bits [51:MAXPHYADDR] *

If execute disable bit capability is not enabled or not available, reserved bit checking in 64-bit mode includes bit 63 and additional bits. This and reserved bit checking for legacy 32-bit paging modes are shown in Table 5-10.

Page 213 of the Intel 253668-032US user manual — 5.13.4 Exception Handling
Page 213 · click to enlarge
Page 213

PROTECTION

Table 5-9. Reserved Bit Checking WIth Execute-Disable Bit Capability Not Enabled Mode Paging Mode Check Bits

32-bit KByte paging (non-PAE) No reserved bits checked

PSE36 - PDE, 4-MByte page Bit [21]

PSE36 - PDE, 4-KByte page No reserved bits checked

PSE36 - PTE No reserved bits checked

PAE - PDP table entry Bits [63:MAXPHYADDR] & [8:5] & [2:1]*

PAE - PDE, 2-MByte page Bits [63:MAXPHYADDR] & [20:13]*

PAE - PDE, 4-KByte page Bits [63:MAXPHYADDR]*

PAE - PTE Bits [63:MAXPHYADDR]*

64-bit PML4E Bit [63], bits [51:MAXPHYADDR]*

PDPTE Bit [63], bits [51:MAXPHYADDR]*

PDE, 2-MByte page Bit [63], bits [51:MAXPHYADDR] & [20:13]*

PDE, 4-KByte page Bit [63], bits [51:MAXPHYADDR]*

PTE Bit [63], bits [51:MAXPHYADDR]*

5.13.4 Exception Handling

When execute disable bit capability is enabled (IA32_EFER.NXE = 1), conditions for a page fault to occur include the same conditions that apply to an Intel 64 or IA-32 processor without execute disable bit capability plus the following new condition: an instruction fetch to a linear address that translates to physical address in a memory page that has the execute-disable bit set.

  • An Execute Disable Bit page fault can occur at all privilege levels. It can occur on any instruction fetch, including (but not limited to): near branches, far branches, CALL/RET/INT/IRET execution, sequential instruction fetches, and task switches. The execute-disable bit in the page translation mechanism is checked only when:
  • IA32_EFER.NXE = 1.
  • The instruction translation look-aside buffer (ITLB) is loaded with a page that is not already present in the ITLB.
Page 214 of the Intel 253668-032US user manual — PROTECTION
Page 214 · click to enlarge
Page 214

PROTECTION

Page 215 of the Intel 253668-032US user manual — 6.1 INTERRUPT AND EXCEPTION OVERVIEW
Page 215 · click to enlarge
Page 215

CHAPTER 6 INTERRUPT AND EXCEPTION HANDLING

This chapter describes the interrupt and exception-handling mechanism when oper ating in protected mode on an Intel 64 or IA-32 processor. Most of the information provided here also applies to interrupt and exception mechanisms used in real- address, virtual-8086 mode, and 64-bit mode.

Chapter 17, “8086 Emulation,” describes information specific to interrupt and excep tion mechanisms in real-address and virtual-8086 mode. Section 6.14, “Exception and Interrupt Handling in 64-bit Mode,” describes information specific to interrupt and exception mechanisms in IA-32e mode and 64-bit sub-mode.

6.1 INTERRUPT AND EXCEPTION OVERVIEW

Interrupts and exceptions are events that indicate that a condition exists somewhere in the system, the processor, or within the currently executing program or task that requires the attention of a processor. They typically result in a forced transfer of execution from the currently running program or task to a special software routine or task called an interrupt handler or an exception handler. The action taken by a processor in response to an interrupt or exception is referred to as servicing or handling the interrupt or exception.

Interrupts occur at random times during the execution of a program, in response to signals from hardware. System hardware uses interrupts to handle events external to the processor, such as requests to service peripheral devices. Software can also generate interrupts by executing the INT n instruction.

Exceptions occur when the processor detects an error condition while executing an instruction, such as division by zero. The processor detects a variety of error condi tions including protection violations, page faults, and internal machine faults. The machine-check architecture of the Pentium 4, Intel Xeon, P6 family, and Pentium processors also permits a machine-check exception to be generated when internal hardware errors and bus errors are detected.

When an interrupt is received or an exception is detected, the currently running procedure or task is suspended while the processor executes an interrupt or excep tion handler. When execution of the handler is complete, the processor resumes execution of the interrupted procedure or task. The resumption of the interrupted procedure or task happens without loss of program continuity, unless recovery from an exception was not possible or an interrupt caused the currently running program to be terminated.

This chapter describes the processor’s interrupt and exception-handling mechanism, when operating in protected mode. A description of the exceptions and the conditions that cause them to be generated is given at the end of this chapter.

Page 216 of the Intel 253668-032US user manual — 6.3.1 External Interrupts
Page 216 · click to enlarge
Page 216

INTERRUPT AND EXCEPTION HANDLING

6.2 EXCEPTION AND INTERRUPT VECTORS

To aid in handling exceptions and interrupts, each architecturally defined exception and each interrupt condition requiring special handling by the processor is assigned a unique identification number, called a vector. The processor uses the vector assigned to an exception or interrupt as an index into the interrupt descriptor table (IDT). The table provides the entry point to an exception or interrupt handler (see Section 6.10, “Interrupt Descriptor Table (IDT)”).

The allowable range for vector numbers is 0 to 255. Vectors in the range 0 through 31 are reserved by the Intel 64 and IA-32 architectures for architecture-defined exceptions and interrupts. Not all of the vectors in this range have a currently defined function. The unassigned vectors in this range are reserved. Do not use the reserved vectors.

Vectors in the range 32 to 255 are designated as user-defined interrupts and are not reserved by the Intel 64 and IA-32 architecture. These interrupts are generally assigned to external I/O devices to enable those devices to send interrupts to the processor through one of the external hardware interrupt mechanisms (see Section 6.3, “Sources of Interrupts”).

Table 6-1 shows vector assignments for architecturally defined exceptions and for the NMI interrupt. This table gives the exception type (see Section 6.5, “Exception Clas sifications”) and indicates whether an error code is saved on the stack for the excep tion. The source of each predefined exception and the NMI interrupt is also given.

6.3 SOURCES OF INTERRUPTS

  • The processor receives interrupts from two sources:
  • External (hardware generated) interrupts.
  • Software-generated interrupts.

6.3.1 External Interrupts

External interrupts are received through pins on the processor or through the local APIC. The primary interrupt pins on Pentium 4, Intel Xeon, P6 family, and Pentium processors are the LINT[1:0] pins, which are connected to the local APIC (see Chapter 10, “Advanced Programmable Interrupt Controller (APIC)”). When the local APIC is enabled, the LINT[1:0] pins can be programmed through the APIC’s local vector table (LVT) to be associated with any of the processor’s exception or interrupt vectors.

When the local APIC is global/hardware disabled, these pins are configured as INTR and NMI pins, respectively. Asserting the INTR pin signals the processor that an external interrupt has occurred. The processor reads from the system bus the inter rupt vector number provided by an external interrupt controller, such as an 8259A

Page 217 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 217 · click to enlarge
Page 217

INTERRUPT AND EXCEPTION HANDLING

(see Section 6.2, “Exception and Interrupt Vectors”). Asserting the NMI pin signals a non-maskable interrupt (NMI), which is assigned to interrupt vector 2.

Table 6-1. Protected-Mode Exceptions and Interrupts

Vector No.

Description Type Error Code

0 #DE Divide Error Fault No DIV and IDIV instructions.

1 #DB RESERVED Fault/ Trap

No For Intel use only.

2 — NMI Interrupt Interrupt No Nonmaskable external interrupt.

3 #BP Breakpoint Trap No INT 3 instruction.

4 #OF Overflow Trap No INTO instruction.

5 #BR BOUND Range Exceeded Fault No BOUND instruction.

6 #UD Invalid Opcode (Undefined Opcode)

Fault No UD2 instruction or reserved opcode.1

7 #NM Device Not Available (No Math Coprocessor)

Fault No Floating-point or WAIT/FWAIT instruction.

8 #DF Double Fault Abort Yes (zero)

Any instruction that can generate an exception, an NMI, or an INTR.

Fault No Floating-point instruction.2

9 Coprocessor Segment Overrun (reserved)

10 #TS Invalid TSS Fault Yes Task switch or TSS access.

11 #NP Segment Not Present Fault Yes Loading segment registers or accessing system segments.

12 #SS Stack-Segment Fault Fault Yes Stack operations and SS register loads.

13 #GP General Protection Fault Yes Any memory reference and other protection checks.

14 #PF Page Fault Fault Yes Any memory reference.

15 — (Intel reserved. Do not use.)

16 #MF x87 FPU Floating-Point Error (Math Fault)

Fault No x87 FPU floating-point or WAIT/FWAIT instruction.

17 #AC Alignment Check Fault Yes (Zero)

Any data reference in memory.3

Mne- monic · Source · No

Page 218 of the Intel 253668-032US user manual — 6.3.2 Maskable Hardware Interrupts
Page 218 · click to enlarge
Page 218

INTERRUPT AND EXCEPTION HANDLING

Table 6-1. Protected-Mode Exceptions and Interrupts (Contd.)

18 #MC Machine Check Abort No Error codes (if any) and source are model dependent.4

19 #XM SIMD Floating-Point Exception

Fault No SSE/SSE2/SSE3 floating-point instructions5

20-31 — Intel reserved. Do not use.

32- 255 — User Defined (Non- reserved) Interrupts

Interrupt External interrupt or INT n instruction.

The processor’s local APIC is normally connected to a system-based I/O APIC. Here, external interrupts received at the I/O APIC’s pins can be directed to the local APIC through the system bus (Pentium 4, Intel Core Duo, Intel Core 2, Intel Atom, and Intel Xeon processors) or the APIC serial bus (P6 family and Pentium processors). The I/O APIC determines the vector number of the interrupt and sends this number to the local APIC. When a system contains multiple processors, processors can also send interrupts to one another by means of the system bus (Pentium 4, Intel Core Duo, Intel Core 2, Intel Atom, and Intel Xeon processors) or the APIC serial bus (P6 family and Pentium processors).

The LINT[1:0] pins are not available on the Intel486 processor and earlier Pentium processors that do not contain an on-chip local APIC. These processors have dedi cated NMI and INTR pins. With these processors, external interrupts are typically generated by a system-based interrupt controller (8259A), with the interrupts being signaled through the INTR pin.

Note that several other pins on the processor can cause a processor interrupt to occur. However, these interrupts are not handled by the interrupt and exception mechanism described in this chapter. These pins include the RESET#, FLUSH#, STPCLK#, SMI#, R/S#, and INIT# pins. Whether they are included on a particular processor is implementation dependent. Pin functions are described in the data books for the individual processors. The SMI# pin is described in Chapter 26, “System Management.”

6.3.2 Maskable Hardware Interrupts

Any external interrupt that is delivered to the processor by means of the INTR pin or through the local APIC is called a maskable hardware interrupt. Maskable hardware interrupts that can be delivered through the INTR pin include all IA-32 architecture

Page 219 of the Intel 253668-032US user manual — 6.4.1 Program-Error Exceptions
Page 219 · click to enlarge
Page 219

INTERRUPT AND EXCEPTION HANDLING

defined interrupt vectors from 0 through 255; those that can be delivered through the local APIC include interrupt vectors 16 through 255.

The IF flag in the EFLAGS register permits all maskable hardware interrupts to be masked as a group (see Section 6.8.1, “Masking Maskable Hardware Interrupts”). Note that when interrupts 0 through 15 are delivered through the local APIC, the APIC indicates the receipt of an illegal vector.

6.3.3 Software-Generated Interrupts

The INT n instruction permits interrupts to be generated from within software by supplying an interrupt vector number as an operand. For example, the INT 35 instruction forces an implicit call to the interrupt handler for interrupt 35.

Any of the interrupt vectors from 0 to 255 can be used as a parameter in this instruc tion. If the processor’s predefined NMI vector is used, however, the response of the processor will not be the same as it would be from an NMI interrupt generated in the normal manner. If vector number 2 (the NMI vector) is used in this instruction, the NMI interrupt handler is called, but the processor’s NMI-handling hardware is not activated.

Interrupts generated in software with the INT n instruction cannot be masked by the IF flag in the EFLAGS register.

6.4 SOURCES OF EXCEPTIONS

  • The processor receives exceptions from three sources:
  • Processor-detected program-error exceptions.
  • Software-generated exceptions.
  • Machine-check exceptions.

6.4.1 Program-Error Exceptions

The processor generates one or more exceptions when it detects program errors during the execution in an application program or the operating system or executive. Intel 64 and IA-32 architectures define a vector number for each processor-detect able exception. Exceptions are classified as faults, traps, and aborts (see Section 6.5, “Exception Classifications”).

Page 220 of the Intel 253668-032US user manual — 6.5 EXCEPTION CLASSIFICATIONS
Page 220 · click to enlarge
Page 220

INTERRUPT AND EXCEPTION HANDLING

6.4.2 Software-Generated Exceptions

The INTO, INT 3, and BOUND instructions permit exceptions to be generated in soft ware. These instructions allow checks for exception conditions to be performed at points in the instruction stream. For example, INT 3 causes a breakpoint exception to be generated.

The INT n instruction can be used to emulate exceptions in software; but there is a limitation. If INT n provides a vector for one of the architecturally-defined excep tions, the processor generates an interrupt to the correct vector (to access the exception handler) but does not push an error code on the stack. This is true even if the associated hardware-generated exception normally produces an error code. The exception handler will still attempt to pop an error code from the stack while handling the exception. Because no error code was pushed, the handler will pop off and discard the EIP instead (in place of the missing error code). This sends the return to the wrong location.

6.4.3 Machine-Check Exceptions

The P6 family and Pentium processors provide both internal and external machine- check mechanisms for checking the operation of the internal chip hardware and bus transactions. These mechanisms are implementation dependent. When a machine- check error is detected, the processor signals a machine-check exception (vector 18) and returns an error code.

See Chapter 6, “Interrupt 18—Machine-Check Exception (#MC)” and Chapter 15, “Machine-Check Architecture,” for more information about the machine-check mechanism.

6.5 EXCEPTION CLASSIFICATIONS

  • Exceptions are classified as faults , traps , or aborts depending on the way they are reported and whether the instruction that caused the exception can be restarted without loss of program or task continuity.
  • Faults — A fault is an exception that can generally be corrected and that, once corrected, allows the program to be restarted with no loss of continuity. When a fault is reported, the processor restores the machine state to the state prior to the beginning of execution of the faulting instruction. The return address (saved contents of the CS and EIP registers) for the fault handler points to the faulting instruction, rather than to the instruction following the faulting instruction.
  • Traps — A trap is an exception that is reported immediately following the execution of the trapping instruction. Traps allow execution of a program or task to be continued without loss of program continuity. The return address for the trap handler points to the instruction to be executed after the trapping instruction.
Page 221 of the Intel 253668-032US user manual — 6.6 PROGRAM OR TASK RESTART
Page 221 · click to enlarge
Page 221

INTERRUPT AND EXCEPTION HANDLING

  • Aborts — An abort is an exception that does not always report the precise location of the instruction causing the exception and does not allow a restart of the program or task that caused the exception. Aborts are used to report severe errors, such as hardware errors and inconsistent or illegal values in system tables.

NOTE

One exception subset normally reported as a fault is not restartable. Such exceptions result in loss of some processor state. For example, executing a POPAD instruction where the stack frame crosses over the end of the stack segment causes a fault to be reported. In this situation, the exception handler sees that the instruction pointer (CS:EIP) has been restored as if the POPAD instruction had not been executed. However, internal processor state (the general-purpose registers) will have been modified. Such cases are considered programming errors. An application causing this class of exceptions should be terminated by the operating system.

6.6 PROGRAM OR TASK RESTART

To allow the restarting of program or task following the handling of an exception or an interrupt, all exceptions (except aborts) are guaranteed to report exceptions on an instruction boundary. All interrupts are guaranteed to be taken on an instruction boundary.

For fault-class exceptions, the return instruction pointer (saved when the processor generates an exception) points to the faulting instruction. So, when a program or task is restarted following the handling of a fault, the faulting instruction is restarted (re- executed). Restarting the faulting instruction is commonly used to handle exceptions that are generated when access to an operand is blocked. The most common example of this type of fault is a page-fault exception (#PF) that occurs when a program or task references an operand located on a page that is not in memory. When a page- fault exception occurs, the exception handler can load the page into memory and resume execution of the program or task by restarting the faulting instruction. To insure that the restart is handled transparently to the currently executing program or task, the processor saves the necessary registers and stack pointers to allow a restart to the state prior to the execution of the faulting instruction.

For trap-class exceptions, the return instruction pointer points to the instruction following the trapping instruction. If a trap is detected during an instruction which transfers execution, the return instruction pointer reflects the transfer. For example, if a trap is detected while executing a JMP instruction, the return instruction pointer points to the destination of the JMP instruction, not to the next address past the JMP instruction. All trap exceptions allow program or task restart with no loss of conti nuity. For example, the overflow exception is a trap exception. Here, the return instruction pointer points to the instruction following the INTO instruction that tested

Page 222 of the Intel 253668-032US user manual — 6.7 NONMASKABLE INTERRUPT (NMI)
Page 222 · click to enlarge
Page 222

INTERRUPT AND EXCEPTION HANDLING

EFLAGS.OF (overflow) flag. The trap handler for this exception resolves the overflow condition. Upon return from the trap handler, program or task execution continues at the instruction following the INTO instruction.

The abort-class exceptions do not support reliable restarting of the program or task. Abort handlers are designed to collect diagnostic information about the state of the processor when the abort exception occurred and then shut down the application and system as gracefully as possible.

Interrupts rigorously support restarting of interrupted programs and tasks without loss of continuity. The return instruction pointer saved for an interrupt points to the next instruction to be executed at the instruction boundary where the processor took the interrupt. If the instruction just executed has a repeat prefix, the interrupt is taken at the end of the current iteration with the registers set to execute the next iteration.

The ability of a P6 family processor to speculatively execute instructions does not affect the taking of interrupts by the processor. Interrupts are taken at instruction boundaries located during the retirement phase of instruction execution; so they are always taken in the “in-order” instruction stream. See Chapter 2, “Intel® 64 and IA- 32 Architectures,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for more information about the P6 family processors’ microarchi tecture and its support for out-of-order instruction execution.

Note that the Pentium processor and earlier IA-32 processors also perform varying amounts of prefetching and preliminary decoding. With these processors as well, exceptions and interrupts are not signaled until actual “in-order” execution of the instructions. For a given code sample, the signaling of exceptions occurs uniformly when the code is executed on any family of IA-32 processors (except where new exceptions or new opcodes have been defined).

6.7 NONMASKABLE INTERRUPT (NMI)

  • The nonmaskable interrupt (NMI) can be generated in either of two ways:
  • External hardware asserts the NMI pin.
  • The processor receives a message on the system bus (Pentium 4, Intel Core Duo, Intel Core 2, Intel Atom, and Intel Xeon processors) or the APIC serial bus (P6 family and Pentium processors) with a delivery mode NMI.

When the processor receives a NMI from either of these sources, the processor handles it immediately by calling the NMI handler pointed to by interrupt vector number 2. The processor also invokes certain hardware conditions to insure that no other interrupts, including NMI interrupts, are received until the NMI handler has completed executing (see Section 6.7.1, “Handling Multiple NMIs”).

Also, when an NMI is received from either of the above sources, it cannot be masked by the IF flag in the EFLAGS register.

Page 223 of the Intel 253668-032US user manual — 6.8.1 Masking Maskable Hardware Interrupts
Page 223 · click to enlarge
Page 223

INTERRUPT AND EXCEPTION HANDLING

It is possible to issue a maskable hardware interrupt (through the INTR pin) to vector 2 to invoke the NMI interrupt handler; however, this interrupt will not truly be an NMI interrupt. A true NMI interrupt that activates the processor’s NMI-handling hardware can only be delivered through one of the mechanisms listed above.

6.7.1 Handling Multiple NMIs

While an NMI interrupt handler is executing, the processor disables additional calls to the NMI handler until the next IRET instruction is executed. This blocking of subse quent NMIs prevents stacking up calls to the NMI handler. It is recommended that the NMI interrupt handler be accessed through an interrupt gate to disable maskable hardware interrupts (see Section 6.8.1, “Masking Maskable Hardware Interrupts”). If the NMI handler is a virtual-8086 task with an IOPL of less than 3, an IRET instruction issued from the handler generates a general-protection exception (see Section 17.2.7, “Sensitive Instructions”). In this case, the NMI is unmasked before the general-protection exception handler is invoked.

6.8 ENABLING AND DISABLING INTERRUPTS

The processor inhibits the generation of some interrupts, depending on the state of the processor and of the IF and RF flags in the EFLAGS register, as described in the following sections.

6.8.1 Masking Maskable Hardware Interrupts

The IF flag can disable the servicing of maskable hardware interrupts received on the processor’s INTR pin or through the local APIC (see Section 6.3.2, “Maskable Hard ware Interrupts”). When the IF flag is clear, the processor inhibits interrupts deliv ered to the INTR pin or through the local APIC from generating an internal interrupt request; when the IF flag is set, interrupts delivered to the INTR or through the local APIC pin are processed as normal external interrupts.

The IF flag does not affect non-maskable interrupts (NMIs) delivered to the NMI pin or delivery mode NMI messages delivered through the local APIC, nor does it affect processor generated exceptions. As with the other flags in the EFLAGS register, the processor clears the IF flag in response to a hardware reset.

The fact that the group of maskable hardware interrupts includes the reserved inter rupt and exception vectors 0 through 32 can potentially cause confusion. Architectur ally, when the IF flag is set, an interrupt for any of the vectors from 0 through 32 can be delivered to the processor through the INTR pin and any of the vectors from 16 through 32 can be delivered through the local APIC. The processor will then generate an interrupt and call the interrupt or exception handler pointed to by the vector number. So for example, it is possible to invoke the page-fault handler through the INTR pin (by means of vector 14); however, this is not a true page-fault exception. It

Page 224 of the Intel 253668-032US user manual — 6.8.2 Masking Instruction Breakpoints
Page 224 · click to enlarge
Page 224

INTERRUPT AND EXCEPTION HANDLING

is an interrupt. As with the INT n instruction (see Section 6.4.2, “Software-Generated Exceptions”), when an interrupt is generated through the INTR pin to an exception vector, the processor does not push an error code on the stack, so the exception handler may not operate correctly.

The IF flag can be set or cleared with the STI (set interrupt-enable flag) and CLI (clear interrupt-enable flag) instructions, respectively. These instructions may be executed only if the CPL is equal to or less than the IOPL. A general-protection excep tion (#GP) is generated if they are executed when the CPL is greater than the IOPL. (The effect of the IOPL on these instructions is modified slightly when the virtual mode extension is enabled by setting the VME flag in control register CR4: see Section 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode.” Behavior is also impacted by the PVI flag: see Section 17.4, “Protected-Mode Virtual Interrupts.”

  • The IF flag is also affected by the following operations:
  • The PUSHF instruction stores all flags on the stack, where they can be examined and modified. The POPF instruction can be used to load the modified flags back into the EFLAGS register.
  • Task switches and the POPF and IRET instructions load the EFLAGS register; therefore, they can be used to modify the setting of the IF flag.
  • When an interrupt is handled through an interrupt gate, the IF flag is automati cally cleared, which disables maskable hardware interrupts. (If an interrupt is handled through a trap gate, the IF flag is not cleared.)

See the descriptions of the CLI, STI, PUSHF, POPF, and IRET instructions in Chapter 3, “Instruction Set Reference, A-M,” in the Intel® 64 and IA-32 Architectures Soft ware Developer’s Manual, Volume 2A, for a detailed description of the operations these instructions are allowed to perform on the IF flag.

6.8.2 Masking Instruction Breakpoints

The RF (resume) flag in the EFLAGS register controls the response of the processor to instruction-breakpoint conditions (see the description of the RF flag in Section 2.3, “System Flags and Fields in the EFLAGS Register”).

When set, it prevents an instruction breakpoint from generating a debug exception (#DB); when clear, instruction breakpoints will generate debug exceptions. The primary function of the RF flag is to prevent the processor from going into a debug exception loop on an instruction-breakpoint. See Section 16.3.1.1, “Instruction- Breakpoint Exception Condition,” for more information on the use of this flag.

Page 225 of the Intel 253668-032US user manual — - FLUSH
Page 225 · click to enlarge
Page 225

INTERRUPT AND EXCEPTION HANDLING

6.8.3 Masking Exceptions and Interrupts When Switching Stacks

To switch to a different stack segment, software often uses a pair of instructions, for example:

MOV SS, AX MOV ESP, StackTop

If an interrupt or exception occurs after the segment selector has been loaded into the SS register but before the ESP register has been loaded, these two parts of the logical address into the stack space are inconsistent for the duration of the interrupt or exception handler.

To prevent this situation, the processor inhibits interrupts, debug exceptions, and single-step trap exceptions after either a MOV to SS instruction or a POP to SS instruction, until the instruction boundary following the next instruction is reached. All other faults may still be generated. If the LSS instruction is used to modify the contents of the SS register (which is the recommended method of modifying this register), this problem does not occur.

6.9 PRIORITY AMONG SIMULTANEOUS EXCEPTIONS AND INTERRUPTS

If more than one exception or interrupt is pending at an instruction boundary, the processor services them in a predictable order. Table 6-2 shows the priority among classes of exception and interrupt sources.

Table 6-2. Priority Among Simultaneous Exceptions and Interrupts

1 (Highest) Hardware Reset and Machine Checks

- RESET

2 Trap on Task Switch

- T flag in TSS is set

3 External Hardware Interventions

- FLUSH

- STOPCLK

- SMI

- INIT

4 Traps on the Previous Instruction

- Debug Trap Exceptions (TF flag set or data/I-O breakpoint)

Priority Description · - Machine Check · - Breakpoints

Page 226 of the Intel 253668-032US user manual — 6.10 INTERRUPT DESCRIPTOR TABLE (IDT)
Page 226 · click to enlarge
Page 226

INTERRUPT AND EXCEPTION HANDLING

Table 6-2. Priority Among Simultaneous Exceptions and Interrupts (Contd.)

5 Nonmaskable Interrupts (NMI) 1

6 Maskable Hardware Interrupts 1

7 Code Breakpoint Fault

8 Faults from Fetching Next Instruction

- Code-Segment Limit Violation

- Code Page Fault

9 Faults from Decoding the Next Instruction

- Instruction length > 15 bytes

- Coprocessor Not Available

10 (Lowest) Faults on Executing an Instruction

- Segment Not Present

- Data Page Fault

- x87 FPU Floating-point exception

- SIMD floating-point exception

NOTE:

1. The Intel486 ™ processor and earlier processors group nonmaskable and maskable interrupts in the same priority class.

While priority among these classes listed in Table 6-2 is consistent throughout the architecture, exceptions within each class are implementation-dependent and may vary from processor to processor. The processor first services a pending exception or interrupt from the class which has the highest priority, transferring execution to the first instruction of the handler. Lower priority exceptions are discarded; lower priority interrupts are held pending. Discarded exceptions are re-generated when the inter rupt handler returns execution to the point in the program or task where the excep tions and/or interrupts occurred.

6.10 INTERRUPT DESCRIPTOR TABLE (IDT)

The interrupt descriptor table (IDT) associates each exception or interrupt vector with a gate descriptor for the procedure or task used to service the associated excep tion or interrupt. Like the GDT and LDTs, the IDT is an array of 8-byte descriptors (in

Show 7 more labels / short text on this page
- Invalid Opcode · - Overflow · - Bound error · - Invalid TSS · - Stack fault · - General Protection · - Alignment Check
Page 227 of the Intel 253668-032US user manual — NOTE
Page 227 · click to enlarge
Page 227

INTERRUPT AND EXCEPTION HANDLING

protected mode). Unlike the GDT, the first entry of the IDT may contain a descriptor. To form an index into the IDT, the processor scales the exception or interrupt vector by eight (the number of bytes in a gate descriptor). Because there are only 256 inter rupt or exception vectors, the IDT need not contain more than 256 descriptors. It can contain fewer than 256 descriptors, because descriptors are required only for the interrupt and exception vectors that may occur. All empty descriptor slots in the IDT should have the present flag for the descriptor set to 0.

The base addresses of the IDT should be aligned on an 8-byte boundary to maximize performance of cache line fills. The limit value is expressed in bytes and is added to the base address to get the address of the last valid byte. A limit value of 0 results in exactly 1 valid byte. Because IDT entries are always eight bytes long, the limit should always be one less than an integral multiple of eight (that is, 8N – 1).

The IDT may reside anywhere in the linear address space. As shown in Figure 6-1, the processor locates the IDT using the IDTR register. This register holds both a 32-bit base address and 16-bit limit for the IDT.

The LIDT (load IDT register) and SIDT (store IDT register) instructions load and store the contents of the IDTR register, respectively. The LIDT instruction loads the IDTR register with the base address and limit held in a memory operand. This instruction can be executed only when the CPL is 0. It normally is used by the initialization code of an operating system when creating an IDT. An operating system also may use it to change from one IDT to another. The SIDT instruction copies the base and limit value stored in IDTR to memory. This instruction can be executed at any privilege level.

If a vector references a descriptor beyond the limit of the IDT, a general-protection exception (#GP) is generated.

NOTE

Because interrupts are delivered to the processor core only once, an incorrectly configured IDT could result in incomplete interrupt handling and/or the blocking of interrupt delivery.

IA-32 architecture rules need to be followed for setting up IDTR base/limit/access fields and each field in the gate descriptors. The same apply for the Intel 64 architecture. This includes implicit referencing of the destination code segment through the GDT or LDT and accessing the stack.

Page 228 of the Intel 253668-032US user manual — 6.11 IDT DESCRIPTORS
Page 228 · click to enlarge
Page 228

INTERRUPT AND EXCEPTION HANDLING

IDT Limit IDT Base Address

Interrupt Descriptor Table (IDT)

+

(n−1)∗8

Gate for Interrupt #3

Gate for Interrupt #2

Gate for Interrupt #1

Figure 6-1. Relationship of the IDTR and IDT

6.11 IDT DESCRIPTORS

  • The IDT may contain any of three kinds of gate descriptors:
  • Task-gate descriptor
  • Interrupt-gate descriptor
  • Trap-gate descriptor

Figure 6-2 shows the formats for the task-gate, interrupt-gate, and trap-gate descriptors. The format of a task gate used in an IDT is the same as that of a task gate used in the GDT or an LDT (see Section 7.2.5, “Task-Gate Descriptor”). The task gate contains the segment selector for a TSS for an exception and/or interrupt handler task.

Interrupt and trap gates are very similar to call gates (see Section 5.8.3, “Call Gates”). They contain a far pointer (segment selector and offset) that the processor uses to transfer program execution to a handler procedure in an exception- or inter rupt-handler code segment. These gates differ in the way the processor handles the IF flag in the EFLAGS register (see Section 6.12.1.2, “Flag Usage By Exception- or Interrupt-Handler Procedure”).

Show 4 more labels / short text on this page
0 IDTR Register · 15 16 47 · Gate for · Interrupt #n
Page 229 of the Intel 253668-032US user manual — 6.12 EXCEPTION AND INTERRUPT HANDLING
Page 229 · click to enlarge
Page 229

INTERRUPT AND EXCEPTION HANDLING

31 16 15 13 14 12 8 7 0

D P L

P

1 0 1 0

31 16 15 0

TSS Segment Selector 0

31 16 15 13 14 12 8 7 0

D P L

P Offset 31..16

0 1 1 D

31 16 15 0

Segment Selector Offset 15..0 0

31 16 15 13 14 12 8 7 0

D P L

P Offset 31..16

1 1 1 D

31 16 15 0

Segment Selector Offset 15..0 0

DPL Offset P Selector

Descriptor Privilege Level Offset to procedure entry point Segment Present flag Segment Selector for destination code segment

Size of gate1 = 32 bits; 0 = 16 bits D

Figure 6-2. IDT Gate Descriptors

6.12 EXCEPTION AND INTERRUPT HANDLING

The processor handles calls to exception- and interrupt-handlers similar to the way it handles calls with a CALL instruction to a procedure or a task. When responding to an exception or interrupt, the processor uses the exception or interrupt vector as an index to a descriptor in the IDT. If the index points to an interrupt gate or trap gate, the processor calls the exception or interrupt handler in a manner similar to a CALL to a call gate (see Section 5.8.2, “Gate Descriptors,” through Section 5.8.6,

Show 4 more labels / short text on this page
Task Gate · Interrupt Gate · Trap Gate · Reserved
Page 230 of the Intel 253668-032US user manual — IDT
Page 230 · click to enlarge
Page 230

INTERRUPT AND EXCEPTION HANDLING

“Returning from a Called Procedure”). If index points to a task gate, the processor executes a task switch to the exception- or interrupt-handler task in a manner similar to a CALL to a task gate (see Section 7.3, “Task Switching”).

6.12.1 Exceptionor Interrupt-Handler Procedures

An interrupt gate or trap gate references an exception- or interrupt-handler proce dure that runs in the context of the currently executing task (see Figure 6-3). The segment selector for the gate points to a segment descriptor for an executable code segment in either the GDT or the current LDT. The offset field of the gate descriptor points to the beginning of the exception- or interrupt-handling procedure.

IDT

Interrupt +

Figure 6-3. Interrupt Procedure Call

Show 13 more labels / short text on this page
Destination · Code Segment · Offset · Procedure · Interrupt · Interrupt or · Vector · Trap Gate · Segment Selector · GDT or LDT · Base Address · Segment · Descriptor
Page 231 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 231 · click to enlarge
Page 231

INTERRUPT AND EXCEPTION HANDLING

When the processor performs a call to the exception- or interrupt-handler procedure: • If the handler procedure is going to be executed at a numerically lower privilege level, a stack switch occurs. When the stack switch occurs:

a. The segment selector and stack pointer for the stack to be used by the handler are obtained from the TSS for the currently executing task. On this new stack, the processor pushes the stack segment selector and stack pointer of the interrupted procedure.

b. The processor then saves the current state of the EFLAGS, CS, and EIP registers on the new stack (see Figures 6-4).

c. If an exception causes an error code to be saved, it is pushed on the new stack after the EIP value. • If the handler procedure is going to be executed at the same privilege level as the interrupted procedure:

a. The processor saves the current state of the EFLAGS, CS, and EIP registers on the current stack (see Figures 6-4).

b. If an exception causes an error code to be saved, it is pushed on the current stack after the EIP value.

Page 232 of the Intel 253668-032US user manual — SS ESP
Page 232 · click to enlarge
Page 232

INTERRUPT AND EXCEPTION HANDLING

Stack Usage with No Privilege-Level Change

EFLAGS

CS EIP

ESP After Transfer to Handler

Stack Usage with Privilege-Level Change

ESP Before Transfer to Handler

SS ESP

EFLAGS

CS

EIP

ESP After Transfer to Handler

Figure 6-4. Stack Usage on Transfers to Interrupt and Exception-Handling Routines

To return from an exception- or interrupt-handler procedure, the handler must use the IRET (or IRETD) instruction. The IRET instruction is similar to the RET instruction except that it restores the saved flags into the EFLAGS register. The IOPL field of the EFLAGS register is restored only if the CPL is 0. The IF flag is changed only if the CPL is less than or equal to the IOPL. See Chapter 3, “Instruction Set Reference, A-M,” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A, for a description of the complete operation performed by the IRET instruction.

If a stack switch occurred when calling the handler procedure, the IRET instruction switches back to the interrupted procedure’s stack on the return.

6.12.1.1 Protection of Exception- and Interrupt-Handler Procedures

The privilege-level protection for exception- and interrupt-handler procedures is similar to that used for ordinary procedure calls when called through a call gate (see Section 5.8.4, “Accessing a Code Segment Through a Call Gate”). The processor does

Show 9 more labels / short text on this page
Interrupted Procedure’s · and Handler’s Stack · ESP Before · Transfer to Handler · Error Code · Interrupted Procedure’s · Handler’s Stack · Stack · Error Code
Page 233 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 233 · click to enlarge
Page 233

INTERRUPT AND EXCEPTION HANDLING

not permit transfer of execution to an exception- or interrupt-handler procedure in a less privileged code segment (numerically greater privilege level) than the CPL.

  • An attempt to violate this rule results in a general-protection exception (#GP). The protection mechanism for exceptionand interrupt-handler procedures is different in the following ways:
  • Because interrupt and exception vectors have no RPL, the RPL is not checked on implicit calls to exception and interrupt handlers.
  • The processor checks the DPL of the interrupt or trap gate only if an exception or interrupt is generated with an INT n , INT 3, or INTO instruction. Here, the CPL must be less than or equal to the DPL of the gate. This restriction prevents application programs or procedures running at privilege level 3 from using a software interrupt to access critical exception handlers, such as the page-fault handler, providing that those handlers are placed in more privileged code segments (numerically lower privilege level). For hardware-generated interrupts and processor-detected exceptions, the processor ignores the DPL of interrupt and trap gates.
  • Because exceptions and interrupts generally do not occur at predictable times, these privilege rules effectively impose restrictions on the privilege levels at which excep tion and interrupthandling procedures can run. Either of the following techniques can be used to avoid privilege-level violations.
  • The exception or interrupt handler can be placed in a conforming code segment. This technique can be used for handlers that only need to access data available on the stack (for example, divide error exceptions). If the handler needs data from a data segment, the data segment needs to be accessible from privilege level 3, which would make it unprotected.
  • The handler can be placed in a nonconforming code segment with privilege level 0. This handler would always run, regardless of the CPL that the interrupted program or task is running at.

6.12.1.2 Flag Usage By Exception- or Interrupt-Handler Procedure

When accessing an exception or interrupt handler through either an interrupt gate or a trap gate, the processor clears the TF flag in the EFLAGS register after it saves the contents of the EFLAGS register on the stack. (On calls to exception and interrupt handlers, the processor also clears the VM, RF, and NT flags in the EFLAGS register, after they are saved on the stack.) Clearing the TF flag prevents instruction tracing from affecting interrupt response. A subsequent IRET instruction restores the TF (and VM, RF, and NT) flags to the values in the saved contents of the EFLAGS register on the stack.

The only difference between an interrupt gate and a trap gate is the way the processor handles the IF flag in the EFLAGS register. When accessing an exception- or interrupt-handling procedure through an interrupt gate, the processor clears the IF flag to prevent other interrupts from interfering with the current interrupt handler. A subsequent IRET instruction restores the IF flag to its value in the saved contents

Page 234 of the Intel 253668-032US user manual — NOTE
Page 234 · click to enlarge
Page 234

INTERRUPT AND EXCEPTION HANDLING

of the EFLAGS register on the stack. Accessing a handler procedure through a trap gate does not affect the IF flag.

6.12.2 Interrupt Tasks

  • When an exception or interrupt handler is accessed through a task gate in the IDT, a task switch results. Handling an exception or interrupt with a separate task offers several advantages:
  • The entire context of the interrupted program or task is saved automatically.
  • A new TSS permits the handler to use a new privilege level 0 stack when handling the exception or interrupt. If an exception or interrupt occurs when the current privilege level 0 stack is corrupted, accessing the handler through a task gate can prevent a system crash by providing the handler with a new privilege level 0 stack.
  • The handler can be further isolated from other tasks by giving it a separate address space. This is done by giving it a separate LDT.

The disadvantage of handling an interrupt with a separate task is that the amount of machine state that must be saved on a task switch makes it slower than using an interrupt gate, resulting in increased interrupt latency.

A task gate in the IDT references a TSS descriptor in the GDT (see Figure 6-5). A switch to the handler task is handled in the same manner as an ordinary task switch (see Section 7.3, “Task Switching”). The link back to the interrupted task is stored in the previous task link field of the handler task’s TSS. If an exception caused an error code to be generated, this error code is copied to the stack of the new task.

When exception- or interrupt-handler tasks are used in an operating system, there are actually two mechanisms that can be used to dispatch tasks: the software sched uler (part of the operating system) and the hardware scheduler (part of the processor's interrupt mechanism). The software scheduler needs to accommodate interrupt tasks that may be dispatched when interrupts are enabled.

NOTE

Because IA-32 architecture tasks are not re-entrant, an interrupt- handler task must disable interrupts between the time it completes handling the interrupt and the time it executes the IRET instruction. This action prevents another interrupt from occurring while the interrupt task’s TSS is still marked busy, which would cause a general-protection (#GP) exception.

Page 235 of the Intel 253668-032US user manual — 6.13 ERROR CODE
Page 235 · click to enlarge
Page 235

INTERRUPT AND EXCEPTION HANDLING

IDT

GDT

Figure 6-5. Interrupt Task Switch

6.13 ERROR CODE

When an exception condition is related to a specific segment, the processor pushes an error code onto the stack of the exception handler (whether it is a procedure or task). The error code has the format shown in Figure 6-6. The error code resembles a segment selector; however, instead of a TI flag and RPL field, the error code contains 3 flags:

EXT External event (bit 0) — When set, indicates that an event external to the program, such as a hardware interrupt, caused the exception.

IDT Descriptor location (bit 1) — When set, indicates that the index portion of the error code refers to a gate descriptor in the IDT; when

Show 8 more labels / short text on this page
TSS for Interrupt- · Handling Task · Interrupt · Vector · Task Gate · TSS Base Address · TSS Selector · TSS Descriptor
Page 236 of the Intel 253668-032US user manual — 6.14 EXCEPTION AND INTERRUPT HANDLING IN 64-BIT MODE
Page 236 · click to enlarge
Page 236

INTERRUPT AND EXCEPTION HANDLING

clear, indicates that the index refers to a descriptor in the GDT or the current LDT.

TI GDT/LDT (bit 2) — Only used when the IDT flag is clear. When set, the TI flag indicates that the index portion of the error code refers to a segment or gate descriptor in the LDT; when clear, it indicates that the index refers to a descriptor in the current GDT.

I D T T

E X T

Figure 6-6. Error Code

The segment selector index field provides an index into the IDT, GDT, or current LDT to the segment or gate selector being referenced by the error code. In some cases the error code is null (that is, all bits in the lower word are clear). A null error code indicates that the error was not caused by a reference to a specific segment or that a null segment descriptor was referenced in an operation.

The format of the error code is different for page-fault exceptions (#PF). See the “Interrupt 14—Page-Fault Exception (#PF)” section in this chapter.

The error code is pushed on the stack as a doubleword or word (depending on the default interrupt, trap, or task gate size). To keep the stack aligned for doubleword pushes, the upper half of the error code is reserved. Note that the error code is not popped when the IRET instruction is executed to return from an exception handler, so the handler must remove the error code before executing a return.

Error codes are not pushed on the stack for exceptions that are generated externally (with the INTR or LINT[1:0] pins) or the INT n instruction, even if an error code is normally produced for those exceptions.

6.14 EXCEPTION AND INTERRUPT HANDLING IN 64-BIT MODE

  • In 64-bit mode, interrupt and exception handling is similar to what has been described for non-64-bit modes. The following are the exceptions:
  • All interrupt handlers pointed by the IDT are in 64-bit code (this does not apply to the SMI handler).
  • The size of interrupt-stack pushes is fixed at 64 bits; and the processor uses 8-byte, zero extended stores.

Reserved · Segment Selector Index

Page 237 of the Intel 253668-032US user manual — TYPE
Page 237 · click to enlarge
Page 237

INTERRUPT AND EXCEPTION HANDLING

  • The stack pointer (SS:RSP) is pushed unconditionally on interrupts. In legacy modes, this push is conditional and based on a change in current privilege level (CPL).
  • The new SS is set to NULL if there is a change in CPL.
  • IRET behavior changes.
  • There is a new interrupt stack-switch mechanism.
  • The alignment of interrupt stack frame is different.

6.14.1 64-Bit Mode IDT

Interrupt and trap gates are 16 bytes in length to provide a 64-bit offset for the instruction pointer (RIP). The 64-bit RIP referenced by interrupt-gate descriptors allows an interrupt service routine to be located anywhere in the linear-address space. See Figure 6-7.

Offset 63..32 8

31 16 15 13 14 12 8 7 0

D P L

P Offset 31..16

TYPE

IST 0 0

31 16 15 0

Segment Selector Offset 15..0 0

DPL Offset P Selector

Descriptor Privilege Level Offset to procedure entry point Segment Present flag Segment Selector for destination code segment

IST Interrupt Stack Table

Figure 6-7. 64-Bit IDT Gate Descriptors

In 64-bit mode, the IDT index is formed by scaling the interrupt vector by 16. The first eight bytes (bytes 7:0) of a 64-bit mode interrupt gate are similar but not iden tical to legacy 32-bit interrupt gates. The type field (bits 11:8 in bytes 7:4) is described in Table 3-2. The Interrupt Stack Table (IST) field (bits 4:0 in bytes 7:4) is used by the stack switching mechanisms described in Section 6.14.5, “Interrupt Stack Table.” Bytes 11:8 hold the upper 32 bits of the target RIP (interrupt segment offset) in canonical form. A general-protection exception (#GP) is generated if soft

Interrupt/Trap Gate · Reserved

Page 238 of the Intel 253668-032US user manual — 6.14.2 64-Bit Mode Stack Frame
Page 238 · click to enlarge
Page 238

INTERRUPT AND EXCEPTION HANDLING

ware attempts to reference an interrupt gate with a target RIP that is not in canonical form.

The target code segment referenced by the interrupt gate must be a 64-bit code segment (CS.L = 1, CS.D = 0). If the target is not a 64-bit code segment, a general- protection exception (#GP) is generated with the IDT vector number reported as the error code.

Only 64-bit interrupt and trap gates can be referenced in IA-32e mode (64-bit mode and compatibility mode). Legacy 32-bit interrupt or trap gate types (0EH or 0FH) are redefined in IA-32e mode as 64-bit interrupt and trap gate types. No 32-bit interrupt or trap gate type exists in IA-32e mode. If a reference is made to a 16-bit interrupt or trap gate (06H or 07H), a general-protection exception (#GP(0)) is generated.

6.14.2 64-Bit Mode Stack Frame

In legacy mode, the size of an IDT entry (16 bits or 32 bits) determines the size of interrupt-stack-frame pushes. SS:ESP is pushed only on a CPL change. In 64-bit mode, the size of interrupt stack-frame pushes is fixed at eight bytes. This is because only 64-bit mode gates can be referenced. 64-bit mode also pushes SS:RSP uncon ditionally, rather than only on a CPL change.

Aside from error codes, pushing SS:RSP unconditionally presents operating systems with a consistent interrupt-stackframe size across all interrupts. Interrupt service- routine entry points that handle interrupts generated by the INTn instruction or external INTR# signal can push an additional error code place-holder to maintain consistency.

In legacy mode, the stack pointer may be at any alignment when an interrupt or exception causes a stack frame to be pushed. This causes the stack frame and succeeding pushes done by an interrupt handler to be at arbitrary alignments. In IA-32e mode, the RSP is aligned to a 16-byte boundary before pushing the stack frame. The stack frame itself is aligned on a 16-byte boundary when the interrupt handler is called. The processor can arbitrarily realign the new RSP on interrupts because the previous (possibly unaligned) RSP is unconditionally saved on the newly aligned stack. The previous RSP will be automatically restored by a subsequent IRET.

Aligning the stack permits exception and interrupt frames to be aligned on a 16-byte boundary before interrupts are re-enabled. This allows the stack to be formatted for optimal storage of 16-byte XMM registers, which enables the interrupt handler to use faster 16-byte aligned loads and stores (MOVAPS rather than MOVUPS) to save and restore XMM registers.

Although the RSP alignment is always performed when LMA = 1, it is only of conse quence for the kernel-mode case where there is no stack switch or IST used. For a stack switch or IST, the OS would have presumably put suitably aligned RSP values in the TSS.

Page 239 of the Intel 253668-032US user manual — 6.14.4 Stack Switching in IA-32e Mode
Page 239 · click to enlarge
Page 239

INTERRUPT AND EXCEPTION HANDLING

6.14.3 IRET in IA-32e Mode

In IA-32e mode, IRET executes with an 8-byte operand size. There is nothing that forces this requirement. The stack is formatted in such a way that for actions where IRET is required, the 8-byte IRET operand size works correctly.

Because interrupt stack-frame pushes are always eight bytes in IA-32e mode, an IRET must pop eight byte items off the stack. This is accomplished by preceding the IRET with a 64-bit operand-size prefix. The size of the pop is determined by the address size of the instruction. The SS/ESP/RSP size adjustment is determined by the stack size.

IRET pops SS:RSP unconditionally off the interrupt stack frame only when it is executed in 64-bit mode. In compatibility mode, IRET pops SS:RSP off the stack only if there is a CPL change. This allows legacy applications to execute properly in compatibility mode when using the IRET instruction. 64-bit interrupt service routines that exit with an IRET unconditionally pop SS:RSP off of the interrupt stack frame, even if the target code segment is running in 64-bit mode or at CPL = 0. This is because the original interrupt always pushes SS:RSP.

In IA-32e mode, IRET is allowed to load a NULL SS under certain conditions. If the target mode is 64-bit mode and the target CPL 3, IRET allows SS to be loaded with a NULL selector. As part of the stack switch mechanism, an interrupt or excep tion sets the new SS to NULL, instead of fetching a new SS selector from the TSS and loading the corresponding descriptor from the GDT or LDT. The new SS selector is set to NULL in order to properly handle returns from subsequent nested far transfers. If the called procedure itself is interrupted, the NULL SS is pushed on the stack frame. On the subsequent IRET, the NULL SS on the stack acts as a flag to tell the processor not to load a new SS descriptor.

6.14.4 Stack Switching in IA-32e Mode

The IA-32 architecture provides a mechanism to automatically switch stack frames in response to an interrupt. The 64-bit extensions of Intel 64 architecture implement a modified version of the legacy stack-switching mechanism and an alternative stack- switching mechanism called the interrupt stack table (IST).

In IA-32 modes, the legacy IA-32 stack-switch mechanism is unchanged. In IA-32e mode, the legacy stack-switch mechanism is modified. When stacks are switched as part of a 64-bit mode privilege-level change (resulting from an interrupt), a new SS descriptor is not loaded. IA-32e mode loads only an inner-level RSP from the TSS. The new SS selector is forced to NULL and the SS selector’s RPL field is set to the new CPL. The new SS is set to NULL in order to handle nested far transfers (CALLF, INT, interrupts and exceptions). The old SS and RSP are saved on the new stack (Figure 6-8). On the subsequent IRET, the old SS is popped from the stack and loaded into the SS register.

Page 240 of the Intel 253668-032US user manual — 6.14.5 Interrupt Stack Table
Page 240 · click to enlarge
Page 240

INTERRUPT AND EXCEPTION HANDLING

In summary, a stack switch in IA-32e mode works like the legacy stack switch, except that a new SS selector is not loaded from the TSS. Instead, the new SS is forced to NULL.

Stack Usage with Privilege-Level Change

Legacy Mode IA-32e Mode

0 +4 +8 +12 +16 +20

SS ESP

SS RSP

0 +8 +16 +24 +32 +40

EFLAGS

RFLAGS

CS

CS

EIP

RIP

Stack Pointer After Transfer to Handler

Figure 6-8. IA-32e Mode Stack Usage After Privilege Level Change

6.14.5 Interrupt Stack Table

In IA-32e mode, a new interrupt stack table (IST) mechanism is available as an alter native to the modified legacy stack-switching mechanism described above. This mechanism unconditionally switches stacks when it is enabled. It can be enabled on an individual interrupt-vector basis using a field in the IDT entry. This means that some interrupt vectors can use the modified legacy mechanism and others can use the IST mechanism.

The IST mechanism is only available in IA-32e mode. It is part of the 64-bit mode TSS. The motivation for the IST mechanism is to provide a method for specific inter rupts (such as NMI, double-fault, and machine-check) to always execute on a known good stack. In legacy mode, interrupts can use the task-switch mechanism to set up a known-good stack by accessing the interrupt service routine through a task gate located in the IDT. However, the legacy task-switch mechanism is not supported in IA-32e mode.

The IST mechanism provides up to seven IST pointers in the TSS. The pointers are referenced by an interrupt-gate descriptor in the interrupt-descriptor table (IDT); see Figure 6-7. The gate descriptor contains a 3-bit IST index field that provides an offset into the IST section of the TSS. Using the IST mechanism, the processor loads the value pointed by an IST pointer into the RSP.

When an interrupt occurs, the new SS selector is forced to NULL and the SS selector’s RPL field is set to the new CPL. The old SS, RSP, RFLAGS, CS, and RIP are pushed onto the new stack. Interrupt processing then proceeds as normal. If the IST index is zero, the modified legacy stack-switching mechanism described above is used.

Show 4 more labels / short text on this page
Handler’s Stack · Handler’s Stack · Error Code · Error Code
Page 241 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 241 · click to enlarge
Page 241

INTERRUPT AND EXCEPTION HANDLING

6.15 EXCEPTION AND INTERRUPT REFERENCE

  • The following sections describe conditions which generate exceptions and interrupts. They are arranged in the order of vector numbers. The information contained in these sections are as follows:
  • Exception Class — Indicates whether the exception class is a fault, trap, or abort type. Some exceptions can be either a fault or trap type, depending on when the error condition is detected. (This section is not applicable to interrupts.)
  • Description — Gives a general description of the purpose of the exception or interrupt type. It also describes how the processor handles the exception or interrupt.
  • Exception Error Code — Indicates whether an error code is saved for the exception. If one is saved, the contents of the error code are described. (This section is not applicable to interrupts.)
  • Saved Instruction Pointer — Describes which instruction the saved (or return) instruction pointer points to. It also indicates whether the pointer can be used to restart a faulting instruction.
  • Program State Change — Describes the effects of the exception or interrupt on the state of the currently running program or task and the possibilities of restarting the program or task without loss of continuity.
Page 242 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 242 · click to enlarge
Page 242

INTERRUPT AND EXCEPTION HANDLING

Interrupt 0—Divide Error Exception (#DE)

Exception Class Fault.

Indicates the divisor operand for a DIV or IDIV instruction is 0 or that the result cannot be represented in the number of bits specified for the destination operand.

None.

Saved contents of CS and EIP registers point to the instruction that generated the exception.

A program-state change does not accompany the divide error, because the exception occurs before the faulting instruction is executed.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 243 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 243 · click to enlarge
Page 243

INTERRUPT AND EXCEPTION HANDLING

Interrupt 1—Debug Exception (#DB)

Exception Class Trap or Fault. The exception handler can distinguish between traps or faults by examining the contents of DR6 and the other debug registers.

Indicates that one or more of several debug-exception conditions has been detected. Whether the exception is a fault or a trap depends on the condition (see Table 6-3). See Chapter 16, “Debugging, Profiling Branches and Time-Stamp Counter,” for detailed information about the debug exceptions.

Table 6-3. Debug Exception Conditions and Corresponding Exception Classes

Exception Condition Exception Class

Instruction fetch breakpoint Fault

Data read or write breakpoint Trap

I/O read or write breakpoint Trap

General detect condition (in conjunction with in-circuit emulation) Fault

None. An exception handler can examine the debug registers to determine which condition caused the exception.

Fault — Saved contents of CS and EIP registers point to the instruction that gener ated the exception.

Trap — Saved contents of CS and EIP registers point to the instruction following the instruction that generated the exception.

Fault — A program-state change does not accompany the debug exception, because the exception occurs before the faulting instruction is executed. The program can resume normal execution upon returning from the debug exception handler.

Trap — A program-state change does accompany the debug exception, because the instruction or task switch being executed is allowed to complete before the exception is generated. However, the new state of the program is not corrupted and execution of the program can continue reliably.

Show 6 more labels / short text on this page
Description · Single-step Trap · Task-switch Trap · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 244 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 244 · click to enlarge
Page 244

INTERRUPT AND EXCEPTION HANDLING

Interrupt 2—NMI Interrupt

Exception Class Not applicable.

The nonmaskable interrupt (NMI) is generated externally by asserting the processor’s NMI pin or through an NMI request set by the I/O APIC to the local APIC. This interrupt causes the NMI interrupt handler to be called.

Not applicable.

The processor always takes an NMI interrupt on an instruction boundary. The saved contents of CS and EIP registers point to the next instruction to be executed at the point the interrupt is taken. See Section 6.5, “Exception Classifications,” for more information about when the processor takes NMI interrupts.

The instruction executing when an NMI interrupt is received is completed before the NMI is generated. A program or task can thus be restarted upon returning from an interrupt handler without loss of continuity, provided the interrupt handler saves the state of the processor before handling the interrupt and restores the processor’s state prior to a return.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 245 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 245 · click to enlarge
Page 245

INTERRUPT AND EXCEPTION HANDLING

Interrupt 3—Breakpoint Exception (#BP)

Exception Class Trap.

Indicates that a breakpoint instruction (INT 3) was executed, causing a breakpoint trap to be generated. Typically, a debugger sets a breakpoint by replacing the first opcode byte of an instruction with the opcode for the INT 3 instruction. (The INT 3 instruction is one byte long, which makes it easy to replace an opcode in a code segment in RAM with the breakpoint opcode.) The operating system or a debugging tool can use a data segment mapped to the same physical address space as the code segment to place an INT 3 instruction in places where it is desired to call the debugger.

With the P6 family, Pentium, Intel486, and Intel386 processors, it is more convenient to set breakpoints with the debug registers. (See Section 16.3.2, “Breakpoint Excep tion (#BP)—Interrupt Vector 3,” for information about the breakpoint exception.) If more breakpoints are needed beyond what the debug registers allow, the INT 3 instruction can be used.

The breakpoint (#BP) exception can also be generated by executing the INT n instruction with an operand of 3. The action of this instruction (INT 3) is slightly different than that of the INT 3 instruction (see “INTn/INTO/INT3—Call to Interrupt Procedure” in Chapter 3 of the Intel® 64 and IA-32 Architectures Software Devel oper’s Manual, Volume 2A).

None.

Saved contents of CS and EIP registers point to the instruction following the INT 3 instruction.

Even though the EIP points to the instruction following the breakpoint instruction, the state of the program is essentially unchanged because the INT 3 instruction does not affect any register or memory locations. The debugger can thus resume the suspended program by replacing the INT 3 instruction that caused the breakpoint with the original opcode and decrementing the saved contents of the EIP register. Upon returning from the debugger, program execution resumes with the replaced instruction.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 246 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 246 · click to enlarge
Page 246

INTERRUPT AND EXCEPTION HANDLING

Interrupt 4—Overflow Exception (#OF)

Exception Class Trap.

Indicates that an overflow trap occurred when an INTO instruction was executed. The INTO instruction checks the state of the OF flag in the EFLAGS register. If the OF flag is set, an overflow trap is generated.

Some arithmetic instructions (such as the ADD and SUB) perform both signed and unsigned arithmetic. These instructions set the OF and CF flags in the EFLAGS register to indicate signed overflow and unsigned overflow, respectively. When performing arithmetic on signed operands, the OF flag can be tested directly or the INTO instruction can be used. The benefit of using the INTO instruction is that if the overflow exception is detected, an exception handler can be called automatically to handle the overflow condition.

None.

The saved contents of CS and EIP registers point to the instruction following the INTO instruction.

Even though the EIP points to the instruction following the INTO instruction, the state of the program is essentially unchanged because the INTO instruction does not affect any register or memory locations. The program can thus resume normal execution upon returning from the overflow exception handler.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 247 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 247 · click to enlarge
Page 247

INTERRUPT AND EXCEPTION HANDLING

Interrupt 5—BOUND Range Exceeded Exception (#BR)

Exception Class Fault.

Indicates that a BOUND-range-exceeded fault occurred when a BOUND instruction was executed. The BOUND instruction checks that a signed array index is within the upper and lower bounds of an array located in memory. If the array index is not within the bounds of the array, a BOUND-range-exceeded fault is generated.

None.

The saved contents of CS and EIP registers point to the BOUND instruction that generated the exception.

A program-state change does not accompany the bounds-check fault, because the operands for the BOUND instruction are not modified. Returning from the BOUND- range-exceeded exception handler causes the BOUND instruction to be restarted.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 248 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 248 · click to enlarge
Page 248

INTERRUPT AND EXCEPTION HANDLING

Interrupt 6—Invalid Opcode Exception (#UD)

Exception Class Fault.

  • Indicates that the processor did one of the following things:
  • Attempted to execute an invalid or reserved opcode.
  • Attempted to execute an instruction with an operand type that is invalid for its accompanying opcode; for example, the source operand for a LES instruction is not a memory location.
  • Attempted to execute an MMX or SSE/SSE2/SSE3 instruction on an Intel 64 or IA-32 processor that does not support the MMX technology or SSE/SSE2/SSE3/SSSE3 extensions, respectively. CPUID feature flags MMX (bit 23), SSE (bit 25), SSE2 (bit 26), SSE3 (ECX, bit 0), SSSE3 (ECX, bit 9) indicate support for these extensions.
  • Attempted to execute an MMX instruction or SSE/SSE2/SSE3/SSSE3 SIMD instruction (with the exception of the MOVNTI, PAUSE, PREFETCH h , SFENCE, LFENCE, MFENCE, CLFLUSH, MONITOR, and MWAIT instructions) when the EM flag in control register CR0 is set (1).
  • Attempted to execute an SSE/SE2/SSE3/SSSE3 instruction when the OSFXSR bit in control register CR4 is clear (0). Note this does not include the following SSE/SSE2/SSE3 instructions: MASKMOVQ, MOVNTQ, MOVNTI, PREFETCH h , SFENCE, LFENCE, MFENCE, and CLFLUSH; or the 64-bit versions of the PAVGB, PAVGW, PEXTRW, PINSRW, PMAXSW, PMAXUB, PMINSW, PMINUB, PMOVMSKB, PMULHUW, PSADBW, PSHUFW, PADDQ, PSUBQ, PALIGNR, PABSB, PABSD, PABSW, PHADDD, PHADDSW, PHADDW, PHSUBD, PHSUBSW, PHSUBW, PMADDUBSM, PMULHRSW, PSHUFB, PSIGNB, PSIGND, and PSIGNW.
  • Attempted to execute an SSE/SSE2/SSE3/SSSE3 instruction on an Intel 64 or IA-32 processor that caused a SIMD floating-point exception when the OSXMMEXCPT bit in control register CR4 is clear (0).
  • Executed a UD2 instruction. Note that even though it is the execution of the UD2 instruction that causes the invalid opcode exception, the saved instruction pointer will still points at the UD2 instruction.
  • Detected a LOCK prefix that precedes an instruction that may not be locked or one that may be locked but the destination operand is not a memory location.
  • Attempted to execute an LLDT, SLDT, LTR, STR, LSL, LAR, VERR, VERW, or ARPL instruction while in real-address or virtual-8086 mode.
  • Attempted to execute the RSM instruction when not in SMM mode.

In Intel 64 and IA-32 processors that implement out-of-order execution microarchi tectures, this exception is not generated until an attempt is made to retire the result of executing an invalid instruction; that is, decoding and speculatively attempting to execute an invalid opcode does not generate this exception. Likewise, in the Pentium

Description

Page 249 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 249 · click to enlarge
Page 249

INTERRUPT AND EXCEPTION HANDLING

processor and earlier IA-32 processors, this exception is not generated as the result of prefetching and preliminary decoding of an invalid instruction. (See Section 6.5, “Exception Classifications,” for general rules for taking of interrupts and exceptions.)

The opcodes D6 and F1 are undefined opcodes reserved by the Intel 64 and IA-32 architectures. These opcodes, even though undefined, do not generate an invalid opcode exception.

The UD2 instruction is guaranteed to generate an invalid opcode exception.

None.

The saved contents of CS and EIP registers point to the instruction that generated the exception.

A program-state change does not accompany an invalid-opcode fault, because the invalid instruction is not executed.

Exception Error Code · Saved Instruction Pointer · Program State Change

Page 250 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 250 · click to enlarge
Page 250

INTERRUPT AND EXCEPTION HANDLING

Interrupt 7—Device Not Available Exception (#NM)

Exception Class Fault.

Indicates one of the following things:

  • The device-not-available exception is generated by either of three conditions:
  • The processor executed an x87 FPU floating-point instruction while the EM flag in control register CR0 was set (1). See the paragraph below for the special case of the WAIT/FWAIT instruction.
  • The processor executed a WAIT/FWAIT instruction while the MP and TS flags of register CR0 were set, regardless of the setting of the EM flag.
  • The processor executed an x87 FPU, MMX, or SSE/SSE2/SSE3 instruction (with the exception of MOVNTI, PAUSE, PREFETCH h , SFENCE, LFENCE, MFENCE, and CLFLUSH) while the TS flag in control register CR0 was set and the EM flag is clear.

The EM flag is set when the processor does not have an internal x87 FPU floating- point unit. A device-not-available exception is then generated each time an x87 FPU floating-point instruction is encountered, allowing an exception handler to call floating-point instruction emulation routines.

The TS flag indicates that a context switch (task switch) has occurred since the last time an x87 floating-point, MMX, or SSE/SSE2/SSE3 instruction was executed; but that the context of the x87 FPU, XMM, and MXCSR registers were not saved. When the TS flag is set and the EM flag is clear, the processor generates a device-not-avail able exception each time an x87 floating-point, MMX, or SSE/SSE2/SSE3 instruction is encountered (with the exception of the instructions listed above). The exception handler can then save the context of the x87 FPU, XMM, and MXCSR registers before it executes the instruction. See Section 2.5, “Control Registers,” for more information about the TS flag.

The MP flag in control register CR0 is used along with the TS flag to determine if WAIT or FWAIT instructions should generate a device-not-available exception. It extends the function of the TS flag to the WAIT and FWAIT instructions, giving the exception handler an opportunity to save the context of the x87 FPU before the WAIT or FWAIT instruction is executed. The MP flag is provided primarily for use with the Intel 286 and Intel386 DX processors. For programs running on the Pentium 4, Intel Xeon, P6 family, Pentium, or Intel486 DX processors, or the Intel 487 SX coprocessors, the MP flag should always be set; for programs running on the Intel486 SX processor, the MP flag should be clear.

None.

Description · Exception Error Code

Page 251 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 251 · click to enlarge
Page 251

INTERRUPT AND EXCEPTION HANDLING

The saved contents of CS and EIP registers point to the floating-point instruction or the WAIT/FWAIT instruction that generated the exception.

A program-state change does not accompany a device-not-available fault, because the instruction that generated the exception is not executed.

If the EM flag is set, the exception handler can then read the floating-point instruc tion pointed to by the EIP and call the appropriate emulation routine.

If the MP and TS flags are set or the TS flag alone is set, the exception handler can save the context of the x87 FPU, clear the TS flag, and continue execution at the interrupted floating-point or WAIT/FWAIT instruction.

Saved Instruction Pointer · Program State Change

Page 252 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 252 · click to enlarge
Page 252

INTERRUPT AND EXCEPTION HANDLING

Interrupt 8—Double Fault Exception (#DF)

Exception Class Abort.

Indicates that the processor detected a second exception while calling an exception handler for a prior exception. Normally, when the processor detects another excep tion while trying to call an exception handler, the two exceptions can be handled seri ally. If, however, the processor cannot handle them serially, it signals the double-fault exception. To determine when two faults need to be signalled as a double fault, the processor divides the exceptions into three classes: benign exceptions, contributory exceptions, and page faults (see Table 6-4).

Table 6-4. Interrupt and Exception Classes

Class Vector Number Description

Benign Exceptions and Interrupts

1 2 3 4 5 6 7 9 16 17 18

Debug NMI Interrupt Breakpoint Overflow BOUND Range Exceeded Invalid Opcode Device Not Available Coprocessor Segment Overrun Floating-Point Error Alignment Check Machine Check

SIMD floating-point INT n INTR

Contributory Exceptions 0 10 11 12 13

Divide Error Invalid TSS Segment Not Present Stack Fault General Protection

Page Faults 14 Page Fault

Table 6-5 shows the various combinations of exception classes that cause a double fault to be generated. A double-fault exception falls in the abort class of exceptions. The program or task cannot be restarted or resumed. The double-fault handler can be used to collect diagnostic information about the state of the machine and/or, when possible, to shut the application and/or system down gracefully or restart the system.

Description · 19 All All

Page 253 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 253 · click to enlarge
Page 253

INTERRUPT AND EXCEPTION HANDLING

A segment or page fault may be encountered while prefetching instructions; however, this behavior is outside the domain of Table 6-5. Any further faults gener ated while the processor is attempting to transfer control to the appropriate fault handler could still lead to a double-fault sequence.

Table 6-5. Conditions for Generating a Double Fault

First Exception Benign Contributory Page Fault

Benign Handle Exceptions Serially

Contributory Handle Exceptions Serially

Generate a Double Fault

Page Fault Handle Exceptions Serially

Generate a Double Fault

Generate a Double Fault

If another exception occurs while attempting to call the double-fault handler, the processor enters shutdown mode. This mode is similar to the state following execu tion of an HLT instruction. In this mode, the processor stops executing instructions until an NMI interrupt, SMI interrupt, hardware reset, or INIT# is received. The processor generates a special bus cycle to indicate that it has entered shutdown mode. Software designers may need to be aware of the response of hardware when it goes into shutdown mode. For example, hardware may turn on an indicator light on the front panel, generate an NMI interrupt to record diagnostic information, invoke reset initialization, generate an INIT initialization, or generate an SMI. If any events are pending during shutdown, they will be handled after an wake event from shut down is processed (for example, A20M# interrupts).

If a shutdown occurs while the processor is executing an NMI interrupt handler, then only a hardware reset can restart the processor. Likewise, if the shutdown occurs while executing in SMM, a hardware reset must be used to restart the processor.

Zero. The processor always pushes an error code of 0 onto the stack of the double- fault handler.

The saved contents of CS and EIP registers are undefined.

A program-state following a double-fault exception is undefined. The program or task cannot be resumed or restarted. The only available action of the double-fault excep tion handler is to collect all possible context information for use in diagnostics and then close the application and/or shut down or reset the processor.

Show 7 more labels / short text on this page
Second Exception · Handle Exceptions Serially · Handle Exceptions Serially · Handle Exceptions Serially · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 254 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 254 · click to enlarge
Page 254

INTERRUPT AND EXCEPTION HANDLING

If the double fault occurs when any portion of the exception handling machine state is corrupted, the handler cannot be invoked and the processor must be reset.

Page 255 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 255 · click to enlarge
Page 255

INTERRUPT AND EXCEPTION HANDLING

Interrupt 9—Coprocessor Segment Overrun

Exception Class Abort. (Intel reserved; do not use. Recent IA-32 processors do not generate this exception.)

Indicates that an Intel386 CPU-based systems with an Intel 387 math coprocessor detected a page or segment violation while transferring the middle portion of an Intel 387 math coprocessor operand. The P6 family, Pentium, and Intel486 proces sors do not generate this exception; instead, this condition is detected with a general protection exception (#GP), interrupt 13.

None.

The saved contents of CS and EIP registers point to the instruction that generated the exception.

A program-state following a coprocessor segment-overrun exception is unde fined. The program or task cannot be resumed or restarted. The only available action of the exception handler is to save the instruction pointer and reinitialize the x87 FPU using the FNINIT instruction.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 256 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 256 · click to enlarge
Page 256

INTERRUPT AND EXCEPTION HANDLING

Interrupt 10—Invalid TSS Exception (#TS)

Exception Class Fault.

Indicates that there was an error related to a TSS. Such an error might be detected during a task switch or during the execution of instructions that use information from a TSS. Table 6-6 shows the conditions that cause an invalid TSS exception to be generated.

Table 6-6. Invalid TSS Conditions

Error Code Index Invalid Condition

TSS segment selector index The TSS segment limit is less than 67H for 32-bit TSS or less than 2CH for 16-bit TSS.

TSS segment selector index During an IRET task switch, the TI flag in the TSS segment selector indicates the LDT.

TSS segment selector index During an IRET task switch, the TSS segment selector exceeds descriptor table limit.

TSS segment selector index During an IRET task switch, the busy flag in the TSS descriptor indicates an inactive task.

TSS segment selector index During an IRET task switch, an attempt to load the backlink limit faults.

TSS segment selector index During an IRET task switch, the backlink is a NULL selector.

TSS segment selector index During an IRET task switch, the backlink points to a descriptor which is not a busy TSS.

TSS segment selector index The new TSS descriptor is beyond the GDT limit.

TSS segment selector index The new TSS descriptor is not writable.

TSS segment selector index Stores to the old TSS encounter a fault condition.

TSS segment selector index The old TSS descriptor is not writable for a jump or IRET task switch.

TSS segment selector index The new TSS backlink is not writable for a call or exception task switch.

TSS segment selector index The new TSS selector is null on an attempt to lock the new TSS.

TSS segment selector index The new TSS selector has the TI bit set on an attempt to lock the new TSS.

TSS segment selector index The new TSS descriptor is not an available TSS descriptor on an attempt to lock the new TSS.

LDT segment selector index LDT or LDT not present.

Description

Page 257 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 257 · click to enlarge
Page 257

INTERRUPT AND EXCEPTION HANDLING

Table 6-6. Invalid TSS Conditions (Contd.)

Error Code Index Invalid Condition

Stack segment selector index

The stack segment selector exceeds descriptor table limit.

Stack segment selector index

The stack segment selector is NULL.

Stack segment selector index

The stack segment descriptor is a non-data segment.

Stack segment selector index

The stack segment is not writable.

Stack segment selector index

The stack segment DPL != CPL.

Stack segment selector index

The stack segment selector RPL != CPL.

Code segment selector index

The code segment selector exceeds descriptor table limit.

Code segment selector index

The code segment selector is NULL.

Code segment selector index

The code segment descriptor is not a code segment type.

Code segment selector index

The nonconforming code segment DPL != CPL.

Code segment selector index

The conforming code segment DPL is greater than CPL.

Data segment selector index The data segment selector exceeds the descriptor table limit.

Data segment selector index The data segment descriptor is not a readable code or data type.

Data segment selector index The data segment descriptor is a nonconforming code type and RPL > DPL.

Data segment selector index The data segment descriptor is a nonconforming code type and CPL > DPL.

TSS segment selector index The TSS segment selector is NULL for LTR.

TSS segment selector index The TSS segment selector has the TI bit set for LTR.

TSS segment selector index The TSS segment descriptor/upper descriptor is beyond the GDT segment limit.

TSS segment selector index The TSS segment descriptor is not an available TSS type.

TSS segment selector index The TSS segment descriptor is an available 286 TSS type in IA-32e mode.

Page 258 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 258 · click to enlarge
Page 258

INTERRUPT AND EXCEPTION HANDLING

Table 6-6. Invalid TSS Conditions (Contd.)

Error Code Index Invalid Condition

TSS segment selector index The TSS segment upper descriptor is not the correct type.

TSS segment selector index The TSS segment descriptor contains a non-canonical base.

TSS segment selector index There is a limit violation in attempting to load SS selector or ESP from a TSS on a call or exception which changes privilege levels in legacy mode.

TSS segment selector index There is a limit violation or canonical fault in attempting to load RSP or IST from a TSS on a call or exception which changes privilege levels in IA-32e mode.

This exception can generated either in the context of the original task or in the context of the new task (see Section 7.3, “Task Switching”). Until the processor has completely verified the presence of the new TSS, the exception is generated in the context of the original task. Once the existence of the new TSS is verified, the task switch is considered complete. Any invalid-TSS conditions detected after this point are handled in the context of the new task. (A task switch is considered complete when the task register is loaded with the segment selector for the new TSS and, if the switch is due to a procedure call or interrupt, the previous task link field of the new TSS references the old TSS.)

The invalid-TSS handler must be a task called using a task gate. Handling this excep tion inside the faulting TSS context is not recommended because the processor state may not be consistent.

An error code containing the segment selector index for the segment descriptor that caused the violation is pushed onto the stack of the exception handler. If the EXT flag is set, it indicates that the exception was caused by an event external to the currently running program (for example, if an external interrupt handler using a task gate attempted a task switch to an invalid TSS).

If the exception condition was detected before the task switch was carried out, the saved contents of CS and EIP registers point to the instruction that invoked the task switch. If the exception condition was detected after the task switch was carried out, the saved contents of CS and EIP registers point to the first instruction of the new task.

The ability of the invalid-TSS handler to recover from the fault depends on the error condition than causes the fault. See Section 7.3, “Task Switching,” for more informa tion on the task switch process and the possible recovery actions that can be taken.

Exception Error Code · Saved Instruction Pointer · Program State Change

Page 259 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 259 · click to enlarge
Page 259

INTERRUPT AND EXCEPTION HANDLING

If an invalid TSS exception occurs during a task switch, it can occur before or after the commit-to-new-task point. If it occurs before the commit point, no program state change occurs. If it occurs after the commit point (when the segment descriptor information for the new segment selectors have been loaded in the segment regis ters), the processor will load all the state information from the new TSS before it generates the exception. During a task switch, the processor first loads all the segment registers with segment selectors from the TSS, then checks their contents for validity. If an invalid TSS exception is discovered, the remaining segment regis ters are loaded but not checked for validity and therefore may not be usable for refer encing memory. The invalid TSS handler should not rely on being able to use the segment selectors found in the CS, SS, DS, ES, FS, and GS registers without causing another exception. The exception handler should load all segment registers before trying to resume the new task; otherwise, general-protection exceptions (#GP) may result later under conditions that make diagnosis more difficult. The Intel recom mended way of dealing situation is to use a task for the invalid TSS exception handler. The task switch back to the interrupted task from the invalid-TSS exception- handler task will then cause the processor to check the registers as it loads them from the TSS.

Page 260 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 260 · click to enlarge
Page 260

INTERRUPT AND EXCEPTION HANDLING

Interrupt 11—Segment Not Present (#NP)

Exception Class Fault.

  • Indicates that the present flag of a segment or gate descriptor is clear. The processor can generate this exception during any of the following operations:
  • While attempting to load CS, DS, ES, FS, or GS registers. [Detection of a notpresent segment while loading the SS register causes a stack fault exception (#SS) to be generated.] This situation can occur while performing a task switch.
  • While attempting to load the LDTR using an LLDT instruction. Detection of a notpresent LDT while loading the LDTR during a task switch operation causes an invalid-TSS exception (#TS) to be generated.
  • When executing the LTR instruction and the TSS is marked not present.
  • While attempting to use a gate descriptor or TSS that is marked segment-notpresent, but is otherwise valid.

An operating system typically uses the segment-not-present exception to implement virtual memory at the segment level. If the exception handler loads the segment and returns, the interrupted program or task resumes execution.

A not-present indication in a gate descriptor, however, does not indicate that a segment is not present (because gates do not correspond to segments). The oper ating system may use the present flag for gate descriptors to trigger exceptions of special significance to the operating system.

A contributory exception or page fault that subsequently referenced a not-present segment would cause a double fault (#DF) to be generated instead of #NP.

  • An error code containing the segment selector index for the segment descriptor that caused the violation is pushed onto the stack of the exception handler. If the EXT flag is set, it indicates that the exception resulted from either:
  • an external event (NMI or INTR) that caused an interrupt, which subsequently referenced a not-present segment
  • a benign exception that subsequently referenced a not-present segment

The IDT flag is set if the error code refers to an IDT entry. This occurs when the IDT entry for an interrupt being serviced references a not-present gate. Such an event could be generated by an INT instruction or a hardware interrupt.

The saved contents of CS and EIP registers normally point to the instruction that generated the exception. If the exception occurred while loading segment descrip

Description · Exception Error Code · Saved Instruction Pointer

Page 261 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 261 · click to enlarge
Page 261

INTERRUPT AND EXCEPTION HANDLING

tors for the segment selectors in a new TSS, the CS and EIP registers point to the first instruction in the new task. If the exception occurred while accessing a gate descriptor, the CS and EIP registers point to the instruction that invoked the access (for example a CALL instruction that references a call gate).

If the segment-not-present exception occurs as the result of loading a register (CS, DS, SS, ES, FS, GS, or LDTR), a program-state change does accompany the excep tion because the register is not loaded. Recovery from this exception is possible by simply loading the missing segment into memory and setting the present flag in the segment descriptor.

If the segment-not-present exception occurs while accessing a gate descriptor, a program-state change does not accompany the exception. Recovery from this excep tion is possible merely by setting the present flag in the gate descriptor.

If a segment-not-present exception occurs during a task switch, it can occur before or after the commit-to-new-task point (see Section 7.3, “Task Switching”). If it occurs before the commit point, no program state change occurs. If it occurs after the commit point, the processor will load all the state information from the new TSS (without performing any additional limit, present, or type checks) before it generates the exception. The segment-not-present exception handler should not rely on being able to use the segment selectors found in the CS, SS, DS, ES, FS, and GS registers without causing another exception. (See the Program State Change description for “Interrupt 10—Invalid TSS Exception (#TS)” in this chapter for additional information on how to handle this situation.)

Program State Change

Page 262 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 262 · click to enlarge
Page 262

INTERRUPT AND EXCEPTION HANDLING

Interrupt 12—Stack Fault Exception (#SS)

Exception Class Fault.

  • Indicates that one of the following stack related conditions was detected:
  • A limit violation is detected during an operation that refers to the SS register. Operations that can cause a limit violation include stack-oriented instructions such as POP, PUSH, CALL, RET, IRET, ENTER, and LEAVE, as well as other memory references which implicitly or explicitly use the SS register (for example, MOV AX, [BP+6] or MOV AX, SS:[EAX+6]). The ENTER instruction generates this exception when there is not enough stack space for allocating local variables.
  • A not-present stack segment is detected when attempting to load the SS register. This violation can occur during the execution of a task switch, a CALL instruction to a different privilege level, a return to a different privilege level, an LSS instruction, or a MOV or POP instruction to the SS register.
  • A canonical violation is detected in 64-bit mode during an operation that reference memory using the stack pointer register containing a non-canonical memory address.

Recovery from this fault is possible by either extending the limit of the stack segment (in the case of a limit violation) or loading the missing stack segment into memory (in the case of a not-present violation.

In the case of a canonical violation that was caused intentionally by software, recovery is possible by loading the correct canonical value into RSP. Otherwise, a canonical violation of the address in RSP likely reflects some register corruption in the software.

If the exception is caused by a not-present stack segment or by overflow of the new stack during an inter-privilege-level call, the error code contains a segment selector for the segment that caused the exception. Here, the exception handler can test the present flag in the segment descriptor pointed to by the segment selector to deter mine the cause of the exception. For a normal limit violation (on a stack segment already in use) the error code is set to 0.

The saved contents of CS and EIP registers generally point to the instruction that generated the exception. However, when the exception results from attempting to load a not-present stack segment during a task switch, the CS and EIP registers point to the first instruction of the new task.

Description · Exception Error Code · Saved Instruction Pointer

Page 263 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 263 · click to enlarge
Page 263

INTERRUPT AND EXCEPTION HANDLING

A program-state change does not generally accompany a stack-fault exception, because the instruction that generated the fault is not executed. Here, the instruction can be restarted after the exception handler has corrected the stack fault condition.

If a stack fault occurs during a task switch, it occurs after the commit-to-new-task point (see Section 7.3, “Task Switching”). Here, the processor loads all the state information from the new TSS (without performing any additional limit, present, or type checks) before it generates the exception. The stack fault handler should thus not rely on being able to use the segment selectors found in the CS, SS, DS, ES, FS, and GS registers without causing another exception. The exception handler should check all segment registers before trying to resume the new task; otherwise, general protection faults may result later under conditions that are more difficult to diagnose. (See the Program State Change description for “Interrupt 10—Invalid TSS Exception (#TS)” in this chapter for additional information on how to handle this situation.)

Program State Change

Page 264 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 264 · click to enlarge
Page 264

INTERRUPT AND EXCEPTION HANDLING

Interrupt 13—General Protection Exception (#GP)

Exception Class Fault.

  • Indicates that the processor detected one of a class of protection violations called “general-protection violations.” The conditions that cause this exception to be gener ated comprise all the protection violations that do not cause other exceptions to be generated (such as, invalid-TSS, segment-not-present, stack-fault, or page-fault exceptions). The following conditions cause general-protection exceptions to be generated:
  • Exceeding the segment limit when accessing the CS, DS, ES, FS, or GS segments.
  • Exceeding the segment limit when referencing a descriptor table (except during a task switch or a stack switch).
  • Transferring execution to a segment that is not executable.
  • Writing to a code segment or a read-only data segment.
  • Reading from an execute-only code segment.
  • Loading the SS register with a segment selector for a read-only segment (unless the selector comes from a TSS during a task switch, in which case an invalid-TSS exception occurs).
  • Loading the SS, DS, ES, FS, or GS register with a segment selector for a system segment.
  • Loading the DS, ES, FS, or GS register with a segment selector for an executeonly code segment.
  • Loading the SS register with the segment selector of an executable segment or a null segment selector.
  • Loading the CS register with a segment selector for a data segment or a null segment selector.
  • Accessing memory using the DS, ES, FS, or GS register when it contains a null segment selector.
  • Switching to a busy task during a call or jump to a TSS.
  • Using a segment selector on a non-IRET task switch that points to a TSS descriptor in the current LDT. TSS descriptors can only reside in the GDT. This condition causes a #TS exception during an IRET task switch.
  • Violating any of the privilege rules described in Chapter 5, “Protection.”
  • Exceeding the instruction length limit of 15 bytes (this only can occur when redundant prefixes are placed before an instruction).
  • Loading the CR0 register with a set PG flag (paging enabled) and a clear PE flag (protection disabled).

Description

Page 265 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 265 · click to enlarge
Page 265

INTERRUPT AND EXCEPTION HANDLING

  • Loading the CR0 register with a set NW flag and a clear CD flag.
  • Referencing an entry in the IDT (following an interrupt or exception) that is not an interrupt, trap, or task gate.
  • Attempting to access an interrupt or exception handler through an interrupt or trap gate from virtual-8086 mode when the handler’s code segment DPL is greater than 0.
  • Attempting to write a 1 into a reserved bit of CR4.
  • Attempting to execute a privileged instruction when the CPL is not equal to 0 (see Section 5.9, “Privileged Instructions,” for a list of privileged instructions).
  • Writing to a reserved bit in an MSR.
  • Accessing a gate that contains a null segment selector.
  • Executing the INT n instruction when the CPL is greater than the DPL of the referenced interrupt, trap, or task gate.
  • The segment selector in a call, interrupt, or trap gate does not point to a code segment.
  • The segment selector operand in the LLDT instruction is a local type (TI flag is set) or does not point to a segment descriptor of the LDT type.
  • The segment selector operand in the LTR instruction is local or points to a TSS that is not available.
  • The target code-segment selector for a call, jump, or return is null.
  • If the PAE and/or PSE flag in control register CR4 is set and the processor detects any reserved bits in a page-directory-pointer-table entry set to 1. These bits are checked during a write to control registers CR0, CR3, or CR4 that causes a reloading of the page-directory-pointer-table entry.
  • Attempting to write a non-zero value into the reserved bits of the MXCSR register.
  • Executing an SSE/SSE2/SSE3 instruction that attempts to access a 128-bit memory location that is not aligned on a 16-byte boundary when the instruction requires 16-byte alignment. This condition also applies to the stack segment.

A program or task can be restarted following any general-protection exception. If the exception occurs while attempting to call an interrupt handler, the interrupted program can be restartable, but the interrupt may be lost.

  • The processor pushes an error code onto the exception handler's stack. If the fault condition was detected while loading a segment descriptor, the error code contains a segment selector to or IDT vector number for the descriptor; otherwise, the error code is 0. The source of the selector in an error code may be any of the following:
  • An operand of the instruction.
  • A selector from a gate which is the operand of the instruction.

Exception Error Code

Page 266 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 266 · click to enlarge
Page 266

INTERRUPT AND EXCEPTION HANDLING

  • A selector from a TSS involved in a task switch.
  • IDT vector number.

The saved contents of CS and EIP registers point to the instruction that generated the exception.

In general, a program-state change does not accompany a general-protection excep tion, because the invalid instruction or operation is not executed. An exception handler can be designed to correct all of the conditions that cause general-protection exceptions and restart the program or task without any loss of program continuity.

If a general-protection exception occurs during a task switch, it can occur before or after the commit-to-new-task point (see Section 7.3, “Task Switching”). If it occurs before the commit point, no program state change occurs. If it occurs after the commit point, the processor will load all the state information from the new TSS (without performing any additional limit, present, or type checks) before it generates the exception. The general-protection exception handler should thus not rely on being able to use the segment selectors found in the CS, SS, DS, ES, FS, and GS registers without causing another exception. (See the Program State Change description for “Interrupt 10—Invalid TSS Exception (#TS)” in this chapter for addi tional information on how to handle this situation.)

General Protection Exception in 64-bit Mode

  • The following conditions cause general-protection exceptions in 64-bit mode:
  • If the memory address is in a non-canonical form.
  • If a segment descriptor memory address is in non-canonical form.
  • If the target offset in a destination operand of a call or jmp is in a non-canonical form.
  • If a code segment or 64-bit call gate overlaps non-canonical space.
  • If the code segment descriptor pointed to by the selector in the 64-bit gate doesn't have the L-bit set and the D-bit clear.
  • If the EFLAGS.NT bit is set in IRET.
  • If the stack segment selector of IRET is null when going back to compatibility mode.
  • If the stack segment selector of IRET is null going back to CPL3 and 64-bit mode.
  • If a null stack segment selector RPL of IRET is not equal to CPL going back to nonCPL3 and 64-bit mode.
  • If the proposed new code segment descriptor of IRET has both the D-bit and the L-bit set.

Saved Instruction Pointer · Program State Change

Page 267 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 267 · click to enlarge
Page 267

INTERRUPT AND EXCEPTION HANDLING

  • If the segment descriptor pointed to by the segment selector in the destination operand is a code segment and it has both the D-bit and the L-bit set.
  • If the segment descriptor from a 64-bit call gate is in non-canonical space.
  • If the DPL from a 64-bit call-gate is less than the CPL or than the RPL of the 64-bit call-gate.
  • If the upper type field of a 64-bit call gate is not 0x0.
  • If an attempt is made to load a null selector in the SS register in compatibility mode.
  • If an attempt is made to load null selector in the SS register in CPL3 and 64-bit mode.
  • If an attempt is made to load a null selector in the SS register in non-CPL3 and 64-bit mode where RPL is not equal to CPL.
  • If an attempt is made to clear CR0.PG while IA-32e mode is enabled.
  • If an attempt is made to set a reserved bit in CR3, CR4 or CR8.
Page 268 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 268 · click to enlarge
Page 268

INTERRUPT AND EXCEPTION HANDLING

Interrupt 14—Page-Fault Exception (#PF)

Exception Class Fault.

  • Indicates that, with paging enabled (the PG flag in the CR0 register is set), the processor detected one of the following conditions while using the page-translation mechanism to translate a linear address to a physical address:
  • The P (present) flag in a page-directory or page-table entry needed for the address translation is clear, indicating that a page table or the page containing the operand is not present in physical memory.
  • The procedure does not have sufficient privilege to access the indicated page (that is, a procedure running in user mode attempts to access a supervisor-mode page).
  • Code running in user mode attempts to write to a read-only page. In the Intel486 and later processors, if the WP flag is set in CR0, the page fault will also be triggered by code running in supervisor mode that tries to write to a read-only page.
  • An instruction fetch to a linear address that translates to a physical address in a memory page with the execute-disable bit set (for information about the execute-disable bit, see Chapter 4, “Paging”).
  • One or more reserved bits in page directory entry are set to 1. See description below of RSVD error code flag.

The exception handler can recover from page-not-present conditions and restart the program or task without any loss of program continuity. It can also restart the program or task after a privilege violation, but the problem that caused the privilege violation may be uncorrectable.

See alsoSection 4.7, “Page-Fault Exceptions.”

Yes (special format). The processor provides the page-fault handler with two items of information to aid in diagnosing the exception and recovering from it: • An error code on the stack. The error code for a page fault has a format different from that for other exceptions (see Figure 6-9). The error code tells the exception handler four things:

— The P flag indicates whether the exception was due to a not-present page (0) or to either an access rights violation or the use of a reserved bit (1).

— The W/R flag indicates whether the memory access that caused the exception was a read (0) or write (1).

Description · Exception Error Code

Page 269 of the Intel 253668-032US user manual — RSVD 0 1
Page 269 · click to enlarge
Page 269

INTERRUPT AND EXCEPTION HANDLING

— The U/S flag indicates whether the processor was executing at user mode (1) or supervisor mode (0) at the time of the exception.

  • — The RSVD flag indicates that the processor detected 1s in reserved bits of the page directory, when the PSE or PAE flags in control register CR4 are set to 1. Note:
  • The PSE flag is only available in recent Intel 64 and IA-32 processors including the Pentium 4, Intel Xeon, P6 family, and Pentium processors.
  • The PAE flag is only available on recent Intel 64 and IA-32 processors including the Pentium 4, Intel Xeon, and P6 family processors.
  • In earlier IA-32 processors, the bit position of the RSVD flag is reserved and is cleared to 0.

— The I/D flag indicates whether the exception was caused by an instruction fetch. This flag is reserved and cleared to 0 if CR4.PAE = 0 (32-bit paging is in use) or IA32_EFER.NXE= 0 (the execute-disable feature is either unsupported or not enabled). See Section 4.7, “Page-Fault Exceptions,” for details.

1 2 3 4

I/D

P W/R U/S RSVD

P 0 1

The fault was caused by a non-present page. The fault was caused by a page-level protection violation.

W/R 0 1

The access causing the fault was a read. The access causing the fault was a write.

U/S 0

The access causing the fault originated when the processor

was executing in supervisor mode. The access causing the fault originated when the processor

was executing in user mode.

RSVD 0 1

The fault was not caused by reserved bit violation. The fault was caused by reserved bits set to 1 in a page directory.

I/D 0 The fault was not caused by an instruction fetch. 1 The fault was caused by an instruction fetch.

Figure 6-9. Page-Fault Error Code

  • The contents of the CR2 register. The processor loads the CR2 register with the 32-bit linear address that generated the exception. The page-fault handler can use this address to locate the corresponding page directory and page-table entries. Another page fault can potentially occur during execution of the pagefault handler; the handler should save the contents of the CR2 register before a

Reserved

Page 270 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 270 · click to enlarge
Page 270

INTERRUPT AND EXCEPTION HANDLING

second page fault can occur.1 If a page fault is caused by a page-level protection violation, the access flag in the page-directory entry is set when the fault occurs. The behavior of IA-32 processors regarding the access flag in the corresponding page-table entry is model specific and not architecturally defined.

The saved contents of CS and EIP registers generally point to the instruction that generated the exception. If the page-fault exception occurred during a task switch, the CS and EIP registers may point to the first instruction of the new task (as described in the following “Program State Change” section).

A program-state change does not normally accompany a page-fault exception, because the instruction that causes the exception to be generated is not executed. After the page-fault exception handler has corrected the violation (for example, loaded the missing page into memory), execution of the program or task can be resumed.

  • When a page-fault exception is generated during a task switch, the program-state may change, as follows. During a task switch, a page-fault exception can occur during any of following operations:
  • While writing the state of the original task into the TSS of that task.
  • While reading the GDT to locate the TSS descriptor of the new task.
  • While reading the TSS of the new task.
  • While reading segment descriptors associated with segment selectors from the new task.
  • While reading the LDT of the new task to verify the segment registers stored in the new TSS.

In the last two cases the exception occurs in the context of the new task. The instruc tion pointer refers to the first instruction of the new task, not to the instruction which caused the task switch (or the last instruction to be executed, in the case of an inter rupt). If the design of the operating system permits page faults to occur during task- switches, the page-fault handler should be called through a task gate.

If a page fault occurs during a task switch, the processor will load all the state infor mation from the new TSS (without performing any additional limit, present, or type checks) before it generates the exception. The page-fault handler should thus not rely on being able to use the segment selectors found in the CS, SS, DS, ES, FS, and GS registers without causing another exception. (See the Program State Change

1. Processors update CR2 whenever a page fault is detected. If a second page fault occurs while an earlier page fault is being delivered, the faulting linear address of the second fault will overwrite the contents of CR2 (replacing the previous address). These updates to CR2 occur even if the page fault results in a double fault or occurs during the delivery of a double fault.

Saved Instruction Pointer · Program State Change

Page 271 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 271 · click to enlarge
Page 271

INTERRUPT AND EXCEPTION HANDLING

description for “Interrupt 10—Invalid TSS Exception (#TS)” in this chapter for addi tional information on how to handle this situation.)

Special care should be taken to ensure that an exception that occurs during an explicit stack switch does not cause the processor to use an invalid stack pointer (SS:ESP). Software written for 16-bit IA-32 processors often use a pair of instruc tions to change to a new stack, for example:

MOV SS, AX MOV SP, StackTop

When executing this code on one of the 32-bit IA-32 processors, it is possible to get a page fault, general-protection fault (#GP), or alignment check fault (#AC) after the segment selector has been loaded into the SS register but before the ESP register has been loaded. At this point, the two parts of the stack pointer (SS and ESP) are inconsistent. The new stack segment is being used with the old stack pointer.

The processor does not use the inconsistent stack pointer if the exception handler switches to a well defined stack (that is, the handler is a task or a more privileged procedure). However, if the exception handler is called at the same privilege level and from the same task, the processor will attempt to use the inconsistent stack pointer.

In systems that handle page-fault, general-protection, or alignment check excep tions within the faulting task (with trap or interrupt gates), software executing at the same privilege level as the exception handler should initialize a new stack by using the LSS instruction rather than a pair of MOV instructions, as described earlier in this note. When the exception handler is running at privilege level 0 (the normal case), the problem is limited to procedures or tasks that run at privilege level 0, typically the kernel of the operating system.

Additional Exception-Handling Information

Page 272 of the Intel 253668-032US user manual — NOTE
Page 272 · click to enlarge
Page 272

INTERRUPT AND EXCEPTION HANDLING

Interrupt 16—x87 FPU Floating-Point Error (#MF)

Exception Class Fault.

Indicates that the x87 FPU has detected a floating-point error. The NE flag in the register CR0 must be set for an interrupt 16 (floating-point error exception) to be generated. (See Section 2.5, “Control Registers,” for a detailed description of the NE flag.)

NOTE

SIMD floating-point exceptions (#XM) are signaled through interrupt 19.

While executing x87 FPU instructions, the x87 FPU detects and reports six types of floating-point error conditions: • Invalid operation (#I)

— Stack overflow or underflow (#IS)

  • — Invalid arithmetic operation (#IA)
  • Divide-by-zero (#Z)
  • Denormalized operand (#D)
  • Numeric overflow (#O)
  • Numeric underflow (#U)
  • Inexact result (precision) (#P)

Each of these error conditions represents an x87 FPU exception type, and for each of exception type, the x87 FPU provides a flag in the x87 FPU status register and a mask bit in the x87 FPU control register. If the x87 FPU detects a floating-point error and the mask bit for the exception type is set, the x87 FPU handles the exception auto matically by generating a predefined (default) response and continuing program execution. The default responses have been designed to provide a reasonable result for most floating-point applications.

If the mask for the exception is clear and the NE flag in register CR0 is set, the x87 FPU does the following:

1. Sets the necessary flag in the FPU status register.
2. Waits until the next “waiting” x87 FPU instruction or WAIT/FWAIT instruction is encountered in the program’s instruction stream.
3. Generates an internal error signal that cause the processor to generate a floating-point exception (#MF).

Description

Page 273 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 273 · click to enlarge
Page 273

INTERRUPT AND EXCEPTION HANDLING

Prior to executing a waiting x87 FPU instruction or the WAIT/FWAIT instruction, the x87 FPU checks for pending x87 FPU floating-point exceptions (as described in step 2 above). Pending x87 FPU floating-point exceptions are ignored for “non-waiting” x87 FPU instructions, which include the FNINIT, FNCLEX, FNSTSW, FNSTSW AX, FNSTCW, FNSTENV, and FNSAVE instructions. Pending x87 FPU exceptions are also ignored when executing the state management instructions FXSAVE and FXRSTOR.

All of the x87 FPU floating-point error conditions can be recovered from. The x87 FPU floating-point-error exception handler can determine the error condition that caused the exception from the settings of the flags in the x87 FPU status word. See “Soft ware Exception Handling” in Chapter 8 of the Intel® 64 and IA-32 Architectures Soft ware Developer’s Manual, Volume 1, for more information on handling x87 FPU floating-point exceptions.

None. The x87 FPU provides its own error information.

The saved contents of CS and EIP registers point to the floating-point or WAIT/FWAIT instruction that was about to be executed when the floating-point-error exception was generated. This is not the faulting instruction in which the error condition was detected. The address of the faulting instruction is contained in the x87 FPU instruc tion pointer register. See “x87 FPU Instruction and Operand (Data) Pointers” in Chapter 8 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for more information about information the FPU saves for use in handling floating-point-error exceptions.

A program-state change generally accompanies an x87 FPU floating-point exception because the handling of the exception is delayed until the next waiting x87 FPU floating-point or WAIT/FWAIT instruction following the faulting instruction. The x87 FPU, however, saves sufficient information about the error condition to allow recovery from the error and re-execution of the faulting instruction if needed.

In situations where non- x87 FPU floating-point instructions depend on the results of an x87 FPU floating-point instruction, a WAIT or FWAIT instruction can be inserted in front of a dependent instruction to force a pending x87 FPU floating-point exception to be handled before the dependent instruction is executed. See “x87 FPU Exception Synchronization” in Chapter 8 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for more information about synchronization of x87 floating-point-error exceptions.

Exception Error Code · Saved Instruction Pointer · Program State Change

Page 274 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 274 · click to enlarge
Page 274

INTERRUPT AND EXCEPTION HANDLING

Interrupt 17—Alignment Check Exception (#AC)

Exception Class Fault.

Indicates that the processor detected an unaligned memory operand when alignment checking was enabled. Alignment checks are only carried out in data (or stack) accesses (not in code fetches or system segment accesses). An example of an align ment-check violation is a word stored at an odd byte address, or a doubleword stored at an address that is not an integer multiple of 4. Table 6-7 lists the alignment requirements various data types recognized by the processor.

Table 6-7. Alignment Requirements by Data Type

Data Type Address Must Be Divisible By

Single-precision floating-point (32-bits) 4

Double-precision floating-point (64-bits) 8

Double extended-precision floating-point (80- bits)

32-bit Far Pointer 2

48-bit Far Pointer 4

GDTR, IDTR, LDTR, or Task Register Contents 4

FSTENV/FLDENV Save Area 4 or 2, depending on operand size

FSAVE/FRSTOR Save Area 4 or 2, depending on operand size

Bit String 2 or 4 depending on the operand-size attribute.

To enable alignment checking, the following conditions must be true: • AM flag in CR0 register is set.

Show 7 more labels / short text on this page
Description · Word 2 · Doubleword 4 · Quadword 8 · Double quadword 16 · Segment Selector 2 · 32-bit Pointer 4
Page 275 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 275 · click to enlarge
Page 275

INTERRUPT AND EXCEPTION HANDLING

  • AC flag in the EFLAGS register is set.
  • The CPL is 3 (protected mode or virtual-8086 mode).

Alignment-check exceptions (#AC) are generated only when operating at privilege level 3 (user mode). Memory references that default to privilege level 0, such as segment descriptor loads, do not generate alignment-check exceptions, even when caused by a memory reference made from privilege level 3.

Storing the contents of the GDTR, IDTR, LDTR, or task register in memory while at privilege level 3 can generate an alignment-check exception. Although application programs do not normally store these registers, the fault can be avoided by aligning the information stored on an even word-address.

The FXSAVE and FXRSTOR instructions save and restore a 512-byte data structure, the first byte of which must be aligned on a 16-byte boundary. If the alignment-check exception (#AC) is enabled when executing these instructions (and CPL is 3), a misaligned memory operand can cause either an alignment-check exception or a general-protection exception (#GP) depending on the processor implementation (see “FXSAVE-Save x87 FPU, MMX, SSE, and SSE2 State” and “FXRSTOR-Restore x87 FPU, MMX, SSE, and SSE2 State” in Chapter 3 of the Intel® 64 and IA-32 Archi tectures Software Developer’s Manual, Volume 2A).

The MOVUPS and MOVUPD instructions perform 128-bit unaligned loads or stores. The LDDQU instructions loads 128-bit unaligned data.They do not generate general- protection exceptions (#GP) when operands are not aligned on a 16-byte boundary. If alignment checking is enabled, alignment-check exceptions (#AC) may or may not be generated depending on processor implementation when data addresses are not aligned on an 8-byte boundary.

FSAVE and FRSTOR instructions can generate unaligned references, which can cause alignment-check faults. These instructions are rarely needed by application programs.

Yes (always zero).

The saved contents of CS and EIP registers point to the instruction that generated the exception.

A program-state change does not accompany an alignment-check fault, because the instruction is not executed.

Exception Error Code · Saved Instruction Pointer · Program State Change

Page 276 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 276 · click to enlarge
Page 276

INTERRUPT AND EXCEPTION HANDLING

Interrupt 18—Machine-Check Exception (#MC)

Exception Class Abort.

Indicates that the processor detected an internal machine error or a bus error, or that an external agent detected a bus error. The machine-check exception is model- specific, available on the Pentium and later generations of processors. The imple mentation of the machine-check exception is different between different processor families, and these implementations may not be compatible with future Intel 64 or IA-32 processors. (Use the CPUID instruction to determine whether this feature is present.)

Bus errors detected by external agents are signaled to the processor on dedicated pins: the BINIT# and MCERR# pins on the Pentium 4, Intel Xeon, and P6 family processors and the BUSCHK# pin on the Pentium processor. When one of these pins is enabled, asserting the pin causes error information to be loaded into machine- check registers and a machine-check exception is generated.

The machine-check exception and machine-check architecture are discussed in detail in Chapter 15, “Machine-Check Architecture.” Also, see the data books for the indi vidual processors for processor-specific hardware information.

None. Error information is provide by machine-check MSRs.

For the Pentium 4 and Intel Xeon processors, the saved contents of extended machine-check state registers are directly associated with the error that caused the machine-check exception to be generated (see Section 15.3.1.2, “IA32_MCG_STATUS MSR,” and Section 15.3.2.6, “IA32_MCG Extended Machine Check State MSRs”).

For the P6 family processors, if the EIPV flag in the MCG_STATUS MSR is set, the saved contents of CS and EIP registers are directly associated with the error that caused the machine-check exception to be generated; if the flag is clear, the saved instruction pointer may not be associated with the error (see Section 15.3.1.2, “IA32_MCG_STATUS MSR”).

For the Pentium processor, contents of the CS and EIP registers may not be associ ated with the error.

The machine-check mechanism is enabled by setting the MCE flag in control register CR4.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 277 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 277 · click to enlarge
Page 277

INTERRUPT AND EXCEPTION HANDLING

For the Pentium 4, Intel Xeon, P6 family, and Pentium processors, a program-state change always accompanies a machine-check exception, and an abort class excep tion is generated. For abort exceptions, information about the exception can be collected from the machine-check MSRs, but the program cannot generally be restarted.

If the machine-check mechanism is not enabled (the MCE flag in control register CR4 is clear), a machine-check exception causes the processor to enter the shutdown state.

Page 278 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 278 · click to enlarge
Page 278

INTERRUPT AND EXCEPTION HANDLING

Interrupt 19—SIMD Floating-Point Exception (#XM)

Exception Class Fault.

Indicates the processor has detected an SSE/SSE2/SSE3 SIMD floating-point excep tion. The appropriate status flag in the MXCSR register must be set and the particular exception unmasked for this interrupt to be generated.

  • There are six classes of numeric exception conditions that can occur while executing an SSE/ SSE2/SSE3 SIMD floating-point instruction:
  • Invalid operation (#I)
  • Divide-by-zero (#Z)
  • Denormal operand (#D)
  • Numeric overflow (#O)
  • Numeric underflow (#U)
  • Inexact result (Precision) (#P)

The invalid operation, divide-by-zero, and denormal-operand exceptions are pre- computation exceptions; that is, they are detected before any arithmetic operation occurs. The numeric underflow, numeric overflow, and inexact result exceptions are post-computational exceptions.

See "SIMD Floating-Point Exceptions" in Chapter 11 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for additional information about the SIMD floating-point exception classes.

  • When a SIMD floating-point exception occurs, the processor does either of the following things:
  • It handles the exception automatically by producing the most reasonable result and allowing program execution to continue undisturbed. This is the response to masked exceptions.
  • It generates a SIMD floating-point exception, which in turn invokes a software exception handler. This is the response to unmasked exceptions.

Each of the six SIMD floating-point exception conditions has a corresponding flag bit and mask bit in the MXCSR register. If an exception is masked (the corresponding mask bit in the MXCSR register is set), the processor takes an appropriate automatic default action and continues with the computation. If the exception is unmasked (the corresponding mask bit is clear) and the operating system supports SIMD floating- point exceptions (the OSXMMEXCPT flag in control register CR4 is set), a software exception handler is invoked through a SIMD floating-point exception. If the excep tion is unmasked and the OSXMMEXCPT bit is clear (indicating that the operating system does not support unmasked SIMD floating-point exceptions), an invalid opcode exception (#UD) is signaled instead of a SIMD floating-point exception.

Description

Page 279 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 279 · click to enlarge
Page 279

INTERRUPT AND EXCEPTION HANDLING

In situations where a SIMD floating-point exception occurred while the SIMD floating-point exceptions were masked (causing the corresponding exception flag to be set) and the SIMD floating-point exception was subsequently unmasked, then no exception is generated when the exception is unmasked.

When SSE/SSE2/SSE3 SIMD floating-point instructions operate on packed operands (made up of two or four sub-operands), multiple SIMD floating-point exception conditions may be detected. If no more than one exception condition is detected for one or more sets of sub-operands, the exception flags are set for each exception condition detected. For example, an invalid exception detected for one sub-operand will not prevent the reporting of a divide-by-zero exception for another sub-operand. However, when two or more exceptions conditions are generated for one sub- operand, only one exception condition is reported, according to the precedences shown in Table 6-8. This exception precedence sometimes results in the higher priority exception condition being reported and the lower priority exception condi tions being ignored.

Table 6-8. SIMD Floating-Point Exceptions Priority

1 (Highest) Invalid operation exception due to SNaN operand (or any NaN operand for maximum, minimum, or certain compare and convert operations).

2 QNaN operand1.

3 Any other invalid operation exception not mentioned above or a divide-by-zero exception2.

4 Denormal operand exception2.

5 Numeric overflow and underflow exceptions possibly in conjunction with the inexact result exception2.

6 (Lowest) Inexact result exception.

None.

Priority Description · Exception Error Code

Page 280 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 280 · click to enlarge
Page 280

INTERRUPT AND EXCEPTION HANDLING

The saved contents of CS and EIP registers point to the SSE/SSE2/SSE3 instruction that was executed when the SIMD floating-point exception was generated. This is the faulting instruction in which the error condition was detected.

A program-state change does not accompany a SIMD floating-point exception because the handling of the exception is immediate unless the particular exception is masked. The available state information is often sufficient to allow recovery from the error and re-execution of the faulting instruction if needed.

Saved Instruction Pointer · Program State Change

Page 281 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 281 · click to enlarge
Page 281

INTERRUPT AND EXCEPTION HANDLING

Interrupts 32 to 255—User Defined Interrupts

Exception Class Not applicable.

  • Indicates that the processor did one of the following things:
  • Executed an INT n instruction where the instruction operand is one of the vector numbers from 32 through 255.
  • Responded to an interrupt request at the INTR pin or from the local APIC when the interrupt vector number associated with the request is from 32 through 255.

Not applicable.

The saved contents of CS and EIP registers point to the instruction that follows the INT n instruction or instruction following the instruction on which the INTR signal occurred.

A program-state change does not accompany interrupts generated by the INT n instruction or the INTR signal. The INT n instruction generates the interrupt within the instruction stream. When the processor receives an INTR signal, it commits all state changes for all previous instructions before it responds to the interrupt; so, program execution can resume upon returning from the interrupt handler.

Show 4 more labels / short text on this page
Description · Exception Error Code · Saved Instruction Pointer · Program State Change
Page 282 of the Intel 253668-032US user manual — INTERRUPT AND EXCEPTION HANDLING
Page 282 · click to enlarge
Page 282

INTERRUPT AND EXCEPTION HANDLING

Page 283 of the Intel 253668-032US user manual — 7.1.1 Task Structure
Page 283 · click to enlarge
Page 283

CHAPTER 7 TASK MANAGEMENT

This chapter describes the IA-32 architecture’s task management facilities. These facilities are only available when the processor is running in protected mode.

This chapter focuses on 32-bit tasks and the 32-bit TSS structure. For information on 16-bit tasks and the 16-bit TSS structure, see Section 7.6, “16-Bit Task-State Segment (TSS).” For information specific to task management in 64-bit mode, see Section 7.7, “Task Management in 64-bit Mode.”

7.1 TASK MANAGEMENT OVERVIEW

A task is a unit of work that a processor can dispatch, execute, and suspend. It can be used to execute a program, a task or process, an operating-system service utility, an interrupt or exception handler, or a kernel or executive utility.

The IA-32 architecture provides a mechanism for saving the state of a task, for dispatching tasks for execution, and for switching from one task to another. When operating in protected mode, all processor execution takes place from within a task. Even simple systems must define at least one task. More complex systems can use the processor’s task management facilities to support multitasking applications.

7.1.1 Task Structure

A task is made up of two parts: a task execution space and a task-state segment (TSS). The task execution space consists of a code segment, a stack segment, and one or more data segments (see Figure 7-1). If an operating system or executive uses the processor’s privilege-level protection mechanism, the task execution space also provides a separate stack for each privilege level.

The TSS specifies the segments that make up the task execution space and provides a storage place for task state information. In multitasking systems, the TSS also provides a mechanism for linking tasks.

A task is identified by the segment selector for its TSS. When a task is loaded into the processor for execution, the segment selector, base address, limit, and segment descriptor attributes for the TSS are loaded into the task register (see Section 2.4.4, “Task Register (TR)”).

If paging is implemented for the task, the base address of the page directory used by the task is loaded into control register CR3.

Page 284 of the Intel 253668-032US user manual — 7.1.2 Task State
Page 284 · click to enlarge
Page 284

TASK MANAGEMENT

(TSS)

Stack Segment (Current Priv.

Stack Seg. Priv. Level 0

Stack Seg. Priv. Level 1

Stack Segment (Priv. Level 2)

CR3

Figure 7-1. Structure of a Task

7.1.2 Task State

  • The following items define the state of the currently executing task:
  • The task’s current execution space, defined by the segment selectors in the segment registers (CS, DS, SS, ES, FS, and GS).
  • The state of the general-purpose registers.
  • The state of the EFLAGS register.
  • The state of the EIP register.
  • The state of control register CR3.
  • The state of the task register.
  • The state of the LDTR register.
  • The I/O map base address and I/O map (contained in the TSS).
  • Stack pointers to the privilege 0, 1, and 2 stacks (contained in the TSS).
  • Link to previously executed task (contained in the TSS).

Prior to dispatching a task, all of these items are contained in the task’s TSS, except the state of the task register. Also, the complete contents of the LDTR register are not contained in the TSS, only the segment selector for the LDT.

Show 6 more labels / short text on this page
Code Segment · Task-State · Data Segment · Segment · Level) · Task Register
Page 285 of the Intel 253668-032US user manual — TASK MANAGEMENT
Page 285 · click to enlarge
Page 285

TASK MANAGEMENT

7.1.3 Executing a Task

  • Software or the processor can dispatch a task for execution in one of the following ways:
  • A explicit call to a task with the CALL instruction.
  • A explicit jump to a task with the JMP instruction.
  • An implicit call (by the processor) to an interrupt-handler task.
  • An implicit call to an exception-handler task.
  • A return (initiated with an IRET instruction) when the NT flag in the EFLAGS register is set.

All of these methods for dispatching a task identify the task to be dispatched with a segment selector that points to a task gate or the TSS for the task. When dispatching a task with a CALL or JMP instruction, the selector in the instruction may select the TSS directly or a task gate that holds the selector for the TSS. When dispatching a task to handle an interrupt or exception, the IDT entry for the interrupt or exception must contain a task gate that holds the selector for the interrupt- or exception- handler TSS.

When a task is dispatched for execution, a task switch occurs between the currently running task and the dispatched task. During a task switch, the execution environ ment of the currently executing task (called the task’s state or context) is saved in its TSS and execution of the task is suspended. The context for the dispatched task is then loaded into the processor and execution of that task begins with the instruction pointed to by the newly loaded EIP register. If the task has not been run since the system was last initialized, the EIP will point to the first instruction of the task’s code; otherwise, it will point to the next instruction after the last instruction that the task executed when it was last active.

If the currently executing task (the calling task) called the task being dispatched (the called task), the TSS segment selector for the calling task is stored in the TSS of the called task to provide a link back to the calling task.

For all IA-32 processors, tasks are not recursive. A task cannot call or jump to itself.

Interrupts and exceptions can be handled with a task switch to a handler task. Here, the processor performs a task switch to handle the interrupt or exception and auto matically switches back to the interrupted task upon returning from the interrupt- handler task or exception-handler task. This mechanism can also handle interrupts that occur during interrupt tasks.

As part of a task switch, the processor can also switch to another LDT, allowing each task to have a different logical-to-physical address mapping for LDT-based segments. The page-directory base register (CR3) also is reloaded on a task switch, allowing each task to have its own set of page tables. These protection facilities help isolate tasks and prevent them from interfering with one another.

If protection mechanisms are not used, the processor provides no protection between tasks. This is true even with operating systems that use multiple privilege levels for protection. A task running at privilege level 3 that uses the same LDT and

Page 286 of the Intel 253668-032US user manual — 7.2.1 Task-State Segment (TSS)
Page 286 · click to enlarge
Page 286

TASK MANAGEMENT

page tables as other privilege-level-3 tasks can access code and corrupt data and the stack of other tasks.

Use of task management facilities for handling multitasking applications is optional. Multitasking can be handled in software, with each software defined task executed in the context of a single IA-32 architecture task.

7.2 TASK MANAGEMENT DATA STRUCTURES

  • The processor defines five data structures for handling task-related activities:
  • Task-state segment (TSS).
  • Task-gate descriptor.
  • TSS descriptor.
  • Task register.
  • NT flag in the EFLAGS register.

When operating in protected mode, a TSS and TSS descriptor must be created for at least one task, and the segment selector for the TSS must be loaded into the task register (using the LTR instruction).

7.2.1 Task-State Segment (TSS)

The processor state information needed to restore a task is saved in a system segment called the task-state segment (TSS). Figure 7-2 shows the format of a TSS for tasks designed for 32-bit CPUs. The fields of a TSS are divided into two main cate gories: dynamic fields and static fields.

For information about 16-bit Intel 286 processor task structures, see Section 7.6, “16-Bit Task-State Segment (TSS).” For information about 64-bit mode task struc tures, see Section 7.7, “Task Management in 64-bit Mode.”

Page 287 of the Intel 253668-032US user manual — T
Page 287 · click to enlarge
Page 287

TASK MANAGEMENT

I/O Map Base Address

T

GS

FS

DS

SS

CS

ES

EDI

ESI

EBP

ESP

EBX

EDX

ECX

EAX

EFLAGS

EIP

CR3 (PDBR)

SS2

ESP2

SS1

ESP1

SS0

ESP0

Reserved bits. Set to 0.

Figure 7-2. 32-Bit Task-State Segment (TSS)

  • The processor updates dynamic fields when a task is suspended during a task switch. The following are dynamic fields:
  • General-purpose register fields — State of the EAX, ECX, EDX, EBX, ESP, EBP, ESI, and EDI registers prior to the task switch.
  • Segment selector fields — Segment selectors stored in the ES, CS, SS, DS, FS, and GS registers prior to the task switch.
  • EFLAGS register field — State of the EFAGS register prior to the task switch.
Show 14 more labels / short text on this page
Reserved · Reserved · LDT Segment Selector · Reserved · Reserved · Reserved · Reserved · Reserved · Reserved · Reserved · Reserved · Reserved · Reserved · Previous Task Link
Page 288 of the Intel 253668-032US user manual — TASK MANAGEMENT
Page 288 · click to enlarge
Page 288

TASK MANAGEMENT

  • EIP (instruction pointer) field — State of the EIP register prior to the task switch.
  • Previous task link field — Contains the segment selector for the TSS of the previous task (updated on a task switch that was initiated by a call, interrupt, or exception). This field (which is sometimes called the back link field) permits a task switch back to the previous task by using the IRET instruction.
  • The processor reads the static fields, but does not normally change them. These fields are set up when a task is created. The following are static fields:
  • LDT segment selector field — Contains the segment selector for the task's LDT.
  • CR3 control register field — Contains the base physical address of the page directory to be used by the task. Control register CR3 is also known as the pagedirectory base register (PDBR).
  • Privilege level-0, -1, and -2 stack pointer fields — These stack pointers consist of a logical address made up of the segment selector for the stack segment (SS0, SS1, and SS2) and an offset into the stack (ESP0, ESP1, and ESP2). Note that the values in these fields are static for a particular task; whereas, the SS and ESP values will change if stack switching occurs within the task.
  • T (debug trap) flag (byte 100, bit 0) — When set, the T flag causes the processor to raise a debug exception when a task switch to this task occurs (see Section 16.3.1.5, “Task-Switch Exception Condition”).
  • I/O map base address field — Contains a 16-bit offset from the base of the TSS to the I/O permission bit map and interrupt redirection bitmap. When present, these maps are stored in the TSS at higher addresses. The I/O map base address points to the beginning of the I/O permission bit map and the end of the interrupt redirection bit map. See Chapter 13, “Input/Output,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1 , for more information about the I/O permission bit map. See Section 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode,” for a detailed description of the interrupt redirection bit map.
  • If paging is used:
  • Avoid placing a page boundary in the part of the TSS that the processor reads during a task switch (the first 104 bytes). The processor may not correctly perform address translations if a boundary occurs in this area. During a task switch, the processor reads and writes into the first 104 bytes of each TSS (using contiguous physical addresses beginning with the physical address of the first byte of the TSS). So, after TSS access begins, if part of the 104 bytes is not physically contiguous, the processor will access incorrect information without generating a page-fault exception.
  • Pages corresponding to the previous task’s TSS, the current task’s TSS, and the descriptor table entries for each all should be marked as read/write.
Page 289 of the Intel 253668-032US user manual — AVL B BASE DPL G
Page 289 · click to enlarge
Page 289

TASK MANAGEMENT

  • Task switches are carried out faster if the pages containing these structures are present in memory before the task switch is initiated.

7.2.2 TSS Descriptor

The TSS, like all other segments, is defined by a segment descriptor. Figure 7-3 shows the format of a TSS descriptor. TSS descriptors may only be placed in the GDT; they cannot be placed in an LDT or the IDT.

An attempt to access a TSS using a segment selector with its TI flag set (which indi cates the current LDT) causes a general-protection exception (#GP) to be generated during CALLs and JMPs; it causes an invalid TSS exception (#TS) during IRETs. A general-protection exception is also generated if an attempt is made to load a segment selector for a TSS into a segment register.

The busy flag (B) in the type field indicates whether the task is busy. A busy task is currently running or suspended. A type field with a value of 1001B indicates an inac tive task; a value of 1011B indicates a busy task. Tasks are not recursive. The processor uses the busy flag to detect an attempt to call a task whose execution has been interrupted. To insure that there is only one busy flag is associated with a task, each TSS should have only one TSS descriptor that points to it.

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

Limit 19:16 0 1 B 0 1

Base 23:16 A V L

D P L

P Base 31:24 G

31 16 15 0

Base Address 15:00 Segment Limit 15:00

AVL B BASE DPL G

Available for use by system software Busy flag Segment Base Address Descriptor Privilege Level Granularity LIMIT P TYPE

Segment Limit Segment Present Segment Type

Figure 7-3. TSS Descriptor

The base, limit, and DPL fields and the granularity and present flags have functions similar to their use in data-segment descriptors (see Section 3.4.5, “Segment Descriptors”). When the G flag is 0 in a TSS descriptor for a 32-bit TSS, the limit field must have a value equal to or greater than 67H, one byte less than the minimum size

TSS Descriptor · Type

Page 290 of the Intel 253668-032US user manual — 7.2.3 TSS Descriptor in 64-bit mode
Page 290 · click to enlarge
Page 290

TASK MANAGEMENT

of a TSS. Attempting to switch to a task whose TSS descriptor has a limit less than 67H generates an invalid-TSS exception (#TS). A larger limit is required if an I/O permission bit map is included or if the operating system stores additional data. The processor does not check for a limit greater than 67H on a task switch; however, it does check when accessing the I/O permission bit map or interrupt redirection bit map.

Any program or procedure with access to a TSS descriptor (that is, whose CPL is numerically equal to or less than the DPL of the TSS descriptor) can dispatch the task with a call or a jump.

In most systems, the DPLs of TSS descriptors are set to values less than 3, so that only privileged software can perform task switching. However, in multitasking appli cations, DPLs for some TSS descriptors may be set to 3 to allow task switching at the application (or user) privilege level.

7.2.3 TSS Descriptor in 64-bit mode

In 64-bit mode, task switching is not supported, but TSS descriptors still exist. The format of a 64-bit TSS is described in Section 7.7.

In 64-bit mode, the TSS descriptor is expanded to 16 bytes (see Figure 7-4). This expansion also applies to an LDT descriptor in 64-bit mode. Table 3-2 provides the encoding information for the segment type field.

Page 291 of the Intel 253668-032US user manual — 7.2.4 Task Register
Page 291 · click to enlarge
Page 291

TASK MANAGEMENT

TSS (or LDT) Descriptor

31 13 12 8 7 0

Base Address 63:32

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

Limit 19:16 0

Base 23:16 A V L

D P L

P Base 31:24 G

31 16 15 0

Base Address 15:00 Segment Limit 15:00

AVL B BASE DPL G

Available for use by system software Busy flag Segment Base Address Descriptor Privilege Level Granularity LIMIT P TYPE

Segment Limit Segment Present Segment Type

Figure 7-4. Format of TSS and LDT Descriptors in 64-bit Mode

7.2.4 Task Register

The task register holds the 16-bit segment selector and the entire segment descriptor (32-bit base address, 16-bit segment limit, and descriptor attributes) for the TSS of the current task (see Figure 2-5). This information is copied from the TSS descriptor in the GDT for the current task. Figure 7-5 shows the path the processor uses to access the TSS (using the information in the task register).

The task register has a visible part (that can be read and changed by software) and an invisible part (maintained by the processor and is inaccessible by software). The segment selector in the visible portion points to a TSS descriptor in the GDT. The processor uses the invisible portion of the task register to cache the segment descriptor for the TSS. Caching these values in a register makes execution of the task more efficient. The LTR (load task register) and STR (store task register) instructions load and read the visible portion of the task register:

Reserved · Reserved 0 · Type

Page 292 of the Intel 253668-032US user manual — GDT
Page 292 · click to enlarge
Page 292

TASK MANAGEMENT

The LTR instruction loads a segment selector (source operand) into the task register that points to a TSS descriptor in the GDT. It then loads the invisible portion of the task register with information from the TSS descriptor. LTR is a privileged instruction that may be executed only when the CPL is 0. It’s used during system initialization to put an initial value in the task register. Afterwards, the contents of the task register are changed implicitly when a task switch occurs.

The STR (store task register) instruction stores the visible portion of the task register in a general-purpose register or memory. This instruction can be executed by code running at any privilege level in order to identify the currently running task. However, it is normally used only by operating system software.

On power up or reset of the processor, segment selector and base address are set to the default value of 0; the limit is set to FFFFH.

TSS

+

Invisible Part Visible Part

GDT

Figure 7-5. Task Register

Show 4 more labels / short text on this page
Base Address Task · Segment Limit Selector · Register · TSS Descriptor
Page 293 of the Intel 253668-032US user manual — DPL P TYPE
Page 293 · click to enlarge
Page 293

TASK MANAGEMENT

7.2.5 Task-Gate Descriptor

A task-gate descriptor provides an indirect, protected reference to a task (see Figure 7-6). It can be placed in the GDT, an LDT, or the IDT. The TSS segment selector field in a task-gate descriptor points to a TSS descriptor in the GDT. The RPL in this segment selector is not used.

The DPL of a task-gate descriptor controls access to the TSS descriptor during a task switch. When a program or procedure makes a call or jump to a task through a task gate, the CPL and the RPL field of the gate selector pointing to the task gate must be less than or equal to the DPL of the task-gate descriptor. Note that when a task gate is used, the DPL of the destination TSS descriptor is not used.

31 16 15 13 14 12 11 8 7 0

D P L

P

1 0 1 0

31 16 15 0

DPL P TYPE

Descriptor Privilege Level Segment Present Segment Type

Figure 7-6. Task-Gate Descriptor

  • A task can be accessed either through a task-gate descriptor or a TSS descriptor. Both of these structures satisfy the following needs:
  • Need for a task to have only one busy fla g — Because the busy flag for a task is stored in the TSS descriptor, each task should have only one TSS descriptor. There may, however, be several task gates that reference the same TSS descriptor.
  • Need to provide selective access to tasks — Task gates fill this need, because they can reside in an LDT and can have a DPL that is different from the TSS descriptor's DPL. A program or procedure that does not have sufficient privilege to access the TSS descriptor for a task in the GDT (which usually has a DPL of 0) may be allowed access to the task through a task gate with a higher DPL. Task gates give the operating system greater latitude for limiting access to specific tasks.
  • Need for an interrupt or exception to be handled by an independent task — Task gates may also reside in the IDT, which allows interrupts and exceptions
Show 4 more labels / short text on this page
Type · Reserved Reserved · TSS Segment Selector · 0 Reserved
Page 294 of the Intel 253668-032US user manual — 7.3 TASK SWITCHING
Page 294 · click to enlarge
Page 294

TASK MANAGEMENT

to be handled by handler tasks. When an interrupt or exception vector points to a task gate, the processor switches to the specified task.

Figure 7-7 illustrates how a task gate in an LDT, a task gate in the GDT, and a task gate in the IDT can all point to the same task.

LDT

TSS GDT

IDT

Figure 7-7. Task Gates Referencing the Same Task

7.3 TASK SWITCHING

  • The processor transfers execution to another task in one of four cases:
  • The current program, task, or procedure executes a JMP or CALL instruction to a TSS descriptor in the GDT.
  • The current program, task, or procedure executes a JMP or CALL instruction to a task-gate descriptor in the GDT or the current LDT.
Show 4 more labels / short text on this page
Task Gate · Task Gate · TSS Descriptor · Task Gate
Page 295 of the Intel 253668-032US user manual — TASK MANAGEMENT
Page 295 · click to enlarge
Page 295

TASK MANAGEMENT

  • An interrupt or exception vector points to a task-gate descriptor in the IDT.
  • The current task executes an IRET when the NT flag in the EFLAGS register is set.

JMP, CALL, and IRET instructions, as well as interrupts and exceptions, are all mech anisms for redirecting a program. The referencing of a TSS descriptor or a task gate (when calling or jumping to a task) or the state of the NT flag (when executing an IRET instruction) determines whether a task switch occurs.

The processor performs the following operations when switching to a new task:

1. Obtains the TSS segment selector for the new task as the operand of the JMP or CALL instruction, from a task gate, or from the previous task link field (for a task switch initiated with an IRET instruction).

2. Checks that the current (old) task is allowed to switch to the new task. Data- access privilege rules apply to JMP and CALL instructions. The CPL of the current (old) task and the RPL of the segment selector for the new task must be less than or equal to the DPL of the TSS descriptor or task gate being referenced. Exceptions, interrupts (except for interrupts generated by the INT n instruction), and the IRET instruction are permitted to switch tasks regardless of the DPL of the destination task-gate or TSS descriptor. For interrupts generated by the INT n instruction, the DPL is checked.

3. Checks that the TSS descriptor of the new task is marked present and has a valid limit (greater than or equal to 67H).
4. Checks that the new task is available (call, jump, exception, or interrupt) or busy (IRET return).
5. Checks that the current (old) TSS, new TSS, and all segment descriptors used in the task switch are paged into system memory.
6. If the task switch was initiated with a JMP or IRET instruction, the processor clears the busy (B) flag in the current (old) task’s TSS descriptor; if initiated with a CALL instruction, an exception, or an interrupt: the busy (B) flag is left set. (See Table 7-2.)
7. If the task switch was initiated with an IRET instruction, the processor clears the NT flag in a temporarily saved image of the EFLAGS register; if initiated with a CALL or JMP instruction, an exception, or an interrupt, the NT flag is left unchanged in the saved EFLAGS image.
8. Saves the state of the current (old) task in the current task’s TSS. The processor finds the base address of the current TSS in the task register and then copies the states of the following registers into the current TSS: all the general-purpose registers, segment selectors from the segment registers, the temporarily saved image of the EFLAGS register, and the instruction pointer register (EIP).
9. If the task switch was initiated with a CALL instruction, an exception, or an interrupt, the processor will set the NT flag in the EFLAGS loaded from the new task. If initiated with an IRET instruction or JMP instruction, the NT flag will reflect the state of NT in the EFLAGS loaded from the new task (see Table 7-2).
Page 296 of the Intel 253668-032US user manual — NOTES
Page 296 · click to enlarge
Page 296

TASK MANAGEMENT

10. If the task switch was initiated with a CALL instruction, JMP instruction, an exception, or an interrupt, the processor sets the busy (B) flag in the new task’s TSS descriptor; if initiated with an IRET instruction, the busy (B) flag is left set.
11. Loads the task register with the segment selector and descriptor for the new task's TSS.
12. The TSS state is loaded into the processor. This includes the LDTR register, the PDBR (control register CR3), the EFLAGS registers, the EIP register, the generalpurpose registers, and the segment selectors. Note that a fault during the load of this state may corrupt architectural state.
13. The descriptors associated with the segment selectors are loaded and qualified. Any errors associated with this loading and qualification occur in the context of the new task.

NOTES

If all checks and saves have been carried out successfully, the processor commits to the task switch. If an unrecoverable error occurs in steps 1 through 11, the processor does not complete the task switch and insures that the processor is returned to its state prior to the execution of the instruction that initiated the task switch. If an unrecoverable error occurs in step 12, architectural state may be corrupted, but an attempt will be made to handle the error in the prior execution environment. If an unrecoverable error occurs after the commit point (in step 13), the processor completes the task switch (without performing additional access and segment avail ability checks) and generates the appropriate exception prior to beginning execution of the new task. If exceptions occur after the commit point, the exception handler must finish the task switch itself before allowing the processor to begin executing the new task. See Chapter 6, “Interrupt 10—Invalid TSS Exception (#TS),” for more information about the affect of exceptions on a task when they occur after the commit point of a task switch.

14. Begins executing the new task. (To an exception handler, the first instruction of the new task appears not to have been executed.)

The state of the currently executing task is always saved when a successful task switch occurs. If the task is resumed, execution starts with the instruction pointed to by the saved EIP value, and the registers are restored to the values they held when the task was suspended.

When switching tasks, the privilege level of the new task does not inherit its privilege level from the suspended task. The new task begins executing at the privilege level specified in the CPL field of the CS register, which is loaded from the TSS. Because tasks are isolated by their separate address spaces and TSSs and because privilege

Page 297 of the Intel 253668-032US user manual — #GP
Page 297 · click to enlarge
Page 297

TASK MANAGEMENT

rules control access to a TSS, software does not need to perform explicit privilege checks on a task switch.

Table 7-1 shows the exception conditions that the processor checks for when switching tasks. It also shows the exception that is generated for each check if an error is detected and the segment that the error code references. (The order of the checks in the table is the order used in the P6 family processors. The exact order is model specific and may be different for other IA-32 processors.) Exception handlers designed to handle these exceptions may be subject to recursive calls if they attempt to reload the segment selector that generated the exception. The cause of the excep tion (or the first of multiple causes) should be fixed before reloading the selector.

Table 7-1. Exception Conditions Checked During a Task Switch

Condition Checked Exception1 Error Code Reference2

Segment selector for a TSS descriptor references the GDT and is within the limits of the table.

#GP

TSS descriptor is present in memory. #NP New Task’s TSS

TSS descriptor is not busy (for task switch initiated by a call, interrupt, or exception).

#GP (for JMP, CALL, INT)

TSS descriptor is not busy (for task switch initiated by an IRET instruction).

#TS (for IRET) New Task’s TSS

TSS segment limit greater than or equal to 108 (for 32-bit TSS) or 44 (for 16-bit TSS). #TS New Task’s TSS

Registers are loaded from the values in the TSS.

LDT segment selector of new task is valid 3. #TS New Task’s LDT

Code segment DPL matches segment selector RPL. #TS New Code Segment

SS segment selector is valid 2. #TS New Stack Segment

Stack segment is present in memory. #SS New Stack Segment

Stack segment DPL matches CPL. #TS New stack segment

LDT of new task is present in memory. #TS New Task’s LDT

CS segment selector is valid 3. #TS New Code Segment

Code segment is present in memory. #NP New Code Segment

Stack segment DPL matches selector RPL. #TS New Stack Segment

DS, ES, FS, and GS segment selectors are valid 3. #TS New Data Segment

DS, ES, FS, and GS segments are readable. #TS New Data Segment

New Task’s TSS · #TS (for IRET) · Task’s back-link TSS

Page 298 of the Intel 253668-032US user manual — 7.4 TASK LINKING
Page 298 · click to enlarge
Page 298

TASK MANAGEMENT

Table 7-1. Exception Conditions Checked During a Task Switch (Contd.)

Condition Checked Exception1 Error Code Reference2

DS, ES, FS, and GS segments are present in memory. #NP New Data Segment

DS, ES, FS, and GS segment DPL greater than or equal to CPL (unless these are conforming segments).

#TS New Data Segment

NOTES: 1. #NP is segment-not-present exception, #GP is general-protection exception, #TS is invalid-TSS exception, and #SS is stack-fault exception. 2. The error code contains an index to the segment descriptor referenced in this column. 3. A segment selector is valid if it is in a compatible type of table (GDT or LDT), occupies an address within the table's segment limit, and refers to a compatible type of descriptor (for example, a seg ment selector in the CS register only is valid when it points to a code-segment descriptor).

The TS (task switched) flag in the control register CR0 is set every time a task switch occurs. System software uses the TS flag to coordinate the actions of floating-point unit when generating floating-point exceptions with the rest of the processor. The TS flag indicates that the context of the floating-point unit may be different from that of the current task. See Section 2.5, “Control Registers”, for a detailed description of the function and use of the TS flag.

7.4 TASK LINKING

The previous task link field of the TSS (sometimes called the “backlink”) and the NT flag in the EFLAGS register are used to return execution to the previous task. EFLAGS.NT = 1 indicates that the currently executing task is nested within the execution of another task.

When a CALL instruction, an interrupt, or an exception causes a task switch: the processor copies the segment selector for the current TSS to the previous task link field of the TSS for the new task; it then sets EFLAGS.NT = 1. If software uses an IRET instruction to suspend the new task, the processor checks for EFLAGS.NT = 1; it then uses the value in the previous task link field to return to the previous task. See Figures 7-8.

When a JMP instruction causes a task switch, the new task is not nested. The previous task link field is not used and EFLAGS.NT = 0. Use a JMP instruction to dispatch a new task when nesting is not desired.

Page 299 of the Intel 253668-032US user manual — TSS
Page 299 · click to enlarge
Page 299

TASK MANAGEMENT

More Deeply Nested Task

TSS

TSS

TSS

EFLAGS

NT=1

NT=1

NT=0

NT=1

Task Register Task Link

Figure 7-8. Nested Tasks

Table 7-2 shows the busy flag (in the TSS segment descriptor), the NT flag, the previous task link field, and TS flag (in control register CR0) during a task switch.

The NT flag may be modified by software executing at any privilege level. It is possible for a program to set the NT flag and execute an IRET instruction. This might randomly invoke the task specified in the previous link field of the current task's TSS. To keep such spurious task switches from succeeding, the operating system should initialize the previous task link field in every TSS that it creates to 0.

Table 7-2. Effect of a Task Switch on Busy Flag, NT Flag,

Previous Task Link Field, and TS Flag

Flag or Field Effect of JMP

Busy (B) flag of new task.

Flag is set. Must have been clear before.

Flag is set. Must have been clear before.

No change. Must have been set.

Busy flag of old task. Flag is cleared. No change. Flag is currently set.

Flag is cleared.

NT flag of new task. Set to value from TSS of new task.

Flag is set. Set to value from TSS of new task.

NT flag of old task. No change. No change. Flag is cleared.

Previous task link field of new task.

No change. Loaded with selector for old task’s TSS.

No change.

Previous task link field of old task.

No change. No change. No change.

TS flag in control register CR0.

Flag is set. Flag is set. Flag is set.

Show 15 more labels / short text on this page
Top Level · Nested · Currently Executing · Task · Task · Task · Previous · Previous Task Link · Previous Task Link · Effect of CALL · Effect of IRET · instruction · Instruction or · Instruction · Interrupt
Page 300 of the Intel 253668-032US user manual — 7.4.2 Modifying Task Linkages
Page 300 · click to enlarge
Page 300

TASK MANAGEMENT

7.4.1 Use of Busy Flag To Prevent Recursive Task Switching

A TSS allows only one context to be saved for a task; therefore, once a task is called (dispatched), a recursive (or re-entrant) call to the task would cause the current state of the task to be lost. The busy flag in the TSS segment descriptor is provided to prevent re-entrant task switching and a subsequent loss of task state information. The processor manages the busy flag as follows:

1. When dispatching a task, the processor sets the busy flag of the new task.
2. If during a task switch, the current task is placed in a nested chain (the task switch is being generated by a CALL instruction, an interrupt, or an exception), the busy flag for the current task remains set.
3. When switching to the new task (initiated by a CALL instruction, interrupt, or exception), the processor generates a general-protection exception (#GP) if the busy flag of the new task is already set. If the task switch is initiated with an IRET instruction, the exception is not raised because the processor expects the busy flag to be set.
4. When a task is terminated by a jump to a new task (initiated with a JMP instruction in the task code) or by an IRET instruction in the task code, the processor clears the busy flag, returning the task to the “not busy” state.

The processor prevents recursive task switching by preventing a task from switching to itself or to any task in a nested chain of tasks. The chain of nested suspended tasks may grow to any length, due to multiple calls, interrupts, or exceptions. The busy flag prevents a task from being invoked if it is in this chain.

The busy flag may be used in multiprocessor configurations, because the processor follows a LOCK protocol (on the bus or in the cache) when it sets or clears the busy flag. This lock keeps two processors from invoking the same task at the same time. See Section 8.1.2.1, “Automatic Locking,” for more information about setting the busy flag in a multiprocessor applications.

7.4.2 Modifying Task Linkages

In a uniprocessor system, in situations where it is necessary to remove a task from a chain of linked tasks, use the following procedure to remove the task:

1. Disable interrupts.
2. Change the previous task link field in the TSS of the pre-empting task (the task that suspended the task to be removed). It is assumed that the pre-empting task is the next task (newer task) in the chain from the task to be removed. Change the previous task link field to point to the TSS of the next oldest task in the chain or to an even older task in the chain.
3. Clear the busy (B) flag in the TSS segment descriptor for the task being removed from the chain. If more than one task is being removed from the chain, the busy flag for each task being remove must be cleared.
4. Enable interrupts.
Page 301 of the Intel 253668-032US user manual — 7.5.1 Mapping Tasks to the Linear and Physical Address Spaces
Page 301 · click to enlarge
Page 301

TASK MANAGEMENT

In a multiprocessing system, additional synchronization and serialization operations must be added to this procedure to insure that the TSS and its segment descriptor are both locked when the previous task link field is changed and the busy flag is cleared.

7.5 TASK ADDRESS SPACE

The address space for a task consists of the segments that the task can access. These segments include the code, data, stack, and system segments referenced in the TSS and any other segments accessed by the task code. The segments are mapped into the processor’s linear address space, which is in turn mapped into the processor’s physical address space (either directly or through paging).

The LDT segment field in the TSS can be used to give each task its own LDT. Giving a task its own LDT allows the task address space to be isolated from other tasks by placing the segment descriptors for all the segments associated with the task in the task’s LDT.

It also is possible for several tasks to use the same LDT. This is a memory-efficient way to allow specific tasks to communicate with or control each other, without drop ping the protection barriers for the entire system.

Because all tasks have access to the GDT, it also is possible to create shared segments accessed through segment descriptors in this table.

If paging is enabled, the CR3 register (PDBR) field in the TSS allows each task to have its own set of page tables for mapping linear addresses to physical addresses. Or, several tasks can share the same set of page tables.

7.5.1 Mapping Tasks to the Linear and Physical Address Spaces

  • Tasks can be mapped to the linear address space and physical address space in one of two ways:
  • One linear-to-physical address space mapping is shared among all tasks. — When paging is not enabled, this is the only choice. Without paging, all linear addresses map to the same physical addresses. When paging is enabled, this form of linear-to-physical address space mapping is obtained by using one page directory for all tasks. The linear address space may exceed the available physical space if demand-paged virtual memory is supported.
  • Each task has its own linear address space that is mapped to the physical address space. — This form of mapping is accomplished by using a different page directory for each task. Because the PDBR (control register CR3) is loaded on task switches, each task may have a different page directory.

The linear address spaces of different tasks may map to completely distinct physical addresses. If the entries of different page directories point to different page tables

Page 302 of the Intel 253668-032US user manual — 7.5.2 Task Logical Address Space
Page 302 · click to enlarge
Page 302

TASK MANAGEMENT

and the page tables point to different pages of physical memory, then the tasks do not share physical addresses.

With either method of mapping task linear address spaces, the TSSs for all tasks must lie in a shared area of the physical space, which is accessible to all tasks. This mapping is required so that the mapping of TSS addresses does not change while the processor is reading and updating the TSSs during a task switch. The linear address space mapped by the GDT also should be mapped to a shared area of the physical space; otherwise, the purpose of the GDT is defeated. Figure 7-9 shows how the linear address spaces of two tasks can overlap in the physical space by sharing page tables.

Intel 253668-032US — TASK MANAGEMENT diagram (page 302)
Fig. 20

Figure 7-9. Overlapping Linear-to-Physical Mappings

7.5.2 Task Logical Address Space

  • To allow the sharing of data among tasks, use the following techniques to create shared logical-to-physical address-space mappings for data segments:
  • Through the segment descriptors in the GDT — All tasks must have access to the segment descriptors in the GDT. If some segment descriptors in the GDT point to segments in the linear-address space that are mapped into an area of the physical-address space common to all tasks, then all tasks can share the data and code in those segments.
  • Through a shared LDT — Two or more tasks can use the same LDT if the LDT fields in their TSSs point to the same LDT. If some segment descriptors in a
Page 303 of the Intel 253668-032US user manual — 7.6 16-BIT TASK-STATE SEGMENT (TSS)
Page 303 · click to enlarge
Page 303

TASK MANAGEMENT

shared LDT point to segments that are mapped to a common area of the physical address space, the data and code in those segments can be shared among the tasks that share the LDT. This method of sharing is more selective than sharing through the GDT, because the sharing can be limited to specific tasks. Other tasks in the system may have different LDTs that do not give them access to the shared segments. • Through segment descriptors in distinct LDTs that are mapped to common addresses in linear address space — If this common area of the linear address space is mapped to the same area of the physical address space for each task, these segment descriptors permit the tasks to share segments. Such segment descriptors are commonly called aliases. This method of sharing is even more selective than those listed above, because, other segment descriptors in the LDTs may point to independent linear addresses which are not shared.

7.6 16-BIT TASK-STATE SEGMENT (TSS)

The 32-bit IA-32 processors also recognize a 16-bit TSS format like the one used in Intel 286 processors (see Figure 7-10). This format is supported for compatibility with software written to run on earlier IA-32 processors.

  • The following information is important to know about the 16-bit TSS.
  • Do not use a 16-bit TSS to implement a virtual-8086 task.
  • The valid segment limit for a 16-bit TSS is 2CH.
  • The 16-bit TSS does not contain a field for the base address of the page directory, which is loaded into control register CR3. A separate set of page tables for each task is not supported for 16-bit tasks. If a 16-bit task is dispatched, the pagetable structure for the previous task is used.
  • The I/O base address is not included in the 16-bit TSS. None of the functions of the I/O map are supported.
  • When task state is saved in a 16-bit TSS, the upper 16 bits of the EFLAGS register and the EIP register are lost.
  • When the general-purpose registers are loaded or saved from a 16-bit TSS, the upper 16 bits of the registers are modified and not maintained.
Page 304 of the Intel 253668-032US user manual — 7.7 TASK MANAGEMENT IN 64-BIT MODE
Page 304 · click to enlarge
Page 304

TASK MANAGEMENT

DI

SI

BP

SP

BX

DX

AX

SS2

SP2

SS1

SP1

SS0

SP0

Figure 7-10. 16-Bit TSS Format

7.7 TASK MANAGEMENT IN 64-BIT MODE

  • In 64-bit mode, task structure and task state are similar to those in protected mode. However, the task switching mechanism available in protected mode is not supported in 64-bit mode. Task management and switching must be performed by software. The processor issues a general-protection exception (#GP) if the following is attempted in 64-bit mode:
  • Control transfer to a TSS or a task gate using JMP, CALL, INTn, or interrupt.
  • An IRET with EFLAGS.NT (nested task) set to 1.
Show 8 more labels / short text on this page
Task LDT Selector · DS Selector · SS Selector · CS Selector · ES Selector · FLAG Word · IP (Entry Point) · Previous Task Link
Page 305 of the Intel 253668-032US user manual — TASK MANAGEMENT
Page 305 · click to enlarge
Page 305

TASK MANAGEMENT

  • Although hardware task-switching is not supported in 64-bit mode, a 64-bit task state segment (TSS) must exist. Figure 7-11 shows the format of a 64-bit TSS. The TSS holds information important to 64-bit mode and that is not directly related to the task-switch mechanism. This information includes:
  • RSPn — The full 64-bit canonical forms of the stack pointers (RSP) for privilege levels 0-2.
  • ISTn — The full 64-bit canonical forms of the interrupt stack table (IST) pointers.
  • I/O map base address — The 16-bit offset to the I/O permission bit map from the 64-bit TSS base.

The operating system must create at least one 64-bit TSS after activating IA-32e mode. It must execute the LTR instruction (in 64-bit mode) to load the TR register with a pointer to the 64-bit TSS responsible for both 64-bit-mode programs and compatibility-mode programs.

Page 306 of the Intel 253668-032US user manual — TASK MANAGEMENT
Page 306 · click to enlarge
Page 306

TASK MANAGEMENT

I/O Map Base Address

IST7 (upper 32 bits)

IST7 (lower 32 bits)

IST6 (upper 32 bits)

IST6 (lower 32 bits)

IST5 (upper 32 bits)

IST5 (lower 32 bits)

IST4 (upper 32 bits)

IST4 (lower 32 bits)

IST3 (upper 32 bits)

IST3 (lower 32 bits)

IST2 (upper 32 bits)

IST2 (lower 32 bits)

IST1 (upper 32 bits)

IST1 (lower 32 bits)

RSP2 (upper 32 bits)

RSP2 (lower 32 bits)

RSP1 (upper 32 bits)

RSP1 (lower 32 bits)

RSP0 (upper 32 bits)

RSP0 (lower 32 bits)

Reserved bits. Set to 0.

Figure 7-11. 64-Bit TSS Format

Show 6 more labels / short text on this page
Reserved · Reserved · Reserved · Reserved · Reserved · Reserved
Page 307 of the Intel 253668-032US user manual — CHAPTER 8 MULTIPLE-PROCESSOR MANAGEMENT
Page 307 · click to enlarge
Page 307

CHAPTER 8 MULTIPLE-PROCESSOR MANAGEMENT

  • The Intel 64 and IA-32 architectures provide mechanisms for managing and improving the performance of multiple processors connected to the same system bus. These include:
  • Bus locking and/or cache coherency management for performing atomic operations on system memory.
  • Serializing instructions. These instructions apply only to the Pentium 4, Intel Xeon, P6 family, and Pentium processors.
  • An advance programmable interrupt controller (APIC) located on the processor chip (see Chapter 10, “Advanced Programmable Interrupt Controller (APIC)”). This feature was introduced by the Pentium processor.
  • A second-level cache (level 2, L2). For the Pentium 4, Intel Xeon, and P6 family processors, the L2 cache is included in the processor package and is tightly coupled to the processor. For the Pentium and Intel486 processors, pins are provided to support an external L2 cache.
  • A third-level cache (level 3, L3). For Intel Xeon processors, the L3 cache is included in the processor package and is tightly coupled to the processor.
  • Intel Hyper-Threading Technology. This extension to the Intel 64 and IA-32 archi tectures enables a single processor core to execute two or more threads concur rently (see Section 8.5, “Intel ® Hyper-Threading Technology and Intel ® MultiCore Technology”).

These mechanisms are particularly useful in symmetric-multiprocessing (SMP) systems. However, they can also be used when an Intel 64 or IA-32 processor and a special-purpose processor (such as a communications, graphics, or video processor) share the system bus.

  • These multiprocessing mechanisms have the following characteristics:
  • To maintain system memory coherency — When two or more processors are attempting simultaneously to access the same address in system memory, some communication mechanism or memory access protocol must be available to promote data coherency and, in some instances, to allow one processor to temporarily lock a memory location.
  • To maintain cache consistency — When one processor accesses data cached on another processor, it must not receive incorrect data. If it modifies data, all other processors that access that data must receive the modified data.
  • To allow predictable ordering of writes to memory — In some circumstances, it is important that memory writes be observed externally in precisely the same order as programmed.
Page 308 of the Intel 253668-032US user manual — NOTE
Page 308 · click to enlarge
Page 308

MULTIPLE-PROCESSOR MANAGEMENT

  • To distribute interrupt handling among a group of processors — When several processors are operating in a system in parallel, it is useful to have a centralized mechanism for receiving interrupts and distributing them to available processors for servicing.
  • To increase system performance by exploiting the multi-threaded and multiprocess nature of contemporary operating systems and applications.

The caching mechanism and cache consistency of Intel 64 and IA-32 processors are discussed in Chapter 11. The APIC architecture is described in Chapter 10. Bus and memory locking, serializing instructions, memory ordering, and Intel Hyper- Threading Technology are discussed in the following sections.

8.1 LOCKED ATOMIC OPERATIONS

  • The 32-bit IA-32 processors support locked atomic operations on locations in system memory. These operations are typically used to manage shared data structures (such as semaphores, segment descriptors, system segments, or page tables) in which two or more processors may try simultaneously to modify the same field or flag. The processor uses three interdependent mechanisms for carrying out locked atomic operations:
  • Guaranteed atomic operations
  • Bus locking, using the LOCK# signal and the LOCK instruction prefix
  • Cache coherency protocols that insure that atomic operations can be carried out on cached data structures (cache lock); this mechanism is present in the Pentium 4, Intel Xeon, and P6 family processors

These mechanisms are interdependent in the following ways. Certain basic memory transactions (such as reading or writing a byte in system memory) are always guar anteed to be handled atomically. That is, once started, the processor guarantees that the operation will be completed before another processor or bus agent is allowed access to the memory location. The processor also supports bus locking for performing selected memory operations (such as a read-modify-write operation in a shared area of memory) that typically need to be handled atomically, but are not automatically handled this way. Because frequently used memory locations are often cached in a processor’s L1 or L2 caches, atomic operations can often be carried out inside a processor’s caches without asserting the bus lock. Here the processor’s cache coherency protocols insure that other processors that are caching the same memory locations are managed properly while atomic operations are performed on cached memory locations.

NOTE

Where there are contested lock accesses, software may need to implement algorithms that ensure fair access to resources in order to prevent lock starvation. The hardware provides no resource that guarantees fairness to participating agents. It is the responsibility of

Page 309 of the Intel 253668-032US user manual — 8.1.2 Bus Locking
Page 309 · click to enlarge
Page 309

MULTIPLE-PROCESSOR MANAGEMENT

software to manage the fairness of semaphores and exclusive locking functions.

The mechanisms for handling locked atomic operations have evolved with the complexity of IA-32 processors. More recent IA-32 processors (such as the Pentium 4, Intel Xeon, and P6 family processors) and Intel 64 provide a more refined locking mechanism than earlier processors. These mechanisms are described in the following sections.

8.1.1 Guaranteed Atomic Operations

  • The Intel486 processor (and newer processors since) guarantees that the following basic memory operations will always be carried out atomically:
  • Reading or writing a byte
  • Reading or writing a word aligned on a 16-bit boundary
  • Reading or writing a doubleword aligned on a 32-bit boundary
  • The Pentium processor (and newer processors since) guarantees that the following additional memory operations will always be carried out atomically:
  • Reading or writing a quadword aligned on a 64-bit boundary
  • 16-bit accesses to uncached memory locations that fit within a 32-bit data bus

The P6 family processors (and newer processors since) guarantee that the following additional memory operation will always be carried out atomically: • Unaligned 16-, 32-, and 64-bit accesses to cached memory that fit within a cache line

Accesses to cacheable memory that are split across bus widths, cache lines, and page boundaries are not guaranteed to be atomic by the Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors. The Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4, Intel Xeon, and P6 family processors provide bus control signals that permit external memory subsystems to make split accesses atomic; however, nonaligned data accesses will seriously impact the performance of the processor and should be avoided.

8.1.2 Bus Locking

Intel 64 and IA-32 processors provide a LOCK# signal that is asserted automatically during certain critical memory operations to lock the system bus or equivalent link. While this output signal is asserted, requests from other processors or bus agents for control of the bus are blocked. Software can specify other occasions when the LOCK semantics are to be followed by prepending the LOCK prefix to an instruction.

In the case of the Intel386, Intel486, and Pentium processors, explicitly locked instructions will result in the assertion of the LOCK# signal. It is the responsibility of

Page 310 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 310 · click to enlarge
Page 310

MULTIPLE-PROCESSOR MANAGEMENT

the hardware designer to make the LOCK# signal available in system hardware to control memory accesses among processors.

For the P6 and more recent processor families, if the memory area being accessed is cached internally in the processor, the LOCK# signal is generally not asserted; instead, locking is only applied to the processor’s caches (see Section 8.1.4, “Effects of a LOCK Operation on Internal Processor Caches”).

8.1.2.1 Automatic Locking

  • The operations on which the processor automatically follows the LOCK semantics are as follows:
  • When executing an XCHG instruction that references memory.
  • When setting the B (busy) flag of a TSS descriptor — The processor tests and sets the busy flag in the type field of the TSS descriptor when switching to a task. To insure that two processors do not switch to the same task simulta neously, the processor follows the LOCK semantics while testing and setting this flag.
  • When updating segment descriptors — When loading a segment descriptor, the processor will set the accessed flag in the segment descriptor if the flag is clear. During this operation, the processor follows the LOCK semantics so that the descriptor will not be modified by another processor while it is being updated. For this action to be effective, operating-system procedures that update descriptors should use the following steps:

— Use a locked operation to modify the access-rights byte to indicate that the segment descriptor is not-present, and specify a value for the type field that indicates that the descriptor is being updated.

— Update the fields of the segment descriptor. (This operation may require several memory accesses; therefore, locked operations cannot be used.)

  • — Use a locked operation to modify the access-rights byte to indicate that the segment descriptor is valid and present.
  • The Intel386 processor always updates the accessed flag in the segment descriptor, whether it is clear or not. The Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors only update this flag if it is not already set.
  • When updating page-directory and page-table entries — When updating page-directory and page-table entries, the processor uses locked cycles to set the accessed and dirty flag in the page-directory and page-table entries.
  • Acknowledging interrupts — After an interrupt request, an interrupt controller may use the data bus to send the interrupt vector for the interrupt to the processor. The processor follows the LOCK semantics during this time to ensure that no other data appears on the data bus when the interrupt vector is being transmitted.
Page 311 of the Intel 253668-032US user manual — NOTE
Page 311 · click to enlarge
Page 311

MULTIPLE-PROCESSOR MANAGEMENT

8.1.2.2 Software Controlled Bus Locking

  • To explicitly force the LOCK semantics, software can use the LOCK prefix with the following instructions when they are used to modify a memory location. An invalidopcode exception (#UD) is generated when the LOCK prefix is used with any other instruction or when no write operation is made to memory (that is, when the destina tion operand is in a register).
  • The bit test and modify instructions (BTS, BTR, and BTC).
  • The exchange instructions (XADD, CMPXCHG, and CMPXCHG8B).
  • The LOCK prefix is automatically assumed for XCHG instruction.
  • The following single-operand arithmetic and logical instructions: INC, DEC, NOT, and NEG.
  • The following two-operand arithmetic and logical instructions: ADD, ADC, SUB, SBB, AND, OR, and XOR.

A locked instruction is guaranteed to lock only the area of memory defined by the destination operand, but may be interpreted by the system as a lock for a larger memory area.

Software should access semaphores (shared memory used for signalling between multiple processors) using identical addresses and operand lengths. For example, if one processor accesses a semaphore using a word access, other processors should not access the semaphore using a byte access.

NOTE

Do not implement semaphores using the WC memory type. Do not perform non-temporal stores to a cache line containing a location used to implement a semaphore.

  • The integrity of a bus lock is not affected by the alignment of the memory field. The LOCK semantics are followed for as many bus cycles as necessary to update the entire operand. However, it is recommend that locked accesses be aligned on their natural boundaries for better system performance:
  • Any boundary for an 8-bit access (locked or otherwise).
  • 16-bit boundary for locked word accesses.
  • 32-bit boundary for locked doubleword accesses.
  • 64-bit boundary for locked quadword accesses.

Locked operations are atomic with respect to all other memory operations and all externally visible events. Only instruction fetch and page table accesses can pass locked instructions. Locked instructions can be used to synchronize data written by one processor and read by another processor.

For the P6 family processors, locked operations serialize all outstanding load and store operations (that is, wait for them to complete). This rule is also true for the Pentium 4 and Intel Xeon processors, with one exception. Load operations that refer

Page 312 of the Intel 253668-032US user manual — 8.1.3 Handling Selfand Cross-Modifying Code
Page 312 · click to enlarge
Page 312

MULTIPLE-PROCESSOR MANAGEMENT

ence weakly ordered memory types (such as the WC memory type) may not be seri alized.

Locked instructions should not be used to insure that data written can be fetched as instructions.

NOTE

The locked instructions for the current versions of the Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors allow data written to be fetched as instructions. However, Intel recommends that developers who require the use of self-modifying code use a different synchronizing mechanism, described in the following sections.

8.1.3 Handling Selfand Cross-Modifying Code

The act of a processor writing data into a currently executing code segment with the intent of executing that data as code is called self-modifying code. IA-32 processors exhibit model-specific behavior when executing self-modified code, depending upon how far ahead of the current execution pointer the code has been modified.

As processor microarchitectures become more complex and start to speculatively execute code ahead of the retirement point (as in P6 and more recent processor families), the rules regarding which code should execute, pre- or post-modification, become blurred. To write self-modifying code and ensure that it is compliant with current and future versions of the IA-32 architectures, use one of the following coding options:

(* OPTION 1 *) Store modified code (as data) into code segment; Jump to new code or an intermediate location; Execute new code;

(* OPTION 2 *) Store modified code (as data) into code segment; Execute a serializing instruction; (* For example, CPUID instruction *) Execute new code;

The use of one of these options is not required for programs intended to run on the Pentium or Intel486 processors, but are recommended to insure compatibility with the P6 and more recent processor families.

Self-modifying code will execute at a lower level of performance than non-self-modi fying or normal code. The degree of the performance deterioration will depend upon the frequency of modification and specific characteristics of the code.

Page 313 of the Intel 253668-032US user manual — 8.1.4 Effects of a LOCK Operation on Internal Processor Caches
Page 313 · click to enlarge
Page 313

MULTIPLE-PROCESSOR MANAGEMENT

The act of one processor writing data into the currently executing code segment of a second processor with the intent of having the second processor execute that data as code is called cross-modifying code. As with self-modifying code, IA-32 processors exhibit model-specific behavior when executing cross-modifying code, depending upon how far ahead of the executing processors current execution pointer the code has been modified.

To write cross-modifying code and insure that it is compliant with current and future versions of the IA-32 architecture, the following processor synchronization algorithm must be implemented:

(* Action of Modifying Processor *) Memory_Flag ← 0; (* Set Memory_Flag to value other than 1 *) Store modified code (as data) into code segment; Memory_Flag ← 1;

(* Action of Executing Processor *) WHILE (Memory_Flag ≠ 1)

Wait for code to update; ELIHW;

Execute serializing instruction; (* For example, CPUID instruction *) Begin executing modified code;

(The use of this option is not required for programs intended to run on the Intel486 processor, but is recommended to insure compatibility with the Pentium 4, Intel Xeon, P6 family, and Pentium processors.)

Like self-modifying code, cross-modifying code will execute at a lower level of perfor mance than non-cross-modifying (normal) code, depending upon the frequency of modification and specific characteristics of the code.

The restrictions on self-modifying code and cross-modifying code also apply to the Intel 64 architecture.

8.1.4 Effects of a LOCK Operation on Internal Processor Caches

For the Intel486 and Pentium processors, the LOCK# signal is always asserted on the bus during a LOCK operation, even if the area of memory being locked is cached in the processor.

For the P6 and more recent processor families, if the area of memory being locked during a LOCK operation is cached in the processor that is performing the LOCK oper ation as write-back memory and is completely contained in a cache line, the processor may not assert the LOCK# signal on the bus. Instead, it will modify the memory location internally and allow it’s cache coherency mechanism to insure that the operation is carried out atomically. This operation is called “cache locking.” The cache coherency mechanism automatically prevents two or more processors that

Page 314 of the Intel 253668-032US user manual — 8.2 MEMORY ORDERING
Page 314 · click to enlarge
Page 314

MULTIPLE-PROCESSOR MANAGEMENT

have cached the same area of memory from simultaneously modifying data in that area.

8.2 MEMORY ORDERING

The term memory ordering refers to the order in which the processor issues reads (loads) and writes (stores) through the system bus to system memory. The Intel 64 and IA-32 architectures support several memory-ordering models depending on the implementation of the architecture. For example, the Intel386 processor enforces program ordering (generally referred to as strong ordering), where reads and writes are issued on the system bus in the order they occur in the instruction stream under all circumstances.

To allow performance optimization of instruction execution, the IA-32 architecture allows departures from strong-ordering model called processor ordering in Pentium 4, Intel Xeon, and P6 family processors. These processor-ordering varia tions (called here the memory-ordering model) allow performance enhancing operations such as allowing reads to go ahead of buffered writes. The goal of any of these variations is to increase instruction execution speeds, while maintaining memory coherency, even in multiple-processor systems.

Section 8.2.1 and Section 8.2.2 describe the memory-ordering implemented by Intel486, Pentium, Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium 4, Intel Xeon, and P6 family processors. Section 8.2.3 gives examples illustrating the behavior of the memory-ordering model on IA-32 and Intel-64 processors. Section 8.2.4 considers the special treatment of stores for string operations and Section 8.2.5 discusses how memory-ordering behavior may be modified through the use of specific instructions.

8.2.1 Memory Ordering in the Intel® Pentium® and Intel486™ Processors

The Pentium and Intel486 processors follow the processor-ordered memory model; however, they operate as strongly-ordered processors under most circumstances. Reads and writes always appear in programmed order at the system bus—except for the following situation where processor ordering is exhibited. Read misses are permitted to go ahead of buffered writes on the system bus when all the buffered writes are cache hits and, therefore, are not directed to the same address being accessed by the read miss.

In the case of I/O operations, both reads and writes always appear in programmed order.

Software intended to operate correctly in processor-ordered processors (such as the Pentium 4, Intel Xeon, and P6 family processors) should not depend on the relatively strong ordering of the Pentium or Intel486 processors. Instead, it should insure that accesses to shared variables that are intended to control concurrent execution

Page 315 of the Intel 253668-032US user manual — 8.2.2 Memory Ordering in P6 and More Recent Processor Families
Page 315 · click to enlarge
Page 315

MULTIPLE-PROCESSOR MANAGEMENT

among processors are explicitly required to obey program ordering through the use of appropriate locking or serializing operations (see Section 8.2.5, “Strengthening or Weakening the Memory-Ordering Model”).

8.2.2 Memory Ordering in P6 and More Recent Processor Families

The Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium 4, and P6 family proces sors also use a processor-ordered memory-ordering model that can be further defined as “write ordered with store-buffer forwarding.” This model can be character ized as follows.

  • In a single-processor system for memory regions defined as write-back cacheable, the memory-ordering model respects the following principles ( Note the memoryordering principles for single-processor and multiple-processor systems are written from the perspective of software executing on the processor, where the term “processor“ refers to a logical processor. For example, a physical processor supporting multiple cores and/or HyperThreading Technology is treated as a multiprocessor systems.):
  • Reads are not reordered with other reads.
  • Writes are not reordered with older reads.
  • Writes to memory are not reordered with other writes, with the exception of

— writes executed with the CLFLUSH instruction,

— streaming stores (writes) executed with the non-temporal move instructions (MOVNTI, MOVNTQ, MOVNTDQ, MOVNTPS, and MOVNTPD),

  • — string operations (see Section 8.2.4.1).
  • Reads may be reordered with older writes to different locations but not with older writes to the same location.
  • Reads or writes cannot be reordered with I/O instructions, locked instructions, or serializing instructions.
  • Reads cannot pass LFENCE and MFENCE instructions.
  • Writes cannot pass SFENCE and MFENCE instructions.
  • In a multiple-processor system, the following ordering principles apply:
  • Individual processors use the same ordering principles as in a single-processor system.
  • Writes by a single processor are observed in the same order by all processors.
  • Writes from an individual processor are NOT ordered with respect to the writes from other processors.
  • Memory ordering obeys causality (memory ordering respects transitive visibility).
  • Any two stores are seen in a consistent order by processors other than those performing the stores
Page 316 of the Intel 253668-032US user manual — NOTE
Page 316 · click to enlarge
Page 316

MULTIPLE-PROCESSOR MANAGEMENT

  • Locked instructions have a total order.

See the example in Figure 8-1. Consider three processors in a system and each processor performs three writes, one to each of three defined locations (A, B, and C). Individually, the processors perform the writes in the same program order, but because of bus arbitration and other memory access mechanisms, the order that the three processors write the individual memory locations can differ each time the respective code sequences are executed on the processors. The final values in loca tion A, B, and C would possibly vary on each execution of the write sequence.

  • The processor-ordering model described in this section is virtually identical to that used by the Pentium and Intel486 processors. The only enhancements in the Pentium 4, Intel Xeon, and P6 family processors are:
  • Added support for speculative reads, while still adhering to the ordering principles above.
  • Store-buffer forwarding, when a read passes a write to the same memory location.
  • Out of order store from long string store and string move operations (see Section 8.2.4, “Out-of-Order Stores For String Operations,” below).

Order of Writes From Individual Processors

Processor #1 Processor #2 Processor #3

Each processor is guaranteed to perform writes in program order.

Write A.1 Write B.1 Write C.1

Write A.2 Write B.2 Write C.2

Write A.3 Write B.3 Write C.3

Example of order of actual writes from all processors to memory

Writes are in order with respect to individual processes.

Write A.1 Write B.1 Write A.2 Write A.3 Write C.1 Write B.2 Write C.2 Write B.3 Write C.3

Writes from all processors are not guaranteed to occur in a particular order.

Figure 8-1. Example of Write Ordering in Multiple-Processor Systems

NOTE

In P6 processor family, store-buffer forwarding to reads of WC memory from streaming stores to the same address does not occur due to errata.

Page 317 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 317 · click to enlarge
Page 317

MULTIPLE-PROCESSOR MANAGEMENT

8.2.3 Examples Illustrating the Memory-Ordering Principles

This section provides a set of examples that illustrate the behavior of the memory- ordering principles introduced in Section 8.2.2. They are designed to give software writers an understanding of how memory ordering may affect the results of different sequences of instructions.

These examples are limited to accesses to memory regions defined as write-back cacheable (WB). (Section 8.2.3.1 describes other limitations on the generality of the examples.) The reader should understand that they describe only software-visible behavior. A logical processor may reorder two accesses even if one of examples indi cates that they may not be reordered. Such an example states only that software cannot detect that such a reordering occurred. Similarly, a logical processor may execute a memory access more than once as long as the behavior visible to software is consistent with a single execution of the memory access.

8.2.3.1 Assumptions, Terminology, and Notation

As noted above, the examples in this section are limited to accesses to memory regions defined as write-back cacheable (WB). They apply only to ordinary loads stores and to locked read-modify-write instructions. They do not necessarily apply to any of the following: out-of-order stores for string instructions (see Section 8.2.4); accesses with a non-temporal hint; reads from memory by the processor as part of address translation (e.g., page walks); and updates to segmentation and paging structures by the processor (e.g., to update “accessed” bits).

  • The principles underlying the examples in this section apply to individual memory accesses and to locked read-modify-write instructions. The Intel-64 memoryordering model guarantees that, for each of the following memory-access instruc tions, the constituent memory operation appears to execute as a single memory access:
  • Instructions that read or write a single byte.
  • Instructions that read or write a word (2 bytes) whose address is aligned on a 2 byte boundary.
  • Instructions that read or write a doubleword (4 bytes) whose address is aligned on a 4 byte boundary.
  • Instructions that read or write a quadword (8 bytes) whose address is aligned on an 8 byte boundary.

Any locked instruction (either the XCHG instruction or another read-modify-write instruction with a LOCK prefix) appears to execute as an indivisible and uninterrupt ible sequence of load(s) followed by store(s) regardless of alignment.

Other instructions may be implemented with multiple memory accesses. From a memory-ordering point of view, there are no guarantees regarding the relative order in which the constituent memory accesses are made. There is also no guarantee that the constituent operations of a store are executed in the same order as the constit uent operations of a load.

Page 318 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 318 · click to enlarge
Page 318

MULTIPLE-PROCESSOR MANAGEMENT

Section 8.2.3.2 through Section 8.2.3.7 give examples using the MOV instruction. The principles that underlie these examples apply to load and store accesses in general and to other instructions that load from or store to memory. Section 8.2.3.8 and Section 8.2.3.9 give examples using the XCHG instruction. The principles that underlie these examples apply to other locked read-modify-write instructions.

  • This section uses the term “processor” is to refer to a logical processor. The examples are written using Intel-64 assembly-language syntax and use the following nota tional conventions:
  • Arguments beginning with an “r”, such as r1 or r2 refer to registers (e.g., EAX) visible only to the processor being considered.
  • Memory locations are denoted with x, y, z.
  • Stores are written as mov [ _x], val , which implies that val is being stored into the memory location x .
  • Loads are written as mov r, [ _x] , which implies that the contents of the memory location x are being loaded into the register r .

As noted earlier, the examples refer only to software visible behavior. When the succeeding sections make statement such as “the two stores are reordered,” the implication is only that “the two stores appear to be reordered from the point of view of software.”

8.2.3.2 Neither Loads Nor Stores Are Reordered with Like Operations

The Intel-64 memory-ordering model allows neither loads nor stores to be reordered with the same kind of operation. That is, it ensures that loads are seen in program order and that stores are seen in program order. This is illustrated by the following example:

Example 8-1. Stores Are Not Reordered with Other Stores

Processor 0 Processor 1

mov [ _x], 1 mov r1, [ _y]

mov [ _y], 1 mov r2, [ _x]

Initially x == y == 0

r1 == 1 and r2 == 0 is not allowed

The disallowed return values could be exhibited only if processor 0’s two stores are reordered (with the two loads occurring between them) or if processor 1’s two loads are reordered (with the two stores occurring between them). If r1 == 1, the store to y occurs before the load from y. Because the Intel-64 memory-ordering model does not allow stores to be reordered, the earlier store to x occurs before the load from y. Because the Intel-64 memory-ordering model does not allow loads to be reordered, the store to x also occurs before the later load from x. This r2 == 1.

Page 319 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 319 · click to enlarge
Page 319

MULTIPLE-PROCESSOR MANAGEMENT

8.2.3.3 Stores Are Not Reordered With Earlier Loads

The Intel-64 memory-ordering model ensures that a store by a processor may not occur before a previous load by the same processor. This is illustrated by the following example:

Example 8-2. Stores Are Not Reordered with Older Loads

Processor 0 Processor 1

mov r1, [ _x] mov r2, [ _y]

mov [ _y], 1 mov [ _x], 1

Initially x == y == 0

r1 == 1 and r2 == 1 is not allowed

  • Assume r1 == 1.
  • Because r1 == 1, processor 1’s store to x occurs before processor 0’s load from x.
  • Because the Intel-64 memory-ordering model prevents each store from being reordered with the earlier load by the same processor, processor 1’s load from y occurs before its store to x.
  • Similarly, processor 0’s load from x occurs before its store to y.
  • Thus, processor 1’s load from y occurs before processor 0’s store to y, implying r2 == 0.

8.2.3.4 Loads May Be Reordered with Earlier Stores to Different Locations

The Intel-64 memory-ordering model allows a load to be reordered with an earlier store to a different location. However, loads are not reordered with stores to the same location.

The fact that a load may be reordered with an earlier store to a different location is illustrated by the following example:

Example 8-3. Loads May be Reordered with Older Stores

Processor 0 Processor 1

mov [ _x], 1 mov [ _y], 1

mov r1, [ _y] mov r2, [ _x]

Initially x == y == 0

r1 == 0 and r2 == 0 is allowed

At each processor, the load and the store are to different locations and hence may be reordered. Any interleaving of the operations is thus allowed. One such interleaving

Page 320 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 320 · click to enlarge
Page 320

MULTIPLE-PROCESSOR MANAGEMENT

has the two loads occurring before the two stores. This would result in each load returning value 0.

The fact that a load may not be reordered with an earlier store to the same location is illustrated by the following example:

Example 8-4. Loads Are not Reordered with Older Stores to the Same Location

mov [ _x], 1

mov r1, [ _x]

Initially x == 0

r1 == 0 is not allowed

The Intel-64 memory-ordering model does not allow the load to be reordered with the earlier store because the accesses are to the same location. Therefore, r1 == 1 must hold.

8.2.3.5 Intra-Processor Forwarding Is Allowed

The memory-ordering model allows concurrent stores by two processors to be seen in different orders by those two processors; specifically, each processor may perceive its own store occurring before that of the other. This is illustrated by the following example:

Example 8-5. Intra-Processor Forwarding is Allowed

Processor 0 Processor 1

mov [ _x], 1 mov [ _y], 1

mov r1, [ _x] mov r3, [ _y]

mov r2, [ _y] mov r4, [ _x]

Initially x == y == 0

r2 == 0 and r4 == 0 is allowed

The memory-ordering model imposes no constraints on the order in which the two stores appear to execute by the two processors. This fact allows processor 0 to see its store before seeing processor 1's, while processor 1 sees its store before seeing processor 0's. (Each processor is self consistent.) This allows r2 == 0 and r4 == 0.

In practice, the reordering in this example can arise as a result of store-buffer forwarding. While a store is temporarily held in a processor's store buffer, it can satisfy the processor's own loads but is not visible to (and cannot satisfy) loads by other processors.

Processor 0

Page 321 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 321 · click to enlarge
Page 321

MULTIPLE-PROCESSOR MANAGEMENT

8.2.3.6 Stores Are Transitively Visible

The memory-ordering model ensures transitive visibility of stores; stores that are causally related appear to all processors to occur in an order consistent with the causality relation. This is illustrated by the following example:

Example 8-6. Stores Are Transitively Visible

Processor 0 Processor 1 Processor 2

mov [ _x], 1 mov r1, [ _x]

mov [ _y], 1 mov r2, [ _y]

Initially x == y == 0

r1 == 1, r2 == 1, r3 == 0 is not allowed

  • Assume that r1 == 1 and r2 == 1.
  • Because r1 == 1, processor 0’s store occurs before processor 1’s load.
  • Because the memory-ordering model prevents a store from being reordered with an earlier load (see Section 8.2.3.3), processor 1’s load occurs before its store. Thus, processor 0’s store causally precedes processor 1’s store.
  • Because processor 0’s store causally precedes processor 1’s store, the memoryordering model ensures that processor 0’s store appears to occur before processor 1’s store from the point of view of all processors.
  • Because r2 == 1, processor 1’s store occurs before processor 2’s load.
  • Because the Intel-64 memory-ordering model prevents loads from being reordered (see Section 8.2.3.2), processor 2’s load occur in order.
  • The above items imply that processor 0’s store to x occurs before processor 2’s load from x. This implies that r3 == 1.

8.2.3.7 Stores Are Seen in a Consistent Order by Other Processors

As noted in Section 8.2.3.5, the memory-ordering model allows stores by two processors to be seen in different orders by those two processors. However, any two stores must appear to execute in the same order to all processors other than those performing the stores. This is illustrated by the following example:

Example 8-7. Stores Are Seen in a Consistent Order by Other Processors

Processor 0 Processor 1 Processor 2 Processor 3

mov [ _x], 1 mov [ _y], 1 mov r1, [ _x] mov r3, [_y]

mov r2, [ _y] mov r4, [_x]

Initially x == y ==0

r1 == 1, r2 == 0, r3 == 1, r4 == 0is not allowed

mov r3, [_x]

Page 322 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 322 · click to enlarge
Page 322

MULTIPLE-PROCESSOR MANAGEMENT

  • By the principles discussed in Section 8.2.3.2,
  • processor 2’s first and second load cannot be reordered,
  • processor 3’s first and second load cannot be reordered.
  • If r1 == 1 and r2 == 0, processor 0’s store appears to precede processor 1’s store with respect to processor 2.
  • Similarly, r3 == 1 and r4 == 0 imply that processor 1’s store appears to precede processor 0’s store with respect to processor 1.

Because the memory-ordering model ensures that any two stores appear to execute in the same order to all processors (other than those performing the stores), this set of return values is not allowed

8.2.3.8 Locked Instructions Have a Total Order

The memory-ordering model ensures that all processors agree on a single execution order of all locked instructions, including those that are larger than 8 bytes or are not naturally aligned. This is illustrated by the following example:

Example 8-8. Locked Instructions Have a Total Order

Processor 0 Processor 1 Processor 2 Processor 3

xchg [ _x], r1 xchg [ _y], r2

mov r3, [ _x] mov r5, [_y]

mov r4, [ _y] mov r6, [_x]

Initially r1 == r2 == 1, x == y == 0

r3 == 1, r4 == 0, r5 == 1, r6 == 0 is not allowed

  • Processor 2 and processor 3 must agree on the order of the two executions of XCHG. Without loss of generality, suppose that processor 0’s XCHG occurs first.
  • If r5 == 1, processor 1’s XCHG into y occurs before processor 3’s load from y.
  • Because the Intel-64 memory-ordering model prevents loads from being reordered (see Section 8.2.3.2), processor 3’s loads occur in order and, therefore, processor 1’s XCHG occurs before processor 3’s load from x.
  • Since processor 0’s XCHG into x occurs before processor 1’s XCHG (by assumption), it occurs before processor 3’s load from x. Thus, r6 == 1.

A similar argument (referring instead to processor 2’s loads) applies if processor 1’s XCHG occurs before processor 0’s XCHG.

8.2.3.9 Loads and Stores Are Not Reordered with Locked Instructions

The memory-ordering model prevents loads and stores from being reordered with locked instructions that execute earlier or later. The examples in this section illustrate only cases in which a locked instruction is executed before a load or a store. The

Page 323 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 323 · click to enlarge
Page 323

MULTIPLE-PROCESSOR MANAGEMENT

reader should note that reordering is prevented also if the locked instruction is executed after a load or a store.

The first example illustrates that loads may not be reordered with earlier locked instructions:

Example 8-9. Loads Are not Reordered with Locks

Processor 0 Processor 1

xchg [ _x], r1 xchg [ _y], r3

mov r2, [ _y] mov r4, [ _x]

Initially x == y == 0, r1 == r3 == 1

r2 == 0 and r4 == 0 is not allowed

As explained in Section 8.2.3.8, there is a total order of the executions of locked instructions. Without loss of generality, suppose that processor 0’s XCHG occurs first.

Because the Intel-64 memory-ordering model prevents processor 1’s load from being reordered with its earlier XCHG, processor 0’s XCHG occurs before processor 1’s load. This implies r4 == 1.

A similar argument (referring instead to processor 2’s accesses) applies if processor 1’s XCHG occurs before processor 0’s XCHG.

The second example illustrates that a store may not be reordered with an earlier locked instruction:

Example 8-10. Stores Are not Reordered with Locks

Processor 0 Processor 1

xchg [ _x], r1 mov r2, [ _y]

mov [ _y], 1 mov r3, [ _x]

Initially x == y == 0, r1 == 1

r2 == 1 and r3 == 0 is not allowed

  • Assume r2 == 1.
  • Because r2 == 1, processor 0’s store to y occurs before processor 1’s load from y.
  • Because the memory-ordering model prevents a store from being reordered with an earlier locked instruction, processor 0’s XCHG into x occurs before its store to y. Thus, processor 0’s XCHG into x occurs before processor 1’s load from y.
  • Because the memory-ordering model prevents loads from being reordered (see Section 8.2.3.2), processor 1’s loads occur in order and, therefore, processor 1’s XCHG into x occurs before processor 1’s load from x. Thus, r3 == 1.
Page 324 of the Intel 253668-032US user manual — NOTE
Page 324 · click to enlarge
Page 324

MULTIPLE-PROCESSOR MANAGEMENT

8.2.4 Out-of-Order Stores For String Operations

The Intel Core 2 Duo, Intel Core, Pentium 4, and P6 family processors modify the processors operation during the string store operations (initiated with the MOVS and STOS instructions) to maximize performance. Once the “fast string” operations initial conditions are met (as described below), the processor will essentially operate on, from an external perspective, the string in a cache line by cache line mode. This results in the processor looping on issuing a cache-line read for the source address and an invalidation on the external bus for the destination address, knowing that all bytes in the destination cache line will be modified, for the length of the string. In this mode interrupts will only be accepted by the processor on cache line boundaries. It is possible in this mode that the destination line invalidations, and therefore stores, will be issued on the external bus out of order.

Code dependent upon sequential store ordering should not use the string operations for the entire data structure to be stored. Data and semaphores should be separated. Order dependent code should use a discrete semaphore uniquely stored to after any string operations to allow correctly ordered data to be seen by all processors.

“Fast string” operation can be disabled by clearing the fast-string-enable bit (bit 0) of IA32_MISC_ENABLES MSR.

  • Initial conditions for “fast string” operations are implementation specific. Example conditions include:
  • EDI and ESI must be 8-byte aligned for the Pentium III processor. EDI must be 8byte aligned for the Pentium 4 processor.
  • String operation must be performed in ascending address order.
  • The initial operation counter (ECX) must be equal to or greater than 64.
  • Source and destination must not overlap by less than a cache line (64 bytes, for Intel Core 2 Duo, Intel Core, Pentium M, and Pentium 4 processors; 32 bytes P6 family and Pentium processors).
  • The memory type for both source and destination addresses must be either WB or WC.

NOTE

Initial conditions for “fast string“ operation in future Intel 64 or IA-32 processor fami lies may differ from above.

8.2.4.1 Memory-Ordering Model for String Operations on Write-back (WB) Memory

This section deals with the memory-ordering model for string operations on write- back (WB) memory for the Intel 64 architecture.

The memory-ordering model respects the follow principles:

1. Stores within a single string operation may be executed out of order.
Page 325 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 325 · click to enlarge
Page 325

MULTIPLE-PROCESSOR MANAGEMENT

2. Stores from separate string operations (for example, stores from consecutive string operations) do not execute out of order. All the stores from an earlier string operation will complete before any store from a later string operation.
3. String operations are not reordered with other store operations.

Fast string operations (e.g. string operations initiated with the MOVS/STOS instruc tions and the REP prefix) may be interrupted by exceptions or interrupts. The inter rupts are precise but may be delayed - for example, the interruptions may be taken at cache line boundaries, after every few iterations of the loop, or after operating on every few bytes. Different implementations may choose different options, or may even choose not to delay interrupt handling, so software should not rely on the delay. When the interrupt/trap handler is reached, the source/destination registers point to the next string element to be operated on, while the EIP stored in the stack points to the string instruction, and the ECX register has the value it held following the last successful iteration. The return from that trap/interrupt handler should cause the string instruction to be resumed from the point where it was interrupted.

The string operation memory-ordering principles, (item 2 and 3 above) should be interpreted by taking the incorruptibility of fast string operations into account. For example, if a fast string operation gets interrupted after k iterations, then stores performed by the interrupt handler will become visible after the fast string stores from iteration 0 to k, and before the fast string stores from the (k+1)th iteration onward.

Stores within a single string operation may execute out of order (item 1 above) only if fast string operation is enabled. Fast string operations are enabled/disabled through the IA32_MISC_ENABLE model specific register.

8.2.4.2 Examples Illustrating Memory-Ordering Principles for String Operations

The following examples uses the same notation and convention as described in Section 8.2.3.1.

In Example 8-11, processor 0 does one round of (128 iterations) doubleword string store operation via rep:stosd, writing the value 1 (value in EAX) into a block of 512 bytes from location _x (kept in ES:EDI) in ascending order. Since each operation stores a doubleword (4 bytes), the operation is repeated 128 times (value in ECX). The block of memory initially contained 0. Processor 1 is reading two memory loca tions that are part of the memory block being updated by processor 0, i.e, reading locations in the range _x to (_x+511).

Example 8-11. Stores Within a String Operation May be Reordered

Processor 0 Processor 1

rep:stosd [ _x] mov r1, [ _z]

mov r2, [ _y]

Page 326 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 326 · click to enlarge
Page 326

MULTIPLE-PROCESSOR MANAGEMENT

Example 8-11. Stores Within a String Operation May be Reordered

Processor 0 Processor 1

Initially on processor 0EAX == 1, ECX==128, ES:EDI ==_x

Initially [_x] to 511[_x]== 0, _x

r1 == 1 and r2 == 0 is allowed

It is possible for processor 1 to perceive that the repeated string stores in processor 0 are happening out of order. We assume that fast string operations are enabled on processor 0.

In Example 8-12, processor 0 does two separate rounds of rep stosd operation of 128 doubleword stores, writing the value 1 (value in EAX) into the first block of 512 bytes from location _x (kept in ES:EDI) in ascending order. It then writes 1 into a second block of memory from (_x+512) to (_x+1023). All of the memory locations initially contain 0. The block of memory initially contained 0. Processor 1 performs two load operations from the two blocks of memory.

Example 8-12. Stores Across String Operations Are not Reordered

Processor 0 Processor 1

rep:stosd [ _x]

mov r1, [ _z]

mov r2, [ _y]

rep:stosd 512[ _x]

Initially on processor 0EAX == 1, ECX==128, ES:EDI ==_x

Initially [_x] to 1023[_x]== 0, _x

r1 == 1 and r2 == 0 is not allowed

It is not possible in the above example for processor 1 to perceive any of the stores from the later string operation (to the second 512 block) in processor 0 before seeing the stores from the earlier string operation to the first 512 block.

The above example assumes that writes to the second block (_x+512 to _x+1023) does not get executed while processor 0’s string operation to the first block has been interrupted. If the string operation to the first block by processor 0 is interrupted, and a write to the second memory block is executed by the interrupt handler, then that change in the second memory block will be visible before the string operation to the first memory block resumes.

In Example 8-13, processor 0 does one round of (128 iterations) doubleword string store operation via rep:stosd, writing the value 1 (value in EAX) into a block of 512 bytes from location _x (kept in ES:EDI) in ascending order. It then writes to a second memory location outside the memory block of the previous string operation.

mov ecx, $128

Page 327 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 327 · click to enlarge
Page 327

MULTIPLE-PROCESSOR MANAGEMENT

Processor 1 performs two read operations, the first read is from an address outside the 512-byte block but to be updated by processor 0, the second ready is from inside the block of memory of string operation.

Example 8-13. String Operations Are not Reordered with later Stores

Processor 0 Processor 1

rep:stosd [ _x] mov r1, [ _z]

mov [_z], $1 mov r2, [ _y]

Initially on processor 0EAX == 1, ECX==128, ES:EDI ==_x

Initially [_y] == [_z] == 0, [_x] to 511[_x]== 0, _x

r1 == 1 and r2 == 0 is not allowed

Processor 1 cannot perceive the later store by processor 0 until it sees all the stores from the string operation. Example 8-13 assumes that processor 0’s store to [_z] is not executed while the string operation has been interrupted. If the string operation is interrupted and the store to [_z] by processor 0 is executed by the interrupt handler, then changes to [_z] will become visible before the string operation resumes.

Example 8-14 illustrates the visibility principle when a string operation is interrupted.

Example 8-14. Interrupted String Operation

Processor 0 Processor 1

rep:stosd [ _x] // interrupted before es:edi reach _y

mov r1, [ _z]

mov [_z], $1 // interrupt handler mov r2, [ _y]

Initially on processor 0EAX == 1, ECX==128, ES:EDI ==_x

Initially [_y] == [_z] == 0, [_x] to 511[_x]== 0, _x

r1 == 1 and r2 == 0 is allowed

In Example 8-14, processor 0 started a string operation to write to a memory block of 512 bytes starting at address _x. Processor 0 got interrupted after k iterations of store operations. The address _y has not yet been updated by processor 0 when processor 0 got interrupted. The interrupt handler that took control on processor 0 writes to the address _z. Processor 1 may see the store to _z from the interrupt handler, before seeing the remaining stores to the 512-byte memory block that are executed when the string operation resumes.

Example 8-15 illustrates the ordering of string operations with earlier stores. No store from a string operation can be visible before all prior stores are visible.

Page 328 of the Intel 253668-032US user manual — 8.2.5 Strengthening or Weakening the Memory-Ordering Model
Page 328 · click to enlarge
Page 328

MULTIPLE-PROCESSOR MANAGEMENT

Example 8-15. String Operations Are not Reordered with Earlier Stores

Processor 0 Processor 1

mov [_z], $1 mov r1, [ _y]

rep:stosd [ _x] mov r2, [ _z]

Initially on processor 0EAX == 1, ECX==128, ES:EDI ==_x

Initially [_y] == [_z] == 0, [_x] to 511[_x]== 0, _x

r1 == 1 and r2 == 0 is not allowed

8.2.5 Strengthening or Weakening the Memory-Ordering Model

  • The Intel 64 and IA-32 architectures provide several mechanisms for strengthening or weakening the memory-ordering model to handle special programming situations. These mechanisms include:
  • The I/O instructions, locking instructions, the LOCK prefix, and serializing instructions force stronger ordering on the processor.
  • The SFENCE instruction (introduced to the IA-32 architecture in the Pentium III processor) and the LFENCE and MFENCE instructions (introduced in the Pentium 4 processor) provide memory-ordering and serialization capabilities for specific types of memory operations.
  • The memory type range registers (MTRRs) can be used to strengthen or weaken memory ordering for specific area of physical memory (see Section 11.11, “Memory Type Range Registers (MTRRs)”). MTRRs are available only in the Pentium 4, Intel Xeon, and P6 family processors.
  • The page attribute table (PAT) can be used to strengthen memory ordering for a specific page or group of pages (see Section 11.12, “Page Attribute Table (PAT)”). The PAT is available only in the Pentium 4, Intel Xeon, and Pentium III processors.

These mechanisms can be used as follows:

Memory mapped devices and other I/O devices on the bus are often sensitive to the order of writes to their I/O buffers. I/O instructions can be used to (the IN and OUT instructions) impose strong write ordering on such accesses as follows. Prior to executing an I/O instruction, the processor waits for all previous instructions in the program to complete and for all buffered writes to drain to memory. Only instruction fetch and page tables walks can pass I/O instructions. Execution of subsequent instructions do not begin until the processor determines that the I/O instruction has been completed.

Synchronization mechanisms in multiple-processor systems may depend upon a strong memory-ordering model. Here, a program can use a locking instruction such

Page 329 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 329 · click to enlarge
Page 329

MULTIPLE-PROCESSOR MANAGEMENT

as the XCHG instruction or the LOCK prefix to insure that a read-modify-write opera tion on memory is carried out atomically. Locking operations typically operate like I/O operations in that they wait for all previous instructions to complete and for all buffered writes to drain to memory (see Section 8.1.2, “Bus Locking”).

Program synchronization can also be carried out with serializing instructions (see Section 8.3). These instructions are typically used at critical procedure or task boundaries to force completion of all previous instructions before a jump to a new section of code or a context switch occurs. Like the I/O and locking instructions, the processor waits until all previous instructions have been completed and all buffered writes have been drained to memory before executing the serializing instruction.

  • The SFENCE, LFENCE, and MFENCE instructions provide a performance-efficient way of insuring load and store memory ordering between routines that produce weaklyordered results and routines that consume that data. The functions of these instruc tions are as follows:
  • SFENCE — Serializes all store (write) operations that occurred prior to the SFENCE instruction in the program instruction stream, but does not affect load operations.
  • LFENCE — Serializes all load (read) operations that occurred prior to the LFENCE instruction in the program instruction stream, but does not affect store operations.
  • MFENCE — Serializes all store and load operations that occurred prior to the MFENCE instruction in the program instruction stream.
  • The MTRRs were introduced in the P6 family processors to define the cache charac teristics for specified areas of physical memory. The following are two examples of how memory types set up with MTRRs can be used strengthen or weaken memory ordering for the Pentium 4, Intel Xeon, and P6 family processors:
  • The strong uncached (UC) memory type forces a strong-ordering model on memory accesses. Here, all reads and writes to the UC memory region appear on the bus and out-of-order or speculative accesses are not performed. This memory type can be applied to an address range dedicated to memory mapped I/O devices to force strong memory ordering.
  • For areas of memory where weak ordering is acceptable, the write back (WB) memory type can be chosen. Here, reads can be performed speculatively and writes can be buffered and combined. For this type of memory, cache locking is performed on atomic (locked) operations that do not split across cache lines, which helps to reduce the performance penalty associated with the use of the typical synchronization instructions, such as XCHG, that lock the bus during the entire read-modify-write operation. With the WB memory type, the XCHG instruction locks the cache instead of the bus if the memory access is contained within a cache line.
Page 330 of the Intel 253668-032US user manual — 8.3 SERIALIZING INSTRUCTIONS
Page 330 · click to enlarge
Page 330

MULTIPLE-PROCESSOR MANAGEMENT

The PAT was introduced in the Pentium III processor to enhance the caching charac teristics that can be assigned to pages or groups of pages. The PAT mechanism typi cally used to strengthen caching characteristics at the page level with respect to the caching characteristics established by the MTRRs. Table 11-7 shows the interaction of the PAT with the MTRRs.

We recommended that software written to run on Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium 4, Intel Xeon, and P6 family processors assume the processor- ordering model or a weaker memory-ordering model. The Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium 4, Intel Xeon, and P6 family processors do not imple ment a strong memory-ordering model, except when using the UC memory type. Despite the fact that Pentium 4, Intel Xeon, and P6 family processors support processor ordering, Intel does not guarantee that future processors will support this model. To make software portable to future processors, it is recommended that oper ating systems provide critical region and resource control constructs and API’s (appli cation program interfaces) based on I/O, locking, and/or serializing instructions be used to synchronize access to shared areas of memory in multiple-processor systems. Also, software should not depend on processor ordering in situations where the system hardware does not support this memory-ordering model.

8.3 SERIALIZING INSTRUCTIONS

The Intel 64 and IA-32 architectures define several serializing instructions. These instructions force the processor to complete all modifications to flags, registers, and memory by previous instructions and to drain all buffered writes to memory before the next instruction is fetched and executed. For example, when a MOV to control register instruction is used to load a new value into control register CR0 to enable protected mode, the processor must perform a serializing operation before it enters protected mode. This serializing operation insures that all operations that were started while the processor was in real-address mode are completed before the switch to protected mode is made.

The concept of serializing instructions was introduced into the IA-32 architecture with the Pentium processor to support parallel instruction execution. Serializing instructions have no meaning for the Intel486 and earlier processors that do not implement parallel instruction execution.

It is important to note that executing of serializing instructions on P6 and more recent processor families constrain speculative execution because the results of speculatively executed instructions are discarded. The following instructions are seri alizing instructions: • Privileged serializing instructions — INVD, INVEPT, INVLPG, INVVPID, LGDT, LIDT, LLDT, LTR, MOV (to control register, with the exception of MOV CR81), MOV (to debug register), WBINVD, and WRMSR.

1. MOV CR8 is not defined architecturally as a serializing instruction.
Page 331 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 331 · click to enlarge
Page 331

MULTIPLE-PROCESSOR MANAGEMENT

  • Non-privileged serializing instructions — CPUID, IRET, and RSM.

When the processor serializes instruction execution, it ensures that all pending memory transactions are completed (including writes stored in its store buffer) before it executes the next instruction. Nothing can pass a serializing instruction and a serializing instruction cannot pass any other instruction (read, write, instruction fetch, or I/O). For example, CPUID can be executed at any privilege level to serialize instruction execution with no effect on program flow, except that the EAX, EBX, ECX, and EDX registers are modified.

The following instructions are memory-ordering instructions, not serializing instruc tions. These drain the data memory subsystem. They do not effect the instruction execution stream: • Non-privileged memory-ordering instructions — SFENCE, LFENCE, and MFENCE.

The SFENCE, LFENCE, and MFENCE instructions provide more granularity in control ling the serialization of memory loads and stores (see Section 8.2.5, “Strengthening or Weakening the Memory-Ordering Model”).

  • The following additional information is worth noting regarding serializing instruc tions:
  • The processor does not writeback the contents of modified data in its data cache to external memory when it serializes instruction execution. Software can force modified data to be written back by executing the WBINVD instruction, which is a serializing instruction. The amount of time or cycles for WBINVD to complete will vary due to the size of different cache hierarchies and other factors. As a conse quence, the use of the WBINVD instruction can have an impact on interrupt/event response time.
  • When an instruction is executed that enables or disables paging (that is, changes the PG flag in control register CR0), the instruction should be followed by a jump instruction. The target instruction of the jump instruction is fetched with the new setting of the PG flag (that is, paging is enabled or disabled), but the jump instruction itself is fetched with the previous setting. The Pentium 4, Intel Xeon, and P6 family processors do not require the jump operation following the move to register CR0 (because any use of the MOV instruction in a Pentium 4, Intel Xeon, or P6 family processor to write to CR0 is completely serializing). However, to maintain backwards and forward compatibility with code written to run on other IA-32 processors, it is recommended that the jump operation be performed.
  • Whenever an instruction is executed to change the contents of CR3 while paging is enabled, the next instruction is fetched using the translation tables that correspond to the new value of CR3. Therefore the next instruction and the sequentially following instructions should have a mapping based upon the new value of CR3. (Global entries in the TLBs are not invalidated, see Section 4.10.3, “Invalidation of TLBs and Paging-Structure Caches.”)
  • The Pentium processor and more recent processor families use branch-prediction techniques to improve performance by prefetching the destination of a branch instruction before the branch instruction is executed. Consequently, instruction
Page 332 of the Intel 253668-032US user manual — 8.4 MULTIPLE-PROCESSOR (MP) INITIALIZATION
Page 332 · click to enlarge
Page 332

MULTIPLE-PROCESSOR MANAGEMENT

execution is not deterministically serialized when a branch instruction is executed.

8.4 MULTIPLE-PROCESSOR (MP) INITIALIZATION

  • The IA-32 architecture (beginning with the P6 family processors) defines a multipleprocessor (MP) initialization protocol called the Multiprocessor Specification Version 1.4 . This specification defines the boot protocol to be used by IA-32 processors in multiple-processor systems. (Here, multiple processors is defined as two or more processors.) The MP initialization protocol has the following important features:
  • It supports controlled booting of multiple processors without requiring dedicated system hardware.
  • It allows hardware to initiate the booting of a system without the need for a dedicated signal or a predefined boot processor.
  • It allows all IA-32 processors to be booted in the same manner, including those supporting Intel Hyper-Threading Technology.
  • The MP initialization protocol also applies to MP systems using Intel 64 processors.
  • The mechanism for carrying out the MP initialization protocol differs depending on the IA-32 processor family, as follows:
  • For P6 family processors — The selection of the BSP and APs (see Section 8.4.1, “BSP and AP Processors”) is handled through arbitration on the APIC bus, using BIPI and FIPI messages. See Appendix C, “MP Initialization For P6 Family Processors,” for a complete discussion of MP initialization for P6 family processors.
  • Intel Xeon processors with family, model, and stepping IDs up to F09H — The selection of the BSP and APs (see Section 8.4.1, “BSP and AP Processors”) is handled through arbitration on the system bus, using BIPI and FIPI messages (see Section 8.4.3, “MP Initialization Protocol Algorithm for Intel Xeon Processors”).
  • Intel Xeon processors with family, model, and stepping IDs of F0AH and beyond, 6E0H and beyond, 6F0H and beyond — The selection of the BSP and APs is handled through a special system bus cycle, without using BIPI and FIPI message arbitration (see Section 8.4.3, “MP Initialization Protocol Algorithm for Intel Xeon Processors”).

The family, model, and stepping ID for a processor is given in the EAX register when the CPUID instruction is executed with a value of 1 in the EAX register.

Page 333 of the Intel 253668-032US user manual — 8.4.2 MP Initialization Protocol Requirements and Restrictions
Page 333 · click to enlarge
Page 333

MULTIPLE-PROCESSOR MANAGEMENT

8.4.1 BSP and AP Processors

The MP initialization protocol defines two classes of processors: the bootstrap processor (BSP) and the application processors (APs). Following a power-up or RESET of an MP system, system hardware dynamically selects one of the processors on the system bus as the BSP. The remaining processors are designated as APs.

As part of the BSP selection mechanism, the BSP flag is set in the IA32_APIC_BASE MSR (see Figure 10-5) of the BSP, indicating that it is the BSP. This flag is cleared for all other processors.

The BSP executes the BIOS’s boot-strap code to configure the APIC environment, sets up system-wide data structures, and starts and initializes the APs. When the BSP and APs are initialized, the BSP then begins executing the operating-system initial ization code.

Following a power-up or reset, the APs complete a minimal self-configuration, then wait for a startup signal (a SIPI message) from the BSP processor. Upon receiving a SIPI message, an AP executes the BIOS AP configuration code, which ends with the AP being placed in halt state.

For Intel 64 and IA-32 processors supporting Intel Hyper-Threading Technology, the MP initialization protocol treats each of the logical processors on the system bus or coherent link domain as a separate processor (with a unique APIC ID). During boot- up, one of the logical processors is selected as the BSP and the remainder of the logical processors are designated as APs.

8.4.2 MP Initialization Protocol Requirements and Restrictions

  • The MP initialization protocol imposes the following requirements and restrictions on the system:
  • The MP protocol is executed only after a power-up or RESET. If the MP protocol has completed and a BSP is chosen, subsequent INITs (either to a specific processor or system wide) do not cause the MP protocol to be repeated. Instead, each logical processor examines its BSP flag (in the IA32_APIC_BASE MSR) to determine whether it should execute the BIOS boot-strap code (if it is the BSP) or enter a wait-for-SIPI state (if it is an AP).
  • All devices in the system that are capable of delivering interrupts to the processors must be inhibited from doing so for the duration of the MP initial ization protocol. The time during which interrupts must be inhibited includes the window between when the BSP issues an INIT-SIPI-SIPI sequence to an AP and when the AP responds to the last SIPI in the sequence.
Page 334 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 334 · click to enlarge
Page 334

MULTIPLE-PROCESSOR MANAGEMENT

8.4.3 MP Initialization Protocol Algorithm for Intel Xeon Processors

Following a power-up or RESET of an MP system, the processors in the system execute the MP initialization protocol algorithm to initialize each of the logical proces sors on the system bus or coherent link domain. In the course of executing this algo rithm, the following boot-up and initialization operations are carried out:

1. Each logical processor is assigned a unique APIC ID, based on system topology. The unique ID is a 32-bit value if the processor supports CPUID leaf 0BH, otherwise the unique ID is an 8-bit value. (see Section 8.4.5, “Identifying Logical Processors in an MP System”). This ID is written into the local APIC ID register for each processor.
2. Each logical processor is assigned a unique arbitration priority based on its APIC ID.
3. Each logical processor executes its internal BIST simultaneously with the other logical processors on the system bus.
4. Upon completion of the BIST, the logical processors use a hardware-defined selection mechanism to select the BSP and the APs from the available logical processors on the system bus. The BSP selection mechanism differs depending on the family, model, and stepping IDs of the processors, as follows:
  • — Family, model, and stepping IDs of F0AH and onwards:
  • The logical processors begin monitoring the BNR# signal, which is toggling. When the BNR# pin stops toggling, each processor attempts to issue a NOP special cycle on the system bus.
  • The logical processor with the highest arbitration priority succeeds in issuing a NOP special cycle and is nominated the BSP. This processor sets the BSP flag in its IA32_APIC_BASE MSR, then fetches and begins executing BIOS boot-strap code, beginning at the reset vector (physical address FFFF FFF0H).
  • The remaining logical processors (that failed in issuing a NOP special cycle) are designated as APs. They leave their BSP flags in the clear state and enter a “wait-for-SIPI state.”
  • — Family, model, and stepping IDs up to F09H:
  • Each processor broadcasts a BIPI to “all including self.” The first processor that broadcasts a BIPI (and thus receives its own BIPI vector), selects itself as the BSP and sets the BSP flag in its IA32_APIC_BASE MSR. (See Appendix C.1, “Overview of the MP Initialization Process For P6 Family Processors,” for a description of the BIPI, FIPI, and SIPI messages.)
  • The remainder of the processors (which were not selected as the BSP) are designated as APs. They leave their BSP flags in the clear state and enter a “wait-for-SIPI state.”
Page 335 of the Intel 253668-032US user manual — ICR_LOW EQU 0FEE00300H
Page 335 · click to enlarge
Page 335

MULTIPLE-PROCESSOR MANAGEMENT

  • The newly established BSP broadcasts an FIPI message to “all including self,” which the BSP and APs treat as an end of MP initialization signal. Only the processor with its BSP flag set responds to the FIPI message. It responds by fetching and executing the BIOS boot-strap code, beginning at the reset vector (physical address FFFF FFF0H).
5. As part of the boot-strap code, the BSP creates an ACPI table and an MP table and adds its initial APIC ID to these tables as appropriate.
6. At the end of the boot-strap procedure, the BSP sets a processor counter to 1, then broadcasts a SIPI message to all the APs in the system. Here, the SIPI message contains a vector to the BIOS AP initialization code (at 000VV000H, where VV is the vector contained in the SIPI message).

7. The first action of the AP initialization code is to set up a race (among the APs) to a BIOS initialization semaphore. The first AP to the semaphore begins executing the initialization code. (See Section 8.4.4, “MP Initialization Example,” for semaphore implementation details.) As part of the AP initialization procedure, the AP adds its APIC ID number to the ACPI and MP tables as appropriate and increments the processor counter by 1. At the completion of the initialization procedure, the AP executes a CLI instruction and halts itself.

8. When each of the APs has gained access to the semaphore and executed the AP initialization code, the BSP establishes a count for the number of processors connected to the system bus, completes executing the BIOS boot-strap code, and then begins executing operating-system boot-strap and start-up code.
9. While the BSP is executing operating-system boot-strap and start-up code, the APs remain in the halted state. In this state they will respond only to INITs, NMIs, and SMIs. They will also respond to snoops and to assertions of the STPCLK# pin.

The following section gives an example (with code) of the MP initialization protocol for multiple Intel Xeon processors operating in an MP configuration.

Appendix B, “Model-Specific Registers (MSRs),” describes how to program the LINT[0:1] pins of the processor’s local APICs after an MP configuration has been completed.

8.4.4 MP Initialization Example

The following example illustrates the use of the MP initialization protocol used to initialize processors in an MP system after the BSP and APs have been established. The code runs on Intel 64 or IA-32 processors that use a protocol. This includes P6 Family processors, Pentium 4 processors, Intel Core Duo, Intel Core 2 Duo and Intel Xeon processors.

The following constants and data definitions are used in the accompanying code examples. They are based on the addresses of the APIC registers defined in Table 10-1.

ICR_LOW EQU 0FEE00300H

Page 336 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 336 · click to enlarge
Page 336

MULTIPLE-PROCESSOR MANAGEMENT

SVR EQU 0FEE000F0H APIC_ID EQU 0FEE00020H LVT3 EQU 0FEE00370H APIC_ENABLED EQU 0100H BOOT_ID DD ? COUNT EQU 00H VACANT EQU 00H

8.4.4.1 Typical BSP Initialization Sequence

After the BSP and APs have been selected (by means of a hardware protocol, see Section 8.4.3, “MP Initialization Protocol Algorithm for Intel Xeon Processors”), the BSP begins executing BIOS boot-strap code (POST) at the normal IA-32 architecture starting address (FFFF FFF0H). The boot-strap code typically performs the following operations:

1. Initializes memory.
2. Loads the microcode update into the processor.
3. Initializes the MTRRs.
4. Enables the caches.
5. Executes the CPUID instruction with a value of 0H in the EAX register, then reads the EBX, ECX, and EDX registers to determine if the BSP is “GenuineIntel.”
6. Executes the CPUID instruction with a value of 1H in the EAX register, then saves the values in the EAX, ECX, and EDX registers in a system configuration space in RAM for use later.
7. Loads start-up code for the AP to execute into a 4-KByte page in the lower 1 MByte of memory.
8. Switches to protected mode and insures that the APIC address space is mapped to the strong uncacheable (UC) memory type.
9. Determine the BSP’s APIC ID from the local APIC ID register (default is 0), the code snippet below is an example that applies to logical processors in a system whose local APIC units operate in xAPIC mode that APIC registers are accessed using memory mapped interface:

MOV ESI, APIC_ID; Address of local APIC ID register MOV EAX, [ESI]; AND EAX, 0FF000000H; Zero out all other bits except APIC ID MOV BOOT_ID, EAX; Save in memory

Saves the APIC ID in the ACPI and MP tables and optionally in the system config- uration space in RAM.

10. Converts the base address of the 4-KByte page for the AP’s bootup code into 8-bit vector. The 8-bit vector defines the address of a 4-KByte page in the real-address
Page 337 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 337 · click to enlarge
Page 337

MULTIPLE-PROCESSOR MANAGEMENT

mode address space (1-MByte space). For example, a vector of 0BDH specifies a start-up memory address of 000BD000H.

11. Enables the local APIC by setting bit 8 of the APIC spurious vector register (SVR).

MOV ESI, SVR; Address of SVR MOV EAX, [ESI]; OR EAX, APIC_ENABLED; Set bit 8 to enable (0 on reset) MOV [ESI], EAX;

12. Sets up the LVT error handling entry by establishing an 8-bit vector for the APIC error handler.

MOV ESI, LVT3; MOV EAX, [ESI]; AND EAX, FFFFFF00H; Clear out previous vector. OR EAX, 000000xxH; xx is the 8-bit vector the APIC error handler. MOV [ESI], EAX;

13. Initializes the Lock Semaphore variable VACANT to 00H. The APs use this semaphore to determine the order in which they execute BIOS AP initialization code.
14. Performs the following operation to set up the BSP to detect the presence of APs in the system and the number of processors:

— Sets the value of the COUNT variable to 1.

— Starts a timer (set for an approximate interval of 100 milliseconds). In the AP BIOS initialization code, the AP will increment the COUNT variable to indicate its presence. When the timer expires, the BSP checks the value of the COUNT variable. If the timer expires and the COUNT variable has not been incre mented, no APs are present or some error has occurred.

15. Broadcasts an INIT-SIPI-SIPI IPI sequence to the APs to wake them up and initialize them:

MOV ESI, ICR_LOW; Load address of ICR low dword into ESI. MOV EAX, 000C4500H; Load ICR encoding for broadcast INIT IPI ; to all APs into EAX. MOV [ESI], EAX; Broadcast INIT IPI to all APs ; 10-millisecond delay loop. MOV EAX, 000C46XXH; Load ICR encoding for broadcast SIPI IP ; to all APs into EAX, where xx is the vector computed in step 10. MOV [ESI], EAX; Broadcast SIPI IPI to all APs ; 200-microsecond delay loop MOV [ESI], EAX; Broadcast second SIPI IPI to all APs ; 200-microsecond delay loop

Step 15:

Page 338 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 338 · click to enlarge
Page 338

MULTIPLE-PROCESSOR MANAGEMENT

MOV EAX, 000C46XXH; Load ICR encoding from broadcast SIPI IP ; to all APs into EAX where xx is the vector computed in step 8.

16. Waits for the timer interrupt.
17. Reads and evaluates the COUNT variable and establishes a processor count.
18. If necessary, reconfigures the APIC and continues with the remaining system diagnostics as appropriate.

8.4.4.2 Typical AP Initialization Sequence

When an AP receives the SIPI, it begins executing BIOS AP initialization code at the vector encoded in the SIPI. The AP initialization code typically performs the following operations:

1. Waits on the BIOS initialization Lock Semaphore. When control of the semaphore is attained, initialization continues.
2. Loads the microcode update into the processor.
3. Initializes the MTRRs (using the same mapping that was used for the BSP).
4. Enables the cache.
5. Executes the CPUID instruction with a value of 0H in the EAX register, then reads the EBX, ECX, and EDX registers to determine if the AP is “GenuineIntel.”
6. Executes the CPUID instruction with a value of 1H in the EAX register, then saves the values in the EAX, ECX, and EDX registers in a system configuration space in RAM for use later.
7. Switches to protected mode and insures that the APIC address space is mapped to the strong uncacheable (UC) memory type.
8. Determines the AP’s APIC ID from the local APIC ID register, and adds it to the MP and ACPI tables and optionally to the system configuration space in RAM.
9. Initializes and configures the local APIC by setting bit 8 in the SVR register and setting up the LVT3 (error LVT) for error handling (as described in steps 9 and 10 in Section 8.4.4.1, “Typical BSP Initialization Sequence”).
10. Configures the APs SMI execution environment. (Each AP and the BSP must have a different SMBASE address.)
11. Increments the COUNT variable by 1.
12. Releases the semaphore.
13. Executes the CLI and HLT instructions.
14. Waits for an INIT IPI.
Page 339 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 339 · click to enlarge
Page 339

MULTIPLE-PROCESSOR MANAGEMENT

8.4.5 Identifying Logical Processors in an MP System

After the BIOS has completed the MP initialization protocol, each logical processor can be uniquely identified by its local APIC ID. Software can access these APIC IDs in either of the following ways: • Read APIC ID for a local APIC — Code running on a logical processor can read APIC ID in one of two ways depending on the local APIC unit is operating in x2APIC mode (see Intel® 64 Architecture x2APIC Specification)or in xAPIC mode:

— If the local APIC unit supports x2APIC and is operating in x2APIC mode, 32- bit APIC ID can be read by executing a RDMSR instruction to read the processor’s x2APIC ID register. This method is equivalent to executing CPUID leaf 0BH described below.

  • — If the local APIC unit is operating in xAPIC mode, 8-bit APIC ID can be read by executing a MOV instruction to read the processor’s local APIC ID register (see Section 10.4.6, “Local APIC ID”). This is the ID to use for directing physical destination mode interrupts to the processor.
  • Read ACPI or MP table — As part of the MP initialization protocol, the BIOS creates an ACPI table and an MP table. These tables are defined in the Multipro cessor Specification Version 1.4 and provide software with a list of the processors in the system and their local APIC IDs. The format of the ACPI table is derived from the ACPI specification, which is an industry standard power management and platform configuration specification for MP systems.
  • Read Initial APIC ID (If the process does not support CPUID leaf 0BH) — An APIC ID is assigned to a logical processor during power up. This is the initial APIC ID reported by CPUID.1:EBX[31:24] and may be different from the current value read from the local APIC. The initial APIC ID can be used to determine the topological relationship between logical processors for multi-processor systems that do not support CPUID leaf 0BH.

Bits in the 8-bit initial APIC ID can be interpreted using several bit masks. Each bit mask can be used to extract an identifier to represent a hierarchical level of the multi-threading resource topology in an MP system (See Section 8.9.1, “Hierarchical Mapping of Shared Resources”). The initial APIC ID may consist of up to four bit-fields. In a non-clustered MP system, the field consists of up to three bit fields. • Read 32-bit APIC ID from CPUID leaf 0BH (If the processor supports CPUID leaf 0BH) — A unique APIC ID is assigned to a logical processor during power up. This APIC ID is reported by CPUID.0BH:EDX[31:0] as a 32-bit value. Use the 32- bit APIC ID and CPUID leaf 0BH to determine the topological relationship between logical processors if the processor supports CPUID leaf 0BH.

Bits in the 32-bit x2APIC ID can be extracted into sub-fields using CPUID leaf 0BH parameters. (See Section 8.9.1, “Hierarchical Mapping of Shared Resources”).

Figure 8-2 shows two examples of APIC ID bit fields in earlier single-core processors. In single-core Intel Xeon processors, the APIC ID assigned to a logical processor

Page 340 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 340 · click to enlarge
Page 340

MULTIPLE-PROCESSOR MANAGEMENT

during power-up and initialization is 8 bits. Bits 2:1 form a 2-bit physical package identifier (which can also be thought of as a socket identifier). In systems that configure physical processors in clusters, bits 4:3 form a 2-bit cluster ID. Bit 0 is used in the Intel Xeon processor MP to identify the two logical processors within the package (see Section 8.9.3, “Hierarchical ID of Logical Processors in an MP System”). For Intel Xeon processors that do not support Intel Hyper-Threading Technology, bit 0 is always set to 0; for Intel Xeon processors supporting Intel Hyper-Threading Technology, bit 0 performs the same function as it does for Intel Xeon processor MP.

For more recent multi-core processors, see Section 8.9.1, “Hierarchical Mapping of Shared Resources” for a complete description of the topological relationships between logical processors and bit field locations within an initial APIC ID across Intel 64 and IA-32 processor families.

Note the number of bit fields and the width of bit-fields are dependent on processor and platform hardware capabilities. Software should determine these at runtime. When initial APIC IDs are assigned to logical processors, the value of APIC ID assigned to a logical processor will respect the bit-field boundaries corresponding core, physical package, etc. Additional examples of the bit fields in the initial APIC ID of multi-threading capable systems are shown in Section 8.9.

APIC ID Format for Intel Xeon Processors that

do not Support Intel Hyper-Threading Technology

1 7 4 3 2 5

APIC ID Format for P6 Family Processors

1 7 4 3 2

Figure 8-2. Interpretation of APIC ID in Early MP Systems

For P6 family processors, the APIC ID that is assigned to a processor during power- up and initialization is 4 bits (see Figure 8-2). Here, bits 0 and 1 form a 2-bit processor (or socket) identifier and bits 2 and 3 form a 2-bit cluster ID.

Show 6 more labels / short text on this page
Reserved · Cluster · Processor ID · Reserved · Cluster · Processor ID
Page 341 of the Intel 253668-032US user manual — 8.6 DETECTING HARDWARE MULTI-THREADING SUPPORT AND TOPOLOGY
Page 341 · click to enlarge
Page 341

MULTIPLE-PROCESSOR MANAGEMENT

8.5 INTEL ® HYPER-THREADING TECHNOLOGY AND INTEL ® MULTI-CORE TECHNOLOGY

Intel Hyper-Threading Technology and Intel multi-core technology are extensions to Intel 64 and IA-32 architectures that enable a single physical processor to execute two or more separate code streams (called threads) concurrently. In Intel Hyper- Threading Technology, a single processor core provides two logical processors that share execution resources (see Section 8.7, “Intel® Hyper-Threading Technology Architecture”). In Intel multi-core technology, a physical processor package provides two or more processor cores. Both configurations require chipsets and a BIOS that support the technologies.

Software should not rely on processor names to determine whether a processor supports Intel Hyper-Threading Technology or Intel multi-core technology. Use the CPUID instruction to determine processor capability (see Section 8.6.2, “Initializing Multi-Core Processors”).

8.6 DETECTING HARDWARE MULTI-THREADING SUPPORT AND TOPOLOGY

  • Use the CPUID instruction to detect the presence of hardware multi-threading support in a physical processor. Hardware multi-threading can support several vari eties of multigrade and/or Intel Hyper-Threading Technology. CPUID instruction provides several sets of parameter information to aid software enumerating topology information. The relevant topology enumeration parameters provided by CPUID include:
  • Hardware Multi-Threading feature flag (CPUID.1:EDX[28] = 1) — Indicates when set that the physical package is capable of supporting Intel Hyper-Threading Technology and/or multiple cores.
  • Processor topology enumeration parameters for 8-bit APIC ID :

— Addressable IDs for Logical processors in the same Package (CPUID.1:EBX[23:16]) — Indicates the maximum number of addressable ID for logical processors in a physical package. Within a physical package, there may be addressable IDs that are not occupied by any logical processors. This parameter does not represents the hardware capability of the physical processor.2 • Addressable IDs for processor cores in the same Package3 (CPUID.(EAX=4, ECX=04):EAX[31:26] + 1 = Y) — Indicates the maximum

2. Operating system and BIOS may implement features that reduce the number of logical proces sors available in a platform to applications at runtime to less than the number of physical pack ages times the number of hardware-capable logical processors per package.
Page 342 of the Intel 253668-032US user manual — 8.6.1 Initializing Processors Supporting Hyper-Threading Technology
Page 342 · click to enlarge
Page 342

MULTIPLE-PROCESSOR MANAGEMENT

number of addressable IDs attributable to processor cores (Y) in the physical package. • Extended Processor Topology Enumeration parameters for 32-bit APIC ID: Intel 64 processors supporting CPUID leaf 0BH will assign unique APIC IDs to each logical processor in the system. CPUID leaf 0BH reports the 32-bit APIC ID and provide topology enumeration parameters. See CPUID instruction reference pages in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A.

The CPUID feature flag may indicate support for hardware multi-threading when only one logical processor available in the package. In this case, the decimal value repre sented by bits 16 through 23 in the EBX register will have a value of 1.

Software should note that the number of logical processors enabled by system soft ware may be less than the value of “Addressable IDs for Logical processors”. Simi larly, the number of cores enabled by system software may be less than the value of “Addressable IDs for processor cores”.

  • Software can detect the availability of the CPUID extended topology enumeration leaf (0BH) by performing two steps:
  • Check maximum input value for basic CPUID information by executing CPUID with EAX= 0. If CPUID.0H:EAX is greater than or equal or 11 (0BH), then proceed to next step,
  • Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero.

If both of the above conditions are true, extended topology enumeration leaf is avail able. Note the presence of CPUID leaf 0BH in a processor does not guarantee support that the local APIC supports x2APIC. If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not supported on that processor.

8.6.1 Initializing Processors Supporting Hyper-Threading Technology

The initialization process for an MP system that contains processors supporting Intel Hyper-Threading Technology is the same as for conventional MP systems (see Section 8.4, “Multiple-Processor (MP) Initialization”). One logical processor in the system is selected as the BSP and other processors (or logical processors) are desig nated as APs. The initialization process is identical to that described in Section 8.4.3, “MP Initialization Protocol Algorithm for Intel Xeon Processors,” and Section 8.4.4, “MP Initialization Example.”

3. Software must check CPUID for its support of leaf 4 when implementing support for multi-core. If CPUID leaf 4 is not available at runtime, software should handle the situation as if there is only one core per package.
4. Maximum number of cores in the physical package must be queried by executing CPUID with EAX=4 and a valid ECX input value. Valid ECX input values start from 0.
Page 343 of the Intel 253668-032US user manual — 8.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threading
Page 343 · click to enlarge
Page 343

MULTIPLE-PROCESSOR MANAGEMENT

During initialization, each logical processor is assigned an APIC ID that is stored in the local APIC ID register for each logical processor. If two or more processors supporting Intel Hyper-Threading Technology are present, each logical processor on the system bus is assigned a unique ID (see Section 8.9.3, “Hierarchical ID of Logical Processors in an MP System”). Once logical processors have APIC IDs, software communicates with them by sending APIC IPI messages.

8.6.2 Initializing Multi-Core Processors

The initialization process for an MP system that contains multi-core Intel 64 or IA-32 processors is the same as for conventional MP systems (see Section 8.4, “Multiple- Processor (MP) Initialization”). A logical processor in one core is selected as the BSP; other logical processors are designated as APs.

During initialization, each logical processor is assigned an APIC ID. Once logical processors have APIC IDs, software may communicate with them by sending APIC IPI messages.

8.6.3 Executing Multiple Threads on an Intel® 64 or IA-32 Processor Supporting Hardware Multi-Threading

Upon completing the operating system boot-up procedure, the bootstrap processor (BSP) executes operating system code. Other logical processors are placed in the halt state. To execute a code stream (thread) on a halted logical processor, the oper ating system issues an interprocessor interrupt (IPI) addressed to the halted logical processor. In response to the IPI, the processor wakes up and begins executing the thread identified by the interrupt vector received as part of the IPI.

To manage execution of multiple threads on logical processors, an operating system can use conventional symmetric multiprocessing (SMP) techniques. For example, the operating-system can use a time-slice or load balancing mechanism to periodically interrupt each of the active logical processors. Upon interrupting a logical processor, the operating system checks its run queue for a thread waiting to be executed and dispatches the thread to the interrupted logical processor.

8.6.4 Handling Interrupts on an IA-32 Processor Supporting Hardware Multi-Threading

Interrupts are handled on processors supporting Intel Hyper-Threading Technology as they are on conventional MP systems. External interrupts are received by the I/O APIC, which distributes them as interrupt messages to specific logical processors (see Figure 8-3).

Logical processors can also send IPIs to other logical processors by writing to the ICR register of its local APIC (see Section 10.7, “Issuing Interprocessor Interrupts”). This also applies to dual-core processors.

Page 344 of the Intel 253668-032US user manual — 8.7 INTEL ® HYPER-THREADING TECHNOLOGY ARCHITECTURE
Page 344 · click to enlarge
Page 344

MULTIPLE-PROCESSOR MANAGEMENT

Intel 253668-032US — MULTIPLE-PROCESSOR MANAGEMENT diagram (page 344)
Fig. 21

Figure 8-3. Local APICs and I/O APIC in MP System Supporting Intel HT Technology

8.7 INTEL ® HYPER-THREADING TECHNOLOGY ARCHITECTURE

Figure 8-4 shows a generalized view of an Intel processor supporting Intel Hyper- Threading Technology, using the original Intel Xeon processor MP as an example. This implementation of the Intel Hyper-Threading Technology consists of two logical processors (each represented by a separate architectural state) which share the processor’s execution engine and the bus interface. Each logical processor also has its own advanced programmable interrupt controller (APIC).

Page 345 of the Intel 253668-032US user manual — 8.7.1 State of the Logical Processors
Page 345 · click to enlarge
Page 345

MULTIPLE-PROCESSOR MANAGEMENT

Logical Processor 0 Architectural

Logical Processor 1 Architectural

Local APIC Local APIC

Figure 8-4. IA-32 Processor with Two Logical Processors Supporting Intel HT

8.7.1 State of the Logical Processors

  • The following features are part of the architectural state of logical processors within Intel 64 or IA-32 processors supporting Intel Hyper-Threading Technology. The features can be subdivided into three groups:
  • Duplicated for each logical processor
  • Shared by logical processors in a physical processor
  • Shared or duplicated, depending on the implementation
  • The following features are duplicated for each logical processor:
  • General purpose registers (EAX, EBX, ECX, EDX, ESI, EDI, ESP, and EBP)
  • Segment registers (CS, DS, SS, ES, FS, and GS)
  • EFLAGS and EIP registers. Note that the CS and EIP/RIP registers for each logical processor point to the instruction stream for the thread being executed by the logical processor.
  • x87 FPU registers (ST0 through ST7, status word, control word, tag word, data operand pointer, and instruction pointer)
  • MMX registers (MM0 through MM7)
  • XMM registers (XMM0 through XMM7) and the MXCSR register
  • Control registers and system table pointer registers (GDTR, LDTR, IDTR, task register)
Show 6 more labels / short text on this page
State · State · Execution Engine · Bus Interface · System Bus · Technology
Page 346 of the Intel 253668-032US user manual — 8.7.3 Memory Type Range Registers (MTRR)
Page 346 · click to enlarge
Page 346

MULTIPLE-PROCESSOR MANAGEMENT

  • Debug registers (DR0, DR1, DR2, DR3, DR6, DR7) and the debug control MSRs
  • Machine check global status (IA32_MCG_STATUS) and machine check capability (IA32_MCG_CAP) MSRs
  • Thermal clock modulation and ACPI Power management control MSRs
  • Time stamp counter MSRs
  • Most of the other MSR registers, including the page attribute table (PAT). See the exceptions below.
  • Local APIC registers.
  • Additional general purpose registers (R8-R15), XMM registers (XMM8-XMM15), control register, IA32_EFER on Intel 64 processors.

The following features are shared by logical processors: • Memory type range registers (MTRRs)

  • Whether the following features are shared or duplicated is implementation-specific:
  • IA32_MISC_ENABLE MSR (MSR address 1A0H)
  • Machine check architecture (MCA) MSRs (except for the IA32_MCG_STATUS and IA32_MCG_CAP MSRs)
  • Performance monitoring control and counter MSRs

8.7.2 APIC Functionality

When a processor supporting Intel Hyper-Threading Technology support is initialized, each logical processor is assigned a local APIC ID (see Table 10-1). The local APIC ID serves as an ID for the logical processor and is stored in the logical processor’s APIC ID register. If two or more processors supporting Intel Hyper-Threading Technology are present in a dual processor (DP) or MP system, each logical processor on the system bus is assigned a unique local APIC ID (see Section 8.9.3, “Hierarchical ID of Logical Processors in an MP System”).

Software communicates with local processors using the APIC’s interprocessor inter rupt (IPI) messaging facility. Setup and programming for APICs is identical in proces sors that support and do not support Intel Hyper-Threading Technology. See Chapter 10, “Advanced Programmable Interrupt Controller (APIC),” for a detailed discussion.

8.7.3 Memory Type Range Registers (MTRR)

MTRRs in a processor supporting Intel Hyper-Threading Technology are shared by logical processors. When one logical processor updates the setting of the MTRRs, settings are automatically shared with the other logical processors in the same phys ical package.

The architectures require that all MP systems based on Intel 64 and IA-32 processors (this includes logical processors) must use an identical MTRR memory map. This

Page 347 of the Intel 253668-032US user manual — 8.7.6 Debug Registers and Extensions
Page 347 · click to enlarge
Page 347

MULTIPLE-PROCESSOR MANAGEMENT

gives software a consistent view of memory, independent of the processor on which it is running. See Section 11.11, “Memory Type Range Registers (MTRRs),” for infor mation on setting up MTRRs.

8.7.4 Page Attribute Table (PAT)

Each logical processor has its own PAT MSR (IA32_PAT). However, as described in Section 11.12, “Page Attribute Table (PAT),” the PAT MSR settings must be the same for all processors in a system, including the logical processors.

8.7.5 Machine Check Architecture

In the Intel HT Technology context as implemented by processors based on Intel NetBurst microarchitecture, all of the machine check architecture (MCA) MSRs (except for the IA32_MCG_STATUS and IA32_MCG_CAP MSRs) are duplicated for each logical processor. This permits logical processors to initialize, configure, query, and handle machine-check exceptions simultaneously within the same physical processor. The design is compatible with machine check exception handlers that follow the guidelines given in Chapter 15, “Machine-Check Architecture.”

The IA32_MCG_STATUS MSR is duplicated for each logical processor so that its machine check in progress bit field (MCIP) can be used to detect recursion on the part of MCA handlers. In addition, the MSR allows each logical processor to deter mine that a machine-check exception is in progress independent of the actions of another logical processor in the same physical package.

Because the logical processors within a physical package are tightly coupled with respect to shared hardware resources, both logical processors are notified of machine check errors that occur within a given physical processor. If machine-check exceptions are enabled when a fatal error is reported, all the logical processors within a physical package are dispatched to the machine-check exception handler. If machine-check exceptions are disabled, the logical processors enter the shutdown state and assert the IERR# signal.

When enabling machine-check exceptions, the MCE flag in control register CR4 should be set for each logical processor.

On Intel Atom family processors that support Intel Hyper-Threading Technology, the MCA facilities are shared between all logical processors on the same processor core.

8.7.6 Debug Registers and Extensions

Each logical processor has its own set of debug registers (DR0, DR1, DR2, DR3, DR6, DR7) and its own debug control MSR. These can be set to control and record debug information for each logical processor independently. Each logical processor also has its own last branch records (LBR) stack.

Page 348 of the Intel 253668-032US user manual — 8.7.10 Serializing Instructions
Page 348 · click to enlarge
Page 348

MULTIPLE-PROCESSOR MANAGEMENT

8.7.7 Performance Monitoring Counters

Performance counters and their companion control MSRs are shared between the logical processors within a processor core for processors based on Intel NetBurst microarchitecture. As a result, software must manage the use of these resources. The performance counter interrupts, events, and precise event monitoring support can be set up and allocated on a per thread (per logical processor) basis.

See Section 30.9, “Performance Monitoring and Intel Hyper-Threading Technology in Processors Based on Intel NetBurst Microarchitecture,” for a discussion of perfor mance monitoring in the Intel Xeon processor MP.

In Intel Atom processor family that support Intel Hyper-Threading Technology, the performance counters (general-purpose and fixed-function counters) and their companion control MSRs are duplicated for each logical processor.

8.7.8 IA32_MISC_ENABLE MSR

The IA32_MISC_ENABLE MSR (MSR address 1A0H) is generally shared between the logical processors in a processor core supporting Intel Hyper-Threading Technology. However, some bit fields within IA32_MISC_ENABLES MSR may be duplicated per logical processor. The partition of shared or duplicated bit fields within IA32_MISC_ENABLES is implementation dependent. Software should program dupli cated fields carefully on all logical processors in the system to ensure consistent behavior.

8.7.9 Memory Ordering

The logical processors in an Intel 64 or IA-32 processor supporting Intel Hyper- Threading Technology obey the same rules for memory ordering as Intel 64 or IA-32 processors without Intel HT Technology (see Section 8.2, “Memory Ordering”). Each logical processor uses a processor-ordered memory model that can be further defined as “write-ordered with store buffer forwarding.” All mechanisms for strength ening or weakening the memory-ordering model to handle special programming situ ations apply to each logical processor.

8.7.10 Serializing Instructions

As a general rule, when a logical processor in a processor supporting Intel Hyper- Threading Technology executes a serializing instruction, only that logical processor is affected by the operation. An exception to this rule is the execution of the WBINVD, INVD, and WRMSR instructions; and the MOV CR instruction when the state of the CD flag in control register CR0 is modified. Here, both logical processors are serialized.

Page 349 of the Intel 253668-032US user manual — 8.7.13 Implementation-Specific Intel HT Technology Facilities
Page 349 · click to enlarge
Page 349

MULTIPLE-PROCESSOR MANAGEMENT

8.7.11 MICROCODE UPDATE Resources

In an Intel processor supporting Intel Hyper-Threading Technology, the microcode update facilities are shared between the logical processors; either logical processor can initiate an update. Each logical processor has its own BIOS signature MSR (IA32_BIOS_SIGN_ID at MSR address 8BH). When a logical processor performs an update for the physical processor, the IA32_BIOS_SIGN_ID MSRs for resident logical processors are updated with identical information. If logical processors initiate an update simultaneously, the processor core provides the necessary synchronization needed to insure that only one update is performed at a time.

Operating system microcode update drivers that adhere to Intel’s guidelines do not need to be modified to run on processors supporting Intel Hyper-Threading Tech nology.

8.7.12 Self Modifying Code

Intel processors supporting Intel Hyper-Threading Technology support self-modifying code, where data writes modify instructions cached or currently in flight. They also support cross-modifying code, where on an MP system writes generated by one processor modify instructions cached or currently in flight on another. See Section 8.1.3, “Handling Self- and Cross-Modifying Code,” for a description of the require ments for self- and cross-modifying code in an IA-32 processor.

8.7.13 Implementation-Specific Intel HT Technology Facilities

  • The following non-architectural facilities are implementation-specific in IA-32 proces sors supporting Intel Hyper-Threading Technology:
  • Caches
  • Translation lookaside buffers (TLBs)
  • Thermal monitoring facilities

The Intel Xeon processor MP implementation is described in the following sections.

8.7.13.1 Processor Caches

For processors supporting Intel Hyper-Threading Technology, the caches are shared. Any cache manipulation instruction that is executed on one logical processor has a global effect on the cache hierarchy of the physical processor. Note the following: • WBINVD instruction — The entire cache hierarchy is invalidated after modified data is written back to memory. All logical processors are stopped from executing until after the write-back and invalidate operation is completed. A special bus cycle is sent to all caching agents. The amount of time or cycles for WBINVD to complete will vary due to the size of different cache hierarchies and other factors.

Page 350 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 350 · click to enlarge
Page 350

MULTIPLE-PROCESSOR MANAGEMENT

  • As a consequence, the use of the WBINVD instruction can have an impact on interrupt/event response time.
  • INVD instruction — The entire cache hierarchy is invalidated without writing back modified data to memory. All logical processors are stopped from executing until after the invalidate operation is completed. A special bus cycle is sent to all caching agents.
  • CLFLUSH instruction — The specified cache line is invalidated from the cache hierarchy after any modified data is written back to memory and a bus cycle is sent to all caching agents, regardless of which logical processor caused the cache line to be filled.
  • CD flag in control register CR0 — Each logical processor has its own CR0 control register, and thus its own CD flag in CR0. The CD flags for the two logical processors are ORed together, such that when any logical processor sets its CD flag, the entire cache is nominally disabled.

8.7.13.2 Processor Translation Lookaside Buffers (TLBs)

In processors supporting Intel Hyper-Threading Technology, data cache TLBs are shared. The instruction cache TLB may be duplicated or shared in each logical processor, depending on implementation specifics of different processor families.

Entries in the TLBs are tagged with an ID that indicates the logical processor that initiated the translation. This tag applies even for translations that are marked global using the page-global feature for memory paging. See Section 4.10, “Caching Trans lation Information,” for information about global translations.

When a logical processor performs a TLB invalidation operation, only the TLB entries that are tagged for that logical processor are guaranteed to be flushed. This protocol applies to all TLB invalidation operations, including writes to control registers CR3 and CR4 and uses of the INVLPG instruction.

8.7.13.3 Thermal Monitor

  • In a processor that supports Intel Hyper-Threading Technology, logical processors share the catastrophic shutdown detector and the automatic thermal monitoring mechanism (see Section 14.5, “Thermal Monitoring and Protection”). Sharing results in the following behavior:
  • If the processor’s core temperature rises above the preset catastrophic shutdown temperature, the processor core halts execution, which causes both logical processors to stop execution.
  • When the processor’s core temperature rises above the preset automatic thermal monitor trip temperature, the clock speed of the processor core is automatically modulated, which effects the execution speed of both logical processors.

For software controlled clock modulation, each logical processor has its own IA32_CLOCK_MODULATION MSR, allowing clock modulation to be enabled or

Page 351 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 351 · click to enlarge
Page 351

MULTIPLE-PROCESSOR MANAGEMENT

disabled on a logical processor basis. Typically, if software controlled clock modula tion is going to be used, the feature must be enabled for all the logical processors within a physical processor and the modulation duty cycle must be set to the same value for each logical processor. If the duty cycle values differ between the logical processors, the processor clock will be modulated at the highest duty cycle selected.

8.7.13.4 External Signal Compatibility

  • This section describes the constraints on external signals received through the pins of a processor supporting Intel Hyper-Threading Technology and how these signals are shared between its logical processors.
  • STPCLK# — A single STPCLK# pin is provided on the physical package of the Intel Xeon processor MP. External control logic uses this pin for power management within the system. When the STPCLK# signal is asserted, the processor core transitions to the stop-grant state, where instruction execution is halted but the processor core continues to respond to snoop transactions. Regardless of whether the logical processors are active or halted when the STPCLK# signal is asserted, execution is stopped on both logical processors and neither will respond to interrupts. In MP systems, the STPCLK# pins on all physical processors are generally tied together. As a result this signal affects all the logical processors within the system simultaneously.
  • LINT0 and LINT1 pins — A processor supporting Intel Hyper-Threading Technology has only one set of LINT0 and LINT1 pins, which are shared between the logical processors. When one of these pins is asserted, both logical processors respond unless the pin has been masked in the APIC local vector tables for one or both of the logical processors. Typically in MP systems, the LINT0 and LINT1 pins are not used to deliver interrupts to the logical processors. Instead all interrupts are delivered to the local processors through the I/O APIC.
  • A20M# pin — On an IA-32 processor, the A20M# pin is typically provided for compatibility with the Intel 286 processor. Asserting this pin causes bit 20 of the physical address to be masked (forced to zero) for all external bus memory accesses. Processors supporting Intel Hyper-Threading Technology provide one A20M# pin, which affects the operation of both logical processors within the physical processor.

The functionality of A20M# is used primarily by older operating systems and not used by modern operating systems. On newer Intel 64 processors, A20M# may be absent.

Page 352 of the Intel 253668-032US user manual — 8.8.2 Memory Type Range Registers (MTRR)
Page 352 · click to enlarge
Page 352

MULTIPLE-PROCESSOR MANAGEMENT

8.8 MULTI-CORE ARCHITECTURE

This section describes the architecture of Intel 64 and IA-32 processors supporting dual-core and quad-core technology. The discussion is applicable to the Intel Pentium processor Extreme Edition, Pentium D, Intel Core Duo, Intel Core 2 Duo, Dual-core Intel Xeon processor, Intel Core 2 Quad processors, and quad-core Intel Xeon processors. Features vary across different microarchitectures and are detectable using CPUID.

In general, each processor core has dedicated microarchitectural resources identical to a single-processor implementation of the underlying microarchitecture without hardware multi-threading capability. Each logical processor in a dual-core processor (whether supporting Intel Hyper-Threading Technology or not) has its own APIC functionality, PAT, machine check architecture, debug registers and extensions. Each logical processor handles serialization instructions or self-modifying code on its own. Memory order is handled the same way as in Intel Hyper-Threading Technology.

The topology of the cache hierarchy (with respect to whether a given cache level is shared by one or more processor cores or by all logical processors in the physical package) depends on the processor implementation. Software must use the deter ministic cache parameter leaf of CPUID instruction to discover the cache-sharing topology between the logical processors in a multi-threading environment.

8.8.1 Logical Processor Support

The topological composition of processor cores and logical processors in a multi-core processor can be discovered using CPUID. Within each processor core, one or more logical processors may be available.

System software must follow the requirement MP initialization sequences (see Section 8.4, “Multiple-Processor (MP) Initialization”) to recognize and enable logical processors. At runtime, software can enumerate those logical processors enabled by system software to identify the topological relationships between these logical processors. (See Section 8.9.5, “Identifying Topological Relationships in a MP System”).

8.8.2 Memory Type Range Registers (MTRR)

MTRR is shared between two logical processors sharing a processor core if the phys ical processor supports Intel Hyper-Threading Technology. MTRR is not shared between logical processors located in different cores or different physical packages.

The Intel 64 and IA-32 architectures require that all logical processors in an MP system use an identical MTRR memory map. This gives software a consistent view of memory, independent of the processor on which it is running.

See Section 11.11, “Memory Type Range Registers (MTRRs).”

Page 353 of the Intel 253668-032US user manual — 8.9 PROGRAMMING CONSIDERATIONS FOR HARDWARE MULTI-THREADING CAPABLE PROCESSORS
Page 353 · click to enlarge
Page 353

MULTIPLE-PROCESSOR MANAGEMENT

8.8.3 Performance Monitoring Counters

Performance counters and their companion control MSRs are shared between two logical processors sharing a processor core if the processor core supports Intel Hyper-Threading Technology and is based on Intel NetBurst microarchitecture. They are not shared between logical processors in different cores or different physical packages. As a result, software must manage the use of these resources, based on the topology of performance monitoring resources. Performance counter interrupts, events, and precise event monitoring support can be set up and allocated on a per thread (per logical processor) basis.

See Section 30.9, “Performance Monitoring and Intel Hyper-Threading Technology in Processors Based on Intel NetBurst Microarchitecture.”

8.8.4 IA32_MISC_ENABLE MSR

Some bit fields in IA32_MISC_ENABLE MSR (MSR address 1A0H) may be shared between two logical processors sharing a processor core, or may be shared between different cores in a physical processor. See Appendix B, “Model-Specific Registers (MSRs)”.

8.8.5 MICROCODE UPDATE Resources

Microcode update facilities are shared between two logical processors sharing a processor core if the physical package supports Intel Hyper-Threading Technology. They are not shared between logical processors in different cores or different phys ical packages. Either logical processor that has access to the microcode update facility can initiate an update.

Each logical processor has its own BIOS signature MSR (IA32_BIOS_SIGN_ID at MSR address 8BH). When a logical processor performs an update for the physical processor, the IA32_BIOS_SIGN_ID MSRs for resident logical processors are updated with identical information. If logical processors initiate an update simulta neously, the processor core provides the synchronization needed to ensure that only one update is performed at a time.

8.9 PROGRAMMING CONSIDERATIONS FOR HARDWARE MULTI-THREADING CAPABLE PROCESSORS

In a multi-threading environment, there may be certain hardware resources that are physically shared at some level of the hardware topology. In the multi-processor systems, typically bus and memory sub-systems are physically shared between multiple sockets. Within a hardware multi-threading capable processors, certain resources are provided for each processor core, while other resources may be

Page 354 of the Intel 253668-032US user manual — 8.9.1 Hierarchical Mapping of Shared Resources
Page 354 · click to enlarge
Page 354

MULTIPLE-PROCESSOR MANAGEMENT

provided for each logical processors (see Section 8.7, “Intel® Hyper-Threading Tech nology Architecture,” and Section 8.8, “Multi-Core Architecture”).

From a software programming perspective, control transfer of processor operation is managed at the granularity of logical processor (operating systems dispatch a runnable task by allocating an available logical processor on the platform). To manage the topology of shared resources in a multi-threading environment, it may be useful for software to understand and manage resources that are shared by more than one logical processors.

8.9.1 Hierarchical Mapping of Shared Resources

The APIC_ID value associated with each logical processor in a multi-processor system is unique (see Section 8.6, “Detecting Hardware Multi-Threading Support and Topology”). This 8-bit or 32-bit value can be decomposed into sub-fields, where each sub-field corresponds a hierarchical level of the topological mapping of hardware resources.

  • The decomposition of an APIC_ID may consist of several sub fields representing the topology within a physical processor package, the higher-order bits of an APIC ID may also be used by cluster vendors to represent the topology of cluster nodes of each coherent multiprocessor systems. If the processor does not support CPUID leaf 0BH, the 8-bit initial APIC ID can represent 4 levels of hierarchy:
  • Cluster — Some multi-threading environments consists of multiple clusters of multi-processor systems. The CLUSTER_ID sub-field is usually supported by vendor firmware to distinguish different clusters. For non-clustered systems, CLUSTER_ID is usually 0 and system topology is reduced to three levels of hierarchy.
  • Package — A multi-processor system consists of two or more sockets, each mates with a physical processor package. The PACKAGE_ID sub-field distin guishes different physical packages within a cluster.
  • Core — A physical processor package consists of one or more processor cores. The CORE_ID sub-field distinguishes processor cores in a package. For a singlecore processor, the width of this bit field is 0.
  • SMT — A processor core provides one or more logical processors sharing execution resources. The SMT_ID sub-field distinguishes logical processors in a core. The width of this bit field is non-zero if a processor core provides more than one logical processors.

SMT and CORE sub-fields are bit-wise contiguous in the APIC_ID field (see Figure 8-5).

Page 355 of the Intel 253668-032US user manual — R SMT
Page 355 · click to enlarge
Page 355

MULTIPLE-PROCESSOR MANAGEMENT

X=31 if x2APIC is supported

SMT ID

Figure 8-5. Generalized Four level Interpretation of the APIC ID

If the processor supports CPUID leaf 0BH, the 32-bit APIC ID can represent cluster plus several levels of topology within the physical processor package. The exact number of hierarchical levels within a physical processor package must be enumer ated through CPUID leaf 0BH. Common processor families may employ topology similar to that represented by 8-bit Initial APIC ID. In general, CPUID leaf 0BH can support topology enumeration algorithm that decompose a 32-bit APIC ID into more than four sub-fields (see Figure 8-6).

The width of each sub-field depends on hardware and software configurations. Field widths can be determined at runtime using the algorithm discussed below (Example 8-16 through Example 8-20).

Figure 7-6 depicts the relationships of three of the hierarchical sub-fields in a hypo thetical MP system. The value of valid APIC_IDs need not be contiguous across package boundary or core boundaries.

R SMT

Q

Q ID

R ID

SMT ID

Physical Processor Topology 32-bit APIC ID Composition

Figure 8-6. Conceptual Five-level Topology and 32-bit APIC ID Composition

Show 9 more labels / short text on this page
Otherwise X= 7 · Reserved · Cluster ID · Package ID · Core ID · Package · Reserved · Cluster ID · Package ID
Page 356 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 356 · click to enlarge
Page 356

MULTIPLE-PROCESSOR MANAGEMENT

8.9.2 Hierarchical Mapping of CPUID Extended Topology Leaf

CPUID leaf 0BH provides enumeration parameters for software to identify each hier archy of the processor topology in a deterministic manner. Each hierarchical level of the topology starting from the SMT level is represented numerically by a sub-leaf index within the CPUID 0BH leaf. Each level of the topology is mapped to a sub-field in the APIC ID, following the general relationship depicted in Figure 8-6. This mech anism allows software to query the exact number of levels within a physical processor package and the bit-width of each sub-field of x2APIC ID directly. For example, • Starting from sub-leaf index 0 and incrementing ECX until CPUID.(EAX=0BH, ECX=N):ECX[15:8] returns an invalid “level type“ encoding. The number of levels within the physical processor package is “N“ (excluding PACKAGE). Using Figure 8-6 as an example, CPUID.(EAX=0BH, ECX=3):ECX[15:8] will report 00H, indicating sub leaf 03H is invalid. This is also depicted by a pseudo code example:

Example 8-16. Number of Levels Below the Physical Processor Package

Byte type = 1;

s = 0; While ( type ) {

  • EAX = 0BH; // query each sub leaf of CPUID leaf 0BH ECX = s; CPUID; type = ECX[15:8]; // examine level type encoding s ++; } N = ECX[7:0];
  • Sub-leaf index 0 (ECX= 0 as input) provides enumeration parameters to extract the SMT sub-field of x2APIC ID. If EAX = 0BH, and ECX =0 is specified as input when executing CPUID, CPUID.(EAX=0BH, ECX=0):EAX[4:0] reports a value (a right-shift count) that allow software to extract part of x2APIC ID to distinguish the next higher topological entities above the SMT level. This value also corresponds to the bit-width of the sub-field of x2APIC ID corresponding the hierarchical level with sub-leaf index 0.
  • For each subsequent higher sub-leaf index m, CPUID.(EAX=0BH, ECX=m):EAX[4:0] reports the right-shift count that will allow software to extract part of x2APIC ID to distinguish higher-level topological entities. This means the right-shift value at of sub-leaf m, corresponds to the least significant (m+1) subfields of the 32-bit x2APIC ID.

Example 8-17. BitWidth Determination of x2APIC ID Subfields

Page 357 of the Intel 253668-032US user manual — 8.9.3 Hierarchical ID of Logical Processors in an MP System
Page 357 · click to enlarge
Page 357

MULTIPLE-PROCESSOR MANAGEMENT

For m = 0, m < N, m ++; { cumulative_width[m] = CPUID.(EAX=0BH, ECX= m): EAX[4:0]; } BitWidth[0] = cumulative_width[0]; For m = 1, m < N, m ++;

BitWidth[m] = cumulative_width[m] - cumulative_width[m-1];

Currently, only the following encoding of hierarchical level type are defined: 0 (invalid), 1 (SMT), and 2 (core). Software must not assume any “level type“ encoding value to be related to any sub-leaf index, except sub-leaf 0.

Example 8-16 and Example 8-17 represent the general technique for using CPUID leaf 0BH to enumerate processor topology of more than two levels of hierarchy inside a physical package. Most processor families to date requires only “SMT” and “CORE” levels within a physical package. The examples in later sections will focus on these three-level topology only.

8.9.3 Hierarchical ID of Logical Processors in an MP System

For Intel 64 and IA-32 processors, system hardware establishes an 8-bit initial APIC ID (or 32-bit APIC ID if the processor supports CPUID leaf 0BH) that is unique for each logical processor following power-up or RESET (see Section 8.6.1). Each logical processor on the system is allocated an initial APIC ID. BIOS may implement features that tell the OS to support less than the total number of logical processors on the system bus. Those logical processors that are not available to applications at runtime are halted during the OS boot process. As a result, the number valid local APIC_IDs that can be queried by affinitizing-current-thread-context (See Example 8-22) is limited to the number of logical processors enabled at runtime by the OS boot process.

Table 8-1 shows an example of the 8-bit APIC IDs that are initially reported for logical processors in a system with four Intel Xeon MP processors that support Intel Hyper- Threading Technology (a total of 8 logical processors, each physical package has two processor cores and supports Intel Hyper-Threading Technology). Of the two logical processors within a Intel Xeon processor MP, logical processor 0 is designated the primary logical processor and logical processor 1 as the secondary logical processor.

Page 358 of the Intel 253668-032US user manual — 0H 0H 0H 0H
Page 358 · click to enlarge
Page 358

MULTIPLE-PROCESSOR MANAGEMENT

T0 T1

T0 T1

T0 T1

T0 T1 SMT_ID

Figure 8-7. Topological Relationships between Hierarchical IDs in a Hypothetical MP

Table 8-1. Initial APIC IDs for the Logical Processors in a System that has Four Intel

Xeon MP Processors Supporting Intel Hyper-Threading Technology1

Initial APIC ID Package ID Core ID SMT ID

0H

1H 0H 0H 1H

2H 1H 0H 0H

3H 1H 0H 1H

4H 2H 0H 0H

5H 2H 0H 1H

6H 3H 0H 0H

7H 3H 0H 1H

Table 8-2 shows the initial APIC IDs for a hypothetical situation with a dual processor system. Each physical package providing two processor cores, and each processor core also supporting Intel Hyper-Threading Technology.

Show 9 more labels / short text on this page
Core ID · Core 0 · Core1 · Core 0 · Core1 · Package 0 · Package 1 · Package ID · Platform
Page 359 of the Intel 253668-032US user manual — 0H 0H 0H 0H
Page 359 · click to enlarge
Page 359

MULTIPLE-PROCESSOR MANAGEMENT

Table 8-2. Initial APIC IDs for the Logical Processors in a System that has Two Physical Processors Supporting Dual-Core and Intel Hyper-Threading Technology

Initial APIC ID Package ID Core ID SMT ID

0H

1H 0H 0H 1H

2H 0H 1H 0H

3H 0H 1H 1H

4H 1H 0H 0H

5H 1H 0H 1H

6H 1H 1H 0H

7H 1H 1H 1H

8.9.3.1 Hierarchical ID of Logical Processors with x2APIC ID

Table 8-3 shows an example of possible x2APIC ID assignments for a dual processor system that support x2APIC. Each physical package providing four processor cores, and each processor core also supporting Intel Hyper-Threading Technology. Note that the x2APIC ID need not be contiguous in the system.

Table 8-3. Example of Possible x2APIC ID Assignment in a System that has Two

Physical Processors Supporting x2APIC and Intel Hyper-Threading Technology

x2APIC ID Package ID Core ID SMT ID

0H

1H 0H 0H 1H

2H 0H 1H 0H

3H 0H 1H 1H

4H 0H 2H 0H

5H 0H 2H 1H

6H 0H 3H 0H

7H 0H 3H 1H

10H 1H 0H 0H

11H 1H 0H 1H

12H 1H 1H 0H

13H 1H 1H 1H

14H 1H 2H 0H

Page 360 of the Intel 253668-032US user manual — 15H 1H 2H 1H
Page 360 · click to enlarge
Page 360

MULTIPLE-PROCESSOR MANAGEMENT

Table 8-3. Example of Possible x2APIC ID Assignment in a System that has Two

Physical Processors Supporting x2APIC and Intel Hyper-Threading Technology

x2APIC ID Package ID Core ID SMT ID

15H 1H 2H 1H

16H 1H 3H 0H

17H 1H 3H 1H

8.9.4 Algorithm for Three-Level Mappings of APIC_ID

Software can gather the initial APIC_IDs for each logical processor supported by the operating system at runtime5 and extract identifiers corresponding to the three levels of sharing topology (package, core, and SMT). The three-level algorithms below focus on a non-clustered MP system for simplicity. They do not assume APIC IDs are contiguous or that all logical processors on the platform are enabled.

Intel supports multi-threading systems where all physical processors report identical values in CPUID leaf 0BH, CPUID.1:EBX[23:16]), CPUID.46:EAX[31:26], and CPUID.47:EAX[25:14]. The algorithms below assume the target system has symmetry across physical package boundaries with respect to the number of logical processors per package, number of cores per package, and cache topology within a package.

The extraction algorithm (for three-level mappings from an APIC ID) uses the general procedure depicted in Example 8-18, and is supplemented by more detailed descriptions on the derivation of topology enumeration parameters for extraction bit masks:

1. Detect hardware multi-threading support in the processor.
2. Derive a set of bit masks that can extract the sub ID of each hierarchical level of the topology. The algorithm to derive extraction bit masks for SMT_ID/CORE_ID/PACKAGE_ID differs based on APIC ID is 32-bit (see step 3 below) or 8-bit (see step 4 below):
3. If the processor supports CPUID leaf 0BH, each APIC ID contains a 32-bit value, the topology enumeration parameters needed to derive three-level extraction bit masks are:
5. As noted in Section 8.6 and Section 8.9.3, the number of logical processors supported by the OS at runtime may be less than the total number logical processors available in the platform hard ware.
6. Maximum number of addressable ID for processor cores in a physical processor is obtained by executing CPUID with EAX=4 and a valid ECX index, The ECX index start at 0.
7. Maximum number addressable ID for processor cores sharing the target cache level is obtained by executing CPUID with EAX = 4 and the ECX index corresponding to the target cache level.
Page 361 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 361 · click to enlarge
Page 361

MULTIPLE-PROCESSOR MANAGEMENT

a. Query the right-shift value for the SMT level of the topology using CPUID leaf 0BH with ECX =0H as input. The number of bits to shift-right on x2APIC ID (EAX[4:0]) can distinguish different higher-level entities above SMT (e.g. processor cores) in the same physical package. This is also the width of the bit mask to extract the SMT_ID.

b. Query CPUID leaf 0BH for the amount of bit shift to distinguish next higher- level entities (e.g. physical processor packages) in the system. This describes an explicit three-level-topology situation for commonly available processors. Consult Example 8-17 to adapt to situations beyond three-level topology of a physical processor. The width of the extraction bit mask can be used to derive the cumulative extraction bitmask to extract the sub IDs of logical processors (including different processor cores) in the same physical package. The extraction bit mask to distinguish merely different processor cores can be derived by xor’ing the SMT extraction bit mask from the cumulative extraction bit mask.

c. Query the 32-bit x2APIC ID for the logical processor where the current thread is executing.

d. Derive the extraction bit masks corresponding to SMT_ID, CORE_ID, and PACKAGE_ID, starting from SMT_ID.

e. Apply each extraction bit mask to the 32-bit x2APIC ID to extract sub-field IDs.

4. If the processor does not support CPUID leaf 0BH, each initial APIC ID contains an 8-bit value, the topology enumeration parameters needed to derive extraction bit masks are:

a. Query the size of address space for sub IDs that can accommodate logical processors in a physical processor package. This size parameters (CPUID.1:EBX[23:16]) can be used to derive the width of an extraction bitmask to enumerate the sub IDs of different logical processors in the same physical package.

b. Query the size of address space for sub IDs that can accommodate processor cores in a physical processor package. This size parameters can be used to derive the width of an extraction bitmask to enumerate the sub IDs of processor cores in the same physical package.

c. Query the 8-bit initial APIC ID for the logical processor where the current thread is executing.

d. Derive the extraction bit masks using respective address sizes corresponding to SMT_ID, CORE_ID, and PACKAGE_ID, starting from SMT_ID.

e. Apply each extraction bit mask to the 8-bit initial APIC ID to extract sub-field IDs.

Page 362 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 362 · click to enlarge
Page 362

MULTIPLE-PROCESSOR MANAGEMENT

Example 8-18. Support Routines for Detecting Hardware Multi-Threading and Identifying the Relationships Between Package, Core and Logical Processors

1. Detect support for Hardware Multi-Threading Support in a processor.

// Returns a non-zero value if CPUID reports the presence of hardware multi-threading // support in the physical package where the current logical processor is located. // This does not guarantee BIOS or OS will enable all logical processors in the physical // package and make them available to applications. // Returns zero if hardware multi-threading is not present.

unsigned int HWMTSupported(void) {

// ensure cpuid instruction is supported

execute cpuid with eax = 0 to get vendor string execute cpuid with eax = 1 to get feature flag and signature

// Check to see if this a Genuine Intel Processor

if (vendor string EQ GenuineIntel) {

return (feature_flag_edx & HWMT_BIT); // bit 28 } return 0; }

Example 8-19. Support Routines for Identifying Package, Core and Logical Processors from 32-bit x2APIC ID

a. Derive the extraction bitmask for logical processors in a processor core and associated mask offset for different cores.

int DeriveSMT_Mask_Offsets (void) {

if (!HWMTSupported()) return -1; execute cpuid with eax = 11, ECX = 0; If (returned level type encoding in ECX[15:8] does not match SMT) return -1; Mask_SMT_shift = EAX[4:0]; // # bits shift right of APIC ID to distinguish different cores SMT_MASK = ~( (-1)

b. Derive the extraction bitmask for processor cores in a physical processor package and associated mask offset for different packages.

#define HWMT_BIT 0x10000000

Page 363 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 363 · click to enlarge
Page 363

MULTIPLE-PROCESSOR MANAGEMENT

int DeriveCore_Mask_Offsets (void) {

if (!HWMTSupported()) return -1; execute cpuid with eax = 11, ECX = 0;

while( ECX[15:8] ) { // level type encoding is valid

If (returned level type encoding in ECX[15:8] matches CORE) {

Mask_Core_shift = EAX[4:0]; // needed to distinguish different physical packages COREPlusSMT_MASK = ~( (-1)

c. Query the x2APIC ID of a logical processor.

APIC_IDs for each logical processor.

unsigned char Getx2APIC_ID (void) {

unsigned reg_edx = 0; execute cpuid with eax = 11, ECX = 0 store returned value of edx return (unsigned) (reg_edx) ; }

Example 8-20. Support Routines for Identifying Package, Core and Logical Processors from 8- bit Initial APIC ID

a. Find the size of address space for logical processors in a physical processor package.

#define NUM_LOGICAL_BITS 0x00FF0000 // Use the mask above and CPUID.1.EBX[23:16] to obtain the max number of addressable IDs // for logical processors in a physical package,

//Returns the size of address space of logical processors in a physical processor package; // Software should not assume the value to be a power of 2.

Page 364 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 364 · click to enlarge
Page 364

MULTIPLE-PROCESSOR MANAGEMENT

unsigned char MaxLPIDsPerPackage(void) {

if (!HWMTSupported()) return 1; execute cpuid with eax = 1

store returned value of ebx return (unsigned char) ((reg_ebx & NUM_LOGICAL_BITS) >> 16); }

b. Find the size of address space for processor cores in a physical processor package.

// Returns the max number of addressable IDs for processor cores in a physical processor package; // Software should not assume cpuid reports this value to be a power of 2.

if (!HWMTSupported()) return (unsigned char) 1; if cpuid supports leaf number 4 { // we can retrieve multi-core topology info using leaf 4

execute cpuid with eax = 4, ecx = 0 store returned value of eax return (unsigned) ((reg_eax >> 26) +1); } else // must be a single-core processor return 1; }

c. Query the initial APIC ID of a logical processor.

#define INITIAL_APIC_ID_BITS 0xFF000000 // CPUID.1.EBX[31:24] initial APIC ID

// Returns the 8-bit unique initial APIC ID for the processor running the code. // Software can use OS services to affinitize the current thread to each logical processor // available under the OS to gather the initial APIC_IDs for each logical processor.

unsigned GetInitAPIC_ID (void) {

unsigned int reg_ebx = 0; execute cpuid with eax = 1 store returned value of ebx return (unsigned) ((reg_ebx & INITIAL_APIC_ID_BITS) >> 24; }

d. Find the width of an extraction bitmask from the maximum count of the bit-field (address size).

unsigned MaxCoreIDsPerPackage(void) {

Page 365 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 365 · click to enlarge
Page 365

MULTIPLE-PROCESSOR MANAGEMENT

// Returns the mask bit width of a bit field from the maximum count that bit field can represent. // This algorithm does not assume ‘address size’ to have a value equal to power of 2. // Address size for SMT_ID can be calculated from MaxLPIDsPerPackage()/MaxCoreIDsPerPackage() // Then use the routine below to derive the corresponding width of SMT extraction bitmask // Address size for CORE_ID is MaxCoreIDsPerPackage(), // Derive the bitwidth for CORE extraction mask similarly

unsigned FindMaskWidth(Unsigned Max_Count) {unsigned int mask_width, cnt = Max_Count;

mov eax, cnt mov ecx, 0 mov mask_width, ecx dec eax bsr cx, ax jz next inc cx mov mask_width, ecx next: mov eax, mask_width } return mask_width; }

e. Extract a sub ID from an 8-bit full ID, using address size of the sub ID and shift count.

// The routine below can extract SMT_ID, CORE_ID, and PACKAGE_ID respectively from the init APIC_ID // To extract SMT_ID, MaxSubIDvalue is set to the address size of SMT_ID, Shift_Count = 0 // To extract CORE_ID, MaxSubIDvalue is the address size of CORE_ID, Shift_Count is width of SMT extraction bitmask. // Returns the value of the sub ID, this is not a zero-based value

Unsigned char GetSubID(unsigned char Full_ID, unsigned char MaxSubIDvalue, unsigned char Shift_Count) {

MaskWidth = FindMaskWidth(MaxSubIDValue); MaskBits = ((uchar) (0xff

__asm {

Page 366 of the Intel 253668-032US user manual — 8.9.5 Identifying Topological Relationships in a MP System
Page 366 · click to enlarge
Page 366

MULTIPLE-PROCESSOR MANAGEMENT

Software must not assume local APIC_ID values in an MP system are consecutive. Non-consecutive local APIC_IDs may be the result of hardware configurations or debug features implemented in the BIOS or OS.

An identifier for each hierarchical level can be extracted from an 8-bit APIC_ID using the support routines illustrated in Example 8-20. The appropriate bit mask and shift value to construct the appropriate bit mask for each level must be determined dynamically at runtime.

8.9.5 Identifying Topological Relationships in a MP System

To detect the number of physical packages, processor cores, or other topological relationships in a MP system, the following procedures are recommended: • Extract the three-level identifiers from the APIC ID of each logical processor enabled by system software. The sequence is as follows (See the pseudo code shown in Example 8-21 and support routines shown in Example 8-18):

  • The extraction start from the right-most bit field, corresponding to SMT_ID, the innermost hierarchy in a three-level topology (See Figure 8-7). For the right-most bit field, the shift value of the working mask is zero. The width of the bit field is determined dynamically using the maximum number of logical processor per core, which can be derived from information provided from CPUID.
  • To extract the next bit-field, the shift value of the working mask is determined from the width of the bit mask of the previous step. The width of the bit field is determined dynamically using the maximum number of cores per package.
  • To extract the remaining bit-field, the shift value of the working mask is determined from the maximum number of logical processor per package. So the remaining bits in the APIC ID (excluding those bits already extracted in the two previous steps) are extracted as the third identifier. This applies to a non-clustered MP system, or if there is no need to distinguish between PACKAGE_ID and CLUSTER_ID.
  • If there is need to distinguish between PACKAGE_ID and CLUSTER_ID, PACKAGE_ID can be extracted using an algorithm similar to the extraction of CORE_ID, assuming the number of physical packages in each node of a clustered system is symmetric.
  • Assemble the three-level identifiers of SMT_ID, CORE_ID, PACKAGE_IDs into arrays for each enabled logical processor. This is shown in Example 8-22a.
  • To detect the number of physical packages: use PACKAGE_ID to identify those logical processors that reside in the same physical package. This is shown in Example 8-22b. This example also depicts a technique to construct a mask to represent the logical processors that reside in the same package.
  • To detect the number of processor cores: use CORE_ID to identify those logical processors that reside in the same core. This is shown in Example 8-22. This
Page 367 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 367 · click to enlarge
Page 367

MULTIPLE-PROCESSOR MANAGEMENT

example also depicts a technique to construct a mask to represent the logical processors that reside in the same core.

In Example 8-21, the numerical ID value can be obtained from the value extracted with the mask by shifting it right by shift count. Algorithms below do not shift the value. The assumption is that the SubID values can be compared for equivalence without the need to shift.

Example 8-21. Pseudo Code Depicting Three-level Extraction Algorithm

// Calculate SMT_MASK, the bit mask pattern to extract SMT_ID, // SMT_MASK is determined using topology enumertaion parameters // from CPUID leaf 0BH (Example 8-19); // otherwise, SMT_MASK is determined using CPUID leaf 01H and leaf 04H (Example 8-20). // This algorithm assumes there is symmetry across core boundary, i.e. each core within a // package has the same number of logical processors // SMT_ID always starts from bit 0, corresponding to the right-most bit-field SMT_ID = APIC_ID & SMT_MASK;

// Extract CORE_ID:

// CORE_MASK is determined in Example 8-19 or Example 8-20 CORE_ID = (APIC_ID & CORE_MASK) ;

// Extract PACKAGE_ID: // Assume single cluster. // Shift out the mask width for maximum logical processors per package // PACKAGE_MASK is determined in Example 8-19 or Example 8-20 PACKAGE_ID = (APIC_ID & PACKAGE_MASK) ; }

Example 8-22. Compute the Number of Packages, Cores, and Processor Relationships in a MP System

a) Assemble lists of PACKAGE_ID, CORE_ID, and SMT_ID of each enabled logical processors

//The BIOS and/or OS may limit the number of logical processors available to applications // after system boot. The below algorithm will compute topology for the processors visible // to the thread that is computing it.

// Extract the 3-levels of IDs on every processor // SystemAffinity is a bitmask of all the processors started by the OS. Use OS specific APIs to // obtain it. // ThreadAffinityMask is used to affinitize the topology enumeration thread to each processor

For Each local_APIC_ID{

Page 368 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 368 · click to enlarge
Page 368

MULTIPLE-PROCESSOR MANAGEMENT

using OS specific APIs. // Allocate per processor arrays to store the Package_ID, Core_ID and SMT_ID for every started // processor.

ThreadAffinityMask = 1; ProcessorNum = 0;

while (ThreadAffinityMask != 0 && ThreadAffinityMask

// Check to make sure we can utilize this processor first. if (ThreadAffinityMask & SystemAffinity){

Set thread to run on the processor specified in ThreadAffinityMask Wait if necessary and ensure thread is running on specified processor

APIC_ID = GetAPIC_ID(); // 32 bit ID in Example 8-19 or 8-bit ID in Example 8-20 Extract the Package_ID, Core_ID and SMT_ID as explained in three level extraction

algorithm of Example 8-21 PackageID[ProcessorNUM] = PACKAGE_ID; CoreID[ProcessorNum] = CORE_ID; SmtID[ProcessorNum] = SMT_ID; ProcessorNum++; } ThreadAffinityMask

b) Using the list of PACKAGE_ID to count the number of physical packages in a MP system and construct, for each package, a multi-bit mask corresponding to those logical processors residing in the same package.

// Compute the number of packages by counting the number of processors // with unique PACKAGE_IDs in the PackageID array. // Compute the mask of processors in each package.

PackageIDBucket is an array of unique PACKAGE_ID values. Allocate an array of NumStartedLPs count of entries in this array. PackageProcessorMask is a corresponding array of the bit mask of processors belonging to the same package, these are processors with the same PACKAGE_ID The algorithm below assumes there is symmetry across package boundary if more than one socket is populated in an MP system. // Bucket Package IDs and compute processor mask for every package.

PackageNum = 1; PackageIDBucket[0] = PackageID[0]; ProcessorMask = 1;

Page 369 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 369 · click to enlarge
Page 369

MULTIPLE-PROCESSOR MANAGEMENT

PackageProcessorMask[0] = ProcessorMask; For (ProcessorNum = 1; ProcessorNum < NumStartedLPs; ProcessorNum++) {

ProcessorMask

// we may be comparing bit-fields of logical processors residing in different // packages, the code below assume package symmetry If (PackageID[ProcessorNum] == PackageIDBucket[i]) {

PackageProcessorMask[i] |= ProcessorMask; Break; // found in existing bucket, skip to next iteration } } if (i ==PackageNum) {

//PACKAGE_ID did not match any bucket, start new bucket PackageIDBucket[i] = PackageID[ProcessorNum]; PackageProcessorMask[i] = ProcessorMask; PackageNum++; } } // PackageNum has the number of Packages started in OS // PackageProcessorMask[] array has the processor set of each package

c) Using the list of CORE_ID to count the number of cores in a MP system and construct, for each core, a multi-bit mask corresponding to those logical processors residing in the same core.

Processors in the same core can be determined by bucketing the processors with the same PACKAGE_ID and CORE_ID. Note that code below can BIT OR the values of PACKGE and CORE ID because they have not been shifted right. The algorithm below assumes there is symmetry across package boundary if more than one socket is populated in an MP system.

//Bucketing PACKAGE and CORE IDs and computing processor mask for every core

CoreNum = 1; CoreIDBucket[0] = PackageID[0] | CoreID[0]; ProcessorMask = 1; CoreProcessorMask[0] = ProcessorMask; For (ProcessorNum = 1; ProcessorNum < NumStartedLPs; ProcessorNum++) {

ProcessorMask

// we may be comparing bit-fields of logical processors residing in different // packages, the code below assume package symmetry If ((PackageID[ProcessorNum] | CoreID[ProcessorNum]) == CoreIDBucket[i]) {

CoreProcessorMask[i] |= ProcessorMask; Break; // found in existing bucket, skip to next iteration }

Page 370 of the Intel 253668-032US user manual — 8.10.1 HLT Instruction
Page 370 · click to enlarge
Page 370

MULTIPLE-PROCESSOR MANAGEMENT

} if (i == CoreNum) {

//Did not match any bucket, start new bucket CoreIDBucket[i] = PackageID[ProcessorNum] | CoreID[ProcessorNum]; CoreProcessorMask[i] = ProcessorMask; CoreNum++; } } // CoreNum has the number of cores started in the OS // CoreProcessorMask[] array has the processor set of each core

Other processor relationships such as processor mask of sibling cores can be computed from set operations of the PackageProcessorMask[] and CoreProcessor Mask[].

The algorithm shown above can be adapted to work with earlier generations of single-core IA-32 processors that support Intel Hyper-Threading Technology and in situations that the deterministic cache parameter leaf is not supported (provided CPUID supports initial APIC ID). A reference code example is available (see Intel® 64 Architecture Processor Topology Enumeration).

8.10 MANAGEMENT OF IDLE AND BLOCKED CONDITIONS

When a logical processor in an MP system (including multi-core processor or proces sors supporting Intel Hyper-Threading Technology) is idle (no work to do) or blocked (on a lock or semaphore), additional management of the core execution engine resource can be accomplished by using the HLT (halt), PAUSE, or the MONITOR/MWAIT instructions.

8.10.1 HLT Instruction

The HLT instruction stops the execution of the logical processor on which it is executed and places it in a halted state until further notice (see the description of the HLT instruction in Chapter 3 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A). When a logical processor is halted, active logical processors continue to have full access to the shared resources within the physical package. Here shared resources that were being used by the halted logical processor become available to active logical processors, allowing them to execute at greater efficiency. When the halted logical processor resumes execution, shared resources are again shared among all active logical processors. (See Section 8.10.6.3, “Halt Idle Logical Processors,” for more information about using the HLT instruction with processors supporting Intel Hyper-Threading Technology.)

Page 371 of the Intel 253668-032US user manual — 8.10.3 Detecting Support MONITOR/MWAIT Instruction
Page 371 · click to enlarge
Page 371

MULTIPLE-PROCESSOR MANAGEMENT

8.10.2 PAUSE Instruction

The PAUSE instruction can improves the performance of processors supporting Intel Hyper-Threading Technology when executing “spin-wait loops” and other routines where one thread is accessing a shared lock or semaphore in a tight polling loop. When executing a spin-wait loop, the processor can suffer a severe performance penalty when exiting the loop because it detects a possible memory order violation and flushes the core processor’s pipeline. The PAUSE instruction provides a hint to the processor that the code sequence is a spin-wait loop. The processor uses this hint to avoid the memory order violation and prevent the pipeline flush. In addition, the PAUSE instruction de-pipelines the spin-wait loop to prevent it from consuming execution resources excessively and consume power needlessly. (See Section 8.10.6.1, “Use the PAUSE Instruction in Spin-Wait Loops,” for more information about using the PAUSE instruction with IA-32 processors supporting Intel Hyper- Threading Technology.)

8.10.3 Detecting Support MONITOR/MWAIT Instruction

  • Streaming SIMD Extensions 3 introduced two instructions (MONITOR and MWAIT) to help multithreaded software improve thread synchronization. In the initial imple mentation, MONITOR and MWAIT are available to software at ring 0. The instructions are conditionally available at levels greater than 0. Use the following steps to detect the availability of MONITOR and MWAIT:
  • Use CPUID to query the MONITOR bit (CPUID.1.ECX[3] = 1).
  • If CPUID indicates support, execute MONITOR inside a TRY/EXCEPT exception handler and trap for an exception. If an exception occurs, MONITOR and MWAIT are not supported at a privilege level greater than 0. See Example 8-23.

Example 8-23. Verifying MONITOR/MWAIT Support

boolean MONITOR_MWAIT_works = TRUE; try { _asm {

xor ecx, ecx xor edx, edx mov eax, MemArea monitor } // Use monitor } except (UNWIND) { // if we get here, MONITOR/MWAIT is not supported

MONITOR_MWAIT_works = FALSE; }

Page 372 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 372 · click to enlarge
Page 372

MULTIPLE-PROCESSOR MANAGEMENT

8.10.4 MONITOR/MWAIT Instruction

Operating systems usually implement idle loops to handle thread synchronization. In a typical idle-loop scenario, there could be several “busy loops” and they would use a set of memory locations. An impacted processor waits in a loop and poll a memory location to determine if there is available work to execute. The posting of work is typically a write to memory (the work-queue of the waiting processor). The time for initiating a work request and getting it scheduled is on the order of a few bus cycles.

From a resource sharing perspective (logical processors sharing execution resources), use of the HLT instruction in an OS idle loop is desirable but has implica tions. Executing the HLT instruction on a idle logical processor puts the targeted processor in a non-execution state. This requires another processor (when posting work for the halted logical processor) to wake up the halted processor using an inter- processor interrupt. The posting and servicing of such an interrupt introduces a delay in the servicing of new work requests.

In a shared memory configuration, exits from busy loops usually occur because of a state change applicable to a specific memory location; such a change tends to be triggered by writes to the memory location by another agent (typically a processor).

MONITOR/MWAIT complement the use of HLT and PAUSE to allow for efficient parti tioning and un-partitioning of shared resources among logical processors sharing physical resources. MONITOR sets up an effective address range that is monitored for write-to-memory activities; MWAIT places the processor in an optimized state (this may vary between different implementations) until a write to the monitored address range occurs.

In the initial implementation of MONITOR and MWAIT, they are available at CPL = 0 only.

Both instructions rely on the state of the processor’s monitor hardware. The monitor hardware can be either armed (by executing the MONITOR instruction) or triggered (due to a variety of events, including a store to the monitored memory region). If upon execution of MWAIT, monitor hardware is in a triggered state: MWAIT behaves as a NOP and execution continues at the next instruction in the execution stream. The state of monitor hardware is not architecturally visible except through the behavior of MWAIT.

  • Multiple events other than a write to the triggering address range can cause a processor that executed MWAIT to wake up. These include events that would lead to voluntary or involuntary context switches, such as:
  • External interrupts, including NMI, SMI, INIT, BINIT, MCERR, A20M#
  • Faults, Aborts (including Machine Check)
  • Architectural TLB invalidations including writes to CR0, CR3, CR4 and certain MSR writes; execution of LMSW (occurring prior to issuing MWAIT but after setting the monitor)
  • Voluntary transitions due to fast system call and far calls (occurring prior to issuing MWAIT but after setting the monitor)
Page 373 of the Intel 253668-032US user manual — 8.10.5 Monitor/Mwait Address Range Determination
Page 373 · click to enlarge
Page 373

MULTIPLE-PROCESSOR MANAGEMENT

Power management related events (such as Thermal Monitor 2 or chipset driven STPCLK# assertion) will not cause the monitor event pending flag to be cleared. Faults will not cause the monitor event pending flag to be cleared.

Software should not allow for voluntary context switches in between MONITOR/MWAIT in the instruction flow. Note that execution of MWAIT does not re- arm the monitor hardware. This means that MONITOR/MWAIT need to be executed in a loop. Also note that exits from the MWAIT state could be due to a condition other than a write to the triggering address; software should explicitly check the triggering data location to determine if the write occurred. Software should also check the value of the triggering address following the execution of the monitor instruction (and prior to the execution of the MWAIT instruction). This check is to identify any writes to the triggering address that occurred during the course of MONITOR execution.

  • The address range provided to the MONITOR instruction must be of write-back caching type. Only write-back memory type stores to the monitored address range will trigger the monitor hardware. If the address range is not in memory of writeback type, the address monitor hardware may not be set up properly or the monitor hardware may not be armed. Software is also responsible for ensuring that
  • Writes that are not intended to cause the exit of a busy loop do not write to a location within the address region being monitored by the monitor hardware,
  • Writes intended to cause the exit of a busy loop are written to locations within the monitored address region.

Not doing so will lead to more false wakeups (an exit from the MWAIT state not due to a write to the intended data location). These have negative performance implica tions. It might be necessary for software to use padding to prevent false wakeups. CPUID provides a mechanism for determining the size data locations for monitoring as well as a mechanism for determining the size of a the pad.

8.10.5 Monitor/Mwait Address Range Determination

  • To use the MONITOR/MWAIT instructions, software should know the length of the region monitored by the MONITOR/MWAIT instructions and the size of the coherence line size for cache-snoop traffic in a multiprocessor system. This information can be queried using the CPUID monitor leaf function (EAX = 05H). You will need the smallest and largest monitor line size:
  • To avoid missed wake-ups: make sure that the data structure used to monitor writes fits within the smallest monitor line-size. Otherwise, the processor may not wake up after a write intended to trigger an exit from MWAIT.
  • To avoid false wake-ups; use the largest monitor line size to pad the data structure used to monitor writes. Software must make sure that beyond the data structure, no unrelated data variable exists in the triggering area for MWAIT. A pad may be needed to avoid this situation.

These above two values bear no relationship to cache line size in the system and soft ware should not make any assumptions to that effect. Within a single-cluster system,

Page 374 of the Intel 253668-032US user manual — 8.10.6 Required Operating System Support
Page 374 · click to enlarge
Page 374

MULTIPLE-PROCESSOR MANAGEMENT

the two parameters should default to be the same (the size of the monitor triggering area is the same as the system coherence line size).

Based on the monitor line sizes returned by the CPUID, the OS should dynamically allocate structures with appropriate padding. If static data structures must be used by an OS, attempt to adapt the data structure and use a dynamically allocated data buffer for thread synchronization. When the latter technique is not possible, consider not using MONITOR/MWAIT when using static data structures.

To set up the data structure correctly for MONITOR/MWAIT on multi-clustered systems: interaction between processors, chipsets, and the BIOS is required (system coherence line size may depend on the chipset used in the system; the size could be different from the processor’s monitor triggering area). The BIOS is responsible to set the correct value for system coherence line size using the IA32_MONITOR_FILTER_LINE_SIZE MSR. Depending on the relative magnitude of the size of the monitor triggering area versus the value written into the IA32_MONITOR_FILTER_LINE_SIZE MSR, the smaller of the parameters will be reported as the Smallest Monitor Line Size. The larger of the parameters will be reported as the Largest Monitor Line Size.

8.10.6 Required Operating System Support

This section describes changes that must be made to an operating system to run on processors supporting Intel Hyper-Threading Technology. It also describes optimiza tions that can help an operating system make more efficient use of the logical processors sharing execution resources. The required changes and suggested opti mizations are representative of the types of modifications that appear in Windows* XP and Linux* kernel 2.4.0 operating systems for Intel processors supporting Intel Hyper-Threading Technology. Additional optimizations for processors supporting Intel Hyper-Threading Technology are described in the Intel® 64 and IA-32 Architec tures Optimization Reference Manual.

8.10.6.1 Use the PAUSE Instruction in Spin-Wait Loops

Intel recommends that a PAUSE instruction be placed in all spin-wait loops that run on Intel processors supporting Intel Hyper-Threading Technology and multi-core processors.

Software routines that use spin-wait loops include multiprocessor synchronization primitives (spin-locks, semaphores, and mutex variables) and idle loops. Such routines keep the processor core busy executing a load-compare-branch loop while a thread waits for a resource to become available. Including a PAUSE instruction in such a loop greatly improves efficiency (see Section 8.10.2, “PAUSE Instruction”). The following routine gives an example of a spin-wait loop that uses a PAUSE instruction:

Spin_Lock:

CMP lockvar, 0 ;Check if lock is free

Page 375 of the Intel 253668-032US user manual — WHILE (1) {
Page 375 · click to enlarge
Page 375

MULTIPLE-PROCESSOR MANAGEMENT

JE Get_Lock PAUSE ;Short delay JMP Spin_Lock Get_Lock:

MOV EAX, 1 XCHG EAX, lockvar ;Try to get lock CMP EAX, 0 ;Test if successful JNE Spin_Lock Critical_Section:

MOV lockvar, 0 ... Continue:

The spin-wait loop above uses a “test, test-and-set” technique for determining the availability of the synchronization variable. This technique is recommended when writing spin-wait loops.

In IA-32 processor generations earlier than the Pentium 4 processor, the PAUSE instruction is treated as a NOP instruction.

8.10.6.2 Potential Usage of MONITOR/MWAIT in C0 Idle Loops

An operating system may implement different handlers for different idle states. A typical OS idle loop on an ACPI-compatible OS is shown in Example 8-24:

Example 8-24. A Typical OS Idle Loop

// WorkQueue is a memory location indicating there is a thread // ready to run. A non-zero value for WorkQueue is assumed to // indicate the presence of work to be scheduled on the processor. // The idle loop is entered with interrupts disabled.

WHILE (1) {

IF (WorkQueue) THEN {

// Schedule work at WorkQueue. } ELSE { // No work to do - wait in appropriate C-state handler depending // on Idle time accumulated

IF (IdleTime >= IdleTimeThreshhold) THEN {

// Call appropriate C1, C2, C3 state handler, C1 handler // shown below } } }

Page 376 of the Intel 253668-032US user manual — MWAIT }
Page 376 · click to enlarge
Page 376

MULTIPLE-PROCESSOR MANAGEMENT

// C1 handler uses a Halt instruction VOID C1Handler() { STI HLT }

The MONITOR and MWAIT instructions may be considered for use in the C0 idle state loops, if MONITOR and MWAIT are supported.

Example 8-25. An OS Idle Loop with MONITOR/MWAIT in the C0 Idle Loop

// WorkQueue is a memory location indicating there is a thread // ready to run. A non-zero value for WorkQueue is assumed to // indicate the presence of work to be scheduled on the processor. // The following example assumes that the necessary padding has been // added surrounding WorkQueue to eliminate false wakeups // The idle loop is entered with interrupts disabled.

WHILE (1) {

IF (WorkQueue) THEN {

// Schedule work at WorkQueue. } ELSE {

// No work to do - wait in appropriate C-state handler depending // on Idle time accumulated.

IF (IdleTime >= IdleTimeThreshhold) THEN {

// Call appropriate C1, C2, C3 state handler, C1 // handler shown below MONITOR WorkQueue // Setup of eax with WorkQueue

// ECX, EDX = 0 IF (WorkQueue != 0) THEN {

MWAIT }

} } } // C1 handler uses a Halt instruction.

VOID C1Handler() { STI HLT

// LinearAddress,

Page 377 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 377 · click to enlarge
Page 377

MULTIPLE-PROCESSOR MANAGEMENT

8.10.6.3 Halt Idle Logical Processors

If one of two logical processors is idle or in a spin-wait loop of long duration, explicitly halt that processor by means of a HLT instruction.

In an MP system, operating systems can place idle processors into a loop that contin uously checks the run queue for runnable software tasks. Logical processors that execute idle loops consume a significant amount of core’s execution resources that might otherwise be used by the other logical processors in the physical package. For this reason, halting idle logical processors optimizes the performance.8 If all logical processors within a physical package are halted, the processor will enter a power- saving state.

8.10.6.4 Potential Usage of MONITOR/MWAIT in C1 Idle Loops

An operating system may also consider replacing HLT with MONITOR/MWAIT in its C1 idle loop. An example is shown in Example 8-26:

Example 8-26. An OS Idle Loop with MONITOR/MWAIT in the C1 Idle Loop

// WorkQueue is a memory location indicating there is a thread // ready to run. A non-zero value for WorkQueue is assumed to // indicate the presence of work to be scheduled on the processor. // The following example assumes that the necessary padding has been // added surrounding WorkQueue to eliminate false wakeups // The idle loop is entered with interrupts disabled. WHILE (1) {

IF (WorkQueue) THEN {

// Schedule work at WorkQueue } ELSE { // No work to do - wait in appropriate C-state handler depending // on Idle time accumulated

IF (IdleTime >= IdleTimeThreshhold) THEN {

// Call appropriate C1, C2, C3 state handler, C1 // handler shown below } } } // C1 handler uses a Halt instruction VOID C1Handler()

8. Excessive transitions into and out of the HALT state could also incur performance penalties. Operating systems should evaluate the performance trade-offs for their operating system.

}

Page 378 of the Intel 253668-032US user manual — STI MWAIT // EAX, ECX = 0 }
Page 378 · click to enlarge
Page 378

MULTIPLE-PROCESSOR MANAGEMENT

MONITOR WorkQueue // Setup of eax with WorkQueue LinearAddress,

// ECX, EDX = 0 IF (WorkQueue != 0) THEN {

STI MWAIT // EAX, ECX = 0 }

8.10.6.5 Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resources

  • Because the logical processors, the order in which threads are dispatched to logical processors for execution can affect the overall efficiency of a system. The following guidelines are recommended for scheduling threads for execution.
  • Dispatch threads to one logical processor per processor core before dispatching threads to the other logical processor sharing execution resources in the same processor core.
  • In an MP system with two or more physical packages, distribute threads out over all the physical processors, rather than concentrate them in one or two physical processors.
  • Use processor affinity to assign a thread to a specific processor core or package, depending on the cache-sharing topology. The practice increases the chance that the processor’s caches will contain some of the thread’s code and data when it is dispatched for execution after being suspended.

8.10.6.6 Eliminate Execution-Based Timing Loops

  • Intel discourages the use of timing loops that depend on a processor’s execution speed to measure time. There are several reasons:
  • Timing loops cause problems when they are calibrated on a IA-32 processor running at one clock speed and then executed on a processor running at another clock speed.
  • Routines for calibrating execution-based timing loops produce unpredictable results when run on an IA-32 processor supporting Intel Hyper-Threading Technology. This is due to the sharing of execution resources between the logical processors within a physical package.

To avoid the problems described, timing loop routines must use a timing mechanism for the loop that does not depend on the execution speed of the logical processors in the system. The following sources are generally available: • A high resolution system timer (for example, an Intel 8254).

{ · }

Page 379 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 379 · click to enlarge
Page 379

MULTIPLE-PROCESSOR MANAGEMENT

  • A high resolution timer within the processor (such as, the local APIC timer or the time-stamp counter).

For additional information, see the Intel® 64 and IA-32 Architectures Optimization Reference Manual.

8.10.6.7 Place Locks and Semaphores in Aligned, 128-Byte Blocks of Memory

When software uses locks or semaphores to synchronize processes, threads, or other code sections; Intel recommends that only one lock or semaphore be present within a cache line (or 128 byte sector, if 128-byte sector is supported). In processors based on Intel NetBurst microarchitecture (which support 128-byte sector consisting of two cache lines), following this recommendation means that each lock or semaphore should be contained in a 128-byte block of memory that begins on a 128-byte boundary. The practice minimizes the bus traffic required to service locks.

Page 380 of the Intel 253668-032US user manual — MULTIPLE-PROCESSOR MANAGEMENT
Page 380 · click to enlarge
Page 380

MULTIPLE-PROCESSOR MANAGEMENT

Page 381 of the Intel 253668-032US user manual — 9.1 INITIALIZATION OVERVIEW
Page 381 · click to enlarge
Page 381

CHAPTER 9 PROCESSOR MANAGEMENT AND INITIALIZATION

This chapter describes the facilities provided for managing processor wide functions and for initializing the processor. The subjects covered include: processor initializa tion, x87 FPU initialization, processor configuration, feature determination, mode switching, the MSRs (in the Pentium, P6 family, Pentium 4, and Intel Xeon proces sors), and the MTRRs (in the P6 family, Pentium 4, and Intel Xeon processors).

9.1 INITIALIZATION OVERVIEW

  • Following power-up or an assertion of the RESET# pin, each processor on the system bus performs a hardware initialization of the processor (known as a hardware reset) and an optional built-in self-test (BIST). A hardware reset sets each processor’s registers to a known state and places the processor in real-address mode. It also invalidates the internal caches, translation lookaside buffers (TLBs) and the branch target buffer (BTB). At this point, the action taken depends on the processor family:
  • Pentium 4 and Intel Xeon processors — All the processors on the system bus (including a single processor in a uniprocessor system) execute the multiple processor (MP) initialization protocol. The processor that is selected through this protocol as the bootstrap processor (BSP) then immediately starts executing software-initialization code in the current code segment beginning at the offset in the EIP register. The application (non-BSP) processors (APs) go into a Wait For Startup IPI (SIPI) state while the BSP is executing initialization code. See Section 8.4, “Multiple-Processor (MP) Initialization,” for more details. Note that in a uniprocessor system, the single Pentium 4 or Intel Xeon processor automatically becomes the BSP.
  • P6 family processors — The action taken is the same as for the Pentium 4 and Intel Xeon processors (as described in the previous paragraph).
  • Pentium processors — In either a singleor dualprocessor system, a single Pentium processor is always pre-designated as the primary processor. Following a reset, the primary processor behaves as follows in both singleand dualprocessor systems. Using the dual-processor (DP) ready initialization protocol, the primary processor immediately starts executing software-initialization code in the current code segment beginning at the offset in the EIP register. The secondary processor (if there is one) goes into a halt state.
  • Intel486 processor — The primary processor (or single processor in a unipro cessor system) immediately starts executing software-initialization code in the current code segment beginning at the offset in the EIP register. (The Intel486 does not automatically execute a DP or MP initialization protocol to determine which processor is the primary processor.)
Page 382 of the Intel 253668-032US user manual — EFLAGS 1 00000002H 00000002H 00000002H
Page 382 · click to enlarge
Page 382

PROCESSOR MANAGEMENT AND INITIALIZATION

The software-initialization code performs all system-specific initialization of the BSP or primary processor and the system logic.

At this point, for MP (or DP) systems, the BSP (or primary) processor wakes up each AP (or secondary) processor to enable those processors to execute self-configuration code.

When all processors are initialized, configured, and synchronized, the BSP or primary processor begins executing an initial operating-system or executive task.

The x87 FPU is also initialized to a known state during hardware reset. x87 FPU soft ware initialization code can then be executed to perform operations such as setting the precision of the x87 FPU and the exception masks. No special initialization of the x87 FPU is required to switch operating modes.

Asserting the INIT# pin on the processor invokes a similar response to a hardware reset. The major difference is that during an INIT, the internal caches, MSRs, MTRRs, and x87 FPU state are left unchanged (although, the TLBs and BTB are invalidated as with a hardware reset). An INIT provides a method for switching from protected to real-address mode while maintaining the contents of the internal caches.

9.1.1 Processor State After Reset

Table 9-1 shows the state of the flags and other registers following power-up for the Pentium 4, Intel Xeon, P6 family, and Pentium processors. The state of control register CR0 is 60000010H (see Figure 9-1). This places the processor is in real- address mode with paging disabled.

9.1.2 Processor Built-In Self-Test (BIST)

Hardware may request that the BIST be performed at power-up. The EAX register is cleared (0H) if the processor passes the BIST. A nonzero value in the EAX register after the BIST indicates that a processor fault was detected. If the BIST is not requested, the contents of the EAX register after a hardware reset is 0H.

The overhead for performing a BIST varies between processor families. For example, the BIST takes approximately 30 million processor clock periods to execute on the Pentium 4 processor. This clock count is model-specific; Intel reserves the right to change the number of periods for any Intel 64 or IA-32 processor, without notification.

Table 9-1. IA-32 Processor States Following Power-up, Reset, or INIT

Register Pentium 4 and Intel

P6 Family Processor Pentium Processor

EFLAGS 1 00000002H 00000002H 00000002H

EIP 0000FFF0H 0000FFF0H 0000FFF0H

CR0 60000010H 2 60000010H 2 60000010H 2

Xeon Processor

Page 383 of the Intel 253668-032US user manual — NA
Page 383 · click to enlarge
Page 383

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-1. IA-32 Processor States Following Power-up, Reset, or INIT (Contd.)

Register Pentium 4 and Intel

P6 Family Processor Pentium Processor

CR2, CR3, CR4 00000000H 00000000H 00000000H

CS Selector = F000H Base = FFFF0000H Limit = FFFFH AR = Present, R/W, Accessed

Selector = F000H Base = FFFF0000H Limit = FFFFH AR = Present, R/W, Accessed

Selector = F000H Base = FFFF0000H Limit = FFFFH AR = Present, R/W, Accessed

SS, DS, ES, FS, GS Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W, Accessed

Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W, Accessed

Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W, Accessed

EDX 00000FxxH 000n06xxH3 000005xxH

EAX 0 4 0 4 0 4

EBX, ECX, ESI, EDI, EBP, ESP

00000000H 00000000H 00000000H

ST0 through ST75 Pwr up or Reset: +0.0 FINIT/FNINIT: Unchanged

Pwr up or Reset+0.0 FINIT/FNINIT: Unchanged
Pwr up or Reset+0.0 FINIT/FNINIT: Unchanged

x87 FPU Control Word5 Pwr up or Reset: 0040H FINIT/FNINIT: 037FH

Pwr up or Reset0040H FINIT/FNINIT: 037FH
Pwr up or Reset0040H FINIT/FNINIT: 037FH

x87 FPU Status Word5 Pwr up or Reset: 0000H FINIT/FNINIT: 0000H

Pwr up or Reset0000H FINIT/FNINIT: 0000H
Pwr up or Reset0000H FINIT/FNINIT: 0000H

x87 FPU Tag Word5 Pwr up or Reset: 5555H FINIT/FNINIT: FFFFH

Pwr up or Reset5555H FINIT/FNINIT: FFFFH
Pwr up or Reset5555H FINIT/FNINIT: FFFFH

x87 FPU Data Operand and CS Seg. Selectors5

Pwr up or Reset0000H FINIT/FNINIT: 0000H
Pwr up or Reset0000H FINIT/FNINIT: 0000H
Pwr up or Reset0000H FINIT/FNINIT: 0000H

x87 FPU Data Operand and Inst. Pointers5

Pwr up or Reset00000000H FINIT/FNINIT: 00000000H
Pwr up or Reset00000000H FINIT/FNINIT: 00000000H
Pwr up or Reset00000000H FINIT/FNINIT: 00000000H

MM0 through MM75 Pwr up or Reset: 0000000000000000H INIT or FINIT/FNINIT: Unchanged

Pentium II and Pentium III Processors Only— Pwr up or Reset: 0000000000000000H INIT or FINIT/FNINIT: Unchanged

Pentium with MMX Technology Only— Pwr up or Reset: 0000000000000000H INIT or FINIT/FNINIT: Unchanged

Pwr up or Reset0000000000000000H INIT: Unchanged

Pentium III processor Only— Pwr up or Reset: 0000000000000000H INIT: Unchanged

NA

MXCSR Pwr up or Reset1F80H INIT: Unchanged

Pentium III processor only- Pwr up or Reset: 1F80H INIT: Unchanged

NA

GDTR, IDTR Base = 00000000H Limit = FFFFH AR = Present, R/W

Base = 00000000H Limit = FFFFH AR = Present, R/W

Base = 00000000H Limit = FFFFH AR = Present, R/W

Xeon Processor · XMM0 through XMM7

Page 384 of the Intel 253668-032US user manual — DR0, DR1, DR2, DR3
Page 384 · click to enlarge
Page 384

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-1. IA-32 Processor States Following Power-up, Reset, or INIT (Contd.)

Register Pentium 4 and Intel

P6 Family Processor Pentium Processor

Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W

Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W

Selector = 0000H Base = 00000000H Limit = FFFFH AR = Present, R/W

DR0, DR1, DR2, DR3

00000000H 00000000H 00000000H

DR6 FFFF0FF0H FFFF0FF0H FFFF0FF0H

DR7 00000400H 00000400H 00000400H

Power up or Reset0H INIT: Unchanged
Power up or Reset0H INIT: Unchanged
Power up or Reset0H INIT: Unchanged

Perf. Counters and Event Select

Power up or Reset0H INIT: Unchanged
Power up or Reset0H INIT: Unchanged
Power up or Reset0H INIT: Unchanged

All Other MSRs Pwr up or Reset: Undefined INIT: Unchanged

Pwr up or ResetUndefined INIT: Unchanged
Pwr up or ResetUndefined INIT: Unchanged

Data and Code Cache, TLBs

Fixed MTRRs Pwr up or Reset: Disabled INIT: Unchanged

Pwr up or ResetDisabled INIT: Unchanged

Variable MTRRs Pwr up or Reset: Disabled INIT: Unchanged

Pwr up or ResetDisabled INIT: Unchanged
Pwr up or ResetUndefined INIT: Unchanged
Pwr up or ResetUndefined INIT: Unchanged
APIC Pwr up or ResetEnabled INIT: Unchanged
Pwr up or ResetEnabled INIT: Unchanged
Pwr up or ResetEnabled INIT: Unchanged

NOTES: 1. The 10 most-significant bits of the EFLAGS register are undefined following a reset. Software should not depend on the states of any of these bits. 2. The CD and NW flags are unchanged, bit 4 is set to 1, all other bits are cleared. 3. Where “n” is the Extended Model Value for the respective processor. 4. If Built-In Self-Test (BIST) is invoked on power up or reset, EAX is 0 only if all tests passed. (BIST cannot be invoked during an INIT.) 5. The state of the x87 FPU and MMX registers is not changed by the execution of an INIT.

Show 8 more labels / short text on this page
Xeon Processor · LDTR, Task Register · Time-Stamp Counter · Invalid Invalid Invalid · Not Implemented · Not Implemented · Machine-Check Architecture · Not Implemented
Page 385 of the Intel 253668-032US user manual — EDX
Page 385 · click to enlarge
Page 385

PROCESSOR MANAGEMENT AND INITIALIZATION

Paging disabled0
Caching disabled1 Not write-through disabled: 1
Alignment check disabled0
Write-protect disabled0

31 19 16 15 0

1 2 3 4 5 6 17 18 28 29 30

T S P G

C D

N W

P A M

W

M P E M 1 N E

P E

External x87 FPU error reporting: 0 (Not used): 1 No task switch: 0 x87 FPU instructions not trapped: 0 WAIT/FWAIT instructions not trapped: 0 Real-address mode: 0

Figure 9-1. Contents of CR0 Register after Reset

9.1.3 Model and Stepping Information

Following a hardware reset, the EDX register contains component identification and revision information (see Figure 9-2). For example, the model, family, and processor type returned for the first processor in the Intel Pentium 4 family is as follows: model (0000B), family (1111B), and processor type (00B).

31 12 11 8 7 4 3 0

16 19 20 23 24

EDX

ID

Family (1111B for the Pentium 4 Processor Family) Model (Beginning with 0000B)

Figure 9-2. Version Information in the EDX Register after Reset

The stepping ID field contains a unique identifier for the processor’s stepping ID or revision level. The extended family and extended model fields were added to the IA-32 architecture in the Pentium 4 processors.

Show 6 more labels / short text on this page
Reserved Reserved · Model Extended Extended · Model Family Stepping · Family · Processor Type · Reserved
Page 386 of the Intel 253668-032US user manual — 9.2.1 Configuring the x87 FPU Environment
Page 386 · click to enlarge
Page 386

PROCESSOR MANAGEMENT AND INITIALIZATION

9.1.4 First Instruction Executed

The first instruction that is fetched and executed following a hardware reset is located at physical address FFFFFFF0H. This address is 16 bytes below the processor’s uppermost physical address. The EPROM containing the software- initialization code must be located at this address.

The address FFFFFFF0H is beyond the 1-MByte addressable range of the processor while in real-address mode. The processor is initialized to this starting address as follows. The CS register has two parts: the visible segment selector part and the hidden base address part. In real-address mode, the base address is normally formed by shifting the 16-bit segment selector value 4 bits to the left to produce a 20-bit base address. However, during a hardware reset, the segment selector in the CS register is loaded with F000H and the base address is loaded with FFFF0000H. The starting address is thus formed by adding the base address to the value in the EIP register (that is, FFFF0000 + FFF0H = FFFFFFF0H).

The first time the CS register is loaded with a new value after a hardware reset, the processor will follow the normal rule for address translation in real-address mode (that is, [CS base address = CS segment selector * 16]). To insure that the base address in the CS register remains unchanged until the EPROM based software- initialization code is completed, the code must not contain a far jump or far call or allow an interrupt to occur (which would cause the CS selector value to be changed).

9.2 X87 FPU INITIALIZATION

Software-initialization code can determine the whether the processor contains an x87 FPU by using the CPUID instruction. The code must then initialize the x87 FPU and set flags in control register CR0 to reflect the state of the x87 FPU environment.

A hardware reset places the x87 FPU in the state shown in Table 9-1. This state is different from the state the x87 FPU is placed in following the execution of an FINIT or FNINIT instruction (also shown in Table 9-1). If the x87 FPU is to be used, the soft ware-initialization code should execute an FINIT/FNINIT instruction following a hard ware reset. These instructions, tag all data registers as empty, clear all the exception masks, set the TOP-of-stack value to 0, and select the default rounding and precision controls setting (round to nearest and 64-bit precision).

If the processor is reset by asserting the INIT# pin, the x87 FPU state is not changed.

9.2.1 Configuring the x87 FPU Environment

Initialization code must load the appropriate values into the MP, EM, and NE flags of control register CR0. These bits are cleared on hardware reset of the processor. Figure 9-2 shows the suggested settings for these flags, depending on the IA-32 processor being initialized. Initialization code can test for the type of processor present before setting or clearing these flags.

Page 387 of the Intel 253668-032US user manual — 9.2.2 Setting the Processor for x87 FPU Software Emulation
Page 387 · click to enlarge
Page 387

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-2. Recommended Settings of EM and MP Flags on IA-32 Processors

EM MP NE IA-32 processor

1 0 1 Intel486™ SX, Intel386™ DX, and Intel386™ SX processors only, without the presence of a math coprocessor.

0 1 1 or 0* Pentium 4, Intel Xeon, P6 family, Pentium, Intel486™ DX, and Intel 487 SX processors, and Intel386 DX and Intel386 SX processors when a companion math coprocessor is present.

0 1 1 or 0* More recent Intel 64 or IA-32 processors

The EM flag determines whether floating-point instructions are executed by the x87 FPU (EM is cleared) or a device-not-available exception (#NM) is generated for all floating-point instructions so that an exception handler can emulate the floating- point operation (EM = 1). Ordinarily, the EM flag is cleared when an x87 FPU or math coprocessor is present and set if they are not present. If the EM flag is set and no x87 FPU, math coprocessor, or floating-point emulator is present, the processor will hang when a floating-point instruction is executed.

The MP flag determines whether WAIT/FWAIT instructions react to the setting of the TS flag. If the MP flag is clear, WAIT/FWAIT instructions ignore the setting of the TS flag; if the MP flag is set, they will generate a device-not-available exception (#NM) if the TS flag is set. Generally, the MP flag should be set for processors with an inte grated x87 FPU and clear for processors without an integrated x87 FPU and without a math coprocessor present. However, an operating system can choose to save the floating-point context at every context switch, in which case there would be no need to set the MP bit.

Table 2-1 shows the actions taken for floating-point and WAIT/FWAIT instructions based on the settings of the EM, MP, and TS flags.

The NE flag determines whether unmasked floating-point exceptions are handled by generating a floating-point error exception internally (NE is set, native mode) or through an external interrupt (NE is cleared). In systems where an external interrupt controller is used to invoke numeric exception handlers (such as MS-DOS-based systems), the NE bit should be cleared.

9.2.2 Setting the Processor for x87 FPU Software Emulation

Setting the EM flag causes the processor to generate a device-not-available excep tion (#NM) and trap to a software exception handler whenever it encounters a floating-point instruction. (Table 9-2 shows when it is appropriate to use this flag.) Setting this flag has two functions:

Page 388 of the Intel 253668-032US user manual — 9.3 CACHE ENABLING
Page 388 · click to enlarge
Page 388

PROCESSOR MANAGEMENT AND INITIALIZATION

  • It allows x87 FPU code to run on an IA-32 processor that has neither an integrated x87 FPU nor is connected to an external math coprocessor, by using a floating-point emulator.
  • It allows floating-point code to be executed using a special or nonstandard floating-point emulator, selected for a particular application, regardless of whether an x87 FPU or math coprocessor is present.

To emulate floating-point instructions, the EM, MP, and NE flag in control register CR0 should be set as shown in Table 9-3.

Table 9-3. Software Emulation Settings of EM, MP, and NE Flags

EM 1

MP 0

NE 1

Regardless of the value of the EM bit, the Intel486 SX processor generates a device- not-available exception (#NM) upon encountering any floating-point instruction.

9.3 CACHE ENABLING

IA-32 processors (beginning with the Intel486 processor) and Intel 64 processors contain internal instruction and data caches. These caches are enabled by clearing the CD and NW flags in control register CR0. (They are set during a hardware reset.) Because all internal cache lines are invalid following reset initialization, it is not necessary to invalidate the cache before enabling caching. Any external caches may require initialization and invalidation using a system-specific initialization and invali dation code sequence.

Depending on the hardware and operating system or executive requirements, addi tional configuration of the processor’s caching facilities will probably be required. Beginning with the Intel486 processor, page-level caching can be controlled with the PCD and PWT flags in page-directory and page-table entries. Beginning with the P6 family processors, the memory type range registers (MTRRs) control the caching characteristics of the regions of physical memory. (For the Intel486 and Pentium processors, external hardware can be used to control the caching characteristics of regions of physical memory.) See Chapter 11, “Memory Cache Control,” for detailed information on configuration of the caching facilities in the Pentium 4, Intel Xeon, and P6 family processors and system memory.

CR0 Bit Value

Page 389 of the Intel 253668-032US user manual — 9.5 MEMORY TYPE RANGE REGISTERS (MTRRS)
Page 389 · click to enlarge
Page 389

PROCESSOR MANAGEMENT AND INITIALIZATION

9.4 MODEL-SPECIFIC REGISTERS (MSRS)

Most IA-32 processors (starting from Pentium processors) and Intel 64 processors contain a model-specific registers (MSRs). A given MSR may not be supported across all families and models for Intel 64 and IA-32 processors. Some MSRs are designated as architectural to simplify software programming; a feature introduced by an archi tectural MSR is expected to be supported in future processors. Non-architectural MSRs are not guaranteed to be supported or to have the same functions on future processors.

  • MSRs that provide control for a number of hardware and software-related features, include:
  • Performance-monitoring counters (see Chapter 20, “Introduction to VirtualMachine Extensions”).
  • Debug extensions (see Chapter 20, “Introduction to Virtual-Machine Exten sions.”).
  • Machine-check exception capability and its accompanying machine-check archi tecture (see Chapter 15, “Machine-Check Architecture”).
  • MTRRs (see Section 11.11, “Memory Type Range Registers (MTRRs)”).
  • Thermal and power management.
  • Instruction-specific support (for example: SYSENTER, SYSEXIT, SWAPGS, etc.).
  • Processor feature/mode support (for example: IA32_EFER, IA32_FEATURE_CONTROL).

The MSRs can be read and written to using the RDMSR and WRMSR instructions, respectively.

When performing software initialization of an IA-32 or Intel 64 processor, many of the MSRs will need to be initialized to set up things like performance-monitoring events, run-time machine checks, and memory types for physical memory.

Lists of available performance-monitoring events are given in Appendix A, “Perfor mance Monitoring Events”, and lists of available MSRs are given in Appendix B, “Model-Specific Registers (MSRs)” The references earlier in this section show where the functions of the various groups of MSRs are described in this manual.

9.5 MEMORY TYPE RANGE REGISTERS (MTRRS)

Memory type range registers (MTRRs) were introduced into the IA-32 architecture with the Pentium Pro processor. They allow the type of caching (or no caching) to be specified in system memory for selected physical address ranges. They allow memory accesses to be optimized for various types of memory such as RAM, ROM, frame buffer memory, and memory-mapped I/O devices.

In general, initializing the MTRRs is normally handled by the software initialization code or BIOS and is not an operating system or executive function. At the very least,

Page 390 of the Intel 253668-032US user manual — 9.7 SOFTWARE INITIALIZATION FOR REAL-ADDRESS MODE OPERATION
Page 390 · click to enlarge
Page 390

PROCESSOR MANAGEMENT AND INITIALIZATION

all the MTRRs must be cleared to 0, which selects the uncached (UC) memory type. See Section 11.11, “Memory Type Range Registers (MTRRs),” for detailed informa tion on the MTRRs.

9.6 INITIALIZING SSE/SSE2/SSE3/SSSE3 EXTENSIONS

For processors that contain SSE/SSE2/SSE3/SSSE3 extensions, steps must be taken when initializing the processor to allow execution of these instructions.

1. Check the CPUID feature flags for the presence of the SSE/SSE2/SSE3/SSSE3 extensions (respectively: EDX bits 25 and 26, ECX bit 0 and 9) and support for the FXSAVE and FXRSTOR instructions (EDX bit 24). Also check for support for the CLFLUSH instruction (EDX bit 19). The CPUID feature flags are loaded in the EDX and ECX registers when the CPUID instruction is executed with a 1 in the EAX register.
2. Set the OSFXSR flag (bit 9 in control register CR4) to indicate that the operating system supports saving and restoring the SSE/SSE2/SSE3/SSSE3 execution environment (XXM and MXCSR registers) with the FXSAVE and FXRSTOR instruc tions, respectively. See Section 2.5, “Control Registers,” for a description of the OSFXSR flag.
3. Set the OSXMMEXCPT flag (bit 10 in control register CR4) to indicate that the operating system supports the handling of SSE/SSE2/SSE3 SIMD floating-point exceptions (#XF). See Section 2.5, “Control Registers,” for a description of the OSXMMEXCPT flag.
4. Set the mask bits and flags in the MXCSR register according to the mode of operation desired for SSE/SSE2/SSE3 SIMD floating-point instructions. See “MXCSR Control and Status Register” in Chapter 10, “Programming with Streaming SIMD Extensions (SSE),” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1 , for a detailed description of the bits and flags in the MXCSR register.

9.7 SOFTWARE INITIALIZATION FOR REAL-ADDRESS MODE OPERATION

Following a hardware reset (either through a power-up or the assertion of the RESET# pin) the processor is placed in real-address mode and begins executing soft ware initialization code from physical address FFFFFFF0H. Software initialization code must first set up the necessary data structures for handling basic system functions, such as a real-mode IDT for handling interrupts and exceptions. If the processor is to remain in real-address mode, software must then load additional operating-system or executive code modules and data structures to allow reliable execution of applica tion programs in real-address mode.

If the processor is going to operate in protected mode, software must load the neces sary data structures to operate in protected mode and then switch to protected

Page 391 of the Intel 253668-032US user manual — 9.8 SOFTWARE INITIALIZATION FOR PROTECTED-MODE OPERATION
Page 391 · click to enlarge
Page 391

PROCESSOR MANAGEMENT AND INITIALIZATION

mode. The protected-mode data structures that must be loaded are described in Section 9.8, “Software Initialization for Protected-Mode Operation.”

9.7.1 Real-Address Mode IDT

In real-address mode, the only system data structure that must be loaded into memory is the IDT (also called the “interrupt vector table”). By default, the address of the base of the IDT is physical address 0H. This address can be changed by using the LIDT instruction to change the base address value in the IDTR. Software initial ization code needs to load interrupt- and exception-handler pointers into the IDT before interrupts can be enabled.

The actual interrupt- and exception-handler code can be contained either in EPROM or RAM; however, the code must be located within the 1-MByte addressable range of the processor in real-address mode. If the handler code is to be stored in RAM, it must be loaded along with the IDT.

9.7.2 NMI Interrupt Handling

  • The NMI interrupt is always enabled (except when multiple NMIs are nested). If the IDT and the NMI interrupt handler need to be loaded into RAM, there will be a period of time following hardware reset when an NMI interrupt cannot be handled. During this time, hardware must provide a mechanism to prevent an NMI interrupt from halting code execution until the IDT and the necessary NMI handler software is loaded. Here are two examples of how NMIs can be handled during the initial states of processor initialization:
  • A simple IDT and NMI interrupt handler can be provided in EPROM. This allows an NMI interrupt to be handled immediately after reset initialization.
  • The system hardware can provide a mechanism to enable and disable NMIs by passing the NMI# signal through an AND gate controlled by a flag in an I/O port. Hardware can clear the flag when the processor is reset, and software can set the flag when it is ready to handle NMI interrupts.

9.8 SOFTWARE INITIALIZATION FOR PROTECTED-MODE OPERATION

The processor is placed in real-address mode following a hardware reset. At this point in the initialization process, some basic data structures and code modules must be loaded into physical memory to support further initialization of the processor, as described in Section 9.7, “Software Initialization for Real-Address Mode Operation.” Before the processor can be switched to protected mode, the software initialization code must load a minimum number of protected mode data structures and code

Page 392 of the Intel 253668-032US user manual — 9.8.1 Protected-Mode System Data Structures
Page 392 · click to enlarge
Page 392

PROCESSOR MANAGEMENT AND INITIALIZATION

  • modules into memory to support reliable operation of the processor in protected mode. These data structures include the following:
  • A IDT.
  • A GDT.
  • A TSS.
  • (Optional) An LDT.
  • If paging is to be used, at least one page directory and one page table.
  • A code segment that contains the code to be executed when the processor switches to protected mode.
  • One or more code modules that contain the necessary interrupt and exception handlers.
  • Software initialization code must also initialize the following system registers before the processor can be switched to protected mode:
  • The GDTR.
  • (Optional.) The IDTR. This register can also be initialized immediately after switching to protected mode, prior to enabling interrupts.
  • Control registers CR1 through CR4.
  • (Pentium 4, Intel Xeon, and P6 family processors only.) The memory type range registers (MTRRs).

With these data structures, code modules, and system registers initialized, the processor can be switched to protected mode by loading control register CR0 with a value that sets the PE flag (bit 0).

9.8.1 Protected-Mode System Data Structures

The contents of the protected-mode system data structures loaded into memory during software initialization, depend largely on the type of memory management the protected-mode operating-system or executive is going to support: flat, flat with paging, segmented, or segmented with paging.

To implement a flat memory model without paging, software initialization code must at a minimum load a GDT with one code and one data-segment descriptor. A null descriptor in the first GDT entry is also required. The stack can be placed in a normal read/write data segment, so no dedicated descriptor for the stack is required. A flat memory model with paging also requires a page directory and at least one page table (unless all pages are 4 MBytes in which case only a page directory is required). See Section 9.8.3, “Initializing Paging.”

Before the GDT can be used, the base address and limit for the GDT must be loaded into the GDTR register using an LGDT instruction.

A multi-segmented model may require additional segments for the operating system, as well as segments and LDTs for each application program. LDTs require segment

Page 393 of the Intel 253668-032US user manual — 9.8.3 Initializing Paging
Page 393 · click to enlarge
Page 393

PROCESSOR MANAGEMENT AND INITIALIZATION

descriptors in the GDT. Some operating systems allocate new segments and LDTs as they are needed. This provides maximum flexibility for handling a dynamic program ming environment. However, many operating systems use a single LDT for all tasks, allocating GDT entries in advance. An embedded system, such as a process controller, might pre-allocate a fixed number of segments and LDTs for a fixed number of application programs. This would be a simple and efficient way to struc ture the software environment of a real-time system.

9.8.2 Initializing Protected-Mode Exceptions and Interrupts

Software initialization code must at a minimum load a protected-mode IDT with gate descriptor for each exception vector that the processor can generate. If interrupt or trap gates are used, the gate descriptors can all point to the same code segment, which contains the necessary exception handlers. If task gates are used, one TSS and accompanying code, data, and task segments are required for each exception handler called with a task gate.

If hardware allows interrupts to be generated, gate descriptors must be provided in the IDT for one or more interrupt handlers.

Before the IDT can be used, the base address and limit for the IDT must be loaded into the IDTR register using an LIDT instruction. This operation is typically carried out immediately after switching to protected mode.

9.8.3 Initializing Paging

  • Paging is controlled by the PG flag in control register CR0. When this flag is clear (its state following a hardware reset), the paging mechanism is turned off; when it is set, paging is enabled. Before setting the PG flag, the following data structures and regis ters must be initialized:
  • Software must load at least one page directory and one page table into physical memory. The page table can be eliminated if the page directory contains a directory entry pointing to itself (here, the page directory and page table reside in the same page), or if only 4-MByte pages are used.
  • Control register CR3 (also called the PDBR register) is loaded with the physical base address of the page directory.
  • (Optional) Software may provide one set of code and data descriptors in the GDT or in an LDT for supervisor mode and another set for user mode.

With this paging initialization complete, paging is enabled and the processor is switched to protected mode at the same time by loading control register CR0 with an image in which the PG and PE flags are set. (Paging cannot be enabled before the processor is switched to protected mode.)

Page 394 of the Intel 253668-032US user manual — 9.8.5 Initializing IA-32e Mode
Page 394 · click to enlarge
Page 394

PROCESSOR MANAGEMENT AND INITIALIZATION

9.8.4 Initializing Multitasking

If the multitasking mechanism is not going to be used and changes between privilege levels are not allowed, it is not necessary load a TSS into memory or to initialize the task register.

If the multitasking mechanism is going to be used and/or changes between privilege levels are allowed, software initialization code must load at least one TSS and an accompanying TSS descriptor. (A TSS is required to change privilege levels because pointers to the privileged-level 0, 1, and 2 stack segments and the stack pointers for these stacks are obtained from the TSS.) TSS descriptors must not be marked as busy when they are created; they should be marked busy by the processor only as a side-effect of performing a task switch. As with descriptors for LDTs, TSS descriptors reside in the GDT.

After the processor has switched to protected mode, the LTR instruction can be used to load a segment selector for a TSS descriptor into the task register. This instruction marks the TSS descriptor as busy, but does not perform a task switch. The processor can, however, use the TSS to locate pointers to privilege-level 0, 1, and 2 stacks. The segment selector for the TSS must be loaded before software performs its first task switch in protected mode, because a task switch copies the current task state into the TSS.

After the LTR instruction has been executed, further operations on the task register are performed by task switching. As with other segments and LDTs, TSSs and TSS descriptors can be either pre-allocated or allocated as needed.

9.8.5 Initializing IA-32e Mode

On Intel 64 processors, the IA32_EFER MSR is cleared on system reset. The oper ating system must be in protected mode with paging enabled before attempting to initialize IA-32e mode. IA-32e mode operation also requires physical-address exten sions with four levels of enhanced paging structures (see Section 4.5, “IA-32e Paging”).

Operating systems should follow this sequence to initialize IA-32e mode:

1. Starting from protected mode, disable paging by setting CR0.PG = 0. Use the MOV CR0 instruction to disable paging (the instruction must be located in an identity-mapped page).
2. Enable physical-address extensions (PAE) by setting CR4.PAE = 1. Failure to enable PAE will result in a #GP fault when an attempt is made to initialize IA-32e mode.
3. Load CR3 with the physical base address of the Level 4 page map table (PML4).
4. Enable IA-32e mode by setting IA32_EFER.LME = 1.
5. Enable paging by setting CR0.PG = 1. This causes the processor to set the IA32_EFER.LMA bit to 1. The MOV CR0 instruction that enables paging and the
Page 395 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 395 · click to enlarge
Page 395

PROCESSOR MANAGEMENT AND INITIALIZATION

following instructions must be located in an identity-mapped page (until such time that a branch to non-identity mapped pages can be effected).

64-bit mode paging tables must be located in the first 4 GBytes of physical-address space prior to activating IA-32e mode. This is necessary because the MOV CR3 instruction used to initialize the page-directory base must be executed in legacy mode prior to activating IA-32e mode (setting CR0.PG = 1 to enable paging). Because MOV CR3 is executed in protected mode, only the lower 32 bits of the register are written, limiting the table location to the low 4 GBytes of memory. Soft ware can relocate the page tables anywhere in physical memory after IA-32e mode is activated.

The processor performs 64-bit mode consistency checks whenever software attempts to modify any of the enable bits directly involved in activating IA-32e mode (IA32_EFER.LME, CR0.PG, and CR4.PAE). It will generate a general protection fault (#GP) if consistency checks fail. 64-bit mode consistency checks ensure that the processor does not enter an undefined mode or state with unpredictable behavior.

  • 64-bit mode consistency checks fail in the following circumstances:
  • An attempt is made to enable or disable IA-32e mode while paging is enabled.
  • IA-32e mode is enabled and an attempt is made to enable paging prior to enabling physical-address extensions (PAE).
  • IA-32e mode is active and an attempt is made to disable physical-address extensions (PAE).
  • If the current CS has the L-bit set on an attempt to activate IA-32e mode.
  • If the TR contains a 16-bit TSS.

9.8.5.1 IA-32e Mode System Data Structures

After activating IA-32e mode, the system-descriptor-table registers (GDTR, LDTR, IDTR, TR) continue to reference legacy protected-mode descriptor tables. Tables referenced by the descriptors all reside in the lower 4 GBytes of linear-address space. After activating IA-32e mode, 64-bit operating-systems should use the LGDT, LLDT, LIDT, and LTR instructions to load the system-descriptor-table registers with refer ences to 64-bit descriptor tables.

9.8.5.2 IA-32e Mode Interrupts and Exceptions

Software must not allow exceptions or interrupts to occur between the time IA-32e mode is activated and the update of the interrupt-descriptor-table register (IDTR) that establishes references to a 64-bit interrupt-descriptor table (IDT). This is because the IDT remains in legacy form immediately after IA-32e mode is activated.

If an interrupt or exception occurs prior to updating the IDTR, a legacy 32-bit inter rupt gate will be referenced and interpreted as a 64-bit interrupt gate with unpredict able results. External interrupts can be disabled by using the CLI instruction.

Non-maskable interrupts (NMI) must be disabled using external hardware.

Page 396 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 396 · click to enlarge
Page 396

PROCESSOR MANAGEMENT AND INITIALIZATION

9.8.5.3 64-bit Mode and Compatibility Mode Operation

IA-32e mode uses two code segment-descriptor bits (CS.L and CS.D, see Figure 3-8) to control the operating modes after IA-32e mode is initialized. If CS.L = 1 and CS.D = 0, the processor is running in 64-bit mode. With this encoding, the default operand size is 32 bits and default address size is 64 bits. Using instruction prefixes, operand size can be changed to 64 bits or 16 bits; address size can be changed to 32 bits.

When IA-32e mode is active and CS.L = 0, the processor operates in compatibility mode. In this mode, CS.D controls default operand and address sizes exactly as it does in the IA-32 architecture. Setting CS.D = 1 specifies default operand and address size as 32 bits. Clearing CS.D to 0 specifies default operand and address size as 16 bits (the CS.L = 1, CS.D = 1 bit combination is reserved).

Compatibility mode execution is selected on a code-segment basis. This mode allows legacy applications to coexist with 64-bit applications running in 64-bit mode. An operating system running in IA-32e mode can execute existing 16-bit and 32-bit applications by clearing their code-segment descriptor’s CS.L bit to 0.

  • In compatibility mode, the following system-level mechanisms continue to operate using the IA-32e-mode architectural semantics:
  • Linear-to-physical address translation uses the 64-bit mode extended pagetranslation mechanism.
  • Interrupts and exceptions are handled using the 64-bit mode mechanisms.
  • System calls (calls through call gates and SYSENTER/SYSEXIT) are handled using the IA-32e mode mechanisms.

9.8.5.4 Switching Out of IA-32e Mode Operation

To return from IA-32e mode to paged-protected mode operation. Operating systems must use the following sequence:

1. Switch to compatibility mode.
2. Deactivate IA-32e mode by clearing CR0.PG = 0. This causes the processor to set IA32_EFER.LMA = 0. The MOV CR0 instruction used to disable paging and subsequent instructions must be located in an identity-mapped page.
3. Load CR3 with the physical base address of the legacy page-table-directory base address.
4. Disable IA-32e mode by setting IA32_EFER.LME = 0.
5. Enable legacy paged-protected mode by setting CR0.PG = 1
6. A branch instruction must follow the MOV CR0 that enables paging. Both the MOV CR0 and the branch instruction must be located in an identity-mapped page.

Registers only available in 64-bit mode (R8-R15 and XMM8-XMM15) are preserved across transitions from 64-bit mode into compatibility mode then back into 64-bit mode. However, values of R8-R15 and XMM8-XMM15 are undefined after transitions

Page 397 of the Intel 253668-032US user manual — 9.9.1 Switching to Protected Mode
Page 397 · click to enlarge
Page 397

PROCESSOR MANAGEMENT AND INITIALIZATION

from 64-bit mode through compatibility mode to legacy or real mode and then back through compatibility mode to 64-bit mode.

9.9 MODE SWITCHING

To use the processor in protected mode after hardware or software reset, a mode switch must be performed from real-address mode. Once in protected mode, soft ware generally does not need to return to real-address mode. To run software written to run in real-address mode (8086 mode), it is generally more convenient to run the software in virtual-8086 mode, than to switch back to real-address mode.

9.9.1 Switching to Protected Mode

Before switching to protected mode from real mode, a minimum set of system data structures and code modules must be loaded into memory, as described in Section 9.8, “Software Initialization for Protected-Mode Operation.” Once these tables are created, software initialization code can switch into protected mode.

Protected mode is entered by executing a MOV CR0 instruction that sets the PE flag in the CR0 register. (In the same instruction, the PG flag in register CR0 can be set to enable paging.) Execution in protected mode begins with a CPL of 0.

Intel 64 and IA-32 processors have slightly different requirements for switching to protected mode. To insure upwards and downwards code compatibility with Intel 64 and IA-32 processors, we recommend that you follow these steps:

1. Disable interrupts. A CLI instruction disables maskable hardware interrupts. NMI interrupts can be disabled with external circuitry. (Software must guarantee that no exceptions or interrupts are generated during the mode switching operation.)
2. Execute the LGDT instruction to load the GDTR register with the base address of the GDT.
3. Execute a MOV CR0 instruction that sets the PE flag (and optionally the PG flag) in control register CR0.
4. Immediately following the MOV CR0 instruction, execute a far JMP or far CALL instruction. (This operation is typically a far jump or call to the next instruction in the instruction stream.)
5. The JMP or CALL instruction immediately after the MOV CR0 instruction changes the flow of execution and serializes the processor.
6. If paging is enabled, the code for the MOV CR0 instruction and the JMP or CALL instruction must come from a page that is identity mapped (that is, the linear address before the jump is the same as the physical address after paging and protected mode is enabled). The target instruction for the JMP or CALL instruction does not need to be identity mapped.
Page 398 of the Intel 253668-032US user manual — 9.9.2 Switching Back to Real-Address Mode
Page 398 · click to enlarge
Page 398

PROCESSOR MANAGEMENT AND INITIALIZATION

7. If a local descriptor table is going to be used, execute the LLDT instruction to load the segment selector for the LDT in the LDTR register.
8. Execute the LTR instruction to load the task register with a segment selector to the initial protected-mode task or to a writable area of memory that can be used to store TSS information on a task switch.
9. After entering protected mode, the segment registers continue to hold the contents they had in real-address mode. The JMP or CALL instruction in step 4 resets the CS register. Perform one of the following operations to update the contents of the remaining segment registers.

— Reload segment registers DS, SS, ES, FS, and GS. If the ES, FS, and/or GS registers are not going to be used, load them with a null selector.

— Perform a JMP or CALL instruction to a new task, which automatically resets the values of the segment registers and branches to a new code segment.

10. Execute the LIDT instruction to load the IDTR register with the address and limit of the protected-mode IDT.
11. Execute the STI instruction to enable maskable hardware interrupts and perform the necessary hardware operation to enable NMI interrupts.

Random failures can occur if other instructions exist between steps 3 and 4 above. Failures will be readily seen in some situations, such as when instructions that refer ence memory are inserted between steps 3 and 4 while in system management mode.

9.9.2 Switching Back to Real-Address Mode

The processor switches from protected mode back to real-address mode if software clears the PE bit in the CR0 register with a MOV CR0 instruction. A procedure that re- enters real-address mode should perform the following steps:

1. Disable interrupts. A CLI instruction disables maskable hardware interrupts. NMI interrupts can be disabled with external circuitry.
2. If paging is enabled, perform the following operations:

— Transfer program control to linear addresses that are identity mapped to physical addresses (that is, linear addresses equal physical addresses).

— Insure that the GDT and IDT are in identity mapped pages.

— Clear the PG bit in the CR0 register.

— Move 0H into the CR3 register to flush the TLB.

3. Transfer program control to a readable segment that has a limit of 64 KBytes (FFFFH). This operation loads the CS register with the segment limit required in real-address mode.
Page 399 of the Intel 253668-032US user manual — 9.10 INITIALIZATION AND MODE SWITCHING EXAMPLE
Page 399 · click to enlarge
Page 399

PROCESSOR MANAGEMENT AND INITIALIZATION

4. Load segment registers SS, DS, ES, FS, and GS with a selector for a descriptor containing the following values, which are appropriate for real-address mode:

— Limit = 64 KBytes (0FFFFH)

— Byte granular (G = 0)

— Expand up (E = 0)

— Writable (W = 1)

— Present (P = 1)

— Base = any value

5. The segment registers must be loaded with non-null segment selectors or the segment registers will be unusable in real-address mode. Note that if the segment registers are not reloaded, execution continues using the descriptor attributes loaded during protected mode.
6. Execute an LIDT instruction to point to a real-address mode interrupt table that is within the 1-MByte real-address mode address range.
7. Clear the PE flag in the CR0 register to switch to real-address mode.
8. Execute a far JMP instruction to jump to a real-address mode program. This operation flushes the instruction queue and loads the appropriate base and access rights values in the CS register.
9. Load the SS, DS, ES, FS, and GS registers as needed by the real-address mode code. If any of the registers are not going to be used in real-address mode, write 0s to them.
10. Execute the STI instruction to enable maskable hardware interrupts and perform the necessary hardware operation to enable NMI interrupts.

NOTE

All the code that is executed in steps 1 through 9 must be in a single page and the linear addresses in that page must be identity mapped to physical addresses.

9.10 INITIALIZATION AND MODE SWITCHING EXAMPLE

  • This section provides an initialization and mode switching example that can be incor porated into an application. This code was originally written to initialize the Intel386 processor, but it will execute successfully on the Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors. The code in this example is intended to reside in EPROM and to run following a hardware reset of the processor. The function of the code is to do the following:
  • Establish a basic real-address mode operating environment.
  • Load the necessary protected-mode system data structures into RAM.
Page 400 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 400 · click to enlarge
Page 400

PROCESSOR MANAGEMENT AND INITIALIZATION

  • Load the system registers with the necessary pointers to the data structures and the appropriate flag settings for protected-mode operation.
  • Switch the processor to protected mode.

Figure 9-3 shows the physical memory layout for the processor following a hardware reset and the starting point of this example. The EPROM that contains the initializa tion code resides at the upper end of the processor’s physical memory address range, starting at address FFFFFFFFH and going down from there. The address of the first instruction to be executed is at FFFFFFF0H, the default starting address for the processor following a hardware reset.

The main steps carried out in this example are summarized in Table 9-4. The source listing for the example (with the filename STARTUP.ASM) is given in Example 9-1. The line numbers given in Table 9-4 refer to the source listing.

  • The following are some additional notes concerning this example:
  • When the processor is switched into protected mode, the original code segment base-address value of FFFF0000H (located in the hidden part of the CS register) is retained and execution continues from the current offset in the EIP register. The processor will thus continue to execute code in the EPROM until a far jump or call is made to a new code segment, at which time, the base address in the CS register will be changed.
  • Maskable hardware interrupts are disabled after a hardware reset and should remain disabled until the necessary interrupt handlers have been installed. The NMI interrupt is not disabled following a reset. The NMI# pin must thus be inhibited from being asserted until an NMI handler has been loaded and made available to the processor.
  • The use of a temporary GDT allows simple transfer of tables from the EPROM to anywhere in the RAM area. A GDT entry is constructed with its base pointing to address 0 and a limit of 4 GBytes. When the DS and ES registers are loaded with this descriptor, the temporary GDT is no longer needed and can be replaced by the application GDT.
  • This code loads one TSS and no LDTs. If more TSSs exist in the application, they must be loaded into RAM. If there are LDTs they may be loaded as well.
Page 401 of the Intel 253668-032US user manual — FFFF 0000H
Page 401 · click to enlarge
Page 401

PROCESSOR MANAGEMENT AND INITIALIZATION

FFFF FFFFH After Reset

[CS.BASE+EIP] FFFF FFF0H

64K EPROM

EIP = 0000 FFF0H

CS.BASE = FFFF 0000H DS.BASE = 0H ES.BASE = 0H SS.BASE = 0H ESP = 0H

FFFF 0000H

[SP, DS, SS, ES]

Figure 9-3. Processor State After Reset

Table 9-4. Main Initialization Steps in STARTUP.ASM Source Listing

STARTUP.ASM Line Numbers

157 157 Jump (short) to the entry code in the EPROM

162 169 Construct a temporary GDT in RAM with one entry: 0 - null 1 - R/W data segment, base = 0, limit = 4 GBytes

171 172 Load the GDTR to point to the temporary GDT

174 177 Load CR0 with PE flag set to switch to protected mode

179 181 Jump near to clear real mode instruction queue

184 186 Load DS, ES registers with GDT[1] descriptor, so both point to the entire physical memory space

Description · From To

Page 402 of the Intel 253668-032US user manual — 9.10.1 Assembler Usage
Page 402 · click to enlarge
Page 402

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-4. Main Initialization Steps in STARTUP.ASM Source Listing (Contd.)

STARTUP.ASM Line Numbers

188 195 Perform specific board initialization that is imposed by the new protected mode

196 218 Copy the application's GDT from ROM into RAM

220 238 Copy the application's IDT from ROM into RAM

241 243 Load application's GDTR

244 245 Load application's IDTR

247 261 Copy the application's TSS from ROM into RAM

263 267 Update TSS descriptor and other aliases in GDT (GDT alias or IDT alias)

277 277 Load the task register (without task switch) using LTR instruction

282 286 Load SS, ESP with the value found in the application's TSS

287 287 Push EFLAGS value found in the application's TSS

288 288 Push CS value found in the application's TSS

289 289 Push EIP value found in the application's TSS

290 293 Load DS, ES with the value found in the application's TSS

296 296 Perform IRET; pop the above values and enter the application code

9.10.1 Assembler Usage

  • In this example, the Intel assembler ASM386 and build tools BLD386 are used to assemble and build the initialization code module. The following assumptions are used when using the Intel ASM386 and BLD386 tools.
  • The ASM386 will generate the right operand size opcodes according to the codesegment attribute. The attribute is assigned either by the ASM386 invocation controls or in the code-segment definition.
  • If a code segment that is going to run in real-address mode is defined, it must be set to a USE 16 attribute. If a 32-bit operand is used in an instruction in this code segment (for example, MOV EAX, EBX), the assembler automatically generates an operand prefix for the instruction that forces the processor to execute a 32-bit operation, even though its default code-segment attribute is 16-bit.
  • Intel's ASM386 assembler allows specific use of the 16or 32-bit instructions, for example, LGDTW, LGDTD, IRETD. If the generic instruction LGDT is used, the defaultsegment attribute will be used to generate the right opcode.

Description · From To

Page 403 of the Intel 253668-032US user manual — LINE SOURCE
Page 403 · click to enlarge
Page 403

PROCESSOR MANAGEMENT AND INITIALIZATION

9.10.2 STARTUP.ASM Listing

Example 9-1 provides high-level sample code designed to move the processor into protected mode. This listing does not include any opcode and offset information.

Example 9-1. STARTUP.ASM

MS-DOS* 5.0(045-N) 386(TM) MACRO ASSEMBLER STARTUP 09:44:51 08/19/92 PAGE 1

MS-DOS 5.0(045-N) 386(TM) MACRO ASSEMBLER V4.0, ASSEMBLY OF MODULE STARTUP OBJECT MODULE PLACED IN startup.obj ASSEMBLER INVOKED BY: f:\386tools\ASM386.EXE startup.a58 pw (132 )

LINE SOURCE

1 NAME STARTUP 2 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 4 ; 5 ; ASSUMPTIONS: 6 ; 7 ; 1. The bottom 64K of memory is ram, and can be used for 8 ; scratch space by this module. 9 ; 10 ; 2. The system has sufficient free usable ram to copy the 11 ; initial GDT, IDT, and TSS 12 ; 13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 15 ; configuration data - must match with build definition 16 17 CS_BASE EQU 0FFFF0000H 18 19 ; CS_BASE is the linear address of the segment STARTUP_CODE 20 ; - this is specified in the build language file 21 22 RAM_START EQU 400H 23 24 ; RAM_START is the start of free, usable ram in the linear 25 ; memory space. The GDT, IDT, and initial TSS will be 26 ; copied above this space, and a small data segment will be 27 ; discarded at this linear address. The 32-bit word at

Page 404 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 404 · click to enlarge
Page 404

PROCESSOR MANAGEMENT AND INITIALIZATION

28 ; RAM_START will contain the linear address of the first 29 ; free byte above the copied tables - this may be useful if 30 ; a memory manager is used. 31 32 TSS_INDEX EQU 10 33 34 ; TSS_INDEX is the index of the TSS of the first task to 35 ; run after startup 36 37 38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 39 40 ; STRUCTURES and EQU 41 ; structures for system data 42 43 ; TSS structure 44 TASK_STATE STRUC 45 link DW ? 46 link_h DW ? 47 ESP0 DD ? 48 SS0 DW ? 49 SS0_h DW ? 50 ESP1 DD ? 51 SS1 DW ? 52 SS1_h DW ? 53 ESP2 DD ? 54 SS2 DW ? 55 SS2_h DW ? 56 CR3_reg DD ? 57 EIP_reg DD ? 58 EFLAGS_regDD ? 59 EAX_reg DD ? 60 ECX_reg DD ? 61 EDX_reg DD ? 62 EBX_reg DD ? 63 ESP_reg DD ? 64 EBP_reg DD ? 65 ESI_reg DD ? 66 EDI_reg DD ? 67 ES_reg DW ? 68 ES_h DW ? 69 CS_reg DW ? 70 CS_h DW ?

Page 405 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 405 · click to enlarge
Page 405

PROCESSOR MANAGEMENT AND INITIALIZATION

71 SS_reg DW ? 72 SS_h DW ? 73 DS_reg DW ? 74 DS_h DW ? 75 FS_reg DW ? 76 FS_h DW ? 77 GS_reg DW ? 78 GS_h DW ? 79 LDT_reg DW ? 80 LDT_h DW ? 81 TRAP_reg DW ? 82 IO_map_baseDW ? 83 TASK_STATE ENDS 84 85 ; basic structure of a descriptor 86 DESC STRUC 87 lim_0_15 DW ? 88 bas_0_15 DW ? 89 bas_16_23DB ? 90 access DB ? 91 gran DB ? 92 bas_24_31DB ? 93 DESC ENDS 94 95 ; structure for use with LGDT and LIDT instructions 96 TABLE_REG STRUC 97 table_limDW ? 98 table_linearDD ? 99 TABLE_REG ENDS 100 101 ; offset of GDT and IDT descriptors in builder generated GDT 102 GDT_DESC_OFF EQU 1*SIZE(DESC) 103 IDT_DESC_OFF EQU 2*SIZE(DESC) 104 105 ; equates for building temporary GDT in RAM 106 LINEAR_SEL EQU 1*SIZE (DESC) 107 LINEAR_PROTO_LO EQU 00000FFFFH ; LINEAR_ALIAS 108 LINEAR_PROTO_HI EQU 000CF9200H 109 110 ; Protection Enable Bit in CR0 111 PE_BIT EQU 1B 112 113 ;

Page 406 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 406 · click to enlarge
Page 406

PROCESSOR MANAGEMENT AND INITIALIZATION

114 115 ; DATA SEGMENT 116 117 ; Initially, this data segment starts at linear 0, according 118 ; to the processor’s power-up state. 119 120 STARTUP_DATA SEGMENT RW 121 122 free_mem_linear_base LABEL DWORD 123 TEMP_GDT LABEL BYTE ; must be first in segment 124 TEMP_GDT_NULL_DESC DESC 125 TEMP_GDT_LINEAR_DESC DESC 126 127 ; scratch areas for LGDT and LIDT instructions 128 TEMP_GDT_SCRATCH TABLE_REG 129 APP_GDT_RAM TABLE_REG 130 APP_IDT_RAM TABLE_REG 131 ; align end_data 132 fill DW ? 133 134 ; last thing in this segment - should be on a dword boundary 135 end_data LABEL BYTE 136 137 STARTUP_DATA ENDS 138 ; 139 140 141 ; CODE SEGMENT 142 STARTUP_CODE SEGMENT ER PUBLIC USE16 143 144 ; filled in by builder 145 PUBLIC GDT_EPROM 146 GDT_EPROM TABLE_REG 147 148 ; filled in by builder 149 PUBLIC IDT_EPROM 150 IDT_EPROM TABLE_REG 151 152 ; entry point into startup code - the bootstrap will vector 153 ; here with a near JMP generated by the builder. This 154 ; label must be in the top 64K of linear memory. 155 156 PUBLIC STARTUP 157 STARTUP: 158

Page 407 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 407 · click to enlarge
Page 407

PROCESSOR MANAGEMENT AND INITIALIZATION

159 ; DS,ES address the bottom 64K of flat linear memory 160 ASSUME DS:STARTUP_DATA, ES:STARTUP_DATA 161 ; See Figure 9-4 162 ; load GDTR with temporary GDT 163 LEA EBX,TEMP_GDT ; build the TEMP_GDT in low ram, 164 MOV DWORD PTR [EBX],0 ; where we can address 165 MOV DWORD PTR [EBX]+4,0 166 MOV DWORD PTR [EBX]+8, LINEAR_PROTO_LO 167 MOV DWORD PTR [EBX]+12, LINEAR_PROTO_HI 168 MOV TEMP_GDT_scratch.table_linear,EBX 169 MOV TEMP_GDT_scratch.table_lim,15 170 171 DB 66H; execute a 32 bit LGDT 172 LGDT TEMP_GDT_scratch 173 174 ; enter protected mode 175 MOV EBX,CR0 176 OR EBX,PE_BIT 177 MOV CR0,EBX 178

179 ; clear prefetch queue 180 JMP CLEAR_LABEL 181 CLEAR_LABEL: 182 183 ; make DS and ES address 4G of linear memory 184 MOV CX,LINEAR_SEL 185 MOV DS,CX 186 MOV ES,CX 187 188 ; do board specific initialization 189 ; 190 ; 191 ; 192 ; 193 194 195 ; See Figure 9-5 196 ; copy EPROM GDT to ram at: 197 ; RAM_START + size (STARTUP_DATA) 198 MOV EAX,RAM_START 199 ADD EAX,OFFSET (end_data) 200 MOV EBX,RAM_START

Page 408 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 408 · click to enlarge
Page 408

PROCESSOR MANAGEMENT AND INITIALIZATION

201 MOV ECX, CS_BASE 202 ADD ECX, OFFSET (GDT_EPROM) 203 MOV ESI, [ECX].table_linear 204 MOV EDI,EAX 205 MOVZX ECX, [ECX].table_lim 206 MOV APP_GDT_ram[EBX].table_lim,CX 207 INC ECX 208 MOV EDX,EAX 209 MOV APP_GDT_ram[EBX].table_linear,EAX 210 ADD EAX,ECX 211 REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI] 212 213 ; fixup GDT base in descriptor 214 MOV ECX,EDX 215 MOV [EDX].bas_0_15+GDT_DESC_OFF,CX 216 ROR ECX,16 217 MOV [EDX].bas_16_23+GDT_DESC_OFF,CL 218 MOV [EDX].bas_24_31+GDT_DESC_OFF,CH 219 220 ; copy EPROM IDT to ram at: 221 ; RAM_START+size(STARTUP_DATA)+SIZE (EPROM GDT) 222 MOV ECX, CS_BASE 223 ADD ECX, OFFSET (IDT_EPROM) 224 MOV ESI, [ECX].table_linear 225 MOV EDI,EAX 226 MOVZX ECX, [ECX].table_lim 227 MOV APP_IDT_ram[EBX].table_lim,CX 228 INC ECX 229 MOV APP_IDT_ram[EBX].table_linear,EAX 230 MOV EBX,EAX 231 ADD EAX,ECX 232 REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI] 233 234 ; fixup IDT pointer in GDT 235 MOV [EDX].bas_0_15+IDT_DESC_OFF,BX 236 ROR EBX,16 237 MOV [EDX].bas_16_23+IDT_DESC_OFF,BL 238 MOV [EDX].bas_24_31+IDT_DESC_OFF,BH 239 240 ; load GDTR and IDTR 241 MOV EBX,RAM_START 242 DB 66H ; execute a 32 bit LGDT 243 LGDT APP_GDT_ram[EBX] 244 DB 66H ; execute a 32 bit LIDT 245 LIDT APP_IDT_ram[EBX]

Page 409 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 409 · click to enlarge
Page 409

PROCESSOR MANAGEMENT AND INITIALIZATION

246 247 ; move the TSS 248 MOV EDI,EAX 249 MOV EBX,TSS_INDEX*SIZE(DESC) 250 MOV ECX,GDT_DESC_OFF ;build linear address for TSS 251 MOV GS,CX 252 MOV DH,GS:[EBX].bas_24_31 253 MOV DL,GS:[EBX].bas_16_23 254 ROL EDX,16 255 MOV DX,GS:[EBX].bas_0_15 256 MOV ESI,EDX 257 LSL ECX,EBX 258 INC ECX 259 MOV EDX,EAX 260 ADD EAX,ECX 261 REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI] 262 263 ; fixup TSS pointer 264 MOV GS:[EBX].bas_0_15,DX 265 ROL EDX,16 266 MOV GS:[EBX].bas_24_31,DH 267 MOV GS:[EBX].bas_16_23,DL 268 ROL EDX,16 269 ;save start of free ram at linear location RAMSTART 270 MOV free_mem_linear_base+RAM_START,EAX 271 272 ;assume no LDT used in the initial task - if necessary, 273 ;code to move the LDT could be added, and should resemble 274 ;that used to move the TSS 275 276 ; load task register 277 LTR BX ; No task switch, only descriptor loading 278 ; See Figure 9-6 279 ; load minimal set of registers necessary to simulate task 280 ; switch 281 282 283 MOV AX,[EDX].SS_reg ; start loading registers 284 MOV EDI,[EDX].ESP_reg 285 MOV SS,AX 286 MOV ESP,EDI ; stack now valid 287 PUSH DWORD PTR [EDX].EFLAGS_reg 288 PUSH DWORD PTR [EDX].CS_reg

Page 410 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 410 · click to enlarge
Page 410

PROCESSOR MANAGEMENT AND INITIALIZATION

289 PUSH DWORD PTR [EDX].EIP_reg 290 MOV AX,[EDX].DS_reg 291 MOV BX,[EDX].ES_reg 292 MOV DS,AX ; DS and ES no longer linear memory 293 MOV ES,BX 294 295 ; simulate far jump to initial task 296 IRETD 297 298 STARTUP_CODE ENDS *** WARNING #377 IN 298, (PASS 2) SEGMENT CONTAINS PRIVILEGED INSTRUCTION(S) 299 300 END STARTUP, DS:STARTUP_DATA, SS:STARTUP_DATA 301 302

ASSEMBLY COMPLETE, 1 WARNING, NO ERRORS.

Page 411 of the Intel 253668-032US user manual — DS, ES = GDT[1] 4 GB
Page 411 · click to enlarge
Page 411

PROCESSOR MANAGEMENT AND INITIALIZATION

FFFF FFFFH

START: [CS.BASE+EIP]

FFFF 0000H

  • Jump near start
  • Construct TEMP_GDT
  • LGDT
  • Move to protected mode

DS, ES = GDT[1] 4 GB

0 GDT [1] GDT [0]

TEMP_GDT

Figure 9-4. Constructing Temporary GDT and Switching to Protected Mode (Lines

162-172 of List File)

GDT_SCRATCH Base · Limit · Base=0, Limit=4G

Page 412 of the Intel 253668-032US user manual — TSS RAM
Page 412 · click to enlarge
Page 412

PROCESSOR MANAGEMENT AND INITIALIZATION

FFFF FFFFH

TSS

IDT GDT

  • Move the GDT, IDT, TSS

from ROM to RAM

  • Fix Aliases
  • LTR

TSS RAM

IDT RAM

GDT RAM

RAM_START

Figure 9-5. Moving the GDT, IDT, and TSS from ROM to RAM (Lines 196-261 of List

File)

Page 413 of the Intel 253668-032US user manual — 9.10.3 MAIN.ASM Source Code
Page 413 · click to enlarge
Page 413

PROCESSOR MANAGEMENT AND INITIALIZATION

EIP EFLAGS

SS = TSS.SS ESP = TSS.ESP PUSH TSS.EFLAG PUSH TSS.CS PUSH TSS.EIP ES = TSS.ES DS = TSS.DS IRET

ESP

ES

CS SS

DS

GDT

TSS RAM

IDT RAM GDT Alias

GDT RAM RAM_START

Figure 9-6. Task Switching (Lines 282-296 of List File)

9.10.3 MAIN.ASM Source Code

The file MAIN.ASM shown in Example 9-2 defines the data and stack segments for this application and can be substituted with the main module task written in a high- level language that is invoked by the IRET instruction executed by STARTUP.ASM.

Example 9-2. MAIN.ASM

NAME main_module data SEGMENT RW

dw 1000 dup(?) DATA ENDS stack stackseg 800

Show 4 more labels / short text on this page
• • · • • • · • · IDT Alias
Page 414 of the Intel 253668-032US user manual — NOT INTENABLED) ;
Page 414 · click to enlarge
Page 414

PROCESSOR MANAGEMENT AND INITIALIZATION

CODE SEGMENT ER use32 PUBLIC main_start:

nop nop nop CODE ENDS END main_start, ds:data, ss:stack

9.10.4 Supporting Files

The batch file shown in Example 9-3 can be used to assemble the source code files STARTUP.ASM and MAIN.ASM and build the final application.

Example 9-3. Batch File to Assemble and Build the Application

ASM386 STARTUP.ASM ASM386 MAIN.ASM BLD386 STARTUP.OBJ, MAIN.OBJ buildfile(EPROM.BLD) bootstrap(STARTUP) Bootload

BLD386 performs several operations in this example: It allocates physical memory location to segments and tables. It generates tables using the build file and the input files. It links object files and resolves references. It generates a boot-loadable file to be programmed into the EPROM.

Example 9-4 shows the build file used as an input to BLD386 to perform the above functions.

Example 9-4. Build File

INIT_BLD_EXAMPLE;

SEGMENT *SEGMENTS(DPL = 0) , startup.startup_code(BASE = 0FFFF0000H) ;

TASK BOOT_TASK(OBJECT = startup, INITIAL,DPL = 0,

NOT INTENABLED) , PROTECTED_MODE_TASK(OBJECT = main_module,DPL = 0,

NOT INTENABLED) ;

Page 415 of the Intel 253668-032US user manual — END
Page 415 · click to enlarge
Page 415

PROCESSOR MANAGEMENT AND INITIALIZATION

TABLE GDT ( LOCATION = GDT_EPROM , ENTRY = ( 10: PROTECTED_MODE_TASK , startup.startup_code , startup.startup_data , main_module.data , main_module.code , main_module.stack

IDT ( LOCATION = IDT_EPROM );

MEMORY ( RESERVE = (0..3FFFH

-- Area for the GDT, IDT, TSS copied from ROM , 60000H..0FFFEFFFFH) , RANGE = (ROM_AREA = ROM (0FFFF0000H..0FFFFFFFFH))

-- Eprom size 64K , RANGE = (RAM_AREA = RAM (4000H..05FFFFH)) );

END

Table 9-5 shows the relationship of each build item with an ASM source file.

Table 9-5. Relationship Between BLD Item and ASM Source File

Item ASM386 and Startup.A58

BLD386 Controls and BLD file

Bootstrap public startup startup:

Near jump at 0FFFFFFF0H to start.

GDT location public GDT_EPROM GDT_EPROM TABLE_REG

TABLE GDT(location = GDT_EPROM)

The location of the GDT will be programmed into the GDT_EPROM location.

IDT location public IDT_EPROM IDT_EPROM TABLE_REG

TABLE IDT(location = IDT_EPROM

The location of the IDT will be programmed into the IDT_EPROM location.

) ), · Effect · bootstrap start(startup)

Page 416 of the Intel 253668-032US user manual — 9.11 MICROCODE UPDATE FACILITIES
Page 416 · click to enlarge
Page 416

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-5. Relationship Between BLD Item and ASM Source File (Contd.)

Item ASM386 and Startup.A58

BLD386 Controls and BLD file

RAM start RAM_START equ 400H memory (reserve = (0..3FFFH)) RAM_START is used as the ram destination for moving the tables. It must be excluded from the application's segment area.

Location of the application TSS in the GDT

TSS_INDEX EQU 10 TABLE GDT( ENTRY = (10: PROTECTED_MODE_ TASK))

Put the descriptor of the application TSS in GDT entry 10.

EPROM size and location

size and location of the initialization code

SEGMENT startup.code (base = 0FFFF0000H) ...memory (RANGE( ROM_AREA = ROM(x..y))

Initialization code size must be less than 64K and resides at upper most 64K of the 4-GByte memory space.

9.11 MICROCODE UPDATE FACILITIES

The Pentium 4, Intel Xeon, and P6 family processors have the capability to correct errata by loading an Intel-supplied data block into the processor. The data block is called a microcode update. This section describes the mechanisms the BIOS needs to provide in order to use this feature during system initialization. It also describes a specification that permits the incorporation of future updates into a system BIOS.

Intel considers the release of a microcode update for a silicon revision to be the equivalent of a processor stepping and completes a full-stepping level validation for releases of microcode updates.

A microcode update is used to correct errata in the processor. The BIOS, which has an update loader, is responsible for loading the update on processors during system initialization (Figure 9-7). There are two steps to this process: the first is to incorpo rate the necessary update data blocks into the BIOS; the second is to load update data blocks into the processor.

Effect

Page 417 of the Intel 253668-032US user manual — 9.11.1 Microcode Update
Page 417 · click to enlarge
Page 417

PROCESSOR MANAGEMENT AND INITIALIZATION

CPU

BIOS

Figure 9-7. Applying Microcode Updates

9.11.1 Microcode Update

A microcode update consists of an Intel-supplied binary that contains a descriptive header and data. No executable code resides within the update. Each microcode update is tailored for a specific list of processor signatures. A mismatch of the processor’s signature with the signature contained in the update will result in a failure to load. A processor signature includes the extended family, extended model, type, family, model, and stepping of the processor (starting with processor family 0fH, model 03H, a given microcode update may be associated with one of multiple processor signatures; see Section 9.11.2 for detail).

Microcode updates are composed of a multi-byte header, followed by encrypted data and then by an optional extended signature table. Table 9-6 provides a definition of the fields; Table 9-7 shows the format of an update.

The header is 48 bytes. The first 4 bytes of the header contain the header version. The update header and its reserved fields are interpreted by software based upon the header version. An encoding scheme guards against tampering and provides a means for determining the authenticity of any given update. For microcode updates with a data size field equal to 00000000H, the size of the microcode update is 2048 bytes. The first 48 bytes contain the microcode update header. The remaining 2000 bytes contain encrypted data.

For microcode updates with a data size not equal to 00000000H, the total size field specifies the size of the microcode update. The first 48 bytes contain the microcode update header. The second part of the microcode update is the encrypted data. The data size field of the microcode update header specifies the encrypted data size, its value must be a multiple of the size of DWORD. The total size field of the microcode update header specifies the encrypted data size plus the header size; its value must be in multiples of 1024 bytes (1 KBytes). The optional extended signature table if implemented follows the encrypted data, and its size is calculated by (Total Size – (Data Size + 48)).

Update Loader · Update · Blocks New Update

Page 418 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 418 · click to enlarge
Page 418

PROCESSOR MANAGEMENT AND INITIALIZATION

NOTE

The optional extended signature table is supported starting with processor family 0FH, model 03H.

Table 9-6. Microcode Update Field Definitions

Field Name Offset (bytes)

Header Version 0 4 Version number of the update header.

Update Revision 4 4 Unique version number for the update, the basis for the update signature provided by the processor to indicate the current update functioning within the processor. Used by the BIOS to authenticate the update and verify that the processor loads successfully. The value in this field cannot be used for processor stepping identification alone. This is a signed 32-bit number.

Date 8 4 Date of the update creation in binary format: mmddyyyy (e.g. 07/18/98 is 07181998H).

12 4 Extended family, extended model, type, family, model, and stepping of processor that requires this particular update revision (e.g., 00000650H). Each microcode update is designed specifically for a given extended family, extended model, type, family, model, and stepping of the processor.

The BIOS uses the processor signature field in conjunction with the CPUID instruction to determine whether or not an update is appropriate to load on a processor. The information encoded within this field exactly corresponds to the bit representations returned by the CPUID instruction.

Checksum 16 4 Checksum of Update Data and Header. Used to verify the integrity of the update header and data. Checksum is correct when the summation of all the DWORDs (including the extended Processor Signature Table) that comprise the microcode update result in 00000000H.

Loader Revision 20 4 Version number of the loader program needed to correctly load this update. The initial version is 00000001H.

Processor Flags 24 4 Platform type information is encoded in the lower 8 bits of this 4-byte field. Each bit represents a particular platform type for a given CPUID. The BIOS uses the processor flags field in conjunction with the platform Id bits in MSR (17H) to determine whether or not an update is appropriate to load on a processor. Multiple bits may be set representing support for multiple platform IDs.

Data Size 28 4 Specifies the size of the encrypted data in bytes, and must be a multiple of DWORDs. If this value is 00000000H, then the microcode update encrypted data is 2000 bytes (or 500 DWORDs).

Total Size 32 4 Specifies the total size of the microcode update in bytes. It is the summation of the header size, the encrypted data size and the size of the optional extended signature table. This value is always a multiple of 1024.

Length (bytes) · Description · Processor Signature

Page 419 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 419 · click to enlarge
Page 419

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-6. Microcode Update Field Definitions (Contd.)

Field Name Offset (bytes)

Reserved 36 12 Reserved fields for future expansion

Update Data 48 Data Size or 2000 Update data

Data Size + 48 4 Specifies the number of extended signature structures (Processor Signature[n], processor flags[n] and checksum[n]) that exist in this microcode update.

Data Size + 52 4 Checksum of update extended processor signature table. Used to verify the integrity of the extended processor signature table. Checksum is correct when the summation of the DWORDs that comprise the extended processor signature table results in 00000000H.

Reserved Data Size + 56 12 Reserved fields

Data Size + 68 + (n * 12) 4 Extended family, extended model, type, family, model, and stepping of processor that requires this particular update revision (e.g., 00000650H). Each microcode update is designed specifically for a given extended family, extended model, type, family, model, and stepping of the processor.

The BIOS uses the processor signature field in conjunction with the CPUID instruction to determine whether or not an update is appropriate to load on a processor. The information encoded within this field exactly corresponds to the bit representations returned by the CPUID instruction.

Processor Flags[n] Data Size + 72 + (n * 12) 4 Platform type information is encoded in the lower 8 bits of this 4-byte field. Each bit represents a particular platform type for a given CPUID. The BIOS uses the processor flags field in conjunction with the platform Id bits in MSR (17H) to determine whether or not an update is appropriate to load on a processor. Multiple bits may be set representing support for multiple platform IDs.

Checksum[n] Data Size + 76 + (n * 12) 4 Used by utility software to decompose a microcode update into multiple microcode updates where each of the new updates is constructed without the optional Extended Processor Signature Table.

To calculate the Checksum, substitute the Primary Processor Signature entry and the Processor Flags entry with the corresponding Extended Patch entry. Delete the Extended Processor Signature Table entries. The Checksum is correct when the summation of all DWORDs that comprise the created Extended Processor Patch results in 00000000H.

Show 5 more labels / short text on this page
Length (bytes) · Description · Extended Signature Count · Extended Checksum · Processor Signature[n]
Page 420 of the Intel 253668-032US user manual — P7
Page 420 · click to enlarge
Page 420

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-7. Microcode Update Format 31 24 16 8 0 Bytes

Month8 Day: 8 Year: 16 8

Processor Signature (CPUID) 12

Res4
Family8
Extended Mode4
Reserved2
Type2
Family4
Model4
Stepping4

P7

P6

P5

P4

P3

P2

P1

P0

Reserved (12 Bytes) 36

Update Data (Data Size bytes, or 2000 Bytes if Data Size = 00000000H) 48

Extended Signature Count ‘n’ Data Size + 48

Extended Processor Signature Table Checksum Data Size + 52

Data Size + 56

Processor Signature[n] Data Size + 68 + (n * 12)

Processor Flags[n] Data Size + 72 + (n * 12)

Checksum[n] Data Size + 76 + (n * 12)

Show 10 more labels / short text on this page
Header Version 0 · Update Revision 4 · Extended · Checksum 16 · Loader Revision 20 · Processor Flags 24 · Reserved (24 bits) · Data Size 28 · Total Size 32 · Reserved (12 Bytes)
Page 421 of the Intel 253668-032US user manual — 9.11.3 Processor Identification
Page 421 · click to enlarge
Page 421

PROCESSOR MANAGEMENT AND INITIALIZATION

9.11.2 Optional Extended Signature Table

The extended signature table is a structure that may be appended to the end of the encrypted data when the encrypted data only supports a single processor signature (optional case). The extended signature table will always be present when the encrypted data supports multiple processor steppings and/or models (required case).

The extended signature table consists of a 20-byte extended signature header struc ture, which contains the extended signature count, the extended processor signature table checksum, and 12 reserved bytes (Table 9-8). Following the extended signa ture header structure, the extended signature table contains 0-to-n extended processor signature structures.

Each processor signature structure consist of the processor signature, processor flags, and a checksum (Table 9-9).

The extended signature count in the extended signature header structure indicates the number of processor signature structures that exist in the extended signature table.

The extended processor signature table checksum is a checksum of all DWORDs that comprise the extended signature table. That includes the extended signature count, extended processor signature table checksum, 12 reserved bytes and the n processor signature structures. A valid extended signature table exists when the result of a DWORD checksum is 00000000H.

Table 9-8. Extended Processor Signature Table Header Structure

Extended Signature Count ‘n’ Data Size + 48 Extended Processor Signature Table Checksum Data Size + 52 Reserved (12 Bytes) Data Size + 56

Table 9-9. Processor Signature Structure

Processor Signature[n] Data Size + 68 + (n * 12) Processor Flags[n] Data Size + 72 + (n * 12) Checksum[n] Data Size + 76 + (n * 12)

9.11.3 Processor Identification

Each microcode update is designed to for a specific processor or set of processors. To determine the correct microcode update to load, software must ensure that one of the processor signatures embedded in the microcode update matches the 32-bit processor signature returned by the CPUID instruction when executed by the target processor with EAX = 1. Attempting to load a microcode update that does not match

Page 422 of the Intel 253668-032US user manual — 9.11.4 Platform Identification
Page 422 · click to enlarge
Page 422

PROCESSOR MANAGEMENT AND INITIALIZATION

a processor signature embedded in the microcode update with the processor signa ture returned by CPUID will cause the BIOS to reject the update.

Example 9-5 shows how to check for a valid processor signature match between the processor and microcode update.

Example 9-5. Pseudo Code to Validate the Processor Signature

ProcessorSignature ← CPUID(1):EAX

If (Update.HeaderVersion == 00000001h) {

// first check the ProcessorSignature field If (ProcessorSignature == Update.ProcessorSignature)

// if extended signature is present Else If (Update.TotalSize > (Update.DataSize + 48)) {

// // Assume the Data Size has been used to calculate the // location of Update.ProcessorSignature[0]. //

For (N ← 0; ((N < Update.ExtendedSignatureCount) AND (ProcessorSignature != Update.ProcessorSignature[N])); N++);

// if the loops ended when the iteration count is // less than the number of processor signatures in // the table, we have a match If (N < Update.ExtendedSignatureCount)

9.11.4 Platform Identification

In addition to verifying the processor signature, the intended processor platform type must be determined to properly target the microcode update. The intended processor platform type is determined by reading the IA32_PLATFORM_ID register, (MSR 17H). This 64-bit register must be read using the RDMSR instruction.

Show 5 more labels / short text on this page
Success · Success Else · Fail } Else · Fail Else · Fail
Page 423 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 423 · click to enlarge
Page 423

PROCESSOR MANAGEMENT AND INITIALIZATION

The three platform ID bits, when read as a binary coded decimal (BCD) number, indi cate the bit position in the microcode update header’s processor flags field associated with the installed processor. The processor flags in the 48-byte header and the processor flags field associated with the extended processor signature structures may have multiple bits set. Each set bit represents a different platform ID that the update supports.

Register Name: IA32_PLATFORM_ID MSR Address: 017H Access: Read Only IA32_PLATFORM_ID is a 64-bit register accessed only when referenced as a Qword through a RDMSR instruction.

Table 9-10. Processor Flags

Bit Descriptions 63:53 Reserved 52:50 Platform Id Bits (RO). The field gives information concerning the intended platform for the processor. See also Table 9-7.

52 51 50 Processor Flag 0 0 0 1 Processor Flag 1 0 1 0 Processor Flag 2 0 1 1 Processor Flag 3 1 0 0 Processor Flag 4 1 0 1 Processor Flag 5 1 1 0 Processor Flag 6 1 1 1 Processor Flag 7

49:0 Reserved

To validate the platform information, software may implement an algorithm similar to the algorithms in Example 9-6.

Example 9-6. Pseudo Code Example of Processor Flags Test

Flag ← 1

If (Update.HeaderVersion == 00000001h) {

If (Update.ProcessorFlags & Flag) {

Load Update

Page 424 of the Intel 253668-032US user manual — N ← 512
Page 424 · click to enlarge
Page 424

PROCESSOR MANAGEMENT AND INITIALIZATION

// // Assume the Data Size has been used to calculate the // location of Update.ProcessorSignature[N] and a match // on Update.ProcessorSignature[N] has already succeeded //

If (Update.ProcessorFlags[n] & Flag) {

Load Update } } }

9.11.5 Microcode Update Checksum

Each microcode update contains a DWORD checksum located in the update header. It is software’s responsibility to ensure that a microcode update is not corrupt. To check for a corrupt microcode update, software must perform a unsigned DWORD (32-bit) checksum of the microcode update. Even though some fields are signed, the checksum procedure treats all DWORDs as unsigned. Microcode updates with a header version equal to 00000001H must sum all DWORDs that comprise the micro code update. A valid checksum check will yield a value of 00000000H. Any other value indicates the microcode update is corrupt and should not be loaded.

The checksum algorithm shown by the pseudo code in Example 9-7 treats the micro code update as an array of unsigned DWORDs. If the data size DWORD field at byte offset 32 equals 00000000H, the size of the encrypted data is 2000 bytes, resulting in 500 DWORDs. Otherwise the microcode update size in DWORDs = (Total Size / 4), where the total size is a multiple of 1024 bytes (1 KBytes).

Example 9-7. Pseudo Code Example of Checksum Test

N ← 512

If (Update.DataSize != 00000000H)

N ← Update.TotalSize / 4

ChkSum ← 0 For (I ← 0; I < N; I++) {

ChkSum ← ChkSum + MicrocodeUpdate[I] }

} Else {

Page 425 of the Intel 253668-032US user manual — 9.11.6 Microcode Update Loader
Page 425 · click to enlarge
Page 425

PROCESSOR MANAGEMENT AND INITIALIZATION

If (ChkSum == 00000000H)

9.11.6 Microcode Update Loader

This section describes an update loader used to load an update into a Pentium 4, Intel Xeon, or P6 family processor. It also discusses the requirements placed on the BIOS to ensure proper loading. The update loader described contains the minimal instruc tions needed to load an update. The specific instruction sequence that is required to load an update is dependent upon the loader revision field contained within the update header. This revision is expected to change infrequently (potentially, only when new processor models are introduced).

Example 9-8 below represents the update loader with a loader revision of 00000001H. Note that the microcode update must be aligned on a 16-byte boundary and the size of the microcode update must be 1-KByte granular.

Example 9-8. Assembly Code Example of Simple Microcode Update Loader

mov ecx,79h ; MSR to read in ECX xor eax,eax ; clear EAX xor ebx,ebx ; clear EBX mov ax,cs ; Segment of microcode update shl eax,4 mov bx,offset Update ; Offset of microcode update add eax,ebx ; Linear Address of Update in EAX add eax,48d ; Offset of the Update Data within the Update xor edx,edx ; Zero in EDX WRMSR ; microcode update trigger

The loader shown in Example 9-8 assumes that update is the address of a microcode update (header and data) embedded within the code segment of the BIOS. It also assumes that the processor is operating in real mode. The data may reside anywhere in memory, aligned on a 16-byte boundary, that is accessible by the processor within its current operating mode.

  • Before the BIOS executes the microcode update trigger (WRMSR) instruction, the following must be true:
  • In 64-bit mode, EAX contains the lower 32-bits of the microcode update linear address. In protected mode, EAX contains the full 32-bit linear address of the microcode update.
  • In 64-bit mode, EDX contains the upper 32-bits of the microcode update linear address. In protected mode, EDX equals zero.

Success Else · Fail

Page 426 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 426 · click to enlarge
Page 426

PROCESSOR MANAGEMENT AND INITIALIZATION

  • ECX contains 79H (address of IA32_BIOS_UPDT_TRIG).
  • Other requirements are:
  • If the update is loaded while the processor is in real mode, then the update data may not cross a segment boundary.
  • If the update is loaded while the processor is in real mode, then the update data may not exceed a segment limit.
  • If paging is enabled, pages that are currently present must map the update data.
  • The microcode update data requires a 16-byte boundary alignment.

9.11.6.1 Hard Resets in Update Loading

The effects of a loaded update are cleared from the processor upon a hard reset. Therefore, each time a hard reset is asserted during the BIOS POST, the update must be reloaded on all processors that observed the reset. The effects of a loaded update are, however, maintained across a processor INIT. There are no side effects caused by loading an update into a processor multiple times.

9.11.6.2 Update in a Multiprocessor System

A multiprocessor (MP) system requires loading each processor with update data appropriate for its CPUID and platform ID bits. The BIOS is responsible for ensuring that this requirement is met and that the loader is located in a module executed by all processors in the system. If a system design permits multiple steppings of Pentium 4, Intel Xeon, and P6 family processors to exist concurrently; then the BIOS must verify individual processors against the update header information to ensure appropriate loading. Given these considerations, it is most practical to load the update during MP initialization.

9.11.6.3 Update in a System Supporting Intel Hyper-Threading Technology

Intel Hyper-Threading Technology has implications on the loading of the microcode update. The update must be loaded for each core in a physical processor. Thus, for a processor supporting Intel Hyper-Threading Technology, only one logical processor per core is required to load the microcode update. Each individual logical processor can independently load the update. However, MP initialization must provide some mechanism (e.g. a software semaphore) to force serialization of microcode update loads and to prevent simultaneous load attempts to the same core.

9.11.6.4 Update in a System Supporting Dual-Core Technology

Dual-core technology has implications on the loading of the microcode update. The microcode update facility is not shared between processor cores in the same physical package. The update must be loaded for each core in a physical processor.

Page 427 of the Intel 253668-032US user manual — 9.11.7 Update Signature and Verification
Page 427 · click to enlarge
Page 427

PROCESSOR MANAGEMENT AND INITIALIZATION

If processor core supports Intel Hyper-Threading Technology, the guideline described in Section 9.11.6.3 also applies.

9.11.6.5 Update Loader Enhancements

  • The update loader presented in Section 9.11.6, “Microcode Update Loader,” is a minimal implementation that can be enhanced to provide additional functionality. Potential enhancements are described below:
  • BIOS can incorporate multiple updates to support multiple steppings of the Pentium 4, Intel Xeon, and P6 family processors. This feature provides for operating in a mixed stepping environment on an MP system and enables a user to upgrade to a later version of the processor. In this case, modify the loader to check the CPUID and platform ID bits of the processor that it is running on against the available headers before loading a particular update. The number of updates is only limited by available BIOS space.
  • A loader can load the update and test the processor to determine if the update was loaded correctly. See Section 9.11.7, “Update Signature and Verification.”
  • A loader can verify the integrity of the update data by performing a checksum on the double words of the update summing to zero. See Section 9.11.5, “Microcode Update Checksum.”
  • A loader can provide power-on messages indicating successful loading of an update.

9.11.7 Update Signature and Verification

The Pentium 4, Intel Xeon, and P6 family processors provide capabilities to verify the authenticity of a particular update and to identify the current update revision. This section describes the model-specific extensions of processors that support this feature. The update verification method below assumes that the BIOS will only verify an update that is more recent than the revision currently loaded in the processor.

CPUID returns a value in a model specific register in addition to its usual register return values. The semantics of CPUID cause it to deposit an update ID value in the 64-bit model-specific register at address 08BH (IA32_BIOS_SIGN_ID). If no update is present in the processor, the value in the MSR remains unmodified. The BIOS must pre-load a zero into the MSR before executing CPUID. If a read of the MSR at 8BH still returns zero after executing CPUID, this indicates that no update is present.

The update ID value returned in the EDX register after RDMSR executes indicates the revision of the update loaded in the processor. This value, in combination with the CPUID value returned in the EAX register, uniquely identifies a particular update. The signature ID can be directly compared with the update revision field in a microcode update header for verification of a correct load. No consecutive updates released for a given stepping of a processor may share the same signature. The processor signa ture returned by CPUID differentiates updates for different steppings.

Page 428 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 428 · click to enlarge
Page 428

PROCESSOR MANAGEMENT AND INITIALIZATION

9.11.7.1 Determining the Signature

An update that is successfully loaded into the processor provides a signature that matches the update revision of the currently functioning revision. This signature is available any time after the actual update has been loaded. Requesting the signature does not have a negative impact upon a loaded update.

The procedure for determining this signature shown in Example 9-9.

Example 9-9. Assembly Code to Retrieve the Update Revision

MOV ECX, 08BH ;IA32_BIOS_SIGN_ID XOR EAX, EAX ;clear EAX XOR EDX, EDX ;clear EDX WRMSR ;Load 0 to MSR at 8BH MOV EAX, 1 cpuid MOV ECX, 08BH ;IA32_BIOS_SIGN_ID rdmsr ;Read Model Specific Register

If there is an update active in the processor, its revision is returned in the EDX register after the RDMSR instruction executes.

IA32_BIOS_SIGN_ID Microcode Update Signature Register MSR Address: 08BH Accessed as a Qword Default Value: XXXXh Access: Read/Write

The IA32_BIOS_SIGN_ID register is used to report the microcode update signature when CPUID executes. The signature is returned in the upper DWORD (Table 9-11).

Table 9-11. Microcode Update Signature Bit Description

63:32 Microcode update signature. This field contains the signature of the currently loaded microcode update when read following the execution of the CPUID instruction, function 1. It is required that this register field be pre-loaded with zero prior to executing the CPUID, function 1. If the field remains equal to zero, then there is no microcode update loaded. Another non-zero value will be the signature.

31:0 Reserved.

9.11.7.2 Authenticating the Update

An update may be authenticated by the BIOS using the signature primitive, described above, and the algorithm in Example 9-10.

Page 429 of the Intel 253668-032US user manual — 9.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specifications
Page 429 · click to enlarge
Page 429

PROCESSOR MANAGEMENT AND INITIALIZATION

Example 9-10. Pseudo Code to Authenticate the Update

Z ← Obtain Update Revision from the Update Header to be authenticated; X ← Obtain Current Update Signature from MSR 8BH;

If (Z > X) {

Load Update that is to be authenticated; Y ← Obtain New Signature from MSR 8BH;

If (Z == Y)

Example 9-10 requires that the BIOS only authenticate updates that contain a numerically larger revision than the currently loaded revision, where Current Signa ture (X)

This authentication procedure relies upon the decoding provided by the processor to verify an update from a potentially hostile source. As an example, this mechanism in conjunction with other safeguards provides security for dynamically incorporating field updates into the BIOS.

9.11.8 Pentium 4, Intel Xeon, and P6 Family Processor Microcode Update Specifications

This section describes the interface that an application can use to dynamically inte grate processor-specific updates into the system BIOS. In this discussion, the appli cation is referred to as the calling program or caller.

The real mode INT15 call specification described here is an Intel extension to an OEM BIOS. This extension allows an application to read and modify the contents of the microcode update data in NVRAM. The update loader, which is part of the system BIOS, cannot be updated by the interface. All of the functions defined in the specifi cation must be implemented for a system to be considered compliant with the speci fication. The INT15 functions are accessible only from real mode.

9.11.8.1 Responsibilities of the BIOS

If a BIOS passes the presence test (INT 15H, AX = 0D042H, BL = 0H), it must imple ment all of the sub-functions defined in the INT 15H, AX = 0D042H specification.

Success Else · Fail } Else · Fail

Page 430 of the Intel 253668-032US user manual — NOTES
Page 430 · click to enlarge
Page 430

PROCESSOR MANAGEMENT AND INITIALIZATION

There are no optional functions. BIOS must load the appropriate update for each processor during system initialization.

A Header Version of an update block containing the value 0FFFFFFFFH indicates that the update block is unused and available for storing a new update.

The BIOS is responsible for providing a region of non-volatile storage (NVRAM) for each potential processor stepping within a system. This storage unit consists of one or more update blocks. An update block is a contiguous 2048-byte block of memory. The BIOS for a single processor system need only provide update blocks to store one microcode update. If the BIOS for a multiple processor system is intended to support mixed processor steppings, then the BIOS needs to provide enough update blocks to store each unique microcode update or for each processor socket on the OEM’s system board.

The BIOS is responsible for managing the NVRAM update blocks. This includes garbage collection, such as removing microcode updates that exist in NVRAM for which a corresponding processor does not exist in the system. This specification only provides the mechanism for ensuring security, the uniqueness of an entry, and that stale entries are not loaded. The actual update block management is implementation specific on a per-BIOS basis.

As an example, the BIOS may use update blocks sequentially in ascending order with CPU signatures sorted versus the first available block. In addition, garbage collection may be implemented as a setup option to clear all NVRAM slots or as BIOS code that searches and eliminates unused entries during boot.

NOTES

For IA-32 processors starting with family 0FH and model 03H and Intel 64 processors, the microcode update may be as large as 16 KBytes. Thus, BIOS must allocate 8 update blocks for each microcode update. In a MP system, a common microcode update may be sufficient for each socket in the system.

For IA-32 processors earlier than family 0FH and model 03H, the microcode update is 2 KBytes. An MP-capable BIOS that supports multiple steppings must allocate a block for each socket in the system.

A single-processor BIOS that supports variable-sized microcode update and fixed-sized microcode update must allocate one 16-KByte region and a second region of at least 2 KBytes.

  • The following algorithm (Example 9-11) describes the steps performed during BIOS initialization used to load the updates into the processor(s). The algorithm assumes:
  • The BIOS ensures that no update contained within NVRAM has a header version or loader version that does not match one currently supported by the BIOS.
  • The update contains a correct checksum.
  • The BIOS ensures that (at most) one update exists for each processor stepping.
  • Older update revisions are not allowed to overwrite more recent ones.
Page 431 of the Intel 253668-032US user manual — I ← I + 1 } }
Page 431 · click to enlarge
Page 431

PROCESSOR MANAGEMENT AND INITIALIZATION

These requirements are checked by the BIOS during the execution of the write update function of this interface. The BIOS sequentially scans through all of the update blocks in NVRAM starting with index 0. The BIOS scans until it finds an update where the processor fields in the header match the processor signature (extended family, extended model, type, family, model, and stepping) as well as the platform bits of the current processor.

Example 9-11. Pseudo Code, Checks Required Prior to Loading an Update

For each processor in the system {

Determine the Processor Signature via CPUID function 1; Determine the Platform Bits ← 1

For (I ← UpdateBlock 0, I < NumOfBlocks; I++) {

If (Update.Header_Version == 0x00000001) {

If ((Update.ProcessorSignature == Processor Signature) &&

(Update.ProcessorFlags & Platform Bits)) {

Load Update.UpdateData into the Processor; Verify update was correctly loaded into the processor Go on to next processor

Break; } Else If (Update.TotalSize > (Update.DataSize + 48)) {

N ← 0 While (N < Update.ExtendedSignatureCount) {

If ((Update.ProcessorSignature[N] ==

Processor Signature) && (Update.ProcessorFlags[N] & Platform Bits)) {

Load Update.UpdateData into the Processor; Verify update correctly loaded into the processor Go on to next processor

Break; } N ← N + 1 } I ← I + (Update.TotalSize / 2048) If ((Update.TotalSize MOD 2048) == 0)

I ← I + 1 } }

Page 432 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 432 · click to enlarge
Page 432

PROCESSOR MANAGEMENT AND INITIALIZATION

NOTES

The platform Id bits in IA32_PLATFORM_ID are encoded as a three- bit binary coded decimal field. The platform bits in the microcode update header are individually bit encoded. The algorithm must do a translation from one format to the other prior to doing a check.

When performing the INT 15H, 0D042H functions, the BIOS must assume that the caller has no knowledge of platform specific requirements. It is the responsibility of BIOS calls to manage all chipset and platform specific prerequisites for managing the NVRAM device. When writing the update data using the Write Update sub-function, the BIOS must maintain implementation specific data requirements (such as the update of NVRAM checksum). The BIOS should also attempt to verify the success of write operations on the storage device used to record the update.

9.11.8.2 Responsibilities of the Calling Program

  • This section of the document lists the responsibilities of a calling program using the interface specifications to load microcode update(s) into BIOS NVRAM.
  • The calling program should call the INT 15H, 0D042H functions from a pure real mode program and should be executing on a system that is running in pure real mode.
  • The caller should issue the presence test function (sub function 0) and verify the signature and return codes of that function.
  • It is important that the calling program provides the required scratch RAM buffers for the BIOS and the proper stack size as specified in the interface definition.
  • The calling program should read any update data that already exists in the BIOS in order to make decisions about the appropriateness of loading the update. The BIOS must refuse to overwrite a newer update with an older version. The update header contains information about version and processor specifics for the calling program to make an intelligent decision about loading.
  • There can be no ambiguous updates. The BIOS must refuse to allow multiple updates for the same CPU to exist at the same time; it also must refuse to load updates for processors that don’t exist on the system.
  • The calling application should implement a verify function that is run after the update write function successfully completes. This function reads back the update and verifies that the BIOS returned an image identical to the one that was written.

Example 9-12 represents a calling program.

} }

Page 433 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 433 · click to enlarge
Page 433

PROCESSOR MANAGEMENT AND INITIALIZATION

Example 9-12. INT 15 DO42 Calling Program Pseudo-code

// // We must be in real mode // If the system is not in Real mode exit // // Detect presence of Genuine Intel processor(s) that can be updated // using(CPUID) // If no Intel processors exist that can be updated exit // // Detect the presence of the Intel microcode update extensions // If the BIOS fails the PresenceTestexit // // If the APIC is enabled, see if any other processors are out there // Read IA32_APICBASE If APIC enabled {

Send Broadcast Message to all processors except self via APIC Have all processors execute CPUID, record the Processor Signature (i.e.,Extended Family, Extended Model, Type, Family, Model, Stepping)

Have all processors read IA32_PLATFORM_ID[52:50], record Platform Id Bits

If current processor cannot be updated

exit } // // Determine the number of unique update blocks needed for this system // NumBlocks = 0 For each processor {

If ((this is a unique processor stepping) AND

(we have a unique update in the database for this processor)) {

Checksum the update from the database; If Checksum fails

exit NumBlocks ← NumBlocks + size of microcode update / 2048 } }

//

Page 434 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 434 · click to enlarge
Page 434

PROCESSOR MANAGEMENT AND INITIALIZATION

// Do we have enough update slots for all CPUs? // If there are more blocks required to support the unique processor steppings than update blocks provided by the BIOS exit // // Do we need any update blocks at all? If not, we are done // If (NumBlocks == 0)

exit // // Record updates for processors in NVRAM. // For (I=0; I

// // Load each Update // Issue the WriteUpdate function

If (STORAGE_FULL) returned {

Display Error -- BIOS is not managing NVRAM appropriately exit }

If (INVALID_REVISION) returned {

Display MessageMore recent update already loaded in NVRAM for this stepping continue }

If any other error returned {

Display Diagnostic exit }

// // Verify the update was loaded correctly // Issue the ReadUpdate function

If an error occurred {

Display Diagnostic exit

Page 435 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 435 · click to enlarge
Page 435

PROCESSOR MANAGEMENT AND INITIALIZATION

} // // Compare the Update read to that written // If (Update read != Update written) {

Display Diagnostic exit }

I ← I + (size of microcode update / 2048) } // // Enable Update Loading, and inform user // Issue the Update Control function with Task = Enable.

9.11.8.3 Microcode Update Functions

Table 9-12 defines current Pentium 4, Intel Xeon, and P6 family processor microcode update functions.

Table 9-12. Microcode Update Functions Microcode Update Function

Presence test 00H Returns information about the supported functions.

Write update data 01H Writes one of the update data areas (slots).

Update control 02H Globally controls the loading of updates. Required

Read update data 03H Reads one of the update data areas (slots).

9.11.8.4 INT 15H-based Interface

Intel recommends that a BIOS interface be provided that allows additional microcode updates to be added to system flash. The INT15H interface is the Intel-defined method for doing this.

The program that calls this interface is responsible for providing three 64-kilobyte RAM areas for BIOS use during calls to the read and write functions. These RAM scratch pads can be used by the BIOS for any purpose, but only for the duration of the function call. The calling routine places real mode segments pointing to the RAM blocks in the CX, DX and SI registers. Calls to functions in this interface must be made with a minimum of 32 kilobytes of stack available to the BIOS.

Show 5 more labels / short text on this page
Function Number · Description Required/Optional · Required · Required · Required
Page 436 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 436 · click to enlarge
Page 436

PROCESSOR MANAGEMENT AND INITIALIZATION

In general, each function returns with CF cleared and AH contains the returned status. The general return codes and other constant definitions are listed in Section 9.11.8.9, “Return Codes.”

The OEM error field (AL) is provided for the OEM to return additional error informa tion specific to the platform. If the BIOS provides no additional information about the error, OEM error must be set to SUCCESS. The OEM error field is undefined if AH contains either SUCCESS (00H) or NOT_IMPLEMENTED (86H). In all other cases, it must be set with either SUCCESS or a value meaningful to the OEM.

The following sections describe functions provided by the INT15H-based interface.

9.11.8.5 Function 00H—Presence Test

This function verifies that the BIOS has implemented required microcode update functions. Table 9-13 lists the parameters and return codes for the function.

Table 9-13. Parameters for the Presence Test

AX Function Code 0D042H

BL Sub-function 00H - Presence test

CF Carry Flag Carry Set - Failure - AH contains status

Carry Clear - All return values valid

AL OEM Error Additional OEM information.

EBX Signature Part 1 'INTE' - Part one of the signature

ECX Signature Part 2 'LPEP'- Part two of the signature

EDX Loader Version Version number of the microcode update loader

SI Update Count Number of 2048 update blocks in NVRAM the BIOS allocated to storing microcode updates

Return Codes (see Table 9-18 for code definitions

SUCCESS The function completed successfully.

NOT_IMPLEMENTED The function is not implemented.

In order to assure that the BIOS function is present, the caller must verify the carry flag, the return code, and the 64-bit signature. The update count reflects the number of 2048-byte blocks available for storage within one non-volatile RAM.

The loader version number refers to the revision of the update loader program that is included in the system BIOS image.

Input · Output · AH Return Code

Page 437 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 437 · click to enlarge
Page 437

PROCESSOR MANAGEMENT AND INITIALIZATION

9.11.8.6 Function 01H—Write Microcode Update Data

This function integrates a new microcode update into the BIOS storage device. Table 9-14 lists the parameters and return codes for the function.

Table 9-14. Parameters for the Write Update Data Function

AX Function Code 0D042H

BL Sub-function 01H - Write update

ES:DI Update Address Real Mode pointer to the Intel Update structure. This buffer is 2048 bytes in length if the processor supports only fixed-size microcode update or... Real Mode pointer to the Intel Update structure. This buffer is 64 KBytes in length if the processor supports a variable-size microcode update.

CX Scratch Pad1 Real mode segment address of 64 KBytes of RAM block

DX Scratch Pad2 Real mode segment address of 64 KBytes of RAM block

SI Scratch Pad3 Real mode segment address of 64 KBytes of RAM block

SS:SP Stack pointer 32 KBytes of stack minimum

CF Carry Flag Carry Set - Failure - AH Contains status

Carry Clear - All return values valid

AH Return Code Status of the call

AL OEM Error Additional OEM information

Return Codes (see Table 9-18 for code definitions

SUCCESS The function completed successfully.

NOT_IMPLEMENTED The function is not implemented.

WRITE_FAILURE A failure occurred because of the inability to write the storage device.

ERASE_FAILURE A failure occurred because of the inability to erase the storage device.

READ_FAILURE A failure occurred because of the inability to read the storage device.

STORAGE_FULL The BIOS non-volatile storage area is unable to accommodate the update because all available update blocks are filled with updates that are needed for processors in the system.

Input · Output

Page 438 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 438 · click to enlarge
Page 438

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-14. Parameters for the Write Update Data Function (Contd.)

CPU_NOT_PRESENT The processor stepping does not currently exist in the system.

INVALID_HEADER The update header contains a header or loader version that is not recognized by the BIOS.

INVALID_HEADER_CS The update does not checksum correctly.

SECURITY_FAILURE The processor rejected the update.

INVALID_REVISION The same or more recent revision of the update exists in the storage device.

The BIOS is responsible for selecting an appropriate update block in the non-volatile storage for storing the new update. This BIOS is also responsible for ensuring the integrity of the information provided by the caller, including authenticating the proposed update before incorporating it into storage.

Before writing the update block into NVRAM, the BIOS should ensure that the update structure meets the following criteria in the following order:

1. The update header version should be equal to an update header version recognized by the BIOS.
2. The update loader version in the update header should be equal to the update loader version contained within the BIOS image.
3. The update block must checksum. This checksum is computed as a 32-bit summation of all double words in the structure, including the header, data, and processor signature table.
  • The BIOS selects update block(s) in non-volatile storage for storing the candidate update. The BIOS can select any available update block as long as it guarantees that only a single update exists for any given processor stepping in non-volatile storage. If the update block selected already contains an update, the following additional criteria apply to overwrite it:
  • The processor signature in the proposed update must be equal to the processor signature in the header of the current update in NVRAM (Processor Signature + platform ID bits).
  • The update revision in the proposed update should be greater than the update revision in the header of the current update in NVRAM.

If no unused update blocks are available and the above criteria are not met, the BIOS can overwrite update block(s) for a processor stepping that is no longer present in the system. This can be done by scanning the update blocks and comparing the processor steppings, identified in the MP Specification table, to the processor step pings that currently exist in the system.

Input · Description

Page 439 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 439 · click to enlarge
Page 439

PROCESSOR MANAGEMENT AND INITIALIZATION

Finally, before storing the proposed update in NVRAM, the BIOS must verify the authenticity of the update via the mechanism described in Section 9.11.6, “Micro code Update Loader.” This includes loading the update into the current processor, executing the CPUID instruction, reading MSR 08Bh, and comparing a calculated value with the update revision in the proposed update header for equality.

When performing the write update function, the BIOS must record the entire update, including the header, the update data, and the extended processor signature table (if applicable). When writing an update, the original contents may be overwritten, assuming the above criteria have been met. It is the responsibility of the BIOS to ensure that more recent updates are not overwritten through the use of this BIOS call, and that only a single update exists within the NVRAM for any processor step ping and platform ID.

Figure 9-8 and Figure 9-9 show the process the BIOS follows to choose an update block and ensure the integrity of the data when it stores the new microcode update.

Page 440 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 440 · click to enlarge
Page 440

PROCESSOR MANAGEMENT AND INITIALIZATION

Does Update Match A

CPU in The System

Valid Update Header Version?

Does Update Checksum Correctly?

Figure 9-8. Microcode Update Write Operation Flow [1]

Show 14 more labels / short text on this page
Write Microcode Update · Return CPU_NOT_PRESENT · No · Yes · Return INVALID_HEADER · No · Yes · Loader Revision Match · No · Return INVALID_HEADER · BIOS’s Loader? · Yes · Return INVALID_HEADER_CS · No
Page 441 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 441 · click to enlarge
Page 441

PROCESSOR MANAGEMENT AND INITIALIZATION

NVRAM?

Update Pass Authenticity Test?

Figure 9-9. Microcode Update Write Operation Flow [2]

Show 19 more labels / short text on this page
Update Matching CPU · Replacement · No · Space Available in · No · policy implemented? · Already In NVRAM? · Yes · No Yes Yes · Update Revision Newer · No · Return INVALID_REVISION · Return STORAGE_FULL · Than NVRAM Update? · Yes · Return SECURITY_FAILURE · Yes · Update NMRAM Record · Return SUCCESS
Page 442 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 442 · click to enlarge
Page 442

PROCESSOR MANAGEMENT AND INITIALIZATION

9.11.8.7 Function 02H—Microcode Update Control

This function enables loading of binary updates into the processor. Table 9-15 lists the parameters and return codes for the function.

Table 9-15. Parameters for the Control Update Sub-function

AX Function Code 0D042H

BL Sub-function 02H - Control update

BH Task See the description below.

CX Scratch Pad1 Real mode segment of 64 KBytes of RAM block

DX Scratch Pad2 Real mode segment of 64 KBytes of RAM block

SI Scratch Pad3 Real mode segment of 64 KBytes of RAM block

SS:SP Stack pointer 32 kilobytes of stack minimum

CF Carry Flag Carry Set - Failure - AH contains status

Carry Clear - All return values valid.

AH Return Code Status of the call

AL OEM Error Additional OEM Information.

BL Update Status Either enable or disable indicator

Return Codes (see Table 9-18 for code definitions)

SUCCESS Function completed successfully.

READ_FAILURE A failure occurred because of the inability to read the storage device.

This control is provided on a global basis for all updates and processors. The caller can determine the current status of update loading (enabled or disabled) without changing the state. The function does not allow the caller to disable loading of binary updates, as this poses a security risk.

The caller specifies the requested operation by placing one of the values from Table 9-16 in the BH register. After successfully completing this function, the BL register contains either the enable or the disable designator. Note that if the function fails, the update status return value is undefined.

Input · Output

Page 443 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 443 · click to enlarge
Page 443

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-16. Mnemonic Values Mnemonic Value Meaning

Enable 1 Enable the Update loading at initialization time.

Query 2 Determine the current state of the update control without changing its status.

The READ_FAILURE error code returned by this function has meaning only if the control function is implemented in the BIOS NVRAM. The state of this feature (enabled/disabled) can also be implemented using CMOS RAM bits where READ failure errors cannot occur.

9.11.8.8 Function 03H—Read Microcode Update Data

This function reads a currently installed microcode update from the BIOS storage into a caller-provided RAM buffer. Table 9-17 lists the parameters and return codes.

Table 9-17. Parameters for the Read Microcode Update Data Function Input

AX Function Code 0D042H

BL Sub-function 03H - Read Update

ES:DI Buffer Address Real Mode pointer to the Intel Update structure that will be written with the binary data

ECX Scratch Pad1 Real Mode Segment address of 64 KBytes of RAM Block (lower 16 bits)

ECX Scratch Pad2 Real Mode Segment address of 64 KBytes of RAM Block (upper 16 bits)

DX Scratch Pad3 Real Mode Segment address of 64 KBytes of RAM Block

SS:SP Stack pointer 32 KBytes of Stack Minimum

SI Update Number This is the index number of the update block to be read. This value is zero based and must be less than the update count returned from the presence test function.

CF Carry Flag Carry Set - Failure - AH contains Status

Carry Clear - All return values are valid.

AH Return Code Status of the Call

Output

Page 444 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 444 · click to enlarge
Page 444

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-17. Parameters for the Read Microcode Update Data Function (Contd.)

AL OEM Error Additional OEM Information

Return Codes (see Table 9-18 for code definitions)

SUCCESS The function completed successfully.

READ_FAILURE There was a failure because of the inability to read the storage device.

UPDATE_NUM_INVALID Update number exceeds the maximum number of update blocks implemented by the BIOS.

NOT_EMPTY The specified update block is a subsequent block in use to store a valid microcode update that spans multiple blocks.

The specified block is not a header block and is not empty.

The read function enables the caller to read any microcode update data that already exists in a BIOS and make decisions about the addition of new updates. As a result of a successful call, the BIOS copies the microcode update into the location pointed to by ES:DI, with the contents of all Update block(s) that are used to store the spec ified microcode update.

If the specified block is not a header block, but does contain valid data from a micro code update that spans multiple update blocks, then the BIOS must return Failure with the NOT_EMPTY error code in AH.

An update block is considered unused and available for storing a new update if its Header Version contains the value 0FFFFFFFFH after return from this function call. The actual implementation of NVRAM storage management is not specified here and is BIOS dependent. As an example, the actual data value used to represent an empty block by the BIOS may be zero, rather than 0FFFFFFFFH. The BIOS is respon sible for translating this information into the header provided by this function.

9.11.8.9 Return Codes

After the call has been made, the return codes listed in Table 9-18 are available in the AH register.

Page 445 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 445 · click to enlarge
Page 445

PROCESSOR MANAGEMENT AND INITIALIZATION

Table 9-18. Return Code Definitions

Return Code Value Description

SUCCESS 00H The function completed successfully.

NOT_IMPLEMENTED 86H The function is not implemented.

ERASE_FAILURE 90H A failure because of the inability to erase the storage device.

WRITE_FAILURE 91H A failure because of the inability to write the storage device.

READ_FAILURE 92H A failure because of the inability to read the storage device.

STORAGE_FULL 93H The BIOS non-volatile storage area is unable to accommodate the update because all available update blocks are filled with updates that are needed for processors in the system.

CPU_NOT_PRESENT 94H The processor stepping does not currently exist in the system.

INVALID_HEADER 95H The update header contains a header or loader version that is not recognized by the BIOS.

INVALID_HEADER_CS 96H The update does not checksum correctly.

SECURITY_FAILURE 97H The update was rejected by the processor.

INVALID_REVISION 98H The same or more recent revision of the update exists in the storage device.

UPDATE_NUM_INVALID 99H The update number exceeds the maximum number of update blocks implemented by the BIOS.

NOT_EMPTY 9AH The specified update block is a subsequent block in use to store a valid microcode update that spans multiple blocks.

The specified block is not a header block and is not empty.

Page 446 of the Intel 253668-032US user manual — PROCESSOR MANAGEMENT AND INITIALIZATION
Page 446 · click to enlarge
Page 446

PROCESSOR MANAGEMENT AND INITIALIZATION

Page 447 of the Intel 253668-032US user manual — 10.1 LOCAL AND I/O APIC OVERVIEW
Page 447 · click to enlarge
Page 447

CHAPTER 10 ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • The Advanced Programmable Interrupt Controller (APIC), referred to in the following sections as the local APIC, was introduced into the IA-32 processors with the Pentium processor (see Section 19.27, “Advanced Programmable Interrupt Controller (APIC)”) and is included in the P6 family, Pentium 4, Intel Xeon processors, and other more recent Intel 64 and IA-32 processor families (see Section 10.4.2, “Presence of the Local APIC”). The local APIC performs two primary functions for the processor:
  • It receives interrupts from the processor’s interrupt pins, from internal sources and from an external I/O APIC (or other external interrupt controller). It sends these to the processor core for handling.
  • In multiple processor (MP) systems, it sends and receives interprocessor interrupt (IPI) messages to and from other logical processors on the system bus. IPI messages can be used to distribute interrupts among the processors in the system or to execute system wide functions (such as, booting up processors or distributing work among a group of processors).

The external I/O APIC is part of Intel’s system chip set. Its primary function is to receive external interrupt events from the system and its associated I/O devices and relay them to the local APIC as interrupt messages. In MP systems, the I/O APIC also provides a mechanism for distributing external interrupts to the local APICs of selected processors or groups of processors on the system bus.

This chapter provides a description of the local APIC and its programming interface. It also provides an overview of the interface between the local APIC and the I/O APIC. Contact Intel for detailed information about the I/O APIC.

When a local APIC has sent an interrupt to its processor core for handling, the processor uses the interrupt and exception handling mechanism described in Chapter 6, “Interrupt and Exception Handling.” See Section 6.1, “Interrupt and Exception Overview,” for an introduction to interrupt and exception handling.

10.1 LOCAL AND I/O APIC OVERVIEW

Each local APIC consists of a set of APIC registers (see Table 10-1) and associated hardware that control the delivery of interrupts to the processor core and the gener ation of IPI messages. The APIC registers are memory mapped and can be read and written to using the MOV instruction.

Local APICs can receive interrupts from the following sources: • Locally connected I/O devices — These interrupts originate as an edge or level asserted by an I/O device that is connected directly to the processor’s local

Page 448 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 448 · click to enlarge
Page 448

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • interrupt pins (LINT0 and LINT1). The I/O devices may also be connected to an 8259-type interrupt controller that is in turn connected to the processor through one of the local interrupt pins.
  • Externally connected I/O devices — These interrupts originate as an edge or level asserted by an I/O device that is connected to the interrupt input pins of an I/O APIC. Interrupts are sent as I/O interrupt messages from the I/O APIC to one or more of the processors in the system.
  • Inter-processor interrupts (IPIs) — An Intel 64 or IA-32 processor can use the IPI mechanism to interrupt another processor or group of processors on the system bus. IPIs are used for software self-interrupts, interrupt forwarding, or preemptive scheduling.
  • APIC timer generated interrupts — The local APIC timer can be programmed to send a local interrupt to its associated processor when a programmed count is reached (see Section 10.6.4, “APIC Timer”).
  • Performance monitoring counter interrupts — P6 family, Pentium 4, and Intel Xeon processors provide the ability to send an interrupt to its associated processor when a performance-monitoring counter overflows (see Section 30.8.5.8, “Generating an Interrupt on Overflow”).
  • Thermal Sensor interrupts — Pentium 4 and Intel Xeon processors provide the ability to send an interrupt to themselves when the internal thermal sensor has been tripped (see Section 14.5.2, “Thermal Monitor”).
  • APIC internal error interrupts — When an error condition is recognized within the local APIC (such as an attempt to access an unimplemented register), the APIC can be programmed to send an interrupt to its associated processor (see Section 10.6.3, “Error Handling”).

Of these interrupt sources: the processor’s LINT0 and LINT1 pins, the APIC timer, the performance-monitoring counters, the thermal sensor, and the internal APIC error detector are referred to as local interrupt sources. Upon receiving a signal from a local interrupt source, the local APIC delivers the interrupt to the processor core using an interrupt delivery protocol that has been set up through a group of APIC registers called the local vector table or LVT (see Section 10.6.1, “Local Vector Table”). A separate entry is provided in the local vector table for each local interrupt source, which allows a specific interrupt delivery protocol to be set up for each source. For example, if the LINT1 pin is going to be used as an NMI pin, the LINT1 entry in the local vector table can be set up to deliver an interrupt with vector number 2 (NMI interrupt) to the processor core.

The local APIC handles interrupts from the other two interrupt sources (externally connected I/O devices and IPIs) through its IPI message handling facilities.

A processor can generate IPIs by programming the interrupt command register (ICR) in its local APIC (see Section 10.7.1, “Interrupt Command Register (ICR)”). The act of writing to the ICR causes an IPI message to be generated and issued on the system bus (for Pentium 4 and Intel Xeon processors) or on the APIC bus (for Pentium and P6 family processors). See Section 10.2, “System Bus Vs. APIC Bus.”

Page 449 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 449 · click to enlarge
Page 449

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

IPIs can be sent to other processors in the system or to the originating processor (self-interrupts). When the target processor receives an IPI message, its local APIC handles the message automatically (using information included in the message such as vector number and trigger mode). See Section 10.7, “Issuing Interprocessor Interrupts,” for a detailed explanation of the local APIC’s IPI message delivery and acceptance mechanism.

The local APIC can also receive interrupts from externally connected devices through the I/O APIC (see Figure 10-1). The I/O APIC is responsible for receiving interrupts generated by system hardware and I/O devices and forwarding them to the local APIC as interrupt messages.

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 449)
Fig. 22

Figure 10-1. Relationship of Local APIC and I/O APIC In Single-Processor Systems

Individual pins on the I/O APIC can be programmed to generate a specific interrupt vector when asserted. The I/O APIC also has a “virtual wire mode” that allows it to communicate with a standard 8259A-style external interrupt controller. Note that the local APIC can be disabled (see Section 10.4.3, “Enabling or Disabling the Local APIC”). This allows an associated processor core to receive interrupts directly from an 8259A interrupt controller.

Both the local APIC and the I/O APIC are designed to operate in MP systems (see Figures 10-2 and 10-3). Each local APIC handles interrupts from the I/O APIC, IPIs from processors on the system bus, and self-generated interrupts. Interrupts can

Page 450 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 450 · click to enlarge
Page 450

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

also be delivered to the individual processors through the local interrupt pins; however, this mechanism is commonly not used in MP systems.

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 450)
Fig. 23

Figure 10-2. Local APICs and I/O APIC When Intel Xeon Processors Are Used in

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 450)
Fig. 24

Figure 10-3. Local APICs and I/O APIC When P6 Family Processors Are Used in

Multiple-Processor Systems · Multiple-Processor Systems

Page 451 of the Intel 253668-032US user manual — 10.2 SYSTEM BUS VS. APIC BUS
Page 451 · click to enlarge
Page 451

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

The IPI mechanism is typically used in MP systems to send fixed interrupts (inter rupts for a specific vector number) and special-purpose interrupts to processors on the system bus. For example, a local APIC can use an IPI to forward a fixed interrupt to another processor for servicing. Special-purpose IPIs (including NMI, INIT, SMI and SIPI IPIs) allow one or more processors on the system bus to perform system- wide boot-up and control functions.

The following sections focus on the local APIC and its implementation in the Pentium 4, Intel Xeon, and P6 family processors. In these sections, the terms “local APIC” and “I/O APIC” refer to local and I/O APICs used with the P6 family processors and to local and I/O xAPICs used with the Pentium 4 and Intel Xeon processors (see Section 10.3, “the Intel® 82489DX External APIC, The APIC, the xAPIC, AND THE X2APIC”).

10.2 SYSTEM BUS VS. APIC BUS

For the P6 family and Pentium processors, the I/O APIC and local APICs communicate through the 3-wire inter-APIC bus (see Figure 10-3). Local APICs also use the APIC bus to send and receive IPIs. The APIC bus and its messages are invisible to software and are not classed as architectural.

Beginning with the Pentium 4 and Intel Xeon processors, the I/O APIC and local APICs (using the xAPIC architecture) communicate through the system bus (see Figure 10-2). The I/O APIC sends interrupt requests to the processors on the system bus through bridge hardware that is part of the Intel chip set. The bridge hardware generates the interrupt messages that go to the local APICs. IPIs between local APICs are transmitted directly on the system bus.

10.3 THE INTEL® 82489DX EXTERNAL APIC, THE APIC, THE XAPIC, AND THE X2APIC

The local APIC in the P6 family and Pentium processors is an architectural subset of the Intel® 82489DX external APIC. See Section 19.27.1, “Software Visible Differ ences Between the Local APIC and the 82489DX.”

The APIC architecture used in the Pentium 4 and Intel Xeon processors (called the xAPIC architecture) is an extension of the APIC architecture found in the P6 family processors. The primary difference between the APIC and xAPIC architectures is that with the xAPIC architecture, the local APICs and the I/O APIC communicate through the system bus. With the APIC architecture, they communication through the APIC bus (see Section 10.2, “System Bus Vs. APIC Bus”). Also, some APIC architectural features have been extended and/or modified in the xAPIC architecture.

The x2APIC architecture is extended from the xAPIC architecture. Extensions to the xAPIC architecture are intended primarily to increase processor addressability. The x2APIC architecture provides backward compatibility to the xAPIC architecture and

Page 452 of the Intel 253668-032US user manual — NOTE
Page 452 · click to enlarge
Page 452

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

forward extendability for future Intel platform innovations. These extensions and modifications are noted in the following sections.

10.4 LOCAL APIC

The following sections describe the architecture of the local APIC and how to detect it, identify it, and determine its status. Descriptions of how to program the local APIC are given in Section 10.6.1, “Local Vector Table,” and Section 10.7.1, “Interrupt Command Register (ICR).”

10.4.1 The Local APIC Block Diagram

Figure 10-4 gives a functional block diagram for the local APIC. Software interacts with the local APIC by reading and writing its registers. APIC registers are memory- mapped to a 4-KByte region of the processor’s physical address space with an initial starting address of FEE00000H. For correct APIC operation, this address space must be mapped to an area of memory that has been designated as strong uncacheable (UC). See Section 11.3, “Methods of Caching Available.”

In MP system configurations, the APIC registers for Intel 64 or IA-32 processors on the system bus are initially mapped to the same 4-KByte region of the physical address space. Software has the option of changing initial mapping to a different 4-KByte region for all the local APICs or of mapping the APIC registers for each local APIC to its own 4-KByte region. Section 10.4.5, “Relocating the Local APIC Regis ters,” describes how to relocate the base address for APIC registers.

On processors supporting x2APIC architecture (indicated by CPUID.01H:ECX[21] =1), the local APIC supports operation in the xAPIC mode (as described in Section 10.4. Additionally, software can enable the local APIC to operate in x2APIC mode for extended processor addressability (see Section 10.5).

NOTE

For P6 family, Pentium 4, and Intel Xeon processors, the APIC handles all memory accesses to addresses within the 4-KByte APIC register space internally and no external bus cycles are produced. For the Pentium processors with an on-chip APIC, bus cycles are produced for accesses to the APIC register space. Thus, for software intended to run on Pentium processors, system software should explicitly not map the APIC register space to regular system memory. Doing so can result in an invalid opcode exception (#UD) being generated or unpredictable execution.

Page 453 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 453 · click to enlarge
Page 453

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 453)
Fig. 25
2. Introduced in the Pentium 4 and Intel Xeon processors.
3. Three-wire APIC bus in P6 family and Pentium processors.
4. Not implemented in Pentium 4 and Intel Xeon processors.

Figure 10-4. Local APIC Structure

Page 454 of the Intel 253668-032US user manual — NOTE
Page 454 · click to enlarge
Page 454

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-1 shows how the APIC registers are mapped into the 4-KByte APIC register space. Registers are 32 bits, 64 bits, or 256 bits in width; all are aligned on 128-bit boundaries. All 32-bit registers should be accessed using 128-bit aligned 32-bit loads or stores. Some processors may support loads and stores of less than 32 bits to some of the APIC registers. This is model specific behavior and is not guaranteed to work on all processors. Any FP/MMX/SSE access to an APIC register, or any access that touches bytes 4 through 15 of an APIC register may cause undefined behavior and must not be executed. This undefined behavior could include hangs, incorrect results or unexpected exceptions, including machine checks, and may vary between imple mentations. Wider registers (64-bit or 256-bit) must be accessed using multiple 32- bit loads or stores, with all accesses being 128-bit aligned.

The local APIC registers listed in Table 10-1 are not MSRs. The only MSR associated with the programming of the local APIC is the IA32_APIC_BASE MSR (see Section 10.4.3, “Enabling or Disabling the Local APIC”).

NOTE

In processors based on Intel Microarchitecture (Nehalem) the Local APIC ID Register is no longer Read/Write; it is Read Only.

Table 10-1 Local APIC Register Address Map

Address Register Name Software Read/Write

FEE0 0020H Local APIC ID Register Read/Write.

FEE0 0030H Local APIC Version Register Read Only.

FEE0 0080H Task Priority Register (TPR) Read/Write.

FEE0 0090H Arbitration Priority Register1 (APR) Read Only.

FEE0 00A0H Processor Priority Register (PPR) Read Only.

FEE0 00B0H EOI Register Write Only.

FEE0 00C0H Remote Read Register1 (RRD) Read Only

FEE0 00D0H Logical Destination Register Read/Write.

FEE0 00E0H Destination Format Register Bits 0-27 Read only; bits 28-31 Read/Write.

Show 6 more labels / short text on this page
FEE0 0000H Reserved · FEE0 0010H Reserved · FEE0 0040H Reserved · FEE0 0050H Reserved · FEE0 0060H Reserved · FEE0 0070H Reserved
Page 455 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 455 · click to enlarge
Page 455

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-1 Local APIC Register Address Map (Contd.)

Address Register Name Software Read/Write

FEE0 00F0H Spurious Interrupt Vector Register Bits 0-8 Read/Write; bits 9-31 Read Only.

FEE0 0100H In-Service Register (ISR); bits 0:31 Read Only.

FEE0 0110H In-Service Register (ISR); bits 32:63 Read Only.

FEE0 0120H In-Service Register (ISR); bits 64:95 Read Only.

FEE0 0130H In-Service Register (ISR); bits 96:127 Read Only.

FEE0 0140H In-Service Register (ISR); bits 128:159 Read Only.

FEE0 0150H In-Service Register (ISR); bits 160:191 Read Only.

FEE0 0160H In-Service Register (ISR); bits 192:223 Read Only.

FEE0 0170H In-Service Register (ISR); bits 224:255 Read Only.

FEE0 0180H Trigger Mode Register (TMR); bits 0:31 Read Only.

FEE0 0190H Trigger Mode Register (TMR); bits 32:63 Read Only.

FEE0 01A0H Trigger Mode Register (TMR); bits 64:95 Read Only.

FEE0 01B0H Trigger Mode Register (TMR); bits 96:127 Read Only.

FEE0 01C0H Trigger Mode Register (TMR); bits 128:159 Read Only.

FEE0 01D0H Trigger Mode Register (TMR); bits 160:191 Read Only.

FEE0 01E0H Trigger Mode Register (TMR); bits 192:223 Read Only.

FEE0 01F0H Trigger Mode Register (TMR); bits 224:255 Read Only.

FEE0 0200H Interrupt Request Register (IRR); bits 0:31 Read Only.

FEE0 0210H Interrupt Request Register (IRR); bits32:63 Read Only.

FEE0 0220H Interrupt Request Register (IRR); bits 64:95 Read Only.

FEE0 0230H Interrupt Request Register (IRR); bits 96:127 Read Only.

FEE0 0240H Interrupt Request Register (IRR); bits 128:159 Read Only.

FEE0 0250H Interrupt Request Register (IRR); bits 160:191 Read Only.

FEE0 0260H Interrupt Request Register (IRR); bits 192:223 Read Only.

FEE0 0270H Interrupt Request Register (IRR); bits 224:255 Read Only.

FEE0 0280H Error Status Register Read Only.

FEE0 0290H through FEE0 02E0H

FEE0 02F0H LVT CMCI Registers Read/Write.

FEE0 0300H Interrupt Command Register (ICR); bits 0-31 Read/Write.

Reserved

Page 456 of the Intel 253668-032US user manual — 10.4.3 Enabling or Disabling the Local APIC
Page 456 · click to enlarge
Page 456

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-1 Local APIC Register Address Map (Contd.)

Address Register Name Software Read/Write

FEE0 0310H Interrupt Command Register (ICR); bits 32-63 Read/Write.

FEE0 0320H LVT Timer Register Read/Write.

FEE0 0330H LVT Thermal Sensor Register2 Read/Write.

FEE0 0340H LVT Performance Monitoring Counters Register3

Read/Write.

FEE0 0350H LVT LINT0 Register Read/Write.

FEE0 0360H LVT LINT1 Register Read/Write.

FEE0 0370H LVT Error Register Read/Write.

FEE0 0380H Initial Count Register (for Timer) Read/Write.

FEE0 0390H Current Count Register (for Timer) Read Only.

FEE0 03A0H through FEE0 03D0H

FEE0 03E0H Divide Configuration Register (for Timer) Read/Write.

NOTES: 1. Not supported in the Pentium 4 and Intel Xeon processors. The Illegal Register Access bit (7) of the ESR will not be set when writing to these registers. 2. Introduced in the Pentium 4 and Intel Xeon processors. This APIC register and its associated function are implementation dependent and may not be present in future IA-32 or Intel 64 pro cessors. 3. Introduced in the Pentium Pro processor. This APIC register and its associated function are implementation dependent and may not be present in future IA-32 or Intel 64 processors.

10.4.2 Presence of the Local APIC

Beginning with the P6 family processors, the presence or absence of an on-chip local APIC can be detected using the CPUID instruction. When the CPUID instruction is executed with a source operand of 1 in the EAX register, bit 9 of the CPUID feature flags returned in the EDX register indicates the presence (set) or absence (clear) of a local APIC.

10.4.3 Enabling or Disabling the Local APIC

The local APIC can be enabled or disabled in either of two ways:

Reserved · FEE0 03F0H Reserved

Page 457 of the Intel 253668-032US user manual — 10.4.4 Local APIC Status and Location
Page 457 · click to enlarge
Page 457

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

1. Using the APIC global enable/disable flag in the IA32_APIC_BASE MSR (MSR address 1BH; see Figure 10-5 ):

— When IA32_APIC_BASE[11] is 0, the processor is functionally equivalent to an IA-32 processor without an on-chip APIC. The CPUID feature flag for the APIC (see Section 10.4.2, “Presence of the Local APIC”) is also set to 0.

— When IA32_APIC_BASE[11] is set to 0, processor APICs based on the 3-wire APIC bus cannot be generally re-enabled until a system hardware reset. The 3-wire bus loses track of arbitration that would be necessary for complete re- enabling. Certain APIC functionality can be enabled (for example: performance and thermal monitoring interrupt generation).

— For processors that use Front Side Bus (FSB) delivery of interrupts, software may disable or enable the APIC by setting and resetting IA32_APIC_BASE[11]. A hardware reset is not required to re-start APIC functionality, if software guarantees no interrupt will be sent to the APIC as IA32_APIC_BASE[11] is cleared.

— When IA32_APIC_BASE[11] is set to 0, prior initialization to the APIC may be lost and the APIC may return to the state described in Section 10.4.7.1, “Local APIC State After Power-Up or Reset.”

2. Using the APIC software enable/disable flag in the spurious-interrupt vector register (see Figure 10-31):

— If IA32_APIC_BASE[11] is 1, software can temporarily disable a local APIC at any time by clearing the APIC software enable/disable flag in the spurious- interrupt vector register (see Figure 10-31). The state of the local APIC when in this software-disabled state is described in Section 10.4.7.2, “Local APIC State After It Has Been Software Disabled.”

— When the local APIC is in the software-disabled state, it can be re-enabled at any time by setting the APIC software enable/disable flag to 1.

For the Pentium processor, the APICEN pin (which is shared with the PICD1 pin) is used during power-up or RESET to disable the local APIC.

10.4.4 Local APIC Status and Location

The status and location of the local APIC are contained in the IA32_APIC_BASE MSR (see Figure 10-5). MSR bit functions are described below: • BSP flag, bit 8 ⎯ Indicates if the processor is the bootstrap processor (BSP). See Section 8.4, “Multiple-Processor (MP) Initialization.” Following a power-up or RESET, this flag is set to 1 for the processor selected as the BSP and set to 0 for the remaining processors (APs).

Page 458 of the Intel 253668-032US user manual — 10.4.6 Local APIC ID
Page 458 · click to enlarge
Page 458

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • APIC Global Enable flag, bit 11 ⎯ Enables or disables the local APIC (see Section 10.4.3, “Enabling or Disabling the Local APIC” ). This flag is available in the Pentium 4, Intel Xeon, and P6 family processors. It is not guaranteed to be available or available at the same location in future Intel 64 or IA-32 processors.
  • APIC Base field, bits 12 through 35 ⎯ Specifies the base address of the APIC registers. This 24-bit value is extended by 12 bits at the low end to form the base address. This automatically aligns the address on a 4-KByte boundary. Following a power-up or RESET, the field is set to FEE0 0000H.
  • Bits 0 through 7, bits 9 and 10, and bits MAXPHYADDR 1 through 63 in the IA32_APIC_BASE MSR are reserved.

63 0 7 10 11 8 9 12

MAXPHYADDR

APIC global enable/disable APIC Base—Base physical address

Figure 10-5. IA32_APIC_BASE MSR (APIC_BASE_MSR in P6 Family)

10.4.5 Relocating the Local APIC Registers

The Pentium 4, Intel Xeon, and P6 family processors permit the starting address of the APIC registers to be relocated from FEE00000H to another physical address by modifying the value in the 24-bit base address field of the IA32_APIC_BASE MSR. This extension of the APIC architecture is provided to help resolve conflicts with memory maps of existing systems and to allow individual processors in an MP system to map their APIC registers to different locations in physical memory.

10.4.6 Local APIC ID

At power up, system hardware assigns a unique APIC ID to each local APIC on the system bus (for Pentium 4 and Intel Xeon processors) or on the APIC bus (for P6 family and Pentium processors). The hardware assigned APIC ID is based on system topology and includes encoding for socket position and cluster information (see Figure 8-2).

In MP systems, the local APIC ID is also used as a processor ID by the BIOS and the operating system. Some processors permit software to modify the APIC ID. However, the ability of software to modify the APIC ID is processor model specific. Because of

1. The MAXPHYADDR is 36 bits for processors that do not support CPUID leaf 80000008H, or indi cated by CPUID.80000008H:EAX[bits 7:0] for processors that support CPUID leaf 80000008H.

APIC Base Reserved · BSP—Processor is BSP · Reserved

Page 459 of the Intel 253668-032US user manual — 10.4.7 Local APIC State
Page 459 · click to enlarge
Page 459

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

this, operating system software should avoid writing to the local APIC ID register. The value returned by bits 31-24 of the EBX register (when the CPUID instruction is executed with a source operand value of 1 in the EAX register) is always the Initial APIC ID (determined by the platform initialization). This is true even if software has changed the value in the Local APIC ID register.

The processor receives the hardware assigned APIC ID (or Initial APIC ID) by sampling pins A11# and A12# and pins BR0# through BR3# (for the Pentium 4, Intel Xeon, and P6 family processors) and pins BE0# through BE3# (for the Pentium processor). The APIC ID latched from these pins is stored in the APIC ID field of the local APIC ID register (see Figure 10-6), and is used as the Initial APIC ID for the processor.

Address0FEE0 0020H Value after reset: 0000 0000H

P6 family and Pentium processors

31 27 24 0

Pentium 4 processors, Xeon processors, and later processors

MSR Address802H

Figure 10-6. Local APIC ID Register

For the P6 family and Pentium processors, the local APIC ID field in the local APIC ID register is 4 bits. Encodings 0H through EH can be used to uniquely identify 15 different processors connected to the APIC bus. For the Pentium 4 and Intel Xeon processors, the xAPIC specification extends the local APIC ID field to 8 bits. These can be used to identify up to 255 processors in the system.

10.4.7 Local APIC State

The following sections describe the state of the local APIC and its registers following a power-up or RESET, after the local APIC has been software disabled, following an INIT reset, and following an INIT-deassert message.

Show 5 more labels / short text on this page
Reserved APIC ID · 31 24 0 · Reserved APIC ID · x2APIC Mode · x2APIC ID
Page 460 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 460 · click to enlarge
Page 460

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

x2APIC will introduce 32-bit ID; see Section 10.5.

10.4.7.1 Local APIC State After Power-Up or Reset

Following a power-up or RESET of the processor, the state of local APIC and its regis ters are as follows: • The following registers are reset to all 0s:

  • IRR, ISR, TMR, ICR, LDR, and TPR
  • Timer initial count and timer current count registers
  • Divide configuration register
  • The DFR register is reset to all 1s.
  • The LVT register is reset to 0s except for the mask bits; these are set to 1s.
  • The local APIC version register is not affected.
  • The local APIC ID register is set to a unique APIC ID. (Pentium and P6 family processors only). The Arb ID register is set to the value in the APIC ID register.
  • The spurious-interrupt vector register is initialized to 000000FFH. By setting bit 8 to 0, software disables the local APIC.
  • If the processor is the only processor in the system or it is the BSP in an MP system (see Section 8.4.1, “BSP and AP Processors” ); the local APIC will respond normally to INIT and NMI messages, to INIT# signals and to STPCLK# signals. If the processor is in an MP system and has been designated as an AP; the local APIC will respond the same as for the BSP. In addition, it will respond to SIPI messages. For P6 family processors only, an AP will not respond to a STPCLK# signal.

10.4.7.2 Local APIC State After It Has Been Software Disabled

  • When the APIC software enable/disable flag in the spurious interrupt vector register has been explicitly cleared (as opposed to being cleared during a power up or RESET), the local APIC is temporarily disabled (see Section 10.4.3, “Enabling or Disabling the Local APIC” ). The operation and response of a local APIC while in this software-disabled state is as follows:
  • The local APIC will respond normally to INIT, NMI, SMI, and SIPI messages.
  • Pending interrupts in the IRR and ISR registers are held and require masking or handling by the CPU.
  • The local APIC can still issue IPIs. It is software’s responsibility to avoid issuing IPIs through the IPI mechanism and the ICR register if sending interrupts through this mechanism is not desired.
  • The reception or transmission of any IPIs that are in progress when the local APIC is disabled are completed before the local APIC enters the software-disabled state.
Page 461 of the Intel 253668-032US user manual — 10.4.8 Local APIC Version Register
Page 461 · click to enlarge
Page 461

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • The mask bits for all the LVT entries are set. Attempts to reset these bits will be ignored.
  • (For Pentium and P6 family processors) The local APIC continues to listen to all bus messages in order to keep its arbitration ID synchronized with the rest of the system.

10.4.7.3 Local APIC State After an INIT Reset (“Wait-for-SIPI” State)

  • An INIT reset of the processor can be initiated in either of two ways:
  • By asserting the processor’s INIT# pin.
  • By sending the processor an INIT IPI (an IPI with the delivery mode set to INIT).

Upon receiving an INIT through either of these mechanisms, the processor responds by beginning the initialization process of the processor core and the local APIC. The state of the local APIC following an INIT reset is the same as it is after a power-up or hardware RESET, except that the APIC ID and arbitration ID registers are not affected. This state is also referred to at the “wait-for-SIPI” state (see also: Section 8.4.2, “MP Initialization Protocol Requirements and Restrictions”).

10.4.7.4 Local APIC State After It Receives an INIT-Deassert IPI

Only the Pentium and P6 family processors support the INIT-deassert IPI. An INIT- disassert IPI has no affect on the state of the APIC, other than to reload the arbitra tion ID register with the value in the APIC ID register.

10.4.8 Local APIC Version Register

The local APIC contains a hardwired version register. Software can use this register to identify the APIC version (see Figure 10-7). In addition, the register specifies the number of entries in the local vector table (LVT) for a specific implementation.

The fields in the local APIC version register are as follows:

Version The version numbers of the local APIC:

1XH Local APIC. For Pentium 4 and Intel Xeon processors, 14H is returned.

0XH 82489DX external APIC.

20H - FFH Reserved.

Max LVT Entry Shows the number of LVT entries minus 1. For the Pentium 4 and Intel Xeon processors (which have 6 LVT entries), the value returned in the Max LVT field is 5; for the P6 family processors (which have 5 LVT entries), the value returned is 4; for the Pentium processor (which has 4 LVT entries), the value returned is 3.

Page 462 of the Intel 253668-032US user manual — 10.5.1 DETECTING AND ENABLING x2APIC
Page 462 · click to enlarge
Page 462

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Version Max. LVT

Value after reset000N 00VVH V = Version, N = # of LVT entries minus 1
AddressFEE0 0030H

Figure 10-7. Local APIC Version Register

10.5 EXTENDED XAPIC (X2APIC)

The x2APIC architecture extends the xAPIC architecture (described in Section 9.4) in a backward compatible manner and provides forward extendability for future Intel platform innovations. Specifically, x2APIC • Retains all key elements of compatibility to the xAPIC architecture:

— interrupt and processor priorities,

  • — interrupt destination types;
  • Provides extensions to scale processor addressability for both the logical and physical destination modes;
  • Adds new features to enhance performance of interrupt delivery;
  • Reduces complexity of logical destination mode interrupt delivery on link based platform architectures.
  • Uses MSR programming interface to access APIC registers in x2APIC mode instead of memory-mapped interfaces. Memory-mapped interface is supported when operating in xAPIC mode.

10.5.1 DETECTING AND ENABLING x2APIC

Processor support for x2APIC mode can be detected by executing CPUID with EAX=1 and then checking ECX, bit 21 ECX. If CPUID.(EAX=1):ECX.21 is set , the processor supports the x2APIC capability and can be placed into the x2APIC mode. • System software can place the local APIC in the x2APIC mode by setting the x2APIC mode enable bit (bit 10) in the IA32_APIC_BASE MSR at MSR address 01BH. The layout for the IA32_APIC_BASE MSR is shown in Figure 10-8.

Show 6 more labels / short text on this page
23 24 15 · Reserved · Reserved · Entry · — delivery modes, · — interrupt sources,
Page 463 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 463 · click to enlarge
Page 463

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

63 0 7 10 11 8 9 12

EN—xAPIC global enable/disable APIC Base—Base physical address

Figure 10-8. IA32_APIC_BASE MSR Supporting x2APIC

Table 10-2, “x2APIC operating mode configurations” describe the possible combina tions of the enable bit (EN - bit 11) and the extended mode bit (EXTD - bit 10) in the IA32_APIC_BASE MSR.

Table 10-2. x2APIC Operating Mode Configurations

xAPIC global enable (IA32_APIC_BASE[11])

x2APIC enable (IA32_APIC_BASE[10]) Description

0 0 local APIC is disabled

1 0 local APIC is enabled in xAPIC mode

1 1 local APIC is enabled in x2APIC mode

Once the local APIC has been switched to x2APIC mode (EN = 1, EXTD = 1), switching back to xAPIC mode would require system software to disable the local APIC unit. Specifically, attempting to write a value to the IA32_APIC_BASE MSR that has (EN= 1, EXTD = 0) when the local APIC is enabled and in x2APIC mode will raise a GP exception. Once bit 10 in IA32_APIC_BASE MSR is set, the only way to leave x2APIC mode using IA32_APIC_BASE would require a WRMSR to set both bit 11 and bit 10 to zero. Section 10.5.6, “x2APIC State Transitions” provides a detailed state diagram for the state transitions allowed for the local APIC.

10.5.1.1 Instructions to Access APIC Registers

In x2APIC mode, system software uses RDMSR and WRMSR to access the APIC regis ters. The MSR addresses for accessing the x2APIC registers are architecturally defined and specified in Section 10.5.1.2, “APIC Register Address Space”. Executing the RDMSR instruction with APIC register address specified in ECX returns the content of bits 0 through 31 of the APIC registers in EAX. Bits 32 through 63 are returned in register EDX - these bits are reserved if the APIC register being read is a

Show 5 more labels / short text on this page
APIC Base Reserved · EXTD—Enable x2APIC mode · BSP—Processor is BSP · Reserved · 0 1 Invalid
Page 464 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 464 · click to enlarge
Page 464

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

32-bit register. Similarly executing the WRMSR instruction with the APIC register address in ECX, writes bits 0 to 31 of register EAX to bits 0 to 31 of the specified APIC register. If the register is a 64-bit register then bits 0 to 31 of register EDX are written to bits 32 to 63 of the APIC register. The Interrupt Command Register is the only APIC register that is implemented as a 64-bit MSR. The semantics of handling reserved bits are defined in Section 10.5.1.3, “Reserved Bit Checking”.

10.5.1.2 APIC Register Address Space

The MSR address range between 0000_0800H through 0000_0BFFH is architectur ally reserved and dedicated for accessing APIC registers in x2APIC mode. Table 10-3 provides the detailed list of the APIC registers in xAPIC mode and x2APIC mode. The MSR address offset specified in the table is relative to the base MSR address of 800H. The MMIO offset specified in the table is relative to the default base address of FEE00000H.

  • There is a one-to-one mapping between the legacy xAPIC register MMIO offset and the MSR address offset with the following exceptions:
  • The Interrupt Command Register (ICR): The two 32-bit ICR registers in xAPIC mode are merged into a single 64-bit MSR in x2APIC mode.
  • The Destination Format Register (DFR) is not supported in x2APIC mode.
  • The SELF IPI register is available only if x2APIC mode is enabled.

The MSR address space is compressed to allow for future growth. Every 32 bit register on a 128- bit boundary in the legacy MMIO space is mapped to a single MSR in the local x2APIC MSR address space. The upper 32-bits of all x2APIC MSRs (except for the ICR) are reserved.

Table 10-3. Local APIC Register Address Map Supported by x2APIC

MSR Offset (x2APIC mode) Register Name

MMIO Offset (xAPIC mode)

0020H 002H Local APIC ID Register Read only See Section 10.5.6.1 for initial values.

0030H 003H Local APIC Version Register

Read only. Same version between extended and legacy modes. Bit 24 is available only to an x2APIC unit (in xAPIC mode and x2APIC modes, See Section 2.5.1).

R/W Semantics Comments · 0000H- 0010H 000H-001H Reserved · 0040H- 0070H 004H-007H Reserved

Page 465 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 465 · click to enlarge
Page 465

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-3. Local APIC Register Address Map Supported by x2APIC (Contd.)

MSR Offset (x2APIC mode) Register Name

MMIO Offset (xAPIC mode)

0080H 008H Task Priority Register (TPR)

Read/Write. Bits 7:0 are RW. Bits 31:8 are Reserved.

00A0H 00AH Processor Priority Register (PPR)

Read only.

00B0H 00BH EOI Register Write only. 0 is the only valid value to write. GP fault on non- zero write

00D0H 00DH Logical Destination Register

Read only. Read/Write in xAPIC mode)

00E0H 00EH Reserved1 GP fault on Read Write in x2APIC mode.

00F0H 00FH Spurious Interrupt Vector Register

Read/Write. Bits 0-8, 12 Read/Write; other bits reserved.

0100H 010H In-Service Register (ISR); bits 0:31

Read Only.

0110H 011H ISR bits 32:63 Read Only.

0120H 012H ISR bits 64:95 Read Only.

0130H 013H ISR bits 96:127 Read Only.

0140H 014H ISR bits 128:159 Read Only.

0150H 015H ISR bits 160:191 Read Only.

0160H 016H ISR bits 192:223 Read Only.

0170H 017H ISR bits 224:255 Read Only.

0180H 018H Trigger Mode Register (TMR); bits 0:31

Read Only.

0190H 019H TMR bits 32:63 Read Only.

01A0H 01AH TMR bits 64:95 Read Only.

01B0H 01BH TMR bits 96:127 Read Only.

01C0H 01CH TMR bits 128:159 Read Only.

01D0H 01DH TMR bits 160:191 Read Only.

01E0H 01EH TMR bits 192:223 Read Only.

R/W Semantics Comments · 0090H 009H Reserved · 00C0H 00CH Reserved

Page 466 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 466 · click to enlarge
Page 466

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-3. Local APIC Register Address Map Supported by x2APIC (Contd.)

MSR Offset (x2APIC mode) Register Name

MMIO Offset (xAPIC mode)

01F0H 01FH TMR bits 224:255 Read Only.

0200H 020H Interrupt Request Register (IRR); bits 0:31

Read Only.

0210H 021H IRR bits32:63 Read Only.

0220H 022H IRR bits 64:95 Read Only.

0230H 023H IRR bits 96:127 Read Only.

0240H 024H IRR bits 128:159 Read Only.

0250H 025H IRR bits 160:191 Read Only.

0260H 026H IRR bits 192:223 Read Only.

0270H 027H IRR bits 224:255 Read Only.

0280H 028H Error Status Register Read/Write. GP fault on non-zero writes

02F0H 02FH LVT CMCI Register Read/Write.

0300H- 0310H2 030H3 Interrupt Command Register (ICR); bits 0-63

Read/Write.

0320H 032H LVT Timer Register Read/Write.

0330H 033H LVT Thermal Sensor Register

Read/Write.

0340H 034H LVT Performance Monitoring Register

Read/Write.

0350H 035H LVT LINT0 Register Read/Write.

0360H 036H LVT LINT1 Register Read/Write.

0370H 037H LVT Error Register Read/Write.

0380H 038H Initial Count Register (for Timer)

Read/Write.

0390H 039H Current Count Register (for Timer)

Read Only.

R/W Semantics Comments · 0290H- 02E0H 029H-02EH Reserved · 03A0H- 03D0H 03AH-03DH Reserved

Page 467 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 467 · click to enlarge
Page 467

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-3. Local APIC Register Address Map Supported by x2APIC (Contd.)

MSR Offset (x2APIC mode) Register Name

MMIO Offset (xAPIC mode)

03E0H 03EH Divide Configuration Register (for Timer)

Read/Write.

Not supported 03FH SELF IPI4 Write only Only in x2APIC mode

10.5.1.3 Reserved Bit Checking

Section 10.5.1.2 and Table 10-3 specifies the reserved bit definitions for the APIC registers in x2APIC mode. Non-zero writes (by WRMSR instruction) to reserved bits to these registers will raise a general protection fault exception while reads return zeros (RsvdZ semantics).

In x2APIC mode, the local APIC ID register is increased to 32 bits wide. This enables 2^32 -1 processors to be addressable in physical destination mode. This 32-bit value is referred to as “x2APIC ID”. A processor implementation may choose to support less than 32 bits in its hardware. System software should be agnostic to the actual number of bits that are implemented. All non-implemented bits will return zeros on reads by software.

The APIC ID value of FFFF_FFFFH and the highest value corresponding to the imple mented bit-width of the local APIC ID register in the system are reserved and cannot be assigned to any logical processor.

In x2APIC mode, the local APIC ID register is a read-only register to system software and will be initialized by hardware. It is accessed via the RDMSR instruction reading the MSR at address 0802H.

Each logical processor in the system (including clusters with a communication fabric) must be configured with an unique x2APIC ID to avoid collisions of x2APIC IDs. On DP and high-end MP processors targeted to specific market segments and depending on the system configuration, it is possible that logical processors in different and "un- connected" clusters power up initialized with overlapping x2APIC IDs. In these configurations, a model-specific means may be provided in those product segments

R/W Semantics Comments · 040H-3FFH Reserved

Page 468 of the Intel 253668-032US user manual — 10.5.4 VM-exit Controls for MSRs and x2APIC Registers
Page 468 · click to enlarge
Page 468

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

to enable BIOS and/or platform firmware to re-configure the x2APIC IDs in some clusters to provide for unique and non-overlapping system wide IDs before config uring the disconnected components into a single system.

10.5.2 x2APIC Register Availability

The local APIC registers can be accessed via the MSR interface only when the local APIC has been switched to the x2APIC mode as described in Section 10.5.1. Accessing any APIC register in the MSR address range 0800H through 0BFFH via RDMSR or WRMSR when the local APIC is not in x2APIC mode will cause the instruc tions to raise a GP fault. In x2APIC mode, the memory mapped interface is not avail able and any access to the MMIO interface will behave similar to that of a legacy xAPIC in globally disabled state. Table 10-4 provides the interactions between the legacy & extended modes and the legacy and register interfaces.

Table 10-4. MSR/MMIO Interface of a Local x2APIC in Different Modes of Operation

MMIO Interface MSR Interface

xAPIC mode Available GP Fault

x2APIC mode Behavior identical to xAPIC in globally disabled state

10.5.3 MSR Access in x2APIC Mode

To allow for efficient access to the APIC registers in x2APIC mode, the serializing semantics of WRMSR are relaxed when writing to the APIC registers. Thus, system software should not use “WRMSR to APIC registers in x2APIC mode” as a serializing instruction. Read and write accesses to the APIC registers will occur in program order. A WRMSR to an APIC register may complete before all preceding stores are globally visible; software can prevent this by inserting a serializing instruction or MFENCE before the WRMSR.

The RDMSR instruction is not serializing and this behavior is unchanged when reading APIC registers in x2APIC mode. System software accessing the APIC regis ters using the RDMSR instruction should not expect a serializing behavior. (Note: The MMIO-based xAPIC interface is mapped by system software as an un-cached region. Consequently, read/writes to the xAPIC-MMIO interface have serializing semantics in the xAPIC mode.)

10.5.4 VM-exit Controls for MSRs and x2APIC Registers

The VMX architecture allows a VMM to specify lists of MSRs to be loaded or stored on VMX transitions using the VMX-transition MSR areas (see VM-exit MSR-store address

Available

Page 469 of the Intel 253668-032US user manual — 10.5.5 Directed EOI with x2APIC Mode
Page 469 · click to enlarge
Page 469

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

field, VM-exit MSR-load address filed, and VM-entry MSR-load address field in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3B).

The X2APIC MSRs cannot to be loaded and stored on VMX transitions. A VMX transi tion fails if the VMM has specified that the transition should access any MSRs in the address range from 0000_0800H to 0000_08FFH (the range used for accessing the X2APIC registers). Specifically, processing of an 128-bit entry in any of the VMX- transition MSR areas fails if bits 31:0 of that entry (represented as ENTRY_LOW_DW) satisfies the expression: “ENTRY_LOW_DW & FFFFF800H = 00000800H”. Such a failure causes an associated VM entry to fail (by reloading host state) and causes an associated VM exit to lead to VMX abort.

10.5.5 Directed EOI with x2APIC Mode

  • Directed EOI capability is intended to enable system software to perform directed EOIs to specific IOxAPICs in the system. System software desiring to perform a directed EOI would do the following:
  • inhibit the broadcast of EOI message by setting bit 12 of the Spurious Interrupt Vector Register, and
  • following the EOI to the local x2APIC unit for a level triggered interrupt, perform a directed EOI to the IOxAPIC generating the interrupt by writing to its EOI register.

Supporting directed EOI capability would require system software to retain a mapping associating level triggered interrupts with IOxAPICs in the system.

Bit 12 of the Spurious Interrupt Vector Register (SVR) in the local x2APIC unit controls the generation of the EOI broadcast if the Directed EOI capability is supported. This bit is reserved to 0 if the processor doesn't support Directed EOI. If SVR[bit 12] is set, a broadcast EOI is not generated on an EOI cycle even if the asso ciated TMR bit is indicating the current interrupt is a level triggered interrupt. Layout of the Spurious Interrupt Vector Register is shown in Figure 10-9.

Page 470 of the Intel 253668-032US user manual — 10.5.6 x2APIC State Transitions
Page 470 · click to enlarge
Page 470

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

0. APIC Disabled 1: APIC Enabled Spurious Vector
MMIO AddressFEE0 00F0H MSR Address: 080FH

Figure 10-9. Spurious Interrupt Vector Register (SVR) of x2APIC

The default value for SVR[bit 12] is clear, indicating that an EOI broadcast will be performed.

The support for Directed EOI capability can be detected by means of bit 24 in the Local APIC Version Register. This feature is supported in both the xAPIC mode and x2APIC modes of a local x2APIC unit. Layout of the Local APIC Version register is as shown in Figure 10-10. The Directed EOI feature is supported if bit 24 is set to 1.

7 8 23 15

Vector Max LVT Entry

MMIO AddressFEE0 0030H MSR Address: 0803H

Figure 10-10. Local APIC Version Register of x2APIC

10.5.6 x2APIC State Transitions

This section provides a detailed description of the x2APIC states of a local x2APIC unit, transitions between these states as well as interactions of these states with INIT and RESET.

10.5.6.1 x2APIC States

The valid states for a local x2APIC unit is listed in Table 10-2: • APIC disabled: IA32_APIC_BASE[EN]=0 and IA32_APIC_BASE[EXTD]=0

Show 6 more labels / short text on this page
Reserved · EOI Broadcast Disable · APIC Software Enable/Disable · Reserved · Reserved · Directed EOI Support
Page 471 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 471 · click to enlarge
Page 471

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • xAPIC mode: IA32_APIC_BASE[EN]=1 and IA32_APIC_BASE[EXTD]=0
  • x2APIC mode: IA32_APIC_BASE[EN]=1 and IA32_APIC_BASE[EXTD]=1
  • Invalid: IA32_APIC_BASE[EN]=0 and IA32_APIC_BASE[EXTD]=1

The state corresponding to EXTD=1 and EN=0 is not valid and it is not possible to get into this state. Values written to the IA32_APIC_BASE_MSR that attempt a transition from a valid state to this invalid state will cause a GP fault. Figure 10-11 shows the comprehensive state transition diagram for a local x2APIC unit.

  • On coming out of RESET, the local APIC unit is enabled and is in the xAPIC mode: IA32_APIC_BASE[EN]=1 and IA32_APIC_BASE[EXTD]=0. The APIC registers are initialized as:
  • The local APIC ID is initialized by hardware with a 32 bit ID (x2APIC ID). The lowest 8 bits of the x2APIC ID is the legacy local xAPIC ID, and is stored in the upper 8 bits of the APIC register for access in xAPIC mode.
  • The following APIC registers are reset to all zeros for those fields that are defined in the xAPIC mode:

— IRR, ISR, TMR, ICR, LDR, TPR, Divide Configuration Register (See Chapter 8 of “Intel® 64 and IA-32 Architectures Software Developer’s Manual“, Vol. 3B for details of individual APIC registers),

  • — Timer initial count and timer current count registers,
  • The LVT registers are reset to 0s except for the mask bits; these are set to 1s.
  • The local APIC version register is not affected.
  • The Spurious Interrupt Vector Register is initialized to 000000FFH.
  • The DFR (available only in xAPIC mode) is reset to all 1s.
  • SELF IPI register is reset to zero.
Page 472 of the Intel 253668-032US user manual — x2APIC After RESET
Page 472 · click to enlarge
Page 472

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 472)
Fig. 26

Figure 10-11. Local x2APIC State Transitions with IA32_APIC_BASE, INIT, and RESET

x2APIC After RESET

  • The valid transitions from the xAPIC mode state are:
  • to the x2APIC mode by setting EXT to 1 (resulting EN=1, EXTD= 1). The physical x2APIC ID (see Figure 10-6 ) is preserved across this transition and the logical x2APIC ID (see Figure 10-21 ) is initialized by hardware during this transition as documented in Section 10.7.2.4 . The state of the extended fields in other APIC registers, which was not initialized at RESET, is not architecturally defined across this transition and system software should explicitly initialize those program mable APIC registers.
  • to the disabled state by setting EN to 0 (resulting EN=0, EXTD= 0).

The result of an INIT in the xAPIC state places the APIC in the state with EN= 1, EXTD= 0. The state of the local APIC ID register is preserved (the 8-bit xAPIC ID is in the upper 8 bits of the APIC ID register). All the other APIC registers are initialized as a result of INIT.

A RESET in this state places the APIC in the state with EN= 1, EXTD= 0. The state of the local APIC ID register is initialized as described in Section 10.5.6.1. All the other APIC registers are initialized described in Section 10.5.6.1.

Page 473 of the Intel 253668-032US user manual — 10.5.7 System Software Transitions
Page 473 · click to enlarge
Page 473

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

x2APIC Transitions From x2APIC Mode

From the x2APIC mode, the only valid x2APIC transition using IA32_APIC_BASE is to the state where the x2APIC is disabled by setting EN to 0 and EXTD to 0. The x2APIC ID (32 bits) and the legacy local xAPIC ID (8 bits) are preserved across this transi tion. A transition from the x2APIC mode to xAPIC mode is not valid and the corre sponding WRMSR to the IA32_APIC_BASE MSR will raise a GP fault.

A RESET in this state places the x2APIC in xAPIC mode. All APIC registers (including the local APIC ID register) are initialized as described in Section 10.5.6.1.

An INIT in this state keeps the x2APIC in the x2APIC mode. The state of the local APIC ID register is preserved (all 32 bits). However, all the other APIC registers are initialized as a result of the INIT transition.

x2APIC Transitions From Disabled Mode

  • From the disabled state, the only valid x2APIC transition using IA32_APIC_BASE is to the xAPIC mode (EN= 1, EXTD = 0). Thus the only means to transition from x2APIC mode to xAPIC mode is a two-step process:
  • first transition from x2APIC mode to local APIC disabled mode (EN= 0, EXTD = 0),
  • followed by another transition from disabled mode to xAPIC mode (EN= 1, EXTD= 0).

Consequently, all the APIC register states in the x2APIC, except for the x2APIC ID (32 bits), are not preserved across mode transitions.

A RESET in the disabled state places the x2APIC in the xAPIC mode. All APIC registers (including the local APIC ID register) are initialized as described in Section 10.5.6.1.

An INIT in the disabled state keeps the x2APIC in the disabled state.

State Changes From xAPIC Mode to x2APIC Mode

  • After APIC register states have been initialized by software in xAPIC mode, a transi tion from xAPIC mode to x2APIC mode does not affect most of the APIC register states, except the following:
  • The Logical Destination Register is not preserved.
  • Any APIC ID value written to the memory-mapped local APIC ID register is not preserved.
  • The high half of the Interrupt Command Register is not preserved.

10.5.7 System Software Transitions

This section describes implications for the x2APIC across system state transitions - specifically initialization and booting.

Page 474 of the Intel 253668-032US user manual — 10.5.8 CPUID Extensions And Topology Enumeration
Page 474 · click to enlarge
Page 474

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Support for the x2APIC architecture can be implemented in the local APIC unit. All existing PCI/MSI capable devices and IOxAPIC unit should work with the x2APIC extensions defined in this document. The x2APIC architecture also provides flexibility to cope with the underlying fabrics that connect the PCI devices, IOxAPICs and Local APIC units.

  • The extensions provided in this specification translate into modifications to:
  • the local APIC unit,
  • the underlying fabrics connecting Message Signaled Interrupts (MSI) capable PCI devices to local xAPICs,
  • the underlying fabrics connecting the IOxAPICs to the local APIC units.

However no modifications are required to PCI or PCIe devices that support direct interrupt delivery to the processors via Message Signaled Interrupts. Similarly no modifications are required to the IOxAPIC. The routing of interrupts from these devices in x2APIC mode leverages the interrupt remapping architecture specified in the Intel® Virtualization Technology for Directed I/O, Rev 1.2 specification.

Modifications to ACPI interfaces to support x2APIC are described in Appendix A, “ACPI Extensions for x2APIC Support”, of the Intel® 64 Architecture x2APIC Specifi cation.

The default will be for the BIOS to pass the control to the OS with the local x2APICs in xAPIC mode if all x2APIC IDs reported by CPUID.0BH:EDX are less than 255, and in x2APIC mode if there are any logical processor reporting its x2APIC ID at 255 or greater.

10.5.8 CPUID Extensions And Topology Enumeration

For Intel 64 and IA-32 processors that support x2APIC, a value of 1 reported by CPUID.01H:ECX[21] indicates that the processor supports x2APIC and the extended topology enumeration leaf (CPUID.0BH).

  • The extended topology enumeration leaf can be accessed by executing CPUID with EAX = 0BH. Processors that do not support x2APIC may support CPUID leaf 0BH. Software can detect the availability of the extended topology enumeration leaf (0BH) by performing two steps:
  • Check maximum input value for basic CPUID information by executing CPUID with EAX= 0. If CPUID.0H:EAX is greater than or equal or 11 (0BH), then proceed to next step
  • Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero.

If both of the above conditions are true, extended topology enumeration leaf is avail able. The presence of CPUID leaf 0BH in a processor does not guarantee support for x2APIC. If CPUID.EAX=0BH, ECX=0H:EBX returns zero and maximum input value for basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not supported on that processor.

Page 475 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 475 · click to enlarge
Page 475

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

The extended topology enumeration leaf is intended to assist software with enumer ating processor topology on systems that requires 32-bit x2APIC IDs to address indi vidual logical processors. For example, a system with greater than 256 logical processors or greater than 64 processor cores will require the OS to use 32-bit x2APIC IDs. Details of CPUID leaf 0BH can be found in the reference pages of CPUID in Chapter 3 of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A.

Processor topology enumeration algorithm for processors supporting the extended topology enumeration leaf of CPUID and processors that do not support CPUID leaf 0BH are treated in Section 8.9.4, “Algorithm for Three-Level Mappings of APIC_ID”.

10.5.8.1 Consistency of APIC IDs and CPUID

The consistency of physical x2APIC ID in MSR 802H in x2APIC mode and the 32-bit value returned in CPUID.0BH:EDX is facilitated by processor hardware.

CPUID.0BH:EDX will report the full 32 bit ID, in xAPIC and x2APIC mode. This allows BIOS to determine if a system has processors with IDs exceeding the 8-bit initial APIC ID limit (CPUID.01H:EBX[31:24]). Initial APIC ID (CPUID.01H:EBX[31:24]) is always equal to CPUID.0BH:EDX[7:0].

If the values of CPUID.0BH:EDX reported by all logical processors in a system are less than 255, BIOS can transfer control to OS in xAPIC mode.

  • If the values of CPUID.0BH:EDX reported by some logical processors in a system are greater or equal than 255, BIOS must support two options to hand off to OS:
  • If BIOS enables logical processors with x2APIC IDs greater than 255, then it should enable X2APIC in Boot Strap Processor (BSP) and all Application Processors (AP) before passing control to the OS. Application requiring processor topology information must use OS provided services based on x2APIC IDs or CPUID.0BH leaf.
  • If a BIOS transfers control to OS in xAPIC mode, then the BIOS must ensure that only logical processors with CPUID.0BH.EDX value less than 255 are enabled. BIOS initialization on all logical processors with CPUID.0B.EDX values greater than or equal to 255 must (a) disable APIC and execute CLI in each logical processor, and (b) leave these logical processor in the lowest power state so that these processors do not respond to INIT IPI during OS boot. The BSP and all the enabled logical processor operate in xAPIC mode after BIOS passed control to OS. Application requiring processor topology information can use OS provided legacy services based on 8-bit initial APIC IDs or legacy topology information from CPUID.01H and CPUID 04H leaves. Even if the BIOS passes control in xAPIC mode, an OS can switch the processors to x2APIC mode later. BIOS SMM handler should always read the APIC_BASE_MSR, determine the APIC mode and use the corresponding access method.
Page 476 of the Intel 253668-032US user manual — 10.6.1 Local Vector Table
Page 476 · click to enlarge
Page 476

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.6 HANDLING LOCAL INTERRUPTS

The following sections describe facilities that are provided in the local APIC for handling local interrupts. These include: the processor’s LINT0 and LINT1 pins, the APIC timer, the performance-monitoring counters, the thermal sensor, and the internal APIC error detector. Local interrupt handling facilities include: the LVT, the error status register (ESR), the divide configuration register (DCR), and the initial count and current count registers.

10.6.1 Local Vector Table

The local vector table (LVT) allows software to specify the manner in which the local interrupts are delivered to the processor core. It consists of the following 32-bit APIC registers (see Figure 10-12), one for each local interrupt: • LVT Timer Register (FEE0 0320H) — Specifies interrupt delivery when the APIC timer signals an interrupt (see Section 10.6.4, “APIC Timer”).

  • LVT Thermal Monitor Register (FEE0 0330H) — Specifies interrupt delivery when the thermal sensor generates an interrupt (see Section 14.5.2, “Thermal Monitor”). This LVT entry is implementation specific, not architectural. If imple mented, it will always be at base address FEE0 0330H.
  • LVT Performance Counter Register (FEE0 0340H) — Specifies interrupt delivery when a performance counter generates an interrupt on overflow (see Section 30.8.5.8, “Generating an Interrupt on Overflow”). This LVT entry is implementation specific, not architectural. If implemented, it is not guaranteed to be at base address FEE0 0340H.
  • LVT LINT0 Register (FEE0 0350H) — Specifies interrupt delivery when an interrupt is signaled at the LINT0 pin.
  • LVT LINT1 Register (FEE0 0360H) — Specifies interrupt delivery when an interrupt is signaled at the LINT1 pin.
  • LVT Error Register (FEE0 0370H) — Specifies interrupt delivery when the APIC detects an internal error (see Section 10.6.3, “Error Handling” ).
  • CMCI LVT Register (FEE0 02F0H) — Specifies interrupt delivery when an overflow condition of corrected machine check error count reaching a threshold value occurred in a machine check bank supporting CMCI (see Section 15.5.1, “CMCI Local APIC Interface” ).

The LVT performance counter register and its associated interrupt were introduced in the P6 processors and are also present in the Pentium 4 and Intel Xeon processors. The LVT thermal monitor register and its associated interrupt were introduced in the Pentium 4 and Intel Xeon processors.

As shown in Figures 10-12, some of these fields and flags are not available (and reserved) for some entries.

Page 477 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 477 · click to enlarge
Page 477

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 477)
Fig. 27
AddressFEE0 0330H † (Pentium 4 and Intel Xeon processors.) When a

performance monitoring counters interrupt is generated, the mask bit for its associated LVT entry is set.

Figure 10-12. Local Vector Table (LVT)

Page 478 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 478 · click to enlarge
Page 478

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

The setup information that can be specified in the registers of the LVT table is as follows:

Vector Interrupt vector number.

Delivery Mode Specifies the type of interrupt to be sent to the processor. Some delivery modes will only operate as intended when used in conjunction with a specific trigger mode. The allowable delivery modes are as follows:

000 (Fixed) Delivers the interrupt specified in the vector field.

010 (SMI) Delivers an SMI interrupt to the processor core through the processor’s local SMI signal path. When using this delivery mode, the vector field should be set to 00H for future compatibility.

100 (NMI) Delivers an NMI interrupt to the processor. The vector information is ignored.

101 (INIT) Delivers an INIT request to the processor core, which causes the processor to perform an INIT. When using this delivery mode, the vector field should be set to 00H for future compatibility.

111 (ExtINT) Causes the processor to respond to the in terrupt as if the interrupt originated in an externally connected (8259A-compatible) interrupt controller. A special INTA bus cycle corresponding to ExtINT, is routed to the ex ternal controller. The external controller is expected to supply the vector information. The APIC architecture supports only one Ex tINT source in a system, usually contained in the compatibility bridge.

Delivery Status (Read Only)

Indicates the interrupt delivery status, as follows:

0 (Idle) There is currently no activity for this inter rupt source, or the previous interrupt from this source was delivered to the processor core and accepted.

1 (Send Pending) Indicates that an interrupt from this source has been delivered to the processor core, but has not yet been accepted (see Section 10.6.5, “Local Interrupt Acceptance”).

Page 479 of the Intel 253668-032US user manual — 10.6.2 Valid Interrupt Vectors
Page 479 · click to enlarge
Page 479

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Interrupt Input Pin Polarity

Specifies the polarity of the corresponding interrupt pin: (0) active high or (1) active low.

Remote IRR Flag (Read Only)

For fixed mode, level-triggered interrupts; this flag is set when the local APIC accepts the interrupt for servicing and is reset when an EOI command is received from the processor. The meaning of this flag is undefined for edge-triggered interrupts and other delivery modes.

Trigger Mode Selects the trigger mode for the local LINT0 and LINT1 pins: (0) edge sensitive and (1) level sensitive. This flag is only used when the delivery mode is Fixed. When the delivery mode is NMI, SMI, or INIT, the trigger mode is always edge sensitive. When the delivery mode is ExtINT, the trigger mode is always level sensitive. The timer and error interrupts are always treated as edge sensitive.

If the local APIC is not used in conjunction with an I/O APIC and fixed delivery mode is selected; the Pentium 4, Intel Xeon, and P6 family processors will always use level-sensitive triggering, regardless if edge-sensitive triggering is selected.

Mask Interrupt mask: (0) enables reception of the interrupt and (1) inhibits reception of the interrupt. When the local APIC handles a performance-monitoring counters interrupt, it automatically sets the mask flag in the corresponding LVT entry. This flag will remain set until software clears it.

Timer Mode Selects the timer mode: (0) one-shot and (1) periodic (see Section 10.6.4, “APIC Timer”).

10.6.2 Valid Interrupt Vectors

The Intel 64 and IA-32 architectures define 256 vector numbers, ranging from 0 through 255 (see Section 6.2, “Exception and Interrupt Vectors”). Local and I/O APICs support 240 of these vectors (in the range of 16 to 255) as valid interrupts.

When an interrupt vector in the range of 0 to 15 is sent or received through the local APIC, the APIC indicates an illegal vector in its Error Status Register (see Section 10.6.3, “Error Handling”). The Intel 64 and IA-32 architectures reserve vectors 16 through 31 for predefined interrupts, exceptions, and Intel-reserved encodings (see Table 6-1). However, the local APIC does not treat vectors in this range as illegal.

When an illegal vector value (0 to 15) is written to an LVT entry and the delivery mode is Fixed (bits 8-11 equal 0), the APIC may signal an illegal vector error, without regard to whether the mask bit is set or whether an interrupt is actually seen on the input.

Page 480 of the Intel 253668-032US user manual — NOTES:
Page 480 · click to enlarge
Page 480

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.6.3 Error Handling

The local APIC provides an error status register (ESR) that it uses to record errors that it detects when handling interrupts (see Figure 10-13). An APIC error interrupt is generated when the local APIC sets one of the error bits in the ESR. The LVT error register allows selection of the interrupt vector to be delivered to the processor core when APIC error is detected. The LVT error register also provides a means of masking an APIC error interrupt.

7 8 1 2 3 4 5 6

Illegal Register Address1

Received Illegal Vector Send Illegal Vector Reserved Receive Accept Error2

Send Accept Error2

Receive Checksum Error2

Send Checksum Error2

AddressFEE0 0280H Value after reset: 0H

NOTES:

1. Used in Intel Core, Pentium 4, Intel Xeon, and P6 family processors; reserved in the Pentium processor.
2. Only used in the P6 family and Pentium processors; reserved in Intel Core, Pentium 4 and Intel Xeon processors.

Figure 10-13. Error Status Register (ESR)

The ESR is a write/read register. A write (of any value) to the ESR must be done just prior to reading the ESR to update the register. This initial write causes the ESR contents to be updated with the latest error status. Back-to-back writes clear the ESR register. After an error bit is set in the register, it remains set until the register is cleared.

The functions of the ESR are listed in Table 10-5.

Reserved

Page 481 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 481 · click to enlarge
Page 481

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-5. ESR Flags

Send Checksum Error (P6 family and Pentium processors only) Set when the local APIC detects a checksum error for a message that it sent on the APIC bus.

Receive Checksum Error (P6 family and Pentium processors only) Set when the local APIC detects a checksum error for a message that it received on the APIC bus.

Send Accept Error (P6 family and Pentium processors only) Set when the local APIC detects that a message it sent was not accepted by any APIC on the APIC bus.

Receive Accept Error (P6 family and Pentium processors only) Set when the local APIC detects that the message it received was not accepted by any APIC on the APIC bus, including itself.

Send Illegal Vector Set when the local APIC detects an illegal vector in the message that it is sending.

Receive Illegal Vector Set when the local APIC detects an illegal vector in the message it received, including an illegal vector code in the local vector table interrupts or in a self-interrupt.

Illegal Reg. Address (Intel Core, Intel Atom, Pentium 4, Intel Xeon, and P6 family processors only) Set when the processor is trying to access a register in the processor's local APIC register address space that is reserved (see Table 10-1). Addresses in one of the 0x10 byte regions marked reserved are illegal register addresses.

The Local APIC Register Map is the address range of the APIC register base address (specified in the IA32_APIC_BASE MSR) plus 4 KBytes.

10.6.3.1 x2APIC Differences in Error Handling

RDMSR and WRMSR operations to reserved addresses in the x2APIC mode will raise a GP fault. Additionally reserved bit violations cause GP faults as detailed in Section 10.5.1.3. Beyond illegal register access and reserved bit violations, other APIC errors are logged in Error Status Register. Writes of a non-zero value to the Error Status Register in x2APIC mode will raise a GP fault.

Write to the ICR (in xAPIC and x2APIC modes) or to SELF IPI register (x2APIC mode only) with an illegal vector (vector

On receiving an IPI with an illegal vector (vector

FLAG Function

Page 482 of the Intel 253668-032US user manual — 10.6.4 APIC Timer
Page 482 · click to enlarge
Page 482

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

If the ICR is programmed with lowest priority delivery mode then the "Re-directible IPI" bit will be set in x2APIC modes (same as legacy xAPIC behavior) and the inter rupt will not be processed.

Write to the ICR with both lowest priority delivery mode and illegal vector, will set the "re-directible IPI" error bit. The interrupt will not be processed and hence the "Send Illegal Vector" error bit will not be set.

7 8 1 2 3 4 5 6

Illegal Register Address Received Illegal Vector Send Illegal Vector Redirectible IPI Reserved

MSR Address828H

Figure 10-14. Error Status Register (ESR) in x2APIC Mode

10.6.4 APIC Timer

The local APIC unit contains a 32-bit programmable timer that is available to soft ware to time events or operations. This timer is set up by programming four regis ters: the divide configuration register (see Figure 10-15), the initial-count and current-count registers (see Figure 10-16), and the LVT timer register (see Figure 10-12).

If CPUID.06H:EAX.ARAT[bit 2] = 1, the processor’s APIC timer runs at a constant rate regardless of P-state transitions and it continues to run at the same rate in deep C-states.

If CPUID.06H:EAX.ARAT[bit 2] = 0 or if CPUID 06H is not supported, the APIC timer may temporarily stop while the processor is in deep C-states or during transitions caused by Enhanced Intel SpeedStep® Technology.

Reserved

Page 483 of the Intel 253668-032US user manual — FEE0 0380H
Page 483 · click to enlarge
Page 483

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

1 2 3 4

AddressFEE0 03E0H Value after reset: 0H

Divide Value (bits 0, 1 and 3)

0. Divide by 2 001: Divide by 4 010: Divide by 8 011: Divide by 16 100: Divide by 32 101: Divide by 64 110: Divide by 128 111: Divide by 1

Figure 10-15. Divide Configuration Register

AddressInitial Count

FEE0 0380H

Current Count FEE0 0390H

Value after reset0H

Figure 10-16. Initial Count and Current Count Registers

The time base for the timer is derived from the processor’s bus clock, divided by the value specified in the divide configuration register.

The timer can be configured through the timer LVT entry for one-shot or periodic operation. In one-shot mode, the timer is started by programming its initial-count register. The initial count value is then copied into the current-count register and count-down begins. After the timer reaches zero, an timer interrupt is generated and the timer remains at its 0 value until reprogrammed.

In periodic mode, the current-count register is automatically reloaded from the initial-count register when the count reaches 0 and a timer interrupt is generated, and the count-down is repeated. If during the count-down process the initial-count register is set, counting will restart, using the new initial-count value. The initial- count register is a read-write register; the current-count register is read only.

The LVT timer register determines the vector number that is delivered to the processor with the timer interrupt that is generated when the timer count reaches zero. The mask flag in the LVT timer register can be used to mask the timer interrupt.

Reserved · Initial Count · Current Count

Page 484 of the Intel 253668-032US user manual — 10.7.1 Interrupt Command Register (ICR)
Page 484 · click to enlarge
Page 484

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.6.5 Local Interrupt Acceptance

When a local interrupt is sent to the processor core, it is subject to the acceptance criteria specified in the interrupt acceptance flow chart in Figure 10-25. If the inter rupt is accepted, it is logged into the IRR register and handled by the processor according to its priority (see Section 10.9.4, “Interrupt Acceptance for Fixed Inter rupts”). If the interrupt is not accepted, it is sent back to the local APIC and retried.

10.7 ISSUING INTERPROCESSOR INTERRUPTS

  • The following sections describe the local APIC facilities that are provided for issuing interprocessor interrupts (IPIs) from software. The primary local APIC facility for issuing IPIs is the interrupt command register (ICR). The ICR can be used for the following functions:
  • To send an interrupt to another processor.
  • To allow a processor to forward an interrupt that it received but did not service to another processor for servicing.
  • To direct the processor to interrupt itself (perform a self interrupt).
  • To deliver special IPIs, such as the start-up IPI (SIPI) message, to other processors.

Interrupts generated with this facility are delivered to the other processors in the system through the system bus (for Pentium 4 and Intel Xeon processors) or the APIC bus (for P6 family and Pentium processors). The ability for a processor to send a lowest priority IPI is model specific and should be avoided by BIOS and operating system software.

10.7.1 Interrupt Command Register (ICR)

The interrupt command register (ICR) is a 64-bit local APIC register (see Figure 10-17) that allows software running on the processor to specify and send interprocessor interrupts (IPIs) to other processors in the system.

To send an IPI, software must set up the ICR to indicate the type of IPI message to be sent and the destination processor or processors. (All fields of the ICR are read- write by software with the exception of the delivery status field, which is read-only.) The act of writing to the low doubleword of the ICR causes the IPI to be sent.

Page 485 of the Intel 253668-032US user manual — FEE0 0310H (32 - 63)
Page 485 · click to enlarge
Page 485

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

11 12 13 14 15 16 17 18 19

Delivery Mode 000Fixed 001: Lowest Priority 1 00: No Shorthand 01: Self
10. All Including Self 11: All Excluding Self 010: SMI 011: Reserved 100: NMI 101: INIT 110: Start Up 111: Reserved
Destination Mode 0Physical 1: Logical
Delivery Status 0Idle 1: Send Pending

Level 0 = De-assert 1 = Assert

AddressFEE0 0300H (0 - 31)

FEE0 0310H (32 - 63)

Value after Reset0H
Trigger Mode 0Edge 1: Level

Figure 10-17. Interrupt Command Register (ICR)

The ICR consists of the following fields.

Vector The vector number of the interrupt being sent.

Delivery Mode Specifies the type of IPI to be sent. This field is also know as the IPI message type field.

000 (Fixed) Delivers the interrupt specified in the vector field to the target processor or processors.

001 (Lowest Priority) Same as fixed mode, except that the inter rupt is delivered to the processor executing at the lowest priority among the set of pro cessors specified in the destination field. The

Show 5 more labels / short text on this page
Reserved Destination Field · Reserved · Vector · Destination Shorthand · Reserved
Page 486 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 486 · click to enlarge
Page 486

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

ability for a processor to send a lowest prior ity IPI is model specific and should be avoid ed by BIOS and operating system software.

010 (SMI) Delivers an SMI interrupt to the target pro cessor or processors. The vector field must be programmed to 00H for future compati bility.

100 (NMI) Delivers an NMI interrupt to the target pro cessor or processors. The vector information is ignored.

101 (INIT) Delivers an INIT request to the target pro cessor or processors, which causes them to perform an INIT. As a result of this IPI mes sage, all the target processors perform an INIT. The vector field must be programmed to 00H for future compatibility.

101 (INIT Level De-assert) (Not supported in the Pentium 4 and Intel Xeon processors.) Sends a synchronization message to all the local APICs in the system to set their arbitration IDs (stored in their Arb ID registers) to the values of their APIC IDs (see Section 10.8, “System and APIC Bus Arbitration”). For this delivery mode, the level flag must be set to 0 and trigger mode flag to 1. This IPI is sent to all proces sors, regardless of the value in the destina tion field or the destination shorthand field; however, software should specify the “all in cluding self” shorthand.

110 (Start-Up) Sends a special “start-up” IPI (called a SIPI) to the target processor or processors. The vector typically points to a start-up routine that is part of the BIOS boot-strap code (see Section 8.4, “Multiple-Processor (MP) Initial ization”). IPIs sent with this delivery mode are not automatically retried if the source APIC is unable to deliver it. It is up to the software to determine if the SIPI was not successfully delivered and to reissue the SIPI if necessary.

011 (Reserved)

Page 487 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 487 · click to enlarge
Page 487

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Destination Mode Selects either physical (0) or logical (1) destination mode (see

Section 10.7.2, “Determining IPI Destination”).

Delivery Status (Read Only)

Indicates the IPI delivery status, as follows:

0 (Idle) There is currently no IPI activity for this local APIC, or the previous IPI sent from this local APIC was delivered and accepted by the tar get processor or processors.

1 (Send Pending) Indicates that the last IPI sent from this lo cal APIC has not yet been accepted by the target processor or processors.

Level For the INIT level de-assert delivery mode this flag must be set to 0; for all other delivery modes it must be set to 1. (This flag has no meaning in Pentium 4 and Intel Xeon processors, and will always be issued as a 1.)

Trigger Mode Selects the trigger mode when using the INIT level de-assert delivery mode: edge (0) or level (1). It is ignored for all other delivery modes. (This flag has no meaning in Pentium 4 and Intel Xeon processors, and will always be issued as a 0.)

Indicates whether a shorthand notation is used to specify the destination of the interrupt and, if so, which shorthand is used. Destination shorthands are used in place of the 8-bit destination field, and can be sent by software using a single write to the low doubleword of the ICR. Shorthands are defined for the following cases: software self interrupt, IPIs to all processors in the system including the sender, IPIs to all processors in the system excluding the sender.

0. (No Shorthand) The destination is specified in the destination field.
1. (Self) The issuing APIC is the one and only destina tion of the IPI. This destination shorthand al lows software to interrupt the processor on which it is executing. An APIC implementa tion is free to deliver the self-interrupt mes sage internally or to issue the message to the bus and “snoop” it as with any other IPI message.
10. (All Including Self) The IPI is sent to all processors in the system including the processor sending the IPI. The APIC will broadcast an IPI message with the

Destination Shorthand

Page 488 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 488 · click to enlarge
Page 488

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

destination field set to FH for Pentium and P6 family processors and to FFH for Pentium 4 and Intel Xeon processors.

11: (All Excluding Self) The IPI is sent to all processors in a system with the exception of the processor sending the IPI. The APIC broadcasts a message with the physical destination mode and destina tion field set to 0xFH for Pentium and P6 family processors and to 0xFFH for Pentium 4 and Intel Xeon processors. Support for this destination shorthand in conjunction with the lowest-priority delivery mode is model specific. For Pentium 4 and Intel Xeon pro cessors, when this shorthand is used togeth er with lowest priority delivery mode, the IPI may be redirected back to the issuing pro cessor.

Destination Specifies the target processor or processors. This field is only used when the destination shorthand field is set to 00B. If the destination mode is set to physical, then bits 56 through 59 contain the APIC ID of the target processor for Pentium and P6 family processors and bits 56 through 63 contain the APIC ID of the target processor the for Pentium 4 and Intel Xeon proces sors. If the destination mode is set to logical, the interpretation of the 8-bit destination field depends on the settings of the DFR and LDR registers of the local APICs in all the processors in the system (see Section 10.7.2, “Determining IPI Destination”).

Not all combinations of options for the ICR are valid. Table 10-6 shows the valid combinations for the fields in the ICR for the Pentium 4 and Intel Xeon processors; Table 10-7 shows the valid combinations for the fields in the ICR for the P6 family processors. Also note that the lower half of the ICR may not be preserved over tran sitions to the deepest C-States.

Table 10-6 Valid Combinations for the Pentium 4 and Intel Xeon Processors’

Local xAPIC Interrupt Command Register

No Shorthand Valid Edge All Modes1 Physical or Logical

No Shorthand Invalid2 Level All Modes Physical or Logical

Self Valid Edge Fixed X3

Self Invalid2 Level Fixed X

Show 5 more labels / short text on this page
Destination Shorthand · Valid/ Invalid · Trigger Mode · Delivery Mode · Destination Mode
Page 489 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 489 · click to enlarge
Page 489

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-6 Valid Combinations for the Pentium 4 and Intel Xeon Processors’

Local xAPIC Interrupt Command Register (Contd.)

Self Invalid X Lowest Priority, NMI, INIT, SMI, Start- Up

All Including Self Valid Edge Fixed X

All Including Self Invalid2 Level Fixed X

All Including Self Invalid X Lowest Priority, NMI, INIT, SMI, Start- Up

Valid Edge Fixed, Lowest Priority1,4, NMI, INIT, SMI, Start-Up

Invalid2 Level FIxed, Lowest Priority4, NMI, INIT, SMI, Start-Up

NOTES: 1. The ability of a processor to send a lowest priority IPI is model specific. 2. For these interrupts, if the trigger mode bit is 1 (Level), the local xAPIC will override the bit set ting and issue the interrupt as an edge triggered interrupt. 3. X means the setting is ignored. 4. When using the “lowest priority” delivery mode and the “all excluding self” destination, the IPI can be redirected back to the issuing APIC, which is essentially the same as the “all including self” destination mode.

Table 10-7 Valid Combinations for the P6 Family Processors’

Local APIC Interrupt Command Register

No Shorthand Valid Edge All Modes1 Physical or Logical

No Shorthand Valid2 Level Fixed, Lowest Priority1, NMI Physical or Logical

No Shorthand Valid3 Level INIT Physical or Logical

Self Valid Edge Fixed X4

Self 1 Level Fixed X

Self Invalid5 X Lowest Priority, NMI, INIT, SMI, Start-Up

All including Self Valid Edge Fixed X

All including Self Valid2 Level Fixed X

All including Self Invalid5 X Lowest Priority, NMI, INIT, SMI, Start-Up

Show 12 more labels / short text on this page
Destination Shorthand · Valid/ Invalid · Trigger Mode · Delivery Mode · Destination Mode · All Excluding Self · All Excluding Self · Destination Shorthand · Valid/ Invalid · Trigger Mode · Delivery Mode · Destination Mode
Page 490 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 490 · click to enlarge
Page 490

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Table 10-7 Valid Combinations for the P6 Family Processors’

Local APIC Interrupt Command Register (Contd.)

All excluding Self Valid Edge All Modes1 X

All excluding Self Valid2 Level Fixed, Lowest Priority1, NMI X

All excluding Self Invalid5 Level SMI, Start-Up X

All excluding Self Valid3 Level INIT X

X Invalid5 Level SMI, Start-Up X

NOTES: 1. The ability of a processor to send a lowest priority IPI is model specific. 2. Treated as edge triggered if level bit is set to 1, otherwise ignored. 3. Treated as edge triggered when Level bit is set to 1; treated as “INIT Level Deassert” message when level bit is set to 0 (deassert). Only INIT level deassert messages are allowed to have the level bit set to 0. For all other messages the level bit must be set to 1.

4. X means the setting is ignored. 5. The behavior of the APIC is undefined.

10.7.1.1 ICR Operation in x2APIC Mode

In x2APIC mode, the layout of the Interrupt Command Register is shown in Figure 10-17. The lower 32 bits of ICR in x2APIC mode is identical to the lower half of the

Show 5 more labels / short text on this page
Destination Shorthand · Valid/ Invalid · Trigger Mode · Delivery Mode · Destination Mode
Page 491 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 491 · click to enlarge
Page 491

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

ICR in xAPIC mode, except the Delivery Status bit is removed since it is not needed in x2APIC mode. The destination ID field is expanded to 32 bits in x2APIC mode.

11 12 13 14 15 16 17 18 19

Delivery Mode 000Fixed 001: Reserved 00: No Shorthand 01: Self
10. All Including Self 11: All Excluding Self 010: SMI 011: Reserved 100: NMI 101: INIT 110: Start Up 111: Reserved
Destination Mode 0Physical 1: Logical

Level 0 = De-assert 1 = Assert

Address830H (63 - 0)
Value after Reset0H
Trigger Mode 0Edge 1: Level

Figure 10-18. Interrupt Command Register (ICR) in x2APIC Mode

To send an IPI, software must set up the ICR or SELF IPI register to indicate the type of IPI message to be sent and the destination processor or processors.

A single MSR write to the Interrupt Command Register is required for dispatching an interrupt in x2APIC mode. With the removal of the Delivery Status bit, system soft ware no longer has a reason to read the ICR. It remains readable only to aid in debugging.

A destination ID value of FFFF_FFFFH is used for broadcast of interrupts in both logical destination and physical destination modes.

Show 5 more labels / short text on this page
Destination Field · Reserved · Vector · Destination Shorthand · Reserved
Page 492 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 492 · click to enlarge
Page 492

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.7.2 Determining IPI Destination

The destination of an IPI can be one, all, or a subset (group) of the processors on the system bus. The sender of the IPI specifies the destination of an IPI with the following APIC registers and fields within the registers: • ICR Register — The following fields in the ICR register are used to specify the destination of an IPI:

— Destination Mode — Selects one of two destination modes (physical or logical).

— Destination Field — In physical destination mode, used to specify the APIC ID of the destination processor; in logical destination mode, used to specify a message destination address (MDA) that can be used to select specific processors in clusters.

— Destination Shorthand — A quick method of specifying all processors, all excluding self, or self as the destination.

  • — Delivery mode, Lowest Priority — Architecturally specifies that a lowestpriority arbitration mechanism be used to select a destination processor from a specified group of processors. The ability of a processor to send a lowest priority IPI is model specific and should be avoided by BIOS and operating system software.
  • Local destination register (LDR) — Used in conjunction with the logical destination mode and MDAs to select the destination processors.
  • Destination format register (DFR) — Used in conjunction with the logical destination mode and MDAs to select the destination processors.

How the ICR, LDR, and DFR are used to select an IPI destination depends on the destination mode used: physical, logical, broadcast/self, or lowest-priority delivery mode. These destination modes are described in the following sections.

10.7.2.1 Physical Destination Mode

In physical destination mode, the destination processor is specified by its local APIC ID (see Section 10.4.6, “Local APIC ID”). For Pentium 4 and Intel Xeon processors, either a single destination (local APIC IDs 00H through FEH) or a broadcast to all APICs (the APIC ID is FFH) may be specified in physical destination mode.

A broadcast IPI (bits 28-31 of the MDA are 1's) or I/O subsystem initiated interrupt with lowest priority delivery mode is not supported in physical destination mode and must not be configured by software. Also, for any non-broadcast IPI or I/O subsystem initiated interrupt with lowest priority delivery mode, software must ensure that APICs defined in the interrupt address are present and enabled to receive interrupts.

For the P6 family and Pentium processors, a single destination is specified in physical destination mode with a local APIC ID of 0H through 0EH, allowing up to 15 local

Page 493 of the Intel 253668-032US user manual — NOTE
Page 493 · click to enlarge
Page 493

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

APICs to be addressed on the APIC bus. A broadcast to all local APICs is specified with 0FH.

NOTE

The number of local APICs that can be addressed on the system bus may be restricted by hardware.

10.7.2.2 Logical Destination Mode

In logical destination mode, IPI destination is specified using an 8-bit message desti nation address (MDA), which is entered in the destination field of the ICR. Upon receiving an IPI message that was sent using logical destination mode, a local APIC compares the MDA in the message with the values in its LDR and DFR to determine if it should accept and handle the IPI. For both configurations of logical destination mode, when combined with lowest priority delivery mode, software is responsible for ensuring that all of the local APICs included in or addressed by the IPI or I/O subsystem interrupt are present and enabled to receive the interrupt.

Figure 10-19 shows the layout of the logical destination register (LDR). The 8-bit logical APIC ID field in this register is used to create an identifier that can be compared with the MDA.

NOTE

The logical APIC ID should not be confused with the local APIC ID that is contained in the local APIC ID register.

31 0 23 24

Reserved Logical APIC ID

Address0FEE0 00D0H Value after reset: 0000 0000H

Figure 10-19. Logical Destination Register (LDR)

Figure 10-20 shows the layout of the destination format register (DFR). The 4-bit model field in this register selects one of two models (flat or cluster) that can be used to interpret the MDA when using logical destination mode.

Page 494 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 494 · click to enlarge
Page 494

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Flat model1111B Cluster model: 0000B
Address0FEE0 00E0H Value after reset: FFFF FFFFH

Figure 10-20. Destination Format Register (DFR)

The interpretation of MDA for the two models is described in the following para graphs.

1. Flat Model — This model is selected by programming DFR bits 28 through 31 to 1111. Here, a unique logical APIC ID can be established for up to 8 local APICs by setting a different bit in the logical APIC ID field of the LDR for each local APIC. A group of local APICs can then be selected by setting one or more bits in the MDA.

Each local APIC performs a bit-wise AND of the MDA and its logical APIC ID. If a true condition is detected, the local APIC accepts the IPI message. A broadcast to all APICs is achieved by setting the MDA to 1s.

2. Cluster Model — This model is selected by programming DFR bits 28 through 31 to 0000. This model supports two basic destination schemes: flat cluster and hierarchical cluster.

The flat cluster destination model is only supported for P6 family and Pentium processors. Using this model, all APICs are assumed to be connected through the APIC bus. Bits 28 through 31 of the MDA contains the encoded address of the destination cluster and bits 24 through 27 identify up to four local APICs within the cluster (each bit is assigned to one local APIC in the cluster, as in the flat connection model). To identify one or more local APICs, bits 28 through 31 of the MDA are compared with bits 28 through 31 of the LDR to determine if a local APIC is part of the cluster. Bits 24 through 27 of the MDA are compared with Bits 24 through 27 of the LDR to identify a local APICs within the cluster.

Sets of processors within a cluster can be specified by writing the target cluster address in bits 28 through 31 of the MDA and setting selected bits in bits 24 through 27 of the MDA, corresponding to the chosen members of the cluster. In this mode, 15 clusters (with cluster addresses of 0 through 14) each having 4 local APICs can be specified in the message. For the P6 and Pentium processor’s local APICs, however, the APIC arbitration ID supports only 15 APIC agents. Therefore, the total number of processors and their local APICs supported in this mode is limited to 15. Broadcast to all local APICs is achieved by setting all destination bits to one. This guarantees a match on all clusters and selects all APICs in each cluster. A broadcast IPI or I/O subsystem broadcast interrupt with

Model · Reserved (All 1s)

Page 495 of the Intel 253668-032US user manual — NOTES
Page 495 · click to enlarge
Page 495

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

lowest priority delivery mode is not supported in cluster mode and must not be configured by software.

The hierarchical cluster destination model can be used with Pentium 4, Intel Xeon, P6 family, or Pentium processors. With this model, a hierarchical network can be created by connecting different flat clusters via independent system or APIC buses. This scheme requires a cluster manager within each cluster, which is responsible for handling message passing between system or APIC buses. One cluster contains up to 4 agents. Thus 15 cluster managers, each with 4 agents, can form a network of up to 60 APIC agents. Note that hierarchical APIC networks requires a special cluster manager device, which is not part of the local or the I/O APIC units.

NOTES

All processors that have their APIC software enabled (using the spurious vector enable/disable bit) must have their DFRs (Desti nation Format Registers) programmed identically.

The default mode for DFR is flat mode. If you are using cluster mode, DFRs must be programmed before the APIC is software enabled. Since some chipsets do not accurately track a system view of the logical mode, program DFRs as soon as possible after starting the processor.

10.7.2.3 Logical Destination Mode in x2APIC Mode

In x2APIC mode, the Logical Destination Register (LDR) is increased to 32 bits wide. It is a read-only register to system software. This 32-bit value is referred to as “logical x2APIC ID”. System software accesses this register via the RDMSR instruc tion reading the MSR at address 80DH. Figure 10-21 provides the layout of the Logical Destination Register in x2APIC mode.

MSR Address80DH

Figure 10-21. Logical Destination Register in x2APIC Mode

In the xAPIC mode, the Destination Format Register (DFR) through MMIO interface determines the choice of a flat logical mode or a clustered logical mode. Flat logical

Logical x2APIC ID

Page 496 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 496 · click to enlarge
Page 496

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

mode is not supported in the x2APIC mode. Hence the Destination Format Register (DFR) is eliminated in x2APIC mode.

  • The 32-bit logical x2APIC ID field of LDR is partitioned into two sub-fields:
  • Cluster ID (LDR[31:16]): is the address of the destination cluster
  • Logical ID (LDR[15:0]): defines a logical ID of the individual local x2APIC within the cluster specified by LDR[31:16].

This layout enables 2^16-1 clusters each with up to 16 unique logical IDs - effec tively providing an addressability of ((2^20) - 16) processors in logical destination mode.

It is likely that processor implementations may choose to support less than 16 bits of the cluster ID or less than 16-bits of the Logical ID in the Logical Destination Register. However system software should be agnostic to the number of bits implemented in the cluster ID and logical ID sub-fields. The x2APIC hardware initialization will ensure that the appropriately initialized logical x2APIC IDs are available to system software and reads of non-implemented bits return zero. This is a read-only register that soft ware must read to determine the logical x2APIC ID of the processor. Specifically, software can apply a 16-bit mask to the lowest 16 bits of the logical x2APIC ID to identify the logical address of a processor within a cluster without needing to know the number of implemented bits in cluster ID and Logical ID sub-fields. Similarly, software can create a message destination address for cluster model, by bit-Oring the Logical X2APIC ID (31:0) of processors that have matching Cluster ID(31:16).

To enable cluster ID assignment in a fashion that matches the system topology char acteristics and to enable efficient routing of logical mode lowest priority device inter rupts in link based platform interconnects, the LDR are initialized by hardware based on the value of x2APIC ID upon x2APIC state transitions. Details of this initialization are provided in Section 10.5.6.

10.7.2.4 Deriving Logical x2APIC ID from the Local x2APIC ID

In x2APIC mode, the 32-bit logical x2APIC ID, which can be read from LDR, is derived from the 32-bit local x2APIC ID. Specifically, the 16-bit logical ID sub-field is derived by shifting 1 by the lowest 4 bits of the x2APIC ID, i.e. Logical ID = 1

Logical x2APIC ID = [(x2APIC ID[31:4]

The use of lowest 4 bits in x2APIC ID implies that at least 16 APIC IDs are reserved for logical processors within a socket in multi-socket configurations. If more than 16 APIC IDS are reserved for logical processors in a socket/package then multiple cluster IDs can exist within the package.

The LDR initialization occurs whenever the x2APIC mode is enabled. This is described in Section 10.5.6.

Page 497 of the Intel 253668-032US user manual — IF (TPR[7:4] ≥ IRRV[7:4]) AND (TPR[7:4] > ISRV[7:4])
Page 497 · click to enlarge
Page 497

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.7.2.5 Broadcast/Self Delivery Mode

The destination shorthand field of the ICR allows the delivery mode to be by-passed in favor of broadcasting the IPI to all the processors on the system bus and/or back to itself (see Section 10.7.1, “Interrupt Command Register (ICR)”). Three destina tion shorthands are supported: self, all excluding self, and all including self. The destination mode is ignored when a destination shorthand is used.

10.7.2.6 Lowest Priority Delivery Mode

With lowest priority delivery mode, the ICR is programmed to send an IPI to several processors on the system bus, using the logical or shorthand destination mechanism for selecting the processor. The selected processors then arbitrate with one another over the system bus or the APIC bus, with the lowest-priority processor accepting the IPI.

For systems based on the Intel Xeon processor, the chipset bus controller accepts messages from the I/O APIC agents in the system and directs interrupts to the processors on the system bus. When using the lowest priority delivery mode, the chipset chooses a target processor to receive the interrupt out of the set of possible targets. The Pentium 4 processor provides a special bus cycle on the system bus that informs the chipset of the current task priority for each logical processor in the system. The chipset saves this information and uses it to choose the lowest priority processor when an interrupt is received.

For systems based on P6 family processors, the processor priority used in lowest- priority arbitration is contained in the arbitration priority register (APR) in each local APIC. Figure 10-22 shows the layout of the APR.

31 0 7 8

Arbitration Priority Sub-Class Arbitration Priority

AddressFEE0 0090H Value after reset: 0H

Figure 10-22. Arbitration Priority Register (APR)

The APR value is computed as follows:

IF (TPR[7:4] ≥ IRRV[7:4]) AND (TPR[7:4] > ISRV[7:4])

THEN

APR[7:0] ← TPR[7:0] ELSE

APR[7:4] ← max(TPR[7:4] AND ISRV[7:4], IRRV[7:4]) APR[3:0] ← 0.

Reserved

Page 498 of the Intel 253668-032US user manual — 10.7.4 SELF IPI Register
Page 498 · click to enlarge
Page 498

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Here, the TPR value is the task priority value in the TPR (see Figure 10-26), the IRRV value is the vector number for the highest priority bit that is set in the IRR (see Figure 10-28) or 00H (if no IRR bit is set), and the ISRV value is the vector number for the highest priority bit that is set in the ISR (see Figure 10-28). Following arbitra tion among the destination processors, the processor with the lowest value in its APR handles the IPI and the other processors ignore it.

(P6 family and Pentium processors.) For these processors, if a focus processor exists, it may accept the interrupt, regardless of its priority. A processor is said to be the focus of an interrupt if it is currently servicing that interrupt or if it has a pending request for that interrupt. For Intel Xeon processors, the concept of a focus processor is not supported.

In operating systems that use the lowest priority delivery mode but do not update the TPR, the TPR information saved in the chipset will potentially cause the interrupt to be always delivered to the same processor from the logical set. This behavior is functionally backward compatible with the P6 family processor but may result in unexpected performance implications.

10.7.3 IPI Delivery and Acceptance

When the low double-word of the ICR is written to, the local APIC creates an IPI message from the information contained in the ICR and sends the message out on the system bus (Pentium 4 and Intel Xeon processors) or the APIC bus (P6 family and Pentium processors). The manner in which these IPIs are handled after being issues in described in Section 10.9, “Handling Interrupts.”

10.7.4 SELF IPI Register

SELF IPIs are used extensively by some system software. The x2APIC architecture introduces a new register interface. This new register is dedicated to the purpose of sending self-IPIs with the intent of enabling a highly optimized path for sending self- IPIs.

Figure 10-23 provides the layout of the SELF IPI register. System software only spec ifies the vector associated with the interrupt to be sent. The semantics of sending a self-IPI via the SELF IPI register are identical to sending a self targeted edge trig gered fixed interrupt with the specified vector. Specifically the semantics are identical to the following settings for an inter-processor interrupt sent via the ICR - Destina tion Shorthand (ICR[19:18] = 01 (Self)), Trigger Mode (ICR[15] = 0 (Edge)), Delivery Mode (ICR[10:8] = 000 (Fixed)), Vector (ICR[7:0] = Vector).

Page 499 of the Intel 253668-032US user manual — 10.8 SYSTEM AND APIC BUS ARBITRATION
Page 499 · click to enlarge
Page 499

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

MSR Address083FH

31 8 7 0

Figure 10-23. SELF IPI register

The SELF IPI register is a write-only register. A RDMSR instruction with address of the SELF IPI register will raise a GP fault.

The handling and prioritization of a self-IPI sent via the SELF IPI register is architec turally identical to that for an IPI sent via the ICR from a legacy xAPIC unit. Specifi cally the state of the interrupt would be tracked via the Interrupt Request Register (IRR) and In Service Register (ISR) and Trigger Mode Register (TMR) as if it were received from the system bus. Also sending the IPI via the Self Interrupt Register ensures that interrupt is delivered to the processor core. Specifically completion of the WRMSR instruction to the SELF IPI register implies that the interrupt has been logged into the IRR. As expected for edge triggered interrupts, depending on the processor priority and readiness to accept interrupts, it is possible that interrupts sent via the SELF IPI register or via the ICR with identical vectors can be combined.

10.8 SYSTEM AND APIC BUS ARBITRATION

When several local APICs and the I/O APIC are sending IPI and interrupt messages on the system bus (or APIC bus), the order in which the messages are sent and handled is determined through bus arbitration.

For the Pentium 4 and Intel Xeon processors, the local and I/O APICs use the arbitra tion mechanism defined for the system bus to determine the order in which IPIs are handled. This mechanism is non-architectural and cannot be controlled by software.

For the P6 family and Pentium processors, the local and I/O APICs use an APIC-based arbitration mechanism to determine the order in which IPIs are handled. Here, each local APIC is given an arbitration priority of from 0 to 15, which the I/O APIC uses during arbitration to determine which local APIC should be given access to the APIC bus. The local APIC with the highest arbitration priority always wins bus access. Upon completion of an arbitration round, the winning local APIC lowers its arbitration priority to 0 and the losing local APICs each raise theirs by 1.

The current arbitration priority for a local APIC is stored in a 4-bit, software-trans parent arbitration ID (Arb ID) register. During reset, this register is initialized to the APIC ID number (stored in the local APIC ID register). The INIT level-deassert IPI, which is issued with and ICR command, can be used to resynchronize the arbitration

Reserved Vector

Page 500 of the Intel 253668-032US user manual — 10.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processors
Page 500 · click to enlarge
Page 500

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

priorities of the local APICs by resetting Arb ID register of each agent to its current APIC ID value. (The Pentium 4 and Intel Xeon processors do not implement the Arb ID register.)

Section 10.11, “APIC Bus Message Passing Mechanism and Protocol (P6 Family, Pentium Processors),” describes the APIC bus arbitration protocols and bus message formats, while Section 10.7.1, “Interrupt Command Register (ICR),” describes the INIT level de-assert IPI message.

10.9 HANDLING INTERRUPTS

When a local APIC receives an interrupt from a local source, an interrupt message from an I/O APIC, or and IPI, the manner in which it handles the message depends on processor implementation, as described in the following sections.

10.9.1 Interrupt Handling with the Pentium 4 and Intel Xeon Processors

With the Pentium 4 and Intel Xeon processors, the local APIC handles the local inter rupts, interrupt messages, and IPIs it receives as follows:

1. It determines if it is the specified destination or not (see Figure 10-24 ). If it is the specified destination, it accepts the message; if it is not, it discards the message.

Belong to Destination? Discard Message

Figure 10-24. Interrupt Acceptance Flow Chart for the Local APIC (Pentium 4 and

2. If the local APIC determines that it is the designated destination for the interrupt and if the interrupt request is an NMI, SMI, INIT, ExtINT, or SIPI, the interrupt is sent directly to the processor core for handling.
Show 5 more labels / short text on this page
Wait to Receive · Bus Message · No Accept Message · Yes · Intel Xeon Processors)
Page 501 of the Intel 253668-032US user manual — 10.9.2 Interrupt Handling with the P6 Family and Pentium Processors
Page 501 · click to enlarge
Page 501

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

3. If the local APIC determines that it is the designated destination for the interrupt but the interrupt request is not one of the interrupts given in step 2, the local APIC sets the appropriate bit in the IRR.
4. When interrupts are pending in the IRR and ISR register, the local APIC dispatches them to the processor one at a time, based on their priority and the current task and processor priorities in the TPR and PPR (see Section 10.9.3.1, “Task and Processor Priorities” ).

5. When a fixed interrupt has been dispatched to the processor core for handling, the completion of the handler routine is indicated with an instruction in the instruction handler code that writes to the end-of-interrupt (EOI) register in the local APIC (see Section 10.9.5, “Signaling Interrupt Servicing Completion”). The act of writing to the EOI register causes the local APIC to delete the interrupt from its ISR queue and (for level-triggered interrupts) send a message on the bus indicating that the interrupt handling has been completed. (A write to the EOI register must not be included in the handler routine for an NMI, SMI, INIT, ExtINT, or SIPI.)

10.9.2 Interrupt Handling with the P6 Family and Pentium Processors

With the P6 family and Pentium processors, the local APIC handles the local inter rupts, interrupt messages, and IPIs it receives as follows (see Figure 10-25).

Page 502 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 502 · click to enlarge
Page 502

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Intel 253668-032US — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC) diagram (page 502)
Fig. 28

Figure 10-25. Interrupt Acceptance Flow Chart for the Local APIC (P6 Family and

1. (IPIs only) It examines the IPI message to determines if it is the specified destination for the IPI as described in Section 10.7.2, “Determining IPI Desti nation.” If it is the specified destination, it continues its acceptance procedure; if it is not the destination, it discards the IPI message. When the message specifies lowest-priority delivery mode, the local APIC will arbitrate with the other processors that were designated on recipients of the IPI message (see Section 10.7.2.6, “Lowest Priority Delivery Mode”).

2. If the local APIC determines that it is the designated destination for the interrupt and if the interrupt request is an NMI, SMI, INIT, ExtINT, or INIT-deassert

Pentium Processors)

Page 503 of the Intel 253668-032US user manual — 10.9.3 Interrupt, Task, and Processor Priority
Page 503 · click to enlarge
Page 503

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

interrupt, or one of the MP protocol IPI messages (BIPI, FIPI, and SIPI), the interrupt is sent directly to the processor core for handling.

3. If the local APIC determines that it is the designated destination for the interrupt but the interrupt request is not one of the interrupts given in step 2, the local APIC looks for an open slot in one of its two pending interrupt queues contained in the IRR and ISR registers (see Figure 10-28). If a slot is available (see Section 10.9.4, “Interrupt Acceptance for Fixed Interrupts”), places the interrupt in the slot. If a slot is not available, it rejects the interrupt request and sends it back to the sender with a retry message.

4. When interrupts are pending in the IRR and ISR register, the local APIC dispatches them to the processor one at a time, based on their priority and the current task and processor priorities in the TPR and PPR (see Section 10.9.3.1, “Task and Processor Priorities” ).

5. When a fixed interrupt has been dispatched to the processor core for handling, the completion of the handler routine is indicated with an instruction in the instruction handler code that writes to the end-of-interrupt (EOI) register in the local APIC (see Section 10.9.5, “Signaling Interrupt Servicing Completion”). The act of writing to the EOI register causes the local APIC to delete the interrupt from its queue and (for level-triggered interrupts) send a message on the bus indicating that the interrupt handling has been completed. (A write to the EOI register must not be included in the handler routine for an NMI, SMI, INIT, ExtINT, or SIPI.)

The following sections describe the acceptance of interrupts and their handling by the local APIC and processor in greater detail.

10.9.3 Interrupt, Task, and Processor Priority

For interrupts that are delivered to the processor through the local APIC, each inter rupt has an implied priority based on its vector number. The local APIC uses this priority to determine when to service the interrupt relative to the other activities of the processor, including the servicing of other interrupts.

For interrupt vectors in the range of 16 to 255, the interrupt priority is determined using the following relationship:

priority = vector / 16

Here the quotient is rounded down to the nearest integer value to determine the priority, with 1 being the lowest priority and 15 is the highest. Because vectors 0 through 31 are reserved for dedicated uses by the Intel 64 and IA-32 architectures, the priorities of user defined interrupts range from 2 to 15.

Each interrupt priority level (sometimes interpreted by software as an interrupt priority class) encompasses 16 vectors. Prioritizing interrupts within a priority level is determined by the vector number. The higher the vector number, the higher the priority within that priority level. In determining the priority of a vector and ranking

Page 504 of the Intel 253668-032US user manual — NOTE
Page 504 · click to enlarge
Page 504

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

of vectors within a priority group, the vector number is often divided into two parts, with the high 4 bits of the vector indicating its priority and the low 4 bit indicating its ranking within the priority group.

10.9.3.1 Task and Processor Priorities

The local APIC also defines a task priority and a processor priority that it uses in determining the order in which interrupts should be handled. The task priority is a software selected value between 0 and 15 (see Figure 10-26) that is written into the task priority register (TPR). The TPR is a read/write register.

31 0 7 8

Task Priority Sub-Class Task Priority

AddressFEE0 0080H Value after reset: 0H

Figure 10-26. Task Priority Register (TPR)

NOTE

In this discussion, the term “task” refers to a software defined task, process, thread, program, or routine that is dispatched to run on the processor by the operating system. It does not refer to an IA-32 architecture defined task as described in Chapter 7, “Task Management.”

The task priority allows software to set a priority threshold for interrupting the processor. The processor will service only those interrupts that have a priority higher than that specified in the TPR. If software sets the task priority in the TPR to 0, the processor will handle all interrupts; it is it set to 15, all interrupts are inhibited from being handled, except those delivered with the NMI, SMI, INIT, ExtINT, INIT-deas sert, and start-up delivery mode. This mechanism enables the operating system to temporarily block specific interrupts (generally low priority interrupts) from disturbing high-priority work that the processor is doing.

The processor priority is set by the processor, also to value between 0 and 15 (see Figure 10-27) that is written into the processor priority register (PPR). The PPR is a read only register. The processor priority represents the current priority at which the processor is executing. It is used to determine whether a pending interrupt can be dispensed to the processor.

Reserved

Page 505 of the Intel 253668-032US user manual — NOTE
Page 505 · click to enlarge
Page 505

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

31 0 7 8

Processor Priority Sub-Class Processor Priority

AddressFEE0 00A0H Value after reset: 0H

Figure 10-27. Processor Priority Register (PPR)

Its value in the PPR is computed as follows:

IF TPR[7:4] ≥ ISRV[7:4]

THEN

PPR[7:0] ← TPR[7:0] ELSE

PPR[7:4] ← ISRV[7:4] PPR[3:0] ← 0

Here, the ISRV value is the vector number of the highest priority ISR bit that is set, or 00H if no ISR bit is set. Essentially, the processor priority is set to either to the highest priority pending interrupt in the ISR or to the current task priority, whichever is higher.

10.9.4 Interrupt Acceptance for Fixed Interrupts

The local APIC queues the fixed interrupts that it accepts in one of two interrupt pending registers: the interrupt request register (IRR) or in-service register (ISR). These two 256-bit read-only registers are shown in Figure 10-28. The 256 bits in these registers represent the 256 possible vectors; vectors 0 through 15 are reserved by the APIC (see also: Section 10.6.2, “Valid Interrupt Vectors”).

NOTE

All interrupts with an NMI, SMI, INIT, ExtINT, start-up, or INIT- deassert delivery mode bypass the IRR and ISR registers and are sent directly to the processor core for servicing.

Reserved

Page 506 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 506 · click to enlarge
Page 506

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

IRR

AddressesIRR FEE0 0200H - FEE0 0270H

ISR FEE0 0100H - FEE0 0170H TMR FEE0 0180H - FEE0 01F0H

Value after reset0H

Figure 10-28. IRR, ISR and TMR Registers

The IRR contains the active interrupt requests that have been accepted, but not yet dispatched to the processor for servicing. When the local APIC accepts an interrupt, it sets the bit in the IRR that corresponds the vector of the accepted interrupt. When the processor core is ready to handle the next interrupt, the local APIC clears the highest priority IRR bit that is set and sets the corresponding ISR bit. The vector for the highest priority bit set in the ISR is then dispatched to the processor core for servicing.

While the processor is servicing the highest priority interrupt, the local APIC can send additional fixed interrupts by setting bits in the IRR. When the interrupt service routine issues a write to the EOI register (see Section 10.9.5, “Signaling Interrupt Servicing Completion”), the local APIC responds by clearing the highest priority ISR bit that is set. It then repeats the process of clearing the highest priority bit in the IRR and setting the corresponding bit in the ISR. The processor core then begins executing the service routing for the highest priority bit set in the ISR.

If more than one interrupt is generated with the same vector number, the local APIC can set the bit for the vector both in the IRR and the ISR. This means that for the Pentium 4 and Intel Xeon processors, the IRR and ISR can queue two interrupts for each interrupt vector: one in the IRR and one in the ISR. Any additional interrupts issued for the same interrupt vector are collapsed into the single bit in the IRR.

For the P6 family and Pentium processors, the IRR and ISR registers can queue no more than two interrupts per priority level, and will reject other interrupts that are received within the same priority level.

If the local APIC receives an interrupt with a priority higher than that of the interrupt currently in serviced, and interrupts are enabled in the processor core, the local APIC dispatches the higher priority interrupt to the processor immediately (without waiting for a write to the EOI register). The currently executing interrupt handler is then interrupted so the higher-priority interrupt can be handled. When the handling of the higher-priority interrupt has been completed, the servicing of the interrupted interrupt is resumed.

The trigger mode register (TMR) indicates the trigger mode of the interrupt (see Figure 10-28). Upon acceptance of an interrupt into the IRR, the corresponding TMR

Reserved · Reserved ISR · Reserved TMR

Page 507 of the Intel 253668-032US user manual — 10.9.6 Task Priority in IA-32e Mode
Page 507 · click to enlarge
Page 507

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

bit is cleared for edge-triggered interrupts and set for level-triggered interrupts. If a TMR bit is set when an EOI cycle for its corresponding interrupt vector is generated, an EOI message is sent to all I/O APICs.

10.9.5 Signaling Interrupt Servicing Completion

For all interrupts except those delivered with the NMI, SMI, INIT, ExtINT, the start- up, or INIT-Deassert delivery mode, the interrupt handler must include a write to the end-of-interrupt (EOI) register (see Figure 10-29). This write must occur at the end of the handler routine, sometime before the IRET instruction. This action indicates that the servicing of the current interrupt is complete and the local APIC can issue the next interrupt from the ISR.

Address0FEE0 00B0H Value after reset: 0H

Figure 10-29. EOI Register

Upon receiving and EOI, the APIC clears the highest priority bit in the ISR and dispatches the next highest priority interrupt to the processor. If the terminated interrupt was a level-triggered interrupt, the local APIC also sends an end-of-inter rupt message to all I/O APICs.

10.9.5.1 Signaling Interrupt Servicing Completion in x2APIC Mode

In the x2APIC mode, the write of a zero value to EOI register is enforced. Writes of a non-zero value to the EOI register in x2APIC mode will raise a GP fault. System soft ware continues to have to perform the EOI write to indicate interrupt service comple tion. But in x2APIC mode, the EOI write is with a value of zero.

10.9.6 Task Priority in IA-32e Mode

In IA-32e mode, operating systems can manage the 16 priority classes of external interrupts (see Section 10.9.3, “Interrupt, Task, and Processor Priority”) explicitly using the task priority register (TPR). Operating systems can use the TPR to tempo rarily block specific (low-priority) interrupts from interrupting a high-priority task. This is done by loading TPR with a value corresponding to the highest-priority inter rupt that is to be blocked. For example:

Page 508 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 508 · click to enlarge
Page 508

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

  • Loading the TPR with a value of 8 (01000B) blocks all interrupts with a priority of 8 or less while allowing all interrupts with a priority of nine or more to be recognized.
  • Loading the TPR with zero enables all external interrupts.
  • Loading the TPR with 0F (01111B) disables all external interrupts.

The TPR (shown in Figure 10-26) is cleared to 0 on reset. In 64-bit mode, software can read and write the TPR using an alternate interface, MOV CR8 instruction. The new priority level is established when the MOV CR8 instruction completes execution. Software does not need to force serialization after loading the TPR using MOV CR8.

Use of the MOV CRn instruction requires a privilege level of 0. Programs running at privilege level greater than 0 cannot read or write the TPR. An attempt to do so results in a general-protection exception, #GP(0). The TPR is abstracted from the interrupt controller (IC), which prioritizes and manages external interrupt delivery to the processor. The IC can be an external device, such as an APIC or 8259. Typically, the IC provides a priority mechanism similar or identical to the TPR. The IC, however, is considered implementation-dependent with the under-lying priority mechanisms subject to change. CR8, by contrast, is part of the Intel 64 architecture. Software can depend on this definition remaining unchanged.

Figure 10-30 shows the layout of CR8; only the low four bits are used. The remaining 60 bits are reserved and must be written with zeros. Failure to do this results in a general-protection exception, #GP(0).

Value after reset0H

Figure 10-30. CR8 Register

10.9.6.1 Interaction of Task Priorities between CR8 and APIC

The first implementation of Intel 64 architecture includes a local advanced program mable interrupt controller (APIC) that is similar to the APIC used with previous IA-32 processors. Some aspects of the local APIC affect the operation of the architecturally defined task priority register and the programming interface using CR8.

  • Notable CR8 and APIC interactions are:
  • The processor powers up with the local APIC enabled.
  • The APIC must be enabled for CR8 to function as the TPR. Writes to CR8 are reflected into the APIC Task Priority Register.
  • APIC.TPR[bits 7:4] = CR8[bits 3:0], APIC.TPR[bits 3:0] = 0. A read of CR8 returns a 64-bit value which is the value of TPR[bits 7:4], zero extended to 64 bits.

Reserved

Page 509 of the Intel 253668-032US user manual — NOTE
Page 509 · click to enlarge
Page 509

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

There are no ordering mechanisms between direct updates of the APIC.TPR and CR8. Operating software should implement either direct APIC TPR updates or CR8 style TPR updates but not mix them. Software can use a serializing instruction (for example, CPUID) to serialize updates between MOV CR8 and stores to the APIC.

10.10 SPURIOUS INTERRUPT

A special situation may occur when a processor raises its task priority to be greater than or equal to the level of the interrupt for which the processor INTR signal is currently being asserted. If at the time the INTA cycle is issued, the interrupt that was to be dispensed has become masked (programmed by software), the local APIC will deliver a spurious-interrupt vector. Dispensing the spurious-interrupt vector does not affect the ISR, so the handler for this vector should return without an EOI.

The vector number for the spurious-interrupt vector is specified in the spurious-inter rupt vector register (see Figure 10-31). The functions of the fields in this register are as follows:

Spurious Vector Determines the vector number to be delivered to the processor when the local APIC generates a spurious vector.

(Pentium 4 and Intel Xeon processors.) Bits 0 through 7 of the this field are programmable by software.

(P6 family and Pentium processors). Bits 4 through 7 of the this field are programmable by software, and bits 0 through 3 are hardwired to logical ones. Software writes to bits 0 through 3 have no effect.

APIC Software Allows software to temporarily enable (1) or disable (0) the local

Enable/Disable APIC (see Section 10.4.3, “Enabling or Disabling the Local APIC”).

Focus Processor Determines if focus processor checking is enabled (0) or disabled (1)

Checking when using the lowest-priority delivery mode. In Pentium 4 and Intel Xeon processors, this bit is reserved and should be cleared to 0.

NOTE

Do not program an LVT or IOAPIC RTE with a spurious vector even if you set the mask bit. A spurious vector ISR does not do an EOI. If for some reason an interrupt is generated by an LVT or RTE entry, the bit in the in-service register will be left set for the spurious vector. This will mask all interrupts at the same or lower priority

Page 510 of the Intel 253668-032US user manual — 10.11 APIC BUS MESSAGE PASSING MECHANISM AND PROTOCOL (P6 FAMILY, PENTIUM PROCESSORS)
Page 510 · click to enlarge
Page 510

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Focus Processor Checking1

0. Enabled 1: Disabled
0. APIC Disabled 1: APIC Enabled Spurious Vector 2
AddressFEE0 00F0H Value after reset: 0000 00FFH
1. Not supported in Pentium 4 and Intel Xeon processors.
2. For the P6 family and Pentium processors, bits 0 through 3 of the spurious vector are hardwired to 1.

Figure 10-31. Spurious-Interrupt Vector Register (SVR)

10.11 APIC BUS MESSAGE PASSING MECHANISM AND PROTOCOL (P6 FAMILY, PENTIUM PROCESSORS)

The Pentium 4 and Intel Xeon processors pass messages among the local and I/O APICs on the system bus, using the system bus message passing mechanism and protocol.

The P6 family and Pentium processors, pass messages among the local and I/O APICs on the serial APIC bus, as follows. Because only one message can be sent at a time on the APIC bus, the I/O APIC and local APICs employ a “rotating priority” arbi tration protocol to gain permission to send a message on the APIC bus. One or more APICs may start sending their messages simultaneously. At the beginning of every message, each APIC presents the type of the message it is sending and its current arbitration priority on the APIC bus. This information is used for arbitration. After each arbitration cycle (within an arbitration round), only the potential winners keep driving the bus. By the time all arbitration cycles are completed, there will be only one APIC left driving the bus. Once a winner is selected, it is granted exclusive use of the bus, and will continue driving the bus to send its actual message.

After each successfully transmitted message, all APICs increase their arbitration priority by 1. The previous winner (that is, the one that has just successfully trans mitted its message) assumes a priority of 0 (lowest). An agent whose arbitration priority was 15 (highest) during arbitration, but did not send a message, adopts the previous winner’s arbitration priority, increments by 1.

Reserved · APIC Software Enable/Disable

Page 511 of the Intel 253668-032US user manual — 10.12 MESSAGE SIGNALLED INTERRUPTS
Page 511 · click to enlarge
Page 511

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

the bus regardless of its sender’s arbitration priority, unless more than one APIC issues an EOI message simultaneously. In the latter case, the APICs sending the EOI messages arbitrate using their arbitration priorities.

If the APICs are set up to use “lowest priority” arbitration (see Section 10.7.2.6, “Lowest Priority Delivery Mode”) and multiple APICs are currently executing at the lowest priority (the value in the APR register), the arbitration priorities (unique values in the Arb ID register) are used to break ties. All 8 bits of the APR are used for the lowest priority arbitration.

10.11.1 Bus Message Formats

See Appendix F, “APIC Bus Message Formats,” for a description of bus message formats used to transmit messages on the serial APIC bus.

10.12 MESSAGE SIGNALLED INTERRUPTS

The PCI Local Bus Specification, Rev 2.2 (www.pcisig.com) introduces the concept of message signalled interrupts. Intel processors and chipsets with this capability currently include the Pentium 4 and Intel Xeon processors. As the specification indi cates:

“Message signalled interrupts (MSI) is an optional feature that enables PCI devices to request service by writing a system-specified message to a system-specified address (PCI DWORD memory write transaction). The transaction address specifies the message destination while the transaction data specifies the message. System software is expected to initialize the message destination and message during device configuration, allocating one or more non- shared messages to each MSI capable function.”

The capabilities mechanism provided by the PCI Local Bus Specification is used to identify and configure MSI capable PCI devices. Among other fields, this structure contains a Message Data Register and a Message Address Register. To request service, the PCI device function writes the contents of the Message Data Register to the address contained in the Message Address Register (and the Message Upper Address register for 64-bit message addresses).

Section 10.12.1 and Section 10.12.2 provide layout details for the Message Address Register and the Message Data Register. The operation issued by the device is a PCI write command to the Message Address Register with the Message Data Register contents. The operation follows semantic rules as defined for PCI write operations and is a DWORD operation.

Page 512 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 512 · click to enlarge
Page 512

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

10.12.1 Message Address Register Format

The format of the Message Address Register (lower 32-bits) is shown in Figure 10-32.

31 20 19 12 11 4 3 2 1 0

0FEEH Destination ID Reserved RH DM XX

Figure 10-32. Layout of the MSI Message Address Register

Fields in the Message Address Register are as follows:

1. Bits 31-20 — These bits contain a fixed value for interrupt messages (0FEEH). This value locates interrupts at the 1-MByte area with a base address of 4G – 18M. All accesses to this region are directed as interrupt messages. Care must to be taken to ensure that no other device claims the region as I/O space.
2. Destination ID — This field contains an 8-bit destination ID. It identifies the message’s target processor(s). The destination ID corresponds to bits 63:56 of the I/O APIC Redirection Table Entry if the IOAPIC is used to dispatch the interrupt to the processor(s).
3. Redirection hint indication (RH) — This bit indicates whether the message should be directed to the processor with the lowest interrupt priority among processors that can receive the interrupt.
  • When RH is 0, the interrupt is directed to the processor listed in the Destination ID field.
  • When RH is 1 and the physical destination mode is used, the Destination ID field must not be set to 0xFF; it must point to a processor that is present and enabled to receive the interrupt.
  • When RH is 1 and the logical destination mode is active in a system using a flat addressing model, the Destination ID field must be set so that bits set to 1 identify processors that are present and enabled to receive the interrupt.
  • If RH is set to 1 and the logical destination mode is active in a system using cluster addressing model, then Destination ID field must not be set to 0xFF; the processors identified with this field must be present and enabled to receive the interrupt.
4. Destination mode (DM) — This bit indicates whether the Destination ID field should be interpreted as logical or physical APIC ID for delivery of the lowest priority interrupt. If RH is 1 and DM is 0, the Destination ID field is in physical
Page 513 of the Intel 253668-032US user manual — 100 - NMI
Page 513 · click to enlarge
Page 513

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

destination mode and only the processor in the system that has the matching APIC ID is considered for delivery of that interrupt (this means no re-direction). If RH is 1 and DM is 1, the Destination ID Field is interpreted as in logical destination mode and the redirection is limited to only those processors that are part of the logical group of processors based on the processor’s logical APIC ID and the Destination ID field in the message. The logical group of processors consists of those identified by matching the 8-bit Destination ID with the logical destination identified by the Destination Format Register and the Logical Destination Register in each local APIC. The details are similar to those described in Section 10.7.2, “Determining IPI Destination.” If RH is 0, then the DM bit is ignored and the message is sent ahead independent of whether the physical or logical destination mode is used.

10.12.2 Message Data Register Format

The layout of the Message Data Register is shown in Figure 10-33.

31 16 15 14 13 11 10 8 7 0

0. Edge 1 - Level
0. Fixed
1. Lowest Priority 010 - SMI 011 - Reserved

Level for Trigger Mode = 0

X - Don’t care Level for Trigger Mode = 1

100 - NMI

101. INIT 110 - Reserved 111 - ExtINT
0. Deassert 1 - Assert

Figure 10-33. Layout of the MSI Message Data Register

Show 4 more labels / short text on this page
Reserved · Reserved Reserved Vector · Trigger Mode · Delivery Mode
Page 514 of the Intel 253668-032US user manual — ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)
Page 514 · click to enlarge
Page 514

ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

Reserved fields are not assumed to be any value. Software must preserve their contents on writes. Other fields in the Message Data Register are described below.

1. Vector — This 8-bit field contains the interrupt vector associated with the message. Values range from 010H to 0FEH. Software must guarantee that the field is not programmed with vector 00H to 0FH.
2. Delivery Mode — This 3-bit field specifies how the interrupt receipt is handled. Delivery Modes operate only in conjunction with specified Trigger Modes. Correct Trigger Modes must be guaranteed by software. Restrictions are indicated below:

a. 000B (Fixed Mode) — Deliver the signal to all the agents listed in the destination. The Trigger Mode for fixed delivery mode can be edge or level.

b. 001B (Lowest Priority) — Deliver the signal to the agent that is executing at the lowest priority of all agents listed in the destination field. The trigger mode can be edge or level.

c. 010B (System Management Interrupt or SMI) — The delivery mode is edge only. For systems that rely on SMI semantics, the vector field is ignored but must be programmed to all zeroes for future compatibility.

d. 100B (NMI) — Deliver the signal to all the agents listed in the destination field. The vector information is ignored. NMI is an edge triggered interrupt regardless of the Trigger Mode Setting.

e. 101B (INIT) — Deliver this signal to all the agents listed in the destination field. The vector information is ignored. INIT is an edge triggered interrupt regardless of the Trigger Mode Setting.

f. 111B (ExtINT) — Deliver the signal to the INTR signal of all agents in the destination field (as an interrupt that originated from an 8259A compatible interrupt controller). The vector is supplied by the INTA cycle issued by the activation of the ExtINT. ExtINT is an edge triggered interrupt.

3. Level — Edge triggered interrupt messages are always interpreted as assert messages. For edge triggered interrupts this field is not used. For level triggered interrupts, this bit reflects the state of the interrupt input.
4. Trigger Mode — This field indicates the signal type that will trigger a message.

a. 0 — Indicates edge sensitive.

b. 1 — Indicates level sensitive.

Page 515 of the Intel 253668-032US user manual — 11.1 INTERNAL CACHES, TLBS, AND BUFFERS
Page 515 · click to enlarge
Page 515

CHAPTER 11 MEMORY CACHE CONTROL

This chapter describes the memory cache and cache control mechanisms, the TLBs, and the store buffer in Intel 64 and IA-32 processors. It also describes the memory type range registers (MTRRs) introduced in the P6 family processors and how they are used to control caching of physical memory locations.

11.1 INTERNAL CACHES, TLBS, AND BUFFERS

The Intel 64 and IA-32 architectures support cache, translation look aside buffers (TLBs), and a store buffer for temporary on-chip (and external) storage of instruc tions and data. (Figure 11-1 shows the arrangement of caches, TLBs, and the store buffer for the Pentium 4 and Intel Xeon processors.) Table 11-1 shows the character istics of these caches and buffers for the Pentium 4, Intel Xeon, P6 family, and Pentium processors. The sizes and characteristics of these units are machine specific and may change in future versions of the processor. The CPUID instruction returns the sizes and characteristics of the caches and buffers for the processor on which the instruction is executed. See “CPUID—CPU Identification” in Chapter 3, “Instruction Set Reference, A-M,” of the Intel® 64 and IA-32 Architec tures Software Developer’s Manual, Volume 2A.

Intel 253668-032US — 11.1 INTERNAL CACHES, TLBS, AND BUFFERS diagram (page 515)
Fig. 29

Figure 11-1. Cache Structure of the Pentium 4 and Intel Xeon Processors

Page 516 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 516 · click to enlarge
Page 516

MEMORY CACHE CONTROL

Intel 253668-032US — MEMORY CACHE CONTROL diagram (page 516)
Fig. 30

Figure 11-2. Cache Structure of the Intel Core i7 Processors

Figure 11-2 shows the cache arrangement of Intel Core i7 processor.

Table 11-1. Characteristics of the Caches, TLBs, Store Buffer, and

Write Combining Buffer in Intel 64 and IA-32 Processors

Cache or Buffer Characteristics

  • Trace Cache 1
  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): 12 K μ ops, 8-way set associative.
  • Intel Core i7, Intel Core 2 Duo, Intel Atom, Intel Core Duo, Intel Core Solo, Pentium M processor: not implemented.
  • P6 family and Pentium processors: not implemented.
  • L1 Instruction Cache
  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): not implemented.
  • Intel Core i7 processor: 32-KByte, 4-way set associative.
  • Intel Core 2 Duo, Intel Atom, Intel Core Duo, Intel Core Solo, Pentium M processor: 32-KByte, 8-way set associative.
  • P6 family and Pentium processors: 8or 16-KByte, 4-way set associative, 32-byte cache line size; 2-way set associative for earlier Pentium processors.
Page 517 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 517 · click to enlarge
Page 517

MEMORY CACHE CONTROL

Table 11-1. Characteristics of the Caches, TLBs, Store Buffer, and

Write Combining Buffer in Intel 64 and IA-32 Processors (Contd.)

Cache or Buffer Characteristics

  • L1 Data Cache
  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): 8-KByte, 4-way set associative, 64-byte cache line size.
  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): 16-KByte, 8-way set associative, 64-byte cache line size.
  • Intel Atom processors: 24-KByte, 6-way set associative, 64-byte cache line size.
  • Intel Core i7, Intel Core 2 Duo, Intel Core Duo, Intel Core Solo, Pentium M and Intel Xeon processors: 32-KByte, 8-way set associative, 64-byte cache line size.
  • P6 family processors: 16-KByte, 4-way set associative, 32-byte cache line size; 8-KBytes, 2-way set associative for earlier P6 family processors.
  • Pentium processors: 16-KByte, 4-way set associative, 32-byte cache line size; 8-KByte, 2-way set associative for earlier Pentium processors.
  • L2 Unified Cache
  • Intel Core 2 Duo and Intel Xeon processors: up to 4-MByte (or 4MBx2 in quadcore processors), 16-way set associative, 64-byte cache line size.
  • Intel Core 2 Duo and Intel Xeon processors: up to 6-MByte (or 6MBx2 in quadcore processors), 24-way set associative, 64-byte cache line size.
  • Intel Core i7 processor: 256KBbyte, 8-way set associative, 64-byte cache line size.
  • Intel Atom processors: 512-KByte, 8-way set associative, 64-byte cache line size.
  • Intel Core Duo, Intel Core Solo processors: 2-MByte, 8-way set associative, 64-byte cache line size
  • Pentium 4 and Intel Xeon processors: 256, 512, 1024, or 2048-KByte, 8way set associative, 64-byte cache line size, 128-byte sector size.
  • Pentium M processor: 1 or 2-MByte, 8-way set associative, 64-byte cache line size.
  • P6 family processors: 128-KByte, 256-KByte, 512-KByte, 1-MByte, or 2MByte, 4-way set associative, 32-byte cache line size.
  • Pentium processor (external optional): System specific, typically 256or 512-KByte, 4-way set associative, 32-byte cache line size.
  • L3 Unified Cache
  • Intel Xeon processors: 512-KByte, 1-MByte, 2-MByte, or 4-MByte, 8-way set associative, 64-byte cache line size, 128-byte sector size.
  • Intel Core i7 processor: Up to 8MByte, 16-way set associative, 64-byte cache line size.
Page 518 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 518 · click to enlarge
Page 518

MEMORY CACHE CONTROL

Table 11-1. Characteristics of the Caches, TLBs, Store Buffer, and

Write Combining Buffer in Intel 64 and IA-32 Processors (Contd.)

Cache or Buffer Characteristics

Instruction TLB (4-KByte Pages)

  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): 128 entries, 4-way set associative.
  • Intel Atom processors: 32-entries, fully associative.
  • Intel Core i7 processor: 64-entries per thread (128-entries per core), 4way set associative.
  • Intel Core 2 Duo, Intel Core Duo, Intel Core Solo processors, Pentium M processor: 128 entries, 4-way set associative.
  • P6 family processors: 32 entries, 4-way set associative.
  • Pentium processor: 32 entries, 4-way set associative; fully set associative for Pentium processors with MMX technology.

Data TLB (4-KByte Pages)

  • Intel Core i7 processor, DTLB0: 64-entries, 4-way set associative.
  • Intel Core 2 Duo processors: DTLB0, 16 entries, DTLB1, 256 entries, 4 ways.
  • Intel Atom processors: 16-entry-per-thread micro-TLB, fully associative; 64-entry DTLB, 4-way set associative; 16-entry PDE cache, fully associative.
  • Pentium 4 and Intel Xeon processors (Based on Intel NetBurst microarchitecture): 64 entry, fully set associative, shared with large page DTLB.
  • Intel Core Duo, Intel Core Solo processors, Pentium M processor: 128 entries, 4-way set associative.
  • Pentium and P6 family processors: 64 entries, 4-way set associative; fully set, associative for Pentium processors with MMX technology.

Instruction TLB (Large Pages)

  • Intel Core i7 processor: 7-entries per thread, fully associative.
  • Intel Core 2 Duo processors: 4 entries, 4 ways.
  • Pentium 4 and Intel Xeon processors: large pages are fragmented.
  • Intel Core Duo, Intel Core Solo, Pentium M processor: 2 entries, fully associative.
  • P6 family processors: 2 entries, fully associative.
  • Pentium processor: Uses same TLB as used for 4-KByte pages.

Data TLB (Large Pages)

  • Intel Core i7 processor, DTLB0: 32-entries, 4-way set associative.
  • Intel Core 2 Duo processors: DTLB0, 16 entries, DTLB1, 32 entries, 4 ways.
  • Intel Atom processors: 8 entries, 4-way set associative.
  • Pentium 4 and Intel Xeon processors: 64 entries, fully set associative; shared with small page data TLBs.
  • Intel Core Duo, Intel Core Solo, Pentium M processor: 8 entries, fully associative.
  • P6 family processors: 8 entries, 4-way set associative.
  • Pentium processor: 8 entries, 4-way set associative; uses same TLB as used for 4-KByte pages in Pentium processors with MMX technology.

Second-level Unified TLB (4-KByte Pages)

  • Intel Core i7 processor, STLB: 512-entries, 4-way set associative.
Page 519 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 519 · click to enlarge
Page 519

MEMORY CACHE CONTROL

Table 11-1. Characteristics of the Caches, TLBs, Store Buffer, and

Write Combining Buffer in Intel 64 and IA-32 Processors (Contd.)

Cache or Buffer Characteristics

  • Store Buffer
  • Intel Core i7 processors: 32entries.
  • Intel Core 2 Duo processors: 20 entries.
  • Intel Atom processors: 8 entries, used for both WC and store buffers.
  • Pentium 4 and Intel Xeon processors: 24 entries.
  • Pentium M processor: 16 entries.
  • P6 family processors: 12 entries.
  • Pentium processor: 2 buffers, 1 entry each (Pentium processors with MMX technology have 4 buffers for 4 entries).

Write Combining (WC) Buffer

  • Intel Core 2 Duo processors: 8 entries.
  • Intel Atom processors: 8 entries, used for both WC and store buffers.
  • Pentium 4 and Intel Xeon processors: 6 or 8 entries.
  • Intel Core Duo, Intel Core Solo, Pentium M processors: 6 entries.
  • P6 family processors: 4 entries.
  • Intel 64 and IA-32 processors may implement four types of caches: the trace cache, the level 1 (L1) cache, the level 2 (L2) cache, and the level 3 (L3) cache. See Figure 11-1. Cache availability is described below:
  • Intel Core i7 processor Family — The L1 cache is divided into two sections: one section is dedicated to caching instructions (pre-decoded instructions) and the other caches data. The L2 cache is a unified data and instruction cache. Each processor core has its own L1 and L2. The L3 cache is an inclusive, unified data and instruction cache, shared by all processor cores inside a physical package. No trace cache is implemented.
  • Intel Core 2 processor and Intel Xeon processor Family based on Intel Core microarchitecture — The L1 cache is divided into two sections: one section is dedicated to caching instructions (pre-decoded instructions) and the other caches data. The L2 cache is a unified data and instruction cache located on the processor chip; it is shared between two processor cores in a dual-core processor implementation. Quad-core processors have two L2, each shared by two processor cores. No trace cache is implemented.
  • Intel Atom processor — The L1 cache is divided into two sections: one section is dedicated to caching instructions (pre-decoded instructions) and the other caches data. The L2 cache is a unified data and instruction cache is located on the processor chip. No trace cache is implemented.
  • Intel Core Solo and Intel Core Duo processors — The L1 cache is divided into two sections: one section is dedicated to caching instructions (pre-decoded instructions) and the other caches data. The L2 cache is a unified data and instruction cache located on the processor chip. It is shared between two processor cores in a dual-core processor implementation. No trace cache is implemented.
Page 520 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 520 · click to enlarge
Page 520

MEMORY CACHE CONTROL

  • Pentium 4 and Intel Xeon processors Based on Intel NetBurst microar chitecture — The trace cache caches decoded instructions ( μ ops) from the instruction decoder and the L1 cache contains data. The L2 and L3 caches are unified data and instruction caches located on the processor chip. Dualcore processors have two L2, one in each processor core. Note that the L3 cache is only implemented on some Intel Xeon processors.
  • P6 family processors — The L1 cache is divided into two sections: one dedicated to caching instructions (pre-decoded instructions) and the other to caching data. The L2 cache is a unified data and instruction cache located on the processor chip. P6 family processors do not implement a trace cache.
  • Pentium processors — The L1 cache has the same structure as on P6 family processors. There is no trace cache. The L2 cache is a unified data and instruction cache external to the processor chip on earlier Pentium processors and implemented on the processor chip in later Pentium processors. For Pentium processors where the L2 cache is external to the processor, access to the cache is through the system bus.

For Intel Core i7 processors and processors based on Intel Core, Intel Atom, and Intel NetBurst microarchitectures, Intel Core Duo, Intel Core Solo and Pentium M proces sors, the cache lines for the L1 and L2 caches (and L3 caches if supported) are 64 bytes wide. The processor always reads a cache line from system memory beginning on a 64-byte boundary. (A 64-byte aligned cache line begins at an address with its 6 least-significant bits clear.) A cache line can be filled from memory with a 8-transfer burst transaction. The caches do not support partially-filled cache lines, so caching even a single doubleword requires caching an entire line.

The L1 and L2 cache lines in the P6 family and Pentium processors are 32 bytes wide, with cache line reads from system memory beginning on a 32-byte boundary (5 least-significant bits of a memory address clear.) A cache line can be filled from memory with a 4-transfer burst transaction. Partially-filled cache lines are not supported.

The trace cache in processors based on Intel NetBurst microarchitecture is available in all execution modes: protected mode, system management mode (SMM), and real-address mode. The L1,L2, and L3 caches are also available in all execution modes; however, use of them must be handled carefully in SMM (see Section 26.4.2, “SMRAM Caching”).

The TLBs store the most recently used page-directory and page-table entries. They speed up memory accesses when paging is enabled by reducing the number of memory accesses that are required to read the page tables stored in system memory. The TLBs are divided into four groups: instruction TLBs for 4-KByte pages, data TLBs for 4-KByte pages; instruction TLBs for large pages (2-MByte or 4-MByte pages), and data TLBs for large pages. The TLBs are normally active only in protected mode with paging enabled. When paging is disabled or the processor is in real- address mode, the TLBs maintain their contents until explicitly or implicitly flushed (see Section 11.9, “Invalidating the Translation Lookaside Buffers (TLBs)”).

Page 521 of the Intel 253668-032US user manual — 11.2 CACHING TERMINOLOGY
Page 521 · click to enlarge
Page 521

MEMORY CACHE CONTROL

Processors based on Intel Core microarchitectures implement one level of instruction TLB and two levels of data TLB. Intel Core i7 processor provides a second-level unified TLB.

The store buffer is associated with the processors instruction execution units. It allows writes to system memory and/or the internal caches to be saved and in some cases combined to optimize the processor’s bus accesses. The store buffer is always enabled in all execution modes.

The processor’s caches are for the most part transparent to software. When enabled, instructions and data flow through these caches without the need for explicit soft ware control. However, knowledge of the behavior of these caches may be useful in optimizing software performance. For example, knowledge of cache dimensions and replacement algorithms gives an indication of how large of a data structure can be operated on at once without causing cache thrashing.

In multiprocessor systems, maintenance of cache consistency may, in rare circum stances, require intervention by system software. For these rare cases, the processor provides privileged cache control instructions for use in flushing caches and forcing memory ordering.

The Pentium III, Pentium 4, and Intel Xeon processors introduced several instructions that software can use to improve the performance of the L1, L2, and L3 caches, including the PREFETCHh and CLFLUSH instructions and the non-temporal move instructions (MOVNTI, MOVNTQ, MOVNTDQ, MOVNTPS, and MOVNTPD). The use of these instructions are discussed in Section 11.5.5, “Cache Management Instruc tions.”

11.2 CACHING TERMINOLOGY

IA-32 processors (beginning with the Pentium processor) and Intel 64 processors use the MESI (modified, exclusive, shared, invalid) cache protocol to maintain consis tency with internal caches and caches in other processors (see Section 11.4, “Cache Control Protocol”).

When the processor recognizes that an operand being read from memory is cache able, the processor reads an entire cache line into the appropriate cache (L1, L2, L3, or all). This operation is called a cache line fill. If the memory location containing that operand is still cached the next time the processor attempts to access the operand, the processor can read the operand from the cache instead of going back to memory. This operation is called a cache hit.

When the processor attempts to write an operand to a cacheable area of memory, it first checks if a cache line for that memory location exists in the cache. If a valid cache line does exist, the processor (depending on the write policy currently in force) can write the operand into the cache instead of writing it out to system memory. This operation is called a write hit. If a write misses the cache (that is, a valid cache line is not present for area of memory being written to), the processor performs a cache line fill, write allocation. Then it writes the operand into the cache line and

Page 522 of the Intel 253668-032US user manual — NOTE
Page 522 · click to enlarge
Page 522

MEMORY CACHE CONTROL

(depending on the write policy currently in force) can also write it out to memory. If the operand is to be written out to memory, it is written first into the store buffer, and then written from the store buffer to memory when the system bus is available. (Note that for the Pentium processor, write misses do not result in a cache line fill; they always result in a write to memory. For this processor, only read misses result in cache line fills.)

When operating in an MP system, IA-32 processors (beginning with the Intel486 processor) and Intel 64 processors have the ability to snoop other processor’s accesses to system memory and to their internal caches. They use this snooping ability to keep their internal caches consistent both with system memory and with the caches in other processors on the bus. For example, in the Pentium and P6 family processors, if through snooping one processor detects that another processor intends to write to a memory location that it currently has cached in shared state, the snooping processor will invalidate its cache line forcing it to perform a cache line fill the next time it accesses the same memory location.

Beginning with the P6 family processors, if a processor detects (through snooping) that another processor is trying to access a memory location that it has modified in its cache, but has not yet written back to system memory, the snooping processor will signal the other processor (by means of the HITM# signal) that the cache line is held in modified state and will preform an implicit write-back of the modified data. The implicit write-back is transferred directly to the initial requesting processor and snooped by the memory controller to assure that system memory has been updated. Here, the processor with the valid data may pass the data to the other processors without actually writing it to system memory; however, it is the responsibility of the memory controller to snoop this operation and update memory.

11.3 METHODS OF CACHING AVAILABLE

The processor allows any area of system memory to be cached in the L1, L2, and L3 caches. In individual pages or regions of system memory, it allows the type of caching (also called memory type) to be specified (see Section 11.5). Memory types currently defined for the Intel 64 and IA-32 architectures are (see Table 11-2): • Strong Uncacheable (UC) —System memory locations are not cached. All reads and writes appear on the system bus and are executed in program order without reordering. No speculative memory accesses, page-table walks, or prefetches of speculated branch targets are made. This type of cache-control is useful for memory-mapped I/O devices. When used with normal RAM, it greatly reduces processor performance.

NOTE

The behavior of FP and SSE/SSE2 operations on operands in UC memory is implementation dependent. In some implementations, accesses to UC memory may occur more than once. To ensure predictable behavior, use loads and stores of general purpose

Page 523 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 523 · click to enlarge
Page 523

MEMORY CACHE CONTROL

registers to access UC memory that may have read or write side effects.

Table 11-2. Memory Types and Their Properties

Memory Type and Mnemonic

No No No Strong Ordering

Uncacheable (UC-) No No No Strong Ordering. Can only be selected through the PAT. Can be overridden by WC in MTRRs.

Write Combining (WC) No No Yes Weak Ordering. Available by programming MTRRs or by selecting it through the PAT.

Write Through (WT) Yes No Yes Speculative Processor Ordering.

Write Back (WB) Yes Yes Yes Speculative Processor Ordering.

Write Protected (WP) Yes for reads; no for writes

No Yes Speculative Processor Ordering. Available by programming MTRRs.

  • Uncacheable (UC-) — Has same characteristics as the strong uncacheable (UC) memory type, except that this memory type can be overridden by programming the MTRRs for the WC memory type. This memory type is available in processor families starting from the Pentium III processors and can only be selected through the PAT.
  • Write Combining (WC) — System memory locations are not cached (as with uncacheable memory) and coherency is not enforced by the processor’s bus coherency protocol. Speculative reads are allowed. Writes may be delayed and combined in the write combining buffer (WC buffer) to reduce memory accesses. If the WC buffer is partially filled, the writes may be delayed until the next occurrence of a serializing event; such as, an SFENCE or MFENCE instruction, CPUID execution, a read or write to uncached memory, an interrupt occurrence, or a LOCK instruction execution. This type of cache-control is appropriate for video frame buffers, where the order of writes is unimportant as long as the writes update memory so they can be seen on the graphics display. See Section 11.3.1, “Buffering of Write Combining Memory Locations,” for more information about caching the WC memory type. This memory type is available in the Pentium Pro and Pentium II processors by programming the MTRRs; or in processor families starting from the Pentium III processors by programming the MTRRs or by selecting it through the PAT.
  • Write-through (WT) — Writes and reads to and from system memory are cached. Reads come from cache lines on cache hits; read misses cause cache fills. Speculative reads are allowed. All writes are written to a cache line (when
Show 4 more labels / short text on this page
Cacheable Writeback Cacheable · Allows Speculative Reads · Memory Ordering Model · Strong Uncacheable (UC)
Page 524 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 524 · click to enlarge
Page 524

MEMORY CACHE CONTROL

  • possible) and through to system memory. When writing through to memory, invalid cache lines are never filled, and valid cache lines are either filled or inval idated. Write combining is allowed. This type of cache-control is appropriate for frame buffers or when there are devices on the system bus that access system memory, but do not perform snooping of memory accesses. It enforces coherency between caches in the processors and system memory.
  • Write-back (WB) — Writes and reads to and from system memory are cached. Reads come from cache lines on cache hits; read misses cause cache fills. Speculative reads are allowed. Write misses cause cache line fills (in processor families starting with the P6 family processors), and writes are performed entirely in the cache, when possible. Write combining is allowed. The write-back memory type reduces bus traffic by eliminating many unnecessary writes to system memory. Writes to a cache line are not immediately forwarded to system memory; instead, they are accumulated in the cache. The modified cache lines are written to system memory later, when a write-back operation is performed. Write-back operations are triggered when cache lines need to be deallocated, such as when new cache lines are being allocated in a cache that is already full. They also are triggered by the mechanisms used to maintain cache consistency. This type of cache-control provides the best performance, but it requires that all devices that access system memory on the system bus be able to snoop memory accesses to insure system memory and cache coherency.
  • Write protected (WP) — Reads come from cache lines when possible, and read misses cause cache fills. Writes are propagated to the system bus and cause corresponding cache lines on all processors on the bus to be invalidated. Speculative reads are allowed. This memory type is available in processor families starting from the P6 family processors by programming the MTRRs (see Table 11-6).

Table 11-3 shows which of these caching methods are available in the Pentium, P6 Family, Pentium 4, and Intel Xeon processors.

Table 11-3. Methods of Caching Available in Intel Core 2 Duo, Intel Atom, Intel Core

Duo, Pentium M, Pentium 4, Intel Xeon, P6 Family, and Pentium Processors

Memory Type Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4 and Intel Xeon Processors

Strong Uncacheable (UC) Yes Yes Yes

Uncacheable (UC-) Yes Yes* No

Write Combining (WC) Yes Yes No

Write Through (WT) Yes Yes Yes

Write Back (WB) Yes Yes Yes

Write Protected (WP) Yes Yes No

P6 Family Processors · Pentium Processor

Page 525 of the Intel 253668-032US user manual — 11.3.1 Buffering of Write Combining Memory Locations
Page 525 · click to enlarge
Page 525

MEMORY CACHE CONTROL

Table 11-3. Methods of Caching Available in Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4, Intel Xeon, P6 Family, and Pentium Processors (Contd.)

Memory Type Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4 and Intel Xeon Processors

11.3.1 Buffering of Write Combining Memory Locations

Writes to the WC memory type are not cached in the typical sense of the word cached. They are retained in an internal write combining buffer (WC buffer) that is separate from the internal L1, L2, and L3 caches and the store buffer. The WC buffer is not snooped and thus does not provide data coherency. Buffering of writes to WC memory is done to allow software a small window of time to supply more modified data to the WC buffer while remaining as non-intrusive to software as possible. The buffering of writes to WC memory also causes data to be collapsed; that is, multiple writes to the same memory location will leave the last data written in the location and the other writes will be lost.

The size and structure of the WC buffer is not architecturally defined. For the Intel Core 2 Duo, Intel Atom, Intel Core Duo, Pentium M, Pentium 4 and Intel Xeon proces sors; the WC buffer is made up of several 64-byte WC buffers. For the P6 family processors, the WC buffer is made up of several 32-byte WC buffers.

When software begins writing to WC memory, the processor begins filling the WC buffers one at a time. When one or more WC buffers has been filled, the processor has the option of evicting the buffers to system memory. The protocol for evicting the WC buffers is implementation dependent and should not be relied on by software for system memory coherency. When using the WC memory type, software must be sensitive to the fact that the writing of data to system memory is being delayed and must deliberately empty the WC buffers when system memory coherency is required.

Once the processor has started to evict data from the WC buffer into system memory, it will make a bus-transaction style decision based on how much of the buffer contains valid data. If the buffer is full (for example, all bytes are valid), the processor will execute a burst-write transaction on the bus. This results in all 32 bytes (P6 family processors) or 64 bytes (Pentium 4 and more recent processor) being transmitted on the data bus in a single burst transaction. If one or more of the WC buffer’s bytes are invalid (for example, have not been written by software), the processor will transmit the data to memory using “partial write” transactions (one chunk at a time, where a “chunk” is 8 bytes).

This will result in a maximum of 4 partial write transactions (for P6 family processors) or 8 partial write transactions (for the Pentium 4 and more recent processors) for one WC buffer of data sent to memory.

P6 Family Processors · Pentium Processor

Page 526 of the Intel 253668-032US user manual — 11.3.2 Choosing a Memory Type
Page 526 · click to enlarge
Page 526

MEMORY CACHE CONTROL

The WC memory type is weakly ordered by definition. Once the eviction of a WC buffer has started, the data is subject to the weak ordering semantics of its defini tion. Ordering is not maintained between the successive allocation/deallocation of WC buffers (for example, writes to WC buffer 1 followed by writes to WC buffer 2 may appear as buffer 2 followed by buffer 1 on the system bus). When a WC buffer is evicted to memory as partial writes there is no guaranteed ordering between succes sive partial writes (for example, a partial write for chunk 2 may appear on the bus before the partial write for chunk 1 or vice versa).

The only elements of WC propagation to the system bus that are guaranteed are those provided by transaction atomicity. For example, with a P6 family processor, a completely full WC buffer will always be propagated as a single 32-bit burst transac tion using any chunk order. In a WC buffer eviction where data will be evicted as partials, all data contained in the same chunk (0 mod 8 aligned) will be propagated simultaneously. Likewise, for more recent processors starting with those based on Intel NetBurst microarchitectures, a full WC buffer will always be propagated as a single burst transactions, using any chunk order within a transaction. For partial buffer propagations, all data contained in the same chunk will be propagated simul taneously.

11.3.2 Choosing a Memory Type

The simplest system memory model does not use memory-mapped I/O with read or write side effects, does not include a frame buffer, and uses the write-back memory type for all memory. An I/O agent can perform direct memory access (DMA) to write- back memory and the cache protocol maintains cache coherency.

A system can use strong uncacheable memory for other memory-mapped I/O, and should always use strong uncacheable memory for memory-mapped I/O with read side effects.

Dual-ported memory can be considered a write side effect, making relatively prompt writes desirable, because those writes cannot be observed at the other port until they reach the memory agent. A system can use strong uncacheable, uncacheable, write- through, or write-combining memory for frame buffers or dual-ported memory that contains pixel values displayed on a screen. Frame buffer memory is typically large (a few megabytes) and is usually written more than it is read by the processor. Using strong uncacheable memory for a frame buffer generates very large amounts of bus traffic, because operations on the entire buffer are implemented using partial writes rather than line writes. Using write-through memory for a frame buffer can displace almost all other useful cached lines in the processor's L2 and L3 caches and L1 data cache. Therefore, systems should use write-combining memory for frame buffers whenever possible.

Software can use page-level cache control, to assign appropriate effective memory types when software will not access data structures in ways that benefit from write- back caching. For example, software may read a large data structure once and not access the structure again until the structure is rewritten by another agent. Such a

Page 527 of the Intel 253668-032US user manual — 11.4 CACHE CONTROL PROTOCOL
Page 527 · click to enlarge
Page 527

MEMORY CACHE CONTROL

large data structure should be marked as uncacheable, or reading it will evict cached lines that the processor will be referencing again.

A similar example would be a write-only data structure that is written to (to export the data to another agent), but never read by software. Such a structure can be marked as uncacheable, because software never reads the values that it writes (though as uncacheable memory, it will be written using partial writes, while as write-back memory, it will be written using line writes, which may not occur until the other agent reads the structure and triggers implicit write-backs).

On the Pentium III, Pentium 4, and more recent processors, new instructions are provided that give software greater control over the caching, prefetching, and the write-back characteristics of data. These instructions allow software to use weakly ordered or processor ordered memory types to improve processor performance, but when necessary to force strong ordering on memory reads and/or writes. They also allow software greater control over the caching of data. For a description of these instructions and there intended use, see Section 11.5.5, “Cache Management Instructions.”

11.3.3 Code Fetches in Uncacheable Memory

Programs may execute code from uncacheable (UC) memory, but the implications are different from accessing data in UC memory. When doing code fetches, the processor never transitions from cacheable code to UC code speculatively. It also never speculatively fetches branch targets that result in UC code.

The processor may fetch the same UC cache line multiple times in order to decode an instruction once. It may decode consecutive UC instructions in a cacheline without fetching between each instruction. It may also fetch additional cachelines from the same or a consecutive 4-KByte page in order to decode one non-speculative UC instruction (this can be true even when the instruction is contained fully in one line).

Because of the above and because cacheline sizes may change in future processors, software should avoid placing memory-mapped I/O with read side effects in the same page or in a subsequent page used to execute UC code.

11.4 CACHE CONTROL PROTOCOL

The following section describes the cache control protocol currently defined for the Intel 64 and IA-32 architectures.

In the L1 data cache and in the L2/L3 unified caches, the MESI (modified, exclusive, shared, invalid) cache protocol maintains consistency with caches of other proces sors. The L1 data cache and the L2/L3 unified caches have two MESI status flags per cache line. Each line can be marked as being in one of the states defined in Table 11-4. In general, the operation of the MESI protocol is transparent to programs.

Page 528 of the Intel 253668-032US user manual — 11.5 CACHE CONTROL
Page 528 · click to enlarge
Page 528

MEMORY CACHE CONTROL

Table 11-4. MESI Cache Line States

Cache Line State M (Modified) E (Exclusive) S (Shared) I (Invalid)

This cache line is valid? Yes Yes Yes No

The memory copy is… Out of date Valid Valid —

Copies exist in caches of other processors?

No No Maybe Maybe

A write to this line … Does not go to the system bus.

Does not go to the system bus.

Causes the processor to gain exclusive ownership of the line.

Goes directly to the system bus.

The L1 instruction cache in P6 family processors implements only the “SI” part of the MESI protocol, because the instruction cache is not writable. The instruction cache monitors changes in the data cache to maintain consistency between the caches when instructions are modified. See Section 11.6, “Self-Modifying Code,” for more information on the implications of caching instructions.

11.5 CACHE CONTROL

  • The Intel 64 and IA-32 architectures provide a variety of mechanisms for controlling the caching of data and instructions and for controlling the ordering of reads and writes between the processor, the caches, and memory. These mechanisms can be divided into two groups:
  • Cache control registers and bits — The Intel 64 and IA-32 architectures define several dedicated registers and various bits within control registers and pageand directory-table entries that control the caching system memory locations in the L1, L2, and L3 caches. These mechanisms control the caching of virtual memory pages and of regions of physical memory.
  • Cache control and memory ordering instructions — The Intel 64 and IA-32 architectures provide several instructions that control the caching of data, the ordering of memory reads and writes, and the prefetching of data. These instruc tions allow software to control the caching of specific data structures, to control memory coherency for specific locations in memory, and to force strong memory ordering at specific locations in a program.

The following sections describe these two groups of cache control mechanisms.

Page 529 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 529 · click to enlarge
Page 529

MEMORY CACHE CONTROL

11.5.1 Cache Control Registers and Bits

Figure 11-3 depicts cache-control mechanisms in IA-32 processors. Other than for the matter of memory address space, these work the same in Intel 64 processors.

The Intel 64 and IA-32 architectures provide the following cache-control registers and bits for use in enabling or restricting caching to various pages or regions in memory: • CD flag, bit 30 of control register CR0 — Controls caching of system memory locations (see Section 2.5, “Control Registers”). If the CD flag is clear, caching is enabled for the whole of system memory, but may be restricted for individual pages or regions of memory by other cache-control mechanisms. When the CD flag is set, caching is restricted in the processor’s caches (cache hierarchy) for the P6 and more recent processor families and prevented for the Pentium processor (see note below). With the CD flag set, however, the caches will still respond to snoop traffic. Caches should be explicitly flushed to insure memory coherency. For highest processor performance, both the CD and the NW flags in control register CR0 should be cleared. Table 11-5 shows the interaction of the CD and NW flags.

The effect of setting the CD flag is somewhat different for processor families starting with P6 family than the Pentium processor (see Table 11-5). To insure memory coherency after the CD flag is set, the caches should be explicitly flushed (see Section 11.5.3, “Preventing Caching”). Setting the CD flag for the P6 and more recent processor families modify cache line fill and update behaviour. Also, setting the CD flag on these processors do not force strict ordering of memory accesses unless the MTRRs are disabled and/or all memory is referenced as uncached (see Section 8.2.5, “Strengthening or Weakening the Memory-Ordering Model”).

Page 530 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 530 · click to enlarge
Page 530

MEMORY CACHE CONTROL

Intel 253668-032US — MEMORY CACHE CONTROL diagram (page 530)
Fig. 31

CD and NW Flags PCD and PWT flags control page-level caching

MTRRs control caching of selected regions of physical memory

1. G flag only available in P6 and later processor families
2. The maximum physical address size is reported by CPUID leaf function 80000008H. The maximum physical address size of

FFFFFFFFFH applies only If 36-bit physical addressing is used.

3. MTRRs available only in P6 and later processor families; similar control available in Pentium processor with the KEN# and WB/WT# pins.
4. PAT available only in Pentium III and later processor families.
5. L3 in processors based on Intel NetBurst microarchitecture can be disabled using IA32_MISC_ENABLES MSR.

Figure 11-3. Cache-Control Registers and Bits Available in Intel 64 and IA-32

Processors

Page 531 of the Intel 253668-032US user manual — NA NA
Page 531 · click to enlarge
Page 531

MEMORY CACHE CONTROL

Table 11-5. Cache Operating Modes

CD NW Caching and Read/Write Policy L1 L2/L31

0 0 Normal Cache Mode. Highest performance cache operation.

  • Read hits access the cache; read misses may cause replacement.
  • Write hits update the cache.
  • Only writes to shared lines and write misses update system memory.
  • Write misses cause cache line fills.
  • Write hits can change shared lines to modified under control of the MTRRs and with associated read invalidation cycle.
  • (Pentium processor only.) Write misses do not cause cache line fills.
  • (Pentium processor only.) Write hits can change shared lines to exclusive under control of WB/WT#.
  • Invalidation is allowed.
  • External snoop traffic is supported.

0 1 Invalid setting.

NA NA

Generates a general-protection exception (#GP) with an error code of 0.

1 0 No-fill Cache Mode. Memory coherency is maintained.3

  • (Pentium 4 and later processor families.) State of processor after a power up or reset.
  • Read hits access the cache; read misses do not cause replacement (see Pentium 4 and Intel Xeon processors reference below).
  • Write hits update the cache.
  • Only writes to shared lines and write misses update system memory.
  • Write misses access memory.
  • Write hits can change shared lines to exclusive under control of the MTRRs and with associated read invalidation cycle.
  • (Pentium processor only.) Write hits can change shared lines to exclusive under control of the WB/WT#.
  • 1 0
  • (P6 and later processor families only.) Strict memory ordering is not enforced unless the MTRRs are disabled and/or all memory is referenced as uncached (see Section 7.2.4., “Strengthening or Weakening the Memory Ordering Model”).
  • Invalidation is allowed.
  • External snoop traffic is supported.
Show 21 more labels / short text on this page
Yes Yes Yes · Yes Yes Yes · Yes Yes · Yes · Yes · Yes · Yes Yes · Yes Yes · Yes · Yes · Yes · Yes · Yes Yes · Yes Yes · Yes Yes · Yes Yes · Yes · Yes · Yes · Yes Yes · Yes Yes
Page 532 of the Intel 253668-032US user manual — NOTES
Page 532 · click to enlarge
Page 532

MEMORY CACHE CONTROL

Table 11-5. Cache Operating Modes

CD NW Caching and Read/Write Policy L1 L2/L31

1 1 Memory coherency is not maintained.2, 3

  • (P6 family and Pentium processors.) State of the processor after a power up or reset.
  • Read hits access the cache; read misses do not cause replacement.
  • Write hits update the cache and change exclusive lines to modified.
  • Shared lines remain shared after write hit.
  • Write misses access memory.
  • Invalidation is inhibited when snooping; but is allowed with INVD and WBINVD instructions.
  • External snoop traffic is supported.

NOTES: 1. The L2/L3 column in this table is definitive for the Pentium 4, Intel Xeon, and P6 family proces sors. It is intended to represent what could be implemented in a system based on a Pentium pro cessor with an external, platform specific, write-back L2 cache. 2. The Pentium 4 and more recent processor families do not support this mode; setting the CD and NW bits to 1 selects the no-fill cache mode. 3. Not supported In Intel Atom processors. If CD = 1 in an Intel Atom processor, caching is disabled.

  • NW flag, bit 29 of control register CR0 — Controls the write policy for system memory locations (see Section 2.5, “Control Registers”). If the NW and CD flags are clear, write-back is enabled for the whole of system memory, but may be restricted for individual pages or regions of memory by other cache-control mechanisms. Table 11-5 shows how the other combinations of CD and NW flags affects caching.

NOTES

For the Pentium 4 and Intel Xeon processors, the NW flag is a don’t care flag; that is, when the CD flag is set, the processor uses the no- fill cache mode, regardless of the setting of the NW flag.

For Intel Atom processors, the NW flag is a don’t care flag; that is, when the CD flag is set, the processor disables caching, regardless of the setting of the NW flag.

For the Pentium processor, when the L1 cache is disabled (the CD and NW flags in control register CR0 are set), external snoops are accepted in DP (dual-processor) systems and inhibited in unipro cessor systems.

When snoops are inhibited, address parity is not checked and APCHK# is not asserted for a corrupt address; however, when snoops are accepted, address parity is checked and APCHK# is asserted for

Show 10 more labels / short text on this page
Yes · Yes · Yes · Yes · Yes · Yes · Yes Yes Yes · Yes Yes Yes · No · Yes
Page 533 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 533 · click to enlarge
Page 533

MEMORY CACHE CONTROL

corrupt addresses.

  • PCD flag in the page-directory and page-table entries — Controls caching for individual page tables and pages, respectively (see Section 4.9, “Paging and Memory Typing”). This flag only has effect when paging is enabled and the CD flag in control register CR0 is clear. The PCD flag enables caching of the page table or page when clear and prevents caching when set.
  • PWT flag in the page-directory and page-table entries — Controls the write policy for individual page tables and pages, respectively (see Section 4.9, “Paging and Memory Typing”). This flag only has effect when paging is enabled and the NW flag in control register CR0 is clear. The PWT flag enables write-back caching of the page table or page when clear and write-through caching when set.
  • PCD and PWT flags in control register CR3 — Control the global caching and write policy for the page directory (see Section 2.5, “Control Registers”). The PCD flag enables caching of the page directory when clear and prevents caching when set. The PWT flag enables write-back caching of the page directory when clear and write-through caching when set. These flags do not affect the caching and write policy for individual page tables. These flags only have effect when paging is enabled and the CD flag in control register CR0 is clear.
  • G (global) flag in the page-directory and page-table entries (introduced to the IA-32 architecture in the P6 family processors) — Controls the flushing of TLB entries for individual pages. See Section 4.10, “Caching Translation Information,” for more information about this flag.
  • PGE (page global enable) flag in control register CR4 — Enables the estab lishment of global pages with the G flag. See Section 4.10, “Caching Translation Information,” for more information about this flag.
  • Memory type range registers (MTRRs) (introduced in P6 family processors) — Control the type of caching used in specific regions of physical memory. Any of the caching types described in Section 11.3, “Methods of Caching Available,” can be selected. See Section 11.11, “Memory Type Range Registers (MTRRs),” for a detailed description of the MTRRs.
  • Page Attribute Table (PAT) MSR (introduced in the Pentium III processor) — Extends the memory typing capabilities of the processor to permit memory types to be assigned on a page-by-page basis (see Section 11.12, “Page Attribute Table (PAT)”).
  • Third-Level Cache Disable flag, bit 6 of the IA32_MISC_ENABLES MSR (Available only in processors based on Intel NetBurst microarchitecture) — Allows the L3 cache to be disabled and enabled, independently of the L1 and L2 caches.
  • KEN# and WB/WT# pins (Pentium processor) — Allow external hardware to control the caching method used for specific areas of memory. They perform similar (but not identical) functions to the MTRRs in the P6 family processors.
  • PCD and PWT pins (Pentium processor) — These pins (which are associated with the PCD and PWT flags in control register CR3 and in the page-directory and
Page 534 of the Intel 253668-032US user manual — 11.5.2 Precedence of Cache Controls
Page 534 · click to enlarge
Page 534

MEMORY CACHE CONTROL

page-table entries) permit caching in an external L2 cache to be controlled on a page-by-page basis, consistent with the control exercised on the L1 cache of these processors. The P6 and more recent processor families do not provide these pins because the L2 cache in internal to the chip package.

11.5.2 Precedence of Cache Controls

The cache control flags and MTRRs operate hierarchically for restricting caching. That is, if the CD flag is set, caching is prevented globally (see Table 11-5). If the CD flag is clear, the page-level cache control flags and/or the MTRRs can be used to restrict caching. If there is an overlap of page-level and MTRR caching controls, the mecha nism that prevents caching has precedence. For example, if an MTRR makes a region of system memory uncacheable, a page-level caching control cannot be used to enable caching for a page in that region. The converse is also true; that is, if a page- level caching control designates a page as uncacheable, an MTRR cannot be used to make the page cacheable.

In cases where there is a overlap in the assignment of the write-back and write- through caching policies to a page and a region of memory, the write-through policy takes precedence. The write-combining policy (which can only be assigned through an MTRR or the PAT) takes precedence over either write-through or write-back.

The selection of memory types at the page level varies depending on whether PAT is being used to select memory types for pages, as described in the following sections.

On processors based on Intel NetBurst microarchitecture, the third-level cache can be disabled by bit 6 of the IA32_MISC_ENABLE MSR. Using IA32_MISC_ENALBES[bit 6] takes precedence over the CD flag, MTRRs, and PAT for the L3 cache in those processors. That is, when the third-level cache disable flag is set (cache disabled), the other cache controls have no affect on the L3 cache; when the flag is clear (enabled), the cache controls have the same affect on the L3 cache as they have on the L1 and L2 caches.

IA32_MISC_ENALBES[bit 6] is not supported in Intel Core i7 processors, nor proces sors based on Intel Core, and Intel Atom microarchitectures.

11.5.2.1 Selecting Memory Types for Pentium Pro and Pentium II Processors

The Pentium Pro and Pentium II processors do not support the PAT. Here, the effec tive memory type for a page is selected with the MTRRs and the PCD and PWT bits in the page-table or page-directory entry for the page. Table 11-6 describes the mapping of MTRR memory types and page-level caching attributes to effective memory types, when normal caching is in effect (the CD and NW flags in control register CR0 are clear). Combinations that appear in gray are implementation- defined for the Pentium Pro and Pentium II processors. System designers are encour aged to avoid these implementation-defined combinations.

Page 535 of the Intel 253668-032US user manual — UC X X UC
Page 535 · click to enlarge
Page 535

MEMORY CACHE CONTROL

Table 11-6. Effective Page-Level Memory Type for Pentium Pro and

MTRR Memory Type1 PCD Value PWT Value Effective Memory Type

UC X X UC

WC 0 0 WC

0 1 WC

1 0 WC

1 1 UC

WT 0 X WT

1 X UC

WP 0 0 WP

0 1 WP

1 0 WC

1 1 UC

WB 0 0 WB

0 1 WT

1 X UC

NOTE:

1. These effective memory types also apply to the Pentium 4, Intel Xeon, and Pentium III proces sors when the PAT bit is not used (set to 0) in page-table and page-directory entries.

When normal caching is in effect, the effective memory type shown in Table 11-6 is determined using the following rules:

1. If the PCD and PWT attributes for the page are both 0, then the effective memory type is identical to the MTRR-defined memory type.
2. If the PCD flag is set, then the effective memory type is UC.
3. If the PCD flag is clear and the PWT flag is set, the effective memory type is WT for the WB memory type and the MTRR-defined memory type for all other memory types.
4. Setting the PCD and PWT flags to opposite values is considered model-specific for the WP and WC memory types and architecturally-defined for the WB, WT, and UC memory types.

Pentium II Processors

Page 536 of the Intel 253668-032US user manual — UC UC UC 1
Page 536 · click to enlarge
Page 536

MEMORY CACHE CONTROL

11.5.2.2 Selecting Memory Types for Pentium III and More Recent Processor Families

The Intel Core 2 Duo, Intel Atom, Intel Core Duo, Intel Core Solo, Pentium M, Pentium 4, Intel Xeon, and Pentium III processors use the PAT to select effective page-level memory types. Here, a memory type for a page is selected by the MTRRs and the value in a PAT entry that is selected with the PAT, PCD and PWT bits in a page-table or page-directory entry (see Section 11.12.3, “Selecting a Memory Type from the PAT”). Table 11-7 describes the mapping of MTRR memory types and PAT entry types to effective memory types, when normal caching is in effect (the CD and NW flags in control register CR0 are clear).

Table 11-7. Effective Page-Level Memory Types for Pentium III and More Recent

Processor Families MTRR Memory Type PAT Entry Value Effective Memory Type

UC UC UC 1

UCUC 1

WC WC

WT UC 1

WB UC 1

WP UC 1

WC UC UC 2

UCWC

WC WC

WT UC 2,3

WB WC

WP UC 2,3

WT UC UC 2

UCUC 2

WC WC

WT WT

WB WT

WP WP 3

Page 537 of the Intel 253668-032US user manual — WB UC UC 2
Page 537 · click to enlarge
Page 537

MEMORY CACHE CONTROL

Table 11-7. Effective Page-Level Memory Types for Pentium III and More Recent

Processor Families (Contd.) MTRR Memory Type PAT Entry Value Effective Memory Type

WB UC UC 2

UCUC 2

WC WC

WT WT

WB WB

WP WP

WP UC UC 2

UCWC 3

WC WC

WT WT 3

WB WP

WP WP

NOTES: 1. The UC attribute comes from the MTRRs and the processors are not required to snoop their caches since the data could never have been cached. This attribute is preferred for performance reasons. 2. The UC attribute came from the page-table or page-directory entry and processors are required to check their caches because the data may be cached due to page aliasing, which is not recom mended. 3. These combinations were specified as “undefined” in previous editions of the Intel® 64 and IA-32 Architectures Software Developer’s Manual. However, all processors that support both the PAT and the MTRRs determine the effective page-level memory types for these combinations as given.

11.5.2.3 Writing Values Across Pages with Different Memory Types

If two adjoining pages in memory have different memory types, and a word or longer operand is written to a memory location that crosses the page boundary between those two pages, the operand might be written to memory twice. This action does not present a problem for writes to actual memory; however, if a device is mapped the memory space assigned to the pages, the device might malfunction.

Page 538 of the Intel 253668-032US user manual — NOTES
Page 538 · click to enlarge
Page 538

MEMORY CACHE CONTROL

11.5.3 Preventing Caching

To disable the L1, L2, and L3 caches after they have been enabled and have received cache fills, perform the following steps:

1. Enter the no-fill cache mode. (Set the CD flag in control register CR0 to 1 and the NW flag to 0.
2. Flush all caches using the WBINVD instruction.
3. Disable the MTRRs and set the default memory type to uncached or set all MTRRs for the uncached memory type (see the discussion of the discussion of the TYPE field and the E flag in Section 11.11.2.1, “IA32_MTRR_DEF_TYPE MSR”).

The caches must be flushed (step 2) after the CD flag is set to insure system memory coherency. If the caches are not flushed, cache hits on reads will still occur and data will be read from valid cache lines.

The intent of the three separate steps listed above address three distinct require ments: (i) discontinue new data replacing existing data in the cache (ii) ensure data already in the cache are evicted to memory, (iii) ensure subsequent memory refer ences observe UC memory type semantics. Different processor implementation of caching control hardware may allow some variation of software implementation of these three requirements. See note below.

NOTES

Setting the CD flag in control register CR0 modifies the processor’s caching behaviour as indicated in Table 11-5, but setting the CD flag alone may not be sufficient across all processor families to force the effective memory type for all physical memory to be UC nor does it force strict memory ordering, due to hardware implementation variations across different processor families. To force the UC memory type and strict memory ordering on all of physical memory, it is sufficient to either program the MTRRs for all physical memory to be UC memory type or disable all MTRRs.

For the Pentium 4 and Intel Xeon processors, after the sequence of steps given above has been executed, the cache lines containing the code between the end of the WBINVD instruction and before the MTRRS have actually been disabled may be retained in the cache hierarchy. Here, to remove code from the cache completely, a second WBINVD instruction must be executed after the MTRRs have been disabled.

For Intel Atom processors, setting the CD flag forces all physical memory to observe UC semantics (without requiring memory type of physical memory to be set explicitly). Consequently, software does not need to issue a second WBINVD as some other processor generations might require.

Page 539 of the Intel 253668-032US user manual — 11.5.5 Cache Management Instructions
Page 539 · click to enlarge
Page 539

MEMORY CACHE CONTROL

11.5.4 Disabling and Enabling the L3 Cache

On processors based on Intel NetBurst microarchitecture, the third-level cache can be disabled by bit 6 of the IA32_MISC_ENABLE MSR. The third-level cache disable flag (bit 6 of the IA32_MISC_ENABLE MSR) allows the L3 cache to be disabled and enabled, independently of the L1 and L2 caches. Prior to using this control to disable or enable the L3 cache, software should disable and flush all the processor caches, as described earlier in Section 11.5.3, “Preventing Caching,” to prevent of loss of infor mation stored in the L3 cache. After the L3 cache has been disabled or enabled, caching for the whole processor can be restored.

Newer Intel 64 processor with L3 do not support IA32_MISC_ENABLES[bit 6], the procedure described in Section 11.5.3, “Preventing Caching,” apply to the entire cache hierarchy.

11.5.5 Cache Management Instructions

The Intel 64 and IA-32 architectures provide several instructions for managing the L1, L2, and L3 caches. The INVD, WBINVD, and WBINVD instructions are system instructions that operate on the L1, L2, and L3 caches as a whole. The PREFETCHh and CLFLUSH instructions and the non-temporal move instructions (MOVNTI, MOVNTQ, MOVNTDQ, MOVNTPS, and MOVNTPD), which were introduced in SSE/SSE2 extensions, offer more granular control over caching.

The INVD and WBINVD instructions are used to invalidate the contents of the L1, L2, and L3 caches. The INVD instruction invalidates all internal cache entries, then generates a special-function bus cycle that indicates that external caches also should be invalidated. The INVD instruction should be used with care. It does not force a write-back of modified cache lines; therefore, data stored in the caches and not written back to system memory will be lost. Unless there is a specific requirement or benefit to invalidating the caches without writing back the modified lines (such as, during testing or fault recovery where cache coherency with main memory is not a concern), software should use the WBINVD instruction.

The WBINVD instruction first writes back any modified lines in all the internal caches, then invalidates the contents of both the L1, L2, and L3 caches. It ensures that cache coherency with main memory is maintained regardless of the write policy in effect (that is, write-through or write-back). Following this operation, the WBINVD instruc tion generates one (P6 family processors) or two (Pentium and Intel486 processors) special-function bus cycles to indicate to external cache controllers that write-back of modified data followed by invalidation of external caches should occur. The amount of time or cycles for WBINVD to complete will vary due to the size of different cache hierarchies and other factors. As a consequence, the use of the WBINVD instruction can have an impact on interrupt/event response time.

The PREFETCHh instructions allow a program to suggest to the processor that a cache line from a specified location in system memory be prefetched into the cache hierarchy (see Section 11.8, “Explicit Caching”).

Page 540 of the Intel 253668-032US user manual — 11.5.6 L1 Data Cache Context Mode
Page 540 · click to enlarge
Page 540

MEMORY CACHE CONTROL

The CLFLUSH instruction allow selected cache lines to be flushed from memory. This instruction give a program the ability to explicitly free up cache space, when it is known that cached section of system memory will not be accessed in the near future.

The non-temporal move instructions (MOVNTI, MOVNTQ, MOVNTDQ, MOVNTPS, and MOVNTPD) allow data to be moved from the processor’s registers directly into system memory without being also written into the L1, L2, and/or L3 caches. These instructions can be used to prevent cache pollution when operating on data that is going to be modified only once before being stored back into system memory. These instructions operate on data in the general-purpose, MMX, and XMM registers.

11.5.6 L1 Data Cache Context Mode

L1 data cache context mode is a feature of processors based on the Intel NetBurst microarchitecture that support Intel Hyper-Threading Technology. When CPUID.1:ECX[bit 10] = 1, the processor supports setting L1 data cache context mode using the L1 data cache context mode flag ( IA32_MISC_ENABLE[bit 24] ). Selectable modes are adaptive mode (default) and shared mode.

The BIOS is responsible for configuring the L1 data cache context mode.

11.5.6.1 Adaptive Mode

  • Adaptive mode facilitates L1 data cache sharing between logical processors. When running in adaptive mode, the L1 data cache is shared across logical processors in the same core if:
  • CR3 control registers for logical processors sharing the cache are identical.
  • The same paging mode is used by logical processors sharing the cache.

In this situation, the entire L1 data cache is available to each logical processor (instead of being competitively shared).

If CR3 values are different for the logical processors sharing an L1 data cache or the logical processors use different paging modes, processors compete for cache resources. This reduces the effective size of the cache for each logical processor. Aliasing of the cache is not allowed (which prevents data thrashing).

11.5.6.2 Shared Mode

In shared mode, the L1 data cache is competitively shared between logical proces sors. This is true even if the logical processors use identical CR3 registers and paging modes.

In shared mode, linear addresses in the L1 data cache can be aliased, meaning that one linear address in the cache can point to different physical locations. The mecha nism for resolving aliasing can lead to thrashing. For this reason, IA32_MISC_ENABLE[bit 24] = 0 is the preferred configuration for processors based

Page 541 of the Intel 253668-032US user manual — 11.7 IMPLICIT CACHING (PENTIUM 4, INTEL XEON, AND P6 FAMILY PROCESSORS)
Page 541 · click to enlarge
Page 541

MEMORY CACHE CONTROL

on the Intel NetBurst microarchitecture that support Intel Hyper-Threading Tech nology.

11.6 SELF-MODIFYING CODE

A write to a memory location in a code segment that is currently cached in the processor causes the associated cache line (or lines) to be invalidated. This check is based on the physical address of the instruction. In addition, the P6 family and Pentium processors check whether a write to a code segment may modify an instruc tion that has been prefetched for execution. If the write affects a prefetched instruc tion, the prefetch queue is invalidated. This latter check is based on the linear address of the instruction. For the Pentium 4 and Intel Xeon processors, a write or a snoop of an instruction in a code segment, where the target instruction is already decoded and resident in the trace cache, invalidates the entire trace cache. The latter behavior means that programs that self-modify code can cause severe degradation of performance when run on the Pentium 4 and Intel Xeon processors.

In practice, the check on linear addresses should not create compatibility problems among IA-32 processors. Applications that include self-modifying code use the same linear address for modifying and fetching the instruction. Systems software, such as a debugger, that might possibly modify an instruction using a different linear address than that used to fetch the instruction, will execute a serializing operation, such as a CPUID instruction, before the modified instruction is executed, which will automati cally resynchronize the instruction cache and prefetch queue. (See Section 8.1.3, “Handling Self- and Cross-Modifying Code,” for more information about the use of self-modifying code.)

For Intel486 processors, a write to an instruction in the cache will modify it in both the cache and memory, but if the instruction was prefetched before the write, the old version of the instruction could be the one executed. To prevent the old instruction from being executed, flush the instruction prefetch unit by coding a jump instruction immediately after any write that modifies an instruction.

11.7 IMPLICIT CACHING (PENTIUM 4, INTEL XEON, AND P6 FAMILY PROCESSORS)

Implicit caching occurs when a memory element is made potentially cacheable, although the element may never have been accessed in the normal von Neumann sequence. Implicit caching occurs on the P6 and more recent processor families due to aggressive prefetching, branch prediction, and TLB miss handling. Implicit caching is an extension of the behavior of existing Intel386, Intel486, and Pentium processor systems, since software running on these processor families also has not been able to deterministically predict the behavior of instruction prefetch.

Page 542 of the Intel 253668-032US user manual — 11.8 EXPLICIT CACHING
Page 542 · click to enlarge
Page 542

MEMORY CACHE CONTROL

To avoid problems related to implicit caching, the operating system must explicitly invalidate the cache when changes are made to cacheable data that the cache coher ency mechanism does not automatically handle. This includes writes to dual-ported or physically aliased memory boards that are not detected by the snooping mecha nisms of the processor, and changes to page- table entries in memory.

The code in Example 11-1 shows the effect of implicit caching on page-table entries. The linear address F000H points to physical location B000H (the page-table entry for F000H contains the value B000H), and the page-table entry for linear address F000 is PTE_F000.

Example 11-1. Effect of Implicit Caching on Page-Table Entries

mov EAX, CR3; Invalidate the TLB mov CR3, EAX; by copying CR3 to itself mov PTE_F000, A000H; Change F000H to point to A000H mov EBX, [F000H];

Because of speculative execution in the P6 and more recent processor families, the last MOV instruction performed would place the value at physical location B000H into EBX, rather than the value at the new physical address A000H. This situation is remedied by placing a TLB invalidation between the load and the store.

11.8 EXPLICIT CACHING

The Pentium III processor introduced four new instructions, the PREFETCHh instruc tions, that provide software with explicit control over the caching of data. These instructions provide “hints” to the processor that the data requested by a PREFETCHh instruction should be read into cache hierarchy now or as soon as possible, in antici pation of its use. The instructions provide different variations of the hint that allow selection of the cache level into which data will be read.

The PREFETCHh instructions can help reduce the long latency typically associated with reading data from memory and thus help prevent processor “stalls.” However, these instructions should be used judiciously. Overuse can lead to resource conflicts and hence reduce the performance of an application. Also, these instructions should only be used to prefetch data from memory; they should not be used to prefetch instructions. For more detailed information on the proper use of the prefetch instruc tion, refer to Chapter 7, “Optimizing Cache Usage,” in the Intel® 64 and IA-32 Archi tectures Optimization Reference Manual.

Page 543 of the Intel 253668-032US user manual — 11.10 STORE BUFFER
Page 543 · click to enlarge
Page 543

MEMORY CACHE CONTROL

11.9 INVALIDATING THE TRANSLATION LOOKASIDE BUFFERS (TLBS)

  • The processor updates its address translation caches (TLBs) transparently to soft ware. Several mechanisms are available, however, that allow software and hardware to invalidate the TLBs either explicitly or as a side effect of another operation. Most details are given in Section 4.10.3, “Invalidation of TLBs and Paging-Structure Caches.” In addition, the following operations invalidate all TLB entries, irrespective of the setting of the G flag:
  • Asserting or de-asserting the FLUSH# pin.
  • (Pentium 4, Intel Xeon, and later processors only.) Writing to an MTRR (with a WRMSR instruction).
  • Writing to control register CR0 to modify the PG or PE flag.
  • (Pentium 4, Intel Xeon, and later processors only.) Writing to control register CR4 to modify the PSE, PGE, or PAE flag.

See Section 4.10, “Caching Translation Information,” for additional information about the TLBs.

11.10 STORE BUFFER

Intel 64 and IA-32 processors temporarily store each write (store) to memory in a store buffer. The store buffer improves processor performance by allowing the processor to continue executing instructions without having to wait until a write to memory and/or to a cache is complete. It also allows writes to be delayed for more efficient use of memory-access bus cycles.

  • In general, the existence of the store buffer is transparent to software, even in systems that use multiple processors. The processor ensures that write operations are always carried out in program order. It also insures that the contents of the store buffer are always drained to memory in the following situations:
  • When an exception or interrupt is generated.
  • (P6 and more recent processor families only) When a serializing instruction is executed.
  • When an I/O instruction is executed.
  • When a LOCK operation is performed.
  • (P6 and more recent processor families only) When a BINIT operation is performed.
  • (Pentium III, and more recent processor families only) When using an SFENCE instruction to order stores.
  • (Pentium 4 and more recent processor families only) When using an MFENCE instruction to order stores.
Page 544 of the Intel 253668-032US user manual — NOTE
Page 544 · click to enlarge
Page 544

MEMORY CACHE CONTROL

The discussion of write ordering in Section 8.2, “Memory Ordering,” gives a detailed description of the operation of the store buffer.

11.11 MEMORY TYPE RANGE REGISTERS (MTRRS)

The following section pertains only to the P6 and more recent processor families.

The memory type range registers (MTRRs) provide a mechanism for associating the memory types (see Section 11.3, “Methods of Caching Available”) with physical- address ranges in system memory. They allow the processor to optimize operations for different types of memory such as RAM, ROM, frame-buffer memory, and memory-mapped I/O devices. They also simplify system hardware design by elimi nating the memory control pins used for this function on earlier IA-32 processors and the external logic needed to drive them.

The MTRR mechanism allows up to 96 memory ranges to be defined in physical memory, and it defines a set of model-specific registers (MSRs) for specifying the type of memory that is contained in each range. Table 11-8 shows the memory types that can be specified and their properties; Figure 11-4 shows the mapping of physical memory with MTRRs. See Section 11.3, “Methods of Caching Available,” for a more detailed description of each memory type.

Following a hardware reset, the P6 and more recent processor families disable all the fixed and variable MTRRs, which in effect makes all of physical memory uncacheable. Initialization software should then set the MTRRs to a specific, system-defined memory map. Typically, the BIOS (basic input/output system) software configures the MTRRs. The operating system or executive is then free to modify the memory map using the normal page-level cacheability attributes.

In a multiprocessor system using a processor in the P6 family or a more recent family, each processor MUST use the identical MTRR memory map so that software will have a consistent view of memory.

NOTE

In multiple processor systems, the operating system must maintain MTRR consistency between all the processors in the system (that is, all processors must use the same MTRR values). The P6 and more recent processor families provide no hardware support for maintaining this consistency.

Table 11-8. Memory Types That Can Be Encoded in MTRRs

Memory Type and Mnemonic Encoding in MTRR

Write Combining (WC) 01H

Uncacheable (UC) 00H · Reserved* 02H

Page 545 of the Intel 253668-032US user manual — NOTE:
Page 545 · click to enlarge
Page 545

MEMORY CACHE CONTROL

Table 11-8. Memory Types That Can Be Encoded in MTRRs (Contd.)

Intel 253668-032US — MEMORY CACHE CONTROL diagram (page 545)
Fig. 32

NOTE:

* Use of these encodings results in a general-protection exception (#GP).

Intel 253668-032US — NOTE: diagram (page 545)
Fig. 33

mapped by an MTRR are set to a default type

Figure 11-4. Mapping Physical Memory With MTRRs

Page 546 of the Intel 253668-032US user manual — VCNT F
Page 546 · click to enlarge
Page 546

MEMORY CACHE CONTROL

11.11.1 MTRR Feature Identification

The availability of the MTRR feature is model-specific. Software can determine if MTRRs are supported on a processor by executing the CPUID instruction and reading the state of the MTRR flag (bit 12) in the feature information register (EDX).

  • If the MTRR flag is set (indicating that the processor implements MTRRs), additional information about MTRRs can be obtained from the 64-bit IA32_MTRRCAP MSR (named MTRRcap MSR for the P6 family processors). The IA32_MTRRCAP MSR is a read-only MSR that can be read with the RDMSR instruction. Figure 11-5 shows the contents of the IA32_MTRRCAP MSR. The functions of the flags and field in this register are as follows:
  • VCNT (variable range registers count) field, bits 0 through 7 — Indicates the number of variable ranges implemented on the processor.
  • FIX (fixed range registers supported) flag, bit 8 — Fixed range MTRRs (IA32_MTRR_FIX64K_00000 through IA32_MTRR_FIX4K_0F8000) are supported when set; no fixed range registers are supported when clear.
  • WC (write combining) flag, bit 10 — The write-combining (WC) memory type is supported when set; the WC type is not supported when clear.
  • SMRR (System-Management Range Register) flag, bit 11 — The systemmanagement range register (SMRR) interface is supported when bit 11 is set; the SMRR interface is not supported when clear.

Bit 9 and bits 11 through 63 in the IA32_MTRRCAP MSR are reserved. If software attempts to write to the IA32_MTRRCAP MSR, a general-protection exception (#GP) is generated.

Software must read IA32_MTRRCAP VCNT field to determine the number of variable MTRRs and query other feature bits in IA32_MTRRCAP to determine additional capa bilities that are supported in a processor. For example, some processors may report a value of ‘8’ in the VCNT field, other processors may report VCNT with different values.

VCNT F

SMRR — SMRR interface supported

FIX — Fixed range registers supported WC — Write-combining memory type supported

VCNT — Number of variable range registers

Figure 11-5. IA32_MTRRCAP Register

7 10 11 · Reserved W · Reserved

Page 547 of the Intel 253668-032US user manual — E
Page 547 · click to enlarge
Page 547

MEMORY CACHE CONTROL

11.11.2 Setting Memory Ranges with MTRRs

The memory ranges and the types of memory specified in each range are set by three groups of registers: the IA32_MTRR_DEF_TYPE MSR, the fixed-range MTRRs, and the variable range MTRRs. These registers can be read and written to using the RDMSR and WRMSR instructions, respectively. The IA32_MTRRCAP MSR indicates the availability of these registers on the processor (see Section 11.11.1, “MTRR Feature Identification”).

11.11.2.1 IA32_MTRR_DEF_TYPE MSR

The IA32_MTRR_DEF_TYPE MSR (named MTRRdefType MSR for the P6 family processors) sets the default properties of the regions of physical memory that are not encompassed by MTRRs. The functions of the flags and field in this register are as follows: • Type field, bits 0 through 7 — Indicates the default memory type used for those physical memory address ranges that do not have a memory type specified for them by an MTRR (see Table 11-8 for the encoding of this field). The legal values for this field are 0, 1, 4, 5, and 6. All other values result in a general- protection exception (#GP) being generated.

Intel recommends the use of the UC (uncached) memory type for all physical memory addresses where memory does not exist. To assign the UC type to nonexistent memory locations, it can either be specified as the default type in the Type field or be explicitly assigned with the fixed and variable MTRRs.

E

FE — Fixed-range MTRRs enable/disable E — MTRR enable/disable

Type — Default memory type

Figure 11-6. IA32_MTRR_DEF_TYPE MSR

  • FE (fixed MTRRs enabled) flag, bit 10 — Fixed-range MTRRs are enabled when set; fixed-range MTRRs are disabled when clear. When the fixed-range MTRRs are enabled, they take priority over the variable-range MTRRs when overlaps in ranges occur. If the fixed-range MTRRs are disabled, the variablerange MTRRs can still be used and can map the range ordinarily covered by the fixed-range MTRRs.
  • E (MTRRs enabled) flag, bit 11 — MTRRs are enabled when set; all MTRRs are disabled when clear, and the UC memory type is applied to all of physical
Show 4 more labels / short text on this page
7 10 11 · Reserved F E · Type · Reserved
Page 548 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 548 · click to enlarge
Page 548

MEMORY CACHE CONTROL

memory. When this flag is set, the FE flag can disable the fixed-range MTRRs; when the flag is clear, the FE flag has no affect. When the E flag is set, the type specified in the default memory type field is used for areas of memory not already mapped by either a fixed or variable MTRR.

Bits 8 and 9, and bits 12 through 63, in the IA32_MTRR_DEF_TYPE MSR are reserved; the processor generates a general-protection exception (#GP) if software attempts to write nonzero values to them.

11.11.2.2 Fixed Range MTRRs

  • The fixed memory ranges are mapped with 11 fixed-range registers of 64 bits each. Each of these registers is divided into 8-bit fields that are used to specify the memory type for each of the sub-ranges the register controls:
  • Register IA32_MTRR_FIX64K_00000 — Maps the 512-KByte address range from 0H to 7FFFFH. This range is divided into eight 64-KByte sub-ranges.
  • Registers IA32_MTRR_FIX16K_80000 and IA32_MTRR_FIX16K_A0000 — Maps the two 128-KByte address ranges from 80000H to BFFFFH. This range is divided into sixteen 16-KByte sub-ranges, 8 ranges per register.
  • Registers IA32_MTRR_FIX4K_C0000 through IA32_MTRR_FIX4K_F8000 — Maps eight 32-KByte address ranges from C0000H to FFFFFH. This range is divided into sixty-four 4-KByte sub-ranges, 8 ranges per register.

Table 11-9 shows the relationship between the fixed physical-address ranges and the corresponding fields of the fixed-range MTRRs; Table 11-8 shows memory type encoding for MTRRs.

For the P6 family processors, the prefix for the fixed range MTRRs is MTRRfix.

11.11.2.3 Variable Range MTRRs

The Pentium 4, Intel Xeon, and P6 family processors permit software to specify the memory type for eight variable-size address ranges, using a pair of MTRRs for each range. The first entry in each pair (IA32_MTRR_PHYSBASEn) defines the base address and memory type for the range; the second entry (IA32_MTRR_PHYSMASKn) contains a mask used to determine the address range. The “n” suffix indicates register pairs 0 through 7.

For P6 family processors, the prefixes for these variable range MTRRs are MTRRphys Base and MTRRphysMask.

Page 549 of the Intel 253668-032US user manual — BC000 BFFFF
Page 549 · click to enlarge
Page 549

MEMORY CACHE CONTROL

Table 11-9. Address Mapping for Fixed-Range MTRRs

Address Range (hexadecimal) MTRR

63 56 55 48 47 40 39 32 31 24 23 16 15 8 7 0

70000- 7FFFF 60000- 6FFFF 50000- 5FFFF 40000- 4FFFF 30000- 3FFFF 20000- 2FFFF 10000- 1FFFF 00000- 0FFFF IA32_MTRR_ FIX64K_00000

9C000 9FFFF 98000- 98FFF 94000- 97FFF 90000- 93FFF 8C000- 8FFFF 88000- 8BFFF 84000- 87FFF 80000- 83FFF IA32_MTRR_ FIX16K_80000

BC000 BFFFF

B8000BBFFF

B4000B7FFF

B0000B3FFF

AC000AFFFF

A8000ABFFF

A4000A7FFF

A0000A3FFF

IA32_MTRR_ FIX16K_A0000

C7000 C7FFF

C6000C6FFF

C5000C5FFF

C4000C4FFF

C3000C3FFF

C2000C2FFF

C1000C1FFF

C0000C0FFF

IA32_MTRR_ FIX4K_C0000

CF000 CFFFF

CE000CEFFF

CD000CDFFF

CC000CCFFF

CB000CBFFF

CA000CAFFF

C9000C9FFF

C8000C8FFF

IA32_MTRR_ FIX4K_C8000

D7000 D7FFF

D6000D6FFF

D5000D5FFF

D4000D4FFF

D3000D3FFF

D2000D2FFF

D1000D1FFF

D0000D0FFF

IA32_MTRR_ FIX4K_D0000

DF000 DFFFF

DE000DEFFF

DD000DDFFF

DC000DCFFF

DB000DBFFF

DA000DAFFF

D9000D9FFF

D8000D8FFF

IA32_MTRR_ FIX4K_D8000

E7000 E7FFF

E6000E6FFF

E5000E5FFF

E4000E4FFF

E3000E3FFF

E2000E2FFF

E1000E1FFF

E0000E0FFF

IA32_MTRR_ FIX4K_E0000

EF000 EFFFF

EE000EEFFF

ED000EDFFF

EC000ECFFF

EB000EBFFF

EA000EAFFF

E9000E9FFF

E8000E8FFF

IA32_MTRR_ FIX4K_E8000

F7000 F7FFF

F6000F6FFF

F5000F5FFF

F4000F4FFF

F3000F3FFF

F2000F2FFF

F1000F1FFF

F0000F0FFF

IA32_MTRR_ FIX4K_F0000

FF000 FFFFF

FE000FEFFF

FD000FDFFF

FC000FCFFF

FB000FBFFF

FA000FAFFF

F9000F9FFF

F8000F8FFF

IA32_MTRR_ FIX4K_F8000

  • Figure 11-7 shows flags and fields in these registers. The functions of these flags and fields are:
  • Type field, bits 0 through 7 — Specifies the memory type for the range (see Table 11-8 for the encoding of this field).
  • PhysBase field, bits 12 through (MAXPHYADDR-1) — Specifies the base address of the address range. This 24-bit value, in the case where MAXPHYADDR is 36 bits, is extended by 12 bits at the low end to form the base address (this automatically aligns the address on a 4-KByte boundary).
  • PhysMask field, bits 12 through (MAXPHYADDR-1) — Specifies a mask (24 bits if the maximum physical address size is 36 bits, 28 bits if the maximum physical address size is 40 bits). The mask determines the range of the region being mapped, according to the following relationships:

— Address_Within_Range AND PhysMask = PhysBase AND PhysMask

— This value is extended by 12 bits at the low end to form the mask value. For more information: see Section 11.11.3, “Example Base and Mask Calcula tions.”

Page 550 of the Intel 253668-032US user manual — MAXPHYADDR
Page 550 · click to enlarge
Page 550

MEMORY CACHE CONTROL

— The width of the PhysMask field depends on the maximum physical address size supported by the processor. CPUID.80000008H reports the maximum physical address size supported by the processor. If CPUID.80000008H is not available, software may assume that the processor supports a 36-bit physical address size (then PhysMask is 24 bits wide and the upper 28 bits of IA32_MTRR_PHYSMASKn are reserved). See the Note below. • V (valid) flag, bit 11 — Enables the register pair when set; disables register pair when clear.

MAXPHYADDR

Type — Memory type for range PhysBase — Base address of range

MAXPHYADDR

V — Valid PhysMask — Sets range mask

MAXPHYADDR: The bit position indicated by MAXPHYADDR depends on the maximum physical address range supported by the processor. It is reported by CPUID leaf function 80000008H. If CPUID does not support leaf 80000008H, the processor supports 36-bit physical address size, then bit PhysMask consists of bits 35:12, and bits 63:36 are reserved.

Figure 11-7. IA32_MTRR_PHYSBASEn and IA32_MTRR_PHYSMASKn Variable-Range

All other bits in the IA32_MTRR_PHYSBASEn and IA32_MTRR_PHYSMASKn registers are reserved; the processor generates a general-protection exception (#GP) if soft ware attempts to write to them.

Some mask values can result in ranges that are not continuous. In such ranges, the area not mapped by the mask value is set to the default memory type. Intel does not encourage the use of “discontinuous” ranges because they could require physical memory to be present throughout the entire 4-GByte physical memory map. If memory is not provided, the behaviour is undefined.

Show 11 more labels / short text on this page
IA32_MTRR_PHYSBASEn Register · Reserved · PhysBase · Type · IA32_MTRR_PHYSMASKn Register · 10 11 12 · Reserved · PhysMask · V Reserved · Reserved · Register Pair
Page 551 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 551 · click to enlarge
Page 551

MEMORY CACHE CONTROL

NOTE

It is possible for software to parse the memory descriptions that BIOS provides by using the ACPI/INT15 e820 interface mechanism. This information then can be used to determine how MTRRs are initialized (for example: allowing the BIOS to define valid memory ranges and the maximum memory range supported by the platform, including the processor).

See Section 11.11.4.1, “MTRR Precedences,” for information on overlapping variable MTRR ranges.

11.11.2.4 System-Management Range Register Interface

If IA32_MTRRCAP[bit 11] is set, the processor supports the SMRR interface to restrict access to a specified memory address range used by system-management mode (SMM) software (see Section 26.4.2.1). If the SMRR interface is supported, SMM software is strongly encouraged to use it to protect the SMI code and data stored by SMI handler in the SMRAM region.

The system-management range registers consist of a pair of MSRs (see Figure 11-8). The IA32_SMRR_PHYSBASE MSR defines the base address for the SMRAM memory range and the memory type used to access it in SMM. The IA32_SMRR_PHYSMASK MSR contains a valid bit and a mask that determines the SMRAM address range protected by the SMRR interface. These MSRs may be written only in SMM; an attempt to write them outside of SMM causes a general-protection exception.1

  • Figure 11-8 shows flags and fields in these registers. The functions of these flags and fields are the following:
  • Type field, bits 0 through 7 — Specifies the memory type for the range (see Table 11-8 for the encoding of this field).
  • PhysBase field, bits 12 through 31 — Specifies the base address of the address range. The address must be less than 4 GBytes and is automatically aligned on a 4-KByte boundary.
  • PhysMask field, bits 12 through 31 — Specifies a mask that determines the range of the region being mapped, according to the following relationships:

— Address_Within_Range AND PhysMask = PhysBase AND PhysMask

— This value is extended by 12 bits at the low end to form the mask value. For more information: see Section 11.11.3, “Example Base and Mask Calcula tions.” • V (valid) flag, bit 11 — Enables the register pair when set; disables register pair when clear.

1. For some processor models, these MSRs can be accessed by RDMSR and WRMSR only if the SMRR interface has been enabled in the IA32_FEATURE_CONTROL MSR. See Appendix B.
Page 552 of the Intel 253668-032US user manual — 11.11.3 Example Base and Mask Calculations
Page 552 · click to enlarge
Page 552

MEMORY CACHE CONTROL

Before attempting to access these SMRR registers, software must test bit 11 in the IA32_MTRRCAP register. If SMRR is not supported, reads from or writes to registers cause general-protection exceptions.

  • When the valid flag in the IA32_SMRR_PHYSMASK MSR is 1, accesses to the specified address range are treated as follows:
  • If the logical processor is in SMM, accesses uses the memory type in the IA32_SMRR_PHYSBASE MSR.
  • If the logical processor is not in SMM, write accesses are ignored and read accesses return a fixed value for each byte. The uncacheable memory type (UC) is used in this case.

The above items apply even if the address range specified overlaps with a range specified by the MTRRs.

Type — Memory type for range PhysBase — Base address of range

V — Valid PhysMask — Sets range mask

Figure 11-8. IA32_SMRR_PHYSBASE and IA32_SMRR_PHYSMASK SMRR Pair

11.11.3 Example Base and Mask Calculations

The examples in this section apply to processors that support a maximum physical address size of 36 bits. The base and mask values entered in variable-range MTRR pairs are 24-bit values that the processor extends to 36-bits.

For example, to enter a base address of 2 MBytes (200000H) in the IA32_MTRR_PHYSBASE3 register, the 12 least-significant bits are truncated and the value 000200H is entered in the PhysBase field. The same operation must be performed on mask values. For example, to map the address range from 200000H to

Show 10 more labels / short text on this page
IA32_SMRR_PHYSBASE Register · Reserved · PhysBase · Type · IA32_SMRR_PHYSMASK Register · 10 11 12 · Reserved · PhysMask · V Reserved · Reserved
Page 553 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 553 · click to enlarge
Page 553

MEMORY CACHE CONTROL

3FFFFFH (2 MBytes to 4 MBytes), a mask value of FFFE00000H is required. Again, the 12 least-significant bits of this mask value are truncated, so that the value entered in the PhysMask field of IA32_MTRR_PHYSMASK3 is FFFE00H. This mask is chosen so that when any address in the 200000H to 3FFFFFH range is AND’d with the mask value, it will return the same value as when the base address is AND’d with the mask value (which is 200000H).

To map the address range from 400000H to 7FFFFFH (4 MBytes to 8 MBytes), a base value of 000400H is entered in the PhysBase field and a mask value of FFFC00H is entered in the PhysMask field.

Example 11-2. Setting-Up Memory for a System

  • Here is an example of setting up the MTRRs for an system. Assume that the system has the following characteristics:
  • 96 MBytes of system memory is mapped as write-back memory (WB) for highest system performance.
  • A custom 4-MByte I/O card is mapped to uncached memory (UC) at a base address of 64 MBytes. This restriction forces the 96 MBytes of system memory to be addressed from 0 to 64 MBytes and from 68 MBytes to 100 MBytes, leaving a 4-MByte hole for the I/O card.
  • An 8-MByte graphics card is mapped to write-combining memory (WC) beginning at address A0000000H.
  • The BIOS area from 15 MBytes to 16 MBytes is mapped to UC memory.

The following settings for the MTRRs will yield the proper mapping of the physical address space for this system configuration.

IA32_MTRR_PHYSBASE0 = 0000 0000 0000 0006H IA32_MTRR_PHYSMASK0 = 0000 000F FC00 0800H Caches 0-64 MByte as WB cache type.

IA32_MTRR_PHYSBASE1 = 0000 0000 0400 0006H IA32_MTRR_PHYSMASK1 = 0000 000F FE00 0800H Caches 64-96 MByte as WB cache type.

IA32_MTRR_PHYSBASE2 = 0000 0000 0600 0006H IA32_MTRR_PHYSMASK2 = 0000 000F FFC0 0800H Caches 96-100 MByte as WB cache type.

IA32_MTRR_PHYSBASE3 = 0000 0000 0400 0000H IA32_MTRR_PHYSMASK3 = 0000 000F FFC0 0800H Caches 64-68 MByte as UC cache type.

IA32_MTRR_PHYSBASE4 = 0000 0000 00F0 0000H IA32_MTRR_PHYSMASK4 = 0000 000F FFF0 0800H Caches 15-16 MByte as UC cache type.

Page 554 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 554 · click to enlarge
Page 554

MEMORY CACHE CONTROL

IA32_MTRR_PHYSBASE5 = 0000 0000 A000 0001H IA32_MTRR_PHYSMASK5 = 0000 000F FF80 0800H Caches A0000000-A0800000 as WC type.

This MTRR setup uses the ability to overlap any two memory ranges (as long as the ranges are mapped to WB and UC memory types) to minimize the number of MTRR registers that are required to configure the memory environment. This setup also fulfills the requirement that two register pairs are left for operating system usage.

11.11.3.1 Base and Mask Calculations for Greater-Than 36-bit Physical Address Support

For Intel 64 and IA-32 processors that support greater than 36 bits of physical address size, software should query CPUID.80000008H to determine the maximum physical address. See the example.

Example 11-3. Setting-Up Memory for a System with a 40-Bit Address Size

If a processor supports 40-bits of physical address size, then the PhysMask field (in IA32_MTRR_PHYSMASKn registers) is 28 bits instead of 24 bits. For this situation, Example 11-2 should be modified as follows:

IA32_MTRR_PHYSBASE0 = 0000 0000 0000 0006H IA32_MTRR_PHYSMASK0 = 0000 00FF FC00 0800H Caches 0-64 MByte as WB cache type.

IA32_MTRR_PHYSBASE1 = 0000 0000 0400 0006H IA32_MTRR_PHYSMASK1 = 0000 00FF FE00 0800H Caches 64-96 MByte as WB cache type.

IA32_MTRR_PHYSBASE2 = 0000 0000 0600 0006H IA32_MTRR_PHYSMASK2 = 0000 00FF FFC0 0800H Caches 96-100 MByte as WB cache type.

IA32_MTRR_PHYSBASE3 = 0000 0000 0400 0000H IA32_MTRR_PHYSMASK3 = 0000 00FF FFC0 0800H Caches 64-68 MByte as UC cache type.

IA32_MTRR_PHYSBASE4 = 0000 0000 00F0 0000H IA32_MTRR_PHYSMASK4 = 0000 00FF FFF0 0800H Caches 15-16 MByte as UC cache type.

IA32_MTRR_PHYSBASE5 = 0000 0000 A000 0001H IA32_MTRR_PHYSMASK5 = 0000 00FF FF80 0800H Caches A0000000-A0800000 as WC type.

Page 555 of the Intel 253668-032US user manual — 11.11.5 MTRR Initialization
Page 555 · click to enlarge
Page 555

MEMORY CACHE CONTROL

11.11.4 Range Size and Alignment Requirement

A range that is to be mapped to a variable-range MTRR must meet the following “power of 2” size and alignment rules:

1. The minimum range size is 4 KBytes and the base address of the range must be on at least a 4-KByte boundary.
2. For ranges greater than 4 KBytes, each range must be of length 2 n and its base address must be aligned on a 2 n boundary, where n is a value equal to or greater than 12. The base-address alignment value cannot be less than its length. For example, an 8-KByte range cannot be aligned on a 4-KByte boundary. It must be aligned on at least an 8-KByte boundary.

11.11.4.1 MTRR Precedences

If the MTRRs are not enabled (by setting the E flag in the IA32_MTRR_DEF_TYPE MSR), then all memory accesses are of the UC memory type. If the MTRRs are enabled, then the memory type used for a memory access is determined as follows:

1. If the physical address falls within the first 1 MByte of physical memory and fixed MTRRs are enabled, the processor uses the memory type stored for the appropriate fixed-range MTRR.
2. Otherwise, the processor attempts to match the physical address with a memory type set by the variable-range MTRRs:

— If one variable memory range matches, the processor uses the memory type stored in the IA32_MTRR_PHYSBASEn register for that range.

— If two or more variable memory ranges match and the memory types are identical, then that memory type is used.

— If two or more variable memory ranges match and one of the memory types is UC, the UC memory type used.

— If two or more variable memory ranges match and the memory types are WT and WB, the WT memory type is used.

— For overlaps not defined by the above rules, processor behavior is undefined.

3. If no fixed or variable memory range matches, the processor uses the default memory type.

11.11.5 MTRR Initialization

On a hardware reset, the P6 and more recent processors clear the valid flags in vari able-range MTRRs and clear the E flag in the IA32_MTRR_DEF_TYPE MSR to disable all MTRRs. All other bits in the MTRRs are undefined.

Prior to initializing the MTRRs, software (normally the system BIOS) must initialize all fixed-range and variable-range MTRR register fields to 0. Software can then initialize

Page 556 of the Intel 253668-032US user manual — 11.11.7 MTRR Maintenance Programming Interface
Page 556 · click to enlarge
Page 556

MEMORY CACHE CONTROL

the MTRRs according to known types of memory, including memory on devices that it auto-configures. Initialization is expected to occur prior to booting the operating system.

See Section 11.11.8, “MTRR Considerations in MP Systems,” for information on initializing MTRRs in MP (multiple-processor) systems.

11.11.6 Remapping Memory Types

A system designer may re-map memory types to tune performance or because a future processor may not implement all memory types supported by the Pentium 4, Intel Xeon, and P6 family processors. The following rules support coherent memory- type re-mappings:

1. A memory type should not be mapped into another memory type that has a weaker memory ordering model. For example, the uncacheable type cannot be mapped into any other type, and the write-back, write-through, and writeprotected types cannot be mapped into the weakly ordered write-combining type.
2. A memory type that does not delay writes should not be mapped into a memory type that does delay writes, because applications of such a memory type may rely on its write-through behavior. Accordingly, the write-back type cannot be mapped into the write-through type.
3. A memory type that views write data as not necessarily stored and read back by a subsequent read, such as the write-protected type, can only be mapped to another type with the same behaviour (and there are no others for the Pentium 4, Intel Xeon, and P6 family processors) or to the uncacheable type.

In many specific cases, a system designer can have additional information about how a memory type is used, allowing additional mappings. For example, write-through memory with no associated write side effects can be mapped into write-back memory.

11.11.7 MTRR Maintenance Programming Interface

The operating system maintains the MTRRs after booting and sets up or changes the memory types for memory-mapped devices. The operating system should provide a driver and application programming interface (API) to access and set the MTRRs. The function calls MemTypeGet() and MemTypeSet() define this interface.

11.11.7.1 MemTypeGet() Function

The MemTypeGet() function returns the memory type of the physical memory range specified by the parameters base and size. The base address is the starting physical address and the size is the number of bytes for the memory range. The function

Page 557 of the Intel 253668-032US user manual — THEN
Page 557 · click to enlarge
Page 557

MEMORY CACHE CONTROL

automatically aligns the base address and size to 4-KByte boundaries. Pseudocode for the MemTypeGet() function is given in Example 11-4.

Example 11-4. MemTypeGet() Pseudocode

#define MIXED_TYPES -1 /* 0 < MIXED_TYPES || MIXED_TYPES > 256 */

IF CPU_FEATURES.MTRR /* processor supports MTRRs */

THEN

Align BASE and SIZE to 4-KByte boundary; IF (BASE + SIZE) wrap 4-GByte address space

THEN return INVALID; FI; IF MTRRdefType.E = 0

THEN return UC; FI; FirstType ¨ Get4KMemType (BASE); /* Obtains memory type for first 4-KByte range. */ /* See Get4KMemType (4KByteRange) in Example 11-5. */ FOR each additional 4-KByte range specified in SIZE

NextType ¨ Get4KMemType (4KByteRange); IF NextType ¼ FirstType

THEN return MixedTypes; FI; ROF; return FirstType; ELSE return UNSUPPORTED; FI;

If the processor does not support MTRRs, the function returns UNSUPPORTED. If the MTRRs are not enabled, then the UC memory type is returned. If more than one memory type corresponds to the specified range, a status of MIXED_TYPES is returned. Otherwise, the memory type defined for the range (UC, WC, WT, WB, or WP) is returned.

The pseudocode for the Get4KMemType() function in Example 11-5 obtains the memory type for a single 4-KByte range at a given physical address. The sample code determines whether an PHY_ADDRESS falls within a fixed range by comparing the address with the known fixed ranges: 0 to 7FFFFH (64-KByte regions), 80000H to BFFFFH (16-KByte regions), and C0000H to FFFFFH (4-KByte regions). If an address falls within one of these ranges, the appropriate bits within one of its MTRRs deter mine the memory type.

Page 558 of the Intel 253668-032US user manual — THEN
Page 558 · click to enlarge
Page 558

MEMORY CACHE CONTROL

Example 11-5. Get4KMemType() Pseudocode

IF IA32_MTRRCAP.FIX AND MTRRdefType.FE /* fixed registers enabled */

THEN IF PHY_ADDRESS is within a fixed range

return IA32_MTRR_FIX.Type; FI; FOR each variable-range MTRR in IA32_MTRRCAP.VCNT

IF IA32_MTRR_PHYSMASK.V = 0

THEN continue; FI; IF (PHY_ADDRESS AND IA32_MTRR_PHYSMASK.Mask) =

(IA32_MTRR_PHYSBASE.Base AND IA32_MTRR_PHYSMASK.Mask) THEN

return IA32_MTRR_PHYSBASE.Type; FI; ROF; return MTRRdefType.Type;

11.11.7.2 MemTypeSet() Function

The MemTypeSet() function in Example 11-6 sets a MTRR for the physical memory range specified by the parameters base and size to the type specified by type. The base address and size are multiples of 4 KBytes and the size is not 0.

Example 11-6. MemTypeSet Pseudocode

IF CPU_FEATURES.MTRR (* processor supports MTRRs *)

THEN

IF BASE and SIZE are not 4-KByte aligned or size is 0

THEN return INVALID; FI; IF (BASE + SIZE) wrap 4-GByte address space

THEN return INVALID; FI; IF TYPE is invalid for Pentium 4, Intel Xeon, and P6 family processors

THEN return UNSUPPORTED; FI; IF TYPE is WC and not supported

THEN return UNSUPPORTED; FI; IF IA32_MTRRCAP.FIX is set AND range can be mapped using a fixed-range MTRR

Page 559 of the Intel 253668-032US user manual — BEGIN
Page 559 · click to enlarge
Page 559

MEMORY CACHE CONTROL

THEN

pre_mtrr_change(); update affected MTRR; post_mtrr_change(); FI;

ELSE (* try to map using a variable MTRR pair *)

IF IA32_MTRRCAP.VCNT = 0

THEN return UNSUPPORTED; FI; IF conflicts with current variable ranges

THEN return RANGE_OVERLAP; FI; IF no MTRRs available

THEN return VAR_NOT_AVAILABLE; FI; IF BASE and SIZE do not meet the power of 2 requirements for variable MTRRs

THEN return INVALID_VAR_REQUEST; FI; pre_mtrr_change(); Update affected MTRRs; post_mtrr_change(); FI;

BEGIN

disable interrupts; Save current value of CR4; disable and flush caches; flush TLBs; disable MTRRs; IF multiprocessing

THEN maintain consistency through IPIs; FI; END post_mtrr_change()

BEGIN

flush caches and TLBs; enable MTRRs; enable caches; restore value of CR4; enable interrupts;

pre_mtrr_change()

Page 560 of the Intel 253668-032US user manual — 11.11.8 MTRR Considerations in MP Systems
Page 560 · click to enlarge
Page 560

MEMORY CACHE CONTROL

END

The physical address to variable range mapping algorithm in the MemTypeSet func tion detects conflicts with current variable range registers by cycling through them and determining whether the physical address in question matches any of the current ranges. During this scan, the algorithm can detect whether any current variable ranges overlap and can be concatenated into a single range.

The pre_mtrr_change() function disables interrupts prior to changing the MTRRs, to avoid executing code with a partially valid MTRR setup. The algorithm disables caching by setting the CD flag and clearing the NW flag in control register CR0. The caches are invalidated using the WBINVD instruction. The algorithm flushes all TLB entries either by clearing the page-global enable (PGE) flag in control register CR4 (if PGE was already set) or by updating control register CR3 (if PGE was already clear). Finally, it disables MTRRs by clearing the E flag in the IA32_MTRR_DEF_TYPE MSR.

After the memory type is updated, the post_mtrr_change() function re-enables the MTRRs and again invalidates the caches and TLBs. This second invalidation is required because of the processor's aggressive prefetch of both instructions and data. The algorithm restores interrupts and re-enables caching by setting the CD flag.

An operating system can batch multiple MTRR updates so that only a single pair of cache invalidations occur.

11.11.8 MTRR Considerations in MP Systems

In MP (multiple-processor) systems, the operating systems must maintain MTRR consistency between all the processors in the system. The Pentium 4, Intel Xeon, and P6 family processors provide no hardware support to maintain this consistency. In general, all processors must have the same MTRR values.

This requirement implies that when the operating system initializes an MP system, it must load the MTRRs of the boot processor while the E flag in register MTRRdefType is 0. The operating system then directs other processors to load their MTRRs with the same memory map. After all the processors have loaded their MTRRs, the operating system signals them to enable their MTRRs. Barrier synchronization is used to prevent further memory accesses until all processors indicate that the MTRRs are enabled. This synchronization is likely to be a shoot-down style algorithm, with shared variables and interprocessor interrupts.

Any change to the value of the MTRRs in an MP system requires the operating system to repeat the loading and enabling process to maintain consistency, using the following procedure:

1. Broadcast to all processors to execute the following code sequence.
2. Disable interrupts.
3. Wait for all processors to reach this point.
Page 561 of the Intel 253668-032US user manual — 11.11.9 Large Page Size Considerations
Page 561 · click to enlarge
Page 561

MEMORY CACHE CONTROL

4. Enter the no-fill cache mode. (Set the CD flag in control register CR0 to 1 and the NW flag to 0.)
5. Flush all caches using the WBINVD instructions. Note on a processor that supports self-snooping, CPUID feature flag bit 27, this step is unnecessary.
6. If the PGE flag is set in control register CR4, flush all TLBs by clearing that flag.
7. If the PGE flag is clear in control register CR4, flush all TLBs by executing a MOV from control register CR3 to another register and then a MOV from that register back to CR3.
8. Disable all range registers (by clearing the E flag in register MTRRdefType). If only variable ranges are being modified, software may clear the valid bits for the affected register pairs instead.
9. Update the MTRRs.
10. Enable all range registers (by setting the E flag in register MTRRdefType). If only variable-range registers were modified and their individual valid bits were cleared, then set the valid bits for the affected ranges instead.
11. Flush all caches and all TLBs a second time. (The TLB flush is required for Pentium 4, Intel Xeon, and P6 family processors. Executing the WBINVD instruction is not needed when using Pentium 4, Intel Xeon, and P6 family processors, but it may be needed in future systems.)
12. Enter the normal cache mode to re-enable caching. (Set the CD and NW flags in control register CR0 to 0.)
13. Set PGE flag in control register CR4, if cleared in Step 6 (above).
14. Wait for all processors to reach this point.
15. Enable interrupts.

11.11.9 Large Page Size Considerations

The MTRRs provide memory typing for a limited number of regions that have a 4 KByte granularity (the same granularity as 4-KByte pages). The memory type for a given page is cached in the processor’s TLBs. When using large pages (2 or 4 MBytes), a single page-table entry covers multiple 4-KByte granules, each with a single memory type. Because the memory type for a large page is cached in the TLB, the processor can behave in an undefined manner if a large page is mapped to a region of memory that MTRRs have mapped with multiple memory types.

Undefined behavior can be avoided by insuring that all MTRR memory-type ranges within a large page are of the same type. If a large page maps to a region of memory containing different MTRR-defined memory types, the PCD and PWT flags in the page-table entry should be set for the most conservative memory type for that range. For example, a large page used for memory mapped I/O and regular memory is mapped as UC memory. Alternatively, the operating system can map the region using multiple 4-KByte pages each with its own memory type.

Page 562 of the Intel 253668-032US user manual — 11.12.1 Detecting Support for the PAT Feature
Page 562 · click to enlarge
Page 562

MEMORY CACHE CONTROL

The requirement that all 4-KByte ranges in a large page are of the same memory type implies that large pages with different memory types may suffer a performance penalty, since they must be marked with the lowest common denominator memory type.

The Pentium 4, Intel Xeon, and P6 family processors provide special support for the physical memory range from 0 to 4 MBytes, which is potentially mapped by both the fixed and variable MTRRs. This support is invoked when a Pentium 4, Intel Xeon, or P6 family processor detects a large page overlapping the first 1 MByte of this memory range with a memory type that conflicts with the fixed MTRRs. Here, the processor maps the memory range as multiple 4-KByte pages within the TLB. This operation insures correct behavior at the cost of performance. To avoid this perfor mance penalty, operating-system software should reserve the large page option for regions of memory at addresses greater than or equal to 4 MBytes.

11.12 PAGE ATTRIBUTE TABLE (PAT)

The Page Attribute Table (PAT) extends the IA-32 architecture’s page-table format to allow memory types to be assigned to regions of physical memory based on linear address mappings. The PAT is a companion feature to the MTRRs; that is, the MTRRs allow mapping of memory types to regions of the physical address space, where the PAT allows mapping of memory types to pages within the linear address space. The MTRRs are useful for statically describing memory types for physical ranges, and are typically set up by the system BIOS. The PAT extends the functions of the PCD and PWT bits in page tables to allow all five of the memory types that can be assigned with the MTRRs (plus one additional memory type) to also be assigned dynamically to pages of the linear address space.

The PAT was introduced to IA-32 architecture on the Pentium III processor. It is also available in the Pentium 4 and Intel Xeon processors.

11.12.1 Detecting Support for the PAT Feature

An operating system or executive can detect the availability of the PAT by executing the CPUID instruction with a value of 1 in the EAX register. Support for the PAT is indi cated by the PAT flag (bit 16 of the values returned to EDX register). If the PAT is supported, the operating system or executive can use the IA32_PAT MSR to program the PAT. When memory types have been assigned to entries in the PAT, software can then use of the PAT-index bit (PAT) in the page-table and page-directory entries along with the PCD and PWT bits to assign memory types from the PAT to individual pages.

Page 563 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 563 · click to enlarge
Page 563

MEMORY CACHE CONTROL

11.12.2 IA32_PAT MSR

The IA32_PAT MSR is located at MSR address 277H (see to Appendix B, “Model- Specific Registers (MSRs),” and this address will remain at the same address on future IA-32 processors that support the PAT feature. Figure 11-9. shows the format of the 64-bit IA32_PAT MSR.

The IA32_PAT MSR contains eight page attribute fields: PA0 through PA7. The three low-order bits of each field are used to specify a memory type. The five high-order bits of each field are reserved, and must be set to all 0s. Each of the eight page attribute fields can contain any of the memory type encodings specified in Table 11-10.

31 27 26 24 23 19 18 16 15 11 10 8 7 3 2 0

Reserved PA3 Reserved PA2 Reserved PA1 Reserved PA0

63 59 58 56 55 51 50 48 47 43 42 40 39 35 34 32

Reserved PA7 Reserved PA6 Reserved PA5 Reserved PA4

Figure 11-9. IA32_PAT MSR

Table 11-10. Memory Types That Can Be Encoded With PAT

01H Write Combining (WC)

04H Write Through (WT)

05H Write Protected (WP)

06H Write Back (WB)

08H - FFH Reserved*

Show 5 more labels / short text on this page
Encoding Mnemonic · 00H Uncacheable (UC) · 02H Reserved* · 03H Reserved* · 07H Uncached (UC-)
Page 564 of the Intel 253668-032US user manual — PAT0 WB
Page 564 · click to enlarge
Page 564

MEMORY CACHE CONTROL

11.12.3 Selecting a Memory Type from the PAT

To select a memory type for a page from the PAT, a 3-bit index made up of the PAT, PCD, and PWT bits must be encoded in the page-table or page-directory entry for the page. Table 11-11 shows the possible encodings of the PAT, PCD, and PWT bits and the PAT entry selected with each encoding. The PAT bit is bit 7 in page-table entries that point to 4-KByte pages and bit 12 in paging-structure entries that point to larger pages. The PCD and PWT bits are bits 4 and 3, respectively, in paging-structure entries that point to pages of any size.

The PAT entry selected for a page is used in conjunction with the MTRR setting for the region of physical memory in which the page is mapped to determine the effective memory type for the page, as shown in Table 11-7.

Table 11-11. Selection of PAT Entries with PAT, PCD, and PWT Flags

PAT PCD PWT PAT Entry

0 0 0 PAT0

0 0 1 PAT1

0 1 0 PAT2

0 1 1 PAT3

1 0 0 PAT4

1 0 1 PAT5

1 1 0 PAT6

1 1 1 PAT7

11.12.4 Programming the PAT

Table 11-12 shows the default setting for each PAT entry following a power up or reset of the processor. The setting remain unchanged following a soft reset (INIT reset).

Table 11-12. Memory Type Setting of PAT Entries Following a Power-up or Reset

PAT Entry Memory Type Following Power-up or Reset

PAT0 WB

PAT1 WT

PAT2 UC-

PAT3 UC

PAT4 WB

PAT5 WT

PAT6 UC-

PAT7 UC

Page 565 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 565 · click to enlarge
Page 565

MEMORY CACHE CONTROL

The values in all the entries of the PAT can be changed by writing to the IA32_PAT MSR using the WRMSR instruction. The IA32_PAT MSR is read and write accessible (use of the RDMSR and WRMSR instructions, respectively) to software operating at a CPL of 0. Table 11-10 shows the allowable encoding of the entries in the PAT. Attempting to write an undefined memory type encoding into the PAT causes a general-protection (#GP) exception to be generated.

The operating system is responsible for insuring that changes to a PAT entry occur in a manner that maintains the consistency of the processor caches and translation lookaside buffers (TLB). This is accomplished by following the procedure as specified in Section 11.11.8, “MTRR Considerations in MP Systems,” for changing the value of an MTRR in a multiple processor system. It requires a specific sequence of operations that includes flushing the processors caches and TLBs.

The PAT allows any memory type to be specified in the page tables, and therefore it is possible to have a single physical page mapped to two or more different linear addresses, each with different memory types. Intel does not support this practice because it may lead to undefined operations that can result in a system failure. In particular, a WC page must never be aliased to a cacheable page because WC writes may not check the processor caches.

When remapping a page that was previously mapped as a cacheable memory type to a WC page, an operating system can avoid this type of aliasing by doing the following:

1. Remove the previous mapping to a cacheable memory type in the page tables; that is, make them not present.
2. Flush the TLBs of processors that may have used the mapping, even specula tively.
3. Create a new mapping to the same physical address with a new memory type, for instance, WC.
4. Flush the caches on all processors that may have used the mapping previously. Note on processors that support self-snooping, CPUID feature flag bit 27, this step is unnecessary.

Operating systems that use a page directory as a page table (to map large pages) and enable page size extensions must carefully scrutinize the use of the PAT index bit for the 4-KByte page-table entries. The PAT index bit for a page-table entry (bit 7) corresponds to the page size bit in a page-directory entry. Therefore, the operating system can only use PAT entries PA0 through PA3 when setting the caching type for a page table that is also used as a page directory. If the operating system attempts to use PAT entries PA4 through PA7 when using this memory as a page table, it effec tively sets the PS bit for the access to this memory as a page directory.

For compatibility with earlier IA-32 processors that do not support the PAT, care should be taken in selecting the encodings for entries in the PAT (see Section 11.12.5, “PAT Compatibility with Earlier IA-32 Processors”).

Page 566 of the Intel 253668-032US user manual — MEMORY CACHE CONTROL
Page 566 · click to enlarge
Page 566

MEMORY CACHE CONTROL

11.12.5 PAT Compatibility with Earlier IA-32 Processors

For IA-32 processors that support the PAT, the IA32_PAT MSR is always active. That is, the PCD and PWT bits in page-table entries and in page-directory entries (that point to pages) are always select a memory type for a page indirectly by selecting an entry in the PAT. They never select the memory type for a page directly as they do in earlier IA-32 processors that do not implement the PAT (see Table 11-6).

To allow compatibility for code written to run on earlier IA-32 processor that do not support the PAT, the PAT mechanism has been designed to allow backward compati bility to earlier processors. This compatibility is provided through the ordering of the PAT, PCD, and PWT bits in the 3-bit PAT entry index. For processors that do not imple ment the PAT, the PAT index bit (bit 7 in the page-table entries and bit 12 in the page- directory entries) is reserved and set to 0. With the PAT bit reserved, only the first four entries of the PAT can be selected with the PCD and PWT bits. At power-up or reset (see Table 11-12), these first four entries are encoded to select the same memory types as the PCD and PWT bits would normally select directly in an IA-32 processor that does not implement the PAT. So, if encodings of the first four entries in the PAT are left unchanged following a power-up or reset, code written to run on earlier IA-32 processors that do not implement the PAT will run correctly on IA-32 processors that do implement the PAT.

Page 567 of the Intel 253668-032US user manual — 12.2 THE MMX STATE AND MMX REGISTER ALIASING
Page 567 · click to enlarge
Page 567

CHAPTER 12 INTEL ® MMX ™ TECHNOLOGY SYSTEM

PROGRAMMING

This chapter describes those features of the Intel® MMX™ technology that must be considered when designing or enhancing an operating system to support MMX tech nology. It covers MMX instruction set emulation, the MMX state, aliasing of MMX registers, saving MMX state, task and context switching considerations, exception handling, and debugging.

12.1 EMULATION OF THE MMX INSTRUCTION SET

The IA-32 or Intel 64 architecture does not support emulation of the MMX instruc tions, as it does for x87 FPU instructions. The EM flag in control register CR0 (provided to invoke emulation of x87 FPU instructions) cannot be used for MMX instruction emulation. If an MMX instruction is executed when the EM flag is set, an invalid opcode exception (UD#) is generated. Table 12-1 shows the interaction of the EM, MP, and TS flags in control register CR0 when executing MMX instructions.

Table 12-1. Action Taken By MMX Instructions

for Different Combinations of EM, MP and TS

EM MP* TS Action

0 1 0 Execute.

0 1 1 #NM exception.

1 1 0 #UD exception.

1 1 1 #UD exception.

12.2 THE MMX STATE AND MMX REGISTER ALIASING

The MMX state consists of eight 64-bit registers (MM0 through MM7). These registers are aliased to the low 64-bits (bits 0 through 63) of floating-point registers R0 through R7 (see Figure 12-1). Note that the MMX registers are mapped to the phys ical locations of the floating-point registers (R0 through R7), not to the relative loca tions of the registers in the floating-point register stack (ST0 through ST7). As a

CR0 Flags

Page 568 of the Intel 253668-032US user manual — INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING
Page 568 · click to enlarge
Page 568

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

result, the MMX register mapping is fixed and is not affected by value in the Top Of Stack (TOS) field in the floating-point status word (bits 11 through 13).

Intel 253668-032US — INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING diagram (page 568)
Fig. 34

Figure 12-1. Mapping of MMX Registers to Floating-Point Registers

When a value is written into an MMX register using an MMX instruction, the value also appears in the corresponding floating-point register in bits 0 through 63. Likewise, when a floating-point value written into a floating-point register by a x87 FPU, the low 64 bits of that value also appears in a the corresponding MMX register.

  • The execution of MMX instructions have several side effects on the x87 FPU state contained in the floating-point registers, the x87 FPU tag word, and the x87 FPU status word. These side effects are as follows:
  • When an MMX instruction writes a value into an MMX register, at the same time, bits 64 through 79 of the corresponding floating-point register are set to all 1s.
  • When an MMX instruction (other than the EMMS instruction) is executed, each of the tag fields in the x87 FPU tag word is set to 00B (valid). (See also Section 12.2.1, “Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Word.”)
Page 569 of the Intel 253668-032US user manual — INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING
Page 569 · click to enlarge
Page 569

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

  • When the EMMS instruction is executed, each tag field in the x87 FPU tag word is set to 11B (empty).
  • Each time an MMX instruction is executed, the TOS value is set to 000B.

Execution of MMX instructions does not affect the other bits in the x87 FPU status word (bits 0 through 10 and bits 14 and 15) or the contents of the other x87 FPU registers that comprise the x87 FPU state (the x87 FPU control word, instruction pointer, data pointer, or opcode registers).

Table 12-2 summarizes the effects of the MMX instructions on the x87 FPU state.

Table 12-2. Effects of MMX Instructions on x87 FPU State

x87 FPU Tag Word

TOS Field of x87 FPU Status Word

Other x87 FPU Registers

Bits 64 Through 79 of x87 FPU Data Registers

Bits 0 Through 63 of x87 FPU Data Registers

Read from MMX register

All tags set to 00B (Valid)

000B Unchanged Unchanged Unchanged

Write to MMX register

All tags set to 00B (Valid)

000B Unchanged Set to all 1s Overwritten with MMX data

EMMS All fields set to 11B (Empty)

000B Unchanged Unchanged Unchanged

12.2.1 Effect of MMX, x87 FPU, FXSAVE, and FXRSTOR Instructions on the x87 FPU Tag Word

Table 12-3 summarizes the effect of MMX and x87 FPU instructions and the FXSAVE and FXRSTOR instructions on the tags in the x87 FPU tag word and the corresponding tags in an image of the tag word stored in memory.

The values in the fields of the x87 FPU tag word do not affect the contents of the MMX registers or the execution of MMX instructions. However, the MMX instructions do modify the contents of the x87 FPU tag word, as is described in Section 12.2, “The MMX State and MMX Register Aliasing.” These modifications may affect the operation of the x87 FPU when executing x87 FPU instructions, if the x87 FPU state is not initialized or restored prior to beginning x87 FPU instruction execution.

Note that the FSAVE, FXSAVE, and FSTENV instructions (which save x87 FPU state information) read the x87 FPU tag register and contents of each of the floating-point registers, determine the actual tag values for each register (empty, nonzero, zero, or special), and store the updated tag word in memory. After executing these instruc tions, all the tags in the x87 FPU tag word are set to empty (11B). Likewise, the EMMS instruction clears MMX state from the MMX/floating-point registers by setting all the tags in the x87 FPU tag word to 11B.

MMX Instruction Type

Page 570 of the Intel 253668-032US user manual — 12.3 SAVING AND RESTORING THE MMX STATE AND REGISTERS
Page 570 · click to enlarge
Page 570

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

Table 12-3. Effect of the MMX, x87 FPU, and FXSAVE/FXRSTOR Instructions on the

x87 FPU Tag Word

Instruction x87 FPU Tag Word Image of x87 FPU Tag Word Stored in Memory

MMX All (except EMMS) All tags are set to 00B (valid). Not affected.

MMX EMMS All tags are set to 11B (empty).

Not affected.

x87 FPU All (except FSAVE, FSTENV, FRSTOR, FLDENV)

Tag for modified floating- point register is set to 00B or 11B.

Not affected.

x87 FPU and FXSAVE

FSAVE, FSTENV, FXSAVE

Tags and register values are read and interpreted; then all tags are set to 11B.

Tags are set according to the actual values in the floating- point registers; that is, empty registers are marked 11B and valid registers are marked 00B (nonzero), 01B (zero), or 10B (special).

x87 FPU and FXRSTOR

FRSTOR, FLDENV, FXRSTOR

All tags marked 11B in memory are set to 11B; all other tags are set according to the value in the corresponding floating-point register: 00B (nonzero), 01B (zero), or 10B (special).

Tags are read and interpreted, but not modified.

12.3 SAVING AND RESTORING THE MMX STATE AND REGISTERS

  • Because the MMX registers are aliased to the x87 FPU data registers, the MMX state can be saved to memory and restored from memory as follows:
  • Execute an FSAVE, FNSAVE, or FXSAVE instruction to save the MMX state to memory. (The FXSAVE instruction also saves the state of the XMM and MXCSR registers.)
  • Execute an FRSTOR or FXRSTOR instruction to restore the MMX state from memory. (The FXRSTOR instruction also restores the state of the XMM and MXCSR registers.)

The save and restore methods described above are required for operating systems (see Section 12.4, “Saving MMX State on Task or Context Switches”). Applications can in some cases save and restore only the MMX registers in the following way:

Instruction Type

Page 571 of the Intel 253668-032US user manual — 12.5 EXCEPTIONS THAT CAN OCCUR WHEN EXECUTING MMX INSTRUCTIONS
Page 571 · click to enlarge
Page 571

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

  • Execute eight MOVQ instructions to save the contents of the MMX0 through MMX7 registers to memory. An EMMS instruction may then (optionally) be executed to clear the MMX state in the x87 FPU.
  • Execute eight MOVQ instructions to read the saved contents of MMX registers from memory into the MMX0 through MMX7 registers.

NOTE

The IA-32 architecture does not support scanning the x87 FPU tag word and then only saving valid entries.

12.4 SAVING MMX STATE ON TASK OR CONTEXT SWITCHES

When switching from one task or context to another, it is often necessary to save the MMX state. As a general rule, if the existing task switching code for an operating system includes facilities for saving the state of the x87 FPU, these facilities can also be relied upon to save the MMX state, without rewriting the task switch code. This reliance is possible because the MMX state is aliased to the x87 FPU state (see Section 12.2, “The MMX State and MMX Register Aliasing”).

With the introduction of the FXSAVE and FXRSTOR instructions and of SSE/SSE2/SSE3/SSSE3 extensions, it is possible (and more efficient) to create state saving facilities in the operating system or executive that save the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3 state in one operation. Section 13.5, “Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switches,” describes how to design such facilities. The techniques describes in this section can be adapted to saving only the MMX and x87 FPU state if needed.

12.5 EXCEPTIONS THAT CAN OCCUR WHEN EXECUTING MMX INSTRUCTIONS

MMX instructions do not generate x87 FPU floating-point exceptions, nor do they affect the processor’s status flags in the EFLAGS register or the x87 FPU status word. The following exceptions can be generated during the execution of an MMX instruc tion: • Exceptions during memory accesses:

— Stack-segment fault (#SS).

— General protection (#GP).

— Page fault (#PF).

— Alignment check (#AC), if alignment checking is enabled.

Page 572 of the Intel 253668-032US user manual — 12.6 DEBUGGING MMX CODE
Page 572 · click to enlarge
Page 572

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

  • System exceptions:

— Invalid Opcode (#UD), if the EM flag in control register CR0 is set when an MMX instruction is executed (see Section 12.1, “Emulation of the MMX Instruction Set”).

  • — Device not available (#NM), if an MMX instruction is executed when the TS flag in control register CR0 is set. (See Section 13.5.1, “Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 State.”)
  • Floating-point error (#MF). (See Section 12.5.1, “Effect of MMX Instructions on Pending x87 Floating-Point Exceptions.”)
  • Other exceptions can occur indirectly due to the faulty execution of the exception handlers for the above exceptions.

12.5.1 Effect of MMX Instructions on Pending x87 Floating-Point Exceptions

If an x87 FPU floating-point exception is pending and the processor encounters an MMX instruction, the processor generates a x87 FPU floating-point error (#MF) prior to executing the MMX instruction, to allow the pending exception to be handled by the x87 FPU floating-point error exception handler. While this exception handler is executing, the x87 FPU state is maintained and is visible to the handler. Upon returning from the exception handler, the MMX instruction is executed, which will alter the x87 FPU state, as described in Section 12.2, “The MMX State and MMX Register Aliasing.”

12.6 DEBUGGING MMX CODE

The debug facilities operate in the same manner when executing MMX instructions as when executing other IA-32 or Intel 64 architecture instructions.

To correctly interpret the contents of the MMX or x87 FPU registers from the FSAVE/FNSAVE or FXSAVE image in memory, a debugger needs to take account of the relationship between the x87 FPU register’s logical locations relative to TOS and the MMX register’s physical locations.

In the x87 FPU context, STn refers to an x87 FPU register at location n relative to the TOS. However, the tags in the x87 FPU tag word are associated with the physical locations of the x87 FPU registers (R0 through R7). The MMX registers always refer to the physical locations of the registers (with MM0 through MM7 being mapped to R0 through R7). Figure 12-2 shows this relationship. Here, the inner circle refers to the physical location of the x87 FPU and MMX registers. The outer circle refers to the x87 FPU registers’s relative location to the current TOS.

When the TOS equals 0 (case A in Figure 12-2), ST0 points to the physical location R0 on the floating-point stack. MM0 maps to ST0, MM1 maps to ST1, and so on.

Page 573 of the Intel 253668-032US user manual — ST0 ST6
Page 573 · click to enlarge
Page 573

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

When the TOS equals 2 (case B in Figure 12-2), ST0 points to the physical location R2. MM0 maps to ST6, MM1 maps to ST7, MM2 maps to ST0, and so on.

x87 FPU “push” x87 FPU “pop” x87 FPU “push”

ST0 ST6

ST7

ST1

ST7

MM0

MM0

(R0)

(R0)

MM7

MM7

MM1

MM1

TOS TOS

MM2

MM6

MM2

ST0

MM6

(R2) (R2)

ST2

MM5

MM3

MM5

MM3

MM4

MM4

ST1

Case ATOS=0 Case B: TOS=2

Outer circle = x87 FPU data register’s logical location relative to TOS Inner circle = x87 FPU tags = MMX register’s location = FP registers’s physical location

Figure 12-2. Mapping of MMX Registers to x87 FPU Data Register Stack

x87 FPU “pop”

Page 574 of the Intel 253668-032US user manual — INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING
Page 574 · click to enlarge
Page 574

INTEL ® MMX ™ TECHNOLOGY SYSTEM PROGRAMMING

Page 575 of the Intel 253668-032US user manual — 13.1 PROVIDING OPERATING SYSTEM SUPPORT FOR SSE/SSE2/SSE3 / SSSE3/SSE4 EXTENSIONS
Page 575 · click to enlarge
Page 575

CHAPTER 13 SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR EXTENDED STATES

This chapter describes system programming features for instruction set extensions operating on the processor state extension known as the SSE state (XMM registers, MXCSR) and for processor extended states. Instruction set extensions operating on the SSE state include the streaming SIMD extensions (SSE), streaming SIMD exten sions 2 (SSE2), streaming SIMD extensions 3 (SSE3), Supplemental SSE3 (SSSE3), and SSE4.

Sections 13.1 through 13.5 cover system programming requirements to enable SSE/SSE2/SSE3/SSSE3/SSE4 extensions, providing operating system or executive support for the SSE/SSE2/SSE3/SSSE3/SSE4 extensions, SIMD floating-point exceptions, exception handling, and task (context) switching.

Operating system support for SSE state, once implemented using FXSAVE/FXRSTOR, provides a limited degree of forward support for subsequent instruction set exten sions operating on the same known set of processor state. Processor extended states refer to an extension in Intel 64 architecture that will allow system executives to implement support for multiple processor state extensions that may be introduced over time without requiring the system executive to be modified each time a new processor state extension is introduced.

  • Managing processor extended states requires the following aspects:
  • using instructions like XSAVE, XRSTOR, to save/restore state information to a memory region consistent with the processor state extensions supported in hardware,
  • using CPUID enumeration features to query the set of extended processor states supported by the processor,
  • using XSETBV instruction to enable individual processor state extensions,
  • maintaining various system programming resources.

System programming for managing processor extended states is described in the sections starting 13.6.

13.1 PROVIDING OPERATING SYSTEM SUPPORT FOR SSE/SSE2/SSE3 / SSSE3/SSE4 EXTENSIONS

To use SSE/SSE2/SSE3/SSSE3/SSE4 extensions, the operating system or executive must provide support for initializing the processor to use these extensions, for handling the FXSAVE and FXRSTOR state saving instructions, and for handling SIMD floating-point exceptions. The following sections provide system programming

Page 576 of the Intel 253668-032US user manual — 13.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Support
Page 576 · click to enlarge
Page 576

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

guidelines for this support. Because SSE/SSE2/SSE3/SSSE3/SSE4 extensions share the same state, experience the same sets of non-numerical and numerical exception behavior, these guidelines that apply to SSE also apply to other sets of SIMD exten sions that operate on the same processor state and subject to the same sets of of non-numerical and numerical exception behavior.

Chapter 11, “Programming with Streaming SIMD Extensions 2 (SSE2),” and Chapter 12, “Programming with SSE3, SSSE3 and SSE4,” in the Intel® 64 and IA-32 Archi tectures Software Developer’s Manual, Volume 1, discuss support for SSE/SSE2/SSE3/SSSE3/SSE4 from an applications point of view program.

13.1.1 Adding Support to an Operating System for SSE/SSE2/SSE3/SSSE3/SSE4 Extensions

The following guidelines describe functions that an operating system or executive must perform to support SSE/SSE2/SSE3/SSSE3/SSE4 extensions:

1. Check that the processor supports the SSE/SSE2/SSE3/SSSE3/SSE4 extensions.
2. Check that the processor supports the FXSAVE and FXRSTOR instructions.
3. Provide an initialization for the SSE, SSE2 SSE3, SSSE3 and SSE4 states.
4. Provide support for the FXSAVE and FXRSTOR instructions.
5. Provide support (if necessary) in non-numeric exception handlers for exceptions generated by the SSE, SSE2, SSE3 and SSE4 instructions.
6. Provide an exception handler for the SIMD floating-point exception (#XM).

The following sections describe how to implement each of these guidelines.

13.1.2 Checking for SSE/SSE2/SSE3/SSSE3/SSE4 Extension Support

If the processor attempts to execute an unsupported SSE/SSE2/SSE3/SSSE3/SSE4 instruction, the processor generates an invalid-opcode exception (#UD).

  • Before an operating system or executive attempts to use SSE/SSE2/SSE3/SSSE3/SSE4 extensions, it should check that support is present. Make sure:
  • CPUID.1:EDX.SSE[bit 25] = 1
  • CPUID.1:EDX.SSE2[bit 26] = 1
  • CPUID.1:ECX.SSE3[bit 0] = 1
  • CPUID.1:ECX.SSSE3[bit 9] = 1
  • CPUID.1:ECX.SSE4_1[bit 19] = 1
  • CPUID.1:ECX.SSE4_2[bit 20] = 1
Page 577 of the Intel 253668-032US user manual — NOTE
Page 577 · click to enlarge
Page 577

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

To use POPCNT instruction, software must check CPUID.1:ECX.POPCNT[bit 23] = 1

13.1.3 Checking for Support for the FXSAVE and FXRSTOR Instructions

A separate check must be made to insure that the processor supports FXSAVE and FXRSTOR. Make sure: • CPUID.1:EDX.FXSR[bit 24] = 1

13.1.4 Initialization of the SSE/SSE2/SSE3/SSSE3/SSE4 Extensions

The operating system or executive should carry out the following steps to set up SSE/SSE2/SSE3/SSSE3/SSE4 extensions for use by application programs:

1. Set CR4.OSFXSR[bit 9] = 1. Setting this flag assumes that the operating system provides facilities for saving and restoring SSE/SSE2/SSE3/SSSE3/SSE4 states using FXSAVE and FXRSTOR instructions. These instructions are commonly used to save the SSE/SSE2/SSE3/SSSE3/SSE4 state during task switches and when invoking the SIMD floating-point exception (#XM) handler (see Section 13.4, “Saving the SSE/SSE2/SSE3/SSSE3/SSE4 State on Task or Context Switches,” and Section 13.1.6, “Providing an Handler for the SIMD Floating-Point Exception (#XM),” respectively). If the processor does not support the FXSAVE and FXRSTOR instructions, attempting to set the OSFXSR flag will cause an exception (#GP) to be generated.

2. Set CR4.OSXMMEXCPT[bit 10] = 1. Setting this flag assumes that the operating system provides an SIMD floating-point exception (#XM) handler (see Section 13.1.6, “Providing an Handler for the SIMD Floating-Point Exception (#XM)”).

NOTE

The OSFXSR and OSXMMEXCPT bits in control register CR4 must be set by the operating system. The processor has no other way of detecting operating-system support for the FXSAVE and FXRSTOR instructions or for handling SIMD floating-point exceptions.

3. Clear CR0.EM[bit 2] = 0. This action disables emulation of the x87 FPU, which is required when executing SSE/SSE2/SSE3/SSSE3/SSE4 instructions (see Section 2.5, “Control Registers”).
4. Set CR0.MP[bit 1] = 1. This setting is the required setting for Intel 64 and IA-32 processors that support the SSE/SSE2/SSE3/SSSE3/SSE4 extensions (see Section 9.2.1, “Configuring the x87 FPU Environment”).

Table 13-1 and Table 13-2 show the actions of the processor when an SSE/SSE2/SSE3/SSSE3/SSE4 instruction is executed, depending on the:

Page 578 of the Intel 253668-032US user manual — SSE4_1 3
Page 578 · click to enlarge
Page 578

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

  • OSFXSR and OSXMMEXCPT flags in control register CR4
  • SSE/SSE2/SSE3/SSSE3/SSE4 feature flags returned by CPUID
  • EM, MP, and TS flags in control register CR0

Table 13-1. Action Taken for Combinations of OSFXSR, OSXMMEXCPT, SSE, SSE2,

SSE3, EM, MP, and TS1

CR4 CPUID CR0 Flags

OSFXSR OSXMMEXCPT SSE, SSE2, SSE3 2

EM MP 4 TS Action

SSE4_1 3

0 X5 X X 1 X #UD exception.

1 X 0 X 1 X #UD exception.

1 X 1 1 1 X #UD exception.

1 0 1 0 1 0 Execute instruction; #UD exception if unmasked SIMD floating-point exception is detected.

1 1 1 0 1 0 Execute instruction; #XM exception if unmasked SIMD floating-point exception is detected.

1 X 1 0 1 1 #NM exception.

NOTES: 1. For execution of any SSE/SSE2/SSE3 instruction except the PAUSE, PREFETCHh, SFENCE, LFENCE, MFENCE, MOVNTI, and CLFLUSH instructions. 2. Exception conditions due to CR4.OSFXSR or CR4.OSXMMEXCPT do not apply to FISTTP. 3. Only applies to DPPS, DPPD, ROUNDPS, ROUNDPD, ROUNDSS, ROUNDSD. 4. For processors that support the MMX instructions, the MP flag should be set. 5. X — Don’t care.

Page 579 of the Intel 253668-032US user manual — 13.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructions
Page 579 · click to enlarge
Page 579

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

Table 13-2. Action Taken for Combinations of OSFXSR, SSSE3, SSE4, EM, and TS

CR4 CPUID CR0 Flags

OSFXSR SSSE3 SSE4_1* SSE4_2**

0 X*** X X #UD exception.

1 0 X X #UD exception.

1 1 1 X #UD exception.

1 1 0 1 #NM exception.

The SIMD floating-point exception mask bits (bits 7 through 12), the flush-to-zero flag (bit 15), the denormals-are-zero flag (bit 6), and the rounding control field (bits 13 and 14) in the MXCSR register should be left in their default values of 0. This permits the application to determine how these features are to be used.

13.1.5 Providing Non-Numeric Exception Handlers for Exceptions Generated by the SSE/SSE2/SSE3/SSSE3/SSE4 Instructions

SSE/SSE2/SSE3/SSSE3/SSE4 instructions can generate the same type of memory access exceptions (such as, page fault, segment not present, and limit violations) and other non-numeric exceptions as other Intel 64 and IA-32 architecture instruc tions generate.

Ordinarily, existing exception handlers can handle these and other non-numeric exceptions without code modification. However, depending on the mechanisms used in existing exception handlers, some modifications might need to be made.

The SSE/SSE2/SSE3/SSSE3/SSE4 extensions can generate the non-numeric excep tions listed below: • Memory Access Exceptions:

— Invalid opcode (#UD).

— Stack-segment fault (#SS).

— General protection (#GP). Executing most SSE/SSE2/SSE3 instructions with an unaligned 128-bit memory reference generates a general-protection exception. (The MOVUPS and MOVUPD instructions allow unaligned a loads or stores of 128-bit memory locations, without generating a general-protection exception.) A 128-bit reference within the stack segment that is not aligned

EM TS Action

Page 580 of the Intel 253668-032US user manual — SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR
Page 580 · click to enlarge
Page 580

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

to a 16-byte boundary will also generate a general-protection exception, instead a stack-segment fault exception (#SS).

— Page fault (#PF).

  • — Alignment check (#AC). When enabled, this type of alignment check operates on operands that are less than 128-bits in size: 16-bit, 32-bit, and 64-bit. To enable the generation of alignment check exceptions, do the following:
  • Set the AM flag (bit 18 of control register CR0)
  • Set the AC flag (bit 18 of the EFLAGS register)
  • CPL must be 3

If alignment check exceptions are enabled, 16-bit, 32-bit, and 64-bit misalignment will be detected for the MOVUPD and MOVUPS instructions; detection of 128-bit misalignment is not guaranteed and may vary with implementation. • System Exceptions:

  • — Invalid-opcode exception (#UD). This exception is generated when executing SSE/SSE2/SSE3/SSSE3 instructions under the following conditions:
  • SSE/SSE2/SSE3/SSSE3/SSE4_1/SSE4_2 feature flags returned by CPUID are set to 0. This condition does not affect the CLFLUSH instruction, nor POPCNT.
  • The CLFSH feature flag returned by the CPUID instruction is set to 0. This exception condition only pertains to the execution of the CLFLUSH instruction.
  • The POPCNT feature flag returned by the CPUID instruction is set to 0. This exception condition only pertains to the execution of the POPCNT instruction.
  • The EM flag (bit 2) in control register CR0 is set to 1, regardless of the value of TS flag (bit 3) of CR0. This condition does not affect the PAUSE, PREFETCH h , MOVNTI, SFENCE, LFENCE, MFENSE, CLFLUSH, CRC32 and POPCNT instructions.
  • The OSFXSR flag (bit 9) in control register CR4 is set to 0. This condition does not affect the PAVGB, PAVGW, PEXTRW, PINSRW, PMAXSW, PMAXUB, PMINSW, PMINUB, PMOVMSKB, PMULHUW, PSADBW, PSHUFW, MASKMOVQ, MOVNTQ, MOVNTI, PAUSE, PREFETCH h , SFENCE, LFENCE, MFENCE, CLFLUSH, CRC32 and POPCNT instructions.
  • Executing a instruction that causes a SIMD floating-point exception when the OSXMMEXCPT flag (bit 10) in control register CR4 is set to 0. See Section 13.5.1, “Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 State.”
Page 581 of the Intel 253668-032US user manual — 13.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)
Page 581 · click to enlarge
Page 581

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

— Device not available (#NM). This exception is generated by executing a SSE/SSE2/SSE3/SSSE3/SSE4 instruction when the TS flag (bit 3) of CR0 is set to 1.

Other exceptions can occur indirectly due to faulty execution of the above exceptions.

13.1.6 Providing an Handler for the SIMD Floating-Point Exception (#XM)

  • SSE/SSE2/SSE3/SSSE3/SSE4 instructions do not generate numeric exceptions on packed integer operations. They can generate the following numeric (SIMD floatingpoint) exceptions on packed and scalar single-precision and double-precision floating-point operations.
  • Invalid operation (#I)
  • Divide-by-zero (#Z)
  • Denormal operand (#D)
  • Numeric overflow (#O)
  • Numeric underflow (#U)
  • Inexact result (Precision) (#P)

These SIMD floating-point exceptions (with the exception of the denormal operand exception) are defined in the IEEE Standard 754 for Binary Floating-Point Arithmetic and represent the same conditions that cause x87 FPU floating-point error excep tions (#MF) to be generated for x87 FPU instructions.

Each of these exceptions can be masked, in which case the processor returns a reasonable result to the destination operand without invoking an exception handler. However, if any of these exceptions are left unmasked, detection of the exception condition results in a SIMD floating-point exception (#XM) being generated. See Chapter 6, “Interrupt 19—SIMD Floating-Point Exception (#XM).”

To handle unmasked SIMD floating-point exceptions, the operating system or execu tive must provide an exception handler. The section titled “SSE and SSE2 SIMD Floating-Point Exceptions” in Chapter 11, “Programming with Streaming SIMD Extensions 2 (SSE2),” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, describes the SIMD floating-point exception classes and gives suggestions for writing an exception handler to handle them.

To indicate that the operating system provides a handler for SIMD floating-point exceptions (#XM), the OSXMMEXCPT flag (bit 10) must be set in control register CR0.

Page 582 of the Intel 253668-032US user manual — 13.3 SAVING AND RESTORING THE SSE/SSE2/SSE3/SSSE3/SSE4 STATE
Page 582 · click to enlarge
Page 582

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

13.1.6.1 Numeric Error flag and IGNNE#

SSE/SSE2/SSE3/SSE4 extensions ignore the NE flag in control register CR0 (that is, treats it as if it were always set) and the IGNNE# pin. When an unmasked SIMD floating-point exception is detected, it is always reported by generating a SIMD floating-point exception (#XM).

13.2 EMULATION OF SSE/SSE2/SSE3/SSSE3/SSE4 EXTENSIONS

The Intel 64 and IA-32 architecture does not support emulation of the SSE/SSE2/SSE3/SSSE3/SSE4 instructions, as they do for x87 FPU instructions.

The EM flag in control register CR0 (provided to invoke emulation of x87 FPU instruc tions) cannot be used to invoke emulation of SSE/SSE2/SSE3/SSSE3/SSE4 instruc tions. If an SSE/SSE2/SSE3/SSSE3/SSE4 instruction is executed when CR0.EM = 1, an invalid opcode exception (#UD) is generated. See Table 13-1.

13.3 SAVING AND RESTORING THE SSE/SSE2/SSE3/SSSE3/SSE4 STATE

  • The SSE/SSE2/SSE3/SSSE3/SSE4 state consists of the state of the XMM and MXCSR registers. The recommended method for saving and restoring this state follows:
  • Execute an FXSAVE instruction to save the state of the XMM and MXCSR registers to memory.
  • Execute an FXRSTOR instruction to restore the state of the XMM and MXCSR registers from the image saved in memory by the FXSAVE instruction.

This save and restore method is required for all operating systems. See Section 13.5, “Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switches.”

  • In some cases, applications can only save the XMM and MXCSR registers in the following way:
  • Execute MOVDQ instructions to save the contents of each XMM registers to memory.
  • Execute a STMXCSR instruction to save the state of the MXCSR register to memory.

In some cases, applications can only restore the XMM and MXCSR registers in the following way: • Execute MOVDQ instructions to read the saved contents of each XMM registers from memory to XMM registers.

Page 583 of the Intel 253668-032US user manual — 13.4 SAVING THE SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON TASK OR CONTEXT SWITCHES
Page 583 · click to enlarge
Page 583

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

  • Execute a LDMXCSR instruction to restore the state of the MXCSR register from memory.

13.4 SAVING THE SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON TASK OR CONTEXT SWITCHES

When switching from one task or context to another, it is often necessary to save the SSE/SSE2/SSE3/SSSE3/SSE4 state. FXSAVE and FXRSTOR instructions provide a simple method for saving and restoring this state. See Section 13.3, “Saving and Restoring the SSE/SSE2/SSE3/SSSE3/SSE4 State.” These instructions offer the added benefit of saving x87 FPU and MMX state as well.

Guidelines for writing such procedures are in Section 13.5, “Designing OS Facilities for AUTOMATICALLY Saving x87 FPU, MMX, and SSE/SSE2/SSE3/SSSE3/SSE4 state on Task or Context Switches.”

13.5 DESIGNING OS FACILITIES FOR AUTOMATICALLY SAVING X87 FPU, MMX, AND SSE/SSE2/SSE3/SSSE3/SSE4 STATE ON TASK OR CONTEXT SWITCHES

The x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state consist of the state of the x87 FPU, MMX, XMM, and MXCSR registers. The FXSAVE and FXRSTOR instructions provide a fast method for saving ad restoring this state. If task or context switching facilities are already implemented in an operating system or executive and they use FSAVE/FNSAVE and FRSTOR to save the x87 FPU and MMX state, these facilities can be extended to save and restore SSE/SSE2/SSE3/SSSE3/SSE4 state by substituting FXSAVE/FXRSTOR for FSAVE/FNSAVE and FRSTOR.

  • Where task or content switching facilities must be written from scratch, several approaches can be taken for using the FXSAVE and FXRSTOR instructions to save and restore x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state:
  • The operating system can require applications that are intended be run as tasks take responsibility for saving the state of the x87 FPU, MMX, XMM, and MXCSR registers prior to a task suspension during a task switch and for restoring the registers when the task is resumed. This approach is appropriate for cooperative multitasking operating systems, where the application has control over (or is able to determine) when a task switch is about to occur and can save state prior to the task switch.
  • The operating system can take the responsibility for automatically saving the x87 FPU, MMX, XMM, and MXCSR registers as part of the task switch process (using an FXSAVE instruction) and automatically restoring the state of the registers
Page 584 of the Intel 253668-032US user manual — NOTE
Page 584 · click to enlarge
Page 584

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

when a suspended task is resumed (using an FXRSTOR instruction). Here, the x87 FPU/MMX/SSE/SSE2/SSE3/SSE4 state must be saved as part of the task state. This approach is appropriate for preemptive multitasking operating systems, where the application cannot know when it is going to be preempted and cannot prepare in advance for task switching. Here, the operating system is responsible for saving and restoring the task and the x87 FPU/MMX/SSE/SSE2/SSE3 state when necessary. • The operating system can take the responsibility for saving the x87 FPU, MMX, XMM, and MXCSR registers as part of the task switch process, but delay the saving of the MMX and x87 FPU state until an x87 FPU, MMX, or SSE/SSE2/SSE3/SSSE3/SSE4 instruction is actually executed by the new task. Using this approach, the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state is saved only if an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction needs to be executed in the new task. (See Section 13.5.1, “Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 State,” for more information.)

13.5.1 Using the TS Flag to Control the Saving of the x87 FPU, MMX, SSE, SSE2, SSE3 SSSE3 and SSE4 State

Saving the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state using FXSAVE requires processor overhead. If the new task does not access x87 FPU, MMX, XMM, and MXCSR registers, avoid overhead by not automatically saving the state on a task switch.

The TS flag in control register CR0 is provided to allow the operating system to delay saving the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state until an instruction that actually accesses this state is encountered in a new task. When the TS flag is set, the processor monitors the instruction stream for an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction. When the processor detects one of these instructions, it raises a device-not-available exception (#NM) prior to executing the instruction. The device-not-available exception handler can then be used to save the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state for the previous task (using an FXSAVE instruction) and load the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state for the current task (using an FXRSTOR instruction). If the task never encounters an x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 instruction, the device-not-available excep tion will not be raised and a task state will not be saved unnecessarily.

NOTE

The CRC32 and POPCNT instructions do not operate on the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state. They operate on the general-purpose registers and are not involved in the OS’s lazy FXSAVE/FXRSTOR technique.

Page 585 of the Intel 253668-032US user manual — XMM/MXCSR
Page 585 · click to enlarge
Page 585

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

The TS flag can be set either explicitly (by executing a MOV instruction to control register CR0) or implicitly (using the IA-32 architecture’s native task switching mech anism). When the native task switching mechanism is used, the processor automati cally sets the TS flag on a task switch. After the device-not-available handler has saved the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state, it should execute the CLTS instruction to clear the TS flag.

Figure 13-1 gives an example of an operating system that implements x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state saving using the TS flag. In this example, task A is the currently running task and task B is the new task. The oper ating system maintains a save area for the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state for each task and defines a variable (x87_MMX_SSE_SSE2_SSE3_StateOwner) that indicates the task that “owns” the state. In this example, task A is the current owner.

On a task switch, the operating system task switching code must execute the following pseudo-code to set the TS flag according to the current owner of the x87 FPU/MMX/SSE/SSE2/SSE3/SSSE3/SSE4 state. If the new task (task B in this example) is not the current owner of this state, the TS flag is set to 1; otherwise, it is set to 0.

Task A Task B

Owner of x87 FPU,

MMX, XMM,

CR0.TS=1 and x87 FPU MMX, SSEx Instruction is encountered

Task B x87 FPU/MMX/

XMM/MXCSR

XMM/MXCSR

Operating System Task Switching Code

Loads Task B x87 FPU/MMX/ XMM/MXCSR State

Saves Task A x87 FPU/MMX/ XMM/MXCSR State

Figure 13-1. Example of Saving the x87 FPU, MMX, SSE, SSE2, SSE3, and SSSE3

State During an Operating-System Controlled Task Switch

IF Task_Being_Switched_To ≠ x87FPU_MMX_XMM_MXCSR_StateOwner THEN CR0.TS ← 1; ELSE CR0.TS ← 0; FI;

Show 9 more labels / short text on this page
Application · MXCSR State · Operating System · Task A · x87 FPU/MMX/ · State Save Area · State Save Area · Device-Not-Available · Exception Handler
Page 586 of the Intel 253668-032US user manual — 13.6 XSAVE/XRSTOR AND PROCESSOR EXTENDED STATE MANAGEMENT
Page 586 · click to enlarge
Page 586

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

If a new task attempts to access an x87 FPU, MMX, XMM, or MXCSR register while the TS flag is set to 1, a device-not-available exception (#NM) is generated. The device- not-available exception handler executes the following pseudo-code.

FXSAVE “To x87FPU/MMX/XMM/MXCSR State Save Area for Current

x87FPU_MMX_XMM_MXCSR_StateOwner”; FXRSTOR “x87FPU/MMX/XMM/MXCSR State From Current Task’s

x87FPU/MMX/XMM/MXCSR State Save Area”; x87FPU_MMX_XMM_MXCSR_StateOwner ← Current_Task; CR0.TS ← 0;

  • This exception handler code performs the following tasks:
  • Saves the x87 FPU, MMX, XMM, or MXCSR registers in the state save area for the current owner of the x87 FPU/MMX/XMM/MXCSR state.
  • Restores the x87 FPU, MMX, XMM, or MXCSR registers from the new task’s save area for the x87 FPU/MMX/XMM/MXCSR state.
  • Updates the current x87 FPU/MMX/XMM/MXCSR state owner to be the current task.
  • Clears the TS flag.

13.6 XSAVE/XRSTOR AND PROCESSOR EXTENDED STATE MANAGEMENT

The features associated with managing processor extended states include • An extensible data layout for existing and future processor state extensions. The layout of the XSAVE/XRSTOR area extends from the 512-byte FXSAVE/FXRSTOR layout to provide compatibility and migration path from managing the legacy FXSAVE/FXRSTOR area. Specifically, the XSAVE/XRSTOR area layout consists of:

— The FXSAVE/FXRSTOR area (512 bytes, the layout is identical to the FXSAVE/FXRSTOR area),

— The XSAVE header area (64 bytes),

— A finite set of save areas, each corresponding to a processor extended state (see Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B, XSAVE instruction). The number of save areas, the offset and the size of each save area is enumerated by CPUID leaf function 0DH. • CPUID Enhancement: CPUID instruction provides information on

— CPUID.01H.ECX.XSAVE[bit 26]. A feature flag indicating the processor’s support of XSAVE/XRSTOR architecture extensions

— CPUID.01H.ECX.OSXSAVE[bit 27]. A feature flag indicating whether OS has enabled extensible state management and communicating that the OS supports processor extended state management.

Page 587 of the Intel 253668-032US user manual — 13.6.1 XSAVE Header
Page 587 · click to enlarge
Page 587

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

  • — CPUID leaf function 0DH enumerates the list of processor states (including legacy x87 FPU, SSE states and processor extended states), the offset and size of individual save area for each processor extended state.
  • Control register enhancement and dedicated register for enabling each processor extended state: CR4. OSXSAVE[bit 18] and the XFEATURE_ENABLED_MASK register (XCR0) are described in Chapter 2, “System Architecture Overview”. XCR0 can be read at all privilege levels but written only at ring 0.
  • Instructions to manage the XFEATURE_ENABLED_MASK register (XCR0) and the XSAVE/XRSTOR area (see Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B ):

— XGETBV: reads XCR0.

— XSETBV: writes to XCR0, ring 0 only.

— XRSTOR: restores from memory the processor states specified by a bit vector mask specified in EDX:EAX.

— XSAVE: saves the current processor states to memory according to a bit vector mask in EDX:EAX.

13.6.1 XSAVE Header

The header section includes a “XSTATE_BV“ bit vector field. If the value of a bit in HEADER.XSTATE_BV is 1, it indicates that the corresponding processor extended state was written to the respective save area in memory by the XSAVE instruction.

If software modifies the save area image of a particular processor state component directly, it is responsible to update the corresponding bit in HEADER.XSTATE_BV to 1. Otherwise, directly modified state information in a save area image may be ignored by XRSTOR.

The order of bit vectors in XSTATE_BV matches those of the XFEATURE_ENABLED_MASK register (XCR0). Although XCR0 has only two bits initially defined for state management, the general relationship between the value of XSTATE_BV and the corresponding processor state in the XSAVE/XRSTOR layout is depicted in Figure 13-2.

Page 588 of the Intel 253668-032US user manual — FXSAVE
Page 588 · click to enlarge
Page 588

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

1 0 Bit Position

0 1 2 4 3

FXSAVE

FXRSTOR

XState_BV, .. Header

Figure 13-2. Future Layout of XSAVE/XRSTOR Area and XSTATE_BV with Five Sets

of Processor State Extensions

The XSAVE header is 64 bytes in length and must be aligned on 64 byte boundary. Therefore, the XSAVE/XRSTOR region must be aligned on 64-byte boundary. The format of the header is as follows (see Table 13-3):

Table 13-3. XSAVE Header Format

15:8 7:0 Byte Offset

Reserved (Must be zero) XSTATE_BV 0

Reserved Reserved (Must be zero) 16

The value of each bit in HEADER.XSTATE_BV may affect the action performed by XRSTOR, depending on the logical value of the respective bits in the XFEATURE_ENABLED_MASK register (XCR0), the restore bit mask (EDX:EAX input to XRSTOR), and HEADER.XSTATE_BV. When an XRSTOR instruction is executed with a restore bit mask selecting the i’th bit vector (and the corresponding XCR0 bit is

Show 14 more labels / short text on this page
XState_BV · Extensions 3 · X87 FPU State · SSE State · Save Area · Extensions 2 · Extensions 4 · Updated · Ext_SaveArea2 · Not updated · Ext_SaveArea3 · Updated Ext_SaveArea4 · Reserved Reserved 32 · Reserved Reserved 48
Page 589 of the Intel 253668-032US user manual — 13.7 INTEROPERABILITY OF XSAVE/XRSTOR AND FXSAVE/FXRSTOR
Page 589 · click to enlarge
Page 589

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

enabled), a value of "1" in the corresponding bit of HEADER.XSTATE_BV causes the processor state to be updated with contents of the save area read from the memory image. A value of "0" in HEADER.XSTATE_BV causes the processor state to be initial ized by hardware supplied values instead of from memory (See the operation detail of XRSTOR in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B).

The save area image corresponding to a bit with "0" value in HEADER.XSTATE_BV may or may not contain the correct state information. XRSTOR will ensure the register state for a component is properly initialized regardless of the value of the save area when the component header bit is zero.

13.7 INTEROPERABILITY OF XSAVE/XRSTOR AND FXSAVE/FXRSTOR

FXSAVE instruction writes x87 FPU and SSE state information to a 512-byte FXSAVE, FXRSTOR save area. FXRSTOR restores the processor’s x87 FPU and SSE states from FXSAVE/FXRSTOR save area image. XSAVE/XRSTOR instructions support x87 FPU and SSE states using the same layout as the FXSAVE/FXRSTOR area to provide interoperability of FXSAVE versus XSAVE, and FXRSTOR versus XRSTOR. XSAVE/XRSTOR provides the additional flexibility for system software to manage SSE state independent of x87 FPU states. Thus system software that had been using FXSAVE/FXRSTOR to manage x87 FPU and SSE states can transition to XSAVE/XRSTOR to manage x87 FPU, SSE and other processor extended states in a systematic and forward-looking manner.

It is also possible for system software to adopt an alternate approach of using FXSAVE/FXRSTOR for x87 and SSE state management, and implementing forward processor extended state management using XSAVE/XRSTOR. In this case, system software must specify the bit vector mask in EDX:EAX appropriately when executing XSAVE/XRSTOR instructions.

For instance, when using the XSAVE instruction, the OS can supply a bit vector in EDX:EAX with the two least significant bits corresponding to x87 FPU and SSE state equal to 0. Then, the XSAVE instruction will not write the processor’s x87 FPU and SSE state into memory. Similarly for the XRSTOR instruction a bit vector mask in EDX:EAX with the least two significant bit equal to 0 will cause the XRSTOR instruc tion to not restore nor initialize the processor’s x87 FPU and SSE state.

The processor’s action as a result of executing XRSTOR, on the x87 FPU state, MXCSR, and XMM registers, are listed in Table 13-4 (Both bit 1 and bit 0 of the XFEATURE_ENABLED_MASK register are presumed to be 1). The x87 FPU or XMM registers may be initialized by the processor (See XRSTOR operation in Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B). When the MXCSR register is updated from memory, reserved bit checking is enforced. The saving/restoring of MXCSR is bound to the SSE state, independent of the x87 FPU state. The action of XSAVE is listed in Table 13-5.

Page 590 of the Intel 253668-032US user manual — EDX:EAX XCR0 1
Page 590 · click to enlarge
Page 590

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

Table 13-4. XRSTOR Action on MXCSR, x87 FPU, XMM Register

EDX:EAX XSTATE_BV MXCSR XMM Registers x87 FPU State

Bit 1 Bit 0 Bit 1 Bit 0

0 0 X X None None None

0 1 X 0 None None Init by processor

0 1 X 1 None None Load

1 0 0 X Load/Check Init by processor None

1 0 1 X Load/Check Load None

1 1 0 0 Load/Check Init by processor Init by processor

1 1 0 1 Load/Check Init by processor Load

1 1 1 0 Load/Check Load Init by processor

1 Load/Check Load Load

Table 13-5. XSAVE Action on MXCSR, x87 FPU, XMM Register

EDX:EAX XCR0 1

MXCSR XMM Registers x87 FPU State

Bit 1 Bit 0 Bit 1 Bit 0

0 0 X 1 None None None

0 1 X 1 None None Store

1 0 0 1 None None None

1 0 1 1 Store Store None

1 1 0 1 None None Store

1 Store Store Store

XSAVE, XRSTOR instructions operating on FP or SSE state will cause a #NM Device Not Available) exception, if CR0.TS is set. Using this feature, system software can implement the “lazy restore” technique of managing x87 FPU/SSE state using either FXSAVE/FXRSTOR or XSAVE/XRSTOR. It can be accomplished even with the inter- mixing of FXSAVE and XSAVE instructions.

Page 591 of the Intel 253668-032US user manual — CPUID.1H:ECX.XSAVE?
Page 591 · click to enlarge
Page 591

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

13.8 DETECTION, ENUMERATION, ENABLING PROCESSOR EXTENDED STATE SUPPORT

An OS can determine if the XSAVE/XRSTOR/XGETBV/XSETBV instructions and the XFEATURE_ENABLED_MASK register (XCR0) are available in the processor by checking the value of CPUID.1.ECX.XSAVE to be 1. The OS must set CR4.OSXSAVE to 1 to enable the new instructions. The OS uses XSETBV to enable the processor state component (setting the corresponding bit in XCR0 to 1) that it will manage using XSAVE/XRSTOR. Bit 0 of XCR0 must be set to 1. The value of CR4.OSXSAVE is reflected in CPUID.01H:ECX.OSXSAVE (bit 27) to communicate the setting to non- privileged software.

CPUID.1H:ECX.XSAVE?

HW support XSAVE, XRSTOR, XSETBV, XFEM

Extended state features Buffer size requirement

Clear buffer to 0

Set valid bits in XCR0 via XSETBV Set CR4.OSXSAVE

Figure 13-3. OS Enabling of Processor Extended State Support

  • The bits that must be enabled in the XFEATURE_ENABLED_MASK register (XCR0) and the size of the memory region needed to save processor extended state informa tion must be enumerated by CPUID leaf 0DH with ECX = 0 as input. However, the recommended usage by system software to use XSAVE/XRSTOR is to:
  • Allocate a memory buffer according to the size reported by CPUID.(EAX=0DH, ECX=0H):ECX. The value reported by CPUID.(EAX=0DH, ECX=0H):ECX always includes the size of the header. Clear the entire buffer prior to being used by XSAVE.
  • Provide EDX:EAX with all bits set to 1 for XSAVE and XRSTOR instructions.

An alternative approach is to read the master bit vector mask EDX:EAX reported by CPUID.(EAX=0D, ECX=0H). This mask may be used as input to the XSAVE/XRSTOR

Show 4 more labels / short text on this page
Check · Enumerate · XSETBV enabled · to 1
Page 592 of the Intel 253668-032US user manual — 13.8.1 Application Programming Model and Processor Extended States
Page 592 · click to enlarge
Page 592

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

instructions, and provides a more constrained list of features than using all 1's in the save mask.

The advantage of using a mask value of all-bits-set-to-1 for XSAVE/XRSTOR is that it can simplify system software’s support for processor extended state management, when multiple generations of hardware may support different number of processor extended states as reported by CPUID. However, there may be additional implemen tation requirement of software modification that may arise due to a particular system software or specific details introduced by a new processor extended state.

13.8.1 Application Programming Model and Processor Extended States

New instruction set extensions may be introduced over time and operating on a processor extended state that must be enabled in the XFEATURE_ENABLED_MASK register (XCR0). The general application programming model for using such instruc tion set extensions are: • Check if OS has enabled processor extended state management. If CPUID.01H:ECX.OSXSAVE is 1, the OS has enabled the XSAVE/XRSTOR/XSETBV/XGETBV instructions and the XFEATURE_ENABLED_MASK register, and it has indicated support for the processor extended state management.

  • Applications do not need to check the value of CPUID.01H:ECX.XSAVE because “CPUID.01H:ECX.OSXSAVE = 1” implies OS has successfully verified CPUID.01H:ECX.XSAVE = 1. CPUID.01H:ECX.OSXSAVE reflects the value of CR4.OSXSAVE, and this bit cannot be set to 1 unless CPUID.01H:ECX.XSAVE = 1.
  • Check whether the processor extended state component associated with a given instruction set extension is enabled by the OS. The bits of EDX:EAX returned by XGETBV as 1 indicate which processor extended state components have been enabled by OS. Note, the CR4.OSFXSR is not used by OS to enable instruction extensions requiring processor extended state support.
  • Check the target instruction set extension is supported in the processor. Each new instruction set extension is expected to provide a feature flag in CPUID when it is introduced.
Page 593 of the Intel 253668-032US user manual — XSAVE, XRSTOR, XGETBV, XCR0
Page 593 · click to enlarge
Page 593

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND

CPUID.1H:ECX.OXSAVE = 1?

Implied HW support for

XSAVE, XRSTOR, XGETBV, XCR0

Check enabled state in

State ok to use

Figure 13-4. Application Detection of New Instruction Extensions and Processor

If all three requirements are met, applications can use the target new instruction set extensions. If any of the above requirements are not met, an attempt to execute an instruction operating on a processor extended state corresponding to bit offset higher than 1 in the XFEATURE_ENABLED_MASK register (XCR0) will cause a #UD exception.

Newer instruction extensions operating on SSE state, but not on any processor extended states corresponding bits in XCR0 with an offset higher than 1, follow the programming model described by Section 13.1 through Section 13.5. XCR0 is not required to enable OS support for SSE state management, but CR4.OSFXSR is required.

Show 9 more labels / short text on this page
Check feature flag · OS provides processor · extended state management · Yes · Check feature flag · for Instruction set · XCR0 via XGETBV · enabled Instructions · Extended State
Page 594 of the Intel 253668-032US user manual — SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR
Page 594 · click to enlarge
Page 594

SYSTEM PROGRAMMING FOR INSTRUCTION SET EXTENSIONS AND PROCESSOR

Page 595 of the Intel 253668-032US user manual — 14.1.1 Software Interface For Initiating Performance State Transitions
Page 595 · click to enlarge
Page 595

CHAPTER 14 POWER AND THERMAL MANAGEMENT

This chapter describes facilities of Intel 64 and IA-32 architecture used for power management and thermal monitoring.

14.1 ENHANCED INTEL SPEEDSTEP ® TECHNOLOGY

Enhanced Intel SpeedStep® Technology was introduced in the Pentium M processor; it is available in Pentium 4, Intel Xeon, Intel® Core™ Solo, Intel® Core™ Duo, Intel® Atom™ and Intel® Core™2 Duo processors. The technology manages processor power consumption using performance state transitions. These states are defined as discrete operating points associated with different frequencies.

  • Enhanced Intel SpeedStep Technology differs from previous generations of Intel SpeedStep Technology in two ways:
  • Centralization of the control mechanism and software interface in the processor by using model-specific registers.
  • Reduced hardware overhead; this permits more frequent performance state transitions.

Previous generations of the Intel SpeedStep Technology require processors to be a deep sleep state, holding off bus master transfers for the duration of a performance state transition. Performance state transitions under the Enhanced Intel SpeedStep Technology are discrete transitions to a new target frequency.

Support is indicated by CPUID, using ECX feature bit 07. Enhanced Intel SpeedStep Technology is enabled by setting IA32_MISC_ENABLE MSR, bit 16. On reset, bit 16 of IA32_MISC_ENABLE MSR is cleared.

14.1.1 Software Interface For Initiating Performance State Transitions

State transitions are initiated by writing a 16-bit value to the IA32_PERF_CTL register, see Figure 14-2. If a transition is already in progress, transition to a new value will subsequently take effect.

Reads of IA32_PERF_CTL determine the last targeted operating point. The current operating point can be read from IA32_PERF_STATUS. IA32_PERF_STATUS is updated dynamically.

The 16-bit encoding that defines valid operating points is model-specific. Applications and performance tools are not expected to use either IA32_PERF_CTL or IA32_PERF_STATUS and should treat both as reserved. Performance monitoring

Page 596 of the Intel 253668-032US user manual — 14.2 P-STATE HARDWARE COORDINATION
Page 596 · click to enlarge
Page 596

POWER AND THERMAL MANAGEMENT

tools can access model-specific events and report the occurrences of state transitions.

14.2 P-STATE HARDWARE COORDINATION

The Advanced Configuration and Power Interface (ACPI) defines performance states (P-state) that are used facilitate system software’s ability to manage processor power consumption. Different P-state correspond to different performance levels that are applied while the processor is actively executing instructions. Enhanced Intel SpeedStep Technology supports P-state by providing software interfaces that control the operating frequency and voltage of a processor.

With multiple processor cores residing in the same physical package, hardware dependencies may exist for a subset of logical processors on a platform. These dependencies may impose requirements that impact coordination of P-state transi tions. As a result, multi-core processors may require an OS to provide additional soft ware support for coordinating P-state transitions for those subsets of logical processors.

A BIOS (following ACPI 3.0 specification) can choose to expose P-state as dependent and hardware-coordinated to OS power management (OSPM) policy. To support OSPMs, multi-core processors must have additional built-in support for P-state hard ware coordination and feedback.

Intel 64 and IA-32 processors with dependent P-state amongst a subset of logical processors permit hardware coordination of P-state and provide a hardware-coordi nation feedback mechanism using IA32_MPERF MSR and IA32_APERF MSR. See Figure 14-1 for an overview of the two 64-bit MSRs and the bullets below for a detailed description:

IA32_MPERF (AddrE7H)
IA32_APERF (AddrE8H)

Figure 14-1. IA32_MPERF MSR and IA32_APERF MSR for P-state Coordination

  • Use CPUID to check the P-State hardware coordination feedback capability bit. CPUID.06H.ECX[Bit 0] = 1 indicates IA32_MPERF MSR and IA32_APERF MSR are present.
  • IA32_MPERF MSR (0xE7) increments in proportion to a fixed frequency, which is configured when the processor is booted.
Page 597 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 597 · click to enlarge
Page 597

POWER AND THERMAL MANAGEMENT

  • IA32_APERF MSR (0xE8) increments in proportion to actual performance, while accounting for hardware coordination of P-state and TM1/TM2; or software initiated throttling.
  • The MSRs are per logical processor; they measure performance only when the targeted processor is in the C0 state.
  • Only the IA32_APERF/IA32_MPERF ratio is architecturally defined; software should not attach meaning to the content of the individual of IA32_APERF or IA32_MPERF MSRs.
  • When either MSR overflows, both MSRs are reset to zero and continue to increment.
  • Both MSRs are full 64-bits counters. Each MSR can be written to independently. However, software should follow the guidelines illustrated in Example 14-1.

If P-states are exposed by the BIOS as hardware coordinated, software is expected to confirm processor support for P-state hardware coordination feedback and use the feedback mechanism to make P-state decisions. The OSPM is expected to either save away the current MSR values (for determination of the delta of the counter ratio at a later time) or reset both MSRs (execute WRMSR with 0 to these MSRs individually) at the start of the time window used for making the P-state decision. When not reset ting the values, overflow of the MSRs can be detected by checking whether the new values read are less than the previously saved values.

Example 14-1 demonstrates steps for using the hardware feedback mechanism provided by IA32_APERF MSR and IA32_MPERF MSR to determine a target P-state.

Example 14-1. Determine Target P-state From Hardware Coordinated Feedback

DWORD PercentBusy; // Percentage of processor time not idle.

// Measure “PercentBusy“ during previous sampling window. // Typically, “PercentBusy“ is measure over a time scale suitable for // power management decisions // // RDMSR of MCNT and ACNT should be performed without delay. // Software needs to exercise care to avoid delays between // the two RDMSRs (for example, interrupts). MCNT = RDMSR(IA32_MPERF); ACNT = RDMSR(IA32_APERF);

// PercentPerformance indicates the percentage of the processor // that is in use. The calculation is based on the PercentBusy, // that is the percentage of processor time not idle and the P-state // hardware coordinated feedback using the ACNT/MCNT ratio. // Note that both values need to be calculated over the same // time window.

PercentPerformance = PercentBusy * (ACNT/MCNT);

Page 598 of the Intel 253668-032US user manual — 14.3.2 System Software Interfaces for Opportunistic Processor Performance Operation
Page 598 · click to enlarge
Page 598

POWER AND THERMAL MANAGEMENT

// This example does not cover the additional logic or algorithms // necessary to coordinate multiple logical processors to a target P-state.

if (TargetPstate != currentPstate) {

SetPState(TargetPstate); } // WRMSR of MCNT and ACNT should be performed without delay. // Software needs to exercise care to avoid delays between // the two WRMSRs (for example, interrupts). WRMSR(IA32_MPERF, 0); WRMSR(IA32_APERF, 0);

14.3 SYSTEM SOFTWARE CONSIDERATIONS AND OPPORTUNISTIC PROCESSOR PERFORMANCE OPERATION

An Intel 64 processor may support a form of processor operation that takes advan tage of design headroom to opportunistically increase performance. In Intel Core i7 processors, Intel Turbo Boost Technology can convert thermal headroom into higher performance across multi-threaded and single-threaded workloads. In Intel Core 2 processors, Intel Dynamic Acceleration can convert thermal headroom into higher performance if only one thread is active.

14.3.1 Intel Dynamic Acceleration

Intel Core 2 Duo processor T 7700 introduces Intel Dynamic Acceleration (IDA). IDA takes advantage of thermal design headroom and opportunistically allows a single core to operate at a higher performance level when the operating system requests increased performance.

14.3.2 System Software Interfaces for Opportunistic Processor Performance Operation

Opportunistic processor operation, applicable to Intel Dynamic Acceleration and Intel Turbo Boost Technology, has the following characteristics: • A transition from a normal state of operation (e.g. IDA/Turbo mode disengaged) to a target state is not guaranteed, but may occur opportunistically after the

TargetPstate = FindPstate(PercentPerformance);

Page 599 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 599 · click to enlarge
Page 599

POWER AND THERMAL MANAGEMENT

  • corresponding enable mechanism is activated, the headroom is available and certain criteria are met.
  • The opportunistic processor performance operation is generally transparent to most application software.
  • System software (BIOS and Operating system) must be aware of hardware support for opportunistic processor performance operation and may need to temporarily disengage opportunistic processor performance operation when it requires more predictable processor operation.
  • When opportunistic processor performance operation is engaged, the OS should use hardware coordination feedback mechanisms to prevent un-intended policy effects if it is activated during inappropriate situations.

14.3.2.1 Discover Hardware Support and Enabling of Opportunistic Processor Operation

If an Intel 64 processor has hardware support for opportunistic processor perfor mance operation, the power-on default state of IA32_MISC_ENABLES[38] indicates the presence of such hardware support. For Intel 64 processors that support oppor tunistic processor performance operation, the default value is 1, indicating its pres ence. For processors that do not support opportunistic processor performance operation, the default value is 0. The power-on default value of IA32_MISC_ENABLES[38] allows BIOS to detect the presence of hardware support of opportunistic processor performance operation.

IA32_MISC_ENABLES[38] is shared across all logical processors in a physical package. It is written by BIOS during platform initiation to enable/disable opportu nistic processor operation in conjunction of OS power management capabilities, see Section 14.3.2.2. BIOS can set IA32_MISC_ENABLES[38] with 1 to disable opportu nistic processor performance operation; it must clear the default value of IA32_MISC_ENABLES[38] to 0 to enable opportunistic processor performance oper ation. OS and applications must use CPUID leaf 06H if it needs to detect processors that has opportunistic processor operation enabled.

When CPUID is executed with EAX = 06H on input, Bit 1 of EAX in Leaf 06H (i.e. CPUID.06H:EAX[1]) indicates opportunistic processor performance operation, such as IDA, has been enabled by BIOS.

Opportunistic processor performance operation can be disabled by setting bit 38 of IA32_MISC_ENABLES. This mechanism is intended for BIOS only. If IA32_MISC_ENABLES[38] is set, CPUID.06H:EAX[1] will return 0.

14.3.2.2 OS Control of Opportunistic Processor Performance Operation

There may be phases of software execution in which system software cannot tolerate the non-deterministic aspects of opportunistic processor performance operation. For example, when calibrating a real-time workload to make a CPU reservation request

Page 600 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 600 · click to enlarge
Page 600

POWER AND THERMAL MANAGEMENT

to the OS, it may be undesirable to allow the possibility of the processor delivering increased performance that cannot be sustained after the calibration phase.

  • System software can temporarily disengage opportunistic processor performance operation by setting bit 32 of the IA32_PERF_CTL MSR (0199H), using a readmodify-write sequence on the MSR. The opportunistic processor performance opera tion can be re-engaged by clearing bit 32 in IA32_PERF_CTL MSR, using a readmodify-write sequence. The DISENAGE bit in IA32_PERF_CTL is not reflected in bit 32 of the IA32_PERF_STATUS MSR (0198H), and it is not shared between logical processors in a physical package. In order for OS to engage IDA/Turbo mode, the BIOS must
  • enable opportunistic processor performance operation, as described in Section 14.3.2.1,
  • expose the operating points associated with IDA/Turbo mode to the OS.

15 32 33 31

Figure 14-2. IA32_PERF_CTL Register

14.3.2.3 Required Changes to OS Power Management P-state Policy

Intel Dynamic Acceleration (IDA) and Intel Turbo Boost Technology can provide opportunistic performance greater than the performance level corresponding to the maximum qualified frequency of the processor (see CPUID’s brand string informa tion). System software can use a pair of MSRs to observe performance feedback. Software must query for the presence of IA32_APERF and IA32_MPERF (see Section 14.2). The ratio between IA32_APERF and IA32_MPERF is architecturally defined and a value greater than unity indicates performance increase occurred during the obser vation period due to IDA. Without incorporating such performance feedback, the target P-state evaluation algorithm can result in a non-optimal P-state target.

  • There are other scenarios under which OS power management may want to disable IDA, some of these are listed below:
  • When engaging ACPI defined passive thermal management, it may be more effective to disable IDA for the duration of passive thermal management.
  • When the user has indicated a policy preference of power savings over perfor mance, OS power management may want to disable IDA while that policy is in effect.

Reserved · IDA/Turbo DISENGAGE · EIST Transition Target

Page 601 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 601 · click to enlarge
Page 601

POWER AND THERMAL MANAGEMENT

14.3.2.4 Application Awareness of Opportunistic Processor Operation (Optional)

There may be situations that an end user or application software wishes to be aware of turbo mode activity. It is possible for an application-level utility to periodically check the occurrences of opportunistic processor operation. The basic elements of an algorithm is described below, using the characteristics of Intel Turbo Boost Tech nology as example.

Using an OS-provided timer service, application software can periodically calculate the ratio between unhalted-core-clockticks (UCC) relative to the unhalted-reference- clockticks (URC) on each logical processor to determine if that logical processor had been requested by OS to run at some frequency higher than the invariant TSC frequency, or the OS has determined system-level demand has reduced sufficiently to put that logical processor into a lower-performance p-state or even lower-activity state.

If an application software have access to information of the base operating ratio between the invariant TSC frequency and the base clock (133.33 MHz), it can convert the sampled ratio into a dynamic frequency estimate for each prior sampling period. The base operating ratio can be read from MSR_PLATFORM_INFO[15:8].

The periodic sampling technique is depicted in Figure 14-3 and described below:

Intel 253668-032US — POWER AND THERMAL MANAGEMENT diagram (page 601)
Fig. 35

Logical Processor i Turbo Activity Ratio = (UCCn+1, i - UCCn, i) / (URCn+1, i - URCn, i)

Figure 14-3. Periodic Query of Activity Ratio of Opportunistic Processor Operation

  • The sampling period chosen by the application (to program an OS timer service) should be sufficiently large to avoid excessive polling overhead to other applica tions or tasks managed by the OS.
Page 602 of the Intel 253668-032US user manual — 14.3.4 Performance and Energy Bias Hint support
Page 602 · click to enlarge
Page 602

POWER AND THERMAL MANAGEMENT

  • When the OS timer service transfers control, the application can use RDPMC (with ECX = 4000_0001H) to read IA32_PERF_FIXED_CTR1 (MSR address 30AH) to record the unhalted core clocktick (UCC) value; followed by RDPMC (ECX=4000_0002H) to read IA32_PERF_FIXED_CTR2 (MSR address 30BH) to record the unhalted reference clocktick (URC) value. This pair of values is needed for each logical processor for each sampling period.
  • The application can calculate the Turbo activity ratio based on the difference of UCC between each sample period, over the difference of URC difference. The effective frequency of each sample period of the logical processor, i , can be estimated by:

(UCCn+1, i - UCC n, i)/(URCn+1, i - URC n, i)* Base_operating_ratio* 133.33MHz

It is possible that the OS had requested a lower-performance P-state during a sampling period. Thus the ratio (UCCn+1, i - UCC n, i)/(URCn+1, i - URC n, i) can reflect the average of Turbo activity (driving the ratio above unity) and some lower P-state transitions (causing the ratio to be < 1).

It is also possible that the OS might requested C-state transitions when the demand is low. The above ratio generally does not account for cycles any logical processor was idle. On Intel Core i7 processors, an application can make use of the time stamp counter (IA-32_TSC) running at a constant frequency (i.e. Base_operating_ratio* 133.33MHz) during C-states. Thus software can calculate ratios that can indicate fractions of sample period spent in the C0 state, using the unhalted reference clock ticks and the invariant TSC. Note the estimate of fraction spent in C0 may be affected by SMM handler if the system software makes use of the “FREEZE_WHILE_SMM_EN“ capability to freeze performance counter values while the SMM handler is servicing an SMI (see Chapter 20, “Introduction to Virtual-Machine Extensions”).

14.3.3 Intel Turbo Boost Technology

Intel Turbo Boost Technology is supported in Intel Core i7 processors and Intel Xeon processors based on Intel microarchitecture (Nehalem). It uses the same principle of leveraging thermal headroom to dynamically increase processor performance for single-threaded and multi-threaded/multi-tasking environment. The programming interface described in Section 14.3.2 also applies to Intel Turbo Boost Technology.

14.3.4 Performance and Energy Bias Hint support

Intel 64 processors may support additional software hint to guide the hardware heuristic of power management features to favor increasing dynamic performance or conserve energy consumption.

Software can detect processor's capability to support performance-energy bias pref erence hint by examining bit 3 of ECX in CPUID leaf 6. The processor supports this capability if CPUID.06H:ECX.SETBH[bit 3] is set and it also implies the presence of a new architectural MSR called IA32_ENERGY_PERF_BIAS (1B0H).

Page 603 of the Intel 253668-032US user manual — 14.4 MWAIT EXTENSIONS FOR ADVANCED POWER MANAGEMENT
Page 603 · click to enlarge
Page 603

POWER AND THERMAL MANAGEMENT

Software can program the lowest four bits of IA32_ENERGY_PERF_BIAS MSR with a value from 0 - 15. The values represent a sliding scale, where a value of 0 (the default reset value) corresponds to a hint preference for highest performance and a value of 15 corresponds to the maximum energy savings. A value of 7 roughly trans lates into a hint to balance performance with energy consumption

Energy Policy Preference Hint

Figure 14-4. IA32_ENERGY_PERF_BIAS Register

The layout of IA32_ENERGY_PERF_BIAS is shown in Figure 14-4. The scope of IA32_ENERGY_PERF_BIAS is per logical processor, which means that each of the logical processors in the package can be programmed with a different value. This may be especially important in virtualization scenarios, where the performance / energy requirements of one logical processor may differ from the other. Conflicting "hints" from various logical processors at higher hierarchy level will be resolved in favor of performance over energy savings.

Software can use whatever criteria it sees fit to program the MSR with the appro priate value. However, the value only serves as a hint to the hardware and the actual impact on performance and energy savings is model specific.

14.4 MWAIT EXTENSIONS FOR ADVANCED POWER MANAGEMENT

IA-32 processors may support a number of C-states1 that reduce power consumption for inactive states. Intel Core Solo and Intel Core Duo processors support both deeper C-state and MWAIT extensions that can be used by OS to implement power management policy.

Software should use CPUID to discover if a target processor supports the enumera tion of MWAIT extensions. If CPUID.05H.ECX[Bit 0] = 1, the target processor supports MWAIT extensions and their enumeration (see Chapter 3, “Instruction Set

1. The processor-specific C-states defined in MWAIT extensions can map to ACPI defined C-state types (C0, C1, C2, C3). The mapping relationship depends on the definition of a C-state by proces sor implementation and is exposed to OSPM by the BIOS using the ACPI defined _CST table.

Reserved

Page 604 of the Intel 253668-032US user manual — 14.5 THERMAL MONITORING AND PROTECTION
Page 604 · click to enlarge
Page 604

POWER AND THERMAL MANAGEMENT

Reference, A-M,” of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A).

  • If CPUID.05H.ECX[Bit 1] = 1, the target processor supports using interrupts as break-events for MWAIT, even when interrupts are disabled. Use this feature to measure C-state residency as follows:
  • Software can write to bit 0 in the MWAIT Extensions register (ECX) when issuing an MWAIT to enter into a processor-specific C-state or sub C-state.
  • When a processor comes out of an inactive C-state or sub C-state, software can read a timestamp before an interrupt service routine (ISR) is potentially executed.

CPUID.05H.EDX allows software to enumerate processor-specific C-states and sub C-states available for use with MWAIT extensions. IA-32 processors may support more than one C-state of a given C-state type. These are called sub C-states. Numer ically higher C-state have higher power savings and latency (upon entering and exiting) than lower-numbered C-state.

At CPL = 0, system software can specify desired C-state and sub C-state by using the MWAIT hints register (EAX). Processors will not go to C-state and sub C-state deeper than what is specified by the hint register. If CPL > 0 and if MONITOR/MWAIT is supported at CPL > 0, the processor will only enter C1-state (regardless of the C-state request in the hints register).

Executing MWAIT generates an exception on processors operating at a privilege level where MONITOR/MWAIT are not supported.

NOTE

If MWAIT is used to enter a C-state (including sub C-state) that is numerically higher than C1, a store to the address range armed by MONITOR instruction will cause the processor to exit MWAIT if the store was originated by other processor agents. A store from non- processor agent may not cause the processor to exit MWAIT.

14.5 THERMAL MONITORING AND PROTECTION

The IA-32 architecture provides the following mechanisms for monitoring tempera ture and controlling thermal power:

1. The catastrophic shutdown detector forces processor execution to stop if the processor’s core temperature rises above a preset limit.
2. Automatic and adaptive thermal monitoring mechanism s force the processor to reduce it’s power consumption in order to operate within predeter mined temperature limits.
3. The software controlled clock modulation mechanism permits operating systems to implement power management policies that reduce power
Page 605 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 605 · click to enlarge
Page 605

POWER AND THERMAL MANAGEMENT

consumption; this is in addition to the reduction offered by automatic thermal monitoring mechanisms.

4. On-die digital thermal sensor and interrupt mechanisms permit the OS to manage thermal conditions natively without relying on BIOS or other system board components.

The first mechanism is not visible to software. The other three mechanisms are visible to software using processor feature information returned by executing CPUID with EAX = 1.

  • The second mechanism includes:
  • Automatic thermal monitoring provides two modes of operation. One mode modulates the clock duty cycle; the second mode changes the processor’s frequency. Both modes are used to control the core temperature of the processor.
  • Adaptive thermal monitoring can provide flexible thermal management on processors made of multiple cores.

The third mechanism modulates the clock duty cycle of the processor. As shown in Figure 14-5, the phrase ‘duty cycle’ does not refer to the actual duty cycle of the clock signal. Instead it refers to the time period during which the clock signal is allowed to drive the processor chip. By using the stop clock mechanism to control how often the processor is clocked, processor power consumption can be modulated.

Clock Applied to Processor

25% Duty Cycle (example only)

Figure 14-5. Processor Modulation Through Stop-Clock Mechanism

For previous automatic thermal monitoring mechanisms, software controlled mecha nisms that changed processor operating parameters to impact changes in thermal conditions. Software did not have native access to the native thermal condition of the processor; nor could software alter the trigger condition that initiated software program control.

The fourth mechanism (listed above) provides access to an on-die digital thermal sensor using a model-specific register and uses an interrupt mechanism to alert soft ware to initiate digital thermal monitoring.

Stop-Clock Duty Cycle

Page 606 of the Intel 253668-032US user manual — 14.5.2 Thermal Monitor
Page 606 · click to enlarge
Page 606

POWER AND THERMAL MANAGEMENT

14.5.1 Catastrophic Shutdown Detector

P6 family processors introduced a thermal sensor that acts as a catastrophic shut down detector. This catastrophic shutdown detector was also implemented in Pentium 4, Intel Xeon and Pentium M processors. It is always enabled. When processor core temperature reaches a factory preset level, the sensor trips and processor execution is halted until after the next reset cycle.

14.5.2 Thermal Monitor

Pentium 4, Intel Xeon and Pentium M processors introduced a second temperature sensor that is factory-calibrated to trip when the processor’s core temperature crosses a level corresponding to the recommended thermal design envelop. The trip- temperature of the second sensor is calibrated below the temperature assigned to the catastrophic shutdown detector.

14.5.2.1 Thermal Monitor 1

The Pentium 4 processor uses the second temperature sensor in conjunction with a mechanism called Thermal Monitor 1 (TM1) to control the core temperature of the processor. TM1 controls the processor’s temperature by modulating the duty cycle of the processor clock. Modulation of duty cycles is processor model specific. Note that the processors STPCLK# pin is not used here; the stop-clock circuitry is controlled internally.

Support for TM1 is indicated by CPUID.1:EDX.TM[bit 29] = 1.

TM1 is enabled by setting the thermal-monitor enable flag (bit 3) in IA32_MISC_ENABLE [see Appendix B, “Model-Specific Registers (MSRs)”]. Following a power-up or reset, the flag is cleared, disabling TM1. BIOS is required to enable only one automatic thermal monitoring modes. Operating systems and applications must not disable the operation of these mechanisms.

14.5.2.2 Thermal Monitor 2

An additional automatic thermal protection mechanism, called Thermal Monitor 2 (TM2), was introduced in the Intel Pentium M processor and also incorporated in newer models of the Pentium 4 processor family. Intel Core Duo and Solo processors, and Intel Core 2 Duo processor family all support TM1 and TM2. TM2 controls the core temperature of the processor by reducing the operating frequency and voltage of the processor and offers a higher performance level for a given level of power reduction than TM1.

TM2 is triggered by the same temperature sensor as TM1. The mechanism to enable TM2 may be implemented differently across various IA-32 processor families with different CPUID signatures in the family encoding value, but will be uniform within an IA-32 processor family.

Page 607 of the Intel 253668-032US user manual — TM_SELECT
Page 607 · click to enlarge
Page 607

POWER AND THERMAL MANAGEMENT

Support for TM2 is indicated by CPUID.1:ECX.TM2[bit 8] = 1.

14.5.2.3 Two Methods for Enabling TM2

On processors with CPUID family/model/stepping signature encoded as 0x69n or 0x6Dn (early Pentium M processors), TM2 is enabled if the TM_SELECT flag (bit 16) of the MSR_THERM2_CTL register is set to 1 (Figure 14-6) and bit 3 of the IA32_MISC_ENABLE register is set to 1.

Following a power-up or reset, the TM_SELECT flag may be cleared. BIOS is required to enable either TM1 or TM2. Operating systems and applications must not disable mechanisms that enable TM1 or TM2. If bit 3 of the IA32_MISC_ENABLE register is set and TM_SELECT flag of the MSR_THERM2_CTL register is cleared, TM1 is enabled.

TM_SELECT

Figure 14-6. MSR_THERM2_CTL Register On Processors with CPUID

Family/Model/Stepping Signature Encoded as 0x69n or 0x6Dn

On processors introduced after the Pentium 4 processor (this includes most Pentium M processors), the method used to enable TM2 is different. TM2 is enable by setting bit 13 of IA32_MISC_ENABLE register to 1. This applies to Intel Core Duo, Core Solo, and Intel Core 2 processor family.

The target operating frequency and voltage for the TM2 transition after TM2 is trig gered is specified by the value written to MSR_THERM2_CTL, bits 15:0 (Figure 14-7). Following a power-up or reset, BIOS is required to enable at least one of these two thermal monitoring mechanisms. If both TM1 and TM2 are supported, BIOS may choose to enable TM2 instead of TM1. Operating systems and applications must not disable the mechanisms that enable TM1or TM2; and they must not alter the value in bits 15:0 of the MSR_THERM2_CTL register.

Reserved · Reserved

Page 608 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 608 · click to enlarge
Page 608

POWER AND THERMAL MANAGEMENT

Figure 14-7. MSR_THERM2_CTL Register for Supporting TM2

14.5.2.4 Performance State Transitions and Thermal Monitoring

  • If the thermal control circuitry (TCC) for thermal monitor (TM1/TM2) is active, writes to the IA32_PERF_CTL will effect a new target operating point as follows:
  • If TM1 is enabled and the TCC is engaged, the performance state transition can commence before the TCC is disengaged.
  • If TM2 is enabled and the TCC is engaged, the performance state transition specified by a write to the IA32_PERF_CTL will commence after the TCC has disengaged.

14.5.2.5 Thermal Status Information

The status of the temperature sensor that triggers the thermal monitor (TM1/TM2) is indicated through the thermal status flag and thermal status log flag in the IA32_THERM_STATUS MSR (see Figure 14-8).

  • The functions of these flags are:
  • Thermal Status flag, bit 0 — When set, indicates that the processor core temperature is currently at the trip temperature of the thermal monitor and that the processor power consumption is being reduced via either TM1 or TM2, depending on which is enabled. When clear, the flag indicates that the core temperature is below the thermal monitor trip temperature. This flag is read only.
  • Thermal Status Log flag, bit 1 — When set, indicates that the thermal sensor has tripped since the last power-up or reset or since the last time that software cleared this flag. This flag is a sticky bit; once set it remains set until cleared by software or until a power-up or reset of the processor. The default state is clear.

Reserved · TM2 Transition Target

Page 609 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 609 · click to enlarge
Page 609

POWER AND THERMAL MANAGEMENT

Thermal Status Thermal Status Log

Figure 14-8. IA32_THERM_STATUS MSR

After the second temperature sensor has been tripped, the thermal monitor (TM1/TM2) will remain engaged for a minimum time period (on the order of 1 ms). The thermal monitor will remain engaged until the processor core temperature drops below the preset trip temperature of the temperature sensor, taking hysteresis into account.

While the processor is in a stop-clock state, interrupts will be blocked from inter rupting the processor. This holding off of interrupts increases the interrupt latency, but does not cause interrupts to be lost. Outstanding interrupts remain pending until clock modulation is complete.

The thermal monitor can be programmed to generate an interrupt to the processor when the thermal sensor is tripped. The delivery mode, mask and vector for this interrupt can be programmed through the thermal entry in the local APIC’s LVT (see Section 10.6.1, “Local Vector Table”). The low-temperature interrupt enable and high-temperature interrupt enable flags in the IA32_THERM_INTERRUPT MSR (see Figure 14-9) control when the interrupt is generated; that is, on a transition from a temperature below the trip point to above and/or vice-versa.

Figure 14-9. IA32_THERM_INTERRUPT MSR

  • High-Temperature Interrupt Enable flag, bit 0 — Enables an interrupt to be generated on the transition from a low-temperature to a high-temperature when set; disables the interrupt when clear.(R/W).
  • Low-Temperature Interrupt Enable flag, bit 1 — Enables an interrupt to be generated on the transition from a high-temperature to a low-temperature when set; disables the interrupt when clear.

The thermal monitor interrupt can be masked by the thermal LVT entry. After a power-up or reset, the low-temperature interrupt enable and high-temperature

Show 4 more labels / short text on this page
Reserved · Reserved · Low-Temperature Interrupt Enable · High-Temperature Interrupt Enable
Page 610 of the Intel 253668-032US user manual — 14.5.3 Software Controlled Clock Modulation
Page 610 · click to enlarge
Page 610

POWER AND THERMAL MANAGEMENT

interrupt enable flags in the IA32_THERM_INTERRUPT MSR are cleared (interrupts are disabled) and the thermal LVT entry is set to mask interrupts. This interrupt should be handled either by the operating system or system management mode (SMM) code.

14.5.2.6 Adaptive Thermal Monitor

The Intel Core 2 Duo processor family supports enhanced thermal management mechanism, referred to as Adaptive Thermal Monitor (Adaptive TM).

Unlike TM2, Adaptive TM is not limited to one TM2 transition target. During a thermal trip event, Adaptive TM (if enabled) selects an optimal target operating point based on whether or not the current operating point has effectively cooled the processor.

Similar to TM2, Adaptive TM is enable by BIOS. The BIOS is required to test the TM1 and TM2 feature flags and enable all available thermal control mechanisms (including Adaptive TM) at platform initiation.

Adaptive TM is available only to a subset of processors that support TM2.

In each chip-multiprocessing (CMP) silicon die, each core has a unique thermal sensor that triggers independently. These thermal sensor can trigger TM1 or TM2 transitions in the same manner as described in Section 14.5.2.1 and Section 14.5.2.2. The trip point of the thermal sensor is not programmable by software since it is set during the fabrication of the processor.

Each thermal sensor in a processor core may be triggered independently to engage thermal management features. In Adaptive TM, both cores will transition to a lower frequency and/or lower voltage level if one sensor is triggered.

Triggering of this sensor is visible to software via the thermal interrupt LVT entry in the local APIC of a given core.

14.5.3 Software Controlled Clock Modulation

Pentium 4, Intel Xeon and Pentium M processors also support software-controlled clock modulation. This provides a means for operating systems to implement a power management policy to reduce the power consumption of the processor. Here, the stop-clock duty cycle is controlled by software through the IA32_CLOCK_MODULATION MSR (see Figure 14-10).

Page 611 of the Intel 253668-032US user manual — 010B 25.0%
Page 611 · click to enlarge
Page 611

POWER AND THERMAL MANAGEMENT

On-Demand Clock Modulation Enable

On-Demand Clock Modulation Duty Cycle

Figure 14-10. IA32_CLOCK_MODULATION MSR

  • The IA32_CLOCK_MODULATION MSR contains the following flag and field used to enable software-controlled clock modulation and to select the clock modulation duty cycle:
  • On-Demand Clock Modulation Enable, bit 4 — Enables on-demand software controlled clock modulation when set; disables software-controlled clock modulation when clear.
  • On-Demand Clock Modulation Duty Cycle, bits 1 through 3 — Selects the on-demand clock modulation duty cycle (see Table 14-1). This field is only active when the on-demand clock modulation enable flag is set.

Table 14-1. On-Demand Clock Modulation Duty Cycle Field Encoding

Duty Cycle Field Encoding Duty Cycle

001B 12.5% (Default)

010B 25.0%

011B 37.5%

100B 50.0%

101B 63.5%

110B 75%

111B 87.5%

The on-demand clock modulation mechanism can be used to control processor power consumption. Power management software can write to the IA32_CLOCK_MODULATION MSR to enable clock modulation and to select a modula tion duty cycle. If on-demand clock modulation and TM1 are both enabled and the thermal status of the processor is hot (bit 0 of the IA32_THERM_STATUS MSR is set),

Reserved · Reserved · 000B Reserved

Page 612 of the Intel 253668-032US user manual — 14.5.5 On Die Digital Thermal Sensors
Page 612 · click to enlarge
Page 612

POWER AND THERMAL MANAGEMENT

clock modulation at the duty cycle specified by TM1 takes precedence, regardless of the setting of the on-demand clock modulation duty cycle.

For Hyper-Threading Technology enabled processors, the IA32_CLOCK_MODULATION register is duplicated for each logical processor. In order for the On-demand clock modulation feature to work properly, the feature must be enabled on all the logical processors within a physical processor. If the programmed duty cycle is not identical for all the logical processors, the processor clock will modu late to the highest duty cycle programmed.

For the P6 family processors, on-demand clock modulation was implemented through the chipset, which controlled clock modulation through the processor’s STPCLK# pin.

14.5.4 Detection of Thermal Monitor and Software Controlled Clock Modulation Facilities

The ACPI flag (bit 22) of the CPUID feature flags indicates the presence of the IA32_THERM_STATUS, IA32_THERM_INTERRUPT, IA32_CLOCK_MODULATION MSRs, and the xAPIC thermal LVT entry.

The TM1 flag (bit 29) of the CPUID feature flags indicates the presence of the auto matic thermal monitoring facilities that modulate clock duty cycles.

14.5.5 On Die Digital Thermal Sensors

On die digital thermal sensor can be read using an MSR (no I/O interface). In Intel Core Duo processors, each core has a unique digital sensor whose temperature is accessible using an MSR. The digital thermal sensor is the preferred method for reading the die temperature because (a) it is located closer to the hottest portions of the die, (b) it enables software to accurately track the die temperature and the potential activation of thermal throttling.

14.5.5.1 Digital Thermal Sensor Enumeration

The processor supports a digital thermal sensor if CPUID.06H.EAX[0] = 1. If the processor supports digital thermal sensor, EBX[bits 3:0] determine the number of thermal thresholds that are available for use.

Software sets thermal thresholds by using the IA32_THERM_INTERRUPT MSR. Soft ware reads output of the digital thermal sensor using the IA32_THERM_STATUS MSR.

Page 613 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 613 · click to enlarge
Page 613

POWER AND THERMAL MANAGEMENT

14.5.5.2 Reading the Digital Sensor

Unlike traditional analog thermal devices, the output of the digital thermal sensor is a temperature relative to the maximum supported operating temperature of the processor.

Temperature measurements returned by digital thermal sensors are always at or below TCC activation temperature. Critical temperature conditions are detected using the “Critical Temperature Status” bit. When this bit is set, the processor is operating at a critical temperature and immediate shutdown of the system should occur. Once the “Critical Temperature Status” bit is set, reliable operation is not guar anteed.

  • See Figure 14-11 for the layout of IA32_THERM_STATUS MSR. Bit fields include:
  • Thermal Status (bit 0, RO) — This bit indicates whether the digital thermal sensor high-temperature output signal (PROCHOT#) is currently active. Bit 0 = 1 indicates the feature is active. This bit may not be written by software; it reflects the state of the digital thermal sensor.
  • Thermal Status Log (bit 1, R/WC0) — This is a sticky bit that indicates the history of the thermal sensor high temperature output signal (PROCHOT#). Bit 1 = 1 if PROCHOT# has been asserted since a previous RESET or the last time software cleared the bit. Software may clear this bit by writing a zero.
  • PROCHOT# or FORCEPR# Event (bit 2, RO) — Indicates whether PROCHOT# or FORCEPR# is being asserted by another agent on the platform.

6 7 9 31 32

1 2 3 4 5 8 10 16 22 23 27

Resolution in Deg. Celsius Digital Readout Thermal Threshold #2 Log Thermal Threshold #2 Status Thermal Threshold #1 Log Thermal Threshold #1 Status Critical Temperature Log

Critical Temperature Status PROCHOT# or FORCEPR# Log PROCHOT# or FORCEPR# Event Thermal Status Log Thermal Status

Figure 14-11. IA32_THERM_STATUS Register

Reserved · Reading Valid

Page 614 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 614 · click to enlarge
Page 614

POWER AND THERMAL MANAGEMENT

  • PROCHOT# or FORCEPR# Log (bit 3, R/WC0) — Sticky bit that indicates whether PROCHOT# or FORCEPR# has been asserted by another agent on the platform since the last clearing of this bit or a reset. If bit 3 = 1, PROCHOT# or FORCEPR# has been externally asserted. Software may clear this bit by writing a zero. External PROCHOT# assertions are only acknowledged if the Bidirectional Prochot feature is enabled.
  • Critical Temperature Status (bit 4, RO) — Indicates whether the critical temperature detector output signal is currently active. If bit 4 = 1, the critical temperature detector output signal is currently active.
  • Critical Temperature Log (bit 5, R/WC0) — Sticky bit that indicates whether the critical temperature detector output signal has been asserted since the last clearing of this bit or reset. If bit 5 = 1, the output signal has been asserted. Software may clear this bit by writing a zero.
  • Thermal Threshold #1 Status (bit 6, RO) — Indicates whether the actual temperature is currently higher than or equal to the value set in Thermal Threshold #1. If bit 6 = 0, the actual temperature is lower. If bit 6 = 1, the actual temperature is greater than or equal to TT#1. Quantitative information of actual temperature can be inferred from Digital Readout, bits 22:16.
  • Thermal Threshold #1 Log (bit 7, R/WC0) — Sticky bit that indicates whether the Thermal Threshold #1 has been reached since the last clearing of this bit or a reset. If bit 7 = 1, the Threshold #1 has been reached. Software may clear this bit by writing a zero.
  • Thermal Threshold #2 Status (bit 8, RO) — Indicates whether actual temperature is currently higher than or equal to the value set in Thermal Threshold #2. If bit 8 = 0, the actual temperature is lower. If bit 8 = 1, the actual temperature is greater than or equal to TT#2. Quantitative information of actual temperature can be inferred from Digital Readout, bits 22:16.
  • Thermal Threshold #2 Log (bit 9, R/WC0) — Sticky bit that indicates whether the Thermal Threshold #2 has been reached since the last clearing of this bit or a reset. If bit 9 = 1, the Thermal Threshold #2 has been reached. Software may clear this bit by writing a zero.
  • Digital Readout (bits 22:16, RO) — Digital temperature reading in 1 degree Celsius relative to the TCC activation temperature.
0. TCC Activation temperature,
1. (TCC Activation - 1) , etc. See the processor’s data sheet for details regarding TCC activation.

A lower reading in the Digital Readout field (bits 22:16) indicates a higher actual temperature. • Resolution in Degrees Celsius (bits 30:27, RO) — Specifies the resolution (or tolerance) of the digital thermal sensor. The value is in degrees Celsius. It is recommended that new threshold values be offset from the current temperature by at least the resolution + 1 in order to avoid hysteresis of interrupt generation.

Page 615 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 615 · click to enlarge
Page 615

POWER AND THERMAL MANAGEMENT

  • Reading Valid (bit 31, RO) — Indicates if the digital readout in bits 22:16 is valid. The readout is valid if bit 31 = 1.

Changes to temperature can be detected using two thresholds (see Figure 14-12); one is set above and the other below the current temperature. These thresholds have the capability of generating interrupts using the core's local APIC which software must then service. Note that the local APIC entries used by these thresholds are also used by the Intel® Thermal Monitor; it is up to software to determine the source of a specific interrupt.

1 2 3 4 5 8 14 16 22 23 24

Threshold #2 Interrupt Enable

Threshold #2 Value Threshold #1 Interrupt Enable Threshold #1 Value Overheat Interrupt Enable FORCPR# Interrupt Enable PROCHOT# Interrupt Enable Low Temp. Interrupt Enable High Temp. Interrupt Enable

Figure 14-12. IA32_THERM_INTERRUPT Register

  • See Figure 14-12 for the layout of IA32_THERM_INTERRUPT MSR. Bit fields include:
  • High-Temperature Interrupt Enable (bit 0, R/W) — This bit allows the BIOS to enable the generation of an interrupt on the transition from low-temperature to a high-temperature threshold. Bit 0 = 0 (default) disables interrupts; bit 0 = 1 enables interrupts.
  • Low-Temperature Interrupt Enable (bit 1, R/W) — This bit allows the BIOS to enable the generation of an interrupt on the transition from high-temperature to a low-temperature (TCC de-activation). Bit 1 = 0 (default) disables interrupts; bit 1 = 1 enables interrupts.
  • PROCHOT# Interrupt Enable (bit 2, R/W) — This bit allows the BIOS or OS to enable the generation of an interrupt when PROCHOT# has been asserted by another agent on the platform and the Bidirectional Prochot feature is enabled. Bit 2 = 0 disables the interrupt; bit 2 = 1 enables the interrupt.
  • FORCEPR# Interrupt Enable (bit 3, R/W) — This bit allows the BIOS or OS to enable the generation of an interrupt when FORCEPR# has been asserted by another agent on the platform. Bit 3 = 0 disables the interrupt; bit 3 = 1 enables the interrupt.

Reserved

Page 616 of the Intel 253668-032US user manual — POWER AND THERMAL MANAGEMENT
Page 616 · click to enlarge
Page 616

POWER AND THERMAL MANAGEMENT

  • Critical Temperature Interrupt Enable (bit 4, R/W) — Enables the generation of an interrupt when the Critical Temperature Detector has detected a critical thermal condition. The recommended response to this condition is a system shutdown. Bit 4 = 0 disables the interrupt; bit 4 = 1 enables the interrupt.
  • Threshold #1 Value (bits 14:8, R/W) — A temperature threshold, encoded relative to the TCC Activation temperature (using the same format as the Digital Readout). This threshold is compared against the Digital Readout and is used to generate the Thermal Threshold #1 Status and Log bits as well as the Threshold #1 thermal interrupt delivery.
  • Threshold #1 Interrupt Enable (bit 15, R/W) — Enables the generation of an interrupt when the actual temperature crosses the Threshold #1 setting in any direction. Bit 15 = 0 enables the interrupt; bit 15 = 1 disables the interrupt.
  • Threshold #2 Value (bits 22:16, R/W) —A temperature threshold, encoded relative to the TCC Activation temperature (using the same format as the Digital Readout). This threshold is compared against the Digital Readout and is used to generate the Thermal Threshold #2 Status and Log bits as well as the Threshold #2 thermal interrupt delivery.
  • Threshold #2 Interrupt Enable (bit 23, R/W) — Enables the generation of an interrupt when the actual temperature crosses the Threshold #2 setting in any direction. Bit 23 = 0 enables the interrupt; bit 23 = 1 disables the interrupt.
Page 617 of the Intel 253668-032US user manual — 15.1 MACHINE-CHECK ARCHITECTURE
Page 617 · click to enlarge
Page 617

CHAPTER 15 MACHINE-CHECK ARCHITECTURE

This chapter describes the machine-check architecture and machine-check exception mechanism found in the Pentium 4, Intel Xeon, and P6 family processors. See Chapter 6, “Interrupt 18—Machine-Check Exception (#MC),” for more information on machine-check exceptions. A brief descrip tion of the Pentium processor’s machine check capability is also given.

Additionally, a signaling mechanism for software to respond to hardware corrected machine check error is covered.

15.1 MACHINE-CHECK ARCHITECTURE

The Pentium 4, Intel Xeon, and P6 family processors implement a machine- check architecture that provides a mechanism for detecting and reporting hardware (machine) errors, such as: system bus errors, ECC errors, parity errors, cache errors, and TLB errors. It consists of a set of model-specific registers (MSRs) that are used to set up machine checking and additional banks of MSRs used for recording errors that are detected.

The processor signals the detection of an uncorrected machine-check error by generating a machine-check exception (#MC), which is an abort class exception. The implementation of the machine-check architecture does not ordinarily permit the processor to be restarted reliably after generating a machine-check exception. However, the machine-check-exception handler can collect information about the machine-check error from the machine- check MSRs.

Starting with 45nm Intel 64 processor with CPUID signature DisplayFamily_DisplayModel encoding of 06H_1AH (see CPUID instruction in Chapter 3, “Instruction Set Reference, A-M” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A), the processor can report information on corrected machine-check errors and deliver a programmable interrupt for software to respond to MC errors, referred to as corrected machine-check error interrupt (CMCI). See Section 15.5 for detail.

Intel 64 processors supporting machine-check architecture and CMCI may also support an additional enhancement, namely, support for software recovery from certain uncorrected recoverable machine check errors. See Section 15.6 for detail.

Page 618 of the Intel 253668-032US user manual — 15.3 MACHINE-CHECK MSRS
Page 618 · click to enlarge
Page 618

MACHINE-CHECK ARCHITECTURE

15.2 COMPATIBILITY WITH PENTIUM PROCESSOR

  • The Pentium 4, Intel Xeon, and P6 family processors support and extend the machine-check exception mechanism introduced in the Pentium processor. The Pentium processor reports the following machine-check errors:
  • data parity errors during read cycles
  • unsuccessful completion of a bus cycle

The above errors are reported using the P5_MC_TYPE and P5_MC_ADDR MSRs (implementation specific for the Pentium processor). Use the RDMSR instruction to read these MSRs. See Appendix B, “Model-Specific Registers (MSRs),” for the addresses.

The machine-check error reporting mechanism that Pentium processors use is similar to that used in Pentium 4, Intel Xeon, and P6 family processors. When an error is detected, it is recorded in P5_MC_TYPE and P5_MC_ADDR; the processor then generates a machine-check exception (#MC).

See Section 15.3.3, “Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecture,” and Section 15.10.2, “Pentium

Processor Machine-Check Exception Handling,” for information on compati bility between machine-check code written to run on the Pentium processors and code written to run on P6 family processors.

15.3 MACHINE-CHECK MSRS

Machine check MSRs in the Pentium 4, Intel Xeon, and P6 family processors consist of a set of global control and status registers and several error- reporting register banks. See Figure 15-1.

Page 619 of the Intel 253668-032US user manual — 15.3.1.1 IA32_MCG_CAP MSR
Page 619 · click to enlarge
Page 619

MACHINE-CHECK ARCHITECTURE

(One Set for Each Hardware Unit)

IA32_MCG_CAP MSR

IA32_MCi_CTL MSR

IA32_MCG_STATUS MSR

IA32_MCi_STATUS MSR

IA32_MCG_CTL MSR

IA32_MCi_ADDR MSR

IA32_MCi_MISC MSR

IA32_MCi_CTL2 MSR

Figure 15-1. Machine-Check MSRs

Each error-reporting bank is associated with a specific hardware unit (or group of hardware units) in the processor. Use RDMSR and WRMSR to read and to write these registers.

15.3.1 Machine-Check Global Control MSRs

The machine-check global control MSRs include the IA32_MCG_CAP, IA32_MCG_STATUS, and IA32_MCG_CTL. See Appendix B, “Model-Specific Registers (MSRs),” for the addresses of these registers.

15.3.1.1 IA32_MCG_CAP MSR

The IA32_MCG_CAP MSR is a read-only register that provides information about the machine-check architecture of the processor. Figure 15-2 shows the structure of the register in Pentium 4, Intel Xeon, and P6 family proces sors.

Global Control MSRs · Error-Reporting Bank Registers

Page 620 of the Intel 253668-032US user manual — MCG_SER_P[24]
Page 620 · click to enlarge
Page 620

MACHINE-CHECK ARCHITECTURE

15 16 23 24

MCG_SER_P[24]

MCG_TES_P[11] MCG_EXT_CNT[23:16]

MCG_CMCI_P[10]

MCG_EXT_P[9]

MCG_CTL_P[8]

Figure 15-2. IA32_MCG_CAP Register

  • Where:
  • Count field, bits 7:0 — Indicates the number of hardware unit error-reporting banks available in a particular processor implementation.
  • MCG_CTL_P (control MSR present) flag, bit 8 — Indicates that the processor implements the IA32_MCG_CTL MSR when set; this register is absent when clear.
  • MCG_EXT_P (extended MSRs present) flag, bit 9 — Indicates that the processor implements the extended machine-check state registers found starting at MSR address 180H; these registers are absent when clear.
  • MCG_CMCI_P (Corrected MC error counting/signaling extension present) flag, bit 10 — Indicates (when set) that extended state and associated MSRs necessary to support the reporting of an interrupt on a corrected MC error event and/or count threshold of corrected MC errors, is present. When this bit is set, it does not imply this feature is supported across all banks. Software should check the availability of the necessary logic on a bank by bank basis when using this signaling capability (i.e. bit 30 settable in individual IA32_MCi_CTL2 register).
  • MCG_TES_P (threshold-based error status present) flag, bit 11 — Indicates (when set) that bits 56:53 of the IA32_MCi_STATUS MSR are part of the architectural space. Bits 56:55 are reserved, and bits 54:53 are used to report threshold-based error status. Note that when MCG_TES_P is not set, bits 56:53 of the IA32_MCi_STATUS MSR are model-specific.
  • MCG_EXT_CNT, bits 23:16 — Indicates the number of extended machinecheck state registers present. This field is meaningful only when the MCG_EXT_P flag is set.
  • MCG_SER_P (software error recovery support present) flag, bit 24 — Indicates (when set) that the processor supports software error recovery (see

10 11 12 · Count · Reserved

Page 621 of the Intel 253668-032US user manual — M C
Page 621 · click to enlarge
Page 621

MACHINE-CHECK ARCHITECTURE

Section 15.6), and IA32_MCi_STATUS MSR bits 56:55 are used to report the signaling of uncorrected recoverable errors and whether software must take recovery actions for uncorrected errors. Note that when MCG_TES_P is not set, bits 56:53 of the IA32_MCi_STATUS MSR are model-specific. If MCG_TES_P is set but MCG_SER_P is not set, bits 56:55 are reserved.

The effect of writing to the IA32_MCG_CAP MSR is undefined.

15.3.1.2 IA32_MCG_STATUS MSR

The IA32_MCG_STATUS MSR describes the current state of the processor after a machine-check exception has occurred (see Figure 15-3).

M C

E

R

I P V

I P V

I P

EIPV—Error IP valid flag MCIP—Machine check in progress flag

RIPV—Restart IP valid flag

Figure 15-3. IA32_MCG_STATUS Register

  • Where:
  • RIPV (restart IP valid) flag, bit 0 — Indicates (when set) that program execution can be restarted reliably at the instruction pointed to by the instruction pointer pushed on the stack when the machine-check exception is generated. When clear, the program cannot be reliably restarted at the pushed instruction pointer.
  • EIPV (error IP valid) flag, bit 1 — Indicates (when set) that the instruction pointed to by the instruction pointer pushed onto the stack when the machinecheck exception is generated is directly associated with the error. When this flag is cleared, the instruction pointed to may not be associated with the error.
  • MCIP (machine check in progress) flag, bit 2 — Indicates (when set) that a machine-check exception was generated. Software can set or clear this flag. The occurrence of a second Machine-Check Event while MCIP is set will cause the processor to enter a shutdown state. For information on processor behavior in the shutdown state, please refer to the description in Chapter 6, “Interrupt and Exception Handling”: “Interrupt 8—Double Fault Exception (#DF)”.

Bits 63:03 in IA32_MCG_STATUS are reserved.

Reserved

Page 622 of the Intel 253668-032US user manual — NOTE
Page 622 · click to enlarge
Page 622

MACHINE-CHECK ARCHITECTURE

15.3.1.3 IA32_MCG_CTL MSR

The IA32_MCG_CTL MSR is present if the capability flag MCG_CTL_P is set in the IA32_MCG_CAP MSR.

IA32_MCG_CTL controls the reporting of machine-check exceptions. If present, writing 1s to this register enables machine-check features and writing all 0s disables machine-check features. All other values are unde fined and/or implementation specific.

15.3.2 Error-Reporting Register Banks

Each error-reporting register bank can contain the IA32_MCi_CTL, IA32_MCi_STATUS, IA32_MCi_ADDR, and IA32_MCi_MISC MSRs. The number of reporting banks is indicated by bits [7:0] of IA32_MCG_CAP MSR (address 0179H). The first error-reporting register (IA32_MC0_CTL) always starts at address 400H.

See Appendix B, “Model-Specific Registers (MSRs),” for addresses of the error-reporting registers in the Pentium 4 and Intel Xeon processors; and for addresses of the error-reporting registers P6 family processors.

15.3.2.1 IA32_MCi_CTL MSRs

The IA32_MCi_CTL MSR controls error reporting for errors produced by a particular hardware unit (or group of hardware units). Each of the 64 flags (EEj) represents a potential error. Setting an EEj flag enables reporting of the associated error and clearing it disables reporting of the error. The processor does not write changes to bits that are not implemented. Figure 15-4 shows the bit fields of IA32_MCi_CTL.

63 0 1 2 3

62 61

E E 6 3

E E 6 2

E E 6 1

E E 0 2

E E 0 1

E E 0 0

EEj—Error reporting enable flag

(where j is 00 through 63)

Figure 15-4. IA32_MCi_CTL Register

NOTE

For P6 family processors, processors based on Intel Core microarchi tecture (excluding processors with DisplayFamily_DisplayModel

Page 623 of the Intel 253668-032US user manual — NOTE
Page 623 · click to enlarge
Page 623

MACHINE-CHECK ARCHITECTURE

encoding of 06H_1AH and onward): the operating system or executive software must not modify the contents of the IA32_MC0_CTL MSR. This MSR is internally aliased to the EBL_CR_POWERON MSR and controls platform-specific error handling features. System specific firmware (the BIOS) is responsible for the appropriate initialization of the IA32_MC0_CTL MSR. P6 family processors only allow the writing of all 1s or all 0s to the IA32_MCi_CTL MSR.

15.3.2.2 IA32_MCi_STATUS MSRS

Each IA32_MCi_STATUS MSR contains information related to a machine- check error if its VAL (valid) flag is set (see Figure 15-5). Software is respon sible for clearing IA32_MCi_STATUS MSRs by explicitly writing 0s to them; writing 1s to them causes a general-protection exception.

NOTE

Figure 15-5 depicts the IA32_MCi_STATUS MSR when IA32_MCG_CAP[24] = 1, IA32_MCG_CAP[11] = 1 and IA32_MCG_CAP[10] = 1. When IA32_MCG_CAP[24] = 0 and IA32_MCG_CAP[11] = 1, bits 56:55 is reserved and bits 54:53 for threshold-based error reporting. When IA32_MCG_CAP[11] = 0, bits 56:53 are part of the “Other Information” field. The use of bits 54:53 for threshold-based error reporting began with Intel Core Duo processors, and is currently used for cache memory. See Section 15.4, “Enhanced Cache Error reporting,” for more information. When IA32_MCG_CAP[10] = 0, bits 52:38 are part of the “Other Infor mation” field. The use of bits 52:38 for corrected MC error count is

Page 624 of the Intel 253668-032US user manual — A E
Page 624 · click to enlarge
Page 624

MACHINE-CHECK ARCHITECTURE

introduced with Intel 64 processor having CPUID DisplayFamily_DisplayModel encoding of 06H_1AH.

Other MSCOD Model 54 53 38 62 61 60 59 58 57 56 55 52 15

37 32 31 16 0

V A L

O V E R

MCA Error Code U S

C N Specific Error Code Info Corrected Error Count

A E

P C

R

Threshold-based error status (54:53)* AR — Recovery action required for UCR error (55)** S — Signaling an uncorrected recoverable (UCR) error (56)** PCC — Processor context corrupted (57)

ADDRV — MCi_ADDR register valid (58) MISCV — MCi_MISC register valid (59) EN — Error reporting enabled (60) UC — Uncorrected error (61) OVER — Error overflow (62) VAL — MCi_STATUS register valid (63)

* When IA32_MCG_CAP[11] (MCG_TES_P) is not set, these bits are model-specific (part of “Other Information”). ** When IA32_MCG_CAP[11] or IA32_MCG_CAP[24] are not set, these bits are reserved, or model-specific (part of “Other Information”).

Figure 15-5. IA32_MCi_STATUS Register

  • Where:
  • MCA (machine-check architecture) error code field, bits 15:0 — Specifies the machine-check architecture-defined error code for the machine-check error condition detected. The machine-check architecture-defined error codes are guaranteed to be the same for all IA-32 processors that implement the machinecheck architecture. See Section 15.9, “Interpreting the MCA Error Codes,” and Appendix E, “Interpreting Machine-Check Error Codes”, for information on machine-check error codes.
  • Model-specific error code field, bits 31:16 — Specifies the model-specific error code that uniquely identifies the machine-check error condition detected. The model-specific error codes may differ among IA-32 processors for the same machine-check error condition. See Appendix E, “Interpreting Machine-Check Error Codes”for information on model-specific error codes.
  • Reserved, Error Status, and Other Information fields, bits 56:32 —
  • Bits 37:32 always contain “Other Information” that is implementationspecific and is not part of the machine-check architecture. Software that is intended to be portable among IA-32 processors should not rely on these values.
Page 625 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 625 · click to enlarge
Page 625

MACHINE-CHECK ARCHITECTURE

  • If IA32_MCG_CAP[10] is 0, bits 52:38 also contain “Other Information” (in the same sense as bits 37:32).
  • If IA32_MCG_CAP[10] is 1, bits 52:38 are architectural (not modelspecific). In this case, bits 52:38 reports the value of a 15 bit counter that increments each time a corrected error is observed by the MCA recording bank. This count value will continue to increment until cleared by software. The most significant bit, 52, is a sticky count overflow bit.
  • If IA32_MCG_CAP[11] is 0, bits 56:53 also contain “Other Information” (in the same sense).
  • If IA32_MCG_CAP[11] is 1, bits 56:53 are architectural (not modelspecific). In this case, bits 56:53 have the following functionality:
  • If IA32_MCG_CAP[24] is 0, bits 56:55 are reserved.
  • If IA32_MCG_CAP[24] is 1, bits 56:55 are defined as follows:
  • S (Signaling) flag, bit 56 - Signals the reporting of UCR errors in this MC bank. See Section 15.6.2 for additional detail.
  • AR (Action Required) flag, bit 55 - Indicates (when set) that MCA error code specific recovery action must be performed by system software at the time this error was signaled. See Section 15.6.2 for additional detail.
  • If the UC bit (Figure 15-5) is 1, bits 54:53 are undefined.
  • If the UC bit (Figure 15-5) is 0, bits 54:53 indicate the status of the hardware structure that reported the threshold-based error. See Table 15-1.

Table 15-1. Bits 54:53 in IA32_MCi_STATUS MSRs

when IA32_MCG_CAP[11] = 1 and UC = 0 Bits 54:53 Meaning

00 No tracking - No hardware status tracking is provided for the structure reporting this event.

01 Green - Status tracking is provided for the structure posting the event; the current status is green (below threshold). For more information, see Section 15.4, “Enhanced Cache Error reporting”.

10 Yellow - Status tracking is provided for the structure posting the event; the current status is yellow (above threshold). For more information, see Section 15.4, “Enhanced Cache Error reporting”.

  • PCC (processor context corrupt) flag, bit 57 — Indicates (when set) that the state of the processor might have been corrupted by the error condition detected and that reliable restarting of the processor may not be possible. When clear, this

11 Reserved

Page 626 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 626 · click to enlarge
Page 626

MACHINE-CHECK ARCHITECTURE

  • flag indicates that the error did not affect the processor’s state. Software restarting might be possible.
  • ADDRV (IA32_MC i _ADDR register valid) flag, bit 58 — Indicates (when set) that the IA32_MCi_ADDR register contains the address where the error occurred (see Section 15.3.2.3, “IA32_MCi_ADDR MSRs”). When clear, this flag indicates that the IA32_MCi_ADDR register is either not implemented or does not contain the address where the error occurred. Do not read these registers if they are not implemented in the processor.
  • MISCV (IA32_MC i _MISC register valid) flag, bit 59 — Indicates (when set) that the IA32_MC i _MISC register contains additional information regarding the error. When clear, this flag indicates that the IA32_MC i _MISC register is either not implemented or does not contain additional information regarding the error. Do not read these registers if they are not implemented in the processor.
  • EN (error enabled) flag, bit 60 — Indicates (when set) that the error was enabled by the associated EEj bit of the IA32_MC i _CTL register.
  • UC (error uncorrected) flag, bit 61 — Indicates (when set) that the processor did not or was not able to correct the error condition. When clear, this flag indicates that the processor was able to correct the error condition.
  • OVER (machine check overflow) flag, bit 62 — Indicates (when set) that a machine-check error occurred while the results of a previous error were still in the error-reporting register bank (that is, the VAL bit was already set in the IA32_MC i _STATUS register). The processor sets the OVER flag and software is responsible for clearing it. In general, enabled errors are written over disabled errors, and uncorrected errors are written over corrected errors. Uncorrected errors are not written over previous valid uncorrected errors. For more infor mation, see Section 15.3.2.2.1, “Overwrite Rules for Machine Check Overflow”.
  • VAL (IA32_MC i _STATUS register valid) flag, bit 63 — Indicates (when set) that the information within the IA32_MCi_STATUS register is valid. When this flag is set, the processor follows the rules given for the OVER flag in the IA32_MCi_STATUS register when overwriting previously valid entries. The processor sets the VAL flag and software is responsible for clearing it.

15.3.2.2.1 Overwrite Rules for Machine Check Overflow

Table 15-2 shows the overwrite rules for how to treat a second event if the cache has already posted an event to the MC bank – that is, what to do if the valid bit for an MC bank already is set to 1. When more than one structure posts events in a given bank, these rules specify whether a new event will overwrite a previous posting or not. These rules define a priority for uncor rected (highest priority), yellow, and green/unmonitored (lowest priority) status.

Page 627 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 627 · click to enlarge
Page 627

MACHINE-CHECK ARCHITECTURE

In Table 15-2, the values in the two left-most columns are IA32_MCi_STATUS[54:53].

Table 15-2. Overwrite Rules for Enabled Errors First Event Second Event UC bit Color MCA Info

00/green 00/green 0 00/green second

00/green yellow 0 yellow second error

yellow 00/green 0 yellow first error

yellow yellow 0 yellow either

00/green/yellow UC 1 undefined second

UC 00/green/yellow 1 undefined first

If a second event overwrites a previously posted event, the information (as guarded by individual valid bits) in the MCi bank is entirely from the second event. Similarly, if a first event is retained, all of the information previously posted for that event is retained. In either case, the OVER bit (MCi_Status[62]) will be set to indicate an overflow.

After software polls a posting and clears the register, the valid bit is no longer set and therefore the meaning of the rest of the bits, including the yellow/green/00 status field in bits 54:53, is undefined. The yellow/green indication will only be posted for events associated with monitored struc tures – otherwise the unmonitored (00) code will be posted in MCi_Status[54:53].

15.3.2.3 IA32_MCi_ADDR MSRs

The IA32_MCi_ADDR MSR contains the address of the code or data memory location that produced the machine-check error if the ADDRV flag in the IA32_MCi_STATUS register is set (see Section 15-6, “IA32_MCi_ADDR MSR”). The IA32_MCi_ADDR register is either not implemented or contains no address if the ADDRV flag in the IA32_MCi_STATUS register is clear. When not implemented in the processor, all reads and writes to this MSR will cause a general protection exception.

The address returned is an offset into a segment, linear address, or physical address. This depends on the error encountered. When these registers are implemented, these registers can be cleared by explicitly writing 0s to these registers. Writing 1s to these registers will cause a general-protection exception. See Figure 15-6.

Page 628 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 628 · click to enlarge
Page 628

MACHINE-CHECK ARCHITECTURE

Processor Without Support For Intel 64 Architecture

Processor With Support for Intel 64 Architecture

* Useful bits in this field depend on the address methodology in use when the the register state is saved.

Figure 15-6. IA32_MCi_ADDR MSR

15.3.2.4 IA32_MCi_MISC MSRs

The IA32_MCi_MISC MSR contains additional information describing the machine-check error if the MISCV flag in the IA32_MCi_STATUS register is set. The IA32_MCi_MISC_MSR is either not implemented or does not contain additional information if the MISCV flag in the IA32_MCi_STATUS register is clear.

When not implemented in the processor, all reads and writes to this MSR will cause a general protection exception. When implemented in a processor, these registers can be cleared by explicitly writing all 0s to them; writing 1s to them causes a general-protection exception to be generated. This register is not implemented in any of the error-reporting register banks for the P6 family processors.

If both MISCV and IA32_MCG_CAP[24] are set, the IA32_MCi_MISC_MSR is defined according to Figure 15-7 to support software recovery of uncor rected errors (see Section 15.6):

Reserved · Address · Address*

Page 629 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 629 · click to enlarge
Page 629

MACHINE-CHECK ARCHITECTURE

Figure 15-7. UCR Support in IA32_MCi_MISC Register

  • Recoverable Address LSB (bits 5:0): The lowest valid recoverable address bit. Indicates the position of the least significant bit (LSB) of the recoverable error address. For example, if the processor logs bits [43:9] of the address, the LSB sub-field in IA32_MCi_MISC is 01001b (9 decimal). For this example, bits [8:0] of the recoverable error address in IA32_MCi_ADDR should be ignored.
  • Address Mode (bits 8:6): Address mode for the address logged in IA32_MCi_ADDR. The supported address modes are given in Table 15-3.

Table 15-3. Address Mode in IA32_MCi_MISC[8:6] IA32_MCi_MISC[8:6] Encoding Definition

100 to 110 Reserved

  • Model Specific Information (bits 63:9): Not architecturally defined.

15.3.2.5 IA32_MCi_CTL2 MSRs

The IA32_MCi_CTL2 MSR provides the programming interface to use corrected MC error signaling capability that is indicated by IA32_MCG_CAP[10] = 1. Software must check for the presence of IA32_MCi_CTL2 on a per-bank basis.

Show 8 more labels / short text on this page
Model Specific Information · Address Mode · Recoverable Address LSB · 000 Segment Offset · 001 Linear Address · 010 Physical Address · 011 Memory Address · 111 Generic
Page 630 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 630 · click to enlarge
Page 630

MACHINE-CHECK ARCHITECTURE

When IA32_MCG_CAP[10] = 1, the IA32_MCi_CTL2 MSR for each bank exists, i.e. reads and writes to these MSR are supported. However, signaling interface for corrected MC errors may not be supported in all banks.

The layout of IA32_MCi_CTL2 is shown in Figure 15-8:

0 14 31 30

Corrected error count threshold

Figure 15-8. IA32_MCi_CTL2 Register

  • Corrected error count threshold, bits 14:0 — Software must initialize this field. The value is compared with the corrected error count field in IA32_MCi_STATUS, bits 38 through 52. An overflow event is signaled to the CMCI LVT entry (see Table 10-1) in the APIC when the count value equals the threshold value. The new LVT entry in the APIC is at 02F0H offset from the APIC_BASE. If CMCI interface is not supported for a particular bank ( but IA32_MCG_CAP[10] = 1) , this field will always read 0.
  • CMCI_EN-Corrected error interrupt enable/disable/indicator, bits 30 — Software sets this bit to enable the generation of corrected machine-check error interrupt (CMCI). If CMCI interface is not supported for a particular bank (but IA32_MCG_CAP[10] = 1) , this bit is writeable but will always return 0 for that bank. This bit also indicates CMCI is supported or not supported in the corre sponding bank. See Section 15.5 for details of software detection of CMCI facility.

Some microarchitectural sub-systems that are the source of corrected MC errors may be shared by more than one logical processors. Consequently, the facilities for reporting MC errors and controlling mechanisms may be shared by more than one logical processors. For example, the IA32_MCi_CTL2 MSR is shared between logical processors sharing a processor core. Software is responsible to program IA32_MCi_CTL2 MSR in a consistent manner with CMCI delivery and usage.

After processor reset, IA32_MCi_CTL2 MSRs are zero’ed.

Reserved · Reserved · CMCI_EN—Enable/disable CMCI

Page 631 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 631 · click to enlarge
Page 631

MACHINE-CHECK ARCHITECTURE

15.3.2.6 IA32_MCG Extended Machine Check State MSRs

The Pentium 4 and Intel Xeon processors implement a variable number of extended machine-check state MSRs. The MCG_EXT_P flag in the IA32_MCG_CAP MSR indicates the presence of these extended registers, and the MCG_EXT_CNT field indicates the number of these registers actually implemented. See Section 15.3.1.1, “IA32_MCG_CAP MSR.” Also see Table 15-4.

Table 15-4. Extended Machine Check State MSRs in Processors Without Support for Intel 64 Architecture MSR Address Description

IA32_MCG_EAX 180H Contains state of the EAX register at the time of the machine- check error.

IA32_MCG_EBX 181H Contains state of the EBX register at the time of the machine- check error.

IA32_MCG_ECX 182H Contains state of the ECX register at the time of the machine- check error.

IA32_MCG_EDX 183H Contains state of the EDX register at the time of the machine- check error.

IA32_MCG_ESI 184H Contains state of the ESI register at the time of the machine- check error.

IA32_MCG_EDI 185H Contains state of the EDI register at the time of the machine- check error.

IA32_MCG_EBP 186H Contains state of the EBP register at the time of the machine- check error.

IA32_MCG_ESP 187H Contains state of the ESP register at the time of the machine- check error.

IA32_MCG_EFLAGS 188H Contains state of the EFLAGS register at the time of the machine-check error.

IA32_MCG_EIP 189H Contains state of the EIP register at the time of the machine- check error.

IA32_MCG_MISC 18AH When set, indicates that a page assist or page fault occurred during DS normal operation.

In processors with support for Intel 64 architecture, 64-bit machine check state MSRs are aliased to the legacy MSRs. In addition, there may be regis ters beyond IA32_MCG_MISC. These may include up to five reserved MSRs (IA32_MCG_RESERVED[1:5]) and save-state MSRs for registers introduced in 64-bit mode. See Table 15-5.

Page 632 of the Intel 253668-032US user manual — IA32_MCG_ RSERVED[1:5]
Page 632 · click to enlarge
Page 632

MACHINE-CHECK ARCHITECTURE

Table 15-5. Extended Machine Check State MSRs In Processors With Support For Intel 64 Architecture MSR Address Description

IA32_MCG_RAX 180H Contains state of the RAX register at the time of the machine- check error.

IA32_MCG_RBX 181H Contains state of the RBX register at the time of the machine- check error.

IA32_MCG_RCX 182H Contains state of the RCX register at the time of the machine- check error.

IA32_MCG_RDX 183H Contains state of the RDX register at the time of the machine- check error.

IA32_MCG_RSI 184H Contains state of the RSI register at the time of the machine- check error.

IA32_MCG_RDI 185H Contains state of the RDI register at the time of the machine- check error.

IA32_MCG_RBP 186H Contains state of the RBP register at the time of the machine- check error.

IA32_MCG_RSP 187H Contains state of the RSP register at the time of the machine- check error.

IA32_MCG_RFLAGS 188H Contains state of the RFLAGS register at the time of the machine-check error.

IA32_MCG_RIP 189H Contains state of the RIP register at the time of the machine- check error.

IA32_MCG_MISC 18AH When set, indicates that a page assist or page fault occurred during DS normal operation.

IA32_MCG_ RSERVED[1:5]

18BH- 18FH These registers, if present, are reserved.

IA32_MCG_R8 190H Contains state of the R8 register at the time of the machine- check error.

IA32_MCG_R9 191H Contains state of the R9 register at the time of the machine- check error.

IA32_MCG_R10 192H Contains state of the R10 register at the time of the machine- check error.

IA32_MCG_R11 193H Contains state of the R11 register at the time of the machine- check error.

IA32_MCG_R12 194H Contains state of the R12 register at the time of the machine- check error.

IA32_MCG_R13 195H Contains state of the R13 register at the time of the machine- check error.

Page 633 of the Intel 253668-032US user manual — 15.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecture
Page 633 · click to enlarge
Page 633

MACHINE-CHECK ARCHITECTURE

Table 15-5. Extended Machine Check State MSRs In Processors With Support For Intel 64 Architecture (Contd.) MSR Address Description

IA32_MCG_R14 196H Contains state of the R14 register at the time of the machine- check error.

IA32_MCG_R15 197H Contains state of the R15 register at the time of the machine- check error.

When a machine-check error is detected on a Pentium 4 or Intel Xeon processor, the processor saves the state of the general-purpose registers, the R/EFLAGS register, and the R/EIP in these extended machine-check state MSRs. This information can be used by a debugger to analyze the error.

These registers are read/write to zero registers. This means software can read them; but if software writes to them, only all zeros is allowed. If soft ware attempts to write a non-zero value into one of these registers, a general-protection (#GP) exception is generated. These registers are cleared on a hardware reset (power-up or RESET), but maintain their contents following a soft reset (INIT reset).

15.3.3 Mapping of the Pentium Processor Machine-Check Errors to the Machine-Check Architecture

The Pentium processor reports machine-check errors using two registers: P5_MC_TYPE and P5_MC_ADDR. The Pentium 4, Intel Xeon, and P6 family processors map these registers to the IA32_MCi_STATUS and IA32_MCi_ADDR in the error-reporting register bank. This bank reports on the same type of external bus errors reported in P5_MC_TYPE and P5_MC_ADDR.

  • The information in these registers can then be accessed in two ways:
  • By reading the IA32_MC i _STATUS and IA32_MC i _ADDR registers as part of a general machine-check exception handler written for Pentium 4 and P6 family processors.
  • By reading the P5_MC_TYPE and P5_MC_ADDR registers using the RDMSR instruction.

The second capability permits a machine-check exception handler written to run on a Pentium processor to be run on a Pentium 4, Intel Xeon, or P6 family processor. There is a limitation in that information returned by the Pentium 4, Intel Xeon, and P6 family processors is encoded differently than information returned by the Pentium processor. To run a Pentium processor machine-check exception handler on a Pentium 4, Intel Xeon, or P6 family

Page 634 of the Intel 253668-032US user manual — 15.5 CORRECTED MACHINE CHECK ERROR INTERRUPT
Page 634 · click to enlarge
Page 634

MACHINE-CHECK ARCHITECTURE

processor; the handler must be written to interpret P5_MC_TYPE encodings correctly.

15.4 ENHANCED CACHE ERROR REPORTING

Starting with Intel Core Duo processors, cache error reporting was enhanced. In earlier Intel processors, cache status was based on the number of correction events that occurred in a cache. In the new paradigm, called “threshold-based error status”, cache status is based on the number of lines (ECC blocks) in a cache that incur repeated corrections. The threshold is chosen by Intel, based on various factors. If a processor supports threshold-based error status, it sets IA32_MCG_CAP[11] (MCG_TES_P) to 1; if not, to 0.

A processor that supports enhanced cache error reporting contains hard ware that tracks the operating status of certain caches and provides an indi cator of their “health”. The hardware reports a “green” status when the number of lines that incur repeated corrections is at or below a pre-defined threshold, and a “yellow” status when the number of affected lines exceeds the threshold. Yellow status means that the cache reporting the event is operating correctly, but you should schedule the system for servicing within a few weeks.

Intel recommends that you rely on this mechanism for structures supported by threshold-base error reporting.

The CPU/system/platform response to a yellow event should be less severe than its response to an uncorrected error. An uncorrected error means that a serious error has actually occurred, whereas the yellow condition is a warning that the number of affected lines has exceeded the threshold but is not, in itself, a serious event: the error was corrected and system state was not compromised.

The green/yellow status indicator is not a foolproof early warning for an uncorrected error resulting from the failure of two bits in the same ECC block. Such a failure can occur and cause an uncorrected error before the yellow threshold is reached. However, the chance of an uncorrected error increases as the number of affected lines increases.

15.5 CORRECTED MACHINE CHECK ERROR INTERRUPT

Corrected machine-check error interrupt (CMCI) is an architectural enhancement to the machine-check architecture. It provides capabilities

Page 635 of the Intel 253668-032US user manual — APIC_BASE + 2F0H
Page 635 · click to enlarge
Page 635

MACHINE-CHECK ARCHITECTURE

beyond those of threshold-based error reporting (Section 15.4). With threshold-based error reporting, software is limited to use periodic polling to query the status of hardware corrected MC errors. CMCI provides a signaling mechanism to deliver a local interrupt based on threshold values that soft ware can program using the IA32_MCi_CTL2 MSRs.

CMCI is disabled by default. System software is required to enable CMCI for each IA32_MCi bank that support the reporting of hardware corrected errors if IA32_MCG_CAP[10] = 1.

System software use IA32_MCi_CTL2 MSR to enable/disable the CMCI capa bility for each bank and program threshold values into IA32_MCi_CTL2 MSR. CMCI is not affected by the CR4.MCE bit, and it is not affected by the IA32_MCi_CTL MSR’s.

To detect the existence of thresholding for a given bank, software writes only bits 14:0 with the threshold value. If the bits persist, then thresholding is available (and CMCI is available). If the bits are all 0's, then no thresholding exists. To detect that CMCI signaling exists, software writes a 1 to bit 30 of the MCi_CTL2 register. Upon subsequent read, If Bit 30 = 0, no CMCI is available for this bank. If Bit 30 = 1, then CMCI is available and enabled.

15.5.1 CMCI Local APIC Interface

The interaction of CMCI is depicted in Figure 15-9.

Software write 1 to enable

Count overflow threshold -> CMCI LVT in local APIC

APIC_BASE + 2F0H

Figure 15-9. CMCI Behavior

Show 5 more labels / short text on this page
MCi_CTL2 · Error threshold · ?= · MCi_STATUS · Error count
Page 636 of the Intel 253668-032US user manual — APIC_BASE + 2F0H
Page 636 · click to enlarge
Page 636

MACHINE-CHECK ARCHITECTURE

CMCI interrupt delivery is configured by writing to the LVT CMCI register entry in the local APIC register space at default address of APIC_BASE + 2F0H. A CMCI interrupt can be delivered to more than one logical processors if multiple logical processors are affected by the associated MC errors. For example, if a corrected bit error in a cache shared by two logical processors caused a CMCI, the interrupt will be delivered to both logical processors sharing that microarchitectural sub-system. Similarly, package level errors may cause CMCI to be delivered to all logical processors within the package. However, system level errors will not be handled by CMCI.

The format of the LVT CMCI register is shown in Figure 15-10. The LVT entry allows the 4 delivery modes, an 8 bit interrupt vector, and masking.

0 10 17 16

7 8 12 13

APIC_BASE + 2F0H

MASK

Delivery Mode Vector Number

Figure 15-10. Local APIC CMCI LVT Register

  • Vector, bits 7:0 — The interrupt vector number. The local APIC allows values 16-255 in this register. Values of 0 through 15 will result in an illegal vector to be logged in the APIC error status register.
  • Delivery mode, bits 10:8 — The following delivery modes are supported:

— 000B: Fixed delivery. Delivers an interrupt to the vector specified in bits 7:0.

— 010B: SMI Delivers an SMI interrupt to the processor core through the processor's local SMI signal path. When using this delivery mode, the vector field should be set to 00H for future compatibility.

— 100B: NMI Delivers an NMI interrupt to the logical processor affected by the error. The vector information is ignored.

— Entry 101B (INIT) and entry 111B (ExtINT) are not supported by CMCI LVT.

— Other bit patterns are reserved.

Reserved · Reserved · Delivery Status

Page 637 of the Intel 253668-032US user manual — 15.5.2 System Software Recommendation for Managing CMCI and Machine Check Resources
Page 637 · click to enlarge
Page 637

MACHINE-CHECK ARCHITECTURE

  • Delivery status, bits 12 — It is a read-only bit that, when set, indicates that an interrupt from this source has been delivered to the processor core, but has not yet been accepted.
  • Mask, bits 16 — When set, inhibits reception of the interrupt. (Unlike the PerfMon LVT entry, this bit is not set when an interrupt is received. When clear, CMCI is not masked. The mask bit is set by default.
  • Bits 31:17, 15:13 and 11 are reserved.

15.5.2 System Software Recommendation for Managing CMCI and Machine Check Resources

System software must enable and manage CMCI, set up interrupt handlers to service CMCI interrupts delivered to affected logical processors, program CMCI LVT entry, and query machine check banks that are shared by more than one logical processors.

This section describes techniques system software can implement to manage CMCI initialization, service CMCI interrupts in a efficient manner to minimize contentions to access shared MSR resources.

15.5.2.1 CMCI Initialization

  • Although a CMCI interrupt may be delivered to more than one logical proces sors depending on the nature of the corrected MC error, only one instance of the interrupt service routine needs to perform the necessary service and make queries to the machine-check banks. The following steps describes a technique that limits the amount of work the system has to do in response to a CMCI.
  • To provide maximum flexibility, system software should define per-thread data structure for each logical processor to allow equal-opportunity and efficient response to interrupt delivery. Specifically, the per-thread data structure should include a set of per-bank fields to track which machine check bank it needs to access in response to a delivered CMCI interrupt. The number of banks that needs to be tracked is determined by IA32_MCG_CAP[7:0].
  • Initialization of per-thread data structure. The initialization of per-thread data structure must be done serially on each logical processor in the system. The sequencing order to start the per-thread initialization between different logical processor is arbitrary. But it must observe the following specific detail to satisfy the shared nature of specific MSR resources:

a. Each thread initializes its data structure to indicate that it does not own any MC bank registers.

Page 638 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 638 · click to enlarge
Page 638

MACHINE-CHECK ARCHITECTURE

  • b. Each thread examines IA32_MCi_CTL2[30] indicator for each bank to determine if another thread has already claimed ownership of that bank.
  • If IA32_MCi_CTL2[30] had been set by another thread. This thread can not own bank i and should proceed to step b. and examine the next machine check bank until all of the machine check banks are exhausted.
  • If IA32_MCi_CTL2[30] = 0, proceed to step c.
  • c. Check whether writing a 1 into IA32_MCi_CTL2[30] can return with 1 on a subsequent read to determine this bank can support CMCI.
  • If IA32_MCi_CTL2[30] = 0, this bank does not support CMCI. This thread can not own bank i and should proceed to step b. and examine the next machine check bank until all of the machine check banks are exhausted.
  • If IA32_MCi_CTL2[30] = 1, modify the per-thread data structure to indicate this thread claims ownership to the MC bank; proceed to initialize the error threshold count (bits 15:0) of that bank as described in Chapter 15, “CMCI Threshold Management”. Then proceed to step b. and examine the next machine check bank until all of the machine check banks are exhausted.
  • After the thread has examined all of the machine check banks, it sees if it owns any MC banks to service CMCI. If any bank has been claimed by this thread:

— Ensure that the CMCI interrupt handler has been set up as described in Chapter 15, “CMCI Interrupt Handler”.

— Initialize the CMCI LVT entry, as described in Chapter 15, “CMCI Local APIC Interface”.

— Log and clear all of IA32_MCi_Status registers for the banks that this thread owns. This will allow new errors to be logged.

15.5.2.2 CMCI Threshold Management

  • The Corrected MC error threshold field, IA32_MCi_CTL2[15:0], is architec turally defined. Specifically, all these bits are writable by software, but different processor implementations may choose to implement less than 15 bits as threshold for the overflow comparison with IA32_MCi_STATUS[52:38]. The following describes techniques that soft ware can manage CMCI threshold to be compatible with changes in imple mentation characteristics:
  • Software can set the initial threshold value to 1 by writing 1 to IA32_MCi_CTL2[15:0]. This will cause overflow condition on every corrected MC error and generates a CMCI interrupt.
  • To increase the threshold and reduce the frequency of CMCI servicing:

a. Find the maximum threshold value a given processor implementation supports. The steps are:

Page 639 of the Intel 253668-032US user manual — 15.6 RECOVERY OF UNCORRECTED RECOVERABLE (UCR) ERRORS
Page 639 · click to enlarge
Page 639

MACHINE-CHECK ARCHITECTURE

  • Write 7FFFH to IA32_MCi_CTL2[15:0],
  • Read back IA32_MCi_CTL2[15:0], the lower 15 bits (14:0) is the maximum threshold supported by the processor.

b. Increase the threshold to a value below the maximum value discovered using step a.

15.5.2.3 CMCI Interrupt Handler

  • The following describes techniques system software may consider to imple ment a CMCI service routine:
  • The service routine examines its private per-thread data structure to check which set of MC banks it has ownership. If the thread does not have ownership of a given MC bank, proceed to the next MC bank. Ownership is determined at initial ization time which is described in Section [Cross Reference to 14.5.2.1].
  • If the thread had claimed ownership to an MC bank,
  • — Check for valid MC errors by testing IA32_MCi_STATUS.VALID[63],
  • Log MC errors,
  • Clear the MSRs of this MC bank.

— If no valid error, proceed to next MC bank. • When all MC banks have been processed, exit service routine and return to original program execution.

This technique will allow each logical processors to handle corrected MC errors independently and requires no synchronization to access shared MSR resources.

15.6 RECOVERY OF UNCORRECTED RECOVERABLE (UCR) ERRORS

Recovery of uncorrected recoverable machine check errors is an enhance ment in machine-check architecture. The first processor that supports this feature is 45nm Intel 64 processor with CPUID signature DisplayFamily_DisplayModel encoding of 06H_2EH. This allow system soft ware to perform recovery action on certain class of uncorrected errors and continue execution.

Page 640 of the Intel 253668-032US user manual — 15.6.2 UCR Error Reporting and Logging
Page 640 · click to enlarge
Page 640

MACHINE-CHECK ARCHITECTURE

15.6.1 Detection of Software Error Recovery Support

Software must use bit 24 of IA32_MCG_CAP (MCG_SER_P) to detect the presence of software error recovery support (see Figure 15-2). When IA32_MCG_CAP[24] is set, this indicates that the processor supports soft ware error recovery. When this bit is clear, this indicates that there is no support for error recovery from the processor and the primary responsibility of the machine check handler is logging the machine check error information and shutting down the system.

The new class of architectural MCA errors from which system software can attempt recovery is called Uncorrected Recoverable (UCR) Errors. UCR errors are uncorrected errors that have been detected and signaled but have not corrupted the processor context. For certain UCR errors, this means that once system software has performed a certain recovery action, it is possible to continue execution on this processor. UCR error reporting provides an error containment mechanism for data poisoning. The machine check handler will use the error log information from the error reporting registers to analyze and implement specific error recovery actions for UCR errors.

15.6.2 UCR Error Reporting and Logging

IA32_MCi_STATUS MSR is used for reporting UCR errors and existing corrected or uncorrected errors. The definitions of IA32_MCi_STATUS, including bit fields to identify UCR errors, is shown in Figure 15-5. UCR errors can be signaled through either the corrected machine check interrupt (CMCI) or machine check exception (MCE) path depending on the type of the UCR error.

  • When IA32_MCG_CAP[24] is set, a UCR error is indicated by the following bit settings in the IA32_MCi_STATUS register:
  • Valid (bit 63) = 1
  • UC (bit 61) = 1
  • PCC (bit 57) = 0

Additional information from the IA32_MCi_MISC and the IA32_MCi_ADDR registers for the UCR error are available when the ADDRV and the MISCV flags in the IA32_MCi_STATUS register are set (see Section 15.3.2.4). The MCA error code field of the IA32_MCi_STATUS register indicates the type of UCR error. System software can interpret the MCA error code field to analyze and identify the necessary recovery action for the given UCR error.

In addition, the IA32_MCi_STATUS register bit fields, bits 56:55, are defined (see Figure 15-5) to provide additional information to help system software to properly identify the necessary recovery action for the UCR error:

Page 641 of the Intel 253668-032US user manual — 15.6.3 UCR Error Classification
Page 641 · click to enlarge
Page 641

MACHINE-CHECK ARCHITECTURE

  • S (Signaling) flag, bit 56 - Indicates (when set) that a machine check exception was generated for the UCR error reported in this MC bank and system software needs to check the AR flag and the MCA error code fields in the IA32_MCi_STATUS register to identify the necessary recovery action for this error. When the S flag in the IA32_MCi_STATUS register is clear, this UCR error was not signaled via a machine check exception and instead was reported as a corrected machine check (CMC). System software is not required to take any recovery action when the S flag in the IA32_MCi_STATUS register is clear.
  • AR (Action Required) flag, bit 55 - Indicates (when set) that MCA error code specific recovery action must be performed by system software at the time this error was signaled. This recovery action must be completed successfully before any additional work is scheduled for this processor When the RIPV flag in the IA32_MCG_STATUS is clear, an alternative execution stream needs to be provided; when the MCA error code specific recovery specific recovery action cannot be successfully completed, system software must shut down the system. When the AR flag in the IA32_MCi_STATUS register is clear, system software may still take MCA error code specific recovery action but this is optional; system software can safely resume program execution at the instruction pointer saved on the stack from the machine check exception when the RIPV flag in the IA32_MCG_STATUS register is set.

Both the S and the AR flags in the IA32_MCi_STATUS register are defined to be sticky bits, which mean that once set, the processor does not clear them. Only software and good power-on reset can clear the S and the AR-flags. Both the S and the AR flags are only set when the processor reports the UCR errors (MCG_CAP[24] is set).

15.6.3 UCR Error Classification

  • With the S and AR flag encoding in the IA32_MCi_STATUS register, UCR errors can be classified as:
  • Uncorrected no action required (UCNA) - is a UCR error that is not signaled via a machine check exception and, instead, is reported to system software as a corrected machine check error. UCNA errors indicate that some data in the system is corrupted, but the data has not been consumed and the processor state is valid and you may continue execution on this processor. UCNA errors require no action from system software to continue execution. A UNCA error is indicated with UC=1, PCC=0, S=0 and AR=0 in the IA32_MCi_STATUS register.
  • software recoverable action optional (SRAO) - a UCR error is signaled via a machine check exception and a system software recovery action is optional and not required to continue execution from this machine check exception. SRAO errors indicate that some data in the system is corrupt, but the data has not been consumed and the processor state is valid. SRAO errors provide the additional error information for system software to perform a recovery action. An SRAO error is indicated with UC=1, PCC=0, S=1, EN=1 and AR=0 in the
Page 642 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 642 · click to enlarge
Page 642

MACHINE-CHECK ARCHITECTURE

IA32_MCi_STATUS register. Recovery actions for SRAO errors are MCA error code specific. The MISCV and the ADDRV flags in the IA32_MCi_STATUS register are set when the additional error information is available from the IA32_MCi_MISC and the IA32_MCi_ADDR registers. System software needs to inspect the MCA error code fields in the IA32_MCi_STATUS register to identify the specific recovery action for a given SRAO error. If MISCV and ADDRV are not set, it is recommended that no system software error recovery be performed however, you can resume execution. • software recoverable action required (SRAR) - a UCR error that requires system software to take a recovery action on this processor before scheduling another stream of execution on this processor. SRAR errors indicate that the error was detected and raised at the point of the consumption in the execution flow. An SRAR error is indicated with UC=1, PCC=0, S=1, EN=1 and AR=1 in the IA32_MCi_STATUS register. Recovery actions are MCA error code specific. The MISCV and the ADDRV flags in the IA32_MCi_STATUS register are set when the additional error information is available from the IA32_MCi_MISC and the IA32_MCi_ADDR registers. System software needs to inspect the MCA error code fields in the IA32_MCi_STATUS register to identify the specific recovery action for a given SRAR error. If MISCV and ADDRV are not set, it is recommended that system software shutdown the system.

Table 15-6 summarizes UCR, corrected, and uncorrected errors.

Table 15-6. MC Error Classifications Type of Error1

UC PCC S AR Signaling Software Action Example

1 1 x x MCE Reset the system

SRAR 1 0 1 1 MCE For known MCACOD, take specific recovery action;

Cache to processor load error

For unknown MCACOD, must bugcheck

SRAO 1 0 1 0 MCE For known MCACOD, take specific recovery action;

Patrol scrub and explicit writeback poison errors

For unknown MCACOD, OK to keep the system running

UCNA 1 0 0 0 CMC Log the error and Ok to keep the system running

Corrected Error (CE) 0 0 x x CMC Log the error and no corrective action required

ECC in caches and memory

Uncorrected Error (UC) · Poison detection error

Page 643 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 643 · click to enlarge
Page 643

MACHINE-CHECK ARCHITECTURE

15.6.4 UCR Error Overwrite Rules

  • In general, the overwrite rules are as follows:
  • UCR errors will overwrite corrected errors.
  • Uncorrected (PCC=1) errors overwrite UCR (PCC=0) errors.
  • UCR errors are not written over previous UCR errors.
  • Corrected errors do not write over previous UCR errors.

Regardless of whether the 1st error is retained or the 2nd error is over written over the 1st error, the OVER flag in the IA32_MCi_STATUS register will be set to indicate an overflow condition. As the S flag and AR flag in the IA32_MCi_STATUS register are defined to be sticky flags, a second event cannot clear these 2 flags once set, however the MC bank information may be filled in for the 2nd error. The table below shows the overwrite rules and how to treat a second error if the first event is already logged in a MC bank along with the resulting bit setting of the UC, PCC, and AR flags in the IA32_MCi_STATUS register. As UCNA and SRA0 errors do not require recovery action from system software to continue program execution, a system reset by system software is not required unless the AR flag or PCC flag is set for the UCR overflow case (OVER=1, VAL=1, UC=1, PCC=0).

Table 15-7 lists overwrite rules for uncorrected errors, corrected errors, and UCR errors.

Table 15-7. Overwrite Rules for UC, CE, and UCR Errors First Event Second Event UC PCC S AR MCA Bank Reset System

CE UCR 1 0 0 if UCNA, else 1

1 if SRAR, else 0

second yes, if AR=1

UCR CE 1 0 0 if UCNA, else 1

1 if SRAR, else 0

first yes, if AR=1

UCNA UCNA 1 0 0 0 first no

UCNA SRAO 1 0 1 0 first no

UCNA SRAR 1 0 1 1 first yes

SRAO UCNA 1 0 1 0 first no

SRAO SRAO 1 0 1 0 first no

SRAO SRAR 1 0 1 1 first yes

SRAR UCNA 1 0 1 1 first yes

SRAR SRAO 1 0 1 1 first yes

SRAR SRAR 1 0 1 1 first yes

UCR UC 1 1 undefined undefined second yes

UC UCR 1 1 undefined undefined first yes

Page 644 of the Intel 253668-032US user manual — IA32_MCG_CTL ← FFFFFFFFFFFFFFFFH;
Page 644 · click to enlarge
Page 644

MACHINE-CHECK ARCHITECTURE

15.7 MACHINE-CHECK AVAILABILITY

The machine-check architecture and machine-check exception (#MC) are model-specific features. Software can execute the CPUID instruction to determine whether a processor implements these features. Following the execution of the CPUID instruction, the settings of the MCA flag (bit 14) and MCE flag (bit 7) in EDX indicate whether the processor implements the machine-check architecture and machine-check exception.

15.8 MACHINE-CHECK INITIALIZATION

To use the processors machine-check architecture, software must initialize the processor to activate the machine-check exception and the error- reporting mechanism.

Example 15-1 gives pseudocode for performing this initialization. This pseudocode checks for the existence of the machine-check architecture and exception; it then enables machine-check exception and the error-reporting register banks. The pseudocode shown is compatible with the Pentium 4, Intel Xeon, P6 family, and Pentium processors.

Following power up or power cycling, IA32_MCi_STATUS registers are not guaranteed to have valid data until after they are initially cleared to zero by software (as shown in the initialization pseudocode in Example 15-1). In addition, when using P6 family processors, software must set MCi_STATUS registers to zero when doing a soft-reset.

Example 15-1. Machine-Check Initialization Pseudocode

Check CPUID Feature Flags for MCE and MCA support IF CPU supports MCE THEN

IF CPU supports MCA THEN

IF (IA32_MCG_CAP.MCG_CTL_P = 1) (* IA32_MCG_CTL register is present *) THEN

IA32_MCG_CTL ← FFFFFFFFFFFFFFFFH;

Page 645 of the Intel 253668-032US user manual — 15.9 INTERPRETING THE MCA ERROR CODES
Page 645 · click to enlarge
Page 645

MACHINE-CHECK ARCHITECTURE

(* enables all MCA features *) FI

(* Determine number of error-reporting banks supported *) COUNT← IA32_MCG_CAP.Count; MAX_BANK_NUMBER ← COUNT - 1;

IF (Processor Family is 6H and Processor EXTMODEL:MODEL is less than 1AH) THEN

(* Enable logging of all errors except for MC0_CTL register *) FOR error-reporting banks (1 through MAX_BANK_NUMBER) DO

IA32_MCi_CTL ← 0FFFFFFFFFFFFFFFFH; OD

ELSE

(* Enable logging of all errors including MC0_CTL register *) FOR error-reporting banks (0 through MAX_BANK_NUMBER) DO

IA32_MCi_CTL ← 0FFFFFFFFFFFFFFFFH; OD FI

(* BIOS clears all errors only on power-on reset *) IF (BIOS detects Power-on reset) THEN

FOR error-reporting banks (0 through MAX_BANK_NUMBER) DO

IA32_MCi_STATUS ← 0; OD ELSE

FOR error-reporting banks (0 through MAX_BANK_NUMBER) DO

(Optional for BIOS and OS) Log valid errors (OS only) IA32_MCi_STATUS ← 0; OD

FI FI

Setup the Machine Check Exception (#MC) handler for vector 18 in IDT

Set the MCE bit (bit 6) in CR4 register to enable Machine-Check Exceptions FI

15.9 INTERPRETING THE MCA ERROR CODES

When the processor detects a machine-check error condition, it writes a 16- bit error code to the MCA error code field of one of the IA32_MCi_STATUS registers and sets the VAL (valid) flag in that register. The processor may

Page 646 of the Intel 253668-032US user manual — 15.9.1 Simple Error Codes
Page 646 · click to enlarge
Page 646

MACHINE-CHECK ARCHITECTURE

also write a 16-bit model-specific error code in the IA32_MCi_STATUS register depending on the implementation of the machine-check architec ture of the processor.

The MCA error codes are architecturally defined for Intel 64 and IA-32 processors. To determine the cause of a machine-check exception, the machine-check exception handler must read the VAL flag for each IA32_MCi_STATUS register. If the flag is set, the machine check-exception handler must then read the MCA error code field of the register. It is the encoding of the MCA error code field [15:0] that determines the type of error being reported and not the register bank reporting it.

There are two types of MCA error codes: simple error codes and compound error codes.

15.9.1 Simple Error Codes

Table 15-8 shows the simple error codes. These unique codes indicate global error information.

Table 15-8. IA32_MCi_Status [15:0] Simple Error Code Encoding Error Code Binary Encoding Meaning

No Error 0000 No error has been reported to this bank of error-reporting registers.

Unclassified 0000 0000 0000 0001 This error has not been classified into the MCA error classes.

Microcode ROM Parity Error

0000 0000 0000 0010 Parity error in internal microcode ROM

External Error 0000 0000 0000 0011 The BINIT# from another processor caused this processor to enter machine check.1

FRC Error 0000 0000 0000 0100 FRC (functional redundancy check) master/slave error

Internal Parity Error 0000 0000 0000 0101 Internal parity error.

Internal Timer Error 0000 0100 0000 0000 Internal timer error.

Internal Unclassified 0000 01xx xxxx xxxx Internal unclassified errors. 2

Page 647 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 647 · click to enlarge
Page 647

MACHINE-CHECK ARCHITECTURE

15.9.2 Compound Error Codes

Compound error codes describe errors related to the TLBs, memory, caches, bus and interconnect logic, and internal timer. A set of sub-fields is common to all of compound errors. These sub-fields describe the type of access, level in the cache hierarchy, and type of request. Table 15-9 shows the general form of the compound error codes.

Table 15-9. IA32_MCi_Status [15:0] Compound Error Code Encoding Type Form Interpretation

Generic Cache Hierarchy 000F 0000 0000 11LL Generic cache hierarchy error

TLB Errors 000F 0000 0001 TTLL {TT}TLB{LL}_ERR

Memory Controller Errors 000F 0000 1MMM CCCC {MMM}_CHANNEL{CCCC}_ERR

Cache Hierarchy Errors 000F 0001 RRRR TTLL {TT}CACHE{LL}_{RRRR}_ERR

Bus and Interconnect Errors 000F 1PPT RRRR IILL BUS{LL}_{PP}_{RRRR}_{II}_{T}_ERR

The “Interpretation” column in the table indicates the name of a compound error. The name is constructed by substituting mnemonics for the sub-field names given within curly braces. For example, the error code ICACHEL1_RD_ERR is constructed from the form:

{TT}CACHE{LL}_{RRRR}_ERR, where {TT} is replaced by I, {LL} is replaced by L1, and {RRRR} is replaced by RD.

For more information on the “Form” and “Interpretation” columns, see Sections Section 15.9.2.1, “Correction Report Filtering (F) Bit” through Section 15.9.2.5, “Bus and Interconnect Errors”.

15.9.2.1 Correction Report Filtering (F) Bit

  • Starting with Intel Core Duo processors, bit 12 in the “Form” column in Table 15-9 is used to indicate that a particular posting to a log may be the last posting for corrections in that line/entry, at least for some time:
  • 0 in bit 12 indicates “normal” filtering (original P6/Pentium4/Xeon processor meaning).
  • 1 in bit 12 indicates “corrected” filtering (filtering is activated for the line/entry in the posting). Filtering means that some or all of the subsequent corrections to this entry (in this structure) will not be posted. The enhanced error reporting introduced with the Intel Core Duo processors is based on tracking the lines affected by repeated corrections (see Section 15.4, “Enhanced Cache Error reporting”). This capability is indicated by IA32_MCG_CAP[11]. Only the first few correction events for a line are posted; subsequent redundant correction events to the same line are not posted. Uncorrected events are always posted.
Page 648 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 648 · click to enlarge
Page 648

MACHINE-CHECK ARCHITECTURE

The behavior of error filtering after crossing the yellow threshold is model- specific.

15.9.2.2 Transaction Type (TT) Sub-Field

The 2-bit TT sub-field (Table 15-10) indicates the type of transaction (data, instruction, or generic). The sub-field applies to the TLB, cache, and inter connect error conditions. Note that interconnect error conditions are prima rily associated with P6 family and Pentium processors, which utilize an external APIC bus separate from the system bus. The generic type is reported when the processor cannot determine the transaction type.

Table 15-10. Encoding for TT (Transaction Type) Sub-Field Transaction Type Mnemonic Binary Encoding

15.9.2.3 Level (LL) Sub-Field

The 2-bit LL sub-field (see Table 15-11) indicates the level in the memory hierarchy where the error occurred (level 0, level 1, level 2, or generic). The LL sub-field also applies to the TLB, cache, and interconnect error condi tions. The Pentium 4, Intel Xeon, and P6 family processors support two levels in the cache hierarchy and one level in the TLBs. Again, the generic type is reported when the processor cannot determine the hierarchy level.

Table 15-11. Level Encoding for LL (Memory Hierarchy Level) Sub-Field

Hierarchy Level Mnemonic Binary Encoding

Level 0 L0 00

Level 1 L1 01

Level 2 L2 10

15.9.2.4 Request (RRRR) Sub-Field

The 4-bit RRRR sub-field (see Table 15-12) indicates the type of action asso ciated with the error. Actions include read and write operations, prefetches, cache evictions, and snoops. Generic error is returned when the type of error cannot be determined. Generic read and generic write are returned when the processor cannot determine the type of instruction or data request that

Show 4 more labels / short text on this page
Instruction I 00 · Data D 01 · Generic G 10 · Generic LG 11
Page 649 of the Intel 253668-032US user manual — OBS 10
Page 649 · click to enlarge
Page 649

MACHINE-CHECK ARCHITECTURE

caused the error. Eviction and snoop requests apply only to the caches. All of the other requests apply to TLBs, caches and interconnects.

Table 15-12. Encoding of Request (RRRR) Sub-Field Request Type Mnemonic Binary Encoding

Generic Error ERR 0000

Generic Read RD 0001

Generic Write WR 0010

Data Read DRD 0011

Data Write DWR 0100

Instruction Fetch IRD 0101

15.9.2.5 Bus and Interconnect Errors

The bus and interconnect errors are defined with the 2-bit PP (participation), 1-bit T (time-out), and 2-bit II (memory or I/O) sub-fields, in addition to the LL and RRRR sub-fields (see Table 15-13). The bus error conditions are implementation dependent and related to the type of bus implemented by the processor. Likewise, the interconnect error conditions are predicated on a specific implementation-dependent interconnect model that describes the connections between the different levels of the storage hierarchy. The type of bus is implementation dependent, and as such is not specified in this document. A bus or interconnect transaction consists of a request involving an address and a response.

Table 15-13. Encodings of PP, T, and II Sub-Fields Sub-Field Transaction Mnemonic Binary Encoding

PP (Participation) Local processor* originated request SRC 00

Local processor* responded to request RES 01

Local processor* observed error as third party

OBS 10

T (Time-out) Request timed out TIMEOUT 1

Request did not time out NOTIMEOUT 0

II (Memory or I/O) Memory Access M 00

Show 5 more labels / short text on this page
Prefetch PREFETCH 0110 · Eviction EVICT 0111 · Snoop SNOOP 1000 · Generic 11 · Reserved 01
Page 650 of the Intel 253668-032US user manual — 15.9.3 Architecturally Defined UCR Errors
Page 650 · click to enlarge
Page 650

MACHINE-CHECK ARCHITECTURE

Table 15-13. Encodings of PP, T, and II Sub-Fields (Contd.)

I/O IO 10

15.9.2.6 Memory Controller Errors

The memory controller errors are defined with the 3-bit MMM (memory transaction type), and 4-bit CCCC (channel) sub-fields. The encodings for MMM and CCCC are defined in Table 15-14.

Table 15-14. Encodings of MMM and CCCC Sub-Fields Sub-Field Transaction Mnemonic Binary Encoding

MMM Generic undefined request GEN 000

Memory read error RD 001

Memory write error WR 010

Address/Command Error AC 011

Memory Scrubbing Error MS 100

CCCC Channel number CHN 0000-1110

Channel not specified 1111

15.9.3 Architecturally Defined UCR Errors

Software recoverable compound error code are defined in this section.

15.9.3.1 Architecturally Defined SRAO Errors

  • The following two SRAO errors are architecturally defined.
  • UCR Errors detected by memory controller scrubbing; and
  • UCR Errors detected during L3 cache (L3) explicit writebacks.

The MCA error code encodings for these two architecturally-defined UCR errors corresponds to sub-classes of compound MCA error codes (see Table

Other transaction 11 · Reserved 101-111

Page 651 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 651 · click to enlarge
Page 651

MACHINE-CHECK ARCHITECTURE

15-9). Their values and compound encoding format are given in Table 15-15.

Table 15-15. MCA Compound Error Code Encoding for SRAO Errors Type MCACOD Value MCA Error Code Encoding1

Memory Scrubbing 0xC0 - 0xCF 0000_0000_1100_CCCC

000F 0000 1MMM CCCC (Memory Controller Error), where

Memory subfield MMM = 100B (memory scrubbing)

Channel subfield CCCC = channel # or generic

L3 Explicit Writeback 0x17A 0000_0001_0111_1010

000F 0001 RRRR TTLL (Cache Hierarchy Error) where

Request subfields RRRR = 0111B (Eviction)

Transaction Type subfields TT = 10B (Generic)

Level subfields LL = 10B

Table 15-16 lists values of relevant bit fields of IA32_MCi_STATUS for archi tecturally defined SRAO errors.

Table 15-16. IA32_MCi_STATUS Values for SRAO Errors SRAO Error Valid OVER UC EN MISCV ADDRV PCC S AR MCACOD

Memory Scrubbing 1 0 1 0 1 0 0xC0-0xCF

L3 Explicit Writeback 1 0 1 0 1 0 0x17A

For both the memory scrubbing and L3 explicit writeback errors, the ADDRV and MISCV flags in the IA32_MCi_STATUS register are set to indicate that the offending physical address information is available from the IA32_MCi_MISC and the IA32_MCi_ADDR registers. For the memory scrub bing and L3 explicit writeback errors, the address mode in the IA32_MCi_MISC register should be set as physical address mode (010b) and the address LSB information in the IA32_MCi_MISC register should indicate the lowest valid address bit in the address information provided from the IA32_MCi_ADDR register.

An MCE signal is broadcast to all logical processors on the system on which the UCR errors are supported. MCi_STATUS banks can be shared by logical processors within a core or within the same package. So several logical processors may find an SRAO error in the shared IA32_MCi_STATUS bank but other processors do not find it in any of the IA32_MCi_STATUS banks. Table 15-17 shows the RIPV and EIPV flag indication in the

Page 652 of the Intel 253668-032US user manual — RIPV EIPV RIPV EIPV
Page 652 · click to enlarge
Page 652

MACHINE-CHECK ARCHITECTURE

IA32_MCG_STATUS register for the memory scrubbing and L3 explicit write back errors on both the reporting and non-reporting logical processors.

Table 15-17. IA32_MCG_STATUS Flag Indication for SRAO Errors SRAO Type Reporting Logical Processors Non-reporting Logical Processors

RIPV EIPV RIPV EIPV

Memory Scrubbing 1 0 1 0

L3 Explicit Writeback 1 0 1 0

15.9.3.2 Architecturally Defined SRAR Errors

  • The following two SRAR errors are architecturally defined.
  • UCR Errors detected on data load; and
  • UCR Errors detected on instruction fetch.

The MCA error code encodings for these two architecturally-defined UCR errors corresponds to sub-classes of compound MCA error codes (see Table 15-9). Their values and compound encoding format are given in Table 15-18.

Table 15-18. MCA Compound Error Code Encoding for SRAR Errors Type MCACOD Value MCA Error Code Encoding1

Data Load 0x134 0000_0001_0011_0100

000F 0001 RRRR TTLL (Cache Hierarchy Error), where

Request subfield RRRR = 0011B (Data Load)

Transaction Type subfield TT= 01B (Data)

Level subfield LL = 00B (Level 0)

Instruction Fetch 0x150 0000_0001_0101_0000

000F 0001 RRRR TTLL (Cache Hierarchy Error), where

Request subfield RRRR = 0101B (Instruction Fetch)

Transaction Type subfield TT= 00B (Instruction)

Level subfield LL = 00B (Level 0)

Page 653 of the Intel 253668-032US user manual — RIPV EIPV RIPV EIPV
Page 653 · click to enlarge
Page 653

MACHINE-CHECK ARCHITECTURE

Table 15-19 lists values of relevant bit fields of IA32_MCi_STATUS for archi tecturally defined SRAR errors.

Table 15-19. IA32_MCi_STATUS Values for SRAR Errors SRAR Error Valid OVER UC EN MISCV ADDRV PCC S AR MCACOD

Data Load 1 0 1 0 1 1 0x134

Instruction Fetch 1 0 1 0 1 1 0x150

For both the data load and instruction fetch errors, the ADDRV and MISCV flags in the IA32_MCi_STATUS register are set to indicate that the offending physical address information is available from the IA32_MCi_MISC and the IA32_MCi_ADDR registers. For the memory scrubbing and L3 explicit write back errors, the address mode in the IA32_MCi_MISC register should be set as physical address mode (010b) and the address LSB information in the IA32_MCi_MISC register should indicate the lowest valid address bit in the address information provided from the IA32_MCi_ADDR register.

An MCE signal is broadcast to all logical processors on the system on which the UCR errors are supported. The IA32_MCG_STATUS MSR allows system software to distinguish the affected logical processor of an SRAR error amongst logical processors that observed SRAR via a shared MCi_STATUS bank.

Table 15-20 shows the RIPV and EIPV flag indication in the IA32_MCG_STATUS register for the data load and instruction fetch errors on both the reporting and non-reporting logical processors.

Table 15-20. IA32_MCG_STATUS Flag Indication for SRAR Errors SRAR Type Affected Logical Processors Non-Affected Logical Processors

RIPV EIPV RIPV EIPV

Data Load 0 1 1 0

instruction Fetch 0 0 1 0

The affected logical processor is the one that has detected and raised an SRAR error at the point of the consumption in the execution flow. The affected logical processor should find the Data Load or the Instruction Fetch error information in the IA32_MCi_STATUS register that is reporting the SRAR error.

For Data Load recoverable errors, the affected logical processor should find that the IA32_MCG_STATUS.RIPV flag is cleared and the IA32_MCG_STATUS.EIPV flag is set indicating that the error is detected at the instruction pointer saved on the stack for this machine check exception and restarting execution with the interrupted context is not possible.

Page 654 of the Intel 253668-032US user manual — 15.9.4 Multiple MCA Errors
Page 654 · click to enlarge
Page 654

MACHINE-CHECK ARCHITECTURE

For Instruction Fetch recoverable error, the affected logical processor should find that the RIPV flag and the EIPV Flag in the IA32_MCG_STATUS register are cleared, indicating that the error is detected at the instruction pointer saved on the stack may not be associated with this error and restarting the execution with the interrupted context is not possible.

The logical processors that observed but not affected by an SRAR error should find that the RIPV flag in the IA32_MCG_STATUS register is set and the EIPV flag in the IA32_MCG_STATUS register is cleared, indicating that it is safe to restart the execution at the instruction saved on the stack for the machine check exception on these processors after the recovery action is successfully taken by system software.

For the Data-Load and the Instruction-Fetch recoverable errors, system software may take the following recovery actions for the affected logical processor: • The current executing thread cannot be continued. You must terminate the interrupted stream of execution and provide a new stream of execution on return from the machine check handler for the affected logical processor

In addition to taking the recovery action described above, system software may also need to disable the use of the affected page from the program. This recovery action by system software may prevent the occurrence of future consumption errors from that affected page.

15.9.4 Multiple MCA Errors

When multiple MCA errors are detected within a certain detection window, the processor may aggregate the reporting of these errors together as a single event, i.e. a single machine exception condition. If this occurs, system software may find multiple MCA errors logged in different MC banks on one logical processor or find multiple MCA errors logged across different processors for a single machine check broadcast event. In order to handle multiple UCR errors reported from a single machine check event and possibly recover from multiple errors, system software may consider the following: • Whether it can recover from multiple errors is determined by the most severe error reported on the system. If the most severe error is found to be an unrecov erable error (VAL=1, UC=1, PCC=1 and EN=1) after system software examines the MC banks of all processors to which the MCA signal is broadcast, recovery from the multiple errors is not possible and system software needs to reset the system.

Page 655 of the Intel 253668-032US user manual — 15.10 GUIDELINES FOR WRITING MACHINE-CHECK SOFTWARE
Page 655 · click to enlarge
Page 655

MACHINE-CHECK ARCHITECTURE

  • When multiple recoverable errors are reported and no other fatal condition (e.g.. overflowed condition for SRAR error) is found for the reported recoverable errors, it is possible for system software to recover from the multiple recoverable errors by taking necessary recovery action for each individual recoverable error. However, system software can no longer expect one to one relationship with the error information recorded in the IA32_MCi_STATUS register and the states of the RIPV and EIPV flags in the IA32_MCG_STATUS register as the states of the RIPV and the EIPV flags in the IA32_MCG_STATUS register may indicate the information for the most severe error recorded on the processor. System software is required to use the RIPV flag indication in the IA32_MCG_STATUS register to make a final decision of recoverability of the errors and find the restart-ability requirement after examining each IA32_MCi_STATUS register error information in the MC banks.

15.9.5 Machine-Check Error Codes Interpretation

Appendix E, “Interpreting Machine-Check Error Codes,” provides information on interpreting the MCA error code, model-specific error code, and other information error code fields. For P6 family processors, information has been included on decoding external bus errors. For Pentium 4 and Intel Xeon processors; information is included on external bus, internal timer and cache hierarchy errors.

15.10 GUIDELINES FOR WRITING MACHINE-CHECK SOFTWARE

  • The machine-check architecture and error logging can be used in three different ways:
  • To detect machine errors during normal instruction execution, using the machine-check exception (#MC).
  • To periodically check and log machine errors.
  • To examine recoverable UCR errors, determine software recoverability and perform recovery actions via a machine-check exception handler or a corrected machine-check interrupt handler.

To use the machine-check exception, the operating system or executive software must provide a machine-check exception handler. This handler may need to be designed specifically for each family of processors.

A special program or utility is required to log machine errors.

Page 656 of the Intel 253668-032US user manual — 15.10.1 Machine-Check Exception Handler
Page 656 · click to enlarge
Page 656

MACHINE-CHECK ARCHITECTURE

Guidelines for writing a machine-check exception handler or a machine- error logging utility are given in the following sections.

15.10.1 Machine-Check Exception Handler

The machine-check exception (#MC) corresponds to vector 18. To service machine-check exceptions, a trap gate must be added to the IDT. The pointer in the trap gate must point to a machine-check exception handler. Two approaches can be taken to designing the exception handler:

1. The handler can merely log all the machine status and error information, then call a debugger or shut down the system.
2. The handler can analyze the reported error information and, in some cases, attempt to correct the error and restart the processor.

For Pentium 4, Intel Xeon, P6 family, and Pentium processors; virtually all machine-check conditions cannot be corrected (they result in abort-type exceptions). The logging of status and error information is therefore a base line implementation requirement.

  • When recovery from a machine-check error may be possible, consider the following when writing a machine-check exception handler:
  • To determine the nature of the error, the handler must read each of the errorreporting register banks. The count field in the IA32_MCG_CAP register gives number of register banks. The first register of register bank 0 is at address 400H.
  • The VAL (valid) flag in each IA32_MC i _STATUS register indicates whether the error information in the register is valid. If this flag is clear, the registers in that bank do not contain valid error information and do not need to be checked.
  • To write a portable exception handler, only the MCA error code field in the IA32_MC i _STATUS register should be checked. See Section 15.9, “Interpreting the MCA Error Codes,” for information that can be used to write an algorithm to interpret this field.
  • The RIPV, PCC, and OVER flags in each IA32_MCi_STATUS register indicate whether recovery from the error is possible. If PCC or OVER are set, recovery is not possible. If RIPV is not set, program execution can not be restarted reliably. When recovery is not possible, the handler typically records the error information and signals an abort to the operating system.
  • Correctable errors are corrected automatically by the processor. The UC flag in each IA32_MC i _STATUS register indicates whether the processor automatically corrected an error.
  • The RIPV flag in the IA32_MCG_STATUS register indicates whether the program can be restarted at the instruction indicated by the instruction pointer (the address of the instruction pushed on the stack when the exception was
Page 657 of the Intel 253668-032US user manual — NOTE
Page 657 · click to enlarge
Page 657

MACHINE-CHECK ARCHITECTURE

  • generated). If this flag is clear, the processor may still be able to be restarted (for debugging purposes) but not without loss of program continuity.
  • For unrecoverable errors, the EIPV flag in the IA32_MCG_STATUS register indicates whether the instruction indicated by the instruction pointer pushed on the stack (when the exception was generated) is related to the error. If the flag is clear, the pushed instruction may not be related to the error.
  • The MCIP flag in the IA32_MCG_STATUS register indicates whether a machinecheck exception was generated. Before returning from the machine-check exception handler, software should clear this flag so that it can be used reliably by an error logging utility. The MCIP flag also detects recursion. The machine-check architecture does not support recursion. When the processor detects machinecheck recursion, it enters the shutdown state.

Example 15-2 gives typical steps carried out by a machine-check exception handler.

Example 15-2. Machine-Check Exception Handler Pseudocode

IF CPU supports MCE

THEN

IF CPU supports MCA

THEN

call errorlogging routine; (* returns restartability *) FI; ELSE (* Pentium(R) processor compatible *)

READ P5_MC_ADDR READ P5_MC_TYPE; report RESTARTABILITY to console; FI; IF error is not restartable

THEN

report RESTARTABILITY to console; abort system; FI; CLEAR MCIP flag in IA32_MCG_STATUS;

15.10.2 Pentium Processor Machine-Check Exception Handling

Machine-check exception handler on P6 family and later processor families, should follow the guidelines described in Section 15.10.1 and Example 15-2 that check the processor’s support of MCA.

NOTE

On processors that support MCA (CPUID.1.EDX.MCA == 1) reading the P5_MC_TYPE and P5_MC_ADDR registers may produce invalid data.

Page 658 of the Intel 253668-032US user manual — THEN
Page 658 · click to enlarge
Page 658

MACHINE-CHECK ARCHITECTURE

When machine-check exceptions are enabled for the Pentium processor (MCE flag is set in control register CR4), the machine-check exception handler uses the RDMSR instruction to read the error type from the P5_MC_TYPE register and the machine check address from the P5_MC_ADDR register. The handler then normally reports these register values to the system console before aborting execution (see Example 15-2).

15.10.3 Logging Correctable Machine-Check Errors

The error handling routine for servicing the machine-check exceptions is responsible for logging uncorrected errors.

  • If a machine-check error is correctable, the processor does not generate a machine-check exception for it. To detect correctable machine-check errors, a utility program must be written that reads each of the machine-check error-reporting register banks and logs the results in an accounting file or data structure. This utility can be implemented in either of the following ways.
  • A system daemon that polls the register banks on an infrequent basis, such as hourly or daily.
  • A user-initiated application that polls the register banks and records the exceptions. Here, the actual polling service is provided by an operating-system driver or through the system call interface.
  • An interrupt service routine servicing CMCI can read the MC banks and log the error.

Example 15-3 gives pseudocode for an error logging utility.

Example 15-3. Machine-Check Error Logging Pseudocode

Assume that execution is restartable; IF the processor supports MCA

THEN FOR each bank of machine-check registers

DO

READ IA32_MCi_STATUS; IF VAL flag in IA32_MCi_STATUS = 1

THEN

IF ADDRV flag in IA32_MCi_STATUS = 1

THEN READ IA32_MCi_ADDR; FI; IF MISCV flag in IA32_MCi_STATUS = 1

THEN READ IA32_MCi_MISC; FI; IF MCIP flag in IA32_MCG_STATUS = 1

(* Machine-check exception is in progress *)

Page 659 of the Intel 253668-032US user manual — THEN
Page 659 · click to enlarge
Page 659

MACHINE-CHECK ARCHITECTURE

AND PCC flag in IA32_MCi_STATUS = 1 OR RIPV flag in IA32_MCG_STATUS = 0 (* execution is not restartable *)

THEN

RESTARTABILITY = FALSE; return RESTARTABILITY to calling procedure; FI; Save time-stamp counter and processor ID; Set IA32_MCi_STATUS to all 0s; Execute serializing instruction (i.e., CPUID); FI; OD; FI;

If the processor supports the machine-check architecture, the utility reads through the banks of error-reporting registers looking for valid register entries. It then saves the values of the IA32_MCi_STATUS, IA32_MCi_ADDR, IA32_MCi_MISC and IA32_MCG_STATUS registers for each bank that is valid. The routine minimizes processing time by recording the raw data into a system data structure or file, reducing the overhead associated with polling. User utilities analyze the collected data in an off-line environment.

When the MCIP flag is set in the IA32_MCG_STATUS register, a machine- check exception is in progress and the machine-check exception handler has called the exception logging routine.

Once the logging process has been completed the exception-handling routine must determine whether execution can be restarted, which is usually possible when damage has not occurred (The PCC flag is clear, in the IA32_MCi_STATUS register) and when the processor can guarantee that execution is restartable (the RIPV flag is set in the IA32_MCG_STATUS register). If execution cannot be restarted, the system is not recoverable and the exception-handling routine should signal the console appropriately before returning the error status to the Operating System kernel for subse quent shutdown.

The machine-check architecture allows buffering of exceptions from a given error-reporting bank although the Pentium 4, Intel Xeon, and P6 family processors do not implement this feature. The error logging routine should provide compatibility with future processors by reading each hardware error-reporting bank's IA32_MCi_STATUS register and then writing 0s to clear the OVER and VAL flags in this register. The error logging utility should re-read the IA32_MCi_STATUS register for the bank ensuring that the valid bit is clear. The processor will write the next error into the register bank and set the VAL flags.

Additional information that should be stored by the exception-logging routine includes the processor’s time-stamp counter value, which provides a

Page 660 of the Intel 253668-032US user manual — 15.10.4 Machine-Check Software Handler Guidelines for Error Recovery
Page 660 · click to enlarge
Page 660

MACHINE-CHECK ARCHITECTURE

mechanism to indicate the frequency of exceptions. A multiprocessing oper ating system stores the identity of the processor node incurring the excep tion using a unique identifier, such as the processor’s APIC ID (see Section 10.9, “Handling Interrupts”).

The basic algorithm given in Example 15-3 can be modified to provide more robust recovery techniques. For example, software has the flexibility to attempt recovery using information unavailable to the hardware. Specifi cally, the machine-check exception handler can, after logging carefully analyze the error-reporting registers when the error-logging routine reports an error that does not allow execution to be restarted. These recovery tech niques can use external bus related model-specific information provided with the error report to localize the source of the error within the system and determine the appropriate recovery strategy.

15.10.4 Machine-Check Software Handler Guidelines for Error Recovery

15.10.4.1 Machine-Check Exception Handler for Error Recovery

  • When writing a machine-check exception (MCE) handler to support software recovery from Uncorrected Recoverable (UCR) errors, consider the following:
  • When IA32_MCG_CAP [24] is zero, there are no recoverable errors supported and all machine-check are fatal exceptions. The logging of status and error information is therefore a baseline implementation requirement.
  • When IA32_MCG_CAP [24] is 1, certain uncorrected errors called uncorrected recoverable (UCR) errors may be software recoverable. The handler can analyze the reported error information, and in some cases attempt to recover from the uncorrected error and continue execution.
  • For processors with DisplayFamily_DisplayModel encoding of 06H_EH and above, a MCA signal is broadcast to all logical processors in the system. Due to the potentially shared machine check MSR resources among the logical processors on the same package/core, the MCE handler may be required to synchronize with the other processors that received a machine check error and serialize access to the machine check registers when analyzing, logging and clearing the information in the machine check registers.
  • The VAL (valid) flag in each IA32_MCi_STATUS register indicates whether the error information in the register is valid. If this flag is clear, the registers in that bank do not contain valid error information and should not be checked.
  • The MCE handler is primarily responsible for processing uncorrected errors. The UC flag in each IA32_MCi_Status register indicates whether the reported error
Page 661 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 661 · click to enlarge
Page 661

MACHINE-CHECK ARCHITECTURE

  • was corrected (UC=0) or uncorrected (UC=1). The MCE handler can optionally log and clear the corrected errors in the MC banks if it can implement software algorithm to avoid the undesired race conditions with the CMCI or CMC polling handler.
  • For uncorrectable errors, the EIPV flag in the IA32_MCG_STATUS register indicates (when set) that the instruction pointed to by the instruction pointer pushed onto the stack when the machine-check exception is generated is directly associated with the error. When this flag is cleared, the instruction pointed to may not be associated with the error.
  • The MCIP flag in the IA32_MCG_STATUS register indicates whether a machinecheck exception was generated. When a machine check exception is generated, it is expected that the MCIP flag in the IA32_MCG_STATUS register is set to 1. If it is not set, this machine check was generated by either an INT 18 instruction or some piece of hardware signaling an interrupt with vector 18.
  • When IA32_MCG_CAP [24] is 1, the following rules can apply when writing a machine check exception (MCE) handler to support software recovery:
  • The PCC flag in each IA32_MCi_STATUS register indicates whether recovery from the error is possible for uncorrected errors (UC=1). If the PCC flag is set for uncorrected errors (UC=1), recovery is not possible. When recovery is not possible, the MCE handler typically records the error information and signals the operating system to reset the system.
  • The RIPV flag in the IA32_MCG_STATUS register indicates whether restarting the program execution from the instruction pointer saved on the stack for the machine check exception is possible. When the RIPV is set, program execution can be restarted reliably when recovery is possible. If the RIPV flag is not set, program execution cannot be restarted reliably. In this case the recovery algorithm may involve terminating the current program execution and resuming an alternate thread of execution upon return from the machine check handler when recovery is possible. When recovery is not possible, the MCE handler signals the operating system to reset the system.
  • When the EN flag is zero but the VAL and UC flags are one in the IA32_MCi_STATUS register, the reported uncorrected error in this bank is not enabled. As uncorrected errors with the EN flag = 0 are not the source of machine check exceptions, the MCE handler should log and clear non-enabled errors when the S bit is set and should continue searching for enabled errors from the other IA32_MCi_STATUS registers. Note that when IA32_MCG_CAP [24] is 0, any uncorrected error condition (VAL =1 and UC=1) including the one with the EN flag cleared are fatal and the handler must signal the operating system to reset the system. For the errors that do not generate machine check exceptions, the EN flag has no meaning. See Appendix A: Table A-4 to find the errors that do not generate machine check exceptions.
  • When the VAL flag is one, the UC flag is one, the EN flag is one and the PCC flag is zero in the IA32_MCi_STATUS register, the error in this bank is an uncorrected recoverable (UCR) error. The MCE handler needs to examine the S flag and the
Page 662 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 662 · click to enlarge
Page 662

MACHINE-CHECK ARCHITECTURE

  • AR flag to find the type of the UCR error for software recovery and determine if software error recovery is possible.
  • When both the S and the AR flags are clear in the IA32_MCi_STATUS register for the UCR error (VAL=1, UC=1, EN=x and PCC=0), the error in this bank is an uncorrected no-action required error (UCNA). UCNA errors are uncorrected but do not require any OS recovery action to continue execution. These errors indicate that some data in the system is corrupt, but that data has not been consumed and may not be consumed. If that data is consumed a non-UNCA machine check exception will be generated. UCNA errors are signaled in the same way as corrected machine check errors and the CMCI and CMC polling handler is primarily responsible for handling UCNA errors. Like corrected errors, the MCA handler can optionally log and clear UCNA errors as long as it can avoid the undesired race condition with the CMCI or CMC polling handler. As UCNA errors are not the source of machine check exceptions, the MCA handler should continue searching for uncorrected or software recoverable errors in all other MC banks.
  • When the S flag in the IA32_MCi_STATUS register is set for the UCR error ((VAL=1, UC=1, EN=1 and PCC=0), the error in this bank is software recoverable and it was signaled through a machine-check exception. The AR flag in the IA32_MCi_STATUS register further clarifies the type of the software recoverable errors.
  • When the AR flag in the IA32_MCi_STATUS register is clear for the software recoverable error (VAL=1, UC=1, EN=1, PCC=0 and S=1), the error in this bank is a software recoverable action optional (SRAO) error. The MCE handler and the operating system can analyze the IA32_MCi_STATUS [15:0] to implement MCA error code specific optional recovery action, but this recovery action is optional. System software can resume the program execution from the instruction pointer saved on the stack for the machine check exception when the RIPV flag in the IA32_MCG_STATUS register is set.
  • When the OVER flag in the IA32_MCi_STATUS register is set for the SRAO error (VAL=1, UC=1, EN=1, PCC=0, S=1 and AR=0), the MCE handler cannot take recovery action as the information of the SRAO error in the IA32_MCi_STATUS register was potentially lost due to the overflow condition. Since the recovery action for SRAO errors is optional, restarting the program execution from the instruction pointer saved on the stack for the machine check exception is still possible for the overflowed SRAO error if the RIPV flag in the IA32_MCG_STATUS is set.
  • When the AR flag in the IA32_MCi_STATUS register is set for the software recoverable error (VAL=1, UC=1, EN=1, PCC=0 and S=1), the error in this bank is a software recoverable action required (SRAR) error. The MCE handler and the operating system must take recovery action in order to continue execution after the machine-check exception. The MCA handler and the operating system need to analyze the IA32_MCi_STATUS [15:0] to determine the MCA error code specific recovery action. If no recovery action can be performed, the operating system must reset the system.
Page 663 of the Intel 253668-032US user manual — THEN
Page 663 · click to enlarge
Page 663

MACHINE-CHECK ARCHITECTURE

  • When the OVER flag in the IA32_MCi_STATUS register is set for the SRAR error (VAL=1, UC=1, EN=1, PCC=0, S=1 and AR=1), the MCE handler cannot take recovery action as the information of the SRAR error in the IA32_MCi_STATUS register was potentially lost due to the overflow condition. Since the recovery action for SRAR errors must be taken, the MCE handler must signal the operating system to reset the system.
  • When the MCE handler cannot find any uncorrected (VAL=1, UC=1 and EN=1) or any software recoverable errors (VAL=1, UC=1, EN=1, PCC=0 and S=1) in any of the IA32_MCi banks of the processors, this is an unexpected condition for the MCE handler and the handler should signal the operating system to reset the system.
  • Before returning from the machine-check exception handler, software must clear the MCIP flag in the IA32_MCG_STATUS register. The MCIP flag is used to detect recursion. The machine-check architecture does not support recursion. When the processor receives a machine check when MCIP is set, it automatically enters the shutdown state.

Example 15-4 gives pseudocode for an MC exception handler that supports recovery of UCR.

Example 15-4. Machine-Check Error Handler Pseudocode Supporting UCR

MACHINE CHECK HANDLER: (* Called from INT 18 handler *) NOERROR = TRUE; ProcessorCount = 0; IF CPU supports MCA

THEN

RESTARTABILITY = TRUE; IF (Processor Family = 6 AND Display_Model >= 0EH) OR (Processor Family > 6)

THEN

MCA_BROADCAST = TRUE; Acquire SpinLock; ProcessorCount++; (* Allowing one logical processor at a time to examine machine check registers *)

CALL MCA ERROR PROCESSING; (* returns RESTARTABILITY and NOERROR *) ELSE

MCA_BROADCAST = FALSE; (* Implement a rendezvous mechanism with the other processors if necessary *) CALL MCA ERROR PROCESSING; FI; ELSE (* Pentium(R) processor compatible *)

READ P5_MC_ADDR READ P5_MC_TYPE; RESTARTABILITY = FALSE; FI;

IF NOERROR = TRUE THEN

IF NOT (MCG_RIPV = 1 AND MCG_EIPV = 0)

THEN

Page 664 of the Intel 253668-032US user manual — CLEAR_MC_BANK = TRUE; GOTO LOG MCA REGISTER; FI;
Page 664 · click to enlarge
Page 664

MACHINE-CHECK ARCHITECTURE

RESTARTABILITY = FALSE; FI FI;

IF RESTARTABILITY = FALSE

THEN

Report RESTARTABILITY to console; Reset system; FI;

IF MCA_BROADCAST = TRUE

THEN

IF ProcessorCount = MAX_PROCESSORS AND NOERROR = TRUE

THEN

Report RESTARTABILITY to console; Reset system; FI; Release SpinLock; Wait till ProcessorCount = MAX_PROCESSRS on system; (* implement a timeout and abort function if necessary *) FI; CLEAR MCIP flag in IA32_MCG_STATUS; RESUME Execution; (* End of MACHINE CHECK HANDLER*)

MCA ERROR PROCESSING: (* MCA Error Processing Routine called from MCA Handler *) IF MCIP flag in IA32_MCG_STATUS = 0

THEN (* MCIP=0 upon MCA is unexpected *)

RESTARTABILITY = FALSE; FI; FOR each bank of machine-check registers

DO

CLEAR_MC_BANK = FALSE; READ IA32_MCi_STATUS; IF VAL Flag in IA32_MCi_STATUS = 1

THEN

IF UC Flag in IA32_MCi_STATUS = 1

THEN

IF Bit 24 in IA32_MCG_CAP = 0

THEN (* the processor does not support software error recovery *)

RESTARTABILITY = FALSE; NOERROR = FALSE; GOTO LOG MCA REGISTER; FI; (* the processor supports software error recovery *) IF EN Flag in IA32_MCi_STATUS = 0 AND OVER Flag in IA32_MCi_STATUS=0

THEN (* It is a spurious MCA Log. Log and clear the register *)

CLEAR_MC_BANK = TRUE; GOTO LOG MCA REGISTER; FI;

Page 665 of the Intel 253668-032US user manual — THEN
Page 665 · click to enlarge
Page 665

MACHINE-CHECK ARCHITECTURE

IF PCC Flag in IA32_MCi_STATUS = 1

THEN (* processor context might have been corrupted *)

RESTARTABILITY = FALSE; ELSE (* It is a uncorrected recoverable (UCR) error *)

IF S Flag in IA32_MCi_STATUS = 0

THEN

IF AR Flag in IA32_MCi_STATUS = 0

THEN (* It is a uncorrected no action required (UCNA) error *)

GOTO CONTINUE; (* let CMCI and CMC polling handler to process *) ELSE

FESTARTABILITY = FALSE; (* S=0, AR=1 is illegal *) FI FI; IF RESTARTABILITY = FALSE

THEN (* no need to take recovery action if RESTARTABILITY is already false *)

NOERROR = FALSE; GOTO LOG MCA REGISTER; FI; (* S in IA32_MCi_STATUS = 1 *) IF AR Flag in IA32_MCi_STATUS = 1

THEN (* It is a software recoverable and action required (SRAR) error *)

IF OVER Flag in IA32_MCi_STATUS = 1

THEN

RESTARTABILITY = FALSE; NOERROR = FALSE; GOTO LOG MCA REGISTER; FI IF MCACOD Value in IA32_MCi_STATUS is recognized AND Current Processor is an Affected Processor

THEN

Implement MCACOD specific recovery action; CLEAR_MC_BANK = TURE; ELSE

RESTARTABILITY = FALSE; FI; ELSE (* It is a software recoverable and action optional (SRAO) error *)

IF OVER Flag in IA32_MCi_STATUS = 0 AND MCACOD in IA32_MCi_STATUS is recognized

THEN

Implement MCACOD specific recovery action; FI; CLEAR_MC_BANK = TRUE; FI; AR FI; PCC NOERROR = FALSE; GOTO LOG MCA REGISTER; ELSE (* It is a corrected error; continue to the next IA32_MCi_STATUS *)

GOTO CONTINUE; FI; UC FI; VAL LOG MCA REGISTER:

SAVE IA32_MCi_STATUS;

Page 666 of the Intel 253668-032US user manual — THEN
Page 666 · click to enlarge
Page 666

MACHINE-CHECK ARCHITECTURE

If MISCV in IA32_MCi_STATUS

THEN

SAVE IA32_MCi_MISC; FI; IF ADDRV in IA32_MCi_STATUS

THEN

SAVE IA32_MCi_ADDR; FI; IF CLEAR_MC_BANK = TRUE

THEN

SET all 0 to IA32_MCi_STATUS; If MISCV in IA32_MCi_STATUS

THEN

SET all 0 to IA32_MCi_MISC; FI; IF ADDRV in IA32_MCi_STATUS

THEN

SET all 0 to IA32_MCi_ADDR; FI; FI; CONTINUE: OD; ( *END FOR *) RETURN; (* End of MCA ERROR PROCESSING*)

15.10.4.2 Corrected Machine-Check Handler for Error Recovery

  • When writing a corrected machine check handler, which is invoked as a result of CMCI or called from an OS CMC Polling dispatcher, consider the following:
  • The VAL (valid) flag in each IA32_MCi_STATUS register indicates whether the error information in the register is valid. If this flag is clear, the registers in that bank does not contain valid error information and does not need to be checked.
  • The CMCI or CMC polling handler is responsible for logging and clearing corrected errors. The UC flag in each IA32_MCi_Status register indicates whether the reported error was corrected (UC=0) or not (UC=1).
  • When IA32_MCG_CAP [24] is one, the CMC handler is also responsible for logging and clearing uncorrected no-action required (UCNA) errors. When the UC flag is one but the PCC, S, and AR flags are zero in the IA32_MCi_STATUS register, the reported error in this bank is an uncorrected no-action required (UCNA) error.
  • In addition to corrected errors and UCNA errors, the CMC handler optionally logs uncorrected (UC=1 and PCC=1), software recoverable machine check errors (UC=1, PCC=0 and S=1), but should avoid clearing those errors from the MC banks. Clearing these errors may result in accidentally removing these errors
Page 667 of the Intel 253668-032US user manual — THEN
Page 667 · click to enlarge
Page 667

MACHINE-CHECK ARCHITECTURE

before these errors are actually handled and processed by the MCE handler for attempted software error recovery.

Example 15-5 gives pseudocode for a CMCI handler with UCR support.

Example 15-5. Corrected Error Handler Pseudocode with UCR Support

Corrected Error HANDLER(* Called from CMCI handler or OS CMC Polling Dispatcher*) IF CPU supports MCA

THEN

FOR each bank of machine-check registers

DO

READ IA32_MCi_STATUS; IF VAL flag in IA32_MCi_STATUS = 1

THEN

IF UC Flag in IA32_MCi_STATUS = 0 (* It is a corrected error *)

THEN

GOTO LOG CMC ERROR; ELSE

IF Bit 24 in IA32_MCG_CAP = 0

THEN

GOTO CONTINUE; FI; IF S Flag in IA32_MCi_STATUS = 0 AND AR Flag in IA32_MCi_STATUS = 0

THEN (* It is a uncorrected no action required error *)

GOTO LOG CMC ERROR FI IF EN Flag in IA32_MCi_STATUS = 0

THEN (* It is a spurious MCA error *)

GOTO LOG MCM ERROR FI; FI; FI; GOTO CONTINUE; LOG CMC ERROR:

SAVE IA32_MCi_STATUS; If MISCV Flag in IA32_MCi_STATUS

THEN

SAVE IA32_MCi_MISC; SET all 0 to IA32_MCi_MISC; FI; IF ADDRV Flag in IA32_MCi_STATUS

THEN

SAVE IA32_MCi_ADDR; SET all 0 to IA32_MCi_ADDR FI; SET all 0 to IA32_MCi_STATUS; CONTINUE: OD; ( *END FOR *) FI;

Page 668 of the Intel 253668-032US user manual — MACHINE-CHECK ARCHITECTURE
Page 668 · click to enlarge
Page 668

MACHINE-CHECK ARCHITECTURE

Page 669 of the Intel 253668-032US user manual — 16.1 OVERVIEW OF DEBUG SUPPORT FACILITIES
Page 669 · click to enlarge
Page 669

CHAPTER 16 DEBUGGING, PROFILING BRANCHES AND TIME-

STAMP COUNTER

  • Intel 64 and IA-32 architectures provide debug facilities for use in debugging code and monitoring performance. These facilities are valuable for debugging application software, system software, and multitasking operating systems. Debug support is accessed using debug registers (DB0 through DB7) and model-specific registers (MSRs):
  • Debug registers hold the addresses of memory and I/O locations called breakpoints. Breakpoints are user-selected locations in a program, a data-storage area in memory, or specific I/O ports. They are set where a programmer or system designer wishes to halt execution of a program and examine the state of the processor by invoking debugger software. A debug exception (#DB) is generated when a memory or I/O access is made to a breakpoint address.
  • MSRs monitor branches, interrupts, and exceptions; they record addresses of the last branch, interrupt or exception taken and the last branch taken before an interrupt or exception.

16.1 OVERVIEW OF DEBUG SUPPORT FACILITIES

  • The following processor facilities support debugging and performance monitoring:
  • Debug exception (#DB) — Transfers program control to a debug procedure or task when a debug event occurs.
  • Breakpoint exception (#BP) — See breakpoint instruction (INT 3) below.
  • Breakpoint-address registers (DR0 through DR3) — Specifies the addresses of up to 4 breakpoints.
  • Debug status register (DR6) — Reports the conditions that were in effect when a debug or breakpoint exception was generated.
  • Debug control register (DR7) — Specifies the forms of memory or I/O access that cause breakpoints to be generated.
  • T (trap) flag, TSS — Generates a debug exception (#DB) when an attempt is made to switch to a task with the T flag set in its TSS.
  • RF (resume) flag, EFLAGS register — Suppresses multiple exceptions to the same instruction.
  • TF (trap) flag, EFLAGS register — Generates a debug exception (#DB) after every execution of an instruction.
  • Breakpoint instruction (INT 3) — Generates a breakpoint exception (#BP) that transfers program control to the debugger procedure or task. This
Page 670 of the Intel 253668-032US user manual — 16.2 DEBUG REGISTERS
Page 670 · click to enlarge
Page 670

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

instruction is an alternative way to set code breakpoints. It is especially useful when more than four breakpoints are desired, or when breakpoints are being placed in the source code. • Last branch recording facilities — Store branch records in the last branch record (LBR) stack MSRs for the most recent taken branches, interrupts, and/or exceptions in MSRs. A branch record consist of a branch-from and a branch-to instruction address. Send branch records out on the system bus as branch trace messages (BTMs).

  • These facilities allow a debugger to be called as a separate task or as a procedure in the context of the current program or task. The following conditions can be used to invoke the debugger:
  • Task switch to a specific task.
  • Execution of the breakpoint instruction.
  • Execution of any instruction.
  • Execution of an instruction at a specified address.
  • Read or write to a specified memory address/range.
  • Write to a specified memory address/range.
  • Input from a specified I/O address/range.
  • Output to a specified I/O address/range.
  • Attempt to change the contents of a debug register.

16.2 DEBUG REGISTERS

Eight debug registers (see Figure 16-1) control the debug operation of the processor. These registers can be written to and read using the move to/from debug register form of the MOV instruction. A debug register may be the source or destination operand for one of these instructions.

Debug registers are privileged resources; a MOV instruction that accesses these registers can only be executed in real-address mode, in SMM or in protected mode at a CPL of 0. An attempt to read or write the debug registers from any other privilege level generates a general-protection exception (#GP).

  • The primary function of the debug registers is to set up and monitor from 1 to 4 breakpoints, numbered 0 though 3. For each breakpoint, the following information can be specified:
  • The linear address where the breakpoint is to occur.
  • The length of the breakpoint location (1, 2, or 4 bytes).
  • The operation that must be performed at the address for a debug exception to be generated.
  • Whether the breakpoint is enabled.
Page 671 of the Intel 253668-032US user manual — 1 B 2 B
Page 671 · click to enlarge
Page 671

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • Whether the breakpoint condition was present when the debug exception was generated.

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

1 2 3 4 5 6 9 10 17 18 25 26 27 28 29 30

3 LEN

2 R/W

2 LEN

1 R/W

1 LEN

0 R/W

0 LEN

1 0 0 G D R/W

3 L E G E

0 L 1 L 2 L 3 G

G

2 G

G

DR7 L

31 16 15 13 14 12 11 8 7 0

1 2 3 4 5 6 9 10

Reserved (set to 1)

3 0 1 B D B S B T

1 B 2 B

B

DR6 B 0

DR5

DR4

DR3 Breakpoint 3 Linear Address

DR2 Breakpoint 2 Linear Address

DR1 Breakpoint 1 Linear Address

DR0 Breakpoint 0 Linear Address

Figure 16-1. Debug Registers

The following paragraphs describe the functions of flags and fields in the debug registers.

Reserved

Page 672 of the Intel 253668-032US user manual — 16.2.3 Debug Status Register (DR6)
Page 672 · click to enlarge
Page 672

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.2.1 Debug Address Registers (DR0-DR3)

Each of the debug-address registers (DR0 through DR3) holds the 32-bit linear address of a breakpoint (see Figure 16-1). Breakpoint comparisons are made before physical address translation occurs. The contents of debug register DR7 further spec- ifies breakpoint conditions.

16.2.2 Debug Registers DR4 and DR5

Debug registers DR4 and DR5 are reserved when debug extensions are enabled (when the DE flag in control register CR4 is set) and attempts to reference the DR4 and DR5 registers cause invalid-opcode exceptions (#UD). When debug extensions are not enabled (when the DE flag is clear), these registers are aliased to debug registers DR6 and DR7.

16.2.3 Debug Status Register (DR6)

  • The debug status register (DR6) reports debug conditions that were sampled at the time the last debug exception was generated (see Figure 16-1). Updates to this register only occur when an exception is generated. The flags in this register show the following information:
  • B0 through B3 (breakpoint condition detected) flags (bits 0 through 3) — Indicates (when set) that its associated breakpoint condition was met when a debug exception was generated. These flags are set if the condition described for each breakpoint by the LEN n , and R/W n flags in debug control register DR7 is true. They may or may not be set if the breakpoint is not enabled by the Ln or the Gn flags in register DR7. Therefore on a #DB, a debug handler should check only those B0-B3 bits which correspond to an enabled breakpoint.
  • BD (debug register access detected) flag (bit 13) — Indicates that the next instruction in the instruction stream accesses one of the debug registers (DR0 through DR7). This flag is enabled when the GD (general detect) flag in debug control register DR7 is set. See Section 16.2.4, “Debug Control Register (DR7),” for further explanation of the purpose of this flag.
  • BS (single step) flag (bit 14) — Indicates (when set) that the debug exception was triggered by the single-step execution mode (enabled with the TF flag in the EFLAGS register). The single-step mode is the highest-priority debug exception. When the BS flag is set, any of the other debug status bits also may be set.
  • BT (task switch) flag (bit 15) — Indicates (when set) that the debug exception resulted from a task switch where the T flag (debug trap flag) in the TSS of the target task was set. See Section 7.2.1, “Task-State Segment (TSS),” for the format of a TSS. There is no flag in debug control register DR7 to enable or disable this exception; the T flag of the TSS is the only enabling flag.

Certain debug exceptions may clear bits 0-3. The remaining contents of the DR6 register are never cleared by the processor. To avoid confusion in identifying debug

Page 673 of the Intel 253668-032US user manual — 16.2.4 Debug Control Register (DR7)
Page 673 · click to enlarge
Page 673

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

exceptions, debug handlers should clear the register before returning to the inter- rupted task.

16.2.4 Debug Control Register (DR7)

  • The debug control register (DR7) enables or disables breakpoints and sets breakpoint conditions (see Figure 16-1). The flags and fields in this register control the following things:
  • L0 through L3 (local breakpoint enable) flags (bits 0, 2, 4, and 6) — Enables (when set) the breakpoint condition for the associated breakpoint for the current task. When a breakpoint condition is detected and its associated L n flag is set, a debug exception is generated. The processor automatically clears these flags on every task switch to avoid unwanted breakpoint conditions in the new task.
  • G0 through G3 (global breakpoint enable) flags (bits 1, 3, 5, and 7) — Enables (when set) the breakpoint condition for the associated breakpoint for all tasks. When a breakpoint condition is detected and its associated G n flag is set, a debug exception is generated. The processor does not clear these flags on a task switch, allowing a breakpoint to be enabled for all tasks.
  • LE and GE (local and global exact breakpoint enable) flags (bits 8, 9) — This feature is not supported in the P6 family processors, later IA-32 processors, and Intel 64 processors. When set, these flags cause the processor to detect the exact instruction that caused a data breakpoint condition. For backward and forward compatibility with other Intel processors, we recommend that the LE and GE flags be set to 1 if exact breakpoints are required.
  • GD (general detect enable) flag (bit 13) — Enables (when set) debugregister protection, which causes a debug exception to be generated prior to any MOV instruction that accesses a debug register. When such a condition is detected, the BD flag in debug status register DR6 is set prior to generating the exception. This condition is provided to support in-circuit emulators.

When the emulator needs to access the debug registers, emulator software can set the GD flag to prevent interference from the program currently executing on the processor.

The processor clears the GD flag upon entering to the debug exception handler, to allow the handler access to the debug registers. • R/W0 through R/W3 (read/write) fields (bits 16, 17, 20, 21, 24, 25, 28, and 29) — Specifies the breakpoint condition for the corresponding breakpoint. The DE (debug extensions) flag in control register CR4 determines how the bits in the R/Wn fields are interpreted. When the DE flag is set, the processor interprets bits as follows:

00 — Break on instruction execution only. 01 — Break on data writes only.

Page 674 of the Intel 253668-032US user manual — 16.2.5 Breakpoint Field Recognition
Page 674 · click to enlarge
Page 674

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

10 — Break on I/O reads or writes. 11 — Break on data reads or writes but not instruction fetches.

When the DE flag is clear, the processor interprets the R/Wn bits the same as for the Intel386™ and Intel486™ processors, which is as follows:

00 — Break on instruction execution only. 01 — Break on data writes only. 10 — Undefined. 11 — Break on data reads or writes but not instruction fetches. • LEN0 through LEN3 (Length) fields (bits 18, 19, 22, 23, 26, 27, 30, and 31) — Specify the size of the memory location at the address specified in the corresponding breakpoint address register (DR0 through DR3). These fields are interpreted as follows:

00 — 1-byte length. 01 — 2-byte length. 10 — Undefined (or 8 byte length, see note below). 11 — 4-byte length.

If the corresponding RWn field in register DR7 is 00 (instruction execution), then the LENn field should also be 00. The effect of using other lengths is undefined. See Section 16.2.5, “Breakpoint Field Recognition,” below.

NOTES

For Pentium® 4 and Intel® Xeon® processors with a CPUID signature corresponding to family 15 (model 3, 4, and 6), break point conditions permit specifying 8-byte length on data read/write with an of encoding 10B in the LENn field.

Encoding 10B is also supported in processors based on Intel Core microarchitecture or enhanced Intel Core microarchitecture, the respective CPUID signatures corresponding to family 6, model 15, and family 6, display_model value 23. The Encoding 10B is supported in processors based on Intel Atom microarchitecture, with CPUID signature of family 6, display_model value 28. The encoding 10B is undefined for other processors.

16.2.5 Breakpoint Field Recognition

Breakpoint address registers (debug registers DR0 through DR3) and the LENn fields for each breakpoint define a range of sequential byte addresses for a data or I/O breakpoint. The LENn fields permit specification of a 1-, 2-, 4-, or 8-byte range, beginning at the linear address specified in the corresponding debug register (DRn). Two-byte ranges must be aligned on word boundaries; 4-byte ranges must be aligned on doubleword boundaries. I/O addresses are zero-extended (from 16 to 32 bits, for comparison with the breakpoint address in the selected debug register). These requirements are enforced by the processor; it uses LENn field bits to mask

Page 675 of the Intel 253668-032US user manual — A0001H A0002H B0002H C0000H
Page 675 · click to enlarge
Page 675

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

the lower address bits in the debug registers. Unaligned data or I/O breakpoint addresses do not yield valid results.

A data breakpoint for reading or writing data is triggered if any of the bytes partici- pating in an access is within the range defined by a breakpoint address register and its LENn field. Table 16-1 provides an example setup of debug registers and data accesses that would subsequently trap or not trap on the breakpoints.

A data breakpoint for an unaligned operand can be constructed using two break- points, where each breakpoint is byte-aligned and the two breakpoints together cover the operand. The breakpoints generate exceptions only for the operand, not for neighboring bytes.

Instruction breakpoint addresses must have a length specification of 1 byte (the LENn field is set to 00). Code breakpoints for other operand sizes are undefined. The processor recognizes an instruction breakpoint address only when it points to the first byte of an instruction. If the instruction has prefixes, the breakpoint address must point to the first prefix.

Table 16-1. Breakpoint Examples

Debug Register R/Wn Breakpoint Address LENn

DR0 DR1 DR2 DR3

R/W0 = 11 (Read/Write) R/W1 = 01 (Write) R/W2 = 11 (Read/Write) R/W3 = 01 (Write)

A0001H A0002H B0002H C0000H

LEN0 = 00 (1 byte) LEN1 = 00 (1 byte) LEN2 = 01) (2 bytes) LEN3 = 11 (4 bytes)

Operation Address Access Length

Data operations that trap - Read or write - Read or write - Write - Write - Read or write - Read or write - Read or write - Write - Write - Write

A0001H A0001H A0002H A0002H B0001H B0002H B0002H C0000H C0001H C0003H

1 2 1 2 4 1 2 4 2 1

Debug Register Setup · Data Accesses · (In Bytes)

Page 676 of the Intel 253668-032US user manual — 16.2.6 Debug Registers and Intel ® 64 Processors
Page 676 · click to enlarge
Page 676

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Table 16-1. Breakpoint Examples (Contd.)

Debug Register R/Wn Breakpoint Address LENn

Data operations that do not trap - Read or write - Read - Read or write - Read or write - Read - Read or write

A0000H A0002H A0003H B0000H C0000H C0004H

1 1 4 2 2 4

16.2.6 Debug Registers and Intel ® 64 Processors

For Intel 64 architecture processors, debug registers DR0–DR7 are 64 bits. In 16-bit or 32-bit modes (protected mode and compatibility mode), writes to a debug register fill the upper 32 bits with zeros. Reads from a debug register return the lower 32 bits. In 64-bit mode, MOV DRn instructions read or write all 64 bits. Operand-size prefixes are ignored.

In 64-bit mode, the upper 32 bits of DR6 and DR7 are reserved and must be written with zeros. Writing 1 to any of the upper 32 bits results in a #GP(0) exception (see Figure 16-2). All 64 bits of DR0–DR3 are writable by software. However, MOV DRn instructions do not check that addresses written to DR0–DR3 are in the linear- address limits of the processor implementation (address matching is supported only on valid addresses generated by the processor implementation). Break point condi- tions for 8-byte memory read/writes are supported in all modes.

Debug Register Setup

Page 677 of the Intel 253668-032US user manual — 16.3.1 Debug Exception (#DB)—Interrupt Vector 1
Page 677 · click to enlarge
Page 677

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

DR7

31 24 23 22 21 20 19 16 15 13 14 12 11 8 7 0

1 2 3 4 5 6 9 10 17 18 25 26 27 28 29 30

3 LEN

2 R/W

2 LEN

1 R/W

1 LEN

0 R/W

0 LEN

2 G 1 G D R/W

0 1

3 L E G E

0 L 1 L 2 L 3 G

G

G

DR7 L

DR6

31 16 15 13 14 12 11 8 7 0

1 2 3 4 5 6 9 10

Reserved (set to 1)

3 0 1 B D B S B T

1 B 2 B

B

DR6 B 0

Figure 16-2. DR6/DR7 Layout on Processors Supporting Intel 64 Technology

16.3 DEBUG EXCEPTIONS

The Intel 64 and IA-32 architectures dedicate two interrupt vectors to handling debug exceptions: vector 1 (debug exception, #DB) and vector 3 (breakpoint excep- tion, #BP). The following sections describe how these exceptions are generated and typical exception handler operations.

16.3.1 Debug Exception (#DB)—Interrupt Vector 1

The debug-exception handler is usually a debugger program or part of a larger soft- ware system. The processor generates a debug exception for any of several condi- tions. The debugger checks flags in the DR6 and DR7 registers to determine which condition caused the exception and which other conditions might apply. Table 16-2 shows the states of these flags following the generation of each kind of breakpoint condition.

Instruction-breakpoint and general-detect condition (see Section 16.3.1.3, “General- Detect Exception Condition”) result in faults; other debug-exception conditions result in traps. The debug exception may report one or both at one time. The following sections describe each class of debug exception.

Reserved

Page 678 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 678 · click to enlarge
Page 678

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

See also: Chapter 6, “Interrupt 1—Debug Exception (#DB),” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.

Table 16-2. Debug Exception Conditions

Debug or Breakpoint Condition DR6 Flags Tested

Single-step trap BS = 1 Trap

Instruction breakpoint, at addresses defined by DRn and LENn

Bn = 1 and (Gn or Ln = 1)

R/Wn = 0 Fault

Data write breakpoint, at addresses defined by DRn and LENn

Bn = 1 and (Gn or Ln = 1)

R/Wn = 1 Trap

I/O read or write breakpoint, at addresses defined by DRn and LENn

Bn = 1 and (Gn or Ln = 1)

R/Wn = 2 Trap

Data read or write (but not instruction fetches), at addresses defined by DRn and LENn

Bn = 1 and (Gn or Ln = 1)

R/Wn = 3 Trap

General detect fault, resulting from an attempt to modify debug registers (usually in conjunction with in-circuit emulation)

BD = 1 Fault

Task switch BT = 1 Trap

16.3.1.1 Instruction-Breakpoint Exception Condition

The processor reports an instruction breakpoint when it attempts to execute an instruction at an address specified in a breakpoint-address register (DB0 through DR3) that has been set up to detect instruction execution (R/W flag is set to 0). Upon reporting the instruction breakpoint, the processor generates a fault-class, debug exception (#DB) before it executes the target instruction for the breakpoint.

Instruction breakpoints are the highest priority debug exceptions. They are serviced before any other exceptions detected during the decoding or execution of an instruc- tion. However, if a code instruction breakpoint is placed on an instruction located immediately after a POP SS/MOV SS instruction, the breakpoint may not be trig- gered. In most situations, POP SS/MOV SS will inhibit such interrupts (see “MOV—Move” and “POP—Pop a Value from the Stack” in Chapters 3 and 4 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B).

Because the debug exception for an instruction breakpoint is generated before the instruction is executed, if the instruction breakpoint is not removed by the exception handler; the processor will detect the instruction breakpoint again when the instruc- tion is restarted and generate another debug exception. To prevent looping on an instruction breakpoint, the Intel 64 and IA-32 architectures provide the RF flag

DR7 Flags Tested · Exception Class

Page 679 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 679 · click to enlarge
Page 679

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

(resume flag) in the EFLAGS register (see Section 2.3, “System Flags and Fields in the EFLAGS Register,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A). When the RF flag is set, the processor ignores instruction breakpoints.

All Intel 64 and IA-32 processors manage the RF flag as follows. The RF Flag is cleared at the start of the instruction after the check for code breakpoint, CS limit violation and FP exceptions. Task Switches and IRETD/IRETQ instructions transfer the RF image from the TSS/stack to the EFLAGS register.

  • When calling an event handler, Intel 64 and IA-32 processors establish the value of the RF flag in the EFLAGS image pushed on the stack:
  • For any fault-class exception except a debug exception generated in response to an instruction breakpoint, the value pushed for RF is 1.
  • For any interrupt arriving after any iteration of a repeated string instruction but the last iteration, the value pushed for RF is 1.
  • For any trap-class exception generated by any iteration of a repeated string instruction but the last iteration, the value pushed for RF is 1.
  • For other cases, the value pushed for RF is the value that was in EFLAG.RF at the time the event handler was called. This includes:

— Debug exceptions generated in response to instruction breakpoints

— Hardware-generated interrupts arriving between instructions (including those arriving after the last iteration of a repeated string instruction)

— Trap-class exceptions generated after an instruction completes (including those generated after the last iteration of a repeated string instruction)

— Software-generated interrupts (RF is pushed as 0, since it was cleared at the start of the software interrupt)

As noted above, the processor does not set the RF flag prior to calling the debug exception handler for debug exceptions resulting from instruction breakpoints. The debug exception handler can prevent recurrence of the instruction breakpoint by setting the RF flag in the EFLAGS image on the stack. If the RF flag in the EFLAGS image is set when the processor returns from the exception handler, it is copied into the RF flag in the EFLAGS register by IRETD/IRETQ or a task switch that causes the return. The processor then ignores instruction breakpoints for the duration of the next instruction. (Note that the POPF, POPFD, and IRET instructions do not transfer the RF image into the EFLAGS register.) Setting the RF flag does not prevent other types of debug-exception conditions (such as, I/O or data breakpoints) from being detected, nor does it prevent non-debug exceptions from being generated.

For the Pentium processor, when an instruction breakpoint coincides with another fault-type exception (such as a page fault), the processor may generate one spurious debug exception after the second exception has been handled, even though the debug exception handler set the RF flag in the EFLAGS image. To prevent a spurious exception with Pentium processors, all fault-class exception handlers should set the RF flag in the EFLAGS image.

Page 680 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 680 · click to enlarge
Page 680

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.3.1.2 Data Memory and I/O Breakpoint Exception Conditions

Data memory and I/O breakpoints are reported when the processor attempts to access a memory or I/O address specified in a breakpoint-address register (DB0 through DR3) that has been set up to detect data or I/O accesses (R/W flag is set to 1, 2, or 3). The processor generates the exception after it executes the instruction that made the access, so these breakpoint condition causes a trap-class exception to be generated.

Because data breakpoints are traps, the original data is overwritten before the trap exception is generated. If a debugger needs to save the contents of a write break- point location, it should save the original contents before setting the breakpoint. The handler can report the saved value after the breakpoint is triggered. The address in the debug registers can be used to locate the new value stored by the instruction that triggered the breakpoint.

Intel486 and later processors ignore the GE and LE flags in DR7. In Intel386 proces- sors, exact data breakpoint matching does not occur unless it is enabled by setting the LE and/or the GE flags.

P6 family processors are unable to report data breakpoints exactly for the REP MOVS and REP STOS instructions until the completion of the iteration after the iteration in which the breakpoint occurred.

For repeated INS and OUTS instructions that generate an I/O-breakpoint debug exception, the processor generates the exception after the completion of the first iteration. Repeated INS and OUTS instructions generate a memory-breakpoint debug exception after the iteration in which the memory address breakpoint location is accessed.

16.3.1.3 General-Detect Exception Condition

When the GD flag in DR7 is set, the general-detect debug exception occurs when a program attempts to access any of the debug registers (DR0 through DR7) at the same time they are being used by another application, such as an emulator or debugger. This protection feature guarantees full control over the debug registers when required. The debug exception handler can detect this condition by checking the state of the BD flag in the DR6 register. The processor generates the exception before it executes the MOV instruction that accesses a debug register, which causes a fault-class exception to be generated.

16.3.1.4 Single-Step Exception Condition

The processor generates a single-step debug exception if (while an instruction is being executed) it detects that the TF flag in the EFLAGS register is set. The excep- tion is a trap-class exception, because the exception is generated after the instruc- tion is executed. The processor will not generate this exception after the instruction that sets the TF flag. For example, if the POPF instruction is used to set the TF flag, a

Page 681 of the Intel 253668-032US user manual — 16.3.2 Breakpoint Exception (#BP)—Interrupt Vector 3
Page 681 · click to enlarge
Page 681

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

single-step trap does not occur until after the instruction that follows the POPF instruction.

The processor clears the TF flag before calling the exception handler. If the TF flag was set in a TSS at the time of a task switch, the exception occurs after the first instruction is executed in the new task.

The TF flag normally is not cleared by privilege changes inside a task. The INT n and INTO instructions, however, do clear this flag. Therefore, software debuggers that single-step code must recognize and emulate INT n or INTO instructions rather than executing them directly. To maintain protection, the operating system should check the CPL after any single-step trap to see if single stepping should continue at the current privilege level.

The interrupt priorities guarantee that, if an external interrupt occurs, single step- ping stops. When both an external interrupt and a single-step interrupt occur together, the single-step interrupt is processed first. This operation clears the TF flag. After saving the return address or switching tasks, the external interrupt input is examined before the first instruction of the single-step handler executes. If the external interrupt is still pending, then it is serviced. The external interrupt handler does not run in single-step mode. To single step an interrupt handler, single step an INT n instruction that calls the interrupt handler.

16.3.1.5 Task-Switch Exception Condition

The processor generates a debug exception after a task switch if the T flag of the new task's TSS is set. This exception is generated after program control has passed to the new task, and prior to the execution of the first instruction of that task. The exception handler can detect this condition by examining the BT flag of the DR6 register.

If entry 1 (#DB) in the IDT is a task gate, the T bit of the corresponding TSS should not be set. Failure to observe this rule will put the processor in a loop.

16.3.2 Breakpoint Exception (#BP)—Interrupt Vector 3

The breakpoint exception (interrupt 3) is caused by execution of an INT 3 instruction. See Chapter 6, “Interrupt 3—Breakpoint Exception (#BP).” Debuggers use break exceptions in the same way that they use the breakpoint registers; that is, as a mechanism for suspending program execution to examine registers and memory locations. With earlier IA-32 processors, breakpoint exceptions are used extensively for setting instruction breakpoints.

With the Intel386 and later IA-32 processors, it is more convenient to set break- points with the breakpoint-address registers (DR0 through DR3). However, the breakpoint exception still is useful for breakpointing debuggers, because a break- point exception can call a separate exception handler. The breakpoint exception is also useful when it is necessary to set more breakpoints than there are debug regis- ters or when breakpoints are being placed in the source code of a program under development.

Page 682 of the Intel 253668-032US user manual — 16.4.1 IA32_DEBUGCTL MSR
Page 682 · click to enlarge
Page 682

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.4 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING OVERVIEW

P6 family processors introduced the ability to set breakpoints on taken branches, interrupts, and exceptions, and to single-step from one branch to the next. This capability has been modified and extended in the Pentium 4, Intel Xeon, Pentium M, Intel® Core™ Solo, Intel® Core™ Duo, Intel® Core™2 Duo, Intel® Core™ i7 and Intel® Atom™ processors to allow logging of branch trace messages in a branch trace store (BTS) buffer in memory.

See the following sections for processor specific implementation of last branch, inter- rupt and exception recording:

— Section 16.5, “Last Branch, Interrupt, and Exception Recording (Intel® Core™2 Duo and Intel® Atom™ Processor Family)”

— Section 16.6, “Last Branch, Interrupt, and Exception Recording (Intel® Core™i7 Processor Family)”

— Section 16.7, “Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture)”

— Section 16.8, “Last Branch, Interrupt, and Exception Recording (Intel® Core™ Solo and Intel® Core™ Duo Processors)”

— Section 16.9, “Last Branch, Interrupt, and Exception Recording (Pentium M Processors)”

— Section 16.10, “Last Branch, Interrupt, and Exception Recording (P6 Family Processors)”

The following subsections of Section 16.4 describe common features of profiling branches. These features are generally enabled using the IA32_DEBUGCTL MSR (older processor may have implemented a subset or model-specific features, see definitions of MSR_DEBUGCTLA, MSR_DEBUGCTLB, MSR_DEBUGCTL).

16.4.1 IA32_DEBUGCTL MSR

The IA32_DEBUGCTL MSR provides bit field controls to enable debug trace inter- rupts, debug trace stores, trace messages enable, single stepping on branches, last branch record recording, and to control freezing of LBR stack or performance counters on a PMI request. IA32_DEBUGCTL MSR is located at register address 01D9H.

See Figure 16-3 for the MSR layout and the bullets below for a description of the flags: • LBR (last branch/interrupt/exception) flag (bit 0) — When set, the processor records a running trace of the most recent branches, interrupts, and/or exceptions taken by the processor (prior to a debug exception being generated)

Page 683 of the Intel 253668-032US user manual — FREEZE_WHILE_SMM_EN
Page 683 · click to enlarge
Page 683

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • in the last branch record (LBR) stack. For more information, see the Section 16.5.1, “LBR Stack”.
  • BTF (single-step on branches) flag (bit 1) — When set, the processor treats the TF flag in the EFLAGS register as a “single-step on branches” flag rather than a “single-step on instructions” flag. This mechanism allows single-stepping the processor on taken branches, interrupts, and exceptions. See Section 16.4.3, “Single-Stepping on Branches, Exceptions, and Interrupts,” for more information about the BTF flag.
  • TR (trace message enable) flag (bit 6) — When set, branch trace messages are enabled. When the processor detects a taken branch, interrupt, or exception; it sends the branch record out on the system bus as a branch trace message (BTM). See Section 16.4.4, “Branch Trace Messages,” for more information about the TR flag.
  • BTS (branch trace store) flag (bit 7) — When set, the flag enables BTS facilities to log BTMs to a memory-resident BTS buffer that is part of the DS save area. See Section 16.4.9, “BTS and DS Save Area.”
  • BTINT (branch trace interrupt) flag (bit 8) — When set, the BTS facilities generate an interrupt when the BTS buffer is full. When clear, BTMs are logged to the BTS buffer in a circular fashion. See Section 16.4.5, “Branch Trace Store (BTS),” for a description of this mechanism.

8 7 6 5 4 3 2 1 0

FREEZE_WHILE_SMM_EN

BTS_OFF_OS — BTS off in OS BTS_OFF_USR — BTS off in user code FREEZE_LBRS_ON_PMI FREEZE_PERFMON_ON_PMI

BTINT — Branch trace interrupt

BTS — Branch trace store

TR — Trace messages enable

BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-3. IA32_DEBUGCTL MSR for Processors based

on Intel Core microarchitecture

  • BTS_OFF_OS (branch trace off in privileged code) flag (bit 9) — When set, BTS or BTM is skipped if CPL is 0. See Section 16.7.2.
  • BTS_OFF_USR (branch trace off in user code) flag (bit 10) — When set, BTS or BTM is skipped if CPL is greater than 0. See Section 16.7.2.

11 12 14 · Reserved · Reserved

Page 684 of the Intel 253668-032US user manual — 16.4.3 Single-Stepping on Branches, Exceptions, and Interrupts
Page 684 · click to enlarge
Page 684

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • FREEZE_LBRS_ON_PMI flag (bit 11) — When set, the LBR stack is frozen on a hardware PMI request (e.g. when a counter overflows and is configured to trigger PMI).
  • FREEZE_PERFMON_ON_PMI flag (bit 12) — When set, a PMI request clears each of the “ENABLE” field of MSR_PERF_GLOBAL_CTRL MSR (see Figure 30-3) to disable all the counters.
  • FREEZE_WHILE_SMM_EN (bit 14) — If this bit is set, upon the delivery of an SMI, the processor will clear all the enable bits of IA32_PERF_GLOBAL_CTRL, save a copy of the content of IA32_DEBUGCTL and disable LBR, BTF, TR, and BTS fields of IA32_DEBUGCTL before transferring control to the SMI handler. Subsequently, the enable bits of IA32_PERF_GLOBAL_CTRL will be set to 1, the saved copy of IA32_DEBUGCTL prior to SMI delivery will be restored, after the SMI handler issues RSM to complete its service. Note that system software must check IA32_DEBUGCTL. to determine if the processor supports the FREEZE_WHILE_SMM_EN control bit. FREEZE_WHILE_SMM_EN is supported if IA32_PERF_CAPABILITIES.FREEZE_WHILE_SMM[Bit 12] is reporting 1. See Section 30.11 for details of detecting the presence of IA32_PERF_CAPABILITIES MSR.

16.4.2 Monitoring Branches, Exceptions, and Interrupts

When the LBR flag (bit 0) in the IA32_DEBUGCTL MSR is set, the processor automat- ically begins recording branch records for taken branches, interrupts, and exceptions (except for debug exceptions) in the LBR stack MSRs.

When the processor generates a a debug exception (#DB), it automatically clears the LBR flag before executing the exception handler. This action does not clear previously stored LBR stack MSRs. The branch record for the last four taken branches, interrupts and/or exceptions are retained for analysis.

A debugger can use the linear addresses in the LBR stack to re-set breakpoints in the breakpoint address registers (DR0 through DR3). This allows a backward trace from the manifestation of a particular bug toward its source.

If the LBR flag is cleared and TR flag in the IA32_DEBUGCTL MSR remains set, the processor will continue to update LBR stack MSRs. This is because BTM information must be generated from entries in the LBR stack. A #DB does not automatically clear the TR flag.

16.4.3 Single-Stepping on Branches, Exceptions, and Interrupts

When software sets both the BTF flag (bit 1) in the IA32_DEBUGCTL MSR and the TF flag in the EFLAGS register, the processor generates a single-step debug exception the next time it takes a branch, services an interrupt, or generates an exception. This mechanism allows the debugger to single-step on control transfers caused by branches, interrupts, and exceptions. This “control-flow single stepping” helps isolate

Page 685 of the Intel 253668-032US user manual — 16.4.5 Branch Trace Store (BTS)
Page 685 · click to enlarge
Page 685

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

a bug to a particular block of code before instruction single-stepping further narrows the search. If the BTF flag is set when the processor generates a debug exception, the processor clears the BTF flag along with the TF flag. The debugger must reset the BTF and TF flags before resuming program execution to continue control-flow single stepping.

16.4.4 Branch Trace Messages

Setting the TR flag (bit 6) in the IA32_DEBUGCTL MSR enables branch trace messages (BTMs). Thereafter, when the processor detects a branch, exception, or interrupt, it sends a branch record out on the system bus as a BTM. A debugging device that is monitoring the system bus can read these messages and synchronize operations with taken branch, interrupt, and exception events.

When interrupts or exceptions occur in conjunction with a taken branch, additional BTMs are sent out on the bus, as described in Section 16.4.2, “Monitoring Branches, Exceptions, and Interrupts.”

Unlike the P6 family and Core family processors, the Pentium 4, Atom, and Intel Xeon processors can collect branch records in the LBR stack MSRs while at the same time sending/storing BTMs when both the TR and LBR flags are set in the IA32_DEBUGCTL MSR (in the case of Pentium 4, processor, MSR_DEBUGCTLA).

16.4.5 Branch Trace Store (BTS)

A trace of taken branches, interrupts, and exceptions is useful for debugging code by providing a method of determining the decision path taken to reach a particular code location. The LBR flag (bit 0) of IA32_DEBUGCTL provides a mechanism for capturing records of taken branches, interrupts, and exceptions and saving them in the last branch record (LBR) stack MSRs, setting the TR flag for sending them out onto the system bus as BTMs. The branch trace store (BTS) mechanism provides the addi- tional capability of saving the branch records in a memory-resident BTS buffer, which is part of the DS save area. The BTS buffer can be configured to be circular so that the most recent branch records are always available or it can be configured to generate an interrupt when the buffer is nearly full so that all the branch records can be saved. The BTINT flag (bit 8) can be used to enable the generation of interrupt when the BTS buffer is full. See Section 16.4.9.2, “Setting Up the DS Save Area.” for additional details.

Setting this flag (BTS) alone can greatly reduce the performance of the processor. CPL-qualified branch trace storing mechanism can help mitigate the performance impact of sending/logging branch trace messages.

Page 686 of the Intel 253668-032US user manual — 16.4.7 Freezing LBR and Performance Counters on PMI
Page 686 · click to enlarge
Page 686

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.4.6 CPL-Qualified Branch Trace Mechanism

CPL-qualified branch trace mechanism is available to a subset of Intel 64 and IA-32 processors that support the branch trace storing mechanism. The processor supports the CPL-qualified branch trace mechanism if CPUID.01H:ECX[bit 4] = 1.

The CPL-qualified branch trace mechanism is described in Section 16.4.9.4. System software can selectively specify CPL qualification to not send/store Branch Trace Messages associated with a specified privilege level. Two bit fields, BTS_OFF_USR (bit 10) and BTS_OFF_OS (bit 9), are provided in the debug control register to specify the CPL of BTMs that will not be logged in the BTS buffer or sent on the bus.

16.4.7 Freezing LBR and Performance Counters on PMI

  • Many issues may generate a performance monitoring interrupt (PMI); a PMI service handler will need to determine cause to handle the situation. Two capabilities that allow a PMI service routine to improve branch tracing and performance monitoring are:
  • Freezing LBRs on PMI (bit 11) — The processor freezes LBRs on a PMI request by clearing the LBR bit (bit 0) in IA32_DEBUGCTL. Software must then re-enable IA32_DEBUGCTL.[0] to continue monitoring branches. When using this feature, software should be careful about writes to IA32_DEBUGCTL to avoid re-enabling LBRs by accident if they were just disabled.
  • Freezing PMCs on PMI (bit 12) — The processor freezes the performance counters on a PMI request by clearing the MSR_PERF_GLOBAL_CTRL MSR (see Figure 30-3). The PMCs affected include both general-purpose counters and fixed-function counters (see Section 30.4.1, “Fixed-function Performance Counters”). Software must re-enable counts by writing 1s to the corresponding enable bits in MSR_PERF_GLOBAL_CTRL before leaving a PMI service routine to continue counter operation.

Freezing LBRs and PMCs on PMIs occur when: • A performance counter had an overflow and was programmed to signal a PMI in case of an overflow.

— For the general-purpose counters; this is done by setting bit 20 of the IA32_PERFEVTSELx register.

  • — For the fixed-function counters; this is done by setting the 3rd bit in the corresponding 4-bit control field of the MSR_PERF_FIXED_CTR_CTRL register (see Figure 30-1) or IA32_FIXED_CTR_CTRL MSR (see Figure 30-2).
  • The PEBS buffer is almost full and reaches the interrupt threshold.
  • The BTS buffer is almost full and reaches the interrupt threshold.
Page 687 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 687 · click to enlarge
Page 687

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.4.8 LBR Stack

The last branch record stack and top-of-stack (TOS) pointer MSRs are supported across Intel 64 and IA-32 processor families. However, the number of MSRs in the LBR stack and the valid range of TOS pointer value can vary between different processor families. Table 16-3 lists the LBR stack size and TOS pointer range for several processor families according to the CPUID signatures of Display- Family/DisplayModel encoding (see CPUID instruction in Chapter 3 of Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A).

Table 16-3. LBR Stack Size and TOS Pointer Range DisplayFamily_DisplayModel Size of LBR Stack Range of TOS Pointer

06_1AH, 06_1EH, 06_1FH, 06_2EH 16 0 to 15

06_17H, 06_1DH 4 0 to 3

06_0FH 4 0 to 3

06_1CH 8 0 to 7

The last branch recording mechanism tracks not only branch instructions (like JMP, Jcc, LOOP and CALL instructions), but also other operations that cause a change in the instruction pointer (like external interrupts, traps and faults). The branch recording mechanisms generally employs a set of MSRs, referred to as last branch record (LRB) stack. The size and exact locations of the LRB stack are generally model-specific. • Last Branch Record (LBR) Stack — The LBR consists of N pairs of MSRs (N is listed in the LBR stack size column of Table 16-3) that store source and destination address of recent branches (see Figure 16-3):

— MSR_LASTBRANCH_0_FROM_IP (address is model specific) through the next consecutive (N-1) MSR address store source addresses

— MSR_LASTBRANCH_0_TO_IP (address is model specific ) through the next consecutive (N-1) MSR address store destination addresses. • Last Branch Record Top-of-Stack (TOS) Pointer — The lowest significant M bits of the TOS Pointer MSR (MSR_LASTBRANCH_TOS, address is model specific) contains an M-bit pointer to the MSR in the LBR stack that contains the most recent branch, interrupt, or exception recorded. The valid range of the M-bit POS pointer is given in Table 16-3.

Page 688 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 688 · click to enlarge
Page 688

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.4.8.1 LBR Stack and Intel® 64 Processors

LBR MSRs are 64-bits. If IA-32e mode is disabled, only the lower 32-bits of the address is recorded. If IA-32e mode is enabled, the processor writes 64-bit values into the MSR.

In 64-bit mode, last branch records store 64-bit addresses; in compatibility mode, the upper 32-bits of last branch records are cleared.

Figure 16-4. 64-bit Address Layout of LBR MSR

Software should query an architectural MSR IA32_PERF_CAPABILITIES[5:0] about the format of the address that is stored in the LBR stack. Four formats are defined by the following encoding:

— 000000B (32-bit record format) — Stores 32-bit offset in current CS of respective source/destination,

— 000001B (64-bit LIP record format) — Stores 64-bit linear address of respective source/destination,

— 000010B (64-bit EIP record format) — Stores 64-bit offset (effective address) of respective source/destination.

— 000011B (64-bit EIP record format) and Flags — Stores 64-bit offset (effective address) of respective source/destination. LBR flags are supported in the upper bits of ‘FROM’ register in the LBR stack. See LBR stack details below for flag support and definition.

Processor’s support for the architectural MSR IA32_PERF_CAPABILITIES is provided by CPUID.01H:ECX[PERF_CAPAB_MSR] (bit 15).

16.4.8.2 LBR Stack and IA-32 Processors

The LBR MSRs in IA-32 processors introduced prior to Intel 64 architecture store the 32-bit “To Linear Address” and “From Linear Address“ using the high and low half of each 64-bit MSR.

Show 4 more labels / short text on this page
MSR_LASTBRANCH_0_FROM_IP through MSR_LASTBRANCH_(N-1)_FROM_IP · Source Address · MSR_LASTBRANCH_0_TO_IP through MSR_LASTBRANCH_(N-1)_TO_IP · Destination Address
Page 689 of the Intel 253668-032US user manual — NOTES
Page 689 · click to enlarge
Page 689

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.4.8.3 Last Exception Records and Intel 64 Architecture

Intel 64 and IA-32 processors also provide MSRs that store the branch record for the last branch taken prior to an exception or an interrupt. The location of the last excep- tion record (LER) MSRs are model specific. The MSRs that store last exception records are 64-bits. If IA-32e mode is disabled, only the lower 32-bits of the address is recorded. If IA-32e mode is enabled, the processor writes 64-bit values into the MSR. In 64-bit mode, last exception records store 64-bit addresses; in compatibility mode, the upper 32-bits of last exception records are cleared.

16.4.9 BTS and DS Save Area

  • The Debug store (DS) feature flag (bit 21), returned by CPUID.1:EDX[21] Indicates that the processor provides the debug store (DS) mechanism. This mechanism allows BTMs to be stored in a memory-resident BTS buffer. See Section 16.4.5, “Branch Trace Store (BTS).” Precise event-based sampling (PEBS, see Section 30.4.4, “Precise Event Based Sampling (PEBS),”) also uses the DS save area provided by debug store mechanism. When CPUID.1:EDX[21] is set, the following BTS facilities are available:
  • The BTS_UNAVAILABLE flag in the IA32_MISC_ENABLE MSR indicates (when clear) the availability of the BTS facilities, including the ability to set the BTS and BTINT bits in the MSR_DEBUGCTLA MSR.
  • The IA32_DS_AREA MSR can be programmed to point to the DS save area.
  • The debug store (DS) save area is a software-designated area of memory that is used to collect the following two types of information:
  • Branch records — When the BTS flag in the IA32_DEBUGCTL MSR is set, a branch record is stored in the BTS buffer in the DS save area whenever a taken branch, interrupt, or exception is detected.
  • PEBS records — When a performance counter is configured for PEBS, a PEBS record is stored in the PEBS buffer in the DS save area after the counter overflow occurs. This record contains the architectural state of the processor (state of the 8 general purpose registers, EIP register, and EFLAGS register) at the next occurrence of the PEBS event that caused the counter to overflow. When the state information has been logged, the counter is automatically reset to a preselected value, and event counting begins again. This feature is available only for a subset of the performance events on processors that support PEBS.

NOTES

DS save area and recording mechanism is not available in the SMM. The feature is disabled on transition to the SMM mode. Similarly DS recording is disabled on the generation of a machine check exception

Page 690 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 690 · click to enlarge
Page 690

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

and is cleared on processor RESET and INIT. DS recording is available in real address mode.

The BTS and PEBS facilities may not be available on all processors. The availability of these facilities is indicated by the BTS_UNAVAILABLE and PEBS_UNAVAILABLE flags, respectively, in the IA32_MISC_ENABLE MSR (see Appendix B).

The DS save area is divided into three parts (see Figure 16-5): buffer management area, branch trace store (BTS) buffer, and PEBS buffer. The buffer management area is used to define the location and size of the BTS and PEBS buffers. The processor then uses the buffer management area to keep track of the branch and/or PEBS records in their respective buffers and to record the performance counter reset value. The linear address of the first byte of the DS buffer management area is specified with the IA32_DS_AREA MSR.

  • The fields in the buffer management area are as follows:
  • BTS buffer base — Linear address of the first byte of the BTS buffer. This address should point to a natural doubleword boundary.
  • BTS index — Linear address of the first byte of the next BTS record to be written to. Initially, this address should be the same as the address in the BTS buffer base field.
  • BTS absolute maximum — Linear address of the next byte past the end of the BTS buffer. This address should be a multiple of the BTS record size (12 bytes) plus 1.
  • BTS interrupt threshold — Linear address of the BTS record on which an interrupt is to be generated. This address must point to an offset from the BTS buffer base that is a multiple of the BTS record size. Also, it must be several records short of the BTS absolute maximum address to allow a pending interrupt to be handled prior to processor writing the BTS absolute maximum record.
  • PEBS buffer base — Linear address of the first byte of the PEBS buffer. This address should point to a natural doubleword boundary.
  • PEBS index — Linear address of the first byte of the next PEBS record to be written to. Initially, this address should be the same as the address in the PEBS buffer base field.
Page 691 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 691 · click to enlarge
Page 691

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Intel 253668-032US — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER diagram (page 691)
Fig. 36

Figure 16-5. DS Save Area

  • PEBS absolute maximum — Linear address of the next byte past the end of the PEBS buffer. This address should be a multiple of the PEBS record size (40 bytes) plus 1.
  • PEBS interrupt threshold — Linear address of the PEBS record on which an interrupt is to be generated. This address must point to an offset from the PEBS buffer base that is a multiple of the PEBS record size. Also, it must be several records short of the PEBS absolute maximum address to allow a pending interrupt to be handled prior to processor writing the PEBS absolute maximum record.
Page 692 of the Intel 253668-032US user manual — 0H
Page 692 · click to enlarge
Page 692

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • PEBS counter reset value — A 40-bit value that the counter is to be reset to after state information has collected following counter overflow. This value allows state information to be collected after a preset number of events have been counted.
  • Figures 16-6 shows the structure of a 12-byte branch record in the BTS buffer. The fields in each record are as follows:
  • Last branch from — Linear address of the instruction from which the branch, interrupt, or exception was taken.
  • Last branch to — Linear address of the branch target or the first instruction in the interrupt or exception service routine.
  • Branch predicted — Bit 4 of field indicates whether the branch that was taken was predicted (set) or not predicted (clear).

0H

4H

8H

Figure 16-6. 32-bit Branch Trace Record Format

Figures 16-7 shows the structure of the 40-byte PEBS records. Nominally the register values are those at the beginning of the instruction that caused the event. However, there are cases where the registers may be logged in a partially modified state. The linear IP field shows the value in the EIP register translated from an offset into the current code segment to a linear address.

Last Branch From · Last Branch To · Branch Predicted

Page 693 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 693 · click to enlarge
Page 693

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

EFLAGS 0H

4H

EAX

8H

EBX

CH

ECX

10H

EDX

14H

ESI

18H

EDI

1CH

EBP

20H

ESP

24H

Figure 16-7. PEBS Record Format

16.4.9.1 DS Save Area and IA-32e Mode Operation

When IA-32e mode is active (IA32_EFER.LMA = 1), the structure of the DS save area is shown in Figure 16-8. The organization of each field in IA-32e mode operation is similar to that of non-IA-32e mode operation. However, each field now stores a 64-bit address. The IA32_DS_AREA MSR holds the 64-bit linear address of the first byte of the DS buffer management area.

Linear IP

Page 694 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 694 · click to enlarge
Page 694

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Intel 253668-032US — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER diagram (page 694)
Fig. 37

Figure 16-8. IA-32e Mode DS Save Area

When IA-32e mode is active, the structure of a branch trace record is similar to that shown in Figure 16-6, but each field is 8 bytes in length. This makes each BTS record 24 bytes (see Figure 16-9). The structure of a PEBS record is similar to that shown in Figure 16-7, but each field is 8 bytes in length and architectural states include register R8 through R15. This makes the size of a PEBS record in 64-bit mode 144 bytes (see Figure 16-10).

Page 695 of the Intel 253668-032US user manual — RFLAGS 0H
Page 695 · click to enlarge
Page 695

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

0H

8H

10H

Figure 16-9. 64-bit Branch Trace Record Format

RFLAGS 0H

RIP

8H

RAX

10H

RBX

18H

RCX

20H

RDX

28H

RSI

30H

RDI

38H

RBP

40H

RSP

48H

R8

50H

R15

88H

Figure 16-10. 64-bit PEBS Record Format

Fields in the buffer management area of a DS save area are described in Section 16.4.9.

The format of a branch trace record and a PEBS record are the same as the 64-bit record formats shown in Figures 16-9 and Figures 16-10, with the exception that the branch predicted bit is not supported by Intel Core microarchitecture or Intel Atom microarchitecture. The 64-bit record formats for BTS and PEBS apply to DS save area for all operating modes.

Last Branch From · Last Branch To · Branch Predicted

Page 696 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 696 · click to enlarge
Page 696

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

The procedures used to program IA32_DEBUG_CTRL MSR to set up a BTS buffer or a CPL-qualified BTS are described in Section 16.4.9.3 and Section 16.4.9.4.

  • Required elements for writing a DS interrupt service routine are largely the same on processors that support using DS Save area for BTS or PEBS records. However, on processors based on Intel NetBurst ® microarchitecture, re-enabling counting requires writing to CCCRs. But a DS interrupt service routine on processors based on Intel Core or Intel Atom microarchitecture should:
  • Re-enable the enable bits in IA32_PERF_GLOBAL_CTRL MSR if it is servicing an overflow PMI due to PEBS.
  • Clear overflow indications by writing to IA32_PERF_GLOBAL_OVF_CTRL when a counting configuration is changed. This includes bit 62 (ClrOvfBuffer) and the overflow indication of counters used in either PEBS or general-purpose counting (specifically: bits 0 or 1; see Figures 30-3).

16.4.9.2 Setting Up the DS Save Area

To save branch records with the BTS buffer, the DS save area must first be set up in memory as described in the following procedure (See Section 30.4.4.1, “Setting up the PEBS Buffer,” for instructions for setting up a PEBS buffer, respectively, in the DS save area):

1. Create the DS buffer management information area in memory (see Section 16.4.9, “BTS and DS Save Area,” and Section 16.4.9.1, “DS Save Area and IA32e Mode Operation”). Also see the additional notes in this section.
2. Write the base linear address of the DS buffer management area into the IA32_DS_AREA MSR.
3. Set up the performance counter entry in the xAPIC LVT for fixed delivery and edge sensitive. See Section 10.6.1, “Local Vector Table.”
4. Establish an interrupt handler in the IDT for the vector associated with the performance counter entry in the xAPIC LVT.
5. Write an interrupt service routine to handle the interrupt. See Section 16.4.9.5, “Writing the DS Interrupt Service Routine.”
  • The following restrictions should be applied to the DS save area.
  • The three DS save area sections should be allocated from a non-paged pool, and marked accessed and dirty. It is the responsibility of the operating system to keep the pages that contain the buffer present and to mark them accessed and dirty. The implication is that the operating system cannot do “lazy” page-table entry propagation for these pages.
  • The DS save area can be larger than a page, but the pages must be mapped to contiguous linear addresses. The buffer may share a page, so it need not be aligned on a 4-KByte boundary. For performance reasons, the base of the buffer must be aligned on a doubleword boundary and should be aligned on a cache line boundary.
Page 697 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 697 · click to enlarge
Page 697

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • It is recommended that the buffer size for the BTS buffer and the PEBS buffer be an integer multiple of the corresponding record sizes.
  • The precise event records buffer should be large enough to hold the number of precise event records that can occur while waiting for the interrupt to be serviced.
  • The DS save area should be in kernel space. It must not be on the same page as code, to avoid triggering self-modifying code actions.
  • There are no memory type restrictions on the buffers, although it is recommended that the buffers be designated as WB memory type for performance considerations.
  • Either the system must be prevented from entering A20M mode while DS save area is active, or bit 20 of all addresses within buffer bounds must be 0.
  • Pages that contain buffers must be mapped to the same physical addresses for all processes, such that any change to control register CR3 will not change the DS addresses.
  • The DS save area is expected to used only on systems with an enabled APIC. The LVT Performance Counter entry in the APCI must be initialized to use an interrupt gate instead of the trap gate.

16.4.9.3 Setting Up the BTS Buffer

Three flags in the MSR_DEBUGCTLA MSR (see Table 16-4), IA32_DEBUGCTL (see Figure 16-3), or MSR_DEBUGCTLB (see Figure 16-16) control the generation of branch records and storing of them in the BTS buffer; these are TR, BTS, and BTINT. The TR flag enables the generation of BTMs. The BTS flag determines whether the BTMs are sent out on the system bus (clear) or stored in the BTS buffer (set). BTMs cannot be simultaneously sent to the system bus and logged in the BTS buffer. The BTINT flag enables the generation of an interrupt when the BTS buffer is full. When this flag is clear, the BTS buffer is a circular buffer.

Table 16-4. IA32_DEBUGCTL Flag Encodings TR BTS BTINT Description

0 X X Branch trace messages (BTMs) off

1 0 X Generate BTMs

1 1 0 Store BTMs in the BTS buffer, used here as a circular buffer

1 1 1 Store BTMs in the BTS buffer, and generate an interrupt when the buffer is nearly full

The following procedure describes how to set up a DS Save area to collect branch records in the BTS buffer:

1. Place values in the BTS buffer base, BTS index, BTS absolute maximum, and BTS interrupt threshold fields of the DS buffer management area to set up the BTS buffer in memory.
Page 698 of the Intel 253668-032US user manual — NOTES
Page 698 · click to enlarge
Page 698

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

2. Set the TR and BTS flags in the IA32_DEBUGCTL for Intel Core Solo and Intel Core Duo processors or later processors (or MSR_DEBUGCTLA MSR for processors based on Intel NetBurst Microarchitecture; or MSR_DEBUGCTLB for Pentium M processors).
3. Clear the BTINT flag in the corresponding IA32_DEBUGCTL (or MSR_DEBUGCTLA MSR; or MSR_DEBUGCTLB) if a circular BTS buffer is desired.

NOTES

If the buffer size is set to less than the minimum allowable value (i.e. BTS absolute maximum < 1 + size of BTS record), the results of BTS is undefined.

In order to prevent generating an interrupt, when working with circular BTS buffer, SW need to set BTS interrupt threshold to a value greater than BTS absolute maximum (fields of the DS buffer management area). It's not enough to clear the BTINT flag itself only.

16.4.9.4 Setting Up CPL-Qualified BTS

If the processor supports CPL-qualified last branch recording mechanism, the gener- ation of branch records and storing of them in the BTS buffer are determined by: TR, BTS, BTS_OFF_OS, BTS_OFF_USR, and BTINT. The encoding of these five bits are shown in Table 16-5.

Table 16-5. CPL-Qualified Branch Trace Store Encodings TR BTS BTS_OFF_OS BTS_OFF_USR BTINT Description

0 X Branch trace messages (BTMs) off

1 0 X X X Generates BTMs but do not store BTMs

1 1 0 0 0 Store all BTMs in the BTS buffer, used here as a circular buffer

1 1 1 0 0 Store BTMs with CPL > 0 in the BTS buffer

1 1 0 1 0 Store BTMs with CPL = 0 in the BTS buffer

1 X Generate BTMs but do not store BTMs

1 1 0 0 1 Store all BTMs in the BTS buffer; generate an interrupt when the buffer is nearly full

Page 699 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 699 · click to enlarge
Page 699

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Table 16-5. CPL-Qualified Branch Trace Store Encodings (Contd.) TR BTS BTS_OFF_OS BTS_OFF_USR BTINT Description

1 1 1 0 1 Store BTMs with CPL > 0 in the BTS buffer; generate an interrupt when the buffer is nearly full

1 1 0 1 1 Store BTMs with CPL = 0 in the BTS buffer; generate an interrupt when the buffer is nearly full

16.4.9.5 Writing the DS Interrupt Service Routine

  • The BTS, non-precise event-based sampling, and PEBS facilities share the same interrupt vector and interrupt service routine (called the debug store interrupt service routine or DS ISR). To handle BTS, non-precise event-based sampling, and PEBS interrupts: separate handler routines must be included in the DS ISR. Use the following guidelines when writing a DS ISR to handle BTS, non-precise event-based sampling, and/or PEBS interrupts.
  • The DS interrupt service routine (ISR) must be part of a kernel driver and operate at a current privilege level of 0 to secure the buffer storage area.
  • Because the BTS, non-precise event-based sampling, and PEBS facilities share the same interrupt vector, the DS ISR must check for all the possible causes of interrupts from these facilities and pass control on to the appropriate handler.
  • BTS and PEBS buffer overflow would be the sources of the interrupt if the buffer index matches/exceeds the interrupt threshold specified. Detection of nonprecise event-based sampling as the source of the interrupt is accomplished by checking for counter overflow.
  • There must be separate save areas, buffers, and state for each processor in an MP system.
  • Upon entering the ISR, branch trace messages and PEBS should be disabled to prevent race conditions during access to the DS save area. This is done by clearing TR flag in the IA32_DEBUGCTL (or MSR_DEBUGCTLA MSR) and by clearing the precise event enable flag in the MSR_PEBS_ENABLE MSR. These settings should be restored to their original values when exiting the ISR.
  • The processor will not disable the DS save area when the buffer is full and the circular mode has not been selected. The current DS setting must be retained and restored by the ISR on exit.
  • After reading the data in the appropriate buffer, up to but not including the current index into the buffer, the ISR must reset the buffer index to the beginning of the buffer. Otherwise, everything up to the index will look like new entries upon the next invocation of the ISR.
Page 700 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 700 · click to enlarge
Page 700

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • The ISR must clear the mask bit in the performance counter LVT entry.
  • The ISR must re-enable the counters to count via IA32_PERF_GLOBAL_CTRL/IA32_PERF_GLOBAL_OVF_CTRL if it is servicing an overflow PMI due to PEBS (or via CCCR's ENABLE bit on processor based on Intel NetBurst microarchitecture).
  • The Pentium 4 Processor and Intel Xeon Processor mask PMIs upon receiving an interrupt. Clear this condition before leaving the interrupt handler.

16.5 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (INTEL® CORE™2 DUO AND INTEL® ATOM™ PROCESSOR FAMILY)

  • The Intel Core 2 Duo processor family and Intel Xeon processors based on Intel Core microarchitecture or enhanced Intel Core microarchitecture provide last branch interrupt and exception recording. The facilities described in this section also apply to Intel Atom processor family. These capabilities are similar to those found in Pentium 4 processors, including support for the following facilities:
  • Debug Trace and Branch Recording Control — The IA32_DEBUGCTL MSR provide bit fields for software to configure mechanisms related to debug trace, branch recording, branch trace store, and performance counter operations. See Section 16.4.1 for a description of the flags. See Figure 16-3 for the MSR layout.
  • Last branch record (LBR) stack — There are a collection of MSR pairs that store the source and destination addresses related to recently executed branches. See Section 16.5.1.
  • Monitoring and single-stepping of branches, exceptions, and interrupts

— See Section 16.4.2 and Section 16.4.3. In addition, the ability to freeze the LBR stack on a PMI request is available.

  • — The Intel Atom processor family clears the TR flag when the FREEZE_LBRS_ON_PMI flag is set.
  • Branch trace messages — See Section 16.4.4.
  • Last exception records — See Section 16.7.3.
  • Branch trace store and CPL-qualified BTS — See Section 16.4.5.
  • FREEZE_LBRS_ON_PMI flag (bit 11) — see Section 16.4.7.
  • FREEZE_PERFMON_ON_PMI flag (bit 12) — see Section 16.4.7.
  • FREEZE_WHILE_SMM_EN (bit 14) — FREEZE_WHILE_SMM_EN is supported if IA32_PERF_CAPABILITIES.FREEZE_WHILE_SMM[Bit 12] is reporting 1. See Section 16.4.1.
Page 701 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 701 · click to enlarge
Page 701

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.5.1 LBR Stack

The last branch record stack and top-of-stack (TOS) pointer MSRs are supported across Intel Core 2, Intel Xeon and Intel Atom processor families. Four pair of MSRs are supported in the LBR stack • Last Branch Record (LBR) Stack

— MSR_LASTBRANCH_0_FROM_IP (address 40H) through MSR_LASTBRANCH_3_FROM_IP (address 43H) store source addresses

— MSR_LASTBRANCH_0_TO_IP (address 60H) through MSR_LASTBRANCH_3_To_IP (address 63H) store destination addresses. • Last Branch Record Top-of-Stack (TOS) Pointer — The lowest significant 2 bits of the TOS Pointer MSR (MSR_LASTBRANCH_TOS, address 1C9H) contains a pointer to the MSR in the LBR stack that contains the most recent branch, interrupt, or exception recorded.

For compatibility, the MSR_LER_TO_LIP and the MSR_LER_FROM_LIP MSRs) dupli- cate functions of the LastExceptionToIP and LastExceptionFromIP MSRs found in P6 family processors.

16.6 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (INTEL® CORE™I7 PROCESSOR FAMILY)

  • The Intel Core i7 processor family and Intel Xeon processors based on Intel microarchitecture (Nehalem) support last branch interrupt and exception recording. These capabilities are similar to those found in Intel Core 2 processors and adds additional capabilities:
  • Debug Trace and Branch Recording Control — The IA32_DEBUGCTL MSR provides bit fields for software to configure mechanisms related to debug trace, branch recording, branch trace store, and performance counter operations. See Section 16.4.1 for a description of the flags. See Figure 16-11 for the MSR layout.
  • Last branch record (LBR) stack — There are 16 MSR pairs that store the source and destination addresses related to recently executed branches. See Section 16.6.1.
  • Monitoring and single-stepping of branches, exceptions, and interrupts — See Section 16.4.2 and Section 16.4.3. In addition, the ability to freeze the LBR stack on a PMI request is available.
  • Branch trace messages — The IA32_DEBUGCTL MSR provides bit fields for software to enable each logical processor to generate branch trace messages. See Section 16.4.4. However, not all BTM messages are observable using the Intel ® QPI link.
  • Last exception records — See Section 16.7.3.
Page 702 of the Intel 253668-032US user manual — 16.6.1 LBR Stack
Page 702 · click to enlarge
Page 702

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • Branch trace store and CPL-qualified BTS — See Section 16.4.6 and Section 16.4.5.
  • FREEZE_LBRS_ON_PMI flag (bit 11) — see Section 16.4.7.
  • FREEZE_PERFMON_ON_PMI flag (bit 12) — see Section 16.4.7.
  • FREEZE_WHILE_SMM_EN (bit 14) — FREEZE_WHILE_SMM_EN is supported if IA32_PERF_CAPABILITIES.FREEZE_WHILE_SMM[Bit 12] is reporting 1. See Section 16.4.1.
  • Processors based on Intel microarchitecture (Nehalem) provide additional capabilities:
  • Independent control of uncore PMI — The IA32_DEBUGCTL MSR provides a bit field (see Figure 16-11) for software to enable each logical processor to receive an uncore counter overflow interrupt.
  • LBR filtering — Processors based on Intel microarchitecture (Nehalem) support filtering of LBR based on combination of CPL and branch type conditions. When LBR filtering is enabled, the LBR stack only captures the subset of branches that are specified by MSR_LBR_SELECT.

8 7 6 5 4 3 2 1 0

FREEZE_WHILE_SMM_EN UNCORE_PMI_EN

BTS_OFF_OS — BTS off in OS BTS_OFF_USR — BTS off in user code FREEZE_LBRS_ON_PMI FREEZE_PERFMON_ON_PMI

BTINT — Branch trace interrupt

BTS — Branch trace store

TR — Trace messages enable

BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-11. IA32_DEBUGCTL MSR for Processors based

on Intel microarchitecture (Nehalem)

16.6.1 LBR Stack

Processors based on Intel microarchitecture (Nehalem) provide 16 pairs of MSR to record last branch record information. The layout of each MSR pair is shown in Table 16-6 and Table 16-7.

11 12 14 · Reserved · Reserved

Page 703 of the Intel 253668-032US user manual — 16.6.2 Filtering of Last Branch Records
Page 703 · click to enlarge
Page 703

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Table 16-6. IA32_LASTBRACH_x_FROM_IP Bit Field Bit Offset Access Description

Data 47:0 R/O The linear address of the branch instruction itself, This is the “branch from“ address

SIGN_EXt 62:48 R/0 Signed extension of bit 47 of this register

MISPRED 63 R/O When set, indicates the branch was predicted; otherwise, the branch was mispredicted.

Table 16-7. IA32_LASTBRACH_x_TO_IP Bit Field Bit Offset Access Description

Data 47:0 R/O The linear address of the target of the branch instruction itself, This is the “branch to“ address

SIGN_EXt 63:48 R/0 Signed extension of bit 47 of this register

Processors based on Intel microarchitecture (Nehalem) have an LBR MSR Stack as shown in Table 16-8.

Table 16-8. LBR Stack Size and TOS Pointer Range

DisplayFamily_DisplayModel Size of LBR Stack Range of TOS Pointer

06_1AH 16 0 to 15

16.6.2 Filtering of Last Branch Records

MSR_LBR_SELECT is cleared to zero at RESET, and LBR filtering is disabled, i.e. all branches will be captured. MSR_LBR_SELECT provides bit fields to specify the condi- tions of subsets of branches that will not be captured in the LBR. The layout of MSR_LBR_SELECT is shown in Table 16-9.

Table 16-9. MSR_LBR_SELECT Bit Field Bit Offset Access Description

CPL_EQ_0 0 R/W When set, do not capture branches occurring in ring 0

CPL_NEQ_0 1 R/W When set, do not capture branches occurring in ring >0

Page 704 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 704 · click to enlarge
Page 704

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

Table 16-9. MSR_LBR_SELECT (Contd.) Bit Field Bit Offset Access Description

JCC 2 R/W When set, do not capture conditional branches

NEAR_REL_CALL 3 R/W When set, do not capture near relative calls

NEAR_IND_CALL 4 R/W When set, do not capture near indirect calls

NEAR_RET 5 R/W When set, do not capture near returns

NEAR_IND_JMP 6 R/W When set, do not capture near indirect jumps

NEAR_REL_JMP 7 R/W When set, do not capture near relative jumps

FAR_BRANCH 8 R/W When set, do not capture far branches

Reserved 63:9 Must be zero

16.7 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (PROCESSORS BASED ON INTEL NETBURST® MICROARCHITECTURE)

  • Pentium 4 and Intel Xeon processors based on Intel NetBurst microarchitecture provide the following methods for recording taken branches, interrupts and exceptions:
  • Store branch records in the last branch record (LBR) stack MSRs for the most recent taken branches, interrupts, and/or exceptions in MSRs. A branch record consist of a branch-from and a branch-to instruction address.
  • Send the branch records out on the system bus as branch trace messages (BTMs).
  • Log BTMs in a memory-resident branch trace store (BTS) buffer.
  • To support these functions, the processor provides the following MSRs and related facilities:
  • MSR_DEBUGCTLA MSR — Enables last branch, interrupt, and exception recording; single-stepping on taken branches; branch trace messages (BTMs); and branch trace store (BTS). This register is named DebugCtlMSR in the P6 family processors.
  • Debug store (DS) feature flag (CPUID.1:EDX.DS[bit 21]) — Indicates that the processor provides the debug store (DS) mechanism, which allows BTMs to be stored in a memory-resident BTS buffer.
  • CPL-qualified debug store (DS) feature flag (CPUID.1:ECX.DS-CPL[bit 4]) — Indicates that the processor provides a CPL-qualified debug store (DS) mechanism, which allows software to selectively skip sending and storing BTMs, according to specified current privilege level settings, into a memory-resident BTS buffer.
Page 705 of the Intel 253668-032US user manual — 16.7.1 MSR_DEBUGCTLA MSR
Page 705 · click to enlarge
Page 705

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

  • IA32_MISC_ENABLE MSR — Indicates that the processor provides the BTS facilities.
  • Last branch record (LBR) stack — The LBR stack is a circular stack that consists of four MSRs (MSR_LASTBRANCH_0 through MSR_LASTBRANCH_3) for the Pentium 4 and Intel Xeon processor family [CPUID family 0FH, models 0H02H]. The LBR stack consists of 16 MSR pairs (MSR_LASTBRANCH_0_FROM_LIP through MSR_LASTBRANCH_15_FROM_LIP and MSR_LASTBRANCH_0_TO_LIP through MSR_LASTBRANCH_15_TO_LIP) for the Pentium 4 and Intel Xeon processor family [CPUID family 0FH, model 03H].
  • Last branch record top-of-stack (TOS) pointer — The TOS Pointer MSR contains a 2-bit pointer (0-3) to the MSR in the LBR stack that contains the most recent branch, interrupt, or exception recorded for the Pentium 4 and Intel Xeon processor family [CPUID family 0FH, models 0H-02H]. This pointer becomes a 4-bit pointer (0-15) for the Pentium 4 and Intel Xeon processor family [CPUID family 0FH, model 03H]. See also: Table 16-10, Figure 16-12, and Section 16.7.2, “LBR Stack for Processors Based on Intel NetBurst Microarchitecture.”
  • Last exception record — See Section 16.7.3, “Last Exception Records.”

16.7.1 MSR_DEBUGCTLA MSR

  • The MSR_DEBUGCTLA MSR enables and disables the various last branch recording mechanisms described in the previous section. This register can be written to using the WRMSR instruction, when operating at privilege level 0 or when in real-address mode. A protected-mode operating system procedure is required to provide user access to this register. Figure 16-12 shows the flags in the MSR_DEBUGCTLA MSR. The functions of these flags are as follows:
  • LBR (last branch/interrupt/exception) flag (bit 0) — When set, the processor records a running trace of the most recent branches, interrupts, and/or exceptions taken by the processor (prior to a debug exception being generated) in the last branch record (LBR) stack. Each branch, interrupt, or exception is recorded as a 64-bit branch record. The processor clears this flag whenever a debug exception is generated (for example, when an instruction or data breakpoint or a single-step trap occurs). See Section 16.7.2, “LBR Stack for Processors Based on Intel NetBurst Microarchitecture.”
  • BTF (single-step on branches) flag (bit 1) — When set, the processor treats the TF flag in the EFLAGS register as a “single-step on branches” flag rather than a “single-step on instructions” flag. This mechanism allows single-stepping the processor on taken branches, interrupts, and exceptions. See Section 16.4.3, “Single-Stepping on Branches, Exceptions, and Interrupts.”
  • TR (trace message enable) flag (bit 2) — When set, branch trace messages are enabled. Thereafter, when the processor detects a taken branch, interrupt, or exception, it sends the branch record out on the system bus as a branch trace message (BTM). See Section 16.4.4, “Branch Trace Messages.”
Page 706 of the Intel 253668-032US user manual — 16.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecture
Page 706 · click to enlarge
Page 706

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

5 4 3 2 1 0

BTS_OFF_OS — Disable storing CPL_0 BTS BTS_OFF_USR — Disable storing non-CPL_0 BTS

BTINT — Branch trace interrupt

BTS — Branch trace store

TR — Trace messages enable

BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-12. MSR_DEBUGCTLA MSR for Pentium 4 and Intel Xeon Processors

  • BTS (branch trace store) flag (bit 3) — When set, enables the BTS facilities to log BTMs to a memory-resident BTS buffer that is part of the DS save area. See Section 16.4.9, “BTS and DS Save Area.”
  • BTINT (branch trace interrupt) flag (bits 4) — When set, the BTS facilities generate an interrupt when the BTS buffer is full. When clear, BTMs are logged to the BTS buffer in a circular fashion. See Section 16.4.5, “Branch Trace Store (BTS).”
  • BTS_OFF_OS (disable ring 0 branch trace store) flag (bit 5) — When set, enables the BTS facilities to skip sending/logging CPL_0 BTMs to the memoryresident BTS buffer. See Section 16.7.2, “LBR Stack for Processors Based on Intel NetBurst Microarchitecture.”
  • BTS_OFF_USR (disable ring 0 branch trace store) flag (bit 6) — When set, enables the BTS facilities to skip sending/logging non-CPL_0 BTMs to the memory-resident BTS buffer. See Section 16.7.2, “LBR Stack for Processors Based on Intel NetBurst Microarchitecture.”

The initial implementation of BTS_OFF_USR and BTS_OFF_OS in MSR_DEBUGCTLA is shown in Figure 16-12. The BTS_OFF_USR and BTS_OFF_OS fields may be implemented on other model-specific debug control register at different locations.

See Appendix B, “Model-Specific Registers (MSRs),” for a detailed description of each of the last branch recording MSRs.

16.7.2 LBR Stack for Processors Based on Intel NetBurst Microarchitecture

The LBR stack is made up of LBR MSRs that are treated by the processor as a circular stack. The TOS pointer (MSR_LASTBRANCH_TOS MSR) points to the LBR MSR (or

Reserved

Page 707 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 707 · click to enlarge
Page 707

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

LBR MSR pair) that contains the most recent (last) branch record placed on the stack. Prior to placing a new branch record on the stack, the TOS is incremented by 1. When the TOS pointer reaches it maximum value, it wraps around to 0. See Table 16-10 and Figure 16-12.

Table 16-10. LBR MSR Stack Size and TOS Pointer Range for the Pentium® 4 and the

Intel® Xeon® Processor Family

DisplayFamily_DisplayModel Size of LBR Stack Range of TOS Pointer

Family 0FH, Models 0H-02H; MSRs at locations 1DBH- 1DEH.

4 0 to 3

Family 0FH, Models; MSRs at locations 680H-68FH.

16 0 to 15

Family 0FH, Model 03H; MSRs at locations 6C0H-6CFH.

16 0 to 15

The registers in the LBR MSR stack and the MSR_LASTBRANCH_TOS MSR are read- only and can be read using the RDMSR instruction.

  • Figure 16-13 shows the layout of a branch record in an LBR MSR (or MSR pair). Each branch record consists of two linear addresses, which represent the “from” and “to” instruction pointers for a branch, interrupt, or exception. The contents of the from and to addresses differ, depending on the source of the branch:
  • Taken branch — If the record is for a taken branch, the “from” address is the address of the branch instruction and the “to” address is the target instruction of the branch.
  • Interrupt — If the record is for an interrupt, the “from” address the return instruction pointer (RIP) saved for the interrupt and the “to” address is the address of the first instruction in the interrupt handler routine. The RIP is the linear address of the next instruction to be executed upon returning from the interrupt handler.
  • Exception — If the record is for an exception, the “from” address is the linear address of the instruction that caused the exception to be generated and the “to” address is the address of the first instruction in the exception handler routine.
Page 708 of the Intel 253668-032US user manual — 16.7.3 Last Exception Records
Page 708 · click to enlarge
Page 708

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

32. 31 MSR_LASTBRANCH_0 through MSR_LASTBRANCH_3 CPUID Family 0FH, Models 0H-02H

CPUID Family 0FH, Model 03H-04H

32. 31
32. 31

Figure 16-13. LBR MSR Branch Record Layout for the Pentium 4

and Intel Xeon Processor Family

Additional information is saved if an exception or interrupt occurs in conjunction with a branch instruction. If a branch instruction generates a trap type exception, two branch records are stored in the LBR stack: a branch record for the branch instruction followed by a branch record for the exception.

If a branch instruction is immediately followed by an interrupt, a branch record is stored in the LBR stack for the branch instruction followed by a record for the interrupt.

16.7.3 Last Exception Records

The Pentium 4, Intel Xeon, Pentium M, Intel® Core™ Solo, Intel® Core™ Duo, Intel® Core™2 Duo, Intel® Core™ i7 and Intel® Atom™ processors provide two MSRs (the MSR_LER_TO_LIP and the MSR_LER_FROM_LIP MSRs) that duplicate the functions of the LastExceptionToIP and LastExceptionFromIP MSRs found in the P6 family processors. The MSR_LER_TO_LIP and MSR_LER_FROM_LIP MSRs contain a branch record for the last branch that the processor took prior to an exception or interrupt being generated.

Show 8 more labels / short text on this page
To Linear Address · From Linear Address · MSR_LASTBRANCH_0_FROM_LIP through MSR_LASTBRANCH_15_FROM_LIP · Reserved · From Linear Address · MSR_LASTBRANCH_0_TO_LIP through MSR_LASTBRANCH_15_TO_LIP · Reserved · To Linear Address
Page 709 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 709 · click to enlarge
Page 709

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.8 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (INTEL® CORE™ SOLO AND INTEL® CORE™ DUO PROCESSORS)

Intel Core Solo and Intel Core Duo processors provide last branch interrupt and exception recording. This capability is almost identical to that found in Pentium 4 and Intel Xeon processors. There are differences in the stack and in some MSR names and locations.

See Figure 16-14 for the layout and the entries below for a description of the flags:

— LBR (last branch/interrupt/exception) flag (bit 0) — When set, the processor records a running trace of the most recent branches, interrupts, and/or exceptions taken by the processor (prior to a debug exception being generated) in the last branch record (LBR) stack. For more information, see the “Last Branch Record (LBR) Stack” below.

— BTF (single-step on branches) flag (bit 1) — When set, the processor treats the TF flag in the EFLAGS register as a “single-step on branches” flag rather than a “single-step on instructions” flag. This mechanism allows single-stepping the processor on taken branches, interrupts, and exceptions. See Section 16.4.3, “Single-Stepping on Branches, Exceptions, and Inter- rupts,” for more information about the BTF flag.

— TR (trace message enable) flag (bit 6) — When set, branch trace messages are enabled. When the processor detects a taken branch, interrupt, or exception; it sends the branch record out on the system bus as a branch trace message (BTM). See Section 16.4.4, “Branch Trace Messages,” for more information about the TR flag.

— BTS (branch trace store) flag (bit 7) — When set, the flag enables BTS facilities to log BTMs to a memory-resident BTS buffer that is part of the DS save area. See Section 16.4.9, “BTS and DS Save Area.”

— BTINT (branch trace interrupt) flag (bits 8) — When set, the BTS facilities generate an interrupt when the BTS buffer is full. When clear, BTMs are logged to the BTS buffer in a circular fashion. See Section 16.4.5, “Branch Trace Store (BTS),” for a description of this mechanism.

Page 710 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 710 · click to enlarge
Page 710

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

8 7 6 5 4 3 2 1 0

BTINT — Branch trace interrupt

BTS — Branch trace store

TR — Trace messages enable

BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-14. IA32_DEBUGCTL MSR for Intel Core Solo

and Intel Core Duo Processors

  • Debug store (DS) feature flag (bit 21), returned by the CPUID instruction — Indicates that the processor provides the debug store (DS) mechanism, which allows BTMs to be stored in a memory-resident BTS buffer. See Section 16.4.5, “Branch Trace Store (BTS).”
  • Last Branch Record (LBR) Stack — The LBR stack consists of 8 MSRs (MSR_LASTBRANCH_0 through MSR_LASTBRANCH_7); bits 31-0 hold the ‘from’ address, bits 63-32 hold the ‘to’ address (MSR addresses start at 40H). See Figure 16-15.
  • Last Branch Record Top-of-Stack (TOS) Pointer — The TOS Pointer MSR contains a 3-bit pointer (bits 2-0) to the MSR in the LBR stack that contains the most recent branch, interrupt, or exception recorded. For Intel Core Solo and Intel Core Duo processors, this MSR is located at register address 01C9H.

For compatibility, the Intel Core Solo and Intel Core Duo processors provide two 32- bit MSRs (the MSR_LER_TO_LIP and the MSR_LER_FROM_LIP MSRs) that duplicate functions of the LastExceptionToIP and LastExceptionFromIP MSRs found in P6 family processors.

For details, see Section 16.7, “Last Branch, Interrupt, and Exception Recording (Processors based on Intel NetBurst® Microarchitecture),” and Appendix B.6, “MSRs In Intel® Core™ Solo and Intel® Core™ Duo Processors.”

Reserved · Reserved

Page 711 of the Intel 253668-032US user manual — 16.9 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (PENTIUM M PROCESSORS)
Page 711 · click to enlarge
Page 711

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

32. 31

From Linear Address To Linear Address

Figure 16-15. LBR Branch Record Layout for the Intel Core Solo

and Intel Core Duo Processor

16.9 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (PENTIUM M PROCESSORS)

Like the Pentium 4 and Intel Xeon processor family, Pentium M processors provide last branch interrupt and exception recording. The capability operates almost identi- cally to that found in Pentium 4 and Intel Xeon processors. There are differences in the shape of the stack and in some MSR names and locations. Note the following: • MSR_DEBUGCTLB MSR — Enables debug trace interrupt, debug trace store, trace messages enable, performance monitoring breakpoint flags, single stepping on branches, and last branch. For Pentium M processors, this MSR is located at register address 01D9H. See Figure 16-16 and the entries below for a description of the flags.

— LBR (last branch/interrupt/exception) flag (bit 0) — When set, the processor records a running trace of the most recent branches, interrupts, and/or exceptions taken by the processor (prior to a debug exception being generated) in the last branch record (LBR) stack. For more information, see the “Last Branch Record (LBR) Stack” bullet below.

— BTF (single-step on branches) flag (bit 1) — When set, the processor treats the TF flag in the EFLAGS register as a “single-step on branches” flag rather than a “single-step on instructions” flag. This mechanism allows single-stepping the processor on taken branches, interrupts, and exceptions. See Section 16.4.3, “Single-Stepping on Branches, Exceptions, and Inter- rupts,” for more information about the BTF flag.

— PBi (performance monitoring/breakpoint pins) flags (bits 5-2) — When these flags are set, the performance monitoring/breakpoint pins on the processor (BP0#, BP1#, BP2#, and BP3#) report breakpoint matches in the corresponding breakpoint-address registers (DR0 through DR3). The processor asserts then deasserts the corresponding BPi# pin when a breakpoint match occurs. When a PBi flag is clear, the performance monitoring/breakpoint pins report performance events. Processor execution is not affected by reporting performance events.

MSR_LASTBRANCH_0 through MSR_LASTBRANCH_7

Page 712 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 712 · click to enlarge
Page 712

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

— TR (trace message enable) flag (bit 6) — When set, branch trace messages are enabled. When the processor detects a taken branch, interrupt, or exception, it sends the branch record out on the system bus as a branch trace message (BTM). See Section 16.4.4, “Branch Trace Messages,” for more information about the TR flag.

— BTS (branch trace store) flag (bit 7) — When set, enables the BTS facilities to log BTMs to a memory-resident BTS buffer that is part of the DS save area. See Section 16.4.9, “BTS and DS Save Area.”

— BTINT (branch trace interrupt) flag (bits 8) — When set, the BTS facilities generate an interrupt when the BTS buffer is full. When clear, BTMs are logged to the BTS buffer in a circular fashion. See Section 16.4.5, “Branch Trace Store (BTS),” for a description of this mechanism.

8 7 6 5 4 3 2 1 0

BTINT — Branch trace interrupt

BTS — Branch trace store

TR — Trace messages enable

PB3/2/1/0 — Performance monitoring breakpoint flags

BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-16. MSR_DEBUGCTLB MSR for Pentium M Processors

  • Debug store (DS) feature flag (bit 21), returned by the CPUID instruction — Indicates that the processor provides the debug store (DS) mechanism, which allows BTMs to be stored in a memory-resident BTS buffer. See Section 16.4.5, “Branch Trace Store (BTS).”
  • Last Branch Record (LBR) Stack — The LBR stack consists of 8 MSRs (MSR_LASTBRANCH_0 through MSR_LASTBRANCH_7); bits 31-0 hold the ‘from’ address, bits 63-32 hold the ‘to’ address. For Pentium M Processors, these pairs are located at register addresses 040H-047H. See Figure 16-17.
  • Last Branch Record Top-of-Stack (TOS) Pointer — The TOS Pointer MSR contains a 3-bit pointer (bits 2-0) to the MSR in the LBR stack that contains the most recent branch, interrupt, or exception recorded. For Pentium M Processors, this MSR is located at register address 01C9H.

Reserved

Page 713 of the Intel 253668-032US user manual — 16.10.1 DEBUGCTLMSR Register
Page 713 · click to enlarge
Page 713

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

32. 31

From Linear Address To Linear Address

Figure 16-17. LBR Branch Record Layout for the Pentium M Processor

For more detail on these capabilities, see Section 16.7.3, “Last Exception Records,” and Appendix B.7, “MSRs In the Pentium M Processor.”

16.10 LAST BRANCH, INTERRUPT, AND EXCEPTION RECORDING (P6 FAMILY PROCESSORS)

The P6 family processors provide five MSRs for recording the last branch, interrupt, or exception taken by the processor: DEBUGCTLMSR, LastBranchToIP, LastBranch- FromIP, LastExceptionToIP, and LastExceptionFromIP. These registers can be used to collect last branch records, to set breakpoints on branches, interrupts, and excep- tions, and to single-step from one branch to the next.

See Appendix B, “Model-Specific Registers (MSRs),” for a detailed description of each of the last branch recording MSRs.

16.10.1 DEBUGCTLMSR Register

The version of the DEBUGCTLMSR register found in the P6 family processors enables last branch, interrupt, and exception recording; taken branch breakpoints; the breakpoint reporting pins; and trace messages. This register can be written to using the WRMSR instruction, when operating at privilege level 0 or when in real-address mode. A protected-mode operating system procedure is required to provide user access to this register. Figure 16-18 shows the flags in the DEBUGCTLMSR register for the P6 family processors. The functions of these flags are as follows: • LBR (last branch/interrupt/exception) flag (bit 0) — When set, the processor records the source and target addresses (in the LastBranchToIP, LastBranchFromIP, LastExceptionToIP, and LastExceptionFromIP MSRs) for the last branch and the last exception or interrupt taken by the processor prior to a debug exception being generated. The processor clears this flag whenever a debug exception, such as an instruction or data breakpoint or single-step trap occurs.

MSR_LASTBRANCH_0 through MSR_LASTBRANCH_7

Page 714 of the Intel 253668-032US user manual — 16.10.2 Last Branch and Last Exception MSRs
Page 714 · click to enlarge
Page 714

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

7 6 5 4 3 2 1 0

P B 3 Reserved

B T F T R

P B 2

P B 1

P B 0

L B R

TR — Trace messages enable PBi — Performance monitoring/breakpoint pins BTF — Single-step on branches LBR — Last branch/interrupt/exception

Figure 16-18. DEBUGCTLMSR Register (P6 Family Processors)

  • BTF (single-step on branches) flag (bit 1) — When set, the processor treats the TF flag in the EFLAGS register as a “single-step on branches” flag. See Section 16.4.3, “Single-Stepping on Branches, Exceptions, and Interrupts.”
  • PB i (performance monitoring/breakpoint pins) flags (bits 2 through 5) — When these flags are set, the performance monitoring/breakpoint pins on the processor (BP0#, BP1#, BP2#, and BP3#) report breakpoint matches in the corresponding breakpoint-address registers (DR0 through DR3). The processor asserts then deasserts the corresponding BP i # pin when a breakpoint match occurs. When a PB i flag is clear, the performance monitoring/breakpoint pins report performance events. Processor execution is not affected by reporting performance events.
  • TR (trace message enable) flag (bit 6) — When set, trace messages are enabled as described in Section 16.4.4, “Branch Trace Messages.” Setting this flag greatly reduces the performance of the processor. When trace messages are enabled, the values stored in the LastBranchToIP, LastBranchFromIP, LastExceptionToIP, and LastExceptionFromIP MSRs are undefined.

16.10.2 Last Branch and Last Exception MSRs

The LastBranchToIP and LastBranchFromIP MSRs are 32-bit registers for recording the instruction pointers for the last branch, interrupt, or exception that the processor took prior to a debug exception being generated. When a branch occurs, the processor loads the address of the branch instruction into the LastBranchFromIP MSR and loads the target address for the branch into the LastBranchToIP MSR.

When an interrupt or exception occurs (other than a debug exception), the address of the instruction that was interrupted by the exception or interrupt is loaded into the LastBranchFromIP MSR and the address of the exception or interrupt handler that is called is loaded into the LastBranchToIP MSR.

The LastExceptionToIP and LastExceptionFromIP MSRs (also 32-bit registers) record the instruction pointers for the last branch that the processor took prior to an excep-

Page 715 of the Intel 253668-032US user manual — 16.10.3 Monitoring Branches, Exceptions, and Interrupts
Page 715 · click to enlarge
Page 715

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

tion or interrupt being generated. When an exception or interrupt occurs, the contents of the LastBranchToIP and LastBranchFromIP MSRs are copied into these registers before the to and from addresses of the exception or interrupt are recorded in the LastBranchToIP and LastBranchFromIP MSRs.

These registers can be read using the RDMSR instruction.

16.10.3 Monitoring Branches, Exceptions, and Interrupts

When the LBR flag in the DEBUGCTLMSR register is set, the processor automatically begins recording branches that it takes, exceptions that are generated (except for debug exceptions), and interrupts that are serviced. Each time a branch, exception, or interrupt occurs, the processor records the to and from instruction pointers in the LastBranchToIP and LastBranchFromIP MSRs. In addition, for interrupts and excep- tions, the processor copies the contents of the LastBranchToIP and LastBranch- FromIP MSRs into the LastExceptionToIP and LastExceptionFromIP MSRs prior to recording the to and from addresses of the interrupt or exception.

When the processor generates a debug exception (#DB), it automatically clears the LBR flag before executing the exception handler, but does not touch the last branch and last exception MSRs. The addresses for the last branch, interrupt, or exception taken are thus retained in the LastBranchToIP and LastBranchFromIP MSRs and the addresses of the last branch prior to an interrupt or exception are retained in the LastExceptionToIP, and LastExceptionFromIP MSRs.

The debugger can use the last branch, interrupt, and/or exception addresses in combination with code-segment selectors retrieved from the stack to reset break- points in the breakpoint-address registers (DR0 through DR3), allowing a backward trace from the manifestation of a particular bug toward its source. Because the instruction pointers recorded in the LastBranchToIP, LastBranchFromIP, LastExcepti- onToIP, and LastExceptionFromIP MSRs are offsets into a code segment, software must determine the segment base address of the code segment associated with the control transfer to calculate the linear address to be placed in the breakpoint-address registers. The segment base address can be determined by reading the segment selector for the code segment from the stack and using it to locate the segment descriptor for the segment in the GDT or LDT. The segment base address can then be read from the segment descriptor.

Before resuming program execution from a debug-exception handler, the handler must set the LBR flag again to re-enable last branch and last exception/interrupt recording.

Page 716 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 716 · click to enlarge
Page 716

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.11 TIME-STAMP COUNTER

  • The Intel 64 and IA-32 architectures (beginning with the Pentium processor) define a time-stamp counter mechanism that can be used to monitor and identify the relative time occurrence of processor events. The counter’s architecture includes the following components:
  • TSC flag — A feature bit that indicates the availability of the time-stamp counter. The counter is available in an if the function CPUID.1:EDX.TSC[bit 4] = 1.
  • IA32_TIME_STAMP_COUNTER MSR (called TSC MSR in P6 family and Pentium processors) — The MSR used as the counter.
  • RDTSC instruction — An instruction used to read the time-stamp counter.
  • TSD flag — A control register flag is used to enable or disable the time-stamp counter (enabled if CR4.TSD[bit 2] = 1).

The time-stamp counter (as implemented in the P6 family, Pentium, Pentium M, Pentium 4, Intel Xeon, Intel Core Solo and Intel Core Duo processors and later processors) is a 64-bit counter that is set to 0 following a RESET of the processor. Following a RESET, the counter increments even when the processor is halted by the HLT instruction or the external STPCLK# pin. Note that the assertion of the external DPSLP# pin may cause the time-stamp counter to stop.

Processor families increment the time-stamp counter differently: • For Pentium M processors (family [06H], models [09H, 0DH]); for Pentium 4 processors, Intel Xeon processors (family [0FH], models [00H, 01H, or 02H]); and for P6 family processors: the time-stamp counter increments with every internal processor clock cycle.

The internal processor clock cycle is determined by the current core-clock to bus- clock ratio. Intel® SpeedStep® technology transitions may also impact the processor clock. • For Pentium 4 processors, Intel Xeon processors (family [0FH], models [03H and higher]); for Intel Core Solo and Intel Core Duo processors (family [06H], model [0EH]); for the Intel Xeon processor 5100 series and Intel Core 2 Duo processors (family [06H], model [0FH]); for Intel Core 2 and Intel Xeon processors (family [06H], display_model [17H]); for Intel Atom processors (family [06H], display_model [1CH]): the time-stamp counter increments at a constant rate. That rate may be set by the maximum core-clock to bus-clock ratio of the processor or may be set by the maximum resolved frequency at which the processor is booted. The maximum resolved frequency may differ from the maximum qualified frequency of the processor, see Section 30.10.5 for more detail.

The specific processor configuration determines the behavior. Constant TSC behavior ensures that the duration of each clock tick is uniform and supports the use of the TSC as a wall clock timer even if the processor core changes frequency. This is the architectural behavior moving forward.

Page 717 of the Intel 253668-032US user manual — 16.11.1 Invariant TSC
Page 717 · click to enlarge
Page 717

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

NOTE

To determine average processor clock frequency, Intel recommends the use of EMON logic to count processor core clocks over the period of time for which the average is required. See Section 30.10, “Counting Clocks,” and Appendix A, “Performance- Monitoring Events,” for more information.

The RDTSC instruction reads the time-stamp counter and is guaranteed to return a monotonically increasing unique value whenever executed, except for a 64-bit counter wraparound. Intel guarantees that the time-stamp counter will not wrap- around within 10 years after being reset. The period for counter wrap is longer for Pentium 4, Intel Xeon, P6 family, and Pentium processors.

Normally, the RDTSC instruction can be executed by programs and procedures running at any privilege level and in virtual-8086 mode. The TSD flag allows use of this instruction to be restricted to programs and procedures running at privilege level 0. A secure operating system would set the TSD flag during system initialization to disable user access to the time-stamp counter. An operating system that disables user access to the time-stamp counter should emulate the instruction through a user-accessible programming interface.

The RDTSC instruction is not serializing or ordered with other instructions. It does not necessarily wait until all previous instructions have been executed before reading the counter. Similarly, subsequent instructions may begin execution before the RDTSC instruction operation is performed.

The RDMSR and WRMSR instructions read and write the time-stamp counter, treating the time-stamp counter as an ordinary MSR (address 10H). In the Pentium 4, Intel Xeon, and P6 family processors, all 64-bits of the time-stamp counter are read using RDMSR (just as with RDTSC). When WRMSR is used to write the time-stamp counter on processors before family [0FH], models [03H, 04H]: only the low-order 32-bits of the time-stamp counter can be written (the high-order 32 bits are cleared to 0). For family [0FH], models [03H, 04H, 06H]; for family [06H]], model [0EH, 0FH]; for family [06H]], display_model [17H, 1AH, 1CH, 1DH]: all 64 bits are writable.

16.11.1 Invariant TSC

The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. Processor’s support for invariant TSC is indicated by CPUID.80000007H:EDX[8].

The invariant TSC will run at a constant rate in all ACPI P-, C-. and T-states. This is the architectural behavior moving forward. On processors with invariant TSC support, the OS may use the TSC for wall clock timer services (instead of ACPI or HPET timers). TSC reads are much more efficient and do not incur the overhead associated with a ring transition or access to a platform resource.

Page 718 of the Intel 253668-032US user manual — DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER
Page 718 · click to enlarge
Page 718

DEBUGGING, PROFILING BRANCHES AND TIME-STAMP COUNTER

16.11.2 IA32_TSC_AUX Register and RDTSCP Support

Processor based on Intel microarchitecture (Nehalem) provides an auxiliary TSC register, IA32_TSC_AUX that is designed to be used in conjunction with IA32_TSC. IA32_TSC_AUX provides a 32-bit field that is initialized by privileged software with a signature value (for example, a logical processor ID).

The primary usage of IA32_TSC_AUX in conjunction with IA32_TSC is to allow soft- ware to read the 64-bit time stamp in IA32_TSC and signature value in IA32_TSC_AUX with the instruction RDTSCP in an atomic operation. RDTSCP returns the 64-bit time stamp in EDX:EAX and the 32-bit TSC_AUX signature value in ECX. The atomicity of RDTSCP ensures that no context switch can occur between the reads of the TSC and TSC_AUX values.

Support for RDTSCP is indicated by CPUID.80000001H:EDX[27]. As with RDTSC instruction, non-ring 0 access is controlled by CR4.TSD (Time Stamp Disable flag).

User mode software can use RDTSCP to detect if CPU migration has occurred between successive reads of the TSC. It can also be used to adjust for per-CPU differ- ences in TSC values in a NUMA system.

Page 719 of the Intel 253668-032US user manual — 17.1 REAL-ADDRESS MODE
Page 719 · click to enlarge
Page 719

CHAPTER 17 8086 EMULATION

  • IA-32 processors (beginning with the Intel386 processor) provide two ways to execute new or legacy programs that are assembled and/or compiled to run on an Intel 8086 processor:
  • Real-address mode.
  • Virtual-8086 mode.

Figure 2-3 shows the relationship of these operating modes to protected mode and system management mode (SMM).

When the processor is powered up or reset, it is placed in the real-address mode. This operating mode almost exactly duplicates the execution environment of the Intel 8086 processor, with some extensions. Virtually any program assembled and/or compiled to run on an Intel 8086 processor will run on an IA-32 processor in this mode.

When running in protected mode, the processor can be switched to virtual-8086 mode to run 8086 programs. This mode also duplicates the execution environment of the Intel 8086 processor, with extensions. In virtual-8086 mode, an 8086 program runs as a separate protected-mode task. Legacy 8086 programs are thus able to run under an operating system (such as Microsoft Windows*) that takes advantage of protected mode and to use protected-mode facilities, such as the protected-mode interrupt- and exception-handling facilities. Protected-mode multitasking permits multiple virtual-8086 mode tasks (with each task running a separate 8086 program) to be run on the processor along with other non-virtual-8086 mode tasks.

This section describes both the basic real-address mode execution environment and the virtual-8086-mode execution environment, available on the IA-32 processors beginning with the Intel386 processor.

17.1 REAL-ADDRESS MODE

The IA-32 architecture’s real-address mode runs programs written for the Intel 8086, Intel 8088, Intel 80186, and Intel 80188 processors, or for the real-address mode of the Intel 286, Intel386, Intel486, Pentium, P6 family, Pentium 4, and Intel Xeon processors.

The execution environment of the processor in real-address mode is designed to duplicate the execution environment of the Intel 8086 processor. To an 8086 program, a processor operating in real-address mode behaves like a high-speed 8086 processor. The principal features of this architecture are defined in Chapter 3, “Basic Execution Environment”, of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1.

Page 720 of the Intel 253668-032US user manual — 8086 EMULATION
Page 720 · click to enlarge
Page 720

8086 EMULATION

  • The following is a summary of the core features of the real-address mode execution environment as would be seen by a program written for the 8086:
  • The processor supports a nominal 1-MByte physical address space (see Section 17.1.1, “Address Translation in Real-Address Mode”, for specific details). This address space is divided into segments, each of which can be up to 64 KBytes in length. The base of a segment is specified with a 16-bit segment selector, which is zero extended to form a 20-bit offset from address 0 in the address space. An operand within a segment is addressed with a 16-bit offset from the base of the segment. A physical address is thus formed by adding the offset to the 20-bit segment base (see Section 17.1.1, “Address Translation in Real-Address Mode”).
  • All operands in “native 8086 code” are 8-bit or 16-bit values. (Operand size override prefixes can be used to access 32-bit operands.)
  • Eight 16-bit general-purpose registers are provided: AX, BX, CX, DX, SP, BP, SI, and DI. The extended 32 bit registers (EAX, EBX, ECX, EDX, ESP, EBP, ESI, and EDI) are accessible to programs that explicitly perform a size override operation.
  • Four segment registers are provided: CS, DS, SS, and ES. (The FS and GS registers are accessible to programs that explicitly access them.) The CS register contains the segment selector for the code segment; the DS and ES registers contain segment selectors for data segments; and the SS register contains the segment selector for the stack segment.
  • The 8086 16-bit instruction pointer (IP) is mapped to the lower 16-bits of the EIP register. Note this register is a 32-bit register and unintentional address wrapping may occur.
  • The 16-bit FLAGS register contains status and control flags. (This register is mapped to the 16 least significant bits of the 32-bit EFLAGS register.)
  • All of the Intel 8086 instructions are supported (see Section 17.1.3, “Instructions Supported in Real-Address Mode”).
  • A single, 16-bit-wide stack is provided for handling procedure calls and invocations of interrupt and exception handlers. This stack is contained in the stack segment identified with the SS register. The SP (stack pointer) register contains an offset into the stack segment. The stack grows down (toward lower segment offsets) from the stack pointer. The BP (base pointer) register also contains an offset into the stack segment that can be used as a pointer to a parameter list. When a CALL instruction is executed, the processor pushes the current instruction pointer (the 16 least-significant bits of the EIP register and, on far calls, the current value of the CS register) onto the stack. On a return, initiated with a RET instruction, the processor pops the saved instruction pointer from the stack into the EIP register (and CS register on far returns). When an implicit call to an interrupt or exception handler is executed, the processor pushes the EIP, CS, and EFLAGS (low-order 16-bits only) registers onto the stack. On a return from an interrupt or exception handler, initiated with an IRET instruction, the processor pops the saved instruction pointer and EFLAGS image from the stack into the EIP, CS, and EFLAGS registers.
Page 721 of the Intel 253668-032US user manual — 17.1.1 Address Translation in Real-Address Mode
Page 721 · click to enlarge
Page 721

8086 EMULATION

  • A single interrupt table, called the “interrupt vector table” or “interrupt table,” is provided for handling interrupts and exceptions (see Figure 17-2). The interrupt table (which has 4-byte entries) takes the place of the interrupt descriptor table (IDT, with 8-byte entries) used when handling protected-mode interrupts and exceptions. Interrupt and exception vector numbers provide an index to entries in the interrupt table. Each entry provides a pointer (called a “vector”) to an interruptor exception-handling procedure. See Section 17.1.4, “Interrupt and Exception Handling”, for more details. It is possible for software to relocate the IDT by means of the LIDT instruction on IA-32 processors beginning with the Intel386 processor.
  • The x87 FPU is active and available to execute x87 FPU instructions in realaddress mode. Programs written to run on the Intel 8087 and Intel 287 math coprocessors can be run in real-address mode without modification.
  • The following extensions to the Intel 8086 execution environment are available in the IA-32 architecture’s real-address mode. If backwards compatibility to Intel 286 and Intel 8086 processors is required, these features should not be used in new programs written to run in real-address mode.
  • Two additional segment registers (FS and GS) are available.
  • Many of the integer and system instructions that have been added to later IA-32 processors can be executed in real-address mode (see Section 17.1.3, “Instruc tions Supported in Real-Address Mode”).
  • The 32-bit operand prefix can be used in real-address mode programs to execute the 32-bit forms of instructions. This prefix also allows real-address mode programs to use the processor’s 32-bit general-purpose registers.
  • The 32-bit address prefix can be used in real-address mode programs, allowing 32-bit offsets.

The following sections describe address formation, registers, available instructions, and interrupt and exception handling in real-address mode. For information on I/O in real-address mode, see Chapter 13, “Input/Output”, of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1.

17.1.1 Address Translation in Real-Address Mode

In real-address mode, the processor does not interpret segment selectors as indexes into a descriptor table; instead, it uses them directly to form linear addresses as the 8086 processor does. It shifts the segment selector left by 4 bits to form a 20-bit base address (see Figure 17-1). The offset into a segment is added to the base address to create a linear address that maps directly to the physical address space.

When using 8086-style address translation, it is possible to specify addresses larger than 1 MByte. For example, with a segment selector value of FFFFH and an offset of FFFFH, the linear (and physical) address would be 10FFEFH (1 megabyte plus 64 KBytes). The 8086 processor, which can form addresses only up to 20 bits long, trun cates the high-order bit, thereby “wrapping” this address to FFEFH. When operating

Page 722 of the Intel 253668-032US user manual — 17.1.3 Instructions Supported in Real-Address Mode
Page 722 · click to enlarge
Page 722

8086 EMULATION

in real-address mode, however, the processor does not truncate such an address and uses it as a physical address. (Note, however, that for IA-32 processors beginning with the Intel486 processor, the A20M# signal can be used in real-address mode to mask address line A20, thereby mimicking the 20-bit wrap-around behavior of the 8086 processor.) Care should be take to ensure that A20M# based address wrapping is handled correctly in multiprocessor based system.

0 Base

+

0 Offset

=

20-bit Linear Address Linear Address

Figure 17-1. Real-Address Mode Address Translation

The IA-32 processors beginning with the Intel386 processor can generate 32-bit offsets using an address override prefix; however, in real-address mode, the value of a 32-bit offset may not exceed FFFFH without causing an exception.

For full compatibility with Intel 286 real-address mode, pseudo-protection faults (interrupt 12 or 13) occur if a 32-bit offset is generated outside the range 0 through FFFFH.

17.1.2 Registers Supported in Real-Address Mode

The register set available in real-address mode includes all the registers defined for the 8086 processor plus the new registers introduced in later IA-32 processors, such as the FS and GS segment registers, the debug registers, the control registers, and the floating-point unit registers. The 32-bit operand prefix allows a real-address mode program to use the 32-bit general-purpose registers (EAX, EBX, ECX, EDX, ESP, EBP, ESI, and EDI).

17.1.3 Instructions Supported in Real-Address Mode

The following instructions make up the core instruction set for the 8086 processor. If backwards compatibility to the Intel 286 and Intel 8086 processors is required, only these instructions should be used in a new program written to run in real-address mode.

16-bit Segment Selector · 16-bit Effective Address

Page 723 of the Intel 253668-032US user manual — 8086 EMULATION
Page 723 · click to enlarge
Page 723

8086 EMULATION

  • Move (MOV) instructions that move operands between general-purpose registers, segment registers, and between memory and general-purpose registers.
  • The exchange (XCHG) instruction.
  • Load segment register instructions LDS and LES.
  • Arithmetic instructions ADD, ADC, SUB, SBB, MUL, IMUL, DIV, IDIV, INC, DEC, CMP, and NEG.
  • Logical instructions AND, OR, XOR, and NOT.
  • Decimal instructions DAA, DAS, AAA, AAS, AAM, and AAD.
  • Stack instructions PUSH and POP (to general-purpose registers and segment registers).
  • Type conversion instructions CWD, CDQ, CBW, and CWDE.
  • Shift and rotate instructions SAL, SHL, SHR, SAR, ROL, ROR, RCL, and RCR.
  • TEST instruction.
  • Control instructions JMP, J cc , CALL, RET, LOOP, LOOPE, and LOOPNE.
  • Interrupt instructions INT n , INTO, and IRET.
  • EFLAGS control instructions STC, CLC, CMC, CLD, STD, LAHF, SAHF, PUSHF, and POPF.
  • I/O instructions IN, INS, OUT, and OUTS.
  • Load effective address (LEA) instruction, and translate (XLATB) instruction.
  • LOCK prefix.
  • Repeat prefixes REP, REPE, REPZ, REPNE, and REPNZ.
  • Processor halt (HLT) instruction.
  • No operation (NOP) instruction.
  • The following instructions, added to later IA-32 processors (some in the Intel 286 processor and the remainder in the Intel386 processor), can be executed in realaddress mode, if backwards compatibility to the Intel 8086 processor is not required.
  • Move (MOV) instructions that operate on the control and debug registers.
  • Load segment register instructions LSS, LFS, and LGS.
  • Generalized multiply instructions and multiply immediate data.
  • Shift and rotate by immediate counts.
  • Stack instructions PUSHA, PUSHAD, POPA and POPAD, and PUSH immediate data.
  • Move with sign extension instructions MOVSX and MOVZX.
  • Long-displacement J cc instructions.
  • Exchange instructions CMPXCHG, CMPXCHG8B, and XADD.
  • String instructions MOVS, CMPS, SCAS, LODS, and STOS.
Page 724 of the Intel 253668-032US user manual — 17.1.4 Interrupt and Exception Handling
Page 724 · click to enlarge
Page 724

8086 EMULATION

  • Bit test and bit scan instructions BT, BTS, BTR, BTC, BSF, and BSR; the byte-seton condition instruction SET c c; and the byte swap (BSWAP) instruction.
  • Double shift instructions SHLD and SHRD.
  • EFLAGS control instructions PUSHF and POPF.
  • ENTER and LEAVE control instructions.
  • BOUND instruction.
  • CPU identification (CPUID) instruction.
  • System instructions CLTS, INVD, WINVD, INVLPG, LGDT, SGDT, LIDT, SIDT, LMSW, SMSW, RDMSR, WRMSR, RDTSC, and RDPMC.

Execution of any of the other IA-32 architecture instructions (not given in the previous two lists) in real-address mode result in an invalid-opcode exception (#UD) being generated.

17.1.4 Interrupt and Exception Handling

When operating in real-address mode, software must provide interrupt and excep tion-handling facilities that are separate from those provided in protected mode. Even during the early stages of processor initialization when the processor is still in real-address mode, elementary real-address mode interrupt and exception-handling facilities must be provided to insure reliable operation of the processor, or the initial ization code must insure that no interrupts or exceptions will occur.

The IA-32 processors handle interrupts and exceptions in real-address mode similar to the way they handle them in protected mode. When a processor receives an inter rupt or generates an exception, it uses the vector number of the interrupt or excep tion as an index into the interrupt table. (In protected mode, the interrupt table is called the interrupt descriptor table (IDT), but in real-address mode, the table is usually called the interrupt vector table, or simply the interrupt table.) The entry in the interrupt vector table provides a pointer to an interrupt- or exception-handler procedure. (The pointer consists of a segment selector for a code segment and a 16- bit offset into the segment.) The processor performs the following actions to make an implicit call to the selected handler:

1. Pushes the current values of the CS and EIP registers onto the stack. (Only the 16 least-significant bits of the EIP register are pushed.)
2. Pushes the low-order 16 bits of the EFLAGS register onto the stack.
3. Clears the IF flag in the EFLAGS register to disable interrupts.
4. Clears the TF, RC, and AC flags, in the EFLAGS register.
5. Transfers program control to the location specified in the interrupt vector table.

An IRET instruction at the end of the handler procedure reverses these steps to return program control to the interrupted program. Exceptions do not return error codes in real-address mode.

Page 725 of the Intel 253668-032US user manual — 8086 EMULATION
Page 725 · click to enlarge
Page 725

8086 EMULATION

The interrupt vector table is an array of 4-byte entries (see Figure 17-2). Each entry consists of a far pointer to a handler procedure, made up of a segment selector and an offset. The processor scales the interrupt or exception vector by 4 to obtain an offset into the interrupt table. Following reset, the base of the interrupt vector table is located at physical address 0 and its limit is set to 3FFH. In the Intel 8086 processor, the base address and limit of the interrupt vector table cannot be changed. In the later IA-32 processors, the base address and limit of the interrupt vector table are contained in the IDTR register and can be changed using the LIDT instruction.

(For backward compatibility to Intel 8086 processors, the default base address and limit of the interrupt vector table should not be changed.)

Up to Entry 255

* Interrupt vector number 0 selects entry 0

IDTR (called “interrupt vector 0”) in the interrupt vector table. Interrupt vector 0 in turn points to the start of the interrupt handler for interrupt 0.

Figure 17-2. Interrupt Vector Table in Real-Address Mode

Table 17-1 shows the interrupt and exception vectors that can be generated in real- address mode and virtual-8086 mode, and in the Intel 8086 processor. See Chapter 6, “Interrupt and Exception Handling”, for a description of the exception conditions.

Show 6 more labels / short text on this page
Entry 3 · Entry 2 · Entry 1 · Segment Selector · Interrupt Vector 0* · Offset
Page 726 of the Intel 253668-032US user manual — 8086 EMULATION
Page 726 · click to enlarge
Page 726

8086 EMULATION

17.2 VIRTUAL-8086 MODE

Virtual-8086 mode is actually a special type of a task that runs in protected mode. When the operating-system or executive switches to a virtual-8086-mode task, the processor emulates an Intel 8086 processor. The execution environment of the processor while in the 8086-emulation state is the same as is described in Section 17.1, “Real-Address Mode” for real-address mode, including the extensions. The major difference between the two modes is that in virtual-8086 mode the 8086 emulator uses some protected-mode services (such as the protected-mode interrupt and exception-handling and paging facilities).

As in real-address mode, any new or legacy program that has been assembled and/or compiled to run on an Intel 8086 processor will run in a virtual-8086-mode task. And several 8086 programs can be run as virtual-8086-mode tasks concur rently with normal protected-mode tasks, using the processor’s multitasking facilities.

Table 17-1. Real-Address Mode Exceptions and Interrupts

Vector No.

0 Divide Error (#DE) Yes Yes Yes

1 Debug Exception (#DB) Yes Yes No

2 NMI Interrupt Yes Yes Yes

3 Breakpoint (#BP) Yes Yes Yes

4 Overflow (#OF) Yes Yes Yes

5 BOUND Range Exceeded (#BR) Yes Yes Reserved

6 Invalid Opcode (#UD) Yes Yes Reserved

7 Device Not Available (#NM) Yes Yes Reserved

8 Double Fault (#DF) Yes Yes Reserved

9 (Intel reserved. Do not use.) Reserved Reserved Reserved

10 Invalid TSS (#TS) Reserved Yes Reserved

11 Segment Not Present (#NP) Reserved Yes Reserved

12 Stack Fault (#SS) Yes Yes Reserved

13 General Protection (#GP)* Yes Yes Reserved

14 Page Fault (#PF) Reserved Yes Reserved

15 (Intel reserved. Do not use.) Reserved Reserved Reserved

16 Floating-Point Error (#MF) Yes Yes Reserved

17 Alignment Check (#AC) Reserved Yes Reserved

18 Machine Check (#MC) Yes Yes Reserved

Description Real-Address Mode · Virtual-8086 Mode · Intel 8086 Processor

Page 727 of the Intel 253668-032US user manual — 17.2.2 Structure of a Virtual-8086 Task
Page 727 · click to enlarge
Page 727

8086 EMULATION

Table 17-1. Real-Address Mode Exceptions and Interrupts (Contd.)

Vector No.

19-31 (Intel reserved. Do not use.) Reserved Reserved Reserved

32- 255 User Defined Interrupts Yes Yes Yes

17.2.1 Enabling Virtual-8086 Mode

The processor runs in virtual-8086 mode when the VM (virtual machine) flag in the EFLAGS register is set. This flag can only be set when the processor switches to a new protected-mode task or resumes virtual-8086 mode via an IRET instruction.

System software cannot change the state of the VM flag directly in the EFLAGS register (for example, by using the POPFD instruction). Instead it changes the flag in the image of the EFLAGS register stored in the TSS or on the stack following a call to an interrupt- or exception-handler procedure. For example, software sets the VM flag in the EFLAGS image in the TSS when first creating a virtual-8086 task.

  • The processor tests the VM flag under three general conditions:
  • When loading segment registers, to determine whether to use 8086-style address translation.
  • When decoding instructions, to determine which instructions are not supported in virtual-8086 mode and which instructions are sensitive to IOPL.
  • When checking privileged instructions, on page accesses, or when performing other permission checks. (Virtual-8086 mode always executes at CPL 3.)

17.2.2 Structure of a Virtual-8086 Task

  • A virtual-8086-mode task consists of the following items:
  • A 32-bit TSS for the task.
  • The 8086 program.
  • A virtual-8086 monitor.
  • 8086 operating-system services.

The TSS of the new task must be a 32-bit TSS, not a 16-bit TSS, because the 16-bit TSS does not load the most-significant word of the EFLAGS register, which contains the VM flag. All TSS’s, stacks, data, and code used to handle exceptions when in virtual-8086 mode must also be 32-bit segments.

Description Real-Address Mode · Virtual-8086 Mode · Intel 8086 Processor

Page 728 of the Intel 253668-032US user manual — 17.2.3 Paging of Virtual-8086 Tasks
Page 728 · click to enlarge
Page 728

8086 EMULATION

The processor enters virtual-8086 mode to run the 8086 program and returns to protected mode to run the virtual-8086 monitor.

The virtual-8086 monitor is a 32-bit protected-mode code module that runs at a CPL of 0. The monitor consists of initialization, interrupt- and exception-handling, and I/O emulation procedures that emulate a personal computer or other 8086-based plat form. Typically, the monitor is either part of or closely associated with the protected- mode general-protection (#GP) exception handler, which also runs at a CPL of 0. As with any protected-mode code module, code-segment descriptors for the virtual- 8086 monitor must exist in the GDT or in the task’s LDT. The virtual-8086 monitor also may need data-segment descriptors so it can examine the IDT or other parts of the 8086 program in the first 1 MByte of the address space. The linear addresses above 10FFEFH are available for the monitor, the operating system, and other system software.

The 8086 operating-system services consists of a kernel and/or operating-system procedures that the 8086 program makes calls to. These services can be imple mented in either of the following two ways: • They can be included in the 8086 program. This approach is desirable for either of the following reasons:

— The 8086 program code modifies the 8086 operating-system services.

— There is not sufficient development time to merge the 8086 operating- system services into main operating system or executive. • They can be implemented or emulated in the virtual-8086 monitor. This approach is desirable for any of the following reasons:

— The 8086 operating-system procedures can be more easily coordinated among several virtual-8086 tasks.

— Memory can be saved by not duplicating 8086 operating-system procedure code for several virtual-8086 tasks.

— The 8086 operating-system procedures can be easily emulated by calls to the main operating system or executive.

The approach chosen for implementing the 8086 operating-system services may result in different virtual-8086-mode tasks using different 8086 operating-system services.

17.2.3 Paging of Virtual-8086 Tasks

Even though a program running in virtual-8086 mode can use only 20-bit linear addresses, the processor converts these addresses into 32-bit linear addresses before mapping them to the physical address space. If paging is being used, the 8086 address space for a program running in virtual-8086 mode can be paged and located in a set of pages in physical address space. If paging is used, it is transparent to the program running in virtual-8086 mode just as it is for any task running on the processor.

Page 729 of the Intel 253668-032US user manual — 17.2.5 Entering Virtual-8086 Mode
Page 729 · click to enlarge
Page 729

8086 EMULATION

  • Paging is not necessary for a single virtual-8086-mode task, but paging is useful or necessary in the following situations:
  • When running multiple virtual-8086-mode tasks. Here, paging allows the lower 1 MByte of the linear address space for each virtual-8086-mode task to be mapped to a different physical address location.
  • When emulating the 8086 address-wraparound that occurs at 1 MByte. When using 8086-style address translation, it is possible to specify addresses larger than 1 MByte. These addresses automatically wraparound in the Intel 8086 processor (see Section 17.1.1, “Address Translation in Real-Address Mode”). If any 8086 programs depend on address wraparound, the same effect can be achieved in a virtual-8086-mode task by mapping the linear addresses between 100000H and 110000H and linear addresses between 0 and 10000H to the same physical addresses.
  • When sharing the 8086 operating-system services or ROM code that is common to several 8086 programs running as different 8086-mode tasks.
  • When redirecting or trapping references to memory-mapped I/O devices.

17.2.4 Protection within a Virtual-8086 Task

  • Protection is not enforced between the segments of an 8086 program. Either of the following techniques can be used to protect the system software running in a virtual8086-mode task from the 8086 program:
  • Reserve the first 1 MByte plus 64 KBytes of each task’s linear address space for the 8086 program. An 8086 processor task cannot generate addresses outside this range.
  • Use the U/S flag of page-table entries to protect the virtual-8086 monitor and other system software in the virtual-8086 mode task space. When the processor is in virtual-8086 mode, the CPL is 3. Therefore, an 8086 processor program has only user privileges. If the pages of the virtual-8086 monitor have supervisor privilege, they cannot be accessed by the 8086 program.

17.2.5 Entering Virtual-8086 Mode

Figure 17-3 summarizes the methods of entering and leaving virtual-8086 mode. The processor switches to virtual-8086 mode in either of the following situations: • Task switch when the VM flag is set to 1 in the EFLAGS register image stored in the TSS for the task. Here the task switch can be initiated in either of two ways:

— A CALL or JMP instruction.

— An IRET instruction, where the NT flag in the EFLAGS image is set to 1. • Return from a protected-mode interrupt or exception handler when the VM flag is set to 1 in the EFLAGS register image on the stack.

Page 730 of the Intel 253668-032US user manual — 8086 EMULATION
Page 730 · click to enlarge
Page 730

8086 EMULATION

When a task switch is used to enter virtual-8086 mode, the TSS for the virtual-8086- mode task must be a 32-bit TSS. (If the new TSS is a 16-bit TSS, the upper word of the EFLAGS register is not in the TSS, causing the processor to clear the VM flag when it loads the EFLAGS register.) The processor updates the VM flag prior to loading the segment registers from their images in the new TSS. The new setting of the VM flag determines whether the processor interprets the contents of the segment registers as 8086-style segment selectors or protected-mode segment selectors. When the VM flag is set, the segment registers are loaded from the TSS, using 8086- style address translation to form base addresses.

See Section 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode”, for infor mation on entering virtual-8086 mode on a return from an interrupt or exception handler.

Page 731 of the Intel 253668-032US user manual — NOTES:
Page 731 · click to enlarge
Page 731

8086 EMULATION

PE=1

CALL

Protected- Mode Interrupt and Exception

RET

VM = 0

VM = 1

Interrupt or Exception2

RESET

IRET 4

IRET 5

Redirect Interrupt to 8086 Program

Interrupt or Exception Handler6

NOTES:

1. Task switch carried out in either of two ways:

- CALL or JMP where the VM flag in the EFLAGS image is 1. - IRET where VM is 1 and NT is 1.

2. Hardware interrupt or exception; software interrupt (INT n ) when IOPL is 3.
3. General-protection exception caused by software interrupt (INT n ), IRET, POPF, PUSHF, IN, or OUT when IOPL is less than 3.
4. Normal return from protected-mode interrupt or exception handler.
5. A return from the 8086 monitor to redirect an interrupt or exception back to an interrupt or exception handler in the 8086 program running in virtual-

8086 mode.

6. Internal redirection of a software interrupt (INT n ) when VME is 1, IOPL is

Figure 17-3. Entering and Leaving Virtual-8086 Mode

Show 15 more labels / short text on this page
Real Mode · Code · Real-Address Mode · PE=0 or RESET · Task Switch VM=0 · Protected Mode · Protected- Mode Tasks · Monitor Virtual-8086 · Handlers · Task Switch1 · Virtual-8086 Mode · #GP Exception3 · Virtual-8086 · Mode Tasks · (8086 Programs)
Page 732 of the Intel 253668-032US user manual — 8086 EMULATION
Page 732 · click to enlarge
Page 732

8086 EMULATION

17.2.6 Leaving Virtual-8086 Mode

  • The processor can leave the virtual-8086 mode only through an interrupt or excep tion. The following are situations where an interrupt or exception will lead to the processor leaving virtual-8086 mode (see Figure 17-3):
  • The processor services a hardware interrupt generated to signal the suspension of execution of the virtual-8086 application. This hardware interrupt may be generated by a timer or other external mechanism. Upon receiving the hardware interrupt, the processor enters protected mode and switches to a protectedmode (or another virtual-8086 mode) task either through a task gate in the protected-mode IDT or through a trap or interrupt gate that points to a handler that initiates a task switch. A task switch from a virtual-8086 task to another task loads the EFLAGS register from the TSS of the new task. The value of the VM flag in the new EFLAGS determines if the new task executes in virtual-8086 mode or not.
  • The processor services an exception caused by code executing the virtual-8086 task or services a hardware interrupt that “belongs to” the virtual-8086 task. Here, the processor enters protected mode and services the exception or hardware interrupt through the protected-mode IDT (normally through an interrupt or trap gate) and the protected-mode exceptionand interrupthandlers. The processor may handle the exception or interrupt within the context of the virtual 8086 task and return to virtual-8086 mode on a return from the handler procedure. The processor may also execute a task switch and handle the exception or interrupt in the context of another task.
  • The processor services a software interrupt generated by code executing in the virtual-8086 task (such as a software interrupt to call a MS-DOS* operating system routine). The processor provides several methods of handling these software interrupts, which are discussed in detail in Section 17.3.3, “Class 3—Software Interrupt Handling in Virtual-8086 Mode”. Most of them involve the processor entering protected mode, often by means of a general-protection (#GP) exception. In protected mode, the processor can send the interrupt to the virtual-8086 monitor for handling and/or redirect the interrupt back to the application program running in virtual-8086 mode task for handling.
  • IA-32 processors that incorporate the virtual mode extension (enabled with the VME flag in control register CR4) are capable of redirecting software-generated interrupts back to the program’s interrupt handlers without leaving virtual-8086 mode. See Section 17.3.3.4, “Method 5: Software Interrupt Handling”, for more information on this mechanism.
  • A hardware reset initiated by asserting the RESET or INIT pin is a special kind of interrupt. When a RESET or INIT is signaled while the processor is in virtual-8086 mode, the processor leaves virtual-8086 mode and enters real-address mode.
  • Execution of the HLT instruction in virtual-8086 mode will cause a generalprotection (GP#) fault, which the protected-mode handler generally sends to the virtual-8086 monitor. The virtual-8086 monitor then determines the correct
Page 733 of the Intel 253668-032US user manual — 17.2.8 Virtual-8086 Mode I/O
Page 733 · click to enlarge
Page 733

8086 EMULATION

execution sequence after verifying that it was entered as a result of a HLT execution.

See Section 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode”, for infor mation on leaving virtual-8086 mode to handle an interrupt or exception generated in virtual-8086 mode.

17.2.7 Sensitive Instructions

When an IA-32 processor is running in virtual-8086 mode, the CLI, STI, PUSHF, POPF, INT n, and IRET instructions are sensitive to IOPL. The IN, INS, OUT, and OUTS instructions, which are sensitive to IOPL in protected mode, are not sensitive in virtual-8086 mode.

The CPL is always 3 while running in virtual-8086 mode; if the IOPL is less than 3, an attempt to use the IOPL-sensitive instructions listed above triggers a general-protec tion exception (#GP). These instructions are sensitive to IOPL to give the virtual- 8086 monitor a chance to emulate the facilities they affect.

17.2.8 Virtual-8086 Mode I/O

Many 8086 programs written for non-multitasking systems directly access I/O ports. This practice may cause problems in a multitasking environment. If more than one program accesses the same port, they may interfere with each other. Most multi tasking systems require application programs to access I/O ports through the oper ating system. This results in simplified, centralized control.

  • The processor provides I/O protection for creating I/O that is compatible with the environment and transparent to 8086 programs. Designers may take any of several possible approaches to protecting I/O ports:
  • Protect the I/O address space and generate exceptions for all attempts to perform I/O directly.
  • Let the 8086 program perform I/O directly.
  • Generate exceptions on attempts to access specific I/O ports.
  • Generate exceptions on attempts to access specific memory-mapped I/O ports.

The method of controlling access to I/O ports depends upon whether they are I/O-port mapped or memory mapped.

17.2.8.1 I/O-Port-Mapped I/O

The I/O permission bit map in the TSS can be used to generate exceptions on attempts to access specific I/O port addresses. The I/O permission bit map of each virtual-8086-mode task determines which I/O addresses generate exceptions for that task. Because each task may have a different I/O permission bit map, the addresses that generate exceptions for one task may be different from the addresses

Page 734 of the Intel 253668-032US user manual — 17.3 INTERRUPT AND EXCEPTION HANDLING IN VIRTUAL-8086 MODE
Page 734 · click to enlarge
Page 734

8086 EMULATION

for another task. This differs from protected mode in which, if the CPL is less than or equal to the IOPL, I/O access is allowed without checking the I/O permission bit map. See Chapter 13, “Input/Output”, in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for more information about the I/O permission bit map.

17.2.8.2 Memory-Mapped I/O

  • In systems which use memory-mapped I/O, the paging facilities of the processor can be used to generate exceptions for attempts to access I/O ports. The virtual-8086 monitor may use paging to control memory-mapped I/O in these ways:
  • Map part of the linear address space of each task that needs to perform I/O to the physical address space where I/O ports are placed. By putting the I/O ports at different addresses (in different pages), the paging mechanism can enforce isolation between tasks.
  • Map part of the linear address space to pages that are not-present. This generates an exception whenever a task attempts to perform I/O to those pages. System software then can interpret the I/O operation being attempted.

Software emulation of the I/O space may require too much operating system inter vention under some conditions. In these cases, it may be possible to generate an exception for only the first attempt to access I/O. The system software then may determine whether a program can be given exclusive control of I/O temporarily, the protection of the I/O space may be lifted, and the program allowed to run at full speed.

17.2.8.3 Special I/O Buffers

Buffers of intelligent controllers (for example, a bit-mapped frame buffer) also can be emulated using page mapping. The linear space for the buffer can be mapped to a different physical space for each virtual-8086-mode task. The virtual-8086 monitor then can control which virtual buffer to copy onto the real buffer in the physical address space.

17.3 INTERRUPT AND EXCEPTION HANDLING IN VIRTUAL-8086 MODE

When the processor receives an interrupt or detects an exception condition while in virtual-8086 mode, it invokes an interrupt or exception handler, just as it does in protected or real-address mode. The interrupt or exception handler that is invoked and the mechanism used to invoke it depends on the class of interrupt or exception that has been detected or generated and the state of various system flags and fields.

Page 735 of the Intel 253668-032US user manual — NOTE
Page 735 · click to enlarge
Page 735

8086 EMULATION

  • In virtual-8086 mode, the interrupts and exceptions are divided into three classes for the purposes of handling:
  • Class 1 — All processor-generated exceptions and all hardware interrupts, including the NMI interrupt and the hardware interrupts sent to the processor’s external interrupt delivery pins. All class 1 exceptions and interrupts are handled by the protected-mode exception and interrupt handlers.
  • Class 2 — Special case for maskable hardware interrupts (Section 6.3.2, “Maskable Hardware Interrupts”) when the virtual mode extensions are enabled.
  • Class 3 — All software-generated interrupts, that is interrupts generated with the INT n instruction 1 .
  • The method the processor uses to handle class 2 and 3 interrupts depends on the setting of the following flags and fields:
  • IOPL field (bits 12 and 13 in the EFLAGS register) — Controls how class 3 software interrupts are handled when the processor is in virtual-8086 mode (see Section 2.3, “System Flags and Fields in the EFLAGS Register”). This field also controls the enabling of the VIF and VIP flags in the EFLAGS register when the VME flag is set. The VIF and VIP flags are provided to assist in the handling of class 2 maskable hardware interrupts.
  • VME flag (bit 0 in control register CR4) — Enables the virtual mode extension for the processor when set (see Section 2.5, “Control Registers”).
  • Software interrupt redirection bit map (32 bytes in the TSS, see Figure 17-5) — Contains 256 flags that indicates how class 3 software interrupts should be handled when they occur in virtual-8086 mode. A software interrupt can be directed either to the interrupt and exception handlers in the currently running 8086 program or to the protected-mode interrupt and exception handlers.
  • The virtual interrupt flag (VIF) and virtual interrupt pending flag (VIP) in the EFLAGS register — Provides virtual interrupt support for the handling of class 2 maskable hardware interrupts (see Section 17.3.2, “Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”).

NOTE

The VME flag, software interrupt redirection bit map, and VIF and VIP flags are only available in IA-32 processors that support the virtual mode extensions. These extensions were introduced in the IA-32 architecture with the Pentium processor.

The following sections describe the actions that processor takes and the possible actions of interrupt and exception handlers for the two classes of interrupts described

1. The INT 3 instruction is a special case (see the description of the INT n instruction in Chapter 3, “Instruction Set Reference, A-M”, of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A ).
Page 736 of the Intel 253668-032US user manual — 17.3.1 Class 1—Hardware Interrupt and Exception Handling in Virtual-8086 Mode
Page 736 · click to enlarge
Page 736

8086 EMULATION

  • in the previous paragraphs. These sections describe three possible types of interrupt and exception handlers:
  • Protected-mode interrupt and exceptions handlers — These are the standard handlers that the processor calls through the protected-mode IDT.
  • Virtual-8086 monitor interrupt and exception handlers — These handlers are resident in the virtual-8086 monitor, and they are commonly accessed through a general-protection exception (#GP, interrupt 13) that is directed to the protected-mode general-protection exception handler.
  • 8086 program interrupt and exception handlers — These handlers are part of the 8086 program that is running in virtual-8086 mode.

The following sections describe how these handlers are used, depending on the selected class and method of interrupt and exception handling.

17.3.1 Class 1—Hardware Interrupt and Exception Handling in Virtual-8086 Mode

In virtual-8086 mode, the Pentium, P6 family, Pentium 4, and Intel Xeon processors handle hardware interrupts and exceptions in the same manner as they are handled by the Intel486 and Intel386 processors. They invoke the protected-mode interrupt or exception handler that the interrupt or exception vector points to in the IDT. Here, the IDT entry must contain either a 32-bit trap or interrupt gate or a task gate. The following sections describe various ways that a virtual-8086 mode interrupt or excep tion can be handled after the protected-mode handler has been invoked.

See Section 17.3.2, “Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”, for a description of the virtual interrupt mechanism that is available for handling maskable hardware interrupts while in virtual-8086 mode. When this mechanism is either not available or not enabled, maskable hardware interrupts are handled in the same manner as exceptions, as described in the following sections.

17.3.1.1 Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gate

When an interrupt or exception vector points to a 32-bit trap or interrupt gate in the IDT, the gate must in turn point to a nonconforming, privilege-level 0, code segment. When accessing this code segment, processor performs the following steps.

1. Switches to 32-bit protected mode and privilege level 0.
2. Saves the state of the processor on the privilege-level 0 stack. The states of the EIP, CS, EFLAGS, ESP, SS, ES, DS, FS, and GS registers are saved (see Figure 17-4).
3. Clears the segment registers. Saving the DS, ES, FS, and GS registers on the stack and then clearing the registers lets the interrupt or exception handler safely
Page 737 of the Intel 253668-032US user manual — TSS
Page 737 · click to enlarge
Page 737

8086 EMULATION

save and restore these registers regardless of the type segment selectors they contain (protected-mode or 8086-style). The interrupt and exception handlers, which may be called in the context of either a protected-mode task or a virtual- 8086-mode task, can use the same code sequences for saving and restoring the registers for any task. Clearing these registers before execution of the IRET instruction does not cause a trap in the interrupt handler. Interrupt procedures that expect values in the segment registers or that return values in the segment registers must use the register images saved on the stack for privilege level 0.

4. Clears VM, NT, RF and TF flags (in the EFLAGS register). If the gate is an interrupt gate, clears the IF flag.
5. Begins executing the selected interrupt or exception handler.

If the trap or interrupt gate references a procedure in a conforming segment or in a segment at a privilege level other than 0, the processor generates a general-protec tion exception (#GP). Here, the error code is the segment selector of the code segment to which a call was attempted.

TSS

Old EIP New ESP

Error Code New ESP

Figure 17-4. Privilege Level 0 Stack After Interrupt or

Exception in Virtual-8086 Mode

Show 23 more labels / short text on this page
Without Error Code · With Error Code · ESP from · ESP from · TSS Unused · Unused · Old GS · Old GS · Old FS · Old FS · Old DS · Old DS · Old ES · Old ES · Old SS · Old SS · Old ESP · Old ESP · Old EFLAGS · Old EFLAGS · Old CS · Old CS · Old EIP
Page 738 of the Intel 253668-032US user manual — 8086 EMULATION
Page 738 · click to enlarge
Page 738

8086 EMULATION

  • Interrupt and exception handlers can examine the VM flag on the stack to determine if the interrupted procedure was running in virtual-8086 mode. If so, the interrupt or exception can be handled in one of three ways:
  • The protected-mode interrupt or exception handler that was called can handle the interrupt or exception.
  • The protected-mode interrupt or exception handler can call the virtual-8086 monitor to handle the interrupt or exception.
  • The virtual-8086 monitor (if called) can in turn pass control back to the 8086 program’s interrupt and exception handler.

If the interrupt or exception is handled with a protected-mode handler, the handler can return to the interrupted program in virtual-8086 mode by executing an IRET instruction. This instruction loads the EFLAGS and segment registers from the images saved in the privilege level 0 stack (see Figure 17-4). A set VM flag in the EFLAGS image causes the processor to switch back to virtual-8086 mode. The CPL at the time the IRET instruction is executed must be 0, otherwise the processor does not change the state of the VM flag.

The virtual-8086 monitor runs at privilege level 0, like the protected-mode interrupt and exception handlers. It is commonly closely tied to the protected-mode general- protection exception (#GP, vector 13) handler. If the protected-mode interrupt or exception handler calls the virtual-8086 monitor to handle the interrupt or exception, the return from the virtual-8086 monitor to the interrupted virtual-8086 mode program requires two return instructions: a RET instruction to return to the protected-mode handler and an IRET instruction to return to the interrupted program.

The virtual-8086 monitor has the option of directing the interrupt and exception back to an interrupt or exception handler that is part of the interrupted 8086 program, as described in Section 17.3.1.2, “Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handler”.

17.3.1.2 Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handler

Because it was designed to run on an 8086 processor, an 8086 program running in a virtual-8086-mode task contains an 8086-style interrupt vector table, which starts at linear address 0. If the virtual-8086 monitor correctly directs an interrupt or excep tion vector back to the virtual-8086-mode task it came from, the handlers in the 8086 program can handle the interrupt or exception. The virtual-8086 monitor must carry out the following steps to send an interrupt or exception back to the 8086 program:

1. Use the 8086 interrupt vector to locate the appropriate handler procedure in the 8086 program interrupt table.
Page 739 of the Intel 253668-032US user manual — 8086 EMULATION
Page 739 · click to enlarge
Page 739

8086 EMULATION

2. Store the EFLAGS (low-order 16 bits only), CS and EIP values of the 8086 program on the privilege-level 3 stack. This is the stack that the virtual-8086mode task is using. (The 8086 handler may use or modify this information.)
3. Change the return link on the privilege-level 0 stack to point to the privilege-level 3 handler procedure.
4. Execute an IRET instruction to pass control to the 8086 program handler.
5. When the IRET instruction from the privilege-level 3 handler triggers a generalprotection exception (#GP) and thus effectively again calls the virtual-8086 monitor, restore the return link on the privilege-level 0 stack to point to the original, interrupted, privilege-level 3 procedure.
6. Copy the low order 16 bits of the EFLAGS image from the privilege-level 3 stack to the privilege-level 0 stack (because some 8086 handlers modify these flags to return information to the code that caused the interrupt).
7. Execute an IRET instruction to pass control back to the interrupted 8086 program.

17.3.1.3 Handling an Interrupt or Exception Through a Task Gate

When an interrupt or exception vector points to a task gate in the IDT, the processor performs a task switch to the selected interrupt- or exception-handling task. The following actions are carried out as part of this task switch:

1. The EFLAGS register with the VM flag set is saved in the current TSS.
2. The link field in the TSS of the called task is loaded with the segment selector of the TSS for the interrupted virtual-8086-mode task.
3. The EFLAGS register is loaded from the image in the new TSS, which clears the VM flag and causes the processor to switch to protected mode.
4. The NT flag in the EFLAGS register is set.
5. The processor begins executing the selected interruptor exception-handler task.

When an IRET instruction is executed in the handler task and the NT flag in the EFLAGS register is set, the processors switches from a protected-mode interrupt- or exception-handler task back to a virtual-8086-mode task. Here, the EFLAGS and segment registers are loaded from images saved in the TSS for the virtual-8086- mode task. If the VM flag is set in the EFLAGS image, the processor switches back to virtual-8086 mode on the task switch. The CPL at the time the IRET instruction is

Page 740 of the Intel 253668-032US user manual — NOTE
Page 740 · click to enlarge
Page 740

8086 EMULATION

executed must be 0, otherwise the processor does not change the state of the VM flag.

17.3.2 Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism

Maskable hardware interrupts are those interrupts that are delivered through the INTR# pin or through an interrupt request to the local APIC (see Section 6.3.2, “Maskable Hardware Interrupts”). These interrupts can be inhibited (masked) from interrupting an executing program or task by clearing the IF flag in the EFLAGS register.

  • When the VME flag in control register CR4 is set and the IOPL field in the EFLAGS register is less than 3, two additional flags are activated in the EFLAGS register:
  • VIF (virtual interrupt) flag, bit 19 of the EFLAGS register.
  • VIP (virtual interrupt pending) flag, bit 20 of the EFLAGS register.

These flags provide the virtual-8086 monitor with more efficient control over handling maskable hardware interrupts that occur during virtual-8086 mode tasks. They also reduce interrupt-handling overhead, by eliminating the need for all IF related operations (such as PUSHF, POPF, CLI, and STI instructions) to trap to the virtual-8086 monitor. The purpose and use of these flags are as follows.

NOTE

The VIF and VIP flags are only available in IA-32 processors that support the virtual mode extensions. These extensions were introduced in the IA-32 architecture with the Pentium processor. When this mechanism is either not available or not enabled, maskable hardware interrupts are handled as class 1 interrupts. Here, if VIF and VIP flags are needed, the virtual-8086 monitor can implement them in software.

Existing 8086 programs commonly set and clear the IF flag in the EFLAGS register to enable and disable maskable hardware interrupts, respectively; for example, to disable interrupts while handling another interrupt or an exception. This practice works well in single task environments, but can cause problems in multitasking and multiple-processor environments, where it is often desirable to prevent an applica tion program from having direct control over the handling of hardware interrupts. When using earlier IA-32 processors, this problem was often solved by creating a virtual IF flag in software. The IA-32 processors (beginning with the Pentium processor) provide hardware support for this virtual IF flag through the VIF and VIP flags.

The VIF flag is a virtualized version of the IF flag, which an application program running from within a virtual-8086 task can used to control the handling of maskable hardware interrupts. When the VIF flag is enabled, the CLI and STI instructions operate on the VIF flag instead of the IF flag. When an 8086 program executes the

Page 741 of the Intel 253668-032US user manual — 8086 EMULATION
Page 741 · click to enlarge
Page 741

8086 EMULATION

CLI instruction, the processor clears the VIF flag to request that the virtual-8086 monitor inhibit maskable hardware interrupts from interrupting program execution; when it executes the STI instruction, the processor sets the VIF flag requesting that the virtual-8086 monitor enable maskable hardware interrupts for the 8086 program. But actually the IF flag, managed by the operating system, always controls whether maskable hardware interrupts are enabled. Also, if under these circum stances an 8086 program tries to read or change the IF flag using the PUSHF or POPF instructions, the processor will change the VIF flag instead, leaving IF unchanged.

The VIP flag provides software a means of recording the existence of a deferred (or pending) maskable hardware interrupt. This flag is read by the processor but never explicitly written by the processor; it can only be written by software.

If the IF flag is set and the VIF and VIP flags are enabled, and the processor receives a maskable hardware interrupt (interrupt vector 0 through 255), the processor performs and the interrupt handler software should perform the following operations:

1. The processor invokes the protected-mode interrupt handler for the interrupt received, as described in the following steps. These steps are almost identical to those described for method 1 interrupt and exception handling in Section 17.3.1.1, “Handling an Interrupt or Exception Through a Protected-Mode Trap or Interrupt Gate”:

a. Switches to 32-bit protected mode and privilege level 0.

b. Saves the state of the processor on the privilege-level 0 stack. The states of the EIP, CS, EFLAGS, ESP, SS, ES, DS, FS, and GS registers are saved (see Figure 17-4).

c. Clears the segment registers.

d. Clears the VM flag in the EFLAGS register.

e. Begins executing the selected protected-mode interrupt handler.

2. The recommended action of the protected-mode interrupt handler is to read the VM flag from the EFLAGS image on the stack. If this flag is set, the handler makes a call to the virtual-8086 monitor.
3. The virtual-8086 monitor should read the VIF flag in the EFLAGS register.

— If the VIF flag is clear, the virtual-8086 monitor sets the VIP flag in the EFLAGS image on the stack to indicate that there is a deferred interrupt pending and returns to the protected-mode handler.

— If the VIF flag is set, the virtual-8086 monitor can handle the interrupt if it “belongs” to the 8086 program running in the interrupted virtual-8086 task; otherwise, it can call the protected-mode interrupt handler to handle the interrupt.

4. The protected-mode handler executes a return to the program executing in virtual-8086 mode.
Page 742 of the Intel 253668-032US user manual — 17.3.3 Class 3—Software Interrupt Handling in Virtual-8086 Mode
Page 742 · click to enlarge
Page 742

8086 EMULATION

5. Upon returning to virtual-8086 mode, the processor continues execution of the 8086 program.
  • When the 8086 program is ready to receive maskable hardware interrupts, it executes the STI instruction to set the VIF flag (enabling maskable hardware interrupts). Prior to setting the VIF flag, the processor automatically checks the VIP flag and does one of the following, depending on the state of the flag:
  • If the VIP flag is clear (indicating no pending interrupts), the processor sets the VIF flag.
  • If the VIP flag is set (indicating a pending interrupt), the processor generates a general-protection exception (#GP).

The recommended action of the protected-mode general-protection exception handler is to then call the virtual-8086 monitor and let it handle the pending inter rupt. After handling the pending interrupt, the typical action of the virtual-8086 monitor is to clear the VIP flag and set the VIF flag in the EFLAGS image on the stack, and then execute a return to the virtual-8086 mode. The next time the processor receives a maskable hardware interrupt, it will then handle it as described in steps 1 through 5 earlier in this section.

If the processor finds that both the VIF and VIP flags are set at the beginning of an instruction, it generates a general-protection exception. This action allows the virtual-8086 monitor to handle the pending interrupt for the virtual-8086 mode task for which the VIF flag is enabled. Note that this situation can only occur immediately following execution of a POPF or IRET instruction or upon entering a virtual-8086 mode task through a task switch.

NOTE

The virtual interrupt mechanism described in this section is also available for use in protected mode, see Section 17.4, “Protected- Mode Virtual Interrupts”.

17.3.3 Class 3—Software Interrupt Handling in Virtual-8086 Mode

When the processor receives a software interrupt (an interrupt generated with the INT n instruction) while in virtual-8086 mode, it can use any of six different methods to handle the interrupt. The method selected depends on the settings of the VME flag in control register CR4, the IOPL field in the EFLAGS register, and the software inter rupt redirection bit map in the TSS. Table 17-2 lists the six methods of handling soft ware interrupts in virtual-8086 mode and the respective settings of the VME flag, IOPL field, and the bits in the interrupt redirection bit map for each method. The table also summarizes the various actions the processor takes for each method.

The VME flag enables the virtual mode extensions for the Pentium and later IA-32 processors. When this flag is clear, the processor responds to interrupts and excep

Page 743 of the Intel 253668-032US user manual — NOTE
Page 743 · click to enlarge
Page 743

8086 EMULATION

  • tions in virtual-8086 mode in the same manner as an Intel386 or Intel486 processor does. When this flag is set, the virtual mode extension provides the following enhancements to virtual-8086 mode:
  • Speeds up the handling of software-generated interrupts in virtual-8086 mode by allowing the processor to bypass the virtual-8086 monitor and redirect software interrupts back to the interrupt handlers that are part of the currently running 8086 program.
  • Supports virtual interrupts for software written to run on the 8086 processor.

The IOPL value interacts with the VME flag and the bits in the interrupt redirection bit map to determine how specific software interrupts should be handled.

The software interrupt redirection bit map (see Figure 17-5) is a 32-byte field in the TSS. This map is located directly below the I/O permission bit map in the TSS. Each bit in the interrupt redirection bit map is mapped to an interrupt vector. Bit 0 in the interrupt redirection bit map (which maps to vector zero in the interrupt table) is located at the I/O base map address in the TSS minus 32 bytes. When a bit in this bit map is set, it indicates that the associated software interrupt (interrupt generated with an INT n instruction) should be handled through the protected-mode IDT and interrupt and exception handlers. When a bit in this bit map is clear, the processor redirects the associated software interrupt back to the interrupt table in the 8086 program (located at linear address 0 in the program’s address space).

NOTE

The software interrupt redirection bit map does not affect hardware generated interrupts and exceptions. Hardware generated interrupts and exceptions are always handled by the protected-mode interrupt and exception handlers.

Page 744 of the Intel 253668-032US user manual — 8086 EMULATION
Page 744 · click to enlarge
Page 744

8086 EMULATION

Table 17-2. Software Interrupt Handling Methods While in Virtual-8086 Mode

Bit in Redir. Bitmap* Processor Action

1 0 3 X Interrupt directed to a protected-mode interrupt handler:

  • Switches to privilege-level 0 stack
  • Pushes GS, FS, DS and ES onto privilege-level 0 stack
  • Pushes SS, ESP, EFLAGS, CS and EIP of interrupted task onto privilege-level 0 stack
  • Clears VM, RF, NT, and TF flags
  • If serviced through interrupt gate, clears IF flag
  • Clears GS, FS, DS and ES to 0
  • Sets CS and EIP from interrupt gate

2 0 < 3 X Interrupt directed to protected-mode general-protection exception (#GP) handler.

3 1 < 3 1 Interrupt directed to a protected-mode general-protection exception (#GP) handler; VIF and VIP flag support for handling class 2 maskable hardware interrupts.

4 1 3 1 Interrupt directed to protected-mode interrupt handler: (see method 1 processor action).

5 1 3 0 Interrupt redirected to 8086 program interrupt handler:

  • Pushes EFLAGS
  • Pushes CS and EIP (lower 16 bits only)
  • Clears IF flag
  • Clears TF flag
  • Loads CS and EIP (lower 16 bits only) from selected entry in the interrupt vector table of the current virtual-8086 task

6 1 < 3 0 Interrupt redirected to 8086 program interrupt handler; VIF and VIP flag support for handling class 2 maskable hardware interrupts:

  • Pushes EFLAGS with IOPL set to 3 and VIF copied to IF
  • Pushes CS and EIP (lower 16 bits only)
  • Clears the VIF flag
  • Clears TF flag
  • Loads CS and EIP (lower 16 bits only) from selected entry in the interrupt vector table of the current virtual-8086 task

Method VME IOPL

Page 745 of the Intel 253668-032US user manual — 64H
Page 745 · click to enlarge
Page 745

8086 EMULATION

31 24 23 0 1

Last byte of bit

I/O Permission Bit Map

Software Interrupt Redirection Bit Map (32 Bytes)

64H

I/O map base must not exceed DFFFH.

Figure 17-5. Software Interrupt Redirection Bit Map in TSS

Redirecting software interrupts back to the 8086 program potentially speeds up interrupt handling because a switch back and forth between virtual-8086 mode and protected mode is not required. This latter interrupt-handling technique is particu larly useful for 8086 operating systems (such as MS-DOS) that use the INT n instruc tion to call operating system procedures.

The CPUID instruction can be used to verify that the virtual mode extension is imple mented on the processor. Bit 1 of the feature flags register (EDX) indicates the avail ability of the virtual mode extension (see “CPUID—CPU Identification” in Chapter 3, “Instruction Set Reference, A-M”, of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A).

The following sections describe the six methods (or mechanisms) for handling soft ware interrupts in virtual-8086 mode. See Section 17.3.2, “Class 2—Maskable Hard ware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”, for a description of the use of the VIF and VIP flags in the EFLAGS register for handling maskable hardware interrupts.

17.3.3.1 Method 1Software Interrupt Handling

When the VME flag in control register CR4 is clear and the IOPL field is 3, a Pentium or later IA-32 processor handles software interrupts in the same manner as they are handled by an Intel386 or Intel486 processor. It executes an implicit call to the inter

Task-State Segment (TSS) · map must be · I/O Map Base

Page 746 of the Intel 253668-032US user manual — 8086 EMULATION
Page 746 · click to enlarge
Page 746

8086 EMULATION

rupt handler in the protected-mode IDT pointed to by the interrupt vector. See Section 17.3.1, “Class 1—Hardware Interrupt and Exception Handling in Virtual-8086 Mode”, for a complete description of this mechanism and its possible uses.

17.3.3.2 Methods 2 and 3Software Interrupt Handling

When a software interrupt occurs in virtual-8086 mode and the method 2 or 3 condi tions are present, the processor generates a general-protection exception (#GP). Method 2 is enabled when the VME flag is set to 0 and the IOPL value is less than 3. Here the IOPL value is used to bypass the protected-mode interrupt handlers and cause any software interrupt that occurs in virtual-8086 mode to be treated as a protected-mode general-protection exception (#GP). The general-protection excep tion handler calls the virtual-8086 monitor, which can then emulate an 8086- program interrupt handler or pass control back to the 8086 program’s handler, as described in Section 17.3.1.2, “Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handler”.

Method 3 is enabled when the VME flag is set to 1, the IOPL value is less than 3, and the corresponding bit for the software interrupt in the software interrupt redirection bit map is set to 1. Here, the processor performs the same operation as it does for method 2 software interrupt handling. If the corresponding bit for the software inter rupt in the software interrupt redirection bit map is set to 0, the interrupt is handled using method 6 (see Section 17.3.3.5, “Method 6: Software Interrupt Handling”).

17.3.3.3 Method 4Software Interrupt Handling

Method 4 handling is enabled when the VME flag is set to 1, the IOPL value is 3, and the bit for the interrupt vector in the redirection bit map is set to 1. Method 4 soft ware interrupt handling allows method 1 style handling when the virtual mode exten sion is enabled; that is, the interrupt is directed to a protected-mode handler (see Section 17.3.3.1, “Method 1: Software Interrupt Handling”).

17.3.3.4 Method 5Software Interrupt Handling

Method 5 software interrupt handling provides a streamlined method of redirecting software interrupts (invoked with the INT n instruction) that occur in virtual 8086 mode back to the 8086 program’s interrupt vector table and its interrupt handlers. Method 5 handling is enabled when the VME flag is set to 1, the IOPL value is 3, and the bit for the interrupt vector in the redirection bit map is set to 0. The processor performs the following actions to make an implicit call to the selected 8086 program interrupt handler:

1. Pushes the low-order 16 bits of the EFLAGS register onto the stack.
2. Pushes the current values of the CS and EIP registers onto the current stack. (Only the 16 least-significant bits of the EIP register are pushed and no stack switch occurs.)
Page 747 of the Intel 253668-032US user manual — NOTE
Page 747 · click to enlarge
Page 747

8086 EMULATION

3. Clears the IF flag in the EFLAGS register to disable interrupts.
4. Clears the TF flag, in the EFLAGS register.
5. Locates the 8086 program interrupt vector table at linear address 0 for the 8086mode task.
6. Loads the CS and EIP registers with values from the interrupt vector table entry pointed to by the interrupt vector number. Only the 16 low-order bits of the EIP are loaded and the 16 high-order bits are set to 0. The interrupt vector table is assumed to be at linear address 0 of the current virtual-8086 task.
7. Begins executing the selected interrupt handler.

An IRET instruction at the end of the handler procedure reverses these steps to return program control to the interrupted 8086 program.

The method 5 handling actions are virtually identical to the actions the processor takes when handling software interrupts in real-address mode. The benefit of using method 5 handling to access the 8086 program handlers is that it avoids the over head of methods 2 and 3 handling, which requires first going to the virtual-8086 monitor, then to the 8086 program handler, then back again to the virtual-8086 monitor, before returning to the interrupted 8086 program (see Section 17.3.1.2, “Handling an Interrupt or Exception With an 8086 Program Interrupt or Exception Handler”).

NOTE

Methods 1 and 4 handling can handle a software interrupt in a virtual- 8086 task with a regular protected-mode handler, but this approach requires all virtual-8086 tasks to use the same software interrupt handlers, which generally does not give sufficient latitude to the programs running in the virtual-8086 tasks, particularly MS-DOS programs.

17.3.3.5 Method 6Software Interrupt Handling

Method 6 handling is enabled when the VME flag is set to 1, the IOPL value is less than 3, and the bit for the interrupt or exception vector in the redirection bit map is set to 0. With method 6 interrupt handling, software interrupts are handled in the same manner as was described for method 5 handling (see Section 17.3.3.4, “Method 5: Software Interrupt Handling”).

Method 6 differs from method 5 in that with the IOPL value set to less than 3, the VIF and VIP flags in the EFLAGS register are enabled, providing virtual interrupt support for handling class 2 maskable hardware interrupts (see Section 17.3.2, “Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”). These flags provide the virtual-8086 monitor with an effi

Page 748 of the Intel 253668-032US user manual — 17.4 PROTECTED-MODE VIRTUAL INTERRUPTS
Page 748 · click to enlarge
Page 748

8086 EMULATION

cient means of handling maskable hardware interrupts that occur during a virtual- 8086 mode task. Also, because the IOPL value is less than 3 and the VIF flag is enabled, the information pushed on the stack by the processor when invoking the interrupt handler is slightly different between methods 5 and 6 (see Table 17-2).

17.4 PROTECTED-MODE VIRTUAL INTERRUPTS

The IA-32 processors (beginning with the Pentium processor) also support the VIF and VIP flags in the EFLAGS register in protected mode by setting the PVI (protected- mode virtual interrupt) flag in the CR4 register. Setting the PVI flag allows applica tions running at privilege level 3 to execute the CLI and STI instructions without causing a general-protection exception (#GP) or affecting hardware interrupts.

When the PVI flag is set to 1, the CPL is 3, and the IOPL is less than 3, the STI and CLI instructions set and clear the VIF flag in the EFLAGS register, leaving IF unaf fected. In this mode of operation, an application running in protected mode and at a CPL of 3 can inhibit interrupts in the same manner as is described in Section 17.3.2, “Class 2—Maskable Hardware Interrupt Handling in Virtual-8086 Mode Using the Virtual Interrupt Mechanism”, for a virtual-8086 mode task. When the application executes the CLI instruction, the processor clears the VIF flag. If the processor receives a maskable hardware interrupt, the processor invokes the protected-mode interrupt handler. This handler checks the state of the VIF flag in the EFLAGS register. If the VIF flag is clear (indicating that the active task does not want to have interrupts handled now), the handler sets the VIP flag in the EFLAGS image on the stack and returns to the privilege-level 3 application, which continues program execution. When the application executes a STI instruction to set the VIF flag, the processor automatically invokes the general-protection exception handler, which can then handle the pending interrupt. After handing the pending interrupt, the handler typi cally sets the VIF flag and clears the VIP flag in the EFLAGS image on the stack and executes a return to the application program. The next time the processor receives a maskable hardware interrupt, the processor will handle it in the normal manner for interrupts received while the processor is operating at a CPL of 3.

As with the virtual mode extension (enabled with the VME flag in the CR4 register), the protected-mode virtual interrupt extension only affects maskable hardware interrupts (interrupt vectors 32 through 255). NMI interrupts and exceptions are handled in the normal manner.

When protected-mode virtual interrupts are disabled (that is, when the PVI flag in control register CR4 is set to 0, the CPL is less than 3, or the IOPL value is 3), then the CLI and STI instructions execute in a manner compatible with the Intel486 processor. That is, if the CPL is greater (less privileged) than the I/O privilege level (IOPL), a general-protection exception occurs. If the IOPL value is 3, CLI and STI clear or set the IF flag, respectively.

PUSHF, POPF, IRET and INT are executed like in the Intel486 processor, regardless of whether protected-mode virtual interrupts are enabled.

Page 749 of the Intel 253668-032US user manual — 8086 EMULATION
Page 749 · click to enlarge
Page 749

8086 EMULATION

It is only possible to enter virtual-8086 mode through a task switch or the execution of an IRET instruction, and it is only possible to leave virtual-8086 mode by faulting to a protected-mode interrupt handler (typically the general-protection exception handler, which in turn calls the virtual 8086-mode monitor). In both cases, the EFLAGS register is saved and restored. This is not true, however, in protected mode when the PVI flag is set and the processor is not in virtual-8086 mode. Here, it is possible to call a procedure at a different privilege level, in which case the EFLAGS register is not saved or modified. However, the states of VIF and VIP flags are never examined by the processor when the CPL is not 3.

Page 750 of the Intel 253668-032US user manual — 8086 EMULATION
Page 750 · click to enlarge
Page 750

8086 EMULATION

Page 751 of the Intel 253668-032US user manual — CHAPTER 18 MIXING 16-BIT AND 32-BIT CODE
Page 751 · click to enlarge
Page 751

CHAPTER 18 MIXING 16-BIT AND 32-BIT CODE

Program modules written to run on IA-32 processors can be either 16-bit modules or 32-bit modules. Table 18-1 shows the characteristic of 16-bit and 32-bit modules.

Table 18-1. Characteristics of 16-Bit and 32-Bit Program Modules

Characteristic 16-Bit Program Modules 32-Bit Program Modules

Segment Size 0 to 64 KBytes 0 to 4 GBytes

Operand Sizes 8 bits and 16 bits 8 bits and 32 bits

Pointer Offset Size (Address Size)

16 bits 32 bits

Stack Pointer Size 16 Bits 32 Bits

Control Transfers Allowed to Code Segments of This Size

16 Bits 32 Bits

  • The IA-32 processors function most efficiently when executing 32-bit program modules. They can, however, also execute 16-bit program modules, in any of the following ways:
  • In real-address mode.
  • In virtual-8086 mode.
  • System management mode (SMM).
  • As a protected-mode task, when the code, data, and stack segments for the task are all configured as a 16-bit segments.
  • By integrating 16-bit and 32-bit segments into a single protected-mode task.
  • By integrating 16-bit operations into 32-bit code segments.

Real-address mode, virtual-8086 mode, and SMM are native 16-bit modes. A legacy program assembled and/or compiled to run on an Intel 8086 or Intel 286 processor should run in real-address mode or virtual-8086 mode without modification. Sixteen- bit program modules can also be written to run in real-address mode for handling system initialization or to run in SMM for handling system management functions. See Chapter 17, “8086 Emulation,” for detailed information on real-address mode and virtual-8086 mode; see Chapter 26, “System Management Mode,” for informa tion on SMM.

This chapter describes how to integrate 16-bit program modules with 32-bit program modules when operating in protected mode and how to mix 16-bit and 32-bit code within 32-bit code segments.

Page 752 of the Intel 253668-032US user manual — 18.2 MIXING 16-BIT AND 32-BIT OPERATIONS WITHIN A CODE SEGMENT
Page 752 · click to enlarge
Page 752

MIXING 16-BIT AND 32-BIT CODE

18.1 DEFINING 16-BIT AND 32-BIT PROGRAM MODULES

  • The following IA-32 architecture mechanisms are used to distinguish between and support 16-bit and 32-bit segments and operations:
  • The D (default operand and address size) flag in code-segment descriptors.
  • The B (default stack size) flag in stack-segment descriptors.
  • 16-bit and 32-bit call gates, interrupt gates, and trap gates.
  • Operand-size and address-size instruction prefixes.
  • 16-bit and 32-bit general-purpose registers.

The D flag in a code-segment descriptor determines the default operand-size and address-size for the instructions of a code segment. (In real-address mode and virtual-8086 mode, which do not use segment descriptors, the default is 16 bits.) A code segment with its D flag set is a 32-bit segment; a code segment with its D flag clear is a 16-bit segment.

The B flag in the stack-segment descriptor specifies the size of stack pointer (the 32-bit ESP register or the 16-bit SP register) used by the processor for implicit stack references. The B flag for all data descriptors also controls upper address range for expand down segments.

When transferring program control to another code segment through a call gate, interrupt gate, or trap gate, the operand size used during the transfer is determined by the type of gate used (16-bit or 32-bit), (not by the D-flag or prefix of the transfer instruction). The gate type determines how return information is saved on the stack (or stacks).

For most efficient and trouble-free operation of the processor, 32-bit programs or tasks should have the D flag in the code-segment descriptor and the B flag in the stack-segment descriptor set, and 16-bit programs or tasks should have these flags clear. Program control transfers from 16-bit segments to 32-bit segments (and vice versa) are handled most efficiently through call, interrupt, or trap gates.

Instruction prefixes can be used to override the default operand size and address size of a code segment. These prefixes can be used in real-address mode as well as in protected mode and virtual-8086 mode. An operand-size or address-size prefix only changes the size for the duration of the instruction.

18.2 MIXING 16-BIT AND 32-BIT OPERATIONS WITHIN A CODE SEGMENT

  • The following two instruction prefixes allow mixing of 32-bit and 16-bit operations within one segment:
  • The operand-size prefix (66H)
  • The address-size prefix (67H)
Page 753 of the Intel 253668-032US user manual — MIXING 16-BIT AND 32-BIT CODE
Page 753 · click to enlarge
Page 753

MIXING 16-BIT AND 32-BIT CODE

These prefixes reverse the default size selected by the D flag in the code-segment descriptor. For example, the processor can interpret the (MOV mem, reg) instruction in any of four ways: • In a 32-bit code segment:

— Moves 32 bits from a 32-bit register to memory using a 32-bit effective address.

— If preceded by an operand-size prefix, moves 16 bits from a 16-bit register to memory using a 32-bit effective address.

— If preceded by an address-size prefix, moves 32 bits from a 32-bit register to memory using a 16-bit effective address.

— If preceded by both an address-size prefix and an operand-size prefix, moves 16 bits from a 16-bit register to memory using a 16-bit effective address. • In a 16-bit code segment:

— Moves 16 bits from a 16-bit register to memory using a 16-bit effective address.

— If preceded by an operand-size prefix, moves 32 bits from a 32-bit register to memory using a 16-bit effective address.

— If preceded by an address-size prefix, moves 16 bits from a 16-bit register to memory using a 32-bit effective address.

— If preceded by both an address-size prefix and an operand-size prefix, moves 32 bits from a 32-bit register to memory using a 32-bit effective address.

  • The previous examples show that any instruction can generate any combination of operand size and address size regardless of whether the instruction is in a 16or 32-bit segment. The choice of the 16or 32-bit default for a code segment is normally based on the following criteria:
  • Performance — Always use 32-bit code segments when possible. They run much faster than 16-bit code segments on P6 family processors, and somewhat faster on earlier IA-32 processors.
  • The operating system the code segment will be running on — If the operating system is a 16-bit operating system, it may not support 32-bit program modules.
  • Mode of operation — If the code segment is being designed to run in realaddress mode, virtual-8086 mode, or SMM, it must be a 16-bit code segment.
  • Backward compatibility to earlier IA-32 processors — If a code segment must be able to run on an Intel 8086 or Intel 286 processor, it must be a 16-bit code segment.
Page 754 of the Intel 253668-032US user manual — 18.4 TRANSFERRING CONTROL AMONG MIXED-SIZE CODE SEGMENTS
Page 754 · click to enlarge
Page 754

MIXING 16-BIT AND 32-BIT CODE

18.3 SHARING DATA AMONG MIXED-SIZE CODE SEGMENTS

Data segments can be accessed from both 16-bit and 32-bit code segments. When a data segment that is larger than 64 KBytes is to be shared among 16- and 32-bit code segments, the data that is to be accessed from the 16-bit code segments must be located within the first 64 KBytes of the data segment. The reason for this is that 16-bit pointers by definition can only point to the first 64 KBytes of a segment.

  • A stack that spans less than 64 KBytes can be shared by both 16and 32-bit code segments. This class of stacks includes:
  • Stacks in expand-up segments with the G (granularity) and B (big) flags in the stack-segment descriptor clear.
  • Stacks in expand-down segments with the G and B flags clear.
  • Stacks in expand-up segments with the G flag set and the B flag clear and where the stack is contained completely within the lower 64 KBytes. (Offsets greater than FFFFH can be used for data, other than the stack, which is not shared.)

See Section 3.4.5, “Segment Descriptors,” for a description of the G and B flags and the expand-down stack type.

The B flag cannot, in general, be used to change the size of stack used by a 16-bit code segment. This flag controls the size of the stack pointer only for implicit stack references such as those caused by interrupts, exceptions, and the PUSH, POP, CALL, and RET instructions. It does not control explicit stack references, such as accesses to parameters or local variables. A 16-bit code segment can use a 32-bit stack only if the code is modified so that all explicit references to the stack are preceded by the 32-bit address-size prefix, causing those references to use 32-bit addressing and explicit writes to the stack pointer are preceded by a 32-bit operand-size prefix.

In 32-bit, expand-down segments, all offsets may be greater than 64 KBytes; there fore, 16-bit code cannot use this kind of stack segment unless the code segment is modified to use 32-bit addressing.

18.4 TRANSFERRING CONTROL AMONG MIXED-SIZE CODE SEGMENTS

  • There are three ways for a procedure in a 16-bit code segment to safely make a call to a 32-bit code segment:
  • Make the call through a 32-bit call gate.
  • Make a 16-bit call to a 32-bit interface procedure. The interface procedure then makes a 32-bit call to the intended destination.
  • Modify the 16-bit procedure, inserting an operand-size prefix before the call, to change it to a 32-bit call.
Page 755 of the Intel 253668-032US user manual — 18.4.2 Stack Management for Control Transfer
Page 755 · click to enlarge
Page 755

MIXING 16-BIT AND 32-BIT CODE

  • Likewise, there are three ways for procedure in a 32-bit code segment to safely make a call to a 16-bit code segment:
  • Make the call through a 16-bit call gate. Here, the EIP value at the CALL instruction cannot exceed FFFFH.
  • Make a 32-bit call to a 16-bit interface procedure. The interface procedure then makes a 16-bit call to the intended destination.
  • Modify the 32-bit procedure, inserting an operand-size prefix before the call, changing it to a 16-bit call. Be certain that the return offset does not exceed FFFFH.
  • These methods of transferring program control overcome the following architectural limitations imposed on calls between 16-bit and 32-bit code segments:
  • Pointers from 16-bit code segments (which by default can only be 16 bits) cannot be used to address data or code located beyond FFFFH in a 32-bit segment.
  • The operand-size attributes for a CALL and its companion RETURN instruction must be the same to maintain stack coherency. This is also true for implicit calls to interrupt and exception handlers and their companion IRET instructions.
  • A 32-bit parameters (particularly a pointer parameter) greater than FFFFH cannot be squeezed into a 16-bit parameter location on a stack.
  • The size of the stack pointer (SP or ESP) changes when switching between 16-bit and 32-bit code segments.

These limitations are discussed in greater detail in the following sections.

18.4.1 Code-Segment Pointer Size

  • For control-transfer instructions that use a pointer to identify the next instruction (that is, those that do not use gates), the operand-size attribute determines the size of the offset portion of the pointer. The implications of this rule are as follows:
  • A JMP, CALL, or RET instruction from a 32-bit segment to a 16-bit segment is always possible using a 32-bit operand size, providing the 32-bit pointer does not exceed FFFFH.
  • A JMP, CALL, or RET instruction from a 16-bit segment to a 32-bit segment cannot address a destination greater than FFFFH, unless the instruction is given an operand-size prefix.

See Section 18.4.5, “Writing Interface Procedures,” for an interface procedure that can transfer program control from 16-bit segments to destinations in 32-bit segments beyond FFFFH.

18.4.2 Stack Management for Control Transfer

Because the stack is managed differently for 16-bit procedure calls than for 32-bit calls, the operand-size attribute of the RET instruction must match that of the CALL

Page 756 of the Intel 253668-032US user manual — MIXING 16-BIT AND 32-BIT CODE
Page 756 · click to enlarge
Page 756

MIXING 16-BIT AND 32-BIT CODE

instruction (see Figure 18-1). On a 16-bit call, the processor pushes the contents of the 16-bit IP register and (for calls between privilege levels) the 16-bit SP register. The matching RET instruction must also use a 16-bit operand size to pop these 16-bit values from the stack into the 16-bit registers.

A 32-bit CALL instruction pushes the contents of the 32-bit EIP register and (for inter-privilege-level calls) the 32-bit ESP register. Here, the matching RET instruction must use a 32-bit operand size to pop these 32-bit values from the stack into the 32-bit registers. If the two parts of a CALL/RET instruction pair do not have matching operand sizes, the stack will not be managed correctly and the values of the instruc tion pointer and stack pointer will not be restored to correct values.

Intel 253668-032US — MIXING 16-BIT AND 32-BIT CODE diagram (page 756)
Fig. 38

Figure 18-1. Stack after Far 16- and 32-Bit Calls

Page 757 of the Intel 253668-032US user manual — MIXING 16-BIT AND 32-BIT CODE
Page 757 · click to enlarge
Page 757

MIXING 16-BIT AND 32-BIT CODE

While executing 32-bit code, if a call is made to a 16-bit code segment which is at the same or a more privileged level (that is, the DPL of the called code segment is less than or equal to the CPL of the calling code segment) through a 16-bit call gate, then the upper 16-bits of the ESP register may be unreliable upon returning to the 32-bit code segment (that is, after executing a RET in the 16-bit code segment).

When the CALL instruction and its matching RET instruction are in code segments that have D flags with the same values (that is, both are 32-bit code segments or both are 16-bit code segments), the default settings may be used. When the CALL instruction and its matching RET instruction are in segments which have different D-flag settings, an operand-size prefix must be used.

18.4.2.1 Controlling the Operand-Size Attribute For a Call

  • Three things can determine the operand-size of a call:
  • The D flag in the segment descriptor for the calling code segment.
  • An operand-size instruction prefix.
  • The type of call gate (16-bit or 32-bit), if a call is made through a call gate.

When a call is made with a pointer (rather than a call gate), the D flag for the calling code segment determines the operand-size for the CALL instruction. This operand- size attribute can be overridden by prepending an operand-size prefix to the CALL instruction. So, for example, if the D flag for a code segment is set for 16 bits and the operand-size prefix is used with a CALL instruction, the processor will cause the infor mation stored on the stack to be stored in 32-bit format. If the call is to a 32-bit code segment, the instructions in that code segment will be able to read the stack coher ently. Also, a RET instruction from the 32-bit code segment without an operand-size prefix will maintain stack coherency with the 16-bit code segment being returned to.

When a CALL instruction references a call-gate descriptor, the type of call is deter mined by the type of call gate (16-bit or 32-bit). The offset to the destination in the code segment being called is taken from the gate descriptor; therefore, if a 32-bit call gate is used, a procedure in a 16-bit code segment can call a procedure located more than 64 KBytes from the base of a 32-bit code segment, because a 32-bit call gate uses a 32-bit offset.

An unmodified 16-bit code segment that has run successfully on an 8086 processor or in real-mode on a later IA-32 architecture processor will have its D flag clear and will not use operand-size override prefixes. As a result, all CALL instructions in this code segment will use the 16-bit operand-size attribute. Procedures in these code

Page 758 of the Intel 253668-032US user manual — 18.4.4 Parameter Translation
Page 758 · click to enlarge
Page 758

MIXING 16-BIT AND 32-BIT CODE

  • segments can be modified to safely call procedures to 32-bit code segments in either of two ways:
  • Relink the CALL instruction to point to 32-bit call gates (see Section 18.4.2.2, “Passing Parameters With a Gate”).
  • Add a 32-bit operand-size prefix to each CALL instruction.

18.4.2.2 Passing Parameters With a Gate

When referencing 32-bit gates with 16-bit procedures, it is important to consider the number of parameters passed in each procedure call. The count field of the gate descriptor specifies the size of the parameter string to copy from the current stack to the stack of a more privileged (numerically lower privilege level) procedure. The count field of a 16-bit gate specifies the number of 16-bit words to be copied, whereas the count field of a 32-bit gate specifies the number of 32-bit doublewords to be copied. The count field for a 32-bit gate must thus be half the size of the number of words being placed on the stack by a 16-bit procedure. Also, the 16-bit procedure must use an even number of words as parameters.

18.4.3 Interrupt Control Transfers

A program-control transfer caused by an exception or interrupt is always carried out through an interrupt or trap gate (located in the IDT). Here, the type of the gate (16-bit or 32-bit) determines the operand-size attribute used in the implicit call to the exception or interrupt handler procedure in another code segment.

A 32-bit interrupt or trap gate provides a safe interface to a 32-bit exception or inter rupt handler when the exception or interrupt occurs in either a 32-bit or a 16-bit code segment. It is sometimes impractical, however, to place exception or interrupt handlers in 16-bit code segments, because only 16-bit return addresses are saved on the stack. If an exception or interrupt occurs in a 32-bit code segment when the EIP was greater than FFFFH, the 16-bit handler procedure cannot provide the correct return address.

18.4.4 Parameter Translation

When segment offsets or pointers (which contain segment offsets) are passed as parameters between 16-bit and 32-bit procedures, some translation is required. If a 32-bit procedure passes a pointer to data located beyond 64 KBytes to a 16-bit procedure, the 16-bit procedure cannot use it. Except for this limitation, interface code can perform any format conversion between 32-bit and 16-bit pointers that may be needed.

Parameters passed by value between 32-bit and 16-bit code also may require trans lation between 32-bit and 16-bit formats. The form of the translation is application- dependent.

Page 759 of the Intel 253668-032US user manual — MIXING 16-BIT AND 32-BIT CODE
Page 759 · click to enlarge
Page 759

MIXING 16-BIT AND 32-BIT CODE

18.4.5 Writing Interface Procedures

  • Placing interface code between 32-bit and 16-bit procedures can be the solution to the following interface problems:
  • Allowing procedures in 16-bit code segments to call procedures with offsets greater than FFFFH in 32-bit code segments.
  • Matching operand-size attributes between companion CALL and RET instructions.
  • Translating parameters (data), including managing parameter strings with a variable count or an odd number of 16-bit words.
  • The possible invalidation of the upper bits of the ESP register.

The interface procedure is simplified where these rules are followed.

1. The interface procedure must reside in a 32-bit code segment (the D flag for the code-segment descriptor is set).
2. All procedures that may be called by 16-bit procedures must have offsets not greater than FFFFH.
3. All return addresses saved by 16-bit procedures must have offsets not greater than FFFFH.

The interface procedure becomes more complex if any of these rules are violated. For example, if a 16-bit procedure calls a 32-bit procedure with an entry point beyond FFFFH, the interface procedure will need to provide the offset to the entry point. The mapping between 16- and 32-bit addresses is only performed automatically when a call gate is used, because the gate descriptor for a call gate contains a 32-bit address. When a call gate is not used, the interface code must provide the 32-bit address.

  • The structure of the interface procedure depends on the types of calls it is going to support, as follows:
  • Calls from 16-bit procedures to 32-bit procedures — Calls to the interface procedure from a 16-bit code segment are made with 16-bit CALL instructions (by default, because the D flag for the calling code-segment descriptor is clear), and 16-bit operand-size prefixes are used with RET instructions to return from the interface procedure to the calling procedure. Calls from the interface procedure to 32-bit procedures are performed with 32-bit CALL instructions (by default, because the D flag for the interface procedure’s code segment is set), and returns from the called procedures to the interface procedure are performed with 32-bit RET instructions (also by default).
  • Calls from 32-bit procedures to 16-bit procedures — Calls to the interface procedure from a 32-bit code segment are made with 32-bit CALL instructions (by default), and returns to the calling procedure from the interface procedure are made with 32-bit RET instructions (also by default). Calls from the interface procedure to 16-bit procedures require the CALL instructions to have the operand-size prefixes, and returns from the called procedures to the interface procedure are performed with 16-bit RET instructions (by default).
Page 760 of the Intel 253668-032US user manual — MIXING 16-BIT AND 32-BIT CODE
Page 760 · click to enlarge
Page 760

MIXING 16-BIT AND 32-BIT CODE

Page 761 of the Intel 253668-032US user manual — 19.1 PROCESSOR FAMILIES AND CATEGORIES
Page 761 · click to enlarge
Page 761

CHAPTER 19 ARCHITECTURE COMPATIBILITY

Intel 64 and IA-32 processors are binary compatible. Compatibility means that, within limited constraints, programs that execute on previous generations of proces sors will produce identical results when executed on later processors. The compati bility constraints and any implementation differences between the Intel 64 and IA-32 processors are described in this chapter.

Each new processor has enhanced the software visible architecture from that found in earlier Intel 64 and IA-32 processors. Those enhancements have been defined with consideration for compatibility with previous and future processors. This chapter also summarizes the compatibility considerations for those extensions.

19.1 PROCESSOR FAMILIES AND CATEGORIES

  • IA-32 processors are referred to in several different ways in this chapter, depending on the type of compatibility information being related, as described in the following:
  • IA-32 Processors — All the Intel processors based on the Intel IA-32 Archi tecture, which include the 8086/88, Intel 286, Intel386, Intel486, Pentium, Pentium Pro, Pentium II, Pentium III , Pentium 4, and Intel Xeon processors.
  • 32-bit Processors — All the IA-32 processors that use a 32-bit architecture, which include the Intel386, Intel486, Pentium, Pentium Pro, Pentium II, Pentium III , Pentium 4, and Intel Xeon processors.
  • 16-bit Processors — All the IA-32 processors that use a 16-bit architecture, which include the 8086/88 and Intel 286 processors.
  • P6 Family Processors — All the IA-32 processors that are based on the P6 microarchitecture, which include the Pentium Pro, Pentium II, and Pentium III processors.
  • Pentium 4 Processors — A family of IA-32 and Intel 64 processors that are based on the Intel NetBurst microarchitecture.
  • Intel Pentium M Processors — A family of IA-32 processors that are based on the Intel Pentium M processor microarchitecture.
  • Intel Core Duo and Solo Processors — Families of IA-32 processors that are based on an improved Intel Pentium M processor microarchitecture.
  • Intel Xeon Processors — A family of IA-32 and Intel 64 processors that are based on the Intel NetBurst microarchitecture. This family includes the Intel Xeon processor and the Intel Xeon processor MP based on the Intel NetBurst microar chitecture. Intel Xeon processors 3000, 3100, 3200, 3300, 3200, 5100, 5200, 5300, 5400, 7200, 7300 series are based on Intel Core microarchitectures and support Intel 64 architecture.
Page 762 of the Intel 253668-032US user manual — 19.3 ENABLING NEW FUNCTIONS AND MODES
Page 762 · click to enlarge
Page 762

ARCHITECTURE COMPATIBILITY

  • Pentium D Processors — A family of dual-core Intel 64 processors that provides two processor cores in a physical package. Each core is based on the Intel NetBurst microarchitecture.
  • Pentium Processor Extreme Editions — A family of dual-core Intel 64 processors that provides two processor cores in a physical package. Each core is based on the Intel NetBurst microarchitecture and supports Intel HyperThreading Technology.
  • Intel Core 2 Processors — A family of Intel 64 processors that are based on the Intel Core microarchitecture. Intel Pentium Dual-Core processors are also based on the Intel Core microarchitecture.
  • Intel Atom Processors — A family of IA-32 and Intel 64 processors that are based on the Intel Atom microarchitecture.

19.2 RESERVED BITS

  • Throughout this manual, certain bits are marked as reserved in many register and memory layout descriptions. When bits are marked as undefined or reserved, it is essential for compatibility with future processors that software treat these bits as having a future, though unknown effect. Software should follow these guidelines in dealing with reserved bits:
  • Do not depend on the states of any reserved bits when testing the values of registers or memory locations that contain such bits. Mask out the reserved bits before testing.
  • Do not depend on the states of any reserved bits when storing them to memory or to a register.
  • Do not depend on the ability to retain information written into any reserved bits.
  • When loading a register, always load the reserved bits with the values indicated in the documentation, if any, or reload them with values previously read from the same register.

Software written for existing IA-32 processor that handles reserved bits correctly will port to future IA-32 processors without generating protection exceptions.

19.3 ENABLING NEW FUNCTIONS AND MODES

Most of the new control functions defined for the P6 family and Pentium processors are enabled by new mode flags in the control registers (primarily register CR4). This register is undefined for IA-32 processors earlier than the Pentium processor. Attempting to access this register with an Intel486 or earlier IA-32 processor results in an invalid-opcode exception (#UD). Consequently, programs that execute correctly on the Intel486 or earlier IA-32 processor cannot erroneously enable these functions. Attempting to set a reserved bit in register CR4 to a value other than its

Page 763 of the Intel 253668-032US user manual — 19.6 STREAMING SIMD EXTENSIONS (SSE)
Page 763 · click to enlarge
Page 763

ARCHITECTURE COMPATIBILITY

original value results in a general-protection exception (#GP). So, programs that execute on the P6 family and Pentium processors cannot erroneously enable func tions that may be implemented in future IA-32 processors.

The P6 family and Pentium processors do not check for attempts to set reserved bits in model-specific registers; however these bits may be checked on more recent processors. It is the obligation of the software writer to enforce this discipline. These reserved bits may be used in future Intel processors.

19.4 DETECTING THE PRESENCE OF NEW FEATURES THROUGH SOFTWARE

Software can check for the presence of new architectural features and extensions in either of two ways:

1. Test for the presence of the feature or extension. Software can test for the presence of new flags in the EFLAGS register and control registers. If these flags are reserved (meaning not present in the processor executing the test), an exception is generated. Likewise, software can attempt to execute a new instruction, which results in an invalid-opcode exception (#UD) being generated if it is not supported.
2. Execute the CPUID instruction. The CPUID instruction (added to the IA-32 in the Pentium processor) indicates the presence of new features directly.

See Chapter 14, “Processor Identification and Feature Determination,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for detailed information on detecting new processor features and extensions.

19.5 INTEL MMX TECHNOLOGY

The Pentium processor with MMX technology introduced the MMX technology and a set of MMX instructions to the IA-32. The MMX instructions are described in Chapter 9, “Programming with Intel® MMX™ Technology,” in the Intel® 64 and IA-32 Archi tectures Software Developer’s Manual, Volume 1, and in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B. The MMX technology and MMX instructions are also included in the Pentium II, Pentium III, Pentium 4, and Intel Xeon processors.

19.6 STREAMING SIMD EXTENSIONS (SSE)

The Streaming SIMD Extensions (SSE) were introduced in the Pentium III processor. The SSE extensions consist of a new set of instructions and a new set of registers. The new registers include the eight 128-bit XMM registers and the 32-bit MXCSR

Page 764 of the Intel 253668-032US user manual — 19.9 ADDITIONAL STREAMING SIMD EXTENSIONS
Page 764 · click to enlarge
Page 764

ARCHITECTURE COMPATIBILITY

control and status register. These instructions and registers are designed to allow SIMD computations to be made on single-precision floating-point numbers. Several of these new instructions also operate in the MMX registers. SSE instructions and registers are described in Section 10, “Programming with Streaming SIMD Exten sions (SSE),” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, and in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B.

19.7 STREAMING SIMD EXTENSIONS 2 (SSE2)

The Streaming SIMD Extensions 2 (SSE2) were introduced in the Pentium 4 and Intel Xeon processors. They consist of a new set of instructions that operate on the XMM and MXCSR registers and perform SIMD operations on double-precision floating- point values and on integer values. Several of these new instructions also operate in the MMX registers. SSE2 instructions and registers are described in Chapter 11, “Programming with Streaming SIMD Extensions 2 (SSE2),” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, and in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B.

19.8 STREAMING SIMD EXTENSIONS 3 (SSE3)

The Streaming SIMD Extensions 3 (SSE3) were introduced in Pentium 4 processors supporting Intel Hyper-Threading Technology and Intel Xeon processors. SSE3 extensions include 13 instructions. Ten of these 13 instructions support the single instruction multiple data (SIMD) execution model used with SSE/SSE2 extensions. One SSE3 instruction accelerates x87 style programming for conversion to integer. The remaining two instructions (MONITOR and MWAIT) accelerate synchronization of threads. SSE3 instructions are described in Chapter 12, “Programming with SSE3, SSSE3 and SSE4,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, and in the Intel® 64 and IA-32 Architectures Software Devel oper’s Manual, Volumes 2A & 2B.

19.9 ADDITIONAL STREAMING SIMD EXTENSIONS

The Supplemental Streaming SIMD Extensions 3 (SSSE3) were introduced in the Intel Core 2 processor and Intel Xeon processor 5100 series. Streaming SIMD Exten sions 4 provided 54 new instructions introduced in 45nm Intel Xeon processors and Intel Core 2 processors. SSSE3, SSE4.1 and SSE4.2 instructions are described in Chapter 12, “Programming with SSE3, SSSE3 and SSE4,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, and in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B.

Page 765 of the Intel 253668-032US user manual — 19.13 NEW INSTRUCTIONS IN THE PENTIUM AND LATER IA-32 PROCESSORS
Page 765 · click to enlarge
Page 765

ARCHITECTURE COMPATIBILITY

19.10 INTEL HYPER-THREADING TECHNOLOGY

Intel Hyper-Threading Technology provides two logical processors that can execute two separate code streams (called threads) concurrently by using shared resources in a single processor core or in a physical package.

This feature was introduced in the Intel Xeon processor MP and later steppings of the Intel Xeon processor, and Pentium 4 processors supporting Intel Hyper-Threading Technology. The feature is also found in the Pentium processor Extreme Edition. See also: Section 8.7, “Intel® Hyper-Threading Technology Architecture.”

Intel Atom processors also support Intel Hyper-Threading Technology.

19.11 MULTI-CORE TECHNOLOGY

The Pentium D processor and Pentium processor Extreme Edition provide two processor cores in each physical processor package. See also: Section 8.5, “Intel® Hyper-Threading Technology and Intel® Multi-Core Technology,” and Section 8.8, “Multi-Core Architecture.” Intel Core 2 Duo, Intel Pentium Dual-Core processors, Intel Xeon processors 3000, 3100, 5100, 5200 series provide two processor cores in each physical processor package. Intel Core 2 Extreme, Intel Core 2 Quad proces sors, Intel Xeon processors 3200, 3300, 5300, 5400, 7300 series provide two processor cores in each physical processor package.

19.12 SPECIFIC FEATURES OF DUAL-CORE PROCESSOR

  • Dual-core processors may have some processor-specific features. Use CPUID feature flags to detect the availability features. Note the following:
  • CPUID Brand String — On Pentium processor Extreme Edition, the process will report the correct brand string only after the correct microcode updates are loaded.
  • Enhanced Intel SpeedStep Technology — This feature is supported in Pentium D processor but not in Pentium processor Extreme Edition.

19.13 NEW INSTRUCTIONS IN THE PENTIUM AND LATER IA-32 PROCESSORS

Table 19-1 identifies the instructions introduced into the IA-32 in the Pentium processor and later IA-32 processors.

Page 766 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 766 · click to enlarge
Page 766

ARCHITECTURE COMPATIBILITY

19.13.1 Instructions Added Prior to the Pentium Processor

  • The following instructions were added in the Intel486 processor:
  • BSWAP (byte swap) instruction.
  • XADD (exchange and add) instruction.
  • CMPXCHG (compare and exchange) instruction.
  • Ι NVD (invalidate cache) instruction.
  • WBINVD (write-back and invalidate cache) instruction.
  • INVLPG (invalidate TLB entry) instruction.

Table 19-1. New Instruction in the Pentium Processor and

Instruction CPUID Identification Bits Introduced In

CMOVcc (conditional move) EDX, Bit 15 Pentium Pro processor

FCMOVcc (floating-point conditional move)

EDX, Bits 0 and 15

FCOMI (floating-point compare and set EFLAGS)

EDX, Bits 0 and 15

RDPMC (read performance monitoring counters)

EAX, Bits 8-11, set to 6H; see Note 1

UD2 (undefined) EAX, Bits 8-11, set to 6H

CMPXCHG8B (compare and exchange 8 bytes)

EDX, Bit 8 Pentium processor

CPUID (CPU identification) None; see Note 2

RDTSC (read time-stamp counter) EDX, Bit 4

RDMSR (read model-specific register) EDX, Bit 5

WRMSR (write model-specific register) EDX, Bit 5

MMX Instructions EDX, Bit 23

NOTES: 1. The RDPMC instruction was introduced in the P6 family of processors and added to later model Pentium processors. This instruction is model specific in nature and not architectural. 2. The CPUID instruction is available in all Pentium and P6 family processors and in later models of the Intel486 processors. The ability to set and clear the ID flag (bit 21) in the EFLAGS register indicates the availability of the CPUID instruction.

  • The following instructions were added in the Intel386 processor:
  • LSS, LFS, and LGS (load SS, FS, and GS registers).
  • Long-displacement conditional jumps.

Later IA-32 Processors

Page 767 of the Intel 253668-032US user manual — 19.16 NEW FLAGS IN THE EFLAGS REGISTER
Page 767 · click to enlarge
Page 767

ARCHITECTURE COMPATIBILITY

  • Single-bit instructions.
  • Bit scan instructions.
  • Double-shift instructions.
  • Byte set on condition instruction.
  • Move with sign/zero extension.
  • Generalized multiply instruction.
  • MOV to and from control registers.
  • MOV to and from test registers (now obsolete).
  • MOV to and from debug registers.
  • RSM (resume from SMM). This instruction was introduced in the Intel386 SL and Intel486 SL processors.
  • The following instructions were added in the Intel 387 math coprocessor:
  • FPREM1.
  • FUCOM, FUCOMP, and FUCOMPP.

19.14 OBSOLETE INSTRUCTIONS

The MOV to and from test registers instructions were removed from the Pentium processor and future IA-32 processors. Execution of these instructions generates an invalid-opcode exception (#UD).

19.15 UNDEFINED OPCODES

All new instructions defined for IA-32 processors use binary encodings that were reserved on earlier-generation processors. Attempting to execute a reserved opcode always results in an invalid-opcode (#UD) exception being generated. Consequently, programs that execute correctly on earlier-generation processors cannot erroneously execute these instructions and thereby produce unexpected results when executed on later IA-32 processors.

19.16 NEW FLAGS IN THE EFLAGS REGISTER

The section titled “EFLAGS Register” in Chapter 3, “Basic Execution Environment,” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, shows the configuration of flags in the EFLAGS register for the P6 family processors. No new flags have been added to this register in the P6 family processors. The flags added to this register in the Pentium and Intel486 processors are described in the following sections.

Page 768 of the Intel 253668-032US user manual — PUSH BP MOV BP, SP
Page 768 · click to enlarge
Page 768

ARCHITECTURE COMPATIBILITY

  • The following flags were added to the EFLAGS register in the Pentium processor:
  • VIF (virtual interrupt flag), bit 19.
  • VIP (virtual interrupt pending), bit 20.
  • ID (identification flag), bit 21.

The AC flag (bit 18) was added to the EFLAGS register in the Intel486 processor.

19.16.1 Using EFLAGS Flags to Distinguish Between 32-Bit IA-32 Processors

  • The following bits in the EFLAGS register that can be used to differentiate between the 32-bit IA-32 processors:
  • Bit 18 (the AC flag) can be used to distinguish an Intel386 processor from the P6 family, Pentium, and Intel486 processors. Since it is not implemented on the Intel386 processor, it will always be clear.
  • Bit 21 (the ID flag) indicates whether an application can execute the CPUID instruction. The ability to set and clear this bit indicates that the processor is a P6 family or Pentium processor. The CPUID instruction can then be used to determine which processor.
  • Bits 19 (the VIF flag) and 20 (the VIP flag) will always be zero on processors that do not support virtual mode extensions, which includes all 32-bit processors prior to the Pentium processor.

See Chapter 14, “Processor Identification and Feature Determination,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for more infor mation on identifying processors.

19.17 STACK OPERATIONS

This section identifies the differences in stack implementation between the various IA-32 processors.

19.17.1 PUSH SP

The P6 family, Pentium, Intel486, Intel386, and Intel 286 processors push a different value on the stack for a PUSH SP instruction than the 8086 processor. The 32-bit processors push the value of the SP register before it is decremented as part of the push operation; the 8086 processor pushes the value of the SP register after it is decremented. If the value pushed is important, replace PUSH SP instructions with the following three instructions:

PUSH BP MOV BP, SP

Page 769 of the Intel 253668-032US user manual — 19.18.1 Control Register CR0 Flags
Page 769 · click to enlarge
Page 769

ARCHITECTURE COMPATIBILITY

XCHG BP, [BP]

This code functions as the 8086 processor PUSH SP instruction on the P6 family, Pentium, Intel486, Intel386, and Intel 286 processors.

19.17.2 EFLAGS Pushed on the Stack

  • The setting of the stored values of bits 12 through 15 (which includes the IOPL field and the NT flag) in the EFLAGS register by the PUSHF instruction, by interrupts, and by exceptions is different with the 32-bit IA-32 processors than with the 8086 and Intel 286 processors. The differences are as follows:
  • 8086 processor—bits 12 through 15 are always set.
  • Intel 286 processor—bits 12 through 15 are always cleared in real-address mode.
  • 32-bit processors in real-address mode—bit 15 (reserved) is always cleared, and bits 12 through 14 have the last value loaded into them.

19.18 X87 FPU

This section addresses the issues that must be faced when porting floating-point software designed to run on earlier IA-32 processors and math coprocessors to a Pentium 4, Intel Xeon, P6 family, or Pentium processor with integrated x87 FPU. To software, a Pentium 4, Intel Xeon, or P6 family processor looks very much like a Pentium processor. Floating-point software which runs on a Pentium or Intel486 DX processor, or on an Intel486 SX processor/Intel 487 SX math coprocessor system or an Intel386 processor/Intel 387 math coprocessor system, will run with at most minor modifications on a Pentium 4, Intel Xeon, or P6 family processor. To port code directly from an Intel 286 processor/Intel 287 math coprocessor system or an Intel 8086 processor/8087 math coprocessor system to a Pentium 4, Intel Xeon, P6 family, or Pentium processor, certain additional issues must be addressed.

In the following sections, the term “32-bit x87 FPUs” refers to the P6 family, Pentium, and Intel486 DX processors, and to the Intel 487 SX and Intel 387 math coproces sors; the term “16-bit IA-32 math coprocessors” refers to the Intel 287 and 8087 math coprocessors.

19.18.1 Control Register CR0 Flags

The ET, NE, and MP flags in control register CR0 control the interface between the integer unit of an IA-32 processor and either its internal x87 FPU or an external math coprocessor. The effect of these flags in the various IA-32 processors are described in the following paragraphs.

The ET (extension type) flag (bit 4 of the CR0 register) is used in the Intel386 processor to indicate whether the math coprocessor in the system is an Intel 287

Page 770 of the Intel 253668-032US user manual — 19.18.2 x87 FPU Status Word
Page 770 · click to enlarge
Page 770

ARCHITECTURE COMPATIBILITY

math coprocessor (flag is clear) or an Intel 387 DX math coprocessor (flag is set). This bit is hardwired to 1 in the P6 family, Pentium, and Intel486 processors.

The NE (Numeric Exception) flag (bit 5 of the CR0 register) is used in the P6 family, Pentium, and Intel486 processors to determine whether unmasked floating-point exceptions are reported internally through interrupt vector 16 (flag is set) or exter nally through an external interrupt (flag is clear). On a hardware reset, the NE flag is initialized to 0, so software using the automatic internal error-reporting mechanism must set this flag to 1. This flag is nonexistent on the Intel386 processor.

As on the Intel 286 and Intel386 processors, the MP (monitor coprocessor) flag (bit 1 of register CR0) determines whether the WAIT/FWAIT instructions or waiting-type floating-point instructions trap when the context of the x87 FPU is different from that of the currently-executing task. If the MP and TS flag are set, then a WAIT/FWAIT instruction and waiting instructions will cause a device-not-available exception (interrupt vector 7). The MP flag is used on the Intel 286 and Intel386 processors to support the use of a WAIT/FWAIT instruction to wait on a device other than a math coprocessor. The device reports its status through the BUSY# pin. Since the P6 family, Pentium, and Intel486 processors do not have such a pin, the MP flag has no relevant use and should be set to 1 for normal operation.

19.18.2 x87 FPU Status Word

This section identifies differences to the x87 FPU status word for the different IA-32 processors and math coprocessors, the reason for the differences, and their impact on software.

19.18.2.1 Condition Code Flags (C0 through C3)

The following information pertains to differences in the use of the condition code flags (C0 through C3) located in bits 8, 9, 10, and 14 of the x87 FPU status word.

After execution of an FINIT instruction or a hardware reset on a 32-bit x87 FPU, the condition code flags are set to 0. The same operations on a 16-bit IA-32 math copro cessor leave these flags intact (they contain their prior value). This difference in operation has no impact on software and provides a consistent state after reset.

Transcendental instruction results in the core range of the P6 family and Pentium processors may differ from the Intel486 DX processor and Intel 487 SX math copro cessor by 2 to 3 units in the last place (ulps)—(see “Transcendental Instruction Accu racy” in Chapter 8, “Programming with the x87 FPU,” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1). As a result, the value saved in the C1 flag may also differ.

After an incomplete FPREM/FPREM1 instruction, the C0, C1, and C3 flags are set to 0 on the 32-bit x87 FPUs. After the same operation on a 16-bit IA-32 math copro cessor, these flags are left intact.

Page 771 of the Intel 253668-032US user manual — 19.18.4 x87 FPU Tag Word
Page 771 · click to enlarge
Page 771

ARCHITECTURE COMPATIBILITY

On the 32-bit x87 FPUs, the C2 flag serves as an incomplete flag for the FTAN instruc tion. On the 16-bit IA-32 math coprocessors, the C2 flag is undefined for the FPTAN instruction. This difference has no impact on software, because Intel 287 or 8087 programs do not check C2 after an FPTAN instruction. The use of this flag on later processors allows fast checking of operand range.

19.18.2.2 Stack Fault Flag

When unmasked stack overflow or underflow occurs on a 32-bit x87 FPU, the IE flag (bit 0) and the SF flag (bit 6) of the x87 FPU status word are set to indicate a stack fault and condition code flag C1 is set or cleared to indicate overflow or underflow, respectively. When unmasked stack overflow or underflow occurs on a 16-bit IA-32 math coprocessor, only the IE flag is set. Bit 6 is reserved on these processors. The addition of the SF flag on a 32-bit x87 FPU has no impact on software. Existing excep tion handlers need not change, but may be upgraded to take advantage of the addi tional information.

19.18.3 x87 FPU Control Word

Only affine closure is supported for infinity control on a 32-bit x87 FPU. The infinity control flag (bit 12 of the x87 FPU control word) remains programmable on these processors, but has no effect. This change was made to conform to the IEEE Stan dard 754 for Binary Floating-Point Arithmetic. On a 16-bit IA-32 math coprocessor, both affine and projective closures are supported, as determined by the setting of bit 12. After a hardware reset, the default value of bit 12 is projective. Software that requires projective infinity arithmetic may give different results.

19.18.4 x87 FPU Tag Word

When loading the tag word of a 32-bit x87 FPU, using an FLDENV, FRSTOR, or FXRSTOR (Pentium III processor only) instruction, the processor examines the incoming tag and classifies the location only as empty or non-empty. Thus, tag values of 00, 01, and 10 are interpreted by the processor to indicate a non-empty location. The tag value of 11 is interpreted by the processor to indicate an empty location. Subsequent operations on a non-empty register always examine the value in the register, not the value in its tag. The FSTENV, FSAVE, and FXSAVE (Pentium III processor only) instructions examine the non-empty registers and put the correct values in the tags before storing the tag word.

The corresponding tag for a 16-bit IA-32 math coprocessor is checked before each register access to determine the class of operand in the register; the tag is updated after every change to a register so that the tag always reflects the most recent status of the register. Software can load a tag with a value that disagrees with the contents of a register (for example, the register contains a valid value, but the tag says special). Here, the 16-bit IA-32 math coprocessors honor the tag and do not examine the register.

Page 772 of the Intel 253668-032US user manual — 19.18.5 Data Types
Page 772 · click to enlarge
Page 772

ARCHITECTURE COMPATIBILITY

Software written to run on a 16-bit IA-32 math coprocessor may not operate correctly on a 16-bit x87 FPU, if it uses the FLDENV, FRSTOR, or FXRSTOR instruc tions to change tags to values (other than to empty) that are different from actual register contents.

The encoding in the tag word for the 32-bit x87 FPUs for unsupported data formats (including pseudo-zero and unnormal) is special (10B), to comply with IEEE Standard 754. The encoding in the 16-bit IA-32 math coprocessors for pseudo-zero and unnormal is valid (00B) and the encoding for other unsupported data formats is special (10B). Code that recognizes the pseudo-zero or unnormal format as valid must therefore be changed if it is ported to a 32-bit x87 FPU.

19.18.5 Data Types

This section discusses the differences of data types for the various x87 FPUs and math coprocessors.

19.18.5.1 NaNs

The 32-bit x87 FPUs distinguish between signaling NaNs (SNaNs) and quiet NaNs (QNaNs). These x87 FPUs only generate QNaNs and normally do not generate an exception upon encountering a QNaN. An invalid-operation exception (#I) is gener ated only upon encountering a SNaN, except for the FCOM, FIST, and FBSTP instruc tions, which also generates an invalid-operation exceptions for a QNaNs. This behavior matches IEEE Standard 754.

The 16-bit IA-32 math coprocessors only generate one kind of NaN (the equivalent of a QNaN), but the raise an invalid-operation exception upon encountering any kind of NaN.

When porting software written to run on a 16-bit IA-32 math coprocessor to a 32-bit x87 FPU, uninitialized memory locations that contain QNaNs should be changed to SNaNs to cause the x87 FPU or math coprocessor to fault when uninitialized memory locations are referenced.

19.18.5.2 Pseudo-zero, Pseudo-NaN, Pseudo-infinity, and Unnormal Formats

The 32-bit x87 FPUs neither generate nor support the pseudo-zero, pseudo-NaN, pseudo-infinity, and unnormal formats. Whenever they encounter them in an arith metic operation, they raise an invalid-operation exception. The 16-bit IA-32 math coprocessors define and support special handling for these formats. Support for these formats was dropped to conform with IEEE Standard 754 for Binary Floating- Point Arithmetic.

This change should not impact software ported from 16-bit IA-32 math coprocessors to 32-bit x87 FPUs. The 32-bit x87 FPUs do not generate these formats, and there fore will not encounter them unless software explicitly loads them in the data regis

Page 773 of the Intel 253668-032US user manual — 19.18.6 Floating-Point Exceptions
Page 773 · click to enlarge
Page 773

ARCHITECTURE COMPATIBILITY

ters. The only affect may be in how software handles the tags in the tag word (see also: Section 19.18.4, “x87 FPU Tag Word”).

19.18.6 Floating-Point Exceptions

This section identifies the implementation differences in exception handling for floating-point instructions in the various x87 FPUs and math coprocessors.

19.18.6.1 Denormal Operand Exception (#D)

When the denormal operand exception is masked, the 32-bit x87 FPUs automatically normalize denormalized numbers when possible; whereas, the 16-bit IA-32 math coprocessors return a denormal result. A program written to run on a 16-bit IA-32 math coprocessor that uses the denormal exception solely to normalize denormal ized operands is redundant when run on the 32-bit x87 FPUs. If such a program is run on 32-bit x87 FPUs, performance can be improved by masking the denormal excep tion. Floating-point programs run faster when the FPU performs normalization of denormalized operands.

The denormal operand exception is not raised for transcendental instructions and the FXTRACT instruction on the 16-bit IA-32 math coprocessors. This exception is raised for these instructions on the 32-bit x87 FPUs. The exception handlers ported to these latter processors need to be changed only if the handlers gives special treatment to different opcodes.

19.18.6.2 Numeric Overflow Exception (#O)

On the 32-bit x87 FPUs, when the numeric overflow exception is masked and the rounding mode is set to chop (toward 0), the result is the largest positive or smallest negative number. The 16-bit IA-32 math coprocessors do not signal the overflow exception when the masked response is not ∞; that is, they signal overflow only when the rounding control is not set to round to 0. If rounding is set to chop (toward 0), the result is positive or negative ∞. Under the most common rounding modes, this difference has no impact on existing software.

If rounding is toward 0 (chop), a program on a 32-bit x87 FPU produces, under over flow conditions, a result that is different in the least significant bit of the significand, compared to the result on a 16-bit IA-32 math coprocessor. The reason for this differ ence is IEEE Standard 754 compatibility.

When the overflow exception is not masked, the precision exception is flagged on the 32-bit x87 FPUs. When the result is stored in the stack, the significand is rounded according to the precision control (PC) field of the FPU control word or according to the opcode. On the 16-bit IA-32 math coprocessors, the precision exception is not flagged and the significand is not rounded. The impact on existing software is that if the result is stored on the stack, a program running on a 32-bit x87 FPU produces a different result under overflow conditions than on a 16-bit IA-32 math coprocessor.

Page 774 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 774 · click to enlarge
Page 774

ARCHITECTURE COMPATIBILITY

The difference is apparent only to the exception handler. This difference is for IEEE Standard 754 compatibility.

19.18.6.3 Numeric Underflow Exception (#U)

When the underflow exception is masked on the 32-bit x87 FPUs, the underflow exception is signaled when both the result is tiny and denormalization results in a loss of accuracy. When the underflow exception is unmasked and the instruction is supposed to store the result on the stack, the significand is rounded to the appro priate precision (according to the PC flag in the FPU control word, for those instruc tions controlled by PC, otherwise to extended precision), after adjusting the exponent.

When the underflow exception is masked on the 16-bit IA-32 math coprocessors and rounding is toward 0, the underflow exception flag is raised on a tiny result, regard less of loss of accuracy. When the underflow exception is not masked and the desti nation is the stack, the significand is not rounded, but instead is left as is.

When the underflow exception is masked, this difference has no impact on existing software. The underflow exception occurs less often when rounding is toward 0.

When the underflow exception not masked. A program running on a 32-bit x87 FPU produces a different result during underflow conditions than on a 16-bit IA-32 math coprocessor if the result is stored on the stack. The difference is only in the least significant bit of the significand and is apparent only to the exception handler.

19.18.6.4 Exception Precedence

There is no difference in the precedence of the denormal-operand exception on the 32-bit x87 FPUs, whether it be masked or not. When the denormal-operand excep tion is not masked on the 16-bit IA-32 math coprocessors, it takes precedence over all other exceptions. This difference causes no impact on existing software, but some unneeded normalization of denormalized operands is prevented on the Intel486 processor and Intel 387 math coprocessor.

19.18.6.5 CS and EIP For FPU Exceptions

On the Intel 32-bit x87 FPUs, the values from the CS and EIP registers saved for floating-point exceptions point to any prefixes that come before the floating-point instruction. On the 8087 math coprocessor, the saved CS and IP registers points to the floating-point instruction.

19.18.6.6 FPU Error Signals

The floating-point error signals to the P6 family, Pentium, and Intel486 processors do not pass through an interrupt controller; an INT# signal from an Intel 387, Intel 287 or 8087 math coprocessors does. If an 8086 processor uses another exception for

Page 775 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 775 · click to enlarge
Page 775

ARCHITECTURE COMPATIBILITY

the 8087 interrupt, both exception vectors should call the floating-point-error excep tion handler. Some instructions in a floating-point-error exception handler may need to be deleted if they use the interrupt controller. The P6 family, Pentium, and Intel486 processors have signals that, with the addition of external logic, support reporting for emulation of the interrupt mechanism used in many personal computers.

On the P6 family, Pentium, and Intel486 processors, an undefined floating-point opcode will cause an invalid-opcode exception (#UD, interrupt vector 6). Undefined floating-point opcodes, like legal floating-point opcodes, cause a device not available exception (#NM, interrupt vector 7) when either the TS or EM flag in control register CR0 is set. The P6 family, Pentium, and Intel486 processors do not check for floating- point error conditions on encountering an undefined floating-point opcode.

19.18.6.7 Assertion of the FERR# Pin

When using the MS-DOS compatibility mode for handing floating-point exceptions, the FERR# pin must be connected to an input to an external interrupt controller. An external interrupt is then generated when the FERR# output drives the input to the interrupt controller and the interrupt controller in turn drives the INTR pin on the processor.

For the P6 family and Intel386 processors, an unmasked floating-point exception always causes the FERR# pin to be asserted upon completion of the instruction that caused the exception. For the Pentium and Intel486 processors, an unmasked floating-point exception may cause the FERR# pin to be asserted either at the end of the instruction causing the exception or immediately before execution of the next floating-point instruction. (Note that the next floating-point instruction would not be executed until the pending unmasked exception has been handled.) See Appendix D, “Guidelines for Writing x87 FPU Extension Handlers,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1, for a complete description of the required mechanism for handling floating-point exceptions using the MS-DOS compatibility mode.

Using FERR# and IGNNE# to handle floating-point exception is deprecated by modern operating systems; this approach also limits newer processors to operate with one logical processor active.

19.18.6.8 Invalid Operation Exception On Denormals

An invalid-operation exception is not generated on the 32-bit x87 FPUs upon encoun tering a denormal value when executing a FSQRT, FDIV, or FPREM instruction or upon conversion to BCD or to integer. The operation proceeds by first normalizing the value. On the 16-bit IA-32 math coprocessors, upon encountering this situation, the invalid-operation exception is generated. This difference has no impact on existing software. Software running on the 32-bit x87 FPUs continues to execute in cases where the 16-bit IA-32 math coprocessors trap. The reason for this change was to eliminate an exception from being raised.

Page 776 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 776 · click to enlarge
Page 776

ARCHITECTURE COMPATIBILITY

19.18.6.9 Alignment Check Exceptions (#AC)

If alignment checking is enabled, a misaligned data operand on the P6 family, Pentium, and Intel486 processors causes an alignment check exception (#AC) when a program or procedure is running at privilege-level 3, except for the stack portion of the FSAVE/FNSAVE, FXSAVE, FRSTOR, and FXRSTOR instructions.

19.18.6.10 Segment Not Present Exception During FLDENV

On the Intel486 processor, when a segment not present exception (#NP) occurs in the middle of an FLDENV instruction, it can happen that part of the environment is loaded and part not. In such cases, the FPU control word is left with a value of 007FH. The P6 family and Pentium processors ensure the internal state is correct at all times by attempting to read the first and last bytes of the environment before updating the internal state.

19.18.6.11 Device Not Available Exception (#NM)

The device-not-available exception (#NM, interrupt 7) will occur in the P6 family, Pentium, and Intel486 processors as described in Section 2.5, “Control Registers,” Table 2-1, and Chapter 6, “Interrupt 7—Device Not Available Exception (#NM).”

19.18.6.12 Coprocessor Segment Overrun Exception

The coprocessor segment overrun exception (interrupt 9) does not occur in the P6 family, Pentium, and Intel486 processors. In situations where the Intel 387 math coprocessor would cause an interrupt 9, the P6 family, Pentium, and Intel486 proces sors simply abort the instruction. To avoid undetected segment overruns, it is recom mended that the floating-point save area be placed in the same page as the TSS. This placement will prevent the FPU environment from being lost if a page fault occurs during the execution of an FLDENV, FRSTOR, or FXRSTOR instruction while the oper ating system is performing a task switch.

19.18.6.13 General Protection Exception (#GP)

A general-protection exception (#GP, interrupt 13) occurs if the starting address of a floating-point operand falls outside a segment’s size. An exception handler should be included to report these programming errors.

19.18.6.14 Floating-Point Error Exception (#MF)

In real mode and protected mode (not including virtual-8086 mode), interrupt vector 16 must point to the floating-point exception handler. In virtual 8086 mode, the virtual-8086 monitor can be programmed to accommodate a different location of the interrupt vector for floating-point exceptions.

Page 777 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 777 · click to enlarge
Page 777

ARCHITECTURE COMPATIBILITY

19.18.7 Changes to Floating-Point Instructions

This section identifies the differences in floating-point instructions for the various Intel FPU and math coprocessor architectures, the reason for the differences, and their impact on software.

19.18.7.1 FDIV, FPREM, and FSQRT Instructions

The 32-bit x87 FPUs support operations on denormalized operands and, when detected, an underflow exception can occur, for compatibility with the IEEE Standard 754. The 16-bit IA-32 math coprocessors do not operate on denormalized operands or return underflow results. Instead, they generate an invalid-operation exception when they detect an underflow condition. An existing underflow exception handler will require change only if it gives different treatment to different opcodes. Also, it is possible that fewer invalid-operation exceptions will occur.

19.18.7.2 FSCALE Instruction

With the 32-bit x87 FPUs, the range of the scaling operand is not restricted. If (0 < | ST(1) < 1), the scaling factor is 0; therefore, ST(0) remains unchanged. If the rounded result is not exact or if there was a loss of accuracy (masked underflow), the precision exception is signaled. With the 16-bit IA-32 math coprocessors, the range of the scaling operand is restricted. If (0 < | ST(1) | < 1), the result is undefined and no exception is signaled. The impact of this difference on exiting software is that different results are delivered on the 32-bit and 16-bit FPUs and math coprocessors when (0 < | ST(1) | < 1).

19.18.7.3 FPREM1 Instruction

The 32-bit x87 FPUs compute a partial remainder according to IEEE Standard 754. This instruction does not exist on the 16-bit IA-32 math coprocessors. The avail ability of the FPREM1 instruction has is no impact on existing software.

19.18.7.4 FPREM Instruction

On the 32-bit x87 FPUs, the condition code flags C0, C3, C1 in the status word correctly reflect the three low-order bits of the quotient following execution of the FPREM instruction. On the 16-bit IA-32 math coprocessors, the quotient bits are incorrect when performing a reduction of (64N + M) when (N ≥ 1) and M is 1 or 2. This difference does not affect existing software; software that works around the bug should not be affected.

19.18.7.5 FUCOM, FUCOMP, and FUCOMPP Instructions

When executing the FUCOM, FUCOMP, and FUCOMPP instructions, the 32-bit x87 FPUs perform unordered compare according to IEEE Standard 754. These instruc

Page 778 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 778 · click to enlarge
Page 778

ARCHITECTURE COMPATIBILITY

tions do not exist on the 16-bit IA-32 math coprocessors. The availability of these new instructions has no impact on existing software.

19.18.7.6 FPTAN Instruction

On the 32-bit x87 FPUs, the range of the operand for the FPTAN instruction is much less restricted (| ST(0) | < 263) than on earlier math coprocessors. The instruction reduces the operand internally using an internal π/4 constant that is more accurate. The range of the operand is restricted to (| ST(0) | < π/4) on the 16-bit IA-32 math coprocessors; the operand must be reduced to this range using FPREM. This change has no impact on existing software.

19.18.7.7 Stack Overflow

On the 32-bit x87 FPUs, if an FPU stack overflow occurs when the invalid-operation exception is masked, the FPU returns the real, integer, or BCD-integer indefinite value to the destination operand, depending on the instruction being executed. On the 16-bit IA-32 math coprocessors, the original operand remains unchanged following a stack overflow, but it is loaded into register ST(1). This difference has no impact on existing software.

19.18.7.8 FSIN, FCOS, and FSINCOS Instructions

On the 32-bit x87 FPUs, these instructions perform three common trigonometric functions. These instructions do not exist on the 16-bit IA-32 math coprocessors. The availability of these instructions has no impact on existing software, but using them provides a performance upgrade.

19.18.7.9 FPATAN Instruction

On the 32-bit x87 FPUs, the range of operands for the FPATAN instruction is unre stricted. On the 16-bit IA-32 math coprocessors, the absolute value of the operand in register ST(0) must be smaller than the absolute value of the operand in register ST(1). This difference has impact on existing software.

19.18.7.10 F2XM1 Instruction

The 32-bit x87 FPUs support a wider range of operands (–1 < ST (0) < + 1) for the F2XM1 instruction. The supported operand range for the 16-bit IA-32 math coproces sors is (0 ≤ ST(0) ≤ 0.5). This difference has no impact on existing software.

19.18.7.11 FLD Instruction

On the 32-bit x87 FPUs, when using the FLD instruction to load an extended-real value, a denormal-operand exception is not generated because the instruction is not

Page 779 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 779 · click to enlarge
Page 779

ARCHITECTURE COMPATIBILITY

arithmetic. The 16-bit IA-32 math coprocessors do report a denormal-operand exception in this situation. This difference does not affect existing software.

On the 32-bit x87 FPUs, loading a denormal value that is in single- or double-real format causes the value to be converted to extended-real format. Loading a denormal value on the 16-bit IA-32 math coprocessors causes the value to be converted to an unnormal. If the next instruction is FXTRACT or FXAM, the 32-bit x87 FPUs will give a different result than the 16-bit IA-32 math coprocessors. This change was made for IEEE Standard 754 compatibility.

On the 32-bit x87 FPUs, loading an SNaN that is in single- or double-real format causes the FPU to generate an invalid-operation exception. The 16-bit IA-32 math coprocessors do not raise an exception when loading a signaling NaN. The invalid- operation exception handler for 16-bit math coprocessor software needs to be updated to handle this condition when porting software to 32-bit FPUs. This change was made for IEEE Standard 754 compatibility.

19.18.7.12 FXTRACT Instruction

On the 32-bit x87 FPUs, if the operand is 0 for the FXTRACT instruction, the divide- by-zero exception is reported and –∞ is delivered to register ST(1). If the operand is +∞, no exception is reported. If the operand is 0 on the 16-bit IA-32 math coproces sors, 0 is delivered to register ST(1) and no exception is reported. If the operand is +∞, the invalid-operation exception is reported. These differences have no impact on existing software. Software usually bypasses 0 and ∞. This change is due to the IEEE Standard 754 recommendation to fully support the “logb” function.

19.18.7.13 Load Constant Instructions

On 32-bit x87 FPUs, rounding control is in effect for the load constant instructions. Rounding control is not in effect for the 16-bit IA-32 math coprocessors. Results for the FLDPI, FLDLN2, FLDLG2, and FLDL2E instructions are the same as for the 16-bit IA-32 math coprocessors when rounding control is set to round to nearest or round to +∞. They are the same for the FLDL2T instruction when rounding control is set to round to nearest, round to –∞, or round to zero. Results are different from the 16-bit IA-32 math coprocessors in the least significant bit of the mantissa if rounding control is set to round to –∞ or round to 0 for the FLDPI, FLDLN2, FLDLG2, and FLDL2E instructions; they are different for the FLDL2T instruction if round to +∞ is specified. These changes were implemented for compatibility with IEEE Standard 754 for Floating-Point Arithmetic recommendations.

19.18.7.14 FSETPM Instruction

With the 32-bit x87 FPUs, the FSETPM instruction is treated as NOP (no operation). This instruction informs the Intel 287 math coprocessor that the processor is in protected mode. This change has no impact on existing software. The 32-bit x87

Page 780 of the Intel 253668-032US user manual — 19.18.9 Obsolete Instructions
Page 780 · click to enlarge
Page 780

ARCHITECTURE COMPATIBILITY

FPUs handle all addressing and exception-pointer information, whether in protected mode or not.

19.18.7.15 FXAM Instruction

With the 32-bit x87 FPUs, if the FPU encounters an empty register when executing the FXAM instruction, it not generate combinations of C0 through C3 equal to 1101 or 1111. The 16-bit IA-32 math coprocessors may generate these combinations, among others. This difference has no impact on existing software; it provides a performance upgrade to provide repeatable results.

19.18.7.16 FSAVE and FSTENV Instructions

With the 32-bit x87 FPUs, the address of a memory operand pointer stored by FSAVE or FSTENV is undefined if the previous floating-point instruction did not refer to memory

19.18.8 Transcendental Instructions

The floating-point results of the P6 family and Pentium processors for transcendental instructions in the core range may differ from the Intel486 processors by about 2 or 3 ulps (see “Transcendental Instruction Accuracy” in Chapter 8, “Programming with the x87 FPU,” of the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1). Condition code flag C1 of the status word may differ as a result. The exact threshold for underflow and overflow will vary by a few ulps. The P6 family and Pentium processors’ results will have a worst case error of less than 1 ulp when rounding to the nearest-even and less than 1.5 ulps when rounding in other modes. The transcendental instructions are guaranteed to be monotonic, with respect to the input operands, throughout the domain supported by the instruction.

Transcendental instructions may generate different results in the round-up flag (C1) on the 32-bit x87 FPUs. The round-up flag is undefined for these instructions on the 16-bit IA-32 math coprocessors. This difference has no impact on existing software.

19.18.9 Obsolete Instructions

The 8087 math coprocessor instructions FENI and FDISI and the Intel 287 math coprocessor instruction FSETPM are treated as integer NOP instructions in the 32-bit x87 FPUs. If these opcodes are detected in the instruction stream, no specific opera tion is performed and no internal states are affected.

Page 781 of the Intel 253668-032US user manual — 19.19 SERIALIZING INSTRUCTIONS
Page 781 · click to enlarge
Page 781

ARCHITECTURE COMPATIBILITY

19.18.10 WAIT/FWAIT Prefix Differences

On the Intel486 processor, when a WAIT/FWAIT instruction precedes a floating-point instruction (one which itself automatically synchronizes with the previous floating- point instruction), the WAIT/FWAIT instruction is treated as a no-op. Pending floating-point exceptions from a previous floating-point instruction are processed not on the WAIT/FWAIT instruction but on the floating-point instruction following the WAIT/FWAIT instruction. In such a case, the report of a floating-point exception may appear one instruction later on the Intel486 processor than on a P6 family or Pentium FPU, or on Intel 387 math coprocessor.

19.18.11 Operands Split Across Segments and/or Pages

On the P6 family, Pentium, and Intel486 processor FPUs, when the first half of an operand to be written is inside a page or segment and the second half is outside, a memory fault can cause the first half to be stored but not the second half. In this situ ation, the Intel 387 math coprocessor stores nothing.

19.18.12 FPU Instruction Synchronization

On the 32-bit x87 FPUs, all floating-point instructions are automatically synchro nized; that is, the processor automatically waits until the previous floating-point instruction has completed before completing the next floating-point instruction. No explicit WAIT/FWAIT instructions are required to assure this synchronization. For the 8087 math coprocessors, explicit waits are required before each floating-point instruction to ensure synchronization. Although 8087 programs having explicit WAIT instructions execute perfectly on the 32-bit IA-32 processors without reassembly, these WAIT instructions are unnecessary.

19.19 SERIALIZING INSTRUCTIONS

Certain instructions have been defined to serialize instruction execution to ensure that modifications to flags, registers and memory are completed before the next instruction is executed (or in P6 family processor terminology “committed to machine state”). Because the P6 family processors use branch-prediction and out-of-order execution techniques to improve performance, instruction execution is not generally serialized until the results of an executed instruction are committed to machine state (see Chapter 2, “Intel® 64 and IA-32 Architectures,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1).

As a result, at places in a program or task where it is critical to have execution completed for all previous instructions before executing the next instruction (for example, at a branch, at the end of a procedure, or in multiprocessor dependent code), it is useful to add a serializing instruction. See Section 8.3, “Serializing Instructions,” for more information on serializing instructions.

Page 782 of the Intel 253668-032US user manual — EM 1 0
Page 782 · click to enlarge
Page 782

ARCHITECTURE COMPATIBILITY

19.20 FPU AND MATH COPROCESSOR INITIALIZATION

Table 9-1 shows the states of the FPUs in the P6 family, Pentium, Intel486 processors and of the Intel 387 math coprocessor and Intel 287 coprocessor following a power- up, reset, or INIT, or following the execution of an FINIT/FNINIT instruction. The following is some additional compatibility information concerning the initialization of x87 FPUs and math coprocessors.

19.20.1 Intel ® 387 and Intel ® 287 Math Coprocessor Initialization

Following an Intel386 processor reset, the processor identifies its coprocessor type (Intel® 287 or Intel® 387 DX math coprocessor) by sampling its ERROR# input some time after the falling edge of RESET# signal and before execution of the first floating- point instruction. The Intel 287 coprocessor keeps its ERROR# output in inactive state after hardware reset; the Intel 387 coprocessor keeps its ERROR# output in active state after hardware reset.

Upon hardware reset or execution of the FINIT/FNINIT instruction, the Intel 387 math coprocessor signals an error condition. The P6 family, Pentium, and Intel486 processors, like the Intel 287 coprocessor, do not.

19.20.2 Intel486 SX Processor and Intel 487 SX Math Coprocessor Initialization

When initializing an Intel486 SX processor and an Intel 487 SX math coprocessor, the initialization routine should check the presence of the math coprocessor and should set the FPU related flags (EM, MP, and NE) in control register CR0 accordingly (see Section 2.5, “Control Registers,” for a complete description of these flags). Table 19-2 gives the recommended settings for these flags when the math coprocessor is present. The FSTCW instruction will give a value of FFFFH for the Intel486 SX micro processor and 037FH for the Intel 487 SX math coprocessor.

Table 19-2. Recommended Values of the EM, MP, and NE Flags for Intel486 SX

Microprocessor/Intel 487 SX Math Coprocessor System

CR0 Flags Intel486 SX Processor Only Intel 487 SX Math Coprocessor Present

EM 1 0

MP 0 1

NE 1 0, for MS-DOS* systems 1, for user-defined exception handler

The EM and MP flags in register CR0 are interpreted as shown in Table 19-3.

Page 783 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 783 · click to enlarge
Page 783

ARCHITECTURE COMPATIBILITY

Table 19-3. EM and MP Flag Interpretation

0 0 Floating-point instructions are passed to FPU; WAIT/FWAIT and other waiting-type instructions ignore TS.

0 1 Floating-point instructions are passed to FPU; WAIT/FWAIT and other waiting-type instructions test TS.

1 0 Floating-point instructions trap to emulator; WAIT/FWAIT and other waiting-type instructions ignore TS.

1 1 Floating-point instructions trap to emulator; WAIT/FWAIT and other waiting-type instructions test TS.

Following is an example code sequence to initialize the system and check for the presence of Intel486 SX processor/Intel 487 SX math coprocessor.

fninit fstcw mem_loc mov ax, mem_loc cmp ax, 037fh jz Intel487_SX_Math_CoProcessor_present ;ax=037fh jmp Intel486_SX_microprocessor_present ;ax=ffffh

If the Intel 487 SX math coprocessor is not present, the following code can be run to set the CR0 register for the Intel486 SX processor.

mov eax, cr0 and eax, fffffffdh ;make MP=0 or eax, 0024h ;make EM=1, NE=1 mov cr0, eax

This initialization will cause any floating-point instruction to generate a device not available exception (#NH), interrupt 7. The software emulation will then take control to execute these instructions. This code is not required if an Intel 487 SX math coprocessor is present in the system. In that case, the typical initialization routine for the Intel486 SX microprocessor will be adequate.

Also, when designing an Intel486 SX processor based system with an Intel 487 SX math coprocessor, timing loops should be independent of clock speed and clocks per instruction. One way to attain this is to implement these loops in hardware and not in software (for example, BIOS).

EM MP Interpretation

Page 784 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 784 · click to enlarge
Page 784

ARCHITECTURE COMPATIBILITY

19.21 CONTROL REGISTERS

The following sections identify the new control registers and control register flags and fields that were introduced to the 32-bit IA-32 in various processor families. See Figure 2-6 for the location of these flags and fields in the control registers.

The Pentium III processor introduced one new control flag in control register CR4: • OSXMMEXCPT (bit 10) — The OS will set this bit if it supports unmasked SIMD floating-point exceptions.

The Pentium II processor introduced one new control flag in control register CR4: • OSFXSR (bit 9) — The OS supports saving and restoring the Pentium III processor state during context switches.

  • The Pentium Pro processor introduced three new control flags in control register CR4:
  • PAE (bit 5) — Physical address extension. Enables paging mechanism to reference extended physical addresses when set; restricts physical addresses to 32 bits when clear (see also: Section 19.22.1.1, “Physical Memory Addressing Extension”).
  • PGE (bit 7) — Page global enable. Inhibits flushing of frequently-used or shared pages on CR3 writes (see also: Section 19.22.1.2, “Global Pages”).
  • PCE (bit 8) — Performance-monitoring counter enable. Enables execution of the RDPMC instruction at any protection level.

The content of CR4 is 0H following a hardware reset.

  • Control register CR4 was introduced in the Pentium processor. This register contains flags that enable certain new extensions provided in the Pentium processor:
  • VME — Virtual-8086 mode extensions. Enables support for a virtual interrupt flag in virtual-8086 mode (see Section 17.3, “Interrupt and Exception Handling in Virtual-8086 Mode”).
  • PVI — Protected-mode virtual interrupts. Enables support for a virtual interrupt flag in protected mode (see Section 17.4, “Protected-Mode Virtual Interrupts”).
  • TSD — Time-stamp disable. Restricts the execution of the RDTSC instruction to procedures running at privileged level 0.
  • DE — Debugging extensions. Causes an undefined opcode (#UD) exception to be generated when debug registers DR4 and DR5 are references for improved performance (see Section 19.23.3, “Debug Registers DR4 and DR5”).
  • PSE — Page size extensions. Enables 4-MByte pages with 32-bit paging when set (see Section 4.3, “32-Bit Paging”).
  • MCE — Machine-check enable. Enables the machine-check exception, allowing exception handling for certain hardware error conditions (see Chapter 15, “Machine-Check Architecture”).

The Intel486 processor introduced five new flags in control register CR0:

Page 785 of the Intel 253668-032US user manual — 19.22.1 New Memory Management Control Flags
Page 785 · click to enlarge
Page 785

ARCHITECTURE COMPATIBILITY

  • NE — Numeric error. Enables the normal mechanism for reporting floating-point numeric errors.
  • WP — Write protect. Write-protects read-only pages against supervisor-mode accesses.
  • AM — Alignment mask. Controls whether alignment checking is performed. Operates in conjunction with the AC (Alignment Check) flag.
  • NW — Not write-through. Enables write-throughs and cache invalidation cycles when clear and disables invalidation cycles and write-throughs that hit in the cache when set.
  • CD — Cache disable. Enables the internal cache when clear and disables the cache when set.
  • The Intel486 processor introduced two new flags in control register CR3:
  • PCD — Page-level cache disable. The state of this flag is driven on the PCD# pin during bus cycles that are not paged, such as interrupt acknowledge cycles, when paging is enabled. The PCD# pin is used to control caching in an external cache on a cycle-by-cycle basis.
  • PWT — Page-level write-through. The state of this flag is driven on the PWT# pin during bus cycles that are not paged, such as interrupt acknowledge cycles, when paging is enabled. The PWT# pin is used to control write through in an external cache on a cycle-by-cycle basis.

19.22 MEMORY MANAGEMENT FACILITIES

The following sections describe the new memory management facilities available in the various IA-32 processors and some compatibility differences.

19.22.1 New Memory Management Control Flags

The Pentium Pro processor introduced three new memory management features: physical memory addressing extension, the global bit in page-table entries, and general support for larger page sizes. These features are only available when oper ating in protected mode.

19.22.1.1 Physical Memory Addressing Extension

The new PAE (physical address extension) flag in control register CR4, bit 5, may enable additional address lines on the processor, allowing extended physical addresses. This option can only be used when paging is enabled, using a new page- table mechanism provided to support the larger physical address range (see Section 4.1, “Paging Modes and Control Bits”).

Page 786 of the Intel 253668-032US user manual — 19.22.3 Descriptor Types and Contents
Page 786 · click to enlarge
Page 786

ARCHITECTURE COMPATIBILITY

19.22.1.2 Global Pages

The new PGE (page global enable) flag in control register CR4, bit 7, provides a mechanism for preventing frequently used pages from being flushed from the trans lation lookaside buffer (TLB). When this flag is set, frequently used pages (such as pages containing kernel procedures or common data tables) can be marked global by setting the global flag in a page-directory or page-table entry.

On a task switch or a write to control register CR3 (which normally causes the TLBs to be flushed), the entries in the TLB marked global are not flushed. Marking pages global in this manner prevents unnecessary reloading of the TLB due to TLB misses on frequently used pages. See Section 4.10, “Caching Translation Information” for a detailed description of this mechanism.

19.22.1.3 Larger Page Sizes

The P6 family processors support large page sizes. For 32-bit paging, this facility is enabled with the PSE (page size extension) flag in control register CR4, bit 4. When this flag is set, the processor supports either 4-KByte or 4-MByte page sizes. PAE paging and IA-32e paging support 2-MByte pages regardless of the value of CR4.PSE (see Section 4.4, “PAE Paging” and Section 4.5, “IA-32e Paging”). See Chapter 4, “Paging,” for more information about large page sizes.

19.22.2 CD and NW Cache Control Flags

The CD and NW flags in control register CR0 were introduced in the Intel486 processor. In the P6 family and Pentium processors, these flags are used to imple ment a writeback strategy for the data cache; in the Intel486 processor, they imple ment a write-through strategy. See Table 11-5 for a comparison of these bits on the P6 family, Pentium, and Intel486 processors. For complete information on caching, see Chapter 11, “Memory Cache Control.”

19.22.3 Descriptor Types and Contents

Operating-system code that manages space in descriptor tables often contains an invalid value in the access-rights field of descriptor-table entries to identify unused entries. Access rights values of 80H and 00H remain invalid for the P6 family, Pentium, Intel486, Intel386, and Intel 286 processors. Other values that were invalid on the Intel 286 processor may be valid on the 32-bit processors because uses for these bits have been defined.

Page 787 of the Intel 253668-032US user manual — 19.23.3 Debug Registers DR4 and DR5
Page 787 · click to enlarge
Page 787

ARCHITECTURE COMPATIBILITY

19.22.4 Changes in Segment Descriptor Loads

On the Intel386 processor, loading a segment descriptor always causes a locked read and write to set the accessed bit of the descriptor. On the P6 family, Pentium, and Intel486 processors, the locked read and write occur only if the bit is not already set.

19.23 DEBUG FACILITIES

The P6 family and Pentium processors include extensions to the Intel486 processor debugging support for breakpoints. To use the new breakpoint features, it is neces sary to set the DE flag in control register CR4.

19.23.1 Differences in Debug Register DR6

It is not possible to write a 1 to reserved bit 12 in debug status register DR6 on the P6 family and Pentium processors; however, it is possible to write a 1 in this bit on the Intel486 processor. See Table 9-1 for the different setting of this register following a power-up or hardware reset.

19.23.2 Differences in Debug Register DR7

The P6 family and Pentium processors determines the type of breakpoint access by the R/W0 through R/W3 fields in debug control register DR7 as follows:

00 Break on instruction execution only.

01 Break on data writes only.

10 Undefined if the DE flag in control register CR4 is cleared; break on I/O reads or writes but not instruction fetches if the DE flag in control register CR4 is set.

11 Break on data reads or writes but not instruction fetches.

On the P6 family and Pentium processors, reserved bits 11, 12, 14 and 15 are hard- wired to 0. On the Intel486 processor, however, bit 12 can be set. See Table 9-1 for the different settings of this register following a power-up or hardware reset.

19.23.3 Debug Registers DR4 and DR5

Although the DR4 and DR5 registers are documented as reserved, previous genera tions of processors aliased references to these registers to debug registers DR6 and DR7, respectively. When debug extensions are not enabled (the DE flag in control register CR4 is cleared), the P6 family and Pentium processors remain compatible with existing software by allowing these aliased references. When debug extensions

Page 788 of the Intel 253668-032US user manual — 19.25 EXCEPTIONS AND/OR EXCEPTION CONDITIONS
Page 788 · click to enlarge
Page 788

ARCHITECTURE COMPATIBILITY

are enabled (the DE flag is set), attempts to reference registers DR4 or DR5 will result in an invalid-opcode exception (#UD).

19.24 RECOGNITION OF BREAKPOINTS

For the Pentium processor, it is recommended that debuggers execute the LGDT instruction before returning to the program being debugged to ensure that break points are detected. This operation does not need to be performed on the P6 family, Intel486, or Intel386 processors.

The implementation of test registers on the Intel486 processor used for testing the cache and TLB has been redesigned using MSRs on the P6 family and Pentium processors. (Note that MSRs used for this function are different on the P6 family and Pentium processors.) The MOV to and from test register instructions generate invalid-opcode exceptions (#UD) on the P6 family processors.

19.25 EXCEPTIONS AND/OR EXCEPTION CONDITIONS

This section describes the new exceptions and exception conditions added to the 32- bit IA-32 processors and implementation differences in existing exception handling. See Chapter 6, “Interrupt and Exception Handling,” for a detailed description of the IA-32 exceptions.

The Pentium III processor introduced new state with the XMM registers. Computations involving data in these registers can produce exceptions. A new MXCSR control/status register is used to determine which exception or exceptions have occurred. When an exception associated with the XMM registers occurs, an interrupt is generated. • SIMD floating-point exception (#XF, interrupt 19) — New exceptions associated with the SIMD floating-point registers and resulting computations.

No new exceptions were added with the Pentium Pro and Pentium II processors. The set of available exceptions is the same as for the Pentium processor. However, the following exception condition was added to the IA-32 with the Pentium Pro processor: • Machine-check exception (#MC, interrupt 18) — New exception conditions. Many exception conditions have been added to the machine-check exception and a new architecture has been added for handling and reporting on hardware errors. See Chapter 15, “Machine-Check Architecture,” for a detailed description of the new conditions.

The following exceptions and/or exception conditions were added to the IA-32 with the Pentium processor: • Machine-check exception (#MC, interrupt 18) — New exception. This exception reports parity and other hardware errors. It is a model-specific exception and

Page 789 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 789 · click to enlarge
Page 789

ARCHITECTURE COMPATIBILITY

  • may not be implemented or implemented differently in future processors. The MCE flag in control register CR4 enables the machine-check exception. When this bit is clear (which it is at reset), the processor inhibits generation of the machinecheck exception.
  • General-protection exception (#GP, interrupt 13) — New exception condition added. An attempt to write a 1 to a reserved bit position of a special register causes a general-protection exception to be generated.
  • Page-fault exception (#PF, interrupt 14) — New exception condition added. When a 1 is detected in any of the reserved bit positions of a page-table entry, pagedirectory entry, or page-directory pointer during address translation, a page-fault exception is generated.

The following exception was added to the Intel486 processor: • Alignment-check exception (#AC, interrupt 17) — New exception. Reports unaligned memory references when alignment checking is being performed.

The following exceptions and/or exception conditions were added to the Intel386 processor: • Divide-error exception (#DE, interrupt 0)

— Change in exception handling. Divide-error exceptions on the Intel386 processors always leave the saved CS:IP value pointing to the instruction that failed. On the 8086 processor, the CS:IP value points to the next instruction.

  • — Change in exception handling. The Intel386 processors can generate the largest negative number as a quotient for the IDIV instruction (80H and 8000H). The 8086 processor generates a divide-error exception instead.
  • Invalid-opcode exception (#UD, interrupt 6) — New exception condition added. Improper use of the LOCK instruction prefix can generate an invalid-opcode exception.
  • Page-fault exception (#PF, interrupt 14) — New exception condition added. If paging is enabled in a 16-bit program, a page-fault exception can be generated as follows. Paging can be used in a system with 16-bit tasks if all tasks use the same page directory. Because there is no place in a 16-bit TSS to store the PDBR register, switching to a 16-bit task does not change the value of the PDBR register. Tasks ported from the Intel 286 processor should be given 32-bit TSSs so they can make full use of paging.
  • General-protection exception (#GP, interrupt 13) — New exception condition added. The Intel386 processor sets a limit of 15 bytes on instruction length. The only way to violate this limit is by putting redundant prefixes before an instruction. A general-protection exception is generated if the limit on instruction length is violated. The 8086 processor has no instruction length limit.
Page 790 of the Intel 253668-032US user manual — 19.26.2 NMI Interrupts
Page 790 · click to enlarge
Page 790

ARCHITECTURE COMPATIBILITY

19.25.1 Machine-Check Architecture

The Pentium Pro processor introduced a new architecture to the IA-32 for handling and reporting on machine-check exceptions. This machine-check architecture (described in detail in Chapter 15, “Machine-Check Architecture”) greatly expands the ability of the processor to report on internal hardware errors.

19.25.2 Priority OF Exceptions

The priority of exceptions are broken down into several major categories:

1. Traps on the previous instruction
2. External interrupts
3. Faults on fetching the next instruction
4. Faults in decoding the next instruction
5. Faults on executing an instruction

There are no changes in the priority of these major categories between the different processors, however, exceptions within these categories are implementation depen dent and may change from processor to processor.

19.26 INTERRUPTS

The following differences in handling interrupts are found among the IA-32 processors.

19.26.1 Interrupt Propagation Delay

External hardware interrupts may be recognized on different instruction boundaries on the P6 family, Pentium, Intel486, and Intel386 processors, due to the superscaler designs of the P6 family and Pentium processors. Therefore, the EIP pushed onto the stack when servicing an interrupt may be different for the P6 family, Pentium, Intel486, and Intel386 processors.

19.26.2 NMI Interrupts

After an NMI interrupt is recognized by the P6 family, Pentium, Intel486, Intel386, and Intel 286 processors, the NMI interrupt is masked until the first IRET instruction is executed, unlike the 8086 processor.

Page 791 of the Intel 253668-032US user manual — 19.27.1 Software Visible Differences Between the Local APIC and the 82489DX
Page 791 · click to enlarge
Page 791

ARCHITECTURE COMPATIBILITY

19.26.3 IDT Limit

The LIDT instruction can be used to set a limit on the size of the IDT. A double-fault exception (#DF) is generated if an interrupt or exception attempts to read a vector beyond the limit. Shutdown then occurs on the 32-bit IA-32 processors if the double- fault handler vector is beyond the limit. (The 8086 processor does not have a shut down mode nor a limit.)

19.27 ADVANCED PROGRAMMABLE INTERRUPT CONTROLLER (APIC)

The Advanced Programmable Interrupt Controller (APIC), referred to in this book as the local APIC, was introduced into the IA-32 processors with the Pentium processor (beginning with the 735/90 and 815/100 models) and is included in the Pentium 4, Intel Xeon, and P6 family processors. The features and functions of the local APIC are derived from the Intel 82489DX external APIC, which was used with the Intel486 and early Pentium processors. Additional refinements of the local APIC architecture were incorporated in the Pentium 4 and Intel Xeon processors.

19.27.1 Software Visible Differences Between the Local APIC and the 82489DX

  • The following features in the local APIC features differ from those found in the 82489DX external APIC:
  • When the local APIC is disabled by clearing the APIC software enable/disable flag in the spurious-interrupt vector MSR, the state of its internal registers are unaffected, except that the mask bits in the LVT are all set to block local interrupts to the processor. Also, the local APIC ceases accepting IPIs except for INIT, SMI, NMI, and start-up IPIs. In the 82489DX, when the local unit is disabled, all the internal registers including the IRR, ISR and TMR are cleared and the mask bits in the LVT are set. In this state, the 82489DX local unit will accept only the reset deassert message.
  • In the local APIC, NMI and INIT (except for INIT deassert) are always treated as edge triggered interrupts, even if programmed otherwise. In the 82489DX, these interrupts are always level triggered.
  • In the local APIC, IPIs generated through the ICR are always treated as edge triggered (except INIT Deassert). In the 82489DX, the ICR can be used to generate either edge or level triggered IPIs.
  • In the local APIC, the logical destination register supports 8 bits; in the 82489DX, it supports 32 bits.
  • In the local APIC, the APIC ID register is 4 bits wide; in the 82489DX, it is 8 bits wide.
Page 792 of the Intel 253668-032US user manual — 19.28 TASK SWITCHING AND TSS
Page 792 · click to enlarge
Page 792

ARCHITECTURE COMPATIBILITY

  • The remote read delivery mode provided in the 82489DX and local APIC for Pentium processors is not supported in the local APIC in the Pentium 4, Intel Xeon, and P6 family processors.
  • For the 82489DX, in the lowest priority delivery mode, all the target local APICs specified by the destination field participate in the lowest priority arbitration. For the local APIC, only those local APICs which have free interrupt slots will participate in the lowest priority arbitration.

19.27.2 New Features Incorporated in the Local APIC for the P6 Family and Pentium Processors

  • The local APIC in the Pentium and P6 family processors have the following new features not found in the 82489DX external APIC.
  • Cluster addressing is supported in logical destination mode.
  • Focus processor checking can be enabled/disabled.
  • Interrupt input signal polarity can be programmed for the LINT0 and LINT1 pins.
  • An SMI IPI is supported through the ICR and I/O redirection table.
  • An error status register is incorporated into the LVT to log and report APIC errors.

In the P6 family processors, the local APIC incorporates an additional LVT register to handle performance monitoring counter interrupts.

19.27.3 New Features Incorporated in the Local APIC of the Pentium 4 and Intel Xeon Processors

  • The local APIC in the Pentium 4 and Intel Xeon processors has the following new features not found in the P6 family and Pentium processors and in the 82489DX.
  • The local APIC ID is extended to 8 bits.
  • An thermal sensor register is incorporated into the LVT to handle thermal sensor interrupts.
  • The the ability to deliver lowest-priority interrupts to a focus processor is no longer supported.
  • The flat cluster logical destination mode is not supported.

19.28 TASK SWITCHING AND TSS

This section identifies the implementation differences of task switching, additions to the TSS and the handling of TSSs and TSS segment selectors.

Page 793 of the Intel 253668-032US user manual — 19.28.5 Differences in I/O Map Base Addresses
Page 793 · click to enlarge
Page 793

ARCHITECTURE COMPATIBILITY

19.28.1 P6 Family and Pentium Processor TSS

When the virtual mode extensions are enabled (by setting the VME flag in control register CR4), the TSS in the P6 family and Pentium processors contain an interrupt redirection bit map, which is used in virtual-8086 mode to redirect interrupts back to an 8086 program.

19.28.2 TSS Selector Writes

During task state saves, the Intel486 processor writes 2-byte segment selectors into a 32-bit TSS, leaving the upper 16 bits undefined. For performance reasons, the P6 family and Pentium processors write 4-byte segment selectors into the TSS, with the upper 2 bytes being 0. For compatibility reasons, code should not depend on the value of the upper 16 bits of the selector in the TSS.

19.28.3 Order of Reads/Writes to the TSS

The order of reads and writes into the TSS is processor dependent. The P6 family and Pentium processors may generate different page-fault addresses in control register CR2 in the same TSS area than the Intel486 and Intel386 processors, if a TSS crosses a page boundary (which is not recommended).

19.28.4 Using A 16-Bit TSS with 32-Bit Constructs

Task switches using 16-bit TSSs should be used only for pure 16-bit code. Any new code written using 32-bit constructs (operands, addressing, or the upper word of the EFLAGS register) should use only 32-bit TSSs. This is due to the fact that the 32-bit processors do not save the upper 16 bits of EFLAGS to a 16-bit TSS. A task switch back to a 16-bit task that was executing in virtual mode will never re-enable the virtual mode, as this flag was not saved in the upper half of the EFLAGS value in the TSS. Therefore, it is strongly recommended that any code using 32-bit constructs use a 32-bit TSS to ensure correct behavior in a multitasking environment.

19.28.5 Differences in I/O Map Base Addresses

The Intel486 processor considers the TSS segment to be a 16-bit segment and wraps around the 64K boundary. Any I/O accesses check for permission to access this I/O address at the I/O base address plus the I/O offset. If the I/O map base address exceeds the specified limit of 0DFFFH, an I/O access will wrap around and obtain the permission for the I/O address at an incorrect location within the TSS. A TSS limit violation does not occur in this situation on the Intel486 processor. However, the P6 family and Pentium processors consider the TSS to be a 32-bit segment and a limit violation occurs when the I/O base address plus the I/O offset is greater than the TSS limit. By following the recommended specification for the I/O base address to be less

Page 794 of the Intel 253668-032US user manual — 19.29 CACHE MANAGEMENT
Page 794 · click to enlarge
Page 794

ARCHITECTURE COMPATIBILITY

than 0DFFFH, the Intel486 processor will not wrap around and access incorrect loca tions within the TSS for I/O port validation and the P6 family and Pentium processors will not experience general-protection exceptions (#GP). Figure 19-1 demonstrates the different areas accessed by the Intel486 and the P6 family and Pentium processors.

P6 family and Pentium Processors

FFFFH + 10H = Outside Segment for I/O Validation

FFFFH

FFFFH

FFFFH I/O Map Base Addres

I/O Map Base Addres

FFFFH

FFFFH + 10H = FH

0H

0H

I/O access at port 10H checks bitmap at I/O map base address FFFFH + 10H = offset 10H. Offset FH from beginning of TSS segment results because

I/O access at port 10H checks

bitmap at I/O address FFFFH + 10H, which exceeds segment limit. Wrap around does not occur, general-protection exception (#GP)

occurs. wraparound occurs.

Figure 19-1. I/O Map Base Address Differences

19.29 CACHE MANAGEMENT

The P6 family processors include two levels of internal caches: L1 (level 1) and L2 (level 2). The L1 cache is divided into an instruction cache and a data cache; the L2 cache is a general-purpose cache. See Section 11.1, “Internal Caches, TLBs, and Buffers,” for a description of these caches. (Note that although the Pentium II processor L2 cache is physically located on a separate chip in the cassette, it is considered an internal cache.)

The Pentium processor includes separate level 1 instruction and data caches. The data cache supports a writeback (or alternatively write-through, on a line by line basis) policy for memory updates.

The Intel486 processor includes a single level 1 cache for both instructions and data.

The meaning of the CD and NW flags in control register CR0 have been redefined for the P6 family and Pentium processors. For these processors, the recommended value (00B) enables writeback for the data cache of the Pentium processor and for the L1

Intel486 Processor · for I/O Validation

Page 795 of the Intel 253668-032US user manual — NOTE
Page 795 · click to enlarge
Page 795

ARCHITECTURE COMPATIBILITY

data cache and L2 cache of the P6 family processors. In the Intel486 processor, setting these flags to (00B) enables write-through for the cache.

External system hardware can force the Pentium processor to disable caching or to use the write-through cache policy should that be required. In the P6 family proces sors, the MTRRs can be used to override the CD and NW flags (see Table 11-6).

The P6 family and Pentium processors support page-level cache management in the same manner as the Intel486 processor by using the PCD and PWT flags in control register CR3, the page-directory entries, and the page-table entries. The Intel486 processor, however, is not affected by the state of the PWT flag since the internal cache of the Intel486 processor is a write-through cache.

19.29.1 Self-Modifying Code with Cache Enabled

On the Intel486 processor, a write to an instruction in the cache will modify it in both the cache and memory. If the instruction was prefetched before the write, however, the old version of the instruction could be the one executed. To prevent this problem, it is necessary to flush the instruction prefetch unit of the Intel486 processor by coding a jump instruction immediately after any write that modifies an instruction. The P6 family and Pentium processors, however, check whether a write may modify an instruction that has been prefetched for execution. This check is based on the linear address of the instruction. If the linear address of an instruction is found to be present in the prefetch queue, the P6 family and Pentium processors flush the prefetch queue, eliminating the need to code a jump instruction after any writes that modify an instruction.

Because the linear address of the write is checked against the linear address of the instructions that have been prefetched, special care must be taken for self-modifying code to work correctly when the physical addresses of the instruction and the written data are the same, but the linear addresses differ. In such cases, it is necessary to execute a serializing operation to flush the prefetch queue after the write and before executing the modified instruction. See Section 8.3, “Serializing Instructions,” for more information on serializing instructions.

NOTE

The check on linear addresses described above is not in practice a concern for compatibility. Applications that include self-modifying code use the same linear address for modifying and fetching the instruction. System software, such as a debugger, that might possibly modify an instruction using a different linear address than that used to fetch the instruction must execute a serializing operation, such as IRET, before the modified instruction is executed.

Page 796 of the Intel 253668-032US user manual — 19.30.2 PCD and PWT Flags
Page 796 · click to enlarge
Page 796

ARCHITECTURE COMPATIBILITY

19.29.2 Disabling the L3 Cache

A unified third-level (L3) cache in processors based on Intel NetBurst microarchitec ture (see Section 11.1, “Internal Caches, TLBs, and Buffers”) provides the third-level cache disable flag, bit 6 of the IA32_MISC_ENABLE MSR. The third-level cache disable flag allows the L3 cache to be disabled and enabled, independently of the L1 and L2 caches (see Section 11.5.4, “Disabling and Enabling the L3 Cache”). The third-level cache disable flag applies only to processors based on Intel NetBurst microarchitecture. Processors with L3 and based on other microarchitectures do not support the third-level cache disable flag.

19.30 PAGING

This section identifies enhancements made to the paging mechanism and implemen tation differences in the paging mechanism for various IA-32 processors.

19.30.1 Large Pages

The Pentium processor extended the memory management/paging facilities of the IA-32 to allow large (4 MBytes) pages sizes (see Section 4.3, “32-Bit Paging”). The first P6 family processor (the Pentium Pro processor) added a 2 MByte page size to the IA-32 in conjunction with the physical address extension (PAE) feature (see Section 4.4, “PAE Paging”).

The availability of large pages with 32-bit paging on any IA-32 processor can be determined via feature bit 3 (PSE) of register EDX after the CPUID instruction has been execution with an argument of 1. (Large pages are always available with PAE paging and IA-32e paging.) Intel processors that do not support the CPUID instruc tion support only 32-bit paging and do not support page size enhancements. (See “CPUID—CPU Identification” in Chapter 3, “Instruction Set Reference, A-M,” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2A, and AP- 485, Intel Processor Identification and the CPUID Instruction, for more information on the CPUID instruction.)

19.30.2 PCD and PWT Flags

  • The PCD and PWT flags were introduced to the IA-32 in the Intel486 processor to control the caching of pages:
  • PCD (page-level cache disable) flag—Controls caching on a page-by-page basis.
  • PWT (page-level write-through) flag—Controls the write-through/writeback caching policy on a page-by-page basis. Since the internal cache of the Intel486 processor is a write-through cache, it is not affected by the state of the PWT flag.
Page 797 of the Intel 253668-032US user manual — 19.31.1 Selector Pushes and Pops
Page 797 · click to enlarge
Page 797

ARCHITECTURE COMPATIBILITY

19.30.3 Enabling and Disabling Paging

Paging is enabled and disabled by loading a value into control register CR0 that modi fies the PG flag. For backward and forward compatibility with all IA-32 processors, Intel recommends that the following operations be performed when enabling or disabling paging:

1. Execute a MOV CR0, REG instruction to either set (enable paging) or clear (disable paging) the PG flag.
2. Execute a near JMP instruction.

The sequence bounded by the MOV and JMP instructions should be identity mapped (that is, the instructions should reside on a page whose linear and physical addresses are identical).

For the P6 family processors, the MOV CR0, REG instruction is serializing, so the jump operation is not required. However, for backwards compatibility, the JMP instruction should still be included.

19.31 STACK OPERATIONS

This section identifies the differences in the stack mechanism for the various IA-32 processors.

19.31.1 Selector Pushes and Pops

When pushing a segment selector onto the stack, the Pentium 4, Intel Xeon, P6 family, and Intel486 processors decrement the ESP register by the operand size and then write 2 bytes. If the operand size is 32-bits, the upper two bytes of the write are not modified. The Pentium processor decrements the ESP register by the operand size and determines the size of the write by the operand size. If the operand size is 32-bits, the upper two bytes are written as 0s.

When popping a segment selector from the stack, the Pentium 4, Intel Xeon, P6 family, and Intel486 processors read 2 bytes and increment the ESP register by the operand size of the instruction. The Pentium processor determines the size of the read from the operand size and increments the ESP register by the operand size.

It is possible to align a 32-bit selector push or pop such that the operation generates an exception on a Pentium processor and not on an Pentium 4, Intel Xeon, P6 family, or Intel486 processor. This could occur if the third and/or fourth byte of the operation lies beyond the limit of the segment or if the third and/or fourth byte of the operation is locate on a non-present or inaccessible page.

  • For a POP-to-memory instruction that meets the following conditions:
  • The stack segment size is 16-bit.
  • Any 32-bit addressing form with the SIB byte specifying ESP as the base register.
Page 798 of the Intel 253668-032US user manual — 19.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gate
Page 798 · click to enlarge
Page 798

ARCHITECTURE COMPATIBILITY

  • The initial stack pointer is FFFCH (32-bit operand) or FFFEH (16-bit operand) and will wrap around to 0H as a result of the POP operation.

The result of the memory write is implementation-specific. For example, in P6 family processors, the result of the memory write is SS:0H plus any scaled index and displacement. In Pentium processors, the result of the memory write may be either a stack fault (real mode or protected mode with stack segment size of 64 KByte), or write to SS:10000H plus any scaled index and displacement (protected mode and stack segment size exceeds 64 KByte).

19.31.2 Error Code Pushes

The Intel486 processor implements the error code pushed on the stack as a 16-bit value. When pushed onto a 32-bit stack, the Intel486 processor only pushes 2 bytes and updates ESP by 4. The P6 family and Pentium processors’ error code is a full 32 bits with the upper 16 bits set to zero. The P6 family and Pentium processors, there fore, push 4 bytes and update ESP by 4. Any code that relies on the state of the upper 16 bits may produce inconsistent results.

19.31.3 Fault Handling Effects on the Stack

During the handling of certain instructions, such as CALL and PUSHA, faults may occur in different sequences for the different processors. For example, during far calls, the Intel486 processor pushes the old CS and EIP before a possible branch fault is resolved. A branch fault is a fault from a branch instruction occurring from a segment limit or access rights violation. If a branch fault is taken, the Intel486 and P6 family processors will have corrupted memory below the stack pointer. However, the ESP register is backed up to make the instruction restartable. The P6 family processors issue the branch before the pushes. Therefore, if a branch fault does occur, these processors do not corrupt memory below the stack pointer. This imple mentation difference, however, does not constitute a compatibility problem, as only values at or above the stack pointer are considered to be valid. Other operations that encounter faults may also corrupt memory below the stack pointer and this behavior may vary on different implementations.

19.31.4 Interlevel RET/IRET From a 16-Bit Interrupt or Call Gate

If a call or interrupt is made from a 32-bit stack environment through a 16-bit gate, only 16 bits of the old ESP can be pushed onto the stack. On the subsequent RET/IRET, the 16-bit ESP is popped but the full 32-bit ESP is updated since control is being resumed in a 32-bit stack environment. The Intel486 processor writes the SS selector into the upper 16 bits of ESP. The P6 family and Pentium processors write zeros into the upper 16 bits.

Page 799 of the Intel 253668-032US user manual — 19.33 SEGMENT AND ADDRESS WRAPAROUND
Page 799 · click to enlarge
Page 799

ARCHITECTURE COMPATIBILITY

19.32 MIXING 16AND 32-BIT SEGMENTS

The features of the 16-bit Intel 286 processor are an object-code compatible subset of those of the 32-bit IA-32 processors. The D (default operation size) flag in segment descriptors indicates whether the processor treats a code or data segment as a 16-bit or 32-bit segment; the B (default stack size) flag in segment descriptors indicates whether the processor treats a stack segment as a 16-bit or 32-bit segment.

The segment descriptors used by the Intel 286 processor are supported by the 32-bit IA-32 processors if the Intel-reserved word (highest word) of the descriptor is clear. On the 32-bit IA-32 processors, this word includes the upper bits of the base address and the segment limit.

The segment descriptors for data segments, code segments, local descriptor tables (there are no descriptors for global descriptor tables), and task gates are the same for the 16- and 32-bit processors. Other 16-bit descriptors (TSS segment, call gate, interrupt gate, and trap gate) are supported by the 32-bit processors.

The 32-bit processors also have descriptors for TSS segments, call gates, interrupt gates, and trap gates that support the 32-bit architecture. Both kinds of descriptors can be used in the same system.

  • For those segment descriptors common to both 16and 32-bit processors, clear bits in the reserved word cause the 32-bit processors to interpret these descriptors exactly as an Intel 286 processor does, that is:
  • Base Address — The upper 8 bits of the 32-bit base address are clear, which limits base addresses to 24 bits.
  • Limit — The upper 4 bits of the limit field are clear, restricting the value of the limit field to 64 KBytes.
  • Granularity bit — The G (granularity) flag is clear, indicating the value of the 16-bit limit is interpreted in units of 1 byte.
  • Big bit — In a data-segment descriptor, the B flag is clear in the segment descriptor used by the 32-bit processors, indicating the segment is no larger than 64 KBytes.
  • Default bit — In a code-segment descriptor, the D flag is clear, indicating 16-bit addressing and operands are the default. In a stack-segment descriptor, the D flag is clear, indicating use of the SP register (instead of the ESP register) and a 64-KByte maximum segment limit.

For information on mixing 16- and 32-bit code in applications, see Chapter 18, “Mixing 16-Bit and 32-Bit Code.”

19.33 SEGMENT AND ADDRESS WRAPAROUND

This section discusses differences in segment and address wraparound between the P6 family, Pentium, Intel486, Intel386, Intel 286, and 8086 processors.

Page 800 of the Intel 253668-032US user manual — 19.34 STORE BUFFERS AND MEMORY ORDERING
Page 800 · click to enlarge
Page 800

ARCHITECTURE COMPATIBILITY

19.33.1 Segment Wraparound

  • On the 8086 processor, an attempt to access a memory operand that crosses offset 65,535 or 0FFFFH or offset 0 (for example, moving a word to offset 65,535 or pushing a word when the stack pointer is set to 1) causes the offset to wrap around modulo 65,536 or 010000H. With the Intel 286 processor, any base and offset combi nation that addresses beyond 16 MBytes wraps around to the 1 MByte of the address space. The P6 family, Pentium, Intel486, and Intel386 processors in real-address mode generate an exception in these cases:
  • A general-protection exception (#GP) if the segment is a data segment (that is, if the CS, DS, ES, FS, or GS register is being used to address the segment).
  • A stack-fault exception (#SS) if the segment is a stack segment (that is, if the SS register is being used).

An exception to this behavior occurs when a stack access is data aligned, and the stack pointer is pointing to the last aligned piece of data that size at the top of the stack (ESP is FFFFFFFCH). When this data is popped, no segment limit violation occurs and the stack pointer will wrap around to 0.

The address space of the P6 family, Pentium, and Intel486 processors may wrap around at 1 MByte in real-address mode. An external A20M# pin forces wraparound if enabled. On Intel 8086 processors, it is possible to specify addresses greater than 1 MByte. For example, with a selector value FFFFH and an offset of FFFFH, the effec tive address would be 10FFEFH (1 MByte plus 65519 bytes). The 8086 processor, which can form addresses up to 20 bits long, truncates the uppermost bit, which “wraps” this address to FFEFH. However, the P6 family, Pentium, and Intel486 processors do not truncate this bit if A20M# is not enabled.

If a stack operation wraps around the address limit, shutdown occurs. (The 8086 processor does not have a shutdown mode or a limit.)

The behavior when executing near the limit of a 4-GByte selector (limit=0xFFFFFFFF) is different between the Pentium Pro and the Pentium 4 family of processors. On the Pentium Pro, instructions which cross the limit -- for example, a two byte instruction such as INC EAX that is encoded as 0xFF 0xC0 starting exactly at the limit faults for a segment violation (a one byte instruction at 0xFFFFFFFF does not cause an excep tion). Using the Pentium 4 microprocessor family, neither of these situations causes a fault.

Segment wraparound and the functionality of A20M# is used primarily by older oper ating systems and not used by modern operating systems. On newer Intel 64 proces sors, A20M# may be absent.

19.34 STORE BUFFERS AND MEMORY ORDERING

The Pentium 4, Intel Xeon, and P6 family processors provide a store buffer for temporary storage of writes (stores) to memory (see Section 11.10, “Store Buffer”). Writes stored in the store buffer(s) are always written to memory in program order,

Page 801 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 801 · click to enlarge
Page 801

ARCHITECTURE COMPATIBILITY

with the exception of “fast string” store operations (see Section 8.2.4, “Out-of-Order Stores For String Operations”).

The Pentium processor has two store buffers, one corresponding to each of the pipe lines. Writes in these buffers are always written to memory in the order they were generated by the processor core.

It should be noted that only memory writes are buffered and I/O writes are not. The Pentium 4, Intel Xeon, P6 family, Pentium, and Intel486 processors do not synchro nize the completion of memory writes on the bus and instruction execution after a write. An I/O, locked, or serializing instruction needs to be executed to synchronize writes with the next instruction (see Section 8.3, “Serializing Instructions”).

The Pentium 4, Intel Xeon, and P6 family processors use processor ordering to main tain consistency in the order that data is read (loaded) and written (stored) in a program and the order the processor actually carries out the reads and writes. With this type of ordering, reads can be carried out speculatively and in any order, reads can pass buffered writes, and writes to memory are always carried out in program order. (See Section 8.2, “Memory Ordering,” for more information about processor ordering.) The Pentium III processor introduced a new instruction to serialize writes and make them globally visible. Memory ordering issues can arise between a producer and a consumer of data. The SFENCE instruction provides a performance- efficient way of ensuring ordering between routines that produce weakly-ordered results and routines that consume this data.

No re-ordering of reads occurs on the Pentium processor, except under the condition noted in Section 8.2.1, “Memory Ordering in the Intel® Pentium® and Intel486™ Processors,” and in the following paragraph describing the Intel486 processor.

Specifically, the store buffers are flushed before the IN instruction is executed. No reads (as a result of cache miss) are reordered around previously generated writes sitting in the store buffers. The implication of this is that the store buffers will be flushed or emptied before a subsequent bus cycle is run on the external bus.

On both the Intel486 and Pentium processors, under certain conditions, a memory read will go onto the external bus before the pending memory writes in the buffer even though the writes occurred earlier in the program execution. A memory read will only be reordered in front of all writes pending in the buffers if all writes pending in the buffers are cache hits and the read is a cache miss. Under these conditions, the Intel486 and Pentium processors will not read from an external memory location that needs to be updated by one of the pending writes.

During a locked bus cycle, the Intel486 processor will always access external memory, it will never look for the location in the on-chip cache. All data pending in the Intel486 processor's store buffers will be written to memory before a locked cycle is allowed to proceed to the external bus. Thus, the locked bus cycle can be used for eliminating the possibility of reordering read cycles on the Intel486 processor. The Pentium processor does check its cache on a read-modify-write access and, if the cache line has been modified, writes the contents back to memory before locking the bus. The P6 family processors write to their cache on a read-modify-write operation (if the access does not split across a cache line) and does not write back to system

Page 802 of the Intel 253668-032US user manual — 19.37 MODEL-SPECIFIC EXTENSIONS TO THE IA-32
Page 802 · click to enlarge
Page 802

ARCHITECTURE COMPATIBILITY

memory. If the access does split across a cache line, it locks the bus and accesses system memory.

I/O reads are never reordered in front of buffered memory writes on an IA-32 processor. This ensures an update of all memory locations before reading the status from an I/O device.

19.35 BUS LOCKING

The Intel 286 processor performs the bus locking differently than the Intel P6 family, Pentium, Intel486, and Intel386 processors. Programs that use forms of memory locking specific to the Intel 286 processor may not run properly when run on later processors.

A locked instruction is guaranteed to lock only the area of memory defined by the destination operand, but may lock a larger memory area. For example, typical 8086 and Intel 286 configurations lock the entire physical memory space. Programmers should not depend on this.

On the Intel 286 processor, the LOCK prefix is sensitive to IOPL. If the CPL is greater than the IOPL, a general-protection exception (#GP) is generated. On the Intel386 DX, Intel486, and Pentium, and P6 family processors, no check against IOPL is performed.

The Pentium processor automatically asserts the LOCK# signal when acknowledging external interrupts. After signaling an interrupt request, an external interrupt controller may use the data bus to send the interrupt vector to the processor. After receiving the interrupt request signal, the processor asserts LOCK# to insure that no other data appears on the data bus until the interrupt vector is received. This bus locking does not occur on the P6 family processors.

19.36 BUS HOLD

Unlike the 8086 and Intel 286 processors, but like the Intel386 and Intel486 proces sors, the P6 family and Pentium processors respond to requests for control of the bus from other potential bus masters, such as DMA controllers, between transfers of parts of an unaligned operand, such as two words which form a doubleword. Unlike the Intel386 processor, the P6 family, Pentium and Intel486 processors respond to bus hold during reset initialization.

19.37 MODEL-SPECIFIC EXTENSIONS TO THE IA-32

Certain extensions to the IA-32 are specific to a processor or family of IA-32 proces sors and may not be implemented or implemented in the same way in future proces

Page 803 of the Intel 253668-032US user manual — 19.37.3 Memory Type Range Registers
Page 803 · click to enlarge
Page 803

ARCHITECTURE COMPATIBILITY

sors. The following sections describe these model-specific extensions. The CPUID instruction indicates the availability of some of the model-specific features.

19.37.1 Model-Specific Registers

The Pentium processor introduced a set of model-specific registers (MSRs) for use in controlling hardware functions and performance monitoring. To access these MSRs, two new instructions were added to the IA-32 architecture: read MSR (RDMSR) and write MSR (WRMSR). The MSRs in the Pentium processor are not guaranteed to be duplicated or provided in the next generation IA-32 processors.

The P6 family processors greatly increased the number of MSRs available to soft ware. See Appendix B, “Model-Specific Registers (MSRs),” for a complete list of the available MSRs. The new registers control the debug extensions, the performance counters, the machine-check exception capability, the machine-check architecture, and the MTRRs. These registers are accessible using the RDMSR and WRMSR instruc tions. Specific information on some of these new MSRs is provided in the following sections. As with the Pentium processor MSR, the P6 family processor MSRs are not guaranteed to be duplicated or provided in the next generation IA-32 processors.

19.37.2 RDMSR and WRMSR Instructions

The RDMSR (read model-specific register) and WRMSR (write model-specific register) instructions recognize a much larger number of model-specific registers in the P6 family processors. (See “RDMSR—Read from Model Specific Register” and “WRMSR—Write to Model Specific Register” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volumes 2A & 2B for more information.)

19.37.3 Memory Type Range Registers

Memory type range registers (MTRRs) are a new feature introduced into the IA-32 in the Pentium Pro processor. MTRRs allow the processor to optimize memory opera tions for different types of memory, such as RAM, ROM, frame buffer memory, and memory-mapped I/O.

MTRRs are MSRs that contain an internal map of how physical address ranges are mapped to various types of memory. The processor uses this internal memory map to determine the cacheability of various physical memory locations and the optimal method of accessing memory locations. For example, if a memory location is speci fied in an MTRR as write-through memory, the processor handles accesses to this location as follows. It reads data from that location in lines and caches the read data or maps all writes to that location to the bus and updates the cache to maintain cache coherency. In mapping the physical address space with MTRRs, the processor recog nizes five types of memory: uncacheable (UC), uncacheable, speculatable, write- combining (WC), write-through (WT), write-protected (WP), and writeback (WB).

Page 804 of the Intel 253668-032US user manual — 19.37.5 Performance-Monitoring Counters
Page 804 · click to enlarge
Page 804

ARCHITECTURE COMPATIBILITY

Earlier IA-32 processors (such as the Intel486 and Pentium processors) used the KEN# (cache enable) pin and external logic to maintain an external memory map and signal cacheable accesses to the processor. The MTRR mechanism simplifies hard ware designs by eliminating the KEN# pin and the external logic required to drive it.

See Chapter 9, “Processor Management and Initialization,” and Appendix B, “Model- Specific Registers (MSRs),” for more information on the MTRRs.

19.37.4 Machine-Check Exception and Architecture

The Pentium processor introduced a new exception called the machine-check excep tion (#MC, interrupt 18). This exception is used to detect hardware-related errors, such as a parity error on a read cycle.

The P6 family processors extend the types of errors that can be detected and that generate a machine-check exception. It also provides a new machine-check architec ture for recording information about a machine-check error and provides extended recovery capability.

The machine-check architecture provides several banks of reporting registers for recording machine-check errors. Each bank of registers is associated with a specific hardware unit in the processor. The primary focus of the machine checks is on bus and interconnect operations; however, checks are also made of translation lookaside buffer (TLB) and cache operations.

The machine-check architecture can correct some errors automatically and allow for reliable restart of instruction execution. It also collects sufficient information for soft ware to use in correcting other machine errors not corrected by hardware.

See Chapter 15, “Machine-Check Architecture,” for more information on the machine-check exception and the machine-check architecture.

19.37.5 Performance-Monitoring Counters

The P6 family and Pentium processors provide two performance-monitoring counters for use in monitoring internal hardware operations. The number of performance monitoring counters and associated programming interfaces may be implementation specific for Pentium 4 processors, Pentium M processors. Later processors may have implemented these as part of an architectural performance monitoring feature. The architectural and non-architectural performance monitoring interfaces for different processor families are described in Chapter 30, “Performance Monitoring,”. Appendix A, “Performance-Monitoring Events,” lists all the events that can be counted for architectural performance monitoring events and non-architectural events. The counters are set up, started, and stopped using two MSRs and the RDMSR and WRMSR instructions. For the P6 family processors, the current count for a particular counter can be read using the new RDPMC instruction.

Page 805 of the Intel 253668-032US user manual — 19.38 TWO WAYS TO RUN INTEL 286 PROCESSOR TASKS
Page 805 · click to enlarge
Page 805

ARCHITECTURE COMPATIBILITY

The performance-monitoring counters are useful for debugging programs, optimizing code, diagnosing system failures, or refining hardware designs. See Chapter 30, “Performance Monitoring,” for more information on these counters.

19.38 TWO WAYS TO RUN INTEL 286 PROCESSOR TASKS

  • When porting 16-bit programs to run on 32-bit IA-32 processors, there are two approaches to consider:
  • Porting an entire 16-bit software system to a 32-bit processor, complete with the old operating system, loader, and system builder. Here, all tasks will have 16-bit TSSs. The 32-bit processor is being used as if it were a faster version of the 16-bit processor.
  • Porting selected 16-bit applications to run in a 32-bit processor environment with a 32-bit operating system, loader, and system builder. Here, the TSSs used to represent 286 tasks should be changed to 32-bit TSSs. It is possible to mix 16 and 32-bit TSSs, but the benefits are small and the problems are great. All tasks in a 32-bit software system should have 32-bit TSSs. It is not necessary to change the 16-bit object modules themselves; TSSs are usually constructed by the operating system, by the loader, or by the system builder. See Chapter 18, “Mixing 16-Bit and 32-Bit Code,” for more detailed information about mixing 16-bit and 32-bit code.

Because the 32-bit processors use the contents of the reserved word of 16-bit segment descriptors, 16-bit programs that place values in this word may not run correctly on the 32-bit processors.

Page 806 of the Intel 253668-032US user manual — ARCHITECTURE COMPATIBILITY
Page 806 · click to enlarge
Page 806

ARCHITECTURE COMPATIBILITY

Display codes

Error codes

What the fault codes shown on the display mean and how to clear them.

CodeMeaningFix
IS0The source of the selector in an error code may be any of the following: p.265

Ask about the Intel 253668-032US

Owners and our team usually reply within a day — and your question helps the next person too.

Add your email to get notified when it’s answered — no spam, ever.

0 questions
No questions yet about the Intel 253668-032US

Be the first to ask — other owners or our team will answer.

Original document

Intel 253668-032US manual PDF

806 pages·5.7 MB·Webcam·PDF
Click any page above to open it here
Page 1 / …
100%
Loading pages…