entry-avr32b.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. lddpc pc, 2f
  355. .align 2
  356. 1: .asciz "Return from critical exception!"
  357. 2: .long panic
  358. .align 1
  359. do_bus_error_write:
  360. sub sp, 4
  361. stmts --sp, r0-lr
  362. call save_full_context_ex
  363. mov r11, 1
  364. rjmp 1f
  365. do_bus_error_read:
  366. sub sp, 4
  367. stmts --sp, r0-lr
  368. call save_full_context_ex
  369. mov r11, 0
  370. 1: mfsr r12, SYSREG_BEAR
  371. mov r10, sp
  372. call do_bus_error
  373. rjmp ret_from_exception
  374. .align 1
  375. do_nmi_ll:
  376. sub sp, 4
  377. stmts --sp, r0-lr
  378. mfsr r9, SYSREG_RSR_NMI
  379. mfsr r8, SYSREG_RAR_NMI
  380. bfextu r0, r9, MODE_SHIFT, 3
  381. brne 2f
  382. 1: pushm r8, r9 /* PC and SR */
  383. mfsr r12, SYSREG_ECR
  384. mov r11, sp
  385. call do_nmi
  386. popm r8-r9
  387. mtsr SYSREG_RAR_NMI, r8
  388. tst r0, r0
  389. mtsr SYSREG_RSR_NMI, r9
  390. brne 3f
  391. ldmts sp++, r0-lr
  392. sub sp, -4 /* skip r12_orig */
  393. rete
  394. 2: sub r10, sp, -(FRAME_SIZE_FULL - REG_LR)
  395. stdsp sp[4], r10 /* replace saved SP */
  396. rjmp 1b
  397. 3: popm lr
  398. sub sp, -4 /* skip sp */
  399. popm r0-r12
  400. sub sp, -4 /* skip r12_orig */
  401. rete
  402. handle_address_fault:
  403. sub sp, 4
  404. stmts --sp, r0-lr
  405. call save_full_context_ex
  406. mfsr r12, SYSREG_ECR
  407. mov r11, sp
  408. call do_address_exception
  409. rjmp ret_from_exception
  410. handle_protection_fault:
  411. sub sp, 4
  412. stmts --sp, r0-lr
  413. call save_full_context_ex
  414. mfsr r12, SYSREG_ECR
  415. mov r11, sp
  416. call do_page_fault
  417. rjmp ret_from_exception
  418. .align 1
  419. do_illegal_opcode_ll:
  420. sub sp, 4
  421. stmts --sp, r0-lr
  422. call save_full_context_ex
  423. mfsr r12, SYSREG_ECR
  424. mov r11, sp
  425. call do_illegal_opcode
  426. rjmp ret_from_exception
  427. do_dtlb_modified:
  428. pushm r0-r3
  429. mfsr r1, SYSREG_TLBEAR
  430. mfsr r0, SYSREG_PTBR
  431. lsr r2, r1, PGDIR_SHIFT
  432. ld.w r0, r0[r2 << 2]
  433. lsl r1, (32 - PGDIR_SHIFT)
  434. lsr r1, (32 - PGDIR_SHIFT) + PAGE_SHIFT
  435. /* Translate to virtual address in P1 */
  436. andl r0, 0xf000
  437. sbr r0, 31
  438. add r2, r0, r1 << 2
  439. ld.w r3, r2[0]
  440. sbr r3, _PAGE_BIT_DIRTY
  441. mov r0, r3
  442. st.w r2[0], r3
  443. /* The page table is up-to-date. Update the TLB entry as well */
  444. andl r0, lo(_PAGE_FLAGS_HARDWARE_MASK)
  445. mtsr SYSREG_TLBELO, r0
  446. /* MMUCR[DRP] is updated automatically, so let's go... */
  447. tlbw
  448. popm r0-r3
  449. rete
  450. do_fpe_ll:
  451. sub sp, 4
  452. stmts --sp, r0-lr
  453. call save_full_context_ex
  454. unmask_interrupts
  455. mov r12, 26
  456. mov r11, sp
  457. call do_fpe
  458. rjmp ret_from_exception
  459. ret_from_exception:
  460. mask_interrupts
  461. lddsp r4, sp[REG_SR]
  462. andh r4, (MODE_MASK >> 16), COH
  463. brne fault_resume_kernel
  464. get_thread_info r0
  465. ld.w r1, r0[TI_flags]
  466. andl r1, _TIF_WORK_MASK, COH
  467. brne fault_exit_work
  468. fault_resume_user:
  469. popm r8-r9
  470. mask_exceptions
  471. mtsr SYSREG_RAR_EX, r8
  472. mtsr SYSREG_RSR_EX, r9
  473. ldmts sp++, r0-lr
  474. sub sp, -4
  475. rete
  476. fault_resume_kernel:
  477. #ifdef CONFIG_PREEMPT
  478. get_thread_info r0
  479. ld.w r2, r0[TI_preempt_count]
  480. cp.w r2, 0
  481. brne 1f
  482. ld.w r1, r0[TI_flags]
  483. bld r1, TIF_NEED_RESCHED
  484. brcc 1f
  485. lddsp r4, sp[REG_SR]
  486. bld r4, SYSREG_GM_OFFSET
  487. brcs 1f
  488. call preempt_schedule_irq
  489. 1:
  490. #endif
  491. popm r8-r9
  492. mask_exceptions
  493. mfsr r1, SYSREG_SR
  494. mtsr SYSREG_RAR_EX, r8
  495. mtsr SYSREG_RSR_EX, r9
  496. popm lr
  497. sub sp, -4 /* ignore SP */
  498. popm r0-r12
  499. sub sp, -4 /* ignore r12_orig */
  500. rete
  501. irq_exit_work:
  502. /* Switch to exception mode so that we can share the same code. */
  503. mfsr r8, SYSREG_SR
  504. cbr r8, SYSREG_M0_OFFSET
  505. orh r8, hi(SYSREG_BIT(M1) | SYSREG_BIT(M2))
  506. mtsr SYSREG_SR, r8
  507. sub pc, -2
  508. get_thread_info r0
  509. ld.w r1, r0[TI_flags]
  510. fault_exit_work:
  511. bld r1, TIF_NEED_RESCHED
  512. brcc 1f
  513. unmask_interrupts
  514. call schedule
  515. mask_interrupts
  516. ld.w r1, r0[TI_flags]
  517. rjmp fault_exit_work
  518. 1: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
  519. tst r1, r2
  520. breq 2f
  521. unmask_interrupts
  522. mov r12, sp
  523. mov r11, r0
  524. call do_notify_resume
  525. mask_interrupts
  526. ld.w r1, r0[TI_flags]
  527. rjmp fault_exit_work
  528. 2: bld r1, TIF_BREAKPOINT
  529. brcc fault_resume_user
  530. rjmp enter_monitor_mode
  531. .section .kprobes.text, "ax", @progbits
  532. .type handle_debug, @function
  533. handle_debug:
  534. sub sp, 4 /* r12_orig */
  535. stmts --sp, r0-lr
  536. mfsr r8, SYSREG_RAR_DBG
  537. mfsr r9, SYSREG_RSR_DBG
  538. unmask_exceptions
  539. pushm r8-r9
  540. bfextu r9, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  541. brne debug_fixup_regs
  542. .Ldebug_fixup_cont:
  543. #ifdef CONFIG_TRACE_IRQFLAGS
  544. call trace_hardirqs_off
  545. #endif
  546. mov r12, sp
  547. call do_debug
  548. mov sp, r12
  549. lddsp r2, sp[REG_SR]
  550. bfextu r3, r2, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  551. brne debug_resume_kernel
  552. get_thread_info r0
  553. ld.w r1, r0[TI_flags]
  554. mov r2, _TIF_DBGWORK_MASK
  555. tst r1, r2
  556. brne debug_exit_work
  557. bld r1, TIF_SINGLE_STEP
  558. brcc 1f
  559. mfdr r4, OCD_DC
  560. sbr r4, OCD_DC_SS_BIT
  561. mtdr OCD_DC, r4
  562. 1: popm r10,r11
  563. mask_exceptions
  564. mtsr SYSREG_RSR_DBG, r11
  565. mtsr SYSREG_RAR_DBG, r10
  566. #ifdef CONFIG_TRACE_IRQFLAGS
  567. call trace_hardirqs_on
  568. 1:
  569. #endif
  570. ldmts sp++, r0-lr
  571. sub sp, -4
  572. retd
  573. .size handle_debug, . - handle_debug
  574. /* Mode of the trapped context is in r9 */
  575. .type debug_fixup_regs, @function
  576. debug_fixup_regs:
  577. mfsr r8, SYSREG_SR
  578. mov r10, r8
  579. bfins r8, r9, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  580. mtsr SYSREG_SR, r8
  581. sub pc, -2
  582. stdsp sp[REG_LR], lr
  583. mtsr SYSREG_SR, r10
  584. sub pc, -2
  585. sub r8, sp, -FRAME_SIZE_FULL
  586. stdsp sp[REG_SP], r8
  587. rjmp .Ldebug_fixup_cont
  588. .size debug_fixup_regs, . - debug_fixup_regs
  589. .type debug_resume_kernel, @function
  590. debug_resume_kernel:
  591. mask_exceptions
  592. popm r10, r11
  593. mtsr SYSREG_RAR_DBG, r10
  594. mtsr SYSREG_RSR_DBG, r11
  595. #ifdef CONFIG_TRACE_IRQFLAGS
  596. bld r11, SYSREG_GM_OFFSET
  597. brcc 1f
  598. call trace_hardirqs_on
  599. 1:
  600. #endif
  601. mfsr r2, SYSREG_SR
  602. mov r1, r2
  603. bfins r2, r3, SYSREG_MODE_OFFSET, SYSREG_MODE_SIZE
  604. mtsr SYSREG_SR, r2
  605. sub pc, -2
  606. popm lr
  607. mtsr SYSREG_SR, r1
  608. sub pc, -2
  609. sub sp, -4 /* skip SP */
  610. popm r0-r12
  611. sub sp, -4
  612. retd
  613. .size debug_resume_kernel, . - debug_resume_kernel
  614. .type debug_exit_work, @function
  615. debug_exit_work:
  616. /*
  617. * We must return from Monitor Mode using a retd, and we must
  618. * not schedule since that involves the D bit in SR getting
  619. * cleared by something other than the debug hardware. This
  620. * may cause undefined behaviour according to the Architecture
  621. * manual.
  622. *
  623. * So we fix up the return address and status and return to a
  624. * stub below in Exception mode. From there, we can follow the
  625. * normal exception return path.
  626. *
  627. * The real return address and status registers are stored on
  628. * the stack in the way the exception return path understands,
  629. * so no need to fix anything up there.
  630. */
  631. sub r8, pc, . - fault_exit_work
  632. mtsr SYSREG_RAR_DBG, r8
  633. mov r9, 0
  634. orh r9, hi(SR_EM | SR_GM | MODE_EXCEPTION)
  635. mtsr SYSREG_RSR_DBG, r9
  636. sub pc, -2
  637. retd
  638. .size debug_exit_work, . - debug_exit_work
  639. .set rsr_int0, SYSREG_RSR_INT0
  640. .set rsr_int1, SYSREG_RSR_INT1
  641. .set rsr_int2, SYSREG_RSR_INT2
  642. .set rsr_int3, SYSREG_RSR_INT3
  643. .set rar_int0, SYSREG_RAR_INT0
  644. .set rar_int1, SYSREG_RAR_INT1
  645. .set rar_int2, SYSREG_RAR_INT2
  646. .set rar_int3, SYSREG_RAR_INT3
  647. .macro IRQ_LEVEL level
  648. .type irq_level\level, @function
  649. irq_level\level:
  650. sub sp, 4 /* r12_orig */
  651. stmts --sp,r0-lr
  652. mfsr r8, rar_int\level
  653. mfsr r9, rsr_int\level
  654. #ifdef CONFIG_PREEMPT
  655. sub r11, pc, (. - system_call)
  656. cp.w r11, r8
  657. breq 4f
  658. #endif
  659. pushm r8-r9
  660. mov r11, sp
  661. mov r12, \level
  662. call do_IRQ
  663. lddsp r4, sp[REG_SR]
  664. bfextu r4, r4, SYSREG_M0_OFFSET, 3
  665. cp.w r4, MODE_SUPERVISOR >> SYSREG_M0_OFFSET
  666. breq 2f
  667. cp.w r4, MODE_USER >> SYSREG_M0_OFFSET
  668. #ifdef CONFIG_PREEMPT
  669. brne 3f
  670. #else
  671. brne 1f
  672. #endif
  673. get_thread_info r0
  674. ld.w r1, r0[TI_flags]
  675. andl r1, _TIF_WORK_MASK, COH
  676. brne irq_exit_work
  677. 1:
  678. #ifdef CONFIG_TRACE_IRQFLAGS
  679. call trace_hardirqs_on
  680. #endif
  681. popm r8-r9
  682. mtsr rar_int\level, r8
  683. mtsr rsr_int\level, r9
  684. ldmts sp++,r0-lr
  685. sub sp, -4 /* ignore r12_orig */
  686. rete
  687. #ifdef CONFIG_PREEMPT
  688. 4: mask_interrupts
  689. mfsr r8, rsr_int\level
  690. sbr r8, 16
  691. mtsr rsr_int\level, r8
  692. ldmts sp++, r0-lr
  693. sub sp, -4 /* ignore r12_orig */
  694. rete
  695. #endif
  696. 2: get_thread_info r0
  697. ld.w r1, r0[TI_flags]
  698. bld r1, TIF_CPU_GOING_TO_SLEEP
  699. #ifdef CONFIG_PREEMPT
  700. brcc 3f
  701. #else
  702. brcc 1b
  703. #endif
  704. sub r1, pc, . - cpu_idle_skip_sleep
  705. stdsp sp[REG_PC], r1
  706. #ifdef CONFIG_PREEMPT
  707. 3: get_thread_info r0
  708. ld.w r2, r0[TI_preempt_count]
  709. cp.w r2, 0
  710. brne 1b
  711. ld.w r1, r0[TI_flags]
  712. bld r1, TIF_NEED_RESCHED
  713. brcc 1b
  714. lddsp r4, sp[REG_SR]
  715. bld r4, SYSREG_GM_OFFSET
  716. brcs 1b
  717. call preempt_schedule_irq
  718. #endif
  719. rjmp 1b
  720. .endm
  721. .section .irq.text,"ax",@progbits
  722. .global irq_level0
  723. .global irq_level1
  724. .global irq_level2
  725. .global irq_level3
  726. IRQ_LEVEL 0
  727. IRQ_LEVEL 1
  728. IRQ_LEVEL 2
  729. IRQ_LEVEL 3
  730. .section .kprobes.text, "ax", @progbits
  731. .type enter_monitor_mode, @function
  732. enter_monitor_mode:
  733. /*
  734. * We need to enter monitor mode to do a single step. The
  735. * monitor code will alter the return address so that we
  736. * return directly to the user instead of returning here.
  737. */
  738. breakpoint
  739. rjmp breakpoint_failed
  740. .size enter_monitor_mode, . - enter_monitor_mode
  741. .type debug_trampoline, @function
  742. .global debug_trampoline
  743. debug_trampoline:
  744. /*
  745. * Save the registers on the stack so that the monitor code
  746. * can find them easily.
  747. */
  748. sub sp, 4 /* r12_orig */
  749. stmts --sp, r0-lr
  750. get_thread_info r0
  751. ld.w r8, r0[TI_rar_saved]
  752. ld.w r9, r0[TI_rsr_saved]
  753. pushm r8-r9
  754. /*
  755. * The monitor code will alter the return address so we don't
  756. * return here.
  757. */
  758. breakpoint
  759. rjmp breakpoint_failed
  760. .size debug_trampoline, . - debug_trampoline
  761. .type breakpoint_failed, @function
  762. breakpoint_failed:
  763. /*
  764. * Something went wrong. Perhaps the debug hardware isn't
  765. * enabled?
  766. */
  767. lda.w r12, msg_breakpoint_failed
  768. mov r11, sp
  769. mov r10, 9 /* SIGKILL */
  770. call die
  771. 1: rjmp 1b
  772. msg_breakpoint_failed:
  773. .asciz "Failed to enter Debug Mode"