From b04ee131851605e5a7d824f46c296520be2350d3 Mon Sep 17 00:00:00 2001 From: able Date: Thu, 7 Sep 2023 14:31:31 -0500 Subject: [PATCH] Register dump on panic --- kernel/src/arch/x86_64/mod.rs | 76 +++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 9bce207..14c95ad 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -1,17 +1,19 @@ use embedded_graphics::pixelcolor::Rgb888; -use crate::{arch::x86_64::graphics::DISPLAY, bootmodules::BootModule}; - +use { + crate::{arch::x86_64::graphics::DISPLAY, bootmodules::BootModule}, + core::arch::asm, +}; pub mod memory; mod cpuid; +mod device_info_collector; mod gdt; pub mod graphics; pub(crate) mod interrupts; pub mod logging; pub mod pci; pub mod virtio; -mod device_info_collector; pub use {logging::log, memory::PAGE_SIZE}; @@ -192,3 +194,71 @@ pub fn hardware_random_u64() -> u64 { } pub fn get_edid() {} + +pub fn register_dump() { + let rax: u64; + let rbx: u64 = 0; + let rcx: u64; + let rdx: u64; + let si: u64; + let di: u64; + + let r8: u64; // TODO: r8-r15 + let r9: u64; + let r10: u64; + let r11: u64; + let r12: u64; + let r13: u64; + let r14: u64; + let r15: u64; + + unsafe { + asm!("", + out("rax") rax, + out("rcx") rcx, + out("rdx") rdx, + out("si") si, + out("di") di, + out("r8") r8, + out("r9") r9, + out("r10") r10, + out("r11") r11, + out("r12") r12, + out("r13") r13, + out("r14") r14, + out("r15") r15, + ) + }; + + log::error!( + "Kernel Panic!\r +Register Dump\r + rax: {:#x}\r + rbx: {:#x}\r + rcx: {:#x}\r + rdx: {:#x}\r + si : {:#x}\r + di : {:#x}\r + r8 : {:#x}\r + r9 : {:#x}\r + r11: {:#x}\r + r12: {:#x}\r + r13: {:#x}\r + r14: {:#x}\r + r15: {:#x}\r +", + rax, + rbx, + rcx, + rdx, + si, + di, + r8, + r9, + r11, + r12, + r13, + r14, + r15, + ); +}