entry-common.S 13 KB

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