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.

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.
Input and Output CS 215 Lecture #20.
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
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
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.
Basic Input/Output Operations
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.
A. Frank - P. Weisberg Operating Systems Functional View of Operating System.
The Processor Data Path & Control Chapter 5 Part 4 – Exception Handling N. Guydosh 3/1/04+
Midterm Wednesday 11/19 Overview: 25% First Midterm material - Number/character representation and conversion, number arithmetic - DeMorgan’s Law, Combinational.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
1 CSC 2405: Computer Systems II Spring 2012 Dr. Tom Way.
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).
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:
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.
Input and Output Computer Organization and Assembly Language: Module 9.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
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.
Chapter 2: Computer-System Structures 2.1 Computer System Operation 2.5 Hardware Protection 2.6 Network Structure.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
Lecture 14 Today’s topics MARIE Architecture Registers Buses
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
MIPS I/O and Interrupt.
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.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Chapter 3 : Top Level View of Computer Functions Basic CPU function, Interconnection, Instruction Format and Interrupt.
CS4315A. Berrached:CMS:UHD1 Operating Systems and Computer Organization Chapter 4.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Structure and Role of a Processor
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.
Interrupts and signals
MIPS I/O and Interrupt.
MIPS I/O and Interrupt.
Computer-System Architecture
Module 2: Computer-System Structures
BIC 10503: COMPUTER ARCHITECTURE
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.
Module 2: Computer-System Structures
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 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Interrupts and Exception Handling
Presentation transcript:

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 to additional set of registers and to user- mode restricted memory space available when the processor operates in kernel mode. Access to additional set of registers and to user- mode restricted memory space available when the processor operates in kernel mode. The MIPS RISC architecture includes the notion of co-processors. If the floating point co-processor is not present it can be emulated by a software. The MIPS RISC architecture includes the notion of co-processors. If the floating point co-processor is not present it can be emulated by a software.

Co-processors The co-processor C1 execute floating point instructions and contain floating point registers. The co-processor C1 execute floating point instructions and contain floating point registers. If the coprocessor C1 does not exist and an instruction specifies a floating point register, a trap occurs. The exception handler can identify the operation specified and may invoke software routines to achieve the effect of the specified operation. If the coprocessor C1 does not exist and an instruction specifies a floating point register, a trap occurs. The exception handler can identify the operation specified and may invoke software routines to achieve the effect of the specified operation. The co-processor C0 is always present and contains registers useful for handling exceptions but is not accessible in user mode. C0 includes the status register, cause register, BadVaddr, and EPC (exception program counter). The co-processor C0 is always present and contains registers useful for handling exceptions but is not accessible in user mode. C0 includes the status register, cause register, BadVaddr, and EPC (exception program counter).

Co-processor 0 BadVaddr 8memory address at which address exception occurred Status12interrupt mask and enable bits Cause13exception type and pending interrupts EPC14address of instruction that caused exception namenumber information

Cause Register The cause register contains information about pending interrupts and the kinds of exception that occurs. The cause register contains information about pending interrupts and the kinds of exception that occurs. The contents of the cause register can be copied into an ordinary register and have the individual bits tested to determine what caused an exception to occur. The contents of the cause register can be copied into an ordinary register and have the individual bits tested to determine what caused an exception to occur. mfc0 $26, $13 mfc0 $26, $13 The above instruction moves data from coprocessor 0 register $13 (cause register) to general purpose register $26 The above instruction moves data from coprocessor 0 register $13 (cause register) to general purpose register $26

Cause Register exception code pending interrupts exception codemeaning 0interrupt 4load from illegal address 5store to illegal address 6bus error on instruction fetch 7bus error on data reference 12arithmetic overflow 15floating point exception

Status Register The status register contains information about the status of features of the computer that can be set by the processor while in kernel mode The status register contains information about the status of features of the computer that can be set by the processor while in kernel mode indicates whether current status is kernel or user indicates whether the processor was in kernel or user mode when the last exception occurred

Status Register Mode Enable Mode Enable Mode Enable Mode: 1=user, 0=kernel Enable: 1=on, 0=off Old Prev Cur

EPC (exception program counter) Contains the address of the instruction that was executing when the exception was generated. Contains the address of the instruction that was executing when the exception was generated. Control can be made to return to this location to continue the program. Control can be made to return to this location to continue the program. The contents of EPC can be transferred to a general register via the following instruction The contents of EPC can be transferred to a general register via the following instruction mfc0 R t, $14

Exception Handler The MIPS R32 architecture fixes the starting address of the exception handler to 0x The MIPS R32 architecture fixes the starting address of the exception handler to 0x A jump table consists of a list of procedure addresses to be called to deal with the various exception conditions. A jump table consists of a list of procedure addresses to be called to deal with the various exception conditions. In an interrupt, the PC had already been incremented and EPC would contain the correct return address. In an interrupt, the PC had already been incremented and EPC would contain the correct return address. In a syscall, the EPC contains the address of the syscall itself, thus the exception handler must first increment the return address by one before the return. In a syscall, the EPC contains the address of the syscall itself, thus the exception handler must first increment the return address by one before the return.

Handling an exception An exception has occurred. What happens? An exception has occurred. What happens? The hardware The hardware copies PC into EPC ($14 on cop0) and puts correct code into Cause Reg ($13 on cop0) copies PC into EPC ($14 on cop0) and puts correct code into Cause Reg ($13 on cop0) Sets PC to 0x , process Sets PC to 0x , process enters kernel mode enters kernel mode Exception handler (software) Exception handler (software) Checks cause register (bits 5 to 2 of $13 in cp0) Checks cause register (bits 5 to 2 of $13 in cp0) jumps to exception service routine for the current exception jumps to exception service routine for the current exception

OS Issues When an interrupt is serviced the processor must be able to execute without being interrupted. It must have the capability of temporarily disabling the interrupt atomically. When an interrupt is serviced the processor must be able to execute without being interrupted. It must have the capability of temporarily disabling the interrupt atomically. If an interrupt occurs while an interrupt service is ongoing, it is simply deferred and considered a pending interrupt. It is serviced after the current request terminates. If an interrupt occurs while an interrupt service is ongoing, it is simply deferred and considered a pending interrupt. It is serviced after the current request terminates. The MIPS RISC architecture does not allow user programs to access beyond 0x (the upper half of the memory). The exception handler is in this part of memory and only executed in kernel mode. The MIPS RISC architecture does not allow user programs to access beyond 0x (the upper half of the memory). The exception handler is in this part of memory and only executed in kernel mode.

OS Issues Changing the mode back to the mode before the exception occurs is accomplished via the instruction eret Changing the mode back to the mode before the exception occurs is accomplished via the instruction eret Old  Previous  Current Old  Previous  Current The mode information is stored in the Status Register and can only be written in the kernel mode. It can be read in user mode. The mode information is stored in the Status Register and can only be written in the kernel mode. It can be read in user mode.

OS Issues Enabling and disabling of interrupts can be done either by applying an interrupt mask (IPM) to bits 10-15, or the enable bit of the Status Register. Enabling and disabling of interrupts can be done either by applying an interrupt mask (IPM) to bits 10-15, or the enable bit of the Status Register. The execution of eret enables interrupts The execution of eret enables interrupts

OS Issues A reentrant exception handler is written such that it is itself interruptible. A reentrant exception handler is written such that it is itself interruptible. Interrupts and traps are assigned priorities. Interrupts and traps are assigned priorities. A check is made for pending interrupt requests after every instruction. A check is made for pending interrupt requests after every instruction. If there is a pending interrupt request, the priority is checked. If it has a higher priority than the currently running code, it serviced first, otherwise it is ignored. If there is a pending interrupt request, the priority is checked. If it has a higher priority than the currently running code, it serviced first, otherwise it is ignored.

Enabling interrupts By default, interrupts are disabled in SPIM By default, interrupts are disabled in SPIM To use respond to interrupts, a program must To use respond to interrupts, a program must Enable interrupts Enable interrupts Status register Status register Enable the interrupt for the specific device Enable the interrupt for the specific device Status register Status register Instruction the device controller to cause interrupts Instruction the device controller to cause interrupts Device control memory mapped address Device control memory mapped address

Exceptions come in two varieties Exceptions come in two varieties Interrupts are generated by hardware Interrupts are generated by hardware I/O device I/O device Clock Clock Power down Power down Traps are generated by code execution Traps are generated by code execution Division by zero Division by zero Illegal memory address Illegal memory address System call System call Software: Interrupt Driven I/O

Interrupt driven I/O structure Our programs have all run in kernel mode only Our programs have all run in kernel mode only Code to service an interrupt must be called from location 0x Code to service an interrupt must be called from location 0x We must return to the address at which the interrupt occurred We must return to the address at which the interrupt occurred kernel 0xffffffff 0x x x x x stack code

Interrupt driven I/O structure A queue is needed for both input and output A queue is needed for both input and output Input Input Characters are added when a keyboard interrupt occurs Characters are added when a keyboard interrupt occurs Characters are removed when the input function is called Characters are removed when the input function is called Output Output Characters are removed when a display interrupt occurs Characters are removed when a display interrupt occurs Characters are added when a keyboard interrupt occurs Characters are added when a keyboard interrupt occurs Echoing Echoing Characters are added when the output function is called Characters are added when the output function is called The output function must initiate the first display handler call The output function must initiate the first display handler call Thereafter, interrupts occur when the display becomes ready Thereafter, interrupts occur when the display becomes ready

Interrupt driven I/O structure input output echo User data input function (syscall 8) output function (syscall 4)

Protecting the buffers The input and output buffers may be modified in response to an interrupt The input and output buffers may be modified in response to an interrupt This could occur while the CPU is in the middle of executing user code which reads from the input buffer or writes to the output buffer This could occur while the CPU is in the middle of executing user code which reads from the input buffer or writes to the output buffer To prevent this destructive concurrent access, we must disable interrupt while accessing the buffers To prevent this destructive concurrent access, we must disable interrupt while accessing the buffers Explicitly and status with 0xfffffffe Explicitly and status with 0xfffffffe Implement I/O functions as system calls Implement I/O functions as system calls