What is need for disabling all interrupts at system initialization or at startup code level . If I do not disable the interrupts what will happen??
There are certain situations interrupts are unwanted, so they are disabled.
The examples are numerous but off the top of my head I can come up with these:
Modification of ss:(e)sp
. If an interrupt is fired, the flags
register is pushed onto the stack. An invalid stack value will move that copy to some random location. Alterating ss:(e)sp
is not atomic, at least on x86, because it consists of multiple instructions, so an interrupt can fire in between.
However, if you write your code properly, you can achieve the same atomicity without disabling interrupts here because they are automatically disabled on certain occasions.
@MichaelPetch uttered some specialty about 8088 processors (the "weaker brother" of the 8086, the first x86 processor), depicting an exception to these "certain occasions," in the comments to this answer:
That is true about interrupts being turned off until the end of the next instruction (after moving a value into
SS
), but there were 8088 processors with a bug where the interrupts weren't properly turned off after aSS
change. Those of us (the dinosaurs) will often putCLI
/STI
around theSS:SP
update just in case (Chances of running an 8088 system with such a bug is likely near zero). From a historical perspective, this PC mag article may shed some light on this ancient issue.
(Code formatters added.)
In general, you can say that operations modifying the IDT/IVT in some non-atomic manner need to disable interrupts.
As an aside: I myself have written several bootloaders already and usually disable interrupts throughout the whole runtime of the bootloader. In Protected Mode, I reenable them eventually. Linux 4.2 handles it similarly. If you're interested, read its source code (/arch/x86/boot/
) or that from Minix!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With