#include "hal/obj.h" #include "limine.h" #include "hal/memory.h" #include "hal/obj.h" #include "lib/panic.h" #include "init.h" #include "lib/printf.h" extern struct limine_memmap_response *_limine_memmap_resp; static jove_objdir_t s_untyped_objdir; #define MEMMAP_MAX_ENTRIES 255 static const char *limine_mmap_entry_type_str[9] = { "USABLE", "RESERVED", "ACPI RECLAIMABLE", "ACPI NVS", "BAD", "LIMINE RECLAIMABLE", "KERNEL", "FRAMEBUFFER", "ACPI TABLES" }; void mem_setup_untyped(void) { { jove_owned_obj_t *untyped_objdir_obj = obj_take(objdir_getlocal(_rootdir_obj, ROOTDIR_UNTYPED_I)); obj_settype(untyped_objdir_obj, JOVE_OBJ_OBJDIR); obj_setvalue(untyped_objdir_obj, (uintptr_t)&s_untyped_objdir); obj_release(untyped_objdir_obj); } if(_limine_memmap_resp == NULL) { kpanic("Limine failed to provide memory map.\n"); } kprintf("Memory map provided by Limine:\n"); size_t untyped_i = 0; uintptr_t highest_phys = 0; for(size_t i = 0; i < _limine_memmap_resp->entry_count; i++) { struct limine_memmap_entry *entry = _limine_memmap_resp->entries[i]; kprintf("Limine: %p : %p %s\n", entry->base, entry->length, limine_mmap_entry_type_str[entry->type]); if(entry->type == LIMINE_MEMMAP_USABLE || entry->type == LIMINE_MEMMAP_ACPI_RECLAIMABLE || entry->type == LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE) { if(entry->base == 0) continue; if(entry->base + entry->length > highest_phys) highest_phys = entry->base + entry->length; { jove_owned_obj_t *untyped_obj = obj_take(&s_untyped_objdir.entries[untyped_i++]); obj_settype(untyped_obj, JOVE_OBJ_UNTYPED); obj_setvalue(untyped_obj, entry->base); jove_untyped_t *untyped_data = obj_deref(untyped_obj); untyped_data->limit = entry->length; obj_release(untyped_obj); } if(untyped_i > MEMMAP_MAX_ENTRIES){ kprintf("!!!Provided memory map exceeds kernel limits. Some memory may not be accessable!!!"); break; } } } kprintf("Highest physical address: %p\n", highest_phys); }