Move panics to separate module

Add special panic code for QEMU tests.
This commit is contained in:
Berkus Decker 2020-10-20 17:54:49 +03:00
parent 6c5d7a13fc
commit d572b2c297
3 changed files with 26 additions and 7 deletions

View File

@ -32,6 +32,7 @@ pub mod arch;
pub use arch::*;
mod macros;
mod mm;
mod panic;
mod platform;
#[cfg(feature = "qemu")]
mod qemu;
@ -100,11 +101,6 @@ pub fn kmain() -> ! {
endless_sleep()
}
#[panic_handler]
fn panicked(_info: &core::panic::PanicInfo) -> ! {
endless_sleep()
}
#[cfg(test)]
mod main_tests {
use super::*;

13
nucleus/src/panic.rs Normal file
View File

@ -0,0 +1,13 @@
#[cfg(not(test))]
#[panic_handler]
fn panicked(info: &core::panic::PanicInfo) -> ! {
crate::println!("{}", info);
crate::endless_sleep()
}
#[cfg(test)]
#[panic_handler]
fn panicked(info: &core::panic::PanicInfo) -> ! {
crate::println!("[failed]\nError: {}\n", info);
crate::qemu::semihosting::exit_failure()
}

View File

@ -4,13 +4,23 @@
*/
pub mod semihosting {
#[cfg(test)]
pub fn exit_success() {
pub fn exit_success() -> ! {
use qemu_exit::QEMUExit;
#[cfg(target_arch = "aarch64")]
let qemu_exit_handle = qemu_exit::AArch64::new();
qemu_exit_handle.exit_success();
qemu_exit_handle.exit_success()
}
#[cfg(test)]
pub fn exit_failure() -> ! {
use qemu_exit::QEMUExit;
#[cfg(target_arch = "aarch64")]
let qemu_exit_handle = qemu_exit::AArch64::new();
qemu_exit_handle.exit_failure()
}
#[cfg(test)]