entry-common.S 14 KB

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