blob: a2dcafdf1bc89a176f80dda748625a615717979a [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 asm_trace_hardirqs_on
Russell Kingf4dc9a42005-04-26 15:20:34 +010039
Dan Williamsf80dff92007-02-16 22:16:32 +010040 /* perform architecture specific actions before user return */
41 arch_ret_to_user r1, lr
Kevin Hilmanb0088482013-03-28 22:54:40 +010042 ct_user_enter
Dan Williamsf80dff92007-02-16 22:16:32 +010043
Catalin Marinasb86040a2009-07-24 12:32:54 +010044 restore_user_regs fast = 1, offset = S_OFF
Catalin Marinasc4c57162009-02-16 11:42:09 +010045 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47/*
48 * Ok, we need to do extra processing, enter the slow path.
49 */
50fast_work_pending:
51 str r0, [sp, #S_R0+S_OFF]! @ returned r0
52work_pending:
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 mov r0, sp @ 'regs'
54 mov r2, why @ 'syscall'
Al Viro0a267fa2012-07-19 17:47:55 +010055 bl do_work_pending
Al Viro66285212012-07-19 17:48:50 +010056 cmp r0, #0
Al Viro81783782012-07-19 17:48:21 +010057 beq no_work_pending
Al Viro66285212012-07-19 17:48:50 +010058 movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
Al Viro81783782012-07-19 17:48:21 +010059 ldmia sp, {r0 - r6} @ have to reload r0 - r6
60 b local_restart @ ... and off we go
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/*
63 * "slow" syscall return path. "why" tells us if this was a real syscall.
64 */
65ENTRY(ret_to_user)
66ret_slow_syscall:
Russell King1ec42c02005-04-26 15:18:26 +010067 disable_irq @ disable interrupts
Ming Lei9fc25522011-06-05 02:24:58 +010068ENTRY(ret_to_user_from_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 ldr r1, [tsk, #TI_FLAGS]
70 tst r1, #_TIF_WORK_MASK
71 bne work_pending
72no_work_pending:
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010073 asm_trace_hardirqs_on
Russell King651e9492013-03-28 11:44:25 +000074
Dan Williamsf80dff92007-02-16 22:16:32 +010075 /* perform architecture specific actions before user return */
76 arch_ret_to_user r1, lr
Kevin Hilmanb0088482013-03-28 22:54:40 +010077 ct_user_enter save = 0
Dan Williamsf80dff92007-02-16 22:16:32 +010078
Catalin Marinasb86040a2009-07-24 12:32:54 +010079 restore_user_regs fast = 0, offset = 0
Ming Lei9fc25522011-06-05 02:24:58 +010080ENDPROC(ret_to_user_from_irq)
Catalin Marinas93ed3972008-08-28 11:22:32 +010081ENDPROC(ret_to_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83/*
84 * This is how we return from a fork.
85 */
86ENTRY(ret_from_fork)
87 bl schedule_tail
Al Viro9fff2fa2012-10-10 22:23:29 -040088 cmp r5, #0
89 movne r0, r4
Russell King68687c82012-10-15 00:16:49 +010090 adrne lr, BSYM(1f)
Al Viro9fff2fa2012-10-10 22:23:29 -040091 movne pc, r5
Russell King68687c82012-10-15 00:16:49 +0100921: get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 b ret_slow_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +010094ENDPROC(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Al Virofa1b4f92006-01-19 12:57:01 +000096 .equ NR_syscalls,0
97#define CALL(x) .equ NR_syscalls,NR_syscalls+1
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#include "calls.S"
Wade Farnsworth1f66e062012-09-07 18:18:25 +010099
100/*
101 * Ensure that the system call table is equal to __NR_syscalls,
102 * which is the value the rest of the system sees
103 */
104.ifne NR_syscalls - __NR_syscalls
105.error "__NR_syscalls is not equal to the size of the syscall table"
106.endif
107
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
Rabin Vincentb21e0232013-04-02 22:11:46 +0100278/*
279 * This pad compensates for the push {lr} at the call site. Note that we are
280 * unable to unwind through a function which does not otherwise save its lr.
281 */
282 UNWIND(.pad #4)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530283 stmdb sp!, {r0-r3, lr}
Rabin Vincentb21e0232013-04-02 22:11:46 +0100284 UNWIND(.save {r0-r3, lr})
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530285.endm
286
287.macro mcount_get_lr reg
288 ldr \reg, [sp, #20]
289.endm
290
291.macro mcount_exit
292 ldmia sp!, {r0-r3, ip, lr}
293 mov pc, ip
294.endm
295
296ENTRY(__gnu_mcount_nc)
Rabin Vincentb21e0232013-04-02 22:11:46 +0100297UNWIND(.fnstart)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530298#ifdef CONFIG_DYNAMIC_FTRACE
299 mov ip, lr
300 ldmia sp!, {lr}
301 mov pc, ip
302#else
303 __mcount
304#endif
Rabin Vincentb21e0232013-04-02 22:11:46 +0100305UNWIND(.fnend)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530306ENDPROC(__gnu_mcount_nc)
307
308#ifdef CONFIG_DYNAMIC_FTRACE
309ENTRY(ftrace_caller)
Rabin Vincentb21e0232013-04-02 22:11:46 +0100310UNWIND(.fnstart)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530311 __ftrace_caller
Rabin Vincentb21e0232013-04-02 22:11:46 +0100312UNWIND(.fnend)
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530313ENDPROC(ftrace_caller)
314#endif
315
Tim Bird376cfa82010-10-09 22:24:38 +0530316#ifdef CONFIG_FUNCTION_GRAPH_TRACER
317ENTRY(ftrace_graph_caller)
Rabin Vincentb21e0232013-04-02 22:11:46 +0100318UNWIND(.fnstart)
Tim Bird376cfa82010-10-09 22:24:38 +0530319 __ftrace_graph_caller
Rabin Vincentb21e0232013-04-02 22:11:46 +0100320UNWIND(.fnend)
Tim Bird376cfa82010-10-09 22:24:38 +0530321ENDPROC(ftrace_graph_caller)
322#endif
323
Rabin Vincentd3b9dc92010-10-07 17:39:47 +0530324.purgem mcount_enter
325.purgem mcount_get_lr
326.purgem mcount_exit
Abhishek Sagar014c2572008-05-31 14:23:50 +0530327
Tim Bird376cfa82010-10-09 22:24:38 +0530328#ifdef CONFIG_FUNCTION_GRAPH_TRACER
329 .globl return_to_handler
330return_to_handler:
331 stmdb sp!, {r0-r3}
332 mov r0, fp @ frame pointer
333 bl ftrace_return_to_handler
334 mov lr, r0 @ r0 has real ret addr
335 ldmia sp!, {r0-r3}
336 mov pc, lr
337#endif
Abhishek Sagar014c2572008-05-31 14:23:50 +0530338
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100339ENTRY(ftrace_stub)
Rabin Vincenta3ba87a2010-08-10 19:37:21 +0100340.Lftrace_stub:
Rabin Vincent28e192d2010-08-03 17:08:09 +0100341 mov pc, lr
Rabin Vincent72fa62f2010-08-10 19:33:52 +0100342ENDPROC(ftrace_stub)
Abhishek Sagar014c2572008-05-31 14:23:50 +0530343
Steven Rostedt606576c2008-10-06 19:06:12 -0400344#endif /* CONFIG_FUNCTION_TRACER */
Abhishek Sagar014c2572008-05-31 14:23:50 +0530345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346/*=============================================================================
347 * SWI handler
348 *-----------------------------------------------------------------------------
349 */
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 .align 5
352ENTRY(vector_swi)
Uwe Kleine-König19c4d592010-05-21 18:06:42 +0100353#ifdef CONFIG_CPU_V7M
354 v7m_exception_entry
355#else
Russell Kingf4dc9a42005-04-26 15:20:34 +0100356 sub sp, sp, #S_FRAME_SIZE
357 stmia sp, {r0 - r12} @ Calling r0 - r12
Catalin Marinasb86040a2009-07-24 12:32:54 +0100358 ARM( add r8, sp, #S_PC )
359 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
360 THUMB( mov r8, sp )
361 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
Russell Kingf4dc9a42005-04-26 15:20:34 +0100362 mrs r8, spsr @ called from non-FIQ mode, so ok.
363 str lr, [sp, #S_PC] @ Save calling PC
364 str r8, [sp, #S_PSR] @ Save CPSR
365 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
Uwe Kleine-König19c4d592010-05-21 18:06:42 +0100366#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 zero_fp
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100368
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100369#ifdef CONFIG_ALIGNMENT_TRAP
370 ldr ip, __cr_alignment
371 ldr ip, [ip]
372 mcr p15, 0, ip, c1, c0 @ update control register
373#endif
374
375 enable_irq
376 ct_user_exit
377 get_thread_info tsk
378
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100379 /*
380 * Get the system call number.
381 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000382
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000383#if defined(CONFIG_OABI_COMPAT)
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000384
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000385 /*
386 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
387 * value to determine if it is an EABI or an old ABI call.
388 */
389#ifdef CONFIG_ARM_THUMB
390 tst r8, #PSR_T_BIT
391 movne r10, #0 @ no thumb OABI emulation
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100392 USER( ldreq r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000393#else
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100394 USER( ldr r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000395#endif
Ben Dooks457c2402013-02-12 18:59:57 +0000396 ARM_BE8(rev r10, r10) @ little endian instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000397
398#elif defined(CONFIG_AEABI)
399
400 /*
401 * Pure EABI user space always put syscall number into scno (r7).
402 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000403#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000404 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100405 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
406 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100407 USER( ldreq scno, [lr, #-4] )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000408
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100409#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000410 /* Legacy ABI only. */
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100411 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100412#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000414 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000415
416#if defined(CONFIG_OABI_COMPAT)
417 /*
418 * If the swi argument is zero, this is an EABI call and we do nothing.
419 *
420 * If this is an old ABI call, get the syscall number into scno and
421 * get the old ABI syscall table address.
422 */
423 bics r10, r10, #0xff000000
424 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
425 ldrne tbl, =sys_oabi_call_table
426#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100428 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000429#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000430
Al Viro81783782012-07-19 17:48:21 +0100431local_restart:
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700432 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000433 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700434
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500435 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 bne __sys_trace
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100439 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
441
442 add r1, sp, #S_OFF
Will Deacond95bc252013-09-19 10:32:20 +01004432: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100444 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Will Deacon377747c2013-05-13 19:16:34 +0100445 bcs arm_syscall
Will Deacond95bc252013-09-19 10:32:20 +0100446 mov why, #0 @ no longer a real syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 b sys_ni_syscall @ not private func
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100448
449#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
450 /*
451 * We failed to handle a fault trying to access the page
452 * containing the swi instruction, but we're not really in a
453 * position to return -EFAULT. Instead, return back to the
454 * instruction and re-enter the user fault handling path trying
455 * to page it in. This will likely result in sending SEGV to the
456 * current task.
457 */
4589001:
459 sub lr, lr, #4
460 str lr, [sp, #S_PC]
461 b ret_fast_syscall
462#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100463ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465 /*
466 * This is the really slow path. We're going to be doing
467 * context switches, and waiting for our parent to respond.
468 */
469__sys_trace:
Will Deaconad722542012-07-06 15:50:14 +0100470 mov r1, scno
471 add r0, sp, #S_OFF
472 bl syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Catalin Marinasb86040a2009-07-24 12:32:54 +0100474 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000475 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 add r1, sp, #S_R0 + S_OFF @ pointer to regs
477 cmp scno, #NR_syscalls @ check upper syscall limit
Will Deaconc7aa00d2012-07-19 17:49:22 +0100478 ldmccia r1, {r0 - r6} @ have to reload r0 - r6
479 stmccia sp, {r4, r5} @ and update the stack args
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
Kees Cookad75b512012-11-15 22:12:17 +0100481 cmp scno, #-1 @ skip the syscall?
482 bne 2b
483 add sp, sp, #S_OFF @ restore stack
484 b ret_slow_syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486__sys_trace_return:
487 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Will Deaconad722542012-07-06 15:50:14 +0100488 mov r0, sp
489 bl syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 b ret_slow_syscall
491
492 .align 5
493#ifdef CONFIG_ALIGNMENT_TRAP
494 .type __cr_alignment, #object
495__cr_alignment:
496 .word cr_alignment
497#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000498 .ltorg
499
500/*
501 * This is the syscall table declaration for native ABI syscalls.
502 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
503 */
504#define ABI(native, compat) native
505#ifdef CONFIG_AEABI
506#define OBSOLETE(syscall) sys_ni_syscall
507#else
508#define OBSOLETE(syscall) syscall
509#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 .type sys_call_table, #object
512ENTRY(sys_call_table)
513#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000514#undef ABI
515#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517/*============================================================================
518 * Special system call wrappers
519 */
520@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000521@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100523 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
525 cmpne scno, #NR_syscalls @ check range
526 stmloia sp, {r5, r6} @ shuffle args
527 movlo r0, r1
528 movlo r1, r2
529 movlo r2, r3
530 movlo r3, r4
531 ldrlo pc, [tbl, scno, lsl #2]
532 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100533ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535sys_sigreturn_wrapper:
536 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100537 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100539ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541sys_rt_sigreturn_wrapper:
542 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100543 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100545ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Nicolas Pitre713c4812006-01-14 16:35:03 +0000547sys_statfs64_wrapper:
548 teq r1, #88
549 moveq r1, #84
550 b sys_statfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100551ENDPROC(sys_statfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000552
553sys_fstatfs64_wrapper:
554 teq r1, #88
555 moveq r1, #84
556 b sys_fstatfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100557ENDPROC(sys_fstatfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559/*
560 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
561 * offset, we return EINVAL.
562 */
563sys_mmap2:
564#if PAGE_SHIFT > 12
565 tst r5, #PGOFF_MASK
566 moveq r5, r5, lsr #PAGE_SHIFT - 12
567 streq r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500568 beq sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 mov r0, #-EINVAL
Russell King7999d8d2006-06-25 11:17:23 +0100570 mov pc, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#else
572 str r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500573 b sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100575ENDPROC(sys_mmap2)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000576
577#ifdef CONFIG_OABI_COMPAT
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000578
Nicolas Pitre687ad012006-01-14 16:35:31 +0000579/*
580 * These are syscalls with argument register differences
581 */
582
583sys_oabi_pread64:
584 stmia sp, {r3, r4}
585 b sys_pread64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100586ENDPROC(sys_oabi_pread64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000587
588sys_oabi_pwrite64:
589 stmia sp, {r3, r4}
590 b sys_pwrite64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100591ENDPROC(sys_oabi_pwrite64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000592
593sys_oabi_truncate64:
594 mov r3, r2
595 mov r2, r1
596 b sys_truncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100597ENDPROC(sys_oabi_truncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000598
599sys_oabi_ftruncate64:
600 mov r3, r2
601 mov r2, r1
602 b sys_ftruncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100603ENDPROC(sys_oabi_ftruncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000604
605sys_oabi_readahead:
606 str r3, [sp]
607 mov r3, r2
608 mov r2, r1
609 b sys_readahead
Catalin Marinas93ed3972008-08-28 11:22:32 +0100610ENDPROC(sys_oabi_readahead)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000611
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000612/*
613 * Let's declare a second syscall table for old ABI binaries
614 * using the compatibility syscall entries.
615 */
616#define ABI(native, compat) compat
617#define OBSOLETE(syscall) syscall
618
619 .type sys_oabi_call_table, #object
620ENTRY(sys_oabi_call_table)
621#include "calls.S"
622#undef ABI
623#undef OBSOLETE
624
Nicolas Pitre687ad012006-01-14 16:35:31 +0000625#endif
626