entry-common.S 11 KB

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