diff options
author | dzwdz | 2021-06-25 21:57:30 +0200 |
---|---|---|
committer | dzwdz | 2021-06-25 21:57:30 +0200 |
commit | 7e8a831e1fa1fb98d2486f0c262c2609c176abab (patch) | |
tree | ad3304a0d16281e019b1e33f7383ed4b97f89afb | |
parent | 654ca8603381ffa385350242cfb96906cf612279 (diff) |
malloc stub + processes
well, there's only one process, but shh
-rw-r--r-- | kernel/main.c | 11 | ||||
-rw-r--r-- | kernel/mem.c | 19 | ||||
-rw-r--r-- | kernel/mem.h | 7 | ||||
-rw-r--r-- | kernel/proc.c | 21 | ||||
-rw-r--r-- | kernel/proc.h | 13 | ||||
-rw-r--r-- | linker.ld | 1 |
6 files changed, 68 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); @@ -21,4 +21,5 @@ SECTIONS *(COMMON) *(.bss) } + _kernel_end = (. + 0xFFF) & ~0xFFF; /* aligned to 4K */ } |