Page 1 of 1

UEFI booting

Posted: Sun Sep 10, 2017 8:35 am
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?

Re: UEFI booting

Posted: Sun Sep 10, 2017 8:41 am
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.

Re: UEFI booting

Posted: Sun Sep 10, 2017 9:42 am
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.

Re: UEFI booting

Posted: Sun Sep 10, 2017 9:46 am
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.

Re: UEFI booting

Posted: Mon Sep 11, 2017 7:31 am
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.

Re: UEFI booting

Posted: Mon Sep 11, 2017 5:26 pm
by prajwal
one option is to use grub 2.0 to boot using UEFI and load your kernel

Re: UEFI booting

Posted: Mon Sep 11, 2017 11:46 pm
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.

Re: UEFI booting

Posted: Tue Sep 12, 2017 12:56 am
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.