OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 122 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next
Author Message
 Post subject: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 3:17 pm 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
I have the impression I was overestimating UEFI all the time:
Question 1.) Is UEFI an important fundament of runtime functions for the kernel, like BIOS interrupts were for DOS? Or is it more like BIOS and 32bit OS where interrupts normally are used only at boot time?

And I thought of all use cases for EFI I can imagine and came up with these:
- turn off watchdog timer
- get mem map
- get video mode
- set video mode
- exit boot services
- load kernel helper files (similar to initial ramdisk)
- boottime messages (diagnostics or bootloader)
- boottime input (bootloader)

Question 2.) Can you name further use cases for UEFI functions?


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 3:25 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
Quick critique: You mean "boot services", not "runtime functions". The two are different :) .
Anyway, boot services are only designed for use like BIOS ints. Once you call ExitBootServices, they can't be used. Runtime services, however, can be used as long as their regions are mapped. One use of a runtime service is setting up a new environment variable from the OS in the firmware.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 3:31 pm 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
nexos wrote:
Quick critique: You mean "boot services", not "runtime functions". The two are different :) .
Anyway, boot services are only designed for use like BIOS ints. Once you call ExitBootServices, they can't be used. Runtime services, however, can be used as long as their regions are mapped. One use of a runtime service is setting up a new environment variable from the OS in the firmware.

No, I didn't mean boot services! I meant runtime services (at least in my first question). Are they important anyway except the env vars you mentioned? Or is it more like pmode where you normally don't have any BIOS interrutps (with exceptions which aren't important here.)

You know, I sort of thought: When I got the boot stuff working there would be a lot of cool UEFI functionality at OS runtime. But I now have the impression that is wrong.

The second question is about ALL UEFI funtions/services.

Greetings
Peter


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 4:34 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3192
It's quite similar to BIOS. While it might be possible to use the real-mode BIOS to access devices like VBE or discs, it's not very practical. Any serious OS will need it's own device drivers anyway.


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 6:36 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
PeterX wrote:
Is UEFI an important fundament of runtime functions for the kernel, like BIOS interrupts were for DOS? Or is it more like BIOS and 32bit OS where interrupts normally are used only at boot time?

UEFI runtime services are mainly for convenience. There's one you can use to change the boot order without opening the UEFI setup. There's one you can use to get the system date and time before you've parsed the ACPI tables to detect the RTC. There's one you can use to reboot or shut down without the help of ACPI.

PeterX wrote:
Can you name further use cases for UEFI functions?

Other than ordinary bootloader stuff you already mentioned or the three runtime services I listed above, I don't think I would go out of my way to use any particular UEFI services.


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 7:21 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
PeterX wrote:
nexos wrote:
Quick critique: You mean "boot services", not "runtime functions". The two are different :) .
Anyway, boot services are only designed for use like BIOS ints. Once you call ExitBootServices, they can't be used. Runtime services, however, can be used as long as their regions are mapped. One use of a runtime service is setting up a new environment variable from the OS in the firmware.

No, I didn't mean boot services! I meant runtime services (at least in my first question). Are they important anyway except the env vars you mentioned? Or is it more like pmode where you normally don't have any BIOS interrutps (with exceptions which aren't important here.)

You know, I sort of thought: When I got the boot stuff working there would be a lot of cool UEFI functionality at OS runtime. But I now have the impression that is wrong.

The second question is about ALL UEFI funtions/services.

Greetings
Peter

Oh ok, I misunderstood, sorry :) . As Octocontrabass stated, UEFI mainly provides convenience functions in runtime. As I already stated, however, it could be a pain calling them, as you need to identity map the runtime services and runtime drivers area of the EFI memory map, which could be incompatible with your OS's memory state.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sat Feb 20, 2021 9:41 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
nexos wrote:
As I already stated, however, it could be a pain calling them, as you need to identity map the runtime services and runtime drivers area of the EFI memory map, which could be incompatible with your OS's memory state.

You can remap the runtime services to any virtual address you want by calling SetVirtualAddressMap() after exiting boot services.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sun Feb 21, 2021 1:21 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
PeterX wrote:
I have the impression I was overestimating UEFI all the time:
Question 1.) Is UEFI an important fundament of runtime functions for the kernel, like BIOS interrupts were for DOS?
Definitely NOT. DOS was lucky so that it could stand on the shoulders of BIOS for I/O.

PeterX wrote:
Or is it more like BIOS and 32bit OS where interrupts normally are used only at boot time?
More like it. 99% of UEFI is completely USELESS after exit Boot Services.

PeterX wrote:
And I thought of all use cases for EFI I can imagine and came up with these:
- turn off watchdog timer
- get mem map
- get video mode
- set video mode
- exit boot services
- load kernel helper files (similar to initial ramdisk)
- boottime messages (diagnostics or bootloader)
- boottime input (bootloader)
Forget ALL of these! These aren't runtime services, a kernel can't use any of these. For example DOS could read a sector into memory using BIOS, but your kernel can't use UEFI Block IO to do the same, you'll have to write a native driver!

PeterX wrote:
Question 2.) Can you name further use cases for UEFI functions?
No! Everything UEFI runtime services provide is a lot simpler to achive without using UEFI. Getting the time? Using a few IO commands is a lot simpler than generating an MS ABI conformant call and parsing it's time structure. Reset the computer? Just do a triple-fault, works 100% of the time. Shutdown? That's not even possible with UEFI, needs a native ACPI driver anyway. Using UEFI variables? Why on earth would anyone do that except for setting the boot order occassionally? Setting virtual map? All kernels will change CR3 directly sooner or later...

That being said, it's not the usefulness of UEFI that's the question. That's the only thing you can use to boot your kernel, so you must support it, whether you like it or not. We must cook from the ingredients we got.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Sun Feb 21, 2021 6:16 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
bzt wrote:
Getting the time? Using a few IO commands is a lot simpler than generating an MS ABI conformant call and parsing it's time structure.

If a legacy RTC exists, yes.

bzt wrote:
Setting virtual map? All kernels will change CR3 directly sooner or later...

That function is for relocating UEFI runtime services to different virtual addresses. It doesn't change CR3 or the page tables.


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Tue Feb 23, 2021 11:02 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
Octocontrabass wrote:
That function is for relocating UEFI runtime services to different virtual addresses. It doesn't change CR3 or the page tables.
The other way around: changing CR3 will remove the ground under UEFI runtime's feet, and "relocating UEFI runtime services" is an utterly and completely dead concept, failure by design. How are you supposed to call SetVirtualAddressMap to configure runtime services' mapping for the new address space, when SetVirtualAddressMap itself is a runtime service? Which one was first, chicken or egg?

And I can't imagine that any OS would afford the unnecessary overhead of calling SetVirtualAddressMap() on each and every task switch when they modify CR3 for some useless functions that are already implemented in the kernel any way. And if they do call it, then they most certainly just expose their kernels to a huge attack vector by allowing UEFI rootkits and malware that installed their own runtime services to poison the OS... Nah, better to forget about UEFI entirely after calling Boot Services, or even better actively stop it from running.

There's simply nothing that would worth having UEFI run-time services for, but at least it's a huge security risk... (sarcasm)

Cheers,
bzt


Last edited by bzt on Tue Feb 23, 2021 11:10 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Tue Feb 23, 2021 11:08 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
bzt wrote:
That being said, it's not the usefulness of UEFI that's the question. That's the only thing you can use to boot your kernel, so you must support it, whether you like it or not. We must cook from the ingredients we got.

Yes, true. I just had some fancy dreams about using some sort of UEFI "drivers" at runtime for all kinds of hardware or at least for some hardware. But I know better now: UEFI is mostly for booting, maybe with some exceptions, but more or less that.

Greetings
Peter


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Tue Feb 23, 2021 4:03 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
bzt wrote:
How are you supposed to call SetVirtualAddressMap to configure runtime services' mapping for the new address space, when SetVirtualAddressMap itself is a runtime service? Which one was first, chicken or egg?
UEFI Specification Version 2.8 (Errata B) wrote:
The call to SetVirtualAddressMap() must be done with the physical mappings. On successful return from this function, the system must then make any future calls with the newly assigned virtual mappings.


bzt wrote:
And I can't imagine that any OS would afford the unnecessary overhead of calling SetVirtualAddressMap() on each and every task switch
UEFI Specification Version 2.8 (Errata B) wrote:
A virtual address map may only be applied one time. Once the runtime system is in virtual mode, calls to this function return EFI_UNSUPPORTED.


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Thu Feb 25, 2021 9:22 am 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 274
Apparently, there's a widespread misconception about UEFI:
https://www.reddit.com/r/osdev/comments/lrvmtk/uefi_os_tutorial/

The good thing is that a guy shared a playlist on youtube by "Poncho" about writing an operating system
from scratch: https://www.youtube.com/playlist?list=PLxN4E629pPnKKqYsNVXpmCza8l0Jb6l8-
I believe that it might be useful to people here as well.

[off-topic]
Btw, I have a question: is r/osdev related with this community or it's just completely unrelated?
[/off-topic]

_________________
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Thu Feb 25, 2021 2:31 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
So it even must less useful as I've originally thought! If what you say is true, then there's really no use of SetVirtualAddressMap!

Octocontrabass wrote:
bzt wrote:
How are you supposed to call SetVirtualAddressMap to configure runtime services' mapping for the new address space, when SetVirtualAddressMap itself is a runtime service? Which one was first, chicken or egg?
UEFI Specification Version 2.8 (Errata B) wrote:
The call to SetVirtualAddressMap() must be done with the physical mappings. On successful return from this function, the system must then make any future calls with the newly assigned virtual mappings.
Erhm, UEFI on 64 bit can't be set to physical mapping mode, as virtual mapping is a requirement for long mode.

Octocontrabass wrote:
bzt wrote:
And I can't imagine that any OS would afford the unnecessary overhead of calling SetVirtualAddressMap() on each and every task switch
UEFI Specification Version 2.8 (Errata B) wrote:
A virtual address map may only be applied one time. Once the runtime system is in virtual mode, calls to this function return EFI_UNSUPPORTED.
Hehe, any OS would switch the virtual mappings pretty frequently during task switches... Those UEFI Consurtium guys really were fools! (Unless they expected the run-time services to be mapped in kernel-space, in which case they unarguably using UEFi as an excuse to create a backdoor in OSes.) Either way, forget UEFI run-time, that's the best!

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: Usefulness of UEFI
PostPosted: Thu Feb 25, 2021 4:54 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
bzt wrote:
Erhm, UEFI on 64 bit can't be set to physical mapping mode, as virtual mapping is a requirement for long mode.

I think you've misunderstood something. The spec uses "physical mappings" to refer to virtual addresses that are equal to physical addresses. You can easily satisfy that requirement without disabling paging by using identity mapping.

Octocontrabass wrote:
Hehe, any OS would switch the virtual mappings pretty frequently during task switches... Those UEFI Consurtium guys really were fools! (Unless they expected the run-time services to be mapped in kernel-space, in which case they unarguably using UEFi as an excuse to create a backdoor in OSes.) Either way, forget UEFI run-time, that's the best!

Why do you assume you must keep the UEFI runtime code and data mapped all the time? You can remove the mappings when you're not using them, and put them back when you want to call a UEFI runtime service.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 122 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 56 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