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 kernel is loaded into memory via UEFI, from the EFI partition, and the entry function is executed by finding the entry-point's address, transmuting it to the correct function signature, and calling it
- The kernel is compiled using this target definition: kernel/x86_64-none-kernel.json · master · Romeo Calota / primitiveos · GitLab
- The code that implements the
fmt::Writertrait can be found at: kernel/src/efi_framebuffer.rs · master · Romeo Calota / primitiveos · GitLab
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,