blob: 4e7f40c577e6e4fe9df3dd677b0d146b1ceb13c2 [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
Russell King6ebbf2c2014-06-30 16:29:12 +010011#include <asm/assembler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/unistd.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053013#include <asm/ftrace.h>
Catalin Marinasc4c57162009-02-16 11:42:09 +010014#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Rob Herring13a50452012-02-07 09:28:22 -060016#ifdef CONFIG_NEED_RET_TO_USER
17#include <mach/entry-macro.S>
18#else
19 .macro arch_ret_to_user, tmp1, tmp2
20 .endm
21#endif
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "entry-header.S"
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26 .align 5
27/*
28 * This is the fast syscall return path. We do as little as
29 * possible here, and this includes saving r0 back into the SVC
30 * stack.
31 */
32ret_fast_syscall:
Catalin Marinasc4c57162009-02-16 11:42:09 +010033 UNWIND(.fnstart )
34 UNWIND(.cantunwind )
Russell King1ec42c02005-04-26 15:18:26 +010035 disable_irq @ disable interrupts
Russell King1b979372015-05-15 11:02:23 +010036 ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing
37 tst r1, #_TIF_SYSCALL_WORK
38 bne __sys_trace_return
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 tst r1, #_TIF_WORK_MASK
40 bne fast_work_pending
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010041 asm_trace_hardirqs_on
Russell Kingf4dc9a42005-04-26 15:20:34 +010042
Dan Williamsf80dff92007-02-16 22:16:32 +010043 /* perform architecture specific actions before user return */
44 arch_ret_to_user r1, lr
Kevin Hilmanb0088482013-03-28 22:54:40 +010045 ct_user_enter
Dan Williamsf80dff92007-02-16 22:16:32 +010046
Catalin Marinasb86040a2009-07-24 12:32:54 +010047 restore_user_regs fast = 1, offset = S_OFF
Catalin Marinasc4c57162009-02-16 11:42:09 +010048 UNWIND(.fnend )
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/*
51 * Ok, we need to do extra processing, enter the slow path.
52 */
53fast_work_pending:
54 str r0, [sp, #S_R0+S_OFF]! @ returned r0
55work_pending:
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 mov r0, sp @ 'regs'
57 mov r2, why @ 'syscall'
Al Viro0a267fa2012-07-19 17:47:55 +010058 bl do_work_pending
Al Viro66285212012-07-19 17:48:50 +010059 cmp r0, #0
Al Viro81783782012-07-19 17:48:21 +010060 beq no_work_pending
Al Viro66285212012-07-19 17:48:50 +010061 movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
Al Viro81783782012-07-19 17:48:21 +010062 ldmia sp, {r0 - r6} @ have to reload r0 - r6
63 b local_restart @ ... and off we go
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065/*
66 * "slow" syscall return path. "why" tells us if this was a real syscall.
67 */
68ENTRY(ret_to_user)
69ret_slow_syscall:
Russell King1ec42c02005-04-26 15:18:26 +010070 disable_irq @ disable interrupts
Ming Lei9fc25522011-06-05 02:24:58 +010071ENTRY(ret_to_user_from_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 ldr r1, [tsk, #TI_FLAGS]
73 tst r1, #_TIF_WORK_MASK
74 bne work_pending
75no_work_pending:
Todd Android Poynord13e5ed2010-12-23 01:52:44 +010076 asm_trace_hardirqs_on
Russell King651e9492013-03-28 11:44:25 +000077
Dan Williamsf80dff92007-02-16 22:16:32 +010078 /* perform architecture specific actions before user return */
79 arch_ret_to_user r1, lr
Kevin Hilmanb0088482013-03-28 22:54:40 +010080 ct_user_enter save = 0
Dan Williamsf80dff92007-02-16 22:16:32 +010081
Catalin Marinasb86040a2009-07-24 12:32:54 +010082 restore_user_regs fast = 0, offset = 0
Ming Lei9fc25522011-06-05 02:24:58 +010083ENDPROC(ret_to_user_from_irq)
Catalin Marinas93ed3972008-08-28 11:22:32 +010084ENDPROC(ret_to_user)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86/*
87 * This is how we return from a fork.
88 */
89ENTRY(ret_from_fork)
90 bl schedule_tail
Al Viro9fff2fa2012-10-10 22:23:29 -040091 cmp r5, #0
92 movne r0, r4
Russell King68687c82012-10-15 00:16:49 +010093 adrne lr, BSYM(1f)
Russell King6ebbf2c2014-06-30 16:29:12 +010094 retne r5
Russell King68687c82012-10-15 00:16:49 +0100951: get_thread_info tsk
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 b ret_slow_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +010097ENDPROC(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Al Virofa1b4f92006-01-19 12:57:01 +000099 .equ NR_syscalls,0
100#define CALL(x) .equ NR_syscalls,NR_syscalls+1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#include "calls.S"
Wade Farnsworth1f66e062012-09-07 18:18:25 +0100102
103/*
104 * Ensure that the system call table is equal to __NR_syscalls,
105 * which is the value the rest of the system sees
106 */
107.ifne NR_syscalls - __NR_syscalls
108.error "__NR_syscalls is not equal to the size of the syscall table"
109.endif
110
Al Virofa1b4f92006-01-19 12:57:01 +0000111#undef CALL
112#define CALL(x) .long x
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114/*=============================================================================
115 * SWI handler
116 *-----------------------------------------------------------------------------
117 */
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .align 5
120ENTRY(vector_swi)
Uwe Kleine-König19c4d592010-05-21 18:06:42 +0100121#ifdef CONFIG_CPU_V7M
122 v7m_exception_entry
123#else
Russell Kingf4dc9a42005-04-26 15:20:34 +0100124 sub sp, sp, #S_FRAME_SIZE
125 stmia sp, {r0 - r12} @ Calling r0 - r12
Catalin Marinasb86040a2009-07-24 12:32:54 +0100126 ARM( add r8, sp, #S_PC )
127 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
128 THUMB( mov r8, sp )
129 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
Russell Kingf4dc9a42005-04-26 15:20:34 +0100130 mrs r8, spsr @ called from non-FIQ mode, so ok.
131 str lr, [sp, #S_PC] @ Save calling PC
132 str r8, [sp, #S_PSR] @ Save CPSR
133 str r0, [sp, #S_OLD_R0] @ Save OLD_R0
Uwe Kleine-König19c4d592010-05-21 18:06:42 +0100134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 zero_fp
Russell King195b58a2014-08-28 13:08:14 +0100136 alignment_trap r10, ip, __cr_alignment
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100137 enable_irq
138 ct_user_exit
139 get_thread_info tsk
140
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100141 /*
142 * Get the system call number.
143 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000144
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000145#if defined(CONFIG_OABI_COMPAT)
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000146
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000147 /*
148 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
149 * value to determine if it is an EABI or an old ABI call.
150 */
151#ifdef CONFIG_ARM_THUMB
152 tst r8, #PSR_T_BIT
153 movne r10, #0 @ no thumb OABI emulation
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100154 USER( ldreq r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000155#else
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100156 USER( ldr r10, [lr, #-4] ) @ get SWI instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000157#endif
Ben Dooks457c2402013-02-12 18:59:57 +0000158 ARM_BE8(rev r10, r10) @ little endian instruction
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000159
160#elif defined(CONFIG_AEABI)
161
162 /*
163 * Pure EABI user space always put syscall number into scno (r7).
164 */
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000165#elif defined(CONFIG_ARM_THUMB)
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000166 /* Legacy ABI only, possibly thumb mode. */
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100167 tst r8, #PSR_T_BIT @ this is SPSR from save_user_regs
168 addne scno, r7, #__NR_SYSCALL_BASE @ put OS number in
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100169 USER( ldreq scno, [lr, #-4] )
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000170
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100171#else
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000172 /* Legacy ABI only. */
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100173 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100174#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000176 adr tbl, sys_call_table @ load syscall table pointer
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000177
178#if defined(CONFIG_OABI_COMPAT)
179 /*
180 * If the swi argument is zero, this is an EABI call and we do nothing.
181 *
182 * If this is an old ABI call, get the syscall number into scno and
183 * get the old ABI syscall table address.
184 */
185 bics r10, r10, #0xff000000
186 eorne scno, r10, #__NR_OABI_SYSCALL_BASE
187 ldrne tbl, =sys_oabi_call_table
188#elif !defined(CONFIG_AEABI)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 bic scno, scno, #0xff000000 @ mask off SWI op-code
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100190 eor scno, scno, #__NR_SYSCALL_BASE @ check OS number
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000191#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000192
Al Viro81783782012-07-19 17:48:21 +0100193local_restart:
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700194 ldr r10, [tsk, #TI_FLAGS] @ check for syscall tracing
Nicolas Pitre3f2829a2006-01-14 16:31:29 +0000195 stmdb sp!, {r4, r5} @ push fifth and sixth args
Nicolas Pitre70c70d92010-08-26 15:08:35 -0700196
Nathaniel Husted29ef73b2012-01-03 14:23:09 -0500197 tst r10, #_TIF_SYSCALL_WORK @ are we tracing syscalls?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 bne __sys_trace
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 cmp scno, #NR_syscalls @ check upper syscall limit
Catalin Marinasb86040a2009-07-24 12:32:54 +0100201 adr lr, BSYM(ret_fast_syscall) @ return address
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
203
204 add r1, sp, #S_OFF
Will Deacond95bc252013-09-19 10:32:20 +01002052: cmp scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
Russell Kinge0f9f4a2005-04-26 15:19:24 +0100206 eor r0, scno, #__NR_SYSCALL_BASE @ put OS number back
Will Deacon377747c2013-05-13 19:16:34 +0100207 bcs arm_syscall
Will Deacond95bc252013-09-19 10:32:20 +0100208 mov why, #0 @ no longer a real syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 b sys_ni_syscall @ not private func
Will Deacon1aa2b3b2013-06-05 11:25:13 +0100210
211#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
212 /*
213 * We failed to handle a fault trying to access the page
214 * containing the swi instruction, but we're not really in a
215 * position to return -EFAULT. Instead, return back to the
216 * instruction and re-enter the user fault handling path trying
217 * to page it in. This will likely result in sending SEGV to the
218 * current task.
219 */
2209001:
221 sub lr, lr, #4
222 str lr, [sp, #S_PC]
223 b ret_fast_syscall
224#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100225ENDPROC(vector_swi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /*
228 * This is the really slow path. We're going to be doing
229 * context switches, and waiting for our parent to respond.
230 */
231__sys_trace:
Will Deaconad722542012-07-06 15:50:14 +0100232 mov r1, scno
233 add r0, sp, #S_OFF
234 bl syscall_trace_enter
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Catalin Marinasb86040a2009-07-24 12:32:54 +0100236 adr lr, BSYM(__sys_trace_return) @ return address
Nicolas Pitre3f471122006-01-14 19:30:04 +0000237 mov scno, r0 @ syscall number (possibly new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 add r1, sp, #S_R0 + S_OFF @ pointer to regs
239 cmp scno, #NR_syscalls @ check upper syscall limit
Will Deaconc7aa00d2012-07-19 17:49:22 +0100240 ldmccia r1, {r0 - r6} @ have to reload r0 - r6
241 stmccia sp, {r4, r5} @ and update the stack args
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 ldrcc pc, [tbl, scno, lsl #2] @ call sys_* routine
Kees Cookad75b512012-11-15 22:12:17 +0100243 cmp scno, #-1 @ skip the syscall?
244 bne 2b
245 add sp, sp, #S_OFF @ restore stack
246 b ret_slow_syscall
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248__sys_trace_return:
249 str r0, [sp, #S_R0 + S_OFF]! @ save returned r0
Will Deaconad722542012-07-06 15:50:14 +0100250 mov r0, sp
251 bl syscall_trace_exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 b ret_slow_syscall
253
254 .align 5
255#ifdef CONFIG_ALIGNMENT_TRAP
256 .type __cr_alignment, #object
257__cr_alignment:
258 .word cr_alignment
259#endif
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000260 .ltorg
261
262/*
263 * This is the syscall table declaration for native ABI syscalls.
264 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
265 */
266#define ABI(native, compat) native
267#ifdef CONFIG_AEABI
268#define OBSOLETE(syscall) sys_ni_syscall
269#else
270#define OBSOLETE(syscall) syscall
271#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 .type sys_call_table, #object
274ENTRY(sys_call_table)
275#include "calls.S"
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000276#undef ABI
277#undef OBSOLETE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
279/*============================================================================
280 * Special system call wrappers
281 */
282@ r0 = syscall number
Russell King567bd982005-12-17 15:25:42 +0000283@ r8 = syscall table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284sys_syscall:
Paul Brook52475932006-05-16 14:25:55 +0100285 bic scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 cmp scno, #__NR_syscall - __NR_SYSCALL_BASE
287 cmpne scno, #NR_syscalls @ check range
288 stmloia sp, {r5, r6} @ shuffle args
289 movlo r0, r1
290 movlo r1, r2
291 movlo r2, r3
292 movlo r3, r4
293 ldrlo pc, [tbl, scno, lsl #2]
294 b sys_ni_syscall
Catalin Marinas93ed3972008-08-28 11:22:32 +0100295ENDPROC(sys_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297sys_sigreturn_wrapper:
298 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100299 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 b sys_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100301ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303sys_rt_sigreturn_wrapper:
304 add r0, sp, #S_OFF
Al Viro653d48b2010-09-17 14:34:39 +0100305 mov why, #0 @ prevent syscall restart handling
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 b sys_rt_sigreturn
Catalin Marinas93ed3972008-08-28 11:22:32 +0100307ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Nicolas Pitre713c4812006-01-14 16:35:03 +0000309sys_statfs64_wrapper:
310 teq r1, #88
311 moveq r1, #84
312 b sys_statfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100313ENDPROC(sys_statfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000314
315sys_fstatfs64_wrapper:
316 teq r1, #88
317 moveq r1, #84
318 b sys_fstatfs64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100319ENDPROC(sys_fstatfs64_wrapper)
Nicolas Pitre713c4812006-01-14 16:35:03 +0000320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*
322 * Note: off_4k (r5) is always units of 4K. If we can't do the requested
323 * offset, we return EINVAL.
324 */
325sys_mmap2:
326#if PAGE_SHIFT > 12
327 tst r5, #PGOFF_MASK
328 moveq r5, r5, lsr #PAGE_SHIFT - 12
329 streq r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500330 beq sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 mov r0, #-EINVAL
Russell King6ebbf2c2014-06-30 16:29:12 +0100332 ret lr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333#else
334 str r5, [sp, #4]
Al Virof8b72562009-11-30 17:37:04 -0500335 b sys_mmap_pgoff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336#endif
Catalin Marinas93ed3972008-08-28 11:22:32 +0100337ENDPROC(sys_mmap2)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000338
339#ifdef CONFIG_OABI_COMPAT
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000340
Nicolas Pitre687ad012006-01-14 16:35:31 +0000341/*
342 * These are syscalls with argument register differences
343 */
344
345sys_oabi_pread64:
346 stmia sp, {r3, r4}
347 b sys_pread64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100348ENDPROC(sys_oabi_pread64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000349
350sys_oabi_pwrite64:
351 stmia sp, {r3, r4}
352 b sys_pwrite64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100353ENDPROC(sys_oabi_pwrite64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000354
355sys_oabi_truncate64:
356 mov r3, r2
357 mov r2, r1
358 b sys_truncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100359ENDPROC(sys_oabi_truncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000360
361sys_oabi_ftruncate64:
362 mov r3, r2
363 mov r2, r1
364 b sys_ftruncate64
Catalin Marinas93ed3972008-08-28 11:22:32 +0100365ENDPROC(sys_oabi_ftruncate64)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000366
367sys_oabi_readahead:
368 str r3, [sp]
369 mov r3, r2
370 mov r2, r1
371 b sys_readahead
Catalin Marinas93ed3972008-08-28 11:22:32 +0100372ENDPROC(sys_oabi_readahead)
Nicolas Pitre687ad012006-01-14 16:35:31 +0000373
Nicolas Pitredd35afc2006-01-14 16:36:12 +0000374/*
375 * Let's declare a second syscall table for old ABI binaries
376 * using the compatibility syscall entries.
377 */
378#define ABI(native, compat) compat
379#define OBSOLETE(syscall) syscall
380
381 .type sys_oabi_call_table, #object
382ENTRY(sys_oabi_call_table)
383#include "calls.S"
384#undef ABI
385#undef OBSOLETE
386
Nicolas Pitre687ad012006-01-14 16:35:31 +0000387#endif
388