OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:06 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: How many sectors to load yhe whole kernel
PostPosted: Fri Jun 03, 2022 3:16 pm 
Offline
Member
Member
User avatar

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

We just load it as any other file, so the number of clusters loaded is provided from the file system. The loader loads a config file which then tells it to load a kernel. Then just load the file, relocate it, and execute it. Although the kernel is expected to be at 1MB physical it relocates itself at a later stage when paging is enabled.

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


Top
 Profile  
 
 Post subject: Re: How many sectors to load yhe whole kernel
PostPosted: Fri Jun 03, 2022 3:26 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
neon wrote:
Although the kernel is expected to be at 1MB physical it relocates itself at a later stage when paging is enabled.

Even if you're writing a BIOS bootloader, you should avoid depending on specific physical addresses like this in your kernel. UEFI doesn't guarantee any particular physical address will be available, and in the future you might want a UEFI bootloader so your OS can run on modern PCs.


Top
 Profile  
 
 Post subject: Re: How many sectors to load yhe whole kernel
PostPosted: Fri Jun 03, 2022 3:48 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hi,
Quote:
Even if you're writing a BIOS bootloader, you should avoid depending on specific physical addresses like this in your kernel. UEFI doesn't guarantee any particular physical address will be available, and in the future you might want a UEFI bootloader so your OS can run on modern PCs.
Just clarifying as our loader is BIOS and UEFI; it can be built to target both. I would expect 1MB physical to always be available. I cannot imagine a scenario where that wouldnt be: but... I suppose if you want to be on the safe side, well.... can just introduce a region based zone allocator and map the file into an available zone. That 1MB comes from the kernel header / boot protocol information. So I suppose we can introduce logic like "if the kernel requested image base is not available, allocate it to an available zone and attempt to perform a relocation if possible. Fatal error if image format not understood."

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


Top
 Profile  
 
 Post subject: Re: How many sectors to load yhe whole kernel
PostPosted: Fri Jun 03, 2022 5:46 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
neon wrote:
I would expect 1MB physical to always be available. I cannot imagine a scenario where that wouldnt be

Why would it always be available? The "standard" PC memory map is only needed for BIOS compatibility, there's nothing about UEFI that requires available memory at 1MB.

neon wrote:
introduce a region based zone allocator and map the file into an available zone.

You can use the allocator provided by UEFI boot services. Your allocations will even appear in the firmware's memory map. The only limitation is that you can't define your own memory types, you have to use the defaults.

neon wrote:
So I suppose we can introduce logic like "if the kernel requested image base is not available, allocate it to an available zone and attempt to perform a relocation if possible. Fatal error if image format not understood."

I would recommend using paging to map the kernel directly to its desired virtual address.


Top
 Profile  
 
 Post subject: Re: How many sectors to load yhe whole kernel
PostPosted: Fri Jun 03, 2022 6:54 pm 
Offline
Member
Member
User avatar

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

At this time, we enable paging in the kernel initial startup rather then the boot loader in order to facilitate creating the PFN free stack used by the kernel (which is easiest to set up with direct access to physical memory.) It was also for compatibility with MultiBoot. However... we did originally use paging in the loader in older versions and I believe still have the code. If we were to enable paging in the loader again (which has been in consideration for some time) then we would need to adjust how we build the PFN free stack. So...paging in the loader... we'll see. It is an option that we may go back to, whenever time allows it. The firmware interfaces have a "Alloc Pages" and "Free Pages" which, for UEFI builds, does indeed call the UEFI boot services. We just have a separate firmware independent allocator to handle the low memory pool (not used in UEFI builds) and conventional memory pool (heap).

If the loader enables paging, we can certainly do what you suggested and just map them to the requested virtual address. Honestly though, for most people, this would be the way to go.

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


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 71 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