Skip to content

Commit

Permalink
main: Apply previous changes to bootmem.
Browse files Browse the repository at this point in the history
Signed-off-by: TunaCici <[email protected]>
  • Loading branch information
TunaCici committed Jun 1, 2024
1 parent c3af50d commit ad322c9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Kernel/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ void kmain(boot_sysinfo* boot_params)
wfi();
}

if ((mem_end - mem_start) < BM_ARENA_SIZE * PAGE_SIZE) {
if ((mem_end - mem_start) < BM_ARENA_SIZE_BYTE) {
klog("[kmain] Not enough memory available to boot :(\n");
klog("[kmain] ---- Detected memory size: %lu MiB\n",
(mem_end - mem_start) / (1024 * 1024));
klog("[kmain] ---- Required minimum size: %u MiB\n",
(BM_ARENA_SIZE * PAGE_SIZE) / (1024 * 1024));
(BM_ARENA_SIZE_BYTE) / (1024 * 1024));
wfi();
}

Expand All @@ -71,20 +71,19 @@ void kmain(boot_sysinfo* boot_params)
/* 1. Init BootMem */
klog("[kmain] Initializing early memory manager...\n");

uint64_t pageCount = bootmem_init(
uint64_t bootmem_size = bootmem_init(
(const void*) (boot_params->k_phy_base + boot_params->k_size));

klog("[kmain] Pages available: %lu (%lu KiB) in bootmem\n",
pageCount, (pageCount * PAGE_SIZE) / 1024
);
klog("[kmain] Available size in bootmem: %lu KiB\n",
bootmem_size / 1024);

/* 2. Init NBBS */
klog("[kmain] Initializing NBBS...\n");

if (nb_init(mem_start + 0x1000000, 32 * 1024)) {
klog("[kmain] Failed to initialize NBBS ;(\n");
} else {
klog("[kmain] Initialized NBBS (%u KiB)!\n", 64u);
klog("[kmain] Initialized NBBS (%lu KiB)!\n", nb_stat_total_memory());
}

klog("[kmain] nb_alloc\n");
Expand All @@ -97,6 +96,16 @@ void kmain(boot_sysinfo* boot_params)
klog("[kmain] nb_alloc fail\n");
}

klog("[kmain] nb_alloc2\n");

uint64_t *bruh2 = nb_alloc(4096);

if (bruh2) {
klog("[kmain] nb_alloc2 ok (0x%p)\n", bruh2);
} else {
klog("[kmain] nb_alloc2 fail\n");
}

nb_free(bruh);

bruh = nb_alloc(4096);
Expand Down

0 comments on commit ad322c9

Please sign in to comment.