genex.S 8.6 KB

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