IF (x86 flag)

IF (x86 flag)

IF (Interrupt Flag) is a system flag bit in the x86 architecture's FLAGS register, which determines whether or not the CPU will handle maskable hardware interrupts.cite web |url=http://download.intel.com/design/PentiumII/manuals/24319102.PDF|format = PDF| title=Intel Architecture Software Developer's Manual, Volume 2: Instruction Set Reference Manual|accessdate=2007-07-13]

The bit, which is bit 9 of the FLAGS register, may be set or cleared by programs with sufficient privileges, as usually determined by the OS kernel. If the flag is set to 1, maskable hardware interrupts will be handled. If cleared (set to 0), such interrupts will be ignored. IF does not affect the handling of non-maskable interrupts or software interrupts generated by the INT instruction.

Setting and clearing

The flag may be set or cleared using the CLI (Clear Interrupts), STI (Set Interrupts) and POPF (Pop Flags) instructions.

CLI clears IF (sets to 0), while STI sets IF to 1. POPF pops 16 bits off the stack into the FLAGS register, which means IF will be set or cleared based on the ninth bit on the top of the stack.

Privilege level

In all three cases, only privileged applications (usually the OS kernel) may modify IF. Note that this only applies to protected mode code (real mode code may always modify IF).

CLI and STI are privileged instructions, which trigger a general protection fault if an unprivileged application attempts to execute it, while POPF will simply not modify the IF flag if the application is unprivileged.

The privilege level required to execute a CLI or STI instruction, or set IF using POPF, is determined by the IOPL (I/O Privilege Level) in EFLAGS. If the IOPL is set to 2 for example, any program running in ring 0, 1, or 2 can execute a CLI. Most modern operating systems set the IOPL to be 0 so only the kernel can execute CLI/STI. The reason for this is that since clearing IF will force the processor to ignore ALL interrupts, the kernel may never get control back if it is not set to 1 again.

CLI

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. Note that CLI only affects the interrupt flag for the processor on which it is executed; in multiprocessor systems, executing a CLI instruction does not disable interrupts on other processors. Thus, a driver/interrupt handler race condition can still occur because other processors may service interrupts and execute the offending interrupt handler. For these systems, other synchronization mechanisms such as locks must be used in addition to CLI/STI to prevent all race conditions.

Because the HLT instruction halts until an interrupt occurs, the combination of a CLI followed by a HLT is commonly used to intentionally hang the computer.

STI

The STI instruction enables interrupts by setting the IF flag.

One interesting quirk about the STI instruction is that, unlike CLI which has an immediate effect, interrupts are not actually enabled until after the instruction immediately following the STI. One side effect of this is that if IF=0, then executing a CLI instruction immediately after an STI instruction means that interrupts are never recognized. The STI instruction sets the IF flag, but interrupts are not checked for until after the next instruction which in this case would be the CLI which takes effect immediately. This behavior exists so a processor that constantly takes interrupts can still make forward progress. See IA-32 manuals for details.

ee also

* FLAGS register (computing)
* Intel 8259
* Advanced Programmable Interrupt Controller
* Intel APIC Architecture
* Interrupt
* Interrupt Handler
* Non-Maskable Interrupt
* Programmable Interrupt Controller
* x86

References

External links

* [http://www.intel.com/products/processor/manuals/index.htm Intel IA-32 Software Developer's Manual]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • X86 assembly language — is the assembly language for the x86 class of processors, which includes Intel s Pentium series and AMD s Athlon series. Like all assembly languages, it uses short mnemonics to represent the fundamental operations that the CPU in a computer can… …   Wikipedia

  • X86-64 — is a superset of the x86 instruction set architecture. x86 64 processors can run existing 32 bit or 16 bit x86 programs at full speed, but also support new programs written with a 64 bit address space and other additional capabilities.The x86 64… …   Wikipedia

  • Flag — Saltar a navegación, búsqueda Para otros usos de este término, véase FLAG. En programación, la bandera o flag se refiere a uno o más bits que se utilizan para almacenar un valor binario o código que tiene asignado un significado. Las banderas… …   Wikipedia Español

  • x86 — This article is about Intel microprocessor architecture in general. For the 32 bit generation of this architecture which is also called x86 , see IA 32. x86 Designer Intel, AMD Bits 16 bit, 32 bit, and/or 64 bit Introduced 1978 Design …   Wikipedia

  • x86-Prozessor — Prozessor Intel i8086 in Gehäuseform DIP 40. Der Intel i8088 besitzt im Vergleich zum …   Deutsch Wikipedia

  • X86 — Die Artikel IA 32 und X86 Prozessor überschneiden sich thematisch. Hilf mit, die Artikel besser voneinander abzugrenzen oder zu vereinigen. Beteilige dich dazu an der Diskussion über diese Überschneidungen. Bitte entferne diesen Baustein erst… …   Deutsch Wikipedia

  • X86-Architektur — Die Artikel IA 32 und X86 Prozessor überschneiden sich thematisch. Hilf mit, die Artikel besser voneinander abzugrenzen oder zu vereinigen. Beteilige dich dazu an der Diskussion über diese Überschneidungen. Bitte entferne diesen Baustein erst… …   Deutsch Wikipedia

  • X86-Prozessor — Die Artikel IA 32 und X86 Prozessor überschneiden sich thematisch. Hilf mit, die Artikel besser voneinander abzugrenzen oder zu vereinigen. Beteilige dich dazu an der Diskussion über diese Überschneidungen. Bitte entferne diesen Baustein erst… …   Deutsch Wikipedia

  • X86 Prozessor — Die Artikel IA 32 und X86 Prozessor überschneiden sich thematisch. Hilf mit, die Artikel besser voneinander abzugrenzen oder zu vereinigen. Beteilige dich dazu an der Diskussion über diese Überschneidungen. Bitte entferne diesen Baustein erst… …   Deutsch Wikipedia

  • Flag (disambiguation) — A flag is a colored cloth with a specified meaning.Flag may also refer to:In computers: * Flag (computing), a true/false, on/off or open/closed indicator (boolean variable) * FLAGS register (computing), a CPU register on x86 systems * Fiber Optic …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”