entry.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Low-level exception handling code
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Authors: Catalin Marinas <catalin.marinas@arm.com>
  6. * Will Deacon <will.deacon@arm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/linkage.h>
  22. #include <asm/assembler.h>
  23. #include <asm/asm-offsets.h>
  24. #include <asm/errno.h>
  25. #include <asm/esr.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/unistd.h>
  28. /*
  29. * Context tracking subsystem. Used to instrument transitions
  30. * between user and kernel mode.
  31. */
  32. .macro ct_user_exit, syscall = 0
  33. #ifdef CONFIG_CONTEXT_TRACKING
  34. bl context_tracking_user_exit
  35. .if \syscall == 1
  36. /*
  37. * Save/restore needed during syscalls. Restore syscall arguments from
  38. * the values already saved on stack during kernel_entry.
  39. */
  40. ldp x0, x1, [sp]
  41. ldp x2, x3, [sp, #S_X2]
  42. ldp x4, x5, [sp, #S_X4]
  43. ldp x6, x7, [sp, #S_X6]
  44. .endif
  45. #endif
  46. .endm
  47. .macro ct_user_enter
  48. #ifdef CONFIG_CONTEXT_TRACKING
  49. bl context_tracking_user_enter
  50. #endif
  51. .endm
  52. /*
  53. * Bad Abort numbers
  54. *-----------------
  55. */
  56. #define BAD_SYNC 0
  57. #define BAD_IRQ 1
  58. #define BAD_FIQ 2
  59. #define BAD_ERROR 3
  60. .macro kernel_entry, el, regsize = 64
  61. sub sp, sp, #S_FRAME_SIZE
  62. .if \regsize == 32
  63. mov w0, w0 // zero upper 32 bits of x0
  64. .endif
  65. stp x0, x1, [sp, #16 * 0]
  66. stp x2, x3, [sp, #16 * 1]
  67. stp x4, x5, [sp, #16 * 2]
  68. stp x6, x7, [sp, #16 * 3]
  69. stp x8, x9, [sp, #16 * 4]
  70. stp x10, x11, [sp, #16 * 5]
  71. stp x12, x13, [sp, #16 * 6]
  72. stp x14, x15, [sp, #16 * 7]
  73. stp x16, x17, [sp, #16 * 8]
  74. stp x18, x19, [sp, #16 * 9]
  75. stp x20, x21, [sp, #16 * 10]
  76. stp x22, x23, [sp, #16 * 11]
  77. stp x24, x25, [sp, #16 * 12]
  78. stp x26, x27, [sp, #16 * 13]
  79. stp x28, x29, [sp, #16 * 14]
  80. .if \el == 0
  81. mrs x21, sp_el0
  82. get_thread_info tsk // Ensure MDSCR_EL1.SS is clear,
  83. ldr x19, [tsk, #TI_FLAGS] // since we can unmask debug
  84. disable_step_tsk x19, x20 // exceptions when scheduling.
  85. .else
  86. add x21, sp, #S_FRAME_SIZE
  87. .endif
  88. mrs x22, elr_el1
  89. mrs x23, spsr_el1
  90. stp lr, x21, [sp, #S_LR]
  91. stp x22, x23, [sp, #S_PC]
  92. /*
  93. * Set syscallno to -1 by default (overridden later if real syscall).
  94. */
  95. .if \el == 0
  96. mvn x21, xzr
  97. str x21, [sp, #S_SYSCALLNO]
  98. .endif
  99. /*
  100. * Registers that may be useful after this macro is invoked:
  101. *
  102. * x21 - aborted SP
  103. * x22 - aborted PC
  104. * x23 - aborted PSTATE
  105. */
  106. .endm
  107. .macro kernel_exit, el, ret = 0
  108. ldp x21, x22, [sp, #S_PC] // load ELR, SPSR
  109. .if \el == 0
  110. ct_user_enter
  111. ldr x23, [sp, #S_SP] // load return stack pointer
  112. msr sp_el0, x23
  113. .endif
  114. msr elr_el1, x21 // set up the return data
  115. msr spsr_el1, x22
  116. .if \ret
  117. ldr x1, [sp, #S_X1] // preserve x0 (syscall return)
  118. .else
  119. ldp x0, x1, [sp, #16 * 0]
  120. .endif
  121. ldp x2, x3, [sp, #16 * 1]
  122. ldp x4, x5, [sp, #16 * 2]
  123. ldp x6, x7, [sp, #16 * 3]
  124. ldp x8, x9, [sp, #16 * 4]
  125. ldp x10, x11, [sp, #16 * 5]
  126. ldp x12, x13, [sp, #16 * 6]
  127. ldp x14, x15, [sp, #16 * 7]
  128. ldp x16, x17, [sp, #16 * 8]
  129. ldp x18, x19, [sp, #16 * 9]
  130. ldp x20, x21, [sp, #16 * 10]
  131. ldp x22, x23, [sp, #16 * 11]
  132. ldp x24, x25, [sp, #16 * 12]
  133. ldp x26, x27, [sp, #16 * 13]
  134. ldp x28, x29, [sp, #16 * 14]
  135. ldr lr, [sp, #S_LR]
  136. add sp, sp, #S_FRAME_SIZE // restore sp
  137. eret // return to kernel
  138. .endm
  139. .macro get_thread_info, rd
  140. mov \rd, sp
  141. and \rd, \rd, #~(THREAD_SIZE - 1) // top of stack
  142. .endm
  143. /*
  144. * These are the registers used in the syscall handler, and allow us to
  145. * have in theory up to 7 arguments to a function - x0 to x6.
  146. *
  147. * x7 is reserved for the system call number in 32-bit mode.
  148. */
  149. sc_nr .req x25 // number of system calls
  150. scno .req x26 // syscall number
  151. stbl .req x27 // syscall table pointer
  152. tsk .req x28 // current thread_info
  153. /*
  154. * Interrupt handling.
  155. */
  156. .macro irq_handler
  157. adrp x1, handle_arch_irq
  158. ldr x1, [x1, #:lo12:handle_arch_irq]
  159. mov x0, sp
  160. blr x1
  161. .endm
  162. .text
  163. /*
  164. * Exception vectors.
  165. */
  166. .align 11
  167. ENTRY(vectors)
  168. ventry el1_sync_invalid // Synchronous EL1t
  169. ventry el1_irq_invalid // IRQ EL1t
  170. ventry el1_fiq_invalid // FIQ EL1t
  171. ventry el1_error_invalid // Error EL1t
  172. ventry el1_sync // Synchronous EL1h
  173. ventry el1_irq // IRQ EL1h
  174. ventry el1_fiq_invalid // FIQ EL1h
  175. ventry el1_error_invalid // Error EL1h
  176. ventry el0_sync // Synchronous 64-bit EL0
  177. ventry el0_irq // IRQ 64-bit EL0
  178. ventry el0_fiq_invalid // FIQ 64-bit EL0
  179. ventry el0_error_invalid // Error 64-bit EL0
  180. #ifdef CONFIG_COMPAT
  181. ventry el0_sync_compat // Synchronous 32-bit EL0
  182. ventry el0_irq_compat // IRQ 32-bit EL0
  183. ventry el0_fiq_invalid_compat // FIQ 32-bit EL0
  184. ventry el0_error_invalid_compat // Error 32-bit EL0
  185. #else
  186. ventry el0_sync_invalid // Synchronous 32-bit EL0
  187. ventry el0_irq_invalid // IRQ 32-bit EL0
  188. ventry el0_fiq_invalid // FIQ 32-bit EL0
  189. ventry el0_error_invalid // Error 32-bit EL0
  190. #endif
  191. END(vectors)
  192. /*
  193. * Invalid mode handlers
  194. */
  195. .macro inv_entry, el, reason, regsize = 64
  196. kernel_entry el, \regsize
  197. mov x0, sp
  198. mov x1, #\reason
  199. mrs x2, esr_el1
  200. b bad_mode
  201. .endm
  202. el0_sync_invalid:
  203. inv_entry 0, BAD_SYNC
  204. ENDPROC(el0_sync_invalid)
  205. el0_irq_invalid:
  206. inv_entry 0, BAD_IRQ
  207. ENDPROC(el0_irq_invalid)
  208. el0_fiq_invalid:
  209. inv_entry 0, BAD_FIQ
  210. ENDPROC(el0_fiq_invalid)
  211. el0_error_invalid:
  212. inv_entry 0, BAD_ERROR
  213. ENDPROC(el0_error_invalid)
  214. #ifdef CONFIG_COMPAT
  215. el0_fiq_invalid_compat:
  216. inv_entry 0, BAD_FIQ, 32
  217. ENDPROC(el0_fiq_invalid_compat)
  218. el0_error_invalid_compat:
  219. inv_entry 0, BAD_ERROR, 32
  220. ENDPROC(el0_error_invalid_compat)
  221. #endif
  222. el1_sync_invalid:
  223. inv_entry 1, BAD_SYNC
  224. ENDPROC(el1_sync_invalid)
  225. el1_irq_invalid:
  226. inv_entry 1, BAD_IRQ
  227. ENDPROC(el1_irq_invalid)
  228. el1_fiq_invalid:
  229. inv_entry 1, BAD_FIQ
  230. ENDPROC(el1_fiq_invalid)
  231. el1_error_invalid:
  232. inv_entry 1, BAD_ERROR
  233. ENDPROC(el1_error_invalid)
  234. /*
  235. * EL1 mode handlers.
  236. */
  237. .align 6
  238. el1_sync:
  239. kernel_entry 1
  240. mrs x1, esr_el1 // read the syndrome register
  241. lsr x24, x1, #ESR_EL1_EC_SHIFT // exception class
  242. cmp x24, #ESR_EL1_EC_DABT_EL1 // data abort in EL1
  243. b.eq el1_da
  244. cmp x24, #ESR_EL1_EC_SYS64 // configurable trap
  245. b.eq el1_undef
  246. cmp x24, #ESR_EL1_EC_SP_ALIGN // stack alignment exception
  247. b.eq el1_sp_pc
  248. cmp x24, #ESR_EL1_EC_PC_ALIGN // pc alignment exception
  249. b.eq el1_sp_pc
  250. cmp x24, #ESR_EL1_EC_UNKNOWN // unknown exception in EL1
  251. b.eq el1_undef
  252. cmp x24, #ESR_EL1_EC_BREAKPT_EL1 // debug exception in EL1
  253. b.ge el1_dbg
  254. b el1_inv
  255. el1_da:
  256. /*
  257. * Data abort handling
  258. */
  259. mrs x0, far_el1
  260. enable_dbg
  261. // re-enable interrupts if they were enabled in the aborted context
  262. tbnz x23, #7, 1f // PSR_I_BIT
  263. enable_irq
  264. 1:
  265. mov x2, sp // struct pt_regs
  266. bl do_mem_abort
  267. // disable interrupts before pulling preserved data off the stack
  268. disable_irq
  269. kernel_exit 1
  270. el1_sp_pc:
  271. /*
  272. * Stack or PC alignment exception handling
  273. */
  274. mrs x0, far_el1
  275. enable_dbg
  276. mov x2, sp
  277. b do_sp_pc_abort
  278. el1_undef:
  279. /*
  280. * Undefined instruction
  281. */
  282. enable_dbg
  283. mov x0, sp
  284. b do_undefinstr
  285. el1_dbg:
  286. /*
  287. * Debug exception handling
  288. */
  289. cmp x24, #ESR_EL1_EC_BRK64 // if BRK64
  290. cinc x24, x24, eq // set bit '0'
  291. tbz x24, #0, el1_inv // EL1 only
  292. mrs x0, far_el1
  293. mov x2, sp // struct pt_regs
  294. bl do_debug_exception
  295. kernel_exit 1
  296. el1_inv:
  297. // TODO: add support for undefined instructions in kernel mode
  298. enable_dbg
  299. mov x0, sp
  300. mov x1, #BAD_SYNC
  301. mrs x2, esr_el1
  302. b bad_mode
  303. ENDPROC(el1_sync)
  304. .align 6
  305. el1_irq:
  306. kernel_entry 1
  307. enable_dbg
  308. #ifdef CONFIG_TRACE_IRQFLAGS
  309. bl trace_hardirqs_off
  310. #endif
  311. irq_handler
  312. #ifdef CONFIG_PREEMPT
  313. get_thread_info tsk
  314. ldr w24, [tsk, #TI_PREEMPT] // get preempt count
  315. cbnz w24, 1f // preempt count != 0
  316. ldr x0, [tsk, #TI_FLAGS] // get flags
  317. tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  318. bl el1_preempt
  319. 1:
  320. #endif
  321. #ifdef CONFIG_TRACE_IRQFLAGS
  322. bl trace_hardirqs_on
  323. #endif
  324. kernel_exit 1
  325. ENDPROC(el1_irq)
  326. #ifdef CONFIG_PREEMPT
  327. el1_preempt:
  328. mov x24, lr
  329. 1: bl preempt_schedule_irq // irq en/disable is done inside
  330. ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
  331. tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
  332. ret x24
  333. #endif
  334. /*
  335. * EL0 mode handlers.
  336. */
  337. .align 6
  338. el0_sync:
  339. kernel_entry 0
  340. mrs x25, esr_el1 // read the syndrome register
  341. lsr x24, x25, #ESR_EL1_EC_SHIFT // exception class
  342. cmp x24, #ESR_EL1_EC_SVC64 // SVC in 64-bit state
  343. b.eq el0_svc
  344. cmp x24, #ESR_EL1_EC_DABT_EL0 // data abort in EL0
  345. b.eq el0_da
  346. cmp x24, #ESR_EL1_EC_IABT_EL0 // instruction abort in EL0
  347. b.eq el0_ia
  348. cmp x24, #ESR_EL1_EC_FP_ASIMD // FP/ASIMD access
  349. b.eq el0_fpsimd_acc
  350. cmp x24, #ESR_EL1_EC_FP_EXC64 // FP/ASIMD exception
  351. b.eq el0_fpsimd_exc
  352. cmp x24, #ESR_EL1_EC_SYS64 // configurable trap
  353. b.eq el0_undef
  354. cmp x24, #ESR_EL1_EC_SP_ALIGN // stack alignment exception
  355. b.eq el0_sp_pc
  356. cmp x24, #ESR_EL1_EC_PC_ALIGN // pc alignment exception
  357. b.eq el0_sp_pc
  358. cmp x24, #ESR_EL1_EC_UNKNOWN // unknown exception in EL0
  359. b.eq el0_undef
  360. cmp x24, #ESR_EL1_EC_BREAKPT_EL0 // debug exception in EL0
  361. b.ge el0_dbg
  362. b el0_inv
  363. #ifdef CONFIG_COMPAT
  364. .align 6
  365. el0_sync_compat:
  366. kernel_entry 0, 32
  367. mrs x25, esr_el1 // read the syndrome register
  368. lsr x24, x25, #ESR_EL1_EC_SHIFT // exception class
  369. cmp x24, #ESR_EL1_EC_SVC32 // SVC in 32-bit state
  370. b.eq el0_svc_compat
  371. cmp x24, #ESR_EL1_EC_DABT_EL0 // data abort in EL0
  372. b.eq el0_da
  373. cmp x24, #ESR_EL1_EC_IABT_EL0 // instruction abort in EL0
  374. b.eq el0_ia
  375. cmp x24, #ESR_EL1_EC_FP_ASIMD // FP/ASIMD access
  376. b.eq el0_fpsimd_acc
  377. cmp x24, #ESR_EL1_EC_FP_EXC32 // FP/ASIMD exception
  378. b.eq el0_fpsimd_exc
  379. cmp x24, #ESR_EL1_EC_UNKNOWN // unknown exception in EL0
  380. b.eq el0_undef
  381. cmp x24, #ESR_EL1_EC_CP15_32 // CP15 MRC/MCR trap
  382. b.eq el0_undef
  383. cmp x24, #ESR_EL1_EC_CP15_64 // CP15 MRRC/MCRR trap
  384. b.eq el0_undef
  385. cmp x24, #ESR_EL1_EC_CP14_MR // CP14 MRC/MCR trap
  386. b.eq el0_undef
  387. cmp x24, #ESR_EL1_EC_CP14_LS // CP14 LDC/STC trap
  388. b.eq el0_undef
  389. cmp x24, #ESR_EL1_EC_CP14_64 // CP14 MRRC/MCRR trap
  390. b.eq el0_undef
  391. cmp x24, #ESR_EL1_EC_BREAKPT_EL0 // debug exception in EL0
  392. b.ge el0_dbg
  393. b el0_inv
  394. el0_svc_compat:
  395. /*
  396. * AArch32 syscall handling
  397. */
  398. adr stbl, compat_sys_call_table // load compat syscall table pointer
  399. uxtw scno, w7 // syscall number in w7 (r7)
  400. mov sc_nr, #__NR_compat_syscalls
  401. b el0_svc_naked
  402. .align 6
  403. el0_irq_compat:
  404. kernel_entry 0, 32
  405. b el0_irq_naked
  406. #endif
  407. el0_da:
  408. /*
  409. * Data abort handling
  410. */
  411. mrs x26, far_el1
  412. // enable interrupts before calling the main handler
  413. enable_dbg_and_irq
  414. ct_user_exit
  415. bic x0, x26, #(0xff << 56)
  416. mov x1, x25
  417. mov x2, sp
  418. bl do_mem_abort
  419. b ret_to_user
  420. el0_ia:
  421. /*
  422. * Instruction abort handling
  423. */
  424. mrs x26, far_el1
  425. // enable interrupts before calling the main handler
  426. enable_dbg_and_irq
  427. ct_user_exit
  428. mov x0, x26
  429. orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts
  430. mov x2, sp
  431. bl do_mem_abort
  432. b ret_to_user
  433. el0_fpsimd_acc:
  434. /*
  435. * Floating Point or Advanced SIMD access
  436. */
  437. enable_dbg
  438. ct_user_exit
  439. mov x0, x25
  440. mov x1, sp
  441. bl do_fpsimd_acc
  442. b ret_to_user
  443. el0_fpsimd_exc:
  444. /*
  445. * Floating Point or Advanced SIMD exception
  446. */
  447. enable_dbg
  448. ct_user_exit
  449. mov x0, x25
  450. mov x1, sp
  451. bl do_fpsimd_exc
  452. b ret_to_user
  453. el0_sp_pc:
  454. /*
  455. * Stack or PC alignment exception handling
  456. */
  457. mrs x26, far_el1
  458. // enable interrupts before calling the main handler
  459. enable_dbg_and_irq
  460. mov x0, x26
  461. mov x1, x25
  462. mov x2, sp
  463. bl do_sp_pc_abort
  464. b ret_to_user
  465. el0_undef:
  466. /*
  467. * Undefined instruction
  468. */
  469. // enable interrupts before calling the main handler
  470. enable_dbg_and_irq
  471. ct_user_exit
  472. mov x0, sp
  473. bl do_undefinstr
  474. b ret_to_user
  475. el0_dbg:
  476. /*
  477. * Debug exception handling
  478. */
  479. tbnz x24, #0, el0_inv // EL0 only
  480. mrs x0, far_el1
  481. mov x1, x25
  482. mov x2, sp
  483. bl do_debug_exception
  484. enable_dbg
  485. ct_user_exit
  486. b ret_to_user
  487. el0_inv:
  488. enable_dbg
  489. ct_user_exit
  490. mov x0, sp
  491. mov x1, #BAD_SYNC
  492. mrs x2, esr_el1
  493. bl bad_mode
  494. b ret_to_user
  495. ENDPROC(el0_sync)
  496. .align 6
  497. el0_irq:
  498. kernel_entry 0
  499. el0_irq_naked:
  500. enable_dbg
  501. #ifdef CONFIG_TRACE_IRQFLAGS
  502. bl trace_hardirqs_off
  503. #endif
  504. ct_user_exit
  505. irq_handler
  506. #ifdef CONFIG_TRACE_IRQFLAGS
  507. bl trace_hardirqs_on
  508. #endif
  509. b ret_to_user
  510. ENDPROC(el0_irq)
  511. /*
  512. * Register switch for AArch64. The callee-saved registers need to be saved
  513. * and restored. On entry:
  514. * x0 = previous task_struct (must be preserved across the switch)
  515. * x1 = next task_struct
  516. * Previous and next are guaranteed not to be the same.
  517. *
  518. */
  519. ENTRY(cpu_switch_to)
  520. add x8, x0, #THREAD_CPU_CONTEXT
  521. mov x9, sp
  522. stp x19, x20, [x8], #16 // store callee-saved registers
  523. stp x21, x22, [x8], #16
  524. stp x23, x24, [x8], #16
  525. stp x25, x26, [x8], #16
  526. stp x27, x28, [x8], #16
  527. stp x29, x9, [x8], #16
  528. str lr, [x8]
  529. add x8, x1, #THREAD_CPU_CONTEXT
  530. ldp x19, x20, [x8], #16 // restore callee-saved registers
  531. ldp x21, x22, [x8], #16
  532. ldp x23, x24, [x8], #16
  533. ldp x25, x26, [x8], #16
  534. ldp x27, x28, [x8], #16
  535. ldp x29, x9, [x8], #16
  536. ldr lr, [x8]
  537. mov sp, x9
  538. ret
  539. ENDPROC(cpu_switch_to)
  540. /*
  541. * This is the fast syscall return path. We do as little as possible here,
  542. * and this includes saving x0 back into the kernel stack.
  543. */
  544. ret_fast_syscall:
  545. disable_irq // disable interrupts
  546. ldr x1, [tsk, #TI_FLAGS]
  547. and x2, x1, #_TIF_WORK_MASK
  548. cbnz x2, fast_work_pending
  549. enable_step_tsk x1, x2
  550. kernel_exit 0, ret = 1
  551. /*
  552. * Ok, we need to do extra processing, enter the slow path.
  553. */
  554. fast_work_pending:
  555. str x0, [sp, #S_X0] // returned x0
  556. work_pending:
  557. tbnz x1, #TIF_NEED_RESCHED, work_resched
  558. /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */
  559. ldr x2, [sp, #S_PSTATE]
  560. mov x0, sp // 'regs'
  561. tst x2, #PSR_MODE_MASK // user mode regs?
  562. b.ne no_work_pending // returning to kernel
  563. enable_irq // enable interrupts for do_notify_resume()
  564. bl do_notify_resume
  565. b ret_to_user
  566. work_resched:
  567. bl schedule
  568. /*
  569. * "slow" syscall return path.
  570. */
  571. ret_to_user:
  572. disable_irq // disable interrupts
  573. ldr x1, [tsk, #TI_FLAGS]
  574. and x2, x1, #_TIF_WORK_MASK
  575. cbnz x2, work_pending
  576. enable_step_tsk x1, x2
  577. no_work_pending:
  578. kernel_exit 0, ret = 0
  579. ENDPROC(ret_to_user)
  580. /*
  581. * This is how we return from a fork.
  582. */
  583. ENTRY(ret_from_fork)
  584. bl schedule_tail
  585. cbz x19, 1f // not a kernel thread
  586. mov x0, x20
  587. blr x19
  588. 1: get_thread_info tsk
  589. b ret_to_user
  590. ENDPROC(ret_from_fork)
  591. /*
  592. * SVC handler.
  593. */
  594. .align 6
  595. el0_svc:
  596. adrp stbl, sys_call_table // load syscall table pointer
  597. uxtw scno, w8 // syscall number in w8
  598. mov sc_nr, #__NR_syscalls
  599. el0_svc_naked: // compat entry point
  600. stp x0, scno, [sp, #S_ORIG_X0] // save the original x0 and syscall number
  601. enable_dbg_and_irq
  602. ct_user_exit 1
  603. ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks
  604. tst x16, #_TIF_SYSCALL_WORK
  605. b.ne __sys_trace
  606. cmp scno, sc_nr // check upper syscall limit
  607. b.hs ni_sys
  608. ldr x16, [stbl, scno, lsl #3] // address in the syscall table
  609. blr x16 // call sys_* routine
  610. b ret_fast_syscall
  611. ni_sys:
  612. mov x0, sp
  613. bl do_ni_syscall
  614. b ret_fast_syscall
  615. ENDPROC(el0_svc)
  616. /*
  617. * This is the really slow path. We're going to be doing context
  618. * switches, and waiting for our parent to respond.
  619. */
  620. __sys_trace:
  621. mov w0, #-1 // set default errno for
  622. cmp scno, x0 // user-issued syscall(-1)
  623. b.ne 1f
  624. mov x0, #-ENOSYS
  625. str x0, [sp, #S_X0]
  626. 1: mov x0, sp
  627. bl syscall_trace_enter
  628. cmp w0, #-1 // skip the syscall?
  629. b.eq __sys_trace_return_skipped
  630. uxtw scno, w0 // syscall number (possibly new)
  631. mov x1, sp // pointer to regs
  632. cmp scno, sc_nr // check upper syscall limit
  633. b.hs __ni_sys_trace
  634. ldp x0, x1, [sp] // restore the syscall args
  635. ldp x2, x3, [sp, #S_X2]
  636. ldp x4, x5, [sp, #S_X4]
  637. ldp x6, x7, [sp, #S_X6]
  638. ldr x16, [stbl, scno, lsl #3] // address in the syscall table
  639. blr x16 // call sys_* routine
  640. __sys_trace_return:
  641. str x0, [sp, #S_X0] // save returned x0
  642. __sys_trace_return_skipped:
  643. mov x0, sp
  644. bl syscall_trace_exit
  645. b ret_to_user
  646. __ni_sys_trace:
  647. mov x0, sp
  648. bl do_ni_syscall
  649. b __sys_trace_return
  650. /*
  651. * Special system call wrappers.
  652. */
  653. ENTRY(sys_rt_sigreturn_wrapper)
  654. mov x0, sp
  655. b sys_rt_sigreturn
  656. ENDPROC(sys_rt_sigreturn_wrapper)