Page 1 of 1

How to use multiboot structure if I have paging enabled?

Posted: Wed Jun 08, 2022 10:13 am
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?

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

Posted: Wed Jun 08, 2022 10:28 am
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.

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

Posted: Wed Jun 08, 2022 10:32 am
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.