debug.s 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. ;;; debug - simple debug print
  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 "c33regs.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. ;;; print a character
  40. ;;; (redirect to required serial driver)
  41. ;;; input:
  42. ;;; r6 = char
  43. ;;; output:
  44. .global Debug_PutChar
  45. Debug_PutChar:
  46. ; xjp Serial_PutChar
  47. xjp PolledSerial_PutChar
  48. ;;; print cr and lf
  49. ;;; input:
  50. ;;; output:
  51. .global Debug_PutCRLF
  52. Debug_PutCRLF:
  53. xld.w %r6, 0x0d
  54. xcall Debug_PutChar
  55. xld.w %r6, 0x0a
  56. xjp Debug_PutChar
  57. ;;; print a space
  58. ;;; input:
  59. ;;; output:
  60. .global Debug_PutSpace
  61. Debug_PutSpace:
  62. xld.w %r6, 0x20
  63. xjp Debug_PutChar
  64. ;;; print a string
  65. ;;; input:
  66. ;;; r6 = address of '\0' terminated string
  67. ;;; output:
  68. ;;; temporary:
  69. ;;; r9 = address during loop
  70. .global Debug_PutString
  71. Debug_PutString:
  72. ld.w %r9, %r6
  73. Debug_PutString_loop:
  74. ld.ub %r6, [%r9]+
  75. cmp %r6, 0
  76. jreq Debug_PutString_done
  77. cmp %r6, 10
  78. jreq Debug_PutString_crlf
  79. xcall Debug_PutChar
  80. jp Debug_PutString_loop
  81. Debug_PutString_crlf:
  82. xcall Debug_PutCRLF
  83. jp Debug_PutString_loop
  84. Debug_PutString_done:
  85. ret
  86. ;;; print a hex nibble
  87. ;;; input:
  88. ;;; r6 = 4 bit number to print
  89. ;;; output:
  90. .global Debug_PutNibble
  91. Debug_PutNibble:
  92. xand %r6, 0x0f
  93. xadd %r6, '0'
  94. xcmp %r6, '9'
  95. jrle Debug_PutNibble_l1
  96. xadd %r6, 'a' - '9' - 1
  97. Debug_PutNibble_l1:
  98. xcall Debug_PutChar
  99. ret
  100. ;;; print a hex word
  101. ;;; input:
  102. ;;; r6 = 32 bit number to print
  103. ;;; output:
  104. ;;; temporary:
  105. ;;; r9 = thet word being output
  106. .global Debug_PutHex
  107. Debug_PutHex:
  108. ld.w %r9, %r6
  109. xsrl %r6, 28
  110. xcall Debug_PutNibble
  111. ld.w %r6, %r9
  112. xsrl %r6, 24
  113. xcall Debug_PutNibble
  114. ld.w %r6, %r9
  115. xsrl %r6, 20
  116. xcall Debug_PutNibble
  117. ld.w %r6, %r9
  118. xsrl %r6, 16
  119. xcall Debug_PutNibble
  120. ld.w %r6, %r9
  121. xsrl %r6, 12
  122. xcall Debug_PutNibble
  123. ld.w %r6, %r9
  124. xsrl %r6, 8
  125. xcall Debug_PutNibble
  126. ld.w %r6, %r9
  127. xsrl %r6, 4
  128. xcall Debug_PutNibble
  129. ld.w %r6, %r9
  130. xcall Debug_PutNibble
  131. ret
  132. debug_8:
  133. pushn %r2
  134. ld.w %r1, %r7
  135. xcall Debug_PutString
  136. xcall Debug_PutSpace
  137. xld.w %r2, 8
  138. debug_8_loop:
  139. ld.w %r6, [%r1]+
  140. xcall Debug_PutHex
  141. xcall Debug_PutSpace
  142. xsub %r2, 1
  143. jrne debug_8_loop
  144. xcall Debug_PutCRLF
  145. popn %r2
  146. ret
  147. ;;; print a hex word
  148. ;;; input:
  149. ;;; output:
  150. ;;; temporary:
  151. .global xdebug
  152. xdebug:
  153. xcall Debug_PutCRLF
  154. xld.w %r6, debug_regs
  155. xcall Debug_PutString
  156. ld.w %r6, %r0
  157. xcall Debug_PutHex
  158. xcall Debug_PutSpace
  159. ld.w %r6, %r1
  160. xcall Debug_PutHex
  161. xcall Debug_PutSpace
  162. ld.w %r6, %r2
  163. xcall Debug_PutHex
  164. xcall Debug_PutSpace
  165. ld.w %r6, %r3
  166. xcall Debug_PutHex
  167. xcall Debug_PutSpace
  168. xcall Debug_PutSpace
  169. ld.w %r6, %sp
  170. xcall Debug_PutHex
  171. xcall Debug_PutCRLF
  172. xld.w %r6, debug_data
  173. ld.w %r7, %r1
  174. xcall debug_8
  175. xld.w %r6, debug_instr
  176. ld.w %r7, %r0
  177. xcall debug_8
  178. xld.w %r6, debug_return
  179. ld.w %r7, %sp
  180. xcall debug_8
  181. ret
  182. debug_regs:
  183. .asciz "r0..r3 sp: "
  184. debug_instr:
  185. .asciz "ip: "
  186. debug_data:
  187. .asciz "sp: "
  188. debug_return:
  189. .asciz "rp: "
  190. .balign 4