0% found this document useful (0 votes)
61 views62 pages

EIE3343 Memory Management - Segmentation and Paging

This document provides an overview of memory management techniques in microprocessors, including segmentation and paging. It discusses real mode memory addressing, which allows access to the first 1MB of memory. Protected mode addressing allows access to memory above 1MB using segmentation and paging. Segmentation divides memory into segments selected by segment registers. Paging maps virtual addresses to physical addresses to access segments in memory. The document describes segmentation mechanisms, descriptors, and program-invisible registers used to implement segmentation and paging.

Uploaded by

v2xv4p6pv8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views62 pages

EIE3343 Memory Management - Segmentation and Paging

This document provides an overview of memory management techniques in microprocessors, including segmentation and paging. It discusses real mode memory addressing, which allows access to the first 1MB of memory. Protected mode addressing allows access to memory above 1MB using segmentation and paging. Segmentation divides memory into segments selected by segment registers. Paging maps virtual addresses to physical addresses to access segments in memory. The document describes segmentation mechanisms, descriptors, and program-invisible registers used to implement segmentation and paging.

Uploaded by

v2xv4p6pv8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Memory Management –

Segmentation and Paging

Dr. Lawrence Cheung

Semester 2, 2023/2024
Introduction
• This chapter
− provides an overview of the Intel family of
microprocessors.
− presents the microprocessor as a programmable
device by first looking at
• (i) its internal programming model and then at
• (ii) how it addresses its memory space.

Memory Management – Segmentation and Paging 2


The Hong Kong Polytechnic University
Objectives
• Upon completion of this chapter, you will be
able to
− Describe how memory is accessed using real
mode memory-addressing techniques.
− Describe how memory is accessed using protected
mode memory-addressing techniques.
− Detail the operation of the memory paging
mechanism.

Memory Management – Segmentation and Paging 3


The Hong Kong Polytechnic University
Topics
• Memory Addressing – Real Mode
• Memory Addressing – Protected Mode
• Segmentation Mechanism
• Paging Mechanism

Memory Management – Segmentation and Paging 4


The Hong Kong Polytechnic University
Topics
• Memory Addressing – Real Mode
• Memory Addressing – Protected Mode
• Segmentation Mechanism
• Paging Mechanism

Memory Management – Segmentation and Paging 5


The Hong Kong Polytechnic University
Real Mode
• In real mode operation, it allows an Intel CPU
to address only the first 1M byte of memory
space (even the Pentium microprocessor).
• Real mode operation
− Is the default operation mode.
− Allows downward compatibility.

Memory Management – Segmentation and Paging 6


The Hong Kong Polytechnic University
Real Mode
− Default operation mode: In all cases, each of these
microprocessors begins operation in the real mode
by default whenever power is applied or the
microprocessor is reset.
− Downward compatibility: Real mode operation
allows application software written for the
8088/8086, which contain only 1M byte of memory,
to function in the 80286 and above without
changing the software.

Memory Management – Segmentation and Paging 7


The Hong Kong Polytechnic University
Real Mode
• The first 1M byte of memory is called either the
real memory or conventional memory system.

Memory Management – Segmentation and Paging 8


The Hong Kong Polytechnic University
Segments and Offsets
• A combination of a segment address and an
offset address access a memory location in the
real mode.
• The segment address, located within one of the
segment registers, defines the beginning
address of any 64K-byte memory segment.
• The offset address selects any location within
the 64K-byte memory segment.

Memory Management – Segmentation and Paging 9


The Hong Kong Polytechnic University
Segments and Offsets
• Example: Segment register = 1000H, Offset
register = F000H

Memory Management – Segmentation and Paging 10


The Hong Kong Polytechnic University
Segments and Offsets

Memory Management – Segmentation and Paging 11


The Hong Kong Polytechnic University
Topics
• Memory Addressing – Real Mode
• Memory Addressing – Protected Mode
• Segmentation Mechanism
• Paging Mechanism

Memory Management – Segmentation and Paging 12


The Hong Kong Polytechnic University
Protected Mode
• Protected mode memory addressing (80286
and above) allows access to data and programs
located above the first 1M byte of memory as
well as within the first 1M byte of memory.

Memory Management – Segmentation and Paging 13


The Hong Kong Polytechnic University
Protected Mode
• Protected mode memory addressing
Logical
Address

Logical
Address Different size!
Memory Management – Segmentation and Paging 14
The Hong Kong Polytechnic University
Topics
• Memory Addressing – Real Mode
• Memory Addressing – Protected Mode
• Segmentation Mechanism
• Paging Mechanism

Memory Management – Segmentation and Paging 15


The Hong Kong Polytechnic University
Segmentation Mechanism
• The segment register is interpreted differently
in different modes by the microprocessor to
access the memory segment.
• In real mode, there are four types of
segments: CS (Code Segment), DS (Data
Segment), ES (Extended Segment) and SS
(Stack Segment).

EIE3343 The Microprocessor and Its Architecture 16


The Hong Kong Polytechnic University
Segmentation Mechanism
• In protected mode, the segment register
stores more information.

EIE3343 The Microprocessor and Its Architecture 17


The Hong Kong Polytechnic University
Segmentation Mechanism
• RPL = Requested Privilege Level

EIE3343 The Microprocessor and Its Architecture 18


The Hong Kong Polytechnic University
Segmentation Mechanism
• TI = Table Indicator
There are a number of descriptor
tables in the memory, but at a DT1
particular instant only 2 of them
are active.
DT2
Segment register
selecter TI RPL
Selector
13 bit 1 bitTI 2 bitRPL
13 bits 1 bit 2bits
DT3
Select either LDT or GDT (LDT)

descriptor 8191 DT7


Select one out of the descriptor 8190 (GDT)
8192 descriptors descriptor 8189
DT9 Memory
space
descriptor 2
EIE3343 The Microprocessor and Its Architecture descriptor 1 19
The Hong Kong Polytechnic University descriptor 0
Segmentation Mechanism
• The descriptor describes the memory
segment's location, length, and access rights
of the segment of memory.
• There are two descriptor tables.
− Global descriptors contain segment definitions
that apply to all programs,
− Local descriptors are usually unique to an
application.

EIE3343 The Microprocessor and Its Architecture 20


The Hong Kong Polytechnic University
Segmentation Mechanism
• Each descriptor table contains 8192
descriptors.

EIE3343 The Microprocessor and Its Architecture 21


The Hong Kong Polytechnic University
Descriptors
• Each descriptor is 8 bytes in length.
• The base address portion of the descriptor
(Base) indicates the starting location of the
memory segment.
• The paragraph boundary limitation is removed
in protected mode.

EIE3343 The Microprocessor and Its Architecture 22


The Hong Kong Polytechnic University
Descriptors
• The segment limit (Limit) contains the last
offset address found in a segment.
• Example: If a segment begins at memory
location F00000H and ends at location
F000FFH, the base address is F00000H and the
limit is FFH.

EIE3343 The Microprocessor and Its Architecture 23


The Hong Kong Polytechnic University
Descriptors
• The 80286 accesses memory segments that
− are of size 1 to 64K bytes.
− begin at any location in its 16M bytes of memory.
• The 80386 and above access memory
segments that
− are of size 1 to 1M bytes or 4K to 4G bytes.
− begin at any location in its 4G bytes of memory .

EIE3343 The Microprocessor and Its Architecture 24


The Hong Kong Polytechnic University
Descriptors
• The upper bound is determined by the
number of bits in the corresponding field.
• The value of the limit will be multiplied by 4K
bytes if the granularity bit (G bit) is set to be 1.

EIE3343 The Microprocessor and Its Architecture 25


The Hong Kong Polytechnic University
Descriptors

Append FFF to the right

EIE3343 The Microprocessor and Its Architecture 26


The Hong Kong Polytechnic University
Descriptors
• The AV bit, in the 80386 and above descriptor,
is used by some operating systems to indicate
that the segment is available (AV = 1) or not
(AV = 0).

EIE3343 The Microprocessor and Its Architecture 27


The Hong Kong Polytechnic University
Descriptors
• The D bit indicates how the 80386 through
the Pentium Pro instructions access register
and memory data in the protected mode or
real mode.
− If D = 0, the instructions are 16-bit instructions
compatible with the 8086-80286 microprocessors,
else the instructions are 32-bit instructions.

EIE3343 The Microprocessor and Its Architecture 28


The Hong Kong Polytechnic University
Descriptors
− The 32-bit instruction mode is only accessible in a
protected mode system such as Windows NT,
Windows 95, or OS/2.
− The access rights byte controls access to the
protected mode memory segment.

EIE3343 The Microprocessor and Its Architecture 29


The Hong Kong Polytechnic University
Descriptors
• Access Rights

EIE3343 The Microprocessor and Its Architecture 30


The Hong Kong Polytechnic University
80286 system
Example

Selector TI RPL
13 bits 1 bit 2bits

EIE3343 The Microprocessor and Its Architecture 31


The Hong Kong Polytechnic University
Program-Invisible Registers
• The global and local descriptor tables are
placed in the memory system.
• 80286 and above contain program-invisible
registers to access and specify the address of
these tables.

EIE3343 The Microprocessor and Its Architecture 32


The Hong Kong Polytechnic University
Program-Invisible Registers
• The program invisible registers are not
directly addressed by software.
• These registers control the microprocessor
when operated in the protected mode.

EIE3343 The Microprocessor and Its Architecture 33


The Hong Kong Polytechnic University
Program-Invisible Registers

EIE3343 The Microprocessor and Its Architecture 34


The Hong Kong Polytechnic University
TR: Task Register

Program-Invisible Registers IDTR: Interrupt Descriptor


Table Register

Segment register Memory


(CS/DS/ES/SS/FS/ space
GS/TR/LDTR)
selecter
selector TI RPL
Selector TI RPL
13 bit 1 bit 2 bit
13 bits 1 bit 2bits

LDT

Starting addr of LDT

point to the
segment
carrying the

Size of GDT
Select a LDT
selecter
selector descriptor in descriptor n
GDT
GDT
Define
the size Starting addr of GDT

EIE3343 The Microprocessor and Its Architecture 35


The Hong Kong Polytechnic University
Program-Invisible Registers
• Each of the segment registers contains a
program-invisible portion used in the
protected mode.
• The program-invisible portion of the segment
register is loaded with the base address, limit,
and access rights each time the number in the
segment register is changed.

EIE3343 The Microprocessor and Its Architecture 36


The Hong Kong Polytechnic University
Program-Invisible Registers
• This allows the microprocessor to access a
memory segment repeatedly without
referring back to the descriptor table for each
access (using a cache instead).
• The GDTR (global descriptor table register)
and IDTR (interrupt descriptor table register)
contain the base address of the descriptor
table and its limit.

EIE3343 The Microprocessor and Its Architecture 37


The Hong Kong Polytechnic University
Program-Invisible Registers
• When protected mode operation is desired,
the address of the global descriptor table and
its limit are loaded into the GDTR.
• Before using protected mode, the interrupt
descriptor table and the IDTR must be
initialized.

EIE3343 The Microprocessor and Its Architecture 38


The Hong Kong Polytechnic University
Program-Invisible Registers
• The location of the local descriptor table is
selected from the global descriptor table.
• One of the global descriptors is set up to
address the local descriptor table.
• To access the local descriptor table, the LDTR
is loaded with a selector, just as a segment
register is loaded with a selector.

EIE3343 The Microprocessor and Its Architecture 39


The Hong Kong Polytechnic University
Program-Invisible Registers
• The task register (TR) holds a selector that
accesses a descriptor that defines a task.
− A task is most often a procedure or application
program.
− The descriptor in TR is stored in the global
descriptor table.
• Task switching allows multitasking systems to
switch from one task to another in a simple
and orderly fashion.
EIE3343 The Microprocessor and Its Architecture 40
The Hong Kong Polytechnic University
Linear Address
• Logical address to linear address

Segment
registers:
CS, DS, ES, SS,
FS, GS, etc.

EIE3343 The Microprocessor and Its Architecture 41


The Hong Kong Polytechnic University
Linear Address
• Logical address to linear address

EIE3343 The Microprocessor and Its Architecture 42


The Hong Kong Polytechnic University
Topics
• Memory Addressing – Real Mode
• Memory Addressing – Protected Mode
• Segmentation Mechanism
• Paging Mechanism

EIE3343 The Microprocessor and Its Architecture 43


The Hong Kong Polytechnic University
Paging Mechanism
• Paging performs linear to physical address
translation.
• Paging allows any program and data
relocatable (even more powerful than the
segment and offset addressing scheme.).

EIE3343 The Microprocessor and Its Architecture 44


The Hong Kong Polytechnic University
Memory Paging
• The memory paging mechanism located
within the 80386 and above allows any
physical memory location to be assigned to
any linear address.
• The linear address is defined as the address
generated by a program.
• With the memory paging unit, the linear
address is invisibly translated into any physical
address.
EIE3343 The Microprocessor and Its Architecture 45
The Hong Kong Polytechnic University
Paging Mechanism
• Linear address to physical address

EIE3343 The Microprocessor and Its Architecture 46


The Hong Kong Polytechnic University
How Paging Works in Intel’s CPU
1. The memory space is divided into a number
of pages.
2. Each page is of size 4 Kbytes.
3. Any data/program is divided into pages of
size 4 Kbytes each and these pages are
individually loaded into the memory space.
4. Any data/program byte is associated with a
logical address.
EIE3343 The Microprocessor and Its Architecture 47
The Hong Kong Polytechnic University
How Paging Works in Intel’s CPU
5. The dir:page info tells which page the
requested data is in.
6. The offset tells which byte in the specified
page is the requested data
A 32-bit linear address is divided
into 3 fields: dir, page and offset

dir page offset


10 bits 10 bits 12 bits

EIE3343 The Microprocessor and Its Architecture 48


The Hong Kong Polytechnic University
How Paging Works in Intel’s CPU

Example: L. Addr = 00F23000H →


0000,0000,1111,0010,0011,0~0B →
Dir = 3H, page = 323H, offset = 0H
EIE3343 The Microprocessor and Its Architecture 49
The Hong Kong Polytechnic University
Paging Registers
• The paging unit is controlled by the contents
of the microprocessor's control registers.

EIE3343 The Microprocessor and Its Architecture 50


The Hong Kong Polytechnic University
Paging Registers

EIE3343 The Microprocessor and Its Architecture 51


The Hong Kong Polytechnic University
Paging Registers
• The PG bit selects paging when it is set to be
1.
• The linear address, as it is generated by the
software, is broken into three sections that
are used to access the page directory entry,
page table entry, and page offset address.
• A page of memory contains 4K bytes of
memory.

EIE3343 The Microprocessor and Its Architecture 52


The Hong Kong Polytechnic University
The Page Directory and Page Table
• A page directory contains entries that locate
the starting addresses of up to 1024 page
tables.
• Each page table contains 1024 entries that
locate the starting addresses of 1024 pages.
page directory page table

4K bytes
::: :::
4K bytes
1K entries
: 4 bytes/entry :
Template format of a table entry

EIE3343 The Microprocessor and Its Architecture 53


The Hong Kong Polytechnic University
The Page Directory and Page Table
• The page directory plus the page tables could
be a big storage overhead to the memory
system.
• Example: A paged memory system of 4G bytes
must allocate 4K bytes of memory for the
page directory and 4K x 1024 bytes for the
1024 page tables.

EIE3343 The Microprocessor and Its Architecture 54


The Hong Kong Polytechnic University
The Page Directory and Page Table

pages
page tables

4K bytes
::: :::

4K bytes
Key data ::::
1 Table (P.D./P.T.) : : page directory

4K bytes
1K entries :
4 bytes/entry :::
:::
::: :::
4K bytes :::
: :::
::

EIE3343 The Microprocessor and Its Architecture 55


The Hong Kong Polytechnic University
The Page Directory and Page Table
• Time overhead - Repaging a 4K byte section of
memory requires access to the page directory
and a page table, both located in memory.
• Intel has incorporated a cache called TLB
(translation look-aside buffer) to hold the
most recent page translation addresses to
speed up the translation.

EIE3343 The Microprocessor and Its Architecture 56


The Hong Kong Polytechnic University
A More Detailed Example

EIE3343 The Microprocessor and Its Architecture 57


The Hong Kong Polytechnic University
A More Detailed Example

EIE3343 The Microprocessor and Its Architecture 58


The Hong Kong Polytechnic University
The Page Directory and Page Table
• Example: Suppose that the EMM386.exe
program allows access to 16M bytes of
extended and conventional memory through
paging, and locations C8000H-EFFFFH must be
repaged to locations 110000-138000H with all
other areas of memory paged to their normal
locations.

EIE3343 The Microprocessor and Its Architecture 59


The Hong Kong Polytechnic University
A More Detailed Example

EIE3343 The Microprocessor and Its Architecture 60


The Hong Kong Polytechnic University
The Full Picture

EIE3343 The Microprocessor and Its Architecture 61


The Hong Kong Polytechnic University
End

You might also like