aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2014-12-13 13:10:18 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2014-12-13 13:10:18 +0100
commit9a494b5b0718eafd89e4bb40dda33b0a4f6ee64f (patch)
tree8c8c70651e74298091c3181d9bdd57a76b0de9bf /kernel
parentd24b3806edddbfff587f1cf91a64338e0fadd48f (diff)
downloadmacroscope-9a494b5b0718eafd89e4bb40dda33b0a4f6ee64f.tar.gz
macroscope-9a494b5b0718eafd89e4bb40dda33b0a4f6ee64f.zip
Remove hard-coded region types.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/include/region.h14
-rw-r--r--kernel/l0/kmain.c10
-rw-r--r--kernel/l0/kmalloc.c2
-rw-r--r--kernel/l0/region.c19
-rw-r--r--kernel/l0/thread.c2
5 files changed, 14 insertions, 33 deletions
diff --git a/kernel/include/region.h b/kernel/include/region.h
index d7a47c4..1fef582 100644
--- a/kernel/include/region.h
+++ b/kernel/include/region.h
@@ -7,29 +7,19 @@
#include <sys.h>
#include <paging.h>
-// Region types
-#define REGION_T_KERNEL_BASE 0x00000001 // base kernel code & data
-#define REGION_T_DESCRIPTORS 0x00000002 // contains more region descriptors
-#define REGION_T_CORE_HEAP 0x00000100 // used for the core kernel heap
-#define REGION_T_KPROC_HEAP 0x00000200 // used for a kernel process' heap
-#define REGION_T_KPROC_STACK 0x00000400 // used for a kernel process' heap
-#define REGION_T_PROC_KSTACK 0x00000800 // used for a process' kernel heap
-#define REGION_T_CACHE 0x00001000 // used for cache
-#define REGION_T_HW 0x00002000 // used for hardware access
-
struct region_info;
typedef void (*page_fault_handler_t)(pagedir_t *pd, struct region_info *r, void* addr);
typedef struct region_info {
void* addr;
size_t size;
- uint32_t type;
+ char* type;
page_fault_handler_t pf;
} region_info_t;
void region_allocator_init(void* kernel_data_end);
-void* region_alloc(size_t size, uint32_t type, page_fault_handler_t pf); // returns 0 on error
+void* region_alloc(size_t size, char* type, page_fault_handler_t pf); // returns 0 on error
region_info_t *find_region(void* addr);
void region_free(void* addr);
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;