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 #include <asm/unistd-oabi.h>
20 .equ NR_syscalls, __NR_syscalls
22 #ifdef CONFIG_NEED_RET_TO_USER
23 #include <mach/entry-macro.S>
25 .macro arch_ret_to_user, tmp1, tmp2
29 #include "entry-header.S"
32 #if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
40 .section .entry.text,"ax",%progbits
42 #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \
43 IS_ENABLED(CONFIG_DEBUG_RSEQ))
45 * This is the fast syscall return path. We do as little as possible here,
46 * such as avoiding writing r0 to the stack. We only use this path if we
47 * have tracing, context tracking and rseq debug disabled - the overheads
48 * from those features make this path too inefficient.
53 disable_irq_notrace @ disable interrupts
54 ldr r2, [tsk, #TI_ADDR_LIMIT]
56 blne addr_limit_check_failed
57 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
58 tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
62 /* perform architecture specific actions before user return */
63 arch_ret_to_user r1, lr
65 restore_user_regs fast = 1, offset = S_OFF
67 ENDPROC(ret_fast_syscall)
69 /* Ok, we need to do extra processing, enter the slow path. */
71 str r0, [sp, #S_R0+S_OFF]! @ returned r0
72 /* fall through to work_pending */
75 * The "replacement" ret_fast_syscall for when tracing, context tracking,
76 * or rseq debug is enabled. As we will need to call out to some C functions,
77 * we save r0 first to avoid needing to save registers around each C function
83 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
84 #if IS_ENABLED(CONFIG_DEBUG_RSEQ)
85 /* do_rseq_syscall needs interrupts enabled. */
89 disable_irq_notrace @ disable interrupts
90 ldr r2, [tsk, #TI_ADDR_LIMIT]
92 blne addr_limit_check_failed
93 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
94 tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
97 ENDPROC(ret_fast_syscall)
99 /* Slower path - fall through to work_pending */
102 tst r1, #_TIF_SYSCALL_WORK
103 bne __sys_trace_return_nosave
106 mov r2, why @ 'syscall'
110 movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
111 ldmia sp, {r0 - r6} @ have to reload r0 - r6
112 b local_restart @ ... and off we go
113 ENDPROC(ret_fast_syscall)
116 * "slow" syscall return path. "why" tells us if this was a real syscall.
117 * IRQs may be enabled here, so always disable them. Note that we use the
118 * "notrace" version to avoid calling into the tracing code unnecessarily.
119 * do_work_pending() will update this state if necessary.
123 #if IS_ENABLED(CONFIG_DEBUG_RSEQ)
124 /* do_rseq_syscall needs interrupts enabled. */
125 enable_irq_notrace @ enable interrupts
129 disable_irq_notrace @ disable interrupts
130 ENTRY(ret_to_user_from_irq)
131 ldr r2, [tsk, #TI_ADDR_LIMIT]
133 blne addr_limit_check_failed
134 ldr r1, [tsk, #TI_FLAGS]
135 tst r1, #_TIF_WORK_MASK
136 bne slow_work_pending
138 asm_trace_hardirqs_on save = 0
140 /* perform architecture specific actions before user return */
141 arch_ret_to_user r1, lr
142 ct_user_enter save = 0
144 restore_user_regs fast = 0, offset = 0
145 ENDPROC(ret_to_user_from_irq)
149 * This is how we return from a fork.
157 1: get_thread_info tsk
159 ENDPROC(ret_from_fork)
161 /*=============================================================================
163 *-----------------------------------------------------------------------------
168 #ifdef CONFIG_CPU_V7M
171 sub sp, sp, #PT_REGS_SIZE
172 stmia sp, {r0 - r12} @ Calling r0 - r12
173 ARM( add r8, sp, #S_PC )
174 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
176 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
177 mrs saved_psr, spsr @ called from non-FIQ mode, so ok.
178 TRACE( mov saved_pc, lr )
179 str saved_pc, [sp, #S_PC] @ Save calling PC
180 str saved_psr, [sp, #S_PSR] @ Save CPSR
181 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
184 alignment_trap r10, ip, __cr_alignment
185 asm_trace_hardirqs_on save=0
190 * Get the system call number.
193 #if defined(CONFIG_OABI_COMPAT)
196 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
197 * value to determine if it is an EABI or an old ABI call.
199 #ifdef CONFIG_ARM_THUMB
200 tst saved_psr, #PSR_T_BIT
201 movne r10, #0 @ no thumb OABI emulation
202 USER( ldreq r10, [saved_pc, #-4] ) @ get SWI instruction
204 USER( ldr r10, [saved_pc, #-4] ) @ get SWI instruction
206 ARM_BE8(rev r10, r10) @ little endian instruction
208 #elif defined(CONFIG_AEABI)
211 * Pure EABI user space always put syscall number into scno (r7).
213 #elif defined(CONFIG_ARM_THUMB)
214 /* Legacy ABI only, possibly thumb mode. */
215 tst saved_psr, #PSR_T_BIT @ this is SPSR from save_user_regs
216 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
217 USER( ldreq scno, [saved_pc, #-4] )
220 /* Legacy ABI only. */
221 USER( ldr scno, [saved_pc, #-4] ) @ get SWI instruction
224 /* saved_psr and saved_pc are now dead */
228 adr tbl, sys_call_table @ load syscall table pointer
230 #if defined(CONFIG_OABI_COMPAT)
232 * If the swi argument is zero, this is an EABI call and we do nothing.
234 * If this is an old ABI call, get the syscall number into scno and
235 * get the old ABI syscall table address.
237 bics r10, r10, #0xff000000
238 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
239 ldrne tbl, =sys_oabi_call_table
240 #elif !defined(CONFIG_AEABI)
241 bic scno, scno, #0xff000000 @ mask off SWI op-code
242 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
246 * Reload the registers that may have been corrupted on entry to
247 * the syscall assembly (by tracing or context tracking.)
249 TRACE( ldmia sp, {r0 - r3} )
252 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
253 stmdb sp!, {r4, r5} @ push fifth and sixth args
255 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
258 invoke_syscall tbl, scno, r10, ret_fast_syscall
261 2: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
262 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
264 mov why, #0 @ no longer a real syscall
265 b sys_ni_syscall @ not private func
267 #if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
269 * We failed to handle a fault trying to access the page
270 * containing the swi instruction, but we're not really in a
271 * position to return -EFAULT. Instead, return back to the
272 * instruction and re-enter the user fault handling path trying
273 * to page it in. This will likely result in sending SEGV to the
285 * This is the really slow path. We're going to be doing
286 * context switches, and waiting for our parent to respond.
291 bl syscall_trace_enter
293 invoke_syscall tbl, scno, r10, __sys_trace_return, reload=1
294 cmp scno, #-1 @ skip the syscall?
296 add sp, sp, #S_OFF @ restore stack
300 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
302 bl syscall_trace_exit
305 __sys_trace_return_nosave:
308 bl syscall_trace_exit
312 #ifdef CONFIG_ALIGNMENT_TRAP
313 .type __cr_alignment, #object
319 .macro syscall_table_start, sym
325 .macro syscall, nr, func
327 .error "Duplicated/unorded system call entry"
333 .equ __sys_nr, \nr + 1
336 .macro syscall_table_end, sym
337 .ifgt __sys_nr - __NR_syscalls
338 .error "System call table too big"
340 .rept __NR_syscalls - __sys_nr
346 #define NATIVE(nr, func) syscall nr, func
349 * This is the syscall table declaration for native ABI syscalls.
350 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
352 syscall_table_start sys_call_table
353 #define COMPAT(nr, native, compat) syscall nr, native
355 #include <calls-eabi.S>
357 #include <calls-oabi.S>
360 syscall_table_end sys_call_table
362 /*============================================================================
363 * Special system call wrappers
365 @ r0 = syscall number
368 bic scno, r0, #__NR_OABI_SYSCALL_BASE
369 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
370 cmpne scno, #NR_syscalls @ check range
371 #ifdef CONFIG_CPU_SPECTRE
375 stmloia sp, {r5, r6} @ shuffle args
380 ldrlo pc, [tbl, scno, lsl #2]
384 sys_sigreturn_wrapper:
386 mov why, #0 @ prevent syscall restart handling
388 ENDPROC(sys_sigreturn_wrapper)
390 sys_rt_sigreturn_wrapper:
392 mov why, #0 @ prevent syscall restart handling
394 ENDPROC(sys_rt_sigreturn_wrapper)
396 sys_statfs64_wrapper:
400 ENDPROC(sys_statfs64_wrapper)
402 sys_fstatfs64_wrapper:
406 ENDPROC(sys_fstatfs64_wrapper)
409 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
410 * offset, we return EINVAL.
417 #ifdef CONFIG_OABI_COMPAT
420 * These are syscalls with argument register differences
426 ENDPROC(sys_oabi_pread64)
431 ENDPROC(sys_oabi_pwrite64)
437 ENDPROC(sys_oabi_truncate64)
439 sys_oabi_ftruncate64:
443 ENDPROC(sys_oabi_ftruncate64)
450 ENDPROC(sys_oabi_readahead)
453 * Let's declare a second syscall table for old ABI binaries
454 * using the compatibility syscall entries.
456 syscall_table_start sys_oabi_call_table
457 #define COMPAT(nr, native, compat) syscall nr, compat
458 #include <calls-oabi.S>
459 syscall_table_end sys_oabi_call_table