kern

annotate 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
rev   line source
nuclear@29 1 #ifndef PROC_H_
nuclear@29 2 #define PROC_H_
nuclear@29 3
nuclear@43 4 #include <inttypes.h>
nuclear@42 5 #include "asmops.h"
nuclear@68 6 #include "rbtree.h"
nuclear@42 7
nuclear@42 8 #define MAX_PROC 128
nuclear@42 9
nuclear@42 10 struct context {
nuclear@54 11 /*struct registers regs;*/ /* saved general purpose registers */
nuclear@54 12 /*uint32_t instr_ptr;*/ /* saved eip */
nuclear@47 13 uint32_t stack_ptr; /* saved esp */
nuclear@54 14 /*uint32_t flags;*/ /* saved eflags */
nuclear@47 15 uint32_t pgtbl_paddr; /* physical address of the page table */
nuclear@42 16 /* TODO add FPU state */
nuclear@42 17 };
nuclear@42 18
nuclear@51 19 enum proc_state {
nuclear@53 20 STATE_RUNNABLE,
nuclear@51 21 STATE_BLOCKED,
nuclear@51 22 STATE_ZOMBIE
nuclear@51 23 };
nuclear@51 24
nuclear@29 25
nuclear@29 26 struct process {
nuclear@51 27 int id, parent;
nuclear@51 28 enum proc_state state;
nuclear@51 29
nuclear@55 30 /* when blocked it's waiting for a wakeup on this address */
nuclear@55 31 void *wait_addr;
nuclear@55 32
nuclear@51 33 int ticks_left;
nuclear@52 34
nuclear@68 35 /* process vm map */
nuclear@68 36 struct rbtree vmmap;
nuclear@68 37
nuclear@52 38 /* extends of the process heap, increased by sbrk */
nuclear@52 39
nuclear@52 40 /* first page of the user stack, extends up to KMEM_START */
nuclear@54 41 int user_stack_pg;
nuclear@54 42 /* first page of the kernel stack, (KERN_STACK_SIZE) */
nuclear@54 43 int kern_stack_pg;
nuclear@52 44
nuclear@42 45 struct context ctx;
nuclear@51 46
nuclear@51 47 struct process *next, *prev; /* for the scheduler queues */
nuclear@29 48 };
nuclear@29 49
nuclear@47 50 void init_proc(void);
nuclear@47 51
nuclear@57 52 int fork(void);
nuclear@57 53
nuclear@47 54 void context_switch(int pid);
nuclear@47 55
nuclear@56 56 void set_current_pid(int pid);
nuclear@51 57 int get_current_pid(void);
nuclear@51 58 struct process *get_current_proc(void);
nuclear@51 59 struct process *get_process(int pid);
nuclear@51 60
nuclear@57 61 /* defined in proc-asm.S */
nuclear@57 62 uint32_t get_instr_ptr(void);
nuclear@57 63 uint32_t get_caller_instr_ptr(void);
nuclear@57 64 void get_instr_stack_ptr(uint32_t *iptr, uint32_t *sptr);
nuclear@57 65
nuclear@29 66 #endif /* PROC_H_ */