cleans up a bit, adds a pmm panic

This commit is contained in:
2025-06-13 12:58:50 -04:00
parent af596cd43a
commit 99a842df7e
2 changed files with 14 additions and 6 deletions

View File

@ -2,10 +2,7 @@
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#ifdef __TESTING__
#include <stdio.h>
#endif
#include <kernel/_kernel.h>
#include <kernel/pmm.h>
@ -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);
}

View File

@ -37,6 +37,10 @@ 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();