Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. MFC0 $k0, $13
  2. nop
  3. sll $k0, 26
  4. srl $k0, 28 #Setting bits 2-5 to the least significant bits
  5. beq $k0, $zero, ext_int #If bits are 0 it is an external interupt.
  6. nop
  7.  
  8. addiu $k1, $zero, 8
  9. bne $k0, $k1, kernel_loop #Making sure the exception was caused by a syscall
  10. nop
  11.  
  12. addiu $k0, $zero, 0x102
  13. bne $v0, $k0, return #Making sure we want to output
  14. nop
  15.  
  16. andi $k0, $k0, 0
  17. lui $k0, 0xffff
  18. sb $a0, 8($k0) #Outputting the character in a0
  19. b return
  20. nop
  21.  
  22.  
  23.  
  24. ext_int:MFC0 $k0, $13
  25. nop
  26. addiu $k1, $zero, 0x400 #Mask to check bit 10
  27. and $k1, $k1, $k0
  28. bne $k1, $zero, timer_int #If the bit is set it is a timer interupt
  29. nop
  30. b kernel_loop #Else kernel loop
  31. nop
  32.  
  33.  
  34.  
  35.  
  36. timer_int:
  37.  
  38. li $k0, 0xFFFF0010 #Clearing the timer interupt.
  39. li $k1, 0b101001
  40. sw $k1, 0($k0)
  41.  
  42. addiu $sp, $sp, -4
  43. sw $ra, 0($sp) #store return address on stack
  44. addiu $sp, $sp, -4
  45. sw $sp, 0($sp) #store frame pointer on stack
  46. move $fp, $sp #establish new frame pointer
  47. addiu $sp, $sp, -4
  48. sw $t0, 0($sp) #Storing the registers used by the processes on the stack.
  49. addiu $sp, $sp, -4
  50. sw $t5, 0($sp)
  51. addiu $sp, $sp, -4
  52. sw $a0, 0($sp)
  53.  
  54. li $k0, 0x80000000
  55. addiu $k0, $k0, curpcb
  56. lw $k1, 0($k0) #load address for current PCB
  57. mfc0 $k0, $14 #load program counter
  58. sw $gp, 4($k1) #store global pointer
  59. sw $sp, 8($k1) #store stack pointer
  60. sw $k0, 0($k1) #store program counter
  61. li $k0, 0x80000000
  62. addiu $k0, $k0, pcb3 #load address for pcb3
  63. bne $k1, $k0, increase #if current pcb is not pcb3, start popping
  64. nop
  65. lui $k1, 0x1
  66. sll $k1, 15
  67. addiu $k1, $k1, pcb1 #load address for pcb1
  68. b pop
  69. nop
  70.  
  71. increase:
  72. addiu $k1, $k1, 12 #go to next pcb
  73.  
  74. pop: li $k0, 0x80000000
  75. addiu $k0, $k0, curpcb #load curpcb address
  76. sw $k1, 0($k0) #store new current process in current process pcb
  77. lw $ra, 0($k1) #load program counter of next process
  78. lw $gp, 4($k1) #load global pointer of next process
  79. lw $sp, 8($k1) #load stack pointer of next process
  80. lw $a0, 0($sp) #load global pointer for reference
  81. addiu $sp, $sp, 4
  82. lw $t5, 0($sp) #Loading registers used by the proccesses
  83. addiu $sp, $sp, 4
  84. lw $t0, 0($sp)
  85. addiu $sp, $sp, 4
  86. lw $fp, 0($sp)
  87. addiu $sp, $sp, 4
  88.  
  89. jr $ra
  90. RFE
  91.  
  92.  
  93. return: MFC0 $k0, $14 #Loading the exception address
  94. nop
  95. addiu $k0, $k0, 4 #The next instruction
  96. jr $k0
  97. RFE
  98.  
  99. kernel_loop: b kernel_loop
  100. nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement