ECE291 Computer Engineering II Lecture 14 Josh Potts University of Illinois at Urbana- Champaign.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Subroutine and Interrupt.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
University of Tehran 1 Microprocessor System Design Interrupt Omid Fatemi
Real-Mode Interrupts Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Chaining Interrupts. Short contents What does chaining interrupts mean? TSR programs Chaining an interrupt example program Reentrancy problems with DOS.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
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.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
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.
Interrupt Processing Haibo Wang ECE Department
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
1 Computer System Overview OS-1 Course AA
Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, All rights reserved. You may modify.
Introduction to Interrupts
Introduction to Computer Engineering by Richard E. Haskell Interrupts Module M17.3 Sections 11.3, 14.1.
Exceptions, Interrupts & Traps
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
Interrupts – (Chapter 12)
More on Interrupts. Interrupt service routines oDOS facilities to install ISRs oRestrictions on ISRs oCurrently running program should have no idea that.
Lecture 10 Interrupts, Part 2, putting it all together Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
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:
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
ECE291 Computer Engineering II Lecture 13 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
MICROPROCESSOR INPUT/OUTPUT
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
ECE291 Lecture 9 Interrupts I. ECE 291 Lecture 9Slide 2 of 28 Lecture Outline Printed lab manual?Printed lab manual? Interrupt I/OInterrupt I/O Interrupt.
1 Microprocessor-based Systems Course 8 Design of input/output interfaces.
Interrupts, Part 1 Dr. Dimitrios S. Nikolopoulos CSL/UIUC
Interrupts Useful in dealing with: The interface: Random processes;
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416.
ECE291 Lecture 9 Interrupt implementation (part of the magic explained!)
ECE291 Computer Engineering II Lecture 11 Josh Potts University of Illinois at Urbana- Champaign.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
Interrupts.
ECE291 Computer Engineering II Lecture 14 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt.
ECE 353 Introduction to Microprocessor Systems Michael J. Schulte Week 11.
Microprocessor System Design Programmable Interrupt Controller.
بسم الله الرحمن الرحيم MEMORY AND I/O.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir. A.C. Verschueren Eindhoven University of Technology Section of Digital.
Interrupts and interrupt responses
Interrupts and signals
MICROPROCESSOR BASED SYSTEM DESIGN
Microprocessor and Assembly Language
Microprocessor Systems Design I
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Anton Burtsev February, 2017
Interrupts In 8085 and 8086.
8254 – SOFTWARE PROGRAMMABLE TIMER
Interrupts – (Chapter 12)
Computer Organization And Assembly Language
Microprocessor and Assembly Language
11.1 Interrupt Mechanism, Type, and Priority
COMPUTER PERIPHERALS AND INTERFACES
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
CHAPTER 6 INPUT/OUTPUT PROGRAMMING
COMP3221: Microprocessors and Embedded Systems
Microprocessor and Assembly Language
Presentation transcript:

ECE291 Computer Engineering II Lecture 14 Josh Potts University of Illinois at Urbana- Champaign

Josh PottsECE291 Outline Hash functions Interrupt driven I/O Interrupt service routines (ISR)

Josh PottsECE291 Hash Functions Consider using a table lookup when the input (I) can span a large range of values but is sparsely populated. Example: Count incoming packets from each of 100 hosts scattered throughout the internet using the 32-bit IP source address. A Table-Lookup would require 4 billion table entries, most of which would be empty.

Josh PottsECE291 Hash Functions (cont.) A Hash Function, H(x), can be used to re-map the four-byte (W.X.Y.Z) IP address to smaller (8-bit) value. H(W.X.Y.Z)=W xor X xor Y xor Z H( ) = 17 H( ) = 190 H( ) = 14 Hash Table IndexIP address 0….. …… … … …..

Josh PottsECE291 Hash Functions Issues Collisions, can occur when two inputs map to the same output. Collision Resolution: Linear Probing Use next-available location in the hash table Add an extra identifier (a tag) to distinguish different entries in the table, example (simplest algorithm) to retrieve data: tag = IP_addressTag i = h(IP_address); if (ht[i].tag == IP_addressTag) then else

Josh PottsECE291 Interrupt Vectors The term interrupt is used in three different contexts: Software interrupts (e.g., 21h) –provide a mechanism whereby the programmer can use the int instruction to access blocks of code that already exist and are resident in machine memory Hardware interrupts –triggered by hardware events external to the microprocessor, rather than resulting from an int or any other instruction –e.g., request for service by external devices such as disk drives Exceptions –hardware origin within the microprocessor itself –e.g., anomalous event within a program, such as an attempt to divide by zero

Josh PottsECE291 Interrupt Driven I/O Consider an I/O operation, where the CPU constantly tests a port (e.g., keyboard) to see if data is available –CPU polls the port if it has data available or can accept data Polled I/O is inherently inefficient Wastes CPU cycles until event occurs Analogy: Checking your watch, standing at the door... Solution is to provide an interrupt driven I/O Perform regular work until an event occurs Process event when it happens, then resume normal activities Analogy: Alarm clock, doorbell, telephone ring...

Josh PottsECE291 Interrupting an 80x86 Microprocessor Interrupt signal (pin) on the 80x86 CPU 8259 Programmable Interrupt Controller (typically built into motherboard chipset) ISA/PCI System Bus (pins defined for IRQ signals) Peripheral Devices (example) IRQ 0: Timer (triggered 18.2/second) IRQ 1: Keyboard (keypress) IRQ 2: PIC IRQ 3: Serial Ports (Modem, network) IRQ 5: Audio card IRQ 6: Floppy (read/write completed) IRQ 8: Real-time Clock IRQ 12: Mouse IRQ 13: Math Co-Processor IRQ 14: IDE Hard-Drive Controller

Josh PottsECE291 Servicing an Interrupt Complete current instruction Preserve current context –PUSHF Store flags to stack –Clear Trap Flag (TF) & IF (Interrupt Flag) –Store return address to stack PUSH CS, PUSH IP Identify Source –Read 8259 PIC status register –Determine which device (N) triggered interrupt Activate Interrupt Service Routine –Use N to index vector table –Read CS/IP from table –Jump to instruction Execute Interrupt Service Routine –usually the handler immediately re- enables the interrupt system (to allow high priority interrupts to occur) –process the interrupt Indicate End-Of-Interrupt (EOI) to 8259 PIC MOV AL,20h OUT 20h,AL ;transfer s the contents of AL to I/O port 20h Return (IRET) –POP IP (Far Return) –POP CS –POPF (Restore Flags)

Josh PottsECE291 Interrupt Service Routines (ISR) Reasons for writing your own ISR –to supersede the default ISR for internal hardware interrupts (e.g., division by zero) –to chain your own ISR onto the default system ISR for a hardware device, so that both the system’s actions and your own will occur on an interrupt (e.g., clock -tick interrupt) –to service interrupts not supported by the default device drivers –to provide communication between a program that terminates and stays resident and other application software

Josh PottsECE291 Interrupt Service Routines (ISR) DOS facilities to enable ISR Restrictions –Currently running program should have no idea that it was interrupted. –ISR should never make DOS call during the actual interrupt processing DOS calls are non-reentrant,i.e., expect single execution FunctionAction INT 21h Function 25hSet Interrupt vector INT 21h Function 35hGet Interrupt vector INT 21h Function 31hTerminate and stay resident

Josh PottsECE291 Interrupt Service Routines ISRs are meant to be short. –keep the time that interrupts are disable and the total length of the service routine to an absolute minimum –remember after interrupts are re-enabled (STI instruction), interrupts of the same or lower priority remain blocked if the interrupt was received through the 8259A PIC ISRs can be interrupted. ISRs must be in memory – Option 1: Redefine interrupt only while your program is running the default ISR will be restored when the executing program terminates – Option 2: Use DOS Terminate-and-Stay-Resident (TSR) command the ISR stays permanently in machine memory

Josh PottsECE291 Installing ISR Let N==interrupt to service Read current function pointer in vector table –Use DOS function 35h –Set AL=N –Call DOS Function AH=35h, INT 21h –Returns: ES:BX = Address stored at vector Set new function pointer in vector table –Use DOS function 25h –Set DS:DX=New Routine –Set AL=N –DOS Function AH=25h, INT 21H

Josh PottsECE291 Installing ISR Interrupts can be installed, chained, or called Install New interrupt (replace old interrupt) MyIntVector PROC FAR.. Save Registers Service Hardware Reset PIC Restore Registers ….. IRET MyIntVector ENDP Chain into interrupt Service MyCode first MyIntVector PROC FAR …... Save Registers MyCode Restore Registers …. JMP CS:Old_Vector MyIntVector ENDP Call Original Interrupt Service MyCode last MyIntVector PROC FAR …... PUSHF CALL CS:Old_Vector….. Save Registers MyCode Restore Registers …... IRET MyIntVector ENDP

Josh PottsECE291 Timer Interrupt ;====== Variables =================== oldv DD ? ; Old Vector (far pointer to old interrupt function) count DW 0 ; Interrupt counter (1/18th second) scount DW 0 ; Second counter mcount DW 0 ; Minute counter ;====== Main procedure ===== main proc far.. ; ---- Install Interrupt Routine----- Call Install ; Main Body of Program (print count values) showc: MOV AX,mcount ; Minute Count.. call pxy MOV AX,scount ; Second Count.. call pxy mov ax,count ; Interrupt Count (1/18th sec).. call pxy MOV AH,1 INT 16h ; Check for key press JZ showc ; (Quit on any key) ; ---- Deinstall Interrupt Routine----- Call DeInst ; Restore original INT8.. main endp

Josh PottsECE291 Timer Interrupt Install Interrupt ;====== Helper Function ============= pxy proc near ; Prints Text on Screen.. pxy endp ;====== Install Interrupt ===== Install proc near ; Install new INT 8 vector PUSH ES MOV AL,8 ; INT = 8 MOV AH,35h ; Subfunction = Read Vector INT 21h ; DOS Service MOV WORD PTR Oldv+0,BX MOV WORD PTR Oldv+2,ES MOV AL,8 ; INT = 8 MOV AH,25h ; Subfunction = Set Vector MOV DX,offset myint ; DS:DX point to function INT 21h ; DOS Service POP ES RET Install ENDP

Josh PottsECE291 Timer Interrupt Uninstall Interrupt ;====== Deinstall Interrupt =========== DeInst proc near ; Deinstall Routine ; (Reinstall old vector).. MOV DX,word ptr Oldv+0 MOV DS,word ptr Oldv+2 MOV AL,8 ; INT = 8 MOV AH,25h ; Subfunction = Set Vector INT 21h ; DOS Service.. RET DeInst endp

Josh PottsECE291 Timer Interrupt ISR Code ;====== ISR Code ========= myint proc near push DS ; Save all registers push AX MOV AX,CS ; Load default segment MOV DS,AX pushf ;Call Orig Function w/flags call oldv ;Far Call to existing routine INC count ; Increment Interupt count CMP count,18 JNEmyintd INC scount ; Next second MOV count,0 CMP scount,60 JNE myintd INC mcount ; Next minute MOV scount,0 myintd: POP AX ; Restore all Registers POP DS IRET ; Return from Interrupt myint endp

Josh PottsECE291 Replacing An Interrupt Handler ;install new interrupt vector setIntMACRO Num, Offset, Segment pushax pushdx pushds movdx, Offset movax, Segment movds, ax moval, Num movah, 25h;set interrupt vector int21h popds popdx popax ENDM ;store old interrupt vector getIntMACRO Num, Offset, Segment moval, Num movah, 35h;get interrupt vector int21h mov Offset, bx mov Segment, es ENDM

Josh PottsECE291 Replacing An Interrupt Handler Title New04h.asm.MODEL small.STACK.DATA Warning DB ‘Overflow - Abort? $‘ old04hOffset DW ? old04hSegment DW ?.CODE ;store old vector getInt 04h, old04hOffset, old04hSegment ;replace with address of new int handler setInt04h,, cs mov al, 50 addal, al into mov al, 100 add al, al into ;calls int 04 - an overflow ;restore original int handler setInt 04h, old04hOffset, old04hSegment movax, 4c00h int21h

Josh PottsECE291 Replacing An Interrupt Handler New04h PROC NEAR pushax pushbx movax, OFFSET Warning push ax callputStr movax, OFFSET yes pushax callgetStr movbx, OFFSET yes cmpBYTE PTR [bx], 'y' jeAbort popbx popax iret Abort: movax, 4c01h int21h New04h ENDP NOTES INTO is a conditional instruction that acts only when the overflow flag is set With INTO after a numerical calculation the control can be automatically routed to a handler routine if the calculation results in a numerical overflow. By default Interrupt 04h consists of an IRET, so it returns without doing anything.