1 // Saved registers for kernel context switches.
2 struct context {
3 uint64 ra;
4 uint64 sp;
5
6 // callee-saved
7 uint64 s0;
8 uint64 s1;
9 uint64 s2;
10 uint64 s3;
11 uint64 s4;
12 uint64 s5;
13 uint64 s6;
14 uint64 s7;
15 uint64 s8;
16 uint64 s9;
17 uint64 s10;
18 uint64 s11;
19 };
20
21 // Per-CPU state.
22 struct cpu {
23 struct proc *proc; // The process running on this cpu, or null.
24 struct context context; // swtch() here to enter scheduler().
25 int noff; // Depth of push_off() nesting.
26 int intena; // Were interrupts enabled before push_off()?
27 };
28
29 extern struct cpu cpus[NCPU];
30
31 // per-process data for the trap handling code in trampoline.S.
32 // sits in a page by itself just under the trampoline page in the
33 // user page table. not specially mapped in the kernel page table.
34 // uservec in trampoline.S saves user registers in the trapframe,
35 // then initializes registers from the trapframe's
36 // kernel_sp, kernel_hartid, kernel_satp, and jumps to kernel_trap.
37 // usertrapret() and userret in trampoline.S set up
38 // the trapframe's kernel_*, restore user registers from the
39 // trapframe, switch to the user page table, and enter user space.
40 // the trapframe includes callee-saved user registers like s0-s11 because the
41 // return-to-user path via usertrapret() doesn't return through
42 // the entire kernel call stack.
43 struct trapframe {
44 /* 0 */ uint64 kernel_satp; // kernel page table
45 /* 8 */ uint64 kernel_sp; // top of process's kernel stack
46 /* 16 */ uint64 kernel_trap; // usertrap()
47 /* 24 */ uint64 epc; // saved user program counter
48 /* 32 */ uint64 kernel_hartid; // saved kernel tp
49 /* 40 */ uint64 ra;
50 /* 48 */ uint64 sp;
51 /* 56 */ uint64 gp;
52 /* 64 */ uint64 tp;
53 /* 72 */ uint64 t0;
54 /* 80 */ uint64 t1;
55 /* 88 */ uint64 t2;
56 /* 96 */ uint64 s0;
57 /* 104 */ uint64 s1;
58 /* 112 */ uint64 a0;
59 /* 120 */ uint64 a1;
60 /* 128 */ uint64 a2;
61 /* 136 */ uint64 a3;
62 /* 144 */ uint64 a4;
63 /* 152 */ uint64 a5;
64 /* 160 */ uint64 a6;
65 /* 168 */ uint64 a7;
66 /* 176 */ uint64 s2;
67 /* 184 */ uint64 s3;
68 /* 192 */ uint64 s4;
69 /* 200 */ uint64 s5;
70 /* 208 */ uint64 s6;
71 /* 216 */ uint64 s7;
72 /* 224 */ uint64 s8;
73 /* 232 */ uint64 s9;
74 /* 240 */ uint64 s10;
75 /* 248 */ uint64 s11;
76 /* 256 */ uint64 t3;
77 /* 264 */ uint64 t4;
78 /* 272 */ uint64 t5;
79 /* 280 */ uint64 t6;
80 };
81
82 enum procstate { UNUSED, USED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
83
84 // Per-process state
85 struct proc {
86 struct spinlock lock;
87
88 // p->lock must be held when using these:
89 enum procstate state; // Process state
90 void *chan; // If non-zero, sleeping on chan
91 int killed; // If non-zero, have been killed
92 int xstate; // Exit status to be returned to parent's wait
93 int pid; // Process ID
94
95 // wait_lock must be held when using this:
96 struct proc *parent; // Parent process
97
98 // these are private to the process, so p->lock need not be held.
99 uint64 kstack; // Virtual address of kernel stack
100 uint64 sz; // Size of process memory (bytes)
101 pagetable_t pagetable; // User page table
102 struct trapframe *trapframe; // data page for trampoline.S
103 struct context context; // swtch() here to run process
104 struct file *ofile[NOFILE]; // Open files
105 struct inode *cwd; // Current directory
106 char name[16]; // Process name (debugging)
107 };