entry-common.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0"
  122. * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see
  123. * arch/arm/kernel/ftrace.c).
  124. */
  125. #ifndef CONFIG_OLD_MCOUNT
  126. #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
  127. #error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.
  128. #endif
  129. #endif
  130. #ifdef CONFIG_DYNAMIC_FTRACE
  131. ENTRY(__gnu_mcount_nc)
  132. mov ip, lr
  133. ldmia sp!, {lr}
  134. mov pc, ip
  135. ENDPROC(__gnu_mcount_nc)
  136. ENTRY(ftrace_caller)
  137. stmdb sp!, {r0-r3, lr}
  138. mov r0, lr
  139. sub r0, r0, #MCOUNT_INSN_SIZE
  140. ldr r1, [sp, #20]
  141. .global ftrace_call
  142. ftrace_call:
  143. bl ftrace_stub
  144. ldmia sp!, {r0-r3, ip, lr}
  145. mov pc, ip
  146. ENDPROC(ftrace_caller)
  147. #ifdef CONFIG_OLD_MCOUNT
  148. ENTRY(mcount)
  149. stmdb sp!, {lr}
  150. ldr lr, [fp, #-4]
  151. ldmia sp!, {pc}
  152. ENDPROC(mcount)
  153. ENTRY(ftrace_caller_old)
  154. stmdb sp!, {r0-r3, lr}
  155. ldr r1, [fp, #-4]
  156. mov r0, lr
  157. sub r0, r0, #MCOUNT_INSN_SIZE
  158. .globl ftrace_call_old
  159. ftrace_call_old:
  160. bl ftrace_stub
  161. ldr lr, [fp, #-4] @ restore lr
  162. ldmia sp!, {r0-r3, pc}
  163. ENDPROC(ftrace_caller_old)
  164. #endif
  165. #else
  166. ENTRY(__gnu_mcount_nc)
  167. stmdb sp!, {r0-r3, lr}
  168. ldr r0, =ftrace_trace_function
  169. ldr r2, [r0]
  170. adr r0, .Lftrace_stub
  171. cmp r0, r2
  172. bne gnu_trace
  173. ldmia sp!, {r0-r3, ip, lr}
  174. mov pc, ip
  175. gnu_trace:
  176. ldr r1, [sp, #20] @ lr of instrumented routine
  177. mov r0, lr
  178. sub r0, r0, #MCOUNT_INSN_SIZE
  179. adr lr, BSYM(1f)
  180. mov pc, r2
  181. 1:
  182. ldmia sp!, {r0-r3, ip, lr}
  183. mov pc, ip
  184. ENDPROC(__gnu_mcount_nc)
  185. #ifdef CONFIG_OLD_MCOUNT
  186. /*
  187. * This is under an ifdef in order to force link-time errors for people trying
  188. * to build with !FRAME_POINTER with a GCC which doesn't use the new-style
  189. * mcount.
  190. */
  191. ENTRY(mcount)
  192. stmdb sp!, {r0-r3, lr}
  193. ldr r0, =ftrace_trace_function
  194. ldr r2, [r0]
  195. adr r0, ftrace_stub
  196. cmp r0, r2
  197. bne trace
  198. ldr lr, [fp, #-4] @ restore lr
  199. ldmia sp!, {r0-r3, pc}
  200. trace:
  201. ldr r1, [fp, #-4] @ lr of instrumented routine
  202. mov r0, lr
  203. sub r0, r0, #MCOUNT_INSN_SIZE
  204. mov lr, pc
  205. mov pc, r2
  206. ldr lr, [fp, #-4] @ restore lr
  207. ldmia sp!, {r0-r3, pc}
  208. ENDPROC(mcount)
  209. #endif
  210. #endif /* CONFIG_DYNAMIC_FTRACE */
  211. ENTRY(ftrace_stub)
  212. .Lftrace_stub:
  213. mov pc, lr
  214. ENDPROC(ftrace_stub)
  215. #endif /* CONFIG_FUNCTION_TRACER */
  216. /*=============================================================================
  217. * SWI handler
  218. *-----------------------------------------------------------------------------
  219. */
  220. /* If we're optimising for StrongARM the resulting code won't
  221. run on an ARM7 and we can save a couple of instructions.
  222. --pb */
  223. #ifdef CONFIG_CPU_ARM710
  224. #define A710(code...) code
  225. .Larm710bug:
  226. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  227. mov r0, r0
  228. add sp, sp, #S_FRAME_SIZE
  229. subs pc, lr, #4
  230. #else
  231. #define A710(code...)
  232. #endif
  233. .align 5
  234. ENTRY(vector_swi)
  235. sub sp, sp, #S_FRAME_SIZE
  236. stmia sp, {r0 - r12} @ Calling r0 - r12
  237. ARM( add r8, sp, #S_PC )
  238. ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
  239. THUMB( mov r8, sp )
  240. THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
  241. mrs r8, spsr @ called from non-FIQ mode, so ok.
  242. str lr, [sp, #S_PC] @ Save calling PC
  243. str r8, [sp, #S_PSR] @ Save CPSR
  244. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  245. zero_fp
  246. /*
  247. * Get the system call number.
  248. */
  249. #if defined(CONFIG_OABI_COMPAT)
  250. /*
  251. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  252. * value to determine if it is an EABI or an old ABI call.
  253. */
  254. #ifdef CONFIG_ARM_THUMB
  255. tst r8, #PSR_T_BIT
  256. movne r10, #0 @ no thumb OABI emulation
  257. ldreq r10, [lr, #-4] @ get SWI instruction
  258. #else
  259. ldr r10, [lr, #-4] @ get SWI instruction
  260. A710( and ip, r10, #0x0f000000 @ check for SWI )
  261. A710( teq ip, #0x0f000000 )
  262. A710( bne .Larm710bug )
  263. #endif
  264. #ifdef CONFIG_CPU_ENDIAN_BE8
  265. rev r10, r10 @ little endian instruction
  266. #endif
  267. #elif defined(CONFIG_AEABI)
  268. /*
  269. * Pure EABI user space always put syscall number into scno (r7).
  270. */
  271. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  272. A710( and ip, ip, #0x0f000000 @ check for SWI )
  273. A710( teq ip, #0x0f000000 )
  274. A710( bne .Larm710bug )
  275. #elif defined(CONFIG_ARM_THUMB)
  276. /* Legacy ABI only, possibly thumb mode. */
  277. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  278. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  279. ldreq scno, [lr, #-4]
  280. #else
  281. /* Legacy ABI only. */
  282. ldr scno, [lr, #-4] @ get SWI instruction
  283. A710( and ip, scno, #0x0f000000 @ check for SWI )
  284. A710( teq ip, #0x0f000000 )
  285. A710( bne .Larm710bug )
  286. #endif
  287. #ifdef CONFIG_ALIGNMENT_TRAP
  288. ldr ip, __cr_alignment
  289. ldr ip, [ip]
  290. mcr p15, 0, ip, c1, c0 @ update control register
  291. #endif
  292. enable_irq
  293. get_thread_info tsk
  294. adr tbl, sys_call_table @ load syscall table pointer
  295. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  296. #if defined(CONFIG_OABI_COMPAT)
  297. /*
  298. * If the swi argument is zero, this is an EABI call and we do nothing.
  299. *
  300. * If this is an old ABI call, get the syscall number into scno and
  301. * get the old ABI syscall table address.
  302. */
  303. bics r10, r10, #0xff000000
  304. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  305. ldrne tbl, =sys_oabi_call_table
  306. #elif !defined(CONFIG_AEABI)
  307. bic scno, scno, #0xff000000 @ mask off SWI op-code
  308. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  309. #endif
  310. stmdb sp!, {r4, r5} @ push fifth and sixth args
  311. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  312. bne __sys_trace
  313. cmp scno, #NR_syscalls @ check upper syscall limit
  314. adr lr, BSYM(ret_fast_syscall) @ return address
  315. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  316. add r1, sp, #S_OFF
  317. 2: mov why, #0 @ no longer a real syscall
  318. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  319. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  320. bcs arm_syscall
  321. b sys_ni_syscall @ not private func
  322. ENDPROC(vector_swi)
  323. /*
  324. * This is the really slow path. We're going to be doing
  325. * context switches, and waiting for our parent to respond.
  326. */
  327. __sys_trace:
  328. mov r2, scno
  329. add r1, sp, #S_OFF
  330. mov r0, #0 @ trace entry [IP = 0]
  331. bl syscall_trace
  332. adr lr, BSYM(__sys_trace_return) @ return address
  333. mov scno, r0 @ syscall number (possibly new)
  334. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  335. cmp scno, #NR_syscalls @ check upper syscall limit
  336. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  337. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  338. b 2b
  339. __sys_trace_return:
  340. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  341. mov r2, scno
  342. mov r1, sp
  343. mov r0, #1 @ trace exit [IP = 1]
  344. bl syscall_trace
  345. b ret_slow_syscall
  346. .align 5
  347. #ifdef CONFIG_ALIGNMENT_TRAP
  348. .type __cr_alignment, #object
  349. __cr_alignment:
  350. .word cr_alignment
  351. #endif
  352. .ltorg
  353. /*
  354. * This is the syscall table declaration for native ABI syscalls.
  355. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  356. */
  357. #define ABI(native, compat) native
  358. #ifdef CONFIG_AEABI
  359. #define OBSOLETE(syscall) sys_ni_syscall
  360. #else
  361. #define OBSOLETE(syscall) syscall
  362. #endif
  363. .type sys_call_table, #object
  364. ENTRY(sys_call_table)
  365. #include "calls.S"
  366. #undef ABI
  367. #undef OBSOLETE
  368. /*============================================================================
  369. * Special system call wrappers
  370. */
  371. @ r0 = syscall number
  372. @ r8 = syscall table
  373. sys_syscall:
  374. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  375. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  376. cmpne scno, #NR_syscalls @ check range
  377. stmloia sp, {r5, r6} @ shuffle args
  378. movlo r0, r1
  379. movlo r1, r2
  380. movlo r2, r3
  381. movlo r3, r4
  382. ldrlo pc, [tbl, scno, lsl #2]
  383. b sys_ni_syscall
  384. ENDPROC(sys_syscall)
  385. sys_fork_wrapper:
  386. add r0, sp, #S_OFF
  387. b sys_fork
  388. ENDPROC(sys_fork_wrapper)
  389. sys_vfork_wrapper:
  390. add r0, sp, #S_OFF
  391. b sys_vfork
  392. ENDPROC(sys_vfork_wrapper)
  393. sys_execve_wrapper:
  394. add r3, sp, #S_OFF
  395. b sys_execve
  396. ENDPROC(sys_execve_wrapper)
  397. sys_clone_wrapper:
  398. add ip, sp, #S_OFF
  399. str ip, [sp, #4]
  400. b sys_clone
  401. ENDPROC(sys_clone_wrapper)
  402. sys_sigreturn_wrapper:
  403. add r0, sp, #S_OFF
  404. mov why, #0 @ prevent syscall restart handling
  405. b sys_sigreturn
  406. ENDPROC(sys_sigreturn_wrapper)
  407. sys_rt_sigreturn_wrapper:
  408. add r0, sp, #S_OFF
  409. mov why, #0 @ prevent syscall restart handling
  410. b sys_rt_sigreturn
  411. ENDPROC(sys_rt_sigreturn_wrapper)
  412. sys_sigaltstack_wrapper:
  413. ldr r2, [sp, #S_OFF + S_SP]
  414. b do_sigaltstack
  415. ENDPROC(sys_sigaltstack_wrapper)
  416. sys_statfs64_wrapper:
  417. teq r1, #88
  418. moveq r1, #84
  419. b sys_statfs64
  420. ENDPROC(sys_statfs64_wrapper)
  421. sys_fstatfs64_wrapper:
  422. teq r1, #88
  423. moveq r1, #84
  424. b sys_fstatfs64
  425. ENDPROC(sys_fstatfs64_wrapper)
  426. /*
  427. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  428. * offset, we return EINVAL.
  429. */
  430. sys_mmap2:
  431. #if PAGE_SHIFT > 12
  432. tst r5, #PGOFF_MASK
  433. moveq r5, r5, lsr #PAGE_SHIFT - 12
  434. streq r5, [sp, #4]
  435. beq sys_mmap_pgoff
  436. mov r0, #-EINVAL
  437. mov pc, lr
  438. #else
  439. str r5, [sp, #4]
  440. b sys_mmap_pgoff
  441. #endif
  442. ENDPROC(sys_mmap2)
  443. #ifdef CONFIG_OABI_COMPAT
  444. /*
  445. * These are syscalls with argument register differences
  446. */
  447. sys_oabi_pread64:
  448. stmia sp, {r3, r4}
  449. b sys_pread64
  450. ENDPROC(sys_oabi_pread64)
  451. sys_oabi_pwrite64:
  452. stmia sp, {r3, r4}
  453. b sys_pwrite64
  454. ENDPROC(sys_oabi_pwrite64)
  455. sys_oabi_truncate64:
  456. mov r3, r2
  457. mov r2, r1
  458. b sys_truncate64
  459. ENDPROC(sys_oabi_truncate64)
  460. sys_oabi_ftruncate64:
  461. mov r3, r2
  462. mov r2, r1
  463. b sys_ftruncate64
  464. ENDPROC(sys_oabi_ftruncate64)
  465. sys_oabi_readahead:
  466. str r3, [sp]
  467. mov r3, r2
  468. mov r2, r1
  469. b sys_readahead
  470. ENDPROC(sys_oabi_readahead)
  471. /*
  472. * Let's declare a second syscall table for old ABI binaries
  473. * using the compatibility syscall entries.
  474. */
  475. #define ABI(native, compat) compat
  476. #define OBSOLETE(syscall) syscall
  477. .type sys_oabi_call_table, #object
  478. ENTRY(sys_oabi_call_table)
  479. #include "calls.S"
  480. #undef ABI
  481. #undef OBSOLETE
  482. #endif