OS Structure. Hardware protection & privilege levels Control transfer to and from the operating system

Similar documents
Systems Programming and Computer Architecture ( ) Timothy Roscoe

Anne Bracy CS 3410 Computer Science Cornell University

W4118: interrupt and system call. Junfeng Yang

Interrupts & System Calls

CS 550 Operating Systems Spring Interrupt

Anne Bracy CS 3410 Computer Science Cornell University

Lecture 2: Architectural Support for OSes

CIS Operating Systems CPU Mode. Professor Qiang Zeng Spring 2018

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

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

Operating Systems. Operating System Structure. Lecture 2 Michael O Boyle

Interrupts and System Calls

Inf2C - Computer Systems Lecture 16 Exceptions and Processor Management

Architectural Support for Operating Systems. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CPS221 Lecture: Operating System Protection

for Operating Systems Computer Systems Laboratory Sungkyunkwan University

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 09, SPRING 2013

System Calls. A contract between processes and the operating system. Michael E. Locasto. Department of Computer Science UofC CPSC 457

CS 550 Operating Systems Spring System Call

Traps, Exceptions, System Calls, & Privileged Mode

CSE 120 Principles of Operating Systems

CSCE Introduction to Computer Systems Spring 2019

Syscalls, exceptions, and interrupts, oh my!

Embedded Systems Programming

CSE 153 Design of Operating Systems

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

Interrupts and System Calls

Review: Hardware user/kernel boundary

Hakim Weatherspoon CS 3410 Computer Science Cornell University

int $0x32 // call interrupt number 50

EE458 - Embedded Systems Exceptions and Interrupts

Unit 2 : Computer and Operating System Structure

CS510 Operating System Foundations. Jonathan Walpole

The Kernel Abstraction

Tutorial 10 Protection Cont.

ECE 485/585 Microprocessor System Design

An Operating System in Action

CSE 153 Design of Operating Systems Fall 18

CS 201. Exceptions and Processes. Gerson Robboy Portland State University

Microkernel Construction

CS 104 Computer Organization and Design

IA32 Intel 32-bit Architecture

Architectural Support for Operating Systems. Jinkyu Jeong ( Computer Systems Laboratory Sungkyunkwan University

CSE 120 Principles of Operating Systems

Mechanisms for entering the system

Architectural Support for OS

Processes. Johan Montelius KTH

CSE 120 Principles of Operating Systems

ECE 650 Systems Programming & Engineering. Spring 2018

CSC 2405: Computer Systems II

A process. the stack

PROTECTION CHAPTER 4 PROTECTION

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

Hardware OS & OS- Application interface

Chapter 5 - Input / Output

Intel VMX technology

CS 537 Lecture 2 Computer Architecture and Operating Systems. OS Tasks

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

Process Scheduling Queues

Microkernel Construction

Why use an Operating System? Operating System Definition

Operating System Architecture. CS3026 Operating Systems Lecture 03

Chapter 13: I/O Systems. Operating System Concepts 9 th Edition

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

by I.-C. Lin, Dept. CS, NCTU. Textbook: Operating System Concepts 8ed CHAPTER 13: I/O SYSTEMS

Introduction to Concurrency (Processes, Threads, Interrupts, etc.)

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

CS333 Intro to Operating Systems. Jonathan Walpole

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

THE CPU SPENDS ALMOST ALL of its time fetching instructions from memory

Lec 22: Interrupts. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

Protection and System Calls. Otto J. Anshus

Last time: introduction. Networks and Operating Systems ( ) Chapter 2: Processes. This time. General OS structure. The kernel is a program!

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

Architectural Support for Operating Systems

Overview of the OS. CS 450 : Operating Systems Michael Saelee

Announcement. Exercise #2 will be out today. Due date is next Monday

Last class: Today: Course administration OS definition, some history. Background on Computer Architecture

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

CS350: Final Exam Review

CPS221 Lecture: Operating System Functions

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

operating system Spring 2017 Prof.Dr. Hasan Balik Student Name : Walid.W. Ramadan mansour Student ID :

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

The Purpose of Interrupt

Operating Systemss and Multicore Programming (1DT089)

INTERRUPTS in microprocessor systems

Windows Interrupts

Operating Systems 2010/2011

These three counters can be programmed for either binary or BCD count.

POLITECNICO DI MILANO. Exception handling. Donatella Sciuto:

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9

Processes. CS439: Principles of Computer Systems January 30, 2019

CS 5460/6460 Operating Systems

Chapter 13: I/O Systems

ECEN 449 Microprocessor System Design. Hardware-Software Communication. Texas A&M University

OS structure. Process management. Major OS components. CSE 451: Operating Systems Spring Module 3 Operating System Components and Structure

Traps, Exceptions, System Calls, & Privileged Mode

Preemptive Scheduling and Mutual Exclusion with Hardware Support

Transcription:

OS Structure Topics Hardware protection & privilege levels Control transfer to and from the operating system Learning Objectives: Explain what hardware protection boundaries are. Explain how applications interact with the operating system and how control flows between them. 2/2/16 CS161 Spring 2016 1

What makes the kernel different? Protection Boundary HW/SW Interface Operating System file system device drivers processes networking virtual memory Applications Hardware 2/2/16 CS161 Spring 2016 2

Protection Boundaries Processor hardware typically provides (at least) two different privilege levels: User mode: how all regular programs run. Kernel mode or supervisor mode: how the OS runs. Most processors have only two modes; x86 has four; some older machines had 8! The mode in which a piece of software is running determines: What instructions may be executed. How addresses are translated. What memory locations may be accessed (enforced through translation). 2/2/16 CS161 Spring 2016 3

Example: Intel Four protection levels Ring 0: Most privileged: OS runs here Rings 1 & 2:Ignored in many environments, although, can run less privileged code (e.g., third party device drivers; possibly some parts of virtual machine monitors) Ring 3: Application code Memory is described in chunks called segments Each segment also has a privilege level (0 through 3) Processor maintains a current protection level (CPL) - usually the protection level of the segment containing the currently executing instruction. Program can read/write data in segments of less privilege than CPL Program cannot directly call code in segments with more privilege. 2/2/16 CS161 Spring 2016 4

Example: MIPS Standard two mode processor User mode: access to CPU/FPU registers and flat, uniform virtual memory address space. Kernel mode: can access memory mapping hardware and special registers. 2/2/16 CS161 Spring 2016 6

Changing Protection Levels Must answer two fundamental questions: How do we transfer control between applications and the kernel? When do we transfer control between applications and the kernel? How: Fundamental mechanism that transfers control from less privileged to more privileged is called a trap. There are different kinds of traps; this gets us to the when 2/2/16 CS161 Spring 2016 7

When does the OS get to run? Sleeping Beauty Approach Hope that something happens to wake you up. What might happen? System calls: An application might want the operating system to do something on its behalf. Exceptions: An application unintentionally does something that requires OS assistance (e.g., divide by 0, read a page not in memory). Interrupts: An asynchronous event (e.g., I/O completion). Alarm Clock Approach The OS can set a timer, which will generate an interrupt, which guarantees that the OS gets to run at a specific time in the future. 2/2/16 CS161 Spring 2016 8

Transferring Control Regardless of why and when control must transfer to the operating system, the mechanism is the same. First, we ll talk about what must happen in the abstract (i.e., not in the context of any particular processor). Then, we ll step through two different hardware platforms and examine how they transfer control. Key points: We can invoke the operating system explicitly via a system call. The operating system can be invoked implicitly via an exception (sometimes called a software interrupt), such as a divide by zero or a bad memory reference. The operating system can be invoked asynchronously via (hardware) interrupts, such as a timer, an I/O device, etc. 2/2/16 CS161 Spring 2016 11

Trap Handling Each type of trap is assigned a number. For example: 1 = system call 2 = timer interrupt 3 = disk interrupt 4 = interprocessor interrupt The operating system sets up a table, indexed by trap number, that contains the address of the code to be executed whenever that kind of trap happens. These pieces of code are called trap handlers. Trap handler table Trap handler for trap 1 Trap handler for trap 3 I m done! WAKEUP! (interrupt) 2/2/16 CS161 Spring 2016 12

MIPS (sys161) Trap Handling (1) MIPS has only 5 distinct traps and those addresses are hardwired (no software dispatch) One each for: 1. Reset, 2. NMI (non-maskable interrupt) 3. Fast-TLB loading 4. Debug 5. One for everything else (software must then do further dispatch). Note: Sys/161 does not support NMI or debug Trap handling varies according to the type of trap. 2/2/16 CS161 Spring 2016 13

MIPS (sys161) Trap Handling (2) The MIPS processor has special registers that get set with vital information at trap time. For example: The EPC (exception program counter) tells you the address that caused the exception. The cause register is set to a value indicating the source of the trap -- interrupt, exception, system call, and which kind of interrupt/exception/system it was. The status register indicates: Mode the processor was in when the interrupt happened. The state of which kinds of interrupts/exceptions are enabled In early versions of the MIPS, you return from trap handlers using a combination of a JMP instruction and an RFE (return from exception). Later versions have ERET (exception return). 2/2/16 CS161 Spring 2016 14

x86 Trap Handling Hardware register, traditionally called PIC (Programmable Interrupt Controller), then APIC (advanced PIC) and most recently LAPIC (local advanced PIC, one per CPU in the system) Maps different events to particular locations in IDT (interrupt descriptor table). PIC sends the appropriate value for the interrupt handler dispatch to the processor. Recall: x86 has multiple protection levels Cannot directly call code in a different level. So, we need a special mechanism to facilitate the transfer. IDT: contains special objects called gates. Gates provide access from lower privileged segments to higher privileged segments. When a low-privilege segment invokes a gate, it automatically raises the CPL to the higher level. When returning from a gate, the CPL drops to its original level. First 32 gates reserved for hardware defined traps. Remaining entries are available to software using the INT (interrupt) instruction. 2/2/16 CS161 Spring 2016 15

x86 System Calls There are multiple ways to handle system calls and different operating systems use different ways: Linux uses a single designated INT instruction (triggers a software interrupt) and then dispatches again within a single handler (like MIPS). Solaris uses the LCALL instruction (goes through a gate). Some new Linux systems use the newer SYSENTER/ SYSEXIT calls. The IRET instruction returns from the trap 2/2/16 CS161 Spring 2016 16

Recap The operating system is just a bunch of code that sits around waiting for something to do (e.g., help out a user process, respond to a hardware device, process a timer interrupt, etc). The operating system runs in privileged mode. Hardware provides some sort of mechanism to transfer control from one privilege level to another. We use the term trap to refer to any mechanism that transfers control into the operating system. There are different kinds of traps: Interrupts (caused by hardware; asynchronous) Exceptions (software interrupts; synchronous with respect to programs) System calls: intentional requests of the operating system on behalf of a program; synchronous with respect to the program) 2/2/16 CS161 Spring 2016 17

2/2/16 CS161 Spring 2016 19