Disable Hardware & Software Interrupts

someone picture someone · Oct 6, 2009 · Viewed 9.9k times · Source

Is it possible to disable all interrupts with a ASM/C/C++ program to get full control about the processor?

If yes -> how?

If not -> how do "atomic" operation system calls work (for example entering a critical section)?

Thanks for your help!

Answer

Ludwig Weinzierl picture Ludwig Weinzierl · Oct 17, 2009

In x86 assembly the the commands are

  • sti set interrupt enable bit
  • cli clear interrupt enable bit

These commands set and clear the IF Flag. When the IF flag is set, the CPU will handle hardware interrupts, and when it is clear the CPU will ignore hardware interrupts. It does not affect the handling of non-maskable interrupts though, nor does it affect software interrupts or exceptions. These instructions also don't work in unprivileged mode (usually everything higher than ring 0, depending on IOPL) though.