xref: /openbmc/linux/arch/arm/kernel/entry-armv.S (revision d3f79584a8b59a6760a8fe465b22e54081eaeb5e)
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
149d30a0c8bSNicolas Pitre	.macro	svc_entry, stack_hole=0
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
185f2741b78SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
186f2741b78SRussell King	bl	trace_hardirqs_off
187f2741b78SRussell King#endif
1881da177e4SLinus Torvalds	.endm
1891da177e4SLinus Torvalds
1901da177e4SLinus Torvalds	.align	5
1911da177e4SLinus Torvalds__dabt_svc:
192ccea7a19SRussell King	svc_entry
1931da177e4SLinus Torvalds	mov	r2, sp
194da740472SRussell King	dabt_helper
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds	@
1971da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
1981da177e4SLinus Torvalds	@
199ac78884eSRussell King	disable_irq_notrace
2001da177e4SLinus Torvalds
20102fe2845SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
20202fe2845SRussell King	tst	r5, #PSR_I_BIT
20302fe2845SRussell King	bleq	trace_hardirqs_on
20402fe2845SRussell King	tst	r5, #PSR_I_BIT
20502fe2845SRussell King	blne	trace_hardirqs_off
20602fe2845SRussell King#endif
207b059bdc3SRussell King	svc_exit r5				@ return from exception
208c4c5716eSCatalin Marinas UNWIND(.fnend		)
20993ed3970SCatalin MarinasENDPROC(__dabt_svc)
2101da177e4SLinus Torvalds
2111da177e4SLinus Torvalds	.align	5
2121da177e4SLinus Torvalds__irq_svc:
213ccea7a19SRussell King	svc_entry
2141613cc11SRussell King	irq_handler
2151613cc11SRussell King
2161da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
217706fdd9fSRussell King	get_thread_info tsk
218706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
219706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get flags
22028fab1a2SRussell King	teq	r8, #0				@ if preempt count != 0
22128fab1a2SRussell King	movne	r0, #0				@ force flags to 0
2221da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2231da177e4SLinus Torvalds	blne	svc_preempt
2241da177e4SLinus Torvalds#endif
22530891c90SRussell King
2267ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
227fbab1c80SRussell King	@ The parent context IRQs must have been enabled to get here in
228fbab1c80SRussell King	@ the first place, so there's no point checking the PSR I bit.
229fbab1c80SRussell King	bl	trace_hardirqs_on
2307ad1bcb2SRussell King#endif
231b059bdc3SRussell King	svc_exit r5				@ return from exception
232c4c5716eSCatalin Marinas UNWIND(.fnend		)
23393ed3970SCatalin MarinasENDPROC(__irq_svc)
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds	.ltorg
2361da177e4SLinus Torvalds
2371da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
2381da177e4SLinus Torvaldssvc_preempt:
23928fab1a2SRussell King	mov	r8, lr
2401da177e4SLinus Torvalds1:	bl	preempt_schedule_irq		@ irq en/disable is done inside
241706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get new tasks TI_FLAGS
2421da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
24328fab1a2SRussell King	moveq	pc, r8				@ go again
2441da177e4SLinus Torvalds	b	1b
2451da177e4SLinus Torvalds#endif
2461da177e4SLinus Torvalds
24715ac49b6SRussell King__und_fault:
24815ac49b6SRussell King	@ Correct the PC such that it is pointing at the instruction
24915ac49b6SRussell King	@ which caused the fault.  If the faulting instruction was ARM
25015ac49b6SRussell King	@ the PC will be pointing at the next instruction, and have to
25115ac49b6SRussell King	@ subtract 4.  Otherwise, it is Thumb, and the PC will be
25215ac49b6SRussell King	@ pointing at the second half of the Thumb instruction.  We
25315ac49b6SRussell King	@ have to subtract 2.
25415ac49b6SRussell King	ldr	r2, [r0, #S_PC]
25515ac49b6SRussell King	sub	r2, r2, r1
25615ac49b6SRussell King	str	r2, [r0, #S_PC]
25715ac49b6SRussell King	b	do_undefinstr
25815ac49b6SRussell KingENDPROC(__und_fault)
25915ac49b6SRussell King
2601da177e4SLinus Torvalds	.align	5
2611da177e4SLinus Torvalds__und_svc:
262d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES
263d30a0c8bSNicolas Pitre	@ If a kprobe is about to simulate a "stmdb sp..." instruction,
264d30a0c8bSNicolas Pitre	@ it obviously needs free stack space which then will belong to
265d30a0c8bSNicolas Pitre	@ the saved context.
266d30a0c8bSNicolas Pitre	svc_entry 64
267d30a0c8bSNicolas Pitre#else
268ccea7a19SRussell King	svc_entry
269d30a0c8bSNicolas Pitre#endif
2701da177e4SLinus Torvalds	@
2711da177e4SLinus Torvalds	@ call emulation code, which returns using r9 if it has emulated
2721da177e4SLinus Torvalds	@ the instruction, or the more conventional lr if we are to treat
2731da177e4SLinus Torvalds	@ this as a real undefined instruction
2741da177e4SLinus Torvalds	@
2751da177e4SLinus Torvalds	@  r0 - instruction
2761da177e4SLinus Torvalds	@
27783e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL
278b059bdc3SRussell King	ldr	r0, [r4, #-4]
27983e686eaSCatalin Marinas#else
28015ac49b6SRussell King	mov	r1, #2
281b059bdc3SRussell King	ldrh	r0, [r4, #-2]			@ Thumb instruction at LR - 2
28285519189SDave Martin	cmp	r0, #0xe800			@ 32-bit instruction if xx >= 0
28315ac49b6SRussell King	blo	__und_svc_fault
28415ac49b6SRussell King	ldrh	r9, [r4]			@ bottom 16 bits
28515ac49b6SRussell King	add	r4, r4, #2
28615ac49b6SRussell King	str	r4, [sp, #S_PC]
28715ac49b6SRussell King	orr	r0, r9, r0, lsl #16
28883e686eaSCatalin Marinas#endif
28915ac49b6SRussell King	adr	r9, BSYM(__und_svc_finish)
290b059bdc3SRussell King	mov	r2, r4
2911da177e4SLinus Torvalds	bl	call_fpe
2921da177e4SLinus Torvalds
29315ac49b6SRussell King	mov	r1, #4				@ PC correction to apply
29415ac49b6SRussell King__und_svc_fault:
2951da177e4SLinus Torvalds	mov	r0, sp				@ struct pt_regs *regs
29615ac49b6SRussell King	bl	__und_fault
2971da177e4SLinus Torvalds
2981da177e4SLinus Torvalds	@
2991da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
3001da177e4SLinus Torvalds	@
30115ac49b6SRussell King__und_svc_finish:
30215ac49b6SRussell King	disable_irq_notrace
3031da177e4SLinus Torvalds
3041da177e4SLinus Torvalds	@
3051da177e4SLinus Torvalds	@ restore SPSR and restart the instruction
3061da177e4SLinus Torvalds	@
307b059bdc3SRussell King	ldr	r5, [sp, #S_PSR]		@ Get SVC cpsr
308df295df6SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
309df295df6SRussell King	tst	r5, #PSR_I_BIT
310df295df6SRussell King	bleq	trace_hardirqs_on
311df295df6SRussell King	tst	r5, #PSR_I_BIT
312df295df6SRussell King	blne	trace_hardirqs_off
313df295df6SRussell King#endif
314b059bdc3SRussell King	svc_exit r5				@ return from exception
315c4c5716eSCatalin Marinas UNWIND(.fnend		)
31693ed3970SCatalin MarinasENDPROC(__und_svc)
3171da177e4SLinus Torvalds
3181da177e4SLinus Torvalds	.align	5
3191da177e4SLinus Torvalds__pabt_svc:
320ccea7a19SRussell King	svc_entry
3214fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
3228dfe7ac9SRussell King	pabt_helper
3231da177e4SLinus Torvalds
3241da177e4SLinus Torvalds	@
3251da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
3261da177e4SLinus Torvalds	@
327ac78884eSRussell King	disable_irq_notrace
3281da177e4SLinus Torvalds
32902fe2845SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
33002fe2845SRussell King	tst	r5, #PSR_I_BIT
33102fe2845SRussell King	bleq	trace_hardirqs_on
33202fe2845SRussell King	tst	r5, #PSR_I_BIT
33302fe2845SRussell King	blne	trace_hardirqs_off
33402fe2845SRussell King#endif
335b059bdc3SRussell King	svc_exit r5				@ return from exception
336c4c5716eSCatalin Marinas UNWIND(.fnend		)
33793ed3970SCatalin MarinasENDPROC(__pabt_svc)
3381da177e4SLinus Torvalds
3391da177e4SLinus Torvalds	.align	5
34049f680eaSRussell King.LCcralign:
34149f680eaSRussell King	.word	cr_alignment
34248d7927bSPaul Brook#ifdef MULTI_DABORT
3431da177e4SLinus Torvalds.LCprocfns:
3441da177e4SLinus Torvalds	.word	processor
3451da177e4SLinus Torvalds#endif
3461da177e4SLinus Torvalds.LCfp:
3471da177e4SLinus Torvalds	.word	fp_enter
3481da177e4SLinus Torvalds
3491da177e4SLinus Torvalds/*
3501da177e4SLinus Torvalds * User mode handlers
3512dede2d8SNicolas Pitre *
3522dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
3531da177e4SLinus Torvalds */
3542dede2d8SNicolas Pitre
3552dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
3562dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8"
3572dede2d8SNicolas Pitre#endif
3582dede2d8SNicolas Pitre
359ccea7a19SRussell King	.macro	usr_entry
360c4c5716eSCatalin Marinas UNWIND(.fnstart	)
361c4c5716eSCatalin Marinas UNWIND(.cantunwind	)	@ don't unwind the user space
362ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
363b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - r12}	)
364b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}	)
365ccea7a19SRussell King
366b059bdc3SRussell King	ldmia	r0, {r3 - r5}
367ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
368b059bdc3SRussell King	mov	r6, #-1			@  ""  ""     ""        ""
369ccea7a19SRussell King
370b059bdc3SRussell King	str	r3, [sp]		@ save the "real" r0 copied
371ccea7a19SRussell King					@ from the exception stack
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvalds	@
3741da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
3751da177e4SLinus Torvalds	@
376b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
377b059bdc3SRussell King	@  r5 - spsr_<exception>
378b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
3791da177e4SLinus Torvalds	@
3801da177e4SLinus Torvalds	@ Also, separately save sp_usr and lr_usr
3811da177e4SLinus Torvalds	@
382b059bdc3SRussell King	stmia	r0, {r4 - r6}
383b86040a5SCatalin Marinas ARM(	stmdb	r0, {sp, lr}^			)
384b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r0, r1, S_SP - S_PC	)
3851da177e4SLinus Torvalds
3861da177e4SLinus Torvalds	@
3871da177e4SLinus Torvalds	@ Enable the alignment trap while in kernel mode
3881da177e4SLinus Torvalds	@
38949f680eaSRussell King	alignment_trap r0
3901da177e4SLinus Torvalds
3911da177e4SLinus Torvalds	@
3921da177e4SLinus Torvalds	@ Clear FP to mark the first stack frame
3931da177e4SLinus Torvalds	@
3941da177e4SLinus Torvalds	zero_fp
395f2741b78SRussell King
396f2741b78SRussell King#ifdef CONFIG_IRQSOFF_TRACER
397f2741b78SRussell King	bl	trace_hardirqs_off
398f2741b78SRussell King#endif
3991da177e4SLinus Torvalds	.endm
4001da177e4SLinus Torvalds
401b49c0f24SNicolas Pitre	.macro	kuser_cmpxchg_check
40240fb79c8SNicolas Pitre#if !defined(CONFIG_CPU_32v6K) && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
403b49c0f24SNicolas Pitre#ifndef CONFIG_MMU
404b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing"
405b49c0f24SNicolas Pitre#else
406b49c0f24SNicolas Pitre	@ Make sure our user space atomic helper is restarted
407b49c0f24SNicolas Pitre	@ if it was interrupted in a critical region.  Here we
408b49c0f24SNicolas Pitre	@ perform a quick test inline since it should be false
409b49c0f24SNicolas Pitre	@ 99.9999% of the time.  The rest is done out of line.
410b059bdc3SRussell King	cmp	r4, #TASK_SIZE
41140fb79c8SNicolas Pitre	blhs	kuser_cmpxchg64_fixup
412b49c0f24SNicolas Pitre#endif
413b49c0f24SNicolas Pitre#endif
414b49c0f24SNicolas Pitre	.endm
415b49c0f24SNicolas Pitre
4161da177e4SLinus Torvalds	.align	5
4171da177e4SLinus Torvalds__dabt_usr:
418ccea7a19SRussell King	usr_entry
419b49c0f24SNicolas Pitre	kuser_cmpxchg_check
4201da177e4SLinus Torvalds	mov	r2, sp
421da740472SRussell King	dabt_helper
422da740472SRussell King	b	ret_from_exception
423c4c5716eSCatalin Marinas UNWIND(.fnend		)
42493ed3970SCatalin MarinasENDPROC(__dabt_usr)
4251da177e4SLinus Torvalds
4261da177e4SLinus Torvalds	.align	5
4271da177e4SLinus Torvalds__irq_usr:
428ccea7a19SRussell King	usr_entry
429bc089602SRussell King	kuser_cmpxchg_check
430187a51adSRussell King	irq_handler
4311613cc11SRussell King	get_thread_info tsk
4321da177e4SLinus Torvalds	mov	why, #0
4339fc2552aSMing Lei	b	ret_to_user_from_irq
434c4c5716eSCatalin Marinas UNWIND(.fnend		)
43593ed3970SCatalin MarinasENDPROC(__irq_usr)
4361da177e4SLinus Torvalds
4371da177e4SLinus Torvalds	.ltorg
4381da177e4SLinus Torvalds
4391da177e4SLinus Torvalds	.align	5
4401da177e4SLinus Torvalds__und_usr:
441ccea7a19SRussell King	usr_entry
442bc089602SRussell King
443b059bdc3SRussell King	mov	r2, r4
444b059bdc3SRussell King	mov	r3, r5
4451da177e4SLinus Torvalds
44615ac49b6SRussell King	@ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the
44715ac49b6SRussell King	@      faulting instruction depending on Thumb mode.
44815ac49b6SRussell King	@ r3 = regs->ARM_cpsr
4491da177e4SLinus Torvalds	@
45015ac49b6SRussell King	@ The emulation code returns using r9 if it has emulated the
45115ac49b6SRussell King	@ instruction, or the more conventional lr if we are to treat
45215ac49b6SRussell King	@ this as a real undefined instruction
4531da177e4SLinus Torvalds	@
454b86040a5SCatalin Marinas	adr	r9, BSYM(ret_from_exception)
45515ac49b6SRussell King
456cb170a45SPaul Brook	tst	r3, #PSR_T_BIT			@ Thumb mode?
45715ac49b6SRussell King	bne	__und_usr_thumb
45815ac49b6SRussell King	sub	r4, r2, #4			@ ARM instr at LR - 4
45915ac49b6SRussell King1:	ldrt	r0, [r4]
46026584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8
46115ac49b6SRussell King	rev	r0, r0				@ little endian instruction
46226584853SCatalin Marinas#endif
46315ac49b6SRussell King	@ r0 = 32-bit ARM instruction which caused the exception
46415ac49b6SRussell King	@ r2 = PC value for the following instruction (:= regs->ARM_pc)
46515ac49b6SRussell King	@ r4 = PC value for the faulting instruction
46615ac49b6SRussell King	@ lr = 32-bit undefined instruction function
46715ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
46815ac49b6SRussell King	b	call_fpe
46915ac49b6SRussell King
47015ac49b6SRussell King__und_usr_thumb:
471cb170a45SPaul Brook	@ Thumb instruction
47215ac49b6SRussell King	sub	r4, r2, #2			@ First half of thumb instr at LR - 2
473ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
474ef4c5368SDave Martin/*
475ef4c5368SDave Martin * Thumb-2 instruction handling.  Note that because pre-v6 and >= v6 platforms
476ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at
477ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6.  This allows simplifying assumptions to be
478ef4c5368SDave Martin * made about .arch directives.
479ef4c5368SDave Martin */
480ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
481ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */
482ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE
483ef4c5368SDave Martin	ldr	r5, .LCcpu_architecture
484ef4c5368SDave Martin	ldr	r5, [r5]
485ef4c5368SDave Martin	cmp	r5, #CPU_ARCH_ARMv7
48615ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
487ef4c5368SDave Martin/*
488ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so
489ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless.  Temporarily
490ef4c5368SDave Martin * override the assembler target arch with the minimum required instead:
491ef4c5368SDave Martin */
492ef4c5368SDave Martin	.arch	armv6t2
493ef4c5368SDave Martin#endif
49415ac49b6SRussell King2:	ldrht	r5, [r4]
49585519189SDave Martin	cmp	r5, #0xe800			@ 32bit instruction if xx != 0
49615ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
49715ac49b6SRussell King3:	ldrht	r0, [r2]
498cb170a45SPaul Brook	add	r2, r2, #2			@ r2 is PC + 2, make it PC + 4
49915ac49b6SRussell King	str	r2, [sp, #S_PC]			@ it's a 2x16bit instr, update
500cb170a45SPaul Brook	orr	r0, r0, r5, lsl #16
50115ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
50215ac49b6SRussell King	@ r0 = the two 16-bit Thumb instructions which caused the exception
50315ac49b6SRussell King	@ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc)
50415ac49b6SRussell King	@ r4 = PC value for the first 16-bit Thumb instruction
50515ac49b6SRussell King	@ lr = 32bit undefined instruction function
506ef4c5368SDave Martin
507ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
508ef4c5368SDave Martin/* If the target arch was overridden, change it back: */
509ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K
510ef4c5368SDave Martin	.arch	armv6k
511cb170a45SPaul Brook#else
512ef4c5368SDave Martin	.arch	armv6
513ef4c5368SDave Martin#endif
514ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */
515ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */
51615ac49b6SRussell King	b	__und_usr_fault_16
517cb170a45SPaul Brook#endif
518c4c5716eSCatalin Marinas UNWIND(.fnend)
51993ed3970SCatalin MarinasENDPROC(__und_usr)
520cb170a45SPaul Brook
5211da177e4SLinus Torvalds/*
52215ac49b6SRussell King * The out of line fixup for the ldrt instructions above.
5231da177e4SLinus Torvalds */
5244260415fSRussell King	.pushsection .fixup, "ax"
525667d1b48SWill Deacon	.align	2
526cb170a45SPaul Brook4:	mov	pc, r9
5274260415fSRussell King	.popsection
5284260415fSRussell King	.pushsection __ex_table,"a"
529cb170a45SPaul Brook	.long	1b, 4b
530c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
531cb170a45SPaul Brook	.long	2b, 4b
532cb170a45SPaul Brook	.long	3b, 4b
533cb170a45SPaul Brook#endif
5344260415fSRussell King	.popsection
5351da177e4SLinus Torvalds
5361da177e4SLinus Torvalds/*
5371da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction.
5381da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler.
5391da177e4SLinus Torvalds *
5401da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor
5411da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well
5421da177e4SLinus Torvalds * defined.  The only instructions that should fault are the
5431da177e4SLinus Torvalds * co-processor instructions.  However, we have to watch out
5441da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug.
5451da177e4SLinus Torvalds *
546b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all
547b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have
548b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's
549b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs
550b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the
551b5872db4SCatalin Marinas * NEON handler code.
552b5872db4SCatalin Marinas *
5531da177e4SLinus Torvalds * Emulators may wish to make use of the following registers:
55415ac49b6SRussell King *  r0  = instruction opcode (32-bit ARM or two 16-bit Thumb)
55515ac49b6SRussell King *  r2  = PC value to resume execution after successful emulation
556db6ccbb6SRussell King *  r9  = normal "successful" return address
55715ac49b6SRussell King *  r10 = this threads thread_info structure
558db6ccbb6SRussell King *  lr  = unrecognised instruction return address
55915ac49b6SRussell King * IRQs disabled, FIQs enabled.
5601da177e4SLinus Torvalds */
561cb170a45SPaul Brook	@
562cb170a45SPaul Brook	@ Fall-through from Thumb-2 __und_usr
563cb170a45SPaul Brook	@
564cb170a45SPaul Brook#ifdef CONFIG_NEON
565*d3f79584SRussell King	get_thread_info r10			@ get current thread
566cb170a45SPaul Brook	adr	r6, .LCneon_thumb_opcodes
567cb170a45SPaul Brook	b	2f
568cb170a45SPaul Brook#endif
5691da177e4SLinus Torvaldscall_fpe:
570*d3f79584SRussell King	get_thread_info r10			@ get current thread
571b5872db4SCatalin Marinas#ifdef CONFIG_NEON
572cb170a45SPaul Brook	adr	r6, .LCneon_arm_opcodes
573*d3f79584SRussell King2:	ldr	r5, [r6], #4			@ mask value
574b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ opcode bits matching in mask
575*d3f79584SRussell King	cmp	r5, #0				@ end mask?
576*d3f79584SRussell King	beq	1f
577*d3f79584SRussell King	and	r8, r0, r5
578b5872db4SCatalin Marinas	cmp	r8, r7				@ NEON instruction?
579b5872db4SCatalin Marinas	bne	2b
580b5872db4SCatalin Marinas	mov	r7, #1
581b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 10]	@ mark CP#10 as used
582b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 11]	@ mark CP#11 as used
583b5872db4SCatalin Marinas	b	do_vfp				@ let VFP handler handle this
584b5872db4SCatalin Marinas1:
585b5872db4SCatalin Marinas#endif
5861da177e4SLinus Torvalds	tst	r0, #0x08000000			@ only CDP/CPRT/LDC/STC have bit 27
587cb170a45SPaul Brook	tstne	r0, #0x04000000			@ bit 26 set on both ARM and Thumb-2
5881da177e4SLinus Torvalds	moveq	pc, lr
5891da177e4SLinus Torvalds	and	r8, r0, #0x00000f00		@ mask out CP number
590b86040a5SCatalin Marinas THUMB(	lsr	r8, r8, #8		)
5911da177e4SLinus Torvalds	mov	r7, #1
5921da177e4SLinus Torvalds	add	r6, r10, #TI_USED_CP
593b86040a5SCatalin Marinas ARM(	strb	r7, [r6, r8, lsr #8]	)	@ set appropriate used_cp[]
594b86040a5SCatalin Marinas THUMB(	strb	r7, [r6, r8]		)	@ set appropriate used_cp[]
5951da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT
5961da177e4SLinus Torvalds	@ Test if we need to give access to iWMMXt coprocessors
5971da177e4SLinus Torvalds	ldr	r5, [r10, #TI_FLAGS]
5981da177e4SLinus Torvalds	rsbs	r7, r8, #(1 << 8)		@ CP 0 or 1 only
5991da177e4SLinus Torvalds	movcss	r7, r5, lsr #(TIF_USING_IWMMXT + 1)
6001da177e4SLinus Torvalds	bcs	iwmmxt_task_enable
6011da177e4SLinus Torvalds#endif
602b86040a5SCatalin Marinas ARM(	add	pc, pc, r8, lsr #6	)
603b86040a5SCatalin Marinas THUMB(	lsl	r8, r8, #2		)
604b86040a5SCatalin Marinas THUMB(	add	pc, r8			)
605b86040a5SCatalin Marinas	nop
6061da177e4SLinus Torvalds
607a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#0
608b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#1 (FPE)
609b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#2 (FPE)
610a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#3
611c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH
612c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#4 (MaverickCrunch)
613c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#5 (MaverickCrunch)
614c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#6 (MaverickCrunch)
615c17fad11SLennert Buytenhek#else
616a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#4
617a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#5
618a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#6
619c17fad11SLennert Buytenhek#endif
620a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#7
621a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#8
622a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#9
6231da177e4SLinus Torvalds#ifdef CONFIG_VFP
624b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#10 (VFP)
625b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#11 (VFP)
6261da177e4SLinus Torvalds#else
627a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#10 (VFP)
628a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#11 (VFP)
6291da177e4SLinus Torvalds#endif
630a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#12
631a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#13
632a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#14 (Debug)
633a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#15 (Control)
6341da177e4SLinus Torvalds
635ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE
636ef4c5368SDave Martin	.align	2
637ef4c5368SDave Martin.LCcpu_architecture:
638ef4c5368SDave Martin	.word	__cpu_architecture
639ef4c5368SDave Martin#endif
640ef4c5368SDave Martin
641b5872db4SCatalin Marinas#ifdef CONFIG_NEON
642b5872db4SCatalin Marinas	.align	6
643b5872db4SCatalin Marinas
644cb170a45SPaul Brook.LCneon_arm_opcodes:
645b5872db4SCatalin Marinas	.word	0xfe000000			@ mask
646b5872db4SCatalin Marinas	.word	0xf2000000			@ opcode
647b5872db4SCatalin Marinas
648b5872db4SCatalin Marinas	.word	0xff100000			@ mask
649b5872db4SCatalin Marinas	.word	0xf4000000			@ opcode
650b5872db4SCatalin Marinas
651b5872db4SCatalin Marinas	.word	0x00000000			@ mask
652b5872db4SCatalin Marinas	.word	0x00000000			@ opcode
653cb170a45SPaul Brook
654cb170a45SPaul Brook.LCneon_thumb_opcodes:
655cb170a45SPaul Brook	.word	0xef000000			@ mask
656cb170a45SPaul Brook	.word	0xef000000			@ opcode
657cb170a45SPaul Brook
658cb170a45SPaul Brook	.word	0xff100000			@ mask
659cb170a45SPaul Brook	.word	0xf9000000			@ opcode
660cb170a45SPaul Brook
661cb170a45SPaul Brook	.word	0x00000000			@ mask
662cb170a45SPaul Brook	.word	0x00000000			@ opcode
663b5872db4SCatalin Marinas#endif
664b5872db4SCatalin Marinas
6651da177e4SLinus Torvaldsdo_fpe:
6665d25ac03SRussell King	enable_irq
6671da177e4SLinus Torvalds	ldr	r4, .LCfp
6681da177e4SLinus Torvalds	add	r10, r10, #TI_FPSTATE		@ r10 = workspace
6691da177e4SLinus Torvalds	ldr	pc, [r4]			@ Call FP module USR entry point
6701da177e4SLinus Torvalds
6711da177e4SLinus Torvalds/*
6721da177e4SLinus Torvalds * The FP module is called with these registers set:
6731da177e4SLinus Torvalds *  r0  = instruction
6741da177e4SLinus Torvalds *  r2  = PC+4
6751da177e4SLinus Torvalds *  r9  = normal "successful" return address
6761da177e4SLinus Torvalds *  r10 = FP workspace
6771da177e4SLinus Torvalds *  lr  = unrecognised FP instruction return address
6781da177e4SLinus Torvalds */
6791da177e4SLinus Torvalds
680124efc27SSantosh Shilimkar	.pushsection .data
6811da177e4SLinus TorvaldsENTRY(fp_enter)
682db6ccbb6SRussell King	.word	no_fp
683124efc27SSantosh Shilimkar	.popsection
6841da177e4SLinus Torvalds
68583e686eaSCatalin MarinasENTRY(no_fp)
68683e686eaSCatalin Marinas	mov	pc, lr
68783e686eaSCatalin MarinasENDPROC(no_fp)
688db6ccbb6SRussell King
68915ac49b6SRussell King__und_usr_fault_32:
69015ac49b6SRussell King	mov	r1, #4
69115ac49b6SRussell King	b	1f
69215ac49b6SRussell King__und_usr_fault_16:
69315ac49b6SRussell King	mov	r1, #2
69415ac49b6SRussell King1:	enable_irq
6951da177e4SLinus Torvalds	mov	r0, sp
696b86040a5SCatalin Marinas	adr	lr, BSYM(ret_from_exception)
69715ac49b6SRussell King	b	__und_fault
69815ac49b6SRussell KingENDPROC(__und_usr_fault_32)
69915ac49b6SRussell KingENDPROC(__und_usr_fault_16)
7001da177e4SLinus Torvalds
7011da177e4SLinus Torvalds	.align	5
7021da177e4SLinus Torvalds__pabt_usr:
703ccea7a19SRussell King	usr_entry
7044fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
7058dfe7ac9SRussell King	pabt_helper
706c4c5716eSCatalin Marinas UNWIND(.fnend		)
7071da177e4SLinus Torvalds	/* fall through */
7081da177e4SLinus Torvalds/*
7091da177e4SLinus Torvalds * This is the return code to user mode for abort handlers
7101da177e4SLinus Torvalds */
7111da177e4SLinus TorvaldsENTRY(ret_from_exception)
712c4c5716eSCatalin Marinas UNWIND(.fnstart	)
713c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7141da177e4SLinus Torvalds	get_thread_info tsk
7151da177e4SLinus Torvalds	mov	why, #0
7161da177e4SLinus Torvalds	b	ret_to_user
717c4c5716eSCatalin Marinas UNWIND(.fnend		)
71893ed3970SCatalin MarinasENDPROC(__pabt_usr)
71993ed3970SCatalin MarinasENDPROC(ret_from_exception)
7201da177e4SLinus Torvalds
7211da177e4SLinus Torvalds/*
7221da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors
7231da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
7241da177e4SLinus Torvalds * previous and next are guaranteed not to be the same.
7251da177e4SLinus Torvalds */
7261da177e4SLinus TorvaldsENTRY(__switch_to)
727c4c5716eSCatalin Marinas UNWIND(.fnstart	)
728c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
7291da177e4SLinus Torvalds	add	ip, r1, #TI_CPU_SAVE
7301da177e4SLinus Torvalds	ldr	r3, [r2, #TI_TP_VALUE]
731b86040a5SCatalin Marinas ARM(	stmia	ip!, {r4 - sl, fp, sp, lr} )	@ Store most regs on stack
732b86040a5SCatalin Marinas THUMB(	stmia	ip!, {r4 - sl, fp}	   )	@ Store most regs on stack
733b86040a5SCatalin Marinas THUMB(	str	sp, [ip], #4		   )
734b86040a5SCatalin Marinas THUMB(	str	lr, [ip], #4		   )
735247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
736d6551e88SRussell King	ldr	r6, [r2, #TI_CPU_DOMAIN]
737afeb90caSHyok S. Choi#endif
738f159f4edSTony Lindgren	set_tls	r3, r4, r5
739df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
740df0698beSNicolas Pitre	ldr	r7, [r2, #TI_TASK]
741df0698beSNicolas Pitre	ldr	r8, =__stack_chk_guard
742df0698beSNicolas Pitre	ldr	r7, [r7, #TSK_STACK_CANARY]
743df0698beSNicolas Pitre#endif
744247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
7451da177e4SLinus Torvalds	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
746afeb90caSHyok S. Choi#endif
747d6551e88SRussell King	mov	r5, r0
748d6551e88SRussell King	add	r4, r2, #TI_CPU_SAVE
749d6551e88SRussell King	ldr	r0, =thread_notify_head
750d6551e88SRussell King	mov	r1, #THREAD_NOTIFY_SWITCH
751d6551e88SRussell King	bl	atomic_notifier_call_chain
752df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
753df0698beSNicolas Pitre	str	r7, [r8]
754df0698beSNicolas Pitre#endif
755b86040a5SCatalin Marinas THUMB(	mov	ip, r4			   )
756d6551e88SRussell King	mov	r0, r5
757b86040a5SCatalin Marinas ARM(	ldmia	r4, {r4 - sl, fp, sp, pc}  )	@ Load all regs saved previously
758b86040a5SCatalin Marinas THUMB(	ldmia	ip!, {r4 - sl, fp}	   )	@ Load all regs saved previously
759b86040a5SCatalin Marinas THUMB(	ldr	sp, [ip], #4		   )
760b86040a5SCatalin Marinas THUMB(	ldr	pc, [ip]		   )
761c4c5716eSCatalin Marinas UNWIND(.fnend		)
76293ed3970SCatalin MarinasENDPROC(__switch_to)
7631da177e4SLinus Torvalds
7641da177e4SLinus Torvalds	__INIT
7652d2669b6SNicolas Pitre
7662d2669b6SNicolas Pitre/*
7672d2669b6SNicolas Pitre * User helpers.
7682d2669b6SNicolas Pitre *
7692d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high
7702d2669b6SNicolas Pitre * vector page.  New segments (if ever needed) must be added in front of
7712d2669b6SNicolas Pitre * existing ones.  This mechanism should be used only for things that are
7722d2669b6SNicolas Pitre * really small and justified, and not be abused freely.
7732d2669b6SNicolas Pitre *
77437b83046SNicolas Pitre * See Documentation/arm/kernel_user_helpers.txt for formal definitions.
7752d2669b6SNicolas Pitre */
776b86040a5SCatalin Marinas THUMB(	.arm	)
7772d2669b6SNicolas Pitre
778ba9b5d76SNicolas Pitre	.macro	usr_ret, reg
779ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB
780ba9b5d76SNicolas Pitre	bx	\reg
781ba9b5d76SNicolas Pitre#else
782ba9b5d76SNicolas Pitre	mov	pc, \reg
783ba9b5d76SNicolas Pitre#endif
784ba9b5d76SNicolas Pitre	.endm
785ba9b5d76SNicolas Pitre
7862d2669b6SNicolas Pitre	.align	5
7872d2669b6SNicolas Pitre	.globl	__kuser_helper_start
7882d2669b6SNicolas Pitre__kuser_helper_start:
7892d2669b6SNicolas Pitre
7902d2669b6SNicolas Pitre/*
79140fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular
79240fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point.
7937c612bfdSNicolas Pitre */
7947c612bfdSNicolas Pitre
79540fb79c8SNicolas Pitre__kuser_cmpxchg64:				@ 0xffff0f60
79640fb79c8SNicolas Pitre
79740fb79c8SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
79840fb79c8SNicolas Pitre
79940fb79c8SNicolas Pitre	/*
80040fb79c8SNicolas Pitre	 * Poor you.  No fast solution possible...
80140fb79c8SNicolas Pitre	 * The kernel itself must perform the operation.
80240fb79c8SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
80340fb79c8SNicolas Pitre	 */
80440fb79c8SNicolas Pitre	stmfd	sp!, {r7, lr}
80540fb79c8SNicolas Pitre	ldr	r7, 1f			@ it's 20 bits
80640fb79c8SNicolas Pitre	swi	__ARM_NR_cmpxchg64
80740fb79c8SNicolas Pitre	ldmfd	sp!, {r7, pc}
80840fb79c8SNicolas Pitre1:	.word	__ARM_NR_cmpxchg64
80940fb79c8SNicolas Pitre
81040fb79c8SNicolas Pitre#elif defined(CONFIG_CPU_32v6K)
81140fb79c8SNicolas Pitre
81240fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, r7}
81340fb79c8SNicolas Pitre	ldrd	r4, r5, [r0]			@ load old val
81440fb79c8SNicolas Pitre	ldrd	r6, r7, [r1]			@ load new val
81540fb79c8SNicolas Pitre	smp_dmb	arm
81640fb79c8SNicolas Pitre1:	ldrexd	r0, r1, [r2]			@ load current val
81740fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
81840fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
81940fb79c8SNicolas Pitre	strexdeq r3, r6, r7, [r2]		@ store newval if eq
82040fb79c8SNicolas Pitre	teqeq	r3, #1				@ success?
82140fb79c8SNicolas Pitre	beq	1b				@ if no then retry
82240fb79c8SNicolas Pitre	smp_dmb	arm
82340fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set returned val and C flag
82440fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, r7}
8255a97d0aeSWill Deacon	usr_ret	lr
82640fb79c8SNicolas Pitre
82740fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP)
82840fb79c8SNicolas Pitre
82940fb79c8SNicolas Pitre#ifdef CONFIG_MMU
83040fb79c8SNicolas Pitre
83140fb79c8SNicolas Pitre	/*
83240fb79c8SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg64
83340fb79c8SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
83440fb79c8SNicolas Pitre	 * causing another process/thread to be scheduled in the middle of
83540fb79c8SNicolas Pitre	 * the critical sequence.  The same strategy as for cmpxchg is used.
83640fb79c8SNicolas Pitre	 */
83740fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, lr}
83840fb79c8SNicolas Pitre	ldmia	r0, {r4, r5}			@ load old val
83940fb79c8SNicolas Pitre	ldmia	r1, {r6, lr}			@ load new val
84040fb79c8SNicolas Pitre1:	ldmia	r2, {r0, r1}			@ load current val
84140fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
84240fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
84340fb79c8SNicolas Pitre2:	stmeqia	r2, {r6, lr}			@ store newval if eq
84440fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
84540fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, pc}
84640fb79c8SNicolas Pitre
84740fb79c8SNicolas Pitre	.text
84840fb79c8SNicolas Pitrekuser_cmpxchg64_fixup:
84940fb79c8SNicolas Pitre	@ Called from kuser_cmpxchg_fixup.
8503ad55155SRussell King	@ r4 = address of interrupted insn (must be preserved).
85140fb79c8SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
85240fb79c8SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
8533ad55155SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
85440fb79c8SNicolas Pitre	mov	r7, #0xffff0fff
85540fb79c8SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
8563ad55155SRussell King	subs	r8, r4, r7
85740fb79c8SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
85840fb79c8SNicolas Pitre	strcs	r7, [sp, #S_PC]
85940fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6
86040fb79c8SNicolas Pitre	bcc	kuser_cmpxchg32_fixup
86140fb79c8SNicolas Pitre#endif
86240fb79c8SNicolas Pitre	mov	pc, lr
86340fb79c8SNicolas Pitre	.previous
86440fb79c8SNicolas Pitre
86540fb79c8SNicolas Pitre#else
86640fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing"
86740fb79c8SNicolas Pitre	mov	r0, #-1
86840fb79c8SNicolas Pitre	adds	r0, r0, #0
86940fb79c8SNicolas Pitre	usr_ret	lr
87040fb79c8SNicolas Pitre#endif
87140fb79c8SNicolas Pitre
87240fb79c8SNicolas Pitre#else
87340fb79c8SNicolas Pitre#error "incoherent kernel configuration"
87440fb79c8SNicolas Pitre#endif
87540fb79c8SNicolas Pitre
87640fb79c8SNicolas Pitre	/* pad to next slot */
87740fb79c8SNicolas Pitre	.rept	(16 - (. - __kuser_cmpxchg64)/4)
87840fb79c8SNicolas Pitre	.word	0
87940fb79c8SNicolas Pitre	.endr
88040fb79c8SNicolas Pitre
88140fb79c8SNicolas Pitre	.align	5
88240fb79c8SNicolas Pitre
8837c612bfdSNicolas Pitre__kuser_memory_barrier:				@ 0xffff0fa0
884ed3768a8SDave Martin	smp_dmb	arm
885ba9b5d76SNicolas Pitre	usr_ret	lr
8867c612bfdSNicolas Pitre
8877c612bfdSNicolas Pitre	.align	5
8887c612bfdSNicolas Pitre
8892d2669b6SNicolas Pitre__kuser_cmpxchg:				@ 0xffff0fc0
8902d2669b6SNicolas Pitre
891dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
8922d2669b6SNicolas Pitre
893dcef1f63SNicolas Pitre	/*
894dcef1f63SNicolas Pitre	 * Poor you.  No fast solution possible...
895dcef1f63SNicolas Pitre	 * The kernel itself must perform the operation.
896dcef1f63SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
897dcef1f63SNicolas Pitre	 */
8985e097445SNicolas Pitre	stmfd	sp!, {r7, lr}
89955afd264SDave Martin	ldr	r7, 1f			@ it's 20 bits
900cc20d429SRussell King	swi	__ARM_NR_cmpxchg
9015e097445SNicolas Pitre	ldmfd	sp!, {r7, pc}
902cc20d429SRussell King1:	.word	__ARM_NR_cmpxchg
903dcef1f63SNicolas Pitre
904dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6
9052d2669b6SNicolas Pitre
90649bca4c2SNicolas Pitre#ifdef CONFIG_MMU
907b49c0f24SNicolas Pitre
908b49c0f24SNicolas Pitre	/*
909b49c0f24SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg
910b49c0f24SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
911b49c0f24SNicolas Pitre	 * causing another process/thread to be scheduled in the middle
912b49c0f24SNicolas Pitre	 * of the critical sequence.  To prevent this, code is added to
913b49c0f24SNicolas Pitre	 * the IRQ and data abort exception handlers to set the pc back
914b49c0f24SNicolas Pitre	 * to the beginning of the critical section if it is found to be
915b49c0f24SNicolas Pitre	 * within that critical section (see kuser_cmpxchg_fixup).
916b49c0f24SNicolas Pitre	 */
917b49c0f24SNicolas Pitre1:	ldr	r3, [r2]			@ load current val
918b49c0f24SNicolas Pitre	subs	r3, r3, r0			@ compare with oldval
919b49c0f24SNicolas Pitre2:	streq	r1, [r2]			@ store newval if eq
920b49c0f24SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
921b49c0f24SNicolas Pitre	usr_ret	lr
922b49c0f24SNicolas Pitre
923b49c0f24SNicolas Pitre	.text
92440fb79c8SNicolas Pitrekuser_cmpxchg32_fixup:
925b49c0f24SNicolas Pitre	@ Called from kuser_cmpxchg_check macro.
926b059bdc3SRussell King	@ r4 = address of interrupted insn (must be preserved).
927b49c0f24SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
928b49c0f24SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
929b059bdc3SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
930b49c0f24SNicolas Pitre	mov	r7, #0xffff0fff
931b49c0f24SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
932b059bdc3SRussell King	subs	r8, r4, r7
933b49c0f24SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
934b49c0f24SNicolas Pitre	strcs	r7, [sp, #S_PC]
935b49c0f24SNicolas Pitre	mov	pc, lr
936b49c0f24SNicolas Pitre	.previous
937b49c0f24SNicolas Pitre
93849bca4c2SNicolas Pitre#else
93949bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing"
94049bca4c2SNicolas Pitre	mov	r0, #-1
94149bca4c2SNicolas Pitre	adds	r0, r0, #0
942ba9b5d76SNicolas Pitre	usr_ret	lr
943b49c0f24SNicolas Pitre#endif
9442d2669b6SNicolas Pitre
9452d2669b6SNicolas Pitre#else
9462d2669b6SNicolas Pitre
947ed3768a8SDave Martin	smp_dmb	arm
948b49c0f24SNicolas Pitre1:	ldrex	r3, [r2]
9492d2669b6SNicolas Pitre	subs	r3, r3, r0
9502d2669b6SNicolas Pitre	strexeq	r3, r1, [r2]
951b49c0f24SNicolas Pitre	teqeq	r3, #1
952b49c0f24SNicolas Pitre	beq	1b
9532d2669b6SNicolas Pitre	rsbs	r0, r3, #0
954b49c0f24SNicolas Pitre	/* beware -- each __kuser slot must be 8 instructions max */
955f00ec48fSRussell King	ALT_SMP(b	__kuser_memory_barrier)
956f00ec48fSRussell King	ALT_UP(usr_ret	lr)
9572d2669b6SNicolas Pitre
9582d2669b6SNicolas Pitre#endif
9592d2669b6SNicolas Pitre
9602d2669b6SNicolas Pitre	.align	5
9612d2669b6SNicolas Pitre
9622d2669b6SNicolas Pitre__kuser_get_tls:				@ 0xffff0fe0
963f159f4edSTony Lindgren	ldr	r0, [pc, #(16 - 8)]	@ read TLS, set in kuser_get_tls_init
964ba9b5d76SNicolas Pitre	usr_ret	lr
965f159f4edSTony Lindgren	mrc	p15, 0, r0, c13, c0, 3	@ 0xffff0fe8 hardware TLS code
966f159f4edSTony Lindgren	.rep	4
967f159f4edSTony Lindgren	.word	0			@ 0xffff0ff0 software TLS value, then
968f159f4edSTony Lindgren	.endr				@ pad up to __kuser_helper_version
9692d2669b6SNicolas Pitre
9702d2669b6SNicolas Pitre__kuser_helper_version:				@ 0xffff0ffc
9712d2669b6SNicolas Pitre	.word	((__kuser_helper_end - __kuser_helper_start) >> 5)
9722d2669b6SNicolas Pitre
9732d2669b6SNicolas Pitre	.globl	__kuser_helper_end
9742d2669b6SNicolas Pitre__kuser_helper_end:
9752d2669b6SNicolas Pitre
976b86040a5SCatalin Marinas THUMB(	.thumb	)
9772d2669b6SNicolas Pitre
9781da177e4SLinus Torvalds/*
9791da177e4SLinus Torvalds * Vector stubs.
9801da177e4SLinus Torvalds *
9817933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the
9827933523dSRussell King * vectors, rather than ldr's.  Note that this code must not
9837933523dSRussell King * exceed 0x300 bytes.
9841da177e4SLinus Torvalds *
9851da177e4SLinus Torvalds * Common stub entry macro:
9861da177e4SLinus Torvalds *   Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
987ccea7a19SRussell King *
988ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address
989ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler.
9901da177e4SLinus Torvalds */
991b7ec4795SNicolas Pitre	.macro	vector_stub, name, mode, correction=0
9921da177e4SLinus Torvalds	.align	5
9931da177e4SLinus Torvalds
9941da177e4SLinus Torvaldsvector_\name:
9951da177e4SLinus Torvalds	.if \correction
9961da177e4SLinus Torvalds	sub	lr, lr, #\correction
9971da177e4SLinus Torvalds	.endif
9981da177e4SLinus Torvalds
999ccea7a19SRussell King	@
1000ccea7a19SRussell King	@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1001ccea7a19SRussell King	@ (parent CPSR)
1002ccea7a19SRussell King	@
1003ccea7a19SRussell King	stmia	sp, {r0, lr}		@ save r0, lr
1004ccea7a19SRussell King	mrs	lr, spsr
1005ccea7a19SRussell King	str	lr, [sp, #8]		@ save spsr
1006ccea7a19SRussell King
1007ccea7a19SRussell King	@
1008ccea7a19SRussell King	@ Prepare for SVC32 mode.  IRQs remain disabled.
1009ccea7a19SRussell King	@
1010ccea7a19SRussell King	mrs	r0, cpsr
1011b86040a5SCatalin Marinas	eor	r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
1012ccea7a19SRussell King	msr	spsr_cxsf, r0
1013ccea7a19SRussell King
1014ccea7a19SRussell King	@
1015ccea7a19SRussell King	@ the branch table must immediately follow this code
1016ccea7a19SRussell King	@
1017ccea7a19SRussell King	and	lr, lr, #0x0f
1018b86040a5SCatalin Marinas THUMB(	adr	r0, 1f			)
1019b86040a5SCatalin Marinas THUMB(	ldr	lr, [r0, lr, lsl #2]	)
1020b7ec4795SNicolas Pitre	mov	r0, sp
1021b86040a5SCatalin Marinas ARM(	ldr	lr, [pc, lr, lsl #2]	)
1022ccea7a19SRussell King	movs	pc, lr			@ branch to handler in SVC mode
102393ed3970SCatalin MarinasENDPROC(vector_\name)
102488987ef9SCatalin Marinas
102588987ef9SCatalin Marinas	.align	2
102688987ef9SCatalin Marinas	@ handler addresses follow this label
102788987ef9SCatalin Marinas1:
10281da177e4SLinus Torvalds	.endm
10291da177e4SLinus Torvalds
10307933523dSRussell King	.globl	__stubs_start
10311da177e4SLinus Torvalds__stubs_start:
10321da177e4SLinus Torvalds/*
10331da177e4SLinus Torvalds * Interrupt dispatcher
10341da177e4SLinus Torvalds */
1035b7ec4795SNicolas Pitre	vector_stub	irq, IRQ_MODE, 4
10361da177e4SLinus Torvalds
10371da177e4SLinus Torvalds	.long	__irq_usr			@  0  (USR_26 / USR_32)
10381da177e4SLinus Torvalds	.long	__irq_invalid			@  1  (FIQ_26 / FIQ_32)
10391da177e4SLinus Torvalds	.long	__irq_invalid			@  2  (IRQ_26 / IRQ_32)
10401da177e4SLinus Torvalds	.long	__irq_svc			@  3  (SVC_26 / SVC_32)
10411da177e4SLinus Torvalds	.long	__irq_invalid			@  4
10421da177e4SLinus Torvalds	.long	__irq_invalid			@  5
10431da177e4SLinus Torvalds	.long	__irq_invalid			@  6
10441da177e4SLinus Torvalds	.long	__irq_invalid			@  7
10451da177e4SLinus Torvalds	.long	__irq_invalid			@  8
10461da177e4SLinus Torvalds	.long	__irq_invalid			@  9
10471da177e4SLinus Torvalds	.long	__irq_invalid			@  a
10481da177e4SLinus Torvalds	.long	__irq_invalid			@  b
10491da177e4SLinus Torvalds	.long	__irq_invalid			@  c
10501da177e4SLinus Torvalds	.long	__irq_invalid			@  d
10511da177e4SLinus Torvalds	.long	__irq_invalid			@  e
10521da177e4SLinus Torvalds	.long	__irq_invalid			@  f
10531da177e4SLinus Torvalds
10541da177e4SLinus Torvalds/*
10551da177e4SLinus Torvalds * Data abort dispatcher
10561da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10571da177e4SLinus Torvalds */
1058b7ec4795SNicolas Pitre	vector_stub	dabt, ABT_MODE, 8
10591da177e4SLinus Torvalds
10601da177e4SLinus Torvalds	.long	__dabt_usr			@  0  (USR_26 / USR_32)
10611da177e4SLinus Torvalds	.long	__dabt_invalid			@  1  (FIQ_26 / FIQ_32)
10621da177e4SLinus Torvalds	.long	__dabt_invalid			@  2  (IRQ_26 / IRQ_32)
10631da177e4SLinus Torvalds	.long	__dabt_svc			@  3  (SVC_26 / SVC_32)
10641da177e4SLinus Torvalds	.long	__dabt_invalid			@  4
10651da177e4SLinus Torvalds	.long	__dabt_invalid			@  5
10661da177e4SLinus Torvalds	.long	__dabt_invalid			@  6
10671da177e4SLinus Torvalds	.long	__dabt_invalid			@  7
10681da177e4SLinus Torvalds	.long	__dabt_invalid			@  8
10691da177e4SLinus Torvalds	.long	__dabt_invalid			@  9
10701da177e4SLinus Torvalds	.long	__dabt_invalid			@  a
10711da177e4SLinus Torvalds	.long	__dabt_invalid			@  b
10721da177e4SLinus Torvalds	.long	__dabt_invalid			@  c
10731da177e4SLinus Torvalds	.long	__dabt_invalid			@  d
10741da177e4SLinus Torvalds	.long	__dabt_invalid			@  e
10751da177e4SLinus Torvalds	.long	__dabt_invalid			@  f
10761da177e4SLinus Torvalds
10771da177e4SLinus Torvalds/*
10781da177e4SLinus Torvalds * Prefetch abort dispatcher
10791da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10801da177e4SLinus Torvalds */
1081b7ec4795SNicolas Pitre	vector_stub	pabt, ABT_MODE, 4
10821da177e4SLinus Torvalds
10831da177e4SLinus Torvalds	.long	__pabt_usr			@  0 (USR_26 / USR_32)
10841da177e4SLinus Torvalds	.long	__pabt_invalid			@  1 (FIQ_26 / FIQ_32)
10851da177e4SLinus Torvalds	.long	__pabt_invalid			@  2 (IRQ_26 / IRQ_32)
10861da177e4SLinus Torvalds	.long	__pabt_svc			@  3 (SVC_26 / SVC_32)
10871da177e4SLinus Torvalds	.long	__pabt_invalid			@  4
10881da177e4SLinus Torvalds	.long	__pabt_invalid			@  5
10891da177e4SLinus Torvalds	.long	__pabt_invalid			@  6
10901da177e4SLinus Torvalds	.long	__pabt_invalid			@  7
10911da177e4SLinus Torvalds	.long	__pabt_invalid			@  8
10921da177e4SLinus Torvalds	.long	__pabt_invalid			@  9
10931da177e4SLinus Torvalds	.long	__pabt_invalid			@  a
10941da177e4SLinus Torvalds	.long	__pabt_invalid			@  b
10951da177e4SLinus Torvalds	.long	__pabt_invalid			@  c
10961da177e4SLinus Torvalds	.long	__pabt_invalid			@  d
10971da177e4SLinus Torvalds	.long	__pabt_invalid			@  e
10981da177e4SLinus Torvalds	.long	__pabt_invalid			@  f
10991da177e4SLinus Torvalds
11001da177e4SLinus Torvalds/*
11011da177e4SLinus Torvalds * Undef instr entry dispatcher
11021da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
11031da177e4SLinus Torvalds */
1104b7ec4795SNicolas Pitre	vector_stub	und, UND_MODE
11051da177e4SLinus Torvalds
11061da177e4SLinus Torvalds	.long	__und_usr			@  0 (USR_26 / USR_32)
11071da177e4SLinus Torvalds	.long	__und_invalid			@  1 (FIQ_26 / FIQ_32)
11081da177e4SLinus Torvalds	.long	__und_invalid			@  2 (IRQ_26 / IRQ_32)
11091da177e4SLinus Torvalds	.long	__und_svc			@  3 (SVC_26 / SVC_32)
11101da177e4SLinus Torvalds	.long	__und_invalid			@  4
11111da177e4SLinus Torvalds	.long	__und_invalid			@  5
11121da177e4SLinus Torvalds	.long	__und_invalid			@  6
11131da177e4SLinus Torvalds	.long	__und_invalid			@  7
11141da177e4SLinus Torvalds	.long	__und_invalid			@  8
11151da177e4SLinus Torvalds	.long	__und_invalid			@  9
11161da177e4SLinus Torvalds	.long	__und_invalid			@  a
11171da177e4SLinus Torvalds	.long	__und_invalid			@  b
11181da177e4SLinus Torvalds	.long	__und_invalid			@  c
11191da177e4SLinus Torvalds	.long	__und_invalid			@  d
11201da177e4SLinus Torvalds	.long	__und_invalid			@  e
11211da177e4SLinus Torvalds	.long	__und_invalid			@  f
11221da177e4SLinus Torvalds
11231da177e4SLinus Torvalds	.align	5
11241da177e4SLinus Torvalds
11251da177e4SLinus Torvalds/*=============================================================================
11261da177e4SLinus Torvalds * Undefined FIQs
11271da177e4SLinus Torvalds *-----------------------------------------------------------------------------
11281da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
11291da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
11301da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register...  brain
11311da177e4SLinus Torvalds * damage alert!  I don't think that we can execute any code in here in any
11321da177e4SLinus Torvalds * other mode than FIQ...  Ok you can switch to another mode, but you can't
11331da177e4SLinus Torvalds * get out of that mode without clobbering one register.
11341da177e4SLinus Torvalds */
11351da177e4SLinus Torvaldsvector_fiq:
11361da177e4SLinus Torvalds	subs	pc, lr, #4
11371da177e4SLinus Torvalds
11381da177e4SLinus Torvalds/*=============================================================================
11391da177e4SLinus Torvalds * Address exception handler
11401da177e4SLinus Torvalds *-----------------------------------------------------------------------------
11411da177e4SLinus Torvalds * These aren't too critical.
11421da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode).
11431da177e4SLinus Torvalds */
11441da177e4SLinus Torvalds
11451da177e4SLinus Torvaldsvector_addrexcptn:
11461da177e4SLinus Torvalds	b	vector_addrexcptn
11471da177e4SLinus Torvalds
11481da177e4SLinus Torvalds/*
11491da177e4SLinus Torvalds * We group all the following data together to optimise
11501da177e4SLinus Torvalds * for CPUs with separate I & D caches.
11511da177e4SLinus Torvalds */
11521da177e4SLinus Torvalds	.align	5
11531da177e4SLinus Torvalds
11541da177e4SLinus Torvalds.LCvswi:
11551da177e4SLinus Torvalds	.word	vector_swi
11561da177e4SLinus Torvalds
11577933523dSRussell King	.globl	__stubs_end
11581da177e4SLinus Torvalds__stubs_end:
11591da177e4SLinus Torvalds
11607933523dSRussell King	.equ	stubs_offset, __vectors_start + 0x200 - __stubs_start
11611da177e4SLinus Torvalds
11627933523dSRussell King	.globl	__vectors_start
11637933523dSRussell King__vectors_start:
1164b86040a5SCatalin Marinas ARM(	swi	SYS_ERROR0	)
1165b86040a5SCatalin Marinas THUMB(	svc	#0		)
1166b86040a5SCatalin Marinas THUMB(	nop			)
1167b86040a5SCatalin Marinas	W(b)	vector_und + stubs_offset
1168b86040a5SCatalin Marinas	W(ldr)	pc, .LCvswi + stubs_offset
1169b86040a5SCatalin Marinas	W(b)	vector_pabt + stubs_offset
1170b86040a5SCatalin Marinas	W(b)	vector_dabt + stubs_offset
1171b86040a5SCatalin Marinas	W(b)	vector_addrexcptn + stubs_offset
1172b86040a5SCatalin Marinas	W(b)	vector_irq + stubs_offset
1173b86040a5SCatalin Marinas	W(b)	vector_fiq + stubs_offset
11741da177e4SLinus Torvalds
11757933523dSRussell King	.globl	__vectors_end
11767933523dSRussell King__vectors_end:
11771da177e4SLinus Torvalds
11781da177e4SLinus Torvalds	.data
11791da177e4SLinus Torvalds
11801da177e4SLinus Torvalds	.globl	cr_alignment
11811da177e4SLinus Torvalds	.globl	cr_no_alignment
11821da177e4SLinus Torvaldscr_alignment:
11831da177e4SLinus Torvalds	.space	4
11841da177e4SLinus Torvaldscr_no_alignment:
11851da177e4SLinus Torvalds	.space	4
118652108641Seric miao
118752108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER
118852108641Seric miao	.globl	handle_arch_irq
118952108641Seric miaohandle_arch_irq:
119052108641Seric miao	.space	4
119152108641Seric miao#endif
1192