Opcode | Encoding | 16-bit | 32-bit | 64-bit | Description |
---|---|---|---|---|---|
FA CLI | zo | Valid | Valid | Valid | Clear EFLAGS.IF . |
Encoding
Encoding | Operand |
---|---|
zo | None |
Description
The CLI
instruction clears EFLAGS.IF
(the interrupt enable flag). Doing so will cause the processor to ignore maskable (external) interrupts.
Operation depends on the operating mode and the current privilege level of the executing code. In addition, two seprate conditions regarding virtual interrupts are used:
VME
Mode (Virtual-8086 Mode Extensions)- If in Virtual-8086 Mode and
CR4.VME
is1
. PVI
Mode (Protected Mode Virtual Interrupts)- If in Protected Mode,
CPL
is3
, andCR4.PVI
is1
.
With those two definitions, operation follows this truth table:
Mode | IOPL | CLI Operation |
---|---|---|
Real Mode | n/a | IF ← 0 |
Virtual-8086 Mode, not VME | 0-2 | #GP fault |
3 | IF ← 0 | |
Virtual-8086 Mode, VME | 0-2 | VIF ← 0 |
3 | IF ← 0 | |
Protected Mode, not PVI | <CPL | #GP fault |
≥CPL | IF ← 0 | |
Protected Mode, PVI | 0-2 | VIF ← 0 |
3 | IF ← 0 |
Operation
public void CLI()
{
if (!CR0.PE)
{
// real mode
EFLAGS.IF = 0;
return;
}
if (IOPL > CPL)
{
// NOTE: CPL is 3 in virtual-8086 mode
EFLAGS.IF = 0;
return;
}
bool vme = EFLAGS.VM && CR4.VME;
bool pvi = !EFLAGS.VM && CPL > 3 && CR4.PVI;
if (vme || pvi)
EFLAGS.VIF = 0;
#GP(0);
}
Flags Affected
CF
(carry flag)- Unmodified.
PF
(parity flag)- Unmodified.
AF
(auxiliary flag)- Unmodified.
ZF
(zero flag)- Unmodified.
SF
(sign flag)- Unmodified.
IF
(interrupt enable flag)- Cleared if in Real Mode or if
IOPL
is greater than or equal toCPL
. OF
(overflow flag)- Unmodified.
VIF
(virtual interrupt flag)- Cleared if in
VME
orPVI
submodes andEFLAGS.IF
is unmodified.
Exceptions
Real-Address Mode
#UD
- If the
LOCK
- prefix is used.
Virtual-8086 Mode
#UD
- If the
LOCK
- prefix is used.
#GP(0)
- If
IOPL
- is less than
3
- and the
VME
- submode is not active.
Protected Mode
#UD
- If the
LOCK
- prefix is used.
#GP(0)
- If
CPL
is greater thanIOPL
but also less than3
. - If
CPL
is greater thanIOPL
and thePVI
submode is not active.
Compatibility Mode
#UD
- If the
LOCK
- prefix is used.
#GP(0)
- If
CPL
is greater thanIOPL
but also less than3
. - If
CPL
is greater thanIOPL
and thePVI
submode is not active.
Long Mode
#UD
- If the
LOCK
- prefix is used.
#GP(0)
- If
CPL
is greater thanIOPL
but also less than3
. - If
CPL
is greater thanIOPL
and thePVI
submode is not active.