Skip to content

Kernel loading into higher half memory - #2

Merged
Daniel-De-Dev merged 4 commits into
mainfrom
feat/virtual-memory-kernel
Sep 20, 2026
Merged

Daniel-De-Dev merged 4 commits into
mainfrom
feat/virtual-memory-kernel

Conversation

@Daniel-De-Dev

Copy link
Copy Markdown
Owner

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 _start but in higher address space and only then jumps to main which 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.

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.
@Daniel-De-Dev
Daniel-De-Dev merged commit a4e7768 into main Sep 20, 2026
1 check passed
@Daniel-De-Dev
Daniel-De-Dev deleted the feat/virtual-memory-kernel branch September 20, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant