Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture

13-6 Vol. 1
INPUT/OUTPUT
Because each task has its own TSS, each task has its own I/O permission bit map.
Access to individual I/O ports can thus be granted to individual tasks.
If in protected mode and the CPL is less than or equal to the current IOPL, the
processor allows all I/O operations to proceed. If the CPL is greater than the IOPL or
if the processor is operating in virtual-8086 mode, the processor checks the I/O
permission bit map to determine if access to a particular I/O port is allowed. Each bit
in the map corresponds to an I/O port byte address. For example, the control bit for
I/O port address 29H in the I/O address space is found at bit position 1 of the sixth
byte in the bit map. Before granting I/O access, the processor tests all the bits corre-
sponding to the I/O port being addressed. For a doubleword access, for example, the
processors tests the four bits corresponding to the four adjacent 8-bit port
addresses. If any tested bit is set, a general-protection exception (#GP) is signaled.
If all tested bits are clear, the I/O operation is allowed to proceed.
Because I/O port addresses are not necessarily aligned to word and doubleword
boundaries, the processor reads two bytes from the I/O permission bit map for every
access to an I/O port. To prevent exceptions from being generated when the ports
with the highest addresses are accessed, an extra byte needs to included in the TSS
immediately after the table. This byte must have all of its bits set, and it must be
within the segment limit.
It is not necessary for the I/O permission bit map to represent all the I/O addresses.
I/O addresses not spanned by the map are treated as if they had set bits in the map.
For example, if the TSS segment limit is 10 bytes past the bit-map base address, the
map has 11 bytes and the first 80 I/O ports are mapped. Higher addresses in the I/O
address space generate exceptions.
Figure 13-2. I/O Permission Bit Map
I/O Map Base
Task State Segment (TSS)
64H
31
24
23
0
1
1111111
I/O Permission Bit Map
0
I/O map base
must not exceed
DFFFH.
Last byte of bit
map must be fol-
lowed by a byte
with all bits set