diff options
Diffstat (limited to 'kernel/l0')
-rw-r--r-- | kernel/l0/kmain.c | 10 | ||||
-rw-r--r-- | kernel/l0/kmalloc.c | 2 | ||||
-rw-r--r-- | kernel/l0/region.c | 19 | ||||
-rw-r--r-- | kernel/l0/thread.c | 2 |
4 files changed, 12 insertions, 21 deletions
diff --git a/kernel/l0/kmain.c b/kernel/l0/kmain.c index 416b802..2e34868 100644 --- a/kernel/l0/kmain.c +++ b/kernel/l0/kmain.c @@ -22,16 +22,16 @@ void breakpoint_handler(registers_t *regs) { } void region_test1() { - void* p = region_alloc(0x1000, REGION_T_HW, 0); + void* p = region_alloc(0x1000, "Test region", 0); dbg_printf("Allocated one-page region: 0x%p\n", p); dbg_print_region_info(); - void* q = region_alloc(0x1000, REGION_T_HW, 0); + void* q = region_alloc(0x1000, "Test region", 0); dbg_printf("Allocated one-page region: 0x%p\n", q); dbg_print_region_info(); - void* r = region_alloc(0x2000, REGION_T_HW, 0); + void* r = region_alloc(0x2000, "Test region", 0); dbg_printf("Allocated two-page region: 0x%p\n", r); dbg_print_region_info(); - void* s = region_alloc(0x10000, REGION_T_CORE_HEAP, 0); + void* s = region_alloc(0x10000, "Test region", 0); dbg_printf("Allocated 16-page region: 0x%p\n", s); dbg_print_region_info(); region_free(p); @@ -52,7 +52,7 @@ void region_test2() { // allocate a big region and try to write into it dbg_printf("Begin region test 2..."); const size_t n = 200; - void* p0 = region_alloc(n * PAGE_SIZE, REGION_T_HW, default_allocator_pf_handler); + void* p0 = region_alloc(n * PAGE_SIZE, "Test big region", default_allocator_pf_handler); for (size_t i = 0; i < n; i++) { uint32_t *x = (uint32_t*)(p0 + i * PAGE_SIZE); x[0] = 12; diff --git a/kernel/l0/kmalloc.c b/kernel/l0/kmalloc.c index a4ef8fe..e356ada 100644 --- a/kernel/l0/kmalloc.c +++ b/kernel/l0/kmalloc.c @@ -8,7 +8,7 @@ #include <region.h> static void* page_alloc_fun_for_kmalloc(size_t bytes) { - void* addr = region_alloc(bytes, REGION_T_CORE_HEAP, default_allocator_pf_handler); + void* addr = region_alloc(bytes, "Core kernel heap", default_allocator_pf_handler); return addr; } diff --git a/kernel/l0/region.c b/kernel/l0/region.c index 956ec07..3127048 100644 --- a/kernel/l0/region.c +++ b/kernel/l0/region.c @@ -215,7 +215,7 @@ void region_allocator_init(void* kernel_data_end) { descriptor_t *u0 = get_unused_descriptor(); u0->used.i.addr = (void*)K_HIGHHALF_ADDR; u0->used.i.size = PAGE_ALIGN_UP(kernel_data_end) - K_HIGHHALF_ADDR; - u0->used.i.type = REGION_T_KERNEL_BASE; + u0->used.i.type = "Kernel code & data"; u0->used.i.pf = 0; u0->used.next_by_addr = 0; first_used_region = u0; @@ -238,7 +238,7 @@ void region_free(void* addr) { mutex_unlock(&ra_mutex); } -static void* region_alloc_inner(size_t size, uint32_t type, page_fault_handler_t pf, bool use_reserve) { +static void* region_alloc_inner(size_t size, char* type, page_fault_handler_t pf, bool use_reserve) { size = PAGE_ALIGN_UP(size); for (descriptor_t *i = first_free_region_by_size; i != 0; i = i->free.first_bigger) { @@ -282,7 +282,7 @@ static void* region_alloc_inner(size_t size, uint32_t type, page_fault_handler_t return 0; //No big enough block found } -void* region_alloc(size_t size, uint32_t type, page_fault_handler_t pf) { +void* region_alloc(size_t size, char* type, page_fault_handler_t pf) { void* result = 0; mutex_lock(&ra_mutex); @@ -290,7 +290,7 @@ void* region_alloc(size_t size, uint32_t type, page_fault_handler_t pf) { uint32_t frame = frame_alloc(1); if (frame == 0) goto try_anyway; - void* descriptor_region = region_alloc_inner(PAGE_SIZE, REGION_T_DESCRIPTORS, 0, true); + void* descriptor_region = region_alloc_inner(PAGE_SIZE, "Region descriptors", 0, true); ASSERT(descriptor_region != 0); int error = pd_map_page(descriptor_region, frame, 1); @@ -386,16 +386,7 @@ void dbg_print_region_info() { } dbg_printf("- Used kernel regions:\n"); for (descriptor_t *d = first_used_region; d != 0; d = d->used.next_by_addr) { - dbg_printf("| 0x%p - 0x%p", d->used.i.addr, d->used.i.addr + d->used.i.size); - if (d->used.i.type & REGION_T_KERNEL_BASE) dbg_printf(" Kernel code & base data"); - if (d->used.i.type & REGION_T_DESCRIPTORS) dbg_printf(" Region descriptors"); - if (d->used.i.type & REGION_T_CORE_HEAP) dbg_printf(" Core heap"); - if (d->used.i.type & REGION_T_KPROC_HEAP) dbg_printf(" Kernel process heap"); - if (d->used.i.type & REGION_T_KPROC_STACK) dbg_printf(" Kernel process stack"); - if (d->used.i.type & REGION_T_PROC_KSTACK) dbg_printf(" Process kernel stack"); - if (d->used.i.type & REGION_T_CACHE) dbg_printf(" Cache"); - if (d->used.i.type & REGION_T_HW) dbg_printf(" Hardware"); - dbg_printf("\n"); + dbg_printf("| 0x%p - 0x%p %s\n", d->used.i.addr, d->used.i.addr + d->used.i.size, d->used.i.type); ASSERT(d != d->used.next_by_addr); } dbg_printf("\\\n"); diff --git a/kernel/l0/thread.c b/kernel/l0/thread.c index b14ad9b..1a67f6c 100644 --- a/kernel/l0/thread.c +++ b/kernel/l0/thread.c @@ -119,7 +119,7 @@ thread_t *new_thread(entry_t entry) { thread_t *t = (thread_t*)kmalloc(sizeof(thread_t)); if (t == 0) return 0; - void* stack = region_alloc(KPROC_STACK_SIZE, REGION_T_KPROC_STACK, 0); + void* stack = region_alloc(KPROC_STACK_SIZE, "Stack", 0); if (stack == 0) { kfree(t); return 0; |