entry-avr32b.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. mov r12, 0
  220. rjmp syscall_return
  221. .global ret_from_kernel_thread
  222. ret_from_kernel_thread:
  223. call schedule_tail
  224. mov r12, r0
  225. mov lr, r2 /* syscall_return */
  226. mov pc, r1
  227. syscall_trace_enter:
  228. pushm r8-r12
  229. call syscall_trace
  230. popm r8-r12
  231. rjmp syscall_trace_cont
  232. syscall_exit_work:
  233. bld r1, TIF_SYSCALL_TRACE
  234. brcc 1f
  235. unmask_interrupts
  236. call syscall_trace
  237. mask_interrupts
  238. ld.w r1, r0[TI_flags]
  239. 1: bld r1, TIF_NEED_RESCHED
  240. brcc 2f
  241. unmask_interrupts
  242. call schedule
  243. mask_interrupts
  244. ld.w r1, r0[TI_flags]
  245. rjmp 1b
  246. 2: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
  247. tst r1, r2
  248. breq 3f
  249. unmask_interrupts
  250. mov r12, sp
  251. mov r11, r0
  252. call do_notify_resume
  253. mask_interrupts
  254. ld.w r1, r0[TI_flags]
  255. rjmp 1b
  256. 3: bld r1, TIF_BREAKPOINT
  257. brcc syscall_exit_cont
  258. rjmp enter_monitor_mode
  259. /* This function expects to find offending PC in SYSREG_RAR_EX */
  260. .type save_full_context_ex, @function
  261. .align 2
  262. save_full_context_ex:
  263. mfsr r11, SYSREG_RAR_EX
  264. sub r9, pc, . - debug_trampoline
  265. mfsr r8, SYSREG_RSR_EX
  266. cp.w r9, r11
  267. breq 3f
  268. mov r12, r8
  269. andh r8, (MODE_MASK >> 16), COH
  270. brne 2f
  271. 1: pushm r11, r12 /* PC and SR */
  272. unmask_exceptions
  273. ret r12
  274. 2: sub r10, sp, -(FRAME_SIZE_FULL - REG_LR)
  275. stdsp sp[4], r10 /* replace saved SP */
  276. rjmp 1b
  277. /*
  278. * The debug handler set up a trampoline to make us
  279. * automatically enter monitor mode upon return, but since
  280. * we're saving the full context, we must assume that the
  281. * exception handler might want to alter the return address
  282. * and/or status register. So we need to restore the original
  283. * context and enter monitor mode manually after the exception
  284. * has been handled.
  285. */
  286. 3: get_thread_info r8
  287. ld.w r11, r8[TI_rar_saved]
  288. ld.w r12, r8[TI_rsr_saved]
  289. rjmp 1b
  290. .size save_full_context_ex, . - save_full_context_ex
  291. /* Low-level exception handlers */
  292. handle_critical:
  293. /*
  294. * AT32AP700x errata:
  295. *
  296. * After a Java stack overflow or underflow trap, any CPU
  297. * memory access may cause erratic behavior. This will happen
  298. * when the four least significant bits of the JOSP system
  299. * register contains any value between 9 and 15 (inclusive).
  300. *
  301. * Possible workarounds:
  302. * - Don't use the Java Extension Module
  303. * - Ensure that the stack overflow and underflow trap
  304. * handlers do not do any memory access or trigger any
  305. * exceptions before the overflow/underflow condition is
  306. * cleared (by incrementing or decrementing the JOSP)
  307. * - Make sure that JOSP does not contain any problematic
  308. * value before doing any exception or interrupt
  309. * processing.
  310. * - Set up a critical exception handler which writes a
  311. * known-to-be-safe value, e.g. 4, to JOSP before doing
  312. * any further processing.
  313. *
  314. * We'll use the last workaround for now since we cannot
  315. * guarantee that user space processes don't use Java mode.
  316. * Non-well-behaving userland will be terminated with extreme
  317. * prejudice.
  318. */
  319. #ifdef CONFIG_CPU_AT32AP700X
  320. /*
  321. * There's a chance we can't touch memory, so temporarily
  322. * borrow PTBR to save the stack pointer while we fix things
  323. * up...
  324. */
  325. mtsr SYSREG_PTBR, sp
  326. mov sp, 4
  327. mtsr SYSREG_JOSP, sp
  328. mfsr sp, SYSREG_PTBR
  329. sub pc, -2
  330. /* Push most of pt_regs on stack. We'll do the rest later */
  331. sub sp, 4
  332. pushm r0-r12
  333. /* PTBR mirrors current_thread_info()->task->active_mm->pgd */
  334. get_thread_info r0
  335. ld.w r1, r0[TI_task]
  336. ld.w r2, r1[TSK_active_mm]
  337. ld.w r3, r2[MM_pgd]
  338. mtsr SYSREG_PTBR, r3
  339. #else
  340. sub sp, 4
  341. pushm r0-r12
  342. #endif
  343. sub r0, sp, -(14 * 4)
  344. mov r1, lr
  345. mfsr r2, SYSREG_RAR_EX
  346. mfsr r3, SYSREG_RSR_EX
  347. pushm r0-r3
  348. mfsr r12, SYSREG_ECR
  349. mov r11, sp
  350. call do_critical_exception
  351. /* We should never get here... */
  352. bad_return:
  353. sub r12, pc, (. - 1f)
  354. bral panic
  355. .align 2
  356. 1: .asciz "Return from critical exception!"
  357. .align 1
  358. do_bus_error_write:
  359. sub sp, 4
  360. stmts --sp, r0-lr
  361. call save_full_context_ex
  362. mov r11, 1
  363. rjmp 1f
  364. do_bus_error_read:
  365. sub sp, 4
  366. stmts --sp, r0-lr
  367. call save_full_context_ex
  368. mov r11, 0
  369. 1: mfsr r12, SYSREG_BEAR
  370. mov r10, sp
  371. call do_bus_error
  372. rjmp ret_from_exception
  373. .align 1
  374. do_nmi_ll:
  375. sub sp, 4
  376. stmts --sp, r0-lr
  377. mfsr r9, SYSREG_RSR_NMI
  378. mfsr r8, SYSREG_RAR_NMI
  379. bfextu r0, r9, MODE_SHIFT, 3
  380. brne 2f
  381. 1: pushm r8, r9 /* PC and SR */
  382. mfsr r12, SYSREG_ECR
  383. mov r11, sp
  384. call do_nmi
  385. popm r8-r9
  386. mtsr SYSREG_RAR_NMI, r8
  387. tst r0, r0
  388. mtsr SYSREG_RSR_NMI, r9
  389. brne 3f
  390. ldmts sp++, r0-lr
  391. sub sp, -4 /* skip r12_orig */
  392. rete
  393. 2: sub r10, sp, -(FRAME_SIZE_FULL - REG_LR)
  394. stdsp sp[4], r10 /* replace saved SP */
  395. rjmp 1b
  396. 3: popm lr
  397. sub sp, -4 /* skip sp */
  398. popm r0-r12
  399. sub sp, -4 /* skip r12_orig */
  400. rete
  401. handle_address_fault:
  402. sub sp, 4
  403. stmts --sp, r0-lr
  404. call save_full_context_ex
  405. mfsr r12, SYSREG_ECR
  406. mov r11, sp
  407. call do_address_exception
  408. rjmp ret_from_exception
  409. handle_protection_fault:
  410. sub sp, 4
  411. stmts --sp, r0-lr
  412. call save_full_context_ex
  413. mfsr r12, SYSREG_ECR
  414. mov r11, sp
  415. call do_page_fault
  416. rjmp ret_from_exception
  417. .align 1
  418. do_illegal_opcode_ll:
  419. sub sp, 4
  420. stmts --sp, r0-lr
  421. call save_full_context_ex
  422. mfsr r12, SYSREG_ECR
  423. mov r11, sp
  424. call do_illegal_opcode
  425. rjmp ret_from_exception
  426. do_dtlb_modified:
  427. pushm r0-r3
  428. mfsr r1, SYSREG_TLBEAR
  429. mfsr r0, SYSREG_PTBR
  430. lsr r2, r1, PGDIR_SHIFT
  431. ld.w r0, r0[r2 << 2]
  432. lsl r1, (32 - PGDIR_SHIFT)
  433. lsr r1, (32 - PGDIR_SHIFT) + PAGE_SHIFT
  434. /* Translate to virtual address in P1 */
  435. andl r0, 0xf000
  436. sbr r0, 31
  437. add r2, r0, r1 << 2
  438. ld.w r3, r2[0]
  439. sbr r3, _PAGE_BIT_DIRTY
  440. mov r0, r3
  441. st.w r2[0], r3
  442. /* The page table is up-to-date. Update the TLB entry as well */
  443. andl r0, lo(_PAGE_FLAGS_HARDWARE_MASK)
  444. mtsr SYSREG_TLBELO, r0
  445. /* MMUCR[DRP] is updated automatically, so let's go... */
  446. tlbw
  447. popm r0-r3
  448. rete
  449. do_fpe_ll:
  450. sub sp, 4
  451. stmts --sp, r0-lr
  452. call save_full_context_ex
  453. unmask_interrupts
  454. mov r12, 26
  455. mov r11, sp
  456. call do_fpe
  457. rjmp ret_from_exception
  458. ret_from_exception:
  459. mask_interrupts
  460. lddsp r4, sp[REG_SR]
  461. andh r4, (MODE_MASK >> 16), COH
  462. brne fault_resume_kernel
  463. get_thread_info r0
  464. ld.w r1, r0[TI_flags]
  465. andl r1, _TIF_WORK_MASK, COH
  466. brne fault_exit_work
  467. fault_resume_user:
  468. popm r8-r9
  469. mask_exceptions
  470. mtsr SYSREG_RAR_EX, r8
  471. mtsr SYSREG_RSR_EX, r9
  472. ldmts sp++, r0-lr
  473. sub sp, -4
  474. rete
  475. fault_resume_kernel:
  476. #ifdef CONFIG_PREEMPT
  477. get_thread_info r0
  478. ld.w r2, r0[TI_preempt_count]
  479. cp.w r2, 0
  480. brne 1f
  481. ld.w r1, r0[TI_flags]
  482. bld r1, TIF_NEED_RESCHED
  483. brcc 1f
  484. lddsp r4, sp[REG_SR]
  485. bld r4, SYSREG_GM_OFFSET
  486. brcs 1f
  487. call preempt_schedule_irq
  488. 1:
  489. #endif
  490. popm r8-r9
  491. mask_exceptions
  492. mfsr r1, SYSREG_SR
  493. mtsr SYSREG_RAR_EX, r8
  494. mtsr SYSREG_RSR_EX, r9
  495. popm lr
  496. sub sp, -4 /* ignore SP */
  497. popm r0-r12
  498. sub sp, -4 /* ignore r12_orig */
  499. rete
  500. irq_exit_work:
  501. /* Switch to exception mode so that we can share the same code. */
  502. mfsr r8, SYSREG_SR
  503. cbr r8, SYSREG_M0_OFFSET
  504. orh r8, hi(SYSREG_BIT(M1) | SYSREG_BIT(M2))
  505. mtsr SYSREG_SR, r8
  506. sub pc, -2
  507. get_thread_info r0
  508. ld.w r1, r0[TI_flags]
  509. fault_exit_work:
  510. bld r1, TIF_NEED_RESCHED
  511. brcc 1f
  512. unmask_interrupts
  513. call schedule
  514. mask_interrupts
  515. ld.w r1, r0[TI_flags]
  516. rjmp fault_exit_work
  517. 1: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
  518. tst r1, r2
  519. breq 2f
  520. unmask_interrupts
  521. mov r12, sp
  522. mov r11, r0
  523. call do_notify_resume
  524. mask_interrupts
  525. ld.w r1, r0[TI_flags]
  526. rjmp fault_exit_work
  527. 2: bld r1, TIF_BREAKPOINT
  528. brcc fault_resume_user
  529. rjmp enter_monitor_mode
  530. .section .kprobes.text, "ax", @progbits
  531. .type handle_debug, @function
  532. handle_debug:
  533. sub sp, 4 /* r12_orig */
  534. stmts --sp, r0-lr
  535. mfsr r8, SYSREG_RAR_DBG
  536. mfsr r9, SYSREG_RSR_DBG
  537. unmask_exceptions
  538. pushm r8-r9
  539. bfextu r9, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  540. brne debug_fixup_regs
  541. .Ldebug_fixup_cont:
  542. #ifdef CONFIG_TRACE_IRQFLAGS
  543. call trace_hardirqs_off
  544. #endif
  545. mov r12, sp
  546. call do_debug
  547. mov sp, r12
  548. lddsp r2, sp[REG_SR]
  549. bfextu r3, r2, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  550. brne debug_resume_kernel
  551. get_thread_info r0
  552. ld.w r1, r0[TI_flags]
  553. mov r2, _TIF_DBGWORK_MASK
  554. tst r1, r2
  555. brne debug_exit_work
  556. bld r1, TIF_SINGLE_STEP
  557. brcc 1f
  558. mfdr r4, OCD_DC
  559. sbr r4, OCD_DC_SS_BIT
  560. mtdr OCD_DC, r4
  561. 1: popm r10,r11
  562. mask_exceptions
  563. mtsr SYSREG_RSR_DBG, r11
  564. mtsr SYSREG_RAR_DBG, r10
  565. #ifdef CONFIG_TRACE_IRQFLAGS
  566. call trace_hardirqs_on
  567. 1:
  568. #endif
  569. ldmts sp++, r0-lr
  570. sub sp, -4
  571. retd
  572. .size handle_debug, . - handle_debug
  573. /* Mode of the trapped context is in r9 */
  574. .type debug_fixup_regs, @function
  575. debug_fixup_regs:
  576. mfsr r8, SYSREG_SR
  577. mov r10, r8
  578. bfins r8, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  579. mtsr SYSREG_SR, r8
  580. sub pc, -2
  581. stdsp sp[REG_LR], lr
  582. mtsr SYSREG_SR, r10
  583. sub pc, -2
  584. sub r8, sp, -FRAME_SIZE_FULL
  585. stdsp sp[REG_SP], r8
  586. rjmp .Ldebug_fixup_cont
  587. .size debug_fixup_regs, . - debug_fixup_regs
  588. .type debug_resume_kernel, @function
  589. debug_resume_kernel:
  590. mask_exceptions
  591. popm r10, r11
  592. mtsr SYSREG_RAR_DBG, r10
  593. mtsr SYSREG_RSR_DBG, r11
  594. #ifdef CONFIG_TRACE_IRQFLAGS
  595. bld r11, SYSREG_GM_OFFSET
  596. brcc 1f
  597. call trace_hardirqs_on
  598. 1:
  599. #endif
  600. mfsr r2, SYSREG_SR
  601. mov r1, r2
  602. bfins r2, r3, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  603. mtsr SYSREG_SR, r2
  604. sub pc, -2
  605. popm lr
  606. mtsr SYSREG_SR, r1
  607. sub pc, -2
  608. sub sp, -4 /* skip SP */
  609. popm r0-r12
  610. sub sp, -4
  611. retd
  612. .size debug_resume_kernel, . - debug_resume_kernel
  613. .type debug_exit_work, @function
  614. debug_exit_work:
  615. /*
  616. * We must return from Monitor Mode using a retd, and we must
  617. * not schedule since that involves the D bit in SR getting
  618. * cleared by something other than the debug hardware. This
  619. * may cause undefined behaviour according to the Architecture
  620. * manual.
  621. *
  622. * So we fix up the return address and status and return to a
  623. * stub below in Exception mode. From there, we can follow the
  624. * normal exception return path.
  625. *
  626. * The real return address and status registers are stored on
  627. * the stack in the way the exception return path understands,
  628. * so no need to fix anything up there.
  629. */
  630. sub r8, pc, . - fault_exit_work
  631. mtsr SYSREG_RAR_DBG, r8
  632. mov r9, 0
  633. orh r9, hi(SR_EM | SR_GM | MODE_EXCEPTION)
  634. mtsr SYSREG_RSR_DBG, r9
  635. sub pc, -2
  636. retd
  637. .size debug_exit_work, . - debug_exit_work
  638. .set rsr_int0, SYSREG_RSR_INT0
  639. .set rsr_int1, SYSREG_RSR_INT1
  640. .set rsr_int2, SYSREG_RSR_INT2
  641. .set rsr_int3, SYSREG_RSR_INT3
  642. .set rar_int0, SYSREG_RAR_INT0
  643. .set rar_int1, SYSREG_RAR_INT1
  644. .set rar_int2, SYSREG_RAR_INT2
  645. .set rar_int3, SYSREG_RAR_INT3
  646. .macro IRQ_LEVEL level
  647. .type irq_level\level, @function
  648. irq_level\level:
  649. sub sp, 4 /* r12_orig */
  650. stmts --sp,r0-lr
  651. mfsr r8, rar_int\level
  652. mfsr r9, rsr_int\level
  653. #ifdef CONFIG_PREEMPT
  654. sub r11, pc, (. - system_call)
  655. cp.w r11, r8
  656. breq 4f
  657. #endif
  658. pushm r8-r9
  659. mov r11, sp
  660. mov r12, \level
  661. call do_IRQ
  662. lddsp r4, sp[REG_SR]
  663. bfextu r4, r4, SYSREG_M0_OFFSET, 3
  664. cp.w r4, MODE_SUPERVISOR >> SYSREG_M0_OFFSET
  665. breq 2f
  666. cp.w r4, MODE_USER >> SYSREG_M0_OFFSET
  667. #ifdef CONFIG_PREEMPT
  668. brne 3f
  669. #else
  670. brne 1f
  671. #endif
  672. get_thread_info r0
  673. ld.w r1, r0[TI_flags]
  674. andl r1, _TIF_WORK_MASK, COH
  675. brne irq_exit_work
  676. 1:
  677. #ifdef CONFIG_TRACE_IRQFLAGS
  678. call trace_hardirqs_on
  679. #endif
  680. popm r8-r9
  681. mtsr rar_int\level, r8
  682. mtsr rsr_int\level, r9
  683. ldmts sp++,r0-lr
  684. sub sp, -4 /* ignore r12_orig */
  685. rete
  686. #ifdef CONFIG_PREEMPT
  687. 4: mask_interrupts
  688. mfsr r8, rsr_int\level
  689. sbr r8, 16
  690. mtsr rsr_int\level, r8
  691. ldmts sp++, r0-lr
  692. sub sp, -4 /* ignore r12_orig */
  693. rete
  694. #endif
  695. 2: get_thread_info r0
  696. ld.w r1, r0[TI_flags]
  697. bld r1, TIF_CPU_GOING_TO_SLEEP
  698. #ifdef CONFIG_PREEMPT
  699. brcc 3f
  700. #else
  701. brcc 1b
  702. #endif
  703. sub r1, pc, . - cpu_idle_skip_sleep
  704. stdsp sp[REG_PC], r1
  705. #ifdef CONFIG_PREEMPT
  706. 3: get_thread_info r0
  707. ld.w r2, r0[TI_preempt_count]
  708. cp.w r2, 0
  709. brne 1b
  710. ld.w r1, r0[TI_flags]
  711. bld r1, TIF_NEED_RESCHED
  712. brcc 1b
  713. lddsp r4, sp[REG_SR]
  714. bld r4, SYSREG_GM_OFFSET
  715. brcs 1b
  716. call preempt_schedule_irq
  717. #endif
  718. rjmp 1b
  719. .endm
  720. .section .irq.text,"ax",@progbits
  721. .global irq_level0
  722. .global irq_level1
  723. .global irq_level2
  724. .global irq_level3
  725. IRQ_LEVEL 0
  726. IRQ_LEVEL 1
  727. IRQ_LEVEL 2
  728. IRQ_LEVEL 3
  729. .section .kprobes.text, "ax", @progbits
  730. .type enter_monitor_mode, @function
  731. enter_monitor_mode:
  732. /*
  733. * We need to enter monitor mode to do a single step. The
  734. * monitor code will alter the return address so that we
  735. * return directly to the user instead of returning here.
  736. */
  737. breakpoint
  738. rjmp breakpoint_failed
  739. .size enter_monitor_mode, . - enter_monitor_mode
  740. .type debug_trampoline, @function
  741. .global debug_trampoline
  742. debug_trampoline:
  743. /*
  744. * Save the registers on the stack so that the monitor code
  745. * can find them easily.
  746. */
  747. sub sp, 4 /* r12_orig */
  748. stmts --sp, r0-lr
  749. get_thread_info r0
  750. ld.w r8, r0[TI_rar_saved]
  751. ld.w r9, r0[TI_rsr_saved]
  752. pushm r8-r9
  753. /*
  754. * The monitor code will alter the return address so we don't
  755. * return here.
  756. */
  757. breakpoint
  758. rjmp breakpoint_failed
  759. .size debug_trampoline, . - debug_trampoline
  760. .type breakpoint_failed, @function
  761. breakpoint_failed:
  762. /*
  763. * Something went wrong. Perhaps the debug hardware isn't
  764. * enabled?
  765. */
  766. lda.w r12, msg_breakpoint_failed
  767. mov r11, sp
  768. mov r10, 9 /* SIGKILL */
  769. call die
  770. 1: rjmp 1b
  771. msg_breakpoint_failed:
  772. .asciz "Failed to enter Debug Mode"