diff --git a/src/kernel.c b/src/kernel.c index 511ef35..5800678 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -55,6 +55,21 @@ static void set_mem_size(multiboot_info_t *mbd, uint32_t magic) } } +extern uint32_t boot_page_table1; + +void get_kernel_page_used(void) +{ + uint32_t *boot_pt = &boot_page_table1; + size_t i = 0; + size_t used_pages = 0; + for (; i < 1024; i++) { + if ((boot_pt[i] != 0) && (boot_pt[i] != (i << 12))) { + used_pages++; + } + } + kprintf("page used: %d/%d\n", used_pages, PT_SIZE); +} + void kernel_main(multiboot_info_t *mbd, uint32_t magic) { terminal_initialize(); @@ -66,28 +81,25 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic) "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"); - // PRINT_PTR(alloc_frame()); - if (true) { + if (false) { void *start = alloc_pages(1); int *ptr; uint32_t i; for (i = 1; (ptr = alloc_pages(PAGE_SIZE)); i++) { - memset(ptr, ~0, PAGE_SIZE); + memset(ptr, i % 256, PAGE_SIZE); *ptr = i; - if (i == 4096 && false) + if (i == 4096 && 0) break; } PRINT_UINT(i); // 32573 - uint16_t bozo = 0; for (uint32_t j = 1; j < i - 1; j++) { ptr = start + j * PAGE_SIZE; - kprintf("j=%d %p: %d\n", j, ptr, *ptr); - if (*ptr != j) { - bozo++; - if (bozo == 12) - break; - } + for (uint32_t k = sizeof(*ptr); + k < PAGE_SIZE - sizeof(*ptr); k++) + if (((uint8_t *)ptr)[k] != (j % 256)) + kprintf("cringe %u != %u\n", + ((uint8_t *)ptr)[k], j % 256); } } else { diff --git a/src/memory/page.c b/src/memory/page.c index 5acdb47..826acf2 100644 --- a/src/memory/page.c +++ b/src/memory/page.c @@ -5,6 +5,7 @@ #include "debug.h" #include "kprintf.h" #include "memory.h" +#include "string.h" #include "utils.h" static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr, @@ -52,6 +53,7 @@ void *alloc_pages(size_t size) } page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS; } + memset((void *)GET_PAGE_ADDR(pd_index, index), 0, nb_pages * PAGE_SIZE); return (void *)GET_PAGE_ADDR(pd_index, index); }