entry-common.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /*
  2. * linux/arch/arm/kernel/entry-common.S
  3. *
  4. * Copyright (C) 2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <asm/assembler.h>
  11. #include <asm/unistd.h>
  12. #include <asm/ftrace.h>
  13. #include <asm/unwind.h>
  14. #ifdef CONFIG_NEED_RET_TO_USER
  15. #include <mach/entry-macro.S>
  16. #else
  17. .macro arch_ret_to_user, tmp1, tmp2
  18. .endm
  19. #endif
  20. #include "entry-header.S"
  21. .align 5
  22. #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING))
  23. /*
  24. * This is the fast syscall return path. We do as little as possible here,
  25. * such as avoiding writing r0 to the stack. We only use this path if we
  26. * have tracing and context tracking disabled - the overheads from those
  27. * features make this path too inefficient.
  28. */
  29. ret_fast_syscall:
  30. UNWIND(.fnstart )
  31. UNWIND(.cantunwind )
  32. disable_irq_notrace @ disable interrupts
  33. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  34. tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  35. bne fast_work_pending
  36. /* perform architecture specific actions before user return */
  37. arch_ret_to_user r1, lr
  38. restore_user_regs fast = 1, offset = S_OFF
  39. UNWIND(.fnend )
  40. ENDPROC(ret_fast_syscall)
  41. /* Ok, we need to do extra processing, enter the slow path. */
  42. fast_work_pending:
  43. str r0, [sp, #S_R0+S_OFF]! @ returned r0
  44. /* fall through to work_pending */
  45. #else
  46. /*
  47. * The "replacement" ret_fast_syscall for when tracing or context tracking
  48. * is enabled. As we will need to call out to some C functions, we save
  49. * r0 first to avoid needing to save registers around each C function call.
  50. */
  51. ret_fast_syscall:
  52. UNWIND(.fnstart )
  53. UNWIND(.cantunwind )
  54. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  55. disable_irq_notrace @ disable interrupts
  56. ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
  57. tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
  58. beq no_work_pending
  59. UNWIND(.fnend )
  60. ENDPROC(ret_fast_syscall)
  61. /* Slower path - fall through to work_pending */
  62. #endif
  63. tst r1, #_TIF_SYSCALL_WORK
  64. bne __sys_trace_return_nosave
  65. slow_work_pending:
  66. mov r0, sp @ 'regs'
  67. mov r2, why @ 'syscall'
  68. bl do_work_pending
  69. cmp r0, #0
  70. beq no_work_pending
  71. movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
  72. ldmia sp, {r0 - r6} @ have to reload r0 - r6
  73. b local_restart @ ... and off we go
  74. ENDPROC(ret_fast_syscall)
  75. /*
  76. * "slow" syscall return path. "why" tells us if this was a real syscall.
  77. * IRQs may be enabled here, so always disable them. Note that we use the
  78. * "notrace" version to avoid calling into the tracing code unnecessarily.
  79. * do_work_pending() will update this state if necessary.
  80. */
  81. ENTRY(ret_to_user)
  82. ret_slow_syscall:
  83. disable_irq_notrace @ disable interrupts
  84. ENTRY(ret_to_user_from_irq)
  85. ldr r1, [tsk, #TI_FLAGS]
  86. tst r1, #_TIF_WORK_MASK
  87. bne slow_work_pending
  88. no_work_pending:
  89. asm_trace_hardirqs_on save = 0
  90. /* perform architecture specific actions before user return */
  91. arch_ret_to_user r1, lr
  92. ct_user_enter save = 0
  93. restore_user_regs fast = 0, offset = 0
  94. ENDPROC(ret_to_user_from_irq)
  95. ENDPROC(ret_to_user)
  96. /*
  97. * This is how we return from a fork.
  98. */
  99. ENTRY(ret_from_fork)
  100. bl schedule_tail
  101. cmp r5, #0
  102. movne r0, r4
  103. badrne lr, 1f
  104. retne r5
  105. 1: get_thread_info tsk
  106. b ret_slow_syscall
  107. ENDPROC(ret_from_fork)
  108. .equ NR_syscalls,0
  109. #define CALL(x) .equ NR_syscalls,NR_syscalls+1
  110. #include "calls.S"
  111. /*
  112. * Ensure that the system call table is equal to __NR_syscalls,
  113. * which is the value the rest of the system sees
  114. */
  115. .ifne NR_syscalls - __NR_syscalls
  116. .error "__NR_syscalls is not equal to the size of the syscall table"
  117. .endif
  118. #undef CALL
  119. #define CALL(x) .long x
  120. /*=============================================================================
  121. * SWI handler
  122. *-----------------------------------------------------------------------------
  123. */
  124. .align 5
  125. ENTRY(vector_swi)
  126. #ifdef CONFIG_CPU_V7M
  127. v7m_exception_entry
  128. #else
  129. sub sp, sp, #PT_REGS_SIZE
  130. stmia sp, {r0 - r12} @ Calling r0 - r12
  131. ARM( add r8, sp, #S_PC )
  132. ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
  133. THUMB( mov r8, sp )
  134. THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
  135. mrs r8, spsr @ called from non-FIQ mode, so ok.
  136. str lr, [sp, #S_PC] @ Save calling PC
  137. str r8, [sp, #S_PSR] @ Save CPSR
  138. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  139. #endif
  140. zero_fp
  141. alignment_trap r10, ip, __cr_alignment
  142. enable_irq
  143. ct_user_exit
  144. get_thread_info tsk
  145. /*
  146. * Get the system call number.
  147. */
  148. #if defined(CONFIG_OABI_COMPAT)
  149. /*
  150. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  151. * value to determine if it is an EABI or an old ABI call.
  152. */
  153. #ifdef CONFIG_ARM_THUMB
  154. tst r8, #PSR_T_BIT
  155. movne r10, #0 @ no thumb OABI emulation
  156. USER( ldreq r10, [lr, #-4] ) @ get SWI instruction
  157. #else
  158. USER( ldr r10, [lr, #-4] ) @ get SWI instruction
  159. #endif
  160. ARM_BE8(rev r10, r10) @ little endian instruction
  161. #elif defined(CONFIG_AEABI)
  162. /*
  163. * Pure EABI user space always put syscall number into scno (r7).
  164. */
  165. #elif defined(CONFIG_ARM_THUMB)
  166. /* Legacy ABI only, possibly thumb mode. */
  167. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  168. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  169. USER( ldreq scno, [lr, #-4] )
  170. #else
  171. /* Legacy ABI only. */
  172. USER( ldr scno, [lr, #-4] ) @ get SWI instruction
  173. #endif
  174. uaccess_disable tbl
  175. adr tbl, sys_call_table @ load syscall table pointer
  176. #if defined(CONFIG_OABI_COMPAT)
  177. /*
  178. * If the swi argument is zero, this is an EABI call and we do nothing.
  179. *
  180. * If this is an old ABI call, get the syscall number into scno and
  181. * get the old ABI syscall table address.
  182. */
  183. bics r10, r10, #0xff000000
  184. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  185. ldrne tbl, =sys_oabi_call_table
  186. #elif !defined(CONFIG_AEABI)
  187. bic scno, scno, #0xff000000 @ mask off SWI op-code
  188. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  189. #endif
  190. local_restart:
  191. ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
  192. stmdb sp!, {r4, r5} @ push fifth and sixth args
  193. tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
  194. bne __sys_trace
  195. cmp scno, #NR_syscalls @ check upper syscall limit
  196. badr lr, ret_fast_syscall @ return address
  197. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  198. add r1, sp, #S_OFF
  199. 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  200. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  201. bcs arm_syscall
  202. mov why, #0 @ no longer a real syscall
  203. b sys_ni_syscall @ not private func
  204. #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
  205. /*
  206. * We failed to handle a fault trying to access the page
  207. * containing the swi instruction, but we're not really in a
  208. * position to return -EFAULT. Instead, return back to the
  209. * instruction and re-enter the user fault handling path trying
  210. * to page it in. This will likely result in sending SEGV to the
  211. * current task.
  212. */
  213. 9001:
  214. sub lr, lr, #4
  215. str lr, [sp, #S_PC]
  216. b ret_fast_syscall
  217. #endif
  218. ENDPROC(vector_swi)
  219. /*
  220. * This is the really slow path. We're going to be doing
  221. * context switches, and waiting for our parent to respond.
  222. */
  223. __sys_trace:
  224. mov r1, scno
  225. add r0, sp, #S_OFF
  226. bl syscall_trace_enter
  227. badr lr, __sys_trace_return @ return address
  228. mov scno, r0 @ syscall number (possibly new)
  229. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  230. cmp scno, #NR_syscalls @ check upper syscall limit
  231. ldmccia r1, {r0 - r6} @ have to reload r0 - r6
  232. stmccia sp, {r4, r5} @ and update the stack args
  233. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  234. cmp scno, #-1 @ skip the syscall?
  235. bne 2b
  236. add sp, sp, #S_OFF @ restore stack
  237. b ret_slow_syscall
  238. __sys_trace_return:
  239. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  240. mov r0, sp
  241. bl syscall_trace_exit
  242. b ret_slow_syscall
  243. __sys_trace_return_nosave:
  244. enable_irq_notrace
  245. mov r0, sp
  246. bl syscall_trace_exit
  247. b ret_slow_syscall
  248. .align 5
  249. #ifdef CONFIG_ALIGNMENT_TRAP
  250. .type __cr_alignment, #object
  251. __cr_alignment:
  252. .word cr_alignment
  253. #endif
  254. .ltorg
  255. /*
  256. * This is the syscall table declaration for native ABI syscalls.
  257. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  258. */
  259. #define ABI(native, compat) native
  260. #ifdef CONFIG_AEABI
  261. #define OBSOLETE(syscall) sys_ni_syscall
  262. #else
  263. #define OBSOLETE(syscall) syscall
  264. #endif
  265. .type sys_call_table, #object
  266. ENTRY(sys_call_table)
  267. #include "calls.S"
  268. #undef ABI
  269. #undef OBSOLETE
  270. /*============================================================================
  271. * Special system call wrappers
  272. */
  273. @ r0 = syscall number
  274. @ r8 = syscall table
  275. sys_syscall:
  276. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  277. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  278. cmpne scno, #NR_syscalls @ check range
  279. stmloia sp, {r5, r6} @ shuffle args
  280. movlo r0, r1
  281. movlo r1, r2
  282. movlo r2, r3
  283. movlo r3, r4
  284. ldrlo pc, [tbl, scno, lsl #2]
  285. b sys_ni_syscall
  286. ENDPROC(sys_syscall)
  287. sys_sigreturn_wrapper:
  288. add r0, sp, #S_OFF
  289. mov why, #0 @ prevent syscall restart handling
  290. b sys_sigreturn
  291. ENDPROC(sys_sigreturn_wrapper)
  292. sys_rt_sigreturn_wrapper:
  293. add r0, sp, #S_OFF
  294. mov why, #0 @ prevent syscall restart handling
  295. b sys_rt_sigreturn
  296. ENDPROC(sys_rt_sigreturn_wrapper)
  297. sys_statfs64_wrapper:
  298. teq r1, #88
  299. moveq r1, #84
  300. b sys_statfs64
  301. ENDPROC(sys_statfs64_wrapper)
  302. sys_fstatfs64_wrapper:
  303. teq r1, #88
  304. moveq r1, #84
  305. b sys_fstatfs64
  306. ENDPROC(sys_fstatfs64_wrapper)
  307. /*
  308. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  309. * offset, we return EINVAL.
  310. */
  311. sys_mmap2:
  312. #if PAGE_SHIFT > 12
  313. tst r5, #PGOFF_MASK
  314. moveq r5, r5, lsr #PAGE_SHIFT - 12
  315. streq r5, [sp, #4]
  316. beq sys_mmap_pgoff
  317. mov r0, #-EINVAL
  318. ret lr
  319. #else
  320. str r5, [sp, #4]
  321. b sys_mmap_pgoff
  322. #endif
  323. ENDPROC(sys_mmap2)
  324. #ifdef CONFIG_OABI_COMPAT
  325. /*
  326. * These are syscalls with argument register differences
  327. */
  328. sys_oabi_pread64:
  329. stmia sp, {r3, r4}
  330. b sys_pread64
  331. ENDPROC(sys_oabi_pread64)
  332. sys_oabi_pwrite64:
  333. stmia sp, {r3, r4}
  334. b sys_pwrite64
  335. ENDPROC(sys_oabi_pwrite64)
  336. sys_oabi_truncate64:
  337. mov r3, r2
  338. mov r2, r1
  339. b sys_truncate64
  340. ENDPROC(sys_oabi_truncate64)
  341. sys_oabi_ftruncate64:
  342. mov r3, r2
  343. mov r2, r1
  344. b sys_ftruncate64
  345. ENDPROC(sys_oabi_ftruncate64)
  346. sys_oabi_readahead:
  347. str r3, [sp]
  348. mov r3, r2
  349. mov r2, r1
  350. b sys_readahead
  351. ENDPROC(sys_oabi_readahead)
  352. /*
  353. * Let's declare a second syscall table for old ABI binaries
  354. * using the compatibility syscall entries.
  355. */
  356. #define ABI(native, compat) compat
  357. #define OBSOLETE(syscall) syscall
  358. .type sys_oabi_call_table, #object
  359. ENTRY(sys_oabi_call_table)
  360. #include "calls.S"
  361. #undef ABI
  362. #undef OBSOLETE
  363. #endif