From 6a56675851c16a0cefcf5a2d10a1227c37e9d886 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 2 Dec 2014 20:12:42 +0100 Subject: Implement kernel memory region allocator. --- kernel/l0/kmain.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'kernel/l0/kmain.c') diff --git a/kernel/l0/kmain.c b/kernel/l0/kmain.c index f6cda4e..cd84cf7 100644 --- a/kernel/l0/kmain.c +++ b/kernel/l0/kmain.c @@ -7,6 +7,7 @@ #include #include #include +#include void breakpoint_handler(registers_t *regs) { dbg_printf("Breakpoint! (int3)\n"); @@ -43,6 +44,34 @@ void kmain(struct multiboot_info_t *mbd, int32_t mb_magic) { paging_setup(kernel_data_end); dbg_printf("Paging seems to be working!\n"); + region_allocator_init(kernel_data_end); + dbg_print_region_stats(); + + size_t p = region_alloc(0x1000, REGION_T_HW, 0); + dbg_printf("Allocated one-page region: 0x%p\n", p); + dbg_print_region_stats(); + size_t q = region_alloc(0x1000, REGION_T_HW, 0); + dbg_printf("Allocated one-page region: 0x%p\n", q); + dbg_print_region_stats(); + size_t r = region_alloc(0x2000, REGION_T_HW, 0); + dbg_printf("Allocated two-page region: 0x%p\n", r); + dbg_print_region_stats(); + size_t s = region_alloc(0x10000, REGION_T_CORE_HEAP, 0); + dbg_printf("Allocated 16-page region: 0x%p\n", s); + dbg_print_region_stats(); + region_free(p); + dbg_printf("Freed region 0x%p\n", p); + dbg_print_region_stats(); + region_free(q); + dbg_printf("Freed region 0x%p\n", q); + dbg_print_region_stats(); + region_free(r); + dbg_printf("Freed region 0x%p\n", r); + dbg_print_region_stats(); + region_free(s); + dbg_printf("Freed region 0x%p\n", s); + dbg_print_region_stats(); + // TODO: // - setup allocator for physical pages (eg: buddy allocator, see OSDev wiki) // - setup allocator for virtual memory space -- cgit v1.2.3