OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to find which physical addresses are used by BOOTBOOT?
PostPosted: Thu Sep 02, 2021 12:15 pm 
Offline
Member
Member

Joined: Sun May 24, 2020 9:11 am
Posts: 61
Location: /dev/null
I'm porting my OS from GRUB to BOOTBOOT. GRUB's multiboot protocol is much more simple. GRUB, for example, does not setup paging nor long mode nor framebuffer etc.

So it's maybe harder to setup, but filling physical memory allocation linked list is easy, whole memory (except for your kernel and initrd, but their position and size is in MBI) is free at the beginning. Same thing with paging.

When it cames to BOOTBOOT, however, I don't know which memory segments are already used (and I should mark them reserved in my physical memory allocation system).


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Thu Sep 02, 2021 2:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
I would expect that information to be in the specification, but I didn't see it when I looked. You might need to submit an issue to have the documentation clarified.


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Fri Sep 03, 2021 7:10 am 
Offline
Member
Member

Joined: Sun May 24, 2020 9:11 am
Posts: 61
Location: /dev/null
It's not in documentation. Only there is description of virtual memory. This is enough to write bootstrap code, but in my operating system I need to manage the paging myself and for that I also need to manage the physical memory.


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Fri Sep 03, 2021 5:30 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 401
antoni wrote:
It's not in documentation. Only there is description of virtual memory. This is enough to write bootstrap code, but in my operating system I need to manage the paging myself and for that I also need to manage the physical memory.


The spec contains a section about "Memory Map Entries" (page 16), which I presume is the same sort of information as provided by e820 interface or UEFI.

Is that what you're after?


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Sat Sep 04, 2021 6:01 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
A glance at the EFI loader's source found this
Code:
// failsafe, don't report our own structures as free
            if( mement->NumberOfPages==0 ||
                ((mement->PhysicalStart <= (UINT64)bootboot &&
                    mement->PhysicalStart+(mement->NumberOfPages*PAGESIZE) > (UINT64)bootboot) ||
                 (mement->PhysicalStart <= (UINT64)env.ptr &&
                    mement->PhysicalStart+(mement->NumberOfPages*PAGESIZE) > (UINT64)env.ptr) ||
                 (mement->PhysicalStart <= (UINT64)initrd.ptr &&
                    mement->PhysicalStart+(mement->NumberOfPages*PAGESIZE) > (UINT64)initrd.ptr) ||
                 (mement->PhysicalStart <= (UINT64)core.ptr &&
                    mement->PhysicalStart+(mement->NumberOfPages*PAGESIZE) > (UINT64)core.ptr) ||
                 (mement->PhysicalStart <= (UINT64)paging &&
                    mement->PhysicalStart+(mement->NumberOfPages*PAGESIZE) > (UINT64)paging)
                )) {
                    continue;
            }

I guess it just ignores the bootloader's structures and doesn't put them in the map if I'm not mistaken. Now, it would be best practice to do what Limine does and create entries specifically for this kind of memory, so that the kernel can reclaim some of it when its done using the bootloader.

Full source is at https://gitlab.com/bztsrc/bootboot/-/blob/master/x86_64-efi/bootboot.c in case I missed something.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Sat Sep 04, 2021 9:13 am 
Offline
Member
Member

Joined: Sun May 24, 2020 9:11 am
Posts: 61
Location: /dev/null
It's true. I checked few addresses that bootboot passed to me and found that they are outside of the memory reported as free. This is good.

It would be nice if I could possibly free up some of that memory, however, this topic I think is already closed.


Top
 Profile  
 
 Post subject: Re: How to find which physical addresses are used by BOOTBOO
PostPosted: Sat Sep 04, 2021 10:53 am 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
To do that, you have three options:
No. 1 - look at the code and figure out which address BOOTBOOT uses, and statically free those address when done with them. I don't recommend this
No. 2 - open an issue in Gitlab for this to be changed
No. 3 - use a different bootloader

I would open an issue personally, as that would help people who will use BOOTBOOT in the future.

_________________
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg


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

All times are UTC - 6 hours


Who is online

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