entry-common.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 <linux/config.h>
  11. #include <asm/unistd.h>
  12. #include "entry-header.S"
  13. .align 5
  14. /*
  15. * This is the fast syscall return path. We do as little as
  16. * possible here, and this includes saving r0 back into the SVC
  17. * stack.
  18. */
  19. ret_fast_syscall:
  20. disable_irq @ disable interrupts
  21. ldr r1, [tsk, #TI_FLAGS]
  22. tst r1, #_TIF_WORK_MASK
  23. bne fast_work_pending
  24. @ fast_restore_user_regs
  25. ldr r1, [sp, #S_OFF + S_PSR] @ get calling cpsr
  26. ldr lr, [sp, #S_OFF + S_PC]! @ get pc
  27. msr spsr_cxsf, r1 @ save in spsr_svc
  28. ldmdb sp, {r1 - lr}^ @ get calling r1 - lr
  29. mov r0, r0
  30. add sp, sp, #S_FRAME_SIZE - S_PC
  31. movs pc, lr @ return & move spsr_svc into cpsr
  32. /*
  33. * Ok, we need to do extra processing, enter the slow path.
  34. */
  35. fast_work_pending:
  36. str r0, [sp, #S_R0+S_OFF]! @ returned r0
  37. work_pending:
  38. tst r1, #_TIF_NEED_RESCHED
  39. bne work_resched
  40. tst r1, #_TIF_NOTIFY_RESUME | _TIF_SIGPENDING
  41. beq no_work_pending
  42. mov r0, sp @ 'regs'
  43. mov r2, why @ 'syscall'
  44. bl do_notify_resume
  45. b ret_slow_syscall @ Check work again
  46. work_resched:
  47. bl schedule
  48. /*
  49. * "slow" syscall return path. "why" tells us if this was a real syscall.
  50. */
  51. ENTRY(ret_to_user)
  52. ret_slow_syscall:
  53. disable_irq @ disable interrupts
  54. ldr r1, [tsk, #TI_FLAGS]
  55. tst r1, #_TIF_WORK_MASK
  56. bne work_pending
  57. no_work_pending:
  58. @ slow_restore_user_regs
  59. ldr r1, [sp, #S_PSR] @ get calling cpsr
  60. ldr lr, [sp, #S_PC]! @ get pc
  61. msr spsr_cxsf, r1 @ save in spsr_svc
  62. ldmdb sp, {r0 - lr}^ @ get calling r1 - lr
  63. mov r0, r0
  64. add sp, sp, #S_FRAME_SIZE - S_PC
  65. movs pc, lr @ return & move spsr_svc into cpsr
  66. /*
  67. * This is how we return from a fork.
  68. */
  69. ENTRY(ret_from_fork)
  70. bl schedule_tail
  71. get_thread_info tsk
  72. ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
  73. mov why, #1
  74. tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  75. beq ret_slow_syscall
  76. mov r1, sp
  77. mov r0, #1 @ trace exit [IP = 1]
  78. bl syscall_trace
  79. b ret_slow_syscall
  80. #include "calls.S"
  81. /*=============================================================================
  82. * SWI handler
  83. *-----------------------------------------------------------------------------
  84. */
  85. /* If we're optimising for StrongARM the resulting code won't
  86. run on an ARM7 and we can save a couple of instructions.
  87. --pb */
  88. #ifdef CONFIG_CPU_ARM710
  89. #define A710(code...) code
  90. .Larm710bug:
  91. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  92. mov r0, r0
  93. add sp, sp, #S_FRAME_SIZE
  94. subs pc, lr, #4
  95. #else
  96. #define A710(code...)
  97. #endif
  98. .align 5
  99. ENTRY(vector_swi)
  100. sub sp, sp, #S_FRAME_SIZE
  101. stmia sp, {r0 - r12} @ Calling r0 - r12
  102. add r8, sp, #S_PC
  103. stmdb r8, {sp, lr}^ @ Calling sp, lr
  104. mrs r8, spsr @ called from non-FIQ mode, so ok.
  105. str lr, [sp, #S_PC] @ Save calling PC
  106. str r8, [sp, #S_PSR] @ Save CPSR
  107. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  108. zero_fp
  109. /*
  110. * Get the system call number.
  111. */
  112. #if defined(CONFIG_OABI_COMPAT)
  113. /*
  114. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  115. * value to determine if it is an EABI or an old ABI call.
  116. */
  117. #ifdef CONFIG_ARM_THUMB
  118. tst r8, #PSR_T_BIT
  119. movne r10, #0 @ no thumb OABI emulation
  120. ldreq r10, [lr, #-4] @ get SWI instruction
  121. #else
  122. ldr r10, [lr, #-4] @ get SWI instruction
  123. A710( and ip, r10, #0x0f000000 @ check for SWI )
  124. A710( teq ip, #0x0f000000 )
  125. A710( bne .Larm710bug )
  126. #endif
  127. #elif defined(CONFIG_AEABI)
  128. /*
  129. * Pure EABI user space always put syscall number into scno (r7).
  130. */
  131. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  132. A710( and ip, ip, #0x0f000000 @ check for SWI )
  133. A710( teq ip, #0x0f000000 )
  134. A710( bne .Larm710bug )
  135. #elif defined(CONFIG_ARM_THUMB)
  136. /* Legacy ABI only, possibly thumb mode. */
  137. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  138. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  139. ldreq scno, [lr, #-4]
  140. #else
  141. /* Legacy ABI only. */
  142. ldr scno, [lr, #-4] @ get SWI instruction
  143. A710( and ip, scno, #0x0f000000 @ check for SWI )
  144. A710( teq ip, #0x0f000000 )
  145. A710( bne .Larm710bug )
  146. #endif
  147. #ifdef CONFIG_ALIGNMENT_TRAP
  148. ldr ip, __cr_alignment
  149. ldr ip, [ip]
  150. mcr p15, 0, ip, c1, c0 @ update control register
  151. #endif
  152. enable_irq
  153. get_thread_info tsk
  154. adr tbl, sys_call_table @ load syscall table pointer
  155. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  156. #if defined(CONFIG_OABI_COMPAT)
  157. /*
  158. * If the swi argument is zero, this is an EABI call and we do nothing.
  159. *
  160. * If this is an old ABI call, get the syscall number into scno and
  161. * get the old ABI syscall table address.
  162. */
  163. bics r10, r10, #0xff000000
  164. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  165. ldrne tbl, =sys_oabi_call_table
  166. #elif !defined(CONFIG_AEABI)
  167. bic scno, scno, #0xff000000 @ mask off SWI op-code
  168. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  169. #endif
  170. stmdb sp!, {r4, r5} @ push fifth and sixth args
  171. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  172. bne __sys_trace
  173. cmp scno, #NR_syscalls @ check upper syscall limit
  174. adr lr, ret_fast_syscall @ return address
  175. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  176. add r1, sp, #S_OFF
  177. 2: mov why, #0 @ no longer a real syscall
  178. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  179. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  180. bcs arm_syscall
  181. b sys_ni_syscall @ not private func
  182. /*
  183. * This is the really slow path. We're going to be doing
  184. * context switches, and waiting for our parent to respond.
  185. */
  186. __sys_trace:
  187. mov r2, scno
  188. add r1, sp, #S_OFF
  189. mov r0, #0 @ trace entry [IP = 0]
  190. bl syscall_trace
  191. adr lr, __sys_trace_return @ return address
  192. mov scno, r0 @ syscall number (possibly new)
  193. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  194. cmp scno, #NR_syscalls @ check upper syscall limit
  195. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  196. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  197. b 2b
  198. __sys_trace_return:
  199. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  200. mov r2, scno
  201. mov r1, sp
  202. mov r0, #1 @ trace exit [IP = 1]
  203. bl syscall_trace
  204. b ret_slow_syscall
  205. .align 5
  206. #ifdef CONFIG_ALIGNMENT_TRAP
  207. .type __cr_alignment, #object
  208. __cr_alignment:
  209. .word cr_alignment
  210. #endif
  211. .ltorg
  212. /*
  213. * This is the syscall table declaration for native ABI syscalls.
  214. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  215. */
  216. #define ABI(native, compat) native
  217. #ifdef CONFIG_AEABI
  218. #define OBSOLETE(syscall) sys_ni_syscall
  219. #else
  220. #define OBSOLETE(syscall) syscall
  221. #endif
  222. .type sys_call_table, #object
  223. ENTRY(sys_call_table)
  224. #include "calls.S"
  225. #undef ABI
  226. #undef OBSOLETE
  227. /*============================================================================
  228. * Special system call wrappers
  229. */
  230. @ r0 = syscall number
  231. @ r8 = syscall table
  232. .type sys_syscall, #function
  233. sys_syscall:
  234. eor scno, r0, #__NR_OABI_SYSCALL_BASE
  235. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  236. cmpne scno, #NR_syscalls @ check range
  237. stmloia sp, {r5, r6} @ shuffle args
  238. movlo r0, r1
  239. movlo r1, r2
  240. movlo r2, r3
  241. movlo r3, r4
  242. ldrlo pc, [tbl, scno, lsl #2]
  243. b sys_ni_syscall
  244. sys_fork_wrapper:
  245. add r0, sp, #S_OFF
  246. b sys_fork
  247. sys_vfork_wrapper:
  248. add r0, sp, #S_OFF
  249. b sys_vfork
  250. sys_execve_wrapper:
  251. add r3, sp, #S_OFF
  252. b sys_execve
  253. sys_clone_wrapper:
  254. add ip, sp, #S_OFF
  255. str ip, [sp, #4]
  256. b sys_clone
  257. sys_sigsuspend_wrapper:
  258. add r3, sp, #S_OFF
  259. b sys_sigsuspend
  260. sys_rt_sigsuspend_wrapper:
  261. add r2, sp, #S_OFF
  262. b sys_rt_sigsuspend
  263. sys_sigreturn_wrapper:
  264. add r0, sp, #S_OFF
  265. b sys_sigreturn
  266. sys_rt_sigreturn_wrapper:
  267. add r0, sp, #S_OFF
  268. b sys_rt_sigreturn
  269. sys_sigaltstack_wrapper:
  270. ldr r2, [sp, #S_OFF + S_SP]
  271. b do_sigaltstack
  272. sys_statfs64_wrapper:
  273. teq r1, #88
  274. moveq r1, #84
  275. b sys_statfs64
  276. sys_fstatfs64_wrapper:
  277. teq r1, #88
  278. moveq r1, #84
  279. b sys_fstatfs64
  280. /*
  281. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  282. * offset, we return EINVAL.
  283. */
  284. sys_mmap2:
  285. #if PAGE_SHIFT > 12
  286. tst r5, #PGOFF_MASK
  287. moveq r5, r5, lsr #PAGE_SHIFT - 12
  288. streq r5, [sp, #4]
  289. beq do_mmap2
  290. mov r0, #-EINVAL
  291. RETINSTR(mov,pc, lr)
  292. #else
  293. str r5, [sp, #4]
  294. b do_mmap2
  295. #endif
  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. sys_oabi_pwrite64:
  304. stmia sp, {r3, r4}
  305. b sys_pwrite64
  306. sys_oabi_truncate64:
  307. mov r3, r2
  308. mov r2, r1
  309. b sys_truncate64
  310. sys_oabi_ftruncate64:
  311. mov r3, r2
  312. mov r2, r1
  313. b sys_ftruncate64
  314. sys_oabi_readahead:
  315. str r3, [sp]
  316. mov r3, r2
  317. mov r2, r1
  318. b sys_readahead
  319. /*
  320. * Let's declare a second syscall table for old ABI binaries
  321. * using the compatibility syscall entries.
  322. */
  323. #define ABI(native, compat) compat
  324. #define OBSOLETE(syscall) syscall
  325. .type sys_oabi_call_table, #object
  326. ENTRY(sys_oabi_call_table)
  327. #include "calls.S"
  328. #undef ABI
  329. #undef OBSOLETE
  330. #endif