OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Serial doesn't work as expected after exiting boot services
PostPosted: Tue Dec 28, 2021 12:16 am 
Offline

Joined: Tue Dec 28, 2021 12:03 am
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: Serial doesn't work as expected after exiting boot servi
PostPosted: Wed Dec 29, 2021 7:16 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
(This question was also posted elsewhere.)

According to the replies you got elsewhere, the problem might be related to memory allocation. Do you have a global allocator implementation? Does it rely on UEFI boot services?


Top
 Profile  
 
 Post subject: Re: Serial doesn't work as expected after exiting boot servi
PostPosted: Sun Jan 02, 2022 6:00 pm 
Offline
Member
Member
User avatar

Joined: Wed Sep 28, 2005 11:00 pm
Posts: 85
sherbst wrote:
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.


Something similar happened to me when I tried to used Rust to write a memory server. It turned out that liballoc was trying to allocate memory for the String, but my memory allocator wasn't initialized yet, so the code would panic. And then the panic handler would panic when it would try to print the panic message, resulting in an infinite loop. I chose to use byte slices (&[u8]) instead and implement the Write trait so that the write! macro can output the formatted sequence to the slice.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group