summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/mem.c16
-rw-r--r--kernel/mem.h9
-rw-r--r--kernel/proc.c6
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;