x86 segmentation, page tables, and interrupts

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.
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.
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.
Page-Faults in Linux How can we study the handling of page-fault exceptions?
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Memory Management (II)
PC hardware and x86 3/3/08 Frans Kaashoek MIT
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
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.
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.
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.
Translation Lookaside Buffer
Descriptor Table & Register
Memory Management Paging (continued) Segmentation
16.317: Microprocessor System Design I
Operating Systems Engineering
CSE 120 Principles of Operating
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
Memory Management References text: Tanenbaum ch.4.
143A: Principles of Operating Systems Lecture 5: Address translation
Protection UQ: Explain the protection mechanism of X86 Intel family microprocessor(10 Marks)
System Segment Descriptor
Page Replacement Implementation Issues
CSE 153 Design of Operating Systems Winter 2018
Operating Modes UQ: State and explain the operating modes of X86 family of processors. Show the mode transition diagram highlighting important features.(10.
Memory Management References text: Tanenbaum ch.4.
Memory Management Paging (continued) Segmentation
Page Replacement Implementation Issues
Translation Lookaside Buffer
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 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 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 kaashoek@mit.edu

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 Main memory CPU instruction for (;;) { next instruction } instruction instruction data data data Memory holds instructions and data CPU interprets instructions

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

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

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 Physical address Virtual address 232-1 232-1 Program1 Data for P1 Virtual address 232-1 Program 2 MMU Data for P2 232-1 Program 3 Physical address Data for P3 Virtualize memory: virtual addresses Virtualize processor: preemptive scheduling

Page map guides translation MMU P1’s PT Page-map register 0xBF 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

Protecting page maps: kernel and user mode mov $val, %cr3 U/K Page-map register 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

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

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

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 232 Two-level structure to translate

x86 page table entry W: writable? U: user mode references allowed? 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? CPU uses vector n to index into IDT Checks that CPL ≤ DPL Saves ESP and SS in internal register Loads ESP and SS from TSS Push user SS Push user ESP Push user EFLAGS Push user CS Push user EIP Clear some EFLAGS bits Set CS and EIP from IDT descriptor

From kernel to user IRET instruction Reverse of INT

Labs Lab 1: start kernel Lab 2: kernel Lab 3: user/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|Z maps to the page directory Z|V maps to V’s page table entry

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