entry-common.S 11 KB

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