Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #mecall test script
  2.  
  3. .text
  4. .globl main
  5.  
  6. #You will update the relevant CSR registers to use your mecall subroutines when ecall is executed
  7. #Program will try to (transfer control to a7? )unless ustatus ready bit is set to 1 (csrrsi zero, 0, 1)
  8. #set vec table, enable interrupts to execute
  9.  
  10. main:
  11. li tp, 1 #set tp
  12. li t0, 0xfffffffc
  13. csrw t0, 64
  14. li t0, 0
  15.  
  16. la t0, handler
  17. csrrw zero, 5, t0 # set utvec (5) to the handlers address #@ destination is 0, only changes source (t0) to csr# (5)
  18. csrrsi zero, 0, 1 # set interrupt enable bit in ustatus (0) #@ global interrupt enable, step 5?
  19. #set bit 0 to 1, of register 0
  20.  
  21.  
  22. #INSTRUCTION_ADDR_MISALIGNED #0
  23. #jump to an invalid address (like zero)
  24. #try to load instruction at PC=0
  25. li t1, 3
  26. jalr t1
  27.  
  28. #INSTRUCTION_ACCESS_FAULT #1
  29. jalr zero
  30.  
  31. #LOAD_ADDRESS_MISALIGNED #4
  32. #ebreak
  33. li t1, 3
  34. lw t0, (t1)
  35. #INSTR is stored in EPC but i lose it when printstr branches to teardown and overwrites it
  36.  
  37. #LOAD_ACCESS_FAULT #5
  38. ebreak
  39. csrrsi zero, 0, 1 #WHY DO I NEED TO RESET USTATUS? what causes ustatus to be reset?
  40. la t1, main
  41. lw t0, 0(t1)
  42.  
  43. #STORE_ADDRESS_MISALIGNED #6
  44. csrrsi zero, 0, 1
  45. li t1, 3
  46. sw t0, 2(t1)
  47.  
  48. #STORE_ACCESS_FAULT #7
  49. csrrsi zero, 0, 1
  50. la t1, main
  51. sw t0, 0(t1)
  52.  
  53.  
  54. #PART 1
  55.  
  56. #get printstring working first to help with other routines
  57. #PrintString, #4
  58. la t0, mecall
  59. csrrw zero, 5, t0 # set utvec (5) to the handlers address
  60. csrrsi zero, 0, 1 # set interrupt enable bit in ustatus (0)
  61. li a6, 4
  62. la a0, startmsg
  63. ecall
  64.  
  65. ebreak
  66. jal PrintChar
  67. jal ReadChar
  68. jal ReadString
  69. #b done # once printstring works, move this line down by one.
  70.  
  71. done:
  72. #Exit, #10
  73. li a6, 10
  74. #ecall # remove this line to test mecall
  75. ecall
  76. li a7, 10
  77. ecall #Use normal ecall to exit
  78.  
  79. .data
  80. startmsg: .string "\nstarting mecall test"
  81. promptstr: .string "\nType a string and press enter: "
  82. promptint1: .string "\nType a single digit number and press enter: "
  83. promptint2: .string "\nType '49' and press enter: "
  84. promptchar: .string "\nenter a char: "
  85. response: .string "\nYou entered: "
  86. printcharmsg: .string "\nLets print the letter 'a' : "
  87. respint: .word 0
  88. respchar: .byte '\0'
  89. respstr: .space 20
  90.  
  91.  
  92. .text
  93.  
  94.  
  95. ReadString: #8
  96. #I CHANGED ALL USES OF A7 TO A6
  97. addi sp, sp, -16
  98. sw ra, 12(sp)
  99. li a6, 4
  100. la a0, promptstr #This gets printed before we type a string. Need to loop until we reach enter key before doing this
  101. ecall
  102. li a6, 8
  103. la a0, respstr #Load a0 with 20 byte buffer (max len of str). This is where we store string
  104. ecall
  105. li a6, 4
  106. la a0, response
  107. ecall
  108. li a6, 4 #Call printstr
  109. la a0, respstr #Print respstr
  110. ecall
  111. lw ra, 12(sp)
  112. addi sp, sp, 16
  113. ret
  114.  
  115. PrintChar: #11
  116. addi sp, sp -16
  117. sw ra, 12(sp)
  118. li a6, 4
  119. la a0, printcharmsg
  120. ebreak
  121. ecall
  122. li a6, 11
  123. andi t0, t0, 0
  124. addi a0, t0, 0x61 #hex 61 is letter a.
  125. ecall
  126. lw ra, 12(sp)
  127. addi sp, sp, 16
  128. ret
  129.  
  130. ReadChar: #12
  131. addi sp, sp, -16
  132. sw ra, 12(sp)
  133. li a6, 4
  134. la a0, promptchar
  135. ecall
  136. li a6, 12
  137. ecall
  138. addi t0, a0, 0
  139. li a6, 4
  140. la a0, response
  141. ecall
  142. li a6, 11
  143. addi a0, t0, 0
  144. ebreak
  145. ecall
  146. lw ra, 12(sp)
  147. addi sp, sp, 16
  148. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement