# 微码

**微码**是一层低级指令，存储在处理器的控制存储器中，通过产生数据通路所需的控制信号序列来实现机器可见指令。在微程序控制的控制单元中，每条机器指令对应控制存储器中存放的一个微指令序列，因此执行一条指令就意味着取出并发出这些微指令；这种方法比硬连线逻辑慢，但设计、扩展和修正起来要容易得多。<sup>[1](https://www.munotes.in/notes/BSc-Computer-Science/FY-BSc-Computer-Science/Semester-1/Digital-System-and-Architecture/the-control-unit-hardwired-and-microprogrammed/)</sup> 在现代 x86 处理器上，同一层还充当更新机制，使厂商无需任何特殊硬件即可在现场修补 CPU 行为。<sup>[2](https://arxiv.org/abs/1910.00948)</sup>

| 关键事实 | 详情 |
|---|---|
| 起源 | *微程序*一词由 M.V.威尔克斯（M.V. Wilkes）于 20 世纪 50 年代初创造；他 1954 年的微控制单元将控制逻辑状态表嵌入存储阵列<sup>[3](https://file.siu.edu.vn/Thuvien/tai-lieu-so-khoa-KT-KHMT/46_Computer%20Organization%20and%20Architecture%2C%2010th%20edition.pdf)</sup><sup> • </sup><sup>[4](https://ocw.mit.edu/courses/6-823-computer-system-architecture-fall-2005/ecfdbf158b80b2255bcb63b9dd5debd8_l04_microprog.pdf)</sup> |
| 编码风格 | 水平微码为每个控制信号分配独立比特（字宽大，并行度最高）；垂直微码使用带解码器的编码字段（紧凑，但多一个解码步骤，关键路径可能更长）<sup>[5](https://technav.ieee.org/topic/microprogramming/)</sup><sup> • </sup><sup>[6](https://eclipse.umbc.edu/robucci/cmpeRSD/Lectures/Lecture09__Ch6_Microprogrammed_Architectures/)</sup> |
| 更新点（英特尔） | 五个加载点：FIT、早期 BIOS、晚期 BIOS、早期操作系统和运行时<sup>[7](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/loading-microcode-os.html)</sup> |
| 首选加载点 | BIOS SPI 闪存中的固件接口表（FIT），在取第一条 BIOS 指令之前应用<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup> |
| Linux 支持 | 内核可从 initrd 早期加载微码，通过 sysfs 晚期加载，或作为内置固件加载；自内核 5.19 起，晚期加载默认不启用<sup>[9](https://kernel.org/doc/html/v5.8/x86/microcode.html)</sup><sup> • </sup><sup>[10](https://kernel.org/doc/html/next/arch/x86/microcode.html)</sup> |
| 安全作用 | 英特尔通过微码更新缓解了 Spectre 和 Meltdown 漏洞<sup>[11](https://arxiv.org/abs/2007.03549)</sup> |
| 安全风险 | 逆向工程获得的 AMD K8/K10 微码被用于构建可由网页浏览器触发的微码木马<sup>[2](https://arxiv.org/abs/1910.00948)</sup> |

## 微程序控制的工作原理

处理单元由数据通路（寄存器、ALU、移位器、总线接口）和控制单元组成，控制单元管理数据通路在执行用户可见指令（即宏指令）时所采取的一系列步骤。每个步骤都是一次寄存器传送，通过在控制点置位一组控制信号来完成；一条完整的宏指令通过产生一个时序恰当的这些信号组序列来执行，这些信号组称为微操作。<sup>[12](https://moca.ncl.ac.uk/firmware/uprog.html)</sup>

在微程序控制的控制单元中，这个序列来自对控制存储器的读取，而非来自时序逻辑电路。微指令寄存器保存当前字，微程序计数器（通常称为 CSAR）提供地址；下一地址逻辑将当前微指令的跳转字段与数据通路返回的状态标志相结合来选择下一地址，默认动作为递增。<sup>[6](https://eclipse.umbc.edu/robucci/cmpeRSD/Lectures/Lecture09__Ch6_Microprogrammed_Architectures/)</sup> 由于微程序介于逻辑设计与运行程序之间，它常被称为固件。<sup>[12](https://moca.ncl.ac.uk/firmware/uprog.html)</sup>

**水平编码与垂直编码。** 水平微指令是宽字，每个控制信号占一位，允许在一个微指令周期内同时进行许多操作，代价是控制存储器较大。垂直微指令将互斥的控制选项分组为编码字段，由小型解码器转换为单个信号，从而产生紧凑的微码，代价是多一个解码步骤且并行度可能受限。实际设计常混合两者，部分字段水平，部分字段编码。<sup>[5](https://technav.ieee.org/topic/microprogramming/)</sup> 在一个示例中，垂直编码的微程序大小仅为水平编码版本的三分之二，但在驱动数据通路之前需要解码，可能延长关键路径。<sup>[6](https://eclipse.umbc.edu/robucci/cmpeRSD/Lectures/Lecture09__Ch6_Microprogrammed_Architectures/)</sup>

## 历史

[莫里斯·威尔克斯](https://www.edgepedia.org/zh/maurice-wilkes)（Maurice Wilkes）于 20 世纪 50 年代初在剑桥提出微程序设计，作为硬连线控制的一种有组织、系统化的替代方案，但这一想法最初看来不可行，因为它需要快速且相对廉价的控制存储器；1964 年《Datamation》的一篇综述发现尚无广泛使用的微程序系统。<sup>[3](https://file.siu.edu.vn/Thuvien/tai-lieu-so-khoa-KT-KHMT/46_Computer%20Organization%20and%20Architecture%2C%2010th%20edition.pdf)</sup> 该技术后来成为实现 CISC 处理器控制单元的流行方式，近年来使用减少，但仍是计算机设计者可用的工具。<sup>[3](https://file.siu.edu.vn/Thuvien/tai-lieu-so-khoa-KT-KHMT/46_Computer%20Organization%20and%20Architecture%2C%2010th%20edition.pdf)</sup> 随着 RISC 架构在 20 世纪 80 年代流行，在高性能处理器设计者中，微程序设计让位于直接硬连线控制。<sup>[5](https://technav.ieee.org/topic/microprogramming/)</sup> ACM 和 IEEE 赞助了一年一度的微程序设计研讨会，持续三十多年；该会议后来更名为微架构国际研讨会，以反映该领域扩展到处理器内部设计，包括流水线、分支预测和多指令执行。<sup>[12](https://moca.ncl.ac.uk/firmware/uprog.html)</sup>

## x86 上的微码更新

更新 x86 微码的能力使厂商能够在现场修改 CPU 行为，修补错误的微架构行为，甚至实现新功能。<sup>[11](https://arxiv.org/abs/2007.03549)</sup> 英特尔按时间顺序记录了启动和运行期间的五个加载点。<sup>[7](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/loading-microcode-os.html)</sup>

1. **FIT 更新。** 固件接口表是平台 BIOS SPI 闪存中的一种数据结构，可能包含指向微码更新的指针。在执行 IA 复位向量处第一条 BIOS 固件指令之前，CPU 处理 FIT 以定位匹配该 CPU 的更新；这是英特尔的首选方法，因为它在启动的最早时间点加载所有更新组件。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>
2. **早期 BIOS 更新。** BIOS 在内存初始化之前加载更新；如果 FIT 已加载更新，则可跳过此步骤，BIOS 可通过在执行 CPUID 后读取 IA32_BIOS_SIGN_ID 寄存器（MSR 8BH）来检测。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>
3. **晚期 BIOS 更新。** 某些架构特性（如英特尔 SGX）需要额外的晚期 BIOS 更新，并在各插槽间同步；未能并行加载可能会阻止这些特性启用。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>
4. **早期操作系统更新。** 操作系统检查自己是否有比 BIOS 所应用的版本更新的微码更新（修订号更高），并在 BIOS 移交控制后不久、CPUID 特性标志被缓存之前以及用户应用程序或虚拟机启动之前加载它。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>
5. **运行时更新。** 可在系统运行工作负载时加载更新，使用会合机制同步所有逻辑处理器；当重置会带来问题时（例如需要保持服务器持续运行时）使用此方式，不过尽可能通过 BIOS 或早期操作系统加载更可取。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>

通常，英特尔的微码更新是累积的：对于任何特定的处理器签名（CPUID 家族/型号/步进）和平台 ID，较新的更新包含之前所有更新的内容。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup> 加载后，某些更新可能会阻止加载修订号更低的更新，即使允许加载较低修订号，加载它也可能无法清除先前已加载的较高修订号更新所产生的全部影响。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup> 加载更新不会扰动先前配置的软件可控状态（如 MSR 值）。<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)</sup>

**Linux 加载。** 内核的 x86 微码加载器支持三种方法：早期加载，在启动期间读取 initrd 文件中存储的微码并应用于引导处理器，然后应用于所有应用处理器，在内核启动期间观察到 CPU 问题之前修复它们；晚期加载，在安装发行版微码包后通过写入 /sys/devices/system/cpu/microcode/reload 完成；以及通过 CONFIG_EXTRA_FIRMWARE 编译进内核的内置微码。<sup>[9](https://kernel.org/doc/html/v5.8/x86/microcode.html)</sup> 自内核 5.19 起，晚期加载默认不启用，已弃用的 /dev/cpu/microcode 接口已被移除。<sup>[10](https://kernel.org/doc/html/next/arch/x86/microcode.html)</sup> 加载器还会在内存中缓存匹配的补丁，以便 CPU 从睡眠恢复时重新应用。<sup>[9](https://kernel.org/doc/html/v5.8/x86/microcode.html)</sup>

## 安全

微码更新是标准的缓解渠道：英特尔通过微码更新缓解了 [Spectre](https://www.edgepedia.org/zh/spectre-security-vulnerability) 和 Meltdown 瞬态执行漏洞。<sup>[11](https://arxiv.org/abs/2007.03549)</sup> AMD 同样建议使用微码补丁（EPYC 7002 处理器为 0x0830107B）作为缓解 CVE-2023-20593 的一部分，这是 [Zen 2](https://www.edgepedia.org/zh/zen-2) 的一个问题，其中寄存器可能未正确写零，可能将另一进程的数据留在 YMM 寄存器中。<sup>[13](https://www.amd.com/en/resources/product-security/bulletin/amd-sb-7008.html)</sup>

同样的灵活性也创造了攻击面。波鸿鲁尔大学、马克斯·普朗克安全与隐私研究所及合作者的研究人员表明，微码更新的灵活性通过类似硬件木马的恶意微码修改开辟了攻击途径，并且尽管微码几乎完全控制处理器硬件，设计有意义的微码木马并不简单，因为硬件缺乏有关所执行软件语义的信息。<sup>[14](https://www.usenix.org/conference/usenixsecurity21/presentation/albartus)</sup> 2019 年对 AMD K8 和 K10 微架构的逆向工程工作恢复了微码语义和更新机制，演示了自定义微码更新，并构建了从 CPU 辅助插桩到可从网页浏览器内触发的微码木马等微程序，后者可实现远程代码执行和密码实现攻击。<sup>[2](https://arxiv.org/abs/1910.00948)</sup> 由于微码是英特尔 SGX 等环境可信计算基础的基础，恶意微码更新将使这些安全属性失效。<sup>[14](https://www.usenix.org/conference/usenixsecurity21/presentation/albartus)</sup>

微码本身也可能藏有瞬态执行弱点。uSpectre 工作表明，条件微码分支预测错误会创建跨越许多宏操作的瞬态执行窗口，在此期间敏感数据可能泄漏；若干已知的 Spectre 和 Meltdown 变体在某些英特尔微架构上就是 uSpectre 的实例，作者提出了一种名为 uSLH 的防御措施。<sup>[15](https://arxiv.org/abs/2501.12890)</sup>

## References

1. [The Control Unit: Hardwired and Microprogrammed, munotes](https://www.munotes.in/notes/BSc-Computer-Science/FY-BSc-Computer-Science/Semester-1/Digital-System-and-Architecture/the-control-unit-hardwired-and-microprogrammed/)
2. [Koppe, Kollenda, Fyrbiak, Kison, Gawlik, Paar, Holz (2019). Reverse Engineering x86 Processor Microcode. arXiv:1910.00948](https://arxiv.org/abs/1910.00948)
3. [William Stallings, Computer Organization and Architecture, 10th edition, Chapter 21: Microprogrammed Control](https://file.siu.edu.vn/Thuvien/tai-lieu-so-khoa-KT-KHMT/46_Computer%20Organization%20and%20Architecture%2C%2010th%20edition.pdf)
4. [MIT 6.823 Lecture 4: Microprogramming (Arvind, Fall 2005)](https://ocw.mit.edu/courses/6-823-computer-system-architecture-fall-2005/ecfdbf158b80b2255bcb63b9dd5debd8_l04_microprog.pdf)
5. [Microprogramming, IEEE Technology Navigator](https://technav.ieee.org/topic/microprogramming/)
6. [Lecture 09: Microprogrammed Architectures, UMBC](https://eclipse.umbc.edu/robucci/cmpeRSD/Lectures/Lecture09__Ch6_Microprogrammed_Architectures/)
7. [Loading Microcode from the OS, Intel Software Security Guidance](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/secure-coding/loading-microcode-os.html)
8. [Microcode Update Guidance, Intel Software Security Guidance](https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/microcode-update-guidance.html)
9. [The Linux Microcode Loader, Linux Kernel documentation (v5.8)](https://kernel.org/doc/html/v5.8/x86/microcode.html)
10. [The Linux Microcode Loader, Linux Kernel documentation (next)](https://kernel.org/doc/html/next/arch/x86/microcode.html)
11. [An Exploratory Analysis of Microcode as a Building Block for System Defenses. arXiv:2007.03549](https://arxiv.org/abs/2007.03549)
12. [Microprogramming History, Mark Smotherman](https://moca.ncl.ac.uk/firmware/uprog.html)
13. [Cross-Process Information Leak, AMD Security Bulletin AMD-SB-7008](https://www.amd.com/en/resources/product-security/bulletin/amd-sb-7008.html)
14. [Albartus et al. (2021). On the Design and Misuse of Microcoded (Embedded) Processors, USENIX Security 21](https://www.usenix.org/conference/usenixsecurity21/presentation/albartus)
15. [Mosier, Nemati, Mitchell, Trippel (2025). Analyzing and Exploiting Branch Mispredictions in Microcode. arXiv:2501.12890](https://arxiv.org/abs/2501.12890)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Computer architecture theory › CPU internal structure

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/microcode

English original: https://www.edgepedia.org/microcode
