Exceptional Control Flow

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Carnegie Mellon 1 Exceptional Control Flow: Exceptions and Processes /18-243: Introduction to Computer Systems 13 th Lecture, June 15, 2011 Instructors:
Exceptional Control Flow Processes Today. Control Flow Processors do only one thing: From startup to shutdown, a CPU simply reads and executes (interprets)
University of Washington Today Midterm grades posted  76. HW 3 due Lab 4 fun! 1.
University of Washington Today Finish up cache-aware programming example Processes  So we can move on to virtual memory 1.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Exceptional Control Flow Part I September 22, 2008 Topics Exceptions Process context switches Creating and destroying processes class11.ppt ,
Pipeline Exceptions & ControlCSCE430/830 Pipeline: Exceptions & Control CSCE430/830 Computer Architecture Lecturer: Prof. Hong Jiang Courtesy of Yifeng.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes.
Exceptions, Interrupts & Traps
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Exceptional Control Flow Topics Exceptions except1.ppt CS 105 “Tour of the Black Holes of Computing”
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
Exceptional Control Flow I March 12, 2002
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Carnegie Mellon 1 CMSC os1: OS and Exceptions Chapter 8.1 Instructors: Haryadi Gunawi Henry Hoffmann Matthew Wachs.
Computer System Structures Interrupts
Exceptional Control Flow
CS 3214 Computer Systems Lecture 9 Godmar Back.
Interrupts and exceptions
Exceptional Control Flow & Processes
Exceptional Control Flow
Exceptions and Processes
Microprocessor Systems Design I
Exceptional Control Flow
Instructor: Randy Bryant
Overview of today’s lecture
Exceptional Control Flow Part I
Exceptional Control Flow
Cache Wrap-up, System Control Flow CSE 410 Winter 2017
os1: OS and Exceptions Chapter 8.1
Instructors: Anthony Rowe, Seth Goldstein and Gregory Kesden
Exceptional Control Flow: System Calls, Page Faults etc.
Cache Wrap-Up, System Control Flow CSE 351 Autumn 2017
Cache Example, System Control Flow CSE 351 Winter 2017
Exceptional Control Flow
Exceptional Control Flow I
Exceptional Control Flow Part I Mar. 11, 2003
Exceptional Control Flow
Exceptional Control Flow Part I
Exceptions Control Flow
Architectural Support for OS
Exceptions and Processes
Exceptional Control Flow
CS201 - Lecture 17 Exceptions
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
System Control Flow and Processes CSE 351 Winter 2018
Caches IV, System Control Flow CSE 351 Autumn 2018
Architectural Support for OS
Exceptional Control Flow & Processes October 2, 2008
Exceptional Control Flow
Interrupts and System Calls
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Exceptional Control Flow
Presentation transcript:

Exceptional Control Flow

Control Flow Processors do only one thing: Physical control flow From startup to shutdown, a CPU simply reads and executes (interprets) a sequence of instructions, one at a time This sequence is the CPU’s control flow (or flow of control) Physical control flow <startup> inst1 inst2 inst3 … instn <shutdown> Time

Altering the Control Flow Up to now: two mechanisms for changing control flow: Jumps and branches Call and return Both react to changes in program state Insufficient for a useful system: Difficult to react to changes in system state page fault occurs data arrives from a disk or a network adapter instruction divides by zero System timer expires System needs mechanisms for “exceptional control flow”

Exceptional Control Flow Exists at all levels of a computer system Low level mechanisms 1. Exceptions Change in control flow in response to a system event (i.e., change in system state) Implemented using combination of hardware and OS software Higher level mechanisms (To be covered in the system software course) 2. Process context switch Implemented by OS software and hardware timer 3. Signals Implemented by OS software 4. Nonlocal jumps: setjmp() and longjmp() Implemented by C runtime library

Exceptions An exception is a transfer of control to the OS in response to some event (i.e., change in processor state) Examples: div by 0, arithmetic overflow, page fault, I/O request completes User Process OS event exception I_current I_next exception processing by exception handler return to I_current return to I_next abort

Exception Tables Exception numbers Each type of event has a unique exception number k k = index into exception table Handler k is called each time exception k occurs code for exception handler 0 Exception Table code for exception handler 1 1 code for exception handler 2 2 ... n-1 ... code for exception handler n-1

Asynchronous Exceptions (Interrupts) Caused by events external to the processor Indicated by setting the processor’s interrupt pin Handler returns to “next” instruction Examples: Timer interrupt Every few ms, an external timer chip triggers an interrupt Used by the kernel to take back control from user programs I/O interrupt from external device Hitting Ctrl-C at the keyboard Arrival of a packet from a network Arrival of data from a disk

Synchronous Exceptions Caused by events that occur as a result of executing an instruction: Traps Intentional Examples: system calls, breakpoint traps, special instructions Returns control to “next” instruction Faults Unintentional but possibly recoverable Examples: page faults (recoverable), protection faults (unrecoverable), floating point exceptions Either re-executes faulting (“current”) instruction or aborts Aborts Unintentional and unrecoverable Examples: illegal instruction, parity error, machine check Aborts current program

System Calls Each x86-64 system call has a unique ID number Examples: Name Description read Read file 1 write Write file 2 open Open file 3 close Close file 4 stat Get info about file 57 fork Create process 59 execve Execute a program 60 _exit Terminate process 62 kill Send signal to process

System Call Example: Opening File User calls: open(filename, options) Calls __open function, which invokes system call instruction syscall 00000000000e5d70 <__open>: ... e5d79: b8 02 00 00 00 mov $0x2,%eax # open is syscall #2 e5d7e: 0f 05 syscall # Return value in %rax e5d80: 48 3d 01 f0 ff ff cmp $0xfffffffffffff001,%rax e5dfa: c3 retq User code Kernel code %rax contains syscall number Other arguments in %rdi, %rsi, %rdx, %r10, %r8, %r9 Return value in %rax Negative value is an error corresponding to negative errno Exception syscall cmp Open file Returns

Fault Example: Page Fault int a[1000]; main () { a[500] = 13; } User writes to memory location That portion (page) of user’s memory is currently on disk Page handler must load page into physical memory Returns to faulting instruction Successful on second try 80483b7: c7 05 10 9d 04 08 0d movl $0xd,0x8049d10 User Process OS exception: page fault movl Create page and load into memory returns

Fault Example: Invalid Memory Reference int a[1000]; main () { a[5000] = 13; } 80483b7: c7 05 60 e3 04 08 0d movl $0xd,0x804e360 User Process OS exception: page fault movl detect invalid address signal process Page fault handler detects invalid address Sends SIGSEGV signal to user process User process exits with “segmentation fault”

Exception Table IA32 (Excerpt) Exception Number Description Exception Class Divide error Fault 13 General protection fault 14 Page fault 18 Machine check Abort 32-255 OS-defined Interrupt or trap Check Table 6-1: http://download.intel.com/design/processor/manuals/253665.pdf