xref: /openbmc/u-boot/arch/arm/cpu/armv8/exceptions.S (revision b32b1bd1)
1/*
2 * (C) Copyright 2013
3 * David Feng <fenghua@phytium.com.cn>
4 *
5 * SPDX-License-Identifier:	GPL-2.0+
6 */
7
8#include <asm-offsets.h>
9#include <config.h>
10#include <asm/ptrace.h>
11#include <asm/macro.h>
12#include <linux/linkage.h>
13
14/*
15 * Exception vectors.
16 */
17	.align	11
18	.globl	vectors
19vectors:
20	.align	7		/* Current EL Synchronous Thread */
21	stp	x29, x30, [sp, #-16]!
22	bl	_exception_entry
23	bl	do_bad_sync
24	b	exception_exit
25
26	.align	7		/* Current EL IRQ Thread */
27	stp	x29, x30, [sp, #-16]!
28	bl	_exception_entry
29	bl	do_bad_irq
30	b	exception_exit
31
32	.align	7		/* Current EL FIQ Thread */
33	stp	x29, x30, [sp, #-16]!
34	bl	_exception_entry
35	bl	do_bad_fiq
36	b	exception_exit
37
38	.align	7		/* Current EL Error Thread */
39	stp	x29, x30, [sp, #-16]!
40	bl	_exception_entry
41	bl	do_bad_error
42	b	exception_exit
43
44	.align	7		 /* Current EL Synchronous Handler */
45	stp	x29, x30, [sp, #-16]!
46	bl	_exception_entry
47	bl	do_sync
48	b	exception_exit
49
50	.align	7		 /* Current EL IRQ Handler */
51	stp	x29, x30, [sp, #-16]!
52	bl	_exception_entry
53	bl	do_irq
54	b	exception_exit
55
56	.align	7		 /* Current EL FIQ Handler */
57	stp	x29, x30, [sp, #-16]!
58	bl	_exception_entry
59	bl	do_fiq
60	b	exception_exit
61
62	.align	7		 /* Current EL Error Handler */
63	stp	x29, x30, [sp, #-16]!
64	bl	_exception_entry
65	bl	do_error
66	b	exception_exit
67
68/*
69 * Enter Exception.
70 * This will save the processor state that is ELR/X0~X30
71 * to the stack frame.
72 */
73_exception_entry:
74	stp	x27, x28, [sp, #-16]!
75	stp	x25, x26, [sp, #-16]!
76	stp	x23, x24, [sp, #-16]!
77	stp	x21, x22, [sp, #-16]!
78	stp	x19, x20, [sp, #-16]!
79	stp	x17, x18, [sp, #-16]!
80	stp	x15, x16, [sp, #-16]!
81	stp	x13, x14, [sp, #-16]!
82	stp	x11, x12, [sp, #-16]!
83	stp	x9, x10, [sp, #-16]!
84	stp	x7, x8, [sp, #-16]!
85	stp	x5, x6, [sp, #-16]!
86	stp	x3, x4, [sp, #-16]!
87	stp	x1, x2, [sp, #-16]!
88
89	/* Could be running at EL3/EL2/EL1 */
90	switch_el x11, 3f, 2f, 1f
913:	mrs	x1, esr_el3
92	mrs	x2, elr_el3
93	b	0f
942:	mrs	x1, esr_el2
95	mrs	x2, elr_el2
96	b	0f
971:	mrs	x1, esr_el1
98	mrs	x2, elr_el1
990:
100	stp	x2, x0, [sp, #-16]!
101	mov	x0, sp
102	ret
103
104
105exception_exit:
106	ldp	x2, x0, [sp],#16
107	switch_el x11, 3f, 2f, 1f
1083:	msr	elr_el3, x2
109	b	0f
1102:	msr	elr_el2, x2
111	b	0f
1121:	msr	elr_el1, x2
1130:
114	ldp	x1, x2, [sp],#16
115	ldp	x3, x4, [sp],#16
116	ldp	x5, x6, [sp],#16
117	ldp	x7, x8, [sp],#16
118	ldp	x9, x10, [sp],#16
119	ldp	x11, x12, [sp],#16
120	ldp	x13, x14, [sp],#16
121	ldp	x15, x16, [sp],#16
122	ldp	x17, x18, [sp],#16
123	ldp	x19, x20, [sp],#16
124	ldp	x21, x22, [sp],#16
125	ldp	x23, x24, [sp],#16
126	ldp	x25, x26, [sp],#16
127	ldp	x27, x28, [sp],#16
128	ldp	x29, x30, [sp],#16
129	eret
130