Issue with panicking in a baremetal kernel for the Raspberry Pi Zero

Hello everyone, I am new to embedded development and I am facing a bug which I do not understand at all.

For some context, I am writing a toy OS for the raspberry pi zero using Rust. I have reduced my problem to the following minimal example: an assembly "bootloader" sets up the interrupt vector table and the stack pointer, and then calls into the kernel entry point in Rust. Once in Rust land, I have defined the #[panic_handler] to be a loop that blinks a led every second.

If the body of the kernel function looks like the following:

#[no_mangle]
pub extern "C" fn kernel() -> ! {
  panic!();
  loop {}
}

Then everything is successful, and the LED blinks as expected.

However, if instead I call unwrap on a None value for example:

#[no_mangle]
pub extern "C" fn kernel() -> ! {
  None::<()>.unwrap();
  loop {}
}

Then nothing happens; The LED is not blinking.

Why is that?

The main difference between these two cases seems to be whether the panic has any payload (in the second case it's a message like "called unwrap on None"). Could you check whether having panic!("some message") works like the first or the second case?

I have made some progress towards understanding what is going on, and that is because the linker script doesn't "work" in the case of unwrap. It somehow puts the binary at starting location 0x20000, while it should really be at 0x8000. I will continue looking into this, it may be related to panic! having a payload.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.