2 * linux/arch/arm/kernel/entry-common.S
4 * Copyright (C) 2000 Russell King
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.
11 #include <asm/assembler.h>
12 #include <asm/unistd.h>
13 #include <asm/ftrace.h>
14 #include <asm/unwind.h>
15 #include <asm/memory.h>
17 #ifdef CONFIG_NEED_RET_TO_USER
18 #include <mach/entry-macro.S>
20 .macro arch_ret_to_user, tmp1, tmp2
24 #include "entry-header.S"
28 #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING))
30 * This is the fast syscall return path. We do as little as possible here,
31 * such as avoiding writing r0 to the stack. We only use this path if we
32 * have tracing and context tracking disabled - the overheads from those
33 * features make this path too inefficient.
38 disable_irq_notrace @ disable interrupts
39 ldr r2, [tsk, #TI_ADDR_LIMIT]
41 blne addr_limit_check_failed
42 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
43 tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
46 /* perform architecture specific actions before user return */
47 arch_ret_to_user r1, lr
49 restore_user_regs fast = 1, offset = S_OFF
51 ENDPROC(ret_fast_syscall)
53 /* Ok, we need to do extra processing, enter the slow path. */
55 str r0, [sp, #S_R0+S_OFF]! @ returned r0
56 /* fall through to work_pending */
59 * The "replacement" ret_fast_syscall for when tracing or context tracking
60 * is enabled. As we will need to call out to some C functions, we save
61 * r0 first to avoid needing to save registers around each C function call.
66 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
67 disable_irq_notrace @ disable interrupts
68 ldr r2, [tsk, #TI_ADDR_LIMIT]
70 blne addr_limit_check_failed
71 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
72 tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
75 ENDPROC(ret_fast_syscall)
77 /* Slower path - fall through to work_pending */
80 tst r1, #_TIF_SYSCALL_WORK
81 bne __sys_trace_return_nosave
84 mov r2, why @ 'syscall'
88 movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
89 ldmia sp, {r0 - r6} @ have to reload r0 - r6
90 b local_restart @ ... and off we go
91 ENDPROC(ret_fast_syscall)
94 * "slow" syscall return path. "why" tells us if this was a real syscall.
95 * IRQs may be enabled here, so always disable them. Note that we use the
96 * "notrace" version to avoid calling into the tracing code unnecessarily.
97 * do_work_pending() will update this state if necessary.
101 disable_irq_notrace @ disable interrupts
102 ENTRY(ret_to_user_from_irq)
103 ldr r2, [tsk, #TI_ADDR_LIMIT]
105 blne addr_limit_check_failed
106 ldr r1, [tsk, #TI_FLAGS]
107 tst r1, #_TIF_WORK_MASK
108 bne slow_work_pending
110 asm_trace_hardirqs_on save = 0
112 /* perform architecture specific actions before user return */
113 arch_ret_to_user r1, lr
114 ct_user_enter save = 0
116 restore_user_regs fast = 0, offset = 0
117 ENDPROC(ret_to_user_from_irq)
121 * This is how we return from a fork.
129 1: get_thread_info tsk
131 ENDPROC(ret_from_fork)
134 #define CALL(x) .equ NR_syscalls,NR_syscalls+1
138 * Ensure that the system call table is equal to __NR_syscalls,
139 * which is the value the rest of the system sees
141 .ifne NR_syscalls - __NR_syscalls
142 .error "__NR_syscalls is not equal to the size of the syscall table"
146 #define CALL(x) .long x
148 /*=============================================================================
150 *-----------------------------------------------------------------------------
155 #ifdef CONFIG_CPU_V7M
158 sub sp, sp, #S_FRAME_SIZE
159 stmia sp, {r0 - r12} @ Calling r0 - r12
160 ARM( add r8, sp, #S_PC )
161 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
163 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
164 mrs r8, spsr @ called from non-FIQ mode, so ok.
165 str lr, [sp, #S_PC] @ Save calling PC
166 str r8, [sp, #S_PSR] @ Save CPSR
167 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
170 alignment_trap r10, ip, __cr_alignment
176 * Get the system call number.
179 #if defined(CONFIG_OABI_COMPAT)
182 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
183 * value to determine if it is an EABI or an old ABI call.
185 #ifdef CONFIG_ARM_THUMB
187 movne r10, #0 @ no thumb OABI emulation
188 USER( ldreq r10, [lr, #-4] ) @ get SWI instruction
190 USER( ldr r10, [lr, #-4] ) @ get SWI instruction
192 ARM_BE8(rev r10, r10) @ little endian instruction
194 #elif defined(CONFIG_AEABI)
197 * Pure EABI user space always put syscall number into scno (r7).
199 #elif defined(CONFIG_ARM_THUMB)
200 /* Legacy ABI only, possibly thumb mode. */
201 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
202 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
203 USER( ldreq scno, [lr, #-4] )
206 /* Legacy ABI only. */
207 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
212 adr tbl, sys_call_table @ load syscall table pointer
214 #if defined(CONFIG_OABI_COMPAT)
216 * If the swi argument is zero, this is an EABI call and we do nothing.
218 * If this is an old ABI call, get the syscall number into scno and
219 * get the old ABI syscall table address.
221 bics r10, r10, #0xff000000
222 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
223 ldrne tbl, =sys_oabi_call_table
224 #elif !defined(CONFIG_AEABI)
225 bic scno, scno, #0xff000000 @ mask off SWI op-code
226 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
230 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
231 stmdb sp!, {r4, r5} @ push fifth and sixth args
233 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
236 cmp scno, #NR_syscalls @ check upper syscall limit
237 badr lr, ret_fast_syscall @ return address
238 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
241 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
242 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
244 mov why, #0 @ no longer a real syscall
245 b sys_ni_syscall @ not private func
247 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
249 * We failed to handle a fault trying to access the page
250 * containing the swi instruction, but we're not really in a
251 * position to return -EFAULT. Instead, return back to the
252 * instruction and re-enter the user fault handling path trying
253 * to page it in. This will likely result in sending SEGV to the
264 * This is the really slow path. We're going to be doing
265 * context switches, and waiting for our parent to respond.
270 bl syscall_trace_enter
272 badr lr, __sys_trace_return @ return address
273 mov scno, r0 @ syscall number (possibly new)
274 add r1, sp, #S_R0 + S_OFF @ pointer to regs
275 cmp scno, #NR_syscalls @ check upper syscall limit
276 ldmccia r1, {r0 - r6} @ have to reload r0 - r6
277 stmccia sp, {r4, r5} @ and update the stack args
278 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
279 cmp scno, #-1 @ skip the syscall?
281 add sp, sp, #S_OFF @ restore stack
285 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
287 bl syscall_trace_exit
290 __sys_trace_return_nosave:
293 bl syscall_trace_exit
297 #ifdef CONFIG_ALIGNMENT_TRAP
298 .type __cr_alignment, #object
305 * This is the syscall table declaration for native ABI syscalls.
306 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
308 #define ABI(native, compat) native
310 #define OBSOLETE(syscall) sys_ni_syscall
312 #define OBSOLETE(syscall) syscall
315 .type sys_call_table, #object
316 ENTRY(sys_call_table)
321 /*============================================================================
322 * Special system call wrappers
324 @ r0 = syscall number
327 bic scno, r0, #__NR_OABI_SYSCALL_BASE
328 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
329 cmpne scno, #NR_syscalls @ check range
330 stmloia sp, {r5, r6} @ shuffle args
335 ldrlo pc, [tbl, scno, lsl #2]
339 sys_sigreturn_wrapper:
341 mov why, #0 @ prevent syscall restart handling
343 ENDPROC(sys_sigreturn_wrapper)
345 sys_rt_sigreturn_wrapper:
347 mov why, #0 @ prevent syscall restart handling
349 ENDPROC(sys_rt_sigreturn_wrapper)
351 sys_statfs64_wrapper:
355 ENDPROC(sys_statfs64_wrapper)
357 sys_fstatfs64_wrapper:
361 ENDPROC(sys_fstatfs64_wrapper)
364 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
365 * offset, we return EINVAL.
370 moveq r5, r5, lsr #PAGE_SHIFT - 12
381 #ifdef CONFIG_OABI_COMPAT
384 * These are syscalls with argument register differences
390 ENDPROC(sys_oabi_pread64)
395 ENDPROC(sys_oabi_pwrite64)
401 ENDPROC(sys_oabi_truncate64)
403 sys_oabi_ftruncate64:
407 ENDPROC(sys_oabi_ftruncate64)
414 ENDPROC(sys_oabi_readahead)
417 * Let's declare a second syscall table for old ABI binaries
418 * using the compatibility syscall entries.
420 #define ABI(native, compat) compat
421 #define OBSOLETE(syscall) syscall
423 .type sys_oabi_call_table, #object
424 ENTRY(sys_oabi_call_table)