Implement physical memory allocator with zone support (AI)
- Added bitmap-based physical memory manager (PMM) that parses the Multiboot2 memory map to discover available RAM regions. - Supports two allocation zones: PMM_ZONE_DMA (below 16MB) and PMM_ZONE_NORMAL (above 16MB), with automatic fallback from NORMAL to DMA when the preferred zone is exhausted. - Marks kernel memory region and multiboot info structure as reserved using _kernel_start/_kernel_end linker symbols. - Page 0 is always marked as used to prevent returning NULL as a valid address. - Added linker script symbols (_kernel_start, _kernel_end) to track kernel memory boundaries for the allocator. - Kernel now initializes PMM after PIC and performs test allocations to verify the subsystem works.
This commit is contained in:
12
src/kernel.c
12
src/kernel.c
@@ -5,6 +5,7 @@
|
||||
#include "idt.h"
|
||||
#include "pic.h"
|
||||
#include "port_io.h"
|
||||
#include "pmm.h"
|
||||
|
||||
void offset_print(const char *str)
|
||||
{
|
||||
@@ -46,6 +47,17 @@ void kernel_main(uint32_t magic, uint32_t addr) {
|
||||
|
||||
init_pic();
|
||||
offset_print("PIC initialized\n");
|
||||
|
||||
init_pmm(addr);
|
||||
offset_print("PMM initialized\n");
|
||||
|
||||
phys_addr_t p1 = pmm_alloc_page(PMM_ZONE_NORMAL);
|
||||
offset_print("Allocated page at: ");
|
||||
print_hex(p1);
|
||||
|
||||
phys_addr_t p2 = pmm_alloc_page(PMM_ZONE_DMA);
|
||||
offset_print("Allocated DMA page at: ");
|
||||
print_hex(p2);
|
||||
|
||||
/* Enable interrupts */
|
||||
asm volatile("sti");
|
||||
|
||||
Reference in New Issue
Block a user