entry-common.S 12 KB

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