aboutsummaryrefslogtreecommitdiff
path: root/src/core/scheduler.h
blob: 62d656141cae3d89059970ef9f757c2d07b12b2e (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef SCHEDULER_H
#define SCHEDULER_H

#include "mem.h"

#define MAX_PROC 10

// If you change the following struct
// please consider updating the code in scheduler_asm.S
typedef struct REGISTERS {
    u32 eax, ebx, ecx, edx;
    u32 cs, eip;
    u32 ss, esp, ebp;
    u32 esi, edi;
    u32 ds, es, fs, gs;
    u32 eflags;
} __attribute__((packed)) REGISTERS;

// If you change the following struct
// please consider updating the code in scheduler_asm.S
typedef struct PROC {
    u16 id;
    u16 pid;
    u32* page_dir;
    REGISTERS regs;
} __attribute__((packed)) PROC;

extern char show_tics;
extern char scheduler_on;
extern PROC procs[MAX_PROC];
extern u16 current_id; // Current running task PID/id
extern u16 nproc; // Number of active tasks

/**
 * Must be called at each clock interrupt
 */
void clock();

/**
 * Called by clock() and schedule the next task
 * Stack is a pointer pointing to the gs register on the stack.
 * The stack must contains the interrupted process registers in the following
 * order: gs,fs,es,ds,edi,esi,ebp,UNUSED,edx,ecx,ebx,eax,eip,cs,eflags,esp,ss
 */
void schedule(u32 *stack);

/**
 * Create a new task to be schedule
 */
void task_create(int *page_dir, void *task, int task_size, int stack_offset);

/**
 * Stack the scheduler starting by task with PID 0
 */
void scheduler_start();

#endif