mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
pmm: properly initialize bootloader reclaimable entries
Co-authored-by: Matheus <matheusuky@gmail.com>
This commit is contained in:
+10
-2
@@ -213,6 +213,7 @@ void *pmm_allocpage(int section) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pmm_makefree(void *address, size_t count) {
|
void pmm_makefree(void *address, size_t count) {
|
||||||
|
MUTEX_ACQUIRE(&freelistmutex);
|
||||||
memorysize += PAGE_SIZE * count;
|
memorysize += PAGE_SIZE * count;
|
||||||
__assert(((uintptr_t)address % PAGE_SIZE) == 0);
|
__assert(((uintptr_t)address % PAGE_SIZE) == 0);
|
||||||
uintmax_t baseid = (uintptr_t)address / PAGE_SIZE;
|
uintmax_t baseid = (uintptr_t)address / PAGE_SIZE;
|
||||||
@@ -220,8 +221,10 @@ void pmm_makefree(void *address, size_t count) {
|
|||||||
uintmax_t pageid = baseid + i;
|
uintmax_t pageid = baseid + i;
|
||||||
PAGE_BOUNDARYCHECK(pageid);
|
PAGE_BOUNDARYCHECK(pageid);
|
||||||
page_t *page = &pages[pageid];
|
page_t *page = &pages[pageid];
|
||||||
|
page->flags |= PAGE_FLAGS_FREE;
|
||||||
insertinfreelist(page);
|
insertinfreelist(page);
|
||||||
}
|
}
|
||||||
|
MUTEX_RELEASE(&freelistmutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pmm_init() {
|
void pmm_init() {
|
||||||
@@ -253,7 +256,7 @@ void pmm_init() {
|
|||||||
memset(pages, 0, pagecount * sizeof(page_t));
|
memset(pages, 0, pagecount * sizeof(page_t));
|
||||||
printf("pmm: %d pages used for page list\n", ROUND_UP(pagecount * sizeof(page_t), PAGE_SIZE) / PAGE_SIZE);
|
printf("pmm: %d pages used for page list\n", ROUND_UP(pagecount * sizeof(page_t), PAGE_SIZE) / PAGE_SIZE);
|
||||||
|
|
||||||
// place pages in free lists
|
// initialize usable memory
|
||||||
for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) {
|
for (size_t i = 0; i < pmm_liminemap.response->entry_count; ++i) {
|
||||||
struct limine_memmap_entry *e = pmm_liminemap.response->entries[i];
|
struct limine_memmap_entry *e = pmm_liminemap.response->entries[i];
|
||||||
if (e->type == LIMINE_MEMMAP_USABLE) {
|
if (e->type == LIMINE_MEMMAP_USABLE) {
|
||||||
@@ -262,6 +265,11 @@ void pmm_init() {
|
|||||||
pages[i].flags |= PAGE_FLAGS_FREE;
|
pages[i].flags |= PAGE_FLAGS_FREE;
|
||||||
insertinfreelist(&pages[i]);
|
insertinfreelist(&pages[i]);
|
||||||
}
|
}
|
||||||
|
} else if (e->type == LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE) {
|
||||||
|
for (int i = 0; i < e->length / PAGE_SIZE; ++i) {
|
||||||
|
page_t *page = &pages[(e->base / PAGE_SIZE) + i];
|
||||||
|
page->refcount = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,6 +331,6 @@ void pmm_free(void *addr, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pmm_getinfo(size_t *total_pages, size_t *free_pages) {
|
void pmm_getinfo(size_t *total_pages, size_t *free_pages) {
|
||||||
*total_pages = pagecount;
|
*total_pages = memorysize / PAGE_SIZE;
|
||||||
*free_pages = freepagecount;
|
*free_pages = freepagecount;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user