genex.S 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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/init.h>
  12. #include <asm/asm.h>
  13. #include <asm/asmmacro.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. __FINIT
  116. .align 5
  117. NESTED(handle_int, PT_SIZE, sp)
  118. SAVE_ALL
  119. CLI
  120. PTR_LA ra, ret_from_irq
  121. move a0, sp
  122. j plat_irq_dispatch
  123. END(handle_int)
  124. __INIT
  125. /*
  126. * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
  127. * This is a dedicated interrupt exception vector which reduces the
  128. * interrupt processing overhead. The jump instruction will be replaced
  129. * at the initialization time.
  130. *
  131. * Be careful when changing this, it has to be at most 128 bytes
  132. * to fit into space reserved for the exception handler.
  133. */
  134. NESTED(except_vec4, 0, sp)
  135. 1: j 1b /* Dummy, will be replaced */
  136. END(except_vec4)
  137. /*
  138. * EJTAG debug exception handler.
  139. * The EJTAG debug exception entry point is 0xbfc00480, which
  140. * normally is in the boot PROM, so the boot PROM must do a
  141. * unconditional jump to this vector.
  142. */
  143. NESTED(except_vec_ejtag_debug, 0, sp)
  144. j ejtag_debug_handler
  145. END(except_vec_ejtag_debug)
  146. __FINIT
  147. /*
  148. * Vectored interrupt handler.
  149. * This prototype is copied to ebase + n*IntCtl.VS and patched
  150. * to invoke the handler
  151. */
  152. NESTED(except_vec_vi, 0, sp)
  153. SAVE_SOME
  154. SAVE_AT
  155. .set push
  156. .set noreorder
  157. #ifdef CONFIG_MIPS_MT_SMTC
  158. /*
  159. * To keep from blindly blocking *all* interrupts
  160. * during service by SMTC kernel, we also want to
  161. * pass the IM value to be cleared.
  162. */
  163. EXPORT(except_vec_vi_mori)
  164. ori a0, $0, 0
  165. #endif /* CONFIG_MIPS_MT_SMTC */
  166. EXPORT(except_vec_vi_lui)
  167. lui v0, 0 /* Patched */
  168. j except_vec_vi_handler
  169. EXPORT(except_vec_vi_ori)
  170. ori v0, 0 /* Patched */
  171. .set pop
  172. END(except_vec_vi)
  173. EXPORT(except_vec_vi_end)
  174. /*
  175. * Common Vectored Interrupt code
  176. * Complete the register saves and invoke the handler which is passed in $v0
  177. */
  178. NESTED(except_vec_vi_handler, 0, sp)
  179. SAVE_TEMP
  180. SAVE_STATIC
  181. #ifdef CONFIG_MIPS_MT_SMTC
  182. /*
  183. * SMTC has an interesting problem that interrupts are level-triggered,
  184. * and the CLI macro will clear EXL, potentially causing a duplicate
  185. * interrupt service invocation. So we need to clear the associated
  186. * IM bit of Status prior to doing CLI, and restore it after the
  187. * service routine has been invoked - we must assume that the
  188. * service routine will have cleared the state, and any active
  189. * level represents a new or otherwised unserviced event...
  190. */
  191. mfc0 t1, CP0_STATUS
  192. and t0, a0, t1
  193. mfc0 t2, CP0_TCCONTEXT
  194. or t0, t0, t2
  195. mtc0 t0, CP0_TCCONTEXT
  196. xor t1, t1, t0
  197. mtc0 t1, CP0_STATUS
  198. _ehb
  199. #endif /* CONFIG_MIPS_MT_SMTC */
  200. CLI
  201. move a0, sp
  202. jalr v0
  203. j ret_from_irq
  204. END(except_vec_vi_handler)
  205. /*
  206. * EJTAG debug exception handler.
  207. */
  208. NESTED(ejtag_debug_handler, PT_SIZE, sp)
  209. .set push
  210. .set noat
  211. MTC0 k0, CP0_DESAVE
  212. mfc0 k0, CP0_DEBUG
  213. sll k0, k0, 30 # Check for SDBBP.
  214. bgez k0, ejtag_return
  215. PTR_LA k0, ejtag_debug_buffer
  216. LONG_S k1, 0(k0)
  217. SAVE_ALL
  218. move a0, sp
  219. jal ejtag_exception_handler
  220. RESTORE_ALL
  221. PTR_LA k0, ejtag_debug_buffer
  222. LONG_L k1, 0(k0)
  223. ejtag_return:
  224. MFC0 k0, CP0_DESAVE
  225. .set mips32
  226. deret
  227. .set pop
  228. END(ejtag_debug_handler)
  229. /*
  230. * This buffer is reserved for the use of the EJTAG debug
  231. * handler.
  232. */
  233. .data
  234. EXPORT(ejtag_debug_buffer)
  235. .fill LONGSIZE
  236. .previous
  237. __INIT
  238. /*
  239. * NMI debug exception handler for MIPS reference boards.
  240. * The NMI debug exception entry point is 0xbfc00000, which
  241. * normally is in the boot PROM, so the boot PROM must do a
  242. * unconditional jump to this vector.
  243. */
  244. NESTED(except_vec_nmi, 0, sp)
  245. j nmi_handler
  246. END(except_vec_nmi)
  247. __FINIT
  248. NESTED(nmi_handler, PT_SIZE, sp)
  249. .set push
  250. .set noat
  251. SAVE_ALL
  252. move a0, sp
  253. jal nmi_exception_handler
  254. RESTORE_ALL
  255. .set mips3
  256. eret
  257. .set pop
  258. END(nmi_handler)
  259. .macro __build_clear_none
  260. .endm
  261. .macro __build_clear_sti
  262. STI
  263. .endm
  264. .macro __build_clear_cli
  265. CLI
  266. .endm
  267. .macro __build_clear_fpe
  268. cfc1 a1, fcr31
  269. li a2, ~(0x3f << 12)
  270. and a2, a1
  271. ctc1 a2, fcr31
  272. STI
  273. .endm
  274. .macro __build_clear_ade
  275. MFC0 t0, CP0_BADVADDR
  276. PTR_S t0, PT_BVADDR(sp)
  277. KMODE
  278. .endm
  279. .macro __BUILD_silent exception
  280. .endm
  281. /* Gas tries to parse the PRINT argument as a string containing
  282. string escapes and emits bogus warnings if it believes to
  283. recognize an unknown escape code. So make the arguments
  284. start with an n and gas will believe \n is ok ... */
  285. .macro __BUILD_verbose nexception
  286. LONG_L a1, PT_EPC(sp)
  287. #ifdef CONFIG_32BIT
  288. PRINT("Got \nexception at %08lx\012")
  289. #endif
  290. #ifdef CONFIG_64BIT
  291. PRINT("Got \nexception at %016lx\012")
  292. #endif
  293. .endm
  294. .macro __BUILD_count exception
  295. LONG_L t0,exception_count_\exception
  296. LONG_ADDIU t0, 1
  297. LONG_S t0,exception_count_\exception
  298. .comm exception_count\exception, 8, 8
  299. .endm
  300. .macro __BUILD_HANDLER exception handler clear verbose ext
  301. .align 5
  302. NESTED(handle_\exception, PT_SIZE, sp)
  303. .set noat
  304. SAVE_ALL
  305. FEXPORT(handle_\exception\ext)
  306. __BUILD_clear_\clear
  307. .set at
  308. __BUILD_\verbose \exception
  309. move a0, sp
  310. jal do_\handler
  311. j ret_from_exception
  312. END(handle_\exception)
  313. .endm
  314. .macro BUILD_HANDLER exception handler clear verbose
  315. __BUILD_HANDLER \exception \handler \clear \verbose _int
  316. .endm
  317. BUILD_HANDLER adel ade ade silent /* #4 */
  318. BUILD_HANDLER ades ade ade silent /* #5 */
  319. BUILD_HANDLER ibe be cli silent /* #6 */
  320. BUILD_HANDLER dbe be cli silent /* #7 */
  321. BUILD_HANDLER bp bp sti silent /* #9 */
  322. BUILD_HANDLER ri ri sti silent /* #10 */
  323. BUILD_HANDLER cpu cpu sti silent /* #11 */
  324. BUILD_HANDLER ov ov sti silent /* #12 */
  325. BUILD_HANDLER tr tr sti silent /* #13 */
  326. BUILD_HANDLER fpe fpe fpe silent /* #15 */
  327. BUILD_HANDLER mdmx mdmx sti silent /* #22 */
  328. BUILD_HANDLER watch watch sti verbose /* #23 */
  329. BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
  330. BUILD_HANDLER mt mt sti verbose /* #25 */
  331. BUILD_HANDLER dsp dsp sti silent /* #26 */
  332. BUILD_HANDLER reserved reserved sti verbose /* others */
  333. #ifdef CONFIG_64BIT
  334. /* A temporary overflow handler used by check_daddi(). */
  335. __INIT
  336. BUILD_HANDLER daddi_ov daddi_ov none silent /* #12 */
  337. #endif