entry-common.S 9.8 KB

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