r/include/proc.h

94 lines
2.6 KiB
C

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc.h
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
typedef struct s_stackframe { /* proc_ptr points here ↑ Low */
u32 gs; /* ┓ │ */
u32 fs; /* ┃ │ */
u32 es; /* ┃ │ */
u32 ds; /* ┃ │ */
u32 edi; /* ┃ │ */
u32 esi; /* ┣ pushed by save() │ */
u32 ebp; /* ┃ │ */
u32 kernel_esp; /* <- 'popad' will ignore it │ */
u32 ebx; /* ┃ ↑栈从高地址往低地址增长*/
u32 edx; /* ┃ │ */
u32 ecx; /* ┃ │ */
u32 eax; /* ┛ │ */
u32 retaddr; /* return address for assembly code save() │ */
u32 eip; /* ┓ │ */
u32 cs; /* ┃ │ */
u32 eflags; /* ┣ these are pushed by CPU during interrupt │ */
u32 esp; /* ┃ │ */
u32 ss; /* ┛ ┷High */
}STACK_FRAME;
//相互持有引用的定义
typedef struct s_proc PROCESS;
typedef struct semaphore SEMAPHORE;
//TODO 信号量
struct semaphore{
int value; //当前资源最大允许个数
int s; //头指针
int e; //尾指针
PROCESS *queue[1000]; //进程队列
};
//TODO
struct s_proc {
STACK_FRAME regs; /* process registers saved in stack frame */
u16 ldt_sel; /* gdt selector giving ldt base and limit */
DESCRIPTOR ldts[LDT_SIZE]; /* local descriptors for code and data */
int ticks; /* remained ticks */
int priority;
u32 pid; /* process id passed in from MM */
char p_name[16]; /* name of the process */
int wake; //TODO 进程睡眠到什么时间
SEMAPHORE *waiting_semaphore; //等待信号量
};
typedef struct s_task {
task_f initial_eip;
int stacksize;
char name[32];
}TASK;
//TODO 6个任务
/* Number of tasks */
#define NR_TASKS 6
/* stacks of tasks */
// #define STACK_SIZE_TESTA 0x8000
// #define STACK_SIZE_TESTB 0x8000
// #define STACK_SIZE_TESTC 0x8000
#define STACK_SIZE_A 0x8000
#define STACK_SIZE_READER_B 0x8000
#define STACK_SIZE_READER_C 0x8000
#define STACK_SIZE_READER_D 0x8000
#define STACK_SIZE_WRITER_E 0x8000
#define STACK_SIZE_WRITER_F 0x8000
// #define STACK_SIZE_TOTAL (STACK_SIZE_TESTA + \
// STACK_SIZE_TESTB + \
// STACK_SIZE_TESTC)
#define STACK_SIZE_TOTAL (STACK_SIZE_A + \
STACK_SIZE_READER_B + \
STACK_SIZE_READER_C + \
STACK_SIZE_READER_D + \
STACK_SIZE_WRITER_E + \
STACK_SIZE_WRITER_F)