summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authordzwdz2021-06-25 21:57:30 +0200
committerdzwdz2021-06-25 21:57:30 +0200
commit7e8a831e1fa1fb98d2486f0c262c2609c176abab (patch)
treead3304a0d16281e019b1e33f7383ed4b97f89afb /kernel
parent654ca8603381ffa385350242cfb96906cf612279 (diff)
malloc stub + processes
well, there's only one process, but shh
Diffstat (limited to 'kernel')
-rw-r--r--kernel/main.c11
-rw-r--r--kernel/mem.c19
-rw-r--r--kernel/mem.h7
-rw-r--r--kernel/proc.c21
-rw-r--r--kernel/proc.h13
5 files changed, 67 insertions, 4 deletions
diff --git a/kernel/main.c b/kernel/main.c
index 458558a..5c2c5e8 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -1,9 +1,9 @@
#include <kernel/gdt.h>
+#include <kernel/mem.h>
+#include <kernel/proc.h>
#include <kernel/tty.h>
#include <platform/sysenter.h>
-extern void stack_top;
-
void r3_test();
void kmain()
@@ -11,9 +11,12 @@ void kmain()
tty_clear();
gdt_init();
sysenter_setup();
+ mem_init();
- tty_const("jumping to ring3...");
- sysexit(r3_test, &stack_top);
+ tty_const("creating process...");
+ struct process *proc = process_new(r3_test);
+ tty_const("switching...");
+ process_switch(proc);
}
void r3_test() {
diff --git a/kernel/mem.c b/kernel/mem.c
new file mode 100644
index 0000000..8fcaf26
--- /dev/null
+++ b/kernel/mem.c
@@ -0,0 +1,19 @@
+#include <kernel/mem.h>
+
+extern void *_kernel_end;
+static void *highest;
+
+void mem_init() {
+ highest = &_kernel_end;
+}
+
+// should always succeed, there are no error checks anywhere
+void *malloc(size_t size) {
+ void *block = highest;
+ highest += size;
+ return block;
+}
+
+void free(void *ptr) {
+ // not implemented
+}
diff --git a/kernel/mem.h b/kernel/mem.h
new file mode 100644
index 0000000..f779997
--- /dev/null
+++ b/kernel/mem.h
@@ -0,0 +1,7 @@
+#pragma once
+#include <stddef.h>
+
+void mem_init();
+
+void *malloc(size_t size);
+void free(void *ptr);
diff --git a/kernel/proc.c b/kernel/proc.c
new file mode 100644
index 0000000..1178952
--- /dev/null
+++ b/kernel/proc.c
@@ -0,0 +1,21 @@
+#include <kernel/mem.h>
+#include <kernel/proc.h>
+#include <platform/sysenter.h>
+
+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->eip = eip;
+
+ return proc;
+}
+
+void process_switch(struct process *proc) {
+ process_current = proc;
+ sysexit(proc->eip, proc->esp);
+}
diff --git a/kernel/proc.h b/kernel/proc.h
new file mode 100644
index 0000000..976b275
--- /dev/null
+++ b/kernel/proc.h
@@ -0,0 +1,13 @@
+#pragma once
+
+struct process {
+ void *stack_top;
+ void *esp;
+
+ void *eip;
+};
+
+extern struct process *process_current;
+
+struct process *process_new(void *eip);
+void process_switch(struct process *proc);