entry-common.S 9.0 KB
Newer Older
L
Linus Torvalds 已提交
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>
L
Linus Torvalds 已提交
12
#include <asm/unistd.h>
13
#include <asm/ftrace.h>
14
#include <asm/unwind.h>
L
Linus Torvalds 已提交
15

16 17 18 19 20 21 22
#ifdef CONFIG_NEED_RET_TO_USER
#include <mach/entry-macro.S>
#else
	.macro  arch_ret_to_user, tmp1, tmp2
	.endm
#endif

L
Linus Torvalds 已提交
23 24 25 26 27 28 29 30 31 32
#include "entry-header.S"


	.align	5
/*
 * This is the fast syscall return path.  We do as little as
 * possible here, and this includes saving r0 back into the SVC
 * stack.
 */
ret_fast_syscall:
33 34
 UNWIND(.fnstart	)
 UNWIND(.cantunwind	)
35
	disable_irq				@ disable interrupts
L
Linus Torvalds 已提交
36 37 38
	ldr	r1, [tsk, #TI_FLAGS]
	tst	r1, #_TIF_WORK_MASK
	bne	fast_work_pending
39
	asm_trace_hardirqs_on
40

41 42
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr
43
	ct_user_enter
44

45
	restore_user_regs fast = 1, offset = S_OFF
46
 UNWIND(.fnend		)
L
Linus Torvalds 已提交
47 48 49 50 51 52 53 54 55

/*
 * Ok, we need to do extra processing, enter the slow path.
 */
fast_work_pending:
	str	r0, [sp, #S_R0+S_OFF]!		@ returned r0
work_pending:
	mov	r0, sp				@ 'regs'
	mov	r2, why				@ 'syscall'
56
	bl	do_work_pending
57
	cmp	r0, #0
58
	beq	no_work_pending
59
	movlt	scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE)
60 61 62
	ldmia	sp, {r0 - r6}			@ have to reload r0 - r6
	b	local_restart			@ ... and off we go

L
Linus Torvalds 已提交
63 64 65 66 67
/*
 * "slow" syscall return path.  "why" tells us if this was a real syscall.
 */
ENTRY(ret_to_user)
ret_slow_syscall:
68
	disable_irq				@ disable interrupts
69
ENTRY(ret_to_user_from_irq)
L
Linus Torvalds 已提交
70 71 72 73
	ldr	r1, [tsk, #TI_FLAGS]
	tst	r1, #_TIF_WORK_MASK
	bne	work_pending
no_work_pending:
74
	asm_trace_hardirqs_on
75

76 77
	/* perform architecture specific actions before user return */
	arch_ret_to_user r1, lr
78
	ct_user_enter save = 0
79

80
	restore_user_regs fast = 0, offset = 0
81
ENDPROC(ret_to_user_from_irq)
82
ENDPROC(ret_to_user)
L
Linus Torvalds 已提交
83 84 85 86 87 88

/*
 * This is how we return from a fork.
 */
ENTRY(ret_from_fork)
	bl	schedule_tail
89 90
	cmp	r5, #0
	movne	r0, r4
91
	adrne	lr, BSYM(1f)
92
	retne	r5
93
1:	get_thread_info tsk
L
Linus Torvalds 已提交
94
	b	ret_slow_syscall
95
ENDPROC(ret_from_fork)
L
Linus Torvalds 已提交
96

97 98
	.equ NR_syscalls,0
#define CALL(x) .equ NR_syscalls,NR_syscalls+1
L
Linus Torvalds 已提交
99
#include "calls.S"
100 101 102 103 104 105 106 107 108

/*
 * Ensure that the system call table is equal to __NR_syscalls,
 * which is the value the rest of the system sees
 */
.ifne NR_syscalls - __NR_syscalls
.error "__NR_syscalls is not equal to the size of the syscall table"
.endif

109 110
#undef CALL
#define CALL(x) .long x
L
Linus Torvalds 已提交
111 112 113 114 115 116 117 118

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

	.align	5
ENTRY(vector_swi)
119 120 121
#ifdef CONFIG_CPU_V7M
	v7m_exception_entry
#else
122 123
	sub	sp, sp, #S_FRAME_SIZE
	stmia	sp, {r0 - r12}			@ Calling r0 - r12
124 125 126 127
 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
128 129 130 131
	mrs	r8, spsr			@ called from non-FIQ mode, so ok.
	str	lr, [sp, #S_PC]			@ Save calling PC
	str	r8, [sp, #S_PSR]		@ Save CPSR
	str	r0, [sp, #S_OLD_R0]		@ Save OLD_R0
132
#endif
L
Linus Torvalds 已提交
133
	zero_fp
134
	alignment_trap r10, ip, __cr_alignment
135 136 137 138
	enable_irq
	ct_user_exit
	get_thread_info tsk

139 140 141
	/*
	 * Get the system call number.
	 */
142

143
#if defined(CONFIG_OABI_COMPAT)
144

145 146 147 148 149 150 151
	/*
	 * 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
	tst	r8, #PSR_T_BIT
	movne	r10, #0				@ no thumb OABI emulation
152
 USER(	ldreq	r10, [lr, #-4]		)	@ get SWI instruction
153
#else
154
 USER(	ldr	r10, [lr, #-4]		)	@ get SWI instruction
155
#endif
156
 ARM_BE8(rev	r10, r10)			@ little endian instruction
157 158 159 160 161 162

#elif defined(CONFIG_AEABI)

	/*
	 * Pure EABI user space always put syscall number into scno (r7).
	 */
163
#elif defined(CONFIG_ARM_THUMB)
164
	/* Legacy ABI only, possibly thumb mode. */
165 166
	tst	r8, #PSR_T_BIT			@ this is SPSR from save_user_regs
	addne	scno, r7, #__NR_SYSCALL_BASE	@ put OS number in
167
 USER(	ldreq	scno, [lr, #-4]		)
168

169
#else
170
	/* Legacy ABI only. */
171
 USER(	ldr	scno, [lr, #-4]		)	@ get SWI instruction
172
#endif
L
Linus Torvalds 已提交
173

174 175 176 177 178 179 180 181 182 183 184 185 186
	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)
L
Linus Torvalds 已提交
187
	bic	scno, scno, #0xff000000		@ mask off SWI op-code
188
	eor	scno, scno, #__NR_SYSCALL_BASE	@ check OS number
189
#endif
190

191
local_restart:
N
Nicolas Pitre 已提交
192
	ldr	r10, [tsk, #TI_FLAGS]		@ check for syscall tracing
193
	stmdb	sp!, {r4, r5}			@ push fifth and sixth args
N
Nicolas Pitre 已提交
194

195
	tst	r10, #_TIF_SYSCALL_WORK		@ are we tracing syscalls?
L
Linus Torvalds 已提交
196 197 198
	bne	__sys_trace

	cmp	scno, #NR_syscalls		@ check upper syscall limit
199
	adr	lr, BSYM(ret_fast_syscall)	@ return address
L
Linus Torvalds 已提交
200 201 202
	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine

	add	r1, sp, #S_OFF
203
2:	cmp	scno, #(__ARM_NR_BASE - __NR_SYSCALL_BASE)
204
	eor	r0, scno, #__NR_SYSCALL_BASE	@ put OS number back
205
	bcs	arm_syscall
206
	mov	why, #0				@ no longer a real syscall
L
Linus Torvalds 已提交
207
	b	sys_ni_syscall			@ not private func
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

#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:
	sub	lr, lr, #4
	str	lr, [sp, #S_PC]
	b	ret_fast_syscall
#endif
223
ENDPROC(vector_swi)
L
Linus Torvalds 已提交
224 225 226 227 228 229

	/*
	 * This is the really slow path.  We're going to be doing
	 * context switches, and waiting for our parent to respond.
	 */
__sys_trace:
230 231 232
	mov	r1, scno
	add	r0, sp, #S_OFF
	bl	syscall_trace_enter
L
Linus Torvalds 已提交
233

234
	adr	lr, BSYM(__sys_trace_return)	@ return address
235
	mov	scno, r0			@ syscall number (possibly new)
L
Linus Torvalds 已提交
236 237
	add	r1, sp, #S_R0 + S_OFF		@ pointer to regs
	cmp	scno, #NR_syscalls		@ check upper syscall limit
238 239
	ldmccia	r1, {r0 - r6}			@ have to reload r0 - r6
	stmccia	sp, {r4, r5}			@ and update the stack args
L
Linus Torvalds 已提交
240
	ldrcc	pc, [tbl, scno, lsl #2]		@ call sys_* routine
241 242 243 244
	cmp	scno, #-1			@ skip the syscall?
	bne	2b
	add	sp, sp, #S_OFF			@ restore stack
	b	ret_slow_syscall
L
Linus Torvalds 已提交
245 246 247

__sys_trace_return:
	str	r0, [sp, #S_R0 + S_OFF]!	@ save returned r0
248 249
	mov	r0, sp
	bl	syscall_trace_exit
L
Linus Torvalds 已提交
250 251 252 253 254 255 256
	b	ret_slow_syscall

	.align	5
#ifdef CONFIG_ALIGNMENT_TRAP
	.type	__cr_alignment, #object
__cr_alignment:
	.word	cr_alignment
257 258 259 260 261 262 263 264 265 266 267 268
#endif
	.ltorg

/*
 * This is the syscall table declaration for native ABI syscalls.
 * With EABI a couple syscalls are obsolete and defined as sys_ni_syscall.
 */
#define ABI(native, compat) native
#ifdef CONFIG_AEABI
#define OBSOLETE(syscall) sys_ni_syscall
#else
#define OBSOLETE(syscall) syscall
L
Linus Torvalds 已提交
269 270 271 272 273
#endif

	.type	sys_call_table, #object
ENTRY(sys_call_table)
#include "calls.S"
274 275
#undef ABI
#undef OBSOLETE
L
Linus Torvalds 已提交
276 277 278 279 280

/*============================================================================
 * Special system call wrappers
 */
@ r0 = syscall number
281
@ r8 = syscall table
L
Linus Torvalds 已提交
282
sys_syscall:
283
		bic	scno, r0, #__NR_OABI_SYSCALL_BASE
L
Linus Torvalds 已提交
284 285 286 287 288 289 290 291 292
		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
293
ENDPROC(sys_syscall)
L
Linus Torvalds 已提交
294 295 296

sys_sigreturn_wrapper:
		add	r0, sp, #S_OFF
A
Al Viro 已提交
297
		mov	why, #0		@ prevent syscall restart handling
L
Linus Torvalds 已提交
298
		b	sys_sigreturn
299
ENDPROC(sys_sigreturn_wrapper)
L
Linus Torvalds 已提交
300 301 302

sys_rt_sigreturn_wrapper:
		add	r0, sp, #S_OFF
A
Al Viro 已提交
303
		mov	why, #0		@ prevent syscall restart handling
L
Linus Torvalds 已提交
304
		b	sys_rt_sigreturn
305
ENDPROC(sys_rt_sigreturn_wrapper)
L
Linus Torvalds 已提交
306

307 308 309 310
sys_statfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_statfs64
311
ENDPROC(sys_statfs64_wrapper)
312 313 314 315 316

sys_fstatfs64_wrapper:
		teq	r1, #88
		moveq	r1, #84
		b	sys_fstatfs64
317
ENDPROC(sys_fstatfs64_wrapper)
318

L
Linus Torvalds 已提交
319 320 321 322 323 324 325 326 327
/*
 * 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]
A
Al Viro 已提交
328
		beq	sys_mmap_pgoff
L
Linus Torvalds 已提交
329
		mov	r0, #-EINVAL
330
		ret	lr
L
Linus Torvalds 已提交
331 332
#else
		str	r5, [sp, #4]
A
Al Viro 已提交
333
		b	sys_mmap_pgoff
L
Linus Torvalds 已提交
334
#endif
335
ENDPROC(sys_mmap2)
336 337

#ifdef CONFIG_OABI_COMPAT
338

339 340 341 342 343 344 345
/*
 * These are syscalls with argument register differences
 */

sys_oabi_pread64:
		stmia	sp, {r3, r4}
		b	sys_pread64
346
ENDPROC(sys_oabi_pread64)
347 348 349 350

sys_oabi_pwrite64:
		stmia	sp, {r3, r4}
		b	sys_pwrite64
351
ENDPROC(sys_oabi_pwrite64)
352 353 354 355 356

sys_oabi_truncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_truncate64
357
ENDPROC(sys_oabi_truncate64)
358 359 360 361 362

sys_oabi_ftruncate64:
		mov	r3, r2
		mov	r2, r1
		b	sys_ftruncate64
363
ENDPROC(sys_oabi_ftruncate64)
364 365 366 367 368 369

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

372 373 374 375 376 377 378 379 380 381 382 383 384
/*
 * Let's declare a second syscall table for old ABI binaries
 * using the compatibility syscall entries.
 */
#define ABI(native, compat) compat
#define OBSOLETE(syscall) syscall

	.type	sys_oabi_call_table, #object
ENTRY(sys_oabi_call_table)
#include "calls.S"
#undef ABI
#undef OBSOLETE

385 386
#endif