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

Similar documents
Operating Systems Engineering Recitation #3 (part 2): Interrupt and Exception Handling on the x86. (heavily) based on MIT 6.

IA32 Intel 32-bit Architecture

Microkernel Construction

PROTECTION CHAPTER 4 PROTECTION

Microkernel Construction

Tutorial 10 Protection Cont.

W4118: interrupt and system call. Junfeng Yang

Part I. X86 architecture overview. Secure Operating System Design and Implementation x86 architecture. x86 processor modes. X86 architecture overview

W4118: virtual machines

143A: Principles of Operating Systems. Lecture 6: Address translation. Anton Burtsev January, 2017

2.5 Address Space. The IBM 6x86 CPU can directly address 64 KBytes of I/O space and 4 GBytes of physical memory (Figure 2-24).

143A: Principles of Operating Systems. Lecture 5: Address translation. Anton Burtsev October, 2018

ICS143A: Principles of Operating Systems. Midterm recap, sample questions. Anton Burtsev February, 2017

238P: Operating Systems. Lecture 5: Address translation. Anton Burtsev January, 2018

Homework / Exam. Return and Review Exam #1 Reading. Machine Projects. Labs. S&S Extracts , PIC Data Sheet. Start on mp3 (Due Class 19)

IA32/Linux Virtual Memory Architecture

Information Security II Prof. Kamakoti Department of Computer Science and Engineering Indian Institute of Technology, Madras

iapx86 Protection Electronic Computers M

Summer 2003 Lecture 27 07/28/03

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

What You Need to Know for Project Three. Dave Eckhardt Steve Muckle

Embedded Systems Programming

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Computer Architecture Lecture 13: Virtual Memory II

MICROPROCESSOR MICROPROCESSOR ARCHITECTURE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

6.828: Using Virtual Memory. Adam Belay

Mechanisms for entering the system

Operating Systems and Protection CS 217

Low Level Programming Lecture 2. International Faculty of Engineerig, Technical University of Łódź

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

3. Process Management in xv6

Intel VMX technology

1. state the priority of interrupts of Draw and explain MSW format of List salient features of

x86 Initial Boot Sequence Advanced Operating Systems and Virtualization Alessandro Pellegrini A.Y. 2017/2018

Virtualization. Adam Belay

Darshan Institute of Engineering & Technology

iapx Systems Electronic Computers M

CSE 451 Autumn Final Solutions mean 77.53, median 79, stdev 12.03

AMD-K5. Software Development Guide PROCESSOR

CS3210: Booting and x86

W4118: PC Hardware and x86. Junfeng Yang

MICROPROCESSOR TECHNOLOGY

CIS Operating Systems CPU Mode. Professor Qiang Zeng Spring 2018

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

Memory Addressing. Pradipta De

MICROPROCESSOR ALL IN ONE. Prof. P. C. Patil UOP S.E.COMP (SEM-II)

Virtual Memory. CS 351: Systems Programming Michael Saelee

CS3210: Isolation Mechanisms

CS3210: Booting and x86. Taesoo Kim

Protection and System Calls. Otto J. Anshus

Operating system organizaton

Administrivia. Lab 1 due Friday 12pm. We give will give short extensions to groups that run into trouble. But us:

Introduction to IA-32. Jo, Heeseung

INTRODUCTION TO IA-32. Jo, Heeseung

3.6. PAGING (VIRTUAL MEMORY) OVERVIEW

CanSecWest Nicolás A. Economou Andrés Lopez Luksenberg

Basic Execution Environment

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

143A: Principles of Operating Systems. Lecture 7: System boot. Anton Burtsev October, 2017

238P: Operating Systems. Lecture 7: System boot. Anton Burtsev January, 2017

Interrupts and System Calls

Interrupts and System Calls. Don Porter CSE 506

Background. IBM sold expensive mainframes to large organizations. Monitor sits between one or more OSes and HW

Virtual memory Paging

Operating systems offer processes running in User Mode a set of interfaces to interact with hardware devices such as

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

xv6 Boot Recap: Transitioning from 16 bit mode to 32 bit mode

Author: Steve Gorman Title: Programming with the Intel architecture in the flat memory model

Review: Hardware user/kernel boundary

Virtual memory - Paging

The process. one problem

x86 Memory Protection and Translation

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

CS 550 Operating Systems Spring Interrupt

143A: Principles of Operating Systems. Lecture 09: First process. Anton Burtsev January, 2017

CS 5460/6460 Operating Systems

Scott M. Lewandowski CS295-2: Advanced Topics in Debugging September 21, 1998

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Complex Instruction Set Computer (CISC)

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

virtual memory Page 1 CSE 361S Disk Disk

OPERATING SYSTEM OVERVIEW

x86 architecture et similia

µ-kernel Construction (12)

Microkernels. Overview. Required reading: Improving IPC by kernel design

CS 153 Design of Operating Systems Winter 2016

Introduction to The x86 Microprocessor

Computer Architecture Background

MOV Move INSTRUCTION SET REFERENCE, A-M. Description. Opcode Instruction 64-Bit Mode. Compat/ Leg Mode

Unit 08 Advanced Microprocessor

Software Virtualization Based Rootkits

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

+ Overview. Projects: Developing an OS Kernel for x86. ! Handling Intel Processor Exceptions: the Interrupt Descriptor Table (IDT)

Lecture 3: O/S Organization. plan: O/S organization processes isolation

CIS Operating Systems Memory Management Address Translation. Professor Qiang Zeng Fall 2017

Dr. Ramesh K. Karne Department of Computer and Information Sciences, Towson University, Towson, MD /12/2014 Slide 1

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 23

Processes. Johan Montelius KTH

Microprocessors and Microcontrollers/High end processors

Transcription:

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

Better view CPU Program 1: for (;;) { next instruction } Main memory Program1 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 Program1 2 32-1 Program 2 Program 3 Data for P1 Data for P2 Data for P3 0 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 Virtual address Physical address 2 32-1 Program1 2 32-1 Virtual address MMU 0 2 32-1 0 Data for P1 Program 2 Data for P2 Physical address 2 32-1 0 Program 3 Data for P3 0 Virtualize memory: virtual addresses Virtualize processor: preemptive scheduling

Page map guides translation Page-map register MMU P1 s PT 0 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 U/K mov $val, %cr3 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? U sh LibOS w. Unix API ls LibOS w. Unix API K Kernel The code running in kernel mode Trusted program: e.g., sets page-map, U/K register Enforces modularity

Entering the kernel: system calls int # sh LibOS w. Unix API ls 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 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 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