Kernel loading into higher half memory - #2
Merged
Merged
Conversation
Restructured the linker to have a new boot section and start using virtual memory for the main sections of the kernel, while boot section uses physical memory. Idea is to have a baked in bootstrap page embedded into the kernel binary, which will be used to initially start virtual memory.
The kernels entry has been refactored to now switch the kernel to high half virtual address, and sets up a single gigapage leaf that adds the mapping. And the identity mapping and the dtb (if it happens to lie in a different gigapage)
The reason for adding the extra argument for main is that high-half compiled code cannot conveniently form the address of a linker symbol whose value lives extremely far away in the low physical address range. Updated and rewrote relevant function and docs for getting the kernels physical memory range.
Made documentation more consistent and reflect the new changes added which i missed earlier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Made the kernel now boot into main such that it already is in higher half virtual memory.
Achieved my reconfiguing the linker (and readjusting the compile "recipie")
Having the produced binary be such that there is "boot" part that is configured to be loaded and run on physical memory, set by the nix configuration. It's responsbile for setting a "gigapage" (a Sv39 root leaf mappings). That maps higher half address and identity maps the physical addresses intially to survive the switch.
Once mapping is active it jumps to that used to be the old
_startbut in higher address space and only then jumps tomainwhich enter fully in virtual space. Point is this internal root page is baked into the binary to avoid the problem reagrding needing fdt to discover memory.