forked from yhzhang0128/egos-2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.h
42 lines (35 loc) · 1.02 KB
/
process.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#include "elf.h"
#include "disk.h"
enum {
PROC_UNUSED,
PROC_LOADING, /* allocated and wait for loading elf binary */
PROC_READY, /* finished loading elf and wait for first running */
PROC_RUNNING,
PROC_RUNNABLE,
PROC_WAIT_TO_SEND,
PROC_WAIT_TO_RECV
};
struct process{
int pid;
int status;
int receiver_pid; /* used when waiting to send a message */
void *sp, *mepc; /* process context = stack pointer (sp)
* + machine exception program counter (mepc) */
};
#define MAX_NPROCESS 16
extern int proc_curr_idx;
extern struct process proc_set[MAX_NPROCESS];
#define curr_pid proc_set[proc_curr_idx].pid
#define curr_status proc_set[proc_curr_idx].status
void timer_init();
void timer_reset();
void proc_init();
int proc_alloc();
void proc_free(int);
void proc_set_ready (int);
void proc_set_running (int);
void proc_set_runnable (int);
void ctx_entry(void);
void ctx_start(void** old_sp, void* new_sp);
void ctx_switch(void** old_sp, void* new_sp);