Why exit Boot Services?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
drewdavis
Posts: 1
Joined: Tue Jul 23, 2024 9:49 pm

Why exit Boot Services?

Post by drewdavis »

While using UEFI, why we need to exit boot services? Can it work without exiting? (I wrote an entire shell without exiting boot services.)
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why exit Boot Services?

Post by Octocontrabass »

rdos
Member
Member
Posts: 3296
Joined: Wed Oct 01, 2008 1:55 pm

Re: Why exit Boot Services?

Post by rdos »

The graphics support in UEFI is a lot worse than in the legacy BIOS using VBE. With VBE, you can setup V86 mode to switch video modes. On UEFI, this is basically impossible.

What this means is that it's best to set the "optimal video mode" that match with the display at boot time, either with VBE or before exiting boot services in UEFI. There is not much use in being able to switch video modes during runtime anyway (I once supported this, but no longer use it).

Still, setting the right video mode with UEFI automatically is far from clear how to do. My current solution is to always use the first available, as this appears to be correct on the implementations I've seen, but this might break on other hardware. Non-native video modes are often not working properly with UEFI either, and some Intel PCs doesn't support the native mode at all if it is not 4:3.
trulyirrelevant
Posts: 5
Joined: Mon Jul 15, 2024 3:15 am

Re: Why exit Boot Services?

Post by trulyirrelevant »

To use the runtime services? RTC is a requirement for a real operating system.
rdos
Member
Member
Posts: 3296
Joined: Wed Oct 01, 2008 1:55 pm

Re: Why exit Boot Services?

Post by rdos »

trulyirrelevant wrote: Wed Jul 24, 2024 2:49 pm To use the runtime services? RTC is a requirement for a real operating system.
I cannot see any use of the runtime services, and they also depend on keeping the paging structure from boot time. This is quite impossible if you switch from long mode to protected mode, but even if you keep the processor mode it requires the ability to keep the unity mapping, which is not a good idea.
trulyirrelevant
Posts: 5
Joined: Mon Jul 15, 2024 3:15 am

Re: Why exit Boot Services?

Post by trulyirrelevant »

x86 and UEFI are antithetical, do BIOS
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why exit Boot Services?

Post by Octocontrabass »

rdos wrote: Thu Jul 25, 2024 1:34 amthey also depend on keeping the paging structure from boot time.
No they don't.

You can call runtime services with your own paging structures. You can choose any virtual addresses, you don't need to identity-map the runtime services memory regions. Runtime services memory regions only need to be mapped right before you call runtime services, and you can unmap them after the call returns.
rdos
Member
Member
Posts: 3296
Joined: Wed Oct 01, 2008 1:55 pm

Re: Why exit Boot Services?

Post by rdos »

Octocontrabass wrote: Thu Jul 25, 2024 7:43 pm
rdos wrote: Thu Jul 25, 2024 1:34 amthey also depend on keeping the paging structure from boot time.
No they don't.

You can call runtime services with your own paging structures. You can choose any virtual addresses, you don't need to identity-map the runtime services memory regions. Runtime services memory regions only need to be mapped right before you call runtime services, and you can unmap them after the call returns.
Still, basically every UEFI is 64-bit, and to call runtime services in long mode, I would need to switch the processor to long mode with an appropriate page table mapping, call the service, and switch back to protected mode. That might work for non-critical occasional services, but not much else. It's a bit like using BIOS services from protected mode. Switching video mode might work, but implementing important services that way is not a good idea.
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Why exit Boot Services?

Post by Octocontrabass »

rdos wrote: Fri Jul 26, 2024 1:40 amThat might work for non-critical occasional services, but not much else.
There isn't anything else. UEFI runtime services are not critical and only meant to be called occasionally.
Post Reply