entry-common.S 5.8 KB

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