genex.S 8.5 KB

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