From 20ba985b3482e7156207328e31f00bc455585901 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Fri, 15 Nov 2024 13:35:48 +0100 Subject: [PATCH] fix: able to read multiboot mmap --- headers/memory.h | 2 +- src/kpanic.c | 3 --- src/memory/frame.c | 17 +++++------------ src/memory/memory.c | 10 +++++----- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/headers/memory.h b/headers/memory.h index 281d611..58e822f 100644 --- a/headers/memory.h +++ b/headers/memory.h @@ -26,7 +26,7 @@ extern uint32_t boot_page_directory; extern uint32_t *page_directory; extern uint32_t page_table_default[1024]; extern uint32_t mem_size; -extern multiboot_uint32_t *mmap_addr; +extern multiboot_memory_map_t *mmap_addr; extern multiboot_uint32_t mmap_length; uint32_t *virt_to_phys(uint32_t *virt_addr); diff --git a/src/kpanic.c b/src/kpanic.c index 276f296..d7aed05 100644 --- a/src/kpanic.c +++ b/src/kpanic.c @@ -17,9 +17,6 @@ void kpanic(const char *format, ...) va_start(va, format); kvprintf(format, &va); va_end(va); - uint32_t faulting_address; - __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address)); - kprintf("fault at address: %p\n", faulting_address); /* for (int i = 16; i < 32; i++) */ /* kprintf("%p\n", page_table1[i]); */ /* show_valloc_mem(); */ diff --git a/src/memory/frame.c b/src/memory/frame.c index 4fc94ae..98a85fc 100644 --- a/src/memory/frame.c +++ b/src/memory/frame.c @@ -5,27 +5,20 @@ #include "debug.h" #include "kprintf.h" #include "memory.h" +#include "string.h" #include "utils.h" void *alloc_frames(size_t size) { const uint32_t nb_frames = CEIL(size, PAGE_SIZE); - /* PRINT_PTR(((multiboot_memory_map_t *)mmap_addr)->addr); */ - /* PRINT_UINT(((multiboot_memory_map_t *)mmap_addr)->len); */ - /* PRINT_UINT(((multiboot_memory_map_t *)mmap_addr)->type); */ - for (uint32_t i = 0; i < mmap_length; - i += sizeof(multiboot_memory_map_t)) { + for (uint32_t i = 0; i < mmap_length; i++) { multiboot_memory_map_t *mmmt = - (multiboot_memory_map_t *)(mmap_addr + i); + (multiboot_memory_map_t *)mmap_addr + i; if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) { + kprintf("type: %d, addr: %p, len: %u, size: %u, \n", + mmmt->type, mmmt->addr, mmmt->len, mmmt->size); } - PRINT_UINT(mmmt->len); - /* kprintf("[%d] available %p: %u bytes\n", i, mmmt->addr, */ - /* mmmt->len); */ - /* PRINT_UINT(mmmt->type); */ } - /* for (size_t i = 0; i < mmap_length; i++) { */ - /* } */ return NULL; } diff --git a/src/memory/memory.c b/src/memory/memory.c index 1fd7268..ff053b1 100644 --- a/src/memory/memory.c +++ b/src/memory/memory.c @@ -9,7 +9,7 @@ uint32_t *page_directory = &boot_page_directory; uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t mem_size; -multiboot_uint32_t *mmap_addr; +multiboot_memory_map_t *mmap_addr; multiboot_uint32_t mmap_length; static void init_multiboot(multiboot_info_t *mbd, uint32_t magic) @@ -36,10 +36,10 @@ static void init_multiboot(multiboot_info_t *mbd, uint32_t magic) multiboot_page_table[i + mbd_size] = ((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) | INIT_FLAGS; - mmap_addr = - (multiboot_uint32_t *)(GET_PAGE_ADDR(1023, mbd_size) + - (uint32_t)mbd_virt->mmap_addr % PAGE_SIZE); - mmap_length = mbd_virt->mmap_length; + mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, mbd_size) + + (uint32_t)mbd_virt->mmap_addr % + PAGE_SIZE); + mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t); } void init_memory(multiboot_info_t *mbd, uint32_t magic)