SayoriOS 0.3.3

scheduler.h
1 #ifndef SCHEDULER_H
2 #define SCHEDULER_H
3
4 #include "common.h"
5 #include "lib/list.h"
6 #include "mem/pmm.h"
7
8 #define DEFAULT_STACK_SIZE 0x8000
9
10 typedef enum {
11 CREATED = 0,
12 RUNNING,
13 PAUSED,
14 DEAD
15 } thread_state_t;
16
17 SAYORI_INLINE const char* thread_state_string(thread_state_t state) {
18 switch (state) {
19 case CREATED:
20 return "CREATED";
21 case RUNNING:
22 return "RUNNING";
23 case PAUSED:
24 return "PAUSED";
25 case DEAD:
26 return "DEAD";
27 default:
28 return "UNKNOWN";
29 }
30 }
31
32 typedef volatile struct {
33 // 0
34 list_item_t list_item; /* List item */
35 // 12
36 physical_addr_t page_dir; /* Page directory */
37 // 16
38 size_t threads_count; /* Count of threads */
39 // 20
40 bool suspend; /* Suspend flag */
41 // 24
42 uint32_t pid; /* Process ID (PID) */
43 // 28
44 virtual_addr_t page_dir_virt; /* Virtual address of page directory */
45 // 32
46 char name[256]; /* Process name */
47 // 32 + 256
48 size_t page_tables_virts[1024]; /* Page table addresses */
49 // Every process should have a path that process operates
50 } __attribute__((packed)) process_t;
51
52 /*-----------------------------------------------------------------------------
53 * Thread structure
54 *---------------------------------------------------------------------------*/
55 typedef volatile struct
56 {
57 // 0
58 list_item_t list_item; /* List item */
59 // 12
60 process_t* process; /* This thread's process */
61 // 16
62 bool suspend; /* Suspend flag */
63 // 20
64 size_t stack_size; /* Size of thread's stack */
65 // 24
66 void* stack;
67 // 28
68 uint32_t esp; /* Thread state */
69 // 32
70 uint32_t entry_point;
71 // 36
72 uint32_t id; /* Thread ID */
73 // 40
74 uint32_t stack_top;
75 // registers here [44]
76 uint32_t eax, ebx, ecx, edx, esi, edi, ebp;
77 // 72
78 thread_state_t state;
79 } __attribute__((packed)) thread_t;
80
81 /* Initialization */
82 void init_task_manager(void);
83
84 extern void task_switch(registers_t regs);
85 void task_switch_v2_wrapper(__attribute__((unused)) registers_t regs);
86 extern void task_switch_v2(thread_t*, thread_t*);
87
88 thread_t* _thread_create_unwrapped(process_t* proc, void* entry_point, size_t stack_size,
89 bool kernel, bool suspend);
90
91 void kill_process(size_t id);
92
93 /* Create new thread */
94 thread_t* thread_create(process_t* proc,
95 void* entry_point,
96 size_t stack_size,
97 bool kernel,
98 bool suspend);
99
100 /* Get current process */
101 volatile process_t * get_current_proc(void);
102
103 /* Suspend thread */
104 void thread_suspend(thread_t* thread, bool suspend);
105
106 /* Exit from thread */
107 void thread_exit(thread_t* thread);
108
109 size_t create_process(void* entry_point, char name[256], bool suspend, bool is_kernel);
110
111 /* Check multitask flag */
112 bool is_multitask(void);
113
114 /* Switch to user mode */
115 extern void user_mode_switch(void* entry_point, uint32_t user_stack_top);
116
117 /* Init user mode */
118 void init_user_mode(void* entry_point, size_t stack_size);
119
120 int32_t spawn(const char *name, int argc, char* eargv[]);
121
122 void scheduler_mode(bool on);
123
124 #endif
common.h
Основные определения ядра
__attribute__
struct registers __attribute__((packed))
Структура данных пакета от мыши
Definition: psf.h:19
get_current_proc
volatile process_t * get_current_proc(void)
Получить текущий обработчик процесса
Definition: scheduler.c:125
thread_exit
void thread_exit(thread_t *thread)
Завершить текущий поток
Definition: scheduler.c:231
_thread_create_unwrapped
thread_t * _thread_create_unwrapped(process_t *proc, void *entry_point, size_t stack_size, bool kernel, bool suspend)
Создание потока
Definition: scheduler.c:147
init_task_manager
void init_task_manager(void)
Инициализация менеджера задач
Definition: scheduler.c:33
thread_suspend
void thread_suspend(thread_t *thread, bool suspend)
Остановить поток
Definition: scheduler.c:222
is_multitask
bool is_multitask(void)
Получение состояния о мультипотоке
Definition: scheduler.c:261
_list_item_t
Definition: list.h:27
registers
Definition: common.h:59