vector.s 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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, R8_RST_RESET
  58. xld.w %r5, DENONLY | IDMAONLY | RSTONLY
  59. ld.b [%r4], %r5
  60. xld.w %r8, __START_VectorTable
  61. ld.w %ttbr, %r8
  62. xld.w %r7, undefined_interrupt
  63. xld.w %r9, vector_count ; fill table
  64. xld.w %r10, undefined_interrupt_size
  65. initialise_loop:
  66. ld.w [%r8]+, %r7
  67. add %r7, %r10
  68. sub %r9, 1
  69. jrne initialise_loop
  70. ENABLE_INTERRUPTS
  71. ret ; exit
  72. ;;; get vector
  73. ;;; input:
  74. ;;; r6 = vector number
  75. ;;; output:
  76. ;;; r4 = vector address
  77. .global Vector_get
  78. Vector_get:
  79. sla %r6, 2
  80. xld.w %r8, __START_VectorTable
  81. add %r6, %r8
  82. ld.w %r4, [%r6]
  83. ret
  84. ;;; set vector
  85. ;;; input:
  86. ;;; r6 = vector number
  87. ;;; r7 = vector address
  88. ;;; output:
  89. ;;; r4 = previous vector address
  90. .global Vector_set
  91. Vector_set:
  92. sla %r6, 2
  93. xld.w %r8, __START_VectorTable
  94. add %r6, %r8
  95. ld.w %r4, [%r6]
  96. ld.w [%r6], %r7
  97. ret
  98. ;;; panic - dump the registers
  99. ;;; input:
  100. ;;; output:
  101. .global panic
  102. panic:
  103. pushn %r15
  104. ld.w %r0, %ahr
  105. ld.w %r1, %alr
  106. pushn %r1
  107. xcall Debug_PutCRLF
  108. xld.w %r6, message_panic
  109. xcall Debug_PutString
  110. xcall Debug_PutCRLF
  111. xld.w %r6, message_sp
  112. xcall Debug_PutString
  113. ld.w %r6, %sp
  114. xcall Debug_PutHex
  115. xcall Debug_PutCRLF
  116. ld.w %r0, %sp
  117. xld.w %r6, message_ahr
  118. xcall Debug_PutString
  119. ld.w %r6, [%r0]+
  120. xcall Debug_PutHex
  121. xcall Debug_PutCRLF
  122. xld.w %r6, message_alr
  123. xcall Debug_PutString
  124. ld.w %r6, [%r0]+
  125. xcall Debug_PutHex
  126. xcall Debug_PutCRLF
  127. xld.w %r6, message_r0
  128. xcall Debug_PutString
  129. ld.w %r6, [%r0]+
  130. xcall Debug_PutHex
  131. xcall Debug_PutSpace
  132. ld.w %r6, [%r0]+
  133. xcall Debug_PutHex
  134. xcall Debug_PutSpace
  135. ld.w %r6, [%r0]+
  136. xcall Debug_PutHex
  137. xcall Debug_PutSpace
  138. ld.w %r6, [%r0]+
  139. xcall Debug_PutHex
  140. xcall Debug_PutCRLF
  141. xld.w %r6, message_r4
  142. xcall Debug_PutString
  143. ld.w %r6, [%r0]+
  144. xcall Debug_PutHex
  145. xcall Debug_PutSpace
  146. ld.w %r6, [%r0]+
  147. xcall Debug_PutHex
  148. xcall Debug_PutSpace
  149. ld.w %r6, [%r0]+
  150. xcall Debug_PutHex
  151. xcall Debug_PutSpace
  152. ld.w %r6, [%r0]+
  153. xcall Debug_PutHex
  154. xcall Debug_PutCRLF
  155. xld.w %r6, message_r8
  156. xcall Debug_PutString
  157. ld.w %r6, [%r0]+
  158. xcall Debug_PutHex
  159. xcall Debug_PutSpace
  160. ld.w %r6, [%r0]+
  161. xcall Debug_PutHex
  162. xcall Debug_PutSpace
  163. ld.w %r6, [%r0]+
  164. xcall Debug_PutHex
  165. xcall Debug_PutSpace
  166. ld.w %r6, [%r0]+
  167. xcall Debug_PutHex
  168. xcall Debug_PutCRLF
  169. xld.w %r6, message_r12
  170. xcall Debug_PutString
  171. ld.w %r6, [%r0]+
  172. xcall Debug_PutHex
  173. xcall Debug_PutSpace
  174. ld.w %r6, [%r0]+
  175. xcall Debug_PutHex
  176. xcall Debug_PutSpace
  177. ld.w %r6, [%r0]+
  178. xcall Debug_PutHex
  179. xcall Debug_PutSpace
  180. ld.w %r6, [%r0]+
  181. xcall Debug_PutHex
  182. xcall Debug_PutCRLF
  183. ;;;
  184. ld.w %r6, [%r0]
  185. xld.w %r7, undefined_interrupt
  186. sub %r6, %r7
  187. xcall Debug_PutHex
  188. xcall Debug_PutSpace
  189. xld.w %r6, undefined_interrupt_size
  190. xcall Debug_PutHex
  191. xcall Debug_PutSpace
  192. ld.w %r6, [%r0]+
  193. xld.w %r7, undefined_interrupt
  194. sub %r6, %r7
  195. sra %r6, 3
  196. xcall Debug_PutHex
  197. xcall Debug_PutCRLF
  198. ;;;
  199. xld.w %r6, message_ps
  200. xcall Debug_PutString
  201. ld.w %r6, [%r0]+
  202. xcall Debug_PutHex
  203. xcall Debug_PutCRLF
  204. xld.w %r6, message_ip
  205. xcall Debug_PutString
  206. ld.w %r6, [%r0]+
  207. xcall Debug_PutHex
  208. xcall Debug_PutCRLF
  209. xld.w %r6, message_stack
  210. xcall Debug_PutString
  211. ld.w %r6, [%r0]+
  212. xcall Debug_PutHex
  213. xcall Debug_PutSpace
  214. ld.w %r6, [%r0]+
  215. xcall Debug_PutHex
  216. xcall Debug_PutSpace
  217. ld.w %r6, [%r0]+
  218. xcall Debug_PutHex
  219. xcall Debug_PutSpace
  220. ld.w %r6, [%r0]+
  221. xcall Debug_PutHex
  222. xcall Debug_PutCRLF
  223. stop: jp stop
  224. popn %r1
  225. ld.w %ahr, %r0
  226. ld.w %alr, %r1
  227. pushn %r1
  228. popn %r15
  229. ret
  230. message_panic:
  231. .asciz "Panic: Register Dump"
  232. message_sp:
  233. .asciz "sp: "
  234. message_ahr:
  235. .asciz "ahr: "
  236. message_alr:
  237. .asciz "alr: "
  238. message_r0:
  239. .asciz "r0: "
  240. message_r4:
  241. .asciz "r4: "
  242. message_r8:
  243. .asciz "r8: "
  244. message_r12:
  245. .asciz "r12: "
  246. message_ps:
  247. .asciz "ps: "
  248. message_ip:
  249. .asciz "ip: "
  250. message_stack:
  251. .asciz "[sp]: "
  252. .balign 4