Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces foundational memory-management infrastructure for the PrismOS kernel by adding a bitmap-based Physical Memory Manager (PMM) and an early identity-mapped paging implementation, plus an extensible CPU exception handler registration path (used for early page-fault handling). It also updates the build and linker script to integrate these new subsystems and export kernel boundary symbols.
Changes:
- Added
pmm(bitmap-based physical page allocator) with Multiboot2 mmap parsing and region reservations. - Added early x86 paging with identity mapping, basic map/unmap/query helpers, and page-fault handler registration.
- Extended IRQ/ISR handling to support per-exception (vectors 0–31) handler registration and dispatch.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/io.h | Adds CR0/CR2/CR3 accessors and invlpg for paging control. |
| src/memory/pmm.h | Declares PMM API and stats structure. |
| src/memory/pmm.c | Implements bitmap PMM init/allocation/free and region reservations. |
| src/memory/paging.h | Declares early paging API and flags. |
| src/memory/paging.c | Implements identity-mapped paging, page table provisioning, and page-fault handler hook. |
| src/kernel.c | Wires PMM + paging initialization into kernel startup. |
| src/interrupts/irq.h | Adds exception handler typedef + registration API. |
| src/interrupts/irq.c | Implements exception handler table and dispatch in isr_handler. |
| Makefile | Builds/links PMM and paging objects into the kernel image. |
| boot/linker.ld | Exports __kernel_start/__kernel_end symbols for memory reservations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+153
to
158
| pmm_init(boot_info, &framebuffer); | ||
| paging_init(&framebuffer); | ||
|
|
||
| // Shell startup marks readiness for user commands. | ||
| DEBUG_LOG("starting shell loop"); | ||
| interrupts_init(); |
Comment on lines
+82
to
+94
| uint32_t start = align_down(start_addr, PAGE_SIZE); | ||
| uint32_t end = align_up(end_addr, PAGE_SIZE); | ||
|
|
||
| if (end <= start) { | ||
| return; | ||
| } | ||
|
|
||
| uint32_t start_page = start / PAGE_SIZE; | ||
| uint32_t end_page = end / PAGE_SIZE; | ||
|
|
||
| if (end_page > MAX_PAGES) { | ||
| end_page = MAX_PAGES; | ||
| } |
Comment on lines
+121
to
+130
| uint32_t start = align_up((uint32_t)start_addr, PAGE_SIZE); | ||
| uint32_t end = align_down((uint32_t)end_addr, PAGE_SIZE); | ||
|
|
||
| if (end <= start) { | ||
| return; | ||
| } | ||
|
|
||
| uint32_t start_page = start / PAGE_SIZE; | ||
| uint32_t end_page = end / PAGE_SIZE; | ||
|
|
Comment on lines
+229
to
+233
| if (fb_end64 > ((uint64_t)MAX_PHYS_ADDR + 1ULL)) { | ||
| fb_end64 = (uint64_t)MAX_PHYS_ADDR + 1ULL; | ||
| } | ||
| reserve_range((uint32_t)fb_start64, (uint32_t)fb_end64); | ||
| } |
Comment on lines
+243
to
+249
| pmm_stats.total_memory_bytes = (uint32_t)highest_phys; | ||
| pmm_stats.total_pages = pmm_stats.total_memory_bytes / PAGE_SIZE; | ||
| pmm_stats.used_pages = pmm_stats.total_pages - pmm_stats.free_pages; | ||
| pmm_stats.usable_memory_bytes = pmm_stats.free_pages * PAGE_SIZE; | ||
| pmm_stats.reserved_memory_bytes = (pmm_stats.total_pages - pmm_stats.free_pages) * PAGE_SIZE; | ||
|
|
||
| PRISMOS_TOTAL_MEMORY_KB = pmm_stats.total_memory_bytes / 1024U; |
Comment on lines
+147
to
+152
| if (fb_start64 <= 0xFFFFFFFFULL) { | ||
| if (fb_end64 > 0x100000000ULL) { | ||
| fb_end64 = 0x100000000ULL; | ||
| } | ||
| map_identity_range((uint32_t)fb_start64, (uint32_t)fb_end64, PAGING_FLAG_READ_WRITE); | ||
| } |
Collaborator
Author
|
@Retr0Aa are you going to review it?? |
Owner
|
@gogo1701 sybau |
Collaborator
Author
|
no @Retr0Aa |
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.
This pull request introduces a physical memory manager (PMM) and an early paging system to the kernel, enabling dynamic page allocation and virtual memory support. It also adds an extensible CPU exception handler mechanism, including robust page fault handling. These features lay the groundwork for more advanced memory management and safer kernel operation.
The most important changes are:
Memory Management (Physical and Virtual):
src/memory/pmm.candsrc/memory/pmm.himplementing a bitmap-based physical memory manager, with initialization from Multiboot2 memory maps, page allocation/freeing, and memory statistics reporting. The PMM reserves critical regions (kernel, boot info, framebuffer, low memory) and exposes an API for page management. ([[1]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-3838634d348124540a02b93da090d0db55ad8668858d2798254a8c267e5cd25fR1-R363),[[2]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-21ba94371f3f6f20ba6dc03979c9841932346d95e7b2f29e52c51ce5f514a7e4R1-R31))src/memory/paging.candsrc/memory/paging.himplementing early x86 paging with identity mapping for bootstrapping, dynamic page table management, and functions for mapping/unmapping pages and querying physical addresses. Paging is enabled during kernel initialization. ([[1]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-3bf621908b857940f2ec9c1b9ede9a6d2d6f7cb9ec088174f8edd2a0020d5291R1-R166),[[2]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-fe9c547c895abaa43d9c3c2d9d778dc772c377591c822bd57f96ce360e075bf7R1-R26))src/kernel.c, ensuring the memory subsystems are ready before enabling interrupts and launching the shell. ([[1]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-1d7a8ae32f442a56c39d6b501d9c5d0383d531f2a39cd177e6b890a57b175da4R10-R11),[[2]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-1d7a8ae32f442a56c39d6b501d9c5d0383d531f2a39cd177e6b890a57b175da4R153-R155))CPU Exception Handling:
[[1]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-2ac966076011ae0ff50d6698ce04e1e1e7c878dc4693665aed69710bd03d8a4fR9-R23),[[2]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-2ac966076011ae0ff50d6698ce04e1e1e7c878dc4693665aed69710bd03d8a4fR42-R55),[[3]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-2ac966076011ae0ff50d6698ce04e1e1e7c878dc4693665aed69710bd03d8a4fR75-R79),[[4]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-8b94c978c19f4bdd92cc552b56bde06b10a2f27e9daae386a40636440db37b83R26),[[5]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-8b94c978c19f4bdd92cc552b56bde06b10a2f27e9daae386a40636440db37b83R39-R42))[src/memory/paging.cR1-R166](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-3bf621908b857940f2ec9c1b9ede9a6d2d6f7cb9ec088174f8edd2a0020d5291R1-R166))Build System and Linker Support:
Makefileto build and link the new PMM and paging modules into the kernel image. ([MakefileR72-R82](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R72-R82))boot/linker.ldto export__kernel_startand__kernel_endsymbols, allowing the memory manager to reserve the kernel image in physical memory. ([[1]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-c8386fa8574eaea80121d2867e817e0e2952fa738dd4256803f6e57977385dc9R5-R6),[[2]](https://github.com/Retr0Aa/PrismOS/pull/10/files#diff-c8386fa8574eaea80121d2867e817e0e2952fa738dd4256803f6e57977385dc9R17-R18))These changes collectively provide the kernel with foundational memory management capabilities and safer exception handling, preparing it for more advanced features and improved robustness.