kern

view src/proc.h @ 72:3941e82b07f2

- implemented syscalls: exit, waitpid, getppid - moved sys_whatever functions out of syscall.c into more reasonable files - putting all the definitions that must be synced with userland to include/kdef.h
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Oct 2011 07:45:56 +0300
parents 0a205396e1a0
children 7ff2b4971216
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 int exit_status;
32 /* when blocked it's waiting for a wakeup on this address */
33 void *wait_addr;
35 int ticks_left;
37 /* process vm map */
38 struct rbtree vmmap;
40 /* extends of the process heap, increased by sbrk */
42 /* first page of the user stack, extends up to KMEM_START */
43 int user_stack_pg;
44 /* first page of the kernel stack, (KERN_STACK_SIZE) */
45 int kern_stack_pg;
47 struct context ctx;
49 struct process *child_list;
51 struct process *next, *prev; /* for the scheduler queues */
52 struct process *sib_next; /* for the sibling list */
53 };
55 void init_proc(void);
57 int sys_fork(void);
58 int sys_exit(int status);
59 int sys_waitpid(int pid, int *status, int opt);
61 void context_switch(int pid);
63 void set_current_pid(int pid);
64 int get_current_pid(void);
65 struct process *get_current_proc(void);
66 struct process *get_process(int pid);
68 int sys_getpid(void);
69 int sys_getppid(void);
71 /* defined in proc-asm.S */
72 uint32_t get_instr_ptr(void);
73 uint32_t get_caller_instr_ptr(void);
74 void get_instr_stack_ptr(uint32_t *iptr, uint32_t *sptr);
76 #endif /* PROC_H_ */