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
[Paging] Transfering setup from bootloader to kernel
[Paging] Transfering setup from bootloader to kernel
currently working on kboot86, the Genesis of my kernel
Re: [Paging] Transfering setup from bootloader to kernel
Make your bootloader initialise a recursive mapping.
Re: [Paging] Transfering setup from bootloader to kernel
I am already doing that. With the current configuration it's not a problem to copy the page directory and the page tables.Boris wrote:Make your bootloader initialise a recursive mapping.
currently working on kboot86, the Genesis of my kernel