blob: b0d0f973bf3698a08f64fe461fddb80862718e44 [file] [log] [blame]
#pragma once
#include "kint.h"
#include "registers.h"
#define INIT_TASKS_INTERRUPT 0x81
extern bool tasks_initialized;
/**
* A process. For now there is only one, the kernel.
*/
struct process
{
bool exists;
int id; // kernel uses pid 0, which cannot exit
int ring;
int uid;
char name[32];
uint page_directory_p;
// most recent (bottom) stack used by a task, next
// stack should be under this one.
// NOTE: must be PAGE ALIGNED
uint last_stack_pos;
};
/**
* The smallest schedulable unit, a thread of a process.
*/
struct task
{
int id;
struct process *proc;
/// Physical address of the top of the stack.
uint stack_top_p;
uint esp, ebp, eip;
};
struct ll_task_i
{
struct ll_task_i *next, *prev;
struct task task;
};
// extern struct process processes[1024];
// extern struct ll_task_i *first_task, *current_task;
// Note: interrupts must be enabled BEFORE this for it to work.
void init_tasks();
struct process *get_process(uint pid);
int get_process_id();
int get_task_id();
// For compatibility I guess
#define getpid get_process_id
typedef void (*task_function_t)(void *data);
#define TASK_FUNCTION(f) ((task_function_t)(f))
void spawn_thread(task_function_t function, void *data);
/**
* Halt the current thread.
*/
void kill_this_thread();
/**
* Force a task switch. Only call in a safe environment (ISR).
*/
extern void switch_task();
/**
* Switch to a specific task. Only call in a safe environment (ISR).
*/
void switch_to_task(struct task *task);
/**
* Internal. Do not call.
*/
void _sys_init_tasks_h(struct registers *regs);