when I use rust write os in qemu, I wrote a stack trace function to resolve frame point trace, but found qemu in loop.
my code is like this:
pub unsafe fn print_stack_trace() {
let mut fp: *const usize;
asm!("mv {}, fp", out(reg) fp);
let mut saved_ra = *fp.sub(1);
let mut saved_fp = *fp.sub(2);
println!("== Begin stack trace ==");
while (!fp.is_null() && saved_fp != 0) || (saved_ra == *fp) {
println!("0x{:016x}, fp = 0x{:016x}", saved_ra, saved_fp);
fp = saved_fp as *const usize;
saved_ra = *fp.sub(1);
saved_fp = *fp.sub(2);
}
println!("== End stack trace ==");
}
but with "-bios opensbi.bin" ,the console out like this:
ra =0x0000000080200010, fp = 0x000000008020fa60
ra =0x0000000080210158, fp = 0x000000008020fcd0
ra =0x0000000080213c3c, fp = 0x000000008020fd10
ra =0x0000000080212190, fp = 0x0000000080210010
ra =0x0000000080200010, fp = 0x000000008020fa60
.........
when I use "-bios rustsbi.bin" (version 0.0.4") run the same code ,the console out like this:
== Begin stack trace ==
0x0000000080210158, fp = 0x000000008020fcd0
0x0000000080213c3c, fp = 0x000000008020fd10
0x0000000080212190, fp = 0x0000000080210010
== End stack trace ==
the result is correct.
Then I write out the ra & fp ,found when
use rustsbi : ra = 0x0000000080210010,fp=0,
so that the code is correct over.
but use opensbi :ra =0x0000000080200010, fp = 0x000000008020fa60
fp is not null, so that is in loop.
when I use rust write os in qemu, I wrote a stack trace function to resolve frame point trace, but found qemu in loop. my code is like this: pub unsafe fn print_stack_trace() { let mut fp: *const usize;
}
but with "-bios opensbi.bin" ,the console out like this: ra =0x0000000080200010, fp = 0x000000008020fa60 ra =0x0000000080210158, fp = 0x000000008020fcd0 ra =0x0000000080213c3c, fp = 0x000000008020fd10 ra =0x0000000080212190, fp = 0x0000000080210010 ra =0x0000000080200010, fp = 0x000000008020fa60 ......... when I use "-bios rustsbi.bin" (version 0.0.4") run the same code ,the console out like this: == Begin stack trace == 0x0000000080210158, fp = 0x000000008020fcd0 0x0000000080213c3c, fp = 0x000000008020fd10 0x0000000080212190, fp = 0x0000000080210010 == End stack trace ==
the result is correct.
Then I write out the ra & fp ,found when use rustsbi : ra = 0x0000000080210010,fp=0, so that the code is correct over. but use opensbi :ra =0x0000000080200010, fp = 0x000000008020fa60 fp is not null, so that is in loop.
where opensbi code has bug?