10-4
INPUT/OUTPUT
When used with one of the repeat prefixes (such as REP), the INS and OUTS instructions
perform string (or block) input or output operations. The repeat prefix REP modifies the INS
and OUTS instructions to transfer blocks of data between an I/O port and memory. Here, the ESI
or EDI register is incremented or decremented (according to the setting of the DF flag in the
EFLAGS register) after each byte, word, or doubleword is transferred between the selected I/O
port and memory.
Refer to the individual references for the IN, INS, OUT, and OUTS instructions in Chapter 3,
Instruction Set Reference, of the Intel Architecture Software Developers Manual, Volume 2, for
more information on these instructions.
10.5.PROTECTED-MODE I/O
When the processor is running in protected mode, the following protection mechanisms regulate
access to I/O ports:
When accessing I/O ports through the I/O address space, two protection devices control
access:
The I/O privilege level (IOPL) field in the EFLAGS register.
The I/O permission bit map of a task state segment (TSS).
When accessing memory-mapped I/O ports, the normal segmentation and paging
protection and the MTRRs (in processors that support them) also affect access to I/O ports.
Refer to Chapter 4, Protection, and Chapter 9, Memory Cache Control, in the Intel Archi-
tecture Software Developers Manual, Volume 3, for a complete discussion of memory
protection.
The following sections describe the protection mechanisms available when accessing I/O ports
in the I/O address space with the I/O instructions.
10.5.1.I/O Privilege Level
In systems where I/O protection is used, the IOPL field in the EFLAGS register controls access
to the I/O address space by restricting use of selected instructions. This protection mechanism
permits the operating system or executive to set the privilege level needed to perform I/O. In a
typical protection ring model, access to the I/O address space is restricted to privilege levels 0
and 1. Here, kernel and the device drivers are allowed to perform I/O, while less privileged
device drivers and application programs are denied access to the I/O address space. Application
programs must then make calls to the operating system to perform I/O.
The following instructions can be executed only if the current privilege level (CPL) of the
program or task currently executing is less than or equal to the IOPL: IN, INS, OUT, OUTS, CLI
(clear interrupt-enable flag), and STI (set interrupt-enable flag). These instructions are called
I/O sensitive instructions, because they are sensitive to the IOPL field. Any attempt by a less
privileged program or task to use an I/O sensitive instruction results in a general-protection