12 Exception
12 Exception
Interruption
When someone needs attention that person
will interrupt the work.
Advantages
• Never need to stop working if nobody needs
attention.
Disadvantages
• Will be stopped in the middle of a task. More
difficult to save/restore state (context switching
can be expensive).
• Hardware and software must be involvedto provide
a context switching mechanism.
31 30 29 28 27 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BD 0 CE 0•••0 IP(7) IP(6) IP(5) IP(4) IP(3) IP(2) IP(1) IP(0) 0 ExcCode 0 0
31 30 29 28 27 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BD 0 CE 0•••0 IP(7) IP(6) IP(5) IP(4) IP(3) IP(2) IP(1) IP(0) 0 ExcCode 0 0
31 30 29 28 27 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BD 0 CE 0•••0 IP(7) IP(6) IP(5) IP(4) IP(3) IP(2) IP(1) IP(0) 0 ExcCode 0 0
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
CU RP FR RE ••• IM(7) IM(6) IM(5) IM(4) IM(3) IM(2) IM(1) IM(0) ••• KUo IEo PUp IEp KUc IEc
External Software
Interrupts Interrupts
The MIPS architecture fix a single address --- 0x8000 0080 --- to be
the starting address of the exception handler.
The exception invocation must also save the returning address for
the exception. But it cannot save this address in $ra, because $ra
contains the returning address for the routine that is currently executing.
ExecCode?
HandleInterrupt
HandleSyscall
HandleOverflow
Restore registers
Clean Up State
31 30 29 28 27 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BD 0 CE 0•••0 IP(7) IP(6) IP(5) IP(4) IP(3) IP(2) IP(1) IP(0) 0 ExcCode 0 0
BD 0 CE 0•••0 IP(7) IP(6) IP(5) IP(4) IP(3) IP(2) IP(1) IP(0) 0 ExcCode 0 0
Exception Handler:
HandleSys:
mfc0 $k1, $14 # Get the EPC Register
addi $k1, $k1, 4 # Increment PC past syscall instruction
mtc0 $k1, $14 # Set the EPC Register
Exception Handler:
Exit: <code for Exit>
.kdata
tmpat: .word 0
tmpv0: .word 0
tmpa0: .word 0
tmpa1: .word 0
tmpa2: .word 0
tmpa3: .word 0
tmpra: .word 0
12/08/21 CMPUT 229
35
Save/Restore Registers
.kdata
tmpat: .word 0 # code to save registers
tmpv0: .word 0 sw $k1, tmpat
tmpa0: .word 0 sw $v0, tmpv0
tmpa1: .word 0 sw $a0, tmpa0
tmpa2: .word 0 sw $a1, tmpa1
tmpa3: .word 0 sw $a2, tmpa2
tmpra: .word 0 sw $a3, tmpa3
sw $ra, tmpra
Exception Handler:
.kdata
putqueue: .space 256
.align 2
.ktext
pqtail: .word 0
pqhead: .word 0
.ktext
DP_handler:
lw $k0, DisplayStatus # Get display status word
bge $k0, $zero, DPRet # Return if it is not Ready
lw $k0, pqhead #
lw $k1, pqtail
beq $k0, $k1, DPRet # Return if put queue is empty
addi $k0, $k0, 1 # Increment head
andi $k0, $k0, 0x00ff # Module counter
sw $k0, pqhead # Save new head
lb $k0, putqueue($k0) # get character from put queue
sb $k0, DisplayData # Send character to display
DPRet: jr $ra # Return to caller
Exception Handler:
.kdata
tmpputsra: .word 0
Puts: lw $k0, tmpa0 # Get address of first character
PutsLoop: lbu $a0, ($k0) # Get a character
beq $a0, $zero, PutsRet # If character is null, we are done
sw $ra, tmpputsra # Save return address
jal Puta0 # Print the character
sw $ra, tmpputsra # Save return address
addi $k0, $k0, 1 # Move pointer to next character
j PutsLoop # Loop back
PutsRet: jr $ra
TLB Invalid
TLB Modified
TLB Refill
Virtual Coherency Data Access
Virtual Coherency Instruction Fetch
The BadVAddr does not save any information for bus errors, since
bus errors are not addressing errors.