swissChili | e20b79b | 2021-03-17 21:20:13 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "kint.h" |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 4 | #include "registers.h" |
swissChili | e20b79b | 2021-03-17 21:20:13 -0700 | [diff] [blame] | 5 | |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 6 | #define INIT_TASKS_INTERRUPT 0x81 |
| 7 | |
| 8 | extern bool tasks_initialized; |
| 9 | |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 10 | struct process |
| 11 | { |
| 12 | bool exists; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 13 | int id; // kernel uses pid 0, which cannot exit |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 14 | int ring; |
| 15 | int uid; |
| 16 | char name[32]; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 17 | uint page_directory_p; |
| 18 | // most recent (bottom) stack used by a task, next |
| 19 | // stack should be under this one. |
| 20 | // NOTE: must be PAGE ALIGNED |
| 21 | uint last_stack_pos; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | struct task |
| 25 | { |
| 26 | int id; |
| 27 | struct process *proc; |
| 28 | uint stack_top_p; // stack frame PHYSICAL address |
| 29 | uint esp, ebp, eip; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct ll_task_i |
| 33 | { |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 34 | struct ll_task_i *next, *prev; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 35 | struct task task; |
| 36 | }; |
| 37 | |
| 38 | // extern struct process processes[1024]; |
| 39 | // extern struct ll_task_i *first_task, *current_task; |
| 40 | |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 41 | // Note: interrupts must be enabled BEFORE this for it to work. |
| 42 | void init_tasks(); |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 43 | struct process *get_process(uint pid); |
| 44 | |
| 45 | int get_process_id(); |
| 46 | int get_task_id(); |
| 47 | |
| 48 | // For compatibility I guess |
| 49 | #define getpid get_process_id |
| 50 | |
swissChili | 1b83922 | 2021-06-03 13:54:40 -0700 | [diff] [blame] | 51 | typedef void (*task_function_t)(void *data); |
| 52 | |
| 53 | #define TASK_FUNCTION(f) ((task_function_t)(f)) |
| 54 | |
| 55 | void spawn_thread(task_function_t function, void *data); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 56 | void kill_this_thread(); |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 57 | extern void switch_task(); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 58 | void switch_to_task(struct task *task); |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 59 | void _sys_init_tasks_h(struct registers *regs); |