xv6-simplified
0.1
简化版xv6
Loading...
Searching...
No Matches
src
include
proc.h
Go to the documentation of this file.
1
10
/* 暂时剔除proc/cpu中用到锁、虚拟内存、文件、目录的数据结构 */
11
12
13
// 内核切换上下文时保存的寄存器
14
struct
context
{
15
uint64
ra
;
16
uint64
sp
;
17
18
// 函数调用时保存的寄存器
19
uint64
s0
;
20
uint64
s1
;
21
uint64
s2
;
22
uint64
s3
;
23
uint64
s4
;
24
uint64
s5
;
25
uint64
s6
;
26
uint64
s7
;
27
uint64
s8
;
28
uint64
s9
;
29
uint64
s10
;
30
uint64
s11
;
31
};
32
33
// trap handling时每个进程保存的帧
34
// trap handling的代码在trampoline.S中
35
// 保存的内容包括所有通用整数寄存器和几个内核相关信息
36
struct
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
// 进程存在状态
76
enum
procstate
{
UNUSED
,
USED
,
SLEEPING
,
RUNNABLE
,
RUNNING
,
ZOMBIE
};
77
78
// 进程
79
struct
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保存的数据结构
106
struct
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
114
extern
struct
cpu
cpus
[
NCPU
];
NCPU
#define NCPU
Definition
param.h:11
NOFILE
#define NOFILE
Definition
param.h:12
cpus
struct cpu cpus[NCPU]
Definition
proc.c:20
procstate
procstate
Definition
proc.h:76
RUNNING
@ RUNNING
Definition
proc.h:76
USED
@ USED
Definition
proc.h:76
RUNNABLE
@ RUNNABLE
Definition
proc.h:76
SLEEPING
@ SLEEPING
Definition
proc.h:76
ZOMBIE
@ ZOMBIE
Definition
proc.h:76
UNUSED
@ UNUSED
Definition
proc.h:76
pagetable_t
uint64 * pagetable_t
Definition
riscv.h:523
context
Definition
proc.h:14
context::s1
uint64 s1
Definition
proc.h:20
context::s9
uint64 s9
Definition
proc.h:28
context::s0
uint64 s0
Definition
proc.h:19
context::s2
uint64 s2
Definition
proc.h:21
context::s4
uint64 s4
Definition
proc.h:23
context::s10
uint64 s10
Definition
proc.h:29
context::sp
uint64 sp
Definition
proc.h:16
context::s7
uint64 s7
Definition
proc.h:26
context::s3
uint64 s3
Definition
proc.h:22
context::s5
uint64 s5
Definition
proc.h:24
context::ra
uint64 ra
Definition
proc.h:15
context::s11
uint64 s11
Definition
proc.h:30
context::s8
uint64 s8
Definition
proc.h:27
context::s6
uint64 s6
Definition
proc.h:25
cpu
Definition
proc.h:106
cpu::proc
struct proc * proc
Definition
proc.h:107
dirent
Definition
fat32.h:31
file
Definition
file.h:11
proc
Definition
proc.h:80
proc::pagetable
pagetable_t pagetable
Definition
proc.h:96
proc::xstate
int xstate
Definition
proc.h:88
proc::state
enum procstate state
Definition
proc.h:81
proc::kstack
uint64 kstack
Definition
proc.h:94
proc::ofile
struct file * ofile[NOFILE]
Definition
proc.h:99
proc::cwd
struct dirent * cwd
Definition
proc.h:100
proc::killed
int killed
Definition
proc.h:87
proc::trapframe
struct trapframe * trapframe
Definition
proc.h:97
proc::name
char name[16]
Definition
proc.h:101
proc::parent
struct proc * parent
Definition
proc.h:91
proc::chan
void * chan
Definition
proc.h:86
proc::sz
uint64 sz
Definition
proc.h:95
proc::pid
int pid
Definition
proc.h:89
trapframe
Definition
proc.h:36
trapframe::a2
uint64 a2
Definition
proc.h:53
trapframe::epc
uint64 epc
Definition
proc.h:40
trapframe::s1
uint64 s1
Definition
proc.h:50
trapframe::s9
uint64 s9
Definition
proc.h:66
trapframe::a7
uint64 a7
Definition
proc.h:58
trapframe::s0
uint64 s0
Definition
proc.h:49
trapframe::s2
uint64 s2
Definition
proc.h:59
trapframe::a4
uint64 a4
Definition
proc.h:55
trapframe::gp
uint64 gp
Definition
proc.h:44
trapframe::kernel_trap
uint64 kernel_trap
Definition
proc.h:39
trapframe::kernel_satp
uint64 kernel_satp
Definition
proc.h:37
trapframe::tp
uint64 tp
Definition
proc.h:45
trapframe::s4
uint64 s4
Definition
proc.h:61
trapframe::t0
uint64 t0
Definition
proc.h:46
trapframe::s10
uint64 s10
Definition
proc.h:67
trapframe::t2
uint64 t2
Definition
proc.h:48
trapframe::a0
uint64 a0
Definition
proc.h:51
trapframe::a1
uint64 a1
Definition
proc.h:52
trapframe::sp
uint64 sp
Definition
proc.h:43
trapframe::s7
uint64 s7
Definition
proc.h:64
trapframe::t4
uint64 t4
Definition
proc.h:70
trapframe::s3
uint64 s3
Definition
proc.h:60
trapframe::a3
uint64 a3
Definition
proc.h:54
trapframe::s5
uint64 s5
Definition
proc.h:62
trapframe::ra
uint64 ra
Definition
proc.h:42
trapframe::kernel_hartid
uint64 kernel_hartid
Definition
proc.h:41
trapframe::s11
uint64 s11
Definition
proc.h:68
trapframe::t5
uint64 t5
Definition
proc.h:71
trapframe::a6
uint64 a6
Definition
proc.h:57
trapframe::t1
uint64 t1
Definition
proc.h:47
trapframe::t3
uint64 t3
Definition
proc.h:69
trapframe::kernel_sp
uint64 kernel_sp
Definition
proc.h:38
trapframe::s8
uint64 s8
Definition
proc.h:65
trapframe::s6
uint64 s6
Definition
proc.h:63
trapframe::t6
uint64 t6
Definition
proc.h:72
trapframe::a5
uint64 a5
Definition
proc.h:56
uint64
unsigned long uint64
Definition
types.h:24
Generated by
1.9.7