Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 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 | |
Alice Wang | a9fe1fb | 2023-07-04 09:10:35 +0000 | [diff] [blame] | 17 | use vmbase::{ |
| 18 | eprintln, |
| 19 | exceptions::{ArmException, Esr, HandleExceptionError}, |
| 20 | logger, |
| 21 | memory::{handle_permission_fault, handle_translation_fault}, |
| 22 | power::reboot, |
| 23 | read_sysreg, |
| 24 | }; |
Jakob Vukalovic | 44b1ce3 | 2023-04-17 19:10:10 +0100 | [diff] [blame] | 25 | |
Alice Wang | ae9ed2a | 2023-07-05 11:36:35 +0000 | [diff] [blame] | 26 | fn handle_exception(exception: &ArmException) -> Result<(), HandleExceptionError> { |
Jakob Vukalovic | b99905d | 2023-04-20 15:46:02 +0100 | [diff] [blame] | 27 | // Handle all translation faults on both read and write, and MMIO guard map |
| 28 | // flagged invalid pages or blocks that caused the exception. |
Jakob Vukalovic | 44b1ce3 | 2023-04-17 19:10:10 +0100 | [diff] [blame] | 29 | // Handle permission faults for DBM flagged entries, and flag them as dirty on write. |
Alice Wang | ae9ed2a | 2023-07-05 11:36:35 +0000 | [diff] [blame] | 30 | match exception.esr { |
| 31 | Esr::DataAbortTranslationFault => handle_translation_fault(exception.far), |
| 32 | Esr::DataAbortPermissionFault => handle_permission_fault(exception.far), |
Jakob Vukalovic | b99905d | 2023-04-20 15:46:02 +0100 | [diff] [blame] | 33 | _ => Err(HandleExceptionError::UnknownException), |
| 34 | } |
Jakob Vukalovic | d3fe9ed | 2023-04-20 15:43:09 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 37 | #[no_mangle] |
Pierre-Clément Tosi | eeb1ace | 2023-05-15 17:23:51 +0000 | [diff] [blame] | 38 | extern "C" fn sync_exception_current(elr: u64, _spsr: u64) { |
Jakob Vukalovic | d3fe9ed | 2023-04-20 15:43:09 +0100 | [diff] [blame] | 39 | // Disable logging in exception handler to prevent unsafe writes to UART. |
| 40 | let _guard = logger::suppress(); |
Jakob Vukalovic | d3fe9ed | 2023-04-20 15:43:09 +0100 | [diff] [blame] | 41 | |
Alice Wang | ae9ed2a | 2023-07-05 11:36:35 +0000 | [diff] [blame] | 42 | let exception = ArmException::from_el1_regs(); |
| 43 | if let Err(e) = handle_exception(&exception) { |
| 44 | exception.print("sync_exception_current", e, elr); |
Jakob Vukalovic | d3fe9ed | 2023-04-20 15:43:09 +0100 | [diff] [blame] | 45 | reboot() |
Pierre-Clément Tosi | da4440a | 2022-08-22 18:06:32 +0100 | [diff] [blame] | 46 | } |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 50 | extern "C" fn irq_current(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 51 | eprintln!("irq_current"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 52 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 56 | extern "C" fn fiq_current(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 57 | eprintln!("fiq_current"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 58 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 62 | extern "C" fn serr_current(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 63 | let esr = read_sysreg!("esr_el1"); |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 64 | eprintln!("serr_current"); |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 65 | eprintln!("esr={esr:#08x}"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 66 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 70 | extern "C" fn sync_lower(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 71 | let esr = read_sysreg!("esr_el1"); |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 72 | eprintln!("sync_lower"); |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 73 | eprintln!("esr={esr:#08x}"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 74 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 78 | extern "C" fn irq_lower(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 79 | eprintln!("irq_lower"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 80 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 84 | extern "C" fn fiq_lower(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 85 | eprintln!("fiq_lower"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 86 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | #[no_mangle] |
Pierre-Clément Tosi | 8cbd4b7 | 2022-08-11 13:59:31 +0100 | [diff] [blame] | 90 | extern "C" fn serr_lower(_elr: u64, _spsr: u64) { |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 91 | let esr = read_sysreg!("esr_el1"); |
Jakob Vukalovic | bff22e1 | 2023-04-18 14:50:47 +0100 | [diff] [blame] | 92 | eprintln!("serr_lower"); |
Jakob Vukalovic | c9afb51 | 2023-03-30 16:04:32 +0000 | [diff] [blame] | 93 | eprintln!("esr={esr:#08x}"); |
Andrew Walbran | dd74b90 | 2022-04-14 16:12:50 +0000 | [diff] [blame] | 94 | reboot(); |
Andrew Walbran | dfb7337 | 2022-04-21 10:52:27 +0000 | [diff] [blame] | 95 | } |