Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. # First section: user data,
  2. # each process has its own "private" area.
  3.  
  4. .data
  5. glob1: .byte 'A'
  6. .space 999
  7. glob2: .byte '0'
  8. .space 999
  9. glob3: .byte 'a'
  10. .space 999
  11.  
  12. # Second section: user code.
  13. #
  14. # The first instructions initializes IO and Timer.
  15. # The last instruction in main are only used for start
  16. # up, they initialize the first process.
  17.  
  18. .text
  19. .set noreorder
  20. main:
  21. li $t0, 0xFFFF0010 # address to Timer registers:
  22. # +0: Timer control register
  23. # +4: Timer count register
  24. # +8: Timer compare register
  25.  
  26. li $t1, 0
  27. sw $t1, 4($t0) # reset counter register
  28.  
  29. li $t1, 63 # count from 0 to 63
  30. sw $t1, 8($t0) # compare register := 63
  31.  
  32. li $t1, 0b101001 # "101001": compare interrupt enable,
  33. # compare reset enable,
  34. # timer start
  35. sw $t1, 0($t0) # control register := "101001"
  36.  
  37. li $t0, 0xFFFF0000 # address to I/O registers:
  38. # +0: Input control register
  39.  
  40. li $t1, 0b10 # "10": interrupt enable
  41. sw $t1, 0($t0) # control register := "10"
  42.  
  43. li $t0, 0x0C03 # enable HW Interrupt 1 (input): bit 11
  44. # enable HW Interrupt 0 (timer): bit 10
  45. # set user mode: bit 1
  46. # enable interrupts: bit 0
  47.  
  48. mtc0 $t0, $12 # CP0 status := 0x0Cma03
  49.  
  50. la $gp, glob1 # dirty setup for process 1
  51.  
  52.  
  53.  
  54. proc1: # ++++++++++ first process +++++++++
  55.  
  56. # Description: proc1 reads the byte stored at 0($gp),
  57. # prints it, increments to the next character,
  58. # saving that back into 0($gp). After printing 'Z',
  59. # this process should then start over again with 'A', in
  60. # an endless loop. The symbol "glob1" may not be used.
  61.  
  62.  
  63. lb $t0, 0($gp) #Loads a byte
  64. nop
  65. ori $t1, $zero, 90 #Loads 90 into t0
  66. move $a0, $t0 #
  67.  
  68. lui $v0, 0x102
  69. nop
  70. syscall
  71. nop
  72. beq $t0, $t1, reset
  73. nop
  74.  
  75. add:
  76. addiu $t0, $t0, 1
  77. sb $t0, 0($gp)
  78.  
  79. j proc1
  80. nop
  81.  
  82. reset:
  83. addiu $t0, $t0, -25
  84. sb $t0, 0($gp)
  85. j proc1
  86. nop
  87.  
  88.  
  89. proc2: # ++++++++++ second process +++++++++
  90.  
  91. # Description: almost identical to the code of proc1 above,
  92. # only 2-3 lines should differ. Prints '0' through '9' in
  93. # an endless loop. The symbol "glob2" may not be used.
  94.  
  95.  
  96. lb $t0, 0($gp) #Loads a byte
  97. nop
  98. ori $t1, $zero, 57 #Loads 90 into t0
  99. move $a0, $t0 #
  100.  
  101. lui $v0, 0x102
  102. nop
  103. syscall
  104. nop
  105. beq $t0, $t1, reset2
  106. nop
  107.  
  108. add2:
  109. addiu $t0, $t0, 1
  110. sb $t0, 0($gp)
  111.  
  112. j proc2
  113. nop
  114.  
  115. reset2:
  116. addiu $t0, $t0, -9
  117. sb $t0, 0($gp)
  118. j proc2
  119. nop
  120.  
  121.  
  122.  
  123. proc3: # +++++++++ third process ++++++++++
  124.  
  125. # Description: almost identical to the code of proc1 above,
  126. # only 2-3 lines should differ. Prints 'a' through 'z' in
  127. # an endless loop. The symbol "glob3" may not be used.
  128.  
  129.  
  130. lb $t0, 0($gp) #Loads a byte
  131. nop
  132. ori $t1, $zero, 122 #Loads 90 into t0
  133. move $a0, $t0 #
  134.  
  135. lui $v0, 0x102
  136. nop
  137. syscall
  138. nop
  139. beq $t0, $t1, reset3
  140. nop
  141.  
  142. add3:
  143. addiu $t0, $t0, 1
  144. sb $t0, 0($gp)
  145.  
  146. j proc3
  147. nop
  148.  
  149. reset3:
  150. addiu $t0, $t0, -25
  151. sb $t0, 0($gp)
  152. j proc3
  153. nop
  154.  
  155.  
  156. # Third section: data structures for the kernel:
  157. # Process Control Block (PCB) consists of three words:
  158. # pcb: .word (next Program Counter for this process)
  159. # .word (contents of $gp for this process)
  160. # .word (contents of $sp for this process)
  161. # All other context is saved on the process' own stack
  162. # during exception handling and SYSCALL.
  163.  
  164. .section .kdata
  165. curpcb: .word pcb1
  166. pcb1: .word 0, 0, 0
  167. pcb2: .word proc2, glob2, 0x7fffbf94
  168. pcb3: .word proc3, glob3, 0x7fff7f94
  169.  
  170. # Fourth section: kernel code.
  171.  
  172. .section .ktext , "xa"
  173. .set noreorder
  174.  
  175. kernel_loop:
  176.  
  177. mfc0 $t2, $13
  178. nop
  179. ori $t5, $zero, 8
  180. sll $t2, $t2, 26
  181. srl $t2, $t2, 28
  182.  
  183.  
  184. beq $t2, $t5, check
  185. nop
  186. beq $zero, $t2, exc
  187. nop
  188. b kernel_loop
  189. nop
  190. check:
  191. lui $t3, 0x102
  192. nop
  193. beq $v0, $t3, back
  194. nop
  195. rfe
  196. nop
  197.  
  198. back:
  199. lui $t4, 0xFFFF
  200. sb $a0, 8($t4)
  201. nop
  202. nop
  203. mfc0 $k0, $14
  204. nop
  205.  
  206. addiu $k0, $k0, 4
  207. jr $k0
  208. rfe
  209.  
  210. exc:
  211. ori $t3, $zero, 1
  212. mfc0 $t2, $13
  213. sll $t2, $t2, 20
  214. srl $t2, $t2, 31
  215.  
  216. beq $t2, $t3, timerint
  217.  
  218. nop
  219. b kernel_loop
  220. nop
  221.  
  222.  
  223. timerint:
  224. #loads in the current stack pointer
  225. la $s0, curpcb
  226. nop
  227.  
  228. ignore:
  229. mfc0 $k1, $14
  230. nop
  231. move $ra, $k1
  232. sw $k1, 0($s0)
  233. sw $gp, 4($s0)
  234.  
  235. addiu $sp, $sp, -4
  236. sw $ra, 0($sp)
  237. addiu $sp, $sp, -4
  238. sw $fp, 0($sp)
  239. move $fp, $sp
  240. addiu $sp, $sp, -100
  241. sw $gp, -4($fp)
  242. sw $s0, -8($fp)
  243.  
  244. sw $s1, -12($fp)
  245. sw $s2, -16($fp)
  246. sw $s3, -20($fp)
  247. sw $s4, -24($fp)
  248. sw $s5, -28($fp)
  249. sw $s6, -32($fp)
  250. sw $s7, -36($fp)
  251.  
  252. sw $t0, -40($fp)
  253. sw $t1, -44($fp)
  254. sw $t2, -48($fp)
  255. sw $t3, -52($fp)
  256. sw $t4, -56($fp)
  257. sw $t5, -60($fp)
  258. sw $t6, -64($fp)
  259. sw $t7, -68($fp)
  260. sw $t8, -72($fp)
  261. sw $t9, -76($fp)
  262.  
  263. sw $a0, -80($fp)
  264. sw $a1, -84($fp)
  265. sw $a2, -88($fp)
  266. sw $a3, -92($fp)
  267.  
  268. sw $v0, -96($fp)
  269. sw $v1, -100($fp)
  270.  
  271. .set noat
  272. sw $at, -104($fp) # FIX
  273. .set at
  274.  
  275. la $s2, pcb2
  276. la $s4, pcb3
  277.  
  278. beq $s0, $s2, pcb2_3
  279. nop
  280. beq $s0, $s4, pcb3_1
  281. nop
  282. b pcb1_2
  283. nop
  284.  
  285. pcb3_1:
  286. la $s3, pcb1
  287. move $s0, $s3
  288. lw $gp, 4($s0)
  289. nop
  290. b load
  291. nop
  292.  
  293. pcb1_2:
  294. la $s3, pcb2
  295. move $s0, $s3
  296. lw $gp, 4($s0)
  297. nop
  298. b load
  299. nop
  300.  
  301. pcb2_3:
  302. la $s3, pcb3
  303. move $s0, $s3
  304. lw $gp, 4($s0)
  305. nop
  306. load:
  307.  
  308. # Clear Timer Interrupt
  309. li $k0, 0xFFFF0010
  310. li $k1, 0b101001
  311. sw $k1, 0($k0)
  312.  
  313. #---------------------
  314. lw $sp, 8($s0)
  315. lw $ra, 0($s0)
  316.  
  317. move $fp, $sp
  318. addiu $fp, $fp, -8
  319.  
  320. sw $gp, 4($fp)
  321. sw $s0, -4($fp)
  322.  
  323. lw $gp, 4($fp)
  324. nop
  325. lw $s0, -4($fp)
  326. nop
  327.  
  328. lw $s1, -8($fp)
  329. nop
  330. lw $s2, -12($fp)
  331. nop
  332. lw $s3, -16($fp)
  333. nop
  334. lw $s4, -20($fp)
  335. nop
  336. lw $s5, -24($fp)
  337. nop
  338. lw $s6, -28($fp)
  339. nop
  340. lw $s7, -32($fp)
  341. nop
  342.  
  343. lw $t0, -36($fp)
  344. nop
  345. lw $t1, -40($fp)
  346. nop
  347. lw $t2, -44($fp)
  348. nop
  349. lw $t3, -48($fp)
  350. nop
  351. lw $t4, -52($fp)
  352. nop
  353. lw $t5, -56($fp)
  354. nop
  355. lw $t6, -60($fp)
  356. nop
  357. lw $t7, -64($fp)
  358. nop
  359. lw $t8, -68($fp)
  360. nop
  361. lw $t9, -72($fp)
  362. nop
  363.  
  364. lw $a0, -76($fp)
  365. nop
  366. lw $a1, -80($fp)
  367. nop
  368. lw $a2, -84($fp)
  369. nop
  370. lw $a3, -88($fp)
  371. nop
  372.  
  373. lw $v0, -92($fp)
  374. nop
  375. lw $v1, -96($fp)
  376. nop
  377.  
  378. .set noat
  379. lw $at, -104($fp) # FIX
  380. nop
  381. .set at
  382.  
  383. jr $ra
  384. rfe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement