entry-common.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. /* perform architecture specific actions before user return */
  29. arch_ret_to_user r1, lr
  30. restore_user_regs fast = 1, offset = S_OFF
  31. UNWIND(.fnend )
  32. /*
  33. * Ok, we need to do extra processing, enter the slow path.
  34. */
  35. fast_work_pending:
  36. str r0, [sp, #S_R0+S_OFF]! @ returned r0
  37. work_pending:
  38. tst r1, #_TIF_NEED_RESCHED
  39. bne work_resched
  40. tst r1, #_TIF_SIGPENDING|_TIF_NOTIFY_RESUME
  41. beq no_work_pending
  42. mov r0, sp @ 'regs'
  43. mov r2, why @ 'syscall'
  44. bl do_notify_resume
  45. b ret_slow_syscall @ Check work again
  46. work_resched:
  47. bl schedule
  48. /*
  49. * "slow" syscall return path. "why" tells us if this was a real syscall.
  50. */
  51. ENTRY(ret_to_user)
  52. ret_slow_syscall:
  53. disable_irq @ disable interrupts
  54. ldr r1, [tsk, #TI_FLAGS]
  55. tst r1, #_TIF_WORK_MASK
  56. bne work_pending
  57. no_work_pending:
  58. /* perform architecture specific actions before user return */
  59. arch_ret_to_user r1, lr
  60. restore_user_regs fast = 0, offset = 0
  61. ENDPROC(ret_to_user)
  62. /*
  63. * This is how we return from a fork.
  64. */
  65. ENTRY(ret_from_fork)
  66. bl schedule_tail
  67. get_thread_info tsk
  68. ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
  69. mov why, #1
  70. tst r1, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  71. beq ret_slow_syscall
  72. mov r1, sp
  73. mov r0, #1 @ trace exit [IP = 1]
  74. bl syscall_trace
  75. b ret_slow_syscall
  76. ENDPROC(ret_from_fork)
  77. .equ NR_syscalls,0
  78. #define CALL(x) .equ NR_syscalls,NR_syscalls+1
  79. #include "calls.S"
  80. #undef CALL
  81. #define CALL(x) .long x
  82. #ifdef CONFIG_FUNCTION_TRACER
  83. #ifdef CONFIG_DYNAMIC_FTRACE
  84. ENTRY(mcount)
  85. stmdb sp!, {r0-r3, lr}
  86. mov r0, lr
  87. sub r0, r0, #MCOUNT_INSN_SIZE
  88. .globl mcount_call
  89. mcount_call:
  90. bl ftrace_stub
  91. ldr lr, [fp, #-4] @ restore lr
  92. ldmia sp!, {r0-r3, pc}
  93. ENTRY(ftrace_caller)
  94. stmdb sp!, {r0-r3, lr}
  95. ldr r1, [fp, #-4]
  96. mov r0, lr
  97. sub r0, r0, #MCOUNT_INSN_SIZE
  98. .globl ftrace_call
  99. ftrace_call:
  100. bl ftrace_stub
  101. ldr lr, [fp, #-4] @ restore lr
  102. ldmia sp!, {r0-r3, pc}
  103. #else
  104. ENTRY(__gnu_mcount_nc)
  105. stmdb sp!, {r0-r3, lr}
  106. ldr r0, =ftrace_trace_function
  107. ldr r2, [r0]
  108. adr r0, ftrace_stub
  109. cmp r0, r2
  110. bne gnu_trace
  111. ldmia sp!, {r0-r3, ip, lr}
  112. mov pc, ip
  113. gnu_trace:
  114. ldr r1, [sp, #20] @ lr of instrumented routine
  115. mov r0, lr
  116. sub r0, r0, #MCOUNT_INSN_SIZE
  117. mov lr, pc
  118. mov pc, r2
  119. ldmia sp!, {r0-r3, ip, lr}
  120. mov pc, ip
  121. ENTRY(mcount)
  122. stmdb sp!, {r0-r3, lr}
  123. ldr r0, =ftrace_trace_function
  124. ldr r2, [r0]
  125. adr r0, ftrace_stub
  126. cmp r0, r2
  127. bne trace
  128. ldr lr, [fp, #-4] @ restore lr
  129. ldmia sp!, {r0-r3, pc}
  130. trace:
  131. ldr r1, [fp, #-4] @ lr of instrumented routine
  132. mov r0, lr
  133. sub r0, r0, #MCOUNT_INSN_SIZE
  134. mov lr, pc
  135. mov pc, r2
  136. ldr lr, [fp, #-4] @ restore lr
  137. ldmia sp!, {r0-r3, pc}
  138. #endif /* CONFIG_DYNAMIC_FTRACE */
  139. .globl ftrace_stub
  140. ftrace_stub:
  141. mov pc, lr
  142. #endif /* CONFIG_FUNCTION_TRACER */
  143. /*=============================================================================
  144. * SWI handler
  145. *-----------------------------------------------------------------------------
  146. */
  147. /* If we're optimising for StrongARM the resulting code won't
  148. run on an ARM7 and we can save a couple of instructions.
  149. --pb */
  150. #ifdef CONFIG_CPU_ARM710
  151. #define A710(code...) code
  152. .Larm710bug:
  153. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  154. mov r0, r0
  155. add sp, sp, #S_FRAME_SIZE
  156. subs pc, lr, #4
  157. #else
  158. #define A710(code...)
  159. #endif
  160. .align 5
  161. ENTRY(vector_swi)
  162. sub sp, sp, #S_FRAME_SIZE
  163. stmia sp, {r0 - r12} @ Calling r0 - r12
  164. ARM( add r8, sp, #S_PC )
  165. ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
  166. THUMB( mov r8, sp )
  167. THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
  168. mrs r8, spsr @ called from non-FIQ mode, so ok.
  169. str lr, [sp, #S_PC] @ Save calling PC
  170. str r8, [sp, #S_PSR] @ Save CPSR
  171. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  172. zero_fp
  173. /*
  174. * Get the system call number.
  175. */
  176. #if defined(CONFIG_OABI_COMPAT)
  177. /*
  178. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  179. * value to determine if it is an EABI or an old ABI call.
  180. */
  181. #ifdef CONFIG_ARM_THUMB
  182. tst r8, #PSR_T_BIT
  183. movne r10, #0 @ no thumb OABI emulation
  184. ldreq r10, [lr, #-4] @ get SWI instruction
  185. #else
  186. ldr r10, [lr, #-4] @ get SWI instruction
  187. A710( and ip, r10, #0x0f000000 @ check for SWI )
  188. A710( teq ip, #0x0f000000 )
  189. A710( bne .Larm710bug )
  190. #endif
  191. #ifdef CONFIG_CPU_ENDIAN_BE8
  192. rev r10, r10 @ little endian instruction
  193. #endif
  194. #elif defined(CONFIG_AEABI)
  195. /*
  196. * Pure EABI user space always put syscall number into scno (r7).
  197. */
  198. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  199. A710( and ip, ip, #0x0f000000 @ check for SWI )
  200. A710( teq ip, #0x0f000000 )
  201. A710( bne .Larm710bug )
  202. #elif defined(CONFIG_ARM_THUMB)
  203. /* Legacy ABI only, possibly thumb mode. */
  204. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  205. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  206. ldreq scno, [lr, #-4]
  207. #else
  208. /* Legacy ABI only. */
  209. ldr scno, [lr, #-4] @ get SWI instruction
  210. A710( and ip, scno, #0x0f000000 @ check for SWI )
  211. A710( teq ip, #0x0f000000 )
  212. A710( bne .Larm710bug )
  213. #endif
  214. #ifdef CONFIG_ALIGNMENT_TRAP
  215. ldr ip, __cr_alignment
  216. ldr ip, [ip]
  217. mcr p15, 0, ip, c1, c0 @ update control register
  218. #endif
  219. enable_irq
  220. get_thread_info tsk
  221. adr tbl, sys_call_table @ load syscall table pointer
  222. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  223. #if defined(CONFIG_OABI_COMPAT)
  224. /*
  225. * If the swi argument is zero, this is an EABI call and we do nothing.
  226. *
  227. * If this is an old ABI call, get the syscall number into scno and
  228. * get the old ABI syscall table address.
  229. */
  230. bics r10, r10, #0xff000000
  231. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  232. ldrne tbl, =sys_oabi_call_table
  233. #elif !defined(CONFIG_AEABI)
  234. bic scno, scno, #0xff000000 @ mask off SWI op-code
  235. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  236. #endif
  237. stmdb sp!, {r4, r5} @ push fifth and sixth args
  238. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  239. bne __sys_trace
  240. cmp scno, #NR_syscalls @ check upper syscall limit
  241. adr lr, BSYM(ret_fast_syscall) @ return address
  242. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  243. add r1, sp, #S_OFF
  244. 2: mov why, #0 @ no longer a real syscall
  245. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  246. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  247. bcs arm_syscall
  248. b sys_ni_syscall @ not private func
  249. ENDPROC(vector_swi)
  250. /*
  251. * This is the really slow path. We're going to be doing
  252. * context switches, and waiting for our parent to respond.
  253. */
  254. __sys_trace:
  255. mov r2, scno
  256. add r1, sp, #S_OFF
  257. mov r0, #0 @ trace entry [IP = 0]
  258. bl syscall_trace
  259. adr lr, BSYM(__sys_trace_return) @ return address
  260. mov scno, r0 @ syscall number (possibly new)
  261. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  262. cmp scno, #NR_syscalls @ check upper syscall limit
  263. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  264. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  265. b 2b
  266. __sys_trace_return:
  267. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  268. mov r2, scno
  269. mov r1, sp
  270. mov r0, #1 @ trace exit [IP = 1]
  271. bl syscall_trace
  272. b ret_slow_syscall
  273. .align 5
  274. #ifdef CONFIG_ALIGNMENT_TRAP
  275. .type __cr_alignment, #object
  276. __cr_alignment:
  277. .word cr_alignment
  278. #endif
  279. .ltorg
  280. /*
  281. * This is the syscall table declaration for native ABI syscalls.
  282. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  283. */
  284. #define ABI(native, compat) native
  285. #ifdef CONFIG_AEABI
  286. #define OBSOLETE(syscall) sys_ni_syscall
  287. #else
  288. #define OBSOLETE(syscall) syscall
  289. #endif
  290. .type sys_call_table, #object
  291. ENTRY(sys_call_table)
  292. #include "calls.S"
  293. #undef ABI
  294. #undef OBSOLETE
  295. /*============================================================================
  296. * Special system call wrappers
  297. */
  298. @ r0 = syscall number
  299. @ r8 = syscall table
  300. sys_syscall:
  301. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  302. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  303. cmpne scno, #NR_syscalls @ check range
  304. stmloia sp, {r5, r6} @ shuffle args
  305. movlo r0, r1
  306. movlo r1, r2
  307. movlo r2, r3
  308. movlo r3, r4
  309. ldrlo pc, [tbl, scno, lsl #2]
  310. b sys_ni_syscall
  311. ENDPROC(sys_syscall)
  312. sys_fork_wrapper:
  313. add r0, sp, #S_OFF
  314. b sys_fork
  315. ENDPROC(sys_fork_wrapper)
  316. sys_vfork_wrapper:
  317. add r0, sp, #S_OFF
  318. b sys_vfork
  319. ENDPROC(sys_vfork_wrapper)
  320. sys_execve_wrapper:
  321. add r3, sp, #S_OFF
  322. b sys_execve
  323. ENDPROC(sys_execve_wrapper)
  324. sys_clone_wrapper:
  325. add ip, sp, #S_OFF
  326. str ip, [sp, #4]
  327. b sys_clone
  328. ENDPROC(sys_clone_wrapper)
  329. sys_sigreturn_wrapper:
  330. add r0, sp, #S_OFF
  331. b sys_sigreturn
  332. ENDPROC(sys_sigreturn_wrapper)
  333. sys_rt_sigreturn_wrapper:
  334. add r0, sp, #S_OFF
  335. b sys_rt_sigreturn
  336. ENDPROC(sys_rt_sigreturn_wrapper)
  337. sys_sigaltstack_wrapper:
  338. ldr r2, [sp, #S_OFF + S_SP]
  339. b do_sigaltstack
  340. ENDPROC(sys_sigaltstack_wrapper)
  341. sys_statfs64_wrapper:
  342. teq r1, #88
  343. moveq r1, #84
  344. b sys_statfs64
  345. ENDPROC(sys_statfs64_wrapper)
  346. sys_fstatfs64_wrapper:
  347. teq r1, #88
  348. moveq r1, #84
  349. b sys_fstatfs64
  350. ENDPROC(sys_fstatfs64_wrapper)
  351. /*
  352. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  353. * offset, we return EINVAL.
  354. */
  355. sys_mmap2:
  356. #if PAGE_SHIFT > 12
  357. tst r5, #PGOFF_MASK
  358. moveq r5, r5, lsr #PAGE_SHIFT - 12
  359. streq r5, [sp, #4]
  360. beq do_mmap2
  361. mov r0, #-EINVAL
  362. mov pc, lr
  363. #else
  364. str r5, [sp, #4]
  365. b do_mmap2
  366. #endif
  367. ENDPROC(sys_mmap2)
  368. #ifdef CONFIG_OABI_COMPAT
  369. /*
  370. * These are syscalls with argument register differences
  371. */
  372. sys_oabi_pread64:
  373. stmia sp, {r3, r4}
  374. b sys_pread64
  375. ENDPROC(sys_oabi_pread64)
  376. sys_oabi_pwrite64:
  377. stmia sp, {r3, r4}
  378. b sys_pwrite64
  379. ENDPROC(sys_oabi_pwrite64)
  380. sys_oabi_truncate64:
  381. mov r3, r2
  382. mov r2, r1
  383. b sys_truncate64
  384. ENDPROC(sys_oabi_truncate64)
  385. sys_oabi_ftruncate64:
  386. mov r3, r2
  387. mov r2, r1
  388. b sys_ftruncate64
  389. ENDPROC(sys_oabi_ftruncate64)
  390. sys_oabi_readahead:
  391. str r3, [sp]
  392. mov r3, r2
  393. mov r2, r1
  394. b sys_readahead
  395. ENDPROC(sys_oabi_readahead)
  396. /*
  397. * Let's declare a second syscall table for old ABI binaries
  398. * using the compatibility syscall entries.
  399. */
  400. #define ABI(native, compat) compat
  401. #define OBSOLETE(syscall) syscall
  402. .type sys_oabi_call_table, #object
  403. ENTRY(sys_oabi_call_table)
  404. #include "calls.S"
  405. #undef ABI
  406. #undef OBSOLETE
  407. #endif