xref: /linux/arch/arm/kernel/entry-common.S (revision 29589ca09a74cfc0c50ad002e298bf4b8e69e0bd)
1d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds *  linux/arch/arm/kernel/entry-common.S
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds *  Copyright (C) 2000 Russell King
61da177e4SLinus Torvalds */
71da177e4SLinus Torvalds
86ebbf2ceSRussell King#include <asm/assembler.h>
91da177e4SLinus Torvalds#include <asm/unistd.h>
10395a59d0SAbhishek Sagar#include <asm/ftrace.h>
11c4c5716eSCatalin Marinas#include <asm/unwind.h>
12e33f8d32SThomas Garnier#include <asm/memory.h>
1396a8fae0SRussell King#ifdef CONFIG_AEABI
1496a8fae0SRussell King#include <asm/unistd-oabi.h>
1596a8fae0SRussell King#endif
1696a8fae0SRussell King
1796a8fae0SRussell King	.equ	NR_syscalls, __NR_syscalls
181da177e4SLinus Torvalds
196f5d248dSArnd Bergmann	.macro  arch_ret_to_user, tmp
206f5d248dSArnd Bergmann#ifdef CONFIG_ARCH_IOP32X
216f5d248dSArnd Bergmann	mrc	p15, 0, \tmp, c15, c1, 0
226f5d248dSArnd Bergmann	tst	\tmp, #(1 << 6)
236f5d248dSArnd Bergmann	bicne	\tmp, \tmp, #(1 << 6)
246f5d248dSArnd Bergmann	mcrne	p15, 0, \tmp, c15, c1, 0	@ Disable cp6 access
2513a5045dSRob Herring#endif
266f5d248dSArnd Bergmann	.endm
2713a5045dSRob Herring
281da177e4SLinus Torvalds#include "entry-header.S"
291da177e4SLinus Torvalds
30309ee042SRussell Kingsaved_psr	.req	r8
31fcea4523SRussell King#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
32fcea4523SRussell Kingsaved_pc	.req	r9
33fcea4523SRussell King#define TRACE(x...) x
34fcea4523SRussell King#else
35309ee042SRussell Kingsaved_pc	.req	lr
36fcea4523SRussell King#define TRACE(x...)
37fcea4523SRussell King#endif
381da177e4SLinus Torvalds
39c6089061SRussell King	.section .entry.text,"ax",%progbits
401da177e4SLinus Torvalds	.align	5
41b74406f3SMathieu Desnoyers#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING) || \
42b74406f3SMathieu Desnoyers	IS_ENABLED(CONFIG_DEBUG_RSEQ))
431da177e4SLinus Torvalds/*
443302caddSRussell King * This is the fast syscall return path.  We do as little as possible here,
453302caddSRussell King * such as avoiding writing r0 to the stack.  We only use this path if we
46b74406f3SMathieu Desnoyers * have tracing, context tracking and rseq debug disabled - the overheads
47b74406f3SMathieu Desnoyers * from those features make this path too inefficient.
481da177e4SLinus Torvalds */
491da177e4SLinus Torvaldsret_fast_syscall:
50afc9f65eSVincent Whitchurch__ret_fast_syscall:
51c4c5716eSCatalin Marinas UNWIND(.fnstart	)
52c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
533302caddSRussell King	disable_irq_notrace			@ disable interrupts
541b979372SRussell King	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
5532d59773SJens Axboe	movs	r1, r1, lsl #16
561da177e4SLinus Torvalds	bne	fast_work_pending
57f4dc9a4cSRussell King
58e33f8d32SThomas Garnier
59f80dff9dSDan Williams	/* perform architecture specific actions before user return */
606f5d248dSArnd Bergmann	arch_ret_to_user r1
61f80dff9dSDan Williams
62b86040a5SCatalin Marinas	restore_user_regs fast = 1, offset = S_OFF
63c4c5716eSCatalin Marinas UNWIND(.fnend		)
643302caddSRussell KingENDPROC(ret_fast_syscall)
651da177e4SLinus Torvalds
663302caddSRussell King	/* Ok, we need to do extra processing, enter the slow path. */
671da177e4SLinus Torvaldsfast_work_pending:
681da177e4SLinus Torvalds	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
693302caddSRussell King	/* fall through to work_pending */
703302caddSRussell King#else
713302caddSRussell King/*
72b74406f3SMathieu Desnoyers * The "replacement" ret_fast_syscall for when tracing, context tracking,
73b74406f3SMathieu Desnoyers * or rseq debug is enabled.  As we will need to call out to some C functions,
74b74406f3SMathieu Desnoyers * we save r0 first to avoid needing to save registers around each C function
75b74406f3SMathieu Desnoyers * call.
763302caddSRussell King */
773302caddSRussell Kingret_fast_syscall:
78afc9f65eSVincent Whitchurch__ret_fast_syscall:
793302caddSRussell King UNWIND(.fnstart	)
803302caddSRussell King UNWIND(.cantunwind	)
813302caddSRussell King	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
82b74406f3SMathieu Desnoyers#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
83b74406f3SMathieu Desnoyers	/* do_rseq_syscall needs interrupts enabled. */
84b74406f3SMathieu Desnoyers	mov	r0, sp				@ 'regs'
85b74406f3SMathieu Desnoyers	bl	do_rseq_syscall
86b74406f3SMathieu Desnoyers#endif
873302caddSRussell King	disable_irq_notrace			@ disable interrupts
883302caddSRussell King	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
8932d59773SJens Axboe	movs	r1, r1, lsl #16
903302caddSRussell King	beq	no_work_pending
913302caddSRussell King UNWIND(.fnend		)
923302caddSRussell KingENDPROC(ret_fast_syscall)
933302caddSRussell King
943302caddSRussell King	/* Slower path - fall through to work_pending */
953302caddSRussell King#endif
963302caddSRussell King
973302caddSRussell King	tst	r1, #_TIF_SYSCALL_WORK
983302caddSRussell King	bne	__sys_trace_return_nosave
993302caddSRussell Kingslow_work_pending:
1001da177e4SLinus Torvalds	mov	r0, sp				@ 'regs'
1011da177e4SLinus Torvalds	mov	r2, why				@ 'syscall'
1020a267fa6SAl Viro	bl	do_work_pending
10366285217SAl Viro	cmp	r0, #0
10481783786SAl Viro	beq	no_work_pending
10566285217SAl Viro	movlt	scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
10681783786SAl Viro	ldmia	sp, {r0 - r6}			@ have to reload r0 - r6
10781783786SAl Viro	b	local_restart			@ ... and off we go
108e83dd377SDrew RichardsonENDPROC(ret_fast_syscall)
10981783786SAl Viro
1101da177e4SLinus Torvalds/*
1111da177e4SLinus Torvalds * "slow" syscall return path.  "why" tells us if this was a real syscall.
1123302caddSRussell King * IRQs may be enabled here, so always disable them.  Note that we use the
1133302caddSRussell King * "notrace" version to avoid calling into the tracing code unnecessarily.
1143302caddSRussell King * do_work_pending() will update this state if necessary.
1151da177e4SLinus Torvalds */
1161da177e4SLinus TorvaldsENTRY(ret_to_user)
1171da177e4SLinus Torvaldsret_slow_syscall:
118b74406f3SMathieu Desnoyers#if IS_ENABLED(CONFIG_DEBUG_RSEQ)
119b74406f3SMathieu Desnoyers	/* do_rseq_syscall needs interrupts enabled. */
120b74406f3SMathieu Desnoyers	enable_irq_notrace			@ enable interrupts
121b74406f3SMathieu Desnoyers	mov	r0, sp				@ 'regs'
122b74406f3SMathieu Desnoyers	bl	do_rseq_syscall
123b74406f3SMathieu Desnoyers#endif
1243302caddSRussell King	disable_irq_notrace			@ disable interrupts
1259fc2552aSMing LeiENTRY(ret_to_user_from_irq)
1261da177e4SLinus Torvalds	ldr	r1, [tsk, #TI_FLAGS]
12732d59773SJens Axboe	movs	r1, r1, lsl #16
1283302caddSRussell King	bne	slow_work_pending
1291da177e4SLinus Torvaldsno_work_pending:
1303302caddSRussell King	asm_trace_hardirqs_on save = 0
131651e9499SRussell King
132f80dff9dSDan Williams	/* perform architecture specific actions before user return */
1336f5d248dSArnd Bergmann	arch_ret_to_user r1
134b0088480SKevin Hilman	ct_user_enter save = 0
135f80dff9dSDan Williams
136b86040a5SCatalin Marinas	restore_user_regs fast = 0, offset = 0
1379fc2552aSMing LeiENDPROC(ret_to_user_from_irq)
13893ed3970SCatalin MarinasENDPROC(ret_to_user)
1391da177e4SLinus Torvalds
1401da177e4SLinus Torvalds/*
1411da177e4SLinus Torvalds * This is how we return from a fork.
1421da177e4SLinus Torvalds */
1431da177e4SLinus TorvaldsENTRY(ret_from_fork)
1441da177e4SLinus Torvalds	bl	schedule_tail
1459fff2fa0SAl Viro	cmp	r5, #0
1469fff2fa0SAl Viro	movne	r0, r4
14714327c66SRussell King	badrne	lr, 1f
1486ebbf2ceSRussell King	retne	r5
14968687c84SRussell King1:	get_thread_info tsk
1501da177e4SLinus Torvalds	b	ret_slow_syscall
15193ed3970SCatalin MarinasENDPROC(ret_from_fork)
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds/*=============================================================================
1541da177e4SLinus Torvalds * SWI handler
1551da177e4SLinus Torvalds *-----------------------------------------------------------------------------
1561da177e4SLinus Torvalds */
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds	.align	5
159b9baf5c8SRussell King (Oracle)#ifdef CONFIG_HARDEN_BRANCH_HISTORY
160b9baf5c8SRussell King (Oracle)ENTRY(vector_bhb_loop8_swi)
161b9baf5c8SRussell King (Oracle)	sub	sp, sp, #PT_REGS_SIZE
162b9baf5c8SRussell King (Oracle)	stmia	sp, {r0 - r12}
163b9baf5c8SRussell King (Oracle)	mov	r8, #8
164b9baf5c8SRussell King (Oracle)1:	b	2f
165b9baf5c8SRussell King (Oracle)2:	subs	r8, r8, #1
166b9baf5c8SRussell King (Oracle)	bne	1b
167892c608aSArd Biesheuvel	dsb	nsh
168b9baf5c8SRussell King (Oracle)	isb
169b9baf5c8SRussell King (Oracle)	b	3f
170b9baf5c8SRussell King (Oracle)ENDPROC(vector_bhb_loop8_swi)
171b9baf5c8SRussell King (Oracle)
172b9baf5c8SRussell King (Oracle)	.align	5
173b9baf5c8SRussell King (Oracle)ENTRY(vector_bhb_bpiall_swi)
174b9baf5c8SRussell King (Oracle)	sub	sp, sp, #PT_REGS_SIZE
175b9baf5c8SRussell King (Oracle)	stmia	sp, {r0 - r12}
176b9baf5c8SRussell King (Oracle)	mcr	p15, 0, r8, c7, c5, 6	@ BPIALL
177b9baf5c8SRussell King (Oracle)	isb
178b9baf5c8SRussell King (Oracle)	b	3f
179b9baf5c8SRussell King (Oracle)ENDPROC(vector_bhb_bpiall_swi)
180b9baf5c8SRussell King (Oracle)#endif
181b9baf5c8SRussell King (Oracle)	.align	5
1821da177e4SLinus TorvaldsENTRY(vector_swi)
18319c4d593SUwe Kleine-König#ifdef CONFIG_CPU_V7M
18419c4d593SUwe Kleine-König	v7m_exception_entry
18519c4d593SUwe Kleine-König#else
1865745eef6SRussell King	sub	sp, sp, #PT_REGS_SIZE
187f4dc9a4cSRussell King	stmia	sp, {r0 - r12}			@ Calling r0 - r12
188b9baf5c8SRussell King (Oracle)3:
189b86040a5SCatalin Marinas ARM(	add	r8, sp, #S_PC		)
190b86040a5SCatalin Marinas ARM(	stmdb	r8, {sp, lr}^		)	@ Calling sp, lr
191b86040a5SCatalin Marinas THUMB(	mov	r8, sp			)
192b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r8, r10, S_SP	)	@ calling sp, lr
193309ee042SRussell King	mrs	saved_psr, spsr			@ called from non-FIQ mode, so ok.
194fcea4523SRussell King TRACE(	mov	saved_pc, lr		)
195309ee042SRussell King	str	saved_pc, [sp, #S_PC]		@ Save calling PC
196309ee042SRussell King	str	saved_psr, [sp, #S_PSR]		@ Save CPSR
197f4dc9a4cSRussell King	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
19819c4d593SUwe Kleine-König#endif
19950596b75SArd Biesheuvel	reload_current r10, ip
2001da177e4SLinus Torvalds	zero_fp
20150807460SArd Biesheuvel	alignment_trap r10, ip, cr_alignment
202dca778c5SRussell King	asm_trace_hardirqs_on save=0
203dca778c5SRussell King	enable_irq_notrace
204dca778c5SRussell King	ct_user_exit save=0
2051aa2b3b7SWill Deacon
206e0f9f4a6SRussell King	/*
207e0f9f4a6SRussell King	 * Get the system call number.
208e0f9f4a6SRussell King	 */
2093f2829a3SNicolas Pitre
210dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
2113f2829a3SNicolas Pitre
212dd35afc2SNicolas Pitre	/*
213dd35afc2SNicolas Pitre	 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
214dd35afc2SNicolas Pitre	 * value to determine if it is an EABI or an old ABI call.
215dd35afc2SNicolas Pitre	 */
216dd35afc2SNicolas Pitre#ifdef CONFIG_ARM_THUMB
217309ee042SRussell King	tst	saved_psr, #PSR_T_BIT
218dd35afc2SNicolas Pitre	movne	r10, #0				@ no thumb OABI emulation
219309ee042SRussell King USER(	ldreq	r10, [saved_pc, #-4]	)	@ get SWI instruction
220dd35afc2SNicolas Pitre#else
221309ee042SRussell King USER(	ldr	r10, [saved_pc, #-4]	)	@ get SWI instruction
222dd35afc2SNicolas Pitre#endif
223457c2403SBen Dooks ARM_BE8(rev	r10, r10)			@ little endian instruction
224dd35afc2SNicolas Pitre
225dd35afc2SNicolas Pitre#elif defined(CONFIG_AEABI)
226dd35afc2SNicolas Pitre
227dd35afc2SNicolas Pitre	/*
228dd35afc2SNicolas Pitre	 * Pure EABI user space always put syscall number into scno (r7).
229dd35afc2SNicolas Pitre	 */
2303f2829a3SNicolas Pitre#elif defined(CONFIG_ARM_THUMB)
231dd35afc2SNicolas Pitre	/* Legacy ABI only, possibly thumb mode. */
232309ee042SRussell King	tst	saved_psr, #PSR_T_BIT		@ this is SPSR from save_user_regs
233e0f9f4a6SRussell King	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
234309ee042SRussell King USER(	ldreq	scno, [saved_pc, #-4]	)
235dd35afc2SNicolas Pitre
236e0f9f4a6SRussell King#else
237dd35afc2SNicolas Pitre	/* Legacy ABI only. */
238309ee042SRussell King USER(	ldr	scno, [saved_pc, #-4]	)	@ get SWI instruction
239e0f9f4a6SRussell King#endif
2401da177e4SLinus Torvalds
241309ee042SRussell King	/* saved_psr and saved_pc are now dead */
242309ee042SRussell King
2432190fed6SRussell King	uaccess_disable tbl
2444e57a4ddSArnd Bergmann	get_thread_info tsk
2452190fed6SRussell King
246dd35afc2SNicolas Pitre	adr	tbl, sys_call_table		@ load syscall table pointer
247dd35afc2SNicolas Pitre
248dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
249dd35afc2SNicolas Pitre	/*
250dd35afc2SNicolas Pitre	 * If the swi argument is zero, this is an EABI call and we do nothing.
251dd35afc2SNicolas Pitre	 *
252dd35afc2SNicolas Pitre	 * If this is an old ABI call, get the syscall number into scno and
253dd35afc2SNicolas Pitre	 * get the old ABI syscall table address.
254dd35afc2SNicolas Pitre	 */
255dd35afc2SNicolas Pitre	bics	r10, r10, #0xff000000
2564e57a4ddSArnd Bergmann	strne	r10, [tsk, #TI_ABI_SYSCALL]
2574e57a4ddSArnd Bergmann	streq	scno, [tsk, #TI_ABI_SYSCALL]
258dd35afc2SNicolas Pitre	eorne	scno, r10, #__NR_OABI_SYSCALL_BASE
259dd35afc2SNicolas Pitre	ldrne	tbl, =sys_oabi_call_table
260dd35afc2SNicolas Pitre#elif !defined(CONFIG_AEABI)
2611da177e4SLinus Torvalds	bic	scno, scno, #0xff000000		@ mask off SWI op-code
2624e57a4ddSArnd Bergmann	str	scno, [tsk, #TI_ABI_SYSCALL]
263e0f9f4a6SRussell King	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
2644e57a4ddSArnd Bergmann#else
2654e57a4ddSArnd Bergmann	str	scno, [tsk, #TI_ABI_SYSCALL]
2663f2829a3SNicolas Pitre#endif
267dca778c5SRussell King	/*
268dca778c5SRussell King	 * Reload the registers that may have been corrupted on entry to
269dca778c5SRussell King	 * the syscall assembly (by tracing or context tracking.)
270dca778c5SRussell King	 */
271dca778c5SRussell King TRACE(	ldmia	sp, {r0 - r3}		)
272dd35afc2SNicolas Pitre
27381783786SAl Virolocal_restart:
27470c70d97SNicolas Pitre	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
2753f2829a3SNicolas Pitre	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
27670c70d97SNicolas Pitre
27729ef73b7SNathaniel Husted	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
2781da177e4SLinus Torvalds	bne	__sys_trace
2791da177e4SLinus Torvalds
280afc9f65eSVincent Whitchurch	invoke_syscall tbl, scno, r10, __ret_fast_syscall
2811da177e4SLinus Torvalds
2821da177e4SLinus Torvalds	add	r1, sp, #S_OFF
283d95bc250SWill Deacon2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
284e0f9f4a6SRussell King	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
2851da177e4SLinus Torvalds	bcs	arm_syscall
286d95bc250SWill Deacon	mov	why, #0				@ no longer a real syscall
2871da177e4SLinus Torvalds	b	sys_ni_syscall			@ not private func
2881aa2b3b7SWill Deacon
2891aa2b3b7SWill Deacon#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
2901aa2b3b7SWill Deacon	/*
2911aa2b3b7SWill Deacon	 * We failed to handle a fault trying to access the page
2921aa2b3b7SWill Deacon	 * containing the swi instruction, but we're not really in a
2931aa2b3b7SWill Deacon	 * position to return -EFAULT. Instead, return back to the
2941aa2b3b7SWill Deacon	 * instruction and re-enter the user fault handling path trying
2951aa2b3b7SWill Deacon	 * to page it in. This will likely result in sending SEGV to the
2961aa2b3b7SWill Deacon	 * current task.
2971aa2b3b7SWill Deacon	 */
2981aa2b3b7SWill Deacon9001:
299309ee042SRussell King	sub	lr, saved_pc, #4
3001aa2b3b7SWill Deacon	str	lr, [sp, #S_PC]
301da594e3fSRussell King	get_thread_info tsk
3021aa2b3b7SWill Deacon	b	ret_fast_syscall
3031aa2b3b7SWill Deacon#endif
30493ed3970SCatalin MarinasENDPROC(vector_swi)
305*29589ca0SArd Biesheuvel	.ltorg
3061da177e4SLinus Torvalds
3071da177e4SLinus Torvalds	/*
3081da177e4SLinus Torvalds	 * This is the really slow path.  We're going to be doing
3091da177e4SLinus Torvalds	 * context switches, and waiting for our parent to respond.
3101da177e4SLinus Torvalds	 */
3111da177e4SLinus Torvalds__sys_trace:
312ad722541SWill Deacon	add	r0, sp, #S_OFF
313ad722541SWill Deacon	bl	syscall_trace_enter
31410573ae5SRussell King	mov	scno, r0
31510573ae5SRussell King	invoke_syscall tbl, scno, r10, __sys_trace_return, reload=1
316ad75b514SKees Cook	cmp	scno, #-1			@ skip the syscall?
317ad75b514SKees Cook	bne	2b
318ad75b514SKees Cook	add	sp, sp, #S_OFF			@ restore stack
3191da177e4SLinus Torvalds
320f18aef74STimothy E Baldwin__sys_trace_return_nosave:
321f18aef74STimothy E Baldwin	enable_irq_notrace
322ad722541SWill Deacon	mov	r0, sp
323ad722541SWill Deacon	bl	syscall_trace_exit
3241da177e4SLinus Torvalds	b	ret_slow_syscall
3251da177e4SLinus Torvalds
326f18aef74STimothy E Baldwin__sys_trace_return:
327f18aef74STimothy E Baldwin	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
3283302caddSRussell King	mov	r0, sp
3293302caddSRussell King	bl	syscall_trace_exit
3303302caddSRussell King	b	ret_slow_syscall
3313302caddSRussell King
33296a8fae0SRussell King	.macro	syscall_table_start, sym
33396a8fae0SRussell King	.equ	__sys_nr, 0
33496a8fae0SRussell King	.type	\sym, #object
33596a8fae0SRussell KingENTRY(\sym)
33696a8fae0SRussell King	.endm
33796a8fae0SRussell King
33896a8fae0SRussell King	.macro	syscall, nr, func
33996a8fae0SRussell King	.ifgt	__sys_nr - \nr
34096a8fae0SRussell King	.error	"Duplicated/unorded system call entry"
34196a8fae0SRussell King	.endif
34296a8fae0SRussell King	.rept	\nr - __sys_nr
34396a8fae0SRussell King	.long	sys_ni_syscall
34496a8fae0SRussell King	.endr
34596a8fae0SRussell King	.long	\func
34696a8fae0SRussell King	.equ	__sys_nr, \nr + 1
34796a8fae0SRussell King	.endm
34896a8fae0SRussell King
34996a8fae0SRussell King	.macro	syscall_table_end, sym
35096a8fae0SRussell King	.ifgt	__sys_nr - __NR_syscalls
35196a8fae0SRussell King	.error	"System call table too big"
35296a8fae0SRussell King	.endif
35396a8fae0SRussell King	.rept	__NR_syscalls - __sys_nr
35496a8fae0SRussell King	.long	sys_ni_syscall
35596a8fae0SRussell King	.endr
35696a8fae0SRussell King	.size	\sym, . - \sym
35796a8fae0SRussell King	.endm
35896a8fae0SRussell King
3590047eb9fSMasahiro Yamada#define __SYSCALL_WITH_COMPAT(nr, native, compat)	__SYSCALL(nr, native)
3600047eb9fSMasahiro Yamada#define __SYSCALL(nr, func) syscall nr, func
36196a8fae0SRussell King
362dd35afc2SNicolas Pitre/*
363dd35afc2SNicolas Pitre * This is the syscall table declaration for native ABI syscalls.
364dd35afc2SNicolas Pitre * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
365dd35afc2SNicolas Pitre */
36696a8fae0SRussell King	syscall_table_start sys_call_table
367dd35afc2SNicolas Pitre#ifdef CONFIG_AEABI
36896a8fae0SRussell King#include <calls-eabi.S>
369dd35afc2SNicolas Pitre#else
37096a8fae0SRussell King#include <calls-oabi.S>
371dd35afc2SNicolas Pitre#endif
37296a8fae0SRussell King	syscall_table_end sys_call_table
3731da177e4SLinus Torvalds
3741da177e4SLinus Torvalds/*============================================================================
3751da177e4SLinus Torvalds * Special system call wrappers
3761da177e4SLinus Torvalds */
3771da177e4SLinus Torvalds@ r0 = syscall number
378567bd980SRussell King@ r8 = syscall table
3791da177e4SLinus Torvaldssys_syscall:
3805247593cSPaul Brook		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
3811da177e4SLinus Torvalds		cmp	scno, #__NR_syscall - __NR_SYSCALL_BASE
3821da177e4SLinus Torvalds		cmpne	scno, #NR_syscalls	@ check range
38310573ae5SRussell King#ifdef CONFIG_CPU_SPECTRE
38410573ae5SRussell King		movhs	scno, #0
38510573ae5SRussell King		csdb
38610573ae5SRussell King#endif
387e44fc388SStefan Agner		stmialo	sp, {r5, r6}		@ shuffle args
3881da177e4SLinus Torvalds		movlo	r0, r1
3891da177e4SLinus Torvalds		movlo	r1, r2
3901da177e4SLinus Torvalds		movlo	r2, r3
3911da177e4SLinus Torvalds		movlo	r3, r4
3921da177e4SLinus Torvalds		ldrlo	pc, [tbl, scno, lsl #2]
3931da177e4SLinus Torvalds		b	sys_ni_syscall
39493ed3970SCatalin MarinasENDPROC(sys_syscall)
3951da177e4SLinus Torvalds
3961da177e4SLinus Torvaldssys_sigreturn_wrapper:
3971da177e4SLinus Torvalds		add	r0, sp, #S_OFF
398653d48b2SAl Viro		mov	why, #0		@ prevent syscall restart handling
3991da177e4SLinus Torvalds		b	sys_sigreturn
40093ed3970SCatalin MarinasENDPROC(sys_sigreturn_wrapper)
4011da177e4SLinus Torvalds
4021da177e4SLinus Torvaldssys_rt_sigreturn_wrapper:
4031da177e4SLinus Torvalds		add	r0, sp, #S_OFF
404653d48b2SAl Viro		mov	why, #0		@ prevent syscall restart handling
4051da177e4SLinus Torvalds		b	sys_rt_sigreturn
40693ed3970SCatalin MarinasENDPROC(sys_rt_sigreturn_wrapper)
4071da177e4SLinus Torvalds
408713c4815SNicolas Pitresys_statfs64_wrapper:
409713c4815SNicolas Pitre		teq	r1, #88
410713c4815SNicolas Pitre		moveq	r1, #84
411713c4815SNicolas Pitre		b	sys_statfs64
41293ed3970SCatalin MarinasENDPROC(sys_statfs64_wrapper)
413713c4815SNicolas Pitre
414713c4815SNicolas Pitresys_fstatfs64_wrapper:
415713c4815SNicolas Pitre		teq	r1, #88
416713c4815SNicolas Pitre		moveq	r1, #84
417713c4815SNicolas Pitre		b	sys_fstatfs64
41893ed3970SCatalin MarinasENDPROC(sys_fstatfs64_wrapper)
419713c4815SNicolas Pitre
4201da177e4SLinus Torvalds/*
4211da177e4SLinus Torvalds * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
4221da177e4SLinus Torvalds * offset, we return EINVAL.
4231da177e4SLinus Torvalds */
4241da177e4SLinus Torvaldssys_mmap2:
4251da177e4SLinus Torvalds		str	r5, [sp, #4]
426f8b72560SAl Viro		b	sys_mmap_pgoff
42793ed3970SCatalin MarinasENDPROC(sys_mmap2)
428687ad019SNicolas Pitre
429687ad019SNicolas Pitre#ifdef CONFIG_OABI_COMPAT
430dd35afc2SNicolas Pitre
431687ad019SNicolas Pitre/*
432687ad019SNicolas Pitre * These are syscalls with argument register differences
433687ad019SNicolas Pitre */
434687ad019SNicolas Pitre
435687ad019SNicolas Pitresys_oabi_pread64:
436687ad019SNicolas Pitre		stmia	sp, {r3, r4}
437687ad019SNicolas Pitre		b	sys_pread64
43893ed3970SCatalin MarinasENDPROC(sys_oabi_pread64)
439687ad019SNicolas Pitre
440687ad019SNicolas Pitresys_oabi_pwrite64:
441687ad019SNicolas Pitre		stmia	sp, {r3, r4}
442687ad019SNicolas Pitre		b	sys_pwrite64
44393ed3970SCatalin MarinasENDPROC(sys_oabi_pwrite64)
444687ad019SNicolas Pitre
445687ad019SNicolas Pitresys_oabi_truncate64:
446687ad019SNicolas Pitre		mov	r3, r2
447687ad019SNicolas Pitre		mov	r2, r1
448687ad019SNicolas Pitre		b	sys_truncate64
44993ed3970SCatalin MarinasENDPROC(sys_oabi_truncate64)
450687ad019SNicolas Pitre
451687ad019SNicolas Pitresys_oabi_ftruncate64:
452687ad019SNicolas Pitre		mov	r3, r2
453687ad019SNicolas Pitre		mov	r2, r1
454687ad019SNicolas Pitre		b	sys_ftruncate64
45593ed3970SCatalin MarinasENDPROC(sys_oabi_ftruncate64)
456687ad019SNicolas Pitre
457687ad019SNicolas Pitresys_oabi_readahead:
458687ad019SNicolas Pitre		str	r3, [sp]
459687ad019SNicolas Pitre		mov	r3, r2
460687ad019SNicolas Pitre		mov	r2, r1
461687ad019SNicolas Pitre		b	sys_readahead
46293ed3970SCatalin MarinasENDPROC(sys_oabi_readahead)
463687ad019SNicolas Pitre
464dd35afc2SNicolas Pitre/*
465dd35afc2SNicolas Pitre * Let's declare a second syscall table for old ABI binaries
466dd35afc2SNicolas Pitre * using the compatibility syscall entries.
467dd35afc2SNicolas Pitre */
46896a8fae0SRussell King	syscall_table_start sys_oabi_call_table
4690047eb9fSMasahiro Yamada#undef __SYSCALL_WITH_COMPAT
4700047eb9fSMasahiro Yamada#define __SYSCALL_WITH_COMPAT(nr, native, compat)	__SYSCALL(nr, compat)
47196a8fae0SRussell King#include <calls-oabi.S>
47296a8fae0SRussell King	syscall_table_end sys_oabi_call_table
473dd35afc2SNicolas Pitre
474687ad019SNicolas Pitre#endif
475687ad019SNicolas Pitre
476