blob: 487c1431320869c0291ed1ad7367b2ea973ddd9c [file] [log] [blame]
swissChilie20b79b2021-03-17 21:20:13 -07001#pragma once
2
3#include "kint.h"
swissChilie9289ee2021-03-20 21:54:28 -07004#include "registers.h"
swissChilie20b79b2021-03-17 21:20:13 -07005
swissChiliaed6ff32021-05-29 17:51:04 -07006#define INIT_TASKS_INTERRUPT 0x81
7
8extern bool tasks_initialized;
9
swissChilie9289ee2021-03-20 21:54:28 -070010struct process
11{
12 bool exists;
swissChilicfd3c3c2021-04-03 15:04:24 -070013 int id; // kernel uses pid 0, which cannot exit
swissChilie9289ee2021-03-20 21:54:28 -070014 int ring;
15 int uid;
16 char name[32];
swissChilicfd3c3c2021-04-03 15:04:24 -070017 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;
swissChilie9289ee2021-03-20 21:54:28 -070022};
23
24struct task
25{
26 int id;
27 struct process *proc;
28 uint stack_top_p; // stack frame PHYSICAL address
29 uint esp, ebp, eip;
swissChilie9289ee2021-03-20 21:54:28 -070030};
31
32struct ll_task_i
33{
swissChilif01ddcc2021-04-04 11:31:34 -070034 struct ll_task_i *next, *prev;
swissChilie9289ee2021-03-20 21:54:28 -070035 struct task task;
36};
37
38// extern struct process processes[1024];
39// extern struct ll_task_i *first_task, *current_task;
40
swissChiliaed6ff32021-05-29 17:51:04 -070041// Note: interrupts must be enabled BEFORE this for it to work.
42void init_tasks();
swissChilie9289ee2021-03-20 21:54:28 -070043struct process *get_process(uint pid);
44
45int get_process_id();
46int get_task_id();
47
48// For compatibility I guess
49#define getpid get_process_id
50
swissChilif01ddcc2021-04-04 11:31:34 -070051void spawn_thread(void (*function)(void *), void *data);
52void kill_this_thread();
swissChilicfd3c3c2021-04-03 15:04:24 -070053extern void switch_task();
swissChilif01ddcc2021-04-04 11:31:34 -070054void switch_to_task(struct task *task);
swissChiliaed6ff32021-05-29 17:51:04 -070055void _sys_init_tasks_h(struct registers *regs);