diff --git a/.cargo/config.toml b/.cargo/config.toml index 5a5e02c..792a36f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,10 +1,11 @@ [unstable] build-std = ["core", "compiler_builtins", "alloc"] build-std-features = ["compiler-builtins-mem"] -panic-abort-tests = true # Or remove this from Cargo.toml: `panic = "abort"` +panic-abort-tests = true # Or remove this from Cargo.toml: `panic = "abort"` [build] target = "x86_64-infinity_os.json" +rustflags = ["-C", "force-frame-pointers=yes"] [target.'cfg(target_os = "none")'] -runner = "bootimage runner" \ No newline at end of file +runner = "bootimage runner" diff --git a/src/kernel/debug/mod.rs b/src/kernel/debug/mod.rs new file mode 100644 index 0000000..25e307c --- /dev/null +++ b/src/kernel/debug/mod.rs @@ -0,0 +1 @@ +pub mod stack_trace; \ No newline at end of file diff --git a/src/kernel/debug/stack_trace.rs b/src/kernel/debug/stack_trace.rs new file mode 100644 index 0000000..dcfd747 --- /dev/null +++ b/src/kernel/debug/stack_trace.rs @@ -0,0 +1,20 @@ +use crate::print; +use core::arch::asm; + +#[repr(C)] +struct StackFrame { + rbp: *const StackFrame, + rip: usize, +} + +pub fn walk_stack() { + let mut frame: *const StackFrame; + unsafe { + asm!("mov {}, rbp", out(reg) frame); + } + + while let Some(stack_frame) = unsafe { frame.as_ref() } { + print!("Function address: {:#x}\n", stack_frame.rip); + frame = stack_frame.rbp; + } +} diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 06447cf..e6e35b1 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -1,5 +1,6 @@ pub mod allocator; pub mod clock; +pub mod debug; pub mod gdt; pub mod interrupts; pub mod memory; diff --git a/src/kernel/task/keyboard.rs b/src/kernel/task/keyboard.rs index 3047e81..2941535 100644 --- a/src/kernel/task/keyboard.rs +++ b/src/kernel/task/keyboard.rs @@ -5,9 +5,9 @@ use core::{ task::{Context, Poll}, }; use crossbeam_queue::ArrayQueue; -use futures_util::{stream::Stream, StreamExt}; use futures_util::task::AtomicWaker; -use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1}; +use futures_util::{stream::Stream, StreamExt}; +use pc_keyboard::{layouts, HandleControl, KeyCode, Keyboard, ScancodeSet1}; static SCANCODE_QUEUE: OnceCell> = OnceCell::uninit(); static WAKER: AtomicWaker = AtomicWaker::new(); @@ -20,7 +20,7 @@ pub(crate) fn add_scancode(scancode: u8) { if let Err(_) = queue.push(scancode) { print!("WARNING: scancode queue full; dropping keyboard input\n"); } else { - WAKER.wake(); // new + WAKER.wake(); } } else { print!("WARNING: scancode queue uninitialized\n"); @@ -75,8 +75,21 @@ pub async fn keyboard_task() { if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { if let Some(key) = keyboard.process_keyevent(key_event) { match key { - DecodedKey::Unicode(character) => print!("{}", character), - DecodedKey::RawKey(key) => print!("{:?}", key), + pc_keyboard::DecodedKey::RawKey( + KeyCode::LAlt + | KeyCode::RAlt2 + | KeyCode::RAltGr + | KeyCode::LControl + | KeyCode::RControl + | KeyCode::RShift + | KeyCode::LShift + | KeyCode::PageDown + | KeyCode::PageUp + | KeyCode::Home + | KeyCode::CapsLock, + ) => {} + pc_keyboard::DecodedKey::Unicode(character) => print!("{}", character), + pc_keyboard::DecodedKey::RawKey(key) => print!("{:?}", key), } } } diff --git a/src/main.rs b/src/main.rs index 63170fd..6927963 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,5 +35,6 @@ pub fn kernel_main(boot_info: &'static BootInfo) -> ! { #[panic_handler] fn panic(info: &PanicInfo) -> ! { print!("{}\n", info); + kernel::debug::stack_trace::walk_stack(); infinity_os::hlt_loop(); }