In: Computer Science
What is the purpose of the CLI and SEI instructions? What do they do, and what are they used for in a typical program?
CLI: Clear interrupt flag; interrupts disabled when interrupt flag cleared.
CLI is commonly used as a synchronization mechanism in uniprocessor systems. For example, a CLI is used in operating systems to disable interrupts so kernel code (typically a driver) can avoid race conditions with an interrupt handler.
If protected-mode virtual interrupts are not enabled, CLI clears the IF flag in the EFLAGS register. No other flags are affected. Clearing the IF flag causes the processor to ignore maskable external interrupts. The IF flag and the CLI and STI instruction have no effect on the generation of exceptions and NMI interrupts.
When protected-mode virtual interrupts are enabled, CPL is 3, and IOPL is less than 3; CLI clears the VIF flag in the EFLAGS register, leaving IF unaffected
SEI - Set Global Interrupt Flag
Sets the Global Interrupt flag in SREG (status register). The instruction following SEI will be executed before any pending interrupts.