xref: /openbmc/linux/arch/arm/kernel/entry-armv.S (revision a09e64fbc0094e3073dbb09c3b4bfe4ab669244b)
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
18f09b9979SNicolas Pitre#include <asm/memory.h>
191da177e4SLinus Torvalds#include <asm/glue.h>
201da177e4SLinus Torvalds#include <asm/vfpmacros.h>
21*a09e64fbSRussell King#include <mach/entry-macro.S>
22d6551e88SRussell King#include <asm/thread_notify.h>
231da177e4SLinus Torvalds
241da177e4SLinus Torvalds#include "entry-header.S"
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds/*
27187a51adSRussell King * Interrupt handling.  Preserves r7, r8, r9
28187a51adSRussell King */
29187a51adSRussell King	.macro	irq_handler
30f80dff9dSDan Williams	get_irqnr_preamble r5, lr
31187a51adSRussell King1:	get_irqnr_and_base r0, r6, r5, lr
32187a51adSRussell King	movne	r1, sp
33187a51adSRussell King	@
34187a51adSRussell King	@ routine called with r0 = irq number, r1 = struct pt_regs *
35187a51adSRussell King	@
36187a51adSRussell King	adrne	lr, 1b
37187a51adSRussell King	bne	asm_do_IRQ
38791be9b9SRussell King
39791be9b9SRussell King#ifdef CONFIG_SMP
40791be9b9SRussell King	/*
41791be9b9SRussell King	 * XXX
42791be9b9SRussell King	 *
43791be9b9SRussell King	 * this macro assumes that irqstat (r6) and base (r5) are
44791be9b9SRussell King	 * preserved from get_irqnr_and_base above
45791be9b9SRussell King	 */
46791be9b9SRussell King	test_for_ipi r0, r6, r5, lr
47791be9b9SRussell King	movne	r0, sp
48791be9b9SRussell King	adrne	lr, 1b
49791be9b9SRussell King	bne	do_IPI
5037ee16aeSRussell King
5137ee16aeSRussell King#ifdef CONFIG_LOCAL_TIMERS
5237ee16aeSRussell King	test_for_ltirq r0, r6, r5, lr
5337ee16aeSRussell King	movne	r0, sp
5437ee16aeSRussell King	adrne	lr, 1b
5537ee16aeSRussell King	bne	do_local_timer
5637ee16aeSRussell King#endif
57791be9b9SRussell King#endif
58791be9b9SRussell King
59187a51adSRussell King	.endm
60187a51adSRussell King
61785d3cd2SNicolas Pitre#ifdef CONFIG_KPROBES
62785d3cd2SNicolas Pitre	.section	.kprobes.text,"ax",%progbits
63785d3cd2SNicolas Pitre#else
64785d3cd2SNicolas Pitre	.text
65785d3cd2SNicolas Pitre#endif
66785d3cd2SNicolas Pitre
67187a51adSRussell King/*
681da177e4SLinus Torvalds * Invalid mode handlers
691da177e4SLinus Torvalds */
70ccea7a19SRussell King	.macro	inv_entry, reason
71ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
72ccea7a19SRussell King	stmib	sp, {r1 - lr}
731da177e4SLinus Torvalds	mov	r1, #\reason
741da177e4SLinus Torvalds	.endm
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds__pabt_invalid:
77ccea7a19SRussell King	inv_entry BAD_PREFETCH
78ccea7a19SRussell King	b	common_invalid
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds__dabt_invalid:
81ccea7a19SRussell King	inv_entry BAD_DATA
82ccea7a19SRussell King	b	common_invalid
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds__irq_invalid:
85ccea7a19SRussell King	inv_entry BAD_IRQ
86ccea7a19SRussell King	b	common_invalid
871da177e4SLinus Torvalds
881da177e4SLinus Torvalds__und_invalid:
89ccea7a19SRussell King	inv_entry BAD_UNDEFINSTR
901da177e4SLinus Torvalds
91ccea7a19SRussell King	@
92ccea7a19SRussell King	@ XXX fall through to common_invalid
93ccea7a19SRussell King	@
94ccea7a19SRussell King
95ccea7a19SRussell King@
96ccea7a19SRussell King@ common_invalid - generic code for failed exception (re-entrant version of handlers)
97ccea7a19SRussell King@
98ccea7a19SRussell Kingcommon_invalid:
99ccea7a19SRussell King	zero_fp
100ccea7a19SRussell King
101ccea7a19SRussell King	ldmia	r0, {r4 - r6}
102ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
103ccea7a19SRussell King	mov	r7, #-1			@  ""   ""    ""        ""
104ccea7a19SRussell King	str	r4, [sp]		@ save preserved r0
105ccea7a19SRussell King	stmia	r0, {r5 - r7}		@ lr_<exception>,
106ccea7a19SRussell King					@ cpsr_<exception>, "old_r0"
107ccea7a19SRussell King
1081da177e4SLinus Torvalds	mov	r0, sp
1091da177e4SLinus Torvalds	b	bad_mode
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds/*
1121da177e4SLinus Torvalds * SVC mode handlers
1131da177e4SLinus Torvalds */
1142dede2d8SNicolas Pitre
1152dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5)
1162dede2d8SNicolas Pitre#define SPFIX(code...) code
1172dede2d8SNicolas Pitre#else
1182dede2d8SNicolas Pitre#define SPFIX(code...)
1192dede2d8SNicolas Pitre#endif
1202dede2d8SNicolas Pitre
121d30a0c8bSNicolas Pitre	.macro	svc_entry, stack_hole=0
122d30a0c8bSNicolas Pitre	sub	sp, sp, #(S_FRAME_SIZE + \stack_hole)
1232dede2d8SNicolas Pitre SPFIX(	tst	sp, #4		)
1242dede2d8SNicolas Pitre SPFIX(	bicne	sp, sp, #4	)
125ccea7a19SRussell King	stmib	sp, {r1 - r12}
126ccea7a19SRussell King
127ccea7a19SRussell King	ldmia	r0, {r1 - r3}
128ccea7a19SRussell King	add	r5, sp, #S_SP		@ here for interlock avoidance
129ccea7a19SRussell King	mov	r4, #-1			@  ""  ""      ""       ""
130d30a0c8bSNicolas Pitre	add	r0, sp, #(S_FRAME_SIZE + \stack_hole)
1312dede2d8SNicolas Pitre SPFIX(	addne	r0, r0, #4	)
132ccea7a19SRussell King	str	r1, [sp]		@ save the "real" r0 copied
133ccea7a19SRussell King					@ from the exception stack
134ccea7a19SRussell King
1351da177e4SLinus Torvalds	mov	r1, lr
1361da177e4SLinus Torvalds
1371da177e4SLinus Torvalds	@
1381da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
1391da177e4SLinus Torvalds	@
1401da177e4SLinus Torvalds	@  r0 - sp_svc
1411da177e4SLinus Torvalds	@  r1 - lr_svc
1421da177e4SLinus Torvalds	@  r2 - lr_<exception>, already fixed up for correct return/restart
1431da177e4SLinus Torvalds	@  r3 - spsr_<exception>
1441da177e4SLinus Torvalds	@  r4 - orig_r0 (see pt_regs definition in ptrace.h)
1451da177e4SLinus Torvalds	@
1461da177e4SLinus Torvalds	stmia	r5, {r0 - r4}
1471da177e4SLinus Torvalds	.endm
1481da177e4SLinus Torvalds
1491da177e4SLinus Torvalds	.align	5
1501da177e4SLinus Torvalds__dabt_svc:
151ccea7a19SRussell King	svc_entry
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds	@
1541da177e4SLinus Torvalds	@ get ready to re-enable interrupts if appropriate
1551da177e4SLinus Torvalds	@
1561da177e4SLinus Torvalds	mrs	r9, cpsr
1571da177e4SLinus Torvalds	tst	r3, #PSR_I_BIT
1581da177e4SLinus Torvalds	biceq	r9, r9, #PSR_I_BIT
1591da177e4SLinus Torvalds
1601da177e4SLinus Torvalds	@
1611da177e4SLinus Torvalds	@ Call the processor-specific abort handler:
1621da177e4SLinus Torvalds	@
1631da177e4SLinus Torvalds	@  r2 - aborted context pc
1641da177e4SLinus Torvalds	@  r3 - aborted context cpsr
1651da177e4SLinus Torvalds	@
1661da177e4SLinus Torvalds	@ The abort handler must return the aborted address in r0, and
1671da177e4SLinus Torvalds	@ the fault status register in r1.  r9 must be preserved.
1681da177e4SLinus Torvalds	@
16948d7927bSPaul Brook#ifdef MULTI_DABORT
1701da177e4SLinus Torvalds	ldr	r4, .LCprocfns
1711da177e4SLinus Torvalds	mov	lr, pc
17248d7927bSPaul Brook	ldr	pc, [r4, #PROCESSOR_DABT_FUNC]
1731da177e4SLinus Torvalds#else
17448d7927bSPaul Brook	bl	CPU_DABORT_HANDLER
1751da177e4SLinus Torvalds#endif
1761da177e4SLinus Torvalds
1771da177e4SLinus Torvalds	@
1781da177e4SLinus Torvalds	@ set desired IRQ state, then call main handler
1791da177e4SLinus Torvalds	@
1801da177e4SLinus Torvalds	msr	cpsr_c, r9
1811da177e4SLinus Torvalds	mov	r2, sp
1821da177e4SLinus Torvalds	bl	do_DataAbort
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds	@
1851da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
1861da177e4SLinus Torvalds	@
1871ec42c0cSRussell King	disable_irq
1881da177e4SLinus Torvalds
1891da177e4SLinus Torvalds	@
1901da177e4SLinus Torvalds	@ restore SPSR and restart the instruction
1911da177e4SLinus Torvalds	@
1921da177e4SLinus Torvalds	ldr	r0, [sp, #S_PSR]
1931da177e4SLinus Torvalds	msr	spsr_cxsf, r0
1941da177e4SLinus Torvalds	ldmia	sp, {r0 - pc}^			@ load r0 - pc, cpsr
1951da177e4SLinus Torvalds
1961da177e4SLinus Torvalds	.align	5
1971da177e4SLinus Torvalds__irq_svc:
198ccea7a19SRussell King	svc_entry
199ccea7a19SRussell King
2007ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
2017ad1bcb2SRussell King	bl	trace_hardirqs_off
2027ad1bcb2SRussell King#endif
2031da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
204706fdd9fSRussell King	get_thread_info tsk
205706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
206706fdd9fSRussell King	add	r7, r8, #1			@ increment it
207706fdd9fSRussell King	str	r7, [tsk, #TI_PREEMPT]
2081da177e4SLinus Torvalds#endif
209ccea7a19SRussell King
210187a51adSRussell King	irq_handler
2111da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
21228fab1a2SRussell King	str	r8, [tsk, #TI_PREEMPT]		@ restore preempt count
213706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get flags
21428fab1a2SRussell King	teq	r8, #0				@ if preempt count != 0
21528fab1a2SRussell King	movne	r0, #0				@ force flags to 0
2161da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
2171da177e4SLinus Torvalds	blne	svc_preempt
2181da177e4SLinus Torvalds#endif
2191da177e4SLinus Torvalds	ldr	r0, [sp, #S_PSR]		@ irqs are already disabled
2201da177e4SLinus Torvalds	msr	spsr_cxsf, r0
2217ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
2227ad1bcb2SRussell King	tst	r0, #PSR_I_BIT
2237ad1bcb2SRussell King	bleq	trace_hardirqs_on
2247ad1bcb2SRussell King#endif
2251da177e4SLinus Torvalds	ldmia	sp, {r0 - pc}^			@ load r0 - pc, cpsr
2261da177e4SLinus Torvalds
2271da177e4SLinus Torvalds	.ltorg
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
2301da177e4SLinus Torvaldssvc_preempt:
23128fab1a2SRussell King	mov	r8, lr
2321da177e4SLinus Torvalds1:	bl	preempt_schedule_irq		@ irq en/disable is done inside
233706fdd9fSRussell King	ldr	r0, [tsk, #TI_FLAGS]		@ get new tasks TI_FLAGS
2341da177e4SLinus Torvalds	tst	r0, #_TIF_NEED_RESCHED
23528fab1a2SRussell King	moveq	pc, r8				@ go again
2361da177e4SLinus Torvalds	b	1b
2371da177e4SLinus Torvalds#endif
2381da177e4SLinus Torvalds
2391da177e4SLinus Torvalds	.align	5
2401da177e4SLinus Torvalds__und_svc:
241d30a0c8bSNicolas Pitre#ifdef CONFIG_KPROBES
242d30a0c8bSNicolas Pitre	@ If a kprobe is about to simulate a "stmdb sp..." instruction,
243d30a0c8bSNicolas Pitre	@ it obviously needs free stack space which then will belong to
244d30a0c8bSNicolas Pitre	@ the saved context.
245d30a0c8bSNicolas Pitre	svc_entry 64
246d30a0c8bSNicolas Pitre#else
247ccea7a19SRussell King	svc_entry
248d30a0c8bSNicolas Pitre#endif
2491da177e4SLinus Torvalds
2501da177e4SLinus Torvalds	@
2511da177e4SLinus Torvalds	@ call emulation code, which returns using r9 if it has emulated
2521da177e4SLinus Torvalds	@ the instruction, or the more conventional lr if we are to treat
2531da177e4SLinus Torvalds	@ this as a real undefined instruction
2541da177e4SLinus Torvalds	@
2551da177e4SLinus Torvalds	@  r0 - instruction
2561da177e4SLinus Torvalds	@
2571da177e4SLinus Torvalds	ldr	r0, [r2, #-4]
2581da177e4SLinus Torvalds	adr	r9, 1f
2591da177e4SLinus Torvalds	bl	call_fpe
2601da177e4SLinus Torvalds
2611da177e4SLinus Torvalds	mov	r0, sp				@ struct pt_regs *regs
2621da177e4SLinus Torvalds	bl	do_undefinstr
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds	@
2651da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
2661da177e4SLinus Torvalds	@
2671ec42c0cSRussell King1:	disable_irq
2681da177e4SLinus Torvalds
2691da177e4SLinus Torvalds	@
2701da177e4SLinus Torvalds	@ restore SPSR and restart the instruction
2711da177e4SLinus Torvalds	@
2721da177e4SLinus Torvalds	ldr	lr, [sp, #S_PSR]		@ Get SVC cpsr
2731da177e4SLinus Torvalds	msr	spsr_cxsf, lr
2741da177e4SLinus Torvalds	ldmia	sp, {r0 - pc}^			@ Restore SVC registers
2751da177e4SLinus Torvalds
2761da177e4SLinus Torvalds	.align	5
2771da177e4SLinus Torvalds__pabt_svc:
278ccea7a19SRussell King	svc_entry
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvalds	@
2811da177e4SLinus Torvalds	@ re-enable interrupts if appropriate
2821da177e4SLinus Torvalds	@
2831da177e4SLinus Torvalds	mrs	r9, cpsr
2841da177e4SLinus Torvalds	tst	r3, #PSR_I_BIT
2851da177e4SLinus Torvalds	biceq	r9, r9, #PSR_I_BIT
2861da177e4SLinus Torvalds
2871da177e4SLinus Torvalds	@
2881da177e4SLinus Torvalds	@ set args, then call main handler
2891da177e4SLinus Torvalds	@
2901da177e4SLinus Torvalds	@  r0 - address of faulting instruction
2911da177e4SLinus Torvalds	@  r1 - pointer to registers on stack
2921da177e4SLinus Torvalds	@
29348d7927bSPaul Brook#ifdef MULTI_PABORT
29448d7927bSPaul Brook	mov	r0, r2			@ pass address of aborted instruction.
29548d7927bSPaul Brook	ldr	r4, .LCprocfns
29648d7927bSPaul Brook	mov	lr, pc
29748d7927bSPaul Brook	ldr	pc, [r4, #PROCESSOR_PABT_FUNC]
29848d7927bSPaul Brook#else
29948d7927bSPaul Brook	CPU_PABORT_HANDLER(r0, r2)
30048d7927bSPaul Brook#endif
30148d7927bSPaul Brook	msr	cpsr_c, r9			@ Maybe enable interrupts
3021da177e4SLinus Torvalds	mov	r1, sp				@ regs
3031da177e4SLinus Torvalds	bl	do_PrefetchAbort		@ call abort handler
3041da177e4SLinus Torvalds
3051da177e4SLinus Torvalds	@
3061da177e4SLinus Torvalds	@ IRQs off again before pulling preserved data off the stack
3071da177e4SLinus Torvalds	@
3081ec42c0cSRussell King	disable_irq
3091da177e4SLinus Torvalds
3101da177e4SLinus Torvalds	@
3111da177e4SLinus Torvalds	@ restore SPSR and restart the instruction
3121da177e4SLinus Torvalds	@
3131da177e4SLinus Torvalds	ldr	r0, [sp, #S_PSR]
3141da177e4SLinus Torvalds	msr	spsr_cxsf, r0
3151da177e4SLinus Torvalds	ldmia	sp, {r0 - pc}^			@ load r0 - pc, cpsr
3161da177e4SLinus Torvalds
3171da177e4SLinus Torvalds	.align	5
31849f680eaSRussell King.LCcralign:
31949f680eaSRussell King	.word	cr_alignment
32048d7927bSPaul Brook#ifdef MULTI_DABORT
3211da177e4SLinus Torvalds.LCprocfns:
3221da177e4SLinus Torvalds	.word	processor
3231da177e4SLinus Torvalds#endif
3241da177e4SLinus Torvalds.LCfp:
3251da177e4SLinus Torvalds	.word	fp_enter
3261da177e4SLinus Torvalds
3271da177e4SLinus Torvalds/*
3281da177e4SLinus Torvalds * User mode handlers
3292dede2d8SNicolas Pitre *
3302dede2d8SNicolas Pitre * EABI note: sp_svc is always 64-bit aligned here, so should S_FRAME_SIZE
3311da177e4SLinus Torvalds */
3322dede2d8SNicolas Pitre
3332dede2d8SNicolas Pitre#if defined(CONFIG_AEABI) && (__LINUX_ARM_ARCH__ >= 5) && (S_FRAME_SIZE & 7)
3342dede2d8SNicolas Pitre#error "sizeof(struct pt_regs) must be a multiple of 8"
3352dede2d8SNicolas Pitre#endif
3362dede2d8SNicolas Pitre
337ccea7a19SRussell King	.macro	usr_entry
338ccea7a19SRussell King	sub	sp, sp, #S_FRAME_SIZE
339ccea7a19SRussell King	stmib	sp, {r1 - r12}
340ccea7a19SRussell King
341ccea7a19SRussell King	ldmia	r0, {r1 - r3}
342ccea7a19SRussell King	add	r0, sp, #S_PC		@ here for interlock avoidance
343ccea7a19SRussell King	mov	r4, #-1			@  ""  ""     ""        ""
344ccea7a19SRussell King
345ccea7a19SRussell King	str	r1, [sp]		@ save the "real" r0 copied
346ccea7a19SRussell King					@ from the exception stack
3471da177e4SLinus Torvalds
3481da177e4SLinus Torvalds	@
3491da177e4SLinus Torvalds	@ We are now ready to fill in the remaining blanks on the stack:
3501da177e4SLinus Torvalds	@
3511da177e4SLinus Torvalds	@  r2 - lr_<exception>, already fixed up for correct return/restart
3521da177e4SLinus Torvalds	@  r3 - spsr_<exception>
3531da177e4SLinus Torvalds	@  r4 - orig_r0 (see pt_regs definition in ptrace.h)
3541da177e4SLinus Torvalds	@
3551da177e4SLinus Torvalds	@ Also, separately save sp_usr and lr_usr
3561da177e4SLinus Torvalds	@
357ccea7a19SRussell King	stmia	r0, {r2 - r4}
358ccea7a19SRussell King	stmdb	r0, {sp, lr}^
3591da177e4SLinus Torvalds
3601da177e4SLinus Torvalds	@
3611da177e4SLinus Torvalds	@ Enable the alignment trap while in kernel mode
3621da177e4SLinus Torvalds	@
36349f680eaSRussell King	alignment_trap r0
3641da177e4SLinus Torvalds
3651da177e4SLinus Torvalds	@
3661da177e4SLinus Torvalds	@ Clear FP to mark the first stack frame
3671da177e4SLinus Torvalds	@
3681da177e4SLinus Torvalds	zero_fp
3691da177e4SLinus Torvalds	.endm
3701da177e4SLinus Torvalds
371b49c0f24SNicolas Pitre	.macro	kuser_cmpxchg_check
372b49c0f24SNicolas Pitre#if __LINUX_ARM_ARCH__ < 6 && !defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
373b49c0f24SNicolas Pitre#ifndef CONFIG_MMU
374b49c0f24SNicolas Pitre#warning "NPTL on non MMU needs fixing"
375b49c0f24SNicolas Pitre#else
376b49c0f24SNicolas Pitre	@ Make sure our user space atomic helper is restarted
377b49c0f24SNicolas Pitre	@ if it was interrupted in a critical region.  Here we
378b49c0f24SNicolas Pitre	@ perform a quick test inline since it should be false
379b49c0f24SNicolas Pitre	@ 99.9999% of the time.  The rest is done out of line.
380b49c0f24SNicolas Pitre	cmp	r2, #TASK_SIZE
381b49c0f24SNicolas Pitre	blhs	kuser_cmpxchg_fixup
382b49c0f24SNicolas Pitre#endif
383b49c0f24SNicolas Pitre#endif
384b49c0f24SNicolas Pitre	.endm
385b49c0f24SNicolas Pitre
3861da177e4SLinus Torvalds	.align	5
3871da177e4SLinus Torvalds__dabt_usr:
388ccea7a19SRussell King	usr_entry
389b49c0f24SNicolas Pitre	kuser_cmpxchg_check
3901da177e4SLinus Torvalds
3911da177e4SLinus Torvalds	@
3921da177e4SLinus Torvalds	@ Call the processor-specific abort handler:
3931da177e4SLinus Torvalds	@
3941da177e4SLinus Torvalds	@  r2 - aborted context pc
3951da177e4SLinus Torvalds	@  r3 - aborted context cpsr
3961da177e4SLinus Torvalds	@
3971da177e4SLinus Torvalds	@ The abort handler must return the aborted address in r0, and
3981da177e4SLinus Torvalds	@ the fault status register in r1.
3991da177e4SLinus Torvalds	@
40048d7927bSPaul Brook#ifdef MULTI_DABORT
4011da177e4SLinus Torvalds	ldr	r4, .LCprocfns
4021da177e4SLinus Torvalds	mov	lr, pc
40348d7927bSPaul Brook	ldr	pc, [r4, #PROCESSOR_DABT_FUNC]
4041da177e4SLinus Torvalds#else
40548d7927bSPaul Brook	bl	CPU_DABORT_HANDLER
4061da177e4SLinus Torvalds#endif
4071da177e4SLinus Torvalds
4081da177e4SLinus Torvalds	@
4091da177e4SLinus Torvalds	@ IRQs on, then call the main handler
4101da177e4SLinus Torvalds	@
4111ec42c0cSRussell King	enable_irq
4121da177e4SLinus Torvalds	mov	r2, sp
4131da177e4SLinus Torvalds	adr	lr, ret_from_exception
4141da177e4SLinus Torvalds	b	do_DataAbort
4151da177e4SLinus Torvalds
4161da177e4SLinus Torvalds	.align	5
4171da177e4SLinus Torvalds__irq_usr:
418ccea7a19SRussell King	usr_entry
419b49c0f24SNicolas Pitre	kuser_cmpxchg_check
4201da177e4SLinus Torvalds
4217ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
4227ad1bcb2SRussell King	bl	trace_hardirqs_off
4237ad1bcb2SRussell King#endif
4241da177e4SLinus Torvalds	get_thread_info tsk
4251da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
426706fdd9fSRussell King	ldr	r8, [tsk, #TI_PREEMPT]		@ get preempt count
427706fdd9fSRussell King	add	r7, r8, #1			@ increment it
428706fdd9fSRussell King	str	r7, [tsk, #TI_PREEMPT]
4291da177e4SLinus Torvalds#endif
430ccea7a19SRussell King
431187a51adSRussell King	irq_handler
4321da177e4SLinus Torvalds#ifdef CONFIG_PREEMPT
433706fdd9fSRussell King	ldr	r0, [tsk, #TI_PREEMPT]
434706fdd9fSRussell King	str	r8, [tsk, #TI_PREEMPT]
4351da177e4SLinus Torvalds	teq	r0, r7
4361da177e4SLinus Torvalds	strne	r0, [r0, -r0]
4371da177e4SLinus Torvalds#endif
4387ad1bcb2SRussell King#ifdef CONFIG_TRACE_IRQFLAGS
4397ad1bcb2SRussell King	bl	trace_hardirqs_on
4407ad1bcb2SRussell King#endif
441ccea7a19SRussell King
4421da177e4SLinus Torvalds	mov	why, #0
4431da177e4SLinus Torvalds	b	ret_to_user
4441da177e4SLinus Torvalds
4451da177e4SLinus Torvalds	.ltorg
4461da177e4SLinus Torvalds
4471da177e4SLinus Torvalds	.align	5
4481da177e4SLinus Torvalds__und_usr:
449ccea7a19SRussell King	usr_entry
4501da177e4SLinus Torvalds
4511da177e4SLinus Torvalds	@
4521da177e4SLinus Torvalds	@ fall through to the emulation code, which returns using r9 if
4531da177e4SLinus Torvalds	@ it has emulated the instruction, or the more conventional lr
4541da177e4SLinus Torvalds	@ if we are to treat this as a real undefined instruction
4551da177e4SLinus Torvalds	@
4561da177e4SLinus Torvalds	@  r0 - instruction
4571da177e4SLinus Torvalds	@
4581da177e4SLinus Torvalds	adr	r9, ret_from_exception
459db6ccbb6SRussell King	adr	lr, __und_usr_unknown
460cb170a45SPaul Brook	tst	r3, #PSR_T_BIT			@ Thumb mode?
461cb170a45SPaul Brook	subeq	r4, r2, #4			@ ARM instr at LR - 4
462cb170a45SPaul Brook	subne	r4, r2, #2			@ Thumb instr at LR - 2
463cb170a45SPaul Brook1:	ldreqt	r0, [r4]
464cb170a45SPaul Brook	beq	call_fpe
465cb170a45SPaul Brook	@ Thumb instruction
466cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7
467cb170a45SPaul Brook2:	ldrht	r5, [r4], #2
468cb170a45SPaul Brook	and	r0, r5, #0xf800			@ mask bits 111x x... .... ....
469cb170a45SPaul Brook	cmp	r0, #0xe800			@ 32bit instruction if xx != 0
470cb170a45SPaul Brook	blo	__und_usr_unknown
471cb170a45SPaul Brook3:	ldrht	r0, [r4]
472cb170a45SPaul Brook	add	r2, r2, #2			@ r2 is PC + 2, make it PC + 4
473cb170a45SPaul Brook	orr	r0, r0, r5, lsl #16
474cb170a45SPaul Brook#else
475cb170a45SPaul Brook	b	__und_usr_unknown
476cb170a45SPaul Brook#endif
477cb170a45SPaul Brook
4781da177e4SLinus Torvalds	@
4791da177e4SLinus Torvalds	@ fallthrough to call_fpe
4801da177e4SLinus Torvalds	@
4811da177e4SLinus Torvalds
4821da177e4SLinus Torvalds/*
4831da177e4SLinus Torvalds * The out of line fixup for the ldrt above.
4841da177e4SLinus Torvalds */
4851da177e4SLinus Torvalds	.section .fixup, "ax"
486cb170a45SPaul Brook4:	mov	pc, r9
4871da177e4SLinus Torvalds	.previous
4881da177e4SLinus Torvalds	.section __ex_table,"a"
489cb170a45SPaul Brook	.long	1b, 4b
490cb170a45SPaul Brook#if __LINUX_ARM_ARCH__ >= 7
491cb170a45SPaul Brook	.long	2b, 4b
492cb170a45SPaul Brook	.long	3b, 4b
493cb170a45SPaul Brook#endif
4941da177e4SLinus Torvalds	.previous
4951da177e4SLinus Torvalds
4961da177e4SLinus Torvalds/*
4971da177e4SLinus Torvalds * Check whether the instruction is a co-processor instruction.
4981da177e4SLinus Torvalds * If yes, we need to call the relevant co-processor handler.
4991da177e4SLinus Torvalds *
5001da177e4SLinus Torvalds * Note that we don't do a full check here for the co-processor
5011da177e4SLinus Torvalds * instructions; all instructions with bit 27 set are well
5021da177e4SLinus Torvalds * defined.  The only instructions that should fault are the
5031da177e4SLinus Torvalds * co-processor instructions.  However, we have to watch out
5041da177e4SLinus Torvalds * for the ARM6/ARM7 SWI bug.
5051da177e4SLinus Torvalds *
506b5872db4SCatalin Marinas * NEON is a special case that has to be handled here. Not all
507b5872db4SCatalin Marinas * NEON instructions are co-processor instructions, so we have
508b5872db4SCatalin Marinas * to make a special case of checking for them. Plus, there's
509b5872db4SCatalin Marinas * five groups of them, so we have a table of mask/opcode pairs
510b5872db4SCatalin Marinas * to check against, and if any match then we branch off into the
511b5872db4SCatalin Marinas * NEON handler code.
512b5872db4SCatalin Marinas *
5131da177e4SLinus Torvalds * Emulators may wish to make use of the following registers:
5141da177e4SLinus Torvalds *  r0  = instruction opcode.
5151da177e4SLinus Torvalds *  r2  = PC+4
516db6ccbb6SRussell King *  r9  = normal "successful" return address
5171da177e4SLinus Torvalds *  r10 = this threads thread_info structure.
518db6ccbb6SRussell King *  lr  = unrecognised instruction return address
5191da177e4SLinus Torvalds */
520cb170a45SPaul Brook	@
521cb170a45SPaul Brook	@ Fall-through from Thumb-2 __und_usr
522cb170a45SPaul Brook	@
523cb170a45SPaul Brook#ifdef CONFIG_NEON
524cb170a45SPaul Brook	adr	r6, .LCneon_thumb_opcodes
525cb170a45SPaul Brook	b	2f
526cb170a45SPaul Brook#endif
5271da177e4SLinus Torvaldscall_fpe:
528b5872db4SCatalin Marinas#ifdef CONFIG_NEON
529cb170a45SPaul Brook	adr	r6, .LCneon_arm_opcodes
530b5872db4SCatalin Marinas2:
531b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ mask value
532b5872db4SCatalin Marinas	cmp	r7, #0				@ end mask?
533b5872db4SCatalin Marinas	beq	1f
534b5872db4SCatalin Marinas	and	r8, r0, r7
535b5872db4SCatalin Marinas	ldr	r7, [r6], #4			@ opcode bits matching in mask
536b5872db4SCatalin Marinas	cmp	r8, r7				@ NEON instruction?
537b5872db4SCatalin Marinas	bne	2b
538b5872db4SCatalin Marinas	get_thread_info r10
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#if defined(CONFIG_CPU_ARM610) || defined(CONFIG_CPU_ARM710)
5481da177e4SLinus Torvalds	and	r8, r0, #0x0f000000		@ mask out op-code bits
5491da177e4SLinus Torvalds	teqne	r8, #0x0f000000			@ SWI (ARM6/7 bug)?
5501da177e4SLinus Torvalds#endif
5511da177e4SLinus Torvalds	moveq	pc, lr
5521da177e4SLinus Torvalds	get_thread_info r10			@ get current thread
5531da177e4SLinus Torvalds	and	r8, r0, #0x00000f00		@ mask out CP number
5541da177e4SLinus Torvalds	mov	r7, #1
5551da177e4SLinus Torvalds	add	r6, r10, #TI_USED_CP
5561da177e4SLinus Torvalds	strb	r7, [r6, r8, lsr #8]		@ set appropriate used_cp[]
5571da177e4SLinus Torvalds#ifdef CONFIG_IWMMXT
5581da177e4SLinus Torvalds	@ Test if we need to give access to iWMMXt coprocessors
5591da177e4SLinus Torvalds	ldr	r5, [r10, #TI_FLAGS]
5601da177e4SLinus Torvalds	rsbs	r7, r8, #(1 << 8)		@ CP 0 or 1 only
5611da177e4SLinus Torvalds	movcss	r7, r5, lsr #(TIF_USING_IWMMXT + 1)
5621da177e4SLinus Torvalds	bcs	iwmmxt_task_enable
5631da177e4SLinus Torvalds#endif
5641da177e4SLinus Torvalds	add	pc, pc, r8, lsr #6
5651da177e4SLinus Torvalds	mov	r0, r0
5661da177e4SLinus Torvalds
5671da177e4SLinus Torvalds	mov	pc, lr				@ CP#0
5681da177e4SLinus Torvalds	b	do_fpe				@ CP#1 (FPE)
5691da177e4SLinus Torvalds	b	do_fpe				@ CP#2 (FPE)
5701da177e4SLinus Torvalds	mov	pc, lr				@ CP#3
571c17fad11SLennert Buytenhek#ifdef CONFIG_CRUNCH
572c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#4 (MaverickCrunch)
573c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#5 (MaverickCrunch)
574c17fad11SLennert Buytenhek	b	crunch_task_enable		@ CP#6 (MaverickCrunch)
575c17fad11SLennert Buytenhek#else
5761da177e4SLinus Torvalds	mov	pc, lr				@ CP#4
5771da177e4SLinus Torvalds	mov	pc, lr				@ CP#5
5781da177e4SLinus Torvalds	mov	pc, lr				@ CP#6
579c17fad11SLennert Buytenhek#endif
5801da177e4SLinus Torvalds	mov	pc, lr				@ CP#7
5811da177e4SLinus Torvalds	mov	pc, lr				@ CP#8
5821da177e4SLinus Torvalds	mov	pc, lr				@ CP#9
5831da177e4SLinus Torvalds#ifdef CONFIG_VFP
5841da177e4SLinus Torvalds	b	do_vfp				@ CP#10 (VFP)
5851da177e4SLinus Torvalds	b	do_vfp				@ CP#11 (VFP)
5861da177e4SLinus Torvalds#else
5871da177e4SLinus Torvalds	mov	pc, lr				@ CP#10 (VFP)
5881da177e4SLinus Torvalds	mov	pc, lr				@ CP#11 (VFP)
5891da177e4SLinus Torvalds#endif
5901da177e4SLinus Torvalds	mov	pc, lr				@ CP#12
5911da177e4SLinus Torvalds	mov	pc, lr				@ CP#13
5921da177e4SLinus Torvalds	mov	pc, lr				@ CP#14 (Debug)
5931da177e4SLinus Torvalds	mov	pc, lr				@ CP#15 (Control)
5941da177e4SLinus Torvalds
595b5872db4SCatalin Marinas#ifdef CONFIG_NEON
596b5872db4SCatalin Marinas	.align	6
597b5872db4SCatalin Marinas
598cb170a45SPaul Brook.LCneon_arm_opcodes:
599b5872db4SCatalin Marinas	.word	0xfe000000			@ mask
600b5872db4SCatalin Marinas	.word	0xf2000000			@ opcode
601b5872db4SCatalin Marinas
602b5872db4SCatalin Marinas	.word	0xff100000			@ mask
603b5872db4SCatalin Marinas	.word	0xf4000000			@ opcode
604b5872db4SCatalin Marinas
605b5872db4SCatalin Marinas	.word	0x00000000			@ mask
606b5872db4SCatalin Marinas	.word	0x00000000			@ opcode
607cb170a45SPaul Brook
608cb170a45SPaul Brook.LCneon_thumb_opcodes:
609cb170a45SPaul Brook	.word	0xef000000			@ mask
610cb170a45SPaul Brook	.word	0xef000000			@ opcode
611cb170a45SPaul Brook
612cb170a45SPaul Brook	.word	0xff100000			@ mask
613cb170a45SPaul Brook	.word	0xf9000000			@ opcode
614cb170a45SPaul Brook
615cb170a45SPaul Brook	.word	0x00000000			@ mask
616cb170a45SPaul Brook	.word	0x00000000			@ opcode
617b5872db4SCatalin Marinas#endif
618b5872db4SCatalin Marinas
6191da177e4SLinus Torvaldsdo_fpe:
6205d25ac03SRussell King	enable_irq
6211da177e4SLinus Torvalds	ldr	r4, .LCfp
6221da177e4SLinus Torvalds	add	r10, r10, #TI_FPSTATE		@ r10 = workspace
6231da177e4SLinus Torvalds	ldr	pc, [r4]			@ Call FP module USR entry point
6241da177e4SLinus Torvalds
6251da177e4SLinus Torvalds/*
6261da177e4SLinus Torvalds * The FP module is called with these registers set:
6271da177e4SLinus Torvalds *  r0  = instruction
6281da177e4SLinus Torvalds *  r2  = PC+4
6291da177e4SLinus Torvalds *  r9  = normal "successful" return address
6301da177e4SLinus Torvalds *  r10 = FP workspace
6311da177e4SLinus Torvalds *  lr  = unrecognised FP instruction return address
6321da177e4SLinus Torvalds */
6331da177e4SLinus Torvalds
6341da177e4SLinus Torvalds	.data
6351da177e4SLinus TorvaldsENTRY(fp_enter)
636db6ccbb6SRussell King	.word	no_fp
637785d3cd2SNicolas Pitre	.previous
6381da177e4SLinus Torvalds
639db6ccbb6SRussell Kingno_fp:	mov	pc, lr
640db6ccbb6SRussell King
641db6ccbb6SRussell King__und_usr_unknown:
6421da177e4SLinus Torvalds	mov	r0, sp
6431da177e4SLinus Torvalds	adr	lr, ret_from_exception
6441da177e4SLinus Torvalds	b	do_undefinstr
6451da177e4SLinus Torvalds
6461da177e4SLinus Torvalds	.align	5
6471da177e4SLinus Torvalds__pabt_usr:
648ccea7a19SRussell King	usr_entry
6491da177e4SLinus Torvalds
65048d7927bSPaul Brook#ifdef MULTI_PABORT
65148d7927bSPaul Brook	mov	r0, r2			@ pass address of aborted instruction.
65248d7927bSPaul Brook	ldr	r4, .LCprocfns
65348d7927bSPaul Brook	mov	lr, pc
65448d7927bSPaul Brook	ldr	pc, [r4, #PROCESSOR_PABT_FUNC]
65548d7927bSPaul Brook#else
65648d7927bSPaul Brook	CPU_PABORT_HANDLER(r0, r2)
65748d7927bSPaul Brook#endif
6581ec42c0cSRussell King	enable_irq				@ Enable interrupts
6591da177e4SLinus Torvalds	mov	r1, sp				@ regs
6601da177e4SLinus Torvalds	bl	do_PrefetchAbort		@ call abort handler
6611da177e4SLinus Torvalds	/* fall through */
6621da177e4SLinus Torvalds/*
6631da177e4SLinus Torvalds * This is the return code to user mode for abort handlers
6641da177e4SLinus Torvalds */
6651da177e4SLinus TorvaldsENTRY(ret_from_exception)
6661da177e4SLinus Torvalds	get_thread_info tsk
6671da177e4SLinus Torvalds	mov	why, #0
6681da177e4SLinus Torvalds	b	ret_to_user
6691da177e4SLinus Torvalds
6701da177e4SLinus Torvalds/*
6711da177e4SLinus Torvalds * Register switch for ARMv3 and ARMv4 processors
6721da177e4SLinus Torvalds * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
6731da177e4SLinus Torvalds * previous and next are guaranteed not to be the same.
6741da177e4SLinus Torvalds */
6751da177e4SLinus TorvaldsENTRY(__switch_to)
6761da177e4SLinus Torvalds	add	ip, r1, #TI_CPU_SAVE
6771da177e4SLinus Torvalds	ldr	r3, [r2, #TI_TP_VALUE]
6781da177e4SLinus Torvalds	stmia	ip!, {r4 - sl, fp, sp, lr}	@ Store most regs on stack
679d6551e88SRussell King#ifdef CONFIG_MMU
680d6551e88SRussell King	ldr	r6, [r2, #TI_CPU_DOMAIN]
681afeb90caSHyok S. Choi#endif
682b876386eSRussell King#if __LINUX_ARM_ARCH__ >= 6
68343cc1981SRussell King#ifdef CONFIG_CPU_32v6K
684b876386eSRussell King	clrex
685b876386eSRussell King#else
68673394322SRussell King	strex	r5, r4, [ip]			@ Clear exclusive monitor
687b876386eSRussell King#endif
688b876386eSRussell King#endif
6894b0e07a5SNicolas Pitre#if defined(CONFIG_HAS_TLS_REG)
6902d2669b6SNicolas Pitre	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
6914b0e07a5SNicolas Pitre#elif !defined(CONFIG_TLS_REG_EMUL)
6921da177e4SLinus Torvalds	mov	r4, #0xffff0fff
6932d2669b6SNicolas Pitre	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
6942d2669b6SNicolas Pitre#endif
695afeb90caSHyok S. Choi#ifdef CONFIG_MMU
6961da177e4SLinus Torvalds	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
697afeb90caSHyok S. Choi#endif
698d6551e88SRussell King	mov	r5, r0
699d6551e88SRussell King	add	r4, r2, #TI_CPU_SAVE
700d6551e88SRussell King	ldr	r0, =thread_notify_head
701d6551e88SRussell King	mov	r1, #THREAD_NOTIFY_SWITCH
702d6551e88SRussell King	bl	atomic_notifier_call_chain
703d6551e88SRussell King	mov	r0, r5
704d6551e88SRussell King	ldmia	r4, {r4 - sl, fp, sp, pc}	@ Load all regs saved previously
7051da177e4SLinus Torvalds
7061da177e4SLinus Torvalds	__INIT
7072d2669b6SNicolas Pitre
7082d2669b6SNicolas Pitre/*
7092d2669b6SNicolas Pitre * User helpers.
7102d2669b6SNicolas Pitre *
7112d2669b6SNicolas Pitre * These are segment of kernel provided user code reachable from user space
7122d2669b6SNicolas Pitre * at a fixed address in kernel memory.  This is used to provide user space
7132d2669b6SNicolas Pitre * with some operations which require kernel help because of unimplemented
7142d2669b6SNicolas Pitre * native feature and/or instructions in many ARM CPUs. The idea is for
7152d2669b6SNicolas Pitre * this code to be executed directly in user mode for best efficiency but
7162d2669b6SNicolas Pitre * which is too intimate with the kernel counter part to be left to user
7172d2669b6SNicolas Pitre * libraries.  In fact this code might even differ from one CPU to another
7182d2669b6SNicolas Pitre * depending on the available  instruction set and restrictions like on
7192d2669b6SNicolas Pitre * SMP systems.  In other words, the kernel reserves the right to change
7202d2669b6SNicolas Pitre * this code as needed without warning. Only the entry points and their
7212d2669b6SNicolas Pitre * results are guaranteed to be stable.
7222d2669b6SNicolas Pitre *
7232d2669b6SNicolas Pitre * Each segment is 32-byte aligned and will be moved to the top of the high
7242d2669b6SNicolas Pitre * vector page.  New segments (if ever needed) must be added in front of
7252d2669b6SNicolas Pitre * existing ones.  This mechanism should be used only for things that are
7262d2669b6SNicolas Pitre * really small and justified, and not be abused freely.
7272d2669b6SNicolas Pitre *
7282d2669b6SNicolas Pitre * User space is expected to implement those things inline when optimizing
7292d2669b6SNicolas Pitre * for a processor that has the necessary native support, but only if such
7302d2669b6SNicolas Pitre * resulting binaries are already to be incompatible with earlier ARM
7312d2669b6SNicolas Pitre * processors due to the use of unsupported instructions other than what
7322d2669b6SNicolas Pitre * is provided here.  In other words don't make binaries unable to run on
7332d2669b6SNicolas Pitre * earlier processors just for the sake of not using these kernel helpers
7342d2669b6SNicolas Pitre * if your compiled code is not going to use the new instructions for other
7352d2669b6SNicolas Pitre * purpose.
7362d2669b6SNicolas Pitre */
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
7462d2669b6SNicolas Pitre	.align	5
7472d2669b6SNicolas Pitre	.globl	__kuser_helper_start
7482d2669b6SNicolas Pitre__kuser_helper_start:
7492d2669b6SNicolas Pitre
7502d2669b6SNicolas Pitre/*
7512d2669b6SNicolas Pitre * Reference prototype:
7522d2669b6SNicolas Pitre *
7537c612bfdSNicolas Pitre *	void __kernel_memory_barrier(void)
7547c612bfdSNicolas Pitre *
7557c612bfdSNicolas Pitre * Input:
7567c612bfdSNicolas Pitre *
7577c612bfdSNicolas Pitre *	lr = return address
7587c612bfdSNicolas Pitre *
7597c612bfdSNicolas Pitre * Output:
7607c612bfdSNicolas Pitre *
7617c612bfdSNicolas Pitre *	none
7627c612bfdSNicolas Pitre *
7637c612bfdSNicolas Pitre * Clobbered:
7647c612bfdSNicolas Pitre *
765b49c0f24SNicolas Pitre *	none
7667c612bfdSNicolas Pitre *
7677c612bfdSNicolas Pitre * Definition and user space usage example:
7687c612bfdSNicolas Pitre *
7697c612bfdSNicolas Pitre *	typedef void (__kernel_dmb_t)(void);
7707c612bfdSNicolas Pitre *	#define __kernel_dmb (*(__kernel_dmb_t *)0xffff0fa0)
7717c612bfdSNicolas Pitre *
7727c612bfdSNicolas Pitre * Apply any needed memory barrier to preserve consistency with data modified
7737c612bfdSNicolas Pitre * manually and __kuser_cmpxchg usage.
7747c612bfdSNicolas Pitre *
7757c612bfdSNicolas Pitre * This could be used as follows:
7767c612bfdSNicolas Pitre *
7777c612bfdSNicolas Pitre * #define __kernel_dmb() \
7787c612bfdSNicolas Pitre *         asm volatile ( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #95" \
7796896eec0SPaul Brook *	        : : : "r0", "lr","cc" )
7807c612bfdSNicolas Pitre */
7817c612bfdSNicolas Pitre
7827c612bfdSNicolas Pitre__kuser_memory_barrier:				@ 0xffff0fa0
7837c612bfdSNicolas Pitre
7847c612bfdSNicolas Pitre#if __LINUX_ARM_ARCH__ >= 6 && defined(CONFIG_SMP)
7857c612bfdSNicolas Pitre	mcr	p15, 0, r0, c7, c10, 5	@ dmb
7867c612bfdSNicolas Pitre#endif
787ba9b5d76SNicolas Pitre	usr_ret	lr
7887c612bfdSNicolas Pitre
7897c612bfdSNicolas Pitre	.align	5
7907c612bfdSNicolas Pitre
7917c612bfdSNicolas Pitre/*
7927c612bfdSNicolas Pitre * Reference prototype:
7937c612bfdSNicolas Pitre *
7942d2669b6SNicolas Pitre *	int __kernel_cmpxchg(int oldval, int newval, int *ptr)
7952d2669b6SNicolas Pitre *
7962d2669b6SNicolas Pitre * Input:
7972d2669b6SNicolas Pitre *
7982d2669b6SNicolas Pitre *	r0 = oldval
7992d2669b6SNicolas Pitre *	r1 = newval
8002d2669b6SNicolas Pitre *	r2 = ptr
8012d2669b6SNicolas Pitre *	lr = return address
8022d2669b6SNicolas Pitre *
8032d2669b6SNicolas Pitre * Output:
8042d2669b6SNicolas Pitre *
8052d2669b6SNicolas Pitre *	r0 = returned value (zero or non-zero)
8062d2669b6SNicolas Pitre *	C flag = set if r0 == 0, clear if r0 != 0
8072d2669b6SNicolas Pitre *
8082d2669b6SNicolas Pitre * Clobbered:
8092d2669b6SNicolas Pitre *
8102d2669b6SNicolas Pitre *	r3, ip, flags
8112d2669b6SNicolas Pitre *
8122d2669b6SNicolas Pitre * Definition and user space usage example:
8132d2669b6SNicolas Pitre *
8142d2669b6SNicolas Pitre *	typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr);
8152d2669b6SNicolas Pitre *	#define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0)
8162d2669b6SNicolas Pitre *
8172d2669b6SNicolas Pitre * Atomically store newval in *ptr if *ptr is equal to oldval for user space.
8182d2669b6SNicolas Pitre * Return zero if *ptr was changed or non-zero if no exchange happened.
8192d2669b6SNicolas Pitre * The C flag is also set if *ptr was changed to allow for assembly
8202d2669b6SNicolas Pitre * optimization in the calling code.
8212d2669b6SNicolas Pitre *
8225964eae8SNicolas Pitre * Notes:
8235964eae8SNicolas Pitre *
8245964eae8SNicolas Pitre *    - This routine already includes memory barriers as needed.
8255964eae8SNicolas Pitre *
8262d2669b6SNicolas Pitre * For example, a user space atomic_add implementation could look like this:
8272d2669b6SNicolas Pitre *
8282d2669b6SNicolas Pitre * #define atomic_add(ptr, val) \
8292d2669b6SNicolas Pitre *	({ register unsigned int *__ptr asm("r2") = (ptr); \
8302d2669b6SNicolas Pitre *	   register unsigned int __result asm("r1"); \
8312d2669b6SNicolas Pitre *	   asm volatile ( \
8322d2669b6SNicolas Pitre *	       "1: @ atomic_add\n\t" \
8332d2669b6SNicolas Pitre *	       "ldr	r0, [r2]\n\t" \
8342d2669b6SNicolas Pitre *	       "mov	r3, #0xffff0fff\n\t" \
8352d2669b6SNicolas Pitre *	       "add	lr, pc, #4\n\t" \
8362d2669b6SNicolas Pitre *	       "add	r1, r0, %2\n\t" \
8372d2669b6SNicolas Pitre *	       "add	pc, r3, #(0xffff0fc0 - 0xffff0fff)\n\t" \
8382d2669b6SNicolas Pitre *	       "bcc	1b" \
8392d2669b6SNicolas Pitre *	       : "=&r" (__result) \
8402d2669b6SNicolas Pitre *	       : "r" (__ptr), "rIL" (val) \
8412d2669b6SNicolas Pitre *	       : "r0","r3","ip","lr","cc","memory" ); \
8422d2669b6SNicolas Pitre *	   __result; })
8432d2669b6SNicolas Pitre */
8442d2669b6SNicolas Pitre
8452d2669b6SNicolas Pitre__kuser_cmpxchg:				@ 0xffff0fc0
8462d2669b6SNicolas Pitre
847dcef1f63SNicolas Pitre#if defined(CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG)
8482d2669b6SNicolas Pitre
849dcef1f63SNicolas Pitre	/*
850dcef1f63SNicolas Pitre	 * Poor you.  No fast solution possible...
851dcef1f63SNicolas Pitre	 * The kernel itself must perform the operation.
852dcef1f63SNicolas Pitre	 * A special ghost syscall is used for that (see traps.c).
853dcef1f63SNicolas Pitre	 */
8545e097445SNicolas Pitre	stmfd	sp!, {r7, lr}
8555e097445SNicolas Pitre	mov	r7, #0xff00		@ 0xfff0 into r7 for EABI
8565e097445SNicolas Pitre	orr	r7, r7, #0xf0
857dcef1f63SNicolas Pitre	swi	#0x9ffff0
8585e097445SNicolas Pitre	ldmfd	sp!, {r7, pc}
859dcef1f63SNicolas Pitre
860dcef1f63SNicolas Pitre#elif __LINUX_ARM_ARCH__ < 6
8612d2669b6SNicolas Pitre
86249bca4c2SNicolas Pitre#ifdef CONFIG_MMU
863b49c0f24SNicolas Pitre
864b49c0f24SNicolas Pitre	/*
865b49c0f24SNicolas Pitre	 * The only thing that can break atomicity in this cmpxchg
866b49c0f24SNicolas Pitre	 * implementation is either an IRQ or a data abort exception
867b49c0f24SNicolas Pitre	 * causing another process/thread to be scheduled in the middle
868b49c0f24SNicolas Pitre	 * of the critical sequence.  To prevent this, code is added to
869b49c0f24SNicolas Pitre	 * the IRQ and data abort exception handlers to set the pc back
870b49c0f24SNicolas Pitre	 * to the beginning of the critical section if it is found to be
871b49c0f24SNicolas Pitre	 * within that critical section (see kuser_cmpxchg_fixup).
872b49c0f24SNicolas Pitre	 */
873b49c0f24SNicolas Pitre1:	ldr	r3, [r2]			@ load current val
874b49c0f24SNicolas Pitre	subs	r3, r3, r0			@ compare with oldval
875b49c0f24SNicolas Pitre2:	streq	r1, [r2]			@ store newval if eq
876b49c0f24SNicolas Pitre	rsbs	r0, r3, #0			@ set return val and C flag
877b49c0f24SNicolas Pitre	usr_ret	lr
878b49c0f24SNicolas Pitre
879b49c0f24SNicolas Pitre	.text
880b49c0f24SNicolas Pitrekuser_cmpxchg_fixup:
881b49c0f24SNicolas Pitre	@ Called from kuser_cmpxchg_check macro.
882b49c0f24SNicolas Pitre	@ r2 = address of interrupted insn (must be preserved).
883b49c0f24SNicolas Pitre	@ sp = saved regs. r7 and r8 are clobbered.
884b49c0f24SNicolas Pitre	@ 1b = first critical insn, 2b = last critical insn.
885b49c0f24SNicolas Pitre	@ If r2 >= 1b and r2 <= 2b then saved pc_usr is set to 1b.
886b49c0f24SNicolas Pitre	mov	r7, #0xffff0fff
887b49c0f24SNicolas Pitre	sub	r7, r7, #(0xffff0fff - (0xffff0fc0 + (1b - __kuser_cmpxchg)))
888b49c0f24SNicolas Pitre	subs	r8, r2, r7
889b49c0f24SNicolas Pitre	rsbcss	r8, r8, #(2b - 1b)
890b49c0f24SNicolas Pitre	strcs	r7, [sp, #S_PC]
891b49c0f24SNicolas Pitre	mov	pc, lr
892b49c0f24SNicolas Pitre	.previous
893b49c0f24SNicolas Pitre
89449bca4c2SNicolas Pitre#else
89549bca4c2SNicolas Pitre#warning "NPTL on non MMU needs fixing"
89649bca4c2SNicolas Pitre	mov	r0, #-1
89749bca4c2SNicolas Pitre	adds	r0, r0, #0
898ba9b5d76SNicolas Pitre	usr_ret	lr
899b49c0f24SNicolas Pitre#endif
9002d2669b6SNicolas Pitre
9012d2669b6SNicolas Pitre#else
9022d2669b6SNicolas Pitre
9037c612bfdSNicolas Pitre#ifdef CONFIG_SMP
9047c612bfdSNicolas Pitre	mcr	p15, 0, r0, c7, c10, 5	@ dmb
9057c612bfdSNicolas Pitre#endif
906b49c0f24SNicolas Pitre1:	ldrex	r3, [r2]
9072d2669b6SNicolas Pitre	subs	r3, r3, r0
9082d2669b6SNicolas Pitre	strexeq	r3, r1, [r2]
909b49c0f24SNicolas Pitre	teqeq	r3, #1
910b49c0f24SNicolas Pitre	beq	1b
9112d2669b6SNicolas Pitre	rsbs	r0, r3, #0
912b49c0f24SNicolas Pitre	/* beware -- each __kuser slot must be 8 instructions max */
9137c612bfdSNicolas Pitre#ifdef CONFIG_SMP
914b49c0f24SNicolas Pitre	b	__kuser_memory_barrier
915b49c0f24SNicolas Pitre#else
916ba9b5d76SNicolas Pitre	usr_ret	lr
917b49c0f24SNicolas Pitre#endif
9182d2669b6SNicolas Pitre
9192d2669b6SNicolas Pitre#endif
9202d2669b6SNicolas Pitre
9212d2669b6SNicolas Pitre	.align	5
9222d2669b6SNicolas Pitre
9232d2669b6SNicolas Pitre/*
9242d2669b6SNicolas Pitre * Reference prototype:
9252d2669b6SNicolas Pitre *
9262d2669b6SNicolas Pitre *	int __kernel_get_tls(void)
9272d2669b6SNicolas Pitre *
9282d2669b6SNicolas Pitre * Input:
9292d2669b6SNicolas Pitre *
9302d2669b6SNicolas Pitre *	lr = return address
9312d2669b6SNicolas Pitre *
9322d2669b6SNicolas Pitre * Output:
9332d2669b6SNicolas Pitre *
9342d2669b6SNicolas Pitre *	r0 = TLS value
9352d2669b6SNicolas Pitre *
9362d2669b6SNicolas Pitre * Clobbered:
9372d2669b6SNicolas Pitre *
938b49c0f24SNicolas Pitre *	none
9392d2669b6SNicolas Pitre *
9402d2669b6SNicolas Pitre * Definition and user space usage example:
9412d2669b6SNicolas Pitre *
9422d2669b6SNicolas Pitre *	typedef int (__kernel_get_tls_t)(void);
9432d2669b6SNicolas Pitre *	#define __kernel_get_tls (*(__kernel_get_tls_t *)0xffff0fe0)
9442d2669b6SNicolas Pitre *
9452d2669b6SNicolas Pitre * Get the TLS value as previously set via the __ARM_NR_set_tls syscall.
9462d2669b6SNicolas Pitre *
9472d2669b6SNicolas Pitre * This could be used as follows:
9482d2669b6SNicolas Pitre *
9492d2669b6SNicolas Pitre * #define __kernel_get_tls() \
9502d2669b6SNicolas Pitre *	({ register unsigned int __val asm("r0"); \
9512d2669b6SNicolas Pitre *         asm( "mov r0, #0xffff0fff; mov lr, pc; sub pc, r0, #31" \
9522d2669b6SNicolas Pitre *	        : "=r" (__val) : : "lr","cc" ); \
9532d2669b6SNicolas Pitre *	   __val; })
9542d2669b6SNicolas Pitre */
9552d2669b6SNicolas Pitre
9562d2669b6SNicolas Pitre__kuser_get_tls:				@ 0xffff0fe0
9572d2669b6SNicolas Pitre
9584b0e07a5SNicolas Pitre#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
9592d2669b6SNicolas Pitre	ldr	r0, [pc, #(16 - 8)]		@ TLS stored at 0xffff0ff0
9602d2669b6SNicolas Pitre#else
9612d2669b6SNicolas Pitre	mrc	p15, 0, r0, c13, c0, 3		@ read TLS register
9622d2669b6SNicolas Pitre#endif
963ba9b5d76SNicolas Pitre	usr_ret	lr
9642d2669b6SNicolas Pitre
9652d2669b6SNicolas Pitre	.rep	5
9662d2669b6SNicolas Pitre	.word	0			@ pad up to __kuser_helper_version
9672d2669b6SNicolas Pitre	.endr
9682d2669b6SNicolas Pitre
9692d2669b6SNicolas Pitre/*
9702d2669b6SNicolas Pitre * Reference declaration:
9712d2669b6SNicolas Pitre *
9722d2669b6SNicolas Pitre *	extern unsigned int __kernel_helper_version;
9732d2669b6SNicolas Pitre *
9742d2669b6SNicolas Pitre * Definition and user space usage example:
9752d2669b6SNicolas Pitre *
9762d2669b6SNicolas Pitre *	#define __kernel_helper_version (*(unsigned int *)0xffff0ffc)
9772d2669b6SNicolas Pitre *
9782d2669b6SNicolas Pitre * User space may read this to determine the curent number of helpers
9792d2669b6SNicolas Pitre * available.
9802d2669b6SNicolas Pitre */
9812d2669b6SNicolas Pitre
9822d2669b6SNicolas Pitre__kuser_helper_version:				@ 0xffff0ffc
9832d2669b6SNicolas Pitre	.word	((__kuser_helper_end - __kuser_helper_start) >> 5)
9842d2669b6SNicolas Pitre
9852d2669b6SNicolas Pitre	.globl	__kuser_helper_end
9862d2669b6SNicolas Pitre__kuser_helper_end:
9872d2669b6SNicolas Pitre
9882d2669b6SNicolas Pitre
9891da177e4SLinus Torvalds/*
9901da177e4SLinus Torvalds * Vector stubs.
9911da177e4SLinus Torvalds *
9927933523dSRussell King * This code is copied to 0xffff0200 so we can use branches in the
9937933523dSRussell King * vectors, rather than ldr's.  Note that this code must not
9947933523dSRussell King * exceed 0x300 bytes.
9951da177e4SLinus Torvalds *
9961da177e4SLinus Torvalds * Common stub entry macro:
9971da177e4SLinus Torvalds *   Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
998ccea7a19SRussell King *
999ccea7a19SRussell King * SP points to a minimal amount of processor-private memory, the address
1000ccea7a19SRussell King * of which is copied into r0 for the mode specific abort handler.
10011da177e4SLinus Torvalds */
1002b7ec4795SNicolas Pitre	.macro	vector_stub, name, mode, correction=0
10031da177e4SLinus Torvalds	.align	5
10041da177e4SLinus Torvalds
10051da177e4SLinus Torvaldsvector_\name:
10061da177e4SLinus Torvalds	.if \correction
10071da177e4SLinus Torvalds	sub	lr, lr, #\correction
10081da177e4SLinus Torvalds	.endif
10091da177e4SLinus Torvalds
1010ccea7a19SRussell King	@
1011ccea7a19SRussell King	@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
1012ccea7a19SRussell King	@ (parent CPSR)
1013ccea7a19SRussell King	@
1014ccea7a19SRussell King	stmia	sp, {r0, lr}		@ save r0, lr
1015ccea7a19SRussell King	mrs	lr, spsr
1016ccea7a19SRussell King	str	lr, [sp, #8]		@ save spsr
1017ccea7a19SRussell King
1018ccea7a19SRussell King	@
1019ccea7a19SRussell King	@ Prepare for SVC32 mode.  IRQs remain disabled.
1020ccea7a19SRussell King	@
1021ccea7a19SRussell King	mrs	r0, cpsr
1022b7ec4795SNicolas Pitre	eor	r0, r0, #(\mode ^ SVC_MODE)
1023ccea7a19SRussell King	msr	spsr_cxsf, r0
1024ccea7a19SRussell King
1025ccea7a19SRussell King	@
1026ccea7a19SRussell King	@ the branch table must immediately follow this code
1027ccea7a19SRussell King	@
1028ccea7a19SRussell King	and	lr, lr, #0x0f
1029b7ec4795SNicolas Pitre	mov	r0, sp
10301da177e4SLinus Torvalds	ldr	lr, [pc, lr, lsl #2]
1031ccea7a19SRussell King	movs	pc, lr			@ branch to handler in SVC mode
10321da177e4SLinus Torvalds	.endm
10331da177e4SLinus Torvalds
10347933523dSRussell King	.globl	__stubs_start
10351da177e4SLinus Torvalds__stubs_start:
10361da177e4SLinus Torvalds/*
10371da177e4SLinus Torvalds * Interrupt dispatcher
10381da177e4SLinus Torvalds */
1039b7ec4795SNicolas Pitre	vector_stub	irq, IRQ_MODE, 4
10401da177e4SLinus Torvalds
10411da177e4SLinus Torvalds	.long	__irq_usr			@  0  (USR_26 / USR_32)
10421da177e4SLinus Torvalds	.long	__irq_invalid			@  1  (FIQ_26 / FIQ_32)
10431da177e4SLinus Torvalds	.long	__irq_invalid			@  2  (IRQ_26 / IRQ_32)
10441da177e4SLinus Torvalds	.long	__irq_svc			@  3  (SVC_26 / SVC_32)
10451da177e4SLinus Torvalds	.long	__irq_invalid			@  4
10461da177e4SLinus Torvalds	.long	__irq_invalid			@  5
10471da177e4SLinus Torvalds	.long	__irq_invalid			@  6
10481da177e4SLinus Torvalds	.long	__irq_invalid			@  7
10491da177e4SLinus Torvalds	.long	__irq_invalid			@  8
10501da177e4SLinus Torvalds	.long	__irq_invalid			@  9
10511da177e4SLinus Torvalds	.long	__irq_invalid			@  a
10521da177e4SLinus Torvalds	.long	__irq_invalid			@  b
10531da177e4SLinus Torvalds	.long	__irq_invalid			@  c
10541da177e4SLinus Torvalds	.long	__irq_invalid			@  d
10551da177e4SLinus Torvalds	.long	__irq_invalid			@  e
10561da177e4SLinus Torvalds	.long	__irq_invalid			@  f
10571da177e4SLinus Torvalds
10581da177e4SLinus Torvalds/*
10591da177e4SLinus Torvalds * Data abort dispatcher
10601da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10611da177e4SLinus Torvalds */
1062b7ec4795SNicolas Pitre	vector_stub	dabt, ABT_MODE, 8
10631da177e4SLinus Torvalds
10641da177e4SLinus Torvalds	.long	__dabt_usr			@  0  (USR_26 / USR_32)
10651da177e4SLinus Torvalds	.long	__dabt_invalid			@  1  (FIQ_26 / FIQ_32)
10661da177e4SLinus Torvalds	.long	__dabt_invalid			@  2  (IRQ_26 / IRQ_32)
10671da177e4SLinus Torvalds	.long	__dabt_svc			@  3  (SVC_26 / SVC_32)
10681da177e4SLinus Torvalds	.long	__dabt_invalid			@  4
10691da177e4SLinus Torvalds	.long	__dabt_invalid			@  5
10701da177e4SLinus Torvalds	.long	__dabt_invalid			@  6
10711da177e4SLinus Torvalds	.long	__dabt_invalid			@  7
10721da177e4SLinus Torvalds	.long	__dabt_invalid			@  8
10731da177e4SLinus Torvalds	.long	__dabt_invalid			@  9
10741da177e4SLinus Torvalds	.long	__dabt_invalid			@  a
10751da177e4SLinus Torvalds	.long	__dabt_invalid			@  b
10761da177e4SLinus Torvalds	.long	__dabt_invalid			@  c
10771da177e4SLinus Torvalds	.long	__dabt_invalid			@  d
10781da177e4SLinus Torvalds	.long	__dabt_invalid			@  e
10791da177e4SLinus Torvalds	.long	__dabt_invalid			@  f
10801da177e4SLinus Torvalds
10811da177e4SLinus Torvalds/*
10821da177e4SLinus Torvalds * Prefetch abort dispatcher
10831da177e4SLinus Torvalds * Enter in ABT mode, spsr = USR CPSR, lr = USR PC
10841da177e4SLinus Torvalds */
1085b7ec4795SNicolas Pitre	vector_stub	pabt, ABT_MODE, 4
10861da177e4SLinus Torvalds
10871da177e4SLinus Torvalds	.long	__pabt_usr			@  0 (USR_26 / USR_32)
10881da177e4SLinus Torvalds	.long	__pabt_invalid			@  1 (FIQ_26 / FIQ_32)
10891da177e4SLinus Torvalds	.long	__pabt_invalid			@  2 (IRQ_26 / IRQ_32)
10901da177e4SLinus Torvalds	.long	__pabt_svc			@  3 (SVC_26 / SVC_32)
10911da177e4SLinus Torvalds	.long	__pabt_invalid			@  4
10921da177e4SLinus Torvalds	.long	__pabt_invalid			@  5
10931da177e4SLinus Torvalds	.long	__pabt_invalid			@  6
10941da177e4SLinus Torvalds	.long	__pabt_invalid			@  7
10951da177e4SLinus Torvalds	.long	__pabt_invalid			@  8
10961da177e4SLinus Torvalds	.long	__pabt_invalid			@  9
10971da177e4SLinus Torvalds	.long	__pabt_invalid			@  a
10981da177e4SLinus Torvalds	.long	__pabt_invalid			@  b
10991da177e4SLinus Torvalds	.long	__pabt_invalid			@  c
11001da177e4SLinus Torvalds	.long	__pabt_invalid			@  d
11011da177e4SLinus Torvalds	.long	__pabt_invalid			@  e
11021da177e4SLinus Torvalds	.long	__pabt_invalid			@  f
11031da177e4SLinus Torvalds
11041da177e4SLinus Torvalds/*
11051da177e4SLinus Torvalds * Undef instr entry dispatcher
11061da177e4SLinus Torvalds * Enter in UND mode, spsr = SVC/USR CPSR, lr = SVC/USR PC
11071da177e4SLinus Torvalds */
1108b7ec4795SNicolas Pitre	vector_stub	und, UND_MODE
11091da177e4SLinus Torvalds
11101da177e4SLinus Torvalds	.long	__und_usr			@  0 (USR_26 / USR_32)
11111da177e4SLinus Torvalds	.long	__und_invalid			@  1 (FIQ_26 / FIQ_32)
11121da177e4SLinus Torvalds	.long	__und_invalid			@  2 (IRQ_26 / IRQ_32)
11131da177e4SLinus Torvalds	.long	__und_svc			@  3 (SVC_26 / SVC_32)
11141da177e4SLinus Torvalds	.long	__und_invalid			@  4
11151da177e4SLinus Torvalds	.long	__und_invalid			@  5
11161da177e4SLinus Torvalds	.long	__und_invalid			@  6
11171da177e4SLinus Torvalds	.long	__und_invalid			@  7
11181da177e4SLinus Torvalds	.long	__und_invalid			@  8
11191da177e4SLinus Torvalds	.long	__und_invalid			@  9
11201da177e4SLinus Torvalds	.long	__und_invalid			@  a
11211da177e4SLinus Torvalds	.long	__und_invalid			@  b
11221da177e4SLinus Torvalds	.long	__und_invalid			@  c
11231da177e4SLinus Torvalds	.long	__und_invalid			@  d
11241da177e4SLinus Torvalds	.long	__und_invalid			@  e
11251da177e4SLinus Torvalds	.long	__und_invalid			@  f
11261da177e4SLinus Torvalds
11271da177e4SLinus Torvalds	.align	5
11281da177e4SLinus Torvalds
11291da177e4SLinus Torvalds/*=============================================================================
11301da177e4SLinus Torvalds * Undefined FIQs
11311da177e4SLinus Torvalds *-----------------------------------------------------------------------------
11321da177e4SLinus Torvalds * Enter in FIQ mode, spsr = ANY CPSR, lr = ANY PC
11331da177e4SLinus Torvalds * MUST PRESERVE SVC SPSR, but need to switch to SVC mode to show our msg.
11341da177e4SLinus Torvalds * Basically to switch modes, we *HAVE* to clobber one register...  brain
11351da177e4SLinus Torvalds * damage alert!  I don't think that we can execute any code in here in any
11361da177e4SLinus Torvalds * other mode than FIQ...  Ok you can switch to another mode, but you can't
11371da177e4SLinus Torvalds * get out of that mode without clobbering one register.
11381da177e4SLinus Torvalds */
11391da177e4SLinus Torvaldsvector_fiq:
11401da177e4SLinus Torvalds	disable_fiq
11411da177e4SLinus Torvalds	subs	pc, lr, #4
11421da177e4SLinus Torvalds
11431da177e4SLinus Torvalds/*=============================================================================
11441da177e4SLinus Torvalds * Address exception handler
11451da177e4SLinus Torvalds *-----------------------------------------------------------------------------
11461da177e4SLinus Torvalds * These aren't too critical.
11471da177e4SLinus Torvalds * (they're not supposed to happen, and won't happen in 32-bit data mode).
11481da177e4SLinus Torvalds */
11491da177e4SLinus Torvalds
11501da177e4SLinus Torvaldsvector_addrexcptn:
11511da177e4SLinus Torvalds	b	vector_addrexcptn
11521da177e4SLinus Torvalds
11531da177e4SLinus Torvalds/*
11541da177e4SLinus Torvalds * We group all the following data together to optimise
11551da177e4SLinus Torvalds * for CPUs with separate I & D caches.
11561da177e4SLinus Torvalds */
11571da177e4SLinus Torvalds	.align	5
11581da177e4SLinus Torvalds
11591da177e4SLinus Torvalds.LCvswi:
11601da177e4SLinus Torvalds	.word	vector_swi
11611da177e4SLinus Torvalds
11627933523dSRussell King	.globl	__stubs_end
11631da177e4SLinus Torvalds__stubs_end:
11641da177e4SLinus Torvalds
11657933523dSRussell King	.equ	stubs_offset, __vectors_start + 0x200 - __stubs_start
11661da177e4SLinus Torvalds
11677933523dSRussell King	.globl	__vectors_start
11687933523dSRussell King__vectors_start:
11691da177e4SLinus Torvalds	swi	SYS_ERROR0
11707933523dSRussell King	b	vector_und + stubs_offset
11717933523dSRussell King	ldr	pc, .LCvswi + stubs_offset
11727933523dSRussell King	b	vector_pabt + stubs_offset
11737933523dSRussell King	b	vector_dabt + stubs_offset
11747933523dSRussell King	b	vector_addrexcptn + stubs_offset
11757933523dSRussell King	b	vector_irq + stubs_offset
11767933523dSRussell King	b	vector_fiq + stubs_offset
11771da177e4SLinus Torvalds
11787933523dSRussell King	.globl	__vectors_end
11797933523dSRussell King__vectors_end:
11801da177e4SLinus Torvalds
11811da177e4SLinus Torvalds	.data
11821da177e4SLinus Torvalds
11831da177e4SLinus Torvalds	.globl	cr_alignment
11841da177e4SLinus Torvalds	.globl	cr_no_alignment
11851da177e4SLinus Torvaldscr_alignment:
11861da177e4SLinus Torvalds	.space	4
11871da177e4SLinus Torvaldscr_no_alignment:
11881da177e4SLinus Torvalds	.space	4
1189