]> git.corax.cc Git - corax/commitdiff
Add task_get_current() and task_set_current() functions; add definitions for keeping...
authorMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 07:09:05 +0000 (16:09 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 27 Sep 2019 07:09:05 +0000 (16:09 +0900)
kernel/arch/task.S
kernel/include/arch.h

index f69c1bf5067cc7d96b337bd7a46b484028f6d6bc..a041b72dcdc605a0d367ccbe58faa3e23a0807b3 100644 (file)
@@ -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
index e77593eb418764af441aa3c8a7a17a7b84881670..7499bae28d4f79eceb158c14901cf6eb71bb1853 100644 (file)
 
 #include <corax/types.h>
 
+#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
  */