3 * Copyright 2014 Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #ifndef _ARCH_EXCEPTION_H
30 #define _ARCH_EXCEPTION_H
32 #define EXCEPTION_STATE_ELR 0x0
33 #define EXCEPTION_STATE_ESR 0x8
34 #define EXCEPTION_STATE_SPSR 0x10
35 #define EXCEPTION_STATE_SP 0x18
36 #define EXCEPTION_STATE_REG(r) (0x20 + r * 0x8)
38 #define ESR_EC_UNKNOWN 0b000000
39 #define ESR_EC_SVC_64 0b010101
40 #define ESR_EC_INSN_ABT_LOWER 0b100000
41 #define ESR_EC_INSN_ABT_SAME 0b100001
42 #define ESR_EC_DATA_ABT_LOWER 0b100100
43 #define ESR_EC_DATA_ABT_SAME 0b100101
44 #define ESR_EC_SERROR 0b101111
45 #define ESR_EC_SS_SAME 0b110011
46 #define ESR_EC_BKPT_64 0b111100
48 #define MDCR_TDE (1 << 8)
50 #define MDSCR_SS (1 << 0)
51 #define MDSCR_KDE (1 << 13)
52 #define MDSCR_MDE (1 << 15)
59 struct exception_state
85 uint32_t sp
: 1; /* M[0] */
86 uint32_t _res0
: 1; /* M[1] */
87 uint32_t el
: 2; /* M[3:2] */
88 uint32_t arch
: 1; /* M[4] */
104 uint32_t spsr_high_unused
;
109 #define CHECK_ES(field, constant) \
110 _Static_assert(offsetof(struct exception_state, field) == constant, \
111 "(struct exception_state)." #field " doesn't match constant " #constant)
112 CHECK_ES(elr
, EXCEPTION_STATE_ELR
);
113 CHECK_ES(esr
, EXCEPTION_STATE_ESR
);
114 CHECK_ES(spsr
, EXCEPTION_STATE_SPSR
);
115 CHECK_ES(sp
, EXCEPTION_STATE_SP
);
116 CHECK_ES(regs
[0], EXCEPTION_STATE_REG(0));
117 CHECK_ES(regs
[30], EXCEPTION_STATE_REG(30));
119 extern struct exception_state exception_state
;
120 extern u64 exception_stack
[];
121 extern u64
*exception_stack_end
;
123 void exception_set_state_ptr(struct exception_state
*exception_state_ptr
);
145 #endif /* !__ASSEMBLER__ */