Baremetal: Implementing fmt::Write leads to Page Fault when calling write!()

Hello,

I am implementing an OS kernel (for learning purposes) in Rust. I've reached a point where I would like to have nice formatted strings printed to the screen using the usual printing macros. As such I implemented the core::fmt::Write trait for my custom writer that outputs to the EFI framebuffer.

The problem is that when I use any of the formatting macros I end up with a CPU Page Fault. I ran through the code with GDB using QEMU.

I noticed 2 problems, both of which manifest in fmt/mod.rs; the first one is in the call to core::fmt::write(), specifically when calling formatter.buf.write_str(*piece). What happens is that when this function is called the call instruction generated jumps to address 0x0 even though the pointer and vtable addresses seem to be fine.
The second issue is that when iterating through the arguments arg.formatter is NULL.

Some info about the infrastructure that I have:

The main purpose for this project is for me to learn Rust and OS design, since I'm not versed in either.

Any insights, hints, anything really, would be very appreciated.

Thank you in advance,
Romeo

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.