From 4337bc11c8de4f14126fb2017e856a458ea12509 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Mon, 21 Oct 2024 13:36:42 +0200 Subject: [PATCH] wip: debug memory pages persistency --- src/kernel.c | 24 +++++++++++++++++++----- src/kpanic.c | 2 +- src/memory/memory.c | 2 +- src/memory/page.c | 2 +- src/memory/virt/vmalloc.c | 4 ++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/kernel.c b/src/kernel.c index 9fecc03..29d6766 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,4 +1,5 @@ #include "alloc.h" +#include "debug.h" #include "drivers.h" #include "gdt.h" #include "idt.h" @@ -35,10 +36,23 @@ void kernel_main(void) "I see no way to confuse an array of 256 seg:off pairs with a " "complex 8*unknown quantity -byte descriptor table. -- Troy " "Martin 03:50, 22 March 2009 (UTC)\n"); - /* kprintf("%p\n", vmalloc(10)); */ - int i = 0; - while (vmalloc(10)) - if (i++ > 11000) - kprintf("%d\n", i++); + /* char *str = vmalloc(10); */ + /* strcpy(str, "hello"); */ + /* int i = 0; */ + /* while (vmalloc(10)) */ + /* if (i++ > 11000) */ + /* kprintf("str: %s at %d\n", str, i); */ + void *tab[1024]; + for (int i = 0; i < 1024; i++) { + tab[i] = alloc_pages(1); + /* PRINT_INT(i); */ + /* PRINT_PTR(tab[i]); */ + if (tab[i]) + memset(tab[i], i, 4096); + } + /* PRINT_UINT(((uint8_t *)tab[0])[0]); */ + for (int i = 0; i < 10; i++) + PRINT_PTR(tab[i]); + /* PRINT_UINT(((uint8_t *)tab[i])[0]); */ shell_init(); } diff --git a/src/kpanic.c b/src/kpanic.c index b5c8024..276f296 100644 --- a/src/kpanic.c +++ b/src/kpanic.c @@ -22,7 +22,7 @@ void kpanic(const char *format, ...) kprintf("fault at address: %p\n", faulting_address); /* for (int i = 16; i < 32; i++) */ /* kprintf("%p\n", page_table1[i]); */ - show_valloc_mem(); + /* show_valloc_mem(); */ /* kprintf("\n\n"); */ /* print_stack(); */ /* kprintf("\n\n"); */ diff --git a/src/memory/memory.c b/src/memory/memory.c index 9a4fe0f..c035774 100644 --- a/src/memory/memory.c +++ b/src/memory/memory.c @@ -16,5 +16,5 @@ void init_memory(void) page_directory[i] = 0x02; for (int16_t i = 0; i < 1024; i++) page_table1[i] = (i << 12) | 0x03; - page_directory[0] = ((uint32_t)page_table1 - HEAP_END) | 0x03; + page_directory[342] = ((uint32_t)page_table1 - HEAP_END) | 0x03; } diff --git a/src/memory/page.c b/src/memory/page.c index 4a78ee3..c2138ad 100644 --- a/src/memory/page.c +++ b/src/memory/page.c @@ -46,7 +46,7 @@ void *alloc_pages(size_t size) /* assert(page_table1[i] >> 12 == i); */ page_table1[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS; } - PRINT_PTR(page_table1[index]); + /* PRINT_PTR(page_table1[index]); */ return (void *)(index * PAGE_SIZE); } diff --git a/src/memory/virt/vmalloc.c b/src/memory/virt/vmalloc.c index c78ced7..dce5352 100644 --- a/src/memory/virt/vmalloc.c +++ b/src/memory/virt/vmalloc.c @@ -17,8 +17,8 @@ static Block *find_block(Zone *head, uint32_t size) block_it = block_it->next_free) { assert(block_it); if (block_it->in_use) { - PRINT_PTR(block_it); - PRINT_PTR(block_it->zone); + /* PRINT_PTR(block_it); */ + /* PRINT_PTR(block_it->zone); */ } assert(!block_it->in_use); if (size <= block_it->size) {