entry-common.S 14 KB

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