Exceptions 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.
CSCI 4717/5717 Computer Architecture
Chapter 6 Limited Direct Execution
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
OS Spring’03 Introduction Operating Systems Spring 2003.
Introduction to Interrupts
OS Spring’04 Introduction Operating Systems Spring 2004.
Exceptions, Interrupts & Traps
COMPUTER SYSTEMS An Integrated Approach to Architecture and Operating Systems Chapter 4 Processor Implementation ©Copyright 2008 Umakishore Ramachandran.
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
3/11/2002CSE Input/Output Input/Output Control Datapath Memory Processor Input Output Memory Input Output Network Control Datapath Processor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Input/ Output By Mohit Sehgal. What is Input/Output of a Computer? Connection with Machine Every machine has I/O (Like a function) In computing, input/output,
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.
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,
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 Exceptional Control Flow The Hardware/Software Interface CSE351 Winter 2013.
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.
Of Privilege, Traps, Interrupts & Exceptions Prof. Sirer CS 316 Cornell University.
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.
Introduction to Operating Systems
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Interrupts and exceptions
Processor States normal exception
MICROPROCESSOR BASED SYSTEM DESIGN
Exceptional Control Flow & Processes
Exceptional Control Flow
Microprocessor Systems Design I
Exceptional Control Flow
Anton Burtsev February, 2017
Exceptional Control Flow
Day 08 Processes.
Day 09 Processes.
Overview of today’s lecture
Exceptional Control Flow
os1: OS and Exceptions Chapter 8.1
Exceptional Control Flow: System Calls, Page Faults etc.
CSE 120 Principles of Operating
Introduction to Operating Systems
Exceptional Control Flow I
Exceptional Control Flow Part I
Architectural Support for OS
Architectural Support for OS
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Exceptions and Processes
Exceptional Control Flow
CS201 - Lecture 17 Exceptions
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.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
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:

Exceptions Control Flow Reading Reference: Textbook 1 Chapter 2 Exceptions Control Flow TANZIR AHMED CSCE 313, Fall 2018

Today’s Discussion: Control Flow Computers 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 system’s physical control flow (or flow of control) Physical control flow <startup> inst1 inst2 inst3 … instn <shutdown> Time

Altering the Control Flow Program-assisted mechanisms for changing control flow: Jumps and branches—react to changes in program state Function call and return using stack discipline—react to program state Insufficient for a useful system The user application is the central thing – how to let OS into the CPU unless the app gives up control? Thus, difficult for the CPU to react to other changes in system state Data arrives from a network adapter Instruction divides by zero User hits control-C at the keyboard System needs mechanisms for “exception control flow”

Exception Control Flow An exception is a transfer of control to the OS in response to some event (i.e., change in processor state) User Process OS event current exception next exception processing by exception handler exception return (optional)

Asynchronous Exceptions (Interrupts) Caused by events external to processor (i.e., outside the current program) Indicated by setting the processor’s interrupt pin(s) Handler returns to “next” instruction after servicing An important concept – Direct Memory Access (DMA) CPU is not busy while data transfer (from disk, network, etc.) happens Examples: I/O interrupts Key pressed on the keyboard Arrival of packet from network, or disk Hard-reset interrupt Hitting reset button Soft-reset interrupt Hitting control-alt-delete to initiate restart on a PC

Interrupt Vectors Each type of event has a unique exception number k numbers Each type of event has a unique exception number k Index into jump table (a.k.a., interrupt vector) Jump table entry k points to a function (exception handler). Handler k is called each time exception k occurs. code for exception handler 0 interrupt vector code for exception handler 1 1 code for exception handler 2 2 ... ... n-1 code for exception handler n-1

Synchronous Exceptions: Traps, Faults, Aborts Caused by events that occur as result of executing an instruction (i.e., from the currently running process): Traps Intentional Examples: system calls (e.g., printf, cout), breakpoint traps, special instructions Returns control to “next” instruction Faults Unintentional but possibly recoverable Examples: Page Faults Either re-executes faulting (“current”) instruction or aborts

Synchronous Exceptions: Traps, Faults, Aborts Unintentional and unrecoverable Examples: parity error, machine check Aborts current program or entire OS

Trap Example Opening a File User calls open(filename, options) Function open executes system-call instruction: int $0x80 OS must find or create file, get it ready for reading or writing Returns integer file descriptor User Process OS exception return int pop Open file

Fault Example #1 Memory Reference User writes to memory location int a[1000]; main () { a[500] = 13; } Memory Reference User writes to memory location That portion (page) of user’s memory is not mapped yet (because memory pages are mapped only when necessary) Page handler must load page into physical memory Returns to faulting instruction Successful on second try User Process OS page fault Allocate page and its mapping in page table return event

Fault Example #2 Illegal Memory Reference User writes to memory location Address is not valid Page handler detects invalid address Sends SIGSEGV signal to user process User process exits with “segmentation fault” int a[1000]; main () { a[5000] = 13; } User Process OS page fault Detect invalid address event Signal process

Summarizing Control Flow Exceptions Events that require nonstandard control flow Are Synchronous (Traps, Faults, Aborts) OR Asynchronous (I/O Interrupts, Hard or Soft Reset etc.) Generated Externally (interrupts) or Internally (traps and faults) OS decides how to handle

Example: Web Server syscall syscall syscall RTU RTU wait wait interrupt interrupt

In Closing Today we learnt the importance and various forms of how applications eventually get the attention of underlying System Hardware and Software (privileged code to keep sanity, illusions, and glues) We saw an interesting analogy with a coffee shop and also looked at some real CS System examples illustrating exception control flow. Next, we will dive a little deeper into Dual Mode Operation. Read Chapter 2 in entirety to prepare for an interesting discussion.