entry-common.S 9.1 KB

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