blob: 74ad15d1a065fba97aac1d4ac43ff33a9e994470 [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
Catalin Marinas26584852009-05-30 14:00:18 +0100396#ifdef CONFIG_CPU_ENDIAN_BE8
397 rev r10, r10 @ little endian instruction
398#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000399
400#elif defined(CONFIG_AEABI)
401
402 /*
403 * Pure EABI user space always put syscall number into scno (r7).
404 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000405#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000406 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100407 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
408 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100409 USER( ldreq scno, [lr, #-4] )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000410
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100411#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000412 /* Legacy ABI only. */
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100413 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000416 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000417
418#if defined(CONFIG_OABI_COMPAT)
419 /*
420 * If the swi argument is zero, this is an EABI call and we do nothing.
421 *
422 * If this is an old ABI call, get the syscall number into scno and
423 * get the old ABI syscall table address.
424 */
425 bics r10, r10, #0xff000000
426 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
427 ldrne tbl, =sys_oabi_call_table
428#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100430 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000431#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000432
Al Viro81783782012-07-19 17:48:21 +0100433local_restart:
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700434 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000435 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700436
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500437 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 bne __sys_trace
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100441 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
443
444 add r1, sp, #S_OFF
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100445 cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
446 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Will Deacon377747c2013-05-13 19:16:34 +0100447 bcs arm_syscall
4482: mov why, #0 @ no longer a real syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 b sys_ni_syscall @ not private func
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100450
451#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
452 /*
453 * We failed to handle a fault trying to access the page
454 * containing the swi instruction, but we're not really in a
455 * position to return -EFAULT. Instead, return back to the
456 * instruction and re-enter the user fault handling path trying
457 * to page it in. This will likely result in sending SEGV to the
458 * current task.
459 */
4609001:
461 sub lr, lr, #4
462 str lr, [sp, #S_PC]
463 b ret_fast_syscall
464#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100465ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467 /*
468 * This is the really slow path. We're going to be doing
469 * context switches, and waiting for our parent to respond.
470 */
471__sys_trace:
Will Deaconad722542012-07-06 15:50:14 +0100472 mov r1, scno
473 add r0, sp, #S_OFF
474 bl syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Catalin Marinasb86040a2009-07-24 12:32:54 +0100476 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000477 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 add r1, sp, #S_R0 + S_OFF @ pointer to regs
479 cmp scno, #NR_syscalls @ check upper syscall limit
Will Deaconc7aa00d2012-07-19 17:49:22 +0100480 ldmccia r1, {r0 - r6} @ have to reload r0 - r6
481 stmccia sp, {r4, r5} @ and update the stack args
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
Kees Cookad75b512012-11-15 22:12:17 +0100483 cmp scno, #-1 @ skip the syscall?
484 bne 2b
485 add sp, sp, #S_OFF @ restore stack
486 b ret_slow_syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488__sys_trace_return:
489 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Will Deaconad722542012-07-06 15:50:14 +0100490 mov r0, sp
491 bl syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 b ret_slow_syscall
493
494 .align 5
495#ifdef CONFIG_ALIGNMENT_TRAP
496 .type __cr_alignment, #object
497__cr_alignment:
498 .word cr_alignment
499#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000500 .ltorg
501
502/*
503 * This is the syscall table declaration for native ABI syscalls.
504 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
505 */
506#define ABI(native, compat) native
507#ifdef CONFIG_AEABI
508#define OBSOLETE(syscall) sys_ni_syscall
509#else
510#define OBSOLETE(syscall) syscall
511#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 .type sys_call_table, #object
514ENTRY(sys_call_table)
515#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000516#undef ABI
517#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519/*============================================================================
520 * Special system call wrappers
521 */
522@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000523@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100525 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
527 cmpne scno, #NR_syscalls @ check range
528 stmloia sp, {r5, r6} @ shuffle args
529 movlo r0, r1
530 movlo r1, r2
531 movlo r2, r3
532 movlo r3, r4
533 ldrlo pc, [tbl, scno, lsl #2]
534 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100535ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537sys_sigreturn_wrapper:
538 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100539 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100541ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543sys_rt_sigreturn_wrapper:
544 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100545 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100547ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Nicolas Pitre713c4812006-01-14 16:35:03 +0000549sys_statfs64_wrapper:
550 teq r1, #88
551 moveq r1, #84
552 b sys_statfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100553ENDPROC(sys_statfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000554
555sys_fstatfs64_wrapper:
556 teq r1, #88
557 moveq r1, #84
558 b sys_fstatfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100559ENDPROC(sys_fstatfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561/*
562 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
563 * offset, we return EINVAL.
564 */
565sys_mmap2:
566#if PAGE_SHIFT > 12
567 tst r5, #PGOFF_MASK
568 moveq r5, r5, lsr #PAGE_SHIFT - 12
569 streq r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500570 beq sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 mov r0, #-EINVAL
Russell King7999d8d2006-06-25 11:17:23 +0100572 mov pc, lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#else
574 str r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500575 b sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100577ENDPROC(sys_mmap2)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000578
579#ifdef CONFIG_OABI_COMPAT
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000580
Nicolas Pitre687ad012006-01-14 16:35:31 +0000581/*
582 * These are syscalls with argument register differences
583 */
584
585sys_oabi_pread64:
586 stmia sp, {r3, r4}
587 b sys_pread64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100588ENDPROC(sys_oabi_pread64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000589
590sys_oabi_pwrite64:
591 stmia sp, {r3, r4}
592 b sys_pwrite64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100593ENDPROC(sys_oabi_pwrite64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000594
595sys_oabi_truncate64:
596 mov r3, r2
597 mov r2, r1
598 b sys_truncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100599ENDPROC(sys_oabi_truncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000600
601sys_oabi_ftruncate64:
602 mov r3, r2
603 mov r2, r1
604 b sys_ftruncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100605ENDPROC(sys_oabi_ftruncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000606
607sys_oabi_readahead:
608 str r3, [sp]
609 mov r3, r2
610 mov r2, r1
611 b sys_readahead
Catalin Marinas93ed3972008-08-28 11:22:32 +0100612ENDPROC(sys_oabi_readahead)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000613
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000614/*
615 * Let's declare a second syscall table for old ABI binaries
616 * using the compatibility syscall entries.
617 */
618#define ABI(native, compat) compat
619#define OBSOLETE(syscall) syscall
620
621 .type sys_oabi_call_table, #object
622ENTRY(sys_oabi_call_table)
623#include "calls.S"
624#undef ABI
625#undef OBSOLETE
626
Nicolas Pitre687ad012006-01-14 16:35:31 +0000627#endif
628