各种头文件
proc.h
#define proc2pid(x) (x - proc_table)
#define FIRST_PROC proc_table[0]
#define LAST_PROC proc_table[NR_TASKS + NR_PROCS - 1]
#define STACK_SIZE_SYS 0x8000
#define STACK_SIZE_TOTAL (STACK_SIZE_TTY + \
STACK_SIZE_SYS + \
STACK_SIZE_TESTA + \
STACK_SIZE_TESTB + \
STACK_SIZE_TESTC)
struct proc {
struct stackframe regs; // 要保存的寄存器
u16 ldt_sel; // LDT 选择子
struct descriptor ldts[LDT_SIZE]; // LDT 描述符
int ticks; // 由某个值递减到 0
int priority; // 若 ticks 递减到 0,则 ticks = priority
u32 pid; // 进程ID
char name[16]; // 进程名
int p_flags; // 标明进程状态。可取值为:
// 0: 表示进程正在运行或准备运行
// SENDING: 进程处于发送消息的状态。由于消息还未送达,进程被阻塞。
// RECEIVING: 进程处于接收消息的状态。由于消息还未收到,进程被阻塞。
MESSAGE * p_msg; // 指向消息体的指针
int p_recvfrom; // 收到消息,该成员记录发送方是谁
int p_sendto; // 发送消息,该成员记录要发送的对象是谁
int has_int_msg; // 如果在任务未准备好处理时发生中断,则非零。(当发生中断,而这个中断需要某个进程来处理,则该成员不为 0)
struct proc * q_sending; // 向此 proc 发送消息的 procs 队列
struct proc * next_sending; // 发送队列中的下一个过程 (q_sending)
int nr_tty; // 该进程对应的控制台
};
type.h
/**
* MESSAGE 机制是从 MINIX 借来的
*/
struct mess1 {
int m1i1;
int m1i2;
int m1i3;
int m1i4;
};
struct mess2 {
void* m2p1;
void* m2p2;
void* m2p3;
void* m2p4;
};
struct mess3 {
int m3i1;
int m3i2;
int m3i3;
int m3i4;
u64 m3l1;
u64 m3l2;
void* m3p1;
void* m3p2;
};
typedef struct {
int source;
int type;
union {
struct mess1 m1;
struct mess2 m2;
struct mess3 m3;
} u;
} MESSAGE;
const.h
#define STR_DEFAULT_LEN 1024
/* the assert macro */
#define ASSERT
#ifdef ASSERT
void assertion_failure(char *exp, char *file, char *base_file, int line);
#define assert(exp) if (exp) ; \
else assertion_failure(#exp, __FILE__, __BASE_FILE__, __LINE__)
#else
#define assert(exp)
#endif
/* Process */
#define SENDING 0x02 /* set when proc trying to send */
#define RECEIVING 0x04 /* set when proc trying to recv */
/* ipc */
#define SEND 1
#define RECEIVE 2
#define BOTH 3 /* BOTH = (SEND | RECEIVE) */
/* magic chars used by `printx' */
#define MAG_CH_PANIC '\002'
#define MAG_CH_ASSERT '\003'
/**
* 这些都是消息类型
* @enum msgtype
* @brief MESSAGE types
*/
enum msgtype {
// 当发生硬中断时,将向某些任务发送一条消息(type==HARD_INT)。
HARD_INT = 1,
/* SYS task */
GET_TICKS,
};
#define RETVAL u.m3.m3i1 // 系统调用的返回值(就是返回给发送方的数据)
/* tasks */
/* 注意 TASK_XXX 的定义要与 global.c 中的 task_table 对应 */
#define INVALID_DRIVER -20
#define INTERRUPT -10 // 单独的消息来源
#define TASK_TTY 0
#define TASK_SYS 1
#define TASK_HD 2
#define TASK_FS 3
/* #define TASK_MM 4 */
#define ANY (NR_TASKS + NR_PROCS + 10)
#define NO_TASK (NR_TASKS + NR_PROCS + 20)
protect.h
/* descriptor indices in LDT */
#define INDEX_LDT_C 0
#define INDEX_LDT_RW 1
【内容翻译】
msg:消息体
msg.type:我要向内核态(系统进程)申请调用的函数。
BOTH:接收与发送都采用一个 msg
TASK_SYS:系统进程
msg.RETVAL:系统进程返回给该用户进程的消息
进程通信大致流程图

用户进程调用 get_ticks() 流程图

版权声明:本文为qq_43098197原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。