genex.S 12 KB

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