entry-avr32b.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. /*
  9. * This file contains the low-level entry-points into the kernel, that is,
  10. * exception handlers, debug trap handlers, interrupt handlers and the
  11. * system call handler.
  12. */
  13. #include <linux/errno.h>
  14. #include <asm/asm.h>
  15. #include <asm/hardirq.h>
  16. #include <asm/irq.h>
  17. #include <asm/ocd.h>
  18. #include <asm/page.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/sysreg.h>
  22. #include <asm/thread_info.h>
  23. #include <asm/unistd.h>
  24. #ifdef CONFIG_PREEMPT
  25. # define preempt_stop mask_interrupts
  26. #else
  27. # define preempt_stop
  28. # define fault_resume_kernel fault_restore_all
  29. #endif
  30. #define __MASK(x) ((1 << (x)) - 1)
  31. #define IRQ_MASK ((__MASK(SOFTIRQ_BITS) << SOFTIRQ_SHIFT) | \
  32. (__MASK(HARDIRQ_BITS) << HARDIRQ_SHIFT))
  33. .section .ex.text,"ax",@progbits
  34. .align 2
  35. exception_vectors:
  36. bral handle_critical
  37. .align 2
  38. bral handle_critical
  39. .align 2
  40. bral do_bus_error_write
  41. .align 2
  42. bral do_bus_error_read
  43. .align 2
  44. bral do_nmi_ll
  45. .align 2
  46. bral handle_address_fault
  47. .align 2
  48. bral handle_protection_fault
  49. .align 2
  50. bral handle_debug
  51. .align 2
  52. bral do_illegal_opcode_ll
  53. .align 2
  54. bral do_illegal_opcode_ll
  55. .align 2
  56. bral do_illegal_opcode_ll
  57. .align 2
  58. bral do_fpe_ll
  59. .align 2
  60. bral do_illegal_opcode_ll
  61. .align 2
  62. bral handle_address_fault
  63. .align 2
  64. bral handle_address_fault
  65. .align 2
  66. bral handle_protection_fault
  67. .align 2
  68. bral handle_protection_fault
  69. .align 2
  70. bral do_dtlb_modified
  71. #define tlbmiss_save pushm r0-r3
  72. #define tlbmiss_restore popm r0-r3
  73. .org 0x50
  74. .global itlb_miss
  75. itlb_miss:
  76. tlbmiss_save
  77. rjmp tlb_miss_common
  78. .org 0x60
  79. dtlb_miss_read:
  80. tlbmiss_save
  81. rjmp tlb_miss_common
  82. .org 0x70
  83. dtlb_miss_write:
  84. tlbmiss_save
  85. .global tlb_miss_common
  86. .align 2
  87. tlb_miss_common:
  88. mfsr r0, SYSREG_TLBEAR
  89. mfsr r1, SYSREG_PTBR
  90. /*
  91. * First level lookup: The PGD contains virtual pointers to
  92. * the second-level page tables, but they may be NULL if not
  93. * present.
  94. */
  95. pgtbl_lookup:
  96. lsr r2, r0, PGDIR_SHIFT
  97. ld.w r3, r1[r2 << 2]
  98. bfextu r1, r0, PAGE_SHIFT, PGDIR_SHIFT - PAGE_SHIFT
  99. cp.w r3, 0
  100. breq page_table_not_present
  101. /* Second level lookup */
  102. ld.w r2, r3[r1 << 2]
  103. mfsr r0, SYSREG_TLBARLO
  104. bld r2, _PAGE_BIT_PRESENT
  105. brcc page_not_present
  106. /* Mark the page as accessed */
  107. sbr r2, _PAGE_BIT_ACCESSED
  108. st.w r3[r1 << 2], r2
  109. /* Drop software flags */
  110. andl r2, _PAGE_FLAGS_HARDWARE_MASK & 0xffff
  111. mtsr SYSREG_TLBELO, r2
  112. /* Figure out which entry we want to replace */
  113. mfsr r1, SYSREG_MMUCR
  114. clz r2, r0
  115. brcc 1f
  116. mov r3, -1 /* All entries have been accessed, */
  117. mov r2, 0 /* so start at 0 */
  118. mtsr SYSREG_TLBARLO, r3 /* and reset TLBAR */
  119. 1: bfins r1, r2, SYSREG_DRP_OFFSET, SYSREG_DRP_SIZE
  120. mtsr SYSREG_MMUCR, r1
  121. tlbw
  122. tlbmiss_restore
  123. rete
  124. /* The slow path of the TLB miss handler */
  125. .align 2
  126. page_table_not_present:
  127. /* Do we need to synchronize with swapper_pg_dir? */
  128. bld r0, 31
  129. brcs sync_with_swapper_pg_dir
  130. page_not_present:
  131. tlbmiss_restore
  132. sub sp, 4
  133. stmts --sp, r0-lr
  134. call save_full_context_ex
  135. mfsr r12, SYSREG_ECR
  136. mov r11, sp
  137. call do_page_fault
  138. rjmp ret_from_exception
  139. .align 2
  140. sync_with_swapper_pg_dir:
  141. /*
  142. * If swapper_pg_dir contains a non-NULL second-level page
  143. * table pointer, copy it into the current PGD. If not, we
  144. * must handle it as a full-blown page fault.
  145. *
  146. * Jumping back to pgtbl_lookup causes an unnecessary lookup,
  147. * but it is guaranteed to be a cache hit, it won't happen
  148. * very often, and we absolutely do not want to sacrifice any
  149. * performance in the fast path in order to improve this.
  150. */
  151. mov r1, lo(swapper_pg_dir)
  152. orh r1, hi(swapper_pg_dir)
  153. ld.w r3, r1[r2 << 2]
  154. cp.w r3, 0
  155. breq page_not_present
  156. mfsr r1, SYSREG_PTBR
  157. st.w r1[r2 << 2], r3
  158. rjmp pgtbl_lookup
  159. /*
  160. * We currently have two bytes left at this point until we
  161. * crash into the system call handler...
  162. *
  163. * Don't worry, the assembler will let us know.
  164. */
  165. /* --- System Call --- */
  166. .org 0x100
  167. system_call:
  168. #ifdef CONFIG_PREEMPT
  169. mask_interrupts
  170. #endif
  171. pushm r12 /* r12_orig */
  172. stmts --sp, r0-lr
  173. mfsr r0, SYSREG_RAR_SUP
  174. mfsr r1, SYSREG_RSR_SUP
  175. #ifdef CONFIG_PREEMPT
  176. unmask_interrupts
  177. #endif
  178. zero_fp
  179. stm --sp, r0-r1
  180. /* check for syscall tracing */
  181. get_thread_info r0
  182. ld.w r1, r0[TI_flags]
  183. bld r1, TIF_SYSCALL_TRACE
  184. brcs syscall_trace_enter
  185. syscall_trace_cont:
  186. cp.w r8, NR_syscalls
  187. brhs syscall_badsys
  188. lddpc lr, syscall_table_addr
  189. ld.w lr, lr[r8 << 2]
  190. mov r8, r5 /* 5th argument (6th is pushed by stub) */
  191. icall lr
  192. .global syscall_return
  193. syscall_return:
  194. get_thread_info r0
  195. mask_interrupts /* make sure we don't miss an interrupt
  196. setting need_resched or sigpending
  197. between sampling and the rets */
  198. /* Store the return value so that the correct value is loaded below */
  199. stdsp sp[REG_R12], r12
  200. ld.w r1, r0[TI_flags]
  201. andl r1, _TIF_ALLWORK_MASK, COH
  202. brne syscall_exit_work
  203. syscall_exit_cont:
  204. popm r8-r9
  205. mtsr SYSREG_RAR_SUP, r8
  206. mtsr SYSREG_RSR_SUP, r9
  207. ldmts sp++, r0-lr
  208. sub sp, -4 /* r12_orig */
  209. rets
  210. .align 2
  211. syscall_table_addr:
  212. .long sys_call_table
  213. syscall_badsys:
  214. mov r12, -ENOSYS
  215. rjmp syscall_return
  216. .global ret_from_fork
  217. ret_from_fork:
  218. call schedule_tail
  219. /* check for syscall tracing */
  220. get_thread_info r0
  221. ld.w r1, r0[TI_flags]
  222. andl r1, _TIF_ALLWORK_MASK, COH
  223. brne syscall_exit_work
  224. rjmp syscall_exit_cont
  225. syscall_trace_enter:
  226. pushm r8-r12
  227. call syscall_trace
  228. popm r8-r12
  229. rjmp syscall_trace_cont
  230. syscall_exit_work:
  231. bld r1, TIF_SYSCALL_TRACE
  232. brcc 1f
  233. unmask_interrupts
  234. call syscall_trace
  235. mask_interrupts
  236. ld.w r1, r0[TI_flags]
  237. 1: bld r1, TIF_NEED_RESCHED
  238. brcc 2f
  239. unmask_interrupts
  240. call schedule
  241. mask_interrupts
  242. ld.w r1, r0[TI_flags]
  243. rjmp 1b
  244. 2: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK
  245. tst r1, r2
  246. breq 3f
  247. unmask_interrupts
  248. mov r12, sp
  249. mov r11, r0
  250. call do_notify_resume
  251. mask_interrupts
  252. ld.w r1, r0[TI_flags]
  253. rjmp 1b
  254. 3: bld r1, TIF_BREAKPOINT
  255. brcc syscall_exit_cont
  256. rjmp enter_monitor_mode
  257. /* This function expects to find offending PC in SYSREG_RAR_EX */
  258. .type save_full_context_ex, @function
  259. .align 2
  260. save_full_context_ex:
  261. mfsr r11, SYSREG_RAR_EX
  262. sub r9, pc, . - debug_trampoline
  263. mfsr r8, SYSREG_RSR_EX
  264. cp.w r9, r11
  265. breq 3f
  266. mov r12, r8
  267. andh r8, (MODE_MASK >> 16), COH
  268. brne 2f
  269. 1: pushm r11, r12 /* PC and SR */
  270. unmask_exceptions
  271. ret r12
  272. 2: sub r10, sp, -(FRAME_SIZE_FULL - REG_LR)
  273. stdsp sp[4], r10 /* replace saved SP */
  274. rjmp 1b
  275. /*
  276. * The debug handler set up a trampoline to make us
  277. * automatically enter monitor mode upon return, but since
  278. * we're saving the full context, we must assume that the
  279. * exception handler might want to alter the return address
  280. * and/or status register. So we need to restore the original
  281. * context and enter monitor mode manually after the exception
  282. * has been handled.
  283. */
  284. 3: get_thread_info r8
  285. ld.w r11, r8[TI_rar_saved]
  286. ld.w r12, r8[TI_rsr_saved]
  287. rjmp 1b
  288. .size save_full_context_ex, . - save_full_context_ex
  289. /* Low-level exception handlers */
  290. handle_critical:
  291. /*
  292. * AT32AP700x errata:
  293. *
  294. * After a Java stack overflow or underflow trap, any CPU
  295. * memory access may cause erratic behavior. This will happen
  296. * when the four least significant bits of the JOSP system
  297. * register contains any value between 9 and 15 (inclusive).
  298. *
  299. * Possible workarounds:
  300. * - Don't use the Java Extension Module
  301. * - Ensure that the stack overflow and underflow trap
  302. * handlers do not do any memory access or trigger any
  303. * exceptions before the overflow/underflow condition is
  304. * cleared (by incrementing or decrementing the JOSP)
  305. * - Make sure that JOSP does not contain any problematic
  306. * value before doing any exception or interrupt
  307. * processing.
  308. * - Set up a critical exception handler which writes a
  309. * known-to-be-safe value, e.g. 4, to JOSP before doing
  310. * any further processing.
  311. *
  312. * We'll use the last workaround for now since we cannot
  313. * guarantee that user space processes don't use Java mode.
  314. * Non-well-behaving userland will be terminated with extreme
  315. * prejudice.
  316. */
  317. #ifdef CONFIG_CPU_AT32AP700X
  318. /*
  319. * There's a chance we can't touch memory, so temporarily
  320. * borrow PTBR to save the stack pointer while we fix things
  321. * up...
  322. */
  323. mtsr SYSREG_PTBR, sp
  324. mov sp, 4
  325. mtsr SYSREG_JOSP, sp
  326. mfsr sp, SYSREG_PTBR
  327. sub pc, -2
  328. /* Push most of pt_regs on stack. We'll do the rest later */
  329. sub sp, 4
  330. pushm r0-r12
  331. /* PTBR mirrors current_thread_info()->task->active_mm->pgd */
  332. get_thread_info r0
  333. ld.w r1, r0[TI_task]
  334. ld.w r2, r1[TSK_active_mm]
  335. ld.w r3, r2[MM_pgd]
  336. mtsr SYSREG_PTBR, r3
  337. #else
  338. sub sp, 4
  339. pushm r0-r12
  340. #endif
  341. sub r0, sp, -(14 * 4)
  342. mov r1, lr
  343. mfsr r2, SYSREG_RAR_EX
  344. mfsr r3, SYSREG_RSR_EX
  345. pushm r0-r3
  346. mfsr r12, SYSREG_ECR
  347. mov r11, sp
  348. call do_critical_exception
  349. /* We should never get here... */
  350. bad_return:
  351. sub r12, pc, (. - 1f)
  352. bral panic
  353. .align 2
  354. 1: .asciz "Return from critical exception!"
  355. .align 1
  356. do_bus_error_write:
  357. sub sp, 4
  358. stmts --sp, r0-lr
  359. call save_full_context_ex
  360. mov r11, 1
  361. rjmp 1f
  362. do_bus_error_read:
  363. sub sp, 4
  364. stmts --sp, r0-lr
  365. call save_full_context_ex
  366. mov r11, 0
  367. 1: mfsr r12, SYSREG_BEAR
  368. mov r10, sp
  369. call do_bus_error
  370. rjmp ret_from_exception
  371. .align 1
  372. do_nmi_ll:
  373. sub sp, 4
  374. stmts --sp, r0-lr
  375. mfsr r9, SYSREG_RSR_NMI
  376. mfsr r8, SYSREG_RAR_NMI
  377. bfextu r0, r9, MODE_SHIFT, 3
  378. brne 2f
  379. 1: pushm r8, r9 /* PC and SR */
  380. mfsr r12, SYSREG_ECR
  381. mov r11, sp
  382. call do_nmi
  383. popm r8-r9
  384. mtsr SYSREG_RAR_NMI, r8
  385. tst r0, r0
  386. mtsr SYSREG_RSR_NMI, r9
  387. brne 3f
  388. ldmts sp++, r0-lr
  389. sub sp, -4 /* skip r12_orig */
  390. rete
  391. 2: sub r10, sp, -(FRAME_SIZE_FULL - REG_LR)
  392. stdsp sp[4], r10 /* replace saved SP */
  393. rjmp 1b
  394. 3: popm lr
  395. sub sp, -4 /* skip sp */
  396. popm r0-r12
  397. sub sp, -4 /* skip r12_orig */
  398. rete
  399. handle_address_fault:
  400. sub sp, 4
  401. stmts --sp, r0-lr
  402. call save_full_context_ex
  403. mfsr r12, SYSREG_ECR
  404. mov r11, sp
  405. call do_address_exception
  406. rjmp ret_from_exception
  407. handle_protection_fault:
  408. sub sp, 4
  409. stmts --sp, r0-lr
  410. call save_full_context_ex
  411. mfsr r12, SYSREG_ECR
  412. mov r11, sp
  413. call do_page_fault
  414. rjmp ret_from_exception
  415. .align 1
  416. do_illegal_opcode_ll:
  417. sub sp, 4
  418. stmts --sp, r0-lr
  419. call save_full_context_ex
  420. mfsr r12, SYSREG_ECR
  421. mov r11, sp
  422. call do_illegal_opcode
  423. rjmp ret_from_exception
  424. do_dtlb_modified:
  425. pushm r0-r3
  426. mfsr r1, SYSREG_TLBEAR
  427. mfsr r0, SYSREG_PTBR
  428. lsr r2, r1, PGDIR_SHIFT
  429. ld.w r0, r0[r2 << 2]
  430. lsl r1, (32 - PGDIR_SHIFT)
  431. lsr r1, (32 - PGDIR_SHIFT) + PAGE_SHIFT
  432. /* Translate to virtual address in P1 */
  433. andl r0, 0xf000
  434. sbr r0, 31
  435. add r2, r0, r1 << 2
  436. ld.w r3, r2[0]
  437. sbr r3, _PAGE_BIT_DIRTY
  438. mov r0, r3
  439. st.w r2[0], r3
  440. /* The page table is up-to-date. Update the TLB entry as well */
  441. andl r0, lo(_PAGE_FLAGS_HARDWARE_MASK)
  442. mtsr SYSREG_TLBELO, r0
  443. /* MMUCR[DRP] is updated automatically, so let's go... */
  444. tlbw
  445. popm r0-r3
  446. rete
  447. do_fpe_ll:
  448. sub sp, 4
  449. stmts --sp, r0-lr
  450. call save_full_context_ex
  451. unmask_interrupts
  452. mov r12, 26
  453. mov r11, sp
  454. call do_fpe
  455. rjmp ret_from_exception
  456. ret_from_exception:
  457. mask_interrupts
  458. lddsp r4, sp[REG_SR]
  459. andh r4, (MODE_MASK >> 16), COH
  460. brne fault_resume_kernel
  461. get_thread_info r0
  462. ld.w r1, r0[TI_flags]
  463. andl r1, _TIF_WORK_MASK, COH
  464. brne fault_exit_work
  465. fault_resume_user:
  466. popm r8-r9
  467. mask_exceptions
  468. mtsr SYSREG_RAR_EX, r8
  469. mtsr SYSREG_RSR_EX, r9
  470. ldmts sp++, r0-lr
  471. sub sp, -4
  472. rete
  473. fault_resume_kernel:
  474. #ifdef CONFIG_PREEMPT
  475. get_thread_info r0
  476. ld.w r2, r0[TI_preempt_count]
  477. cp.w r2, 0
  478. brne 1f
  479. ld.w r1, r0[TI_flags]
  480. bld r1, TIF_NEED_RESCHED
  481. brcc 1f
  482. lddsp r4, sp[REG_SR]
  483. bld r4, SYSREG_GM_OFFSET
  484. brcs 1f
  485. call preempt_schedule_irq
  486. 1:
  487. #endif
  488. popm r8-r9
  489. mask_exceptions
  490. mfsr r1, SYSREG_SR
  491. mtsr SYSREG_RAR_EX, r8
  492. mtsr SYSREG_RSR_EX, r9
  493. popm lr
  494. sub sp, -4 /* ignore SP */
  495. popm r0-r12
  496. sub sp, -4 /* ignore r12_orig */
  497. rete
  498. irq_exit_work:
  499. /* Switch to exception mode so that we can share the same code. */
  500. mfsr r8, SYSREG_SR
  501. cbr r8, SYSREG_M0_OFFSET
  502. orh r8, hi(SYSREG_BIT(M1) | SYSREG_BIT(M2))
  503. mtsr SYSREG_SR, r8
  504. sub pc, -2
  505. get_thread_info r0
  506. ld.w r1, r0[TI_flags]
  507. fault_exit_work:
  508. bld r1, TIF_NEED_RESCHED
  509. brcc 1f
  510. unmask_interrupts
  511. call schedule
  512. mask_interrupts
  513. ld.w r1, r0[TI_flags]
  514. rjmp fault_exit_work
  515. 1: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK
  516. tst r1, r2
  517. breq 2f
  518. unmask_interrupts
  519. mov r12, sp
  520. mov r11, r0
  521. call do_notify_resume
  522. mask_interrupts
  523. ld.w r1, r0[TI_flags]
  524. rjmp fault_exit_work
  525. 2: bld r1, TIF_BREAKPOINT
  526. brcc fault_resume_user
  527. rjmp enter_monitor_mode
  528. .section .kprobes.text, "ax", @progbits
  529. .type handle_debug, @function
  530. handle_debug:
  531. sub sp, 4 /* r12_orig */
  532. stmts --sp, r0-lr
  533. mfsr r8, SYSREG_RAR_DBG
  534. mfsr r9, SYSREG_RSR_DBG
  535. unmask_exceptions
  536. pushm r8-r9
  537. bfextu r9, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  538. brne debug_fixup_regs
  539. .Ldebug_fixup_cont:
  540. #ifdef CONFIG_TRACE_IRQFLAGS
  541. call trace_hardirqs_off
  542. #endif
  543. mov r12, sp
  544. call do_debug
  545. mov sp, r12
  546. lddsp r2, sp[REG_SR]
  547. bfextu r3, r2, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  548. brne debug_resume_kernel
  549. get_thread_info r0
  550. ld.w r1, r0[TI_flags]
  551. mov r2, _TIF_DBGWORK_MASK
  552. tst r1, r2
  553. brne debug_exit_work
  554. bld r1, TIF_SINGLE_STEP
  555. brcc 1f
  556. mfdr r4, OCD_DC
  557. sbr r4, OCD_DC_SS_BIT
  558. mtdr OCD_DC, r4
  559. 1: popm r10,r11
  560. mask_exceptions
  561. mtsr SYSREG_RSR_DBG, r11
  562. mtsr SYSREG_RAR_DBG, r10
  563. #ifdef CONFIG_TRACE_IRQFLAGS
  564. call trace_hardirqs_on
  565. 1:
  566. #endif
  567. ldmts sp++, r0-lr
  568. sub sp, -4
  569. retd
  570. .size handle_debug, . - handle_debug
  571. /* Mode of the trapped context is in r9 */
  572. .type debug_fixup_regs, @function
  573. debug_fixup_regs:
  574. mfsr r8, SYSREG_SR
  575. mov r10, r8
  576. bfins r8, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  577. mtsr SYSREG_SR, r8
  578. sub pc, -2
  579. stdsp sp[REG_LR], lr
  580. mtsr SYSREG_SR, r10
  581. sub pc, -2
  582. sub r8, sp, -FRAME_SIZE_FULL
  583. stdsp sp[REG_SP], r8
  584. rjmp .Ldebug_fixup_cont
  585. .size debug_fixup_regs, . - debug_fixup_regs
  586. .type debug_resume_kernel, @function
  587. debug_resume_kernel:
  588. mask_exceptions
  589. popm r10, r11
  590. mtsr SYSREG_RAR_DBG, r10
  591. mtsr SYSREG_RSR_DBG, r11
  592. #ifdef CONFIG_TRACE_IRQFLAGS
  593. bld r11, SYSREG_GM_OFFSET
  594. brcc 1f
  595. call trace_hardirqs_on
  596. 1:
  597. #endif
  598. mfsr r2, SYSREG_SR
  599. mov r1, r2
  600. bfins r2, r3, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  601. mtsr SYSREG_SR, r2
  602. sub pc, -2
  603. popm lr
  604. mtsr SYSREG_SR, r1
  605. sub pc, -2
  606. sub sp, -4 /* skip SP */
  607. popm r0-r12
  608. sub sp, -4
  609. retd
  610. .size debug_resume_kernel, . - debug_resume_kernel
  611. .type debug_exit_work, @function
  612. debug_exit_work:
  613. /*
  614. * We must return from Monitor Mode using a retd, and we must
  615. * not schedule since that involves the D bit in SR getting
  616. * cleared by something other than the debug hardware. This
  617. * may cause undefined behaviour according to the Architecture
  618. * manual.
  619. *
  620. * So we fix up the return address and status and return to a
  621. * stub below in Exception mode. From there, we can follow the
  622. * normal exception return path.
  623. *
  624. * The real return address and status registers are stored on
  625. * the stack in the way the exception return path understands,
  626. * so no need to fix anything up there.
  627. */
  628. sub r8, pc, . - fault_exit_work
  629. mtsr SYSREG_RAR_DBG, r8
  630. mov r9, 0
  631. orh r9, hi(SR_EM | SR_GM | MODE_EXCEPTION)
  632. mtsr SYSREG_RSR_DBG, r9
  633. sub pc, -2
  634. retd
  635. .size debug_exit_work, . - debug_exit_work
  636. .set rsr_int0, SYSREG_RSR_INT0
  637. .set rsr_int1, SYSREG_RSR_INT1
  638. .set rsr_int2, SYSREG_RSR_INT2
  639. .set rsr_int3, SYSREG_RSR_INT3
  640. .set rar_int0, SYSREG_RAR_INT0
  641. .set rar_int1, SYSREG_RAR_INT1
  642. .set rar_int2, SYSREG_RAR_INT2
  643. .set rar_int3, SYSREG_RAR_INT3
  644. .macro IRQ_LEVEL level
  645. .type irq_level\level, @function
  646. irq_level\level:
  647. sub sp, 4 /* r12_orig */
  648. stmts --sp,r0-lr
  649. mfsr r8, rar_int\level
  650. mfsr r9, rsr_int\level
  651. #ifdef CONFIG_PREEMPT
  652. sub r11, pc, (. - system_call)
  653. cp.w r11, r8
  654. breq 4f
  655. #endif
  656. pushm r8-r9
  657. mov r11, sp
  658. mov r12, \level
  659. call do_IRQ
  660. lddsp r4, sp[REG_SR]
  661. bfextu r4, r4, SYSREG_M0_OFFSET, 3
  662. cp.w r4, MODE_SUPERVISOR >> SYSREG_M0_OFFSET
  663. breq 2f
  664. cp.w r4, MODE_USER >> SYSREG_M0_OFFSET
  665. #ifdef CONFIG_PREEMPT
  666. brne 3f
  667. #else
  668. brne 1f
  669. #endif
  670. get_thread_info r0
  671. ld.w r1, r0[TI_flags]
  672. andl r1, _TIF_WORK_MASK, COH
  673. brne irq_exit_work
  674. 1:
  675. #ifdef CONFIG_TRACE_IRQFLAGS
  676. call trace_hardirqs_on
  677. #endif
  678. popm r8-r9
  679. mtsr rar_int\level, r8
  680. mtsr rsr_int\level, r9
  681. ldmts sp++,r0-lr
  682. sub sp, -4 /* ignore r12_orig */
  683. rete
  684. #ifdef CONFIG_PREEMPT
  685. 4: mask_interrupts
  686. mfsr r8, rsr_int\level
  687. sbr r8, 16
  688. mtsr rsr_int\level, r8
  689. ldmts sp++, r0-lr
  690. sub sp, -4 /* ignore r12_orig */
  691. rete
  692. #endif
  693. 2: get_thread_info r0
  694. ld.w r1, r0[TI_flags]
  695. bld r1, TIF_CPU_GOING_TO_SLEEP
  696. #ifdef CONFIG_PREEMPT
  697. brcc 3f
  698. #else
  699. brcc 1b
  700. #endif
  701. sub r1, pc, . - cpu_idle_skip_sleep
  702. stdsp sp[REG_PC], r1
  703. #ifdef CONFIG_PREEMPT
  704. 3: get_thread_info r0
  705. ld.w r2, r0[TI_preempt_count]
  706. cp.w r2, 0
  707. brne 1b
  708. ld.w r1, r0[TI_flags]
  709. bld r1, TIF_NEED_RESCHED
  710. brcc 1b
  711. lddsp r4, sp[REG_SR]
  712. bld r4, SYSREG_GM_OFFSET
  713. brcs 1b
  714. call preempt_schedule_irq
  715. #endif
  716. rjmp 1b
  717. .endm
  718. .section .irq.text,"ax",@progbits
  719. .global irq_level0
  720. .global irq_level1
  721. .global irq_level2
  722. .global irq_level3
  723. IRQ_LEVEL 0
  724. IRQ_LEVEL 1
  725. IRQ_LEVEL 2
  726. IRQ_LEVEL 3
  727. .section .kprobes.text, "ax", @progbits
  728. .type enter_monitor_mode, @function
  729. enter_monitor_mode:
  730. /*
  731. * We need to enter monitor mode to do a single step. The
  732. * monitor code will alter the return address so that we
  733. * return directly to the user instead of returning here.
  734. */
  735. breakpoint
  736. rjmp breakpoint_failed
  737. .size enter_monitor_mode, . - enter_monitor_mode
  738. .type debug_trampoline, @function
  739. .global debug_trampoline
  740. debug_trampoline:
  741. /*
  742. * Save the registers on the stack so that the monitor code
  743. * can find them easily.
  744. */
  745. sub sp, 4 /* r12_orig */
  746. stmts --sp, r0-lr
  747. get_thread_info r0
  748. ld.w r8, r0[TI_rar_saved]
  749. ld.w r9, r0[TI_rsr_saved]
  750. pushm r8-r9
  751. /*
  752. * The monitor code will alter the return address so we don't
  753. * return here.
  754. */
  755. breakpoint
  756. rjmp breakpoint_failed
  757. .size debug_trampoline, . - debug_trampoline
  758. .type breakpoint_failed, @function
  759. breakpoint_failed:
  760. /*
  761. * Something went wrong. Perhaps the debug hardware isn't
  762. * enabled?
  763. */
  764. lda.w r12, msg_breakpoint_failed
  765. mov r11, sp
  766. mov r10, 9 /* SIGKILL */
  767. call die
  768. 1: rjmp 1b
  769. msg_breakpoint_failed:
  770. .asciz "Failed to enter Debug Mode"