entry-common.S 11.1 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
#include <asm/memory.h>
16
17
18
19
20
#ifdef CONFIG_AEABI
#include <asm/unistd-oabi.h>
#endif

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

22
23
24
25
26
27
28
#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
29
30
#include "entry-header.S"

31
saved_psr	.req	r8
Russell King's avatar
Russell King committed
32
33
34
35
#if defined(CONFIG_TRACE_IRQFLAGS) || defined(CONFIG_CONTEXT_TRACKING)
saved_pc	.req	r9
#define TRACE(x...) x
#else
36
saved_pc	.req	lr
Russell King's avatar
Russell King committed
37
38
#define TRACE(x...)
#endif
Linus Torvalds's avatar
Linus Torvalds committed
39
40

	.align	5
Russell King's avatar
Russell King committed
41
#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING))
Linus Torvalds's avatar
Linus Torvalds committed
42
/*
Russell King's avatar
Russell King committed
43
44
45
46
 * 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
47
48
 */
ret_fast_syscall:
49
50
 UNWIND(.fnstart	)
 UNWIND(.cantunwind	)
Russell King's avatar
Russell King committed
51
	disable_irq_notrace			@ disable interrupts
52
53
54
	ldr	r2, [tsk, #TI_ADDR_LIMIT]
	cmp	r2, #TASK_SIZE
	blne	addr_limit_check_failed
55
	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
56
	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
Linus Torvalds's avatar
Linus Torvalds committed
57
	bne	fast_work_pending
58

59

60
61
62
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr

63
	restore_user_regs fast = 1, offset = S_OFF
64
 UNWIND(.fnend		)
Russell King's avatar
Russell King committed
65
ENDPROC(ret_fast_syscall)
Linus Torvalds's avatar
Linus Torvalds committed
66

Russell King's avatar
Russell King committed
67
	/* Ok, we need to do extra processing, enter the slow path. */
Linus Torvalds's avatar
Linus Torvalds committed
68
69
fast_work_pending:
	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
Russell King's avatar
Russell King committed
70
71
72
73
74
75
76
77
78
79
80
81
	/* 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
82
83
84
	ldr	r2, [tsk, #TI_ADDR_LIMIT]
	cmp	r2, #TASK_SIZE
	blne	addr_limit_check_failed
Russell King's avatar
Russell King committed
85
	ldr	r1, [tsk, #TI_FLAGS]		@ re-check for syscall tracing
86
	tst	r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK
Russell King's avatar
Russell King committed
87
88
89
90
91
92
93
94
95
96
	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
97
98
	mov	r0, sp				@ 'regs'
	mov	r2, why				@ 'syscall'
99
	bl	do_work_pending
100
	cmp	r0, #0
101
	beq	no_work_pending
102
	movlt	scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
103
104
	ldmia	sp, {r0 - r6}			@ have to reload r0 - r6
	b	local_restart			@ ... and off we go
105
ENDPROC(ret_fast_syscall)
106

Linus Torvalds's avatar
Linus Torvalds committed
107
108
/*
 * "slow" syscall return path.  "why" tells us if this was a real syscall.
Russell King's avatar
Russell King committed
109
110
111
 * 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
112
113
114
 */
ENTRY(ret_to_user)
ret_slow_syscall:
Russell King's avatar
Russell King committed
115
	disable_irq_notrace			@ disable interrupts
116
ENTRY(ret_to_user_from_irq)
117
118
119
	ldr	r2, [tsk, #TI_ADDR_LIMIT]
	cmp	r2, #TASK_SIZE
	blne	addr_limit_check_failed
Linus Torvalds's avatar
Linus Torvalds committed
120
121
	ldr	r1, [tsk, #TI_FLAGS]
	tst	r1, #_TIF_WORK_MASK
Russell King's avatar
Russell King committed
122
	bne	slow_work_pending
Linus Torvalds's avatar
Linus Torvalds committed
123
no_work_pending:
Russell King's avatar
Russell King committed
124
	asm_trace_hardirqs_on save = 0
125

126
127
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr
128
	ct_user_enter save = 0
129

130
	restore_user_regs fast = 0, offset = 0
131
ENDPROC(ret_to_user_from_irq)
132
ENDPROC(ret_to_user)
Linus Torvalds's avatar
Linus Torvalds committed
133
134
135
136
137
138

/*
 * This is how we return from a fork.
 */
ENTRY(ret_from_fork)
	bl	schedule_tail
139
140
	cmp	r5, #0
	movne	r0, r4
141
	badrne	lr, 1f
142
	retne	r5
143
1:	get_thread_info tsk
Linus Torvalds's avatar
Linus Torvalds committed
144
	b	ret_slow_syscall
145
ENDPROC(ret_from_fork)
Linus Torvalds's avatar
Linus Torvalds committed
146
147
148
149
150
151
152
153

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

	.align	5
ENTRY(vector_swi)
154
155
156
#ifdef CONFIG_CPU_V7M
	v7m_exception_entry
#else
157
	sub	sp, sp, #PT_REGS_SIZE
158
	stmia	sp, {r0 - r12}			@ Calling r0 - r12
159
160
161
162
 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
163
	mrs	saved_psr, spsr			@ called from non-FIQ mode, so ok.
Russell King's avatar
Russell King committed
164
 TRACE(	mov	saved_pc, lr		)
165
166
	str	saved_pc, [sp, #S_PC]		@ Save calling PC
	str	saved_psr, [sp, #S_PSR]		@ Save CPSR
167
	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
168
#endif
Linus Torvalds's avatar
Linus Torvalds committed
169
	zero_fp
170
	alignment_trap r10, ip, __cr_alignment
171
172
173
	asm_trace_hardirqs_on save=0
	enable_irq_notrace
	ct_user_exit save=0
174

175
176
177
	/*
	 * Get the system call number.
	 */
178

179
#if defined(CONFIG_OABI_COMPAT)
180

181
182
183
184
185
	/*
	 * 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
186
	tst	saved_psr, #PSR_T_BIT
187
	movne	r10, #0				@ no thumb OABI emulation
188
 USER(	ldreq	r10, [saved_pc, #-4]	)	@ get SWI instruction
189
#else
190
 USER(	ldr	r10, [saved_pc, #-4]	)	@ get SWI instruction
191
#endif
192
 ARM_BE8(rev	r10, r10)			@ little endian instruction
193
194
195
196
197
198

#elif defined(CONFIG_AEABI)

	/*
	 * Pure EABI user space always put syscall number into scno (r7).
	 */
199
#elif defined(CONFIG_ARM_THUMB)
200
	/* Legacy ABI only, possibly thumb mode. */
201
	tst	saved_psr, #PSR_T_BIT		@ this is SPSR from save_user_regs
202
	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
203
 USER(	ldreq	scno, [saved_pc, #-4]	)
204

205
#else
206
	/* Legacy ABI only. */
207
 USER(	ldr	scno, [saved_pc, #-4]	)	@ get SWI instruction
208
#endif
Linus Torvalds's avatar
Linus Torvalds committed
209

210
211
	/* saved_psr and saved_pc are now dead */

212
213
	uaccess_disable tbl

214
215
216
217
218
219
220
221
222
223
224
225
226
	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
227
	bic	scno, scno, #0xff000000		@ mask off SWI op-code
228
	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
229
#endif
230
	get_thread_info tsk
231
232
233
234
235
	/*
	 * Reload the registers that may have been corrupted on entry to
	 * the syscall assembly (by tracing or context tracking.)
	 */
 TRACE(	ldmia	sp, {r0 - r3}		)
236

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

241
	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
Linus Torvalds's avatar
Linus Torvalds committed
242
243
244
	bne	__sys_trace

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

	add	r1, sp, #S_OFF
249
2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
250
	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
251
	bcs	arm_syscall
252
	mov	why, #0				@ no longer a real syscall
Linus Torvalds's avatar
Linus Torvalds committed
253
	b	sys_ni_syscall			@ not private func
254
255
256
257
258
259
260
261
262
263
264

#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:
265
	sub	lr, saved_pc, #4
266
	str	lr, [sp, #S_PC]
267
	get_thread_info tsk
268
269
	b	ret_fast_syscall
#endif
270
ENDPROC(vector_swi)
Linus Torvalds's avatar
Linus Torvalds committed
271
272
273
274
275
276

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

281
	badr	lr, __sys_trace_return		@ return address
282
	mov	scno, r0			@ syscall number (possibly new)
Linus Torvalds's avatar
Linus Torvalds committed
283
284
	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
	cmp	scno, #NR_syscalls		@ check upper syscall limit
285
286
	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
287
	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
288
289
290
291
	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
292
293
294

__sys_trace_return:
	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
295
296
	mov	r0, sp
	bl	syscall_trace_exit
Linus Torvalds's avatar
Linus Torvalds committed
297
298
	b	ret_slow_syscall

Russell King's avatar
Russell King committed
299
__sys_trace_return_nosave:
300
	enable_irq_notrace
Russell King's avatar
Russell King committed
301
302
303
304
	mov	r0, sp
	bl	syscall_trace_exit
	b	ret_slow_syscall

Linus Torvalds's avatar
Linus Torvalds committed
305
306
307
308
309
	.align	5
#ifdef CONFIG_ALIGNMENT_TRAP
	.type	__cr_alignment, #object
__cr_alignment:
	.word	cr_alignment
310
311
312
#endif
	.ltorg

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
	.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

342
343
344
345
/*
 * This is the syscall table declaration for native ABI syscalls.
 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
 */
346
347
	syscall_table_start sys_call_table
#define COMPAT(nr, native, compat) syscall nr, native
348
#ifdef CONFIG_AEABI
349
#include <calls-eabi.S>
350
#else
351
#include <calls-oabi.S>
Linus Torvalds's avatar
Linus Torvalds committed
352
#endif
353
354
#undef COMPAT
	syscall_table_end sys_call_table
Linus Torvalds's avatar
Linus Torvalds committed
355
356
357
358
359

/*============================================================================
 * Special system call wrappers
 */
@ r0 = syscall number
360
@ r8 = syscall table
Linus Torvalds's avatar
Linus Torvalds committed
361
sys_syscall:
362
		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
Linus Torvalds's avatar
Linus Torvalds committed
363
364
365
366
367
368
369
370
371
		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
372
ENDPROC(sys_syscall)
Linus Torvalds's avatar
Linus Torvalds committed
373
374
375

sys_sigreturn_wrapper:
		add	r0, sp, #S_OFF
Al Viro's avatar
Al Viro committed
376
		mov	why, #0		@ prevent syscall restart handling
Linus Torvalds's avatar
Linus Torvalds committed
377
		b	sys_sigreturn
378
ENDPROC(sys_sigreturn_wrapper)
Linus Torvalds's avatar
Linus Torvalds committed
379
380
381

sys_rt_sigreturn_wrapper:
		add	r0, sp, #S_OFF
Al Viro's avatar
Al Viro committed
382
		mov	why, #0		@ prevent syscall restart handling
Linus Torvalds's avatar
Linus Torvalds committed
383
		b	sys_rt_sigreturn
384
ENDPROC(sys_rt_sigreturn_wrapper)
Linus Torvalds's avatar
Linus Torvalds committed
385

386
387
388
389
sys_statfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_statfs64
390
ENDPROC(sys_statfs64_wrapper)
391
392
393
394
395

sys_fstatfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_fstatfs64
396
ENDPROC(sys_fstatfs64_wrapper)
397

Linus Torvalds's avatar
Linus Torvalds committed
398
399
400
401
402
403
/*
 * Note: off_4k (r5) is always units of 4K.  If we can't do the requested
 * offset, we return EINVAL.
 */
sys_mmap2:
		str	r5, [sp, #4]
Al Viro's avatar
Al Viro committed
404
		b	sys_mmap_pgoff
405
ENDPROC(sys_mmap2)
406
407

#ifdef CONFIG_OABI_COMPAT
408

409
410
411
412
413
414
415
/*
 * These are syscalls with argument register differences
 */

sys_oabi_pread64:
		stmia	sp, {r3, r4}
		b	sys_pread64
416
ENDPROC(sys_oabi_pread64)
417
418
419
420

sys_oabi_pwrite64:
		stmia	sp, {r3, r4}
		b	sys_pwrite64
421
ENDPROC(sys_oabi_pwrite64)
422
423
424
425
426

sys_oabi_truncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_truncate64
427
ENDPROC(sys_oabi_truncate64)
428
429
430
431
432

sys_oabi_ftruncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_ftruncate64
433
ENDPROC(sys_oabi_ftruncate64)
434
435
436
437
438
439

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

442
443
444
445
/*
 * Let's declare a second syscall table for old ABI binaries
 * using the compatibility syscall entries.
 */
446
447
448
449
	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
450

451
452
#endif