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:
36
src/pmm.h
Normal file
36
src/pmm.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef PMM_H
|
||||
#define PMM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
typedef uintptr_t phys_addr_t;
|
||||
|
||||
typedef enum {
|
||||
PMM_ZONE_DMA, // < 16 MB
|
||||
PMM_ZONE_NORMAL, // Any other memory
|
||||
PMM_ZONE_HIGHMEM // > 4 GB (if 64-bit or PAE, but we are 32-bit for now) - actually sticking to DMA and NORMAL is enough for 32-bit typically
|
||||
} pmm_zone_t;
|
||||
|
||||
/*
|
||||
* Initialize the physical memory manager.
|
||||
* @param multiboot_addr Address of the multiboot info structure
|
||||
*/
|
||||
void init_pmm(uint32_t multiboot_addr);
|
||||
|
||||
/*
|
||||
* Allocate a physical page.
|
||||
* @param zone The preferred zone to allocate from.
|
||||
* @return Physical address of the allocated page, or 0 if out of memory.
|
||||
*/
|
||||
phys_addr_t pmm_alloc_page(pmm_zone_t zone);
|
||||
|
||||
/*
|
||||
* Free a physical page.
|
||||
* @param addr Physical address of the page to free.
|
||||
*/
|
||||
void pmm_free_page(phys_addr_t addr);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user