entry-common.S 6.8 KB

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