diff options
author | Anton Kling <anton@kling.gg> | 2023-11-08 18:10:56 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-11-08 21:29:31 +0100 |
commit | 2026a4f95f3a7dcc9613c8abe2d79d8284b8cd37 (patch) | |
tree | 55eae1e7d8528dc5961cca760fe19d21f3cbe4a1 /kernel/init | |
parent | 006302465965129777884e09114c7a503f8342ac (diff) |
Kernel/MMU: Detect system memory and dynamically adjust memory usage available
Previously this would be hardcoded but now it can be detected by the
bootloader and passed in via the multiboot header.
Diffstat (limited to 'kernel/init')
-rw-r--r-- | kernel/init/kernel.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/kernel/init/kernel.c b/kernel/init/kernel.c index 8c0f70c..9fe7ac4 100644 --- a/kernel/init/kernel.c +++ b/kernel/init/kernel.c @@ -39,17 +39,21 @@ uintptr_t data_end; void kernel_main(uint32_t kernel_end, unsigned long magic, unsigned long addr, uint32_t inital_stack) { - data_end = kernel_end; + (void)kernel_end; + data_end = 0xc0400000; inital_esp = inital_stack; asm("cli"); kprintf("If you see this then the serial driver works :D.\n"); assert(magic == MULTIBOOT_BOOTLOADER_MAGIC); - paging_init(); + multiboot_info_t *mb = (multiboot_info_t *)(addr + 0xc0000000); + uint32_t mem_kb = mb->mem_lower; + uint32_t mem_mb = (mb->mem_upper - 1000) / 1000; + uint64_t memsize_kb = mem_mb * 1000 + mem_kb; + paging_init(memsize_kb); klog("Paging Initalized", LOG_SUCCESS); - multiboot_info_t *mb = - mmu_map_frames((multiboot_info_t *)addr, sizeof(multiboot_info_t)); + mb = mmu_map_frames((multiboot_info_t *)addr, sizeof(multiboot_info_t)); gdt_init(); klog("GDT Initalized", LOG_SUCCESS); |