1
הנבמ םיבשחמ
ta8
Spring 2006 Amar Lior
Adapted from Computer Organization&Design, H/S interface, Patterson Hennessy@UCB,3rd edition
ta8 Spring 200 6 Amar Lior Adapted from Computer - - PowerPoint PPT Presentation
ta8 Spring 200 6 Amar Lior Adapted from Computer Organization&Design, H/S interface, Patterson Hennessy@UCB,3 rd edition 1 Exceptions and Interrupts Exception: An unscheduled event that disrupts program execution
1
Adapted from Computer Organization&Design, H/S interface, Patterson Hennessy@UCB,3rd edition
2
Exception: An unscheduled event that
Interrupts: An exception that comes from
3
Program
e.g. overflow, division by zero, using undefined
instruction
Invoking the operating system from user
Timer
Generated by internal processor timer Used in pre-emptive multi-tasking
I/O
from I/O controller (keyboard, disk)
Hardware failure
e.g. memory parity error
4
.include "defines.h" .data hello: .string "hello world\n" .text .globl _start _start: movl $SYS_write,%eax // SYS_write = 4 movl $STDOUT,%ebx // fd = fileno(stdio) movl $hello,%ecx // buf = str movl $12,%edx // count = 0x6 int $0x80 movl $SYS_exit,%eax xorl %ebx,%ebx int $0x80 ret
5
6
The address of the affected address is saved
The cause of the register is used to record
Than the process jump to the exception
In MIPS 0x8000 0180 In SPIM 0x8000 0080
7
Added to instruction cycle Processor checks for interrupt
Indicated by an interrupt signal
If no interrupt, fetch next instruction If interrupt pending:
Suspend execution of current program Save context Set PC to start address of interrupt handler routine Process interrupt Restore context and continue interrupted program
8
Instruction Cycle (with Interrupts) - State Diagram
9
Disable interrupts
Processor will ignore further interrupts whilst processing
Interrupts remain pending and are checked after first
interrupt has been processed
Interrupts handled in sequence as they occur
Define priorities
Low priority interrupts can be interrupted by higher
priority interrupts
When higher priority interrupt has been processed,
processor returns to previous interrupt
10
11
12
80x86 has one interrupt line 8086 based systems use one 8259A
8259A has 8 interrupt lines Called Programmable Interrupt Controller
13
8259A accepts interrupts 8259A determines priority 8259A signals 8086 (raises INTR line) CPU Acknowledges 8259A puts correct vector on data bus CPU processes interrupt
14
8086 INTR 8259A IRQ0 IRQ1 IRQ2 IRQ3 IRQ4 IRQ5 IRQ6 IRQ7
System Timer Keyboard Slave 8259A Serial port Serial port IDE controller Floppy controller LPT1
15
Trap
Invalid opcode
6
Available for software and hardware interrupts
32-255 Fault
Page Fault
14 Trap
Overflow
4 Trap
Breakpoint
3 Trap Non-Maskable Interrupt (NMI) 2 Trap or Fault Debug exception 1 Fault Divide by zero Type Description Number
caused the exception
16
In MIPS processors, a part of the CPU called
Not all the coprocessor 0’s registers are
The mfc0 and mtc0 instructions are used to
The EPC contain the address of the offending
And the address if the next instruction if the
17
Address of instruction that caused exception 14 Epc Exception type and pending interrupt bits 13 Cause Interrupt mask and enable bits 12 Status Value compared against timer that caused interrupt when they match 11 Compare Timer 9 Count Memory address at which offending memory reference
8 BadVAddr Usage Register Number Register Name
18
interrupt level
the mask is 0
spim)
situation interrupts are disabled and the EPC is not updated if another exception
interrupt
I n t e r r u p t e n a b l e 1 E x c e p t i
L e v e l 4 U s e r M
e 8 15
Interrupt mask
19
The delayed branch is 1 if the last exception
The interrupt pending bits become 1 when
The exception code describe the cause of the
2 6 8 15
Pending Interrupts Exception Code Branch Delay
31
20
Floating point exception FPE 15 Trap Tr 13 Arithmetic overflow exception Ov 12 Coprocessor unimplemented CpU 11 Reserved instruction exception RI 10 Breakpoint exception Bp 9 Syscall exception Sys 8 Buss error on data load or store DBE 7 Buss error in instruction fetch IBE 6 Address error exception (store) AdES 5 Address error exception (load or fetch) AdEL 4 Interrupt (hardware) Int
Cause of Exception Name Number
21
Exception and interrupts cause the MIPS
Called the exception handler This code examine the exception’s code and
The operating system respond by
22