summaryrefslogtreecommitdiff
path: root/src/stem/task/task.h
blob: f59bb2bac0be27b7011a6acf2e81d03a4422800d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef DEF_TASK_H
#define DEF_TASK_H

#include <types.h>
#include <mem/paging.h>
#include "idt.h"

struct process {
	uint32_t pid, uid, privilege, threads;
	struct process *parent;
	struct page_directory *pagedir;

	struct process *next;	//Forms a linked list
};

#define TS_RUNNING 0	
#define TS_SLEEPING 1	//Sleeping for a defined amount of time
#define TS_WAIKWAIT 2	//Waiting to be waked up by something precise (thread currently blocked)

#define PL_USER 3
#define PL_SERVICE 2
#define PL_DRIVER 1
#define PL_KERNEL 0

typedef void (*thread_entry)(void*);

struct thread {
	struct process *process;
	uint32_t esp, ebp, eip;
	uint8_t state;
	uint32_t timeWait;
	void* kernelStack_addr;
	uint32_t kernelStack_size;

	struct thread *next;	//Forms a linked list
};

extern struct thread *current_thread;

void tasking_init(thread_entry whereToGo, void *data);
void tasking_switch();
void tasking_updateKernelPagetable(uint32_t idx, struct page_table *table, uint32_t tablePhysical);
uint32_t tasking_handleException(struct registers *regs);

struct thread * thread_new(struct process *proc, thread_entry entry_point, void *data);
struct process* process_new(struct process *parent, uint32_t uid, uint32_t privilege);

#endif