xref: /openbmc/linux/arch/arm/kernel/entry-armv.S (revision c0e7f7ee717e2b4c5791e7422424c96b5008c39e)
11da177e4SLinus Torvalds/*
21da177e4SLinus Torvalds *  linux/arch/arm/kernel/entry-armv.S
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds *  Copyright (C) 1996,1997,1998 Russell King.
51da177e4SLinus Torvalds *  ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
6afeb90caSHyok S. Choi *  nommu support by Hyok S. Choi (hyok.choi@samsung.com)
71da177e4SLinus Torvalds *
81da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify
91da177e4SLinus Torvalds * it under the terms of the GNU General Public License version 2 as
101da177e4SLinus Torvalds * published by the Free Software Foundation.
111da177e4SLinus Torvalds *
121da177e4SLinus Torvalds *  Low-level vector interface routines
131da177e4SLinus Torvalds *
1470b6f2b4SNicolas Pitre *  Note:  there is a StrongARM bug in the STMIA rn, {regs}^ instruction
1570b6f2b4SNicolas Pitre *  that causes it to save wrong values...  Be aware!
161da177e4SLinus Torvalds */
171da177e4SLinus Torvalds
186f6f6a70SRob Herring#include <asm/assembler.h>
19f09b9979SNicolas Pitre#include <asm/memory.h>
20753790e7SRussell King#include <asm/glue-df.h>
21753790e7SRussell King#include <asm/glue-pf.h>
221da177e4SLinus Torvalds#include <asm/vfpmacros.h>
23243c8654SRob Herring#ifndef CONFIG_MULTI_IRQ_HANDLER
24a09e64fbSRussell King#include <mach/entry-macro.S>
25243c8654SRob Herring#endif
26d6551e88SRussell King#include <asm/thread_notify.h>
27c4c5716eSCatalin Marinas#include <asm/unwind.h>
28cc20d429SRussell King#include <asm/unistd.h>
29f159f4edSTony Lindgren#include <asm/tls.h>
309f97da78SDavid Howells#include <asm/system_info.h>
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds#include "entry-header.S"
33cd544ce7SMagnus Damm#include <asm/entry-macro-multi.S>
341da177e4SLinus Torvalds
351da177e4SLinus Torvalds/*
36d9600c99SRussell King * Interrupt handling.
37187a51adSRussell King */
38187a51adSRussell King	.macro	irq_handler
3952108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER
40d9600c99SRussell King	ldr	r1, =handle_arch_irq
4152108641Seric miao	mov	r0, sp
4252108641Seric miao	adr	lr, BSYM(9997f)
43abeb24aeSMarc Zyngier	ldr	pc, [r1]
44abeb24aeSMarc Zyngier#else
45cd544ce7SMagnus Damm	arch_irq_handler_default
46abeb24aeSMarc Zyngier#endif
47f00ec48fSRussell King9997:
48187a51adSRussell King	.endm
49187a51adSRussell King
50ac8b9c1cSRussell King	.macro	pabt_helper
518dfe7ac9SRussell King	@ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
52ac8b9c1cSRussell King#ifdef MULTI_PABORT
530402beceSRussell King	ldr	ip, .LCprocfns
54ac8b9c1cSRussell King	mov	lr, pc
550402beceSRussell King	ldr	pc, [ip, #PROCESSOR_PABT_FUNC]
56ac8b9c1cSRussell King#else
57ac8b9c1cSRussell King	bl	CPU_PABORT_HANDLER
58ac8b9c1cSRussell King#endif
59ac8b9c1cSRussell King	.endm
60ac8b9c1cSRussell King
61ac8b9c1cSRussell King	.macro	dabt_helper
62ac8b9c1cSRussell King
63ac8b9c1cSRussell King	@
64ac8b9c1cSRussell King	@ Call the processor-specific abort handler:
65ac8b9c1cSRussell King	@
66da740472SRussell King	@  r2 - pt_regs
673e287becSRussell King	@  r4 - aborted context pc
683e287becSRussell King	@  r5 - aborted context psr
69ac8b9c1cSRussell King	@
70ac8b9c1cSRussell King	@ The abort handler must return the aborted address in r0, and
71ac8b9c1cSRussell King	@ the fault status register in r1.  r9 must be preserved.
72ac8b9c1cSRussell King	@
73ac8b9c1cSRussell King#ifdef MULTI_DABORT
740402beceSRussell King	ldr	ip, .LCprocfns
75ac8b9c1cSRussell King	mov	lr, pc
760402beceSRussell King	ldr	pc, [ip, #PROCESSOR_DABT_FUNC]
77ac8b9c1cSRussell King#else
78ac8b9c1cSRussell King	bl	CPU_DABORT_HANDLER
79ac8b9c1cSRussell King#endif
80ac8b9c1cSRussell King	.endm
81ac8b9c1cSRussell King
82785d3cd2SNicolas Pitre#ifdef CONFIG_KPROBES
83785d3cd2SNicolas Pitre	.section	.kprobes.text,"ax",%progbits
84785d3cd2SNicolas Pitre#else
85785d3cd2SNicolas Pitre	.text
86785d3cd2SNicolas Pitre#endif
87785d3cd2SNicolas Pitre
88187a51adSRussell King/*
891da177e4SLinus Torvalds * Invalid mode handlers
901da177e4SLinus Torvalds */
91ccea7a19SRussell King	.macro	inv_entry, reason
92ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
93b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - lr}		)
94b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}		)
95b86040a5SCatalin Marinas THUMB(	str	sp, [sp, #S_SP]		)
96b86040a5SCatalin Marinas THUMB(	str	lr, [sp, #S_LR]		)
971da177e4SLinus Torvalds	mov	r1, #\reason
981da177e4SLinus Torvalds	.endm
991da177e4SLinus Torvalds
1001da177e4SLinus Torvalds__pabt_invalid:
101ccea7a19SRussell King	inv_entry BAD_PREFETCH
102ccea7a19SRussell King	b	common_invalid
10393ed3970SCatalin MarinasENDPROC(__pabt_invalid)
1041da177e4SLinus Torvalds
1051da177e4SLinus Torvalds__dabt_invalid:
106ccea7a19SRussell King	inv_entry BAD_DATA
107ccea7a19SRussell King	b	common_invalid
10893ed3970SCatalin MarinasENDPROC(__dabt_invalid)
1091da177e4SLinus Torvalds
1101da177e4SLinus Torvalds__irq_invalid:
111ccea7a19SRussell King	inv_entry BAD_IRQ
112ccea7a19SRussell King	b	common_invalid
11393ed3970SCatalin MarinasENDPROC(__irq_invalid)
1141da177e4SLinus Torvalds
1151da177e4SLinus Torvalds__und_invalid:
116ccea7a19SRussell King	inv_entry BAD_UNDEFINSTR
1171da177e4SLinus Torvalds
118ccea7a19SRussell King	@
119ccea7a19SRussell King	@ XXX fall through to common_invalid
120ccea7a19SRussell King	@
121ccea7a19SRussell King
122ccea7a19SRussell King@
123ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers)
124ccea7a19SRussell King@
125ccea7a19SRussell Kingcommon_invalid:
126ccea7a19SRussell King	zero_fp
127ccea7a19SRussell King
128ccea7a19SRussell King	ldmia	r0, {r4 - r6}
129ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
130ccea7a19SRussell King	mov	r7, #-1			@  ""   ""    ""        ""
131ccea7a19SRussell King	str	r4, [sp]		@ save preserved r0
132ccea7a19SRussell King	stmia	r0, {r5 - r7}		@ lr_<exception>,
133ccea7a19SRussell King					@ cpsr_<exception>, "old_r0"
134ccea7a19SRussell King
1351da177e4SLinus Torvalds	mov	r0, sp
1361da177e4SLinus Torvalds	b	bad_mode
13793ed3970SCatalin MarinasENDPROC(__und_invalid)
1381da177e4SLinus Torvalds
1391da177e4SLinus Torvalds/*
1401da177e4SLinus Torvalds * SVC mode handlers
1411da177e4SLinus Torvalds */
1422dede2d8SNicolas Pitre
1432dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
1442dede2d8SNicolas Pitre#define SPFIX(code...) code
1452dede2d8SNicolas Pitre#else
1462dede2d8SNicolas Pitre#define SPFIX(code...)
1472dede2d8SNicolas Pitre#endif
1482dede2d8SNicolas Pitre
149*c0e7f7eeSDaniel Thompson	.macro	svc_entry, stack_hole=0, trace=1
150c4c5716eSCatalin Marinas UNWIND(.fnstart		)
151c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc}		)
152b86040a5SCatalin Marinas	sub	sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
153b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL
154b86040a5SCatalin Marinas SPFIX(	str	r0, [sp]	)	@ temporarily saved
155b86040a5SCatalin Marinas SPFIX(	mov	r0, sp		)
156b86040a5SCatalin Marinas SPFIX(	tst	r0, #4		)	@ test original stack alignment
157b86040a5SCatalin Marinas SPFIX(	ldr	r0, [sp]	)	@ restored
158b86040a5SCatalin Marinas#else
1592dede2d8SNicolas Pitre SPFIX(	tst	sp, #4		)
160b86040a5SCatalin Marinas#endif
161b86040a5SCatalin Marinas SPFIX(	subeq	sp, sp, #4	)
162b86040a5SCatalin Marinas	stmia	sp, {r1 - r12}
163ccea7a19SRussell King
164b059bdc3SRussell King	ldmia	r0, {r3 - r5}
165b059bdc3SRussell King	add	r7, sp, #S_SP - 4	@ here for interlock avoidance
166b059bdc3SRussell King	mov	r6, #-1			@  ""  ""      ""       ""
167b059bdc3SRussell King	add	r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
168b059bdc3SRussell King SPFIX(	addeq	r2, r2, #4	)
169b059bdc3SRussell King	str	r3, [sp, #-4]!		@ save the "real" r0 copied
170ccea7a19SRussell King					@ from the exception stack
171ccea7a19SRussell King
172b059bdc3SRussell King	mov	r3, lr
1731da177e4SLinus Torvalds
1741da177e4SLinus Torvalds	@
1751da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
1761da177e4SLinus Torvalds	@
177b059bdc3SRussell King	@  r2 - sp_svc
178b059bdc3SRussell King	@  r3 - lr_svc
179b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
180b059bdc3SRussell King	@  r5 - spsr_<exception>
181b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
1821da177e4SLinus Torvalds	@
183b059bdc3SRussell King	stmia	r7, {r2 - r6}
184f2741b78SRussell King
185*c0e7f7eeSDaniel Thompson	.if \trace
186f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
187f2741b78SRussell King	bl	trace_hardirqs_off
188f2741b78SRussell King#endif
189*c0e7f7eeSDaniel Thompson	.endif
1901da177e4SLinus Torvalds	.endm
1911da177e4SLinus Torvalds
1921da177e4SLinus Torvalds	.align	5
1931da177e4SLinus Torvalds__dabt_svc:
194ccea7a19SRussell King	svc_entry
1951da177e4SLinus Torvalds	mov	r2, sp
196da740472SRussell King	dabt_helper
197e16b31bfSMarc Zyngier THUMB(	ldr	r5, [sp, #S_PSR]	)	@ potentially updated CPSR
198b059bdc3SRussell King	svc_exit r5				@ return from exception
199c4c5716eSCatalin Marinas UNWIND(.fnend		)
20093ed3970SCatalin MarinasENDPROC(__dabt_svc)
2011da177e4SLinus Torvalds
2021da177e4SLinus Torvalds	.align	5
2031da177e4SLinus Torvalds__irq_svc:
204ccea7a19SRussell King	svc_entry
2051613cc11SRussell King	irq_handler
2061613cc11SRussell King
2071da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
208706fdd9fSRussell King	get_thread_info tsk
209706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
210706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get flags
21128fab1a2SRussell King	teq	r8, #0				@ if preempt count != 0
21228fab1a2SRussell King	movne	r0, #0				@ force flags to 0
2131da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2141da177e4SLinus Torvalds	blne	svc_preempt
2151da177e4SLinus Torvalds#endif
21630891c90SRussell King
2179b56febeSRussell King	svc_exit r5, irq = 1			@ return from exception
218c4c5716eSCatalin Marinas UNWIND(.fnend		)
21993ed3970SCatalin MarinasENDPROC(__irq_svc)
2201da177e4SLinus Torvalds
2211da177e4SLinus Torvalds	.ltorg
2221da177e4SLinus Torvalds
2231da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
2241da177e4SLinus Torvaldssvc_preempt:
22528fab1a2SRussell King	mov	r8, lr
2261da177e4SLinus Torvalds1:	bl	preempt_schedule_irq		@ irq en/disable is done inside
227706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get new tasks TI_FLAGS
2281da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2296ebbf2ceSRussell King	reteq	r8				@ go again
2301da177e4SLinus Torvalds	b	1b
2311da177e4SLinus Torvalds#endif
2321da177e4SLinus Torvalds
23315ac49b6SRussell King__und_fault:
23415ac49b6SRussell King	@ Correct the PC such that it is pointing at the instruction
23515ac49b6SRussell King	@ which caused the fault.  If the faulting instruction was ARM
23615ac49b6SRussell King	@ the PC will be pointing at the next instruction, and have to
23715ac49b6SRussell King	@ subtract 4.  Otherwise, it is Thumb, and the PC will be
23815ac49b6SRussell King	@ pointing at the second half of the Thumb instruction.  We
23915ac49b6SRussell King	@ have to subtract 2.
24015ac49b6SRussell King	ldr	r2, [r0, #S_PC]
24115ac49b6SRussell King	sub	r2, r2, r1
24215ac49b6SRussell King	str	r2, [r0, #S_PC]
24315ac49b6SRussell King	b	do_undefinstr
24415ac49b6SRussell KingENDPROC(__und_fault)
24515ac49b6SRussell King
2461da177e4SLinus Torvalds	.align	5
2471da177e4SLinus Torvalds__und_svc:
248d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES
249d30a0c8bSNicolas Pitre	@ If a kprobe is about to simulate a "stmdb sp..." instruction,
250d30a0c8bSNicolas Pitre	@ it obviously needs free stack space which then will belong to
251d30a0c8bSNicolas Pitre	@ the saved context.
252d30a0c8bSNicolas Pitre	svc_entry 64
253d30a0c8bSNicolas Pitre#else
254ccea7a19SRussell King	svc_entry
255d30a0c8bSNicolas Pitre#endif
2561da177e4SLinus Torvalds	@
2571da177e4SLinus Torvalds	@ call emulation code, which returns using r9 if it has emulated
2581da177e4SLinus Torvalds	@ the instruction, or the more conventional lr if we are to treat
2591da177e4SLinus Torvalds	@ this as a real undefined instruction
2601da177e4SLinus Torvalds	@
2611da177e4SLinus Torvalds	@  r0 - instruction
2621da177e4SLinus Torvalds	@
26383e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL
264b059bdc3SRussell King	ldr	r0, [r4, #-4]
26583e686eaSCatalin Marinas#else
26615ac49b6SRussell King	mov	r1, #2
267b059bdc3SRussell King	ldrh	r0, [r4, #-2]			@ Thumb instruction at LR - 2
26885519189SDave Martin	cmp	r0, #0xe800			@ 32-bit instruction if xx >= 0
26915ac49b6SRussell King	blo	__und_svc_fault
27015ac49b6SRussell King	ldrh	r9, [r4]			@ bottom 16 bits
27115ac49b6SRussell King	add	r4, r4, #2
27215ac49b6SRussell King	str	r4, [sp, #S_PC]
27315ac49b6SRussell King	orr	r0, r9, r0, lsl #16
27483e686eaSCatalin Marinas#endif
27515ac49b6SRussell King	adr	r9, BSYM(__und_svc_finish)
276b059bdc3SRussell King	mov	r2, r4
2771da177e4SLinus Torvalds	bl	call_fpe
2781da177e4SLinus Torvalds
27915ac49b6SRussell King	mov	r1, #4				@ PC correction to apply
28015ac49b6SRussell King__und_svc_fault:
2811da177e4SLinus Torvalds	mov	r0, sp				@ struct pt_regs *regs
28215ac49b6SRussell King	bl	__und_fault
2831da177e4SLinus Torvalds
28415ac49b6SRussell King__und_svc_finish:
285b059bdc3SRussell King	ldr	r5, [sp, #S_PSR]		@ Get SVC cpsr
286b059bdc3SRussell King	svc_exit r5				@ return from exception
287c4c5716eSCatalin Marinas UNWIND(.fnend		)
28893ed3970SCatalin MarinasENDPROC(__und_svc)
2891da177e4SLinus Torvalds
2901da177e4SLinus Torvalds	.align	5
2911da177e4SLinus Torvalds__pabt_svc:
292ccea7a19SRussell King	svc_entry
2934fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
2948dfe7ac9SRussell King	pabt_helper
295b059bdc3SRussell King	svc_exit r5				@ return from exception
296c4c5716eSCatalin Marinas UNWIND(.fnend		)
29793ed3970SCatalin MarinasENDPROC(__pabt_svc)
2981da177e4SLinus Torvalds
2991da177e4SLinus Torvalds	.align	5
300*c0e7f7eeSDaniel Thompson__fiq_svc:
301*c0e7f7eeSDaniel Thompson	svc_entry trace=0
302*c0e7f7eeSDaniel Thompson	mov	r0, sp				@ struct pt_regs *regs
303*c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
304*c0e7f7eeSDaniel Thompson	svc_exit_via_fiq
305*c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
306*c0e7f7eeSDaniel ThompsonENDPROC(__fiq_svc)
307*c0e7f7eeSDaniel Thompson
308*c0e7f7eeSDaniel Thompson	.align	5
30949f680eaSRussell King.LCcralign:
31049f680eaSRussell King	.word	cr_alignment
31148d7927bSPaul Brook#ifdef MULTI_DABORT
3121da177e4SLinus Torvalds.LCprocfns:
3131da177e4SLinus Torvalds	.word	processor
3141da177e4SLinus Torvalds#endif
3151da177e4SLinus Torvalds.LCfp:
3161da177e4SLinus Torvalds	.word	fp_enter
3171da177e4SLinus Torvalds
3181da177e4SLinus Torvalds/*
319*c0e7f7eeSDaniel Thompson * Abort mode handlers
320*c0e7f7eeSDaniel Thompson */
321*c0e7f7eeSDaniel Thompson
322*c0e7f7eeSDaniel Thompson@
323*c0e7f7eeSDaniel Thompson@ Taking a FIQ in abort mode is similar to taking a FIQ in SVC mode
324*c0e7f7eeSDaniel Thompson@ and reuses the same macros. However in abort mode we must also
325*c0e7f7eeSDaniel Thompson@ save/restore lr_abt and spsr_abt to make nested aborts safe.
326*c0e7f7eeSDaniel Thompson@
327*c0e7f7eeSDaniel Thompson	.align 5
328*c0e7f7eeSDaniel Thompson__fiq_abt:
329*c0e7f7eeSDaniel Thompson	svc_entry trace=0
330*c0e7f7eeSDaniel Thompson
331*c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
332*c0e7f7eeSDaniel Thompson THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
333*c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
334*c0e7f7eeSDaniel Thompson	mov	r1, lr		@ Save lr_abt
335*c0e7f7eeSDaniel Thompson	mrs	r2, spsr	@ Save spsr_abt, abort is now safe
336*c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
337*c0e7f7eeSDaniel Thompson THUMB( mov	r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
338*c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
339*c0e7f7eeSDaniel Thompson	stmfd	sp!, {r1 - r2}
340*c0e7f7eeSDaniel Thompson
341*c0e7f7eeSDaniel Thompson	add	r0, sp, #8			@ struct pt_regs *regs
342*c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
343*c0e7f7eeSDaniel Thompson
344*c0e7f7eeSDaniel Thompson	ldmfd	sp!, {r1 - r2}
345*c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
346*c0e7f7eeSDaniel Thompson THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
347*c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
348*c0e7f7eeSDaniel Thompson	mov	lr, r1		@ Restore lr_abt, abort is unsafe
349*c0e7f7eeSDaniel Thompson	msr	spsr_cxsf, r2	@ Restore spsr_abt
350*c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
351*c0e7f7eeSDaniel Thompson THUMB( mov	r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
352*c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
353*c0e7f7eeSDaniel Thompson
354*c0e7f7eeSDaniel Thompson	svc_exit_via_fiq
355*c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
356*c0e7f7eeSDaniel ThompsonENDPROC(__fiq_abt)
357*c0e7f7eeSDaniel Thompson
358*c0e7f7eeSDaniel Thompson/*
3591da177e4SLinus Torvalds * User mode handlers
3602dede2d8SNicolas Pitre *
3612dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
3621da177e4SLinus Torvalds */
3632dede2d8SNicolas Pitre
3642dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
3652dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8"
3662dede2d8SNicolas Pitre#endif
3672dede2d8SNicolas Pitre
368*c0e7f7eeSDaniel Thompson	.macro	usr_entry, trace=1
369c4c5716eSCatalin Marinas UNWIND(.fnstart	)
370c4c5716eSCatalin Marinas UNWIND(.cantunwind	)	@ don't unwind the user space
371ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
372b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - r12}	)
373b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}	)
374ccea7a19SRussell King
375b059bdc3SRussell King	ldmia	r0, {r3 - r5}
376ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
377b059bdc3SRussell King	mov	r6, #-1			@  ""  ""     ""        ""
378ccea7a19SRussell King
379b059bdc3SRussell King	str	r3, [sp]		@ save the "real" r0 copied
380ccea7a19SRussell King					@ from the exception stack
3811da177e4SLinus Torvalds
3821da177e4SLinus Torvalds	@
3831da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
3841da177e4SLinus Torvalds	@
385b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
386b059bdc3SRussell King	@  r5 - spsr_<exception>
387b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
3881da177e4SLinus Torvalds	@
3891da177e4SLinus Torvalds	@ Also, separately save sp_usr and lr_usr
3901da177e4SLinus Torvalds	@
391b059bdc3SRussell King	stmia	r0, {r4 - r6}
392b86040a5SCatalin Marinas ARM(	stmdb	r0, {sp, lr}^			)
393b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r0, r1, S_SP - S_PC	)
3941da177e4SLinus Torvalds
3951da177e4SLinus Torvalds	@
3961da177e4SLinus Torvalds	@ Enable the alignment trap while in kernel mode
3971da177e4SLinus Torvalds	@
3988229c54fSRussell King	alignment_trap r0, .LCcralign
3991da177e4SLinus Torvalds
4001da177e4SLinus Torvalds	@
4011da177e4SLinus Torvalds	@ Clear FP to mark the first stack frame
4021da177e4SLinus Torvalds	@
4031da177e4SLinus Torvalds	zero_fp
404f2741b78SRussell King
405*c0e7f7eeSDaniel Thompson	.if	\trace
406f2741b78SRussell King#ifdef CONFIG_IRQSOFF_TRACER
407f2741b78SRussell King	bl	trace_hardirqs_off
408f2741b78SRussell King#endif
409b0088480SKevin Hilman	ct_user_exit save = 0
410*c0e7f7eeSDaniel Thompson	.endif
4111da177e4SLinus Torvalds	.endm
4121da177e4SLinus Torvalds
413b49c0f24SNicolas Pitre	.macro	kuser_cmpxchg_check
4141b16c4bcSRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) && \
4151b16c4bcSRussell King    !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
416b49c0f24SNicolas Pitre#ifndef CONFIG_MMU
417b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing"
418b49c0f24SNicolas Pitre#else
419b49c0f24SNicolas Pitre	@ Make sure our user space atomic helper is restarted
420b49c0f24SNicolas Pitre	@ if it was interrupted in a critical region.  Here we
421b49c0f24SNicolas Pitre	@ perform a quick test inline since it should be false
422b49c0f24SNicolas Pitre	@ 99.9999% of the time.  The rest is done out of line.
423b059bdc3SRussell King	cmp	r4, #TASK_SIZE
42440fb79c8SNicolas Pitre	blhs	kuser_cmpxchg64_fixup
425b49c0f24SNicolas Pitre#endif
426b49c0f24SNicolas Pitre#endif
427b49c0f24SNicolas Pitre	.endm
428b49c0f24SNicolas Pitre
4291da177e4SLinus Torvalds	.align	5
4301da177e4SLinus Torvalds__dabt_usr:
431ccea7a19SRussell King	usr_entry
432b49c0f24SNicolas Pitre	kuser_cmpxchg_check
4331da177e4SLinus Torvalds	mov	r2, sp
434da740472SRussell King	dabt_helper
435da740472SRussell King	b	ret_from_exception
436c4c5716eSCatalin Marinas UNWIND(.fnend		)
43793ed3970SCatalin MarinasENDPROC(__dabt_usr)
4381da177e4SLinus Torvalds
4391da177e4SLinus Torvalds	.align	5
4401da177e4SLinus Torvalds__irq_usr:
441ccea7a19SRussell King	usr_entry
442bc089602SRussell King	kuser_cmpxchg_check
443187a51adSRussell King	irq_handler
4441613cc11SRussell King	get_thread_info tsk
4451da177e4SLinus Torvalds	mov	why, #0
4469fc2552aSMing Lei	b	ret_to_user_from_irq
447c4c5716eSCatalin Marinas UNWIND(.fnend		)
44893ed3970SCatalin MarinasENDPROC(__irq_usr)
4491da177e4SLinus Torvalds
4501da177e4SLinus Torvalds	.ltorg
4511da177e4SLinus Torvalds
4521da177e4SLinus Torvalds	.align	5
4531da177e4SLinus Torvalds__und_usr:
454ccea7a19SRussell King	usr_entry
455bc089602SRussell King
456b059bdc3SRussell King	mov	r2, r4
457b059bdc3SRussell King	mov	r3, r5
4581da177e4SLinus Torvalds
45915ac49b6SRussell King	@ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the
46015ac49b6SRussell King	@      faulting instruction depending on Thumb mode.
46115ac49b6SRussell King	@ r3 = regs->ARM_cpsr
4621da177e4SLinus Torvalds	@
46315ac49b6SRussell King	@ The emulation code returns using r9 if it has emulated the
46415ac49b6SRussell King	@ instruction, or the more conventional lr if we are to treat
46515ac49b6SRussell King	@ this as a real undefined instruction
4661da177e4SLinus Torvalds	@
467b86040a5SCatalin Marinas	adr	r9, BSYM(ret_from_exception)
46815ac49b6SRussell King
4691417a6b8SCatalin Marinas	@ IRQs must be enabled before attempting to read the instruction from
4701417a6b8SCatalin Marinas	@ user space since that could cause a page/translation fault if the
4711417a6b8SCatalin Marinas	@ page table was modified by another CPU.
4721417a6b8SCatalin Marinas	enable_irq
4731417a6b8SCatalin Marinas
474cb170a45SPaul Brook	tst	r3, #PSR_T_BIT			@ Thumb mode?
47515ac49b6SRussell King	bne	__und_usr_thumb
47615ac49b6SRussell King	sub	r4, r2, #4			@ ARM instr at LR - 4
47715ac49b6SRussell King1:	ldrt	r0, [r4]
478457c2403SBen Dooks ARM_BE8(rev	r0, r0)				@ little endian instruction
479457c2403SBen Dooks
48015ac49b6SRussell King	@ r0 = 32-bit ARM instruction which caused the exception
48115ac49b6SRussell King	@ r2 = PC value for the following instruction (:= regs->ARM_pc)
48215ac49b6SRussell King	@ r4 = PC value for the faulting instruction
48315ac49b6SRussell King	@ lr = 32-bit undefined instruction function
48415ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
48515ac49b6SRussell King	b	call_fpe
48615ac49b6SRussell King
48715ac49b6SRussell King__und_usr_thumb:
488cb170a45SPaul Brook	@ Thumb instruction
48915ac49b6SRussell King	sub	r4, r2, #2			@ First half of thumb instr at LR - 2
490ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
491ef4c5368SDave Martin/*
492ef4c5368SDave Martin * Thumb-2 instruction handling.  Note that because pre-v6 and >= v6 platforms
493ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at
494ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6.  This allows simplifying assumptions to be
495ef4c5368SDave Martin * made about .arch directives.
496ef4c5368SDave Martin */
497ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
498ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */
499ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE
500ef4c5368SDave Martin	ldr	r5, .LCcpu_architecture
501ef4c5368SDave Martin	ldr	r5, [r5]
502ef4c5368SDave Martin	cmp	r5, #CPU_ARCH_ARMv7
50315ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
504ef4c5368SDave Martin/*
505ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so
506ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless.  Temporarily
507ef4c5368SDave Martin * override the assembler target arch with the minimum required instead:
508ef4c5368SDave Martin */
509ef4c5368SDave Martin	.arch	armv6t2
510ef4c5368SDave Martin#endif
51115ac49b6SRussell King2:	ldrht	r5, [r4]
512f8fe23ecSVictor KamenskyARM_BE8(rev16	r5, r5)				@ little endian instruction
51385519189SDave Martin	cmp	r5, #0xe800			@ 32bit instruction if xx != 0
51415ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
51515ac49b6SRussell King3:	ldrht	r0, [r2]
516f8fe23ecSVictor KamenskyARM_BE8(rev16	r0, r0)				@ little endian instruction
517cb170a45SPaul Brook	add	r2, r2, #2			@ r2 is PC + 2, make it PC + 4
51815ac49b6SRussell King	str	r2, [sp, #S_PC]			@ it's a 2x16bit instr, update
519cb170a45SPaul Brook	orr	r0, r0, r5, lsl #16
52015ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
52115ac49b6SRussell King	@ r0 = the two 16-bit Thumb instructions which caused the exception
52215ac49b6SRussell King	@ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc)
52315ac49b6SRussell King	@ r4 = PC value for the first 16-bit Thumb instruction
52415ac49b6SRussell King	@ lr = 32bit undefined instruction function
525ef4c5368SDave Martin
526ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
527ef4c5368SDave Martin/* If the target arch was overridden, change it back: */
528ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K
529ef4c5368SDave Martin	.arch	armv6k
530cb170a45SPaul Brook#else
531ef4c5368SDave Martin	.arch	armv6
532ef4c5368SDave Martin#endif
533ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */
534ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */
53515ac49b6SRussell King	b	__und_usr_fault_16
536cb170a45SPaul Brook#endif
537c4c5716eSCatalin Marinas UNWIND(.fnend)
53893ed3970SCatalin MarinasENDPROC(__und_usr)
539cb170a45SPaul Brook
5401da177e4SLinus Torvalds/*
54115ac49b6SRussell King * The out of line fixup for the ldrt instructions above.
5421da177e4SLinus Torvalds */
5434260415fSRussell King	.pushsection .fixup, "ax"
544667d1b48SWill Deacon	.align	2
5453780f7abSArun K S4:	str     r4, [sp, #S_PC]			@ retry current instruction
5466ebbf2ceSRussell King	ret	r9
5474260415fSRussell King	.popsection
5484260415fSRussell King	.pushsection __ex_table,"a"
549cb170a45SPaul Brook	.long	1b, 4b
550c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
551cb170a45SPaul Brook	.long	2b, 4b
552cb170a45SPaul Brook	.long	3b, 4b
553cb170a45SPaul Brook#endif
5544260415fSRussell King	.popsection
5551da177e4SLinus Torvalds
5561da177e4SLinus Torvalds/*
5571da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction.
5581da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler.
5591da177e4SLinus Torvalds *
5601da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor
5611da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well
5621da177e4SLinus Torvalds * defined.  The only instructions that should fault are the
5631da177e4SLinus Torvalds * co-processor instructions.  However, we have to watch out
5641da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug.
5651da177e4SLinus Torvalds *
566b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all
567b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have
568b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's
569b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs
570b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the
571b5872db4SCatalin Marinas * NEON handler code.
572b5872db4SCatalin Marinas *
5731da177e4SLinus Torvalds * Emulators may wish to make use of the following registers:
57415ac49b6SRussell King *  r0  = instruction opcode (32-bit ARM or two 16-bit Thumb)
57515ac49b6SRussell King *  r2  = PC value to resume execution after successful emulation
576db6ccbb6SRussell King *  r9  = normal "successful" return address
57715ac49b6SRussell King *  r10 = this threads thread_info structure
578db6ccbb6SRussell King *  lr  = unrecognised instruction return address
5791417a6b8SCatalin Marinas * IRQs enabled, FIQs enabled.
5801da177e4SLinus Torvalds */
581cb170a45SPaul Brook	@
582cb170a45SPaul Brook	@ Fall-through from Thumb-2 __und_usr
583cb170a45SPaul Brook	@
584cb170a45SPaul Brook#ifdef CONFIG_NEON
585d3f79584SRussell King	get_thread_info r10			@ get current thread
586cb170a45SPaul Brook	adr	r6, .LCneon_thumb_opcodes
587cb170a45SPaul Brook	b	2f
588cb170a45SPaul Brook#endif
5891da177e4SLinus Torvaldscall_fpe:
590d3f79584SRussell King	get_thread_info r10			@ get current thread
591b5872db4SCatalin Marinas#ifdef CONFIG_NEON
592cb170a45SPaul Brook	adr	r6, .LCneon_arm_opcodes
593d3f79584SRussell King2:	ldr	r5, [r6], #4			@ mask value
594b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ opcode bits matching in mask
595d3f79584SRussell King	cmp	r5, #0				@ end mask?
596d3f79584SRussell King	beq	1f
597d3f79584SRussell King	and	r8, r0, r5
598b5872db4SCatalin Marinas	cmp	r8, r7				@ NEON instruction?
599b5872db4SCatalin Marinas	bne	2b
600b5872db4SCatalin Marinas	mov	r7, #1
601b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 10]	@ mark CP#10 as used
602b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 11]	@ mark CP#11 as used
603b5872db4SCatalin Marinas	b	do_vfp				@ let VFP handler handle this
604b5872db4SCatalin Marinas1:
605b5872db4SCatalin Marinas#endif
6061da177e4SLinus Torvalds	tst	r0, #0x08000000			@ only CDP/CPRT/LDC/STC have bit 27
607cb170a45SPaul Brook	tstne	r0, #0x04000000			@ bit 26 set on both ARM and Thumb-2
6086ebbf2ceSRussell King	reteq	lr
6091da177e4SLinus Torvalds	and	r8, r0, #0x00000f00		@ mask out CP number
610b86040a5SCatalin Marinas THUMB(	lsr	r8, r8, #8		)
6111da177e4SLinus Torvalds	mov	r7, #1
6121da177e4SLinus Torvalds	add	r6, r10, #TI_USED_CP
613b86040a5SCatalin Marinas ARM(	strb	r7, [r6, r8, lsr #8]	)	@ set appropriate used_cp[]
614b86040a5SCatalin Marinas THUMB(	strb	r7, [r6, r8]		)	@ set appropriate used_cp[]
6151da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT
6161da177e4SLinus Torvalds	@ Test if we need to give access to iWMMXt coprocessors
6171da177e4SLinus Torvalds	ldr	r5, [r10, #TI_FLAGS]
6181da177e4SLinus Torvalds	rsbs	r7, r8, #(1 << 8)		@ CP 0 or 1 only
6191da177e4SLinus Torvalds	movcss	r7, r5, lsr #(TIF_USING_IWMMXT + 1)
6201da177e4SLinus Torvalds	bcs	iwmmxt_task_enable
6211da177e4SLinus Torvalds#endif
622b86040a5SCatalin Marinas ARM(	add	pc, pc, r8, lsr #6	)
623b86040a5SCatalin Marinas THUMB(	lsl	r8, r8, #2		)
624b86040a5SCatalin Marinas THUMB(	add	pc, r8			)
625b86040a5SCatalin Marinas	nop
6261da177e4SLinus Torvalds
6276ebbf2ceSRussell King	ret.w	lr				@ CP#0
628b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#1 (FPE)
629b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#2 (FPE)
6306ebbf2ceSRussell King	ret.w	lr				@ CP#3
631c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH
632c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#4 (MaverickCrunch)
633c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#5 (MaverickCrunch)
634c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#6 (MaverickCrunch)
635c17fad11SLennert Buytenhek#else
6366ebbf2ceSRussell King	ret.w	lr				@ CP#4
6376ebbf2ceSRussell King	ret.w	lr				@ CP#5
6386ebbf2ceSRussell King	ret.w	lr				@ CP#6
639c17fad11SLennert Buytenhek#endif
6406ebbf2ceSRussell King	ret.w	lr				@ CP#7
6416ebbf2ceSRussell King	ret.w	lr				@ CP#8
6426ebbf2ceSRussell King	ret.w	lr				@ CP#9
6431da177e4SLinus Torvalds#ifdef CONFIG_VFP
644b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#10 (VFP)
645b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#11 (VFP)
6461da177e4SLinus Torvalds#else
6476ebbf2ceSRussell King	ret.w	lr				@ CP#10 (VFP)
6486ebbf2ceSRussell King	ret.w	lr				@ CP#11 (VFP)
6491da177e4SLinus Torvalds#endif
6506ebbf2ceSRussell King	ret.w	lr				@ CP#12
6516ebbf2ceSRussell King	ret.w	lr				@ CP#13
6526ebbf2ceSRussell King	ret.w	lr				@ CP#14 (Debug)
6536ebbf2ceSRussell King	ret.w	lr				@ CP#15 (Control)
6541da177e4SLinus Torvalds
655ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE
656ef4c5368SDave Martin	.align	2
657ef4c5368SDave Martin.LCcpu_architecture:
658ef4c5368SDave Martin	.word	__cpu_architecture
659ef4c5368SDave Martin#endif
660ef4c5368SDave Martin
661b5872db4SCatalin Marinas#ifdef CONFIG_NEON
662b5872db4SCatalin Marinas	.align	6
663b5872db4SCatalin Marinas
664cb170a45SPaul Brook.LCneon_arm_opcodes:
665b5872db4SCatalin Marinas	.word	0xfe000000			@ mask
666b5872db4SCatalin Marinas	.word	0xf2000000			@ opcode
667b5872db4SCatalin Marinas
668b5872db4SCatalin Marinas	.word	0xff100000			@ mask
669b5872db4SCatalin Marinas	.word	0xf4000000			@ opcode
670b5872db4SCatalin Marinas
671b5872db4SCatalin Marinas	.word	0x00000000			@ mask
672b5872db4SCatalin Marinas	.word	0x00000000			@ opcode
673cb170a45SPaul Brook
674cb170a45SPaul Brook.LCneon_thumb_opcodes:
675cb170a45SPaul Brook	.word	0xef000000			@ mask
676cb170a45SPaul Brook	.word	0xef000000			@ opcode
677cb170a45SPaul Brook
678cb170a45SPaul Brook	.word	0xff100000			@ mask
679cb170a45SPaul Brook	.word	0xf9000000			@ opcode
680cb170a45SPaul Brook
681cb170a45SPaul Brook	.word	0x00000000			@ mask
682cb170a45SPaul Brook	.word	0x00000000			@ opcode
683b5872db4SCatalin Marinas#endif
684b5872db4SCatalin Marinas
6851da177e4SLinus Torvaldsdo_fpe:
6861da177e4SLinus Torvalds	ldr	r4, .LCfp
6871da177e4SLinus Torvalds	add	r10, r10, #TI_FPSTATE		@ r10 = workspace
6881da177e4SLinus Torvalds	ldr	pc, [r4]			@ Call FP module USR entry point
6891da177e4SLinus Torvalds
6901da177e4SLinus Torvalds/*
6911da177e4SLinus Torvalds * The FP module is called with these registers set:
6921da177e4SLinus Torvalds *  r0  = instruction
6931da177e4SLinus Torvalds *  r2  = PC+4
6941da177e4SLinus Torvalds *  r9  = normal "successful" return address
6951da177e4SLinus Torvalds *  r10 = FP workspace
6961da177e4SLinus Torvalds *  lr  = unrecognised FP instruction return address
6971da177e4SLinus Torvalds */
6981da177e4SLinus Torvalds
699124efc27SSantosh Shilimkar	.pushsection .data
7001da177e4SLinus TorvaldsENTRY(fp_enter)
701db6ccbb6SRussell King	.word	no_fp
702124efc27SSantosh Shilimkar	.popsection
7031da177e4SLinus Torvalds
70483e686eaSCatalin MarinasENTRY(no_fp)
7056ebbf2ceSRussell King	ret	lr
70683e686eaSCatalin MarinasENDPROC(no_fp)
707db6ccbb6SRussell King
70815ac49b6SRussell King__und_usr_fault_32:
70915ac49b6SRussell King	mov	r1, #4
71015ac49b6SRussell King	b	1f
71115ac49b6SRussell King__und_usr_fault_16:
71215ac49b6SRussell King	mov	r1, #2
7131417a6b8SCatalin Marinas1:	mov	r0, sp
714b86040a5SCatalin Marinas	adr	lr, BSYM(ret_from_exception)
71515ac49b6SRussell King	b	__und_fault
71615ac49b6SRussell KingENDPROC(__und_usr_fault_32)
71715ac49b6SRussell KingENDPROC(__und_usr_fault_16)
7181da177e4SLinus Torvalds
7191da177e4SLinus Torvalds	.align	5
7201da177e4SLinus Torvalds__pabt_usr:
721ccea7a19SRussell King	usr_entry
7224fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
7238dfe7ac9SRussell King	pabt_helper
724c4c5716eSCatalin Marinas UNWIND(.fnend		)
7251da177e4SLinus Torvalds	/* fall through */
7261da177e4SLinus Torvalds/*
7271da177e4SLinus Torvalds * This is the return code to user mode for abort handlers
7281da177e4SLinus Torvalds */
7291da177e4SLinus TorvaldsENTRY(ret_from_exception)
730c4c5716eSCatalin Marinas UNWIND(.fnstart	)
731c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7321da177e4SLinus Torvalds	get_thread_info tsk
7331da177e4SLinus Torvalds	mov	why, #0
7341da177e4SLinus Torvalds	b	ret_to_user
735c4c5716eSCatalin Marinas UNWIND(.fnend		)
73693ed3970SCatalin MarinasENDPROC(__pabt_usr)
73793ed3970SCatalin MarinasENDPROC(ret_from_exception)
7381da177e4SLinus Torvalds
739*c0e7f7eeSDaniel Thompson	.align	5
740*c0e7f7eeSDaniel Thompson__fiq_usr:
741*c0e7f7eeSDaniel Thompson	usr_entry trace=0
742*c0e7f7eeSDaniel Thompson	kuser_cmpxchg_check
743*c0e7f7eeSDaniel Thompson	mov	r0, sp				@ struct pt_regs *regs
744*c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
745*c0e7f7eeSDaniel Thompson	get_thread_info tsk
746*c0e7f7eeSDaniel Thompson	restore_user_regs fast = 0, offset = 0
747*c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
748*c0e7f7eeSDaniel ThompsonENDPROC(__fiq_usr)
749*c0e7f7eeSDaniel Thompson
7501da177e4SLinus Torvalds/*
7511da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors
7521da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
7531da177e4SLinus Torvalds * previous and next are guaranteed not to be the same.
7541da177e4SLinus Torvalds */
7551da177e4SLinus TorvaldsENTRY(__switch_to)
756c4c5716eSCatalin Marinas UNWIND(.fnstart	)
757c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7581da177e4SLinus Torvalds	add	ip, r1, #TI_CPU_SAVE
759b86040a5SCatalin Marinas ARM(	stmia	ip!, {r4 - sl, fp, sp, lr} )	@ Store most regs on stack
760b86040a5SCatalin Marinas THUMB(	stmia	ip!, {r4 - sl, fp}	   )	@ Store most regs on stack
761b86040a5SCatalin Marinas THUMB(	str	sp, [ip], #4		   )
762b86040a5SCatalin Marinas THUMB(	str	lr, [ip], #4		   )
763a4780adeSAndré Hentschel	ldr	r4, [r2, #TI_TP_VALUE]
764a4780adeSAndré Hentschel	ldr	r5, [r2, #TI_TP_VALUE + 4]
765247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
766d6551e88SRussell King	ldr	r6, [r2, #TI_CPU_DOMAIN]
767afeb90caSHyok S. Choi#endif
768a4780adeSAndré Hentschel	switch_tls r1, r4, r5, r3, r7
769df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
770df0698beSNicolas Pitre	ldr	r7, [r2, #TI_TASK]
771df0698beSNicolas Pitre	ldr	r8, =__stack_chk_guard
772df0698beSNicolas Pitre	ldr	r7, [r7, #TSK_STACK_CANARY]
773df0698beSNicolas Pitre#endif
774247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
7751da177e4SLinus Torvalds	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
776afeb90caSHyok S. Choi#endif
777d6551e88SRussell King	mov	r5, r0
778d6551e88SRussell King	add	r4, r2, #TI_CPU_SAVE
779d6551e88SRussell King	ldr	r0, =thread_notify_head
780d6551e88SRussell King	mov	r1, #THREAD_NOTIFY_SWITCH
781d6551e88SRussell King	bl	atomic_notifier_call_chain
782df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
783df0698beSNicolas Pitre	str	r7, [r8]
784df0698beSNicolas Pitre#endif
785b86040a5SCatalin Marinas THUMB(	mov	ip, r4			   )
786d6551e88SRussell King	mov	r0, r5
787b86040a5SCatalin Marinas ARM(	ldmia	r4, {r4 - sl, fp, sp, pc}  )	@ Load all regs saved previously
788b86040a5SCatalin Marinas THUMB(	ldmia	ip!, {r4 - sl, fp}	   )	@ Load all regs saved previously
789b86040a5SCatalin Marinas THUMB(	ldr	sp, [ip], #4		   )
790b86040a5SCatalin Marinas THUMB(	ldr	pc, [ip]		   )
791c4c5716eSCatalin Marinas UNWIND(.fnend		)
79293ed3970SCatalin MarinasENDPROC(__switch_to)
7931da177e4SLinus Torvalds
7941da177e4SLinus Torvalds	__INIT
7952d2669b6SNicolas Pitre
7962d2669b6SNicolas Pitre/*
7972d2669b6SNicolas Pitre * User helpers.
7982d2669b6SNicolas Pitre *
7992d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high
8002d2669b6SNicolas Pitre * vector page.  New segments (if ever needed) must be added in front of
8012d2669b6SNicolas Pitre * existing ones.  This mechanism should be used only for things that are
8022d2669b6SNicolas Pitre * really small and justified, and not be abused freely.
8032d2669b6SNicolas Pitre *
80437b83046SNicolas Pitre * See Documentation/arm/kernel_user_helpers.txt for formal definitions.
8052d2669b6SNicolas Pitre */
806b86040a5SCatalin Marinas THUMB(	.arm	)
8072d2669b6SNicolas Pitre
808ba9b5d76SNicolas Pitre	.macro	usr_ret, reg
809ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB
810ba9b5d76SNicolas Pitre	bx	\reg
811ba9b5d76SNicolas Pitre#else
8126ebbf2ceSRussell King	ret	\reg
813ba9b5d76SNicolas Pitre#endif
814ba9b5d76SNicolas Pitre	.endm
815ba9b5d76SNicolas Pitre
8165b43e7a3SRussell King	.macro	kuser_pad, sym, size
8175b43e7a3SRussell King	.if	(. - \sym) & 3
8185b43e7a3SRussell King	.rept	4 - (. - \sym) & 3
8195b43e7a3SRussell King	.byte	0
8205b43e7a3SRussell King	.endr
8215b43e7a3SRussell King	.endif
8225b43e7a3SRussell King	.rept	(\size - (. - \sym)) / 4
8235b43e7a3SRussell King	.word	0xe7fddef1
8245b43e7a3SRussell King	.endr
8255b43e7a3SRussell King	.endm
8265b43e7a3SRussell King
827f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS
8282d2669b6SNicolas Pitre	.align	5
8292d2669b6SNicolas Pitre	.globl	__kuser_helper_start
8302d2669b6SNicolas Pitre__kuser_helper_start:
8312d2669b6SNicolas Pitre
8322d2669b6SNicolas Pitre/*
83340fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular
83440fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point.
8357c612bfdSNicolas Pitre */
8367c612bfdSNicolas Pitre
83740fb79c8SNicolas Pitre__kuser_cmpxchg64:				@ 0xffff0f60
83840fb79c8SNicolas Pitre
83940fb79c8SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
84040fb79c8SNicolas Pitre
84140fb79c8SNicolas Pitre	/*
84240fb79c8SNicolas Pitre	 * Poor you.  No fast solution possible...
84340fb79c8SNicolas Pitre	 * The kernel itself must perform the operation.
84440fb79c8SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
84540fb79c8SNicolas Pitre	 */
84640fb79c8SNicolas Pitre	stmfd	sp!, {r7, lr}
84740fb79c8SNicolas Pitre	ldr	r7, 1f			@ it's 20 bits
84840fb79c8SNicolas Pitre	swi	__ARM_NR_cmpxchg64
84940fb79c8SNicolas Pitre	ldmfd	sp!, {r7, pc}
85040fb79c8SNicolas Pitre1:	.word	__ARM_NR_cmpxchg64
85140fb79c8SNicolas Pitre
85240fb79c8SNicolas Pitre#elif defined(CONFIG_CPU_32v6K)
85340fb79c8SNicolas Pitre
85440fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, r7}
85540fb79c8SNicolas Pitre	ldrd	r4, r5, [r0]			@ load old val
85640fb79c8SNicolas Pitre	ldrd	r6, r7, [r1]			@ load new val
85740fb79c8SNicolas Pitre	smp_dmb	arm
85840fb79c8SNicolas Pitre1:	ldrexd	r0, r1, [r2]			@ load current val
85940fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
86040fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
86140fb79c8SNicolas Pitre	strexdeq r3, r6, r7, [r2]		@ store newval if eq
86240fb79c8SNicolas Pitre	teqeq	r3, #1				@ success?
86340fb79c8SNicolas Pitre	beq	1b				@ if no then retry
86440fb79c8SNicolas Pitre	smp_dmb	arm
86540fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set returned val and C flag
86640fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, r7}
8675a97d0aeSWill Deacon	usr_ret	lr
86840fb79c8SNicolas Pitre
86940fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP)
87040fb79c8SNicolas Pitre
87140fb79c8SNicolas Pitre#ifdef CONFIG_MMU
87240fb79c8SNicolas Pitre
87340fb79c8SNicolas Pitre	/*
87440fb79c8SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg64
87540fb79c8SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
87640fb79c8SNicolas Pitre	 * causing another process/thread to be scheduled in the middle of
87740fb79c8SNicolas Pitre	 * the critical sequence.  The same strategy as for cmpxchg is used.
87840fb79c8SNicolas Pitre	 */
87940fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, lr}
88040fb79c8SNicolas Pitre	ldmia	r0, {r4, r5}			@ load old val
88140fb79c8SNicolas Pitre	ldmia	r1, {r6, lr}			@ load new val
88240fb79c8SNicolas Pitre1:	ldmia	r2, {r0, r1}			@ load current val
88340fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
88440fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
88540fb79c8SNicolas Pitre2:	stmeqia	r2, {r6, lr}			@ store newval if eq
88640fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
88740fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, pc}
88840fb79c8SNicolas Pitre
88940fb79c8SNicolas Pitre	.text
89040fb79c8SNicolas Pitrekuser_cmpxchg64_fixup:
89140fb79c8SNicolas Pitre	@ Called from kuser_cmpxchg_fixup.
8923ad55155SRussell King	@ r4 = address of interrupted insn (must be preserved).
89340fb79c8SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
89440fb79c8SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
8953ad55155SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
89640fb79c8SNicolas Pitre	mov	r7, #0xffff0fff
89740fb79c8SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
8983ad55155SRussell King	subs	r8, r4, r7
89940fb79c8SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
90040fb79c8SNicolas Pitre	strcs	r7, [sp, #S_PC]
90140fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6
90240fb79c8SNicolas Pitre	bcc	kuser_cmpxchg32_fixup
90340fb79c8SNicolas Pitre#endif
9046ebbf2ceSRussell King	ret	lr
90540fb79c8SNicolas Pitre	.previous
90640fb79c8SNicolas Pitre
90740fb79c8SNicolas Pitre#else
90840fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing"
90940fb79c8SNicolas Pitre	mov	r0, #-1
91040fb79c8SNicolas Pitre	adds	r0, r0, #0
91140fb79c8SNicolas Pitre	usr_ret	lr
91240fb79c8SNicolas Pitre#endif
91340fb79c8SNicolas Pitre
91440fb79c8SNicolas Pitre#else
91540fb79c8SNicolas Pitre#error "incoherent kernel configuration"
91640fb79c8SNicolas Pitre#endif
91740fb79c8SNicolas Pitre
9185b43e7a3SRussell King	kuser_pad __kuser_cmpxchg64, 64
91940fb79c8SNicolas Pitre
9207c612bfdSNicolas Pitre__kuser_memory_barrier:				@ 0xffff0fa0
921ed3768a8SDave Martin	smp_dmb	arm
922ba9b5d76SNicolas Pitre	usr_ret	lr
9237c612bfdSNicolas Pitre
9245b43e7a3SRussell King	kuser_pad __kuser_memory_barrier, 32
9257c612bfdSNicolas Pitre
9262d2669b6SNicolas Pitre__kuser_cmpxchg:				@ 0xffff0fc0
9272d2669b6SNicolas Pitre
928dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
9292d2669b6SNicolas Pitre
930dcef1f63SNicolas Pitre	/*
931dcef1f63SNicolas Pitre	 * Poor you.  No fast solution possible...
932dcef1f63SNicolas Pitre	 * The kernel itself must perform the operation.
933dcef1f63SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
934dcef1f63SNicolas Pitre	 */
9355e097445SNicolas Pitre	stmfd	sp!, {r7, lr}
93655afd264SDave Martin	ldr	r7, 1f			@ it's 20 bits
937cc20d429SRussell King	swi	__ARM_NR_cmpxchg
9385e097445SNicolas Pitre	ldmfd	sp!, {r7, pc}
939cc20d429SRussell King1:	.word	__ARM_NR_cmpxchg
940dcef1f63SNicolas Pitre
941dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6
9422d2669b6SNicolas Pitre
94349bca4c2SNicolas Pitre#ifdef CONFIG_MMU
944b49c0f24SNicolas Pitre
945b49c0f24SNicolas Pitre	/*
946b49c0f24SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg
947b49c0f24SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
948b49c0f24SNicolas Pitre	 * causing another process/thread to be scheduled in the middle
949b49c0f24SNicolas Pitre	 * of the critical sequence.  To prevent this, code is added to
950b49c0f24SNicolas Pitre	 * the IRQ and data abort exception handlers to set the pc back
951b49c0f24SNicolas Pitre	 * to the beginning of the critical section if it is found to be
952b49c0f24SNicolas Pitre	 * within that critical section (see kuser_cmpxchg_fixup).
953b49c0f24SNicolas Pitre	 */
954b49c0f24SNicolas Pitre1:	ldr	r3, [r2]			@ load current val
955b49c0f24SNicolas Pitre	subs	r3, r3, r0			@ compare with oldval
956b49c0f24SNicolas Pitre2:	streq	r1, [r2]			@ store newval if eq
957b49c0f24SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
958b49c0f24SNicolas Pitre	usr_ret	lr
959b49c0f24SNicolas Pitre
960b49c0f24SNicolas Pitre	.text
96140fb79c8SNicolas Pitrekuser_cmpxchg32_fixup:
962b49c0f24SNicolas Pitre	@ Called from kuser_cmpxchg_check macro.
963b059bdc3SRussell King	@ r4 = address of interrupted insn (must be preserved).
964b49c0f24SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
965b49c0f24SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
966b059bdc3SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
967b49c0f24SNicolas Pitre	mov	r7, #0xffff0fff
968b49c0f24SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
969b059bdc3SRussell King	subs	r8, r4, r7
970b49c0f24SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
971b49c0f24SNicolas Pitre	strcs	r7, [sp, #S_PC]
9726ebbf2ceSRussell King	ret	lr
973b49c0f24SNicolas Pitre	.previous
974b49c0f24SNicolas Pitre
97549bca4c2SNicolas Pitre#else
97649bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing"
97749bca4c2SNicolas Pitre	mov	r0, #-1
97849bca4c2SNicolas Pitre	adds	r0, r0, #0
979ba9b5d76SNicolas Pitre	usr_ret	lr
980b49c0f24SNicolas Pitre#endif
9812d2669b6SNicolas Pitre
9822d2669b6SNicolas Pitre#else
9832d2669b6SNicolas Pitre
984ed3768a8SDave Martin	smp_dmb	arm
985b49c0f24SNicolas Pitre1:	ldrex	r3, [r2]
9862d2669b6SNicolas Pitre	subs	r3, r3, r0
9872d2669b6SNicolas Pitre	strexeq	r3, r1, [r2]
988b49c0f24SNicolas Pitre	teqeq	r3, #1
989b49c0f24SNicolas Pitre	beq	1b
9902d2669b6SNicolas Pitre	rsbs	r0, r3, #0
991b49c0f24SNicolas Pitre	/* beware -- each __kuser slot must be 8 instructions max */
992f00ec48fSRussell King	ALT_SMP(b	__kuser_memory_barrier)
993f00ec48fSRussell King	ALT_UP(usr_ret	lr)
9942d2669b6SNicolas Pitre
9952d2669b6SNicolas Pitre#endif
9962d2669b6SNicolas Pitre
9975b43e7a3SRussell King	kuser_pad __kuser_cmpxchg, 32
9982d2669b6SNicolas Pitre
9992d2669b6SNicolas Pitre__kuser_get_tls:				@ 0xffff0fe0
1000f159f4edSTony Lindgren	ldr	r0, [pc, #(16 - 8)]	@ read TLS, set in kuser_get_tls_init
1001ba9b5d76SNicolas Pitre	usr_ret	lr
1002f159f4edSTony Lindgren	mrc	p15, 0, r0, c13, c0, 3	@ 0xffff0fe8 hardware TLS code
10035b43e7a3SRussell King	kuser_pad __kuser_get_tls, 16
10045b43e7a3SRussell King	.rep	3
1005f159f4edSTony Lindgren	.word	0			@ 0xffff0ff0 software TLS value, then
1006f159f4edSTony Lindgren	.endr				@ pad up to __kuser_helper_version
10072d2669b6SNicolas Pitre
10082d2669b6SNicolas Pitre__kuser_helper_version:				@ 0xffff0ffc
10092d2669b6SNicolas Pitre	.word	((__kuser_helper_end - __kuser_helper_start) >> 5)
10102d2669b6SNicolas Pitre
10112d2669b6SNicolas Pitre	.globl	__kuser_helper_end
10122d2669b6SNicolas Pitre__kuser_helper_end:
10132d2669b6SNicolas Pitre
1014f6f91b0dSRussell King#endif
1015f6f91b0dSRussell King
1016b86040a5SCatalin Marinas THUMB(	.thumb	)
10172d2669b6SNicolas Pitre
10181da177e4SLinus Torvalds/*
10191da177e4SLinus Torvalds * Vector stubs.
10201da177e4SLinus Torvalds *
102119accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the
102219accfd3SRussell King * vectors, rather than ldr's.  Note that this code must not exceed
102319accfd3SRussell King * a page size.
10241da177e4SLinus Torvalds *
10251da177e4SLinus Torvalds * Common stub entry macro:
10261da177e4SLinus Torvalds *   Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1027ccea7a19SRussell King *
1028ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address
1029ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler.
10301da177e4SLinus Torvalds */
1031b7ec4795SNicolas Pitre	.macro	vector_stub, name, mode, correction=0
10321da177e4SLinus Torvalds	.align	5
10331da177e4SLinus Torvalds
10341da177e4SLinus Torvaldsvector_\name:
10351da177e4SLinus Torvalds	.if \correction
10361da177e4SLinus Torvalds	sub	lr, lr, #\correction
10371da177e4SLinus Torvalds	.endif
10381da177e4SLinus Torvalds
1039ccea7a19SRussell King	@
1040ccea7a19SRussell King	@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1041ccea7a19SRussell King	@ (parent CPSR)
1042ccea7a19SRussell King	@
1043ccea7a19SRussell King	stmia	sp, {r0, lr}		@ save r0, lr
1044ccea7a19SRussell King	mrs	lr, spsr
1045ccea7a19SRussell King	str	lr, [sp, #8]		@ save spsr
1046ccea7a19SRussell King
1047ccea7a19SRussell King	@
1048ccea7a19SRussell King	@ Prepare for SVC32 mode.  IRQs remain disabled.
1049ccea7a19SRussell King	@
1050ccea7a19SRussell King	mrs	r0, cpsr
1051b86040a5SCatalin Marinas	eor	r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
1052ccea7a19SRussell King	msr	spsr_cxsf, r0
1053ccea7a19SRussell King
1054ccea7a19SRussell King	@
1055ccea7a19SRussell King	@ the branch table must immediately follow this code
1056ccea7a19SRussell King	@
1057ccea7a19SRussell King	and	lr, lr, #0x0f
1058b86040a5SCatalin Marinas THUMB(	adr	r0, 1f			)
1059b86040a5SCatalin Marinas THUMB(	ldr	lr, [r0, lr, lsl #2]	)
1060b7ec4795SNicolas Pitre	mov	r0, sp
1061b86040a5SCatalin Marinas ARM(	ldr	lr, [pc, lr, lsl #2]	)
1062ccea7a19SRussell King	movs	pc, lr			@ branch to handler in SVC mode
106393ed3970SCatalin MarinasENDPROC(vector_\name)
106488987ef9SCatalin Marinas
106588987ef9SCatalin Marinas	.align	2
106688987ef9SCatalin Marinas	@ handler addresses follow this label
106788987ef9SCatalin Marinas1:
10681da177e4SLinus Torvalds	.endm
10691da177e4SLinus Torvalds
1070b9b32bf7SRussell King	.section .stubs, "ax", %progbits
10711da177e4SLinus Torvalds__stubs_start:
107219accfd3SRussell King	@ This must be the first word
107319accfd3SRussell King	.word	vector_swi
107419accfd3SRussell King
107519accfd3SRussell Kingvector_rst:
107619accfd3SRussell King ARM(	swi	SYS_ERROR0	)
107719accfd3SRussell King THUMB(	svc	#0		)
107819accfd3SRussell King THUMB(	nop			)
107919accfd3SRussell King	b	vector_und
108019accfd3SRussell King
10811da177e4SLinus Torvalds/*
10821da177e4SLinus Torvalds * Interrupt dispatcher
10831da177e4SLinus Torvalds */
1084b7ec4795SNicolas Pitre	vector_stub	irq, IRQ_MODE, 4
10851da177e4SLinus Torvalds
10861da177e4SLinus Torvalds	.long	__irq_usr			@  0  (USR_26 / USR_32)
10871da177e4SLinus Torvalds	.long	__irq_invalid			@  1  (FIQ_26 / FIQ_32)
10881da177e4SLinus Torvalds	.long	__irq_invalid			@  2  (IRQ_26 / IRQ_32)
10891da177e4SLinus Torvalds	.long	__irq_svc			@  3  (SVC_26 / SVC_32)
10901da177e4SLinus Torvalds	.long	__irq_invalid			@  4
10911da177e4SLinus Torvalds	.long	__irq_invalid			@  5
10921da177e4SLinus Torvalds	.long	__irq_invalid			@  6
10931da177e4SLinus Torvalds	.long	__irq_invalid			@  7
10941da177e4SLinus Torvalds	.long	__irq_invalid			@  8
10951da177e4SLinus Torvalds	.long	__irq_invalid			@  9
10961da177e4SLinus Torvalds	.long	__irq_invalid			@  a
10971da177e4SLinus Torvalds	.long	__irq_invalid			@  b
10981da177e4SLinus Torvalds	.long	__irq_invalid			@  c
10991da177e4SLinus Torvalds	.long	__irq_invalid			@  d
11001da177e4SLinus Torvalds	.long	__irq_invalid			@  e
11011da177e4SLinus Torvalds	.long	__irq_invalid			@  f
11021da177e4SLinus Torvalds
11031da177e4SLinus Torvalds/*
11041da177e4SLinus Torvalds * Data abort dispatcher
11051da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
11061da177e4SLinus Torvalds */
1107b7ec4795SNicolas Pitre	vector_stub	dabt, ABT_MODE, 8
11081da177e4SLinus Torvalds
11091da177e4SLinus Torvalds	.long	__dabt_usr			@  0  (USR_26 / USR_32)
11101da177e4SLinus Torvalds	.long	__dabt_invalid			@  1  (FIQ_26 / FIQ_32)
11111da177e4SLinus Torvalds	.long	__dabt_invalid			@  2  (IRQ_26 / IRQ_32)
11121da177e4SLinus Torvalds	.long	__dabt_svc			@  3  (SVC_26 / SVC_32)
11131da177e4SLinus Torvalds	.long	__dabt_invalid			@  4
11141da177e4SLinus Torvalds	.long	__dabt_invalid			@  5
11151da177e4SLinus Torvalds	.long	__dabt_invalid			@  6
11161da177e4SLinus Torvalds	.long	__dabt_invalid			@  7
11171da177e4SLinus Torvalds	.long	__dabt_invalid			@  8
11181da177e4SLinus Torvalds	.long	__dabt_invalid			@  9
11191da177e4SLinus Torvalds	.long	__dabt_invalid			@  a
11201da177e4SLinus Torvalds	.long	__dabt_invalid			@  b
11211da177e4SLinus Torvalds	.long	__dabt_invalid			@  c
11221da177e4SLinus Torvalds	.long	__dabt_invalid			@  d
11231da177e4SLinus Torvalds	.long	__dabt_invalid			@  e
11241da177e4SLinus Torvalds	.long	__dabt_invalid			@  f
11251da177e4SLinus Torvalds
11261da177e4SLinus Torvalds/*
11271da177e4SLinus Torvalds * Prefetch abort dispatcher
11281da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
11291da177e4SLinus Torvalds */
1130b7ec4795SNicolas Pitre	vector_stub	pabt, ABT_MODE, 4
11311da177e4SLinus Torvalds
11321da177e4SLinus Torvalds	.long	__pabt_usr			@  0 (USR_26 / USR_32)
11331da177e4SLinus Torvalds	.long	__pabt_invalid			@  1 (FIQ_26 / FIQ_32)
11341da177e4SLinus Torvalds	.long	__pabt_invalid			@  2 (IRQ_26 / IRQ_32)
11351da177e4SLinus Torvalds	.long	__pabt_svc			@  3 (SVC_26 / SVC_32)
11361da177e4SLinus Torvalds	.long	__pabt_invalid			@  4
11371da177e4SLinus Torvalds	.long	__pabt_invalid			@  5
11381da177e4SLinus Torvalds	.long	__pabt_invalid			@  6
11391da177e4SLinus Torvalds	.long	__pabt_invalid			@  7
11401da177e4SLinus Torvalds	.long	__pabt_invalid			@  8
11411da177e4SLinus Torvalds	.long	__pabt_invalid			@  9
11421da177e4SLinus Torvalds	.long	__pabt_invalid			@  a
11431da177e4SLinus Torvalds	.long	__pabt_invalid			@  b
11441da177e4SLinus Torvalds	.long	__pabt_invalid			@  c
11451da177e4SLinus Torvalds	.long	__pabt_invalid			@  d
11461da177e4SLinus Torvalds	.long	__pabt_invalid			@  e
11471da177e4SLinus Torvalds	.long	__pabt_invalid			@  f
11481da177e4SLinus Torvalds
11491da177e4SLinus Torvalds/*
11501da177e4SLinus Torvalds * Undef instr entry dispatcher
11511da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
11521da177e4SLinus Torvalds */
1153b7ec4795SNicolas Pitre	vector_stub	und, UND_MODE
11541da177e4SLinus Torvalds
11551da177e4SLinus Torvalds	.long	__und_usr			@  0 (USR_26 / USR_32)
11561da177e4SLinus Torvalds	.long	__und_invalid			@  1 (FIQ_26 / FIQ_32)
11571da177e4SLinus Torvalds	.long	__und_invalid			@  2 (IRQ_26 / IRQ_32)
11581da177e4SLinus Torvalds	.long	__und_svc			@  3 (SVC_26 / SVC_32)
11591da177e4SLinus Torvalds	.long	__und_invalid			@  4
11601da177e4SLinus Torvalds	.long	__und_invalid			@  5
11611da177e4SLinus Torvalds	.long	__und_invalid			@  6
11621da177e4SLinus Torvalds	.long	__und_invalid			@  7
11631da177e4SLinus Torvalds	.long	__und_invalid			@  8
11641da177e4SLinus Torvalds	.long	__und_invalid			@  9
11651da177e4SLinus Torvalds	.long	__und_invalid			@  a
11661da177e4SLinus Torvalds	.long	__und_invalid			@  b
11671da177e4SLinus Torvalds	.long	__und_invalid			@  c
11681da177e4SLinus Torvalds	.long	__und_invalid			@  d
11691da177e4SLinus Torvalds	.long	__und_invalid			@  e
11701da177e4SLinus Torvalds	.long	__und_invalid			@  f
11711da177e4SLinus Torvalds
11721da177e4SLinus Torvalds	.align	5
11731da177e4SLinus Torvalds
11741da177e4SLinus Torvalds/*=============================================================================
117519accfd3SRussell King * Address exception handler
117619accfd3SRussell King *-----------------------------------------------------------------------------
117719accfd3SRussell King * These aren't too critical.
117819accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode).
117919accfd3SRussell King */
118019accfd3SRussell King
118119accfd3SRussell Kingvector_addrexcptn:
118219accfd3SRussell King	b	vector_addrexcptn
118319accfd3SRussell King
118419accfd3SRussell King/*=============================================================================
1185*c0e7f7eeSDaniel Thompson * FIQ "NMI" handler
11861da177e4SLinus Torvalds *-----------------------------------------------------------------------------
1187*c0e7f7eeSDaniel Thompson * Handle a FIQ using the SVC stack allowing FIQ act like NMI on x86
1188*c0e7f7eeSDaniel Thompson * systems.
11891da177e4SLinus Torvalds */
1190*c0e7f7eeSDaniel Thompson	vector_stub	fiq, FIQ_MODE, 4
1191*c0e7f7eeSDaniel Thompson
1192*c0e7f7eeSDaniel Thompson	.long	__fiq_usr			@  0  (USR_26 / USR_32)
1193*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  1  (FIQ_26 / FIQ_32)
1194*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  2  (IRQ_26 / IRQ_32)
1195*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  3  (SVC_26 / SVC_32)
1196*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  4
1197*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  5
1198*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  6
1199*c0e7f7eeSDaniel Thompson	.long	__fiq_abt			@  7
1200*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  8
1201*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  9
1202*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  a
1203*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  b
1204*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  c
1205*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  d
1206*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  e
1207*c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  f
12081da177e4SLinus Torvalds
1209e39e3f3eSRussell King	.globl	vector_fiq_offset
1210e39e3f3eSRussell King	.equ	vector_fiq_offset, vector_fiq
1211e39e3f3eSRussell King
1212b9b32bf7SRussell King	.section .vectors, "ax", %progbits
12137933523dSRussell King__vectors_start:
1214b9b32bf7SRussell King	W(b)	vector_rst
1215b9b32bf7SRussell King	W(b)	vector_und
1216b9b32bf7SRussell King	W(ldr)	pc, __vectors_start + 0x1000
1217b9b32bf7SRussell King	W(b)	vector_pabt
1218b9b32bf7SRussell King	W(b)	vector_dabt
1219b9b32bf7SRussell King	W(b)	vector_addrexcptn
1220b9b32bf7SRussell King	W(b)	vector_irq
1221b9b32bf7SRussell King	W(b)	vector_fiq
12221da177e4SLinus Torvalds
12231da177e4SLinus Torvalds	.data
12241da177e4SLinus Torvalds
12251da177e4SLinus Torvalds	.globl	cr_alignment
12261da177e4SLinus Torvaldscr_alignment:
12271da177e4SLinus Torvalds	.space	4
122852108641Seric miao
122952108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER
123052108641Seric miao	.globl	handle_arch_irq
123152108641Seric miaohandle_arch_irq:
123252108641Seric miao	.space	4
123352108641Seric miao#endif
1234