OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 9:33 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Is my little algorithm right?
PostPosted: Wed Oct 17, 2018 10:17 am 
Offline

Joined: Wed Oct 17, 2018 9:56 am
Posts: 19
I think that when I get the memory map from GRUB, I parse it and if I get a free usable 4mb block then push it to the stack. Is it right? Do you have suggestions or improvements?


Top
 Profile  
 
 Post subject: Re: Is my little algorithm right?
PostPosted: Wed Oct 17, 2018 11:24 am 
Offline

Joined: Wed Oct 17, 2018 9:56 am
Posts: 19
Following the higher half tutorial, the code suggest set the 4MB bit in cr4 so I've set it. Shouldn't I?


Top
 Profile  
 
 Post subject: Re: Is my little algorithm right?
PostPosted: Wed Oct 17, 2018 1:04 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Rather than blindly following a tutorial you should think about what you are doing. For most purposes I think the default 4KB page size is the best choice.

What advantage do you see in larger pages?


Top
 Profile  
 
 Post subject: Re: Is my little algorithm right?
PostPosted: Wed Oct 17, 2018 1:24 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
You need to be careful not to consider the kernel itself unused memory.

There's an extra danger here: The multiboot structures, where your memory map is stored, is also somewhere in unused memory (somewhere else than your kernel, GRUB does do that). You need to check every page for whether it overlaps with any of the multiboot structures that you use (remember, there's a bunch of pointers in there).

When you initialize paging, you may be tempted to use some hard-coded physical addresses for that, but you can't do that. GRUB might put its information there. Instead you should make 4096 byte sized variables with 4096 byte alignment in your code. Then you can use those pages, as GRUB will know to avoid your variables (using your ELF program headers).

Do we have a wiki article about this? I've done a bunch of detailed explanations in the past, it would be good to write up a canonical page with hints. This is after all a key thing.


Top
 Profile  
 
 Post subject: Re: Is my little algorithm right?
PostPosted: Wed Oct 17, 2018 2:38 pm 
Offline

Joined: Wed Oct 17, 2018 9:56 am
Posts: 19
iansjack wrote:
Rather than blindly following a tutorial you should think about what you are doing. For most purposes I think the default 4KB page size is the best choice.

What advantage do you see in larger pages?

I tried, but when I tried to fill the BootPageDirectory
Code:
BootPageDirectory:
    .int 0x00000083     
    .fill KERNEL_PAGE_NUMBER - 1, 4, 0
    .int 0x00000083
    .fill 0x400 - KERNEL_PAGE_NUMBER - 1, 4, 0

I couldn't understand how to do it. So I left how it was with 4MB pages...

sortie wrote:
You need to be careful not to consider the kernel itself unused memory.

There's an extra danger here: The multiboot structures, where your memory map is stored, is also somewhere in unused memory (somewhere else than your kernel, GRUB does do that). You need to check every page for whether it overlaps with any of the multiboot structures that you use (remember, there's a bunch of pointers in there).

So I have to verify if the page isn't between those flags-like that I set in the linker (e. g. . = start at the beginning plus . = end at the bottom) and between mmap->mmap_addr and mmap->mmap_addr + mmap_length too?

sortie wrote:
When you initialize paging, you may be tempted to use some hard-coded physical addresses for that, but you can't do that. GRUB might put its information there. Instead you should make 4096 byte sized variables with 4096 byte alignment in your code. Then you can use those pages, as GRUB will know to avoid your variables (using your ELF program headers).

I think it's used in the higher half tutorial while doing that type of definition I put above... right?


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

All times are UTC - 6 hours


Who is online

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