xref: /openbmc/linux/arch/arm/kernel/entry-common.S (revision a3ba87a6)
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}
14972fa62faSRabin VincentENDPROC(mcount)
150014c257cSAbhishek Sagar
151014c257cSAbhishek SagarENTRY(ftrace_caller)
152014c257cSAbhishek Sagar	stmdb	sp!, {r0-r3, lr}
153014c257cSAbhishek Sagar	ldr	r1, [fp, #-4]
154014c257cSAbhishek Sagar	mov	r0, lr
155395a59d0SAbhishek Sagar	sub	r0, r0, #MCOUNT_INSN_SIZE
156014c257cSAbhishek Sagar
157014c257cSAbhishek Sagar	.globl ftrace_call
158014c257cSAbhishek Sagarftrace_call:
159014c257cSAbhishek Sagar	bl	ftrace_stub
160d4cc510cSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
161014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
16272fa62faSRabin VincentENDPROC(ftrace_caller)
163014c257cSAbhishek Sagar
164014c257cSAbhishek Sagar#else
165014c257cSAbhishek Sagar
166181f817eSUwe Kleine-KönigENTRY(__gnu_mcount_nc)
167181f817eSUwe Kleine-König	stmdb	sp!, {r0-r3, lr}
168181f817eSUwe Kleine-König	ldr	r0, =ftrace_trace_function
169181f817eSUwe Kleine-König	ldr	r2, [r0]
170a3ba87a6SRabin Vincent	adr	r0, .Lftrace_stub
171181f817eSUwe Kleine-König	cmp	r0, r2
172181f817eSUwe Kleine-König	bne	gnu_trace
173181f817eSUwe Kleine-König	ldmia	sp!, {r0-r3, ip, lr}
1746176d394SDmitry Artamonow	mov	pc, ip
175181f817eSUwe Kleine-König
176181f817eSUwe Kleine-Königgnu_trace:
177181f817eSUwe Kleine-König	ldr	r1, [sp, #20]			@ lr of instrumented routine
178181f817eSUwe Kleine-König	mov	r0, lr
179181f817eSUwe Kleine-König	sub	r0, r0, #MCOUNT_INSN_SIZE
180a3ba87a6SRabin Vincent	adr	lr, BSYM(1f)
181181f817eSUwe Kleine-König	mov	pc, r2
182a3ba87a6SRabin Vincent1:
183181f817eSUwe Kleine-König	ldmia	sp!, {r0-r3, ip, lr}
1846176d394SDmitry Artamonow	mov	pc, ip
18572fa62faSRabin VincentENDPROC(__gnu_mcount_nc)
186181f817eSUwe Kleine-König
18709bfafacSRabin Vincent#ifdef CONFIG_OLD_MCOUNT
18809bfafacSRabin Vincent/*
18909bfafacSRabin Vincent * This is under an ifdef in order to force link-time errors for people trying
19009bfafacSRabin Vincent * to build with !FRAME_POINTER with a GCC which doesn't use the new-style
19109bfafacSRabin Vincent * mcount.
19209bfafacSRabin Vincent */
193014c257cSAbhishek SagarENTRY(mcount)
194014c257cSAbhishek Sagar	stmdb	sp!, {r0-r3, lr}
195014c257cSAbhishek Sagar	ldr	r0, =ftrace_trace_function
196014c257cSAbhishek Sagar	ldr	r2, [r0]
197014c257cSAbhishek Sagar	adr	r0, ftrace_stub
198014c257cSAbhishek Sagar	cmp	r0, r2
199014c257cSAbhishek Sagar	bne	trace
200d4cc510cSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
201014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
202014c257cSAbhishek Sagar
203014c257cSAbhishek Sagartrace:
204b3c960b2SUwe Kleine-König	ldr	r1, [fp, #-4]			@ lr of instrumented routine
205014c257cSAbhishek Sagar	mov	r0, lr
206395a59d0SAbhishek Sagar	sub	r0, r0, #MCOUNT_INSN_SIZE
207014c257cSAbhishek Sagar	mov	lr, pc
208014c257cSAbhishek Sagar	mov	pc, r2
2093ef7143dSUwe Kleine-König	ldr	lr, [fp, #-4]			@ restore lr
210014c257cSAbhishek Sagar	ldmia	sp!, {r0-r3, pc}
21172fa62faSRabin VincentENDPROC(mcount)
21209bfafacSRabin Vincent#endif
213014c257cSAbhishek Sagar
214014c257cSAbhishek Sagar#endif /* CONFIG_DYNAMIC_FTRACE */
215014c257cSAbhishek Sagar
21672fa62faSRabin VincentENTRY(ftrace_stub)
217a3ba87a6SRabin Vincent.Lftrace_stub:
218014c257cSAbhishek Sagar	mov	pc, lr
21972fa62faSRabin VincentENDPROC(ftrace_stub)
220014c257cSAbhishek Sagar
221606576ceSSteven Rostedt#endif /* CONFIG_FUNCTION_TRACER */
222014c257cSAbhishek Sagar
2231da177e4SLinus Torvalds/*=============================================================================
2241da177e4SLinus Torvalds * SWI handler
2251da177e4SLinus Torvalds *-----------------------------------------------------------------------------
2261da177e4SLinus Torvalds */
2271da177e4SLinus Torvalds
2281da177e4SLinus Torvalds	/* If we're optimising for StrongARM the resulting code won't
2291da177e4SLinus Torvalds	   run on an ARM7 and we can save a couple of instructions.
2301da177e4SLinus Torvalds								--pb */
2311da177e4SLinus Torvalds#ifdef CONFIG_CPU_ARM710
2323f2829a3SNicolas Pitre#define A710(code...) code
2333f2829a3SNicolas Pitre.Larm710bug:
2341da177e4SLinus Torvalds	ldmia	sp, {r0 - lr}^			@ Get calling r0 - lr
2351da177e4SLinus Torvalds	mov	r0, r0
2361da177e4SLinus Torvalds	add	sp, sp, #S_FRAME_SIZE
23760ac133aSNicolas Pitre	subs	pc, lr, #4
2381da177e4SLinus Torvalds#else
2393f2829a3SNicolas Pitre#define A710(code...)
2401da177e4SLinus Torvalds#endif
2411da177e4SLinus Torvalds
2421da177e4SLinus Torvalds	.align	5
2431da177e4SLinus TorvaldsENTRY(vector_swi)
244f4dc9a4cSRussell King	sub	sp, sp, #S_FRAME_SIZE
245f4dc9a4cSRussell King	stmia	sp, {r0 - r12}			@ Calling r0 - r12
246b86040a5SCatalin Marinas ARM(	add	r8, sp, #S_PC		)
247b86040a5SCatalin Marinas ARM(	stmdb	r8, {sp, lr}^		)	@ Calling sp, lr
248b86040a5SCatalin Marinas THUMB(	mov	r8, sp			)
249b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r8, r10, S_SP	)	@ calling sp, lr
250f4dc9a4cSRussell King	mrs	r8, spsr			@ called from non-FIQ mode, so ok.
251f4dc9a4cSRussell King	str	lr, [sp, #S_PC]			@ Save calling PC
252f4dc9a4cSRussell King	str	r8, [sp, #S_PSR]		@ Save CPSR
253f4dc9a4cSRussell King	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
2541da177e4SLinus Torvalds	zero_fp
255e0f9f4a6SRussell King
256e0f9f4a6SRussell King	/*
257e0f9f4a6SRussell King	 * Get the system call number.
258e0f9f4a6SRussell King	 */
2593f2829a3SNicolas Pitre
260dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
2613f2829a3SNicolas Pitre
262dd35afc2SNicolas Pitre	/*
263dd35afc2SNicolas Pitre	 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
264dd35afc2SNicolas Pitre	 * value to determine if it is an EABI or an old ABI call.
265dd35afc2SNicolas Pitre	 */
266dd35afc2SNicolas Pitre#ifdef CONFIG_ARM_THUMB
267dd35afc2SNicolas Pitre	tst	r8, #PSR_T_BIT
268dd35afc2SNicolas Pitre	movne	r10, #0				@ no thumb OABI emulation
269dd35afc2SNicolas Pitre	ldreq	r10, [lr, #-4]			@ get SWI instruction
270dd35afc2SNicolas Pitre#else
271dd35afc2SNicolas Pitre	ldr	r10, [lr, #-4]			@ get SWI instruction
272dd35afc2SNicolas Pitre  A710(	and	ip, r10, #0x0f000000		@ check for SWI		)
273dd35afc2SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
274dd35afc2SNicolas Pitre  A710(	bne	.Larm710bug						)
275dd35afc2SNicolas Pitre#endif
27626584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8
27726584853SCatalin Marinas	rev	r10, r10			@ little endian instruction
27826584853SCatalin Marinas#endif
279dd35afc2SNicolas Pitre
280dd35afc2SNicolas Pitre#elif defined(CONFIG_AEABI)
281dd35afc2SNicolas Pitre
282dd35afc2SNicolas Pitre	/*
283dd35afc2SNicolas Pitre	 * Pure EABI user space always put syscall number into scno (r7).
284dd35afc2SNicolas Pitre	 */
2853f2829a3SNicolas Pitre  A710(	ldr	ip, [lr, #-4]			@ get SWI instruction	)
2863f2829a3SNicolas Pitre  A710(	and	ip, ip, #0x0f000000		@ check for SWI		)
2873f2829a3SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
2883f2829a3SNicolas Pitre  A710(	bne	.Larm710bug						)
289dd35afc2SNicolas Pitre
2903f2829a3SNicolas Pitre#elif defined(CONFIG_ARM_THUMB)
291dd35afc2SNicolas Pitre
292dd35afc2SNicolas Pitre	/* Legacy ABI only, possibly thumb mode. */
293e0f9f4a6SRussell King	tst	r8, #PSR_T_BIT			@ this is SPSR from save_user_regs
294e0f9f4a6SRussell King	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
295e0f9f4a6SRussell King	ldreq	scno, [lr, #-4]
296dd35afc2SNicolas Pitre
297e0f9f4a6SRussell King#else
298dd35afc2SNicolas Pitre
299dd35afc2SNicolas Pitre	/* Legacy ABI only. */
300e0f9f4a6SRussell King	ldr	scno, [lr, #-4]			@ get SWI instruction
3013f2829a3SNicolas Pitre  A710(	and	ip, scno, #0x0f000000		@ check for SWI		)
3023f2829a3SNicolas Pitre  A710(	teq	ip, #0x0f000000						)
3033f2829a3SNicolas Pitre  A710(	bne	.Larm710bug						)
304dd35afc2SNicolas Pitre
305e0f9f4a6SRussell King#endif
3061da177e4SLinus Torvalds
3071da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP
3081da177e4SLinus Torvalds	ldr	ip, __cr_alignment
3091da177e4SLinus Torvalds	ldr	ip, [ip]
3101da177e4SLinus Torvalds	mcr	p15, 0, ip, c1, c0		@ update control register
3111da177e4SLinus Torvalds#endif
3121ec42c0cSRussell King	enable_irq
3131da177e4SLinus Torvalds
3141da177e4SLinus Torvalds	get_thread_info tsk
315dd35afc2SNicolas Pitre	adr	tbl, sys_call_table		@ load syscall table pointer
3161da177e4SLinus Torvalds	ldr	ip, [tsk, #TI_FLAGS]		@ check for syscall tracing
317dd35afc2SNicolas Pitre
318dd35afc2SNicolas Pitre#if defined(CONFIG_OABI_COMPAT)
319dd35afc2SNicolas Pitre	/*
320dd35afc2SNicolas Pitre	 * If the swi argument is zero, this is an EABI call and we do nothing.
321dd35afc2SNicolas Pitre	 *
322dd35afc2SNicolas Pitre	 * If this is an old ABI call, get the syscall number into scno and
323dd35afc2SNicolas Pitre	 * get the old ABI syscall table address.
324dd35afc2SNicolas Pitre	 */
325dd35afc2SNicolas Pitre	bics	r10, r10, #0xff000000
326dd35afc2SNicolas Pitre	eorne	scno, r10, #__NR_OABI_SYSCALL_BASE
327dd35afc2SNicolas Pitre	ldrne	tbl, =sys_oabi_call_table
328dd35afc2SNicolas Pitre#elif !defined(CONFIG_AEABI)
3291da177e4SLinus Torvalds	bic	scno, scno, #0xff000000		@ mask off SWI op-code
330e0f9f4a6SRussell King	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
3313f2829a3SNicolas Pitre#endif
332dd35afc2SNicolas Pitre
3333f2829a3SNicolas Pitre	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
3341da177e4SLinus Torvalds	tst	ip, #_TIF_SYSCALL_TRACE		@ are we tracing syscalls?
3351da177e4SLinus Torvalds	bne	__sys_trace
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvalds	cmp	scno, #NR_syscalls		@ check upper syscall limit
338b86040a5SCatalin Marinas	adr	lr, BSYM(ret_fast_syscall)	@ return address
3391da177e4SLinus Torvalds	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
3401da177e4SLinus Torvalds
3411da177e4SLinus Torvalds	add	r1, sp, #S_OFF
3421da177e4SLinus Torvalds2:	mov	why, #0				@ no longer a real syscall
343e0f9f4a6SRussell King	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
344e0f9f4a6SRussell King	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
3451da177e4SLinus Torvalds	bcs	arm_syscall
3461da177e4SLinus Torvalds	b	sys_ni_syscall			@ not private func
34793ed3970SCatalin MarinasENDPROC(vector_swi)
3481da177e4SLinus Torvalds
3491da177e4SLinus Torvalds	/*
3501da177e4SLinus Torvalds	 * This is the really slow path.  We're going to be doing
3511da177e4SLinus Torvalds	 * context switches, and waiting for our parent to respond.
3521da177e4SLinus Torvalds	 */
3531da177e4SLinus Torvalds__sys_trace:
3543f471126SNicolas Pitre	mov	r2, scno
3551da177e4SLinus Torvalds	add	r1, sp, #S_OFF
3561da177e4SLinus Torvalds	mov	r0, #0				@ trace entry [IP = 0]
3571da177e4SLinus Torvalds	bl	syscall_trace
3581da177e4SLinus Torvalds
359b86040a5SCatalin Marinas	adr	lr, BSYM(__sys_trace_return)	@ return address
3603f471126SNicolas Pitre	mov	scno, r0			@ syscall number (possibly new)
3611da177e4SLinus Torvalds	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
3621da177e4SLinus Torvalds	cmp	scno, #NR_syscalls		@ check upper syscall limit
3631da177e4SLinus Torvalds	ldmccia	r1, {r0 - r3}			@ have to reload r0 - r3
3641da177e4SLinus Torvalds	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
3651da177e4SLinus Torvalds	b	2b
3661da177e4SLinus Torvalds
3671da177e4SLinus Torvalds__sys_trace_return:
3681da177e4SLinus Torvalds	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
3693f471126SNicolas Pitre	mov	r2, scno
3701da177e4SLinus Torvalds	mov	r1, sp
3711da177e4SLinus Torvalds	mov	r0, #1				@ trace exit [IP = 1]
3721da177e4SLinus Torvalds	bl	syscall_trace
3731da177e4SLinus Torvalds	b	ret_slow_syscall
3741da177e4SLinus Torvalds
3751da177e4SLinus Torvalds	.align	5
3761da177e4SLinus Torvalds#ifdef CONFIG_ALIGNMENT_TRAP
3771da177e4SLinus Torvalds	.type	__cr_alignment, #object
3781da177e4SLinus Torvalds__cr_alignment:
3791da177e4SLinus Torvalds	.word	cr_alignment
3801da177e4SLinus Torvalds#endif
381dd35afc2SNicolas Pitre	.ltorg
382dd35afc2SNicolas Pitre
383dd35afc2SNicolas Pitre/*
384dd35afc2SNicolas Pitre * This is the syscall table declaration for native ABI syscalls.
385dd35afc2SNicolas Pitre * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
386dd35afc2SNicolas Pitre */
387dd35afc2SNicolas Pitre#define ABI(native, compat) native
388dd35afc2SNicolas Pitre#ifdef CONFIG_AEABI
389dd35afc2SNicolas Pitre#define OBSOLETE(syscall) sys_ni_syscall
390dd35afc2SNicolas Pitre#else
391dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall
392dd35afc2SNicolas Pitre#endif
3931da177e4SLinus Torvalds
3941da177e4SLinus Torvalds	.type	sys_call_table, #object
3951da177e4SLinus TorvaldsENTRY(sys_call_table)
3961da177e4SLinus Torvalds#include "calls.S"
397dd35afc2SNicolas Pitre#undef ABI
398dd35afc2SNicolas Pitre#undef OBSOLETE
3991da177e4SLinus Torvalds
4001da177e4SLinus Torvalds/*============================================================================
4011da177e4SLinus Torvalds * Special system call wrappers
4021da177e4SLinus Torvalds */
4031da177e4SLinus Torvalds@ r0 = syscall number
404567bd980SRussell King@ r8 = syscall table
4051da177e4SLinus Torvaldssys_syscall:
4065247593cSPaul Brook		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
4071da177e4SLinus Torvalds		cmp	scno, #__NR_syscall - __NR_SYSCALL_BASE
4081da177e4SLinus Torvalds		cmpne	scno, #NR_syscalls	@ check range
4091da177e4SLinus Torvalds		stmloia	sp, {r5, r6}		@ shuffle args
4101da177e4SLinus Torvalds		movlo	r0, r1
4111da177e4SLinus Torvalds		movlo	r1, r2
4121da177e4SLinus Torvalds		movlo	r2, r3
4131da177e4SLinus Torvalds		movlo	r3, r4
4141da177e4SLinus Torvalds		ldrlo	pc, [tbl, scno, lsl #2]
4151da177e4SLinus Torvalds		b	sys_ni_syscall
41693ed3970SCatalin MarinasENDPROC(sys_syscall)
4171da177e4SLinus Torvalds
4181da177e4SLinus Torvaldssys_fork_wrapper:
4191da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4201da177e4SLinus Torvalds		b	sys_fork
42193ed3970SCatalin MarinasENDPROC(sys_fork_wrapper)
4221da177e4SLinus Torvalds
4231da177e4SLinus Torvaldssys_vfork_wrapper:
4241da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4251da177e4SLinus Torvalds		b	sys_vfork
42693ed3970SCatalin MarinasENDPROC(sys_vfork_wrapper)
4271da177e4SLinus Torvalds
4281da177e4SLinus Torvaldssys_execve_wrapper:
4291da177e4SLinus Torvalds		add	r3, sp, #S_OFF
4301da177e4SLinus Torvalds		b	sys_execve
43193ed3970SCatalin MarinasENDPROC(sys_execve_wrapper)
4321da177e4SLinus Torvalds
4331da177e4SLinus Torvaldssys_clone_wrapper:
4341da177e4SLinus Torvalds		add	ip, sp, #S_OFF
4351da177e4SLinus Torvalds		str	ip, [sp, #4]
4361da177e4SLinus Torvalds		b	sys_clone
43793ed3970SCatalin MarinasENDPROC(sys_clone_wrapper)
4381da177e4SLinus Torvalds
4391da177e4SLinus Torvaldssys_sigreturn_wrapper:
4401da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4411da177e4SLinus Torvalds		b	sys_sigreturn
44293ed3970SCatalin MarinasENDPROC(sys_sigreturn_wrapper)
4431da177e4SLinus Torvalds
4441da177e4SLinus Torvaldssys_rt_sigreturn_wrapper:
4451da177e4SLinus Torvalds		add	r0, sp, #S_OFF
4461da177e4SLinus Torvalds		b	sys_rt_sigreturn
44793ed3970SCatalin MarinasENDPROC(sys_rt_sigreturn_wrapper)
4481da177e4SLinus Torvalds
4491da177e4SLinus Torvaldssys_sigaltstack_wrapper:
4501da177e4SLinus Torvalds		ldr	r2, [sp, #S_OFF + S_SP]
4511da177e4SLinus Torvalds		b	do_sigaltstack
45293ed3970SCatalin MarinasENDPROC(sys_sigaltstack_wrapper)
4531da177e4SLinus Torvalds
454713c4815SNicolas Pitresys_statfs64_wrapper:
455713c4815SNicolas Pitre		teq	r1, #88
456713c4815SNicolas Pitre		moveq	r1, #84
457713c4815SNicolas Pitre		b	sys_statfs64
45893ed3970SCatalin MarinasENDPROC(sys_statfs64_wrapper)
459713c4815SNicolas Pitre
460713c4815SNicolas Pitresys_fstatfs64_wrapper:
461713c4815SNicolas Pitre		teq	r1, #88
462713c4815SNicolas Pitre		moveq	r1, #84
463713c4815SNicolas Pitre		b	sys_fstatfs64
46493ed3970SCatalin MarinasENDPROC(sys_fstatfs64_wrapper)
465713c4815SNicolas Pitre
4661da177e4SLinus Torvalds/*
4671da177e4SLinus Torvalds * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
4681da177e4SLinus Torvalds * offset, we return EINVAL.
4691da177e4SLinus Torvalds */
4701da177e4SLinus Torvaldssys_mmap2:
4711da177e4SLinus Torvalds#if PAGE_SHIFT > 12
4721da177e4SLinus Torvalds		tst	r5, #PGOFF_MASK
4731da177e4SLinus Torvalds		moveq	r5, r5, lsr #PAGE_SHIFT - 12
4741da177e4SLinus Torvalds		streq	r5, [sp, #4]
475f8b72560SAl Viro		beq	sys_mmap_pgoff
4761da177e4SLinus Torvalds		mov	r0, #-EINVAL
4777999d8d7SRussell King		mov	pc, lr
4781da177e4SLinus Torvalds#else
4791da177e4SLinus Torvalds		str	r5, [sp, #4]
480f8b72560SAl Viro		b	sys_mmap_pgoff
4811da177e4SLinus Torvalds#endif
48293ed3970SCatalin MarinasENDPROC(sys_mmap2)
483687ad019SNicolas Pitre
484687ad019SNicolas Pitre#ifdef CONFIG_OABI_COMPAT
485dd35afc2SNicolas Pitre
486687ad019SNicolas Pitre/*
487687ad019SNicolas Pitre * These are syscalls with argument register differences
488687ad019SNicolas Pitre */
489687ad019SNicolas Pitre
490687ad019SNicolas Pitresys_oabi_pread64:
491687ad019SNicolas Pitre		stmia	sp, {r3, r4}
492687ad019SNicolas Pitre		b	sys_pread64
49393ed3970SCatalin MarinasENDPROC(sys_oabi_pread64)
494687ad019SNicolas Pitre
495687ad019SNicolas Pitresys_oabi_pwrite64:
496687ad019SNicolas Pitre		stmia	sp, {r3, r4}
497687ad019SNicolas Pitre		b	sys_pwrite64
49893ed3970SCatalin MarinasENDPROC(sys_oabi_pwrite64)
499687ad019SNicolas Pitre
500687ad019SNicolas Pitresys_oabi_truncate64:
501687ad019SNicolas Pitre		mov	r3, r2
502687ad019SNicolas Pitre		mov	r2, r1
503687ad019SNicolas Pitre		b	sys_truncate64
50493ed3970SCatalin MarinasENDPROC(sys_oabi_truncate64)
505687ad019SNicolas Pitre
506687ad019SNicolas Pitresys_oabi_ftruncate64:
507687ad019SNicolas Pitre		mov	r3, r2
508687ad019SNicolas Pitre		mov	r2, r1
509687ad019SNicolas Pitre		b	sys_ftruncate64
51093ed3970SCatalin MarinasENDPROC(sys_oabi_ftruncate64)
511687ad019SNicolas Pitre
512687ad019SNicolas Pitresys_oabi_readahead:
513687ad019SNicolas Pitre		str	r3, [sp]
514687ad019SNicolas Pitre		mov	r3, r2
515687ad019SNicolas Pitre		mov	r2, r1
516687ad019SNicolas Pitre		b	sys_readahead
51793ed3970SCatalin MarinasENDPROC(sys_oabi_readahead)
518687ad019SNicolas Pitre
519dd35afc2SNicolas Pitre/*
520dd35afc2SNicolas Pitre * Let's declare a second syscall table for old ABI binaries
521dd35afc2SNicolas Pitre * using the compatibility syscall entries.
522dd35afc2SNicolas Pitre */
523dd35afc2SNicolas Pitre#define ABI(native, compat) compat
524dd35afc2SNicolas Pitre#define OBSOLETE(syscall) syscall
525dd35afc2SNicolas Pitre
526dd35afc2SNicolas Pitre	.type	sys_oabi_call_table, #object
527dd35afc2SNicolas PitreENTRY(sys_oabi_call_table)
528dd35afc2SNicolas Pitre#include "calls.S"
529dd35afc2SNicolas Pitre#undef ABI
530dd35afc2SNicolas Pitre#undef OBSOLETE
531dd35afc2SNicolas Pitre
532687ad019SNicolas Pitre#endif
533687ad019SNicolas Pitre
534