genex.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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. mfc0 t2, CP0_TCCONTEXT
  227. or t0, t0, t2
  228. mtc0 t0, CP0_TCCONTEXT
  229. xor t1, t1, t0
  230. mtc0 t1, CP0_STATUS
  231. _ehb
  232. #endif /* CONFIG_MIPS_MT_SMTC */
  233. CLI
  234. #ifdef CONFIG_TRACE_IRQFLAGS
  235. move s0, v0
  236. #ifdef CONFIG_MIPS_MT_SMTC
  237. move s1, a0
  238. #endif
  239. TRACE_IRQS_OFF
  240. #ifdef CONFIG_MIPS_MT_SMTC
  241. move a0, s1
  242. #endif
  243. move v0, s0
  244. #endif
  245. LONG_L s0, TI_REGS($28)
  246. LONG_S sp, TI_REGS($28)
  247. PTR_LA ra, ret_from_irq
  248. jr v0
  249. END(except_vec_vi_handler)
  250. /*
  251. * EJTAG debug exception handler.
  252. */
  253. NESTED(ejtag_debug_handler, PT_SIZE, sp)
  254. .set push
  255. .set noat
  256. MTC0 k0, CP0_DESAVE
  257. mfc0 k0, CP0_DEBUG
  258. sll k0, k0, 30 # Check for SDBBP.
  259. bgez k0, ejtag_return
  260. PTR_LA k0, ejtag_debug_buffer
  261. LONG_S k1, 0(k0)
  262. SAVE_ALL
  263. move a0, sp
  264. jal ejtag_exception_handler
  265. RESTORE_ALL
  266. PTR_LA k0, ejtag_debug_buffer
  267. LONG_L k1, 0(k0)
  268. ejtag_return:
  269. MFC0 k0, CP0_DESAVE
  270. .set mips32
  271. deret
  272. .set pop
  273. END(ejtag_debug_handler)
  274. /*
  275. * This buffer is reserved for the use of the EJTAG debug
  276. * handler.
  277. */
  278. .data
  279. EXPORT(ejtag_debug_buffer)
  280. .fill LONGSIZE
  281. .previous
  282. __INIT
  283. /*
  284. * NMI debug exception handler for MIPS reference boards.
  285. * The NMI debug exception entry point is 0xbfc00000, which
  286. * normally is in the boot PROM, so the boot PROM must do a
  287. * unconditional jump to this vector.
  288. */
  289. NESTED(except_vec_nmi, 0, sp)
  290. j nmi_handler
  291. END(except_vec_nmi)
  292. __FINIT
  293. NESTED(nmi_handler, PT_SIZE, sp)
  294. .set push
  295. .set noat
  296. SAVE_ALL
  297. move a0, sp
  298. jal nmi_exception_handler
  299. RESTORE_ALL
  300. .set mips3
  301. eret
  302. .set pop
  303. END(nmi_handler)
  304. .macro __build_clear_none
  305. .endm
  306. .macro __build_clear_sti
  307. TRACE_IRQS_ON
  308. STI
  309. .endm
  310. .macro __build_clear_cli
  311. CLI
  312. TRACE_IRQS_OFF
  313. .endm
  314. .macro __build_clear_fpe
  315. cfc1 a1, fcr31
  316. li a2, ~(0x3f << 12)
  317. and a2, a1
  318. ctc1 a2, fcr31
  319. TRACE_IRQS_ON
  320. STI
  321. .endm
  322. .macro __build_clear_ade
  323. MFC0 t0, CP0_BADVADDR
  324. PTR_S t0, PT_BVADDR(sp)
  325. KMODE
  326. .endm
  327. .macro __BUILD_silent exception
  328. .endm
  329. /* Gas tries to parse the PRINT argument as a string containing
  330. string escapes and emits bogus warnings if it believes to
  331. recognize an unknown escape code. So make the arguments
  332. start with an n and gas will believe \n is ok ... */
  333. .macro __BUILD_verbose nexception
  334. LONG_L a1, PT_EPC(sp)
  335. #ifdef CONFIG_32BIT
  336. PRINT("Got \nexception at %08lx\012")
  337. #endif
  338. #ifdef CONFIG_64BIT
  339. PRINT("Got \nexception at %016lx\012")
  340. #endif
  341. .endm
  342. .macro __BUILD_count exception
  343. LONG_L t0,exception_count_\exception
  344. LONG_ADDIU t0, 1
  345. LONG_S t0,exception_count_\exception
  346. .comm exception_count\exception, 8, 8
  347. .endm
  348. .macro __BUILD_HANDLER exception handler clear verbose ext
  349. .align 5
  350. NESTED(handle_\exception, PT_SIZE, sp)
  351. .set noat
  352. SAVE_ALL
  353. FEXPORT(handle_\exception\ext)
  354. __BUILD_clear_\clear
  355. .set at
  356. __BUILD_\verbose \exception
  357. move a0, sp
  358. PTR_LA ra, ret_from_exception
  359. j do_\handler
  360. END(handle_\exception)
  361. .endm
  362. .macro BUILD_HANDLER exception handler clear verbose
  363. __BUILD_HANDLER \exception \handler \clear \verbose _int
  364. .endm
  365. BUILD_HANDLER adel ade ade silent /* #4 */
  366. BUILD_HANDLER ades ade ade silent /* #5 */
  367. BUILD_HANDLER ibe be cli silent /* #6 */
  368. BUILD_HANDLER dbe be cli silent /* #7 */
  369. BUILD_HANDLER bp bp sti silent /* #9 */
  370. BUILD_HANDLER ri ri sti silent /* #10 */
  371. BUILD_HANDLER cpu cpu sti silent /* #11 */
  372. BUILD_HANDLER ov ov sti silent /* #12 */
  373. BUILD_HANDLER tr tr sti silent /* #13 */
  374. BUILD_HANDLER fpe fpe fpe silent /* #15 */
  375. BUILD_HANDLER mdmx mdmx sti silent /* #22 */
  376. BUILD_HANDLER watch watch sti verbose /* #23 */
  377. BUILD_HANDLER mcheck mcheck cli verbose /* #24 */
  378. BUILD_HANDLER mt mt sti silent /* #25 */
  379. BUILD_HANDLER dsp dsp sti silent /* #26 */
  380. BUILD_HANDLER reserved reserved sti verbose /* others */
  381. .align 5
  382. LEAF(handle_ri_rdhwr_vivt)
  383. #ifdef CONFIG_MIPS_MT_SMTC
  384. PANIC_PIC("handle_ri_rdhwr_vivt called")
  385. #else
  386. .set push
  387. .set noat
  388. .set noreorder
  389. /* check if TLB contains a entry for EPC */
  390. MFC0 k1, CP0_ENTRYHI
  391. andi k1, 0xff /* ASID_MASK */
  392. MFC0 k0, CP0_EPC
  393. PTR_SRL k0, PAGE_SHIFT + 1
  394. PTR_SLL k0, PAGE_SHIFT + 1
  395. or k1, k0
  396. MTC0 k1, CP0_ENTRYHI
  397. mtc0_tlbw_hazard
  398. tlbp
  399. tlb_probe_hazard
  400. mfc0 k1, CP0_INDEX
  401. .set pop
  402. bltz k1, handle_ri /* slow path */
  403. /* fall thru */
  404. #endif
  405. END(handle_ri_rdhwr_vivt)
  406. LEAF(handle_ri_rdhwr)
  407. .set push
  408. .set noat
  409. .set noreorder
  410. /* 0x7c03e83b: rdhwr v1,$29 */
  411. MFC0 k1, CP0_EPC
  412. lui k0, 0x7c03
  413. lw k1, (k1)
  414. ori k0, 0xe83b
  415. .set reorder
  416. bne k0, k1, handle_ri /* if not ours */
  417. /* The insn is rdhwr. No need to check CAUSE.BD here. */
  418. get_saved_sp /* k1 := current_thread_info */
  419. .set noreorder
  420. MFC0 k0, CP0_EPC
  421. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  422. ori k1, _THREAD_MASK
  423. xori k1, _THREAD_MASK
  424. LONG_L v1, TI_TP_VALUE(k1)
  425. LONG_ADDIU k0, 4
  426. jr k0
  427. rfe
  428. #else
  429. LONG_ADDIU k0, 4 /* stall on $k0 */
  430. MTC0 k0, CP0_EPC
  431. /* I hope three instructions between MTC0 and ERET are enough... */
  432. ori k1, _THREAD_MASK
  433. xori k1, _THREAD_MASK
  434. LONG_L v1, TI_TP_VALUE(k1)
  435. .set mips3
  436. eret
  437. .set mips0
  438. #endif
  439. .set pop
  440. END(handle_ri_rdhwr)
  441. #ifdef CONFIG_64BIT
  442. /* A temporary overflow handler used by check_daddi(). */
  443. __INIT
  444. BUILD_HANDLER daddi_ov daddi_ov none silent /* #12 */
  445. #endif