genex.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. #ifdef CONFIG_TRACE_IRQFLAGS
  121. /*
  122. * Check to see if the interrupted code has just disabled
  123. * interrupts and ignore this interrupt for now if so.
  124. *
  125. * local_irq_disable() disables interrupts and then calls
  126. * trace_hardirqs_off() to track the state. If an interrupt is taken
  127. * after interrupts are disabled but before the state is updated
  128. * it will appear to restore_all that it is incorrectly returning with
  129. * interrupts disabled
  130. */
  131. .set push
  132. .set noat
  133. mfc0 k0, CP0_STATUS
  134. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  135. and k0, ST0_IEP
  136. bnez k0, 1f
  137. mfc0 k0, EP0_EPC
  138. .set noreorder
  139. j k0
  140. rfe
  141. #else
  142. and k0, ST0_IE
  143. bnez k0, 1f
  144. eret
  145. #endif
  146. 1:
  147. .set pop
  148. #endif
  149. SAVE_ALL
  150. CLI
  151. TRACE_IRQS_OFF
  152. LONG_L s0, TI_REGS($28)
  153. LONG_S sp, TI_REGS($28)
  154. PTR_LA ra, ret_from_irq
  155. j plat_irq_dispatch
  156. END(handle_int)
  157. __INIT
  158. /*
  159. * Special interrupt vector for MIPS64 ISA & embedded MIPS processors.
  160. * This is a dedicated interrupt exception vector which reduces the
  161. * interrupt processing overhead. The jump instruction will be replaced
  162. * at the initialization time.
  163. *
  164. * Be careful when changing this, it has to be at most 128 bytes
  165. * to fit into space reserved for the exception handler.
  166. */
  167. NESTED(except_vec4, 0, sp)
  168. 1: j 1b /* Dummy, will be replaced */
  169. END(except_vec4)
  170. /*
  171. * EJTAG debug exception handler.
  172. * The EJTAG debug exception entry point is 0xbfc00480, which
  173. * normally is in the boot PROM, so the boot PROM must do a
  174. * unconditional jump to this vector.
  175. */
  176. NESTED(except_vec_ejtag_debug, 0, sp)
  177. j ejtag_debug_handler
  178. END(except_vec_ejtag_debug)
  179. __FINIT
  180. /*
  181. * Vectored interrupt handler.
  182. * This prototype is copied to ebase + n*IntCtl.VS and patched
  183. * to invoke the handler
  184. */
  185. NESTED(except_vec_vi, 0, sp)
  186. SAVE_SOME
  187. SAVE_AT
  188. .set push
  189. .set noreorder
  190. #ifdef CONFIG_MIPS_MT_SMTC
  191. /*
  192. * To keep from blindly blocking *all* interrupts
  193. * during service by SMTC kernel, we also want to
  194. * pass the IM value to be cleared.
  195. */
  196. FEXPORT(except_vec_vi_mori)
  197. ori a0, $0, 0
  198. #endif /* CONFIG_MIPS_MT_SMTC */
  199. FEXPORT(except_vec_vi_lui)
  200. lui v0, 0 /* Patched */
  201. j except_vec_vi_handler
  202. FEXPORT(except_vec_vi_ori)
  203. ori v0, 0 /* Patched */
  204. .set pop
  205. END(except_vec_vi)
  206. EXPORT(except_vec_vi_end)
  207. /*
  208. * Common Vectored Interrupt code
  209. * Complete the register saves and invoke the handler which is passed in $v0
  210. */
  211. NESTED(except_vec_vi_handler, 0, sp)
  212. SAVE_TEMP
  213. SAVE_STATIC
  214. #ifdef CONFIG_MIPS_MT_SMTC
  215. /*
  216. * SMTC has an interesting problem that interrupts are level-triggered,
  217. * and the CLI macro will clear EXL, potentially causing a duplicate
  218. * interrupt service invocation. So we need to clear the associated
  219. * IM bit of Status prior to doing CLI, and restore it after the
  220. * service routine has been invoked - we must assume that the
  221. * service routine will have cleared the state, and any active
  222. * level represents a new or otherwised unserviced event...
  223. */
  224. mfc0 t1, CP0_STATUS
  225. and t0, a0, t1
  226. #ifdef CONFIG_MIPS_MT_SMTC_IM_BACKSTOP
  227. mfc0 t2, CP0_TCCONTEXT
  228. or t0, t0, t2
  229. mtc0 t0, CP0_TCCONTEXT
  230. #endif /* CONFIG_MIPS_MT_SMTC_IM_BACKSTOP */
  231. xor t1, t1, t0
  232. mtc0 t1, CP0_STATUS
  233. _ehb
  234. #endif /* CONFIG_MIPS_MT_SMTC */
  235. CLI
  236. #ifdef CONFIG_TRACE_IRQFLAGS
  237. move s0, v0
  238. #ifdef CONFIG_MIPS_MT_SMTC
  239. move s1, a0
  240. #endif
  241. TRACE_IRQS_OFF
  242. #ifdef CONFIG_MIPS_MT_SMTC
  243. move a0, s1
  244. #endif
  245. move v0, s0
  246. #endif
  247. LONG_L s0, TI_REGS($28)
  248. LONG_S sp, TI_REGS($28)
  249. PTR_LA ra, ret_from_irq
  250. jr v0
  251. END(except_vec_vi_handler)
  252. /*
  253. * EJTAG debug exception handler.
  254. */
  255. NESTED(ejtag_debug_handler, PT_SIZE, sp)
  256. .set push
  257. .set noat
  258. MTC0 k0, CP0_DESAVE
  259. mfc0 k0, CP0_DEBUG
  260. sll k0, k0, 30 # Check for SDBBP.
  261. bgez k0, ejtag_return
  262. PTR_LA k0, ejtag_debug_buffer
  263. LONG_S k1, 0(k0)
  264. SAVE_ALL
  265. move a0, sp
  266. jal ejtag_exception_handler
  267. RESTORE_ALL
  268. PTR_LA k0, ejtag_debug_buffer
  269. LONG_L k1, 0(k0)
  270. ejtag_return:
  271. MFC0 k0, CP0_DESAVE
  272. .set mips32
  273. deret
  274. .set pop
  275. END(ejtag_debug_handler)
  276. /*
  277. * This buffer is reserved for the use of the EJTAG debug
  278. * handler.
  279. */
  280. .data
  281. EXPORT(ejtag_debug_buffer)
  282. .fill LONGSIZE
  283. .previous
  284. __INIT
  285. /*
  286. * NMI debug exception handler for MIPS reference boards.
  287. * The NMI debug exception entry point is 0xbfc00000, which
  288. * normally is in the boot PROM, so the boot PROM must do a
  289. * unconditional jump to this vector.
  290. */
  291. NESTED(except_vec_nmi, 0, sp)
  292. j nmi_handler
  293. END(except_vec_nmi)
  294. __FINIT
  295. NESTED(nmi_handler, PT_SIZE, sp)
  296. .set push
  297. .set noat
  298. SAVE_ALL
  299. move a0, sp
  300. jal nmi_exception_handler
  301. RESTORE_ALL
  302. .set mips3
  303. eret
  304. .set pop
  305. END(nmi_handler)
  306. .macro __build_clear_none
  307. .endm
  308. .macro __build_clear_sti
  309. TRACE_IRQS_ON
  310. STI
  311. .endm
  312. .macro __build_clear_cli
  313. CLI
  314. TRACE_IRQS_OFF
  315. .endm
  316. .macro __build_clear_fpe
  317. cfc1 a1, fcr31
  318. li a2, ~(0x3f << 12)
  319. and a2, a1
  320. ctc1 a2, fcr31
  321. TRACE_IRQS_ON
  322. STI
  323. .endm
  324. .macro __build_clear_ade
  325. MFC0 t0, CP0_BADVADDR
  326. PTR_S t0, PT_BVADDR(sp)
  327. KMODE
  328. .endm
  329. .macro __BUILD_silent exception
  330. .endm
  331. /* Gas tries to parse the PRINT argument as a string containing
  332. string escapes and emits bogus warnings if it believes to
  333. recognize an unknown escape code. So make the arguments
  334. start with an n and gas will believe \n is ok ... */
  335. .macro __BUILD_verbose nexception
  336. LONG_L a1, PT_EPC(sp)
  337. #ifdef CONFIG_32BIT
  338. PRINT("Got \nexception at %08lx\012")
  339. #endif
  340. #ifdef CONFIG_64BIT
  341. PRINT("Got \nexception at %016lx\012")
  342. #endif
  343. .endm
  344. .macro __BUILD_count exception
  345. LONG_L t0,exception_count_\exception
  346. LONG_ADDIU t0, 1
  347. LONG_S t0,exception_count_\exception
  348. .comm exception_count\exception, 8, 8
  349. .endm
  350. .macro __BUILD_HANDLER exception handler clear verbose ext
  351. .align 5
  352. NESTED(handle_\exception, PT_SIZE, sp)
  353. .set noat
  354. SAVE_ALL
  355. FEXPORT(handle_\exception\ext)
  356. __BUILD_clear_\clear
  357. .set at
  358. __BUILD_\verbose \exception
  359. move a0, sp
  360. PTR_LA ra, ret_from_exception
  361. j do_\handler
  362. END(handle_\exception)
  363. .endm
  364. .macro BUILD_HANDLER exception handler clear verbose
  365. __BUILD_HANDLER \exception \handler \clear \verbose _int
  366. .endm
  367. BUILD_HANDLER adel ade ade silent /* #4 */
  368. BUILD_HANDLER ades ade ade silent /* #5 */
  369. BUILD_HANDLER ibe be cli silent /* #6 */
  370. BUILD_HANDLER dbe be cli silent /* #7 */
  371. BUILD_HANDLER bp bp sti silent /* #9 */
  372. BUILD_HANDLER ri ri sti silent /* #10 */
  373. BUILD_HANDLER cpu cpu sti silent /* #11 */
  374. BUILD_HANDLER ov ov sti silent /* #12 */
  375. BUILD_HANDLER tr tr sti silent /* #13 */
  376. BUILD_HANDLER fpe fpe fpe silent /* #15 */
  377. BUILD_HANDLER mdmx mdmx sti silent /* #22 */
  378. BUILD_HANDLER watch watch sti verbose /* #23 */
  379. BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
  380. BUILD_HANDLER mt mt sti silent /* #25 */
  381. BUILD_HANDLER dsp dsp sti silent /* #26 */
  382. BUILD_HANDLER reserved reserved sti verbose /* others */
  383. .align 5
  384. LEAF(handle_ri_rdhwr_vivt)
  385. #ifdef CONFIG_MIPS_MT_SMTC
  386. PANIC_PIC("handle_ri_rdhwr_vivt called")
  387. #else
  388. .set push
  389. .set noat
  390. .set noreorder
  391. /* check if TLB contains a entry for EPC */
  392. MFC0 k1, CP0_ENTRYHI
  393. andi k1, 0xff /* ASID_MASK */
  394. MFC0 k0, CP0_EPC
  395. PTR_SRL k0, PAGE_SHIFT + 1
  396. PTR_SLL k0, PAGE_SHIFT + 1
  397. or k1, k0
  398. MTC0 k1, CP0_ENTRYHI
  399. mtc0_tlbw_hazard
  400. tlbp
  401. tlb_probe_hazard
  402. mfc0 k1, CP0_INDEX
  403. .set pop
  404. bltz k1, handle_ri /* slow path */
  405. /* fall thru */
  406. #endif
  407. END(handle_ri_rdhwr_vivt)
  408. LEAF(handle_ri_rdhwr)
  409. .set push
  410. .set noat
  411. .set noreorder
  412. /* 0x7c03e83b: rdhwr v1,$29 */
  413. MFC0 k1, CP0_EPC
  414. lui k0, 0x7c03
  415. lw k1, (k1)
  416. ori k0, 0xe83b
  417. .set reorder
  418. bne k0, k1, handle_ri /* if not ours */
  419. /* The insn is rdhwr. No need to check CAUSE.BD here. */
  420. get_saved_sp /* k1 := current_thread_info */
  421. .set noreorder
  422. MFC0 k0, CP0_EPC
  423. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  424. ori k1, _THREAD_MASK
  425. xori k1, _THREAD_MASK
  426. LONG_L v1, TI_TP_VALUE(k1)
  427. LONG_ADDIU k0, 4
  428. jr k0
  429. rfe
  430. #else
  431. LONG_ADDIU k0, 4 /* stall on $k0 */
  432. MTC0 k0, CP0_EPC
  433. /* I hope three instructions between MTC0 and ERET are enough... */
  434. ori k1, _THREAD_MASK
  435. xori k1, _THREAD_MASK
  436. LONG_L v1, TI_TP_VALUE(k1)
  437. .set mips3
  438. eret
  439. .set mips0
  440. #endif
  441. .set pop
  442. END(handle_ri_rdhwr)
  443. #ifdef CONFIG_64BIT
  444. /* A temporary overflow handler used by check_daddi(). */
  445. __INIT
  446. BUILD_HANDLER daddi_ov daddi_ov none silent /* #12 */
  447. #endif