entry-common.S 5.6 KB

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