diff --git a/Makefile b/Makefile index 39e23f9..79b59dd 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ include arch/$(SOCKS_ARCH)/config.mk # Platform-independent kernel source files #################################### -KERNEL_SRC_DIRS := init kernel vm ds util obj test +KERNEL_SRC_DIRS := init kernel vm ds util obj sched test KERNEL_C_FILES := $(foreach dir,$(KERNEL_SRC_DIRS),$(wildcard $(dir)/*.c)) KERNEL_OBJ := $(addprefix $(BUILD_DIR)/,$(KERNEL_C_FILES:.c=.o)) diff --git a/include/socks/sched.h b/include/socks/sched.h new file mode 100644 index 0000000..a58d3c2 --- /dev/null +++ b/include/socks/sched.h @@ -0,0 +1,43 @@ +#ifndef SOCKS_SCHED_H_ +#define SOCKS_SCHED_H_ + +#include +#include +#include +#include + +typedef enum task_state { + TASK_RUNNING, + TASK_STOPPED, +} task_state_t; + +typedef enum task_thread_state { + TASK_THREAD_READY, + TASK_THREAD_SLEEPING, + TASK_THREAD_STOPPED, +} task_thread_state_t; + +typedef struct task { + struct task *t_parent; + unsigned int t_id; + task_state_t t_state; + + pmap_t t_pmap; + + btree_node_t t_tasklist; + queue_t t_threads; + queue_t t_children; +} task_t; + +typedef struct task_thread { + task_thread_state_t tr_state; + unsigned int tr_id; + unsigned int tr_prio; + + queue_entry_t tr_threads; + void *tr_kstack; +} task_thread_t; + +extern kern_status_t sched_init(void); + +#endif diff --git a/init/main.c b/init/main.c index ee686e8..13c084c 100644 --- a/init/main.c +++ b/init/main.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ void kernel_init(uintptr_t arg) ml_init(arg); object_bootstrap(); + sched_init(); run_all_tests(); diff --git a/sched/sched.c b/sched/sched.c new file mode 100644 index 0000000..8ad9cd0 --- /dev/null +++ b/sched/sched.c @@ -0,0 +1,31 @@ +#include +#include +#include + +static object_type_t task_type = { + .ob_name = "task", + .ob_size = sizeof(task_t), +}; + +static object_type_t thread_type = { + .ob_name = "thread", + .ob_size = sizeof(task_thread_t), +}; + +kern_status_t sched_init(void) +{ + kern_status_t status = KERN_OK; + + status = object_type_register(&task_type); + if (status != KERN_OK) { + return status; + } + + status = object_type_register(&thread_type); + if (status != KERN_OK) { + return status; + } + + printk("sched: initialised"); + return status; +}