genex.S 9.9 KB

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