entry-common.S 11 KB

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