entry-common.S 11 KB

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