
112
Chapter 3: General-Purpose Programming
AMD 64-Bit Technology
24593—Rev. 3.09—September 2003
and that ordering can change from one implementation to
another. If the use of an unaligned I/O port is required, and the
order of bus transactions to that port is important, software
should decompose the access into multiple, smaller aligned
accesses.
Memory-Mapped I/O.
To maximize software performance,
processor implementations can execute instructions out of
program order. This can cause the sequence of memory accesses
to also be out of program order, called
weakly ordered
. As
described in “Accessing Memory” on page 113, the processor
can perform memory reads in any order, it can perform reads
without knowing whether it requires the result (speculation),
and it can reorder reads ahead of writes. In the case of writes,
multiple writes to memory locations in close proximity to each
other can be combined into a single write or a burst of multiple
writes. Writes can also be delayed, or buffered, by the
processor.
Application software that needs to force memory ordering to
memory-mapped I/O devices can do so using the read/write
barrier instructions: LFENCE, SFENCE, and MFENCE. These
instructions are described in “Forcing Memory Order” on
page 115. Serializing instructions, I/O instructions, and locked
instructions can also be used as read/write barriers, but they
modify program state and are an inferior method for enforcing
strong-memory ordering.
Typically, the operating system controls access to memory-
mapped I/O devices. The AMD64 architecture provides
facilities for system software to specify the types of accesses
and their ordering for entire regions of memory. These facilities
are also used to manage the cacheability of memory regions.
See “System-Management Instructions” in Volume 2 for
further information.
3.8.3
Protected-Mode
I/O
In protected mode, access to the I/O-address space is governed
by the I/O privilege level (IOPL) field in the rFLAGS register,
and the I/O-permission bitmap in the current task-state
segment (TSS).
I/O-Privilege Level.
RFLAGS.IOPL governs access to
IOPL-
sensitive
instructions. All of the I/O instructions (IN, INS, OUT,
and OUTS) are IOPL-sensitive. IOPL-sensitive instructions
cannot be executed by a program unless the program’s current-