xref: /openbmc/linux/arch/arm/kernel/entry-armv.S (revision 1b16c4bcf80e319b2226a886b72b8466179c8e3a)
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
195b059bdc3SRussell King	svc_exit r5				@ return from exception
196c4c5716eSCatalin Marinas UNWIND(.fnend		)
19793ed3970SCatalin MarinasENDPROC(__dabt_svc)
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds	.align	5
2001da177e4SLinus Torvalds__irq_svc:
201ccea7a19SRussell King	svc_entry
2021613cc11SRussell King	irq_handler
2031613cc11SRussell King
2041da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
205706fdd9fSRussell King	get_thread_info tsk
206706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
207706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get flags
20828fab1a2SRussell King	teq	r8, #0				@ if preempt count != 0
20928fab1a2SRussell King	movne	r0, #0				@ force flags to 0
2101da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2111da177e4SLinus Torvalds	blne	svc_preempt
2121da177e4SLinus Torvalds#endif
21330891c90SRussell King
2149b56febeSRussell King	svc_exit r5, irq = 1			@ return from exception
215c4c5716eSCatalin Marinas UNWIND(.fnend		)
21693ed3970SCatalin MarinasENDPROC(__irq_svc)
2171da177e4SLinus Torvalds
2181da177e4SLinus Torvalds	.ltorg
2191da177e4SLinus Torvalds
2201da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
2211da177e4SLinus Torvaldssvc_preempt:
22228fab1a2SRussell King	mov	r8, lr
2231da177e4SLinus Torvalds1:	bl	preempt_schedule_irq		@ irq en/disable is done inside
224706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get new tasks TI_FLAGS
2251da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
22628fab1a2SRussell King	moveq	pc, r8				@ go again
2271da177e4SLinus Torvalds	b	1b
2281da177e4SLinus Torvalds#endif
2291da177e4SLinus Torvalds
23015ac49b6SRussell King__und_fault:
23115ac49b6SRussell King	@ Correct the PC such that it is pointing at the instruction
23215ac49b6SRussell King	@ which caused the fault.  If the faulting instruction was ARM
23315ac49b6SRussell King	@ the PC will be pointing at the next instruction, and have to
23415ac49b6SRussell King	@ subtract 4.  Otherwise, it is Thumb, and the PC will be
23515ac49b6SRussell King	@ pointing at the second half of the Thumb instruction.  We
23615ac49b6SRussell King	@ have to subtract 2.
23715ac49b6SRussell King	ldr	r2, [r0, #S_PC]
23815ac49b6SRussell King	sub	r2, r2, r1
23915ac49b6SRussell King	str	r2, [r0, #S_PC]
24015ac49b6SRussell King	b	do_undefinstr
24115ac49b6SRussell KingENDPROC(__und_fault)
24215ac49b6SRussell King
2431da177e4SLinus Torvalds	.align	5
2441da177e4SLinus Torvalds__und_svc:
245d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES
246d30a0c8bSNicolas Pitre	@ If a kprobe is about to simulate a "stmdb sp..." instruction,
247d30a0c8bSNicolas Pitre	@ it obviously needs free stack space which then will belong to
248d30a0c8bSNicolas Pitre	@ the saved context.
249d30a0c8bSNicolas Pitre	svc_entry 64
250d30a0c8bSNicolas Pitre#else
251ccea7a19SRussell King	svc_entry
252d30a0c8bSNicolas Pitre#endif
2531da177e4SLinus Torvalds	@
2541da177e4SLinus Torvalds	@ call emulation code, which returns using r9 if it has emulated
2551da177e4SLinus Torvalds	@ the instruction, or the more conventional lr if we are to treat
2561da177e4SLinus Torvalds	@ this as a real undefined instruction
2571da177e4SLinus Torvalds	@
2581da177e4SLinus Torvalds	@  r0 - instruction
2591da177e4SLinus Torvalds	@
26083e686eaSCatalin Marinas#ifndef CONFIG_THUMB2_KERNEL
261b059bdc3SRussell King	ldr	r0, [r4, #-4]
26283e686eaSCatalin Marinas#else
26315ac49b6SRussell King	mov	r1, #2
264b059bdc3SRussell King	ldrh	r0, [r4, #-2]			@ Thumb instruction at LR - 2
26585519189SDave Martin	cmp	r0, #0xe800			@ 32-bit instruction if xx >= 0
26615ac49b6SRussell King	blo	__und_svc_fault
26715ac49b6SRussell King	ldrh	r9, [r4]			@ bottom 16 bits
26815ac49b6SRussell King	add	r4, r4, #2
26915ac49b6SRussell King	str	r4, [sp, #S_PC]
27015ac49b6SRussell King	orr	r0, r9, r0, lsl #16
27183e686eaSCatalin Marinas#endif
27215ac49b6SRussell King	adr	r9, BSYM(__und_svc_finish)
273b059bdc3SRussell King	mov	r2, r4
2741da177e4SLinus Torvalds	bl	call_fpe
2751da177e4SLinus Torvalds
27615ac49b6SRussell King	mov	r1, #4				@ PC correction to apply
27715ac49b6SRussell King__und_svc_fault:
2781da177e4SLinus Torvalds	mov	r0, sp				@ struct pt_regs *regs
27915ac49b6SRussell King	bl	__und_fault
2801da177e4SLinus Torvalds
28115ac49b6SRussell King__und_svc_finish:
282b059bdc3SRussell King	ldr	r5, [sp, #S_PSR]		@ Get SVC cpsr
283b059bdc3SRussell King	svc_exit r5				@ return from exception
284c4c5716eSCatalin Marinas UNWIND(.fnend		)
28593ed3970SCatalin MarinasENDPROC(__und_svc)
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvalds	.align	5
2881da177e4SLinus Torvalds__pabt_svc:
289ccea7a19SRussell King	svc_entry
2904fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
2918dfe7ac9SRussell King	pabt_helper
292b059bdc3SRussell King	svc_exit r5				@ return from exception
293c4c5716eSCatalin Marinas UNWIND(.fnend		)
29493ed3970SCatalin MarinasENDPROC(__pabt_svc)
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds	.align	5
29749f680eaSRussell King.LCcralign:
29849f680eaSRussell King	.word	cr_alignment
29948d7927bSPaul Brook#ifdef MULTI_DABORT
3001da177e4SLinus Torvalds.LCprocfns:
3011da177e4SLinus Torvalds	.word	processor
3021da177e4SLinus Torvalds#endif
3031da177e4SLinus Torvalds.LCfp:
3041da177e4SLinus Torvalds	.word	fp_enter
3051da177e4SLinus Torvalds
3061da177e4SLinus Torvalds/*
3071da177e4SLinus Torvalds * User mode handlers
3082dede2d8SNicolas Pitre *
3092dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
3101da177e4SLinus Torvalds */
3112dede2d8SNicolas Pitre
3122dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
3132dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8"
3142dede2d8SNicolas Pitre#endif
3152dede2d8SNicolas Pitre
316ccea7a19SRussell King	.macro	usr_entry
317c4c5716eSCatalin Marinas UNWIND(.fnstart	)
318c4c5716eSCatalin Marinas UNWIND(.cantunwind	)	@ don't unwind the user space
319ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
320b86040a5SCatalin Marinas ARM(	stmib	sp, {r1 - r12}	)
321b86040a5SCatalin Marinas THUMB(	stmia	sp, {r0 - r12}	)
322ccea7a19SRussell King
323b059bdc3SRussell King	ldmia	r0, {r3 - r5}
324ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
325b059bdc3SRussell King	mov	r6, #-1			@  ""  ""     ""        ""
326ccea7a19SRussell King
327b059bdc3SRussell King	str	r3, [sp]		@ save the "real" r0 copied
328ccea7a19SRussell King					@ from the exception stack
3291da177e4SLinus Torvalds
3301da177e4SLinus Torvalds	@
3311da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
3321da177e4SLinus Torvalds	@
333b059bdc3SRussell King	@  r4 - lr_<exception>, already fixed up for correct return/restart
334b059bdc3SRussell King	@  r5 - spsr_<exception>
335b059bdc3SRussell King	@  r6 - orig_r0 (see pt_regs definition in ptrace.h)
3361da177e4SLinus Torvalds	@
3371da177e4SLinus Torvalds	@ Also, separately save sp_usr and lr_usr
3381da177e4SLinus Torvalds	@
339b059bdc3SRussell King	stmia	r0, {r4 - r6}
340b86040a5SCatalin Marinas ARM(	stmdb	r0, {sp, lr}^			)
341b86040a5SCatalin Marinas THUMB(	store_user_sp_lr r0, r1, S_SP - S_PC	)
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvalds	@
3441da177e4SLinus Torvalds	@ Enable the alignment trap while in kernel mode
3451da177e4SLinus Torvalds	@
34649f680eaSRussell King	alignment_trap r0
3471da177e4SLinus Torvalds
3481da177e4SLinus Torvalds	@
3491da177e4SLinus Torvalds	@ Clear FP to mark the first stack frame
3501da177e4SLinus Torvalds	@
3511da177e4SLinus Torvalds	zero_fp
352f2741b78SRussell King
353f2741b78SRussell King#ifdef CONFIG_IRQSOFF_TRACER
354f2741b78SRussell King	bl	trace_hardirqs_off
355f2741b78SRussell King#endif
356b0088480SKevin Hilman	ct_user_exit save = 0
3571da177e4SLinus Torvalds	.endm
3581da177e4SLinus Torvalds
359b49c0f24SNicolas Pitre	.macro	kuser_cmpxchg_check
360*1b16c4bcSRussell King#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS) && \
361*1b16c4bcSRussell King    !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
362b49c0f24SNicolas Pitre#ifndef CONFIG_MMU
363b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing"
364b49c0f24SNicolas Pitre#else
365b49c0f24SNicolas Pitre	@ Make sure our user space atomic helper is restarted
366b49c0f24SNicolas Pitre	@ if it was interrupted in a critical region.  Here we
367b49c0f24SNicolas Pitre	@ perform a quick test inline since it should be false
368b49c0f24SNicolas Pitre	@ 99.9999% of the time.  The rest is done out of line.
369b059bdc3SRussell King	cmp	r4, #TASK_SIZE
37040fb79c8SNicolas Pitre	blhs	kuser_cmpxchg64_fixup
371b49c0f24SNicolas Pitre#endif
372b49c0f24SNicolas Pitre#endif
373b49c0f24SNicolas Pitre	.endm
374b49c0f24SNicolas Pitre
3751da177e4SLinus Torvalds	.align	5
3761da177e4SLinus Torvalds__dabt_usr:
377ccea7a19SRussell King	usr_entry
378b49c0f24SNicolas Pitre	kuser_cmpxchg_check
3791da177e4SLinus Torvalds	mov	r2, sp
380da740472SRussell King	dabt_helper
381da740472SRussell King	b	ret_from_exception
382c4c5716eSCatalin Marinas UNWIND(.fnend		)
38393ed3970SCatalin MarinasENDPROC(__dabt_usr)
3841da177e4SLinus Torvalds
3851da177e4SLinus Torvalds	.align	5
3861da177e4SLinus Torvalds__irq_usr:
387ccea7a19SRussell King	usr_entry
388bc089602SRussell King	kuser_cmpxchg_check
389187a51adSRussell King	irq_handler
3901613cc11SRussell King	get_thread_info tsk
3911da177e4SLinus Torvalds	mov	why, #0
3929fc2552aSMing Lei	b	ret_to_user_from_irq
393c4c5716eSCatalin Marinas UNWIND(.fnend		)
39493ed3970SCatalin MarinasENDPROC(__irq_usr)
3951da177e4SLinus Torvalds
3961da177e4SLinus Torvalds	.ltorg
3971da177e4SLinus Torvalds
3981da177e4SLinus Torvalds	.align	5
3991da177e4SLinus Torvalds__und_usr:
400ccea7a19SRussell King	usr_entry
401bc089602SRussell King
402b059bdc3SRussell King	mov	r2, r4
403b059bdc3SRussell King	mov	r3, r5
4041da177e4SLinus Torvalds
40515ac49b6SRussell King	@ r2 = regs->ARM_pc, which is either 2 or 4 bytes ahead of the
40615ac49b6SRussell King	@      faulting instruction depending on Thumb mode.
40715ac49b6SRussell King	@ r3 = regs->ARM_cpsr
4081da177e4SLinus Torvalds	@
40915ac49b6SRussell King	@ The emulation code returns using r9 if it has emulated the
41015ac49b6SRussell King	@ instruction, or the more conventional lr if we are to treat
41115ac49b6SRussell King	@ this as a real undefined instruction
4121da177e4SLinus Torvalds	@
413b86040a5SCatalin Marinas	adr	r9, BSYM(ret_from_exception)
41415ac49b6SRussell King
415cb170a45SPaul Brook	tst	r3, #PSR_T_BIT			@ Thumb mode?
41615ac49b6SRussell King	bne	__und_usr_thumb
41715ac49b6SRussell King	sub	r4, r2, #4			@ ARM instr at LR - 4
41815ac49b6SRussell King1:	ldrt	r0, [r4]
41926584853SCatalin Marinas#ifdef CONFIG_CPU_ENDIAN_BE8
42015ac49b6SRussell King	rev	r0, r0				@ little endian instruction
42126584853SCatalin Marinas#endif
42215ac49b6SRussell King	@ r0 = 32-bit ARM instruction which caused the exception
42315ac49b6SRussell King	@ r2 = PC value for the following instruction (:= regs->ARM_pc)
42415ac49b6SRussell King	@ r4 = PC value for the faulting instruction
42515ac49b6SRussell King	@ lr = 32-bit undefined instruction function
42615ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
42715ac49b6SRussell King	b	call_fpe
42815ac49b6SRussell King
42915ac49b6SRussell King__und_usr_thumb:
430cb170a45SPaul Brook	@ Thumb instruction
43115ac49b6SRussell King	sub	r4, r2, #2			@ First half of thumb instr at LR - 2
432ef4c5368SDave Martin#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
433ef4c5368SDave Martin/*
434ef4c5368SDave Martin * Thumb-2 instruction handling.  Note that because pre-v6 and >= v6 platforms
435ef4c5368SDave Martin * can never be supported in a single kernel, this code is not applicable at
436ef4c5368SDave Martin * all when __LINUX_ARM_ARCH__ < 6.  This allows simplifying assumptions to be
437ef4c5368SDave Martin * made about .arch directives.
438ef4c5368SDave Martin */
439ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
440ef4c5368SDave Martin/* If the target CPU may not be Thumb-2-capable, a run-time check is needed: */
441ef4c5368SDave Martin#define NEED_CPU_ARCHITECTURE
442ef4c5368SDave Martin	ldr	r5, .LCcpu_architecture
443ef4c5368SDave Martin	ldr	r5, [r5]
444ef4c5368SDave Martin	cmp	r5, #CPU_ARCH_ARMv7
44515ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
446ef4c5368SDave Martin/*
447ef4c5368SDave Martin * The following code won't get run unless the running CPU really is v7, so
448ef4c5368SDave Martin * coding round the lack of ldrht on older arches is pointless.  Temporarily
449ef4c5368SDave Martin * override the assembler target arch with the minimum required instead:
450ef4c5368SDave Martin */
451ef4c5368SDave Martin	.arch	armv6t2
452ef4c5368SDave Martin#endif
45315ac49b6SRussell King2:	ldrht	r5, [r4]
45485519189SDave Martin	cmp	r5, #0xe800			@ 32bit instruction if xx != 0
45515ac49b6SRussell King	blo	__und_usr_fault_16		@ 16bit undefined instruction
45615ac49b6SRussell King3:	ldrht	r0, [r2]
457cb170a45SPaul Brook	add	r2, r2, #2			@ r2 is PC + 2, make it PC + 4
45815ac49b6SRussell King	str	r2, [sp, #S_PC]			@ it's a 2x16bit instr, update
459cb170a45SPaul Brook	orr	r0, r0, r5, lsl #16
46015ac49b6SRussell King	adr	lr, BSYM(__und_usr_fault_32)
46115ac49b6SRussell King	@ r0 = the two 16-bit Thumb instructions which caused the exception
46215ac49b6SRussell King	@ r2 = PC value for the following Thumb instruction (:= regs->ARM_pc)
46315ac49b6SRussell King	@ r4 = PC value for the first 16-bit Thumb instruction
46415ac49b6SRussell King	@ lr = 32bit undefined instruction function
465ef4c5368SDave Martin
466ef4c5368SDave Martin#if __LINUX_ARM_ARCH__ < 7
467ef4c5368SDave Martin/* If the target arch was overridden, change it back: */
468ef4c5368SDave Martin#ifdef CONFIG_CPU_32v6K
469ef4c5368SDave Martin	.arch	armv6k
470cb170a45SPaul Brook#else
471ef4c5368SDave Martin	.arch	armv6
472ef4c5368SDave Martin#endif
473ef4c5368SDave Martin#endif /* __LINUX_ARM_ARCH__ < 7 */
474ef4c5368SDave Martin#else /* !(CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7) */
47515ac49b6SRussell King	b	__und_usr_fault_16
476cb170a45SPaul Brook#endif
477c4c5716eSCatalin Marinas UNWIND(.fnend)
47893ed3970SCatalin MarinasENDPROC(__und_usr)
479cb170a45SPaul Brook
4801da177e4SLinus Torvalds/*
48115ac49b6SRussell King * The out of line fixup for the ldrt instructions above.
4821da177e4SLinus Torvalds */
4834260415fSRussell King	.pushsection .fixup, "ax"
484667d1b48SWill Deacon	.align	2
485cb170a45SPaul Brook4:	mov	pc, r9
4864260415fSRussell King	.popsection
4874260415fSRussell King	.pushsection __ex_table,"a"
488cb170a45SPaul Brook	.long	1b, 4b
489c89cefedSGuennadi Liakhovetski#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7
490cb170a45SPaul Brook	.long	2b, 4b
491cb170a45SPaul Brook	.long	3b, 4b
492cb170a45SPaul Brook#endif
4934260415fSRussell King	.popsection
4941da177e4SLinus Torvalds
4951da177e4SLinus Torvalds/*
4961da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction.
4971da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler.
4981da177e4SLinus Torvalds *
4991da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor
5001da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well
5011da177e4SLinus Torvalds * defined.  The only instructions that should fault are the
5021da177e4SLinus Torvalds * co-processor instructions.  However, we have to watch out
5031da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug.
5041da177e4SLinus Torvalds *
505b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all
506b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have
507b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's
508b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs
509b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the
510b5872db4SCatalin Marinas * NEON handler code.
511b5872db4SCatalin Marinas *
5121da177e4SLinus Torvalds * Emulators may wish to make use of the following registers:
51315ac49b6SRussell King *  r0  = instruction opcode (32-bit ARM or two 16-bit Thumb)
51415ac49b6SRussell King *  r2  = PC value to resume execution after successful emulation
515db6ccbb6SRussell King *  r9  = normal "successful" return address
51615ac49b6SRussell King *  r10 = this threads thread_info structure
517db6ccbb6SRussell King *  lr  = unrecognised instruction return address
51815ac49b6SRussell King * IRQs disabled, FIQs enabled.
5191da177e4SLinus Torvalds */
520cb170a45SPaul Brook	@
521cb170a45SPaul Brook	@ Fall-through from Thumb-2 __und_usr
522cb170a45SPaul Brook	@
523cb170a45SPaul Brook#ifdef CONFIG_NEON
524d3f79584SRussell King	get_thread_info r10			@ get current thread
525cb170a45SPaul Brook	adr	r6, .LCneon_thumb_opcodes
526cb170a45SPaul Brook	b	2f
527cb170a45SPaul Brook#endif
5281da177e4SLinus Torvaldscall_fpe:
529d3f79584SRussell King	get_thread_info r10			@ get current thread
530b5872db4SCatalin Marinas#ifdef CONFIG_NEON
531cb170a45SPaul Brook	adr	r6, .LCneon_arm_opcodes
532d3f79584SRussell King2:	ldr	r5, [r6], #4			@ mask value
533b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ opcode bits matching in mask
534d3f79584SRussell King	cmp	r5, #0				@ end mask?
535d3f79584SRussell King	beq	1f
536d3f79584SRussell King	and	r8, r0, r5
537b5872db4SCatalin Marinas	cmp	r8, r7				@ NEON instruction?
538b5872db4SCatalin Marinas	bne	2b
539b5872db4SCatalin Marinas	mov	r7, #1
540b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 10]	@ mark CP#10 as used
541b5872db4SCatalin Marinas	strb	r7, [r10, #TI_USED_CP + 11]	@ mark CP#11 as used
542b5872db4SCatalin Marinas	b	do_vfp				@ let VFP handler handle this
543b5872db4SCatalin Marinas1:
544b5872db4SCatalin Marinas#endif
5451da177e4SLinus Torvalds	tst	r0, #0x08000000			@ only CDP/CPRT/LDC/STC have bit 27
546cb170a45SPaul Brook	tstne	r0, #0x04000000			@ bit 26 set on both ARM and Thumb-2
5471da177e4SLinus Torvalds	moveq	pc, lr
5481da177e4SLinus Torvalds	and	r8, r0, #0x00000f00		@ mask out CP number
549b86040a5SCatalin Marinas THUMB(	lsr	r8, r8, #8		)
5501da177e4SLinus Torvalds	mov	r7, #1
5511da177e4SLinus Torvalds	add	r6, r10, #TI_USED_CP
552b86040a5SCatalin Marinas ARM(	strb	r7, [r6, r8, lsr #8]	)	@ set appropriate used_cp[]
553b86040a5SCatalin Marinas THUMB(	strb	r7, [r6, r8]		)	@ set appropriate used_cp[]
5541da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT
5551da177e4SLinus Torvalds	@ Test if we need to give access to iWMMXt coprocessors
5561da177e4SLinus Torvalds	ldr	r5, [r10, #TI_FLAGS]
5571da177e4SLinus Torvalds	rsbs	r7, r8, #(1 << 8)		@ CP 0 or 1 only
5581da177e4SLinus Torvalds	movcss	r7, r5, lsr #(TIF_USING_IWMMXT + 1)
5591da177e4SLinus Torvalds	bcs	iwmmxt_task_enable
5601da177e4SLinus Torvalds#endif
561b86040a5SCatalin Marinas ARM(	add	pc, pc, r8, lsr #6	)
562b86040a5SCatalin Marinas THUMB(	lsl	r8, r8, #2		)
563b86040a5SCatalin Marinas THUMB(	add	pc, r8			)
564b86040a5SCatalin Marinas	nop
5651da177e4SLinus Torvalds
566a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#0
567b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#1 (FPE)
568b86040a5SCatalin Marinas	W(b)	do_fpe				@ CP#2 (FPE)
569a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#3
570c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH
571c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#4 (MaverickCrunch)
572c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#5 (MaverickCrunch)
573c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#6 (MaverickCrunch)
574c17fad11SLennert Buytenhek#else
575a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#4
576a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#5
577a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#6
578c17fad11SLennert Buytenhek#endif
579a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#7
580a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#8
581a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#9
5821da177e4SLinus Torvalds#ifdef CONFIG_VFP
583b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#10 (VFP)
584b86040a5SCatalin Marinas	W(b)	do_vfp				@ CP#11 (VFP)
5851da177e4SLinus Torvalds#else
586a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#10 (VFP)
587a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#11 (VFP)
5881da177e4SLinus Torvalds#endif
589a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#12
590a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#13
591a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#14 (Debug)
592a771fe6eSCatalin Marinas	movw_pc	lr				@ CP#15 (Control)
5931da177e4SLinus Torvalds
594ef4c5368SDave Martin#ifdef NEED_CPU_ARCHITECTURE
595ef4c5368SDave Martin	.align	2
596ef4c5368SDave Martin.LCcpu_architecture:
597ef4c5368SDave Martin	.word	__cpu_architecture
598ef4c5368SDave Martin#endif
599ef4c5368SDave Martin
600b5872db4SCatalin Marinas#ifdef CONFIG_NEON
601b5872db4SCatalin Marinas	.align	6
602b5872db4SCatalin Marinas
603cb170a45SPaul Brook.LCneon_arm_opcodes:
604b5872db4SCatalin Marinas	.word	0xfe000000			@ mask
605b5872db4SCatalin Marinas	.word	0xf2000000			@ opcode
606b5872db4SCatalin Marinas
607b5872db4SCatalin Marinas	.word	0xff100000			@ mask
608b5872db4SCatalin Marinas	.word	0xf4000000			@ opcode
609b5872db4SCatalin Marinas
610b5872db4SCatalin Marinas	.word	0x00000000			@ mask
611b5872db4SCatalin Marinas	.word	0x00000000			@ opcode
612cb170a45SPaul Brook
613cb170a45SPaul Brook.LCneon_thumb_opcodes:
614cb170a45SPaul Brook	.word	0xef000000			@ mask
615cb170a45SPaul Brook	.word	0xef000000			@ opcode
616cb170a45SPaul Brook
617cb170a45SPaul Brook	.word	0xff100000			@ mask
618cb170a45SPaul Brook	.word	0xf9000000			@ opcode
619cb170a45SPaul Brook
620cb170a45SPaul Brook	.word	0x00000000			@ mask
621cb170a45SPaul Brook	.word	0x00000000			@ opcode
622b5872db4SCatalin Marinas#endif
623b5872db4SCatalin Marinas
6241da177e4SLinus Torvaldsdo_fpe:
6255d25ac03SRussell King	enable_irq
6261da177e4SLinus Torvalds	ldr	r4, .LCfp
6271da177e4SLinus Torvalds	add	r10, r10, #TI_FPSTATE		@ r10 = workspace
6281da177e4SLinus Torvalds	ldr	pc, [r4]			@ Call FP module USR entry point
6291da177e4SLinus Torvalds
6301da177e4SLinus Torvalds/*
6311da177e4SLinus Torvalds * The FP module is called with these registers set:
6321da177e4SLinus Torvalds *  r0  = instruction
6331da177e4SLinus Torvalds *  r2  = PC+4
6341da177e4SLinus Torvalds *  r9  = normal "successful" return address
6351da177e4SLinus Torvalds *  r10 = FP workspace
6361da177e4SLinus Torvalds *  lr  = unrecognised FP instruction return address
6371da177e4SLinus Torvalds */
6381da177e4SLinus Torvalds
639124efc27SSantosh Shilimkar	.pushsection .data
6401da177e4SLinus TorvaldsENTRY(fp_enter)
641db6ccbb6SRussell King	.word	no_fp
642124efc27SSantosh Shilimkar	.popsection
6431da177e4SLinus Torvalds
64483e686eaSCatalin MarinasENTRY(no_fp)
64583e686eaSCatalin Marinas	mov	pc, lr
64683e686eaSCatalin MarinasENDPROC(no_fp)
647db6ccbb6SRussell King
64815ac49b6SRussell King__und_usr_fault_32:
64915ac49b6SRussell King	mov	r1, #4
65015ac49b6SRussell King	b	1f
65115ac49b6SRussell King__und_usr_fault_16:
65215ac49b6SRussell King	mov	r1, #2
65315ac49b6SRussell King1:	enable_irq
6541da177e4SLinus Torvalds	mov	r0, sp
655b86040a5SCatalin Marinas	adr	lr, BSYM(ret_from_exception)
65615ac49b6SRussell King	b	__und_fault
65715ac49b6SRussell KingENDPROC(__und_usr_fault_32)
65815ac49b6SRussell KingENDPROC(__und_usr_fault_16)
6591da177e4SLinus Torvalds
6601da177e4SLinus Torvalds	.align	5
6611da177e4SLinus Torvalds__pabt_usr:
662ccea7a19SRussell King	usr_entry
6634fb28474SKirill A. Shutemov	mov	r2, sp				@ regs
6648dfe7ac9SRussell King	pabt_helper
665c4c5716eSCatalin Marinas UNWIND(.fnend		)
6661da177e4SLinus Torvalds	/* fall through */
6671da177e4SLinus Torvalds/*
6681da177e4SLinus Torvalds * This is the return code to user mode for abort handlers
6691da177e4SLinus Torvalds */
6701da177e4SLinus TorvaldsENTRY(ret_from_exception)
671c4c5716eSCatalin Marinas UNWIND(.fnstart	)
672c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
6731da177e4SLinus Torvalds	get_thread_info tsk
6741da177e4SLinus Torvalds	mov	why, #0
6751da177e4SLinus Torvalds	b	ret_to_user
676c4c5716eSCatalin Marinas UNWIND(.fnend		)
67793ed3970SCatalin MarinasENDPROC(__pabt_usr)
67893ed3970SCatalin MarinasENDPROC(ret_from_exception)
6791da177e4SLinus Torvalds
6801da177e4SLinus Torvalds/*
6811da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors
6821da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
6831da177e4SLinus Torvalds * previous and next are guaranteed not to be the same.
6841da177e4SLinus Torvalds */
6851da177e4SLinus TorvaldsENTRY(__switch_to)
686c4c5716eSCatalin Marinas UNWIND(.fnstart	)
687c4c5716eSCatalin Marinas UNWIND(.cantunwind	)
6881da177e4SLinus Torvalds	add	ip, r1, #TI_CPU_SAVE
689b86040a5SCatalin Marinas ARM(	stmia	ip!, {r4 - sl, fp, sp, lr} )	@ Store most regs on stack
690b86040a5SCatalin Marinas THUMB(	stmia	ip!, {r4 - sl, fp}	   )	@ Store most regs on stack
691b86040a5SCatalin Marinas THUMB(	str	sp, [ip], #4		   )
692b86040a5SCatalin Marinas THUMB(	str	lr, [ip], #4		   )
693a4780adeSAndré Hentschel	ldr	r4, [r2, #TI_TP_VALUE]
694a4780adeSAndré Hentschel	ldr	r5, [r2, #TI_TP_VALUE + 4]
695247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
696d6551e88SRussell King	ldr	r6, [r2, #TI_CPU_DOMAIN]
697afeb90caSHyok S. Choi#endif
698a4780adeSAndré Hentschel	switch_tls r1, r4, r5, r3, r7
699df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
700df0698beSNicolas Pitre	ldr	r7, [r2, #TI_TASK]
701df0698beSNicolas Pitre	ldr	r8, =__stack_chk_guard
702df0698beSNicolas Pitre	ldr	r7, [r7, #TSK_STACK_CANARY]
703df0698beSNicolas Pitre#endif
704247055aaSCatalin Marinas#ifdef CONFIG_CPU_USE_DOMAINS
7051da177e4SLinus Torvalds	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
706afeb90caSHyok S. Choi#endif
707d6551e88SRussell King	mov	r5, r0
708d6551e88SRussell King	add	r4, r2, #TI_CPU_SAVE
709d6551e88SRussell King	ldr	r0, =thread_notify_head
710d6551e88SRussell King	mov	r1, #THREAD_NOTIFY_SWITCH
711d6551e88SRussell King	bl	atomic_notifier_call_chain
712df0698beSNicolas Pitre#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
713df0698beSNicolas Pitre	str	r7, [r8]
714df0698beSNicolas Pitre#endif
715b86040a5SCatalin Marinas THUMB(	mov	ip, r4			   )
716d6551e88SRussell King	mov	r0, r5
717b86040a5SCatalin Marinas ARM(	ldmia	r4, {r4 - sl, fp, sp, pc}  )	@ Load all regs saved previously
718b86040a5SCatalin Marinas THUMB(	ldmia	ip!, {r4 - sl, fp}	   )	@ Load all regs saved previously
719b86040a5SCatalin Marinas THUMB(	ldr	sp, [ip], #4		   )
720b86040a5SCatalin Marinas THUMB(	ldr	pc, [ip]		   )
721c4c5716eSCatalin Marinas UNWIND(.fnend		)
72293ed3970SCatalin MarinasENDPROC(__switch_to)
7231da177e4SLinus Torvalds
7241da177e4SLinus Torvalds	__INIT
7252d2669b6SNicolas Pitre
7262d2669b6SNicolas Pitre/*
7272d2669b6SNicolas Pitre * User helpers.
7282d2669b6SNicolas Pitre *
7292d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high
7302d2669b6SNicolas Pitre * vector page.  New segments (if ever needed) must be added in front of
7312d2669b6SNicolas Pitre * existing ones.  This mechanism should be used only for things that are
7322d2669b6SNicolas Pitre * really small and justified, and not be abused freely.
7332d2669b6SNicolas Pitre *
73437b83046SNicolas Pitre * See Documentation/arm/kernel_user_helpers.txt for formal definitions.
7352d2669b6SNicolas Pitre */
736b86040a5SCatalin Marinas THUMB(	.arm	)
7372d2669b6SNicolas Pitre
738ba9b5d76SNicolas Pitre	.macro	usr_ret, reg
739ba9b5d76SNicolas Pitre#ifdef CONFIG_ARM_THUMB
740ba9b5d76SNicolas Pitre	bx	\reg
741ba9b5d76SNicolas Pitre#else
742ba9b5d76SNicolas Pitre	mov	pc, \reg
743ba9b5d76SNicolas Pitre#endif
744ba9b5d76SNicolas Pitre	.endm
745ba9b5d76SNicolas Pitre
7465b43e7a3SRussell King	.macro	kuser_pad, sym, size
7475b43e7a3SRussell King	.if	(. - \sym) & 3
7485b43e7a3SRussell King	.rept	4 - (. - \sym) & 3
7495b43e7a3SRussell King	.byte	0
7505b43e7a3SRussell King	.endr
7515b43e7a3SRussell King	.endif
7525b43e7a3SRussell King	.rept	(\size - (. - \sym)) / 4
7535b43e7a3SRussell King	.word	0xe7fddef1
7545b43e7a3SRussell King	.endr
7555b43e7a3SRussell King	.endm
7565b43e7a3SRussell King
757f6f91b0dSRussell King#ifdef CONFIG_KUSER_HELPERS
7582d2669b6SNicolas Pitre	.align	5
7592d2669b6SNicolas Pitre	.globl	__kuser_helper_start
7602d2669b6SNicolas Pitre__kuser_helper_start:
7612d2669b6SNicolas Pitre
7622d2669b6SNicolas Pitre/*
76340fb79c8SNicolas Pitre * Due to the length of some sequences, __kuser_cmpxchg64 spans 2 regular
76440fb79c8SNicolas Pitre * kuser "slots", therefore 0xffff0f80 is not used as a valid entry point.
7657c612bfdSNicolas Pitre */
7667c612bfdSNicolas Pitre
76740fb79c8SNicolas Pitre__kuser_cmpxchg64:				@ 0xffff0f60
76840fb79c8SNicolas Pitre
76940fb79c8SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
77040fb79c8SNicolas Pitre
77140fb79c8SNicolas Pitre	/*
77240fb79c8SNicolas Pitre	 * Poor you.  No fast solution possible...
77340fb79c8SNicolas Pitre	 * The kernel itself must perform the operation.
77440fb79c8SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
77540fb79c8SNicolas Pitre	 */
77640fb79c8SNicolas Pitre	stmfd	sp!, {r7, lr}
77740fb79c8SNicolas Pitre	ldr	r7, 1f			@ it's 20 bits
77840fb79c8SNicolas Pitre	swi	__ARM_NR_cmpxchg64
77940fb79c8SNicolas Pitre	ldmfd	sp!, {r7, pc}
78040fb79c8SNicolas Pitre1:	.word	__ARM_NR_cmpxchg64
78140fb79c8SNicolas Pitre
78240fb79c8SNicolas Pitre#elif defined(CONFIG_CPU_32v6K)
78340fb79c8SNicolas Pitre
78440fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, r7}
78540fb79c8SNicolas Pitre	ldrd	r4, r5, [r0]			@ load old val
78640fb79c8SNicolas Pitre	ldrd	r6, r7, [r1]			@ load new val
78740fb79c8SNicolas Pitre	smp_dmb	arm
78840fb79c8SNicolas Pitre1:	ldrexd	r0, r1, [r2]			@ load current val
78940fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
79040fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
79140fb79c8SNicolas Pitre	strexdeq r3, r6, r7, [r2]		@ store newval if eq
79240fb79c8SNicolas Pitre	teqeq	r3, #1				@ success?
79340fb79c8SNicolas Pitre	beq	1b				@ if no then retry
79440fb79c8SNicolas Pitre	smp_dmb	arm
79540fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set returned val and C flag
79640fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, r7}
7975a97d0aeSWill Deacon	usr_ret	lr
79840fb79c8SNicolas Pitre
79940fb79c8SNicolas Pitre#elif !defined(CONFIG_SMP)
80040fb79c8SNicolas Pitre
80140fb79c8SNicolas Pitre#ifdef CONFIG_MMU
80240fb79c8SNicolas Pitre
80340fb79c8SNicolas Pitre	/*
80440fb79c8SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg64
80540fb79c8SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
80640fb79c8SNicolas Pitre	 * causing another process/thread to be scheduled in the middle of
80740fb79c8SNicolas Pitre	 * the critical sequence.  The same strategy as for cmpxchg is used.
80840fb79c8SNicolas Pitre	 */
80940fb79c8SNicolas Pitre	stmfd	sp!, {r4, r5, r6, lr}
81040fb79c8SNicolas Pitre	ldmia	r0, {r4, r5}			@ load old val
81140fb79c8SNicolas Pitre	ldmia	r1, {r6, lr}			@ load new val
81240fb79c8SNicolas Pitre1:	ldmia	r2, {r0, r1}			@ load current val
81340fb79c8SNicolas Pitre	eors	r3, r0, r4			@ compare with oldval (1)
81440fb79c8SNicolas Pitre	eoreqs	r3, r1, r5			@ compare with oldval (2)
81540fb79c8SNicolas Pitre2:	stmeqia	r2, {r6, lr}			@ store newval if eq
81640fb79c8SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
81740fb79c8SNicolas Pitre	ldmfd	sp!, {r4, r5, r6, pc}
81840fb79c8SNicolas Pitre
81940fb79c8SNicolas Pitre	.text
82040fb79c8SNicolas Pitrekuser_cmpxchg64_fixup:
82140fb79c8SNicolas Pitre	@ Called from kuser_cmpxchg_fixup.
8223ad55155SRussell King	@ r4 = address of interrupted insn (must be preserved).
82340fb79c8SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
82440fb79c8SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
8253ad55155SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
82640fb79c8SNicolas Pitre	mov	r7, #0xffff0fff
82740fb79c8SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0f60 + (1b - __kuser_cmpxchg64)))
8283ad55155SRussell King	subs	r8, r4, r7
82940fb79c8SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
83040fb79c8SNicolas Pitre	strcs	r7, [sp, #S_PC]
83140fb79c8SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6
83240fb79c8SNicolas Pitre	bcc	kuser_cmpxchg32_fixup
83340fb79c8SNicolas Pitre#endif
83440fb79c8SNicolas Pitre	mov	pc, lr
83540fb79c8SNicolas Pitre	.previous
83640fb79c8SNicolas Pitre
83740fb79c8SNicolas Pitre#else
83840fb79c8SNicolas Pitre#warning "NPTL on non MMU needs fixing"
83940fb79c8SNicolas Pitre	mov	r0, #-1
84040fb79c8SNicolas Pitre	adds	r0, r0, #0
84140fb79c8SNicolas Pitre	usr_ret	lr
84240fb79c8SNicolas Pitre#endif
84340fb79c8SNicolas Pitre
84440fb79c8SNicolas Pitre#else
84540fb79c8SNicolas Pitre#error "incoherent kernel configuration"
84640fb79c8SNicolas Pitre#endif
84740fb79c8SNicolas Pitre
8485b43e7a3SRussell King	kuser_pad __kuser_cmpxchg64, 64
84940fb79c8SNicolas Pitre
8507c612bfdSNicolas Pitre__kuser_memory_barrier:				@ 0xffff0fa0
851ed3768a8SDave Martin	smp_dmb	arm
852ba9b5d76SNicolas Pitre	usr_ret	lr
8537c612bfdSNicolas Pitre
8545b43e7a3SRussell King	kuser_pad __kuser_memory_barrier, 32
8557c612bfdSNicolas Pitre
8562d2669b6SNicolas Pitre__kuser_cmpxchg:				@ 0xffff0fc0
8572d2669b6SNicolas Pitre
858dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
8592d2669b6SNicolas Pitre
860dcef1f63SNicolas Pitre	/*
861dcef1f63SNicolas Pitre	 * Poor you.  No fast solution possible...
862dcef1f63SNicolas Pitre	 * The kernel itself must perform the operation.
863dcef1f63SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
864dcef1f63SNicolas Pitre	 */
8655e097445SNicolas Pitre	stmfd	sp!, {r7, lr}
86655afd264SDave Martin	ldr	r7, 1f			@ it's 20 bits
867cc20d429SRussell King	swi	__ARM_NR_cmpxchg
8685e097445SNicolas Pitre	ldmfd	sp!, {r7, pc}
869cc20d429SRussell King1:	.word	__ARM_NR_cmpxchg
870dcef1f63SNicolas Pitre
871dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6
8722d2669b6SNicolas Pitre
87349bca4c2SNicolas Pitre#ifdef CONFIG_MMU
874b49c0f24SNicolas Pitre
875b49c0f24SNicolas Pitre	/*
876b49c0f24SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg
877b49c0f24SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
878b49c0f24SNicolas Pitre	 * causing another process/thread to be scheduled in the middle
879b49c0f24SNicolas Pitre	 * of the critical sequence.  To prevent this, code is added to
880b49c0f24SNicolas Pitre	 * the IRQ and data abort exception handlers to set the pc back
881b49c0f24SNicolas Pitre	 * to the beginning of the critical section if it is found to be
882b49c0f24SNicolas Pitre	 * within that critical section (see kuser_cmpxchg_fixup).
883b49c0f24SNicolas Pitre	 */
884b49c0f24SNicolas Pitre1:	ldr	r3, [r2]			@ load current val
885b49c0f24SNicolas Pitre	subs	r3, r3, r0			@ compare with oldval
886b49c0f24SNicolas Pitre2:	streq	r1, [r2]			@ store newval if eq
887b49c0f24SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
888b49c0f24SNicolas Pitre	usr_ret	lr
889b49c0f24SNicolas Pitre
890b49c0f24SNicolas Pitre	.text
89140fb79c8SNicolas Pitrekuser_cmpxchg32_fixup:
892b49c0f24SNicolas Pitre	@ Called from kuser_cmpxchg_check macro.
893b059bdc3SRussell King	@ r4 = address of interrupted insn (must be preserved).
894b49c0f24SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
895b49c0f24SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
896b059bdc3SRussell King	@ If r4 >= 1b and r4 <= 2b then saved pc_usr is set to 1b.
897b49c0f24SNicolas Pitre	mov	r7, #0xffff0fff
898b49c0f24SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
899b059bdc3SRussell King	subs	r8, r4, r7
900b49c0f24SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
901b49c0f24SNicolas Pitre	strcs	r7, [sp, #S_PC]
902b49c0f24SNicolas Pitre	mov	pc, lr
903b49c0f24SNicolas Pitre	.previous
904b49c0f24SNicolas Pitre
90549bca4c2SNicolas Pitre#else
90649bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing"
90749bca4c2SNicolas Pitre	mov	r0, #-1
90849bca4c2SNicolas Pitre	adds	r0, r0, #0
909ba9b5d76SNicolas Pitre	usr_ret	lr
910b49c0f24SNicolas Pitre#endif
9112d2669b6SNicolas Pitre
9122d2669b6SNicolas Pitre#else
9132d2669b6SNicolas Pitre
914ed3768a8SDave Martin	smp_dmb	arm
915b49c0f24SNicolas Pitre1:	ldrex	r3, [r2]
9162d2669b6SNicolas Pitre	subs	r3, r3, r0
9172d2669b6SNicolas Pitre	strexeq	r3, r1, [r2]
918b49c0f24SNicolas Pitre	teqeq	r3, #1
919b49c0f24SNicolas Pitre	beq	1b
9202d2669b6SNicolas Pitre	rsbs	r0, r3, #0
921b49c0f24SNicolas Pitre	/* beware -- each __kuser slot must be 8 instructions max */
922f00ec48fSRussell King	ALT_SMP(b	__kuser_memory_barrier)
923f00ec48fSRussell King	ALT_UP(usr_ret	lr)
9242d2669b6SNicolas Pitre
9252d2669b6SNicolas Pitre#endif
9262d2669b6SNicolas Pitre
9275b43e7a3SRussell King	kuser_pad __kuser_cmpxchg, 32
9282d2669b6SNicolas Pitre
9292d2669b6SNicolas Pitre__kuser_get_tls:				@ 0xffff0fe0
930f159f4edSTony Lindgren	ldr	r0, [pc, #(16 - 8)]	@ read TLS, set in kuser_get_tls_init
931ba9b5d76SNicolas Pitre	usr_ret	lr
932f159f4edSTony Lindgren	mrc	p15, 0, r0, c13, c0, 3	@ 0xffff0fe8 hardware TLS code
9335b43e7a3SRussell King	kuser_pad __kuser_get_tls, 16
9345b43e7a3SRussell King	.rep	3
935f159f4edSTony Lindgren	.word	0			@ 0xffff0ff0 software TLS value, then
936f159f4edSTony Lindgren	.endr				@ pad up to __kuser_helper_version
9372d2669b6SNicolas Pitre
9382d2669b6SNicolas Pitre__kuser_helper_version:				@ 0xffff0ffc
9392d2669b6SNicolas Pitre	.word	((__kuser_helper_end - __kuser_helper_start) >> 5)
9402d2669b6SNicolas Pitre
9412d2669b6SNicolas Pitre	.globl	__kuser_helper_end
9422d2669b6SNicolas Pitre__kuser_helper_end:
9432d2669b6SNicolas Pitre
944f6f91b0dSRussell King#endif
945f6f91b0dSRussell King
946b86040a5SCatalin Marinas THUMB(	.thumb	)
9472d2669b6SNicolas Pitre
9481da177e4SLinus Torvalds/*
9491da177e4SLinus Torvalds * Vector stubs.
9501da177e4SLinus Torvalds *
95119accfd3SRussell King * This code is copied to 0xffff1000 so we can use branches in the
95219accfd3SRussell King * vectors, rather than ldr's.  Note that this code must not exceed
95319accfd3SRussell King * a page size.
9541da177e4SLinus Torvalds *
9551da177e4SLinus Torvalds * Common stub entry macro:
9561da177e4SLinus Torvalds *   Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
957ccea7a19SRussell King *
958ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address
959ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler.
9601da177e4SLinus Torvalds */
961b7ec4795SNicolas Pitre	.macro	vector_stub, name, mode, correction=0
9621da177e4SLinus Torvalds	.align	5
9631da177e4SLinus Torvalds
9641da177e4SLinus Torvaldsvector_\name:
9651da177e4SLinus Torvalds	.if \correction
9661da177e4SLinus Torvalds	sub	lr, lr, #\correction
9671da177e4SLinus Torvalds	.endif
9681da177e4SLinus Torvalds
969ccea7a19SRussell King	@
970ccea7a19SRussell King	@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
971ccea7a19SRussell King	@ (parent CPSR)
972ccea7a19SRussell King	@
973ccea7a19SRussell King	stmia	sp, {r0, lr}		@ save r0, lr
974ccea7a19SRussell King	mrs	lr, spsr
975ccea7a19SRussell King	str	lr, [sp, #8]		@ save spsr
976ccea7a19SRussell King
977ccea7a19SRussell King	@
978ccea7a19SRussell King	@ Prepare for SVC32 mode.  IRQs remain disabled.
979ccea7a19SRussell King	@
980ccea7a19SRussell King	mrs	r0, cpsr
981b86040a5SCatalin Marinas	eor	r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
982ccea7a19SRussell King	msr	spsr_cxsf, r0
983ccea7a19SRussell King
984ccea7a19SRussell King	@
985ccea7a19SRussell King	@ the branch table must immediately follow this code
986ccea7a19SRussell King	@
987ccea7a19SRussell King	and	lr, lr, #0x0f
988b86040a5SCatalin Marinas THUMB(	adr	r0, 1f			)
989b86040a5SCatalin Marinas THUMB(	ldr	lr, [r0, lr, lsl #2]	)
990b7ec4795SNicolas Pitre	mov	r0, sp
991b86040a5SCatalin Marinas ARM(	ldr	lr, [pc, lr, lsl #2]	)
992ccea7a19SRussell King	movs	pc, lr			@ branch to handler in SVC mode
99393ed3970SCatalin MarinasENDPROC(vector_\name)
99488987ef9SCatalin Marinas
99588987ef9SCatalin Marinas	.align	2
99688987ef9SCatalin Marinas	@ handler addresses follow this label
99788987ef9SCatalin Marinas1:
9981da177e4SLinus Torvalds	.endm
9991da177e4SLinus Torvalds
1000b9b32bf7SRussell King	.section .stubs, "ax", %progbits
10011da177e4SLinus Torvalds__stubs_start:
100219accfd3SRussell King	@ This must be the first word
100319accfd3SRussell King	.word	vector_swi
100419accfd3SRussell King
100519accfd3SRussell Kingvector_rst:
100619accfd3SRussell King ARM(	swi	SYS_ERROR0	)
100719accfd3SRussell King THUMB(	svc	#0		)
100819accfd3SRussell King THUMB(	nop			)
100919accfd3SRussell King	b	vector_und
101019accfd3SRussell King
10111da177e4SLinus Torvalds/*
10121da177e4SLinus Torvalds * Interrupt dispatcher
10131da177e4SLinus Torvalds */
1014b7ec4795SNicolas Pitre	vector_stub	irq, IRQ_MODE, 4
10151da177e4SLinus Torvalds
10161da177e4SLinus Torvalds	.long	__irq_usr			@  0  (USR_26 / USR_32)
10171da177e4SLinus Torvalds	.long	__irq_invalid			@  1  (FIQ_26 / FIQ_32)
10181da177e4SLinus Torvalds	.long	__irq_invalid			@  2  (IRQ_26 / IRQ_32)
10191da177e4SLinus Torvalds	.long	__irq_svc			@  3  (SVC_26 / SVC_32)
10201da177e4SLinus Torvalds	.long	__irq_invalid			@  4
10211da177e4SLinus Torvalds	.long	__irq_invalid			@  5
10221da177e4SLinus Torvalds	.long	__irq_invalid			@  6
10231da177e4SLinus Torvalds	.long	__irq_invalid			@  7
10241da177e4SLinus Torvalds	.long	__irq_invalid			@  8
10251da177e4SLinus Torvalds	.long	__irq_invalid			@  9
10261da177e4SLinus Torvalds	.long	__irq_invalid			@  a
10271da177e4SLinus Torvalds	.long	__irq_invalid			@  b
10281da177e4SLinus Torvalds	.long	__irq_invalid			@  c
10291da177e4SLinus Torvalds	.long	__irq_invalid			@  d
10301da177e4SLinus Torvalds	.long	__irq_invalid			@  e
10311da177e4SLinus Torvalds	.long	__irq_invalid			@  f
10321da177e4SLinus Torvalds
10331da177e4SLinus Torvalds/*
10341da177e4SLinus Torvalds * Data abort dispatcher
10351da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10361da177e4SLinus Torvalds */
1037b7ec4795SNicolas Pitre	vector_stub	dabt, ABT_MODE, 8
10381da177e4SLinus Torvalds
10391da177e4SLinus Torvalds	.long	__dabt_usr			@  0  (USR_26 / USR_32)
10401da177e4SLinus Torvalds	.long	__dabt_invalid			@  1  (FIQ_26 / FIQ_32)
10411da177e4SLinus Torvalds	.long	__dabt_invalid			@  2  (IRQ_26 / IRQ_32)
10421da177e4SLinus Torvalds	.long	__dabt_svc			@  3  (SVC_26 / SVC_32)
10431da177e4SLinus Torvalds	.long	__dabt_invalid			@  4
10441da177e4SLinus Torvalds	.long	__dabt_invalid			@  5
10451da177e4SLinus Torvalds	.long	__dabt_invalid			@  6
10461da177e4SLinus Torvalds	.long	__dabt_invalid			@  7
10471da177e4SLinus Torvalds	.long	__dabt_invalid			@  8
10481da177e4SLinus Torvalds	.long	__dabt_invalid			@  9
10491da177e4SLinus Torvalds	.long	__dabt_invalid			@  a
10501da177e4SLinus Torvalds	.long	__dabt_invalid			@  b
10511da177e4SLinus Torvalds	.long	__dabt_invalid			@  c
10521da177e4SLinus Torvalds	.long	__dabt_invalid			@  d
10531da177e4SLinus Torvalds	.long	__dabt_invalid			@  e
10541da177e4SLinus Torvalds	.long	__dabt_invalid			@  f
10551da177e4SLinus Torvalds
10561da177e4SLinus Torvalds/*
10571da177e4SLinus Torvalds * Prefetch abort dispatcher
10581da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10591da177e4SLinus Torvalds */
1060b7ec4795SNicolas Pitre	vector_stub	pabt, ABT_MODE, 4
10611da177e4SLinus Torvalds
10621da177e4SLinus Torvalds	.long	__pabt_usr			@  0 (USR_26 / USR_32)
10631da177e4SLinus Torvalds	.long	__pabt_invalid			@  1 (FIQ_26 / FIQ_32)
10641da177e4SLinus Torvalds	.long	__pabt_invalid			@  2 (IRQ_26 / IRQ_32)
10651da177e4SLinus Torvalds	.long	__pabt_svc			@  3 (SVC_26 / SVC_32)
10661da177e4SLinus Torvalds	.long	__pabt_invalid			@  4
10671da177e4SLinus Torvalds	.long	__pabt_invalid			@  5
10681da177e4SLinus Torvalds	.long	__pabt_invalid			@  6
10691da177e4SLinus Torvalds	.long	__pabt_invalid			@  7
10701da177e4SLinus Torvalds	.long	__pabt_invalid			@  8
10711da177e4SLinus Torvalds	.long	__pabt_invalid			@  9
10721da177e4SLinus Torvalds	.long	__pabt_invalid			@  a
10731da177e4SLinus Torvalds	.long	__pabt_invalid			@  b
10741da177e4SLinus Torvalds	.long	__pabt_invalid			@  c
10751da177e4SLinus Torvalds	.long	__pabt_invalid			@  d
10761da177e4SLinus Torvalds	.long	__pabt_invalid			@  e
10771da177e4SLinus Torvalds	.long	__pabt_invalid			@  f
10781da177e4SLinus Torvalds
10791da177e4SLinus Torvalds/*
10801da177e4SLinus Torvalds * Undef instr entry dispatcher
10811da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
10821da177e4SLinus Torvalds */
1083b7ec4795SNicolas Pitre	vector_stub	und, UND_MODE
10841da177e4SLinus Torvalds
10851da177e4SLinus Torvalds	.long	__und_usr			@  0 (USR_26 / USR_32)
10861da177e4SLinus Torvalds	.long	__und_invalid			@  1 (FIQ_26 / FIQ_32)
10871da177e4SLinus Torvalds	.long	__und_invalid			@  2 (IRQ_26 / IRQ_32)
10881da177e4SLinus Torvalds	.long	__und_svc			@  3 (SVC_26 / SVC_32)
10891da177e4SLinus Torvalds	.long	__und_invalid			@  4
10901da177e4SLinus Torvalds	.long	__und_invalid			@  5
10911da177e4SLinus Torvalds	.long	__und_invalid			@  6
10921da177e4SLinus Torvalds	.long	__und_invalid			@  7
10931da177e4SLinus Torvalds	.long	__und_invalid			@  8
10941da177e4SLinus Torvalds	.long	__und_invalid			@  9
10951da177e4SLinus Torvalds	.long	__und_invalid			@  a
10961da177e4SLinus Torvalds	.long	__und_invalid			@  b
10971da177e4SLinus Torvalds	.long	__und_invalid			@  c
10981da177e4SLinus Torvalds	.long	__und_invalid			@  d
10991da177e4SLinus Torvalds	.long	__und_invalid			@  e
11001da177e4SLinus Torvalds	.long	__und_invalid			@  f
11011da177e4SLinus Torvalds
11021da177e4SLinus Torvalds	.align	5
11031da177e4SLinus Torvalds
11041da177e4SLinus Torvalds/*=============================================================================
110519accfd3SRussell King * Address exception handler
110619accfd3SRussell King *-----------------------------------------------------------------------------
110719accfd3SRussell King * These aren't too critical.
110819accfd3SRussell King * (they're not supposed to happen, and won't happen in 32-bit data mode).
110919accfd3SRussell King */
111019accfd3SRussell King
111119accfd3SRussell Kingvector_addrexcptn:
111219accfd3SRussell King	b	vector_addrexcptn
111319accfd3SRussell King
111419accfd3SRussell King/*=============================================================================
11151da177e4SLinus Torvalds * Undefined FIQs
11161da177e4SLinus Torvalds *-----------------------------------------------------------------------------
11171da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
11181da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
11191da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register...  brain
11201da177e4SLinus Torvalds * damage alert!  I don't think that we can execute any code in here in any
11211da177e4SLinus Torvalds * other mode than FIQ...  Ok you can switch to another mode, but you can't
11221da177e4SLinus Torvalds * get out of that mode without clobbering one register.
11231da177e4SLinus Torvalds */
11241da177e4SLinus Torvaldsvector_fiq:
11251da177e4SLinus Torvalds	subs	pc, lr, #4
11261da177e4SLinus Torvalds
1127e39e3f3eSRussell King	.globl	vector_fiq_offset
1128e39e3f3eSRussell King	.equ	vector_fiq_offset, vector_fiq
1129e39e3f3eSRussell King
1130b9b32bf7SRussell King	.section .vectors, "ax", %progbits
11317933523dSRussell King__vectors_start:
1132b9b32bf7SRussell King	W(b)	vector_rst
1133b9b32bf7SRussell King	W(b)	vector_und
1134b9b32bf7SRussell King	W(ldr)	pc, __vectors_start + 0x1000
1135b9b32bf7SRussell King	W(b)	vector_pabt
1136b9b32bf7SRussell King	W(b)	vector_dabt
1137b9b32bf7SRussell King	W(b)	vector_addrexcptn
1138b9b32bf7SRussell King	W(b)	vector_irq
1139b9b32bf7SRussell King	W(b)	vector_fiq
11401da177e4SLinus Torvalds
11411da177e4SLinus Torvalds	.data
11421da177e4SLinus Torvalds
11431da177e4SLinus Torvalds	.globl	cr_alignment
11441da177e4SLinus Torvalds	.globl	cr_no_alignment
11451da177e4SLinus Torvaldscr_alignment:
11461da177e4SLinus Torvalds	.space	4
11471da177e4SLinus Torvaldscr_no_alignment:
11481da177e4SLinus Torvalds	.space	4
114952108641Seric miao
115052108641Seric miao#ifdef CONFIG_MULTI_IRQ_HANDLER
115152108641Seric miao	.globl	handle_arch_irq
115252108641Seric miaohandle_arch_irq:
115352108641Seric miao	.space	4
115452108641Seric miao#endif
1155