Linux 什么是英特尔微码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4366837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:57:12  来源:igfitidea点击:

What is Intel microcode?

linuxassemblyintel

提问by Quamis

From what I've read it's used to fix bugs in the CPU without modifying the BIOS. From my basic knowledge of Assembly I know that assembly instructions are split into microcodes internally by the CPU and executed accordingly. But intel somehow gives access to make some updates while the system is up and running.

从我读过的内容来看,它用于在不修改 BIOS 的情况下修复 CPU 中的错误。根据我对汇编的基本知识,我知道汇编指令在 CPU 内部被拆分为微代码并相应地执行。但是英特尔以某种方式允许在系统启动并运行时进行一些更新。

Anyone has more info on them? Is there any documentation regarding what can it be done with microcodes and how can they be used?

有人有更多关于他们的信息吗?是否有任何关于微代码可以做什么以及如何使用它们的文档?



EDIT: I've read the wikipedia article: didn't figure out how can I write some on my own, and what uses it would have.

编辑:我已经阅读了维基百科文章:不知道如何自己写一些,以及它有什么用途。

采纳答案by Thomas Pornin

In older times, microcode was heavily used in CPU: every single instruction was split into microcode. This enabled relatively complex instruction sets in modest CPU (consider that a Motorola 68000, with its many operand modes and eight 32-bit registers, fits in 40000 transistors, whereas a single-core modern x86 will have more than a hundred millions). This is not true anymore. For performance reasons, most instructions are now "hardwired": their interpretation is performed by inflexible circuitry, outside of any microcode.

在过去,微码在 CPU 中被大量使用:每条指令都被拆分为微码。这在适度的 CPU 中启用了相对复杂的指令集(考虑到摩托罗拉 68000具有许多操作数模式和八个 32 位寄存器,可容纳 40000 个晶体管,而现代单核 x86 将有超过一亿个)。这已经不是真的了。出于性能原因,大多数指令现在都是“硬连线”的:它们的解释是由不灵活的电路执行的,在任何微代码之外。

In a recent x86, it is plausible that some complex instructions such as fsin(which computes the sine function on a floating point value) are implemented with microcode, but simple instructions (including integer multiplication with imul) are not. This limits what can be achieved with custom microcode.

在最近的 x86 中,一些复杂的指令(例如fsin(计算浮点值的正弦函数))是用微代码实现的,但简单的指令(包括整数乘法imul)不是。这限制了使用自定义微码可以实现的目标。

That being said, microcode format is not only very specific to the specific processor model (e.g. microcode for a Pentium III and a Pentium IV cannot be freely exchanged with eachother -- and, of course, using Intel microcode for an AMD processor is out of the question), but it is also a severely protected secret. Intel has published the method by which an operating system or a motherboard BIOS may update the microcode (it must be done after each hard reset; the update is kept in volatile RAM) but the microcode contentsare undocumented. The Intel? 64 and IA-32 Architectures Software Developer's Manual(volume 3a) describes the update procedure (section 9.11 "microcode update facilities") but states that the actual microcode is "encrypted" and clock-full of checksums. The wording is vague enough that just about any kind of cryptographic protection may be hidden, but the bottom-line is that it is not currently possible, for people other than Intel, to write and try some custom microcode.

话虽如此,微码格式不仅非常特定于特定的处理器模型(例如,Pentium III 和 Pentium IV 的微码不能相互自由交换——当然,对 AMD 处理器使用 Intel 微码是不可能的。问题),但这也是一个受到严格保护的秘密。英特尔已发布操作系统或主板 BIOS 更新微码的方法(必须在每次硬重置后完成;更新保存在易失性 RAM 中),但微码内容未记录。在英特尔?64 和 IA-32 架构软件开发人员手册(第 3a 卷)描述了更新程序(第 9.11 节“微码更新设施”),但指出实际微码是“加密的”并且时钟充满校验和。措辞非常含糊,几乎可以隐藏任何类型的加密保护,但最重要的是,对于英特尔以外的人来说,目前不可能编写和尝试一些自定义微码。

If the "encryption" does not include a digital (asymmetric) signature and/or if the people at Intel botched the protection system somehow, then it may be conceivable that some remarkable reverse-engineering effort couldpotentially enable one to produce such microcode, but, given the probably limited applicability (since most instructions are hardwired), chances are that this would not buy much, as far as programming power is concerned.

如果“加密”不包括数字(非对称)签名和/或英特尔的人员以某种方式破坏了保护系统,那么可以想象一些非凡的逆向工程工作可能使人们能够生成这样的微代码,但是,考虑到适用性可能有限(因为大多数指令都是硬连线的),就编程能力而言,这可能不会带来太多好处。

回答by Paul R

You don't normally write micro-code. To do so requires intimate knowledge of the CPU micro-architecture. Intel doesn't general release any information on either their micro-architecture or their micro-code.

您通常不会编写微代码。要做到这一点,需要对 CPU 微架构有深入的了解。英特尔一般不会发布有关其微架构或微代码的任何信息。

回答by old_timer

Think loosely about a virtual machine or simulator where say for example qemu-arm can simulate an arm processor on an x86 host, ideally the software running on the simulated arm has no idea that it isnt a real arm. Take this idea to the level where the whole chip is designed such that it always looks like you are an x86, the software never knows there is some programmable items inside the chip. And that some other processor inside is somewhat designed for the purpose of implementing/simulating an x86. Supposedly the popular AMD 29000 product line just went away because the hardware team and perhaps processor/core became the guts of an early x86 clone. Transmeta, where Linus worked, had a vliw processor that was made to be a low power x86. In that case the translation layer was not (as much of) a secret. Vliw, very long instruction word, RISC taken to the extreme, is the kind of thing you build for this kind of task.

松散地考虑一下虚拟机或模拟器,例如 qemu-arm 可以在 x86 主机上模拟 arm 处理器,理想情况下,在模拟 arm 上运行的软件不知道它不是真正的 arm。把这个想法带到整个芯片的设计水平,它总是看起来你是一个 x86,软件永远不知道芯片内部有一些可编程的项目。并且内部的其他一些处理器在某种程度上是为了实现/模拟 x86 的目的而设计的。据说流行的 AMD 29000 产品线刚刚消失是因为硬件团队和处理器/核心成为早期 x86 克隆的核心。Linus 工作的 Transmeta 有一个 vliw 处理器,它是低功耗 x86 处理器。在那种情况下,翻译层不是(尽可能多的)秘密。Vliw,很长的指令字,

No it is not as much of an emulation layer as I am implying, there isnt some linux running there with a qemu program inside each chip. It is somewhere between hardwired where there is no software/microcode in the middle and a full blow emulation. The programmable bits may be like an fpga, programmable gates, or it may be software or programmable state machines, meaning not-programmable gates, just what runs on the gates is programmable.

不,它不像我暗示的那样是一个仿真层,没有一些 linux 在那里运行,每个芯片内都有一个 qemu 程序。它介于硬连线(中间没有软件/微代码)和全面模拟之间。可编程位可能类似于 fpga、可编程门,也可能是软件或可编程状态机,即不可编程门,只是在门上运行的内容是可编程的。

Your non-x86, non-big iron type processors. Take ARM for example, are hardwired, no microcode. Microcontrollers, PIC, MSP430, AVR, assume these are not microcoded. Basically do not assume all processors are microcoded, few if any processor families are. It is just that the ones we deal with in PCs have been and may still be, so it may feel like they all are.

您的非 x86、非大型铁型处理器。以 ARM 为例,是硬连线的,没有微码。微控制器、PIC、MSP430、AVR 假定这些不是微编码的。基本上不要假设所有处理器都是微编码的,如果有处理器系列的话,很少。只是我们在 PC 中处理的那些已经并且可能仍然存在,因此可能感觉它们都是。

As fun as it may sound to play with this microcode, it is likely very specific to the processor family, and you likely will never gain access to how it works unless you work for Intel or AMD, each of which likely have their own internals. So you would need to get a job at one of the two, then work your way through the trenches to become one of what is likely an elite team that does this work. And once you get that far your career is trapped, your skills may be limited to one job at one company. You might have more fun programming individual gpus on a video card, something that is documented or at least has tools, something you can do today without spending 10 years at AMD or Intel to possibly get nowhere.

尽管使用此微代码听起来很有趣,但它可能非常特定于处理器系列,除非您为 Intel 或 AMD 工作,否则您可能永远无法了解它的工作原理,它们可能都有自己的内部结构。因此,您需要在两者之一中找到一份工作,然后通过战壕努力成为可能从事这项工作的精英团队之一。一旦你走得那么远,你的职业生涯就陷入困境,你的技能可能仅限于一家公司的一份工作。您可能会在视频卡上对单个 gpu 进行编程,这可能会更有趣,有记录的东西或至少有工具,您今天可以做的事情,而无需在 AMD 或英特尔工作 10 年,可能一无所获。