Serial doesn't work as expected after exiting boot services
Posted: Tue Dec 28, 2021 12:16 am
Recently got back into trying to implement a small OS for fun. It currently is simply a UEFI application/loader. I hope to make it function like some sort of loader to load my kernel.
When the loader starts up, I have it print some text over COM1. Redirecting serial to stdio with QEMU, I can see that this works. Indeed, after exiting boot services, writing to COM1 still works... sometimes.
I am writing this in Rust, and when attempt to send a simple string ("Hello, world\n") over COM1, it works fine. However, when I do some processing to generate this string (&format!("some value: {}", value)), nothing gets sent to COM1.
I have a similar issue with the UEFI graphics output protocol's frame buffer. I can write to the frame buffer before and after exiting boot services, but if the write to the frame buffer is behind a couple function calls, it just doesn't work.
In my small amount of understanding I thought maybe the stack was somehow overwriting these parts of memory. Not sure if that is happening or even possible, but I tried to inspect ebp and esp to see if anything was obvious. I find that for the entirety of the execution of my loader esp is 0x7FF1A130 and ebp is 0x0. This is further confusing to me because I thought ebp had to be at a higher address than esp. In addition, esp doesn't seem to move during the execution of the loader: another thing I would expect to happen. I also tried to move the stack to an arbitrary location, which gave me a page fault (not surprised).
All in all, not sure if the stack thing is the issue just thought I would mention it (and maybe someone can fill in my understanding on how the stack works).
Any ideas appreciated.
Thanks,
Sawyer
When the loader starts up, I have it print some text over COM1. Redirecting serial to stdio with QEMU, I can see that this works. Indeed, after exiting boot services, writing to COM1 still works... sometimes.
I am writing this in Rust, and when attempt to send a simple string ("Hello, world\n") over COM1, it works fine. However, when I do some processing to generate this string (&format!("some value: {}", value)), nothing gets sent to COM1.
I have a similar issue with the UEFI graphics output protocol's frame buffer. I can write to the frame buffer before and after exiting boot services, but if the write to the frame buffer is behind a couple function calls, it just doesn't work.
In my small amount of understanding I thought maybe the stack was somehow overwriting these parts of memory. Not sure if that is happening or even possible, but I tried to inspect ebp and esp to see if anything was obvious. I find that for the entirety of the execution of my loader esp is 0x7FF1A130 and ebp is 0x0. This is further confusing to me because I thought ebp had to be at a higher address than esp. In addition, esp doesn't seem to move during the execution of the loader: another thing I would expect to happen. I also tried to move the stack to an arbitrary location, which gave me a page fault (not surprised).
All in all, not sure if the stack thing is the issue just thought I would mention it (and maybe someone can fill in my understanding on how the stack works).
Any ideas appreciated.
Thanks,
Sawyer