entry-common.S 15 KB

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