170 likes | 488 Views
MIPS Interrupts. MIPS interrupts. The materials of this lecture can be found in A7-A8. Also, the slides are developed with the help of http://jjc.hydrus.net/cs61c/handouts/interrupts1.pdf. The MIPS memory . Actually, everything above 0x7fffffff is used by the system. What is in there?.
E N D
MIPS interrupts • The materials of this lecture can be found in A7-A8. • Also, the slides are developed with the help of http://jjc.hydrus.net/cs61c/handouts/interrupts1.pdf
The MIPS memory • Actually, everything above 0x7fffffff is used by the system.
What is in there? • Special operating system functions • I/O registers mapped to memory addresses • …
SPIM Simulator • SPIM allows you to read from key board (which is similar to reading something from the true I/O register)
trykeyboard.asm .text .globl main main: addu $s7, $ra, $zero, # Save the ra addi $s0, $0, 113 #q addi $t0, $0, 0 lui $t0, 0xFFFF # $t0 = 0xFFFF0000; waitloop: lw $t1, 0($t0) andi $t1, $t1, 0x0001 # $t1 &= 0x00000001; beq $t1, $zero, waitloop lw $a0, 4($t0) beq $a0, $s0, done li $v0,1 syscall li $v0,4 la $a0, new_line syscall j waitloop done: jr $ra add $zero, $zero, $zero #nop add $zero, $zero, $zero #nop .data new_line: .asciiz " " Remember to call SPIM with -mapped_io option
question • Is this the most efficient way to do it? • Remember that the processor usually has a lot of things to do simultaneously
Interrupt • The key problem is that the time when the input occurs cannot be predicted by your program • Wouldn’t it be nice if you could “focus on what you are doing” while be “interrupted” if some inputs come?
MIPS Interrupt • $k0 and $k1 are both used as temporary variables in interrupt servicing routines. • Coprocessor 0 is also used with interrupts. In Coprocessor 0, registers $8, $12, $13, and $14 are all important in servicing interrupts. • These registers can be read and modified using the instructions mfc0 (move from coprocessor 0) and mtc0 (move to coprocessor 0).
EPC Register • The EPC register contains the value of the program counter, $pc, at the time of the interrupt. This is where the program will return after handling the interrupt.
.text • .globl main • main: • addu $s7, $ra, $zero, # Save the ra • mfc0 $t0, $12 • ori $t0, 0xff01 • mtc0 $t0, $12 • here: • j here • jr $ra • add $zero, $zero, $zero #nop • add $zero, $zero, $zero #nop • .text 0x80000080 • mfc0 $k0, $13 # $k0 = $Cause; • mfc0 $k1, $14 # $k1 = $EPC; • andi $k0, $k0, 0x003c # $k0 &= 0x003c; // Only keep Exception Code. • bne $k0, $zero, done # if ($k == 0) { // Exception Code 0 is I/O. • addi $t0, $0, 0 • lui $t0, 0xFFFF # $t0 = 0xFFFF0000; • lw $a0, 4($t0) • li $v0,1 • syscall • li $v0,4 • la $a0, new_line • syscall • done: • jr $k1 # return; • .data • new_line: • .asciiz " "