1 // Copyright 2022, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 //! Exception handlers.
16
17 use core::arch::asm;
18 use vmbase::{console::emergency_write_str, eprintln, power::reboot};
19
20 #[no_mangle]
sync_exception_current()21 extern "C" fn sync_exception_current() {
22 emergency_write_str("sync_exception_current\n");
23 print_esr();
24 reboot();
25 }
26
27 #[no_mangle]
irq_current()28 extern "C" fn irq_current() {
29 emergency_write_str("irq_current\n");
30 reboot();
31 }
32
33 #[no_mangle]
fiq_current()34 extern "C" fn fiq_current() {
35 emergency_write_str("fiq_current\n");
36 reboot();
37 }
38
39 #[no_mangle]
serr_current()40 extern "C" fn serr_current() {
41 emergency_write_str("serr_current\n");
42 print_esr();
43 reboot();
44 }
45
46 #[no_mangle]
sync_lower()47 extern "C" fn sync_lower() {
48 emergency_write_str("sync_lower\n");
49 print_esr();
50 reboot();
51 }
52
53 #[no_mangle]
irq_lower()54 extern "C" fn irq_lower() {
55 emergency_write_str("irq_lower\n");
56 reboot();
57 }
58
59 #[no_mangle]
fiq_lower()60 extern "C" fn fiq_lower() {
61 emergency_write_str("fiq_lower\n");
62 reboot();
63 }
64
65 #[no_mangle]
serr_lower()66 extern "C" fn serr_lower() {
67 emergency_write_str("serr_lower\n");
68 print_esr();
69 reboot();
70 }
71
72 #[inline]
print_esr()73 fn print_esr() {
74 let mut esr: u64;
75 unsafe {
76 asm!("mrs {esr}, esr_el1", esr = out(reg) esr);
77 }
78 eprintln!("esr={:#08x}", esr);
79 }
80