entry-common.S 6.7 KB

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