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