blob: 4bc816a74a2ee9e9e478165846f4b79680bb395c [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)
Russell Kingf4dc9a42005-04-26 15:20:34 +0100353 sub sp, sp, #S_FRAME_SIZE
354 stmia sp, {r0 - r12} @ Calling r0 - r12
Catalin Marinasb86040a2009-07-24 12:32:54 +0100355 ARM( add r8, sp, #S_PC )
356 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
357 THUMB( mov r8, sp )
358 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
Russell Kingf4dc9a42005-04-26 15:20:34 +0100359 mrs r8, spsr @ called from non-FIQ mode, so ok.
360 str lr, [sp, #S_PC] @ Save calling PC
361 str r8, [sp, #S_PSR] @ Save CPSR
362 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 zero_fp
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100364
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100365#ifdef CONFIG_ALIGNMENT_TRAP
366 ldr ip, __cr_alignment
367 ldr ip, [ip]
368 mcr p15, 0, ip, c1, c0 @ update control register
369#endif
370
371 enable_irq
372 ct_user_exit
373 get_thread_info tsk
374
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100375 /*
376 * Get the system call number.
377 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000378
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000379#if defined(CONFIG_OABI_COMPAT)
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000380
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000381 /*
382 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
383 * value to determine if it is an EABI or an old ABI call.
384 */
385#ifdef CONFIG_ARM_THUMB
386 tst r8, #PSR_T_BIT
387 movne r10, #0 @ no thumb OABI emulation
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100388 USER( ldreq r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000389#else
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100390 USER( ldr r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000391#endif
Catalin Marinas26584852009-05-30 14:00:18 +0100392#ifdef CONFIG_CPU_ENDIAN_BE8
393 rev r10, r10 @ little endian instruction
394#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000395
396#elif defined(CONFIG_AEABI)
397
398 /*
399 * Pure EABI user space always put syscall number into scno (r7).
400 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000401#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000402 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100403 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
404 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100405 USER( ldreq scno, [lr, #-4] )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000406
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100407#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000408 /* Legacy ABI only. */
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100409 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100410#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000412 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000413
414#if defined(CONFIG_OABI_COMPAT)
415 /*
416 * If the swi argument is zero, this is an EABI call and we do nothing.
417 *
418 * If this is an old ABI call, get the syscall number into scno and
419 * get the old ABI syscall table address.
420 */
421 bics r10, r10, #0xff000000
422 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
423 ldrne tbl, =sys_oabi_call_table
424#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100426 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000427#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000428
Al Viro81783782012-07-19 17:48:21 +0100429local_restart:
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700430 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000431 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700432
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500433 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 bne __sys_trace
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100437 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
439
440 add r1, sp, #S_OFF
4412: mov why, #0 @ no longer a real syscall
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100442 cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
443 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 bcs arm_syscall
445 b sys_ni_syscall @ not private func
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100446
447#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
448 /*
449 * We failed to handle a fault trying to access the page
450 * containing the swi instruction, but we're not really in a
451 * position to return -EFAULT. Instead, return back to the
452 * instruction and re-enter the user fault handling path trying
453 * to page it in. This will likely result in sending SEGV to the
454 * current task.
455 */
4569001:
457 sub lr, lr, #4
458 str lr, [sp, #S_PC]
459 b ret_fast_syscall
460#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100461ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 /*
464 * This is the really slow path. We're going to be doing
465 * context switches, and waiting for our parent to respond.
466 */
467__sys_trace:
Will Deaconad722542012-07-06 15:50:14 +0100468 mov r1, scno
469 add r0, sp, #S_OFF
470 bl syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Catalin Marinasb86040a2009-07-24 12:32:54 +0100472 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000473 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 add r1, sp, #S_R0 + S_OFF @ pointer to regs
475 cmp scno, #NR_syscalls @ check upper syscall limit
Will Deaconc7aa00d2012-07-19 17:49:22 +0100476 ldmccia r1, {r0 - r6} @ have to reload r0 - r6
477 stmccia sp, {r4, r5} @ and update the stack args
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
Kees Cookad75b512012-11-15 22:12:17 +0100479 cmp scno, #-1 @ skip the syscall?
480 bne 2b
481 add sp, sp, #S_OFF @ restore stack
482 b ret_slow_syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484__sys_trace_return:
485 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Will Deaconad722542012-07-06 15:50:14 +0100486 mov r0, sp
487 bl syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 b ret_slow_syscall
489
490 .align 5
491#ifdef CONFIG_ALIGNMENT_TRAP
492 .type __cr_alignment, #object
493__cr_alignment:
494 .word cr_alignment
495#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000496 .ltorg
497
498/*
499 * This is the syscall table declaration for native ABI syscalls.
500 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
501 */
502#define ABI(native, compat) native
503#ifdef CONFIG_AEABI
504#define OBSOLETE(syscall) sys_ni_syscall
505#else
506#define OBSOLETE(syscall) syscall
507#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 .type sys_call_table, #object
510ENTRY(sys_call_table)
511#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000512#undef ABI
513#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515/*============================================================================
516 * Special system call wrappers
517 */
518@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000519@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100521 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
523 cmpne scno, #NR_syscalls @ check range
524 stmloia sp, {r5, r6} @ shuffle args
525 movlo r0, r1
526 movlo r1, r2
527 movlo r2, r3
528 movlo r3, r4
529 ldrlo pc, [tbl, scno, lsl #2]
530 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100531ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533sys_sigreturn_wrapper:
534 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100535 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100537ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539sys_rt_sigreturn_wrapper:
540 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100541 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100543ENDPROC(sys_rt_sigreturn_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