xv6-simplified 0.1
简化版xv6
Loading...
Searching...
No Matches
proc.h
Go to the documentation of this file.
1
10/* 暂时剔除proc/cpu中用到锁、虚拟内存、文件、目录的数据结构 */
11
12
13// 内核切换上下文时保存的寄存器
14struct context {
17
18 // 函数调用时保存的寄存器
31};
32
33// trap handling时每个进程保存的帧
34// trap handling的代码在trampoline.S中
35// 保存的内容包括所有通用整数寄存器和几个内核相关信息
36struct trapframe {
37 /* 0 */ uint64 kernel_satp; // 内核页表
38 /* 8 */ uint64 kernel_sp; // 进程的内核栈顶指针
39 /* 16 */ uint64 kernel_trap; // usertrap()函数地址
40 /* 24 */ uint64 epc; // 保存返回用户模式时的PC
41 /* 32 */ uint64 kernel_hartid; // 保存内核的tp(内核id)
42 /* 40 */ uint64 ra;
43 /* 48 */ uint64 sp;
44 /* 56 */ uint64 gp;
45 /* 64 */ uint64 tp;
46 /* 72 */ uint64 t0;
47 /* 80 */ uint64 t1;
48 /* 88 */ uint64 t2;
49 /* 96 */ uint64 s0;
50 /* 104 */ uint64 s1;
51 /* 112 */ uint64 a0;
52 /* 120 */ uint64 a1;
53 /* 128 */ uint64 a2;
54 /* 136 */ uint64 a3;
55 /* 144 */ uint64 a4;
56 /* 152 */ uint64 a5;
57 /* 160 */ uint64 a6;
58 /* 168 */ uint64 a7;
59 /* 176 */ uint64 s2;
60 /* 184 */ uint64 s3;
61 /* 192 */ uint64 s4;
62 /* 200 */ uint64 s5;
63 /* 208 */ uint64 s6;
64 /* 216 */ uint64 s7;
65 /* 224 */ uint64 s8;
66 /* 232 */ uint64 s9;
67 /* 240 */ uint64 s10;
68 /* 248 */ uint64 s11;
69 /* 256 */ uint64 t3;
70 /* 264 */ uint64 t4;
71 /* 272 */ uint64 t5;
72 /* 280 */ uint64 t6;
73};
74
75// 进程存在状态
77
78// 进程
79struct proc
80{
81 enum procstate state; // 进程当前的状态
82 // 一种资源,可能是进程、文件描述符、设备
83 // 若得不到使用,则进程会为此sleep
84 // 直到释放该资源时wakeup等待该资源的所有进程
85 // 为0代表未sleep
86 void *chan;
87 int killed; // 是否被killed
88 int xstate; // 子进程exit()时的状态
89 int pid; // 进程ID
90
91 struct proc *parent; // 父进程
92
93 // 以下内容属于进程私有
94 uint64 kstack; // 内核栈的虚拟地址
95 uint64 sz; // 进程在内存中的size(byte) (实则是页表的大小)
96 pagetable_t pagetable; // 用户的页表
97 struct trapframe *trapframe;// 处理trap时上下文帧
98 struct context context; // 上下文
99 struct file *ofile[NOFILE]; // 打开的文件
100 struct dirent *cwd; // 当前所在目录
101 char name[16]; // 进程名称
102};
103
104
105// 每个CPU保存的数据结构
106struct cpu {
107 struct proc *proc; // 在该CPU上运行的进程
108 struct context context; // 调度中切换进程时进程用于切换的上下文信息
109 // 暂未用到锁机制,不存在push_off()嵌套的深度
110// int noff; // push_off()嵌套深度
111// int intena; // 在push_off()前是否启用了中断
112};
113
114extern struct cpu cpus[NCPU];
#define NCPU
Definition param.h:11
#define NOFILE
Definition param.h:12
struct cpu cpus[NCPU]
Definition proc.c:20
procstate
Definition proc.h:76
@ RUNNING
Definition proc.h:76
@ USED
Definition proc.h:76
@ RUNNABLE
Definition proc.h:76
@ SLEEPING
Definition proc.h:76
@ ZOMBIE
Definition proc.h:76
@ UNUSED
Definition proc.h:76
uint64 * pagetable_t
Definition riscv.h:523
Definition proc.h:14
uint64 s1
Definition proc.h:20
uint64 s9
Definition proc.h:28
uint64 s0
Definition proc.h:19
uint64 s2
Definition proc.h:21
uint64 s4
Definition proc.h:23
uint64 s10
Definition proc.h:29
uint64 sp
Definition proc.h:16
uint64 s7
Definition proc.h:26
uint64 s3
Definition proc.h:22
uint64 s5
Definition proc.h:24
uint64 ra
Definition proc.h:15
uint64 s11
Definition proc.h:30
uint64 s8
Definition proc.h:27
uint64 s6
Definition proc.h:25
Definition proc.h:106
struct proc * proc
Definition proc.h:107
Definition fat32.h:31
Definition file.h:11
Definition proc.h:80
pagetable_t pagetable
Definition proc.h:96
int xstate
Definition proc.h:88
enum procstate state
Definition proc.h:81
uint64 kstack
Definition proc.h:94
struct file * ofile[NOFILE]
Definition proc.h:99
struct dirent * cwd
Definition proc.h:100
int killed
Definition proc.h:87
struct trapframe * trapframe
Definition proc.h:97
char name[16]
Definition proc.h:101
struct proc * parent
Definition proc.h:91
void * chan
Definition proc.h:86
uint64 sz
Definition proc.h:95
int pid
Definition proc.h:89
Definition proc.h:36
uint64 a2
Definition proc.h:53
uint64 epc
Definition proc.h:40
uint64 s1
Definition proc.h:50
uint64 s9
Definition proc.h:66
uint64 a7
Definition proc.h:58
uint64 s0
Definition proc.h:49
uint64 s2
Definition proc.h:59
uint64 a4
Definition proc.h:55
uint64 gp
Definition proc.h:44
uint64 kernel_trap
Definition proc.h:39
uint64 kernel_satp
Definition proc.h:37
uint64 tp
Definition proc.h:45
uint64 s4
Definition proc.h:61
uint64 t0
Definition proc.h:46
uint64 s10
Definition proc.h:67
uint64 t2
Definition proc.h:48
uint64 a0
Definition proc.h:51
uint64 a1
Definition proc.h:52
uint64 sp
Definition proc.h:43
uint64 s7
Definition proc.h:64
uint64 t4
Definition proc.h:70
uint64 s3
Definition proc.h:60
uint64 a3
Definition proc.h:54
uint64 s5
Definition proc.h:62
uint64 ra
Definition proc.h:42
uint64 kernel_hartid
Definition proc.h:41
uint64 s11
Definition proc.h:68
uint64 t5
Definition proc.h:71
uint64 a6
Definition proc.h:57
uint64 t1
Definition proc.h:47
uint64 t3
Definition proc.h:69
uint64 kernel_sp
Definition proc.h:38
uint64 s8
Definition proc.h:65
uint64 s6
Definition proc.h:63
uint64 t6
Definition proc.h:72
uint64 a5
Definition proc.h:56
unsigned long uint64
Definition types.h:24