How to use multiboot structure if I have paging enabled?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mrjbom
Member
Member
Posts: 315
Joined: Sun Jul 21, 2019 7:34 am

How to use multiboot structure if I have paging enabled?

Post by mrjbom »

In my higher half kernel, I enable paging, but since the multiboot info struct is usually located below 1 mb and outside of my kernel data, I can't safely take information from it.
I see two ways out:
1. Map the first 1 MB each time when you need to get data from the structure.
2. Copy multiboot info struct once and use the copied data.
But both ways have problems:
1. It is not particularly safe and may cause problems in the future.
2. Copying all the information that the structure contains and its various parts is very difficult, it is necessary to manually copy all its parts (for example mmap).

How can I solve this problem?
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: How to use multiboot structure if I have paging enabled?

Post by kzinti »

Here is one way to do it (it seems simple enough):

Bootloader:
1) Identity map the first 4 GB of memory
2) Map the kernel in high-address space
3) Enable paging
4) Jump to the kernel, pass a pointer to the multiboot info

Kernel:
5) Extract / copy all the desired information out of the multiboot structure
6) Unmap the first 4 GB of memory

Alternatively you could parse the multiboot info in the bootloader (and you probably want to do that anyways to know where the memory and framebuffer are). Then build you own data structure with what you need "struct BootData" and pass it to the kernel. The above still applies.

I think the key here is to not try to copy the multiboot info as-is. Instead walk that info and store what you need in your own data structures.
Last edited by kzinti on Wed Jun 08, 2022 10:58 am, edited 1 time in total.
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

Re: How to use multiboot structure if I have paging enabled?

Post by nullplan »

So, after you have set up paging, the address given for the multiboot info is a physical address. How do you access physical addresses? You map them to virtual addresses!

Essentially, you need to change your viewpoint: The address GRUB has given you is a physical address, as are all the addresses contained in the multiboot data. If you must access the information after enabling paging, you must do so like all other info present at some physical address.
Carpe diem!
Post Reply