xref: /openbmc/linux/arch/arm/kernel/entry-common.S (revision 09bfafac)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds *  linux/arch/arm/kernel/entry-common.S
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds *  Copyright (C) 2000 Russell King
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify
71da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as
81da177e4SLinus Torvalds * published by the Free Software Foundation.
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds#include <asm/unistd.h>
12395a59d0SAbhishek Sagar#include <asm/ftrace.h>
13a09e64fbSRussell King#include <mach/entry-macro.S>
14c4c5716eSCatalin Marinas#include <asm/unwind.h>
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds#include "entry-header.S"
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds
191da177e4SLinus Torvalds	.align	5
201da177e4SLinus Torvalds/*
211da177e4SLinus Torvalds * This is the fast syscall return path.  We do as little as
221da177e4SLinus Torvalds * possible here, and this includes saving r0 back into the SVC
231da177e4SLinus Torvalds * stack.
241da177e4SLinus Torvalds */
251da177e4SLinus Torvaldsret_fast_syscall:
26c4c5716eSCatalin Marinas UNWIND(.fnstart	)
27c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
281ec42c0cSRussell King	disable_irq				@ disable interrupts
291da177e4SLinus Torvalds	ldr	r1, [tsk, #TI_FLAGS]
301da177e4SLinus Torvalds	tst	r1, #_TIF_WORK_MASK
311da177e4SLinus Torvalds	bne	fast_work_pending
32f4dc9a4cSRussell King
33f80dff9dSDan Williams	/* perform architecture specific actions before user return */
34f80dff9dSDan Williams	arch_ret_to_user r1, lr
35f80dff9dSDan Williams
36b86040a5SCatalin Marinas	restore_user_regs fast = 1, offset = S_OFF
37c4c5716eSCatalin Marinas UNWIND(.fnend		)
381da177e4SLinus Torvalds
391da177e4SLinus Torvalds/*
401da177e4SLinus Torvalds * Ok, we need to do extra processing, enter the slow path.
411da177e4SLinus Torvalds */
421da177e4SLinus Torvaldsfast_work_pending:
431da177e4SLinus Torvalds	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
441da177e4SLinus Torvaldswork_pending:
451da177e4SLinus Torvalds	tst	r1, #_TIF_NEED_RESCHED
461da177e4SLinus Torvalds	bne	work_resched
47d0420c83SDavid Howells	tst	r1, #_TIF_SIGPENDING|_TIF_NOTIFY_RESUME
481da177e4SLinus Torvalds	beq	no_work_pending
491da177e4SLinus Torvalds	mov	r0, sp				@ 'regs'
501da177e4SLinus Torvalds	mov	r2, why				@ 'syscall'
511da177e4SLinus Torvalds	bl	do_notify_resume
52a6c61e9dSDaniel Jacobowitz	b	ret_slow_syscall		@ Check work again
531da177e4SLinus Torvalds
541da177e4SLinus Torvaldswork_resched:
551da177e4SLinus Torvalds	bl	schedule
561da177e4SLinus Torvalds/*
571da177e4SLinus Torvalds * "slow" syscall return path.  "why" tells us if this was a real syscall.
581da177e4SLinus Torvalds */
591da177e4SLinus TorvaldsENTRY(ret_to_user)
601da177e4SLinus Torvaldsret_slow_syscall:
611ec42c0cSRussell King	disable_irq				@ disable interrupts
621da177e4SLinus Torvalds	ldr	r1, [tsk, #TI_FLAGS]
631da177e4SLinus Torvalds	tst	r1, #_TIF_WORK_MASK
641da177e4SLinus Torvalds	bne	work_pending
651da177e4SLinus Torvaldsno_work_pending:
66f80dff9dSDan Williams	/* perform architecture specific actions before user return */
67f80dff9dSDan Williams	arch_ret_to_user r1, lr
68f80dff9dSDan Williams
69b86040a5SCatalin Marinas	restore_user_regs fast = 0, offset = 0
7093ed3970SCatalin MarinasENDPROC(ret_to_user)
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds/*
731da177e4SLinus Torvalds * This is how we return from a fork.
741da177e4SLinus Torvalds */
751da177e4SLinus TorvaldsENTRY(ret_from_fork)
761da177e4SLinus Torvalds	bl	schedule_tail
771da177e4SLinus Torvalds	get_thread_info tsk
781da177e4SLinus Torvalds	ldr	r1, [tsk, #TI_FLAGS]		@ check for syscall tracing
791da177e4SLinus Torvalds	mov	why, #1
801da177e4SLinus Torvalds	tst	r1, #_TIF_SYSCALL_TRACE		@ are we tracing syscalls?
811da177e4SLinus Torvalds	beq	ret_slow_syscall
821da177e4SLinus Torvalds	mov	r1, sp
831da177e4SLinus Torvalds	mov	r0, #1				@ trace exit [IP = 1]
841da177e4SLinus Torvalds	bl	syscall_trace
851da177e4SLinus Torvalds	b	ret_slow_syscall
8693ed3970SCatalin MarinasENDPROC(ret_from_fork)
871da177e4SLinus Torvalds
88fa1b4f91SAl Viro	.equ NR_syscalls,0
89fa1b4f91SAl Viro#define CALL(x) .equ NR_syscalls,NR_syscalls+1
901da177e4SLinus Torvalds#include "calls.S"
91fa1b4f91SAl Viro#undef CALL
92fa1b4f91SAl Viro#define CALL(x) .long x
931da177e4SLinus Torvalds
94606576ceSSteven Rostedt#ifdef CONFIG_FUNCTION_TRACER
95686ff228SRabin Vincent/*
96686ff228SRabin Vincent * When compiling with -pg, gcc inserts a call to the mcount routine at the
97686ff228SRabin Vincent * start of every function.  In mcount, apart from the function's address (in
98686ff228SRabin Vincent * lr), we need to get hold of the function's caller's address.
99686ff228SRabin Vincent *
100686ff228SRabin Vincent * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:
101686ff228SRabin Vincent *
102686ff228SRabin Vincent *	bl	mcount
103686ff228SRabin Vincent *
104686ff228SRabin Vincent * These versions have the limitation that in order for the mcount routine to
105686ff228SRabin Vincent * be able to determine the function's caller's address, an APCS-style frame
106686ff228SRabin Vincent * pointer (which is set up with something like the code below) is required.
107686ff228SRabin Vincent *
108686ff228SRabin Vincent *	mov     ip, sp
109686ff228SRabin Vincent *	push    {fp, ip, lr, pc}
110686ff228SRabin Vincent *	sub     fp, ip, #4
111686ff228SRabin Vincent *
112686ff228SRabin Vincent * With EABI, these frame pointers are not available unless -mapcs-frame is
113686ff228SRabin Vincent * specified, and if building as Thumb-2, not even then.
114686ff228SRabin Vincent *
115686ff228SRabin Vincent * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,
116686ff228SRabin Vincent * with call sites like:
117686ff228SRabin Vincent *
118686ff228SRabin Vincent *	push	{lr}
119686ff228SRabin Vincent *	bl	__gnu_mcount_nc
120686ff228SRabin Vincent *
121686ff228SRabin Vincent * With these compilers, frame pointers are not necessary.
122686ff228SRabin Vincent *
123686ff228SRabin Vincent * mcount can be thought of as a function called in the middle of a subroutine
124686ff228SRabin Vincent * call.  As such, it needs to be transparent for both the caller and the
125686ff228SRabin Vincent * callee: the original lr needs to be restored when leaving mcount, and no
126686ff228SRabin Vincent * registers should be clobbered.  (In the __gnu_mcount_nc implementation, we
127686ff228SRabin Vincent * clobber the ip register.  This is OK because the ARM calling convention
128686ff228SRabin Vincent * allows it to be clobbered in subroutines and doesn't use it to hold
129686ff228SRabin Vincent * parameters.)
130686ff228SRabin Vincent */
13109bfafacSRabin Vincent
13209bfafacSRabin Vincent#ifndef CONFIG_OLD_MCOUNT
13309bfafacSRabin Vincent#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
13409bfafacSRabin Vincent#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.
13509bfafacSRabin Vincent#endif
13609bfafacSRabin Vincent#endif
13709bfafacSRabin Vincent
138014c257cSAbhishek Sagar#ifdef CONFIG_DYNAMIC_FTRACE
139014c257cSAbhishek SagarENTRY(mcount)
140014c257cSAbhishek Sagar	stmdb	sp!, {r0-r3, lr}
141014c257cSAbhishek Sagar	mov	r0, lr
142395a59d0SAbhishek Sagar	sub	r0, r0, #MCOUNT_INSN_SIZE
143014c257cSAbhishek Sagar
144014c257cSAbhishek Sagar	.globl mcount_call
145014c257cSAbhishek Sagarmcount_call:
146014c257cSAbhishek Sagar	bl	ftrace_stub
147d4cc510cSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
148014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
149014c257cSAbhishek Sagar
150014c257cSAbhishek SagarENTRY(ftrace_caller)
151014c257cSAbhishek Sagar	stmdb	sp!, {r0-r3, lr}
152014c257cSAbhishek Sagar	ldr	r1, [fp, #-4]
153014c257cSAbhishek Sagar	mov	r0, lr
154395a59d0SAbhishek Sagar	sub	r0, r0, #MCOUNT_INSN_SIZE
155014c257cSAbhishek Sagar
156014c257cSAbhishek Sagar	.globl ftrace_call
157014c257cSAbhishek Sagarftrace_call:
158014c257cSAbhishek Sagar	bl	ftrace_stub
159d4cc510cSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
160014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
161014c257cSAbhishek Sagar
162014c257cSAbhishek Sagar#else
163014c257cSAbhishek Sagar
164181f817eSUwe Kleine-KönigENTRY(__gnu_mcount_nc)
165181f817eSUwe Kleine-König	stmdb	sp!, {r0-r3, lr}
166181f817eSUwe Kleine-König	ldr	r0, =ftrace_trace_function
167181f817eSUwe Kleine-König	ldr	r2, [r0]
168181f817eSUwe Kleine-König	adr	r0, ftrace_stub
169181f817eSUwe Kleine-König	cmp	r0, r2
170181f817eSUwe Kleine-König	bne	gnu_trace
171181f817eSUwe Kleine-König	ldmia	sp!, {r0-r3, ip, lr}
1726176d394SDmitry Artamonow	mov	pc, ip
173181f817eSUwe Kleine-König
174181f817eSUwe Kleine-Königgnu_trace:
175181f817eSUwe Kleine-König	ldr	r1, [sp, #20]			@ lr of instrumented routine
176181f817eSUwe Kleine-König	mov	r0, lr
177181f817eSUwe Kleine-König	sub	r0, r0, #MCOUNT_INSN_SIZE
178181f817eSUwe Kleine-König	mov	lr, pc
179181f817eSUwe Kleine-König	mov	pc, r2
180181f817eSUwe Kleine-König	ldmia	sp!, {r0-r3, ip, lr}
1816176d394SDmitry Artamonow	mov	pc, ip
182181f817eSUwe Kleine-König
18309bfafacSRabin Vincent#ifdef CONFIG_OLD_MCOUNT
18409bfafacSRabin Vincent/*
18509bfafacSRabin Vincent * This is under an ifdef in order to force link-time errors for people trying
18609bfafacSRabin Vincent * to build with !FRAME_POINTER with a GCC which doesn't use the new-style
18709bfafacSRabin Vincent * mcount.
18809bfafacSRabin Vincent */
189014c257cSAbhishek SagarENTRY(mcount)
190014c257cSAbhishek Sagar	stmdb	sp!, {r0-r3, lr}
191014c257cSAbhishek Sagar	ldr	r0, =ftrace_trace_function
192014c257cSAbhishek Sagar	ldr	r2, [r0]
193014c257cSAbhishek Sagar	adr	r0, ftrace_stub
194014c257cSAbhishek Sagar	cmp	r0, r2
195014c257cSAbhishek Sagar	bne	trace
196d4cc510cSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
197014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
198014c257cSAbhishek Sagar
199014c257cSAbhishek Sagartrace:
200b3c960b2SUwe Kleine-König	ldr	r1, [fp, #-4]			@ lr of instrumented routine
201014c257cSAbhishek Sagar	mov	r0, lr
202395a59d0SAbhishek Sagar	sub	r0, r0, #MCOUNT_INSN_SIZE
203014c257cSAbhishek Sagar	mov	lr, pc
204014c257cSAbhishek Sagar	mov	pc, r2
2053ef7143dSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
206014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
20709bfafacSRabin Vincent#endif
208014c257cSAbhishek Sagar
209014c257cSAbhishek Sagar#endif /* CONFIG_DYNAMIC_FTRACE */
210014c257cSAbhishek Sagar
211014c257cSAbhishek Sagar	.globl ftrace_stub
212014c257cSAbhishek Sagarftrace_stub:
213014c257cSAbhishek Sagar	mov	pc, lr
214014c257cSAbhishek Sagar
215606576ceSSteven Rostedt#endif /* CONFIG_FUNCTION_TRACER */
216014c257cSAbhishek Sagar
2171da177e4SLinus Torvalds/*=============================================================================
2181da177e4SLinus Torvalds * SWI handler
2191da177e4SLinus Torvalds *-----------------------------------------------------------------------------
2201da177e4SLinus Torvalds */
2211da177e4SLinus Torvalds
2221da177e4SLinus Torvalds	/* If we're optimising for StrongARM the resulting code won't
2231da177e4SLinus Torvalds	   run on an ARM7 and we can save a couple of instructions.
2241da177e4SLinus Torvalds								--pb */
2251da177e4SLinus Torvalds#ifdef CONFIG_CPU_ARM710
2263f2829a3SNicolas Pitre#define A710(code...) code
2273f2829a3SNicolas Pitre.Larm710bug:
2281da177e4SLinus Torvalds	ldmia	sp, {r0 - lr}^			@ Get calling r0 - lr
2291da177e4SLinus Torvalds	mov	r0, r0
2301da177e4SLinus Torvalds	add	sp, sp, #S_FRAME_SIZE
23160ac133aSNicolas Pitre	subs	pc, lr, #4
2321da177e4SLinus Torvalds#else
2333f2829a3SNicolas Pitre#define A710(code...)
2341da177e4SLinus Torvalds#endif
2351da177e4SLinus Torvalds
2361da177e4SLinus Torvalds	.align	5
2371da177e4SLinus TorvaldsENTRY(vector_swi)
238f4dc9a4cSRussell King	sub	sp, sp, #S_FRAME_SIZE
239f4dc9a4cSRussell King	stmia	sp, {r0 - r12}			@ Calling r0 - r12
240b86040a5SCatalin Marinas ARM(	add	r8, sp, #S_PC		)
241b86040a5SCatalin Marinas ARM(	stmdb	r8, {sp, lr}^		)	@ Calling sp, lr
242b86040a5SCatalin Marinas THUMB(	mov	r8, sp			)
243b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r8, r10, S_SP	)	@ calling sp, lr
244f4dc9a4cSRussell King	mrs	r8, spsr			@ called from non-FIQ mode, so ok.
245f4dc9a4cSRussell King	str	lr, [sp, #S_PC]			@ Save calling PC
246f4dc9a4cSRussell King	str	r8, [sp, #S_PSR]		@ Save CPSR
247f4dc9a4cSRussell King	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
2481da177e4SLinus Torvalds	zero_fp
249e0f9f4a6SRussell King
250e0f9f4a6SRussell King	/*
251e0f9f4a6SRussell King	 * Get the system call number.
252e0f9f4a6SRussell King	 */
2533f2829a3SNicolas Pitre
254dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
2553f2829a3SNicolas Pitre
256dd35afc2SNicolas Pitre	/*
257dd35afc2SNicolas Pitre	 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
258dd35afc2SNicolas Pitre	 * value to determine if it is an EABI or an old ABI call.
259dd35afc2SNicolas Pitre	 */
260dd35afc2SNicolas Pitre#ifdef CONFIG_ARM_THUMB
261dd35afc2SNicolas Pitre	tst	r8, #PSR_T_BIT
262dd35afc2SNicolas Pitre	movne	r10, #0				@ no thumb OABI emulation
263dd35afc2SNicolas Pitre	ldreq	r10, [lr, #-4]			@ get SWI instruction
264dd35afc2SNicolas Pitre#else
265dd35afc2SNicolas Pitre	ldr	r10, [lr, #-4]			@ get SWI instruction
266dd35afc2SNicolas Pitre  A710(	and	ip, r10, #0x0f000000		@ check for SWI		)
267dd35afc2SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
268dd35afc2SNicolas Pitre  A710(	bne	.Larm710bug						)
269dd35afc2SNicolas Pitre#endif
27026584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8
27126584853SCatalin Marinas	rev	r10, r10			@ little endian instruction
27226584853SCatalin Marinas#endif
273dd35afc2SNicolas Pitre
274dd35afc2SNicolas Pitre#elif defined(CONFIG_AEABI)
275dd35afc2SNicolas Pitre
276dd35afc2SNicolas Pitre	/*
277dd35afc2SNicolas Pitre	 * Pure EABI user space always put syscall number into scno (r7).
278dd35afc2SNicolas Pitre	 */
2793f2829a3SNicolas Pitre  A710(	ldr	ip, [lr, #-4]			@ get SWI instruction	)
2803f2829a3SNicolas Pitre  A710(	and	ip, ip, #0x0f000000		@ check for SWI		)
2813f2829a3SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
2823f2829a3SNicolas Pitre  A710(	bne	.Larm710bug						)
283dd35afc2SNicolas Pitre
2843f2829a3SNicolas Pitre#elif defined(CONFIG_ARM_THUMB)
285dd35afc2SNicolas Pitre
286dd35afc2SNicolas Pitre	/* Legacy ABI only, possibly thumb mode. */
287e0f9f4a6SRussell King	tst	r8, #PSR_T_BIT			@ this is SPSR from save_user_regs
288e0f9f4a6SRussell King	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
289e0f9f4a6SRussell King	ldreq	scno, [lr, #-4]
290dd35afc2SNicolas Pitre
291e0f9f4a6SRussell King#else
292dd35afc2SNicolas Pitre
293dd35afc2SNicolas Pitre	/* Legacy ABI only. */
294e0f9f4a6SRussell King	ldr	scno, [lr, #-4]			@ get SWI instruction
2953f2829a3SNicolas Pitre  A710(	and	ip, scno, #0x0f000000		@ check for SWI		)
2963f2829a3SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
2973f2829a3SNicolas Pitre  A710(	bne	.Larm710bug						)
298dd35afc2SNicolas Pitre
299e0f9f4a6SRussell King#endif
3001da177e4SLinus Torvalds
3011da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP
3021da177e4SLinus Torvalds	ldr	ip, __cr_alignment
3031da177e4SLinus Torvalds	ldr	ip, [ip]
3041da177e4SLinus Torvalds	mcr	p15, 0, ip, c1, c0		@ update control register
3051da177e4SLinus Torvalds#endif
3061ec42c0cSRussell King	enable_irq
3071da177e4SLinus Torvalds
3081da177e4SLinus Torvalds	get_thread_info tsk
309dd35afc2SNicolas Pitre	adr	tbl, sys_call_table		@ load syscall table pointer
3101da177e4SLinus Torvalds	ldr	ip, [tsk, #TI_FLAGS]		@ check for syscall tracing
311dd35afc2SNicolas Pitre
312dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
313dd35afc2SNicolas Pitre	/*
314dd35afc2SNicolas Pitre	 * If the swi argument is zero, this is an EABI call and we do nothing.
315dd35afc2SNicolas Pitre	 *
316dd35afc2SNicolas Pitre	 * If this is an old ABI call, get the syscall number into scno and
317dd35afc2SNicolas Pitre	 * get the old ABI syscall table address.
318dd35afc2SNicolas Pitre	 */
319dd35afc2SNicolas Pitre	bics	r10, r10, #0xff000000
320dd35afc2SNicolas Pitre	eorne	scno, r10, #__NR_OABI_SYSCALL_BASE
321dd35afc2SNicolas Pitre	ldrne	tbl, =sys_oabi_call_table
322dd35afc2SNicolas Pitre#elif !defined(CONFIG_AEABI)
3231da177e4SLinus Torvalds	bic	scno, scno, #0xff000000		@ mask off SWI op-code
324e0f9f4a6SRussell King	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
3253f2829a3SNicolas Pitre#endif
326dd35afc2SNicolas Pitre
3273f2829a3SNicolas Pitre	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
3281da177e4SLinus Torvalds	tst	ip, #_TIF_SYSCALL_TRACE		@ are we tracing syscalls?
3291da177e4SLinus Torvalds	bne	__sys_trace
3301da177e4SLinus Torvalds
3311da177e4SLinus Torvalds	cmp	scno, #NR_syscalls		@ check upper syscall limit
332b86040a5SCatalin Marinas	adr	lr, BSYM(ret_fast_syscall)	@ return address
3331da177e4SLinus Torvalds	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
3341da177e4SLinus Torvalds
3351da177e4SLinus Torvalds	add	r1, sp, #S_OFF
3361da177e4SLinus Torvalds2:	mov	why, #0				@ no longer a real syscall
337e0f9f4a6SRussell King	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
338e0f9f4a6SRussell King	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
3391da177e4SLinus Torvalds	bcs	arm_syscall
3401da177e4SLinus Torvalds	b	sys_ni_syscall			@ not private func
34193ed3970SCatalin MarinasENDPROC(vector_swi)
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvalds	/*
3441da177e4SLinus Torvalds	 * This is the really slow path.  We're going to be doing
3451da177e4SLinus Torvalds	 * context switches, and waiting for our parent to respond.
3461da177e4SLinus Torvalds	 */
3471da177e4SLinus Torvalds__sys_trace:
3483f471126SNicolas Pitre	mov	r2, scno
3491da177e4SLinus Torvalds	add	r1, sp, #S_OFF
3501da177e4SLinus Torvalds	mov	r0, #0				@ trace entry [IP = 0]
3511da177e4SLinus Torvalds	bl	syscall_trace
3521da177e4SLinus Torvalds
353b86040a5SCatalin Marinas	adr	lr, BSYM(__sys_trace_return)	@ return address
3543f471126SNicolas Pitre	mov	scno, r0			@ syscall number (possibly new)
3551da177e4SLinus Torvalds	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
3561da177e4SLinus Torvalds	cmp	scno, #NR_syscalls		@ check upper syscall limit
3571da177e4SLinus Torvalds	ldmccia	r1, {r0 - r3}			@ have to reload r0 - r3
3581da177e4SLinus Torvalds	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
3591da177e4SLinus Torvalds	b	2b
3601da177e4SLinus Torvalds
3611da177e4SLinus Torvalds__sys_trace_return:
3621da177e4SLinus Torvalds	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
3633f471126SNicolas Pitre	mov	r2, scno
3641da177e4SLinus Torvalds	mov	r1, sp
3651da177e4SLinus Torvalds	mov	r0, #1				@ trace exit [IP = 1]
3661da177e4SLinus Torvalds	bl	syscall_trace
3671da177e4SLinus Torvalds	b	ret_slow_syscall
3681da177e4SLinus Torvalds
3691da177e4SLinus Torvalds	.align	5
3701da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP
3711da177e4SLinus Torvalds	.type	__cr_alignment, #object
3721da177e4SLinus Torvalds__cr_alignment:
3731da177e4SLinus Torvalds	.word	cr_alignment
3741da177e4SLinus Torvalds#endif
375dd35afc2SNicolas Pitre	.ltorg
376dd35afc2SNicolas Pitre
377dd35afc2SNicolas Pitre/*
378dd35afc2SNicolas Pitre * This is the syscall table declaration for native ABI syscalls.
379dd35afc2SNicolas Pitre * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
380dd35afc2SNicolas Pitre */
381dd35afc2SNicolas Pitre#define ABI(native, compat) native
382dd35afc2SNicolas Pitre#ifdef CONFIG_AEABI
383dd35afc2SNicolas Pitre#define OBSOLETE(syscall) sys_ni_syscall
384dd35afc2SNicolas Pitre#else
385dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall
386dd35afc2SNicolas Pitre#endif
3871da177e4SLinus Torvalds
3881da177e4SLinus Torvalds	.type	sys_call_table, #object
3891da177e4SLinus TorvaldsENTRY(sys_call_table)
3901da177e4SLinus Torvalds#include "calls.S"
391dd35afc2SNicolas Pitre#undef ABI
392dd35afc2SNicolas Pitre#undef OBSOLETE
3931da177e4SLinus Torvalds
3941da177e4SLinus Torvalds/*============================================================================
3951da177e4SLinus Torvalds * Special system call wrappers
3961da177e4SLinus Torvalds */
3971da177e4SLinus Torvalds@ r0 = syscall number
398567bd980SRussell King@ r8 = syscall table
3991da177e4SLinus Torvaldssys_syscall:
4005247593cSPaul Brook		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
4011da177e4SLinus Torvalds		cmp	scno, #__NR_syscall - __NR_SYSCALL_BASE
4021da177e4SLinus Torvalds		cmpne	scno, #NR_syscalls	@ check range
4031da177e4SLinus Torvalds		stmloia	sp, {r5, r6}		@ shuffle args
4041da177e4SLinus Torvalds		movlo	r0, r1
4051da177e4SLinus Torvalds		movlo	r1, r2
4061da177e4SLinus Torvalds		movlo	r2, r3
4071da177e4SLinus Torvalds		movlo	r3, r4
4081da177e4SLinus Torvalds		ldrlo	pc, [tbl, scno, lsl #2]
4091da177e4SLinus Torvalds		b	sys_ni_syscall
41093ed3970SCatalin MarinasENDPROC(sys_syscall)
4111da177e4SLinus Torvalds
4121da177e4SLinus Torvaldssys_fork_wrapper:
4131da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4141da177e4SLinus Torvalds		b	sys_fork
41593ed3970SCatalin MarinasENDPROC(sys_fork_wrapper)
4161da177e4SLinus Torvalds
4171da177e4SLinus Torvaldssys_vfork_wrapper:
4181da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4191da177e4SLinus Torvalds		b	sys_vfork
42093ed3970SCatalin MarinasENDPROC(sys_vfork_wrapper)
4211da177e4SLinus Torvalds
4221da177e4SLinus Torvaldssys_execve_wrapper:
4231da177e4SLinus Torvalds		add	r3, sp, #S_OFF
4241da177e4SLinus Torvalds		b	sys_execve
42593ed3970SCatalin MarinasENDPROC(sys_execve_wrapper)
4261da177e4SLinus Torvalds
4271da177e4SLinus Torvaldssys_clone_wrapper:
4281da177e4SLinus Torvalds		add	ip, sp, #S_OFF
4291da177e4SLinus Torvalds		str	ip, [sp, #4]
4301da177e4SLinus Torvalds		b	sys_clone
43193ed3970SCatalin MarinasENDPROC(sys_clone_wrapper)
4321da177e4SLinus Torvalds
4331da177e4SLinus Torvaldssys_sigreturn_wrapper:
4341da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4351da177e4SLinus Torvalds		b	sys_sigreturn
43693ed3970SCatalin MarinasENDPROC(sys_sigreturn_wrapper)
4371da177e4SLinus Torvalds
4381da177e4SLinus Torvaldssys_rt_sigreturn_wrapper:
4391da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4401da177e4SLinus Torvalds		b	sys_rt_sigreturn
44193ed3970SCatalin MarinasENDPROC(sys_rt_sigreturn_wrapper)
4421da177e4SLinus Torvalds
4431da177e4SLinus Torvaldssys_sigaltstack_wrapper:
4441da177e4SLinus Torvalds		ldr	r2, [sp, #S_OFF + S_SP]
4451da177e4SLinus Torvalds		b	do_sigaltstack
44693ed3970SCatalin MarinasENDPROC(sys_sigaltstack_wrapper)
4471da177e4SLinus Torvalds
448713c4815SNicolas Pitresys_statfs64_wrapper:
449713c4815SNicolas Pitre		teq	r1, #88
450713c4815SNicolas Pitre		moveq	r1, #84
451713c4815SNicolas Pitre		b	sys_statfs64
45293ed3970SCatalin MarinasENDPROC(sys_statfs64_wrapper)
453713c4815SNicolas Pitre
454713c4815SNicolas Pitresys_fstatfs64_wrapper:
455713c4815SNicolas Pitre		teq	r1, #88
456713c4815SNicolas Pitre		moveq	r1, #84
457713c4815SNicolas Pitre		b	sys_fstatfs64
45893ed3970SCatalin MarinasENDPROC(sys_fstatfs64_wrapper)
459713c4815SNicolas Pitre
4601da177e4SLinus Torvalds/*
4611da177e4SLinus Torvalds * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
4621da177e4SLinus Torvalds * offset, we return EINVAL.
4631da177e4SLinus Torvalds */
4641da177e4SLinus Torvaldssys_mmap2:
4651da177e4SLinus Torvalds#if PAGE_SHIFT > 12
4661da177e4SLinus Torvalds		tst	r5, #PGOFF_MASK
4671da177e4SLinus Torvalds		moveq	r5, r5, lsr #PAGE_SHIFT - 12
4681da177e4SLinus Torvalds		streq	r5, [sp, #4]
469f8b72560SAl Viro		beq	sys_mmap_pgoff
4701da177e4SLinus Torvalds		mov	r0, #-EINVAL
4717999d8d7SRussell King		mov	pc, lr
4721da177e4SLinus Torvalds#else
4731da177e4SLinus Torvalds		str	r5, [sp, #4]
474f8b72560SAl Viro		b	sys_mmap_pgoff
4751da177e4SLinus Torvalds#endif
47693ed3970SCatalin MarinasENDPROC(sys_mmap2)
477687ad019SNicolas Pitre
478687ad019SNicolas Pitre#ifdef CONFIG_OABI_COMPAT
479dd35afc2SNicolas Pitre
480687ad019SNicolas Pitre/*
481687ad019SNicolas Pitre * These are syscalls with argument register differences
482687ad019SNicolas Pitre */
483687ad019SNicolas Pitre
484687ad019SNicolas Pitresys_oabi_pread64:
485687ad019SNicolas Pitre		stmia	sp, {r3, r4}
486687ad019SNicolas Pitre		b	sys_pread64
48793ed3970SCatalin MarinasENDPROC(sys_oabi_pread64)
488687ad019SNicolas Pitre
489687ad019SNicolas Pitresys_oabi_pwrite64:
490687ad019SNicolas Pitre		stmia	sp, {r3, r4}
491687ad019SNicolas Pitre		b	sys_pwrite64
49293ed3970SCatalin MarinasENDPROC(sys_oabi_pwrite64)
493687ad019SNicolas Pitre
494687ad019SNicolas Pitresys_oabi_truncate64:
495687ad019SNicolas Pitre		mov	r3, r2
496687ad019SNicolas Pitre		mov	r2, r1
497687ad019SNicolas Pitre		b	sys_truncate64
49893ed3970SCatalin MarinasENDPROC(sys_oabi_truncate64)
499687ad019SNicolas Pitre
500687ad019SNicolas Pitresys_oabi_ftruncate64:
501687ad019SNicolas Pitre		mov	r3, r2
502687ad019SNicolas Pitre		mov	r2, r1
503687ad019SNicolas Pitre		b	sys_ftruncate64
50493ed3970SCatalin MarinasENDPROC(sys_oabi_ftruncate64)
505687ad019SNicolas Pitre
506687ad019SNicolas Pitresys_oabi_readahead:
507687ad019SNicolas Pitre		str	r3, [sp]
508687ad019SNicolas Pitre		mov	r3, r2
509687ad019SNicolas Pitre		mov	r2, r1
510687ad019SNicolas Pitre		b	sys_readahead
51193ed3970SCatalin MarinasENDPROC(sys_oabi_readahead)
512687ad019SNicolas Pitre
513dd35afc2SNicolas Pitre/*
514dd35afc2SNicolas Pitre * Let's declare a second syscall table for old ABI binaries
515dd35afc2SNicolas Pitre * using the compatibility syscall entries.
516dd35afc2SNicolas Pitre */
517dd35afc2SNicolas Pitre#define ABI(native, compat) compat
518dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall
519dd35afc2SNicolas Pitre
520dd35afc2SNicolas Pitre	.type	sys_oabi_call_table, #object
521dd35afc2SNicolas PitreENTRY(sys_oabi_call_table)
522dd35afc2SNicolas Pitre#include "calls.S"
523dd35afc2SNicolas Pitre#undef ABI
524dd35afc2SNicolas Pitre#undef OBSOLETE
525dd35afc2SNicolas Pitre
526687ad019SNicolas Pitre#endif
527687ad019SNicolas Pitre
528