Files
RedBear-OS/src/arch/x86_shared/interrupt/trace.rs
T
bjorn3 cea93f7647 cargo fix --edition & rustfmt
Or to be precise:
RUST_TARGET_PATH=$(pwd)/targets cargo fix --edition \
--target targets/x86_64-unknown-kernel.json \
--target targets/i686-unknown-kernel.json \
--target targets/aarch64-unknown-kernel.json \
--target targets/riscv64-unknown-kernel.json \
-Zbuild-std=core,alloc --allow-dirty --bin kernel
cargo fmt
2025-09-10 16:44:36 +02:00

36 lines
923 B
Rust

use core::mem;
pub struct StackTrace {
pub fp: usize,
pub pc_ptr: *const usize,
}
impl StackTrace {
#[inline(always)]
pub unsafe fn start() -> Option<Self> {
unsafe {
let mut fp: usize;
#[cfg(target_arch = "x86")]
core::arch::asm!("mov {}, ebp", out(reg) fp);
#[cfg(target_arch = "x86_64")]
core::arch::asm!("mov {}, rbp", out(reg) fp);
let pc_ptr = fp.checked_add(mem::size_of::<usize>())?;
Some(Self {
fp,
pc_ptr: pc_ptr as *const usize,
})
}
}
pub unsafe fn next(self) -> Option<Self> {
unsafe {
let fp = *(self.fp as *const usize);
let pc_ptr = fp.checked_add(mem::size_of::<usize>())?;
Some(Self {
fp: fp,
pc_ptr: pc_ptr as *const usize,
})
}
}
}