@@ -10,30 +10,94 @@ extern "C" {
1010#define PROC_KERNEL 0
1111#define PROC_MAX 16
1212
13- #define PROC_STATE_IDLE 0
14- #define PROC_STATE_RUNNING 1
13+ /*
14+ DISPATCH
15+ +------------+
16+ | |
17+ +------------+ +----------+-+ +--v---------+EXIT +------------+
18+ | NEW +-----> READY | | RUNNING +------> TERMINATED |
19+ +------------+ +--^-------^-+ +--+-------+-+ +------------+
20+ | | | |
21+ | | | |
22+ | +------------+ |
23+ | INTERRUPT |
24+ | |
25+ I/O COMPLETED| +------------+ |I/O WAIT
26+ +-------+ WAITING <-------+
27+ +------------+
28+ */
29+
30+ #define PROC_STATE_NEW 0
31+ #define PROC_STATE_READY 1
32+ #define PROC_STATE_RUNNING 2
33+ #define PROC_STATE_WAITING 3
34+ #define PROC_STATE_TERMINATED 7
1535
1636#define PROC_PRIO_NORMAL 3
1737
1838#define PROC_PARENT_NONE 0
1939
2040#define RLIMIT_DATA (4 * 1024 * 1024)
2141
22- typedef struct {
23- uintptr_t brk ;
24- uintptr_t heap ;
25- char * name ;
26- int parent_pid ;
27- int pid ;
28- uint8_t priority ;
29- uint8_t state ;
42+ #define PROC_STACK_SIZE 1024
43+
44+ typedef struct cpu_state_t {
45+ uint64_t rax ;
46+ uint64_t rbx ;
47+ uint64_t rcx ;
48+ uint64_t rdx ;
49+ uint64_t rsi ;
50+ uint64_t rdi ;
51+ uint64_t rbp ;
52+ uint64_t rsp ;
53+ uint64_t r8 ;
54+ uint64_t r9 ;
55+ uint64_t r10 ;
56+ uint64_t r11 ;
57+ uint64_t r12 ;
58+ uint64_t r13 ;
59+ uint64_t r14 ;
60+ uint64_t r15 ;
61+ // phys_addr_t cr3;
62+ uint64_t rip ;
63+ uint64_t cs ;
64+ uint64_t rflags ;
65+ uint64_t ss ;
66+ } __attribute__((packed )) cpu_state_t ;
67+
68+ typedef cpu_state_t * cpu_state_p ;
69+
70+ typedef uint8_t proc_state_t ;
71+
72+ typedef struct proc_info_t proc_info_t ;
73+ typedef proc_info_t * proc_info_p ;
74+
75+ typedef struct proc_info_t {
76+ proc_info_p parent ;
77+ proc_info_p * children ;
78+ uint32_t children_count ;
79+ uint32_t pid ;
80+ char name [32 ];
81+ uintptr_t brk ;
82+ uintptr_t heap ;
83+ uintptr_t * stack ;
84+ proc_state_t state ;
85+ uint8_t priority ;
86+ cpu_state_t * cpu_state ;
87+ void (* entrypoint )(void * );
88+ void * arguments ;
89+ proc_info_p next ;
3090} proc_info_t ;
3191
3292typedef proc_info_t * proc_info_p ;
3393
3494extern proc_info_p procs [PROC_MAX ];
3595extern proc_info_p current ;
3696
97+ void init_scheduler ();
98+ void proc_create (proc_info_p proc , void (* entrypoint )(void * ), void * arg );
99+ void proc_execute (proc_info_p proc );
100+
37101#ifdef __cplusplus
38102}
39103#endif
0 commit comments