entry-common.S 14 KB

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