entry-common.S 9.9 KB

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