entry-common.S 6.7 KB

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