entry-common.S 12 KB

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