genex.S 8.4 KB

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