mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add stack dump as a macro in the lib for cramium-hal
I have a feeling this won't be the last time I want to use a utility like this during bringup...
This commit is contained in:
parent
891489f789
commit
b4ffcfe11a
1 changed files with 35 additions and 0 deletions
|
|
@ -48,3 +48,38 @@ pub fn cache_flush() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A function for dumping stack. Used to help diagnose tricky problems. Invoke as:
|
||||||
|
/// `unsafe { cramium_hal::dump_stack!(0x300) };` inside any stack frame where
|
||||||
|
/// you want to dump some stack. The extents are specified as number of bytes,
|
||||||
|
/// and should be word-aligned.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! dump_stack {
|
||||||
|
($extent_bytes:expr) => {{
|
||||||
|
$crate::dump_stack!($extent_bytes, cramium_hal::read_sp);
|
||||||
|
}};
|
||||||
|
// Explicit SP reader path
|
||||||
|
($extent_bytes:expr, $read_sp:path) => {{
|
||||||
|
// No internal `unsafe` so the caller must use `unsafe { dump_stack!(...) }`
|
||||||
|
let sp = $read_sp();
|
||||||
|
let __word: usize = core::mem::size_of::<u32>();
|
||||||
|
let __extent_words: usize = ($extent_bytes) / __word;
|
||||||
|
let mut __i: usize = 0;
|
||||||
|
while __i < __extent_words {
|
||||||
|
if __i % 8 == 0 {
|
||||||
|
$crate::print!("\n\r{:08x}|{:04x}: ", sp + __i * __word, __i * __word);
|
||||||
|
}
|
||||||
|
// volatile read of the stack word
|
||||||
|
$crate::print!("{:08x} ", ((sp as *const u32).add(__i)).read_volatile());
|
||||||
|
__i += 1;
|
||||||
|
}
|
||||||
|
$crate::println!("");
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn read_sp() -> usize {
|
||||||
|
let sp: usize;
|
||||||
|
core::arch::asm!("mv {0}, sp", out(reg) sp);
|
||||||
|
sp
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue