Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch.5.1.5 Receiver Interrupt Program Example: http://www.cs.umb.edu/~cheungr/cs444/CS444_UART_Receiver_interrupts.htm.

Slides:



Advertisements
Similar presentations
1 Homework Reading –Intel 8254 Programmable Interval Timer (PIT) Data Sheet Machine Projects –Continue on MP3 Labs –Continue in labs with your assigned.
Advertisements

Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
I/O Unit.
1 Homework Reading –Review previous material on “interrupts” Machine Projects –MP4 Due today –Starting on MP5 (Due at start of Class 28) Labs –Continue.
Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O – Examples would be console.
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
6-1 I/O Methods I/O – Transfer of data between memory of the system and the I/O device Most devices operate asynchronously from the CPU Most methods involve.
Communication Lab - Interrupts 1/13 Sequential Programming  Our C++ programs are sequential ( סדרתיים), they start at the first instruction and end at.
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: internal fault (e.g.. divide by.
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
1 Interrupts INPUT/OUTPUT ORGANIZATION: Interrupts CS 147 JOKO SUTOMO.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
The 8051 Microcontroller and Embedded Systems
INTERRUPTS PROGRAMMING
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
MICROPROCESSOR INPUT/OUTPUT
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Interrupts Useful in dealing with: The interface: Random processes;
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
 The Programmable Interrupt Controller (PlC) functions as an overall manager in an Interrupt-Driven system. It accepts requests from the peripheral equipment,
INTERRUPTS. Topics to be discussed  8088/86 Hardware Interrupts pins 8088/86 Hardware Interrupts pins   Pin description Pin description.
Intel 8259A PIC EEE 365 [FALL 2014] LECTURE 21 ATANU K SAHA BRAC UNIVERSITY.
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Homework Reading Machine Projects
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Lecture 2 Interrupts.
Homework Reading Machine Projects Labs
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and exceptions
Interrupts and signals
Microprocessor and Assembly Language
68HC11 Interrupts & Resets.
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Introduction An interrupt is an event which informs the CPU that its service (action) is needed. Sources of interrupts: Internal fault (e.g.. divide by.
Anton Burtsev February, 2017
Discussions on hw5 Objectives:
Computer Architecture
Interrupts In 8085 and 8086.
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
8259-programmable interrupt controller
Homework Reading Machine Projects Labs
Presentation On 8259 Made by Md Shabbir Hasan.
Programmable Interrupt Controller 8259
Programmable Interrupt Controller 8259
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
8253 Timer In software programming of 8085, it has been shown that a delay subroutine can be programmed to introduce a predefined time delay. The delay.
* * * * * * * 8051 Interrupts Programming.
Discussions on hw5 Objectives:
Computer System Overview
Operating Systems Chapter 5: Input/Output Management
Chapter 8 I/O.
8259 Programmable Interrupt Controller
Transmitter Interrupts
COMPUTER PERIPHERALS AND INTERFACES
CNET 315 Microprocessor & Assembly Language
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer System Overview
Chapter 8 I/O.
Computer System Overview
CHAPTER 6 INPUT/OUTPUT PROGRAMMING
Programmable Interrupt Controller (PIC)
Lecture 7 System architecture Input-output
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch.5.1.5 Receiver Interrupt Program Example: http://www.cs.umb.edu/~cheungr/cs444/CS444_UART_Receiver_interrupts.htm

Interrupts What is an interrupt? What does an interrupt do to the “flow of control” Interrupts used to overlap computation & I/O Examples would be console I/O, printer output, and disk accesses Normally handled by the OS. Thus under UNIX and NT, rarely coded by ordinary programmers. In embedded systems and real-time systems, part of the normal programming work.

Interrupts (Cont’d) Why interrupts over polling? Because polling Ties up the CPU in one activity Uses cycles that could be used more effectively Code can’t be any faster than the tightest polling loop Bottom line: an interrupt is an asynchronous subroutine call (triggered by a hardware event) that saves both the return address and the system status

When an Interrupt Occurs Finish the current instruction Save minimal state information on stack Transfer to the interrupt handler, also known as the interrupt service routine (ISR) But there is more to it than this…How do we know which device interrupted? And what happens if two (or more) devices request an interrupt at the same time?

How an interrupt happens Com Port Bus

x86 Interrupts Interrupt signals go from device to the PIC and to CPU All 3 signals are on the bus Program the PIC and device using IN or OUT instructions on certain I/O port address, e.g. PIC : 0x20 and 0x21 COM2: 0x2f8, 0x2f9 …

x86 Interrupts (cont’d) UART receives a character and signals an interrupt on a bus line. Interrupt Controller detects the signal. If no pending interrupts are pending, it services the interrupt immediately. If another one is in progress or a higher priority one is pending, the device is ignored. It continues to assert the interrupt signal until it is serviced. To handle the interrupt, the controller puts an interrupt vector number (e.g 0x23 for COM2) on the data bus and asserts a signal (INTR)to interrupt the CPU.

x86 Interrupts (cont’d) CPU stops what it is doing and starts doing something else. CPU uses the interrupt vector number to index the IDT (interrupt descriptor table) and find the interrupt vector (i.e. address of the interrupt service routine) CPU runs the service routine which includes writing a certain value(EOI) to the interrupt controller’s I/O port to ack the interrupt

Saving the Context The hardware saves certain info before the service procedure. Info saved depends on the CPU. Saving the Program counter is the minimum. Some saves internal registers. Most of the CPUs save info on the stack.

Programmable Interrupt Controller (PIC) Programmable means it has multiple possible behaviors selectable by software (via its own I/O ports) Devices send IRQ signals to interrupt controller Interrupt controller prioritizes signals, sending highest to CPU

Interrupt Controller Details Each device has an IRQ number based on its wiring to the PIC Ex. COM2 uses IRQ3, timer 0 uses IRQ0 PIC: the 8259A chip Supports eight interrupt request (IRQ) lines Two chips used in PC, called “master” and “slave” Priority: highest to lowest order is IRQ0-1, IRQ8-15, IRQ3-7 Asserts INTR to CPU, responds to resulting INTA# with an 8-bit interrupt type code (“nn”) on the data bus.

Interrupt Controller Programming PIC is accessible at port addresses 0x20 and 0x21 (for master), using “initialization command words” (ICWs) and “operational command words” (OCWs) ICWs used to set such things as: How much to add to the IRQ to produce nn (8 used for DOS, 0x20 for Linux, 0x50 for Windows) We trust the (Linux) bootup code to handle this setup OCWs used for: EOI command: Reset interrupt in PIC after accepted by ISR (outb of 0x20 to port 0x20, for master) Get/Set Interrupt Mask Register (port 0x21 for master) Ex: 0111 1110 = 0x7e enables IRQs 0 and 7, disables 2-6

Interrupt Process Requesting device generates a signal on IRQn PIC checks its interrupt mask before putting out a logic high on INTR line Between instructions, and if IF=1, the CPU sees INTR and initiates its interrupt cycle. The interrupt handler (ISR) executes Requesting device is usually accessed in the ISR and is thus notified of the completion of the event Ex: UART receiver detects inb for received char

CPU’s interrupt cycle CPU detects INTR between instructions with IF=1 CPU sends back a low on INTA# PIC responds by setting INTR low and puts out 8-bit interrupt code, nn, on data lines CPU reads nn and executes int nn instruction: Machine state saved on stack (cs:eip and eflags) IF set to zero Access IDT[nn] to obtain ISR address ISR address loaded in eip Causing the interrupt handler to execute next

Interrupt Handler Details ISR must Save all registers used Issue EOI command (end-of-interrupt) to PIC Service the device, i.e., do whatever processing is needed for the event the device was signaling Ex. Read the received character, for UART receiver int’s Restore registers Finish with iret instruction.

UART Interrupts The UART is a real I/O device, more typical of interrupt sources than timer 0 The UART has four ways to interrupt, we’ll study just receiver interrupts. No interrupts are enabled until we command the UART to enable them, via register 1, the IER (i.e port 0x3f8+1 or port 0x2f8+1)

UART Receiver Interrupts The receiver interrupts each time it receives a char, and remembers the interrupt-in-progress COM1 is connected to pin IR4 on the PIC, so its IRQ is 4. Similarly COM2’s is 3. The nn code generated by the PIC for COM1 is 0x24, so its interrupt gate descriptor is IDT[0x24] The ISR must read in the received char to satisfy the UART, even if no one wants the char. It also must send an EOI command to the PIC. The receiver detects the inb for the char, and this completes the interrupt-in-progress

UART Interrupts (COM1) Initialization Shutdown Disallow interrupts in CPU (cli) Enable interrupts in the UART (outb to port 0x3f9, IER) Unmask IRQ4 in the PIC by ensuring bit 4 is 0 in the Interrupt Mask Register accessible via port 0x21. Set up interrupt gate descriptor in IDT, using irq4inthand Allow interrupts (sti) Shutdown Disallow interrupts (cli) Disable interrupts in the UART Disallow COM1 interrupts by masking IRQ4 in the P.I.C. by making bit 4 be 1 in the Mask Register (port 0x21)

UART (COM1) Interrupts: two parts of the interrupt handler irq4inthand – the outer assembly language interrupt handler Save registers Call C function irq4inthandc Restore registers iret irq4inthandc - the C interrupt handler Issue the EOI command to the PIC Input the char, and whatever else is wanted

Example Program for COM2 receiver interrupts Look at http://www.cs.umb.edu/~cheungr/cs444/CS444_UART_Receiver_interrupts.htm Steps 1-5: initialization steps Step 6: wait forever loop Steps 10-13: shut down interrupts Steps 7-9: interrupt handler, need the envelope routine Routines pic_end_int(), pic_enable_irq(), pic_disable_irq() are functions implemented in the SAPC library in directory $pclibsrc Look at $pcinc for include files

Interrupt Envelope Routine From $pclibsrc/irq3.s: The bold lines are the essential ones you should understand. The others date from Linux and are only needed to guard against bad user-level code. # like linux SAVE_MOST and RESTORE_MOST macros in irq.h .text .globl _irq3inthand KERNEL_DS = 0x18 _irq3inthand: cld # D bit gets restored by iret (this can be dropped) push %es # in case user code changes data segs (this can be dropped) push %ds # (this can be dropped) pushl %eax # save C scratch regs <---(1) register saves pushl %edx pushl %ecx movl $KERNEL_DS, %edx # (this can be dropped) mov %dx, %ds # (this can be dropped) mov %dx, %es # (this can be dropped) call _irq3inthandc # call C interrupt handler <---(2) call into C popl %ecx <---(3) register restores popl %edx popl %eax pop %ds #(this can be dropped) pop %es #(this can be dropped) iret <---(4) iret instruction