What about ‘interrupts’? An introduction to the basic issues affecting the design of code that performs servicing of interrupts.

Slides:



Advertisements
Similar presentations
Registers of the 8086/ /2002 JNM.
Advertisements

Microprocessors.
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
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
TK 2633 Microprocessor & Interfacing
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.
Exceptions and Interrupts How does Linux handle service- requests from the cpu and from the peripheral devices?
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
1 Computer System Overview OS-1 Course AA
Introduction to Interrupts
On handling interrupts An introduction to the basic issues affecting the design of code that performs servicing of interrupts.
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
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:
An Introduction to 8086 Microprocessor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
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.
Electrical Engineering Department Engineering College Prince Sattam bin Abdul Aziz University Text Book: - Triebel and Singh, "The 8088 and 8086 Microprocessors",
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Lecture 09: Interrupts & The 80x86 IBM PC and Compatible Computers Chapter 14 Interrupts and the 8259 Chip.
Interrupts in the guest VM A look at the steps needed to “reflect” hardware interrupts back into the ROM-BIOS for servicing.
Interrupts Useful in dealing with: The interface: Random processes;
2 nd Year - 1 st Semester Asst. Lect. Mohammed Salim Computer Architecture I 1.
Computer Architecture Lecture 2 System Buses. Program Concept Hardwired systems are inflexible General purpose hardware can do different tasks, given.
INT- interrupt program execution 1. It decrements the sp by 2 and pushes the flag registers on the stack. 2. Decrement the sp by 2 and push the content.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
ECEG-3202 Computer Architecture and Organization Chapter 3 Top Level View of Computer Function and Interconnection.
Dec Hex Bin 14 E ORG ; FOURTEEN Interrupts In x86 PC.
Chapter 6: Computer Components Dr Mohamed Menacer Taibah University
8086 Interrupts and Interrupt Applications
Group 1 chapter 3 Alex Francisco Mario Palomino Mohammed Ur-Rehman Maria Lopez.
Structure and Role of a Processor
MICROPROCESSOR DETAILS 1 Updated April 2011 ©Paul R. Godin prgodin gmail.com.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Block diagram of a computer system Basic components of a computer system using block diagrams: Cpu Memory Input and output unit Evolution of microprocessor.
Intel 8086 MICROPROCESSOR ARCHITECTURE
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
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
Microprocessor and Assembly Language
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Introduction to 8086 Microprocessor
Interrupts In 8085 and 8086.
8086 Microprocessor.
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
Introduction of microprocessor
Basic Microprocessor Architecture
Intel 8088 (8086) Microprocessor Structure
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
Flags Register & Jump Instruction
Computer System Overview
Intel 8088 (8086) Microprocessor Structure
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
CS 301 Fall 2002 Computer Organization
Interrupts.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Computer Operation 6/22/2019.
Presentation transcript:

What about ‘interrupts’? An introduction to the basic issues affecting the design of code that performs servicing of interrupts

Recall the PC components Central Processing Unit Main Memory I/O device I/O device I/O device I/O device system bus These peripheral I/O components act autonomously (i.e., independently of whatever the CPU might happen to be doing at any given moment)

Recall the ‘Fetch-Execute’ cycle INTR ? Fetch next instruction Advance instruction-pointer Decode fetched instruction Execute decoded instruction no Interrupt Service Routine yes

Compare-and-branch We make frequent use of program-loops, such as this one: xor%bx, %bx# initialize array-index again: … # … inc%bx# increment array-index cmp$16, %bx# index still below 16? jbagain# yes, go through again …# otherwise ‘fall through’

The ‘cmp’ instruction The instruction ‘cmp’ causes the CPU to perform internally a subtraction-operation Example:sub$16, %bx The value 16 is subtacted from the value in register BX (but without changing BX) However, the values of bits in the FLAGS register DO get changed, so as to reflect the result of that subtraction-operation!

The FLAGS register OFOF DFDF IFIF TFTF SFSF ZFZF 0 AFAF 0 PFPF 1 CFCF Legend:ZF = Zero Flag SF = Sign Flag CF = Carry Flag PF = Parity Flag TF = Trap Flag OF = Overflow Flag IF = Interrupt Flag AF = Auxiliary FlagDF = Direction Flag Status-flags Control-flags

Effect of ‘cmp $16, %bx’ When this compare-instruction is executed the first time (while BX = 0x0000), the effect upon the FLAGS value is based on this subtraction: (binary zero) (binary 16) = Thus SF=1, ZF=0, CF=1 (due to ‘borrow’), etc.

The ‘jb again’ instruction This conditional-jump instruction examines the setting of the CF-bit (the Carry-Flag) –If CF=1 (i.e., true), then control is transferred to backward, to the instruction at ‘again:’ –If CF=0 (i.e., false), then control continues forward normally (i.e., it “falls through” to the instruction that follows the conditional-jump The CPU performs its ‘jump’ by adding a signed-integer to the value in register IP

Asynchronous interruptions! So programs can be ‘interrupted’ anytime (i.e., at the end of any fetch-execute cycle) Maybe even, for example, right here: cmp $16, %bx jb again An interrupt could occur AFTER the cmp-operation has set the FLAGS, but BEFORE the jb-instruction has tested any of those FLAG-bits

Consider the ‘yes’ case INTR ? Fetch next instruction Advance instruction-pointer Decode fetched instruction Execute decoded instruction no Interrupt Service Routine yes The Interrupt Service Routine may do some arithmetical or logical operations that cause FLAGS to be modified – and so invalidate the program’s conditional-jump!

How CPU solves this problem When an interrupt-request is recognized by the CPU, it automatically ‘saves’ the crucial elements of its program-context Thereby it can ‘resume’ its main program (after it services the interrupt) with those crucial register-values restored: –The address of the next instruction (CS:IP) –The previous settings of the FLAGS bits

The ‘interruption’ senario Dynamic Random Assess Memory (DRAM) Central Processing Unit (CPU) Programmable Interrupt Controller (PIC) peripheral device (keyboard, mouse, timer, etc) Interrupt Vector Table stack-area main program interrupt handler CSIP SSSP FLAGS INTR INTA

The sequence of actions 1.Some device issues an interrupt-request 2.Interrupt Controller forwards it to CPU 3.CPU saves FLAGS, CS, and IP on stack 4.CPU issues acknowledgement to PIC 5.PIC sends Interrupt ID-number to CPU 6.CPU uses ID-number as index into IVT and loads CS and IP with vector-values

What the ISR works with The Interrupt Service Routine begins with the its stack setup like this: Saved FLAGS value Saved CS-value Saved IP-value room here for the stack to grow downward as needed SS:SP (“top” of the stack) If the ISR needs to use any of the other CPU registers, it should push their values onto the stack before it modifies them, then pop those saved values back before returning

What does ‘iret’ do? An Interrupt Service Routine concludes by executing an ‘iret’ instruction -- to resume whatever program had gotten interrupted, and with its FLAGS restored as they were So what ‘iret’ does is to ‘pop’ the top three word-values off the stack and into the IP, CS, and FLAGS registers, respectively, in a single ‘atomic’ operation

A role played by the PIC Before resuming an interrupted program, an interrupt-handler needs to let the PIC know that it has finished servicing the preceding interrupt-request, and that it now is safe to be sent another request Otherwise the stack-area might grow too large if more and more new interrupts got sent while old ones were being serviced

The EOI command Here’s how an interrupt-handler sends an ‘End-Of-Interrupt’ notification to the PIC: NOTE: It’s pure coincidence that the same number (i.e., ‘$0x20’) is used twice in this code-fragment (but easy to remember it!) mov $0x20, %al# put EOI command-code in AL out %al, $0x20# output AL to port number 0x20

Our demo-program To illustrate the PC’s interrupt-handling mechanism, we wrote a short program (named ‘tickdemo.s’) that you can study It has two ‘threads-of-execution’, plus a ‘shared’ variable that both threads use (i.e., one as ‘writer’, the other as ‘reader’) The main thread stores a new value into the IVT that points to the second thread

A timer-tick will interrupt ‘main’ The ‘isr’ thread The ‘main’ thread 0 Our program structure ticks: Interrupt vector table = IVT[ 0x08 ]

A ‘critical section’ of code Modifying the timer-tick interrupt-vector is done by a two-step instruction-sequence –First change the vector’s lo-word (offset) –Then change the vector’s hi-word (segment) What if an interrupt should occur between those two steps? We MUST prevent that from happening! So we use the ‘cli’ and ‘sti’ instructions

In-class exercise The BIOS startup-code programs the timer so that it issues interrupts at a steady rate of about 18.2 timer-ticks per second Can you modify our interrupt-handler code so that it only increment the ‘ticks’ counter once-per-second? i.e., like a digital watch HINT: You may need to add at least one new variable in this program’s data-area

An arithmetical ‘hint’ The number of seconds that have elapsed since ‘ticks’ began counting occurrences of timer-interrupts can be obtained using one of these formulas: # How we can calculate ‘elapsed seconds’ from the value of ‘ticks’ seconds = ticks  (ticks-per-second) = ticks  18.2 = ticks  (182 / 10) = ( ticks * 10 ) / 182  use this last one!