Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MFC0 $k0, $13
- nop
- sll $k0, 26
- srl $k0, 28 #Setting bits 2-5 to the least significant bits
- beq $k0, $zero, ext_int #If bits are 0 it is an external interupt.
- nop
- addiu $k1, $zero, 8
- bne $k0, $k1, kernel_loop #Making sure the exception was caused by a syscall
- nop
- addiu $k0, $zero, 0x102
- bne $v0, $k0, return #Making sure we want to output
- nop
- andi $k0, $k0, 0
- lui $k0, 0xffff
- sb $a0, 8($k0) #Outputting the character in a0
- b return
- nop
- ext_int:MFC0 $k0, $13
- nop
- addiu $k1, $zero, 0x400 #Mask to check bit 10
- and $k1, $k1, $k0
- bne $k1, $zero, timer_int #If the bit is set it is a timer interupt
- nop
- b kernel_loop #Else kernel loop
- nop
- timer_int:
- li $k0, 0xFFFF0010 #Clearing the timer interupt.
- li $k1, 0b101001
- sw $k1, 0($k0)
- addiu $sp, $sp, -4
- sw $ra, 0($sp) #store return address on stack
- addiu $sp, $sp, -4
- sw $sp, 0($sp) #store frame pointer on stack
- move $fp, $sp #establish new frame pointer
- addiu $sp, $sp, -4
- sw $t0, 0($sp) #Storing the registers used by the processes on the stack.
- addiu $sp, $sp, -4
- sw $t5, 0($sp)
- addiu $sp, $sp, -4
- sw $a0, 0($sp)
- li $k0, 0x80000000
- addiu $k0, $k0, curpcb
- lw $k1, 0($k0) #load address for current PCB
- mfc0 $k0, $14 #load program counter
- sw $gp, 4($k1) #store global pointer
- sw $sp, 8($k1) #store stack pointer
- sw $k0, 0($k1) #store program counter
- li $k0, 0x80000000
- addiu $k0, $k0, pcb3 #load address for pcb3
- bne $k1, $k0, increase #if current pcb is not pcb3, start popping
- nop
- lui $k1, 0x1
- sll $k1, 15
- addiu $k1, $k1, pcb1 #load address for pcb1
- b pop
- nop
- increase:
- addiu $k1, $k1, 12 #go to next pcb
- pop: li $k0, 0x80000000
- addiu $k0, $k0, curpcb #load curpcb address
- sw $k1, 0($k0) #store new current process in current process pcb
- lw $ra, 0($k1) #load program counter of next process
- lw $gp, 4($k1) #load global pointer of next process
- lw $sp, 8($k1) #load stack pointer of next process
- lw $a0, 0($sp) #load global pointer for reference
- addiu $sp, $sp, 4
- lw $t5, 0($sp) #Loading registers used by the proccesses
- addiu $sp, $sp, 4
- lw $t0, 0($sp)
- addiu $sp, $sp, 4
- lw $fp, 0($sp)
- addiu $sp, $sp, 4
- jr $ra
- RFE
- return: MFC0 $k0, $14 #Loading the exception address
- nop
- addiu $k0, $k0, 4 #The next instruction
- jr $k0
- RFE
- kernel_loop: b kernel_loop
- nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement