[Paging] Transfering setup from bootloader to kernel

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
Neroku
Posts: 24
Joined: Tue Dec 01, 2015 4:53 am

[Paging] Transfering setup from bootloader to kernel

Post by Neroku »

Hello,

I am loading my kernel by means of a custom bootloader. The bootloader copies the content of an ELF file into memory. Then, this in-memory ELF image (e.i.: the kernel itself) is parsed and loaded. Before parsing the ELF image, the bootloader enables the paging subsystem, because I want to take full advantage of the program segment flags ("segment" in terms of ELF) such as execute, write and read-only in order to prevent read-only data and code segments from being written.

As suggested in the tutorials, I'm using one-to-one mapping (identity mapping) for the entire lowest megabyte and map the kernel to virtual address 0xc00000 (3 GiB), being physically located at 0x100000 (1 MiB). The information regarding the kernel's virtual and physical address is not fixed by the bootloader, but actually resides in the ELF image in the VMA and LMA fields, respectively.

At some point the kernel has eventually to work with the page directory and the page tables. Since the kernel can always figure out the physical address of the page directory being used by reading the CR3 register, it would be at first sight possible to copy the page directory and the page tables that were originally set up by the bootloader when the kernel was loaded, as long as there is a way to perfom a translation from a virtual address to its corresponding physical address, like having, for instance, an entry of the page directory poiting to itself (as stated in the tutorial Paging#Manipulation).

I would like to know whether this approach of transfering the old paging setup from the bootloader to the kernel is considered to be an elegant solution.
Do you have any other suggestions?


Thanks in advance
currently working on kboot86, the Genesis of my kernel
Boris
Member
Member
Posts: 145
Joined: Sat Nov 07, 2015 3:12 pm

Re: [Paging] Transfering setup from bootloader to kernel

Post by Boris »

Make your bootloader initialise a recursive mapping.
User avatar
Neroku
Posts: 24
Joined: Tue Dec 01, 2015 4:53 am

Re: [Paging] Transfering setup from bootloader to kernel

Post by Neroku »

Boris wrote:Make your bootloader initialise a recursive mapping.
I am already doing that. With the current configuration it's not a problem to copy the page directory and the page tables.
currently working on kboot86, the Genesis of my kernel
Post Reply