entry-common.S 14 KB

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