blob: 49d9f93052476b51e0136b760312b7d829cf4899 [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 */
Al Viro21c11762012-04-28 17:51:42 -040059 ldr r2, [sp, #S_PSR]
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 mov r0, sp @ 'regs'
Al Viro21c11762012-04-28 17:51:42 -040061 tst r2, #15 @ are we returning to user mode?
62 bne no_work_pending @ no? just leave, then...
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 mov r2, why @ 'syscall'
Russell Kingb2b163b2010-09-17 14:56:16 +010064 tst r1, #_TIF_SIGPENDING @ delivering a signal?
65 movne why, #0 @ prevent further restarts
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 bl do_notify_resume
Daniel Jacobowitza6c61e92005-11-19 10:01:07 +000067 b ret_slow_syscall @ Check work again
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69work_resched:
70 bl schedule
71/*
72 * "slow" syscall return path. "why" tells us if this was a real syscall.
73 */
74ENTRY(ret_to_user)
75ret_slow_syscall:
Russell King1ec42c02005-04-26 15:18:26 +010076 disable_irq @ disable interrupts
Ming Lei9fc25522011-06-05 02:24:58 +010077ENTRY(ret_to_user_from_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 ldr r1, [tsk, #TI_FLAGS]
79 tst r1, #_TIF_WORK_MASK
80 bne work_pending
81no_work_pending:
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010082#if defined(CONFIG_IRQSOFF_TRACER)
83 asm_trace_hardirqs_on
84#endif
Dan Williamsf80dff92007-02-16 22:16:32 +010085 /* perform architecture specific actions before user return */
86 arch_ret_to_user r1, lr
87
Catalin Marinasb86040a2009-07-24 12:32:54 +010088 restore_user_regs fast = 0, offset = 0
Ming Lei9fc25522011-06-05 02:24:58 +010089ENDPROC(ret_to_user_from_irq)
Catalin Marinas93ed3972008-08-28 11:22:32 +010090ENDPROC(ret_to_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92/*
93 * This is how we return from a fork.
94 */
95ENTRY(ret_from_fork)
96 bl schedule_tail
97 get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 mov why, #1
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 b ret_slow_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100100ENDPROC(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Al Virofa1b4f92006-01-19 12:57:01 +0000102 .equ NR_syscalls,0
103#define CALL(x) .equ NR_syscalls,NR_syscalls+1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#include "calls.S"
Al Virofa1b4f92006-01-19 12:57:01 +0000105#undef CALL
106#define CALL(x) .long x
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Steven Rostedt606576c2008-10-06 19:06:12 -0400108#ifdef CONFIG_FUNCTION_TRACER
Rabin Vincent686ff222010-08-03 17:09:40 +0100109/*
110 * When compiling with -pg, gcc inserts a call to the mcount routine at the
111 * start of every function. In mcount, apart from the function's address (in
112 * lr), we need to get hold of the function's caller's address.
113 *
114 * Older GCCs (pre-4.4) inserted a call to a routine called mcount like this:
115 *
116 * bl mcount
117 *
118 * These versions have the limitation that in order for the mcount routine to
119 * be able to determine the function's caller's address, an APCS-style frame
120 * pointer (which is set up with something like the code below) is required.
121 *
122 * mov ip, sp
123 * push {fp, ip, lr, pc}
124 * sub fp, ip, #4
125 *
126 * With EABI, these frame pointers are not available unless -mapcs-frame is
127 * specified, and if building as Thumb-2, not even then.
128 *
129 * Newer GCCs (4.4+) solve this problem by introducing a new version of mcount,
130 * with call sites like:
131 *
132 * push {lr}
133 * bl __gnu_mcount_nc
134 *
135 * With these compilers, frame pointers are not necessary.
136 *
137 * mcount can be thought of as a function called in the middle of a subroutine
138 * call. As such, it needs to be transparent for both the caller and the
139 * callee: the original lr needs to be restored when leaving mcount, and no
140 * registers should be clobbered. (In the __gnu_mcount_nc implementation, we
141 * clobber the ip register. This is OK because the ARM calling convention
142 * allows it to be clobbered in subroutines and doesn't use it to hold
143 * parameters.)
Rabin Vincent3b6c2232010-08-10 19:43:28 +0100144 *
145 * When using dynamic ftrace, we patch out the mcount call by a "mov r0, r0"
146 * for the mcount case, and a "pop {lr}" for the __gnu_mcount_nc case (see
147 * arch/arm/kernel/ftrace.c).
Rabin Vincent686ff222010-08-03 17:09:40 +0100148 */
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100149
150#ifndef CONFIG_OLD_MCOUNT
151#if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
152#error Ftrace requires CONFIG_FRAME_POINTER=y with GCC older than 4.4.0.
153#endif
154#endif
155
Rabin Vincentd68133b2012-01-24 16:52:52 +0100156.macro mcount_adjust_addr rd, rn
157 bic \rd, \rn, #1 @ clear the Thumb bit if present
158 sub \rd, \rd, #MCOUNT_INSN_SIZE
159.endm
160
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530161.macro __mcount suffix
162 mcount_enter
Rabin Vincent28e192d2010-08-03 17:08:09 +0100163 ldr r0, =ftrace_trace_function
164 ldr r2, [r0]
Rabin Vincenta3ba87a2010-08-10 19:37:21 +0100165 adr r0, .Lftrace_stub
Rabin Vincent28e192d2010-08-03 17:08:09 +0100166 cmp r0, r2
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530167 bne 1f
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200168
Tim Bird376cfa82010-10-09 22:24:38 +0530169#ifdef CONFIG_FUNCTION_GRAPH_TRACER
170 ldr r1, =ftrace_graph_return
171 ldr r2, [r1]
172 cmp r0, r2
173 bne ftrace_graph_caller\suffix
174
175 ldr r1, =ftrace_graph_entry
176 ldr r2, [r1]
177 ldr r0, =ftrace_graph_entry_stub
178 cmp r0, r2
179 bne ftrace_graph_caller\suffix
180#endif
181
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530182 mcount_exit
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200183
Rabin Vincentd3b9dc92010-10-07 17:39:47 +05301841: mcount_get_lr r1 @ lr of instrumented func
Rabin Vincentd68133b2012-01-24 16:52:52 +0100185 mcount_adjust_addr r0, lr @ instrumented function
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530186 adr lr, BSYM(2f)
Rabin Vincent28e192d2010-08-03 17:08:09 +0100187 mov pc, r2
Rabin Vincentd3b9dc92010-10-07 17:39:47 +05301882: mcount_exit
189.endm
190
191.macro __ftrace_caller suffix
192 mcount_enter
193
194 mcount_get_lr r1 @ lr of instrumented func
Rabin Vincentd68133b2012-01-24 16:52:52 +0100195 mcount_adjust_addr r0, lr @ instrumented function
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530196
197 .globl ftrace_call\suffix
198ftrace_call\suffix:
199 bl ftrace_stub
200
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530201#ifdef CONFIG_FUNCTION_GRAPH_TRACER
202 .globl ftrace_graph_call\suffix
203ftrace_graph_call\suffix:
204 mov r0, r0
205#endif
206
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530207 mcount_exit
208.endm
Uwe Kleine-König181f8172009-08-13 20:38:16 +0200209
Tim Bird376cfa82010-10-09 22:24:38 +0530210.macro __ftrace_graph_caller
211 sub r0, fp, #4 @ &lr of instrumented routine (&parent)
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530212#ifdef CONFIG_DYNAMIC_FTRACE
213 @ called from __ftrace_caller, saved in mcount_enter
214 ldr r1, [sp, #16] @ instrumented routine (func)
Rabin Vincentd68133b2012-01-24 16:52:52 +0100215 mcount_adjust_addr r1, r1
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530216#else
217 @ called from __mcount, untouched in lr
Rabin Vincentd68133b2012-01-24 16:52:52 +0100218 mcount_adjust_addr r1, lr @ instrumented routine (func)
Rabin Vincentdd686eb2010-11-06 23:03:21 +0530219#endif
Tim Bird376cfa82010-10-09 22:24:38 +0530220 mov r2, fp @ frame pointer
221 bl prepare_ftrace_return
222 mcount_exit
223.endm
Abhishek Sagar014c2572008-05-31 14:23:50 +0530224
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100225#ifdef CONFIG_OLD_MCOUNT
226/*
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530227 * mcount
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100228 */
Abhishek Sagar014c2572008-05-31 14:23:50 +0530229
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530230.macro mcount_enter
231 stmdb sp!, {r0-r3, lr}
232.endm
233
234.macro mcount_get_lr reg
235 ldr \reg, [fp, #-4]
236.endm
237
238.macro mcount_exit
239 ldr lr, [fp, #-4]
Rabin Vincent28e192d2010-08-03 17:08:09 +0100240 ldmia sp!, {r0-r3, pc}
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530241.endm
242
243ENTRY(mcount)
244#ifdef CONFIG_DYNAMIC_FTRACE
245 stmdb sp!, {lr}
246 ldr lr, [fp, #-4]
247 ldmia sp!, {pc}
248#else
249 __mcount _old
250#endif
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100251ENDPROC(mcount)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530252
253#ifdef CONFIG_DYNAMIC_FTRACE
254ENTRY(ftrace_caller_old)
255 __ftrace_caller _old
256ENDPROC(ftrace_caller_old)
Rabin Vincent09bfafa2010-08-10 19:32:37 +0100257#endif
Abhishek Sagar014c2572008-05-31 14:23:50 +0530258
Tim Bird376cfa82010-10-09 22:24:38 +0530259#ifdef CONFIG_FUNCTION_GRAPH_TRACER
260ENTRY(ftrace_graph_caller_old)
261 __ftrace_graph_caller
262ENDPROC(ftrace_graph_caller_old)
263#endif
264
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530265.purgem mcount_enter
266.purgem mcount_get_lr
267.purgem mcount_exit
268#endif
269
270/*
271 * __gnu_mcount_nc
272 */
273
274.macro mcount_enter
275 stmdb sp!, {r0-r3, lr}
276.endm
277
278.macro mcount_get_lr reg
279 ldr \reg, [sp, #20]
280.endm
281
282.macro mcount_exit
283 ldmia sp!, {r0-r3, ip, lr}
284 mov pc, ip
285.endm
286
287ENTRY(__gnu_mcount_nc)
288#ifdef CONFIG_DYNAMIC_FTRACE
289 mov ip, lr
290 ldmia sp!, {lr}
291 mov pc, ip
292#else
293 __mcount
294#endif
295ENDPROC(__gnu_mcount_nc)
296
297#ifdef CONFIG_DYNAMIC_FTRACE
298ENTRY(ftrace_caller)
299 __ftrace_caller
300ENDPROC(ftrace_caller)
301#endif
302
Tim Bird376cfa82010-10-09 22:24:38 +0530303#ifdef CONFIG_FUNCTION_GRAPH_TRACER
304ENTRY(ftrace_graph_caller)
305 __ftrace_graph_caller
306ENDPROC(ftrace_graph_caller)
307#endif
308
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530309.purgem mcount_enter
310.purgem mcount_get_lr
311.purgem mcount_exit
Abhishek Sagar014c2572008-05-31 14:23:50 +0530312
Tim Bird376cfa82010-10-09 22:24:38 +0530313#ifdef CONFIG_FUNCTION_GRAPH_TRACER
314 .globl return_to_handler
315return_to_handler:
316 stmdb sp!, {r0-r3}
317 mov r0, fp @ frame pointer
318 bl ftrace_return_to_handler
319 mov lr, r0 @ r0 has real ret addr
320 ldmia sp!, {r0-r3}
321 mov pc, lr
322#endif
Abhishek Sagar014c2572008-05-31 14:23:50 +0530323
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100324ENTRY(ftrace_stub)
Rabin Vincenta3ba87a2010-08-10 19:37:21 +0100325.Lftrace_stub:
Rabin Vincent28e192d2010-08-03 17:08:09 +0100326 mov pc, lr
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100327ENDPROC(ftrace_stub)
Abhishek Sagar014c2572008-05-31 14:23:50 +0530328
Steven Rostedt606576c2008-10-06 19:06:12 -0400329#endif /* CONFIG_FUNCTION_TRACER */
Abhishek Sagar014c2572008-05-31 14:23:50 +0530330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331/*=============================================================================
332 * SWI handler
333 *-----------------------------------------------------------------------------
334 */
335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 .align 5
337ENTRY(vector_swi)
Russell Kingf4dc9a42005-04-26 15:20:34 +0100338 sub sp, sp, #S_FRAME_SIZE
339 stmia sp, {r0 - r12} @ Calling r0 - r12
Catalin Marinasb86040a2009-07-24 12:32:54 +0100340 ARM( add r8, sp, #S_PC )
341 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
342 THUMB( mov r8, sp )
343 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
Russell Kingf4dc9a42005-04-26 15:20:34 +0100344 mrs r8, spsr @ called from non-FIQ mode, so ok.
345 str lr, [sp, #S_PC] @ Save calling PC
346 str r8, [sp, #S_PSR] @ Save CPSR
347 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 zero_fp
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100349
350 /*
351 * Get the system call number.
352 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000353
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000354#if defined(CONFIG_OABI_COMPAT)
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000355
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000356 /*
357 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
358 * value to determine if it is an EABI or an old ABI call.
359 */
360#ifdef CONFIG_ARM_THUMB
361 tst r8, #PSR_T_BIT
362 movne r10, #0 @ no thumb OABI emulation
363 ldreq r10, [lr, #-4] @ get SWI instruction
364#else
365 ldr r10, [lr, #-4] @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000366#endif
Catalin Marinas26584852009-05-30 14:00:18 +0100367#ifdef CONFIG_CPU_ENDIAN_BE8
368 rev r10, r10 @ little endian instruction
369#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000370
371#elif defined(CONFIG_AEABI)
372
373 /*
374 * Pure EABI user space always put syscall number into scno (r7).
375 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000376#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000377 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100378 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
379 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
380 ldreq scno, [lr, #-4]
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000381
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100382#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000383 /* Legacy ABI only. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100384 ldr scno, [lr, #-4] @ get SWI instruction
385#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387#ifdef CONFIG_ALIGNMENT_TRAP
388 ldr ip, __cr_alignment
389 ldr ip, [ip]
390 mcr p15, 0, ip, c1, c0 @ update control register
391#endif
Russell King1ec42c02005-04-26 15:18:26 +0100392 enable_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 get_thread_info tsk
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000395 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000396
397#if defined(CONFIG_OABI_COMPAT)
398 /*
399 * If the swi argument is zero, this is an EABI call and we do nothing.
400 *
401 * If this is an old ABI call, get the syscall number into scno and
402 * get the old ABI syscall table address.
403 */
404 bics r10, r10, #0xff000000
405 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
406 ldrne tbl, =sys_oabi_call_table
407#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100409 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000410#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000411
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700412 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000413 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700414
415#ifdef CONFIG_SECCOMP
416 tst r10, #_TIF_SECCOMP
417 beq 1f
418 mov r0, scno
419 bl __secure_computing
420 add r0, sp, #S_R0 + S_OFF @ pointer to regs
421 ldmia r0, {r0 - r3} @ have to reload r0 - r3
4221:
423#endif
424
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500425 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 bne __sys_trace
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100429 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
431
432 add r1, sp, #S_OFF
4332: mov why, #0 @ no longer a real syscall
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100434 cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
435 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 bcs arm_syscall
437 b sys_ni_syscall @ not private func
Catalin Marinas93ed3972008-08-28 11:22:32 +0100438ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 /*
441 * This is the really slow path. We're going to be doing
442 * context switches, and waiting for our parent to respond.
443 */
444__sys_trace:
Will Deaconad722542012-07-06 15:50:14 +0100445 mov r1, scno
446 add r0, sp, #S_OFF
447 bl syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Catalin Marinasb86040a2009-07-24 12:32:54 +0100449 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000450 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 add r1, sp, #S_R0 + S_OFF @ pointer to regs
452 cmp scno, #NR_syscalls @ check upper syscall limit
453 ldmccia r1, {r0 - r3} @ have to reload r0 - r3
454 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
455 b 2b
456
457__sys_trace_return:
458 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Will Deaconad722542012-07-06 15:50:14 +0100459 mov r1, scno
460 mov r0, sp
461 bl syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 b ret_slow_syscall
463
464 .align 5
465#ifdef CONFIG_ALIGNMENT_TRAP
466 .type __cr_alignment, #object
467__cr_alignment:
468 .word cr_alignment
469#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000470 .ltorg
471
472/*
473 * This is the syscall table declaration for native ABI syscalls.
474 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
475 */
476#define ABI(native, compat) native
477#ifdef CONFIG_AEABI
478#define OBSOLETE(syscall) sys_ni_syscall
479#else
480#define OBSOLETE(syscall) syscall
481#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 .type sys_call_table, #object
484ENTRY(sys_call_table)
485#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000486#undef ABI
487#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489/*============================================================================
490 * Special system call wrappers
491 */
492@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000493@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100495 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
497 cmpne scno, #NR_syscalls @ check range
498 stmloia sp, {r5, r6} @ shuffle args
499 movlo r0, r1
500 movlo r1, r2
501 movlo r2, r3
502 movlo r3, r4
503 ldrlo pc, [tbl, scno, lsl #2]
504 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100505ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507sys_fork_wrapper:
508 add r0, sp, #S_OFF
509 b sys_fork
Catalin Marinas93ed3972008-08-28 11:22:32 +0100510ENDPROC(sys_fork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512sys_vfork_wrapper:
513 add r0, sp, #S_OFF
514 b sys_vfork
Catalin Marinas93ed3972008-08-28 11:22:32 +0100515ENDPROC(sys_vfork_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517sys_execve_wrapper:
518 add r3, sp, #S_OFF
519 b sys_execve
Catalin Marinas93ed3972008-08-28 11:22:32 +0100520ENDPROC(sys_execve_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522sys_clone_wrapper:
523 add ip, sp, #S_OFF
524 str ip, [sp, #4]
525 b sys_clone
Catalin Marinas93ed3972008-08-28 11:22:32 +0100526ENDPROC(sys_clone_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528sys_sigreturn_wrapper:
529 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100530 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100532ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534sys_rt_sigreturn_wrapper:
535 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100536 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100538ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540sys_sigaltstack_wrapper:
541 ldr r2, [sp, #S_OFF + S_SP]
542 b do_sigaltstack
Catalin Marinas93ed3972008-08-28 11:22:32 +0100543ENDPROC(sys_sigaltstack_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Nicolas Pitre713c4812006-01-14 16:35:03 +0000545sys_statfs64_wrapper:
546 teq r1, #88
547 moveq r1, #84
548 b sys_statfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100549ENDPROC(sys_statfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000550
551sys_fstatfs64_wrapper:
552 teq r1, #88
553 moveq r1, #84
554 b sys_fstatfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100555ENDPROC(sys_fstatfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557/*
558 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
559 * offset, we return EINVAL.
560 */
561sys_mmap2:
562#if PAGE_SHIFT > 12
563 tst r5, #PGOFF_MASK
564 moveq r5, r5, lsr #PAGE_SHIFT - 12
565 streq r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500566 beq sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 mov r0, #-EINVAL
Russell King7999d8d2006-06-25 11:17:23 +0100568 mov pc, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#else
570 str r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500571 b sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100573ENDPROC(sys_mmap2)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000574
575#ifdef CONFIG_OABI_COMPAT
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000576
Nicolas Pitre687ad012006-01-14 16:35:31 +0000577/*
578 * These are syscalls with argument register differences
579 */
580
581sys_oabi_pread64:
582 stmia sp, {r3, r4}
583 b sys_pread64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100584ENDPROC(sys_oabi_pread64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000585
586sys_oabi_pwrite64:
587 stmia sp, {r3, r4}
588 b sys_pwrite64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100589ENDPROC(sys_oabi_pwrite64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000590
591sys_oabi_truncate64:
592 mov r3, r2
593 mov r2, r1
594 b sys_truncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100595ENDPROC(sys_oabi_truncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000596
597sys_oabi_ftruncate64:
598 mov r3, r2
599 mov r2, r1
600 b sys_ftruncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100601ENDPROC(sys_oabi_ftruncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000602
603sys_oabi_readahead:
604 str r3, [sp]
605 mov r3, r2
606 mov r2, r1
607 b sys_readahead
Catalin Marinas93ed3972008-08-28 11:22:32 +0100608ENDPROC(sys_oabi_readahead)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000609
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000610/*
611 * Let's declare a second syscall table for old ABI binaries
612 * using the compatibility syscall entries.
613 */
614#define ABI(native, compat) compat
615#define OBSOLETE(syscall) syscall
616
617 .type sys_oabi_call_table, #object
618ENTRY(sys_oabi_call_table)
619#include "calls.S"
620#undef ABI
621#undef OBSOLETE
622
Nicolas Pitre687ad012006-01-14 16:35:31 +0000623#endif
624