Even worse are those that infect the BIOS. Nearly impossible to repair without replacing the hardware. But they're ultra-rare, and I think you have to be messing around with it.
BIOS viruses are not that common, especially as BIOSes are now getting harder to infect.
It is possible for a virus to flash down code and then hook into the OS install process to push it back up.
Two things you can have are a BIOS that can be jumper locked against flashing, or that requires a signed image before flashing.
Early BIOS viruses tended to limit themselves to general mayhem (wiping the BIOS). They would use the power management and control interface of the BIOS to allow OS/BIOS interaction.
Another thing that makes this rare is the fact that it is so relatively difficult for a person to achieve, and Windows is relatively easy to infect (repeatedly, if necessary).