From 99a842df7e21f3378725d98479bbe54f617dd4c3 Mon Sep 17 00:00:00 2001 From: Nathan Singer Date: Fri, 13 Jun 2025 12:58:50 -0400 Subject: [PATCH] cleans up a bit, adds a pmm panic --- kernel/arch/pmm/pmm.c | 13 ++++++++----- kernel/kmain.c | 7 ++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kernel/arch/pmm/pmm.c b/kernel/arch/pmm/pmm.c index 0e7df18..84f592c 100644 --- a/kernel/arch/pmm/pmm.c +++ b/kernel/arch/pmm/pmm.c @@ -2,10 +2,7 @@ #include #include #include - -#ifdef __TESTING__ #include -#endif #include #include @@ -50,6 +47,12 @@ void pmm_init(void); void* pmm_alloc_block(void); void pmm_free_block(void* p); +void pmm_panic(const char* str) +{ + printf("PMM: "); + panic(str); +} + void __pmm_set(uint32_t bit, struct pmm_mem_info* mem_block) { (mem_block->bitmap)[bit / 32] |= (1 << (bit % 32)); @@ -131,10 +134,10 @@ void __pmm_free_block(void* p, struct pmm_mem_info* mem_block) // TODO this might still be a little flaky // should we be able to free any pointer? or just ones that we've given out? if (idx == 0) - panic("Trying to free reserved memory!"); + pmm_panic("Trying to free reserved memory!"); if (pmm_test(idx) == 0) - panic("Trying to free a block that was already free!"); + pmm_panic("Trying to free a block that was already free!"); __pmm_unset(idx, mem_block); } diff --git a/kernel/kmain.c b/kernel/kmain.c index f3f69b7..443b046 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -36,7 +36,11 @@ void verify_memmap(multiboot_info_t* mbd, uint32_t magic) printf("Start Addr: %4 | Length: %4 | Size: %2 | Type: %d\n", mmmt->addr, mmmt->len, mmmt->size, mmmt->type); - + + // This is pretty flaky, we want to actually create a linked list, + // where each block of available memory gets its own mem_block + // not just this main one + // TODO if (mmmt->addr == 0x100000) { pmm_add_mem_block((uint32_t) mmmt->addr, (uint32_t) mmmt->len); } @@ -68,6 +72,7 @@ void _main(multiboot_info_t* mbd, uint32_t magic) print_main_mem(); + pmm_free_block(a); pmm_free_block(a); print_main_mem();