entry.S 17 KB

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