OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Jun 16, 2021 10:46 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: understanding bootloaders
PostPosted: Thu May 13, 2021 6:30 pm 
Offline

Joined: Sat May 01, 2021 8:47 pm
Posts: 15
How do bootloaders detect devices, peripherals, etc. on boot? I know sometimes it's designed and/or hardcoded for only certain stuff(as in some laptops), but how would you go about finding text mode buffer, refresh/polling rate of monitor/display, etc..

Also, how do the EDK II/gnu-efi libraries work? Like how do they detect and write to devices such as NIC, GPU, CPU..

How do CPUs and proprietary drivers detect cpu temperature, etc.?

The guides and tutorials skim this and tell you to figure it out and/or use a library and dont do anything too low-level


Top
 Profile  
 
 Post subject: Re: understanding bootloaders
PostPosted: Thu May 13, 2021 6:57 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1515
Hi,

From the perspective of a boot loader, I only ever obtain information by querying available firmware interfaces: disk drives are scanned using the firmware device ID space int 13h services (BIOS) or EFI boot services, video and EDID information is obtained from VBE (Legacy BIOS) or GOP (EFI). The questions here are very broad: they work by querying the respective firmware service and may attempt a fallback if not available (serial debug out, pci scanning for network device, etc.)

_________________
OS Development Series | Project Neptune | Repository | Wiki
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: understanding bootloaders
PostPosted: Fri May 14, 2021 7:30 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1517
newosdeveloper2021 wrote:
How do bootloaders detect devices, peripherals, etc. on boot?
Short answer: they don't. Firmware does, and loaders just ask the firmware what devices it had detected.
newosdeveloper2021 wrote:
I know sometimes it's designed and/or hardcoded for only certain stuff(as in some laptops), but how would you go about finding text mode buffer,
Under BIOS with VGA cards, that's always 0xB8000. Under UEFI, text mode buffer isn't supported at all.
newosdeveloper2021 wrote:
refresh/polling rate of monitor/display, etc..
Bootloaders do not need these. But if they want, they could ask the firmware (BIOS/UEFI) for such an information.
newosdeveloper2021 wrote:
Also, how do the EDK II/gnu-efi libraries work? Like how do they detect and write to devices such as NIC, GPU, CPU..
UEFI is designed in a way that everything is communicating through "protocols" (which aren't protocols at all, just interfaces). So if you want to know how many video cards are in the system, you ask the firmware to return handles to GOP interfaces. Likewise, if you want to know how many disks there are, you ask the firmware to return handles to block IO protocol interfaces.
"Writing" to a device is calling a method within a particular interface instance.
newosdeveloper2021 wrote:
How do CPUs and proprietary drivers detect cpu temperature, etc.?
Bootloaders do not need these. And kernels have their own driver for the specific sensor device.
newosdeveloper2021 wrote:
The guides and tutorials skim this and tell you to figure it out
Our wiki (pages like boot seq, bootloader) is the best source (follow the links like rolling your own bootloader, etc.). For BIOS, see RBIL. For UEFI, see the official spec. For a tutorial, check out the source of an Open Source bootloader, like Limine, BOOTBOOT, or GRUB (however this latter is a "bit" bloated, easy to get lost in its source).
newosdeveloper2021 wrote:
use a library and dont do anything too low-level
For a library, take a look at GNU-EFI (gcc only) or POSIX-EFI (works with gcc and Clang too). But don't get high hopes about not doing anything too low-level, because writing an OS is all about being as low level as possible.

Cheers,
bzt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

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