fix: able to read multiboot mmap

This commit is contained in:
Starnakin 2024-11-15 13:35:48 +01:00
parent 09ea386b21
commit 20ba985b34
4 changed files with 11 additions and 21 deletions

View File

@ -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);

View File

@ -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(); */

View File

@ -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;
}

View File

@ -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)