|
|
@ -1,13 +1,13 @@
|
|
|
|
use core::mem::size_of;
|
|
|
|
use core::mem::size_of;
|
|
|
|
|
|
|
|
use rcore_memory::PAGE_SIZE;
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
extern "C" {
|
|
|
|
fn stext();
|
|
|
|
fn stext();
|
|
|
|
fn etext();
|
|
|
|
fn etext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the current frame pointer.
|
|
|
|
/// Returns the current frame pointer.or stack base pointer
|
|
|
|
#[inline(always)]
|
|
|
|
#[inline(always)]
|
|
|
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
|
|
|
|
|
|
|
pub fn fp() -> usize {
|
|
|
|
pub fn fp() -> usize {
|
|
|
|
let ptr: usize;
|
|
|
|
let ptr: usize;
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
@ -18,13 +18,16 @@ pub fn fp() -> usize {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
asm!("mv $0, s0" : "=r"(ptr));
|
|
|
|
asm!("mv $0, s0" : "=r"(ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
|
|
|
asm!("mov %rbp, $0" : "=r"(ptr));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ptr
|
|
|
|
ptr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns the current link register.
|
|
|
|
/// Returns the current link register.or return address
|
|
|
|
#[inline(always)]
|
|
|
|
#[inline(always)]
|
|
|
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
|
|
|
|
|
|
|
pub fn lr() -> usize {
|
|
|
|
pub fn lr() -> usize {
|
|
|
|
let ptr: usize;
|
|
|
|
let ptr: usize;
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
|
#[cfg(target_arch = "aarch64")]
|
|
|
@ -35,13 +38,16 @@ pub fn lr() -> usize {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
asm!("mv $0, ra" : "=r"(ptr));
|
|
|
|
asm!("mv $0, ra" : "=r"(ptr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
|
|
|
asm!("movq 8(%rbp), $0" : "=r"(ptr));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ptr
|
|
|
|
ptr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Print the backtrace starting from the caller
|
|
|
|
// Print the backtrace starting from the caller
|
|
|
|
pub fn backtrace() {
|
|
|
|
pub fn backtrace() {
|
|
|
|
#[cfg(any(target_arch = "aarch64", target_arch = "riscv32", target_arch = "riscv64"))]
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
let mut current_pc = lr();
|
|
|
|
let mut current_pc = lr();
|
|
|
|
let mut current_fp = fp();
|
|
|
|
let mut current_fp = fp();
|
|
|
@ -61,6 +67,16 @@ pub fn backtrace() {
|
|
|
|
current_pc = *(current_fp as *const usize).offset(1);
|
|
|
|
current_pc = *(current_fp as *const usize).offset(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Kernel stack at 0x0000_57ac_0000_0000 (defined in bootloader crate)
|
|
|
|
|
|
|
|
// size = 512 pages
|
|
|
|
|
|
|
|
current_fp = *(current_fp as *const usize).offset(0);
|
|
|
|
|
|
|
|
if (current_fp >= 0x0000_57ac_0000_0000 + 512 * PAGE_SIZE - size_of::<usize>()) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
current_pc = *(current_fp as *const usize).offset(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|