blob: 82aaf0aeb85d2723285668b226e53b8e12b63f12 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/entry-common.S
3 *
4 * Copyright (C) 2000 Russell King
5 *
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.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/unistd.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053012#include <asm/ftrace.h>
Catalin Marinasc4c57162009-02-16 11:42:09 +010013#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Rob Herring13a50452012-02-07 09:28:22 -060015#ifdef CONFIG_NEED_RET_TO_USER
16#include <mach/entry-macro.S>
17#else
18 .macro arch_ret_to_user, tmp1, tmp2
19 .endm
20#endif
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "entry-header.S"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25 .align 5
26/*
27 * This is the fast syscall return path. We do as little as
28 * possible here, and this includes saving r0 back into the SVC
29 * stack.
30 */
31ret_fast_syscall:
Catalin Marinasc4c57162009-02-16 11:42:09 +010032 UNWIND(.fnstart )
33 UNWIND(.cantunwind )
Russell King1ec42c02005-04-26 15:18:26 +010034 disable_irq @ disable interrupts
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 ldr r1, [tsk, #TI_FLAGS]
36 tst r1, #_TIF_WORK_MASK
37 bne fast_work_pending
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010038#if defined(CONFIG_IRQSOFF_TRACER)
39 asm_trace_hardirqs_on
40#endif
Russell Kingf4dc9a42005-04-26 15:20:34 +010041
Dan Williamsf80dff92007-02-16 22:16:32 +010042 /* perform architecture specific actions before user return */
43 arch_ret_to_user r1, lr
44
Catalin Marinasb86040a2009-07-24 12:32:54 +010045 restore_user_regs fast = 1, offset = S_OFF
Catalin Marinasc4c57162009-02-16 11:42:09 +010046 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
49 * Ok, we need to do extra processing, enter the slow path.
50 */
51fast_work_pending:
52 str r0, [sp, #S_R0+S_OFF]! @ returned r0
53work_pending:
54 tst r1, #_TIF_NEED_RESCHED
55 bne work_resched
Al Viro84849b32012-04-24 16:40:34 -040056 /*
57 * TIF_SIGPENDING or TIF_NOTIFY_RESUME must've been set if we got here
58 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 mov r0, sp @ 'regs'
60 mov r2, why @ 'syscall'
Russell Kingb2b163b2010-09-17 14:56:16 +010061 tst r1, #_TIF_SIGPENDING @ delivering a signal?
62 movne why, #0 @ prevent further restarts
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 bl do_notify_resume
Daniel Jacobowitza6c61e92005-11-19 10:01:07 +000064 b ret_slow_syscall @ Check work again
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66work_resched:
67 bl schedule
68/*
69 * "slow" syscall return path. "why" tells us if this was a real syscall.
70 */
71ENTRY(ret_to_user)
72ret_slow_syscall:
Russell King1ec42c02005-04-26 15:18:26 +010073 disable_irq @ disable interrupts
Ming Lei9fc25522011-06-05 02:24:58 +010074ENTRY(ret_to_user_from_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 ldr r1, [tsk, #TI_FLAGS]
76 tst r1, #_TIF_WORK_MASK
77 bne work_pending
78no_work_pending:
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010079#if defined(CONFIG_IRQSOFF_TRACER)
80 asm_trace_hardirqs_on
81#endif
Dan Williamsf80dff92007-02-16 22:16:32 +010082 /* perform architecture specific actions before user return */
83 arch_ret_to_user r1, lr
84
Catalin Marinasb86040a2009-07-24 12:32:54 +010085 restore_user_regs fast = 0, offset = 0
Ming Lei9fc25522011-06-05 02:24:58 +010086ENDPROC(ret_to_user_from_irq)
Catalin Marinas93ed3972008-08-28 11:22:32 +010087ENDPROC(ret_to_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89/*
90 * This is how we return from a fork.
91 */
92ENTRY(ret_from_fork)
93 bl schedule_tail
94 get_thread_info tsk
95 ldr r1, [tsk, #TI_FLAGS] @ check for syscall tracing
96 mov why, #1
Nathaniel Husted29ef73b2012-01-03 14:23:09 -050097 tst r1, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 beq ret_slow_syscall
99 mov r1, sp
100 mov r0, #1 @ trace exit [IP = 1]
101 bl syscall_trace
102 b ret_slow_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100103ENDPROC(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Al Virofa1b4f92006-01-19 12:57:01 +0000105 .equ NR_syscalls,0
106#define CALL(x) .equ NR_syscalls,NR_syscalls+1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#include "calls.S"
Al Virofa1b4f92006-01-19 12:57:01 +0000108#undef CALL
109#define CALL(x) .long x
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Steven Rostedt606576c2008-10-06 19:06:12 -0400111#ifdef CONFIG_FUNCTION_TRACER
Rabin Vincent686ff222010-08-03 17:09:40 +0100112/*
113 * When compiling with -pg, gcc inserts a call to the mcount routine at the
114 * start of every function. In mcount, apart from the function's address (in
115 * lr), we need to get hold of the function's caller's address.
116 *
117 * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:
118 *
119 * bl mcount
120 *
121 * These versions have the limitation that in order for the mcount routine to
122 * be able to determine the function's caller's address, an APCS-style frame
123 * pointer (which is set up with something like the code below) is required.
124 *
125 * mov ip, sp
126 * push {fp, ip, lr, pc}
127 * sub fp, ip, #4
128 *
129 * With EABI, these frame pointers are not available unless -mapcs-frame is
130 * specified, and if building as Thumb-2, not even then.
131 *
132 * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,
133 * with call sites like:
134 *
135 * push {lr}
136 * bl __gnu_mcount_nc
137 *
138 * With these compilers, frame pointers are not necessary.
139 *
140 * mcount can be thought of as a function called in the middle of a subroutine
141 * call. As such, it needs to be transparent for both the caller and the
142 * callee: the original lr needs to be restored when leaving mcount, and no
143 * registers should be clobbered. (In the __gnu_mcount_nc implementation, we
144 * clobber the ip register. This is OK because the ARM calling convention
145 * allows it to be clobbered in subroutines and doesn't use it to hold
146 * parameters.)
Rabin Vincent3b6c2232010-08-10 19:43:28 +0100147 *
148 * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0"
149 * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see
150 * arch/arm/kernel/ftrace.c).
Rabin Vincent686ff222010-08-03 17:09:40 +0100151 */
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100152
153#ifndef CONFIG_OLD_MCOUNT
154#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
155#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.
156#endif
157#endif
158
Rabin Vincentd68133b2012-01-24 16:52:52 +0100159.macro mcount_adjust_addr rd, rn
160 bic \rd, \rn, #1 @ clear the Thumb bit if present
161 sub \rd, \rd, #MCOUNT_INSN_SIZE
162.endm
163
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530164.macro __mcount suffix
165 mcount_enter
Rabin Vincent28e192d2010-08-03 17:08:09 +0100166 ldr r0, =ftrace_trace_function
167 ldr r2, [r0]
Rabin Vincenta3ba87a2010-08-10 19:37:21 +0100168 adr r0, .Lftrace_stub
Rabin Vincent28e192d2010-08-03 17:08:09 +0100169 cmp r0, r2
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530170 bne 1f
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200171
Tim Bird376cfa82010-10-09 22:24:38 +0530172#ifdef CONFIG_FUNCTION_GRAPH_TRACER
173 ldr r1, =ftrace_graph_return
174 ldr r2, [r1]
175 cmp r0, r2
176 bne ftrace_graph_caller\suffix
177
178 ldr r1, =ftrace_graph_entry
179 ldr r2, [r1]
180 ldr r0, =ftrace_graph_entry_stub
181 cmp r0, r2
182 bne ftrace_graph_caller\suffix
183#endif
184
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530185 mcount_exit
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200186
Rabin Vincentd3b9dc92010-10-07 17:39:47 +05301871: mcount_get_lr r1 @ lr of instrumented func
Rabin Vincentd68133b2012-01-24 16:52:52 +0100188 mcount_adjust_addr r0, lr @ instrumented function
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530189 adr lr, BSYM(2f)
Rabin Vincent28e192d2010-08-03 17:08:09 +0100190 mov pc, r2
Rabin Vincentd3b9dc92010-10-07 17:39:47 +05301912: mcount_exit
192.endm
193
194.macro __ftrace_caller suffix
195 mcount_enter
196
197 mcount_get_lr r1 @ lr of instrumented func
Rabin Vincentd68133b2012-01-24 16:52:52 +0100198 mcount_adjust_addr r0, lr @ instrumented function
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530199
200 .globl ftrace_call\suffix
201ftrace_call\suffix:
202 bl ftrace_stub
203
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530204#ifdef CONFIG_FUNCTION_GRAPH_TRACER
205 .globl ftrace_graph_call\suffix
206ftrace_graph_call\suffix:
207 mov r0, r0
208#endif
209
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530210 mcount_exit
211.endm
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200212
Tim Bird376cfa82010-10-09 22:24:38 +0530213.macro __ftrace_graph_caller
214 sub r0, fp, #4 @ &lr of instrumented routine (&parent)
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530215#ifdef CONFIG_DYNAMIC_FTRACE
216 @ called from __ftrace_caller, saved in mcount_enter
217 ldr r1, [sp, #16] @ instrumented routine (func)
Rabin Vincentd68133b2012-01-24 16:52:52 +0100218 mcount_adjust_addr r1, r1
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530219#else
220 @ called from __mcount, untouched in lr
Rabin Vincentd68133b2012-01-24 16:52:52 +0100221 mcount_adjust_addr r1, lr @ instrumented routine (func)
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530222#endif
Tim Bird376cfa82010-10-09 22:24:38 +0530223 mov r2, fp @ frame pointer
224 bl prepare_ftrace_return
225 mcount_exit
226.endm
Abhishek Sagar014c2572008-05-31 14:23:50 +0530227
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100228#ifdef CONFIG_OLD_MCOUNT
229/*
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530230 * mcount
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100231 */
Abhishek Sagar014c2572008-05-31 14:23:50 +0530232
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530233.macro mcount_enter
234 stmdb sp!, {r0-r3, lr}
235.endm
236
237.macro mcount_get_lr reg
238 ldr \reg, [fp, #-4]
239.endm
240
241.macro mcount_exit
242 ldr lr, [fp, #-4]
Rabin Vincent28e192d2010-08-03 17:08:09 +0100243 ldmia sp!, {r0-r3, pc}
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530244.endm
245
246ENTRY(mcount)
247#ifdef CONFIG_DYNAMIC_FTRACE
248 stmdb sp!, {lr}
249 ldr lr, [fp, #-4]
250 ldmia sp!, {pc}
251#else
252 __mcount _old
253#endif
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100254ENDPROC(mcount)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530255
256#ifdef CONFIG_DYNAMIC_FTRACE
257ENTRY(ftrace_caller_old)
258 __ftrace_caller _old
259ENDPROC(ftrace_caller_old)
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100260#endif
Abhishek Sagar014c2572008-05-31 14:23:50 +0530261
Tim Bird376cfa82010-10-09 22:24:38 +0530262#ifdef CONFIG_FUNCTION_GRAPH_TRACER
263ENTRY(ftrace_graph_caller_old)
264 __ftrace_graph_caller
265ENDPROC(ftrace_graph_caller_old)
266#endif
267
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530268.purgem mcount_enter
269.purgem mcount_get_lr
270.purgem mcount_exit
271#endif
272
273/*
274 * __gnu_mcount_nc
275 */
276
277.macro mcount_enter
278 stmdb sp!, {r0-r3, lr}
279.endm
280
281.macro mcount_get_lr reg
282 ldr \reg, [sp, #20]
283.endm
284
285.macro mcount_exit
286 ldmia sp!, {r0-r3, ip, lr}
287 mov pc, ip
288.endm
289
290ENTRY(__gnu_mcount_nc)
291#ifdef CONFIG_DYNAMIC_FTRACE
292 mov ip, lr
293 ldmia sp!, {lr}
294 mov pc, ip
295#else
296 __mcount
297#endif
298ENDPROC(__gnu_mcount_nc)
299
300#ifdef CONFIG_DYNAMIC_FTRACE
301ENTRY(ftrace_caller)
302 __ftrace_caller
303ENDPROC(ftrace_caller)
304#endif
305
Tim Bird376cfa82010-10-09 22:24:38 +0530306#ifdef CONFIG_FUNCTION_GRAPH_TRACER
307ENTRY(ftrace_graph_caller)
308 __ftrace_graph_caller
309ENDPROC(ftrace_graph_caller)
310#endif
311
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530312.purgem mcount_enter
313.purgem mcount_get_lr
314.purgem mcount_exit
Abhishek Sagar014c2572008-05-31 14:23:50 +0530315
Tim Bird376cfa82010-10-09 22:24:38 +0530316#ifdef CONFIG_FUNCTION_GRAPH_TRACER
317 .globl return_to_handler
318return_to_handler:
319 stmdb sp!, {r0-r3}
320 mov r0, fp @ frame pointer
321 bl ftrace_return_to_handler
322 mov lr, r0 @ r0 has real ret addr
323 ldmia sp!, {r0-r3}
324 mov pc, lr
325#endif
Abhishek Sagar014c2572008-05-31 14:23:50 +0530326
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100327ENTRY(ftrace_stub)
Rabin Vincenta3ba87a2010-08-10 19:37:21 +0100328.Lftrace_stub:
Rabin Vincent28e192d2010-08-03 17:08:09 +0100329 mov pc, lr
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100330ENDPROC(ftrace_stub)
Abhishek Sagar014c2572008-05-31 14:23:50 +0530331
Steven Rostedt606576c2008-10-06 19:06:12 -0400332#endif /* CONFIG_FUNCTION_TRACER */
Abhishek Sagar014c2572008-05-31 14:23:50 +0530333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334/*=============================================================================
335 * SWI handler
336 *-----------------------------------------------------------------------------
337 */
338
339 /* If we're optimising for StrongARM the resulting code won't
340 run on an ARM7 and we can save a couple of instructions.
341 --pb */
342#ifdef CONFIG_CPU_ARM710
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000343#define A710(code...) code
344.Larm710bug:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 ldmia sp, {r0 - lr}^ @ Get calling r0 - lr
346 mov r0, r0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 add sp, sp, #S_FRAME_SIZE
Nicolas Pitre60ac1332005-10-12 19:51:24 +0100348 subs pc, lr, #4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349#else
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000350#define A710(code...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351#endif
352
353 .align 5
354ENTRY(vector_swi)
Russell Kingf4dc9a42005-04-26 15:20:34 +0100355 sub sp, sp, #S_FRAME_SIZE
356 stmia sp, {r0 - r12} @ Calling r0 - r12
Catalin Marinasb86040a2009-07-24 12:32:54 +0100357 ARM( add r8, sp, #S_PC )
358 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
359 THUMB( mov r8, sp )
360 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
Russell Kingf4dc9a42005-04-26 15:20:34 +0100361 mrs r8, spsr @ called from non-FIQ mode, so ok.
362 str lr, [sp, #S_PC] @ Save calling PC
363 str r8, [sp, #S_PSR] @ Save CPSR
364 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 zero_fp
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100366
367 /*
368 * Get the system call number.
369 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000370
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000371#if defined(CONFIG_OABI_COMPAT)
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000372
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000373 /*
374 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
375 * value to determine if it is an EABI or an old ABI call.
376 */
377#ifdef CONFIG_ARM_THUMB
378 tst r8, #PSR_T_BIT
379 movne r10, #0 @ no thumb OABI emulation
380 ldreq r10, [lr, #-4] @ get SWI instruction
381#else
382 ldr r10, [lr, #-4] @ get SWI instruction
383 A710( and ip, r10, #0x0f000000 @ check for SWI )
384 A710( teq ip, #0x0f000000 )
385 A710( bne .Larm710bug )
386#endif
Catalin Marinas26584852009-05-30 14:00:18 +0100387#ifdef CONFIG_CPU_ENDIAN_BE8
388 rev r10, r10 @ little endian instruction
389#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000390
391#elif defined(CONFIG_AEABI)
392
393 /*
394 * Pure EABI user space always put syscall number into scno (r7).
395 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000396 A710( ldr ip, [lr, #-4] @ get SWI instruction )
397 A710( and ip, ip, #0x0f000000 @ check for SWI )
398 A710( teq ip, #0x0f000000 )
399 A710( bne .Larm710bug )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000400
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000401#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000402
403 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100404 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
405 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
406 ldreq scno, [lr, #-4]
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000407
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100408#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000409
410 /* Legacy ABI only. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100411 ldr scno, [lr, #-4] @ get SWI instruction
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000412 A710( and ip, scno, #0x0f000000 @ check for SWI )
413 A710( teq ip, #0x0f000000 )
414 A710( bne .Larm710bug )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000415
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418#ifdef CONFIG_ALIGNMENT_TRAP
419 ldr ip, __cr_alignment
420 ldr ip, [ip]
421 mcr p15, 0, ip, c1, c0 @ update control register
422#endif
Russell King1ec42c02005-04-26 15:18:26 +0100423 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 get_thread_info tsk
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000426 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000427
428#if defined(CONFIG_OABI_COMPAT)
429 /*
430 * If the swi argument is zero, this is an EABI call and we do nothing.
431 *
432 * If this is an old ABI call, get the syscall number into scno and
433 * get the old ABI syscall table address.
434 */
435 bics r10, r10, #0xff000000
436 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
437 ldrne tbl, =sys_oabi_call_table
438#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100440 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000441#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000442
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700443 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000444 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700445
446#ifdef CONFIG_SECCOMP
447 tst r10, #_TIF_SECCOMP
448 beq 1f
449 mov r0, scno
450 bl __secure_computing
451 add r0, sp, #S_R0 + S_OFF @ pointer to regs
452 ldmia r0, {r0 - r3} @ have to reload r0 - r3
4531:
454#endif
455
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500456 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 bne __sys_trace
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100460 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
462
463 add r1, sp, #S_OFF
4642: mov why, #0 @ no longer a real syscall
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100465 cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
466 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 bcs arm_syscall
468 b sys_ni_syscall @ not private func
Catalin Marinas93ed3972008-08-28 11:22:32 +0100469ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 /*
472 * This is the really slow path. We're going to be doing
473 * context switches, and waiting for our parent to respond.
474 */
475__sys_trace:
Nicolas Pitre3f471122006-01-14 19:30:04 +0000476 mov r2, scno
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 add r1, sp, #S_OFF
478 mov r0, #0 @ trace entry [IP = 0]
479 bl syscall_trace
480
Catalin Marinasb86040a2009-07-24 12:32:54 +0100481 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000482 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 add r1, sp, #S_R0 + S_OFF @ pointer to regs
484 cmp scno, #NR_syscalls @ check upper syscall limit
485 ldmccia r1, {r0 - r3} @ have to reload r0 - r3
486 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
487 b 2b
488
489__sys_trace_return:
490 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Nicolas Pitre3f471122006-01-14 19:30:04 +0000491 mov r2, scno
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 mov r1, sp
493 mov r0, #1 @ trace exit [IP = 1]
494 bl syscall_trace
495 b ret_slow_syscall
496
497 .align 5
498#ifdef CONFIG_ALIGNMENT_TRAP
499 .type __cr_alignment, #object
500__cr_alignment:
501 .word cr_alignment
502#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000503 .ltorg
504
505/*
506 * This is the syscall table declaration for native ABI syscalls.
507 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
508 */
509#define ABI(native, compat) native
510#ifdef CONFIG_AEABI
511#define OBSOLETE(syscall) sys_ni_syscall
512#else
513#define OBSOLETE(syscall) syscall
514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 .type sys_call_table, #object
517ENTRY(sys_call_table)
518#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000519#undef ABI
520#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522/*============================================================================
523 * Special system call wrappers
524 */
525@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000526@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100528 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
530 cmpne scno, #NR_syscalls @ check range
531 stmloia sp, {r5, r6} @ shuffle args
532 movlo r0, r1
533 movlo r1, r2
534 movlo r2, r3
535 movlo r3, r4
536 ldrlo pc, [tbl, scno, lsl #2]
537 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100538ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540sys_fork_wrapper:
541 add r0, sp, #S_OFF
542 b sys_fork
Catalin Marinas93ed3972008-08-28 11:22:32 +0100543ENDPROC(sys_fork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545sys_vfork_wrapper:
546 add r0, sp, #S_OFF
547 b sys_vfork
Catalin Marinas93ed3972008-08-28 11:22:32 +0100548ENDPROC(sys_vfork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550sys_execve_wrapper:
551 add r3, sp, #S_OFF
552 b sys_execve
Catalin Marinas93ed3972008-08-28 11:22:32 +0100553ENDPROC(sys_execve_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555sys_clone_wrapper:
556 add ip, sp, #S_OFF
557 str ip, [sp, #4]
558 b sys_clone
Catalin Marinas93ed3972008-08-28 11:22:32 +0100559ENDPROC(sys_clone_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561sys_sigreturn_wrapper:
562 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100563 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100565ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567sys_rt_sigreturn_wrapper:
568 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100569 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100571ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573sys_sigaltstack_wrapper:
574 ldr r2, [sp, #S_OFF + S_SP]
575 b do_sigaltstack
Catalin Marinas93ed3972008-08-28 11:22:32 +0100576ENDPROC(sys_sigaltstack_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Nicolas Pitre713c4812006-01-14 16:35:03 +0000578sys_statfs64_wrapper:
579 teq r1, #88
580 moveq r1, #84
581 b sys_statfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100582ENDPROC(sys_statfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000583
584sys_fstatfs64_wrapper:
585 teq r1, #88
586 moveq r1, #84
587 b sys_fstatfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100588ENDPROC(sys_fstatfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590/*
591 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
592 * offset, we return EINVAL.
593 */
594sys_mmap2:
595#if PAGE_SHIFT > 12
596 tst r5, #PGOFF_MASK
597 moveq r5, r5, lsr #PAGE_SHIFT - 12
598 streq r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500599 beq sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 mov r0, #-EINVAL
Russell King7999d8d2006-06-25 11:17:23 +0100601 mov pc, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#else
603 str r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500604 b sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100606ENDPROC(sys_mmap2)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000607
608#ifdef CONFIG_OABI_COMPAT
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000609
Nicolas Pitre687ad012006-01-14 16:35:31 +0000610/*
611 * These are syscalls with argument register differences
612 */
613
614sys_oabi_pread64:
615 stmia sp, {r3, r4}
616 b sys_pread64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100617ENDPROC(sys_oabi_pread64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000618
619sys_oabi_pwrite64:
620 stmia sp, {r3, r4}
621 b sys_pwrite64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100622ENDPROC(sys_oabi_pwrite64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000623
624sys_oabi_truncate64:
625 mov r3, r2
626 mov r2, r1
627 b sys_truncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100628ENDPROC(sys_oabi_truncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000629
630sys_oabi_ftruncate64:
631 mov r3, r2
632 mov r2, r1
633 b sys_ftruncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100634ENDPROC(sys_oabi_ftruncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000635
636sys_oabi_readahead:
637 str r3, [sp]
638 mov r3, r2
639 mov r2, r1
640 b sys_readahead
Catalin Marinas93ed3972008-08-28 11:22:32 +0100641ENDPROC(sys_oabi_readahead)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000642
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000643/*
644 * Let's declare a second syscall table for old ABI binaries
645 * using the compatibility syscall entries.
646 */
647#define ABI(native, compat) compat
648#define OBSOLETE(syscall) syscall
649
650 .type sys_oabi_call_table, #object
651ENTRY(sys_oabi_call_table)
652#include "calls.S"
653#undef ABI
654#undef OBSOLETE
655
Nicolas Pitre687ad012006-01-14 16:35:31 +0000656#endif
657