aboutsummaryrefslogtreecommitdiff
path: root/kernel/inc/proc.h
blob: 42ff75d1a6167fa6f95bc6d6437da7ddaa41a49b (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
// MIT License, Copyright (c) 2020 Marvin Borner

#ifndef PROC_H
#define PROC_H

#include <def.h>
#include <drivers/int.h>
#include <list.h>
#include <stack.h>
#include <sys.h>

#define PROC_QUANTUM 15 // Milliseconds or something // TODO
#define PROC_STACK_SIZE 0x4000 // 16KiB

#define EFLAGS_ALWAYS 0x2 // Always one
#define EFLAGS_INTERRUPTS 0x200 // Enable interrupts

#define RING(regs) ((regs->cs) & 3)

enum proc_priv { PROC_PRIV_NONE, PROC_PRIV_ROOT, PROC_PRIV_KERNEL };
enum proc_state { PROC_RUNNING, PROC_BLOCKED };

struct proc {
	u32 pid;
	u32 entry;

	char name[64];
	char dir[64];
	u8 fpu[512];
	struct page_dir *page_dir;
	enum proc_priv priv;
	enum proc_state state;
	struct stack *messages;
	struct list *memory;

	u32 bus_conn;

	struct {
		u32 user;
		u32 user_ptr;
		u32 kernel;
		u32 kernel_ptr;
	} stack;

	struct {
		u32 user;
		u32 kernel;
	} ticks;

	struct {
		u8 val;
		u8 cnt;
	} quantum;
};

u32 scheduler(u32 esp);
NORETURN void proc_init(void);
void proc_print(void);
struct proc *proc_current(void);
u8 proc_super(void);
u8 proc_idle(void);
struct proc *proc_from_pid(u32 pid);
void proc_exit(s32 status);
void proc_yield(void);
void proc_set_quantum(struct proc *proc, u32 value) NONNULL;
void proc_reset_quantum(struct proc *proc) NONNULL;
void proc_state(struct proc *proc, enum proc_state state) NONNULL;
struct proc *proc_make(enum proc_priv priv);
void proc_make_regs(struct proc *proc) NONNULL;
void proc_stack_user_push(struct proc *proc, const void *data, u32 size) NONNULL;
void proc_stack_kernel_push(struct proc *proc, const void *data, u32 size) NONNULL;

#endif