Fall 2017 :: CSE 306
Virtual Memory in x86
Nima Honarmand
Virtual Memory in x86 Nima Honarmand Fall 2017 :: CSE 306 x86 - - PowerPoint PPT Presentation
Fall 2017 :: CSE 306 Virtual Memory in x86 Nima Honarmand Fall 2017 :: CSE 306 x86 Processor Modes Real mode walks and talks like a really old x86 chip State at boot 20-bit address space, direct physical memory access 1 MB
Fall 2017 :: CSE 306
Nima Honarmand
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
xv6 uses protected mode w/o PAE (i.e., 32-bit virtual and physical addresses)
etc.)
bigger address space
Fall 2017 :: CSE 306
NIC, etc.) connected to system bus
address space by the BIOS
read/write operations on its physical addresses
any way they want (driver knows) Processor Core MMU Cache System Interconnect (Bus) DRAM (Memory) Disk Network Card
…
Virtual Addr Data Physical Addr
: all addrs virtual : all addrs physical
Fall 2017 :: CSE 306
0xdeadbeef Virtual Address Linear Address Physical Address 0x0eadbeef 0x6eadbeef Segmentation Paging
Protected/Long mode only
Fall 2017 :: CSE 306
translation
would use physical addresses directly
to be mapped somewhere in the page table, and kernel code should use the corresponding virtual addresses
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
(move ecx to stack offset 0x40)
instruction type:
Fall 2017 :: CSE 306
segments
specific process
and length
Fall 2017 :: CSE 306
level (CPL) the processor is operating under at the time the selector is created
level management in x86, read about DPL, CPL and RPL in either Intel or AMD architecture manuals
Table Index (13 bits) LDT or GDT? (1 bit) RPL (2 bits)
Fall 2017 :: CSE 306
context switch, interrupt, etc.
the segments selectors to kernel segments
instruction is executed
Fall 2017 :: CSE 306
Source: AMD64 Architecture Programmer’s Manual (Volume 2)
Fall 2017 :: CSE 306
space size (4GB in 32-bit x86)
c->gdt[SEG_KCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, 0); c->gdt[SEG_KDATA] = SEG(STA_W, 0, 0xffffffff, 0); c->gdt[SEG_UCODE] = SEG(STA_X|STA_R, 0, 0xffffffff, DPL_USER); c->gdt[SEG_UDATA] = SEG(STA_W, 0, 0xffffffff, DPL_USER);
Execute & Read permission Base address 0x00000000 Segment Length (4 GB) Ring 0
Fall 2017 :: CSE 306
x86 processor dumps some data on the stack
stack?
user stack is completely under the user program’s control
before it can dump the data
Fall 2017 :: CSE 306
specified layout
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
Source: AMD64 Architecture Programmer’s Manual (Volume 2) : Linear Address
Fall 2017 :: CSE 306
PDE in Protected-mode w/o PAE PTE in Protected-mode w/o PAE
Fall 2017 :: CSE 306
page
Fall 2017 :: CSE 306
virtual addresses and need to be translated
transferring to kernel
→ To make OS designer’s life easier, most OSes map the kernel into the same (virtual address) in every process address space
Fall 2017 :: CSE 306
part of the virtual address space
mappings are the same
= Kernel’s mappings
part) differ across processes
Virtual Address Space User part of address space Kernel part of address space User code User data User data User code User stack Kernel code Kernel data & stacks 1-to-1 Mapping of Physical RAM Mapping for Device Addrs
3G 4G
Fall 2017 :: CSE 306
physical address it knows
instructions can only use virtual addresses
table which will translate to 0x00F00000
beginning address of the 1-1 mapping region
Fall 2017 :: CSE 306
address 0x80100000?
Fall 2017 :: CSE 306
Fall 2017 :: CSE 306
__thread int tid; … printf (“my thread id is %d\n”, tid);
Identical code gets different value in each thread
Fall 2017 :: CSE 306
private instance
info) in a thread environment block (TEB)
Fall 2017 :: CSE 306
address
mov eax, gs:(0x0)
Fall 2017 :: CSE 306
(<4MB). I don’t care about swapping or addressing more than 4MB.
page?
Fall 2017 :: CSE 306
exceptions