University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.

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.
University of Washington Today Move on to … 1. University of Washington Hmm… Lets look at this again Disk Main Memory L2 unified cache L1 I-cache L1 D-cache.
CS 153 Design of Operating Systems Spring 2015 Lecture 3: Intro and Architectural Support for Operating Systems.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Exceptional Control Flow Part I September 22, 2008 Topics Exceptions Process context switches Creating and destroying processes class11.ppt ,
OS Spring’03 Introduction Operating Systems Spring 2003.
Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes.
Introduction to Interrupts
Exceptions, Interrupts & Traps
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
Fabián E. Bustamante, Spring 2007 Exceptional Control Flow Part I Today Exceptions Process context switches Creating and destroying processes Next time.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
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);
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Carnegie Mellon 1 Exceptional Control Flow: Exceptions and Processes : Introduction to Computer Systems 13 th Lecture, Oct. 7, 2014 Instructors:
University of Washington Today Finished up virtual memory On to memory allocation Lab 3 grades up HW 4 up later today. Lab 5 out (this afternoon): time.
CSC 2405 Computer Systems II Exceptions Mini-Lecture Traps & Interrupts.
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.
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);
Exceptional Control Flow I March 12, 2002
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);
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.
Spring 2016Assembly Review 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);
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.
Exceptional Control Flow & Processes
Exceptional Control Flow
Exceptions and Processes
Microprocessor Systems Design I
Final exam: Wednesday, March 20, 2:30pm
Exceptional Control Flow
Exceptional Control Flow
Roadmap C: Java: Assembly language: OS: Machine code: Computer system:
Day 08 Processes.
Day 09 Processes.
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 I
Exceptional Control Flow Part I
Exceptions Control Flow
Exceptions and Processes
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
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Exceptional Control Flow & Processes October 2, 2008
Interrupts and System Calls
Presentation transcript:

University of Washington Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013

University of Washington Roadmap 2 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); c.setGals(17); float mpg = c.getMPG(); get_mpg: pushq %rbp movq %rsp, %rbp... popq %rbp ret Java: C: Assembly language: Machine code: Computer system: OS: Data & addressing Integers & floats Machine code & C x86 assembly programming Procedures & stacks Arrays & structs Memory & caches Exceptions & processes Virtual memory Memory allocation Java vs. C Winter 2013 Exceptional Control Flow

University of Washington Control Flow So far, we’ve seen how the flow of control changes as a single program executes A CPU executes more than one program at a time though – we also need to understand how control flows across the many components of the system Exceptional control flow is the basic mechanism used for:  Transferring control between processes and OS  Handling I/O and virtual memory within the OS  Implementing multi-process applications like shells and web servers  Implementing concurrency Winter Exceptional Control Flow

University of Washington Control Flow Processors do only one thing:  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) Winter Exceptional Control Flow inst 1 inst 2 inst 3 … inst n Physical control flow time

University of Washington Altering the Control Flow Up to now: two ways to change control flow:  Jumps (conditional and unconditional)  Call and return Both react to changes in program state Processor also needs to react to changes in system state  user hits “Ctrl-C” at the keyboard  user clicks on a different application’s window on the screen  data arrives from a disk or a network adapter  instruction divides by zero  system timer expires Can jumps and procedure calls achieve this?  Jumps and calls are not sufficient – the system needs mechanisms for “exceptional” control flow! Winter Exceptional Control Flow

University of Washington Exceptional Control Flow Exists at all levels of a computer system Low level mechanisms  Exceptions  change processor’s in control flow in response to a system event (i.e., change in system state, user-generated interrupt)  Combination of hardware and OS software Higher level mechanisms  Process context switch  Signals – you’ll hear about these in CSE451 and CSE466  Implemented by either:  OS software  C language runtime library Winter Exceptional Control Flow

University of Washington An exception is transfer of control to the operating system (OS) in response to some event (i.e., change in processor state) Examples: div by 0, page fault, I/O request completes, Ctrl-C How does the system know where to jump to in the OS? User ProcessOS exception exception processing by exception handler return to I_current return to I_next abort event I_current I_next 7 Winter 2013 Exceptional Control Flow Exceptions

University of Washington n-1 Interrupt Vectors Winter Exceptional Control Flow Each type of event has a unique exception number k k = index into exception table (a.k.a. interrupt vector) Handler k is called each time exception k occurs Exception Table code for exception handler 0 code for exception handler 1 code for exception handler 2 code for exception handler n-1... Exception numbers

University of Washington Asynchronous Exceptions (Interrupts) Caused by events external to the processor  Indicated by setting the processor’s interrupt pin(s)  Handler returns to “next” instruction Examples:  I/O interrupts  hitting Ctrl-C on the keyboard  clicking a mouse button or tapping a touchscreen  arrival of a packet from a network  arrival of data from a disk  Hard reset interrupt  hitting the reset button on front panel  Soft reset interrupt  hitting Ctrl-Alt-Delete on a PC Winter Exceptional Control Flow

University of Washington Synchronous Exceptions Caused by events that occur as a result of executing an instruction:  Traps  Intentional: transfer control to OS to perform some function  Examples: system calls, breakpoint traps, special instructions  Returns control to “next” instruction  Faults  Unintentional but possibly recoverable  Examples: page faults (recoverable), segment protection faults (unrecoverable), integer divide-by-zero exceptions (unrecoverable)  Either re-executes faulting (“current”) instruction or aborts  Aborts  Unintentional and unrecoverable  Examples: parity error, machine check  Aborts current program Winter Exceptional Control Flow

University of Washington Trap Example: Opening File User calls: open(filename, options) Function open executes system call instruction int OS must find or create file, get it ready for reading or writing Returns integer file descriptor 0804d070 : d082:cd 80 int $0x80 804d084:5b pop %ebx... User ProcessOS exception open file returns int pop 11 Winter 2013 Exceptional Control Flow

University of Washington 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: mov is executed again! Successful on second try int a[1000]; main () { a[500] = 13; } 80483b7:c d d movl $0xd,0x8049d10 User ProcessOS exception: page fault Create page and load into memory returns movl 12 Winter 2013 Exceptional Control Flow Fault Example: Page Fault

University of Washington Page handler detects invalid address Sends SIGSEGV signal to user process User process exits with “segmentation fault” int a[1000]; main () { a[5000] = 13; } 80483b7:c e d movl $0xd,0x804e360 User ProcessOS exception: page fault detect invalid address movl signal process 13 Winter 2013 Exceptional Control Flow Fault Example: Invalid Memory Reference

University of Washington Exception Table IA32 (Excerpt) Winter Exceptional Control Flow Exception NumberDescriptionException Class 0Divide errorFault 13General protection faultFault 14Page faultFault 18Machine checkAbort OS-definedInterrupt or trap 128 (0x80)System callTrap OS-definedInterrupt or trap

University of Washington Summary Exceptions  Events that require non-standard control flow  Generated externally (interrupts) or internally (traps and faults)  After an exception is handled, one of three things may happen:  Re-execute the current instruction  Resume execution with the next instruction  Abort the process that caused the exception Winter Exceptional Control Flow

University of Washington Winter Exceptional Control Flow