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 | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 6 | struct process |
| 7 | { |
| 8 | bool exists; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 9 | int id; // kernel uses pid 0, which cannot exit |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 10 | int ring; |
| 11 | int uid; |
| 12 | char name[32]; |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 13 | uint page_directory_p; |
| 14 | // most recent (bottom) stack used by a task, next |
| 15 | // stack should be under this one. |
| 16 | // NOTE: must be PAGE ALIGNED |
| 17 | uint last_stack_pos; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
| 20 | struct task |
| 21 | { |
| 22 | int id; |
| 23 | struct process *proc; |
| 24 | uint stack_top_p; // stack frame PHYSICAL address |
| 25 | uint esp, ebp, eip; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | struct ll_task_i |
| 29 | { |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 30 | struct ll_task_i *next, *prev; |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 31 | struct task task; |
| 32 | }; |
| 33 | |
| 34 | // extern struct process processes[1024]; |
| 35 | // extern struct ll_task_i *first_task, *current_task; |
| 36 | |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 37 | extern void init_tasks(); |
swissChili | e9289ee | 2021-03-20 21:54:28 -0700 | [diff] [blame] | 38 | struct process *get_process(uint pid); |
| 39 | |
| 40 | int get_process_id(); |
| 41 | int get_task_id(); |
| 42 | |
| 43 | // For compatibility I guess |
| 44 | #define getpid get_process_id |
| 45 | |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 46 | void spawn_thread(void (*function)(void *), void *data); |
| 47 | void kill_this_thread(); |
swissChili | cfd3c3c | 2021-04-03 15:04:24 -0700 | [diff] [blame] | 48 | extern void switch_task(); |
swissChili | f01ddcc | 2021-04-04 11:31:34 -0700 | [diff] [blame] | 49 | void switch_to_task(struct task *task); |