UEFI booting

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
jordyd
Posts: 7
Joined: Thu Sep 07, 2017 1:29 pm
Libera.chat IRC: jordyd

UEFI booting

Post by jordyd »

I've been using "legacy" BIOS so far, but want to switch to UEFI. However, reading the UEFI documentation, I can't seem to find anywhere where it says what the boot environment is like. For example, is paging enabled? Is there a GDT set up? Are there any special considerations I have to take into account when setting these things up, assuming they're not set up?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: UEFI booting

Post by BrightLight »

jordyd wrote:For example, is paging enabled? Is there a GDT set up? Are there any special considerations I have to take into account when setting these things up, assuming they're not set up?
I don't know a whole lot about UEFI, but UEFI normally leaves you in 64-bit mode, which means paging is enabled and there is a GDT, with the segment registers set to 64-bit long mode selectors. Supposedly, UEFI leaves all memory identity-mapped, which means virtual address equals physical address. So you can easily set up your own paging/GDT structures without taking into consideration the current paging structures, and then reload CR3 and the segment registers.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
no92
Member
Member
Posts: 307
Joined: Wed Oct 30, 2013 1:57 pm
Libera.chat IRC: no92
Location: Germany
Contact:

Re: UEFI booting

Post by no92 »

The UEFI spec requires all memory listed by the UEFI memory map to be identity mapped in long mode, while also allowing paging to be disabled in protected mode. As for the GDT, the UEFI spec doesn't say anything about the state you are left with - it does say however that using the firmware requires you to restore the original GDT. You can assume that you will be left with a working state when you take over, but really nothing beyond that.
jordyd
Posts: 7
Joined: Thu Sep 07, 2017 1:29 pm
Libera.chat IRC: jordyd

Re: UEFI booting

Post by jordyd »

Thanks guys, that was very informative. I was under the impression that UEFI could be used on 32-bit computers, and presumably would drop you into protected mode on those computers. Is this incorrect? I'm not really sure where I got that idea.
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: UEFI booting

Post by Octocontrabass »

No, that's correct. A 32-bit computer can have UEFI, and 32-bit UEFI will start you in protected mode.

It's also possible (but uncommon) for a 64-bit computer to have 32-bit UEFI. It'll start you in protected mode, but you can switch to long mode.
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: UEFI booting

Post by prajwal »

one option is to use grub 2.0 to boot using UEFI and load your kernel
complexity is the core of simplicity
jordyd
Posts: 7
Joined: Thu Sep 07, 2017 1:29 pm
Libera.chat IRC: jordyd

Re: UEFI booting

Post by jordyd »

Main reason I want to use UEFI is that I need access to the EBDA on systems that use both legacy BIOS as well as UEFI, so I'm trying to figure out how to do that. I don't want to make this into a thread about finding the EBDA, however. I just noted that on the page describing how to find the EBDA on the OSDev Wiki, it mentions that on UEFI systems the method may not work, and on those systems it requires looking in the system tables. Does GRUB provide me with UEFI data structures? I can't seem to find anything on that, and it doesn't appear to be in the multiboot spec.
jordyd
Posts: 7
Joined: Thu Sep 07, 2017 1:29 pm
Libera.chat IRC: jordyd

Re: UEFI booting

Post by jordyd »

I did some reading and found this https://www.gnu.org/software/grub/manua ... ion-format, which, if you scroll enough, indicates that you can access the UEFI system table pointer from Multiboot 2, which effectively solves my issue. Hopefully someone else will find this useful as well.
Post Reply