Skip to content

Feat/granular paging - #3

Merged
Daniel-De-Dev merged 9 commits into
mainfrom
feat/granular-paging
Oct 6, 2026
Merged

Daniel-De-Dev merged 9 commits into
mainfrom
feat/granular-paging

Conversation

@Daniel-De-Dev

Copy link
Copy Markdown
Owner

Implemented the transition from the intial bootstrap paging to something more alike how the kernel will be operating normally.

Builds the intial kernel page mappings where kernel can no longer use identity mappings. And also locks down the permissions for the kernels sections and also makes the fdt mapped too so it remains accessible.

At this point kernel has fully transitioned to virtual memory and can start with potentially work towards having an actual user program running in lower memory.

Since the frame allocator will return addresses for physical memory, a
helper is added so the kernel can later temporary make a physical address
mapped/accessible. (It's mapped to the last possible gigapage on the higher half
virtual address space), then performs the operation that is provided.
Implemented a way to have a virtual address mapped to a physical frame.
The method will deal with allocating and writing the page table entries
and allocate tables when necessary.

When needing to write to the physical memory for the physical page
tables, the with_bootstrap_frame is used to have that table mapped and
actually accessible.
Added helpers that allow for easily read and write to *mapped* frames,
but they are unsafe due to invariants which cannot be proved. Will work
on restructuring the setup so invariant can better be encoded via types.

A clear distinction needs to be put in place between when page
operations are occurring at the start or when later normal kernel
operations. Otherwise, future implementations will needs constantly use
unsafe guards.
…y in types

This is done to avoid relying on implicit global assumptions.

Add `AllocatedFrame` to better encode exclusive ownership of a physical
frame and that the owner is free to use the underlying memory. The frame
allocator now returns this type.

Define `BootstrapPaging` to represent the initial paging stage, where the
kernel relies on assumptions about the existing page table and its
accessibility.
Some functions don't make sense to allow to have called multiple times.
Like the bootstrap paging and allocator initialization. Hence, added
global bools that only allow them to succeed once and then fail
otherwise. This will prevent from initializing 2 instances when only 1 is
supposed to be allowed to exist.
Added also VirtRange (counterpart of PhysRange, essentially copy paste).
Added a wrapper around map_page that now will allow to map a range of
memory instead.
Explicitly defined a transition from the bootstrap paging that worked
using mostly using gigapages, to now removing identity mappings and
using granular 4KiB pages with appropriate permissions.
@Daniel-De-Dev
Daniel-De-Dev merged commit 053ec59 into main Oct 6, 2026
@Daniel-De-Dev
Daniel-De-Dev deleted the feat/granular-paging branch October 6, 2026 15:02
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