aboutsummaryrefslogtreecommitdiff
path: root/kernel/l0/kmain.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-02 20:12:42 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-02 20:12:42 +0100
commit6a56675851c16a0cefcf5a2d10a1227c37e9d886 (patch)
treeaebd4784159999993e3ae9f1e7c15961f267cad6 /kernel/l0/kmain.c
parent456fc99e8feac598f7c6f1a3aaa82bf994404e39 (diff)
downloadkogata-6a56675851c16a0cefcf5a2d10a1227c37e9d886.tar.gz
kogata-6a56675851c16a0cefcf5a2d10a1227c37e9d886.zip
Implement kernel memory region allocator.
Diffstat (limited to 'kernel/l0/kmain.c')
-rw-r--r--kernel/l0/kmain.c29
1 files changed, 29 insertions, 0 deletions
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 <idt.h>
#include <frame.h>
#include <paging.h>
+#include <region.h>
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