entry-common.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. disable_irq @ disable interrupts
  46. b no_work_pending
  47. work_resched:
  48. bl schedule
  49. /*
  50. * "slow" syscall return path. "why" tells us if this was a real syscall.
  51. */
  52. ENTRY(ret_to_user)
  53. ret_slow_syscall:
  54. disable_irq @ disable interrupts
  55. ldr r1, [tsk, #TI_FLAGS]
  56. tst r1, #_TIF_WORK_MASK
  57. bne work_pending
  58. no_work_pending:
  59. @ slow_restore_user_regs
  60. ldr r1, [sp, #S_PSR] @ get calling cpsr
  61. ldr lr, [sp, #S_PC]! @ get pc
  62. msr spsr_cxsf, r1 @ save in spsr_svc
  63. ldmdb sp, {r0 - lr}^ @ get calling r1 - lr
  64. mov r0, r0
  65. add sp, sp, #S_FRAME_SIZE - S_PC
  66. movs pc, lr @ return & move spsr_svc into cpsr
  67. /*
  68. * This is how we return from a fork.
  69. */
  70. ENTRY(ret_from_fork)
  71. bl schedule_tail
  72. get_thread_info tsk
  73. ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
  74. mov why, #1
  75. tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  76. beq ret_slow_syscall
  77. mov r1, sp
  78. mov r0, #1 @ trace exit [IP = 1]
  79. bl syscall_trace
  80. b ret_slow_syscall
  81. #include "calls.S"
  82. /*=============================================================================
  83. * SWI handler
  84. *-----------------------------------------------------------------------------
  85. */
  86. /* If we're optimising for StrongARM the resulting code won't
  87. run on an ARM7 and we can save a couple of instructions.
  88. --pb */
  89. #ifdef CONFIG_CPU_ARM710
  90. .macro arm710_bug_check, instr, temp
  91. and \temp, \instr, #0x0f000000 @ check for SWI
  92. teq \temp, #0x0f000000
  93. bne .Larm700bug
  94. .endm
  95. .Larm700bug:
  96. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  97. mov r0, r0
  98. add sp, sp, #S_FRAME_SIZE
  99. subs pc, lr, #4
  100. #else
  101. .macro arm710_bug_check, instr, temp
  102. .endm
  103. #endif
  104. .align 5
  105. ENTRY(vector_swi)
  106. sub sp, sp, #S_FRAME_SIZE
  107. stmia sp, {r0 - r12} @ Calling r0 - r12
  108. add r8, sp, #S_PC
  109. stmdb r8, {sp, lr}^ @ Calling sp, lr
  110. mrs r8, spsr @ called from non-FIQ mode, so ok.
  111. str lr, [sp, #S_PC] @ Save calling PC
  112. str r8, [sp, #S_PSR] @ Save CPSR
  113. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  114. zero_fp
  115. /*
  116. * Get the system call number.
  117. */
  118. #ifdef CONFIG_ARM_THUMB
  119. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  120. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  121. ldreq scno, [lr, #-4]
  122. #else
  123. ldr scno, [lr, #-4] @ get SWI instruction
  124. #endif
  125. arm710_bug_check scno, ip
  126. #ifdef CONFIG_ALIGNMENT_TRAP
  127. ldr ip, __cr_alignment
  128. ldr ip, [ip]
  129. mcr p15, 0, ip, c1, c0 @ update control register
  130. #endif
  131. enable_irq
  132. str r4, [sp, #-S_OFF]! @ push fifth arg
  133. get_thread_info tsk
  134. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  135. bic scno, scno, #0xff000000 @ mask off SWI op-code
  136. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  137. adr tbl, sys_call_table @ load syscall table pointer
  138. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  139. bne __sys_trace
  140. adr lr, ret_fast_syscall @ return address
  141. cmp scno, #NR_syscalls @ check upper syscall limit
  142. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  143. add r1, sp, #S_OFF
  144. 2: mov why, #0 @ no longer a real syscall
  145. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  146. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  147. bcs arm_syscall
  148. b sys_ni_syscall @ not private func
  149. /*
  150. * This is the really slow path. We're going to be doing
  151. * context switches, and waiting for our parent to respond.
  152. */
  153. __sys_trace:
  154. add r1, sp, #S_OFF
  155. mov r0, #0 @ trace entry [IP = 0]
  156. bl syscall_trace
  157. adr lr, __sys_trace_return @ return address
  158. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  159. cmp scno, #NR_syscalls @ check upper syscall limit
  160. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  161. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  162. b 2b
  163. __sys_trace_return:
  164. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  165. mov r1, sp
  166. mov r0, #1 @ trace exit [IP = 1]
  167. bl syscall_trace
  168. b ret_slow_syscall
  169. .align 5
  170. #ifdef CONFIG_ALIGNMENT_TRAP
  171. .type __cr_alignment, #object
  172. __cr_alignment:
  173. .word cr_alignment
  174. #endif
  175. .type sys_call_table, #object
  176. ENTRY(sys_call_table)
  177. #include "calls.S"
  178. /*============================================================================
  179. * Special system call wrappers
  180. */
  181. @ r0 = syscall number
  182. @ r5 = syscall table
  183. .type sys_syscall, #function
  184. sys_syscall:
  185. eor scno, r0, #__NR_SYSCALL_BASE
  186. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  187. cmpne scno, #NR_syscalls @ check range
  188. stmloia sp, {r5, r6} @ shuffle args
  189. movlo r0, r1
  190. movlo r1, r2
  191. movlo r2, r3
  192. movlo r3, r4
  193. ldrlo pc, [tbl, scno, lsl #2]
  194. b sys_ni_syscall
  195. sys_fork_wrapper:
  196. add r0, sp, #S_OFF
  197. b sys_fork
  198. sys_vfork_wrapper:
  199. add r0, sp, #S_OFF
  200. b sys_vfork
  201. sys_execve_wrapper:
  202. add r3, sp, #S_OFF
  203. b sys_execve
  204. sys_clone_wrapper:
  205. add ip, sp, #S_OFF
  206. str ip, [sp, #4]
  207. b sys_clone
  208. sys_sigsuspend_wrapper:
  209. add r3, sp, #S_OFF
  210. b sys_sigsuspend
  211. sys_rt_sigsuspend_wrapper:
  212. add r2, sp, #S_OFF
  213. b sys_rt_sigsuspend
  214. sys_sigreturn_wrapper:
  215. add r0, sp, #S_OFF
  216. b sys_sigreturn
  217. sys_rt_sigreturn_wrapper:
  218. add r0, sp, #S_OFF
  219. b sys_rt_sigreturn
  220. sys_sigaltstack_wrapper:
  221. ldr r2, [sp, #S_OFF + S_SP]
  222. b do_sigaltstack
  223. sys_futex_wrapper:
  224. str r5, [sp, #4] @ push sixth arg
  225. b sys_futex
  226. sys_arm_fadvise64_64_wrapper:
  227. str r5, [sp, #4] @ push r5 to stack
  228. b sys_arm_fadvise64_64
  229. sys_mbind_wrapper:
  230. str r5, [sp, #4]
  231. b sys_mbind
  232. sys_ipc_wrapper:
  233. str r5, [sp, #4] @ push sixth arg
  234. b sys_ipc
  235. /*
  236. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  237. * offset, we return EINVAL.
  238. */
  239. sys_mmap2:
  240. #if PAGE_SHIFT > 12
  241. tst r5, #PGOFF_MASK
  242. moveq r5, r5, lsr #PAGE_SHIFT - 12
  243. streq r5, [sp, #4]
  244. beq do_mmap2
  245. mov r0, #-EINVAL
  246. RETINSTR(mov,pc, lr)
  247. #else
  248. str r5, [sp, #4]
  249. b do_mmap2
  250. #endif