entry-common.S 14 KB

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