summaryrefslogtreecommitdiff
path: root/src/kernel/task/task.h
blob: 69b431d851d3cbd7103a0f736dcbdddd6292c276 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef DEF_TASK_H
#define DEF_TASK_H

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

#define TS_RUNNING 0	
#define TS_WAKEWAIT 2	//Waiting to be waked up by something precise (thread currently blocked)

#define PL_UNKNOWN 2
#define PL_USER 1
#define PL_KERNEL 0

#define EX_TH_NORMAL	0x10000		//ERROR code : just one thread exits, because it has to
#define EX_TH_EXCEPTION 0x10001		//ERROR code : just one thread exits, because of an unhandled exception
#define EX_PR_EXCEPTION 0x10002		//ERROR code : all process finishes, because of an unhandled exception

#define USER_STACK_SIZE 0x10000	//64k, but pages will be mapped one by one as they are used

typedef void (*thread_entry)(void*);

class thread;
class process {
	public:

	uint32_t pid, uid, privilege, thread_count;
	process *parent;
	page_directory *pagedir;
	size_t stack, data;

	segment_map *dataseg;

	process *next;	//Forms a linked list
	thread *threads;

	process() {}	// must not be used directly
	process(process *parent, uint32_t uid, uint32_t privilege);
};

class thread {
	public:

	class process *process;
	uint32_t esp, ebp, eip;
	uint8_t state;
	uint32_t timeWait;
	void* kernelStack_addr;
	uint32_t kernelStack_size;

	thread *next, *queue_next;	//queue_next is used in sched.c

	thread(class process *proc, thread_entry entry_point, void *data, void *u_esp);

	void wakeUp();
};

extern thread *current_thread;

void tasking_init();
#ifdef __cplusplus
extern "C" void schedule();
#else
void schedule();
#endif
void tasking_updateKernelPagetable(uint32_t idx, page_table *table, uint32_t tablePhysical);
uint32_t tasking_handleException(registers *regs);

void thread_goInactive();	//Blocks the current thread. it is then waked up by another thread or a system event. 
int proc_priv();	//Returns current privilege level

void thread_exit();	//syscall
void process_exit(size_t retval);	//syscall
size_t process_sbrk(size_t size);
void process_brk(size_t ptr);

#endif