From f3fac1c19681baf708e8691bb63b3efed59d0aee Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 27 Sep 2019 16:09:05 +0900 Subject: [PATCH] Add task_get_current() and task_set_current() functions; add definitions for keeping track of a task's state and quantum --- kernel/arch/task.S | 25 +++++++++++++++++++++++++ kernel/include/arch.h | 15 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/kernel/arch/task.S b/kernel/arch/task.S index f69c1bf..a041b72 100644 --- a/kernel/arch/task.S +++ b/kernel/arch/task.S @@ -33,6 +33,8 @@ .global task_prepare .global task_switch +.global task_get_current +.global task_set_current task_prepare: /* @@ -219,3 +221,26 @@ task_switch: /* pretend that we're returning from an interrupt */ jmp _int_restore + +task_get_current: + cpuidx %ecx + movl $_cpu, %eax +0: subl $1, %ecx + js 1f + addl $CPU_SIZE, %eax + jmp 0b + +1: movl CUR_TASK(%eax), %eax + ret + +task_set_current: + cpuidx %ecx + movl $_cpu, %eax +0: subl $1, %ecx + js 1f + addl $CPU_SIZE, %eax + jmp 0b + +1: movl 4(%esp), %ecx + movl %ecx, CUR_TASK(%eax) + ret diff --git a/kernel/include/arch.h b/kernel/include/arch.h index e77593e..7499bae 100644 --- a/kernel/include/arch.h +++ b/kernel/include/arch.h @@ -21,11 +21,23 @@ #include +#define TASK_STATE_BROKEN 0 +#define TASK_STATE_RUNNING 1 +#define TASK_STATE_READY 2 +#define TASK_STATE_WAITING 3 + +typedef struct task task_t; + struct task { u32_t t_sp; u32_t t_pgdir; void *t_kstack; u32_t t_privl; + + u32_t t_tslice; + u32_t t_rslice; + + u32_t t_state; } __attribute__((packed)); int cpu_get_id(void); @@ -37,6 +49,9 @@ u32_t cpu_set_pstate(int pstate); int task_prepare(struct task*, u32_t cr3, u32_t eip, u32_t esp0, u32_t esp, u32_t priv); int task_switch(struct task*); +task_t* task_get_current(void); +void task_set_current(task_t*); + /* * Definitions, types, and prototypes related to paging */ -- 2.47.3