fix: malloc

This commit is contained in:
2024-11-28 11:20:45 +01:00
parent 295c513f2d
commit dc12949329
2 changed files with 25 additions and 11 deletions

View File

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