|
Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
|
Physical page allocator for managing system memory blocks. More...
#include "mem_layout/mem_layout.h"#include "page_table/page_table.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>

Go to the source code of this file.
Macros | |
| #define | PHYS_ADDR_NULL ((phy_addr)NULL) |
| A null physical address value. | |
Functions | |
| bool | page_allocator_add_region (phy_addr mem_start, size_t mem_size, bool check_kernel_overlap) |
| Registers a new physical memory region with the allocator. | |
| bool | page_allocator_remove_region (phy_addr mem_start) |
| Removes a previously registered memory region. | |
| void | fixup_page_allocator (void) |
| Rewrites allocator bitmap pointers after the switch to high virtual addresses. | |
| bool | reserve_page (phy_addr start, size_t num_pages) |
| Reserves a specific number of contiguous pages. | |
| phy_addr | page_alloc (size_t num_pages) |
| Allocates a contiguous block of physical pages. | |
| void | page_free (phy_addr start, size_t num_pages) |
| Frees a previously allocated block of physical pages. | |
| void | page_dump_status (void) |
| Scans the bitmap and prints the status of all memory regions. | |
Physical page allocator for managing system memory blocks.
This module handles allocation and deallocation of fixed-size 4 KiB pages, tracks page usage with a bitmap, and exposes the kernel page allocator API.
| phy_addr page_alloc | ( | size_t | num_pages | ) |
Allocates a contiguous block of physical pages.
Searches for a free span of memory large enough to hold num_pages.
| num_pages | The number of contiguous 4 KiB pages requested. |
| bool page_allocator_add_region | ( | phy_addr | mem_start, |
| size_t | mem_size, | ||
| bool | check_kernel_overlap | ||
| ) |
Registers a new physical memory region with the allocator.
Initializes a new memory chunk for the range starting at mem_start and spanning mem_size bytes. If check_kernel_overlap is true, the region is rejected when it overlaps the kernel image.
| mem_start | The physical address of the beginning of the region. |
| mem_size | Total size of the region, in bytes. |
| check_kernel_overlap | Whether to reject regions that overlap with the kernel image. |
| bool page_allocator_remove_region | ( | phy_addr | mem_start | ) |
Removes a previously registered memory region.
Marks the region that starts at mem_start as no longer managed by the allocator.
| mem_start | The physical base address of the region to remove. |
| void page_dump_status | ( | void | ) |
Scans the bitmap and prints the status of all memory regions.
Iterates through the managed page pool and groups contiguous pages with the same status (FREE or USED) into blocks for concise UART output.
| void page_free | ( | phy_addr | start, |
| size_t | num_pages | ||
| ) |
Frees a previously allocated block of physical pages.
Marks the specified range of pages as available for future allocations.
| start | The physical address of the first page to free. |
| num_pages | The number of contiguous pages to release. |
| bool reserve_page | ( | phy_addr | start, |
| size_t | num_pages | ||
| ) |
Reserves a specific number of contiguous pages.
Marks the specified range of pages as reserved.
| start | The physical address of the first page to reserve. |
| num_pages | The number of contiguous pages to reserve. |