OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 11:02 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Fri Dec 29, 2023 11:41 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
rdos wrote:
I'm aware that these locations and pathnames might not be in the UEFI specification,

They are in the specification. Microsoft uses them on removable media to boot the Windows installer.

rdos wrote:
Actually, I have no idea how to modify Load Options or BootOrder outside of the EFI environment where the OS loader would run.

Runtime services work almost exactly like boot services, except you can continue to call them after you've called ExitBootServices(). Unfortunately, you must also deal with firmware bugs that don't affect Windows, so you should call SetVirtualAddressMap() even though it's supposed to be optional, and you should preserve boot services memory even though the firmware isn't supposed to access it.


Top
 Profile  
 
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Fri Dec 29, 2023 2:25 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3195
Octocontrabass wrote:
rdos wrote:
Actually, I have no idea how to modify Load Options or BootOrder outside of the EFI environment where the OS loader would run.

Runtime services work almost exactly like boot services, except you can continue to call them after you've called ExitBootServices(). Unfortunately, you must also deal with firmware bugs that don't affect Windows, so you should call SetVirtualAddressMap() even though it's supposed to be optional, and you should preserve boot services memory even though the firmware isn't supposed to access it.


Runtime services are not likely to work when processor mode is changed. For 64-bit UEFI, my stub loader switches the processor to protected mode before it starts the kernel. It might have worked with 32-bit UEFI, but those are typically buggy and it's better to boot with MBR on those systems.


Top
 Profile  
 
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Fri Dec 29, 2023 2:34 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
rdos wrote:
Runtime services are not likely to work when processor mode is changed.

Runtime services don't care what mode the processor is in when your OS is running as long as you return the processor to the correct mode before calling them.


Top
 Profile  
 
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Thu Jan 04, 2024 9:51 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
rdos wrote:
Well, that works if the BIOS has a EFI command line (shell), but if it doesn't you are better off with a USB stick that has /efi/boot/bootx64.efi (and /efi/boot/bootia32.efi if the machine is 32-bit). I'm aware that these locations and pathnames might not be in the UEFI specification, but they appear to work on all machines where I have tried them, so they are at least inofficial standards for x86.

these options are part of standard, but they clearly marked there as the "last resort default behavior for removable devices". that is if there is nothing else to boot found, only then they will be tried. so, if you have some OS already installed, this won't work. without additional trickery, like some BIOS-like changing the boot device order. But then it's better to just break into the "load from file" option and start your loader, no matter how it's called and where inside a FAT volume it sits. this option must be present in any sane firmware. just like the possibility of installing UEFI shell. but even for this abused variant, ESP marking for the FAT volume is not necessary. also some iditiotic firmwares won't boot these "magic" bootxxxx.efi things unless you directly allow some "USB boot" or whatever sh1t they invent. the point is it's non comformant inventions, one barely should rely upon, because they would lead an OSL and user experience with it to become a bunch of ugly hacks, extreme mess and frustration still not working half the cases.

Octocontrabas wrote:
you should preserve boot services memory even though the firmware isn't supposed to access it.

just my not asked opinion: better to just weed the idea of trying such a machine out instead of trying to comply with what broke compliance this hard on its own.

Octocontrabas wrote:
Microsoft uses them on removable media to boot the Windows installer.

who doesn't? OpenBSD does, everybody does. but why? only because it seems "easier". really, it's so much easier to search through lunatic firmwares facing them rejecting to boot at all, no matter how many times and ports you inserted your stick into, :mrgreen: then guessing that the USB boot yet needs to be allowed, then finding out how to make that USB boot allowed, then change the order to put the USB boot atop, then waiting the sacral moment of the fw accepting that bootx64.efi, maybe still it won't? it's much easier, than finding "load from file", going through its file navigation capabilities, finding that PciRoot()\Pci()\USB()\USB()\USB()\HD(MBR, 1, b16b00b5)\efi\cooldudes\coolosldr.efi and hitting it. For me, it's a more valuable thing, that I proudly can ensure my user, that they don't need to format their sticks if they want to install my OS, than ability to add a few of machines with pornographicaly bugged firmwares to the supported list. :D

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Fri Jan 05, 2024 9:28 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3195
Octocontrabass wrote:
rdos wrote:
Runtime services are not likely to work when processor mode is changed.

Runtime services don't care what mode the processor is in when your OS is running as long as you return the processor to the correct mode before calling them.


I suppose that might be possible after all. I already have code that switches to long mode (and back), and adding new code that switch the processor to long mode with an unity page table mapping and then call a runtime service seems to be possible. Not easy, but at least possible.


Top
 Profile  
 
 Post subject: Re: Making a bootloader for UEFI and BIOS at the same time.
PostPosted: Fri Jan 05, 2024 9:31 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3195
zaval wrote:
these options are part of standard, but they clearly marked there as the "last resort default behavior for removable devices". that is if there is nothing else to boot found, only then they will be tried. so, if you have some OS already installed, this won't work. without additional trickery, like some BIOS-like changing the boot device order. But then it's better to just break into the "load from file" option and start your loader, no matter how it's called and where inside a FAT volume it sits. this option must be present in any sane firmware. just like the possibility of installing UEFI shell. but even for this abused variant, ESP marking for the FAT volume is not necessary. also some iditiotic firmwares won't boot these "magic" bootxxxx.efi things unless you directly allow some "USB boot" or whatever sh1t they invent. the point is it's non comformant inventions, one barely should rely upon, because they would lead an OSL and user experience with it to become a bunch of ugly hacks, extreme mess and frustration still not working half the cases.


Well, I generally don't want multiboot, and by booting from an USB stick I can repartition the hard drive, and then the UEFI boot loader will be unable to boot the previous OS and needs to resort to default settings. Maybe ugly, but it seems to work well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 19 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