entry-common.S 10.7 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
2
3
4
5
6
7
8
9
10
/*
 *  linux/arch/arm/kernel/entry-common.S
 *
 *  Copyright (C) 2000 Russell King
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

11
#include <asm/assembler.h>
Linus Torvalds's avatar
Linus Torvalds committed
12
#include <asm/unistd.h>
13
#include <asm/ftrace.h>
14
#include <asm/unwind.h>
15
16
17
18
19
#ifdef CONFIG_AEABI
#include <asm/unistd-oabi.h>
#endif

	.equ	NR_syscalls, __NR_syscalls
Linus Torvalds's avatar
Linus Torvalds committed
20

21
22
23
24
25
26
27
#ifdef CONFIG_NEED_RET_TO_USER
#include <mach/entry-macro.S>
#else
	.macro  arch_ret_to_user, tmp1, tmp2
	.endm
#endif

Linus Torvalds's avatar
Linus Torvalds committed
28
29
#include "entry-header.S"

30
31
saved_psr	.req	r8
saved_pc	.req	lr
Linus Torvalds's avatar
Linus Torvalds committed
32
33

	.align	5
Russell King's avatar
Russell King committed
34
#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING))
Linus Torvalds's avatar
Linus Torvalds committed
35
/*
Russell King's avatar
Russell King committed
36
37
38
39
 * This is the fast syscall return path.  We do as little as possible here,
 * such as avoiding writing r0 to the stack.  We only use this path if we
 * have tracing and context tracking disabled - the overheads from those
 * features make this path too inefficient.
Linus Torvalds's avatar
Linus Torvalds committed
40
41
 */
ret_fast_syscall:
42
43
 UNWIND(.fnstart	)
 UNWIND(.cantunwind	)
Russell King's avatar
Russell King committed
44
	disable_irq_notrace			@ disable interrupts
45
	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
Russell King's avatar
Russell King committed
46
	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
Linus Torvalds's avatar
Linus Torvalds committed
47
	bne	fast_work_pending
48

49
50
51
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr

52
	restore_user_regs fast = 1, offset = S_OFF
53
 UNWIND(.fnend		)
Russell King's avatar
Russell King committed
54
ENDPROC(ret_fast_syscall)
Linus Torvalds's avatar
Linus Torvalds committed
55

Russell King's avatar
Russell King committed
56
	/* Ok, we need to do extra processing, enter the slow path. */
Linus Torvalds's avatar
Linus Torvalds committed
57
58
fast_work_pending:
	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
Russell King's avatar
Russell King committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
	/* fall through to work_pending */
#else
/*
 * The "replacement" ret_fast_syscall for when tracing or context tracking
 * is enabled.  As we will need to call out to some C functions, we save
 * r0 first to avoid needing to save registers around each C function call.
 */
ret_fast_syscall:
 UNWIND(.fnstart	)
 UNWIND(.cantunwind	)
	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
	disable_irq_notrace			@ disable interrupts
	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
	beq	no_work_pending
 UNWIND(.fnend		)
ENDPROC(ret_fast_syscall)

	/* Slower path - fall through to work_pending */
#endif

	tst	r1, #_TIF_SYSCALL_WORK
	bne	__sys_trace_return_nosave
slow_work_pending:
Linus Torvalds's avatar
Linus Torvalds committed
83
84
	mov	r0, sp				@ 'regs'
	mov	r2, why				@ 'syscall'
85
	bl	do_work_pending
86
	cmp	r0, #0
87
	beq	no_work_pending
88
	movlt	scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
89
90
	ldmia	sp, {r0 - r6}			@ have to reload r0 - r6
	b	local_restart			@ ... and off we go
91
ENDPROC(ret_fast_syscall)
92

Linus Torvalds's avatar
Linus Torvalds committed
93
94
/*
 * "slow" syscall return path.  "why" tells us if this was a real syscall.
Russell King's avatar
Russell King committed
95
96
97
 * IRQs may be enabled here, so always disable them.  Note that we use the
 * "notrace" version to avoid calling into the tracing code unnecessarily.
 * do_work_pending() will update this state if necessary.
Linus Torvalds's avatar
Linus Torvalds committed
98
99
100
 */
ENTRY(ret_to_user)
ret_slow_syscall:
Russell King's avatar
Russell King committed
101
	disable_irq_notrace			@ disable interrupts
102
ENTRY(ret_to_user_from_irq)
Linus Torvalds's avatar
Linus Torvalds committed
103
104
	ldr	r1, [tsk, #TI_FLAGS]
	tst	r1, #_TIF_WORK_MASK
Russell King's avatar
Russell King committed
105
	bne	slow_work_pending
Linus Torvalds's avatar
Linus Torvalds committed
106
no_work_pending:
Russell King's avatar
Russell King committed
107
	asm_trace_hardirqs_on save = 0
108

109
110
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr
111
	ct_user_enter save = 0
112

113
	restore_user_regs fast = 0, offset = 0
114
ENDPROC(ret_to_user_from_irq)
115
ENDPROC(ret_to_user)
Linus Torvalds's avatar
Linus Torvalds committed
116
117
118
119
120
121

/*
 * This is how we return from a fork.
 */
ENTRY(ret_from_fork)
	bl	schedule_tail
122
123
	cmp	r5, #0
	movne	r0, r4
124
	badrne	lr, 1f
125
	retne	r5
126
1:	get_thread_info tsk
Linus Torvalds's avatar
Linus Torvalds committed
127
	b	ret_slow_syscall
128
ENDPROC(ret_from_fork)
Linus Torvalds's avatar
Linus Torvalds committed
129
130
131
132
133
134
135
136

/*=============================================================================
 * SWI handler
 *-----------------------------------------------------------------------------
 */

	.align	5
ENTRY(vector_swi)
137
138
139
#ifdef CONFIG_CPU_V7M
	v7m_exception_entry
#else
140
	sub	sp, sp, #PT_REGS_SIZE
141
	stmia	sp, {r0 - r12}			@ Calling r0 - r12
142
143
144
145
 ARM(	add	r8, sp, #S_PC		)
 ARM(	stmdb	r8, {sp, lr}^		)	@ Calling sp, lr
 THUMB(	mov	r8, sp			)
 THUMB(	store_user_sp_lr r8, r10, S_SP	)	@ calling sp, lr
146
147
148
	mrs	saved_psr, spsr			@ called from non-FIQ mode, so ok.
	str	saved_pc, [sp, #S_PC]		@ Save calling PC
	str	saved_psr, [sp, #S_PSR]		@ Save CPSR
149
	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
150
#endif
Linus Torvalds's avatar
Linus Torvalds committed
151
	zero_fp
152
	alignment_trap r10, ip, __cr_alignment
153
154
155
	enable_irq
	ct_user_exit

156
157
158
	/*
	 * Get the system call number.
	 */
159

160
#if defined(CONFIG_OABI_COMPAT)
161

162
163
164
165
166
	/*
	 * If we have CONFIG_OABI_COMPAT then we need to look at the swi
	 * value to determine if it is an EABI or an old ABI call.
	 */
#ifdef CONFIG_ARM_THUMB
167
	tst	saved_psr, #PSR_T_BIT
168
	movne	r10, #0				@ no thumb OABI emulation
169
 USER(	ldreq	r10, [saved_pc, #-4]	)	@ get SWI instruction
170
#else
171
 USER(	ldr	r10, [saved_pc, #-4]	)	@ get SWI instruction
172
#endif
173
 ARM_BE8(rev	r10, r10)			@ little endian instruction
174
175
176
177
178
179

#elif defined(CONFIG_AEABI)

	/*
	 * Pure EABI user space always put syscall number into scno (r7).
	 */
180
#elif defined(CONFIG_ARM_THUMB)
181
	/* Legacy ABI only, possibly thumb mode. */
182
	tst	saved_psr, #PSR_T_BIT		@ this is SPSR from save_user_regs
183
	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
184
 USER(	ldreq	scno, [saved_pc, #-4]	)
185

186
#else
187
	/* Legacy ABI only. */
188
 USER(	ldr	scno, [saved_pc, #-4]	)	@ get SWI instruction
189
#endif
Linus Torvalds's avatar
Linus Torvalds committed
190

191
192
	/* saved_psr and saved_pc are now dead */

193
194
	uaccess_disable tbl

195
196
197
198
199
200
201
202
203
204
205
206
207
	adr	tbl, sys_call_table		@ load syscall table pointer

#if defined(CONFIG_OABI_COMPAT)
	/*
	 * If the swi argument is zero, this is an EABI call and we do nothing.
	 *
	 * If this is an old ABI call, get the syscall number into scno and
	 * get the old ABI syscall table address.
	 */
	bics	r10, r10, #0xff000000
	eorne	scno, r10, #__NR_OABI_SYSCALL_BASE
	ldrne	tbl, =sys_oabi_call_table
#elif !defined(CONFIG_AEABI)
Linus Torvalds's avatar
Linus Torvalds committed
208
	bic	scno, scno, #0xff000000		@ mask off SWI op-code
209
	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
210
#endif
211
	get_thread_info tsk
212

213
local_restart:
Nicolas Pitre's avatar
Nicolas Pitre committed
214
	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
215
	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
Nicolas Pitre's avatar
Nicolas Pitre committed
216

217
	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
Linus Torvalds's avatar
Linus Torvalds committed
218
219
220
	bne	__sys_trace

	cmp	scno, #NR_syscalls		@ check upper syscall limit
221
	badr	lr, ret_fast_syscall		@ return address
Linus Torvalds's avatar
Linus Torvalds committed
222
223
224
	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine

	add	r1, sp, #S_OFF
225
2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
226
	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
227
	bcs	arm_syscall
228
	mov	why, #0				@ no longer a real syscall
Linus Torvalds's avatar
Linus Torvalds committed
229
	b	sys_ni_syscall			@ not private func
230
231
232
233
234
235
236
237
238
239
240

#if defined(CONFIG_OABI_COMPAT) || !defined(CONFIG_AEABI)
	/*
	 * We failed to handle a fault trying to access the page
	 * containing the swi instruction, but we're not really in a
	 * position to return -EFAULT. Instead, return back to the
	 * instruction and re-enter the user fault handling path trying
	 * to page it in. This will likely result in sending SEGV to the
	 * current task.
	 */
9001:
241
	sub	lr, saved_pc, #4
242
	str	lr, [sp, #S_PC]
243
	get_thread_info tsk
244
245
	b	ret_fast_syscall
#endif
246
ENDPROC(vector_swi)
Linus Torvalds's avatar
Linus Torvalds committed
247
248
249
250
251
252

	/*
	 * This is the really slow path.  We're going to be doing
	 * context switches, and waiting for our parent to respond.
	 */
__sys_trace:
253
254
255
	mov	r1, scno
	add	r0, sp, #S_OFF
	bl	syscall_trace_enter
Linus Torvalds's avatar
Linus Torvalds committed
256

257
	badr	lr, __sys_trace_return		@ return address
258
	mov	scno, r0			@ syscall number (possibly new)
Linus Torvalds's avatar
Linus Torvalds committed
259
260
	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
	cmp	scno, #NR_syscalls		@ check upper syscall limit
261
262
	ldmccia	r1, {r0 - r6}			@ have to reload r0 - r6
	stmccia	sp, {r4, r5}			@ and update the stack args
Linus Torvalds's avatar
Linus Torvalds committed
263
	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
264
265
266
267
	cmp	scno, #-1			@ skip the syscall?
	bne	2b
	add	sp, sp, #S_OFF			@ restore stack
	b	ret_slow_syscall
Linus Torvalds's avatar
Linus Torvalds committed
268
269
270

__sys_trace_return:
	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
271
272
	mov	r0, sp
	bl	syscall_trace_exit
Linus Torvalds's avatar
Linus Torvalds committed
273
274
	b	ret_slow_syscall

Russell King's avatar
Russell King committed
275
__sys_trace_return_nosave:
276
	enable_irq_notrace
Russell King's avatar
Russell King committed
277
278
279
280
	mov	r0, sp
	bl	syscall_trace_exit
	b	ret_slow_syscall

Linus Torvalds's avatar
Linus Torvalds committed
281
282
283
284
285
	.align	5
#ifdef CONFIG_ALIGNMENT_TRAP
	.type	__cr_alignment, #object
__cr_alignment:
	.word	cr_alignment
286
287
288
#endif
	.ltorg

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
	.macro	syscall_table_start, sym
	.equ	__sys_nr, 0
	.type	\sym, #object
ENTRY(\sym)
	.endm

	.macro	syscall, nr, func
	.ifgt	__sys_nr - \nr
	.error	"Duplicated/unorded system call entry"
	.endif
	.rept	\nr - __sys_nr
	.long	sys_ni_syscall
	.endr
	.long	\func
	.equ	__sys_nr, \nr + 1
	.endm

	.macro	syscall_table_end, sym
	.ifgt	__sys_nr - __NR_syscalls
	.error	"System call table too big"
	.endif
	.rept	__NR_syscalls - __sys_nr
	.long	sys_ni_syscall
	.endr
	.size	\sym, . - \sym
	.endm

#define NATIVE(nr, func) syscall nr, func

318
319
320
321
/*
 * This is the syscall table declaration for native ABI syscalls.
 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
 */
322
323
	syscall_table_start sys_call_table
#define COMPAT(nr, native, compat) syscall nr, native
324
#ifdef CONFIG_AEABI
325
#include <calls-eabi.S>
326
#else
327
#include <calls-oabi.S>
Linus Torvalds's avatar
Linus Torvalds committed
328
#endif
329
330
#undef COMPAT
	syscall_table_end sys_call_table
Linus Torvalds's avatar
Linus Torvalds committed
331
332
333
334
335

/*============================================================================
 * Special system call wrappers
 */
@ r0 = syscall number
336
@ r8 = syscall table
Linus Torvalds's avatar
Linus Torvalds committed
337
sys_syscall:
338
		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds's avatar
Linus Torvalds committed
339
340
341
342
343
344
345
346
347
		cmp	scno, #__NR_syscall - __NR_SYSCALL_BASE
		cmpne	scno, #NR_syscalls	@ check range
		stmloia	sp, {r5, r6}		@ shuffle args
		movlo	r0, r1
		movlo	r1, r2
		movlo	r2, r3
		movlo	r3, r4
		ldrlo	pc, [tbl, scno, lsl #2]
		b	sys_ni_syscall
348
ENDPROC(sys_syscall)
Linus Torvalds's avatar
Linus Torvalds committed
349
350
351

sys_sigreturn_wrapper:
		add	r0, sp, #S_OFF
Al Viro's avatar
Al Viro committed
352
		mov	why, #0		@ prevent syscall restart handling
Linus Torvalds's avatar
Linus Torvalds committed
353
		b	sys_sigreturn
354
ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds's avatar
Linus Torvalds committed
355
356
357

sys_rt_sigreturn_wrapper:
		add	r0, sp, #S_OFF
Al Viro's avatar
Al Viro committed
358
		mov	why, #0		@ prevent syscall restart handling
Linus Torvalds's avatar
Linus Torvalds committed
359
		b	sys_rt_sigreturn
360
ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds's avatar
Linus Torvalds committed
361

362
363
364
365
sys_statfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_statfs64
366
ENDPROC(sys_statfs64_wrapper)
367
368
369
370
371

sys_fstatfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_fstatfs64
372
ENDPROC(sys_fstatfs64_wrapper)
373

Linus Torvalds's avatar
Linus Torvalds committed
374
375
376
377
378
379
380
381
382
/*
 * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
 * offset, we return EINVAL.
 */
sys_mmap2:
#if PAGE_SHIFT > 12
		tst	r5, #PGOFF_MASK
		moveq	r5, r5, lsr #PAGE_SHIFT - 12
		streq	r5, [sp, #4]
Al Viro's avatar
Al Viro committed
383
		beq	sys_mmap_pgoff
Linus Torvalds's avatar
Linus Torvalds committed
384
		mov	r0, #-EINVAL
385
		ret	lr
Linus Torvalds's avatar
Linus Torvalds committed
386
387
#else
		str	r5, [sp, #4]
Al Viro's avatar
Al Viro committed
388
		b	sys_mmap_pgoff
Linus Torvalds's avatar
Linus Torvalds committed
389
#endif
390
ENDPROC(sys_mmap2)
391
392

#ifdef CONFIG_OABI_COMPAT
393

394
395
396
397
398
399
400
/*
 * These are syscalls with argument register differences
 */

sys_oabi_pread64:
		stmia	sp, {r3, r4}
		b	sys_pread64
401
ENDPROC(sys_oabi_pread64)
402
403
404
405

sys_oabi_pwrite64:
		stmia	sp, {r3, r4}
		b	sys_pwrite64
406
ENDPROC(sys_oabi_pwrite64)
407
408
409
410
411

sys_oabi_truncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_truncate64
412
ENDPROC(sys_oabi_truncate64)
413
414
415
416
417

sys_oabi_ftruncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_ftruncate64
418
ENDPROC(sys_oabi_ftruncate64)
419
420
421
422
423
424

sys_oabi_readahead:
		str	r3, [sp]
		mov	r3, r2
		mov	r2, r1
		b	sys_readahead
425
ENDPROC(sys_oabi_readahead)
426

427
428
429
430
/*
 * Let's declare a second syscall table for old ABI binaries
 * using the compatibility syscall entries.
 */
431
432
433
434
	syscall_table_start sys_oabi_call_table
#define COMPAT(nr, native, compat) syscall nr, compat
#include <calls-oabi.S>
	syscall_table_end sys_oabi_call_table
435

436
437
#endif