7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section 13.2.2.

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

DMA Controller (8237 Programming Examples)
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
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.
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.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
Architectural Support for Operating Systems. Announcements Most office hours are finalized Assignments up every Wednesday, due next week CS 415 section.
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.
Hardware Support for Operating Systems Sunny Gleason Vivek Uppal COM S 414
Introduction to Interrupts
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Exceptions, Interrupts & Traps
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 CS503: Operating Systems Part 1: OS Interface Dongyan Xu Department of Computer Science Purdue University.
CHAPTER 5 I/O PRINCIPLE Understand the principles of System Bus
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
ELEC4601 Microprocessor systems Lab 3 Tutorial
Interrupts and DMA CSCI The Role of the Operating System in Performing I/O Two main jobs of a computer are: –Processing –Performing I/O manage and.
IRQ  The IRQ is a number set in the computer for the interrupt request.  assigned to devices to allow it to "interrupt", or send a signal, to the computer.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Interrupts Useful in dealing with: The interface: Random processes;
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
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 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.
Programmable Interrupt Controller (PIC)
8086 Interrupts and Interrupt Applications
6. HAL and IDT ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section  Hardware Abstraction Layer ◦ Section
14.2: x86 PC AND INTERRUPT ASSIGNMENT
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
10. Epilogue ENGI 3655 Lab Sessions.  We took control of the computer as early as possible, right after the end of the BIOS  Our multi-stage bootloader.
Lecture 3 CSE 341 – Microprocessors Lecture 3 Md. Omar Faruqe UB 1228
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. 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
Homework Reading Machine Projects Labs
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Interrupts and exceptions
Interrupts and signals
Interfacing with Hardware
Homework Reading Machine Projects Labs
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
Anton Burtsev February, 2017
Operating Systems (CS 340 D)
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
8259-programmable interrupt controller
Homework Reading Machine Projects Labs
IRQ, DMA and I/O Ports - Introduction -
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.
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
Processor Fundamentals
8259 Programmable Interrupt Controller
COMPUTER PERIPHERALS AND INTERFACES
Interrupts and Exception Handling
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Programmable Interrupt Controller (PIC)
COMP3221: Microprocessors and Embedded Systems
Lecture 12 Input/Output (programmer view)
Presentation transcript:

7. IRQ and PIC ENGI 3655 Lab Sessions

Richard Khoury2 Textbook Readings  Interrupts ◦ Section

Richard Khoury3 Interrupts  Last week, we learned about interrupts ◦ Two kinds, software and hardware ◦ Software signal errors ◦ Hardware signal that a device needs attention  We coded routines to handle interrupts ◦ 256 interrupt descriptors in the IDT ◦ Special routine for the first 32 interrupts, default handler for the others  This week, we move on to hardware interrupts

Richard Khoury4 Hardware Interrupts I/O Controller Input or output ready, or error Translate IRQ into Interrupt no. Send IRQ Signal CPU’s Interrupt Request line Execute instruction Check IR line Execute instruction Check IR line Jump to location pointed in IDT Save state information Interrupt Handler Routine Restore state information Perform regular I/O functions Programmable Interrupt Controller (PIC) CPU OS Execute instruction

Richard Khoury5 PIC  Programmable Interrupt Controller receives interrupts from system, asserts priority, and notifies the CPU ◦ You should guess that it is system-specific  The Intel PIC is the 8259A chip ◦ Can handle 8 IRQs – insufficient for a modern computer ◦ Motherboard has two cascading 8259A chips, a master and a slave

Richard Khoury6 Default Hardware Interrupts MASTER PIC  IRQ 0: Programmable Interval Timer (PIT)  IRQ 1: Keyboard controller  IRQ 2: Cascade from slave PIC  IRQ 3: Serial Port COM2  IRQ 4: Serial Port COM1  IRQ 5: Parallel Port LPT2  IRQ 6: Floppy disk controller  IRQ 7: Parallel Port LPT1 SLAVE PIC  IRQ 8: Real-Time Clock  IRQ 9: CGA Retrace  IRQ 10 is reserved  IRQ 11 is reserved  IRQ 12: PS/2 Mouse controller  IRQ 13: Math coprocessor  IRQ 14: Hard disk controller 1  IRQ 15: Hard disk controller 2

Handling IRQs  We will need a function to set up IRQ handling in our OS ◦ Called by the HAL after the GDT and IDT initialization functions  Three steps ◦ Remap the PIC’s interrupt numbers ◦ Install interrupt descriptors for the IRQ in the IDT ◦ Initialize the values of variables needed for the default IRQ functions

Richard Khoury8 Remapping Interrupts  The first thing we need to do is map IRQ to interrupts in the IDT ◦ By default, IRQ 0-7 are mapped to interrupts 8-15, and IRQ 8-15 are mapped to interrupts ◦ Not good; interrupts 8-15 are already used, and this will lead to conflicts  Recall from last week: 0-18 are already used, are reserved by Intel ◦ So we will remap IRQ 0-15 to interrupt 32-47

Richard Khoury9 Remapping Interrupts  We will need to reinitialize the two PICs  As with any chip, this will require us to write data into the ports ◦ Each PIC has a command port and a data port  Master PIC command port: 0x20, data port 0x21  Slave PIC command port: 0xA0, data port 0xA1  Recall: we have a port-writing function in our HAL ◦ port.h/.c

Richard Khoury10 Remapping Interrupts  Initialization of a PIC is done by sending four successive Initialization Control Words (ICW)  The details are in the specs (on the website)  ICW1 is the initialization command word (goes to the command port) ◦ Hints: Call address interval does not apply for us, and we are using the PIC in edge triggered mode  ICW2 is the new IDT value of the first IRQ to each chip (data) ◦ The next IRQ of the PIC will have the following seven interrupt values ◦ We will use 32 for the master and 40 for the slave

Richard Khoury11 Remapping Interrupts  ICW3 is the IRQ pin connecting the master and the slave (IRQ2) (data) ◦ Hint: remember that C does not handle binary numbers directly, unlike Assembly!  ICW4 defines the PIC behaviour (data) ◦ Hints: we will use normal end-of-interrupt (EOI) operations, we will not use buffered mode, and Special Fully Nested Mode only applies if there are more than 2 PIC

Richard Khoury12 Remapping Interrupts  After we’re done reinitializing the PICs, we can clear the data port to zero ◦ Or restore the previous state if we saved it before initialization  After that, the IRQs are mapped to interrupts  So we have to update the information in the IDT ◦ Without modifying the code of IDT.c/.h ◦ That’s something we learned last week!

Richard Khoury13 Installing IRQs  Recall: function i86_install_ir ◦ Writes an interrupt descriptor in the IDT and maps it to a function, the interrupt handler routine (IHR) ◦ We’ll use it to install the IRQ handler routines to interrupts  Recall: The IHR is a three-part function ◦ Low Part is a global, interrupt-specific, Assembly function that pushes the interrupt number and error code on the stack and calls the Common Part ◦ Common Part is a common Assembly function that pushes all the registers on the stack and calls the Top Part ◦ Top Part is a C function that receives the registers as argument and takes interrupt-specific action ◦ That’s what our IRQ handler routines will be as well

Richard Khoury14 IRQ Handler Functions  Structure of Low Part ◦ Identical to ISR function except we need to differentiate the IRQ number and interrupt number _irq#: push byte 0 push byte ## jmp irq_common_stub ◦ Where ## = 32 + #  Structure of Common Part ◦ Identical to ISR function except we call the irq_handler function instead of the fault_handler function

Richard Khoury15 IRQ Handler Functions  Structure of Top Part void irq_handler(struct isrregs *r) { ◦ Execute hardware’s handler function, or default handler if none is available ◦ Send end-of-interrupt signal to PIC ◦ Do NOT run an infinite loop }

Richard Khoury16 IRQ Handler Functions  Each IRQ corresponds to a piece of hardware  When we install each of them we will write a handler for it  So for now, we need to make sure that our OS’s IRQ functions can allow us to install and uninstall custom IRQ handler functions

Richard Khoury17 IRQ Handler Functions  There are 16 IRQs, so we will create an array of 16 pointers to handler functions void *irq_routines[16];  Installing and uninstalling a handler function for an IRQ is simply changing the corresponding pointer void irq_install_handler(uint32_t irq, void (*handler)(struct isrregs *r)) { irq_routines[irq] = handler; } void irq_uninstall_handler(uint32_t irq) { irq_routines[irq] = 0; }

Richard Khoury18 IRQ Handler Functions  Initially, the pointers will all be 0 ◦ We haven’t installed any hardware yet!  Don’t forget to initialize them at 0 in the end of the IRQ initialize function!

Richard Khoury19 IRQ Handler Functions  First function of Top Part:  Checks the registers it received in argument and retrieves the IRQ handler pointer corresponding to the correct interrupt  If not zero, call that function (pass registers as argument, as the handler function will need them)  If zero, take default action ◦ Create an array of messages and display the one corresponding to the interrupt number

Richard Khoury20 End Of Interrupt Signal  Second function of the Top Part  The EOI signals to the PIC that the interrupt has been dealt with  It’s a command word that has to be written in the PIC command port ◦ Which PIC? ◦ IRQ 0-7, Master PIC ◦ IRQ 8-15, both PICs, because Slave PIC is connected to Master PIC  The command word is 0x20

Richard Khoury21 Lab Assignment  Write IRQ.h & IRQ.c  You need an i86_irq_initialize function ◦ Called by cpu_initialize after initializing the IDT ◦ Reinitialize the PICs ◦ Installs new descriptors for ints in the IDT ◦ Sets the IRQ handler pointers to 0  You’ll also need all the functions described ◦ Install/Uninstall IRQ handler pointers ◦ Top Part of the IRQ handler function ◦ Array of pointers to IRQ handler functions  Add to GlobalCFunctions.inc ◦ 16 Low parts and 1 Common part of the IRQ handler functions

Richard Khoury22 Lab Assignment  Don’t forget to call the IRQ initialization function from the CPU initialization function  Otherwise it won’t do anything  Once you’re done (and if you did it correctly) it’s now safe to reinitialize interrupts ◦ Recall: we had cleared them with the CLI command in the bootloader before going into protected mode ◦ We can restore them by adding this line in main(), after initializing the HAL __asm__ __volatile__ ("sti");  If we did this previously, our OS crashed ◦ Now, our OS immediately detects an IRQ0 ◦ We’ll deal with that next week

Richard Khoury23 Lab Assignment  So for this lab, you: ◦ Write IRQ.c/IRQ.h ◦ Add functions in GlobalCFunctions.inc ◦ Add one line in i86.c ◦ Add one line in main.c  You should not be changing any other files ◦ Especially IDT.c/IDT.h