Homework / Exam Return and Review Exam #1 Reading Machine Projects

Slides:



Advertisements
Similar presentations
CS 4284 Systems Capstone Godmar Back Processes and Threads.
Advertisements

1 Homework Reading –Intel 8254 Programmable Interval Timer (PIT) Data Sheet Machine Projects –Continue on MP3 Labs –Continue in labs with your assigned.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
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.
Context Switch Animation Another one by Anastasia.
LOGO Chapter 1 Interrupt handling. hardware interrupt Under x86, hardware interrupts are called IRQ's. When the CPU receives an interrupt, it stops whatever.
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
PC hardware and x86 3/3/08 Frans Kaashoek MIT
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Interrupt Processing Haibo Wang ECE Department
1 Homework Reading –PAL, pp , Machine Projects –Finish mp2warmup Questions? –Start mp2 as soon as possible Labs –Continue labs with your.
Linux Operating System
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Introduction to Interrupts
Homework / Exam Return and Review Exam #1 Reading Machine Projects
Intel IA32 OS Support -Refresh
COMP201 Computer Systems Exceptions and Interrupts.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
6.828: PC hardware and x86 Frans Kaashoek
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.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Chapter 2 Parts of a Computer System. 2.1 PC Hardware: Memory.
Functions/Methods in Assembly
6. HAL and IDT ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section  Hardware Abstraction Layer ◦ Section
7. IRQ and PIC ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  Interrupts ◦ Section
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
Lecture 7 Interrupt ,Trap and System Call
Transmitter Interrupts Review of Receiver Interrupts How to Handle Transmitter Interrupts? Critical Regions Text: Tanenbaum
Homework Reading Machine Projects
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
Assembly language.
Interrupts and signals
Microprocessor and Assembly Language
Operating Systems Engineering
Microprocessor Systems Design I
Homework Reading Machine Projects Labs
Anton Burtsev February, 2017
Discussions on hw5 Objectives:
Computer Architecture
Anton Burtsev February, 2017
Interrupts In 8085 and 8086.
Homework Reading Labs S&S Extracts ,
Interrupts – (Chapter 12)
Computer Organization And Assembly Language
Homework Reading Machine Projects Labs PAL, pp ,
Aaron Miller David Cohen Spring 2011
Homework Reading Machine Projects Labs
Basic Microprocessor Architecture
x86 segmentation, page tables, and interrupts
Homework Reading Continue work on mp1
Interrupt.
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.
Interrupt Driven I/O References Text: Tanenbaum ch.1.4.3, ch Receiver Interrupt Program Example:
Discussions on hw5 Objectives:
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.
Assembly Language Programming II: C Compiler Calling Sequences
CS 301 Fall 2002 Computer Organization
Discussions on HW2 Objectives
Transmitter Interrupts
Discussions on HW2 Objectives
CNET 315 Microprocessor & Assembly Language
Low-Level Thread Dispatching on the x86
CHAPTER 6 INPUT/OUTPUT PROGRAMMING
COMP3221: Microprocessors and Embedded Systems
Interrupts and System Calls
Presentation transcript:

Homework / Exam Return and Review Exam #1 Reading Machine Projects S&S Extracts 385-393, PIC Data Sheet Machine Projects Start on mp3 (Due Class 19) Labs Continue in labs with your assigned section

Interrupts An interrupt acts as a “hardware generated” function call – External versus Internal I/O device generates a signal to processor Processor interrupts software execution Processor executes appropriate interrupt service routine (ISR) for the I/O device ISR returns control to the software that was executing before the interrupt occurred

Adding Interrupts to the Hardware Add Programmable Interrupt Controller “Chip” IRQ line from I/O device to PIC Interrupt line from PIC to CPU Control Bus (M/IO#, W/R#, D/C#) Address Bus x86 CPU I/O Device IRQ Line Program. Interrupt Controller Memory Data Bus Interrupt Line

Adding Interrupts to the Hardware Programmable Interrupt Controller: The 8259A chip Each Chip supports eight interrupt request (IRQ) lines Asserts INTR to CPU, responds to resulting INTA# with an 8-bit interrupt vector (“0xdd”) on the data bus Industry Standard Architecture (ISA) Bus Priority: highest to lowest order is IRQ0-1, IRQ8-15, IRQ3-7 IRQ0 IRQ8 IRQ1 IRQ9 IRQ10 To CPU Slave 8259 Master 8259 IRQ3 IRQ11 IRQ4 IRQ12 IRQ5 IRQ13 IRQ6 IRQ14 IRQ7 IRQ15

Interrupt Handling Software that was executing “never knew what hit it” – execution is suspended until ISR ends Processor does the following: Pushes %eflags, %cs, and %eip on stack (similar to making a function call but it saves more context) Inhibits other interrupts (similar to cli instruction) Initiates an Interrupt Acknowledge Cycle to get IV Uses IV to get address of Interrupt Service Routine Sets %eip to entry point of the ISR

Interrupt Acknowledge Cycle CPU Interrupt Acknowledge (INTA#) bus cycle M/IO# = 0, W/R# = 0, D/C# = 0 PIC responds with Interrupt Vector (IV) to CPU IV is an 8 bit number (0 – 255) equal to the IRQ number plus a constant (0x20 for Linux) passed to the processor on the data bus Processor uses IV as an index into the Interrupt Descriptor Table (IDT) to get entry point for ISR

Interrupt Descriptor Table IDT is an array of 8-byte entries (gates) in memory A special register contains the address of the IDT In our Tutor VM systems, the IDT is located in the Tutor memory area At startup, S/W loads that register using instruction: lidt idt_48 # load idt with 0,0x5604c … idt_48: .word 0x400 # idt limit=0x400 .word 0x604c,0x5 # idt base=0x0005604c

Interrupt Gate Descriptor Contents of each Interrupt Gate Descriptor: typedef struct desc_struct { unsigned short addr_lo; /* bits 0-15: handler offset lsbs */ unsigned short selector; /* bits 16-31: selector of handler */ unsigned char zero; /* bits 32-39: all 0 */ unsigned char flags; /* bits 40-47: valid, dpl, type */ unsigned short addr_hi;/* bits 48-63: handler offset msbs */ } Gate_descriptor; An example from Tutor VM memory 25 eb 10 00 00 8e 05 00 ISR address = 0x0005eb25, CS = 0x0010, flags = 0x8e

Interrupt Service Routine What does an ISR do to “handle” interrupt? Saves any additional registers it uses Must make I/O device turn off interrupt signal If it does not  infinite loop re-executing the ISR Usually accomplished by reading/writing a port Performs in or out instructions as needed Uses out to send End of Interrupt (EOI) to PIC Restores any additional saved registers Executes iret instruction to return

Interrupt Return When the ISR executes iret instruction Processor pops %eip, %cs, and %eflags (Note: Done as a single “atomic” operation) Popping %eflags may have side effect of re-enabling interrupts (The IF flag bit is in %eflags register) The software that was interrupted resumes its normal execution like nothing happened (It’s “context” has been preserved)

Implementing ISR Code Want to write most of ISR code in “C”, but … Can’t push/pop scratch registers in C code Can’t tell C compiler to generate iret instead of ret Write a small assembly ISR or use inline Assy Push System registers / C compiler scratch registers Call C function for body of ISR code Pop System Registers / C compiler scratch registers Execute iret

Assembly Language ISR Wrapper .text # Example for MP3 IRQ0 timer chip interrupt .globl _irq0inthand KERNEL_DS = 0x18 # Linux kernel data segment value _irq0inthand: cld # D bit gets restored to old val by iret push %es # in case user code changes data segments push %ds pushl %eax # save C scratch regs pushl %edx pushl %ecx movl $KERNEL_DS, %edx mov %dx, %ds # make sure our data segments are in use now mov %dx, %es

Assembly Language ISR Wrapper call _irq0inthandc # call C interrupt handler popl %ecx # restore C scratch registers popl %edx popl %eax pop %ds # restore data segment registers pop %es iret # return to interrupted background code /* C interrupt Handler Code for MP3 IRQ0 timer chip interrupt */ void irq0inthandc() { pic_end_int(); /* notify PIC that its part is done */ tickcount++; /* count the tick in global variable */ }

In-line Assembly ISR Allows us to write MP3 IRQ0 ISR without need for an assembly language wrapper function Store the address of irq0inthandc ISR directly in the IDT instead of address of irq0inthand( ) Compare to the existing IRQ0 ISR code in mp3 and previous Assembly Language ISR Wrapper Since our exercises do not change the Direction Flag and the CS or ES registers, we don’t need to save and restore that part of the context

In-line Assembly Code Modified MP3 C interrupt handler code for IRQ0 void irq0inthandc(void) { /* hardware pushes 3 registers before entry here */ /* compiler generated code adds stack frame */ asm("pushl %eax"); /* save scratch registers */ asm("pushl %ecx"); asm("pushl %edx"); pic_end_int(); /* notify PIC that its part is done */ tickcount++; /* count the tick in global var */

In-Line Assembly Code State of the Stack during irq0inthandc execution: Pushed by compiler Stack frame code %esp %ebp Push for call to pic_end_int Pushed by in-line assembly code Pushed by HW interrupt * * * %edx %ecx %eax %ebp %eip %cs %eflags Background Stack State Pop from ret in pic_end_int Popped by in-line assembly code Popped by in-line assembly iret

In-line Assembly Code asm("popl %edx"); /* restore scratch registers */ asm("popl %ecx"); asm("popl %eax"); asm("movl %ebp, %esp"); /* undo stack frame */ asm("popl %ebp"); asm("iret"); /* return from interrupt */ /* compiler generated ret instruction is never reached */ }

Advantage of External Interrupts Processor can start an I/O device and go off to do other useful work – not wait for it When I/O device needs attention, the ISR for that I/O device is invoked automatically Example: When the COM1 THRE goes to the 1 state, the COM1 port ISR is invoked to load another ASCII character into the data port and returns

Exceptions and SW Interrupts Internal – not based on external I/O device Exceptions Possible side effects of executing an instruction Divide by zero  Execute an exception “ISR” Software Interrupts Instruction int $n deliberately placed in the code System Call  Execute system call (e.g. Linux OS) Tutor Breakpoint (int $3)  Return to debugger