genex.S 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 2000, 2001, 2003 Ralf Baechle
  7. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  8. * Copyright (C) 2001 MIPS Technologies, Inc.
  9. * Copyright (C) 2002 Maciej W. Rozycki
  10. */
  11. #include <linux/config.h>
  12. #include <linux/init.h>
  13. #include <asm/asm.h>
  14. #include <asm/cacheops.h>
  15. #include <asm/regdef.h>
  16. #include <asm/fpregdef.h>
  17. #include <asm/mipsregs.h>
  18. #include <asm/stackframe.h>
  19. #include <asm/war.h>
  20. #define PANIC_PIC(msg) \
  21. .set push; \
  22. .set reorder; \
  23. PTR_LA a0,8f; \
  24. .set noat; \
  25. PTR_LA AT, panic; \
  26. jr AT; \
  27. 9: b 9b; \
  28. .set pop; \
  29. TEXT(msg)
  30. __INIT
  31. NESTED(except_vec0_generic, 0, sp)
  32. PANIC_PIC("Exception vector 0 called")
  33. END(except_vec0_generic)
  34. NESTED(except_vec1_generic, 0, sp)
  35. PANIC_PIC("Exception vector 1 called")
  36. END(except_vec1_generic)
  37. /*
  38. * General exception vector for all other CPUs.
  39. *
  40. * Be careful when changing this, it has to be at most 128 bytes
  41. * to fit into space reserved for the exception handler.
  42. */
  43. NESTED(except_vec3_generic, 0, sp)
  44. .set push
  45. .set noat
  46. #if R5432_CP0_INTERRUPT_WAR
  47. mfc0 k0, CP0_INDEX
  48. #endif
  49. mfc0 k1, CP0_CAUSE
  50. andi k1, k1, 0x7c
  51. #ifdef CONFIG_64BIT
  52. dsll k1, k1, 1
  53. #endif
  54. PTR_L k0, exception_handlers(k1)
  55. jr k0
  56. .set pop
  57. END(except_vec3_generic)
  58. /*
  59. * General exception handler for CPUs with virtual coherency exception.
  60. *
  61. * Be careful when changing this, it has to be at most 256 (as a special
  62. * exception) bytes to fit into space reserved for the exception handler.
  63. */
  64. NESTED(except_vec3_r4000, 0, sp)
  65. .set push
  66. .set mips3
  67. .set noat
  68. mfc0 k1, CP0_CAUSE
  69. li k0, 31<<2
  70. andi k1, k1, 0x7c
  71. .set push
  72. .set noreorder
  73. .set nomacro
  74. beq k1, k0, handle_vced
  75. li k0, 14<<2
  76. beq k1, k0, handle_vcei
  77. #ifdef CONFIG_64BIT
  78. dsll k1, k1, 1
  79. #endif
  80. .set pop
  81. PTR_L k0, exception_handlers(k1)
  82. jr k0
  83. /*
  84. * Big shit, we now may have two dirty primary cache lines for the same
  85. * physical address. We can safely invalidate the line pointed to by
  86. * c0_badvaddr because after return from this exception handler the
  87. * load / store will be re-executed.
  88. */
  89. handle_vced:
  90. MFC0 k0, CP0_BADVADDR
  91. li k1, -4 # Is this ...
  92. and k0, k1 # ... really needed?
  93. mtc0 zero, CP0_TAGLO
  94. cache Index_Store_Tag_D, (k0)
  95. cache Hit_Writeback_Inv_SD, (k0)
  96. #ifdef CONFIG_PROC_FS
  97. PTR_LA k0, vced_count
  98. lw k1, (k0)
  99. addiu k1, 1
  100. sw k1, (k0)
  101. #endif
  102. eret
  103. handle_vcei:
  104. MFC0 k0, CP0_BADVADDR
  105. cache Hit_Writeback_Inv_SD, (k0) # also cleans pi
  106. #ifdef CONFIG_PROC_FS
  107. PTR_LA k0, vcei_count
  108. lw k1, (k0)
  109. addiu k1, 1
  110. sw k1, (k0)
  111. #endif
  112. eret
  113. .set pop
  114. END(except_vec3_r4000)
  115. /*
  116. * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
  117. * This is a dedicated interrupt exception vector which reduces the
  118. * interrupt processing overhead. The jump instruction will be replaced
  119. * at the initialization time.
  120. *
  121. * Be careful when changing this, it has to be at most 128 bytes
  122. * to fit into space reserved for the exception handler.
  123. */
  124. NESTED(except_vec4, 0, sp)
  125. 1: j 1b /* Dummy, will be replaced */
  126. END(except_vec4)
  127. /*
  128. * EJTAG debug exception handler.
  129. * The EJTAG debug exception entry point is 0xbfc00480, which
  130. * normally is in the boot PROM, so the boot PROM must do a
  131. * unconditional jump to this vector.
  132. */
  133. NESTED(except_vec_ejtag_debug, 0, sp)
  134. j ejtag_debug_handler
  135. END(except_vec_ejtag_debug)
  136. __FINIT
  137. /*
  138. * Vectored interrupt handler.
  139. * This prototype is copied to ebase + n*IntCtl.VS and patched
  140. * to invoke the handler
  141. */
  142. NESTED(except_vec_vi, 0, sp)
  143. SAVE_SOME
  144. SAVE_AT
  145. .set push
  146. .set noreorder
  147. EXPORT(except_vec_vi_lui)
  148. lui v0, 0 /* Patched */
  149. j except_vec_vi_handler
  150. EXPORT(except_vec_vi_ori)
  151. ori v0, 0 /* Patched */
  152. .set pop
  153. END(except_vec_vi)
  154. EXPORT(except_vec_vi_end)
  155. /*
  156. * Common Vectored Interrupt code
  157. * Complete the register saves and invoke the handler which is passed in $v0
  158. */
  159. NESTED(except_vec_vi_handler, 0, sp)
  160. SAVE_TEMP
  161. SAVE_STATIC
  162. CLI
  163. move a0, sp
  164. jalr v0
  165. j ret_from_irq
  166. END(except_vec_vi_handler)
  167. /*
  168. * EJTAG debug exception handler.
  169. */
  170. NESTED(ejtag_debug_handler, PT_SIZE, sp)
  171. .set push
  172. .set noat
  173. MTC0 k0, CP0_DESAVE
  174. mfc0 k0, CP0_DEBUG
  175. sll k0, k0, 30 # Check for SDBBP.
  176. bgez k0, ejtag_return
  177. PTR_LA k0, ejtag_debug_buffer
  178. LONG_S k1, 0(k0)
  179. SAVE_ALL
  180. move a0, sp
  181. jal ejtag_exception_handler
  182. RESTORE_ALL
  183. PTR_LA k0, ejtag_debug_buffer
  184. LONG_L k1, 0(k0)
  185. ejtag_return:
  186. MFC0 k0, CP0_DESAVE
  187. .set mips32
  188. deret
  189. .set pop
  190. END(ejtag_debug_handler)
  191. /*
  192. * This buffer is reserved for the use of the EJTAG debug
  193. * handler.
  194. */
  195. .data
  196. EXPORT(ejtag_debug_buffer)
  197. .fill LONGSIZE
  198. .previous
  199. __INIT
  200. /*
  201. * NMI debug exception handler for MIPS reference boards.
  202. * The NMI debug exception entry point is 0xbfc00000, which
  203. * normally is in the boot PROM, so the boot PROM must do a
  204. * unconditional jump to this vector.
  205. */
  206. NESTED(except_vec_nmi, 0, sp)
  207. j nmi_handler
  208. END(except_vec_nmi)
  209. __FINIT
  210. NESTED(nmi_handler, PT_SIZE, sp)
  211. .set push
  212. .set noat
  213. .set mips3
  214. SAVE_ALL
  215. move a0, sp
  216. jal nmi_exception_handler
  217. RESTORE_ALL
  218. eret
  219. .set pop
  220. END(nmi_handler)
  221. .macro __build_clear_none
  222. .endm
  223. .macro __build_clear_sti
  224. STI
  225. .endm
  226. .macro __build_clear_cli
  227. CLI
  228. .endm
  229. .macro __build_clear_fpe
  230. cfc1 a1, fcr31
  231. li a2, ~(0x3f << 12)
  232. and a2, a1
  233. ctc1 a2, fcr31
  234. STI
  235. .endm
  236. .macro __build_clear_ade
  237. MFC0 t0, CP0_BADVADDR
  238. PTR_S t0, PT_BVADDR(sp)
  239. KMODE
  240. .endm
  241. .macro __BUILD_silent exception
  242. .endm
  243. /* Gas tries to parse the PRINT argument as a string containing
  244. string escapes and emits bogus warnings if it believes to
  245. recognize an unknown escape code. So make the arguments
  246. start with an n and gas will believe \n is ok ... */
  247. .macro __BUILD_verbose nexception
  248. LONG_L a1, PT_EPC(sp)
  249. #ifdef CONFIG_32BIT
  250. PRINT("Got \nexception at %08lx\012")
  251. #endif
  252. #ifdef CONFIG_64BIT
  253. PRINT("Got \nexception at %016lx\012")
  254. #endif
  255. .endm
  256. .macro __BUILD_count exception
  257. LONG_L t0,exception_count_\exception
  258. LONG_ADDIU t0, 1
  259. LONG_S t0,exception_count_\exception
  260. .comm exception_count\exception, 8, 8
  261. .endm
  262. .macro __BUILD_HANDLER exception handler clear verbose ext
  263. .align 5
  264. NESTED(handle_\exception, PT_SIZE, sp)
  265. .set noat
  266. SAVE_ALL
  267. FEXPORT(handle_\exception\ext)
  268. __BUILD_clear_\clear
  269. .set at
  270. __BUILD_\verbose \exception
  271. move a0, sp
  272. jal do_\handler
  273. j ret_from_exception
  274. END(handle_\exception)
  275. .endm
  276. .macro BUILD_HANDLER exception handler clear verbose
  277. __BUILD_HANDLER \exception \handler \clear \verbose _int
  278. .endm
  279. BUILD_HANDLER adel ade ade silent /* #4 */
  280. BUILD_HANDLER ades ade ade silent /* #5 */
  281. BUILD_HANDLER ibe be cli silent /* #6 */
  282. BUILD_HANDLER dbe be cli silent /* #7 */
  283. BUILD_HANDLER bp bp sti silent /* #9 */
  284. BUILD_HANDLER ri ri sti silent /* #10 */
  285. BUILD_HANDLER cpu cpu sti silent /* #11 */
  286. BUILD_HANDLER ov ov sti silent /* #12 */
  287. BUILD_HANDLER tr tr sti silent /* #13 */
  288. BUILD_HANDLER fpe fpe fpe silent /* #15 */
  289. BUILD_HANDLER mdmx mdmx sti silent /* #22 */
  290. BUILD_HANDLER watch watch sti verbose /* #23 */
  291. BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
  292. BUILD_HANDLER mt mt sti verbose /* #25 */
  293. BUILD_HANDLER dsp dsp sti silent /* #26 */
  294. BUILD_HANDLER reserved reserved sti verbose /* others */
  295. #ifdef CONFIG_64BIT
  296. /* A temporary overflow handler used by check_daddi(). */
  297. __INIT
  298. BUILD_HANDLER daddi_ov daddi_ov none silent /* #12 */
  299. #endif