X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT

Slides:



Advertisements
Similar presentations
Memory Management Unit
Advertisements

Memory Management Paging &Segmentation CS311, CS350 & CS550.
Unit 4 Chapter-1 Multitasking. The Task State Segment.
16.317: Microprocessor System Design I
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.
Microprocessors system architectures – IA32 real and virtual-8086 mode Jakub Yaghob.
Memory Management Questions answered in this lecture: How do processes share memory? What is static relocation? What is dynamic relocation? What is segmentation?
OS Memory Addressing.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
CS591 (Spring 2001) The Linux Kernel: Signals & Interrupts.
Operating Systems: Segments 1 Segmentation Hardware Support single user program system: – wish somehow to relocate address 0 to after operating system.
1 Operating Systems and Protection CS Goals of Today’s Lecture How multiple programs can run at once  Processes  Context switching  Process.
IA-32 Processor Architecture
Page-Faults in Linux How can we study the handling of page-fault exceptions?
Memory Management (II)
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 Operating Systems and Protection Professor Jennifer Rexford CS 217.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
CS2422 Assembly Language & System Programming September 22, 2005.
Microprocessor Systems Design I Instructor: Dr. Michael Geiger Fall 2012 Lecture 15: Protected mode intro.
UNIT 2 Memory Management Unit and Segment Description and Paging
Intel IA32 OS Support -Refresh
80386DX.
6.828: PC hardware and x86 Frans Kaashoek
Cosc 3P92 Week 9 & 10 Lecture slides
The Intel Microprocessors. Real Mode Memory Addressing Real mode, also called real address mode, is an operating mode of and later x86-compatible.
Multitasking Mr. Mahendra B. Salunke Asst. Prof. Dept. of Computer Engg., STES SITS, Narhe, Pune-41 STES Sinhgad Institute of Tech. & Science Dept. of.
COS 598: Advanced Operating System. Operating System Review What are the two purposes of an OS? What are the two modes of execution? Why do we have two.
CS 6560 Operating System Design Lecture 8: Memory Management.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
80386DX.
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.
Operating Systems Engineering Based on MIT (2012, lec3) Recitation 2: OS Organization.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
Segment Descriptor Segments are areas of memory defined by a programmer and can be a code, data or stack segment. In segments need not be all the.
Lab4: Virtual Memory CS 3410 : Computer System Organization & Programming Spring 2015.
D P L s G D X U P Segment Descriptor A T Y P E
Page Replacement Implementation Issues Text: –Tanenbaum ch. 4.7.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
X86 (32-bit) Paging Reference –text: Tanenbaum ch.4.3 Reference on Win2K memory management –text: Tanenbaum ch
Information Security - 2. Task Switching Every process has an associated Task State Segment, whose starting point is stored in the Task register. A task.
Information Security - 2. Descriptor Tables Descriptors are stored in three tables: – Global descriptor table (GDT) Maintains a list of most segments.
OS Memory Addressing. Architecture CPU – Processing units – Caches – Interrupt controllers – MMU Memory Interconnect North bridge South bridge PCI, etc.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
Descriptor Table & Register
Memory Management Paging (continued) Segmentation
16.317: Microprocessor System Design I
Operating Systems Engineering
Outline Paging Swapping and demand paging Virtual memory.
Today How was the midterm review? Lab4 due today.
Microprocessor Systems Design I
Anton Burtsev February, 2017
Anton Burtsev February, 2017
Address Translation Mechanism of 80386
143A: Principles of Operating Systems Lecture 5: Address translation
x86 segmentation, page tables, and interrupts
Page Replacement Implementation Issues
CSE 153 Design of Operating Systems Winter 2018
Memory Management Paging (continued) Segmentation
Page Replacement Implementation Issues
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 153 Design of Operating Systems Winter 2019
Memory Management Paging (continued) Segmentation
Interrupts and System Calls
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

x86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT

Outline Enforcing modularity with virtualization –Virtualize processor and memory x86 mechanism for virtualization –Segmentation –User and kernel mode –Page tables –System calls

Last lecture’s computer Memory holds instructions and data CPU interprets instructions for (;;) { next instruction } instruction data CPU Main memory

Better view For modularity reasons: many programs OS switches processor(s) between programs Program 1: for (;;) { next instruction } Program1 Program 2 Program 3 Data for P2 Data for P1 Data for P3 CPU Main memory

Problem: no boundaries A program can modify other programs data A program jumps into other program’s code A program may get into an infinite loop Program1 Program 2 Program 3 Data for P2 Data for P1 Data for P3 Main memory

Goal: enforcing modularity Give each program its private memory for code, stack, and data Prevent one program from getting out of its memory Allowing sharing between programs when needed Force programs to share processor

Solution approach: virtualization Virtualize memory: virtual addresses Virtualize processor: preemptive scheduling Program1 Program 2 Program 3 Data for P2 Data for P1 Data for P3 Virtual address Physical address MMU Physical address Virtual address

Page map guides translation Each program has its own page map –Physical memory doesn’t have to be contiguous When switching program, switch page map Page maps stored in main memory MMU Page-map register 0 0xBF P1’s PT

Protecting page maps: kernel and user mode Kernel mode: can change page-map register, U/K In user mode: cannot Processor starts in kernel mode On interrupts, processor switches to kernel mode mov $val, %cr3 Page-map register U/K

What is a kernel? The code running in kernel mode –Trusted program: e.g., sets page-map, U/K register –Enforces modularity Kernel LibOS w. Unix API sh LibOS w. Unix API ls K U

Entering the kernel: system calls Special instructions –Switches U/K bit Enter kernel at kernel-specified addresses Kernel LibOS w. Unix API sh LibOS w. Unix API ls int # iret

x86 virtual addresses x86 starts in real mode (no protection) –segment registers (cs, ss, ds, es) –segment * 16 + offset  physical address OS can switch to protected mode –Segmentation and paging

Translation with segments LDGT loads CPU’s GDT PE bit in CR0 register enables protected mode Segments registers contain index

Segment descriptor Linear address = logical address + base –assert: logical address < limit Segment restricts what memory an application can reference

JOS code Why does EIP contain the address of “ljmp” instruction after “movl %eax, %cr0”?

Enforcing modularity in x86 CPL: current privilege level –0: privileged (kernel mode) –3: user mode User programs can set segment selector Kernel can load value in CPL and GDT, but user programs cannot

x86 two-level page table Page size is 4,096 bytes –1,048,576 pages in 2 32 –Two-level structure to translate

x86 page table entry W: writable? –Page fault when W = 0 and writing U: user mode references allowed? –Page fault when U = 0 and user references address P: present? –Page fault when P = 0

what does the x86 do exactly?

When does page table take effect? PG enables page-based translation CR3 contains address of page table –Where does the next instruction come from? When changing PDE or PTE, you must flush TLB –Reload CR3

User mode to kernel mode Instruction: INT n, or interrupt n indexes into interrupt descriptor table (IDT) IDTR contains physical address of IDT

IDT descriptor Three ways to get into kernel: –User asks (trap) –Page fault (trap) –Interrupts

What happens on trap/interrupt? 1.CPU uses vector n to index into IDT 2.Checks that CPL ≤ DPL 3.Saves ESP and SS in internal register 4.Loads ESP and SS from TSS 5.Push user SS 6.Push user ESP 7.Push user EFLAGS 8.Push user CS 9.Push user EIP 10.Clear some EFLAGS bits 11.Set CS and EIP from IDT descriptor

From kernel to user IRET instruction –Reverse of INT

Labs Lab 1: start kernel –setup and use segmentation Lab 2: kernel –Set up kernel address space Lab 3: user/kernel –Set up user address space –Set up IDT –System calls and page faults Lab 4: many user programs –Preemptive scheduling

JOS

Recall x86 page table To find P for V OS can walk PT manually

VPT: Mapping the page table Z|Z maps to the page directory Z|V maps to V’s page table entry Z

Summary Kernel enforcing modularity –By switching processor between programs –By giving each program its own virtual memory x86 support for enforcing modularity –Segments –User and kernel mode –Page tables –Interrupts and traps JOS