STI

Set Interrupt Flag

stableVMJITAOTinstruction

Encodings

OpcodeInstructionOp/En64-bitCompat/LegacyDescription
FBSTIZOValidValidSet interrupt flag; external, maskable interrupts enabled at the end of the next instruction.

Measured cost

Loading measurements from arch-data...

Flags named

Description

In most cases, STI sets the interrupt flag (IF) in the EFLAGS register. This allows the processor to respond to maskable hardware interrupts.

If IF = 0, maskable hardware interrupts remain inhibited on the instruction boundary following an execution of STI. (The delayed effect of this instruction is provided to allow interrupts to be enabled just before returning from a procedure or subroutine. For instance, if an STI instruction is followed by an RET instruction, the RET instruction is allowed to execute before external interrupts are recognized. No interrupts can be recognized if an execution of CLI immediately follow such an execution of STI.) The inhibition ends after delivery of another event (e.g., exception) or the execution of the next instruction.

The IF flag and the STI and CLI instructions do not prohibit the generation of exceptions and nonmaskable interrupts (NMIs). However, NMIs (and system-management interrupts) may be inhibited on the instruction boundary following an execution of STI that begins with IF = 0.

Operation is different in two modes defined as follows:

If IOPL < 3, EFLAGS.VIP = 1, and either VME mode or PVI mode is active, STI sets the VIF flag in the EFLAGS register, leaving IF unaffected.

Table 4-22 indicates the action of the STI instruction depending on the processor operating mode, IOPL, CPL, and EFLAGS.VIP.

Decision Table for STI Results

ModeIOPLEFLAGS.VIPSTI Result
l-addressX1XIF = 1
, not PVI2CPLXIF = 1
< CPLX#GP fault
3XIF = 1

Operation

IF CR0.PE = 0 (* Executing in real-address mode *)
    THEN IF := 1; (* Set Interrupt Flag *)
    ELSE
          IF IOPL  CPL (* CPL = 3 if EFLAGS.VM = 1 *)
                THEN IF := 1; (* Set Interrupt Flag *)
                ELSE
                      IF VME mode OR PVI mode
                            THEN
                                  IF EFLAGS.VIP = 0
                                        THEN VIF := 1; (* Set Virtual Interrupt Flag *)
                                        ELSE #GP(0);
                                  FI;
                            ELSE #GP(0);
                      FI;
          FI;

FI;

Flags affected

Either the IF flag or the VIF flag is set to 1. Other flags are unaffected.

Exceptions

Protected mode
#GP(0)If CPL is greater than IOPL and PVI mode is not active. If CPL is greater than IOPL and EFLAGS.VIP = 1.
#UDIf the LOCK prefix is used.
Real address mode
#UDIf the LOCK prefix is used.
Virtual-8086 mode
#GP(0)If IOPL is less than 3 and VME mode is not active. If IOPL is less than 3 and EFLAGS.VIP = 1.
#UDIf the LOCK prefix is used.
Compatibility mode
Same exceptions as in protected mode.
64-bit mode
Same exceptions as in protected mode.

Sources