entry-common.S 9.0 KB

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