diff options
author | dzwdz | 2021-07-06 19:44:15 +0200 |
---|---|---|
committer | dzwdz | 2021-07-06 19:44:15 +0200 |
commit | 89537c396393c8569b39f14cb8e2c73e676a3e00 (patch) | |
tree | 41ab74848b422e51c104dd8598916a1894344eca /kernel | |
parent | 7e8a831e1fa1fb98d2486f0c262c2609c176abab (diff) |
stub page allocator
the malloc stub didn't even make sense
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/mem.c | 16 | ||||
-rw-r--r-- | kernel/mem.h | 9 | ||||
-rw-r--r-- | kernel/proc.c | 6 |
3 files changed, 17 insertions, 14 deletions
diff --git a/kernel/mem.c b/kernel/mem.c index 8fcaf26..08eb285 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -1,19 +1,19 @@ #include <kernel/mem.h> extern void *_kernel_end; -static void *highest; +static void *highest_page; void mem_init() { - highest = &_kernel_end; + highest_page = &_kernel_end; } -// should always succeed, there are no error checks anywhere -void *malloc(size_t size) { - void *block = highest; - highest += size; - return block; +void *page_alloc(size_t pages) { + void *bottom = highest_page; + highest_page += pages * PAGE_SIZE; + return bottom; } -void free(void *ptr) { +// frees `pages` consecutive pages starting from *first +void page_free(void *first, size_t pages) { // not implemented } diff --git a/kernel/mem.h b/kernel/mem.h index f779997..e8e6a4f 100644 --- a/kernel/mem.h +++ b/kernel/mem.h @@ -1,7 +1,12 @@ #pragma once #include <stddef.h> +#define PAGE_SIZE 4096 + void mem_init(); -void *malloc(size_t size); -void free(void *ptr); +// allocates `pages` consecutive pages +void *page_alloc(size_t pages); + +// frees `pages` consecutive pages starting from *first +void page_free(void *first, size_t pages); diff --git a/kernel/proc.c b/kernel/proc.c index 1178952..959ef94 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -6,10 +6,8 @@ struct process *process_current; struct process *process_new(void *eip) { struct process *proc; - proc = malloc(sizeof(struct process)); - - // should allocate an actual page. TODO - proc->stack_top = proc->esp = malloc(4096); + proc = page_alloc(1); // TODO kmalloc + proc->stack_top = proc->esp = page_alloc(1) + 1 * PAGE_SIZE; proc->eip = eip; return proc; |