IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.

Slides:



Advertisements
Similar presentations
Memory Management Unit
Advertisements

ITEC 352 Lecture 27 Memory(4). Review Questions? Cache control –L1/L2  Main memory example –Formulas for hits.
4/14/2017 Discussed Earlier segmentation - the process address space is divided into logical pieces called segments. The following are the example of types.
Intel MP.
Allocating Memory.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Introduction to the Intel x86’s support for “virtual” memory
Misc Exercise 2 updated with Part III.  Due on next Tuesday 12:30pm. Project 2 (Suggestion)  Write a small test for each call.  Start from file system.
Linux Memory Issues An introduction to some low-level and some high-level memory management concepts.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures.
Defining protected-mode segment-descriptors An example of a protected-mode bootsector application that draws a message to the video display.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Chapter 8.3: Memory Management
Memory Management (II)
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Processor Exceptions A survey of the x86 exceptions and mechanism for handling faults, traps, and aborts.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Linux Memory Issues Introduction. Some Architecture History 8080 (late-1970s) 16-bit address (64-KB) 8086 (early-1980s) 20-bit address (1-MB) (mid-’80s)
Chapter 3.2 : Virtual Memory
Venturing into 64-bit mode Examining the steps needed to take the processor into IA-32e mode -- and then back out again.
Segment-registers’ hidden bits A look at how segmentation attributes are cached within the CPU’s segment-registers.
Venturing into protected-mode
Introduction to the Intel x86’s support for “virtual” memory
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
A ‘protected-mode’ exploration A look at the steps needed to build segment-descriptors for displaying a message while in protected-mode.
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
Interrupts in Protected-Mode Writing a protected-mode interrupt-service routine for the timer-tick interrupt.
UNIT 2 Memory Management Unit and Segment Description and Paging
80386DX.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Subject: Operating System.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Computer Architecture 2011 – VM x86 1 Computer Architecture Virtual Memory (VM) – x86 By Dan Tsafrir, 30/5/2011 Presentation based on slides by Lihu Rappoport.
Paging Example What is the data corresponding to the logical address below:
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
80386DX.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
Memory Management CS Spring Overview Partitioning, Segmentation, and Paging External versus Internal Fragmentation Logical to Physical Address.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
X86 (32-bit) Paging Reference –text: Tanenbaum ch.4.3 Reference on Win2K memory management –text: Tanenbaum ch
Information Security - 2. Memory Segmentation Segment Descriptors – to In 8086, the program is not expected to generate a non- existent memory.
Information Security - 2. Descriptor Tables Descriptors are stored in three tables: – Global descriptor table (GDT) Maintains a list of most segments.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Memory Management.
COMBINED PAGING AND SEGMENTATION
143A: Principles of Operating Systems Lecture 5: Address translation
Copyright © 2011, Elsevier Inc. All rights Reserved.
x86 segmentation, page tables, and interrupts
Operating Modes UQ: State and explain the operating modes of X86 family of processors. Show the mode transition diagram highlighting important features.(10.
Practice Six Chapter Eight.
Module IV Memory Organization.
Page Replacement Implementation Issues
Introduction to the Intel x86’s support for “virtual” memory
Virtual Memory Hardware
Introduction to the Pentium’s support for “virtual” memory
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Assembly Language for Intel-Based Computers, 5th Edition
COMP755 Advanced Operating Systems
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory

What is ‘paging’? It’s a scheme for dynamically remapping addresses for fixed-size memory-blocks Virtual address-spacePhysical address-space

What’s ‘paging’ good for? For efficient ‘time-sharing’ among multiple tasks, an operating system needs to have several programs residing in main memory at the same time To accomplish this using actual physical memory-addressing would require doing address-relocation calculations each time a program was loaded (to avoid conflicting with any addresses already being used)

Why use ‘paging’? Use of ‘paging’ allows ‘relocations’ to be done just once (by the linker), and every program can ‘reuse’ the same addresses Task #1 Task #2 Task #3 physical memory

How to enable paging PGPG CDCD NWNW AMAM WPWP NENE ETET TSTS EMEM MPMP PEPE Control Register CR0 Protected-Mode must be enabled (PE=1) Then ‘Paging’ can be enabled (set PG=1) # Here is how you can enable paging (if already in protected-mode) mov%cr0, %eax# get current machine status bts$31, %eax# turn on the PE-bit’s image mov%eax, %cr0# put modified status in CR0 jmppg# now flush the prefetch queue pg: # but you had better prepare your ‘mapping-tables’ beforehand!

Several ‘paging’ schemes Intel’s design for ‘paging’ has continued to evolve since its introduction in CPU New processors support the initial design, as well as several optional extensions We shall describe the initial design which is simplest and remains as the ‘default’ It is based on subdividing the entire 4GB virtual address-space into 4KB blocks

Terminology The 4KB memory-blocks are called ‘page frames’ -- and they are non-overlapping Therefore each page-frame begins at a memory-address which is a multiple of 4K Remember: 4K = 4 x 1024 = 4096 = 2 12 So the address of any page-frame will have its lowest 12-bits equal to zeros Example: page six begins at 0x

Control Register CR3 Register CR3 is used by the CPU to find the tables in memory which will define the address-translation that it should employ This table is called the ‘Page Directory’ and its address must be ‘page-aligned’ Physical Address of the Page-Directory 310

Page-Directory The Page-Directory occupies one frame, so it has room for byte entries Each page-directory entry may contain a pointer to a further data-structure, called a Page-Table (also page-aligned 4KB size) Each Page-Table occupies one frame and has enough room for byte entries Page-Table entries may contain pointers

Two-Level Translation Scheme PAGE DIRECTORY CR3 PAGE TABLES PAGE FRAMES

Address-translation The CPU examines any virtual address it encounters, subdividing it into three fields offset into page-frame index into page-directory index into page-table bits 12-bits This field selects one of the 1024 array-entries in the Page-Directory This field selects one of the 1024 array-entries in that Page-Table This field provides the offset to one of the 4096 bytes in that Page-Frame

Page-Level ‘protection’ Each entry in a Page-Table can assign a collection of ‘attributes’ to the Page-Frame that it points to; for example: –The P-bit (page is ‘present’) can be used by the operating system to support its implementation of “demand paging” –The W/R-bit can be used to mark a page as ‘Writable’ or as ‘Read-Only’ –The U/S-bit can be used to mark a page as ‘User accessible’ or as ‘Supervisor-Only’

Format of a Page-Table entry PAGE-FRAME BASE ADDRESSPWU PWTPWT PCDPCD AD AVAIL LEGEND P = Present (1=yes, 0=no) W = Writable (1 = yes, 0 = no) U = User (1 = yes, 0 = no) A = Accessed (1 = yes, 0 = no) D = Dirty (1 = yes, 0 = no) PWT = Page Write-Through (1=yes, 0 = no) PCD = Page Cache-Disable (1 = yes, 0 = no)

Format of a Page-Directory entry PAGE-TABLE BASE ADDRESSPWU PWTPWT PCDPCD A0 PSPS AVAIL LEGEND P = Present (1=yes, 0=no) W = Writable (1 = yes, 0 = no) U = User (1 = yes, 0 = no) A = Accessed (1 = yes, 0 = no) PWT = Page Write-Through (1=yes, 0 = no) PCD = Page Cache-Disable (1 = yes, 0 = no) PS = Page-Size (0=4KB, 1 = 4MB)

Violations When a task violates the page-attributes of any Page-Frame, the CPU will generate a ‘Page-Fault’ Exception (interrupt 0x0E) Then the operating system’s page-fault exception-handler gets control and can take whatever action it deems is suitable The CPU will provide help to the OS in determining why a Page-Fault occurred

The Error-Code format The CPU will push an Error-Code onto the operating system’s stack P W/RW/R U/SU/S reserved (=0) Legend: P (Present): 1=attempted to access a ‘not-present’ page W/R (Write/Read): 1=attempted to write to a ‘read-only’ page U/S (User/Supervisor): 1=user attempted to access a ‘supervisor’ page ‘User’ means that CPL = 3; ‘Supervisor’ means that CPL = 0, 1, or 2

Control Register CR2 Whenever a ‘Page-Fault’ is encountered, the CPU will save the virtual-address that caused that fault into the CR2 register –If the CPU was trying to modify the value of an operand in a ‘read-only’ page, then that operand’s virtual address is written into CR2 –If the CPU was trying to read the value of an operand in a supervisor-only page (or was trying to fetch-and- execute an instruction) while CPL=3, the relevant virtual address will be written into CR2

Identity-mapping When the CPU first turns on the ‘paging’ capability, it must be executing code from an ‘identity-mapped’ page (or it crashes!) We have created a demo-program that shows how to create the Page-Directory and Page-Tables for an identity-mapping of the lowest 24 page-frames of RAM But it maps the 25th page-frame to VRAM

Using a ‘repeat-macro’ Our assembler’s macro-capability can be used to build an ‘identity-map’ page-table # Our linker-script offers us an advantage if we use the ‘.data’ section here.section.data.align0x1000 pgtbl:entry = 0# the initial physical address.rept24# we define 24 table-entries.longentry + 0x003# ‘present’ and ‘writable’ entry = entry + 0x1000# advance physical address.endr# conclusion of this macro.align0x1000 pgdir:.longpgtbl + 0x x003# first page-directory entry.align0x1000

Our ‘fileview’ utility One advantage of constructing paging-tables at assembly-time is that we can then examine the resulting table-entries with our ‘fileview’ utility For a demo-program named ‘pagedemo.s’: $ as pagedemo.s –o pagedemo.o $ ld pagedemo.o -T ldscript -o pagedemo.b Examine the executable ‘pagedemo.b’ file: $./fileview pagedemo.b

Depiction of identity-mapping 24 page-framesRAM Virtual address-space Physical address-space 0x x x00000 ‘identity’ mapping

Mapping used in ‘pagedemo.s’ 24 page-framesRAM Virtual address-space Physical address-space 0x x x page-frame VRAM 0x xB8000 0xB9000

‘paging’ requires protected-mode Memory-addressing in protected-mode is performed using ‘segment-descriptors’ Register GDTR holds a pseudo-descriptor ‘null’ descriptor Base_addressLimit GDTR ‘data’ descriptor ‘code’ descriptor 0x18 0x10 0x08 0x00 GLOBAL DESCRIPTOR TABLE

Segment-Descriptor Format Base[31..24]GD RSVRSV AVLAVL Limit [19..16] P DPLDPL SX C/DC/D R/WR/W ABase[23..16] Base[15..0]Limit[15..0] Legend: DPL = Descriptor Privilege Level (0..3) G = Granularity (0 = byte, 1 = 4KB-page)P = Present (0 = no, 1 = yes) D = Default size (0 = 16-bit, 1 = 32-bit)S = System (0 = yes, 1 = no) X = eXecutable (0 = no, 1 = yes)A = Accessed (0 = no, 1 = yes) code-segments: R = Readable (0 = no, 1 = yes)C = Conforming (0=no, 1=yes) data-segments: W = Writable (0 = no, 1 = yes)D = expands-Down (0=no, 1=yes) RSV = Reserved for future use by IntelAVL = Available for user’s purposes

Descriptor Implementations 009A FFFF FFFF 00 ‘code’ descriptor‘data’ descriptor # segment-descriptor for ‘executable’ 64KB segment.word0xFFFF, 0x0000, 0x9A01, 0x0000 # segment-descriptor for ‘writable’ 64KB segment.word0xFFFF, 0x0000, 0x9201, 0x0000

GDTR register-format Segment Base-Address Segment Limit bits 32 bits regGDT:.word0x0017, theGDT, 0x0001# register-image for GDTR lgdtregGDT# initializes register GDTR The register-image (48-bits) is prepared in a memory-location… … then the register gets loaded from memory via a special instruction

In-class exercise #1 Can you modify our ‘pagedemo.s’ program so that the first page-frame of the video display memory (physical address-range starts from 0xB8000) will appear to start from the virtual-address 0x19000 ?