CH02
CH02
(A)
(1978)
Microcontrollers)
(2000)
Increase Increase
Programming
Model
General Purpose
Registers
Special Purpose
Registers
Segment
80386 and above:
Registers
-32-bit registers (except seg. regs.)
-Two additional segment registers:F,G
General-Purpose Registers
• The top portion of the programming
model contains the general purpose
registers: EAX, EBX, ECX, EDX,
EBP, ESI, and EDI
• Can carry both Data & Address offsets
• Although general in nature, each has
a special purpose and name:
• EAX – Accumulator
Used also as AX (16 bit), AH (8
bit), and AL (8 bit)
• EBX – Base Index often used to
address memory (BX, BH, and BL)
General-Purpose Registers (continued)
• ECX – count, for shifts, rotates,
and loops (CX, CH, and CL)
• EDX – data, used with multiply
and divide (DX, DH, and DL)
• EBP – base pointer used to
address stack data (BP)
• ESI – source index (SI) for
memory locations, e.g. with
string instructions
• EDI – destination index (DI) for
memory locations
Special-Purpose Registers
• ESP, EIP, and EFLAGS
Each has a specific task
– ESP – Stack pointer: Offset to the top of the stack in
the stack segment. Used with procedure calls (SP)
– EIP – Instruction Pointer: Offset to the next
instruction in a program in the code segment (IP)
– EFLAGS – indicates latest conditions (state) of the
microprocessor (FLAGS)
Used With
SS
CS
EFLAGS
80386DX
Determined by
The Flags last operation
20-bit (5-byte) 64 KB +
Physical Segment 16-bit each
Memory address
Top of CS:
090F0
FFFF+
190EF
Disadvantages:
• Complex hardware and for address generation
• Address computation delay for every memory access
• Software limitation: Program size limited by segment size (64KB with
the 8086)
Limitations of the above real mode segmentation
scheme
• Segment size is fixed at and limited to 64 KB
• Segment can not begin at an arbitrary memory address…
With 20-bit memory addressing, can only begin at
addresses starting with 0H, i.e. at 16 byte intervals
→ Principle is difficult to apply with 80286 and above,
with segment registers remaining at 16-bits!
Append: 00H 0000H
80286 and above use 24, 32 bit addresses but still 16-
bit segment registers
• No protection mechanisms: Programs can overwrite
operating system code segments and corrupt them!
LSB
LSB
Max Limit <
Base: 3-byte → 24 bit addressing Max Limit =
Max offset
Max offset
Base: 4-byte → 32 bit addressing
Limit: 2-byte (16 bit) → Seg. Size: 1B-64 KB
Limit: 2 1/2-byte (20 bit) → Size: 1B-1MB
Note provision for upward compatibility
With G (4 K multiplier) bit = 1: 4KB-4GB
(286 software run on higher processors)
Protected Mode: 80386 and above (Pentium class)
• The base is a 32-bit address at which
the memory segment starts
• The limit is a 20-bit number. When
added to the base, it addresses the
last location in the segment
• The limit has a modifier bit called
Granularity (G). If G=0: no change
• If G=1, append limit with FFFH, i.e.
segment size is multiplied by 4K
• With limit specifying 1 MB segments
and G=1 (i.e. 4K multiplier): Max
Segment size = 4K x 1 MB = 4 GB
• With 16K segments like this, the
system can address 16K x 4 GB = 64 TB
(not necessarily all will be in physical
memory)
80386 and above Example:
• Descriptor has: base = 23000000H
limit = 012FFH
With G = 0
Segment start = 23000000H
Segment end = 23000000H + 012FFH=230012FFH
Segment size = 12FFH+1H = 1300H
(= 19 x 256 bytes)
(Segment
Register) (Offset
Register)
Segment Descriptor Table
Table
Access
Maximum
Allowed
Offset
16-bit
Segment
Register H
000b
Descriptor # 0
What is the RPL value?
What is the selector value? GDT Base Address
Are we using the global or the local descriptor? table?
(= segment #)
The Access Rights Byte: 80286 & higher*
Code
Segment DPL will be compared with
the request privilege level
(RPL) in the segment register
specifying this segment.
Highest
RPL Hardware
(In Seg Reg)
Privilege
Comparator RPL DPL
DPL Allow
(in descriptor)
Access
to segment
Lowest
Types of Descriptor Tables in memory
• One Global Descriptor Table (GDT): (64 KB Max) (Start and Limit are cached in GDTR)
• One Interrupt Descriptor Table (IDT): (64 KB Max) (Start, Limit cached in IDTR)
8-byte descriptors called “interrupt gates” that define the attributes and starting addresses of the
interrupt service routines for up to 256 hardware and software interrupts
• Several local segment descriptor tables, one table for each task. The GDT contains descriptors for these
tables as mentioned in 2 above.
Types of Descriptor Tables in memory
Segment Register
Offset
i
16-bit
Segment # i
Selectors Base, Calculate
Limit, Physical Addressed Byte
LDTR Access
Address
for Seg i
Memory
8-byte System:
Descriptors
Code,
Data,
For each Task Stack,
Extra
Segments
Base,
Limit,
Access One LDT table for each task
Interrupt Descriptor for LDT j
number
for task 0 for task j
…..
(table base address, limit)
Program Invisible Registers (caches)
In main memory Invisible mP Registers (not seen by programmer)
Segment Descriptor
Descriptor cache for the currently used 6 segments
Loaded
from GDT
or LDT tables
In memory
Visible Segment Selector every time
mp registers the segment
number
changes
Task Cache for the task state segment (TSS) and the descriptor of the local segment
Register descriptor table - for the currently executing task Loaded
from the GDT
Task Selector Task’s TSS In memory
every time
LDT Selector Task’s LDT the task
changes
Global
LDT Register
(for the GDT and IDT tables)
Descriptor Table
(GDT) for: GDT (24 or 32 bits) GDT (16-bit)
segments, tasks,
and LDT
Descriptor
Table for
interrupts
Physical
Byte Address
#
Logical (To Memory)/
Page # or Get from HD
- Page table maps logical page #s
to corresponding physical frame #’s
- Offset part is the same for both
2-Level Paging
• 232 = 4 GB address space → 1 M x 4K pages
• The 1-level approach requires a single contiguous page table (but
maybe we do not need to do all translations!)
• 2-level paging uses several smaller page tables (up to 1K tables), each
providing translation for 1K pages.
• The smaller page tables can easily fit in memory and we
can use as many of them as needed
• Start address for each page table used is kept in one directory table
• For 2-level Paging: 32-bit linear byte address space (as
generated by the processor) is divided into three parts:
– Directory: 10 bits, determines which page table in the page table
directory
– Page table: 10 bits, determines which page in that page table
– Memory offset: 12 bits, determines which byte in that page (same
for both logical and physical pages)
2-Level Memory Paging: 80386 and above
32-bit linear byte address 1024 x 1024 = 1 M
(232 = 4 G virtual bytes)
Page #
(1 of 1 M pages)
10 10 12 bits 3 Which byte in that
page? (offset in page)
1 1024
Which page table? Addressed Physical byte
(Page table # in
Directory)
2 Which page in that 1K x 4 bytes = 4KB
page table? (In memory) offset
(Page # in page table)
Logical
4 bytes
table
Start address of
offset Physical Page
1K x 4 bytes 4 K bytes
(In memory)
Page mapping
4 bytes Is done here
Start address of (Linear → Physical)
a page table Page In Page Out
offset 1024
1024 page
page table entries
Page table directory Start addresses per table
Base address
1024 x 1024 x 4 K = 4 G Physical bytes
80386 and above:
Paging is controlled by four control registers CR0-CR3 on the mp
(Pentium only)
Remaining 12
Most significant 20 bits of the Bits are set to 0’s
000H
table
10 10 12 bits
Which page table
in Directory? Append
Which byte in that 1024
00b
page? Addressed Physical byte
10 bits
→ 12-bit offset Which page in that
For 1024 pages Offset
page table? Append
10 bits 12 bits
00b
→ 12-bit offset 20 bits + 1 byte
+
000H
(In memory) Physical Page # Append 4 K byte page
Append 4 bytes
20 bits 12 bits 20 bits 12 bits
000H +
Append 000H
1024
1024 page
CR3 page table entries
Base Address 000H entries
of page directory
1024 x 1024 x 4 K = 4 G Physical bytes
Linear → Physical
Memory Paging: Example Linear Physical
C8FFF
Physical Page 4K
00110H Bytes
Physical
Base address for page table 0 Address Corresponding
Physical Byte
,,,,,
000H Page 00110 (Physical)
Base for table 2 + 000H
Base for table 1
12 bits000H Start of
20 bits
000H
Page Table 0
000H + +
Base Address + = 320H 4K
Table Directory
of Page = 000H Bytes
Table Directory
Associative
Corresponding 1
Search Frame #
3
Add entry to TLB Add entry to TLB
into 3
2 memory
2 Add entry to
Page Table
But page table hit
2,3 1
TLB miss 3
& Page table miss
→ Page fault P bit = 0 3
Physical
We assume Miss in page table also
1-Level page tables Note: Frame = Physical Page
i.e.
for simplicity
Organizational Model of the Processor
- Functional aspects- how the processor actually functions
- Internal organization is determined by functionality required
Two main tasks for the microprocessor in a mp-based system:
1. Interface with external peripherals
2. Execute instructions
External Buses
Control bus
Microprocessor-based
System; e.g. a microcomputer
Memory I/O Devices
The 8086 processor model (Organization)
• Early pipelining attempts
• Two main functional units:
- The Bus Interface Unit (BIU)
- The Execution Unit (EU)
• The BIU generates memory and I/O addresses for reading code and
transferring data to/from the processor
• The EU receives code and data from the BIU, executes the
instructions, and stores results in the general purpose registers
• Pipelined architecture:
Two, hopefully independent operations, are executed at the same
time by two separate units:
- Fetch by the BIU
- Execute by the EU
& Control
External mp busses
EU empties it
Execution: (EU) by executing
instructions
• Recognize, decode, and
execute fetched program
instructions
ALU
Pipelined
(8086)
0.25:1
2-stage
1 execution pipelining
unit
0.5:1
Super pipelining
EU
On Chip