entry-common.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 <asm/unistd.h>
  11. #include <asm/ftrace.h>
  12. #include <mach/entry-macro.S>
  13. #include <asm/unwind.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. UNWIND(.fnstart )
  23. UNWIND(.cantunwind )
  24. disable_irq @ disable interrupts
  25. ldr r1, [tsk, #TI_FLAGS]
  26. tst r1, #_TIF_WORK_MASK
  27. bne fast_work_pending
  28. /* perform architecture specific actions before user return */
  29. arch_ret_to_user r1, lr
  30. restore_user_regs fast = 1, offset = S_OFF
  31. UNWIND(.fnend )
  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_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. /* perform architecture specific actions before user return */
  59. arch_ret_to_user r1, lr
  60. restore_user_regs fast = 0, offset = 0
  61. ENDPROC(ret_to_user)
  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. ENDPROC(ret_from_fork)
  77. .equ NR_syscalls,0
  78. #define CALL(x) .equ NR_syscalls,NR_syscalls+1
  79. #include "calls.S"
  80. #undef CALL
  81. #define CALL(x) .long x
  82. #ifdef CONFIG_FUNCTION_TRACER
  83. #ifdef CONFIG_DYNAMIC_FTRACE
  84. ENTRY(mcount)
  85. stmdb sp!, {r0-r3, lr}
  86. mov r0, lr
  87. sub r0, r0, #MCOUNT_INSN_SIZE
  88. .globl mcount_call
  89. mcount_call:
  90. bl ftrace_stub
  91. ldr lr, [fp, #-4] @ restore lr
  92. ldmia sp!, {r0-r3, pc}
  93. ENTRY(ftrace_caller)
  94. stmdb sp!, {r0-r3, lr}
  95. ldr r1, [fp, #-4]
  96. mov r0, lr
  97. sub r0, r0, #MCOUNT_INSN_SIZE
  98. .globl ftrace_call
  99. ftrace_call:
  100. bl ftrace_stub
  101. ldr lr, [fp, #-4] @ restore lr
  102. ldmia sp!, {r0-r3, pc}
  103. #else
  104. ENTRY(mcount)
  105. stmdb sp!, {r0-r3, lr}
  106. ldr r0, =ftrace_trace_function
  107. ldr r2, [r0]
  108. adr r0, ftrace_stub
  109. cmp r0, r2
  110. bne trace
  111. ldr lr, [fp, #-4] @ restore lr
  112. ldmia sp!, {r0-r3, pc}
  113. trace:
  114. ldr r1, [fp, #-4] @ lr of instrumented routine
  115. mov r0, lr
  116. sub r0, r0, #MCOUNT_INSN_SIZE
  117. mov lr, pc
  118. mov pc, r2
  119. mov lr, r1 @ restore lr
  120. ldmia sp!, {r0-r3, pc}
  121. #endif /* CONFIG_DYNAMIC_FTRACE */
  122. .globl ftrace_stub
  123. ftrace_stub:
  124. mov pc, lr
  125. #endif /* CONFIG_FUNCTION_TRACER */
  126. /*=============================================================================
  127. * SWI handler
  128. *-----------------------------------------------------------------------------
  129. */
  130. /* If we're optimising for StrongARM the resulting code won't
  131. run on an ARM7 and we can save a couple of instructions.
  132. --pb */
  133. #ifdef CONFIG_CPU_ARM710
  134. #define A710(code...) code
  135. .Larm710bug:
  136. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  137. mov r0, r0
  138. add sp, sp, #S_FRAME_SIZE
  139. subs pc, lr, #4
  140. #else
  141. #define A710(code...)
  142. #endif
  143. .align 5
  144. ENTRY(vector_swi)
  145. sub sp, sp, #S_FRAME_SIZE
  146. stmia sp, {r0 - r12} @ Calling r0 - r12
  147. ARM( add r8, sp, #S_PC )
  148. ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
  149. THUMB( mov r8, sp )
  150. THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
  151. mrs r8, spsr @ called from non-FIQ mode, so ok.
  152. str lr, [sp, #S_PC] @ Save calling PC
  153. str r8, [sp, #S_PSR] @ Save CPSR
  154. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  155. zero_fp
  156. /*
  157. * Get the system call number.
  158. */
  159. #if defined(CONFIG_OABI_COMPAT)
  160. /*
  161. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  162. * value to determine if it is an EABI or an old ABI call.
  163. */
  164. #ifdef CONFIG_ARM_THUMB
  165. tst r8, #PSR_T_BIT
  166. movne r10, #0 @ no thumb OABI emulation
  167. ldreq r10, [lr, #-4] @ get SWI instruction
  168. #else
  169. ldr r10, [lr, #-4] @ get SWI instruction
  170. A710( and ip, r10, #0x0f000000 @ check for SWI )
  171. A710( teq ip, #0x0f000000 )
  172. A710( bne .Larm710bug )
  173. #endif
  174. #ifdef CONFIG_CPU_ENDIAN_BE8
  175. rev r10, r10 @ little endian instruction
  176. #endif
  177. #elif defined(CONFIG_AEABI)
  178. /*
  179. * Pure EABI user space always put syscall number into scno (r7).
  180. */
  181. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  182. A710( and ip, ip, #0x0f000000 @ check for SWI )
  183. A710( teq ip, #0x0f000000 )
  184. A710( bne .Larm710bug )
  185. #elif defined(CONFIG_ARM_THUMB)
  186. /* Legacy ABI only, possibly thumb mode. */
  187. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  188. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  189. ldreq scno, [lr, #-4]
  190. #else
  191. /* Legacy ABI only. */
  192. ldr scno, [lr, #-4] @ get SWI instruction
  193. A710( and ip, scno, #0x0f000000 @ check for SWI )
  194. A710( teq ip, #0x0f000000 )
  195. A710( bne .Larm710bug )
  196. #endif
  197. #ifdef CONFIG_ALIGNMENT_TRAP
  198. ldr ip, __cr_alignment
  199. ldr ip, [ip]
  200. mcr p15, 0, ip, c1, c0 @ update control register
  201. #endif
  202. enable_irq
  203. get_thread_info tsk
  204. adr tbl, sys_call_table @ load syscall table pointer
  205. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  206. #if defined(CONFIG_OABI_COMPAT)
  207. /*
  208. * If the swi argument is zero, this is an EABI call and we do nothing.
  209. *
  210. * If this is an old ABI call, get the syscall number into scno and
  211. * get the old ABI syscall table address.
  212. */
  213. bics r10, r10, #0xff000000
  214. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  215. ldrne tbl, =sys_oabi_call_table
  216. #elif !defined(CONFIG_AEABI)
  217. bic scno, scno, #0xff000000 @ mask off SWI op-code
  218. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  219. #endif
  220. stmdb sp!, {r4, r5} @ push fifth and sixth args
  221. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  222. bne __sys_trace
  223. cmp scno, #NR_syscalls @ check upper syscall limit
  224. adr lr, BSYM(ret_fast_syscall) @ return address
  225. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  226. add r1, sp, #S_OFF
  227. 2: mov why, #0 @ no longer a real syscall
  228. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  229. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  230. bcs arm_syscall
  231. b sys_ni_syscall @ not private func
  232. ENDPROC(vector_swi)
  233. /*
  234. * This is the really slow path. We're going to be doing
  235. * context switches, and waiting for our parent to respond.
  236. */
  237. __sys_trace:
  238. mov r2, scno
  239. add r1, sp, #S_OFF
  240. mov r0, #0 @ trace entry [IP = 0]
  241. bl syscall_trace
  242. adr lr, BSYM(__sys_trace_return) @ return address
  243. mov scno, r0 @ syscall number (possibly new)
  244. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  245. cmp scno, #NR_syscalls @ check upper syscall limit
  246. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  247. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  248. b 2b
  249. __sys_trace_return:
  250. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  251. mov r2, scno
  252. mov r1, sp
  253. mov r0, #1 @ trace exit [IP = 1]
  254. bl syscall_trace
  255. b ret_slow_syscall
  256. .align 5
  257. #ifdef CONFIG_ALIGNMENT_TRAP
  258. .type __cr_alignment, #object
  259. __cr_alignment:
  260. .word cr_alignment
  261. #endif
  262. .ltorg
  263. /*
  264. * This is the syscall table declaration for native ABI syscalls.
  265. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  266. */
  267. #define ABI(native, compat) native
  268. #ifdef CONFIG_AEABI
  269. #define OBSOLETE(syscall) sys_ni_syscall
  270. #else
  271. #define OBSOLETE(syscall) syscall
  272. #endif
  273. .type sys_call_table, #object
  274. ENTRY(sys_call_table)
  275. #include "calls.S"
  276. #undef ABI
  277. #undef OBSOLETE
  278. /*============================================================================
  279. * Special system call wrappers
  280. */
  281. @ r0 = syscall number
  282. @ r8 = syscall table
  283. sys_syscall:
  284. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  285. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  286. cmpne scno, #NR_syscalls @ check range
  287. stmloia sp, {r5, r6} @ shuffle args
  288. movlo r0, r1
  289. movlo r1, r2
  290. movlo r2, r3
  291. movlo r3, r4
  292. ldrlo pc, [tbl, scno, lsl #2]
  293. b sys_ni_syscall
  294. ENDPROC(sys_syscall)
  295. sys_fork_wrapper:
  296. add r0, sp, #S_OFF
  297. b sys_fork
  298. ENDPROC(sys_fork_wrapper)
  299. sys_vfork_wrapper:
  300. add r0, sp, #S_OFF
  301. b sys_vfork
  302. ENDPROC(sys_vfork_wrapper)
  303. sys_execve_wrapper:
  304. add r3, sp, #S_OFF
  305. b sys_execve
  306. ENDPROC(sys_execve_wrapper)
  307. sys_clone_wrapper:
  308. add ip, sp, #S_OFF
  309. str ip, [sp, #4]
  310. b sys_clone
  311. ENDPROC(sys_clone_wrapper)
  312. sys_sigsuspend_wrapper:
  313. add r3, sp, #S_OFF
  314. b sys_sigsuspend
  315. ENDPROC(sys_sigsuspend_wrapper)
  316. sys_rt_sigsuspend_wrapper:
  317. add r2, sp, #S_OFF
  318. b sys_rt_sigsuspend
  319. ENDPROC(sys_rt_sigsuspend_wrapper)
  320. sys_sigreturn_wrapper:
  321. add r0, sp, #S_OFF
  322. b sys_sigreturn
  323. ENDPROC(sys_sigreturn_wrapper)
  324. sys_rt_sigreturn_wrapper:
  325. add r0, sp, #S_OFF
  326. b sys_rt_sigreturn
  327. ENDPROC(sys_rt_sigreturn_wrapper)
  328. sys_sigaltstack_wrapper:
  329. ldr r2, [sp, #S_OFF + S_SP]
  330. b do_sigaltstack
  331. ENDPROC(sys_sigaltstack_wrapper)
  332. sys_statfs64_wrapper:
  333. teq r1, #88
  334. moveq r1, #84
  335. b sys_statfs64
  336. ENDPROC(sys_statfs64_wrapper)
  337. sys_fstatfs64_wrapper:
  338. teq r1, #88
  339. moveq r1, #84
  340. b sys_fstatfs64
  341. ENDPROC(sys_fstatfs64_wrapper)
  342. /*
  343. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  344. * offset, we return EINVAL.
  345. */
  346. sys_mmap2:
  347. #if PAGE_SHIFT > 12
  348. tst r5, #PGOFF_MASK
  349. moveq r5, r5, lsr #PAGE_SHIFT - 12
  350. streq r5, [sp, #4]
  351. beq do_mmap2
  352. mov r0, #-EINVAL
  353. mov pc, lr
  354. #else
  355. str r5, [sp, #4]
  356. b do_mmap2
  357. #endif
  358. ENDPROC(sys_mmap2)
  359. ENTRY(pabort_ifar)
  360. mrc p15, 0, r0, cr6, cr0, 2
  361. ENTRY(pabort_noifar)
  362. mov pc, lr
  363. ENDPROC(pabort_ifar)
  364. ENDPROC(pabort_noifar)
  365. #ifdef CONFIG_OABI_COMPAT
  366. /*
  367. * These are syscalls with argument register differences
  368. */
  369. sys_oabi_pread64:
  370. stmia sp, {r3, r4}
  371. b sys_pread64
  372. ENDPROC(sys_oabi_pread64)
  373. sys_oabi_pwrite64:
  374. stmia sp, {r3, r4}
  375. b sys_pwrite64
  376. ENDPROC(sys_oabi_pwrite64)
  377. sys_oabi_truncate64:
  378. mov r3, r2
  379. mov r2, r1
  380. b sys_truncate64
  381. ENDPROC(sys_oabi_truncate64)
  382. sys_oabi_ftruncate64:
  383. mov r3, r2
  384. mov r2, r1
  385. b sys_ftruncate64
  386. ENDPROC(sys_oabi_ftruncate64)
  387. sys_oabi_readahead:
  388. str r3, [sp]
  389. mov r3, r2
  390. mov r2, r1
  391. b sys_readahead
  392. ENDPROC(sys_oabi_readahead)
  393. /*
  394. * Let's declare a second syscall table for old ABI binaries
  395. * using the compatibility syscall entries.
  396. */
  397. #define ABI(native, compat) compat
  398. #define OBSOLETE(syscall) syscall
  399. .type sys_oabi_call_table, #object
  400. ENTRY(sys_oabi_call_table)
  401. #include "calls.S"
  402. #undef ABI
  403. #undef OBSOLETE
  404. #endif