kern

view src/proc.h @ 68:0a205396e1a0

- added a generic red-black tree data structure - added a VM map as an red-black tree of vm_pages in the process structure - constructed the vm map of the memory passed by the kernel initially to the first process.
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 10 Oct 2011 04:16:01 +0300
parents 437360696883
children 3941e82b07f2
line source
1 #ifndef PROC_H_
2 #define PROC_H_
4 #include <inttypes.h>
5 #include "asmops.h"
6 #include "rbtree.h"
8 #define MAX_PROC 128
10 struct context {
11 /*struct registers regs;*/ /* saved general purpose registers */
12 /*uint32_t instr_ptr;*/ /* saved eip */
13 uint32_t stack_ptr; /* saved esp */
14 /*uint32_t flags;*/ /* saved eflags */
15 uint32_t pgtbl_paddr; /* physical address of the page table */
16 /* TODO add FPU state */
17 };
19 enum proc_state {
20 STATE_RUNNABLE,
21 STATE_BLOCKED,
22 STATE_ZOMBIE
23 };
26 struct process {
27 int id, parent;
28 enum proc_state state;
30 /* when blocked it's waiting for a wakeup on this address */
31 void *wait_addr;
33 int ticks_left;
35 /* process vm map */
36 struct rbtree vmmap;
38 /* extends of the process heap, increased by sbrk */
40 /* first page of the user stack, extends up to KMEM_START */
41 int user_stack_pg;
42 /* first page of the kernel stack, (KERN_STACK_SIZE) */
43 int kern_stack_pg;
45 struct context ctx;
47 struct process *next, *prev; /* for the scheduler queues */
48 };
50 void init_proc(void);
52 int fork(void);
54 void context_switch(int pid);
56 void set_current_pid(int pid);
57 int get_current_pid(void);
58 struct process *get_current_proc(void);
59 struct process *get_process(int pid);
61 /* defined in proc-asm.S */
62 uint32_t get_instr_ptr(void);
63 uint32_t get_caller_instr_ptr(void);
64 void get_instr_stack_ptr(uint32_t *iptr, uint32_t *sptr);
66 #endif /* PROC_H_ */