nuclear@29: #ifndef PROC_H_ nuclear@29: #define PROC_H_ nuclear@29: nuclear@43: #include nuclear@42: #include "asmops.h" nuclear@68: #include "rbtree.h" nuclear@90: #include "file.h" nuclear@42: nuclear@42: #define MAX_PROC 128 nuclear@90: #define MAX_FD 64 nuclear@42: nuclear@42: struct context { nuclear@54: /*struct registers regs;*/ /* saved general purpose registers */ nuclear@54: /*uint32_t instr_ptr;*/ /* saved eip */ nuclear@47: uint32_t stack_ptr; /* saved esp */ nuclear@54: /*uint32_t flags;*/ /* saved eflags */ nuclear@47: uint32_t pgtbl_paddr; /* physical address of the page table */ nuclear@42: /* TODO add FPU state */ nuclear@42: }; nuclear@42: nuclear@51: enum proc_state { nuclear@53: STATE_RUNNABLE, nuclear@51: STATE_BLOCKED, nuclear@51: STATE_ZOMBIE nuclear@51: }; nuclear@51: nuclear@29: nuclear@29: struct process { nuclear@51: int id, parent; nuclear@51: enum proc_state state; nuclear@51: nuclear@72: int exit_status; nuclear@72: nuclear@55: /* when blocked it's waiting for a wakeup on this address */ nuclear@55: void *wait_addr; nuclear@55: nuclear@51: int ticks_left; nuclear@52: nuclear@68: /* process vm map */ nuclear@68: struct rbtree vmmap; nuclear@68: nuclear@52: /* extends of the process heap, increased by sbrk */ nuclear@52: nuclear@52: /* first page of the user stack, extends up to KMEM_START */ nuclear@54: int user_stack_pg; nuclear@54: /* first page of the kernel stack, (KERN_STACK_SIZE) */ nuclear@54: int kern_stack_pg; nuclear@52: nuclear@42: struct context ctx; nuclear@51: nuclear@90: /* open files */ nuclear@90: struct file files[MAX_FD]; nuclear@90: nuclear@72: struct process *child_list; nuclear@72: nuclear@51: struct process *next, *prev; /* for the scheduler queues */ nuclear@72: struct process *sib_next; /* for the sibling list */ nuclear@29: }; nuclear@29: nuclear@47: void init_proc(void); nuclear@47: nuclear@72: int sys_fork(void); nuclear@72: int sys_exit(int status); nuclear@72: int sys_waitpid(int pid, int *status, int opt); nuclear@57: nuclear@47: void context_switch(int pid); nuclear@47: nuclear@56: void set_current_pid(int pid); nuclear@51: int get_current_pid(void); nuclear@51: struct process *get_current_proc(void); nuclear@51: struct process *get_process(int pid); nuclear@51: nuclear@72: int sys_getpid(void); nuclear@72: int sys_getppid(void); nuclear@72: nuclear@57: /* defined in proc-asm.S */ nuclear@57: uint32_t get_instr_ptr(void); nuclear@57: uint32_t get_caller_instr_ptr(void); nuclear@57: void get_instr_stack_ptr(uint32_t *iptr, uint32_t *sptr); nuclear@57: nuclear@29: #endif /* PROC_H_ */