Intel Microcode

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Intel microcode is microcode that runs inside x86 processors made by Intel. Since the P6 microarchitecture introduced in the mid-1990s, the microcode programs can be patched by the operating system or BIOS firmware to workaround bugs found in the CPU after release.[1] Intel had originally designed microcode updates for processor debugging under its design for testing (DFT) initiative.[2]

Following the Pentium FDIV bug the patchable microcode function took on a wider purpose to allow in-field updating without needing to do a product recall.[1]

In the P6 and later microarchitectures, lists of x86 instructions are internally converted into simpler RISC-style micro-operations that are specific to a particular processor and stepping level.[1]

Micro-operations[edit]

On the Pentium Pro, each micro-operation is 72-bits wide,[3]:43 or 118-bits wide.[4]:2[5]:14 This includes two source fields, and one destination field, with the ability to hold a 32-bit immediate value.[4][5]:14 The Pentium Pro is able to detect parity errors in its internal microcode ROM and report these via the Machine Check Architecture.[6]

Micro-operations have a consistent format with up to three source inputs, and two destination outputs.[7] The processor performs register renaming to map these inputs to and from the real register file (RRF) before and after their execution.[7] Out-of-order execution is used, so the micro-operations and instructions they represent may not appear in the same order.

During development of the Pentium Pro, several microcode fixes were included between the A2 and B0 steppings.[8] For the Pentium II (based on the P6 Pentium Pro), additional micro-operations were added to support the MMX instruction set.[9] In several cases, "microcode assists" were added to handle rare corner-cases in a reliable way.[9]

The Pentium 4 can have 126 micro-operations in flight at the same time.[10]:10 Micro-operations are decoded and stored in an Execution Trace Cache with 12,000 entries, to avoid repeated decoding of the same x86 instructions.[10]:5 Groups of six micro-operations are packed into a trace line.[10]:5 Complex instructions, such as exception handling, result in jumping to the microcode ROM.[10]:6 During development of the Pentium 4, microcode accounted for 14% of processor bugs versus 30% of processor bugs during development of the Pentium Pro.[11]:35

The Intel Core microarchitecture introduced in 2006 added "micro-operations fusion" for some common pairs of instructions including comparison followed by a jump.[12] The instruction decoders in the Core convert x86 instructions into microcode in three different ways:

Conversion of x86 instructions to micro-operations on Core[12]
x86 instructions x86 decoders micro-operations
common simple decoder × 3 1–3
most others complex decoder × 1 ≤4
very complex microcode sequencer many

For Intel's hyper-threading implementation of simultaneous multithreading, the microcode ROM, trace cache, and instruction decoders are shared, but the micro-operation queue is not shared.[13]

Update facility[edit]

In the mid-1990s, a facility for supplying new microcode was initially referred to as the Pentium Pro Stepping data file, and BIOS Update Feature. It was intended that user mode applications should make a BIOS interrupt call to supply a new "BIOS Update Data Block", which the BIOS would partially validate and save to nonvolatile BIOS memory, this could be supplied to the installed processors on next boot.[14]

Intel distributed a program called BUP_UTIL.EXE, renamed CHECKUP3.EXE that could be run under DOS. Collections of multiple microcode updates were concatencated together and numerically numbered with the extension .PDB, such as PEP6.PDB.[15]:79

Processor interface[edit]

The processor boots up using a set of microcode held inside the processor and stored in an internal ROM.[1] A microcode update populates a separate SRAM and set of "match registers" that act as breakpoints within the microcode ROM, to allow jumping to the updated list of micro-operations in the SRAM.[1] A match is performed between the Microcode Instruction Pointer (UIP) all of the match registers, with any match resulting in a jump to the corresponding destination microcode address.[2]:3 In the original P6 architecture there is space in the SRAM for 60 micro-operations, and multiple match/destination register pairs.[1][2]:3 It takes one processor instruction cycle to jump from ROM microcode to patched microcode held in SRAM.[1] Match registers consist of a microcode match address, and a microcode destination address.[16]

The processor must be in protection ring zero ("Ring 0") in order to initiate a microcode update.[16]:1 Each CPU in a symmetric multiprocessing arrangement needs to be updated individually.[16]:1

An update is initiated by placing its address in eax register, setting ecx = 0x79, and executing a wrmsr (Write model-specific register).[17]:435

Microcode update format[edit]

Intel distributes microcode updates as a 2,048 (2 kilobyte) binary blob.[1] The update contains information about which processors it is designed for, so that this can be checked against the result of the CPUID instruction.[1] The structure is a 48-byte header, followed by 2,000-bytes intended to be read directly by the processor to be updated:[1]

  1. a microcode program that is executed by the processor during the microcode update process.[1] This microcode is able to reconfigure and enable or disable components using a special register, and it must update the breakpoint match registers.[1]
  2. up to sixty patched micro-operations to be populated into the SRAM.[1]
  3. padding consisting of random values design to obfuscate understanding of the format of the microcode update.[1]

Each block is encoded differently, and the majority of the 2,000 bytes are not used as configuration program and SRAM micro-operation contents themselves are much smaller.[1] Final determination and validation of whether an update can be applied to a processor is performed during decryption via the processor.[14] Each microcode update is specific to a particular CPU revision, and is designed to be rejected by CPUs with a different stepping level. Microcode updates are encrypted to prevent tampering and to enable validation.[18]

With the Pentium there are two layers of encryption and the precise details explicitly not documented Intel, instead being only known to less than ten employees.[19]

Microcode updates for Intel Atom, Nehalem and Sandy Bridge additionally contain an extra 520-byte header containing a 2048-bit RSA modulus with an exponent of 17 decimal.[16]:7,8

Observed Intel microcode data-block lengths (in bytes)[16]:16
Micro architecture Example processors Supplied length Functional length Suspected encoding
P6 Pentium Pro 2000 864; 872; 944; 1968 64-bit block cipher
Core PIII … Core 2 4048 3096
Netburst P4, Pentium D, Celeron 2000–7120 2000 + N*1024 chained block cipher
Atom, Nehalem, Sandy Bridge Core i3/i5/i7 976–16336 976 + N*1024; 5120 AES + RSA signature

Debugging[edit]

Special debugging-specific microcode can be loaded to enable Extended Execution Trace, which then outputs extra information via the Breakpoint Monitor Pins.[20] On the Pentium 4, loading special microcode can give access to Microcode Extended Execution Trace mode.[20] When using the JTAG Test Access Port (TAP), a pair of Breakpoint Control registers allow breaking on microcode addresses.[20]

During the mid-1980s NEC and Intel had a long-running court case under Judge William Austin Ingram, and subsequently Judge William Percival Gray, about microcode copyright.[21] NEC had been acting as a second source for Intel 8086 CPUs with its NEC μPD8086, and held long-term patent and copyright cross-licensing agreements with Intel. In August 1982 Intel sued NEC for copyright infridgement over the microcode implementation.[22][23] NEC prevailed by demonstrating via cleanroom software engineering that the similiarites in the implementation of microcode on its V20 and V30 processors was the result of the restrictions demanded by the architecture, rather than via copying.[21]

The Intel 386 can perform a built-in self-test of the microcode and programmable logic arrays, with the value of the self-test placed in the EAXregister.[24] During the BIST, the microprogram counter is re-used to walk through all of the ROMs, with the results being collated via a network of multiple-input signature registers (MISRs) and linear-feedback shift registers.[25] On start up of the Intel 486, a hardware-controlled BIST runs for 220 clock cycles to check various arrays including the microcode ROM, after which control is transferred to the microcode for further self-testing of registers and computation units.[26] The Intel 486 microcode ROM has 250,000 transistors.[26]

AMD had a long-term contract to reuse Intel's 286, 386 and 486 microcode.[27] In October 2004, a court ruled that the agreement did not cover AMD distributing Intel's 486 in-circuit emulation (ICE) microcode.[27]

References[edit]

  1. ^ a b c d e f g h i j k l m n o Gwennap, Linley (15 September 1997). "P6 Microcode Can Be Patched" (PDF). Microprocessor Report. Archived from the original (PDF) on 21 December 2009. Retrieved 23 January 2018. Intel has implemented a microcode patch capability in its P6 processors, including Pentium Pro and Pentium II … allows the microcode to be altered after the processor is fabricated, repairing bugs that are found after the processor is designed. … originally intended the feature to be used only for debugging, but after dealing with the expense of the Pentium FDIV bug … Intel decided to make it usable in the field. … P6 chip contains a complete set of microcode in an internal ROM … BIOS writes a memory address into a special CPU register to trigger a download sequence … P6 processors contain a small SRAM that holds up to 60 microinstructions. The patch code is downloaded into this SRAM … also contains a set of "match" registers that cause a trap when a particular microcode address is encountered. (This is similar to the "instruction breakpoint" capability used to debug assembly code.) This trap, which takes a single cycle to process, vectors microcode execution into the patch RAM. … downloaded microcode consists of two segments. … first is an initialization routine that is run immediately … also initializes the match registers, if necessary. … second segment contains one or more patches that remain in the patch RAM during normal operation and are accessed via a match-register trap. … original microcode is stored in ROM, … match registers allow the operation of the microcode to be changed. In this way, an x86 instruction that is operating incorrectly can be repaired, assuming it is implemented in microcode. … a patch is created to replace a section of the original microcode, performing the correct operation and then jumping back. … number of match registers, … more than one. … single bug, … might require multiple patches, and some bugs are too complex to repair … mechanism could allow multiple bugs to be fixed, … features of the P6 processor can be disabled via a special register … 2,048-byte block of data. The block contains a 48-byte header—which includes a date code, the CPU ID (which includes the stepping level) of the target processor, and a checksum—and 2,000 bytes of data to be downloaded by the processor. … checksum … is not used by the CPU. … 2,000 data bytes are encrypted in a way that Intel claims will be extremely difficult to break. The bytes are divided into blocks of varying lengths, each of which is encoded differently. … typically much smaller than 2,000 bytes, the remaining data is random noise intended to confuse anyone attempting to break the encryption. … Intel has not published any information on the format of its microcode, … is deliberately designed to be difficult to understand. Only a small number of Intel employees know the P6 microcode formats.
  2. ^ a b c Yeoh Eng Hong; Lim Seong Leong; Wong Yik Choong; Lock Choon Hou; Mahmud Adnan (20 April 1998). Chao, Lin (ed.). "An Overview of Advanced Failure Analysis Techniques for Pentium® and Pentium® Pro Microprocessors" (PDF). Intel Technology Journal (Q2). Pentium Pro microprocessor … Micropatching DFT feature. … consists of two key elements: the microcode patch RAM and several pairs of Match and Destination registers. … Microcode Instruction Pointer (UIP) matches the content of a Match register, the UIP will be reloaded with a new address from the Destination register. … UIP for the reset subroutine can be set in the Match register … thereby bypassing the reset subroutine altogether.
  3. ^ Kubiatowicz, John (3 May 2004). "Dynamic Scheduling in P6 (Pentium Pro, II, III)" (PDF). Low Power Design, Advanced Intel Processors. CS152 Computer Architecture and Engineering (Lecture 25). Complex 80x86 instructions are executed by a conventional microprogram (8K x 72 bits) that issues long sequences of micro-operations
  4. ^ a b Gwennap, Linley (16 February 1995). "Intel's P6 Uses Decoupled Superscalar Design" (PDF). Microprocessor Report. 9 (2). MicroDesign Resources. pp. 1–7. P6 uops have a fixed length of 118 bits, using a regular structure to encode an operation, two sources, and a destination. The source and destination fields are each wide enough to contain a 32-bit operand.
  5. ^ a b Asanovic, Krste (2002). "P6 uops" (PDF). Microprocessor Evolution: 4004 to Pentium Pro (Spring): 14. Retrieved 23 January 2018. Each uop has fixed format of around 118 bits … – opcode, two sources, and destination … – sources and destination fields are 32-bits wide to hold immediate or operand
  6. ^ 16.6.1. Simple Error Codes (PDF). Machine Check Architecture (Report). Pentium® Pro Family Developer's Manual. 3: Operating System Writer's Guide. 3 January 1996. p. 401. Archived from the original on 6 September 2001. Retrieved 1 October 2018. unique codes indicate global error information … Microcode ROM Parity ErrorCS1 maint: unfit url (link)
  7. ^ a b Ronen, Ronny; Intel Labs (18 January 2005). Micro Operations (Uops) (PDF). The Pentium II/III Processor "Compiler on a Chip" (Report). Haifa: Tel Aviv University. pp. 26, 31, 32, 43, 44, 46. Archived from the original (PDF) on 16 April 2007. Retrieved 23 January 2018. Each "CISC" inst is broken into one or more uops … Canonical representation of src/dest (3 src, 2 dest) … e.g., pop eax becomes esp1<-esp0+4, eax1<-[esp0]ID: Convert instructions into uops. Buffers up to 6 uopsAlloc & RAT … able to work on up to 3 uops per clock … Reservation station (RS) … Pool of all "not yet executed" uops (up to 20) … In order Retirement: … Retires up to 3 uops per clock … OOO Cluster … Up to 5 resource-ready uops are selected, and dispatched per clock
  8. ^ Papworth, David B.; Intel Corporation (April 1996). "Tuning the Pentium Pro Microarchitecture" (PDF). IEEE Micro. p. 14. ISSN 0272-1732. Retrieved 8 October 2018. B0 stepping incorporated several microcode bugs and speed path fixes for problems discovered on the A-step silicon
  9. ^ a b Kagan, Michael; Gochman, Simcha; Orenstien, Doron; Lin, Derrick (1997). "MMX Microarchitecture of Pentium Processors With MMX Technology and Pentium II Microprocessors" (PDF). Intel Technology Journal (Q3): 6, 7. Pentium II processor's microarchitecture is similar to that of the Pentium Pro microprocessor … modified to convert the new MMX instructions to Pentium Pro processor-specific uops (new Single Instruction Multiple Data [SIMD] uops were added to implement the new functionality). … A microcode assist was created to correct the problem and redo the operation. An assist is a customer-invisible event that flushes out the machine and allows microcode to handle rare but difficult-to-handle problems. Since all MMX instructions zero the TOS, the assist needs to write the TOS to zero and restart the operation. … Illegal opcodes that are instruction holes in the MMX instruction opcode map are defined to generate a one uop assist call. This assist call instructs the ROB to flush the machine and causes an assist microcode flow to cause the processor to handle illegal opcode faults.
  10. ^ a b c d Hinton, Glenn; Sager, Dave; Upton, Mike; Boggs, Darrell; Carmean, Doug; Kyker, Alan; Roussel, Patrice (2001). Chao, Lin (ed.). "The Microarchitecture of the Pentium 4 Processor" (PDF). Intel Technology Journal (Q1). IA-32 instruction bytes are then decoded into basic operations called uops (micro-operations) … advanced form of a Level 1 (L1) instruction cache called the Execution Trace Cache … between the instruction decode logic and the execution core … to store the already decoded … uops. … instructions are decoded once … then used repeatedly from there … has a capacity to hold up to 12K uops … similar hit rate to an 8K to 16K byte conventional instruction cache. … packs the uops into groups of six uops per trace line … microcode ROM … for complex IA-32 instructions, such as string move, and for fault and interrupt handling … Trace Cache jumps into the microcode ROM which then issues the uops … After the microcode ROM finishes sequencing uops … front end of the machine resumes fetching uops from the Trace Cache. … deep buffering of the Pentium 4 processor (126 uops and 48 loads in flight)
  11. ^ Bentley, Bob; Gray, Rand (2001). Chao, Lin (ed.). "Validating The Intel® Pentium® 4 Processor" (PDF). Intel Technology Journal (Q1). p. 29–26. Bug Discussion
  12. ^ a b De Gelas, Johan (1 May 2006). "Intel Core versus AMD's K8 architecture". AnandTech. p. 3. Retrieved 23 January 2018. Core architecture is equipped with four x86 decoders, 3 simple decoders and 1 complex decoder … to translate the 1 to 15 byte variable length x86 instructions into … fixed length RISC-like instructions (called micro-ops). … common x86 instructions are translated into a single micro-op … complex decoder is responsible for the instructions that produce up to 4 micro-ops. … really long and complex x86 instructions are handled by a microcode sequencer. … macro-op fusion … the x86 compare instruction (CMP) is fused with a jump (JNE TARG).
  13. ^ Kim, Dongkeun; Shih-wei Liao, Steve; Wang, Perry H.; del Cuvillo, Juan; Tian, Xinmin; Zou, Xiang; Wang, Hong; Yeung, Donald; Girkar, Milind; Shen, John P. (11 January 2004). "Physical Experimentation with Prefetching Helper Threads on Intels Hyper-Threaded Processors" (PDF): 4, 5. Retrieved 24 January 2018. L1 Trace cache: 12K micro-ops, 8-way set associative, 6 micro-ops per line … Shared: Trace cache, … IA-32 instruction decode, Microcode ROM, Uop retirement logic, … Partitioned: Uop queue Cite journal requires |journal= (help)
  14. ^ a b Intel Corporation (12 January 1996). 8: Pentium Pro Processor BIOS Update Feature (PDF) (Report). 2.0. p. 45. Retrieved 1 October 2018. authentication procedure relies upon the decryption provided by the processor to verify an update from a potentially hostile sources.
  15. ^ Mueller, Scott; Zacker, Craig (September 1998). Minatel, Jim; Byus, Jill; Kughen, Rick (eds.). Upgrading and Repairing PCs (PDF) (Tenth Annivesary ed.). Que Publishing. p. 79. ISBN 0-7897-1636-4. Retrieved 1 October 2018. Processor Steppings (Revisions) and Microcode Update Revisions Supported by the Update Database File PEP6.PDB … Using the processor update utility (CHECKUP3.EXE), … can easily verify … the correct microcode update
  16. ^ a b c d e Chen, Daming Dominic; Ahn, Gail-Joon (11 December 2014). "Security Analysis of x86 Processor Microcode" (PDF). Arizona State University: 1, 5, 7. Retrieved 23 January 2018. supervisor privileges (ring zero) are required to update processor microcode … Since the 1970s, processor manufacturers have decoded the x86 … into a sequence of … (RISC) micro-operations (uops) … introduced writable patch memory to provide an update mechanism for implementing dynamic debugging capabilities and correcting processor errata, especially after the infamous Pentium FDIV bug of 1994. … P6 (Pentium Pro) microarchitecture in 1995, … K7 microarchitecture in 1999 … with symmetric multiprocessing (SMP) … should be executed synchronously on each logical processor … patch RAM in addition to the MROM … up to 60 microinstructions, with patching implemented by pairs of match and destination registers. … a 520 byte block containing a 2048-bit RSA modulus that appears to be constant within each processor family. This is followed by a four byte RSA exponent with the fixed value 11h Cite journal requires |journal= (help)
  17. ^ Shanley, T. (1998). The BIOS Update Loader. Pentium Pro and Pentium II System Architecture. Addison-Wesley Professional. p. 435.
  18. ^ Wolfe, Alexander (30 June 1997). "Intel preps plan to bust bugs in Pentium MPUs". EE Times. No. 960. Archived from the original on 1999-11-13. Retrieved 3 October 2018 – via Techweb. obscure moniker "BIOS Update Feature." … "Each BIOS Update is tailored for a particular stepping of [a] processor," … data block is mapped directly-… after decryption-to the microcode itself.
  19. ^ Wolfe, Alexander (30 June 1997). "Hole seen in Intel's bug-busting feature". EE Times. Santa Clara. Archived from the original on 2003-03-09. Ajay Malhortra, a technical marketing manager based here at Intel's microprocessor group. "Not only is the data block containing the microcode patch encrypted, but once the processor examines the header of the BIOS update, there are two levels of encryption in the processor that must occur before it will successfully load the update." … closely guarded secret. "There is no documentation," said Frank Binns, an architect in Intel's microprocessor group. "It's not as if you can get an Intel 'Red Book' with this stuff written down. It's actually in the heads of less than 10 people in the whole of Intel."
  20. ^ a b c "Details of Intel Probe mode". Hardice. Retrieved 23 January 2018. emit a packet over the BPM when special instructions are executed … To enable Extended Execution Trace, special microcode patches must be applied … For the Pentium 4 only, there exists a second type … called microcode Extended Execution Trace … Control Register Bus in turn allows access to internal arrays and functions on the processor, such as accessing the LLC and the microcode/Virtual Fuse PROM. … that sits on the CPU package but is not within the CPU silicon die. This PROM also contains the microcode that the CPU loads during cold boot. … breakpoint on a 48-bit microcode address … accessed by the TAP commands BRKPTCTLA and BRKPTCTLB.
  21. ^ a b Elkins, David S. (Winter 1990). "NEC v. Intel: A Guide to Using "Clean Room" Procedures as Evidence". Computer/Law Journal. 10 (4). p. 453. NEC's use of its clean room procedures as trial evidence … Judge Gray defined microcode … within the Copyright Act's definition of a "computer program," … Intel's microcode is copyrightable. … Intel's microcode did not contain the required copyright notice. … copyrights had been forfeited. … Intel was left with no basis for its claim of copying
  22. ^ Hinckley, Robert C. (January 1987). "NEC v. Intel: Will Hardware Be Drawn into the Black Hole of Copyright Editors'" (Article 2). Santa Clara High Technology Law Journal. 3 (1). Appendix: Microcode formats; 8086/8088 Format; V20/V30 format
  23. ^ Leong, Kathy Chin (28 March 1988). "Intel witness recants story". Vol. 22 no. 13. San Jose. pp. 83, 84. ISSN 0010-4841. Retrieved 2 October 2018. Cite magazine requires |magazine= (help)
  24. ^ "Intel386 DX Microprocessor 32-BIT CHMOS Microprocessor with Integrated Memory Management" (PDF) (231630–011). December 1995. Archived from the original on 3 September 2004. self-test checks the function of all of the Control ROM … EAX register will contain a signature of 00000000h indicating the Intel386 DX passed its self-test of microcode and major PLA contents Cite journal requires |journal= (help)CS1 maint: unfit url (link)
  25. ^ "5.1 Exhaustive Test in the Intel 80386" (PDF). Built-In-Self-Test (BIST) for Embedded Systems. Testing of Embedded System. IIT Kharagpur: 21. 7 October 2006. Retrieved 6 October 2018. For ROMs, the patterns are generated by the microprogram counter which is part of the normal logic.
  26. ^ a b Gelsinger, Patrick; lyengar, Sundar; Krauskopf, Joseph; Nadir, James; Intel (1999). "Computer Aided Design and Built In Self Test on the i486™ CPU" (PDF). Computer Design: VLSI in Computers and Processors. IEEE: 200–201.
  27. ^ a b "Court ruling against AMD causes some concern". InfoWorld. 17 October 1994. p. 5. Retrieved 24 January 2018. The decision by the federal district court in San Jose, Calif., said that AMD does not have the right to use Intel's in-circuit emulation (ICE) code in the AMD microprocessors. This code is present on all AMD 486s but is only used in a low-power 486-DXL and 486-DXLV processors. … AMD has started to rework its entire line of 486s to eliminate the code.

Further reading[edit]