I read that microcode is loaded in the processor on each reboot. It resides on flash memory and when the machine is booted, it gets copied to the CPU. Or in the case of Linux, the OS itself has the microcode copy for the processor. But how does the microcode get copied to the processor? All data moves in a computer by the consent of the CPU. CPU is given instructions in machine language. As microcode is imperative for execution of these machine language instructions, so without the microcode being present in the processor, how the instruction for accessing the flash memory and doing the consequent operations are done by CPU? Does this mean that hard-wired non-microcoded instructions copy the microcode in real mode?
Answer
I read that microcode is loaded in the processor on each reboot.
The BIOS can issue a microcode update during boot. So can the operating system. Frequently these updates are required, especially with later Intel CPUs.
It resides on flash memory and when the machine is booted, it gets copied to the CPU. Or in the case of Linux, the OS itself has the microcode copy for the processor. But how does the microcode get copied to the processor?
Modern Intel and CPUs have a mechanism called "Model Specific Registers", and special CPU instructions to read (RDMSR) and write to them (WRMSR). While these registers affect CPU settings, writing to a specific one with the address of the new microcode tells the CPU to read a region of memory and apply over the existing microcode.
All data moves in a computer by the consent of the CPU. CPU is given instructions in machine language. As microcode is imperative for execution of these machine language instructions, so without the microcode being present in the processor, how the instruction for accessing the flash memory and doing the consequent operations are done by CPU?
There is always a microcode. The mechanism above updates the microcode. Intel/AMD don't really publish specifics on how it works, they only provide an update mechanism. Obviously somehow it is copying a ROM microcode to some sort of CPU internal memory. But there is some microcode there when the CPU starts. Some recent Intel and possibly AMD CPUs won't work reliably after boot without a microcode update done by the BIOS but evidently they will function well enough to perform an initial microcode update.
Does this mean that hard-wired non-microcoded instructions copy the microcode in real mode?
The initial microcode setup is done internally by the CPU and no instructions are executed to achieve that. It's setup before the first CPU instruction is executed.
To update the BIOS the appropriate RDMSR and WRMSR instructions must be executed.
Reference: "This instruction must be executed at privilege level 0 or in real-address mode; otherwise, a general protection exception #GP(0) will be generated." If it's not executed in real mode it must be done in ring 0 or kernel mode. You can update the microcode anytime.
No comments:
Post a Comment