Page 1 of 1

Why exit Boot Services?

Posted: Tue Jul 23, 2024 9:51 pm
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.)

Re: Why exit Boot Services?

Posted: Tue Jul 23, 2024 11:16 pm
by Octocontrabass

Re: Why exit Boot Services?

Posted: Wed Jul 24, 2024 12:56 am
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.

Re: Why exit Boot Services?

Posted: Wed Jul 24, 2024 2:49 pm
by trulyirrelevant
To use the runtime services? RTC is a requirement for a real operating system.

Re: Why exit Boot Services?

Posted: Thu Jul 25, 2024 1:34 am
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.

Re: Why exit Boot Services?

Posted: Thu Jul 25, 2024 8:54 am
by trulyirrelevant
x86 and UEFI are antithetical, do BIOS

Re: Why exit Boot Services?

Posted: Thu Jul 25, 2024 7:43 pm
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.

Re: Why exit Boot Services?

Posted: Fri Jul 26, 2024 1:40 am
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.

Re: Why exit Boot Services?

Posted: Fri Jul 26, 2024 12:12 pm
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.