diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2025-12-11 16:34:51 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2025-12-11 16:34:51 +0800 |
| commit | 27fc7bda593c8bd2c24a334a368772b5f15d4e9e (patch) | |
| tree | cee97c7b0ba2701be3981b587902e03ba8b85e12 /include/kernel | |
| parent | 497e4a1b2f6f9181518e9887991c0464bd8f6bcf (diff) | |
| download | lume-27fc7bda593c8bd2c24a334a368772b5f15d4e9e.tar.gz lume-27fc7bda593c8bd2c24a334a368772b5f15d4e9e.tar.xz | |
feat:Cooperative Multitasking
Diffstat (limited to 'include/kernel')
| -rw-r--r-- | include/kernel/proc.h | 55 | ||||
| -rw-r--r-- | include/kernel/timer.h | 7 |
2 files changed, 62 insertions, 0 deletions
diff --git a/include/kernel/proc.h b/include/kernel/proc.h new file mode 100644 index 0000000..89a3db7 --- /dev/null +++ b/include/kernel/proc.h @@ -0,0 +1,55 @@ +#pragma once +#include "common/types.h" + +struct Context +{ + uint64 ra; + uint64 sp; + + uint64 s0; + uint64 s1; + uint64 s2; + uint64 s3; + uint64 s4; + uint64 s5; + uint64 s6; + uint64 s7; + uint64 s8; + uint64 s9; + uint64 s10; + uint64 s11; +}; + +enum ProcState{ + UNUSED, + USED, + SLEEPING, + RUNNABLE, + RUNNING, + ZOMBIE, +}; + +struct Proc +{ + struct Context context; + + enum ProcState state; + int pid; + + void* kstack; + char name[16]; + + // +}; + +inline void intr_on() { asm volatile("csrs sstatus, 0x2"); } +inline void intr_off() { asm volatile("csrc sstatus, 0x2"); } + +namespace ProcManager +{ + void init(); + void scheduler(); + void yield(); + + void create_kernel_thread(void (*func)(), const char *name); +}
\ No newline at end of file diff --git a/include/kernel/timer.h b/include/kernel/timer.h new file mode 100644 index 0000000..c35e874 --- /dev/null +++ b/include/kernel/timer.h @@ -0,0 +1,7 @@ +#include "common/types.h" + +namespace Timer{ + uint64 get_time(); + void set_next_trigger(); + void init(); +}
\ No newline at end of file |
