x86-64bootloaderosdevpaginguefi

Setting up Paging in the Bootloader (UEFI)


I am writing a hobby OS with it's own uefi-target x64 bootloader. In the UEFI specification it states that identity-mapped paging is enabled:

Paging mode is enabled and any memory space defined by the UEFI memory map is identity mapped (virtual address equals physical address), although the attributes of certain regions may not have all read, write, and execute attributes or be unmarked for purposes of platform protection. The mappings to other regions, such as those for unaccepted memory, are undefined and may vary from implementation to implementation.

Source

The kernel I am writing is supposed to be a higher-half kernel, thus I set up a new paging scheme in the loader that maps the kernel code pages, bootinformation, ... to higher half adddresses. But from what I know paging is usually set up in the kernel.

Are there any downsides to only setting it up in the loader?


Solution

  • If your kernel will eventually have a user-space portion, you'll need code in the kernel for handling page tables. If some of the functions can be helpful in setting up the kernel mappings, it might avoid some code-duplication to have all the kernel's memory-layout related stuff in the kernel proper.

    And if you want to reuse (and/or not step on) the actual PTEs from the bootloader, the kernel would have to find them by walking from CR3, vs. knowing where it put them itself.