summaryrefslogtreecommitdiff
path: root/kc/core/task.h
blob: bea4756c1896ce4608219faa8a09a26b4eb2c83b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once

#include <stdint.h>

enum kc_thread_status
{
    READY,
    RUNNING,
    SLEEPING,
    BLOCKED,
    TERMINATED
};

struct kc_thread_state
{
    uint64_t stack;
    uint64_t stack_top;
    uint64_t page_map;
};

struct kc_thread
{
    struct kc_thread *next;
    uint64_t time_elapsed;
    uint64_t sleep_expiration;
    enum kc_thread_status status;
    struct kc_thread_state state;
};

extern void cpu_set_thread(
        struct kc_thread_state *current,
        struct kc_thread_state *next,
        uint64_t *cpu_tss_rsp0);

void task_init(void);
void task_schedule(void);