idk we're trying out pmm

This commit is contained in:
2025-06-11 17:33:42 -04:00
parent 03aecd514f
commit f216c32f22
6 changed files with 104 additions and 86 deletions

View File

@ -12,6 +12,7 @@
#include <kernel/x86/keyb.h>
#include <kernel/x86/pit.h>
#include <kernel/x86/pci.h>
#include <kernel/pmm.h>
#include "multiboot.h"
@ -19,44 +20,32 @@ void verify_memmap(multiboot_info_t* mbd, uint32_t magic)
{
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
panic("Invalid magic number!");
else
printf("%2\n", magic);
if (!(mbd->flags >> 6 & 0x1))
panic("Invalid memory map given by GRUB bootloader!");
#ifdef __TESTING__
if (!(mbd->flags & (1 << 0)))
panic("Memory info not passed to kernel!");
puts("Printing available memory map...");
uint32_t i;
for (i = 0; i < mbd->mmap_length; i += sizeof(multiboot_memory_map_t)) {
multiboot_memory_map_t* mmmt = (multiboot_memory_map_t*) (mbd->mmap_addr + i);
printf("Start Addr: %4 | Length: %4 | Size: %2 | Type: ",
mmmt->addr, mmmt->len, mmmt->size);
switch (mmmt->type) {
case MULTIBOOT_MEMORY_AVAILABLE:
puts("Available");
break;
case MULTIBOOT_MEMORY_RESERVED:
puts("Reserved");
break;
case MULTIBOOT_MEMORY_ACPI_RECLAIMABLE:
puts("ACPI Reclaimable");
break;
case MULTIBOOT_MEMORY_NVS:
puts("NVS");
break;
case MULTIBOOT_MEMORY_BADRAM:
puts("Bad ram");
break;
default:
puts("Unknown");
break;
}
printf("Start Addr: %4 | Length: %4 | Size: %2 | Type: %d\n",
mmmt->addr, mmmt->len, mmmt->size, mmmt->type);
// if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) -> DO SOMETHING
// mmmt-> len is in bytes (according to multiboot specification0
// mmmt->len / 1024 == kib // block size == blocks
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE && (mmmt->addr == 0x100000)) {
// This is the main mem address we want
// TODO: this is probably flaky, so i want to find a better and more reliable way to do this
set_grub_mem_map(mmmt->addr, mmmt->len);
}
}
#endif
printf("%2 %2\n", mbd->mem_lower, mbd->mem_upper);
}
void _main(multiboot_info_t* mbd, uint32_t magic)
@ -65,6 +54,7 @@ void _main(multiboot_info_t* mbd, uint32_t magic)
terminal_initialize();
serial_initialize();
#endif
printf("%2, %2\n", mbd->mem_lower, mbd->mem_upper);
verify_memmap(mbd, magic);
@ -76,7 +66,7 @@ void _main(multiboot_info_t* mbd, uint32_t magic)
serial_initialize();
#endif
setup_paging();
//setup_paging();
init_kb();