Chapter 12 Interrupts STOP!!! Do this!!!. Interrupts Have device tell OS it is ready OS can then interrupt what it is doing to: Determine what device.

Slides:



Advertisements
Similar presentations
Chapter 3 Basic Input/Output
Advertisements

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.
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
CSCI 4717/5717 Computer Architecture
68HC11 Polling and Interrupts
ECE 372 – Microcontroller Design Parallel IO Ports - Interrupts
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
OS2-1 Chapter 2 Computer System Structures. OS2-2 Outlines Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
1 Exceptions, Interrupts, and the OS STOP!! Do this!!!
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Interrupts STOP!!! Do this!!!. CMPE12cGabriel Hugh Elkaim 2 Interrupts Have device tell OS/CPU it is ready Requires hardware to support. OS/CPU can then.
OS Spring’03 Introduction Operating Systems Spring 2003.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
Chapter 8 Overview Programmed I/O Introduction to Interrupt Driven I/O Project 3.
OS Spring’04 Introduction Operating Systems Spring 2004.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
MIPS I/O and Interrupt. SPIM I/O and MIPS Interrupts The materials of this lecture can be found in A7-A8 (3 rd Edition) and B7-B8 (4 th Edition).
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Interrupts. 2 Definition: An electrical signal sent to the CPU (at any time) to alert it to the occurrence of some event that needs its attention Purpose:
Introduction to Embedded Systems
COMP201 Computer Systems Exceptions and Interrupts.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
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.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
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.
1 Interrupts, Resets Today: First Hour: Interrupts –Section 5.2 of Huang’s Textbook –In-class Activity #1 Second Hour: More Interrupts Section 5.2 of Huang’s.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
MIPS I/O and Interrupt.
Microprogramming and Exceptions Spring 2005 Ilam University.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Interrupts STOP!!! Do this!!!. Interrupts Have device tell OS it is ready OS can then interrupt what it is doing to: Determine what device wants service.
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.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Interrupts and exceptions
Interrupts and signals
68HC11 Interrupts & Resets.
MIPS I/O and Interrupt.
Timer and Interrupts.
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
Architectural Support for OS
Interrupts and Exception Handling
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.
MIPS I/O and Interrupt.
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
ECE/CS 552: Pipelining and Exceptions
COMP3221: Microprocessors and Embedded Systems
Interrupts and Exception Handling
Presentation transcript:

Chapter 12 Interrupts STOP!!! Do this!!!

Interrupts Have device tell OS it is ready OS can then interrupt what it is doing to: Determine what device wants service Determine what service it wants Perform or start the service Go back to what OS was doing

Interrupts Example Interrupts I/O Device Change in status Error condition Processor problem Thermal over-ride shutdown Internal error detected Clock

Interrupts Interrupt Properties They arrive asynchronously Can’t communicate with running program (no args or return values) They are associated with various priorities Want to handle soon (interrupt latency) (usually) want to resume program

Traps Traps: Internal conditions related to instruction stream syscall why doesn’t HC11 have a syscall? Illegal instruction Arithmetic overflow “lw” from unaligned address

Traps Trap Properties they arrive synchronously get trap in same place if you re-run program they are associated with various priorities must handle immediately (usually) want to resume program

Exceptions Exception: mechanism used to handle both interrupts and traps HW handles initial reaction then invokes SW called an Exception Handler HW (MIPS) 1. Sets state giving cause of exception 2. Changes to Kernel mode, saving the previous mode in a hardware stack – for dangerous work ahead. 3. Disables further interrupts – to prevent infinite loop 4. Saves current PC – to be able to resume previously running program 5. Jumps to hardware address 0x

Exceptions HW (HC11) 1.Wait for current instruction to complete 2.Disable further interrupts 3.Save all CPU registers and return address on stack 4.Access “interrupt vector table” according to source 5.Jump to where the interrupt routine is specified in table 6.Use RTI to return

Exceptions Exception Handler (.ktext beginning at 0x ) Set flag to detect incorrect entry Saves some registers Ascertain exception type MIPS: exception_code in Cause register Jump to specific exception handler Handle specific exception To resume program, jump to clean up routine Restore registers Reset flag (that detects incorrect entry) Restore previous mode Re-enable interrupts Jump back to program (using Exception Program Counter (EPC))

Exceptions syscall handler Change EPC to point to next instruction resume after syscall Look at syscall number (MIPS: $2) Jump to specific syscall handler putc handler (one of many syscall handlers) Add char (from $4) to putqueue Turn on display interrupts Try to print a char Jump back to main exception handler getc handler Turn on keyboard interrupts Try to get char when interrupt comes Jump back to main exception handler with data in $2

Exceptions External (I/O) interrupt handler Which interrupt MIPS: interrupt field in Cause register Call specific interrupt handler Jump back to main exception handler

MIPS Exception Registers Kernel Registers k0 and k1 GPR $26 ($k0) and $27 ($k1) (used to store EPC) Kernel can hop in between any two user instructions Coprocessor “C0” registers Status ($12), Cause ($13), EPC ($14) mfco $s0, $14 reads C0 register $14 (EPC) and puts it in $s0 mtc0 $s0, $14 writes $s0 to C0 register $12 (Status)

MIPS Exception Registers Cause Register – way hardware makes information available to software about pending interrupts. 6 hardware interrupt bits 2 software interrupt bits 4 bits of exception code Status Register – contains information about the status of features of the computer that can be set by the processor when in kernel mode. Interrupt masks 3 mode/interrupt enable pairs mode is user/kernel on interrupts, stack mode/interrupt pairs

HC11 Exceptions ; 1unavailable to userSCI ISR_JUMP2EQU$7BC5; SPI ISR_JUMP3EQU$7BC8; Pulse Accumulator Input ISR_JUMP4EQU$7BCB; Pulse Accumulator Overflow ; 5unavailable to userTimer Overflow ; 6unavailable to userOutput Compare 5 ISR_JUMP7EQU$7BD4; Output Compare 4 ISR_JUMP8EQU$7BD7; Output Compare 3 ISR_JUMP9EQU$7BDA; Output Compare 2 ISR_JUMP10EQU$7BDE; Output Compare 1 ISR_JUMP11EQU$7BE3; Input Capture 3 ISR_JUMP12EQU$7BE6; Input Capture 2 ISR_JUMP13EQU$7BE9; Input Capture 1 ; 14unavailable to userReal Time Interrupt ISR_JUMP15EQU$7BEC; IRQ ; 16unavailable to userXIRQ ; 17unavailable to userSWI ; 18unavailable to userIllegal Opcode ISR_JUMP19EQU$7BF8; Cop fail ISR_JUMP20EQU$7BFB; Cop clock fail ; 21unavailable to userReset (found at 0x8040)

HC11 Exceptions ********************************************************** * Some of the internal 64 registers are defined here. Their definitions * should be self-evident from the Motorola manuals. BAUDEQUREGBASE+$2B; sci baud register SCCR1EQUREGBASE+$2C; sci control1 register SCCR2EQUREGBASE+$2D; sci control2 register SCSREQUREGBASE+$2E; sci status register SCDREQUREGBASE+$2F; sci data register ********************************************************** * Useful system variables * These may change if the monitor software changed. * O.K. ver2.17 * Addresses can be found in the linker map file. _GETCHREQU$8A0A; char getchr (void) IRQCOUNTEQU$0CD5; 16-bit integer that increments ; each time IRQ is called _PUTCHREQU$89E5; char putchar (char c) TICSECEQU$02E3; 16-bit integer that increments ; once each second

HC11 Exceptions _WAITEQU$8A37; software timer ms per ; tick, argument in x-reg USERTICKEQU$02D7; unsigned int incremented every ; 4.096ms by system clock

Multiple Interrupts How about multiple simultaneous exceptions? Have priorities in HW / SW Handle highest-priority interrupt first Equal priority interrupts handled arbitrarily Give higher priority more serious (e.g., power failing) can’t wait long (e.g., rotating disk)

Multiple Interrupts How about interrupts during exception handling? Make it wait until done with first interrupt May be a bad idea for higher priority interrupts Make exception handler re-entrant Make able to handle multiple active calls Allow higher-priority exceptions to bypass lower- priority exception currently being serviced

Multiple Interrupts Initial exceptions disables all interrupts Exception handler (EH) determines exception’s priority EH saves state that could be clobbered by higher priority interrupts (e.g. EPC) EH re-enables higher-priority interrupts Higher-priority interrupts may or may nor occur This EH eventually finishes

Multiprogramming An active program is called a process or task A processes’ state is program counter registers memory locations being used Some OS memory EPC other registers

Multiprogramming OS has one exception handler called the “kernel” On exception, CPU jumps into the kernel Kernel will eventually resume the user process If the user process needs I/O (disk read) Kernel schedules it 20ms is ~ 2 million instructions Start another task (multitasking) If user process does not need I/O Kick it out (context switch) after some amount of time Every X clock interrupts and switch again

Multiprogramming OS has several job queues An entry is the complete state of a process A queue of ready jobs with priority Queues for I/O device(s) Jobs are moved to ready queue when I/O complete Queue of sleeping or halted jobs Possibly other queues OS picks jobs from the ready queue as appropriate

Generalized Interrupts 1.User program running 2.Exception is generated Internal/External Trap/Interrupt 3.Determine source of exception Requires a bus cycle for some peripheral bus architectures. 4.Save return PC and any status registers modified by hardware MIPS: EPC, Control, Status HC11: program counter, index registers, acc.

Generalized Interrupts 5.Jump to exception handler MIPS: Single EH uses interrupt and exceptions type bits to find correct procedure HC11: Jump table starting at 0xFFD : Jump to location specified by interrupt device – vectored interrupts 6.Save state used by exception handler 7.Go to specific case Check exception type Query device Check syscall register

Generalized Interrupts 8.Process Exception Enable higher-priority interrupts if possible For interrupt, clear device’s interrupt flag Check device for multiple conditions 9.Restore state used by exception handler 10.Return from exception Restore mode Restore hardware-saved state Jump back to user program or exception handler