entry-common.S 8.9 KB

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