entry-common.S 13 KB

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