entry-common.S 9.1 KB

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