Systems Programming For The Intel Architecture
Systems Programming For The Intel Architecture
Systems Programming
for the Intel Architecture
Steve Goddard
[email protected]
http://www.cse.unl.edu/~goddard/Courses/CSCE351
2
System Flags in the
EFLAGS Register
4
Segmented Memory Model
Segment Descriptor
6
Segment Selector
8
Segment Registers
10
Memory Management
Registers
11
12
Gate Descriptors
◆ To provide controlled access to code segments
with different privilege levels, the processor
provides a special set of descriptors called gate
descriptors. There are four kinds of gate
descriptors:
» Call gates
» Trap gates
» Interrupt gates
» Task gates
13
Call Gates
◆ A call-gate descriptor may reside in the GDT or in an
LDT, but not in the interrupt descriptor table (IDT). It
performs six functions:
1. It specifies the code segment to be accessed.
2. It defines an entry point for a procedure in the specified code
segment.
3. It specifies the privilege level required for a caller trying to access
the procedure.
4. If a stack switch occurs, it specifies the number of optional
parameters to be copied between stacks.
5. It defines the size of values to be pushed onto the target stack: 16-
bit gates force 16-bit pushes and 32-bit gates force 32-bit pushes.
6. It specifies whether the call-gate descriptor is valid.
14
Call Gate Mechanism
15
Segment Descriptor
Gate Descriptor
16
Interrupt Descriptor Table (IDT)
◆ Associates each exception or interrupt vector with
a gate descriptor for the procedure or task used to
service the associated exception or interrupt.
17
18
Task Management
◆ The Intel Architecture provides a mechanism for
» saving the state of a task,
» for dispatching tasks for execution, and
» for switching from one task to another.
◆ When operating in protected mode, all processor
execution takes place from within a task.
◆ A task is made up of two parts:
» a task execution space
» task-state segment (TSS).
19
20
Task State
◆ The following items define the state of the currently
executing task:
» The task’s current execution space, defined by the segment
selectors in the segment registers (CS, DS, SS, ES, FS, and GS).
» The state of the general-purpose registers.
» The state of the EFLAGS register.
» The state of the EIP register.
» The state of control register CR3.
» The state of the task register.
» The state of the LDTR register.
» The I/O map base address and I/O map (contained in the TSS).
» Stack pointers to the privilege 0, 1, and 2 stacks (contained in the
TSS).
» Link to previously executed task (contained in the TSS).
21
TSS Structure
22
Task Register
23
TSS Descriptor
24
Task Gate Descriptor
25
26
Putting It All Together
27