xref: /openbmc/linux/arch/arm/kernel/entry-armv.S (revision d2912cb15bdda8ba4a5dd73396ad62641af2f520)
1*d2912cb1SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-only */
21da177e4SLinus Torvalds/*
31da177e4SLinus Torvalds *  linux/arch/arm/kernel/entry-armv.S
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds *  Copyright (C) 1996,1997,1998 Russell King.
61da177e4SLinus Torvalds *  ARM700 fix by Matthew Godbolt (linux-user@willothewisp.demon.co.uk)
7afeb90caSHyok S. Choi *  nommu support by Hyok S. Choi (hyok.choi@samsung.com)
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds *  Low-level vector interface routines
101da177e4SLinus Torvalds *
1170b6f2b4SNicolas Pitre *  Note:  there is a StrongARM bug in the STMIA rn, {regs}^ instruction
1270b6f2b4SNicolas Pitre *  that causes it to save wrong values...  Be aware!
131da177e4SLinus Torvalds */
141da177e4SLinus Torvalds
159b9cf81aSPaul Gortmaker#include <linux/init.h>
169b9cf81aSPaul Gortmaker
176f6f6a70SRob Herring#include <asm/assembler.h>
18f09b9979SNicolas Pitre#include <asm/memory.h>
19753790e7SRussell King#include <asm/glue-df.h>
20753790e7SRussell King#include <asm/glue-pf.h>
211da177e4SLinus Torvalds#include <asm/vfpmacros.h>
224c301f9bSPalmer Dabbelt#ifndef CONFIG_GENERIC_IRQ_MULTI_HANDLER
23a09e64fbSRussell King#include <mach/entry-macro.S>
24243c8654SRob Herring#endif
25d6551e88SRussell King#include <asm/thread_notify.h>
26c4c5716eSCatalin Marinas#include <asm/unwind.h>
27cc20d429SRussell King#include <asm/unistd.h>
28f159f4edSTony Lindgren#include <asm/tls.h>
299f97da78SDavid Howells#include <asm/system_info.h>
301da177e4SLinus Torvalds
311da177e4SLinus Torvalds#include "entry-header.S"
32cd544ce7SMagnus Damm#include <asm/entry-macro-multi.S>
33a0266c21SWang Nan#include <asm/probes.h>
341da177e4SLinus Torvalds
351da177e4SLinus Torvalds/*
36d9600c99SRussell King * Interrupt handling.
37187a51adSRussell King */
38187a51adSRussell King	.macro	irq_handler
394c301f9bSPalmer Dabbelt#ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
40d9600c99SRussell King	ldr	r1, =handle_arch_irq
4152108641Seric miao	mov	r0, sp
4214327c66SRussell King	badr	lr, 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
82c6089061SRussell King	.section	.entry.text,"ax",%progbits
83785d3cd2SNicolas Pitre
84187a51adSRussell King/*
851da177e4SLinus Torvalds * Invalid mode handlers
861da177e4SLinus Torvalds */
87ccea7a19SRussell King	.macro	inv_entry, reason
885745eef6SRussell King	sub	sp, sp, #PT_REGS_SIZE
89b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - lr}		)
90b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}		)
91b86040a5SCatalin Marinas THUMB(	str	sp, [sp, #S_SP]		)
92b86040a5SCatalin Marinas THUMB(	str	lr, [sp, #S_LR]		)
931da177e4SLinus Torvalds	mov	r1, #\reason
941da177e4SLinus Torvalds	.endm
951da177e4SLinus Torvalds
961da177e4SLinus Torvalds__pabt_invalid:
97ccea7a19SRussell King	inv_entry BAD_PREFETCH
98ccea7a19SRussell King	b	common_invalid
9993ed3970SCatalin MarinasENDPROC(__pabt_invalid)
1001da177e4SLinus Torvalds
1011da177e4SLinus Torvalds__dabt_invalid:
102ccea7a19SRussell King	inv_entry BAD_DATA
103ccea7a19SRussell King	b	common_invalid
10493ed3970SCatalin MarinasENDPROC(__dabt_invalid)
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds__irq_invalid:
107ccea7a19SRussell King	inv_entry BAD_IRQ
108ccea7a19SRussell King	b	common_invalid
10993ed3970SCatalin MarinasENDPROC(__irq_invalid)
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds__und_invalid:
112ccea7a19SRussell King	inv_entry BAD_UNDEFINSTR
1131da177e4SLinus Torvalds
114ccea7a19SRussell King	@
115ccea7a19SRussell King	@ XXX fall through to common_invalid
116ccea7a19SRussell King	@
117ccea7a19SRussell King
118ccea7a19SRussell King@
119ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers)
120ccea7a19SRussell King@
121ccea7a19SRussell Kingcommon_invalid:
122ccea7a19SRussell King	zero_fp
123ccea7a19SRussell King
124ccea7a19SRussell King	ldmia	r0, {r4 - r6}
125ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
126ccea7a19SRussell King	mov	r7, #-1			@  ""   ""    ""        ""
127ccea7a19SRussell King	str	r4, [sp]		@ save preserved r0
128ccea7a19SRussell King	stmia	r0, {r5 - r7}		@ lr_<exception>,
129ccea7a19SRussell King					@ cpsr_<exception>, "old_r0"
130ccea7a19SRussell King
1311da177e4SLinus Torvalds	mov	r0, sp
1321da177e4SLinus Torvalds	b	bad_mode
13393ed3970SCatalin MarinasENDPROC(__und_invalid)
1341da177e4SLinus Torvalds
1351da177e4SLinus Torvalds/*
1361da177e4SLinus Torvalds * SVC mode handlers
1371da177e4SLinus Torvalds */
1382dede2d8SNicolas Pitre
1392dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
1402dede2d8SNicolas Pitre#define SPFIX(code...) code
1412dede2d8SNicolas Pitre#else
1422dede2d8SNicolas Pitre#define SPFIX(code...)
1432dede2d8SNicolas Pitre#endif
1442dede2d8SNicolas Pitre
1452190fed6SRussell King	.macro	svc_entry, stack_hole=0, trace=1, uaccess=1
146c4c5716eSCatalin Marinas UNWIND(.fnstart		)
147c4c5716eSCatalin Marinas UNWIND(.save {r0 - pc}		)
148e6a9dc61SRussell King	sub	sp, sp, #(SVC_REGS_SIZE + \stack_hole - 4)
149b86040a5SCatalin Marinas#ifdef CONFIG_THUMB2_KERNEL
150b86040a5SCatalin Marinas SPFIX(	str	r0, [sp]	)	@ temporarily saved
151b86040a5SCatalin Marinas SPFIX(	mov	r0, sp		)
152b86040a5SCatalin Marinas SPFIX(	tst	r0, #4		)	@ test original stack alignment
153b86040a5SCatalin Marinas SPFIX(	ldr	r0, [sp]	)	@ restored
154b86040a5SCatalin Marinas#else
1552dede2d8SNicolas Pitre SPFIX(	tst	sp, #4		)
156b86040a5SCatalin Marinas#endif
157b86040a5SCatalin Marinas SPFIX(	subeq	sp, sp, #4	)
158b86040a5SCatalin Marinas	stmia	sp, {r1 - r12}
159ccea7a19SRussell King
160b059bdc3SRussell King	ldmia	r0, {r3 - r5}
161b059bdc3SRussell King	add	r7, sp, #S_SP - 4	@ here for interlock avoidance
162b059bdc3SRussell King	mov	r6, #-1			@  ""  ""      ""       ""
163e6a9dc61SRussell King	add	r2, sp, #(SVC_REGS_SIZE + \stack_hole - 4)
164b059bdc3SRussell King SPFIX(	addeq	r2, r2, #4	)
165b059bdc3SRussell King	str	r3, [sp, #-4]!		@ save the "real" r0 copied
166ccea7a19SRussell King					@ from the exception stack
167ccea7a19SRussell King
168b059bdc3SRussell King	mov	r3, lr
1691da177e4SLinus Torvalds
1701da177e4SLinus Torvalds	@
1711da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
1721da177e4SLinus Torvalds	@
173b059bdc3SRussell King	@  r2 - sp_svc
174b059bdc3SRussell King	@  r3 - lr_svc
175b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
176b059bdc3SRussell King	@  r5 - spsr_<exception>
177b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
1781da177e4SLinus Torvalds	@
179b059bdc3SRussell King	stmia	r7, {r2 - r6}
180f2741b78SRussell King
181e6978e4bSRussell King	get_thread_info tsk
182e6978e4bSRussell King	ldr	r0, [tsk, #TI_ADDR_LIMIT]
183e6978e4bSRussell King	mov	r1, #TASK_SIZE
184e6978e4bSRussell King	str	r1, [tsk, #TI_ADDR_LIMIT]
185e6978e4bSRussell King	str	r0, [sp, #SVC_ADDR_LIMIT]
186e6978e4bSRussell King
1872190fed6SRussell King	uaccess_save r0
1882190fed6SRussell King	.if \uaccess
1892190fed6SRussell King	uaccess_disable r0
1902190fed6SRussell King	.endif
1912190fed6SRussell King
192c0e7f7eeSDaniel Thompson	.if \trace
193f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
194f2741b78SRussell King	bl	trace_hardirqs_off
195f2741b78SRussell King#endif
196c0e7f7eeSDaniel Thompson	.endif
1971da177e4SLinus Torvalds	.endm
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds	.align	5
2001da177e4SLinus Torvalds__dabt_svc:
2012190fed6SRussell King	svc_entry uaccess=0
2021da177e4SLinus Torvalds	mov	r2, sp
203da740472SRussell King	dabt_helper
204e16b31bfSMarc Zyngier THUMB(	ldr	r5, [sp, #S_PSR]	)	@ potentially updated CPSR
205b059bdc3SRussell King	svc_exit r5				@ return from exception
206c4c5716eSCatalin Marinas UNWIND(.fnend		)
20793ed3970SCatalin MarinasENDPROC(__dabt_svc)
2081da177e4SLinus Torvalds
2091da177e4SLinus Torvalds	.align	5
2101da177e4SLinus Torvalds__irq_svc:
211ccea7a19SRussell King	svc_entry
2121613cc11SRussell King	irq_handler
2131613cc11SRussell King
2141da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
215706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
216706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get flags
21728fab1a2SRussell King	teq	r8, #0				@ if preempt count != 0
21828fab1a2SRussell King	movne	r0, #0				@ force flags to 0
2191da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2201da177e4SLinus Torvalds	blne	svc_preempt
2211da177e4SLinus Torvalds#endif
22230891c90SRussell King
2239b56febeSRussell King	svc_exit r5, irq = 1			@ return from exception
224c4c5716eSCatalin Marinas UNWIND(.fnend		)
22593ed3970SCatalin MarinasENDPROC(__irq_svc)
2261da177e4SLinus Torvalds
2271da177e4SLinus Torvalds	.ltorg
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
2301da177e4SLinus Torvaldssvc_preempt:
23128fab1a2SRussell King	mov	r8, lr
2321da177e4SLinus Torvalds1:	bl	preempt_schedule_irq		@ irq en/disable is done inside
233706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get new tasks TI_FLAGS
2341da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2356ebbf2ceSRussell King	reteq	r8				@ go again
2361da177e4SLinus Torvalds	b	1b
2371da177e4SLinus Torvalds#endif
2381da177e4SLinus Torvalds
23915ac49b6SRussell King__und_fault:
24015ac49b6SRussell King	@ Correct the PC such that it is pointing at the instruction
24115ac49b6SRussell King	@ which caused the fault.  If the faulting instruction was ARM
24215ac49b6SRussell King	@ the PC will be pointing at the next instruction, and have to
24315ac49b6SRussell King	@ subtract 4.  Otherwise, it is Thumb, and the PC will be
24415ac49b6SRussell King	@ pointing at the second half of the Thumb instruction.  We
24515ac49b6SRussell King	@ have to subtract 2.
24615ac49b6SRussell King	ldr	r2, [r0, #S_PC]
24715ac49b6SRussell King	sub	r2, r2, r1
24815ac49b6SRussell King	str	r2, [r0, #S_PC]
24915ac49b6SRussell King	b	do_undefinstr
25015ac49b6SRussell KingENDPROC(__und_fault)
25115ac49b6SRussell King
2521da177e4SLinus Torvalds	.align	5
2531da177e4SLinus Torvalds__und_svc:
254d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES
255d30a0c8bSNicolas Pitre	@ If a kprobe is about to simulate a "stmdb sp..." instruction,
256d30a0c8bSNicolas Pitre	@ it obviously needs free stack space which then will belong to
257d30a0c8bSNicolas Pitre	@ the saved context.
258a0266c21SWang Nan	svc_entry MAX_STACK_SIZE
259d30a0c8bSNicolas Pitre#else
260ccea7a19SRussell King	svc_entry
261d30a0c8bSNicolas Pitre#endif
2621da177e4SLinus Torvalds	@
2631da177e4SLinus Torvalds	@ call emulation code, which returns using r9 if it has emulated
2641da177e4SLinus Torvalds	@ the instruction, or the more conventional lr if we are to treat
2651da177e4SLinus Torvalds	@ this as a real undefined instruction
2661da177e4SLinus Torvalds	@
2671da177e4SLinus Torvalds	@  r0 - instruction
2681da177e4SLinus Torvalds	@
26983e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL
270b059bdc3SRussell King	ldr	r0, [r4, #-4]
27183e686eaSCatalin Marinas#else
27215ac49b6SRussell King	mov	r1, #2
273b059bdc3SRussell King	ldrh	r0, [r4, #-2]			@ Thumb instruction at LR - 2
27485519189SDave Martin	cmp	r0, #0xe800			@ 32-bit instruction if xx >= 0
27515ac49b6SRussell King	blo	__und_svc_fault
27615ac49b6SRussell King	ldrh	r9, [r4]			@ bottom 16 bits
27715ac49b6SRussell King	add	r4, r4, #2
27815ac49b6SRussell King	str	r4, [sp, #S_PC]
27915ac49b6SRussell King	orr	r0, r9, r0, lsl #16
28083e686eaSCatalin Marinas#endif
28114327c66SRussell King	badr	r9, __und_svc_finish
282b059bdc3SRussell King	mov	r2, r4
2831da177e4SLinus Torvalds	bl	call_fpe
2841da177e4SLinus Torvalds
28515ac49b6SRussell King	mov	r1, #4				@ PC correction to apply
28615ac49b6SRussell King__und_svc_fault:
2871da177e4SLinus Torvalds	mov	r0, sp				@ struct pt_regs *regs
28815ac49b6SRussell King	bl	__und_fault
2891da177e4SLinus Torvalds
29015ac49b6SRussell King__und_svc_finish:
29187eed3c7SRussell King	get_thread_info tsk
292b059bdc3SRussell King	ldr	r5, [sp, #S_PSR]		@ Get SVC cpsr
293b059bdc3SRussell King	svc_exit r5				@ return from exception
294c4c5716eSCatalin Marinas UNWIND(.fnend		)
29593ed3970SCatalin MarinasENDPROC(__und_svc)
2961da177e4SLinus Torvalds
2971da177e4SLinus Torvalds	.align	5
2981da177e4SLinus Torvalds__pabt_svc:
299ccea7a19SRussell King	svc_entry
3004fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
3018dfe7ac9SRussell King	pabt_helper
302b059bdc3SRussell King	svc_exit r5				@ return from exception
303c4c5716eSCatalin Marinas UNWIND(.fnend		)
30493ed3970SCatalin MarinasENDPROC(__pabt_svc)
3051da177e4SLinus Torvalds
3061da177e4SLinus Torvalds	.align	5
307c0e7f7eeSDaniel Thompson__fiq_svc:
308c0e7f7eeSDaniel Thompson	svc_entry trace=0
309c0e7f7eeSDaniel Thompson	mov	r0, sp				@ struct pt_regs *regs
310c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
311c0e7f7eeSDaniel Thompson	svc_exit_via_fiq
312c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
313c0e7f7eeSDaniel ThompsonENDPROC(__fiq_svc)
314c0e7f7eeSDaniel Thompson
315c0e7f7eeSDaniel Thompson	.align	5
31649f680eaSRussell King.LCcralign:
31749f680eaSRussell King	.word	cr_alignment
31848d7927bSPaul Brook#ifdef MULTI_DABORT
3191da177e4SLinus Torvalds.LCprocfns:
3201da177e4SLinus Torvalds	.word	processor
3211da177e4SLinus Torvalds#endif
3221da177e4SLinus Torvalds.LCfp:
3231da177e4SLinus Torvalds	.word	fp_enter
3241da177e4SLinus Torvalds
3251da177e4SLinus Torvalds/*
326c0e7f7eeSDaniel Thompson * Abort mode handlers
327c0e7f7eeSDaniel Thompson */
328c0e7f7eeSDaniel Thompson
329c0e7f7eeSDaniel Thompson@
330c0e7f7eeSDaniel Thompson@ Taking a FIQ in abort mode is similar to taking a FIQ in SVC mode
331c0e7f7eeSDaniel Thompson@ and reuses the same macros. However in abort mode we must also
332c0e7f7eeSDaniel Thompson@ save/restore lr_abt and spsr_abt to make nested aborts safe.
333c0e7f7eeSDaniel Thompson@
334c0e7f7eeSDaniel Thompson	.align 5
335c0e7f7eeSDaniel Thompson__fiq_abt:
336c0e7f7eeSDaniel Thompson	svc_entry trace=0
337c0e7f7eeSDaniel Thompson
338c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
339c0e7f7eeSDaniel Thompson THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
340c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
341c0e7f7eeSDaniel Thompson	mov	r1, lr		@ Save lr_abt
342c0e7f7eeSDaniel Thompson	mrs	r2, spsr	@ Save spsr_abt, abort is now safe
343c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
344c0e7f7eeSDaniel Thompson THUMB( mov	r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
345c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
346c0e7f7eeSDaniel Thompson	stmfd	sp!, {r1 - r2}
347c0e7f7eeSDaniel Thompson
348c0e7f7eeSDaniel Thompson	add	r0, sp, #8			@ struct pt_regs *regs
349c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
350c0e7f7eeSDaniel Thompson
351c0e7f7eeSDaniel Thompson	ldmfd	sp!, {r1 - r2}
352c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
353c0e7f7eeSDaniel Thompson THUMB( mov	r0, #ABT_MODE | PSR_I_BIT | PSR_F_BIT )
354c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
355c0e7f7eeSDaniel Thompson	mov	lr, r1		@ Restore lr_abt, abort is unsafe
356c0e7f7eeSDaniel Thompson	msr	spsr_cxsf, r2	@ Restore spsr_abt
357c0e7f7eeSDaniel Thompson ARM(	msr	cpsr_c, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
358c0e7f7eeSDaniel Thompson THUMB( mov	r0, #SVC_MODE | PSR_I_BIT | PSR_F_BIT )
359c0e7f7eeSDaniel Thompson THUMB( msr	cpsr_c, r0 )
360c0e7f7eeSDaniel Thompson
361c0e7f7eeSDaniel Thompson	svc_exit_via_fiq
362c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
363c0e7f7eeSDaniel ThompsonENDPROC(__fiq_abt)
364c0e7f7eeSDaniel Thompson
365c0e7f7eeSDaniel Thompson/*
3661da177e4SLinus Torvalds * User mode handlers
3672dede2d8SNicolas Pitre *
3685745eef6SRussell King * EABI note: sp_svc is always 64-bit aligned here, so should PT_REGS_SIZE
3691da177e4SLinus Torvalds */
3702dede2d8SNicolas Pitre
3715745eef6SRussell King#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (PT_REGS_SIZE & 7)
3722dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8"
3732dede2d8SNicolas Pitre#endif
3742dede2d8SNicolas Pitre
3752190fed6SRussell King	.macro	usr_entry, trace=1, uaccess=1
376c4c5716eSCatalin Marinas UNWIND(.fnstart	)
377c4c5716eSCatalin Marinas UNWIND(.cantunwind	)	@ don't unwind the user space
3785745eef6SRussell King	sub	sp, sp, #PT_REGS_SIZE
379b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - r12}	)
380b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}	)
381ccea7a19SRussell King
382195b58adSRussell King ATRAP(	mrc	p15, 0, r7, c1, c0, 0)
383195b58adSRussell King ATRAP(	ldr	r8, .LCcralign)
384195b58adSRussell King
385b059bdc3SRussell King	ldmia	r0, {r3 - r5}
386ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
387b059bdc3SRussell King	mov	r6, #-1			@  ""  ""     ""        ""
388ccea7a19SRussell King
389b059bdc3SRussell King	str	r3, [sp]		@ save the "real" r0 copied
390ccea7a19SRussell King					@ from the exception stack
3911da177e4SLinus Torvalds
392195b58adSRussell King ATRAP(	ldr	r8, [r8, #0])
393195b58adSRussell King
3941da177e4SLinus Torvalds	@
3951da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
3961da177e4SLinus Torvalds	@
397b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
398b059bdc3SRussell King	@  r5 - spsr_<exception>
399b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
4001da177e4SLinus Torvalds	@
4011da177e4SLinus Torvalds	@ Also, separately save sp_usr and lr_usr
4021da177e4SLinus Torvalds	@
403b059bdc3SRussell King	stmia	r0, {r4 - r6}
404b86040a5SCatalin Marinas ARM(	stmdb	r0, {sp, lr}^			)
405b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r0, r1, S_SP - S_PC	)
4061da177e4SLinus Torvalds
4072190fed6SRussell King	.if \uaccess
4082190fed6SRussell King	uaccess_disable ip
4092190fed6SRussell King	.endif
4102190fed6SRussell King
4111da177e4SLinus Torvalds	@ Enable the alignment trap while in kernel mode
412195b58adSRussell King ATRAP(	teq	r8, r7)
413195b58adSRussell King ATRAP( mcrne	p15, 0, r8, c1, c0, 0)
4141da177e4SLinus Torvalds
4151da177e4SLinus Torvalds	@
4161da177e4SLinus Torvalds	@ Clear FP to mark the first stack frame
4171da177e4SLinus Torvalds	@
4181da177e4SLinus Torvalds	zero_fp
419f2741b78SRussell King
420c0e7f7eeSDaniel Thompson	.if	\trace
42111b8b25cSRussell King#ifdef CONFIG_TRACE_IRQFLAGS
422f2741b78SRussell King	bl	trace_hardirqs_off
423f2741b78SRussell King#endif
424b0088480SKevin Hilman	ct_user_exit save = 0
425c0e7f7eeSDaniel Thompson	.endif
4261da177e4SLinus Torvalds	.endm
4271da177e4SLinus Torvalds
428b49c0f24SNicolas Pitre	.macro	kuser_cmpxchg_check
429db695c05SRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS)
430b49c0f24SNicolas Pitre#ifndef CONFIG_MMU
431b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing"
432b49c0f24SNicolas Pitre#else
433b49c0f24SNicolas Pitre	@ Make sure our user space atomic helper is restarted
434b49c0f24SNicolas Pitre	@ if it was interrupted in a critical region.  Here we
435b49c0f24SNicolas Pitre	@ perform a quick test inline since it should be false
436b49c0f24SNicolas Pitre	@ 99.9999% of the time.  The rest is done out of line.
437b059bdc3SRussell King	cmp	r4, #TASK_SIZE
43840fb79c8SNicolas Pitre	blhs	kuser_cmpxchg64_fixup
439b49c0f24SNicolas Pitre#endif
440b49c0f24SNicolas Pitre#endif
441b49c0f24SNicolas Pitre	.endm
442b49c0f24SNicolas Pitre
4431da177e4SLinus Torvalds	.align	5
4441da177e4SLinus Torvalds__dabt_usr:
4452190fed6SRussell King	usr_entry uaccess=0
446b49c0f24SNicolas Pitre	kuser_cmpxchg_check
4471da177e4SLinus Torvalds	mov	r2, sp
448da740472SRussell King	dabt_helper
449da740472SRussell King	b	ret_from_exception
450c4c5716eSCatalin Marinas UNWIND(.fnend		)
45193ed3970SCatalin MarinasENDPROC(__dabt_usr)
4521da177e4SLinus Torvalds
4531da177e4SLinus Torvalds	.align	5
4541da177e4SLinus Torvalds__irq_usr:
455ccea7a19SRussell King	usr_entry
456bc089602SRussell King	kuser_cmpxchg_check
457187a51adSRussell King	irq_handler
4581613cc11SRussell King	get_thread_info tsk
4591da177e4SLinus Torvalds	mov	why, #0
4609fc2552aSMing Lei	b	ret_to_user_from_irq
461c4c5716eSCatalin Marinas UNWIND(.fnend		)
46293ed3970SCatalin MarinasENDPROC(__irq_usr)
4631da177e4SLinus Torvalds
4641da177e4SLinus Torvalds	.ltorg
4651da177e4SLinus Torvalds
4661da177e4SLinus Torvalds	.align	5
4671da177e4SLinus Torvalds__und_usr:
4682190fed6SRussell King	usr_entry uaccess=0
469bc089602SRussell King
470b059bdc3SRussell King	mov	r2, r4
471b059bdc3SRussell King	mov	r3, r5
4721da177e4SLinus Torvalds
47315ac49b6SRussell King	@ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the
47415ac49b6SRussell King	@      faulting instruction depending on Thumb mode.
47515ac49b6SRussell King	@ r3 = regs->ARM_cpsr
4761da177e4SLinus Torvalds	@
47715ac49b6SRussell King	@ The emulation code returns using r9 if it has emulated the
47815ac49b6SRussell King	@ instruction, or the more conventional lr if we are to treat
47915ac49b6SRussell King	@ this as a real undefined instruction
4801da177e4SLinus Torvalds	@
48114327c66SRussell King	badr	r9, ret_from_exception
48215ac49b6SRussell King
4831417a6b8SCatalin Marinas	@ IRQs must be enabled before attempting to read the instruction from
4841417a6b8SCatalin Marinas	@ user space since that could cause a page/translation fault if the
4851417a6b8SCatalin Marinas	@ page table was modified by another CPU.
4861417a6b8SCatalin Marinas	enable_irq
4871417a6b8SCatalin Marinas
488cb170a45SPaul Brook	tst	r3, #PSR_T_BIT			@ Thumb mode?
48915ac49b6SRussell King	bne	__und_usr_thumb
49015ac49b6SRussell King	sub	r4, r2, #4			@ ARM instr at LR - 4
49115ac49b6SRussell King1:	ldrt	r0, [r4]
492457c2403SBen Dooks ARM_BE8(rev	r0, r0)				@ little endian instruction
493457c2403SBen Dooks
4942190fed6SRussell King	uaccess_disable ip
4952190fed6SRussell King
49615ac49b6SRussell King	@ r0 = 32-bit ARM instruction which caused the exception
49715ac49b6SRussell King	@ r2 = PC value for the following instruction (:= regs->ARM_pc)
49815ac49b6SRussell King	@ r4 = PC value for the faulting instruction
49915ac49b6SRussell King	@ lr = 32-bit undefined instruction function
50014327c66SRussell King	badr	lr, __und_usr_fault_32
50115ac49b6SRussell King	b	call_fpe
50215ac49b6SRussell King
50315ac49b6SRussell King__und_usr_thumb:
504cb170a45SPaul Brook	@ Thumb instruction
50515ac49b6SRussell King	sub	r4, r2, #2			@ First half of thumb instr at LR - 2
506ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
507ef4c5368SDave Martin/*
508ef4c5368SDave Martin * Thumb-2 instruction handling.  Note that because pre-v6 and >= v6 platforms
509ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at
510ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6.  This allows simplifying assumptions to be
511ef4c5368SDave Martin * made about .arch directives.
512ef4c5368SDave Martin */
513ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
514ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */
515ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE
516ef4c5368SDave Martin	ldr	r5, .LCcpu_architecture
517ef4c5368SDave Martin	ldr	r5, [r5]
518ef4c5368SDave Martin	cmp	r5, #CPU_ARCH_ARMv7
51915ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
520ef4c5368SDave Martin/*
521ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so
522ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless.  Temporarily
523ef4c5368SDave Martin * override the assembler target arch with the minimum required instead:
524ef4c5368SDave Martin */
525ef4c5368SDave Martin	.arch	armv6t2
526ef4c5368SDave Martin#endif
52715ac49b6SRussell King2:	ldrht	r5, [r4]
528f8fe23ecSVictor KamenskyARM_BE8(rev16	r5, r5)				@ little endian instruction
52985519189SDave Martin	cmp	r5, #0xe800			@ 32bit instruction if xx != 0
5302190fed6SRussell King	blo	__und_usr_fault_16_pan		@ 16bit undefined instruction
53115ac49b6SRussell King3:	ldrht	r0, [r2]
532f8fe23ecSVictor KamenskyARM_BE8(rev16	r0, r0)				@ little endian instruction
5332190fed6SRussell King	uaccess_disable ip
534cb170a45SPaul Brook	add	r2, r2, #2			@ r2 is PC + 2, make it PC + 4
53515ac49b6SRussell King	str	r2, [sp, #S_PC]			@ it's a 2x16bit instr, update
536cb170a45SPaul Brook	orr	r0, r0, r5, lsl #16
53714327c66SRussell King	badr	lr, __und_usr_fault_32
53815ac49b6SRussell King	@ r0 = the two 16-bit Thumb instructions which caused the exception
53915ac49b6SRussell King	@ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc)
54015ac49b6SRussell King	@ r4 = PC value for the first 16-bit Thumb instruction
54115ac49b6SRussell King	@ lr = 32bit undefined instruction function
542ef4c5368SDave Martin
543ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
544ef4c5368SDave Martin/* If the target arch was overridden, change it back: */
545ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K
546ef4c5368SDave Martin	.arch	armv6k
547cb170a45SPaul Brook#else
548ef4c5368SDave Martin	.arch	armv6
549ef4c5368SDave Martin#endif
550ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */
551ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */
55215ac49b6SRussell King	b	__und_usr_fault_16
553cb170a45SPaul Brook#endif
554c4c5716eSCatalin Marinas UNWIND(.fnend)
55593ed3970SCatalin MarinasENDPROC(__und_usr)
556cb170a45SPaul Brook
5571da177e4SLinus Torvalds/*
55815ac49b6SRussell King * The out of line fixup for the ldrt instructions above.
5591da177e4SLinus Torvalds */
560c4a84ae3SArd Biesheuvel	.pushsection .text.fixup, "ax"
561667d1b48SWill Deacon	.align	2
5623780f7abSArun K S4:	str     r4, [sp, #S_PC]			@ retry current instruction
5636ebbf2ceSRussell King	ret	r9
5644260415fSRussell King	.popsection
5654260415fSRussell King	.pushsection __ex_table,"a"
566cb170a45SPaul Brook	.long	1b, 4b
567c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
568cb170a45SPaul Brook	.long	2b, 4b
569cb170a45SPaul Brook	.long	3b, 4b
570cb170a45SPaul Brook#endif
5714260415fSRussell King	.popsection
5721da177e4SLinus Torvalds
5731da177e4SLinus Torvalds/*
5741da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction.
5751da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler.
5761da177e4SLinus Torvalds *
5771da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor
5781da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well
5791da177e4SLinus Torvalds * defined.  The only instructions that should fault are the
5801da177e4SLinus Torvalds * co-processor instructions.  However, we have to watch out
5811da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug.
5821da177e4SLinus Torvalds *
583b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all
584b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have
585b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's
586b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs
587b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the
588b5872db4SCatalin Marinas * NEON handler code.
589b5872db4SCatalin Marinas *
5901da177e4SLinus Torvalds * Emulators may wish to make use of the following registers:
59115ac49b6SRussell King *  r0  = instruction opcode (32-bit ARM or two 16-bit Thumb)
59215ac49b6SRussell King *  r2  = PC value to resume execution after successful emulation
593db6ccbb6SRussell King *  r9  = normal "successful" return address
59415ac49b6SRussell King *  r10 = this threads thread_info structure
595db6ccbb6SRussell King *  lr  = unrecognised instruction return address
5961417a6b8SCatalin Marinas * IRQs enabled, FIQs enabled.
5971da177e4SLinus Torvalds */
598cb170a45SPaul Brook	@
599cb170a45SPaul Brook	@ Fall-through from Thumb-2 __und_usr
600cb170a45SPaul Brook	@
601cb170a45SPaul Brook#ifdef CONFIG_NEON
602d3f79584SRussell King	get_thread_info r10			@ get current thread
603cb170a45SPaul Brook	adr	r6, .LCneon_thumb_opcodes
604cb170a45SPaul Brook	b	2f
605cb170a45SPaul Brook#endif
6061da177e4SLinus Torvaldscall_fpe:
607d3f79584SRussell King	get_thread_info r10			@ get current thread
608b5872db4SCatalin Marinas#ifdef CONFIG_NEON
609cb170a45SPaul Brook	adr	r6, .LCneon_arm_opcodes
610d3f79584SRussell King2:	ldr	r5, [r6], #4			@ mask value
611b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ opcode bits matching in mask
612d3f79584SRussell King	cmp	r5, #0				@ end mask?
613d3f79584SRussell King	beq	1f
614d3f79584SRussell King	and	r8, r0, r5
615b5872db4SCatalin Marinas	cmp	r8, r7				@ NEON instruction?
616b5872db4SCatalin Marinas	bne	2b
617b5872db4SCatalin Marinas	mov	r7, #1
618b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 10]	@ mark CP#10 as used
619b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 11]	@ mark CP#11 as used
620b5872db4SCatalin Marinas	b	do_vfp				@ let VFP handler handle this
621b5872db4SCatalin Marinas1:
622b5872db4SCatalin Marinas#endif
6231da177e4SLinus Torvalds	tst	r0, #0x08000000			@ only CDP/CPRT/LDC/STC have bit 27
624cb170a45SPaul Brook	tstne	r0, #0x04000000			@ bit 26 set on both ARM and Thumb-2
6256ebbf2ceSRussell King	reteq	lr
6261da177e4SLinus Torvalds	and	r8, r0, #0x00000f00		@ mask out CP number
627b86040a5SCatalin Marinas THUMB(	lsr	r8, r8, #8		)
6281da177e4SLinus Torvalds	mov	r7, #1
6291da177e4SLinus Torvalds	add	r6, r10, #TI_USED_CP
630b86040a5SCatalin Marinas ARM(	strb	r7, [r6, r8, lsr #8]	)	@ set appropriate used_cp[]
631b86040a5SCatalin Marinas THUMB(	strb	r7, [r6, r8]		)	@ set appropriate used_cp[]
6321da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT
6331da177e4SLinus Torvalds	@ Test if we need to give access to iWMMXt coprocessors
6341da177e4SLinus Torvalds	ldr	r5, [r10, #TI_FLAGS]
6351da177e4SLinus Torvalds	rsbs	r7, r8, #(1 << 8)		@ CP 0 or 1 only
636e44fc388SStefan Agner	movscs	r7, r5, lsr #(TIF_USING_IWMMXT + 1)
6371da177e4SLinus Torvalds	bcs	iwmmxt_task_enable
6381da177e4SLinus Torvalds#endif
639b86040a5SCatalin Marinas ARM(	add	pc, pc, r8, lsr #6	)
640b86040a5SCatalin Marinas THUMB(	lsl	r8, r8, #2		)
641b86040a5SCatalin Marinas THUMB(	add	pc, r8			)
642b86040a5SCatalin Marinas	nop
6431da177e4SLinus Torvalds
6446ebbf2ceSRussell King	ret.w	lr				@ CP#0
645b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#1 (FPE)
646b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#2 (FPE)
6476ebbf2ceSRussell King	ret.w	lr				@ CP#3
648c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH
649c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#4 (MaverickCrunch)
650c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#5 (MaverickCrunch)
651c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#6 (MaverickCrunch)
652c17fad11SLennert Buytenhek#else
6536ebbf2ceSRussell King	ret.w	lr				@ CP#4
6546ebbf2ceSRussell King	ret.w	lr				@ CP#5
6556ebbf2ceSRussell King	ret.w	lr				@ CP#6
656c17fad11SLennert Buytenhek#endif
6576ebbf2ceSRussell King	ret.w	lr				@ CP#7
6586ebbf2ceSRussell King	ret.w	lr				@ CP#8
6596ebbf2ceSRussell King	ret.w	lr				@ CP#9
6601da177e4SLinus Torvalds#ifdef CONFIG_VFP
661b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#10 (VFP)
662b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#11 (VFP)
6631da177e4SLinus Torvalds#else
6646ebbf2ceSRussell King	ret.w	lr				@ CP#10 (VFP)
6656ebbf2ceSRussell King	ret.w	lr				@ CP#11 (VFP)
6661da177e4SLinus Torvalds#endif
6676ebbf2ceSRussell King	ret.w	lr				@ CP#12
6686ebbf2ceSRussell King	ret.w	lr				@ CP#13
6696ebbf2ceSRussell King	ret.w	lr				@ CP#14 (Debug)
6706ebbf2ceSRussell King	ret.w	lr				@ CP#15 (Control)
6711da177e4SLinus Torvalds
672ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE
673ef4c5368SDave Martin	.align	2
674ef4c5368SDave Martin.LCcpu_architecture:
675ef4c5368SDave Martin	.word	__cpu_architecture
676ef4c5368SDave Martin#endif
677ef4c5368SDave Martin
678b5872db4SCatalin Marinas#ifdef CONFIG_NEON
679b5872db4SCatalin Marinas	.align	6
680b5872db4SCatalin Marinas
681cb170a45SPaul Brook.LCneon_arm_opcodes:
682b5872db4SCatalin Marinas	.word	0xfe000000			@ mask
683b5872db4SCatalin Marinas	.word	0xf2000000			@ opcode
684b5872db4SCatalin Marinas
685b5872db4SCatalin Marinas	.word	0xff100000			@ mask
686b5872db4SCatalin Marinas	.word	0xf4000000			@ opcode
687b5872db4SCatalin Marinas
688b5872db4SCatalin Marinas	.word	0x00000000			@ mask
689b5872db4SCatalin Marinas	.word	0x00000000			@ opcode
690cb170a45SPaul Brook
691cb170a45SPaul Brook.LCneon_thumb_opcodes:
692cb170a45SPaul Brook	.word	0xef000000			@ mask
693cb170a45SPaul Brook	.word	0xef000000			@ opcode
694cb170a45SPaul Brook
695cb170a45SPaul Brook	.word	0xff100000			@ mask
696cb170a45SPaul Brook	.word	0xf9000000			@ opcode
697cb170a45SPaul Brook
698cb170a45SPaul Brook	.word	0x00000000			@ mask
699cb170a45SPaul Brook	.word	0x00000000			@ opcode
700b5872db4SCatalin Marinas#endif
701b5872db4SCatalin Marinas
7021da177e4SLinus Torvaldsdo_fpe:
7031da177e4SLinus Torvalds	ldr	r4, .LCfp
7041da177e4SLinus Torvalds	add	r10, r10, #TI_FPSTATE		@ r10 = workspace
7051da177e4SLinus Torvalds	ldr	pc, [r4]			@ Call FP module USR entry point
7061da177e4SLinus Torvalds
7071da177e4SLinus Torvalds/*
7081da177e4SLinus Torvalds * The FP module is called with these registers set:
7091da177e4SLinus Torvalds *  r0  = instruction
7101da177e4SLinus Torvalds *  r2  = PC+4
7111da177e4SLinus Torvalds *  r9  = normal "successful" return address
7121da177e4SLinus Torvalds *  r10 = FP workspace
7131da177e4SLinus Torvalds *  lr  = unrecognised FP instruction return address
7141da177e4SLinus Torvalds */
7151da177e4SLinus Torvalds
716124efc27SSantosh Shilimkar	.pushsection .data
7171abd3502SRussell King	.align	2
7181da177e4SLinus TorvaldsENTRY(fp_enter)
719db6ccbb6SRussell King	.word	no_fp
720124efc27SSantosh Shilimkar	.popsection
7211da177e4SLinus Torvalds
72283e686eaSCatalin MarinasENTRY(no_fp)
7236ebbf2ceSRussell King	ret	lr
72483e686eaSCatalin MarinasENDPROC(no_fp)
725db6ccbb6SRussell King
72615ac49b6SRussell King__und_usr_fault_32:
72715ac49b6SRussell King	mov	r1, #4
72815ac49b6SRussell King	b	1f
7292190fed6SRussell King__und_usr_fault_16_pan:
7302190fed6SRussell King	uaccess_disable ip
73115ac49b6SRussell King__und_usr_fault_16:
73215ac49b6SRussell King	mov	r1, #2
7331417a6b8SCatalin Marinas1:	mov	r0, sp
73414327c66SRussell King	badr	lr, ret_from_exception
73515ac49b6SRussell King	b	__und_fault
73615ac49b6SRussell KingENDPROC(__und_usr_fault_32)
73715ac49b6SRussell KingENDPROC(__und_usr_fault_16)
7381da177e4SLinus Torvalds
7391da177e4SLinus Torvalds	.align	5
7401da177e4SLinus Torvalds__pabt_usr:
741ccea7a19SRussell King	usr_entry
7424fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
7438dfe7ac9SRussell King	pabt_helper
744c4c5716eSCatalin Marinas UNWIND(.fnend		)
7451da177e4SLinus Torvalds	/* fall through */
7461da177e4SLinus Torvalds/*
7471da177e4SLinus Torvalds * This is the return code to user mode for abort handlers
7481da177e4SLinus Torvalds */
7491da177e4SLinus TorvaldsENTRY(ret_from_exception)
750c4c5716eSCatalin Marinas UNWIND(.fnstart	)
751c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7521da177e4SLinus Torvalds	get_thread_info tsk
7531da177e4SLinus Torvalds	mov	why, #0
7541da177e4SLinus Torvalds	b	ret_to_user
755c4c5716eSCatalin Marinas UNWIND(.fnend		)
75693ed3970SCatalin MarinasENDPROC(__pabt_usr)
75793ed3970SCatalin MarinasENDPROC(ret_from_exception)
7581da177e4SLinus Torvalds
759c0e7f7eeSDaniel Thompson	.align	5
760c0e7f7eeSDaniel Thompson__fiq_usr:
761c0e7f7eeSDaniel Thompson	usr_entry trace=0
762c0e7f7eeSDaniel Thompson	kuser_cmpxchg_check
763c0e7f7eeSDaniel Thompson	mov	r0, sp				@ struct pt_regs *regs
764c0e7f7eeSDaniel Thompson	bl	handle_fiq_as_nmi
765c0e7f7eeSDaniel Thompson	get_thread_info tsk
766c0e7f7eeSDaniel Thompson	restore_user_regs fast = 0, offset = 0
767c0e7f7eeSDaniel Thompson UNWIND(.fnend		)
768c0e7f7eeSDaniel ThompsonENDPROC(__fiq_usr)
769c0e7f7eeSDaniel Thompson
7701da177e4SLinus Torvalds/*
7711da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors
7721da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
7731da177e4SLinus Torvalds * previous and next are guaranteed not to be the same.
7741da177e4SLinus Torvalds */
7751da177e4SLinus TorvaldsENTRY(__switch_to)
776c4c5716eSCatalin Marinas UNWIND(.fnstart	)
777c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7781da177e4SLinus Torvalds	add	ip, r1, #TI_CPU_SAVE
779b86040a5SCatalin Marinas ARM(	stmia	ip!, {r4 - sl, fp, sp, lr} )	@ Store most regs on stack
780b86040a5SCatalin Marinas THUMB(	stmia	ip!, {r4 - sl, fp}	   )	@ Store most regs on stack
781b86040a5SCatalin Marinas THUMB(	str	sp, [ip], #4		   )
782b86040a5SCatalin Marinas THUMB(	str	lr, [ip], #4		   )
783a4780adeSAndré Hentschel	ldr	r4, [r2, #TI_TP_VALUE]
784a4780adeSAndré Hentschel	ldr	r5, [r2, #TI_TP_VALUE + 4]
785247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
7861eef5d2fSRussell King	mrc	p15, 0, r6, c3, c0, 0		@ Get domain register
7871eef5d2fSRussell King	str	r6, [r1, #TI_CPU_DOMAIN]	@ Save old domain register
788d6551e88SRussell King	ldr	r6, [r2, #TI_CPU_DOMAIN]
789afeb90caSHyok S. Choi#endif
790a4780adeSAndré Hentschel	switch_tls r1, r4, r5, r3, r7
791050e9baaSLinus Torvalds#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
792df0698beSNicolas Pitre	ldr	r7, [r2, #TI_TASK]
793df0698beSNicolas Pitre	ldr	r8, =__stack_chk_guard
794ffa47aa6SArnd Bergmann	.if (TSK_STACK_CANARY > IMM12_MASK)
795ffa47aa6SArnd Bergmann	add	r7, r7, #TSK_STACK_CANARY & ~IMM12_MASK
796ffa47aa6SArnd Bergmann	.endif
797ffa47aa6SArnd Bergmann	ldr	r7, [r7, #TSK_STACK_CANARY & IMM12_MASK]
798df0698beSNicolas Pitre#endif
799247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
8001da177e4SLinus Torvalds	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
801afeb90caSHyok S. Choi#endif
802d6551e88SRussell King	mov	r5, r0
803d6551e88SRussell King	add	r4, r2, #TI_CPU_SAVE
804d6551e88SRussell King	ldr	r0, =thread_notify_head
805d6551e88SRussell King	mov	r1, #THREAD_NOTIFY_SWITCH
806d6551e88SRussell King	bl	atomic_notifier_call_chain
807050e9baaSLinus Torvalds#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
808df0698beSNicolas Pitre	str	r7, [r8]
809df0698beSNicolas Pitre#endif
810b86040a5SCatalin Marinas THUMB(	mov	ip, r4			   )
811d6551e88SRussell King	mov	r0, r5
812b86040a5SCatalin Marinas ARM(	ldmia	r4, {r4 - sl, fp, sp, pc}  )	@ Load all regs saved previously
813b86040a5SCatalin Marinas THUMB(	ldmia	ip!, {r4 - sl, fp}	   )	@ Load all regs saved previously
814b86040a5SCatalin Marinas THUMB(	ldr	sp, [ip], #4		   )
815b86040a5SCatalin Marinas THUMB(	ldr	pc, [ip]		   )
816c4c5716eSCatalin Marinas UNWIND(.fnend		)
81793ed3970SCatalin MarinasENDPROC(__switch_to)
8181da177e4SLinus Torvalds
8191da177e4SLinus Torvalds	__INIT
8202d2669b6SNicolas Pitre
8212d2669b6SNicolas Pitre/*
8222d2669b6SNicolas Pitre * User helpers.
8232d2669b6SNicolas Pitre *
8242d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high
8252d2669b6SNicolas Pitre * vector page.  New segments (if ever needed) must be added in front of
8262d2669b6SNicolas Pitre * existing ones.  This mechanism should be used only for things that are
8272d2669b6SNicolas Pitre * really small and justified, and not be abused freely.
8282d2669b6SNicolas Pitre *
82937b83046SNicolas Pitre * See Documentation/arm/kernel_user_helpers.txt for formal definitions.
8302d2669b6SNicolas Pitre */
831b86040a5SCatalin Marinas THUMB(	.arm	)
8322d2669b6SNicolas Pitre
833ba9b5d76SNicolas Pitre	.macro	usr_ret, reg
834ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB
835ba9b5d76SNicolas Pitre	bx	\reg
836ba9b5d76SNicolas Pitre#else
8376ebbf2ceSRussell King	ret	\reg
838ba9b5d76SNicolas Pitre#endif
839ba9b5d76SNicolas Pitre	.endm
840ba9b5d76SNicolas Pitre
8415b43e7a3SRussell King	.macro	kuser_pad, sym, size
8425b43e7a3SRussell King	.if	(. - \sym) & 3
8435b43e7a3SRussell King	.rept	4 - (. - \sym) & 3
8445b43e7a3SRussell King	.byte	0
8455b43e7a3SRussell King	.endr
8465b43e7a3SRussell King	.endif
8475b43e7a3SRussell King	.rept	(\size - (. - \sym)) / 4
8485b43e7a3SRussell King	.word	0xe7fddef1
8495b43e7a3SRussell King	.endr
8505b43e7a3SRussell King	.endm
8515b43e7a3SRussell King
852f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS
8532d2669b6SNicolas Pitre	.align	5
8542d2669b6SNicolas Pitre	.globl	__kuser_helper_start
8552d2669b6SNicolas Pitre__kuser_helper_start:
8562d2669b6SNicolas Pitre
8572d2669b6SNicolas Pitre/*
85840fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular
85940fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point.
8607c612bfdSNicolas Pitre */
8617c612bfdSNicolas Pitre
86240fb79c8SNicolas Pitre__kuser_cmpxchg64:				@ 0xffff0f60
86340fb79c8SNicolas Pitre
864db695c05SRussell King#if defined(CONFIG_CPU_32v6K)
86540fb79c8SNicolas Pitre
86640fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, r7}
86740fb79c8SNicolas Pitre	ldrd	r4, r5, [r0]			@ load old val
86840fb79c8SNicolas Pitre	ldrd	r6, r7, [r1]			@ load new val
86940fb79c8SNicolas Pitre	smp_dmb	arm
87040fb79c8SNicolas Pitre1:	ldrexd	r0, r1, [r2]			@ load current val
87140fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
872e44fc388SStefan Agner	eorseq	r3, r1, r5			@ compare with oldval (2)
87340fb79c8SNicolas Pitre	strexdeq r3, r6, r7, [r2]		@ store newval if eq
87440fb79c8SNicolas Pitre	teqeq	r3, #1				@ success?
87540fb79c8SNicolas Pitre	beq	1b				@ if no then retry
87640fb79c8SNicolas Pitre	smp_dmb	arm
87740fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set returned val and C flag
87840fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, r7}
8795a97d0aeSWill Deacon	usr_ret	lr
88040fb79c8SNicolas Pitre
88140fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP)
88240fb79c8SNicolas Pitre
88340fb79c8SNicolas Pitre#ifdef CONFIG_MMU
88440fb79c8SNicolas Pitre
88540fb79c8SNicolas Pitre	/*
88640fb79c8SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg64
88740fb79c8SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
88840fb79c8SNicolas Pitre	 * causing another process/thread to be scheduled in the middle of
88940fb79c8SNicolas Pitre	 * the critical sequence.  The same strategy as for cmpxchg is used.
89040fb79c8SNicolas Pitre	 */
89140fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, lr}
89240fb79c8SNicolas Pitre	ldmia	r0, {r4, r5}			@ load old val
89340fb79c8SNicolas Pitre	ldmia	r1, {r6, lr}			@ load new val
89440fb79c8SNicolas Pitre1:	ldmia	r2, {r0, r1}			@ load current val
89540fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
896e44fc388SStefan Agner	eorseq	r3, r1, r5			@ compare with oldval (2)
897e44fc388SStefan Agner2:	stmiaeq	r2, {r6, lr}			@ store newval if eq
89840fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
89940fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, pc}
90040fb79c8SNicolas Pitre
90140fb79c8SNicolas Pitre	.text
90240fb79c8SNicolas Pitrekuser_cmpxchg64_fixup:
90340fb79c8SNicolas Pitre	@ Called from kuser_cmpxchg_fixup.
9043ad55155SRussell King	@ r4 = address of interrupted insn (must be preserved).
90540fb79c8SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
90640fb79c8SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
9073ad55155SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
90840fb79c8SNicolas Pitre	mov	r7, #0xffff0fff
90940fb79c8SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
9103ad55155SRussell King	subs	r8, r4, r7
911e44fc388SStefan Agner	rsbscs	r8, r8, #(2b - 1b)
91240fb79c8SNicolas Pitre	strcs	r7, [sp, #S_PC]
91340fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6
91440fb79c8SNicolas Pitre	bcc	kuser_cmpxchg32_fixup
91540fb79c8SNicolas Pitre#endif
9166ebbf2ceSRussell King	ret	lr
91740fb79c8SNicolas Pitre	.previous
91840fb79c8SNicolas Pitre
91940fb79c8SNicolas Pitre#else
92040fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing"
92140fb79c8SNicolas Pitre	mov	r0, #-1
92240fb79c8SNicolas Pitre	adds	r0, r0, #0
92340fb79c8SNicolas Pitre	usr_ret	lr
92440fb79c8SNicolas Pitre#endif
92540fb79c8SNicolas Pitre
92640fb79c8SNicolas Pitre#else
92740fb79c8SNicolas Pitre#error "incoherent kernel configuration"
92840fb79c8SNicolas Pitre#endif
92940fb79c8SNicolas Pitre
9305b43e7a3SRussell King	kuser_pad __kuser_cmpxchg64, 64
93140fb79c8SNicolas Pitre
9327c612bfdSNicolas Pitre__kuser_memory_barrier:				@ 0xffff0fa0
933ed3768a8SDave Martin	smp_dmb	arm
934ba9b5d76SNicolas Pitre	usr_ret	lr
9357c612bfdSNicolas Pitre
9365b43e7a3SRussell King	kuser_pad __kuser_memory_barrier, 32
9377c612bfdSNicolas Pitre
9382d2669b6SNicolas Pitre__kuser_cmpxchg:				@ 0xffff0fc0
9392d2669b6SNicolas Pitre
940db695c05SRussell King#if __LINUX_ARM_ARCH__ < 6
9412d2669b6SNicolas Pitre
94249bca4c2SNicolas Pitre#ifdef CONFIG_MMU
943b49c0f24SNicolas Pitre
944b49c0f24SNicolas Pitre	/*
945b49c0f24SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg
946b49c0f24SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
947b49c0f24SNicolas Pitre	 * causing another process/thread to be scheduled in the middle
948b49c0f24SNicolas Pitre	 * of the critical sequence.  To prevent this, code is added to
949b49c0f24SNicolas Pitre	 * the IRQ and data abort exception handlers to set the pc back
950b49c0f24SNicolas Pitre	 * to the beginning of the critical section if it is found to be
951b49c0f24SNicolas Pitre	 * within that critical section (see kuser_cmpxchg_fixup).
952b49c0f24SNicolas Pitre	 */
953b49c0f24SNicolas Pitre1:	ldr	r3, [r2]			@ load current val
954b49c0f24SNicolas Pitre	subs	r3, r3, r0			@ compare with oldval
955b49c0f24SNicolas Pitre2:	streq	r1, [r2]			@ store newval if eq
956b49c0f24SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
957b49c0f24SNicolas Pitre	usr_ret	lr
958b49c0f24SNicolas Pitre
959b49c0f24SNicolas Pitre	.text
96040fb79c8SNicolas Pitrekuser_cmpxchg32_fixup:
961b49c0f24SNicolas Pitre	@ Called from kuser_cmpxchg_check macro.
962b059bdc3SRussell King	@ r4 = address of interrupted insn (must be preserved).
963b49c0f24SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
964b49c0f24SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
965b059bdc3SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
966b49c0f24SNicolas Pitre	mov	r7, #0xffff0fff
967b49c0f24SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
968b059bdc3SRussell King	subs	r8, r4, r7
969e44fc388SStefan Agner	rsbscs	r8, r8, #(2b - 1b)
970b49c0f24SNicolas Pitre	strcs	r7, [sp, #S_PC]
9716ebbf2ceSRussell King	ret	lr
972b49c0f24SNicolas Pitre	.previous
973b49c0f24SNicolas Pitre
97449bca4c2SNicolas Pitre#else
97549bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing"
97649bca4c2SNicolas Pitre	mov	r0, #-1
97749bca4c2SNicolas Pitre	adds	r0, r0, #0
978ba9b5d76SNicolas Pitre	usr_ret	lr
979b49c0f24SNicolas Pitre#endif
9802d2669b6SNicolas Pitre
9812d2669b6SNicolas Pitre#else
9822d2669b6SNicolas Pitre
983ed3768a8SDave Martin	smp_dmb	arm
984b49c0f24SNicolas Pitre1:	ldrex	r3, [r2]
9852d2669b6SNicolas Pitre	subs	r3, r3, r0
9862d2669b6SNicolas Pitre	strexeq	r3, r1, [r2]
987b49c0f24SNicolas Pitre	teqeq	r3, #1
988b49c0f24SNicolas Pitre	beq	1b
9892d2669b6SNicolas Pitre	rsbs	r0, r3, #0
990b49c0f24SNicolas Pitre	/* beware -- each __kuser slot must be 8 instructions max */
991f00ec48fSRussell King	ALT_SMP(b	__kuser_memory_barrier)
992f00ec48fSRussell King	ALT_UP(usr_ret	lr)
9932d2669b6SNicolas Pitre
9942d2669b6SNicolas Pitre#endif
9952d2669b6SNicolas Pitre
9965b43e7a3SRussell King	kuser_pad __kuser_cmpxchg, 32
9972d2669b6SNicolas Pitre
9982d2669b6SNicolas Pitre__kuser_get_tls:				@ 0xffff0fe0
999f159f4edSTony Lindgren	ldr	r0, [pc, #(16 - 8)]	@ read TLS, set in kuser_get_tls_init
1000ba9b5d76SNicolas Pitre	usr_ret	lr
1001f159f4edSTony Lindgren	mrc	p15, 0, r0, c13, c0, 3	@ 0xffff0fe8 hardware TLS code
10025b43e7a3SRussell King	kuser_pad __kuser_get_tls, 16
10035b43e7a3SRussell King	.rep	3
1004f159f4edSTony Lindgren	.word	0			@ 0xffff0ff0 software TLS value, then
1005f159f4edSTony Lindgren	.endr				@ pad up to __kuser_helper_version
10062d2669b6SNicolas Pitre
10072d2669b6SNicolas Pitre__kuser_helper_version:				@ 0xffff0ffc
10082d2669b6SNicolas Pitre	.word	((__kuser_helper_end - __kuser_helper_start) >> 5)
10092d2669b6SNicolas Pitre
10102d2669b6SNicolas Pitre	.globl	__kuser_helper_end
10112d2669b6SNicolas Pitre__kuser_helper_end:
10122d2669b6SNicolas Pitre
1013f6f91b0dSRussell King#endif
1014f6f91b0dSRussell King
1015b86040a5SCatalin Marinas THUMB(	.thumb	)
10162d2669b6SNicolas Pitre
10171da177e4SLinus Torvalds/*
10181da177e4SLinus Torvalds * Vector stubs.
10191da177e4SLinus Torvalds *
102019accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the
102119accfd3SRussell King * vectors, rather than ldr's.  Note that this code must not exceed
102219accfd3SRussell King * a page size.
10231da177e4SLinus Torvalds *
10241da177e4SLinus Torvalds * Common stub entry macro:
10251da177e4SLinus Torvalds *   Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
1026ccea7a19SRussell King *
1027ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address
1028ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler.
10291da177e4SLinus Torvalds */
1030b7ec4795SNicolas Pitre	.macro	vector_stub, name, mode, correction=0
10311da177e4SLinus Torvalds	.align	5
10321da177e4SLinus Torvalds
10331da177e4SLinus Torvaldsvector_\name:
10341da177e4SLinus Torvalds	.if \correction
10351da177e4SLinus Torvalds	sub	lr, lr, #\correction
10361da177e4SLinus Torvalds	.endif
10371da177e4SLinus Torvalds
1038ccea7a19SRussell King	@
1039ccea7a19SRussell King	@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1040ccea7a19SRussell King	@ (parent CPSR)
1041ccea7a19SRussell King	@
1042ccea7a19SRussell King	stmia	sp, {r0, lr}		@ save r0, lr
1043ccea7a19SRussell King	mrs	lr, spsr
1044ccea7a19SRussell King	str	lr, [sp, #8]		@ save spsr
1045ccea7a19SRussell King
1046ccea7a19SRussell King	@
1047ccea7a19SRussell King	@ Prepare for SVC32 mode.  IRQs remain disabled.
1048ccea7a19SRussell King	@
1049ccea7a19SRussell King	mrs	r0, cpsr
1050b86040a5SCatalin Marinas	eor	r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
1051ccea7a19SRussell King	msr	spsr_cxsf, r0
1052ccea7a19SRussell King
1053ccea7a19SRussell King	@
1054ccea7a19SRussell King	@ the branch table must immediately follow this code
1055ccea7a19SRussell King	@
1056ccea7a19SRussell King	and	lr, lr, #0x0f
1057b86040a5SCatalin Marinas THUMB(	adr	r0, 1f			)
1058b86040a5SCatalin Marinas THUMB(	ldr	lr, [r0, lr, lsl #2]	)
1059b7ec4795SNicolas Pitre	mov	r0, sp
1060b86040a5SCatalin Marinas ARM(	ldr	lr, [pc, lr, lsl #2]	)
1061ccea7a19SRussell King	movs	pc, lr			@ branch to handler in SVC mode
106293ed3970SCatalin MarinasENDPROC(vector_\name)
106388987ef9SCatalin Marinas
106488987ef9SCatalin Marinas	.align	2
106588987ef9SCatalin Marinas	@ handler addresses follow this label
106688987ef9SCatalin Marinas1:
10671da177e4SLinus Torvalds	.endm
10681da177e4SLinus Torvalds
1069b9b32bf7SRussell King	.section .stubs, "ax", %progbits
107019accfd3SRussell King	@ This must be the first word
107119accfd3SRussell King	.word	vector_swi
107219accfd3SRussell King
107319accfd3SRussell Kingvector_rst:
107419accfd3SRussell King ARM(	swi	SYS_ERROR0	)
107519accfd3SRussell King THUMB(	svc	#0		)
107619accfd3SRussell King THUMB(	nop			)
107719accfd3SRussell King	b	vector_und
107819accfd3SRussell King
10791da177e4SLinus Torvalds/*
10801da177e4SLinus Torvalds * Interrupt dispatcher
10811da177e4SLinus Torvalds */
1082b7ec4795SNicolas Pitre	vector_stub	irq, IRQ_MODE, 4
10831da177e4SLinus Torvalds
10841da177e4SLinus Torvalds	.long	__irq_usr			@  0  (USR_26 / USR_32)
10851da177e4SLinus Torvalds	.long	__irq_invalid			@  1  (FIQ_26 / FIQ_32)
10861da177e4SLinus Torvalds	.long	__irq_invalid			@  2  (IRQ_26 / IRQ_32)
10871da177e4SLinus Torvalds	.long	__irq_svc			@  3  (SVC_26 / SVC_32)
10881da177e4SLinus Torvalds	.long	__irq_invalid			@  4
10891da177e4SLinus Torvalds	.long	__irq_invalid			@  5
10901da177e4SLinus Torvalds	.long	__irq_invalid			@  6
10911da177e4SLinus Torvalds	.long	__irq_invalid			@  7
10921da177e4SLinus Torvalds	.long	__irq_invalid			@  8
10931da177e4SLinus Torvalds	.long	__irq_invalid			@  9
10941da177e4SLinus Torvalds	.long	__irq_invalid			@  a
10951da177e4SLinus Torvalds	.long	__irq_invalid			@  b
10961da177e4SLinus Torvalds	.long	__irq_invalid			@  c
10971da177e4SLinus Torvalds	.long	__irq_invalid			@  d
10981da177e4SLinus Torvalds	.long	__irq_invalid			@  e
10991da177e4SLinus Torvalds	.long	__irq_invalid			@  f
11001da177e4SLinus Torvalds
11011da177e4SLinus Torvalds/*
11021da177e4SLinus Torvalds * Data abort dispatcher
11031da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
11041da177e4SLinus Torvalds */
1105b7ec4795SNicolas Pitre	vector_stub	dabt, ABT_MODE, 8
11061da177e4SLinus Torvalds
11071da177e4SLinus Torvalds	.long	__dabt_usr			@  0  (USR_26 / USR_32)
11081da177e4SLinus Torvalds	.long	__dabt_invalid			@  1  (FIQ_26 / FIQ_32)
11091da177e4SLinus Torvalds	.long	__dabt_invalid			@  2  (IRQ_26 / IRQ_32)
11101da177e4SLinus Torvalds	.long	__dabt_svc			@  3  (SVC_26 / SVC_32)
11111da177e4SLinus Torvalds	.long	__dabt_invalid			@  4
11121da177e4SLinus Torvalds	.long	__dabt_invalid			@  5
11131da177e4SLinus Torvalds	.long	__dabt_invalid			@  6
11141da177e4SLinus Torvalds	.long	__dabt_invalid			@  7
11151da177e4SLinus Torvalds	.long	__dabt_invalid			@  8
11161da177e4SLinus Torvalds	.long	__dabt_invalid			@  9
11171da177e4SLinus Torvalds	.long	__dabt_invalid			@  a
11181da177e4SLinus Torvalds	.long	__dabt_invalid			@  b
11191da177e4SLinus Torvalds	.long	__dabt_invalid			@  c
11201da177e4SLinus Torvalds	.long	__dabt_invalid			@  d
11211da177e4SLinus Torvalds	.long	__dabt_invalid			@  e
11221da177e4SLinus Torvalds	.long	__dabt_invalid			@  f
11231da177e4SLinus Torvalds
11241da177e4SLinus Torvalds/*
11251da177e4SLinus Torvalds * Prefetch abort dispatcher
11261da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
11271da177e4SLinus Torvalds */
1128b7ec4795SNicolas Pitre	vector_stub	pabt, ABT_MODE, 4
11291da177e4SLinus Torvalds
11301da177e4SLinus Torvalds	.long	__pabt_usr			@  0 (USR_26 / USR_32)
11311da177e4SLinus Torvalds	.long	__pabt_invalid			@  1 (FIQ_26 / FIQ_32)
11321da177e4SLinus Torvalds	.long	__pabt_invalid			@  2 (IRQ_26 / IRQ_32)
11331da177e4SLinus Torvalds	.long	__pabt_svc			@  3 (SVC_26 / SVC_32)
11341da177e4SLinus Torvalds	.long	__pabt_invalid			@  4
11351da177e4SLinus Torvalds	.long	__pabt_invalid			@  5
11361da177e4SLinus Torvalds	.long	__pabt_invalid			@  6
11371da177e4SLinus Torvalds	.long	__pabt_invalid			@  7
11381da177e4SLinus Torvalds	.long	__pabt_invalid			@  8
11391da177e4SLinus Torvalds	.long	__pabt_invalid			@  9
11401da177e4SLinus Torvalds	.long	__pabt_invalid			@  a
11411da177e4SLinus Torvalds	.long	__pabt_invalid			@  b
11421da177e4SLinus Torvalds	.long	__pabt_invalid			@  c
11431da177e4SLinus Torvalds	.long	__pabt_invalid			@  d
11441da177e4SLinus Torvalds	.long	__pabt_invalid			@  e
11451da177e4SLinus Torvalds	.long	__pabt_invalid			@  f
11461da177e4SLinus Torvalds
11471da177e4SLinus Torvalds/*
11481da177e4SLinus Torvalds * Undef instr entry dispatcher
11491da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
11501da177e4SLinus Torvalds */
1151b7ec4795SNicolas Pitre	vector_stub	und, UND_MODE
11521da177e4SLinus Torvalds
11531da177e4SLinus Torvalds	.long	__und_usr			@  0 (USR_26 / USR_32)
11541da177e4SLinus Torvalds	.long	__und_invalid			@  1 (FIQ_26 / FIQ_32)
11551da177e4SLinus Torvalds	.long	__und_invalid			@  2 (IRQ_26 / IRQ_32)
11561da177e4SLinus Torvalds	.long	__und_svc			@  3 (SVC_26 / SVC_32)
11571da177e4SLinus Torvalds	.long	__und_invalid			@  4
11581da177e4SLinus Torvalds	.long	__und_invalid			@  5
11591da177e4SLinus Torvalds	.long	__und_invalid			@  6
11601da177e4SLinus Torvalds	.long	__und_invalid			@  7
11611da177e4SLinus Torvalds	.long	__und_invalid			@  8
11621da177e4SLinus Torvalds	.long	__und_invalid			@  9
11631da177e4SLinus Torvalds	.long	__und_invalid			@  a
11641da177e4SLinus Torvalds	.long	__und_invalid			@  b
11651da177e4SLinus Torvalds	.long	__und_invalid			@  c
11661da177e4SLinus Torvalds	.long	__und_invalid			@  d
11671da177e4SLinus Torvalds	.long	__und_invalid			@  e
11681da177e4SLinus Torvalds	.long	__und_invalid			@  f
11691da177e4SLinus Torvalds
11701da177e4SLinus Torvalds	.align	5
11711da177e4SLinus Torvalds
11721da177e4SLinus Torvalds/*=============================================================================
117319accfd3SRussell King * Address exception handler
117419accfd3SRussell King *-----------------------------------------------------------------------------
117519accfd3SRussell King * These aren't too critical.
117619accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode).
117719accfd3SRussell King */
117819accfd3SRussell King
117919accfd3SRussell Kingvector_addrexcptn:
118019accfd3SRussell King	b	vector_addrexcptn
118119accfd3SRussell King
118219accfd3SRussell King/*=============================================================================
1183c0e7f7eeSDaniel Thompson * FIQ "NMI" handler
11841da177e4SLinus Torvalds *-----------------------------------------------------------------------------
1185c0e7f7eeSDaniel Thompson * Handle a FIQ using the SVC stack allowing FIQ act like NMI on x86
1186c0e7f7eeSDaniel Thompson * systems.
11871da177e4SLinus Torvalds */
1188c0e7f7eeSDaniel Thompson	vector_stub	fiq, FIQ_MODE, 4
1189c0e7f7eeSDaniel Thompson
1190c0e7f7eeSDaniel Thompson	.long	__fiq_usr			@  0  (USR_26 / USR_32)
1191c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  1  (FIQ_26 / FIQ_32)
1192c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  2  (IRQ_26 / IRQ_32)
1193c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  3  (SVC_26 / SVC_32)
1194c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  4
1195c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  5
1196c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  6
1197c0e7f7eeSDaniel Thompson	.long	__fiq_abt			@  7
1198c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  8
1199c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  9
1200c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  a
1201c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  b
1202c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  c
1203c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  d
1204c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  e
1205c0e7f7eeSDaniel Thompson	.long	__fiq_svc			@  f
12061da177e4SLinus Torvalds
120731b96caeSArd Biesheuvel	.globl	vector_fiq
1208e39e3f3eSRussell King
1209b9b32bf7SRussell King	.section .vectors, "ax", %progbits
1210b48da558SArd Biesheuvel.L__vectors_start:
1211b9b32bf7SRussell King	W(b)	vector_rst
1212b9b32bf7SRussell King	W(b)	vector_und
1213b48da558SArd Biesheuvel	W(ldr)	pc, .L__vectors_start + 0x1000
1214b9b32bf7SRussell King	W(b)	vector_pabt
1215b9b32bf7SRussell King	W(b)	vector_dabt
1216b9b32bf7SRussell King	W(b)	vector_addrexcptn
1217b9b32bf7SRussell King	W(b)	vector_irq
1218b9b32bf7SRussell King	W(b)	vector_fiq
12191da177e4SLinus Torvalds
12201da177e4SLinus Torvalds	.data
12211abd3502SRussell King	.align	2
12221da177e4SLinus Torvalds
12231da177e4SLinus Torvalds	.globl	cr_alignment
12241da177e4SLinus Torvaldscr_alignment:
12251da177e4SLinus Torvalds	.space	4
1226