entry-common.S 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. #if defined(CONFIG_OABI_COMPAT)
  296. /*
  297. * If the swi argument is zero, this is an EABI call and we do nothing.
  298. *
  299. * If this is an old ABI call, get the syscall number into scno and
  300. * get the old ABI syscall table address.
  301. */
  302. bics r10, r10, #0xff000000
  303. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  304. ldrne tbl, =sys_oabi_call_table
  305. #elif !defined(CONFIG_AEABI)
  306. bic scno, scno, #0xff000000 @ mask off SWI op-code
  307. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  308. #endif
  309. ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
  310. stmdb sp!, {r4, r5} @ push fifth and sixth args
  311. #ifdef CONFIG_SECCOMP
  312. tst r10, #_TIF_SECCOMP
  313. beq 1f
  314. mov r0, scno
  315. bl __secure_computing
  316. add r0, sp, #S_R0 + S_OFF @ pointer to regs
  317. ldmia r0, {r0 - r3} @ have to reload r0 - r3
  318. 1:
  319. #endif
  320. tst r10, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  321. bne __sys_trace
  322. cmp scno, #NR_syscalls @ check upper syscall limit
  323. adr lr, BSYM(ret_fast_syscall) @ return address
  324. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  325. add r1, sp, #S_OFF
  326. 2: mov why, #0 @ no longer a real syscall
  327. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  328. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  329. bcs arm_syscall
  330. b sys_ni_syscall @ not private func
  331. ENDPROC(vector_swi)
  332. /*
  333. * This is the really slow path. We're going to be doing
  334. * context switches, and waiting for our parent to respond.
  335. */
  336. __sys_trace:
  337. mov r2, scno
  338. add r1, sp, #S_OFF
  339. mov r0, #0 @ trace entry [IP = 0]
  340. bl syscall_trace
  341. adr lr, BSYM(__sys_trace_return) @ return address
  342. mov scno, r0 @ syscall number (possibly new)
  343. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  344. cmp scno, #NR_syscalls @ check upper syscall limit
  345. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  346. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  347. b 2b
  348. __sys_trace_return:
  349. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  350. mov r2, scno
  351. mov r1, sp
  352. mov r0, #1 @ trace exit [IP = 1]
  353. bl syscall_trace
  354. b ret_slow_syscall
  355. .align 5
  356. #ifdef CONFIG_ALIGNMENT_TRAP
  357. .type __cr_alignment, #object
  358. __cr_alignment:
  359. .word cr_alignment
  360. #endif
  361. .ltorg
  362. /*
  363. * This is the syscall table declaration for native ABI syscalls.
  364. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  365. */
  366. #define ABI(native, compat) native
  367. #ifdef CONFIG_AEABI
  368. #define OBSOLETE(syscall) sys_ni_syscall
  369. #else
  370. #define OBSOLETE(syscall) syscall
  371. #endif
  372. .type sys_call_table, #object
  373. ENTRY(sys_call_table)
  374. #include "calls.S"
  375. #undef ABI
  376. #undef OBSOLETE
  377. /*============================================================================
  378. * Special system call wrappers
  379. */
  380. @ r0 = syscall number
  381. @ r8 = syscall table
  382. sys_syscall:
  383. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  384. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  385. cmpne scno, #NR_syscalls @ check range
  386. stmloia sp, {r5, r6} @ shuffle args
  387. movlo r0, r1
  388. movlo r1, r2
  389. movlo r2, r3
  390. movlo r3, r4
  391. ldrlo pc, [tbl, scno, lsl #2]
  392. b sys_ni_syscall
  393. ENDPROC(sys_syscall)
  394. sys_fork_wrapper:
  395. add r0, sp, #S_OFF
  396. b sys_fork
  397. ENDPROC(sys_fork_wrapper)
  398. sys_vfork_wrapper:
  399. add r0, sp, #S_OFF
  400. b sys_vfork
  401. ENDPROC(sys_vfork_wrapper)
  402. sys_execve_wrapper:
  403. add r3, sp, #S_OFF
  404. b sys_execve
  405. ENDPROC(sys_execve_wrapper)
  406. sys_clone_wrapper:
  407. add ip, sp, #S_OFF
  408. str ip, [sp, #4]
  409. b sys_clone
  410. ENDPROC(sys_clone_wrapper)
  411. sys_sigreturn_wrapper:
  412. add r0, sp, #S_OFF
  413. mov why, #0 @ prevent syscall restart handling
  414. b sys_sigreturn
  415. ENDPROC(sys_sigreturn_wrapper)
  416. sys_rt_sigreturn_wrapper:
  417. add r0, sp, #S_OFF
  418. mov why, #0 @ prevent syscall restart handling
  419. b sys_rt_sigreturn
  420. ENDPROC(sys_rt_sigreturn_wrapper)
  421. sys_sigaltstack_wrapper:
  422. ldr r2, [sp, #S_OFF + S_SP]
  423. b do_sigaltstack
  424. ENDPROC(sys_sigaltstack_wrapper)
  425. sys_statfs64_wrapper:
  426. teq r1, #88
  427. moveq r1, #84
  428. b sys_statfs64
  429. ENDPROC(sys_statfs64_wrapper)
  430. sys_fstatfs64_wrapper:
  431. teq r1, #88
  432. moveq r1, #84
  433. b sys_fstatfs64
  434. ENDPROC(sys_fstatfs64_wrapper)
  435. /*
  436. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  437. * offset, we return EINVAL.
  438. */
  439. sys_mmap2:
  440. #if PAGE_SHIFT > 12
  441. tst r5, #PGOFF_MASK
  442. moveq r5, r5, lsr #PAGE_SHIFT - 12
  443. streq r5, [sp, #4]
  444. beq sys_mmap_pgoff
  445. mov r0, #-EINVAL
  446. mov pc, lr
  447. #else
  448. str r5, [sp, #4]
  449. b sys_mmap_pgoff
  450. #endif
  451. ENDPROC(sys_mmap2)
  452. #ifdef CONFIG_OABI_COMPAT
  453. /*
  454. * These are syscalls with argument register differences
  455. */
  456. sys_oabi_pread64:
  457. stmia sp, {r3, r4}
  458. b sys_pread64
  459. ENDPROC(sys_oabi_pread64)
  460. sys_oabi_pwrite64:
  461. stmia sp, {r3, r4}
  462. b sys_pwrite64
  463. ENDPROC(sys_oabi_pwrite64)
  464. sys_oabi_truncate64:
  465. mov r3, r2
  466. mov r2, r1
  467. b sys_truncate64
  468. ENDPROC(sys_oabi_truncate64)
  469. sys_oabi_ftruncate64:
  470. mov r3, r2
  471. mov r2, r1
  472. b sys_ftruncate64
  473. ENDPROC(sys_oabi_ftruncate64)
  474. sys_oabi_readahead:
  475. str r3, [sp]
  476. mov r3, r2
  477. mov r2, r1
  478. b sys_readahead
  479. ENDPROC(sys_oabi_readahead)
  480. /*
  481. * Let's declare a second syscall table for old ABI binaries
  482. * using the compatibility syscall entries.
  483. */
  484. #define ABI(native, compat) compat
  485. #define OBSOLETE(syscall) syscall
  486. .type sys_oabi_call_table, #object
  487. ENTRY(sys_oabi_call_table)
  488. #include "calls.S"
  489. #undef ABI
  490. #undef OBSOLETE
  491. #endif