entry-common.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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(__gnu_mcount_nc)
  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 gnu_trace
  125. ldmia sp!, {r0-r3, ip, lr}
  126. bx ip
  127. gnu_trace:
  128. ldr r1, [sp, #20] @ lr of instrumented routine
  129. mov r0, lr
  130. sub r0, r0, #MCOUNT_INSN_SIZE
  131. mov lr, pc
  132. mov pc, r2
  133. ldmia sp!, {r0-r3, ip, lr}
  134. bx ip
  135. ENTRY(mcount)
  136. stmdb sp!, {r0-r3, lr}
  137. ldr r0, =ftrace_trace_function
  138. ldr r2, [r0]
  139. adr r0, ftrace_stub
  140. cmp r0, r2
  141. bne trace
  142. ldr lr, [fp, #-4] @ restore lr
  143. ldmia sp!, {r0-r3, pc}
  144. trace:
  145. ldr r1, [fp, #-4] @ lr of instrumented routine
  146. mov r0, lr
  147. sub r0, r0, #MCOUNT_INSN_SIZE
  148. mov lr, pc
  149. mov pc, r2
  150. mov lr, r1 @ restore lr
  151. ldmia sp!, {r0-r3, pc}
  152. #endif /* CONFIG_DYNAMIC_FTRACE */
  153. .globl ftrace_stub
  154. ftrace_stub:
  155. mov pc, lr
  156. #endif /* CONFIG_FUNCTION_TRACER */
  157. /*=============================================================================
  158. * SWI handler
  159. *-----------------------------------------------------------------------------
  160. */
  161. /* If we're optimising for StrongARM the resulting code won't
  162. run on an ARM7 and we can save a couple of instructions.
  163. --pb */
  164. #ifdef CONFIG_CPU_ARM710
  165. #define A710(code...) code
  166. .Larm710bug:
  167. ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
  168. mov r0, r0
  169. add sp, sp, #S_FRAME_SIZE
  170. subs pc, lr, #4
  171. #else
  172. #define A710(code...)
  173. #endif
  174. .align 5
  175. ENTRY(vector_swi)
  176. sub sp, sp, #S_FRAME_SIZE
  177. stmia sp, {r0 - r12} @ Calling r0 - r12
  178. add r8, sp, #S_PC
  179. stmdb r8, {sp, lr}^ @ Calling sp, lr
  180. mrs r8, spsr @ called from non-FIQ mode, so ok.
  181. str lr, [sp, #S_PC] @ Save calling PC
  182. str r8, [sp, #S_PSR] @ Save CPSR
  183. str r0, [sp, #S_OLD_R0] @ Save OLD_R0
  184. zero_fp
  185. /*
  186. * Get the system call number.
  187. */
  188. #if defined(CONFIG_OABI_COMPAT)
  189. /*
  190. * If we have CONFIG_OABI_COMPAT then we need to look at the swi
  191. * value to determine if it is an EABI or an old ABI call.
  192. */
  193. #ifdef CONFIG_ARM_THUMB
  194. tst r8, #PSR_T_BIT
  195. movne r10, #0 @ no thumb OABI emulation
  196. ldreq r10, [lr, #-4] @ get SWI instruction
  197. #else
  198. ldr r10, [lr, #-4] @ get SWI instruction
  199. A710( and ip, r10, #0x0f000000 @ check for SWI )
  200. A710( teq ip, #0x0f000000 )
  201. A710( bne .Larm710bug )
  202. #endif
  203. #ifdef CONFIG_CPU_ENDIAN_BE8
  204. rev r10, r10 @ little endian instruction
  205. #endif
  206. #elif defined(CONFIG_AEABI)
  207. /*
  208. * Pure EABI user space always put syscall number into scno (r7).
  209. */
  210. A710( ldr ip, [lr, #-4] @ get SWI instruction )
  211. A710( and ip, ip, #0x0f000000 @ check for SWI )
  212. A710( teq ip, #0x0f000000 )
  213. A710( bne .Larm710bug )
  214. #elif defined(CONFIG_ARM_THUMB)
  215. /* Legacy ABI only, possibly thumb mode. */
  216. tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
  217. addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
  218. ldreq scno, [lr, #-4]
  219. #else
  220. /* Legacy ABI only. */
  221. ldr scno, [lr, #-4] @ get SWI instruction
  222. A710( and ip, scno, #0x0f000000 @ check for SWI )
  223. A710( teq ip, #0x0f000000 )
  224. A710( bne .Larm710bug )
  225. #endif
  226. #ifdef CONFIG_ALIGNMENT_TRAP
  227. ldr ip, __cr_alignment
  228. ldr ip, [ip]
  229. mcr p15, 0, ip, c1, c0 @ update control register
  230. #endif
  231. enable_irq
  232. get_thread_info tsk
  233. adr tbl, sys_call_table @ load syscall table pointer
  234. ldr ip, [tsk, #TI_FLAGS] @ check for syscall tracing
  235. #if defined(CONFIG_OABI_COMPAT)
  236. /*
  237. * If the swi argument is zero, this is an EABI call and we do nothing.
  238. *
  239. * If this is an old ABI call, get the syscall number into scno and
  240. * get the old ABI syscall table address.
  241. */
  242. bics r10, r10, #0xff000000
  243. eorne scno, r10, #__NR_OABI_SYSCALL_BASE
  244. ldrne tbl, =sys_oabi_call_table
  245. #elif !defined(CONFIG_AEABI)
  246. bic scno, scno, #0xff000000 @ mask off SWI op-code
  247. eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
  248. #endif
  249. stmdb sp!, {r4, r5} @ push fifth and sixth args
  250. tst ip, #_TIF_SYSCALL_TRACE @ are we tracing syscalls?
  251. bne __sys_trace
  252. cmp scno, #NR_syscalls @ check upper syscall limit
  253. adr lr, ret_fast_syscall @ return address
  254. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  255. add r1, sp, #S_OFF
  256. 2: mov why, #0 @ no longer a real syscall
  257. cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
  258. eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
  259. bcs arm_syscall
  260. b sys_ni_syscall @ not private func
  261. ENDPROC(vector_swi)
  262. /*
  263. * This is the really slow path. We're going to be doing
  264. * context switches, and waiting for our parent to respond.
  265. */
  266. __sys_trace:
  267. mov r2, scno
  268. add r1, sp, #S_OFF
  269. mov r0, #0 @ trace entry [IP = 0]
  270. bl syscall_trace
  271. adr lr, __sys_trace_return @ return address
  272. mov scno, r0 @ syscall number (possibly new)
  273. add r1, sp, #S_R0 + S_OFF @ pointer to regs
  274. cmp scno, #NR_syscalls @ check upper syscall limit
  275. ldmccia r1, {r0 - r3} @ have to reload r0 - r3
  276. ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
  277. b 2b
  278. __sys_trace_return:
  279. str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
  280. mov r2, scno
  281. mov r1, sp
  282. mov r0, #1 @ trace exit [IP = 1]
  283. bl syscall_trace
  284. b ret_slow_syscall
  285. .align 5
  286. #ifdef CONFIG_ALIGNMENT_TRAP
  287. .type __cr_alignment, #object
  288. __cr_alignment:
  289. .word cr_alignment
  290. #endif
  291. .ltorg
  292. /*
  293. * This is the syscall table declaration for native ABI syscalls.
  294. * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
  295. */
  296. #define ABI(native, compat) native
  297. #ifdef CONFIG_AEABI
  298. #define OBSOLETE(syscall) sys_ni_syscall
  299. #else
  300. #define OBSOLETE(syscall) syscall
  301. #endif
  302. .type sys_call_table, #object
  303. ENTRY(sys_call_table)
  304. #include "calls.S"
  305. #undef ABI
  306. #undef OBSOLETE
  307. /*============================================================================
  308. * Special system call wrappers
  309. */
  310. @ r0 = syscall number
  311. @ r8 = syscall table
  312. sys_syscall:
  313. bic scno, r0, #__NR_OABI_SYSCALL_BASE
  314. cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
  315. cmpne scno, #NR_syscalls @ check range
  316. stmloia sp, {r5, r6} @ shuffle args
  317. movlo r0, r1
  318. movlo r1, r2
  319. movlo r2, r3
  320. movlo r3, r4
  321. ldrlo pc, [tbl, scno, lsl #2]
  322. b sys_ni_syscall
  323. ENDPROC(sys_syscall)
  324. sys_fork_wrapper:
  325. add r0, sp, #S_OFF
  326. b sys_fork
  327. ENDPROC(sys_fork_wrapper)
  328. sys_vfork_wrapper:
  329. add r0, sp, #S_OFF
  330. b sys_vfork
  331. ENDPROC(sys_vfork_wrapper)
  332. sys_execve_wrapper:
  333. add r3, sp, #S_OFF
  334. b sys_execve
  335. ENDPROC(sys_execve_wrapper)
  336. sys_clone_wrapper:
  337. add ip, sp, #S_OFF
  338. str ip, [sp, #4]
  339. b sys_clone
  340. ENDPROC(sys_clone_wrapper)
  341. sys_sigsuspend_wrapper:
  342. add r3, sp, #S_OFF
  343. b sys_sigsuspend
  344. ENDPROC(sys_sigsuspend_wrapper)
  345. sys_rt_sigsuspend_wrapper:
  346. add r2, sp, #S_OFF
  347. b sys_rt_sigsuspend
  348. ENDPROC(sys_rt_sigsuspend_wrapper)
  349. sys_sigreturn_wrapper:
  350. add r0, sp, #S_OFF
  351. b sys_sigreturn
  352. ENDPROC(sys_sigreturn_wrapper)
  353. sys_rt_sigreturn_wrapper:
  354. add r0, sp, #S_OFF
  355. b sys_rt_sigreturn
  356. ENDPROC(sys_rt_sigreturn_wrapper)
  357. sys_sigaltstack_wrapper:
  358. ldr r2, [sp, #S_OFF + S_SP]
  359. b do_sigaltstack
  360. ENDPROC(sys_sigaltstack_wrapper)
  361. sys_statfs64_wrapper:
  362. teq r1, #88
  363. moveq r1, #84
  364. b sys_statfs64
  365. ENDPROC(sys_statfs64_wrapper)
  366. sys_fstatfs64_wrapper:
  367. teq r1, #88
  368. moveq r1, #84
  369. b sys_fstatfs64
  370. ENDPROC(sys_fstatfs64_wrapper)
  371. /*
  372. * Note: off_4k (r5) is always units of 4K. If we can't do the requested
  373. * offset, we return EINVAL.
  374. */
  375. sys_mmap2:
  376. #if PAGE_SHIFT > 12
  377. tst r5, #PGOFF_MASK
  378. moveq r5, r5, lsr #PAGE_SHIFT - 12
  379. streq r5, [sp, #4]
  380. beq do_mmap2
  381. mov r0, #-EINVAL
  382. mov pc, lr
  383. #else
  384. str r5, [sp, #4]
  385. b do_mmap2
  386. #endif
  387. ENDPROC(sys_mmap2)
  388. ENTRY(pabort_ifar)
  389. mrc p15, 0, r0, cr6, cr0, 2
  390. ENTRY(pabort_noifar)
  391. mov pc, lr
  392. ENDPROC(pabort_ifar)
  393. ENDPROC(pabort_noifar)
  394. #ifdef CONFIG_OABI_COMPAT
  395. /*
  396. * These are syscalls with argument register differences
  397. */
  398. sys_oabi_pread64:
  399. stmia sp, {r3, r4}
  400. b sys_pread64
  401. ENDPROC(sys_oabi_pread64)
  402. sys_oabi_pwrite64:
  403. stmia sp, {r3, r4}
  404. b sys_pwrite64
  405. ENDPROC(sys_oabi_pwrite64)
  406. sys_oabi_truncate64:
  407. mov r3, r2
  408. mov r2, r1
  409. b sys_truncate64
  410. ENDPROC(sys_oabi_truncate64)
  411. sys_oabi_ftruncate64:
  412. mov r3, r2
  413. mov r2, r1
  414. b sys_ftruncate64
  415. ENDPROC(sys_oabi_ftruncate64)
  416. sys_oabi_readahead:
  417. str r3, [sp]
  418. mov r3, r2
  419. mov r2, r1
  420. b sys_readahead
  421. ENDPROC(sys_oabi_readahead)
  422. /*
  423. * Let's declare a second syscall table for old ABI binaries
  424. * using the compatibility syscall entries.
  425. */
  426. #define ABI(native, compat) compat
  427. #define OBSOLETE(syscall) syscall
  428. .type sys_oabi_call_table, #object
  429. ENTRY(sys_oabi_call_table)
  430. #include "calls.S"
  431. #undef ABI
  432. #undef OBSOLETE
  433. #endif