entry-common.S 14 KB

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