vector.s 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. ;;; vector.s
  2. ;;;
  3. ;;; Copyright (c) 2009 Openmoko Inc.
  4. ;;;
  5. ;;; Authors Christopher Hall <hsw@openmoko.com>
  6. ;;;
  7. ;;; Redistribution and use in source and binary forms, with or without
  8. ;;; modification, are permitted provided that the following conditions are
  9. ;;; met:
  10. ;;;
  11. ;;; 1. Redistributions of source code must retain the above copyright
  12. ;;; notice, this list of conditions and the following disclaimer.
  13. ;;;
  14. ;;; 2. Redistributions in binary form must reproduce the above copyright
  15. ;;; notice, this list of conditions and the following disclaimer in
  16. ;;; the documentation and/or other materials provided with the
  17. ;;; distribution.
  18. ;;;
  19. ;;; THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY
  20. ;;; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. ;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. ;;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  23. ;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. ;;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. ;;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  26. ;;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  28. ;;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  29. ;;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. .include "regs.inc"
  31. ;;; register usage
  32. ;;; r0 .. r3 must be preserved
  33. ;;; r4 result low
  34. ;;; r5 result high
  35. ;;; r6 .. r9 arguments 1..4
  36. ;;; r10 ..r14 reserved
  37. ;;; r15 __dp value
  38. .section .text
  39. ;;; undefined interrupt
  40. ;;; input:
  41. ;;; output:
  42. .global undefined_interrupt
  43. undefined_interrupt:
  44. xcall panic
  45. nop
  46. undefined_interrupt_size = . -undefined_interrupt
  47. .rept vector_count
  48. xcall panic
  49. nop
  50. .endr
  51. ;;; initialise vector table
  52. ;;; input:
  53. ;;; output:
  54. .global Vector_initialise
  55. Vector_initialise:
  56. DISABLE_INTERRUPTS
  57. xld.w %r4, R32_CMU_PROTECT
  58. xld.w %r5, CMU_PROTECT_OFF
  59. ld.w [%r4], %r5
  60. xld.w %r6, R32_CMU_OPT
  61. ld.w %r7, [%r6]
  62. or %r7, 1
  63. ld.w [%r6], %r7
  64. ld.w %r5, CMU_PROTECT_ON
  65. ld.w [%r4], %r5
  66. xld.w %r4, R8_RST_RESET
  67. xld.w %r5, DENONLY | IDMAONLY | RSTONLY
  68. ld.b [%r4], %r5
  69. xld.w %r8, __START_VectorTable
  70. ld.w %ttbr, %r8
  71. xld.w %r7, undefined_interrupt
  72. xld.w %r9, vector_count ; fill table
  73. xld.w %r10, undefined_interrupt_size
  74. initialise_loop:
  75. ld.w [%r8]+, %r7
  76. add %r7, %r10
  77. sub %r9, 1
  78. jrne initialise_loop
  79. ENABLE_INTERRUPTS
  80. ret ; exit
  81. ;;; get vector
  82. ;;; input:
  83. ;;; r6 = vector number
  84. ;;; output:
  85. ;;; r4 = vector address
  86. .global Vector_get
  87. Vector_get:
  88. sla %r6, 2
  89. xld.w %r8, __START_VectorTable
  90. add %r6, %r8
  91. ld.w %r4, [%r6]
  92. ret
  93. ;;; set vector
  94. ;;; input:
  95. ;;; r6 = vector number
  96. ;;; r7 = vector address
  97. ;;; output:
  98. ;;; r4 = previous vector address
  99. .global Vector_set
  100. Vector_set:
  101. sla %r6, 2
  102. xld.w %r8, __START_VectorTable
  103. add %r6, %r8
  104. ld.w %r4, [%r6]
  105. ld.w [%r6], %r7
  106. ret
  107. ;;; panic - dump the registers
  108. ;;; input:
  109. ;;; output:
  110. .global panic
  111. panic:
  112. pushn %r15
  113. ld.w %r0, %ahr
  114. ld.w %r1, %alr
  115. pushn %r1
  116. xcall Debug_PutCRLF
  117. xld.w %r6, message_panic
  118. xcall Debug_PutString
  119. xcall Debug_PutCRLF
  120. xld.w %r6, message_sp
  121. xcall Debug_PutString
  122. ld.w %r6, %sp
  123. xcall Debug_PutHex
  124. xcall Debug_PutCRLF
  125. ld.w %r0, %sp
  126. xld.w %r6, message_ahr
  127. xcall Debug_PutString
  128. ld.w %r6, [%r0]+
  129. xcall Debug_PutHex
  130. xcall Debug_PutCRLF
  131. xld.w %r6, message_alr
  132. xcall Debug_PutString
  133. ld.w %r6, [%r0]+
  134. xcall Debug_PutHex
  135. xcall Debug_PutCRLF
  136. xld.w %r6, message_r0
  137. xcall Debug_PutString
  138. ld.w %r6, [%r0]+
  139. xcall Debug_PutHex
  140. xcall Debug_PutSpace
  141. ld.w %r6, [%r0]+
  142. xcall Debug_PutHex
  143. xcall Debug_PutSpace
  144. ld.w %r6, [%r0]+
  145. xcall Debug_PutHex
  146. xcall Debug_PutSpace
  147. ld.w %r6, [%r0]+
  148. xcall Debug_PutHex
  149. xcall Debug_PutCRLF
  150. xld.w %r6, message_r4
  151. xcall Debug_PutString
  152. ld.w %r6, [%r0]+
  153. xcall Debug_PutHex
  154. xcall Debug_PutSpace
  155. ld.w %r6, [%r0]+
  156. xcall Debug_PutHex
  157. xcall Debug_PutSpace
  158. ld.w %r6, [%r0]+
  159. xcall Debug_PutHex
  160. xcall Debug_PutSpace
  161. ld.w %r6, [%r0]+
  162. xcall Debug_PutHex
  163. xcall Debug_PutCRLF
  164. xld.w %r6, message_r8
  165. xcall Debug_PutString
  166. ld.w %r6, [%r0]+
  167. xcall Debug_PutHex
  168. xcall Debug_PutSpace
  169. ld.w %r6, [%r0]+
  170. xcall Debug_PutHex
  171. xcall Debug_PutSpace
  172. ld.w %r6, [%r0]+
  173. xcall Debug_PutHex
  174. xcall Debug_PutSpace
  175. ld.w %r6, [%r0]+
  176. xcall Debug_PutHex
  177. xcall Debug_PutCRLF
  178. xld.w %r6, message_r12
  179. xcall Debug_PutString
  180. ld.w %r6, [%r0]+
  181. xcall Debug_PutHex
  182. xcall Debug_PutSpace
  183. ld.w %r6, [%r0]+
  184. xcall Debug_PutHex
  185. xcall Debug_PutSpace
  186. ld.w %r6, [%r0]+
  187. xcall Debug_PutHex
  188. xcall Debug_PutSpace
  189. ld.w %r6, [%r0]+
  190. xcall Debug_PutHex
  191. xcall Debug_PutCRLF
  192. ;;;
  193. ld.w %r6, [%r0]
  194. xld.w %r7, undefined_interrupt
  195. sub %r6, %r7
  196. xcall Debug_PutHex
  197. xcall Debug_PutSpace
  198. xld.w %r6, undefined_interrupt_size
  199. xcall Debug_PutHex
  200. xcall Debug_PutSpace
  201. ld.w %r6, [%r0]+
  202. xld.w %r7, undefined_interrupt
  203. sub %r6, %r7
  204. sra %r6, 3
  205. xcall Debug_PutHex
  206. xcall Debug_PutCRLF
  207. ;;;
  208. xld.w %r6, message_ps
  209. xcall Debug_PutString
  210. ld.w %r6, [%r0]+
  211. xcall Debug_PutHex
  212. xcall Debug_PutCRLF
  213. xld.w %r6, message_ip
  214. xcall Debug_PutString
  215. ld.w %r6, [%r0]+
  216. xcall Debug_PutHex
  217. xcall Debug_PutCRLF
  218. xld.w %r6, message_stack
  219. xcall Debug_PutString
  220. ld.w %r6, [%r0]+
  221. xcall Debug_PutHex
  222. xcall Debug_PutSpace
  223. ld.w %r6, [%r0]+
  224. xcall Debug_PutHex
  225. xcall Debug_PutSpace
  226. ld.w %r6, [%r0]+
  227. xcall Debug_PutHex
  228. xcall Debug_PutSpace
  229. ld.w %r6, [%r0]+
  230. xcall Debug_PutHex
  231. xcall Debug_PutCRLF
  232. stop: jp stop
  233. popn %r1
  234. ld.w %ahr, %r0
  235. ld.w %alr, %r1
  236. pushn %r1
  237. popn %r15
  238. ret
  239. message_panic:
  240. .asciz "Panic: Register Dump"
  241. message_sp:
  242. .asciz "sp: "
  243. message_ahr:
  244. .asciz "ahr: "
  245. message_alr:
  246. .asciz "alr: "
  247. message_r0:
  248. .asciz "r0: "
  249. message_r4:
  250. .asciz "r4: "
  251. message_r8:
  252. .asciz "r8: "
  253. message_r12:
  254. .asciz "r12: "
  255. message_ps:
  256. .asciz "ps: "
  257. message_ip:
  258. .asciz "ip: "
  259. message_stack:
  260. .asciz "[sp]: "
  261. .balign 4