entry-common.S 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. #if defined(CONFIG_IRQSOFF_TRACER)
  29. asm_trace_hardirqs_on
  30. #endif
  31. /* perform architecture specific actions before user return */
  32. arch_ret_to_user r1, lr
  33. restore_user_regs fast = 1, offset = S_OFF
  34. UNWIND(.fnend )
  35. /*
  36. * Ok, we need to do extra processing, enter the slow path.
  37. */
  38. fast_work_pending:
  39. str r0, [sp, #S_R0+S_OFF]! @ returned r0
  40. work_pending:
  41. tst r1, #_TIF_NEED_RESCHED
  42. bne work_resched
  43. tst r1, #_TIF_SIGPENDING|_TIF_NOTIFY_RESUME
  44. beq no_work_pending
  45. mov r0, sp @ 'regs'
  46. mov r2, why @ 'syscall'
  47. tst r1, #_TIF_SIGPENDING @ delivering a signal?
  48. movne why, #0 @ prevent further restarts
  49. bl do_notify_resume
  50. b ret_slow_syscall @ Check work again
  51. work_resched:
  52. bl schedule
  53. /*
  54. * "slow" syscall return path. "why" tells us if this was a real syscall.
  55. */
  56. ENTRY(ret_to_user)
  57. ret_slow_syscall:
  58. disable_irq @ disable interrupts
  59. ldr r1, [tsk, #TI_FLAGS]
  60. tst r1, #_TIF_WORK_MASK
  61. bne work_pending
  62. no_work_pending:
  63. #if defined(CONFIG_IRQSOFF_TRACER)
  64. asm_trace_hardirqs_on
  65. #endif
  66. /* perform architecture specific actions before user return */
  67. arch_ret_to_user r1, lr
  68. restore_user_regs fast = 0, offset = 0
  69. ENDPROC(ret_to_user)
  70. /*
  71. * This is how we return from a fork.
  72. */
  73. ENTRY(ret_from_fork)
  74. bl schedule_tail
  75. get_thread_info tsk
  76. ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
  77. mov why, #1
  78. tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  79. beq ret_slow_syscall
  80. mov r1, sp
  81. mov r0, #1 @ trace exit [IP = 1]
  82. bl syscall_trace
  83. b ret_slow_syscall
  84. ENDPROC(ret_from_fork)
  85. .equ NR_syscalls,0
  86. #define CALL(x) .equ NR_syscalls,NR_syscalls+1
  87. #include "calls.S"
  88. #undef CALL
  89. #define CALL(x) .long x
  90. #ifdef CONFIG_FUNCTION_TRACER
  91. /*
  92. * When compiling with -pg, gcc inserts a call to the mcount routine at the
  93. * start of every function. In mcount, apart from the function's address (in
  94. * lr), we need to get hold of the function's caller's address.
  95. *
  96. * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:
  97. *
  98. * bl mcount
  99. *
  100. * These versions have the limitation that in order for the mcount routine to
  101. * be able to determine the function's caller's address, an APCS-style frame
  102. * pointer (which is set up with something like the code below) is required.
  103. *
  104. * mov ip, sp
  105. * push {fp, ip, lr, pc}
  106. * sub fp, ip, #4
  107. *
  108. * With EABI, these frame pointers are not available unless -mapcs-frame is
  109. * specified, and if building as Thumb-2, not even then.
  110. *
  111. * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,
  112. * with call sites like:
  113. *
  114. * push {lr}
  115. * bl __gnu_mcount_nc
  116. *
  117. * With these compilers, frame pointers are not necessary.
  118. *
  119. * mcount can be thought of as a function called in the middle of a subroutine
  120. * call. As such, it needs to be transparent for both the caller and the
  121. * callee: the original lr needs to be restored when leaving mcount, and no
  122. * registers should be clobbered. (In the __gnu_mcount_nc implementation, we
  123. * clobber the ip register. This is OK because the ARM calling convention
  124. * allows it to be clobbered in subroutines and doesn't use it to hold
  125. * parameters.)
  126. *
  127. * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0"
  128. * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see
  129. * arch/arm/kernel/ftrace.c).
  130. */
  131. #ifndef CONFIG_OLD_MCOUNT
  132. #if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
  133. #error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.
  134. #endif
  135. #endif
  136. .macro __mcount suffix
  137. mcount_enter
  138. ldr r0, =ftrace_trace_function
  139. ldr r2, [r0]
  140. adr r0, .Lftrace_stub
  141. cmp r0, r2
  142. bne 1f
  143. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  144. ldr r1, =ftrace_graph_return
  145. ldr r2, [r1]
  146. cmp r0, r2
  147. bne ftrace_graph_caller\suffix
  148. ldr r1, =ftrace_graph_entry
  149. ldr r2, [r1]
  150. ldr r0, =ftrace_graph_entry_stub
  151. cmp r0, r2
  152. bne ftrace_graph_caller\suffix
  153. #endif
  154. mcount_exit
  155. 1: mcount_get_lr r1 @ lr of instrumented func
  156. mov r0, lr @ instrumented function
  157. sub r0, r0, #MCOUNT_INSN_SIZE
  158. adr lr, BSYM(2f)
  159. mov pc, r2
  160. 2: mcount_exit
  161. .endm
  162. .macro __ftrace_caller suffix
  163. mcount_enter
  164. mcount_get_lr r1 @ lr of instrumented func
  165. mov r0, lr @ instrumented function
  166. sub r0, r0, #MCOUNT_INSN_SIZE
  167. .globl ftrace_call\suffix
  168. ftrace_call\suffix:
  169. bl ftrace_stub
  170. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  171. .globl ftrace_graph_call\suffix
  172. ftrace_graph_call\suffix:
  173. mov r0, r0
  174. #endif
  175. mcount_exit
  176. .endm
  177. .macro __ftrace_graph_caller
  178. sub r0, fp, #4 @ &lr of instrumented routine (&parent)
  179. #ifdef CONFIG_DYNAMIC_FTRACE
  180. @ called from __ftrace_caller, saved in mcount_enter
  181. ldr r1, [sp, #16] @ instrumented routine (func)
  182. #else
  183. @ called from __mcount, untouched in lr
  184. mov r1, lr @ instrumented routine (func)
  185. #endif
  186. sub r1, r1, #MCOUNT_INSN_SIZE
  187. mov r2, fp @ frame pointer
  188. bl prepare_ftrace_return
  189. mcount_exit
  190. .endm
  191. #ifdef CONFIG_OLD_MCOUNT
  192. /*
  193. * mcount
  194. */
  195. .macro mcount_enter
  196. stmdb sp!, {r0-r3, lr}
  197. .endm
  198. .macro mcount_get_lr reg
  199. ldr \reg, [fp, #-4]
  200. .endm
  201. .macro mcount_exit
  202. ldr lr, [fp, #-4]
  203. ldmia sp!, {r0-r3, pc}
  204. .endm
  205. ENTRY(mcount)
  206. #ifdef CONFIG_DYNAMIC_FTRACE
  207. stmdb sp!, {lr}
  208. ldr lr, [fp, #-4]
  209. ldmia sp!, {pc}
  210. #else
  211. __mcount _old
  212. #endif
  213. ENDPROC(mcount)
  214. #ifdef CONFIG_DYNAMIC_FTRACE
  215. ENTRY(ftrace_caller_old)
  216. __ftrace_caller _old
  217. ENDPROC(ftrace_caller_old)
  218. #endif
  219. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  220. ENTRY(ftrace_graph_caller_old)
  221. __ftrace_graph_caller
  222. ENDPROC(ftrace_graph_caller_old)
  223. #endif
  224. .purgem mcount_enter
  225. .purgem mcount_get_lr
  226. .purgem mcount_exit
  227. #endif
  228. /*
  229. * __gnu_mcount_nc
  230. */
  231. .macro mcount_enter
  232. stmdb sp!, {r0-r3, lr}
  233. .endm
  234. .macro mcount_get_lr reg
  235. ldr \reg, [sp, #20]
  236. .endm
  237. .macro mcount_exit
  238. ldmia sp!, {r0-r3, ip, lr}
  239. mov pc, ip
  240. .endm
  241. ENTRY(__gnu_mcount_nc)
  242. #ifdef CONFIG_DYNAMIC_FTRACE
  243. mov ip, lr
  244. ldmia sp!, {lr}
  245. mov pc, ip
  246. #else
  247. __mcount
  248. #endif
  249. ENDPROC(__gnu_mcount_nc)
  250. #ifdef CONFIG_DYNAMIC_FTRACE
  251. ENTRY(ftrace_caller)
  252. __ftrace_caller
  253. ENDPROC(ftrace_caller)
  254. #endif
  255. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  256. ENTRY(ftrace_graph_caller)
  257. __ftrace_graph_caller
  258. ENDPROC(ftrace_graph_caller)
  259. #endif
  260. .purgem mcount_enter
  261. .purgem mcount_get_lr
  262. .purgem mcount_exit
  263. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  264. .globl return_to_handler
  265. return_to_handler:
  266. stmdb sp!, {r0-r3}
  267. mov r0, fp @ frame pointer
  268. bl ftrace_return_to_handler
  269. mov lr, r0 @ r0 has real ret addr
  270. ldmia sp!, {r0-r3}
  271. mov pc, lr
  272. #endif
  273. ENTRY(ftrace_stub)
  274. .Lftrace_stub:
  275. mov pc, lr
  276. ENDPROC(ftrace_stub)
  277. #endif /* CONFIG_FUNCTION_TRACER */
  278. /*=============================================================================
  279. * SWI handler
  280. *-----------------------------------------------------------------------------
  281. */
  282. /* If we're optimising for StrongARM the resulting code won't
  283. run on an ARM7 and we can save a couple of instructions.
  284. --pb */
  285. #ifdef CONFIG_CPU_ARM710
  286. #define A710(code...) code
  287. .Larm710bug:
  288. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  289. mov r0, r0
  290. add sp, sp, #S_FRAME_SIZE
  291. subs pc, lr, #4
  292. #else
  293. #define A710(code...)
  294. #endif
  295. .align 5
  296. ENTRY(vector_swi)
  297. sub sp, sp, #S_FRAME_SIZE
  298. stmia sp, {r0 - r12} @ Calling r0 - r12
  299. ARM( add r8, sp, #S_PC )
  300. ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
  301. THUMB( mov r8, sp )
  302. THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
  303. mrs r8, spsr @ called from non-FIQ mode, so ok.
  304. str lr, [sp, #S_PC] @ Save calling PC
  305. str r8, [sp, #S_PSR] @ Save CPSR
  306. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  307. zero_fp
  308. /*
  309. * Get the system call number.
  310. */
  311. #if defined(CONFIG_OABI_COMPAT)
  312. /*
  313. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  314. * value to determine if it is an EABI or an old ABI call.
  315. */
  316. #ifdef CONFIG_ARM_THUMB
  317. tst r8, #PSR_T_BIT
  318. movne r10, #0 @ no thumb OABI emulation
  319. ldreq r10, [lr, #-4] @ get SWI instruction
  320. #else
  321. ldr r10, [lr, #-4] @ get SWI instruction
  322. A710( and ip, r10, #0x0f000000 @ check for SWI )
  323. A710( teq ip, #0x0f000000 )
  324. A710( bne .Larm710bug )
  325. #endif
  326. #ifdef CONFIG_CPU_ENDIAN_BE8
  327. rev r10, r10 @ little endian instruction
  328. #endif
  329. #elif defined(CONFIG_AEABI)
  330. /*
  331. * Pure EABI user space always put syscall number into scno (r7).
  332. */
  333. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  334. A710( and ip, ip, #0x0f000000 @ check for SWI )
  335. A710( teq ip, #0x0f000000 )
  336. A710( bne .Larm710bug )
  337. #elif defined(CONFIG_ARM_THUMB)
  338. /* Legacy ABI only, possibly thumb mode. */
  339. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  340. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  341. ldreq scno, [lr, #-4]
  342. #else
  343. /* Legacy ABI only. */
  344. ldr scno, [lr, #-4] @ get SWI instruction
  345. A710( and ip, scno, #0x0f000000 @ check for SWI )
  346. A710( teq ip, #0x0f000000 )
  347. A710( bne .Larm710bug )
  348. #endif
  349. #ifdef CONFIG_ALIGNMENT_TRAP
  350. ldr ip, __cr_alignment
  351. ldr ip, [ip]
  352. mcr p15, 0, ip, c1, c0 @ update control register
  353. #endif
  354. enable_irq
  355. get_thread_info tsk
  356. adr tbl, sys_call_table @ load syscall table pointer
  357. #if defined(CONFIG_OABI_COMPAT)
  358. /*
  359. * If the swi argument is zero, this is an EABI call and we do nothing.
  360. *
  361. * If this is an old ABI call, get the syscall number into scno and
  362. * get the old ABI syscall table address.
  363. */
  364. bics r10, r10, #0xff000000
  365. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  366. ldrne tbl, =sys_oabi_call_table
  367. #elif !defined(CONFIG_AEABI)
  368. bic scno, scno, #0xff000000 @ mask off SWI op-code
  369. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  370. #endif
  371. ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
  372. stmdb sp!, {r4, r5} @ push fifth and sixth args
  373. #ifdef CONFIG_SECCOMP
  374. tst r10, #_TIF_SECCOMP
  375. beq 1f
  376. mov r0, scno
  377. bl __secure_computing
  378. add r0, sp, #S_R0 + S_OFF @ pointer to regs
  379. ldmia r0, {r0 - r3} @ have to reload r0 - r3
  380. 1:
  381. #endif
  382. tst r10, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  383. bne __sys_trace
  384. cmp scno, #NR_syscalls @ check upper syscall limit
  385. adr lr, BSYM(ret_fast_syscall) @ return address
  386. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  387. add r1, sp, #S_OFF
  388. 2: mov why, #0 @ no longer a real syscall
  389. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  390. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  391. bcs arm_syscall
  392. b sys_ni_syscall @ not private func
  393. ENDPROC(vector_swi)
  394. /*
  395. * This is the really slow path. We're going to be doing
  396. * context switches, and waiting for our parent to respond.
  397. */
  398. __sys_trace:
  399. mov r2, scno
  400. add r1, sp, #S_OFF
  401. mov r0, #0 @ trace entry [IP = 0]
  402. bl syscall_trace
  403. adr lr, BSYM(__sys_trace_return) @ return address
  404. mov scno, r0 @ syscall number (possibly new)
  405. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  406. cmp scno, #NR_syscalls @ check upper syscall limit
  407. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  408. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  409. b 2b
  410. __sys_trace_return:
  411. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  412. mov r2, scno
  413. mov r1, sp
  414. mov r0, #1 @ trace exit [IP = 1]
  415. bl syscall_trace
  416. b ret_slow_syscall
  417. .align 5
  418. #ifdef CONFIG_ALIGNMENT_TRAP
  419. .type __cr_alignment, #object
  420. __cr_alignment:
  421. .word cr_alignment
  422. #endif
  423. .ltorg
  424. /*
  425. * This is the syscall table declaration for native ABI syscalls.
  426. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  427. */
  428. #define ABI(native, compat) native
  429. #ifdef CONFIG_AEABI
  430. #define OBSOLETE(syscall) sys_ni_syscall
  431. #else
  432. #define OBSOLETE(syscall) syscall
  433. #endif
  434. .type sys_call_table, #object
  435. ENTRY(sys_call_table)
  436. #include "calls.S"
  437. #undef ABI
  438. #undef OBSOLETE
  439. /*============================================================================
  440. * Special system call wrappers
  441. */
  442. @ r0 = syscall number
  443. @ r8 = syscall table
  444. sys_syscall:
  445. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  446. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  447. cmpne scno, #NR_syscalls @ check range
  448. stmloia sp, {r5, r6} @ shuffle args
  449. movlo r0, r1
  450. movlo r1, r2
  451. movlo r2, r3
  452. movlo r3, r4
  453. ldrlo pc, [tbl, scno, lsl #2]
  454. b sys_ni_syscall
  455. ENDPROC(sys_syscall)
  456. sys_fork_wrapper:
  457. add r0, sp, #S_OFF
  458. b sys_fork
  459. ENDPROC(sys_fork_wrapper)
  460. sys_vfork_wrapper:
  461. add r0, sp, #S_OFF
  462. b sys_vfork
  463. ENDPROC(sys_vfork_wrapper)
  464. sys_execve_wrapper:
  465. add r3, sp, #S_OFF
  466. b sys_execve
  467. ENDPROC(sys_execve_wrapper)
  468. sys_clone_wrapper:
  469. add ip, sp, #S_OFF
  470. str ip, [sp, #4]
  471. b sys_clone
  472. ENDPROC(sys_clone_wrapper)
  473. sys_sigreturn_wrapper:
  474. add r0, sp, #S_OFF
  475. mov why, #0 @ prevent syscall restart handling
  476. b sys_sigreturn
  477. ENDPROC(sys_sigreturn_wrapper)
  478. sys_rt_sigreturn_wrapper:
  479. add r0, sp, #S_OFF
  480. mov why, #0 @ prevent syscall restart handling
  481. b sys_rt_sigreturn
  482. ENDPROC(sys_rt_sigreturn_wrapper)
  483. sys_sigaltstack_wrapper:
  484. ldr r2, [sp, #S_OFF + S_SP]
  485. b do_sigaltstack
  486. ENDPROC(sys_sigaltstack_wrapper)
  487. sys_statfs64_wrapper:
  488. teq r1, #88
  489. moveq r1, #84
  490. b sys_statfs64
  491. ENDPROC(sys_statfs64_wrapper)
  492. sys_fstatfs64_wrapper:
  493. teq r1, #88
  494. moveq r1, #84
  495. b sys_fstatfs64
  496. ENDPROC(sys_fstatfs64_wrapper)
  497. /*
  498. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  499. * offset, we return EINVAL.
  500. */
  501. sys_mmap2:
  502. #if PAGE_SHIFT > 12
  503. tst r5, #PGOFF_MASK
  504. moveq r5, r5, lsr #PAGE_SHIFT - 12
  505. streq r5, [sp, #4]
  506. beq sys_mmap_pgoff
  507. mov r0, #-EINVAL
  508. mov pc, lr
  509. #else
  510. str r5, [sp, #4]
  511. b sys_mmap_pgoff
  512. #endif
  513. ENDPROC(sys_mmap2)
  514. #ifdef CONFIG_OABI_COMPAT
  515. /*
  516. * These are syscalls with argument register differences
  517. */
  518. sys_oabi_pread64:
  519. stmia sp, {r3, r4}
  520. b sys_pread64
  521. ENDPROC(sys_oabi_pread64)
  522. sys_oabi_pwrite64:
  523. stmia sp, {r3, r4}
  524. b sys_pwrite64
  525. ENDPROC(sys_oabi_pwrite64)
  526. sys_oabi_truncate64:
  527. mov r3, r2
  528. mov r2, r1
  529. b sys_truncate64
  530. ENDPROC(sys_oabi_truncate64)
  531. sys_oabi_ftruncate64:
  532. mov r3, r2
  533. mov r2, r1
  534. b sys_ftruncate64
  535. ENDPROC(sys_oabi_ftruncate64)
  536. sys_oabi_readahead:
  537. str r3, [sp]
  538. mov r3, r2
  539. mov r2, r1
  540. b sys_readahead
  541. ENDPROC(sys_oabi_readahead)
  542. /*
  543. * Let's declare a second syscall table for old ABI binaries
  544. * using the compatibility syscall entries.
  545. */
  546. #define ABI(native, compat) compat
  547. #define OBSOLETE(syscall) syscall
  548. .type sys_oabi_call_table, #object
  549. ENTRY(sys_oabi_call_table)
  550. #include "calls.S"
  551. #undef ABI
  552. #undef OBSOLETE
  553. #endif