
Chapter 3: General-Purpose Programming
93
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
Also, implementation of certain media instructions (such as
FXSAVE and FXRSTOR) and system instructions (such as
RDMSR and WRMSR) is indicated by CPUID function bits. See
“Processor Feature Identification” in Volume 2 for a full
description of the CPUID instruction and its function codes.
3.7
Control Transfers
3.7.1
Overview
From the application-program’s viewpoint, program-control
flow is sequential—that is, instructions are addressed and
executed sequentially—except when a branch instruction (a
call, return, jump, interrupt, or return from interrupt) is
encountered, in which case program flow changes to the branch
instruction’s target address. Branches are used to iterate
through loops and move through conditional program logic.
Branches cause a new instruction pointer to be loaded into the
rIP register, and sometimes cause the CS register to point to a
different code segment. The CS:rIP values can be specified as
part of a branch instruction, or they can be read from a register
or memory.
Branches can also be used to transfer control to another
program or procedure running at a different privilege level. In
such cases, the processor automatically checks the source
program and target program privileges to ensure that the
transfer is allowed before loading CS:rIP with the new values.
3.7.2
Privilege Levels
The processor’s
protected
modes include legacy protected mode
and long mode (both compatibility mode and 64-bit mode). In
all protected modes and virtual x86 mode, privilege levels are
used to isolate and protect programs and data from each other.
The privilege levels are designated with a numerical value from
0 to 3, with 0 being the most privileged and 3 being the least
privileged. Privilege 0 is normally reserved for critical system-
software components that require direct access to, and control
over, all processor and system resources. Privilege 3 is used by
application software. The intermediate privilege levels (1 and
2) are used, for example, by device drivers and library routines
that access and control a limited set of processor and system
resources.
Figure 3-9 on page 94 shows the relationship of the four
privilege-levels to each other. The protection scheme is
implemented using the segmented memory-management