• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 vmbase::{
18     arch::aarch64::exceptions::{
19         handle_permission_fault, handle_translation_fault, ArmException, Esr, HandleExceptionError,
20     },
21     logger, read_sysreg,
22 };
23 
handle_exception(exception: &ArmException) -> Result<(), HandleExceptionError>24 fn handle_exception(exception: &ArmException) -> Result<(), HandleExceptionError> {
25     // Handle all translation faults on both read and write, and MMIO guard map
26     // flagged invalid pages or blocks that caused the exception.
27     // Handle permission faults for DBM flagged entries, and flag them as dirty on write.
28     match exception.esr {
29         Esr::DataAbortTranslationFault => handle_translation_fault(exception.far),
30         Esr::DataAbortPermissionFault => handle_permission_fault(exception.far),
31         _ => Err(HandleExceptionError::UnknownException),
32     }
33 }
34 
35 #[no_mangle]
sync_exception_current(elr: u64, _spsr: u64)36 extern "C" fn sync_exception_current(elr: u64, _spsr: u64) {
37     // Disable logging in exception handler to prevent unsafe writes to UART.
38     let _guard = logger::suppress();
39 
40     let exception = ArmException::from_el1_regs();
41     if let Err(e) = handle_exception(&exception) {
42         exception.print_and_reboot("sync_exception_current", e, elr);
43     }
44 }
45 
46 #[no_mangle]
irq_current(_elr: u64, _spsr: u64)47 extern "C" fn irq_current(_elr: u64, _spsr: u64) {
48     panic!("irq_current");
49 }
50 
51 #[no_mangle]
fiq_current(_elr: u64, _spsr: u64)52 extern "C" fn fiq_current(_elr: u64, _spsr: u64) {
53     panic!("fiq_current");
54 }
55 
56 #[no_mangle]
serr_current(_elr: u64, _spsr: u64)57 extern "C" fn serr_current(_elr: u64, _spsr: u64) {
58     let esr = read_sysreg!("esr_el1");
59     panic!("serr_current, esr={esr:#08x}");
60 }
61 
62 #[no_mangle]
sync_lower(_elr: u64, _spsr: u64)63 extern "C" fn sync_lower(_elr: u64, _spsr: u64) {
64     let esr = read_sysreg!("esr_el1");
65     panic!("sync_lower, esr={esr:#08x}");
66 }
67 
68 #[no_mangle]
irq_lower(_elr: u64, _spsr: u64)69 extern "C" fn irq_lower(_elr: u64, _spsr: u64) {
70     panic!("irq_lower");
71 }
72 
73 #[no_mangle]
fiq_lower(_elr: u64, _spsr: u64)74 extern "C" fn fiq_lower(_elr: u64, _spsr: u64) {
75     panic!("fiq_lower");
76 }
77 
78 #[no_mangle]
serr_lower(_elr: u64, _spsr: u64)79 extern "C" fn serr_lower(_elr: u64, _spsr: u64) {
80     let esr = read_sysreg!("esr_el1");
81     panic!("serr_lower, esr={esr:#08x}");
82 }
83