kern

view src/proc.h @ 96:07fe6a614185

filesystem
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 Dec 2011 04:39:00 +0200
parents 7ff2b4971216
children
line source
1 #ifndef PROC_H_
2 #define PROC_H_
4 #include <inttypes.h>
5 #include "asmops.h"
6 #include "rbtree.h"
7 #include "file.h"
9 #define MAX_PROC 128
10 #define MAX_FD 64
12 struct context {
13 /*struct registers regs;*/ /* saved general purpose registers */
14 /*uint32_t instr_ptr;*/ /* saved eip */
15 uint32_t stack_ptr; /* saved esp */
16 /*uint32_t flags;*/ /* saved eflags */
17 uint32_t pgtbl_paddr; /* physical address of the page table */
18 /* TODO add FPU state */
19 };
21 enum proc_state {
22 STATE_RUNNABLE,
23 STATE_BLOCKED,
24 STATE_ZOMBIE
25 };
28 struct process {
29 int id, parent;
30 enum proc_state state;
32 int exit_status;
34 /* when blocked it's waiting for a wakeup on this address */
35 void *wait_addr;
37 int ticks_left;
39 /* process vm map */
40 struct rbtree vmmap;
42 /* extends of the process heap, increased by sbrk */
44 /* first page of the user stack, extends up to KMEM_START */
45 int user_stack_pg;
46 /* first page of the kernel stack, (KERN_STACK_SIZE) */
47 int kern_stack_pg;
49 struct context ctx;
51 /* open files */
52 struct file files[MAX_FD];
54 unsigned int umask;
56 struct process *child_list;
58 struct process *next, *prev; /* for the scheduler queues */
59 struct process *sib_next; /* for the sibling list */
60 };
62 void init_proc(void);
64 int sys_fork(void);
65 int sys_exit(int status);
66 int sys_waitpid(int pid, int *status, int opt);
68 void context_switch(int pid);
70 void set_current_pid(int pid);
71 int get_current_pid(void);
72 struct process *get_current_proc(void);
73 struct process *get_process(int pid);
75 int sys_getpid(void);
76 int sys_getppid(void);
78 /* defined in proc-asm.S */
79 uint32_t get_instr_ptr(void);
80 uint32_t get_caller_instr_ptr(void);
81 void get_instr_stack_ptr(uint32_t *iptr, uint32_t *sptr);
83 #endif /* PROC_H_ */