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 // prepare_return() 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 struct trapframe {
41 /* 0 */ uint64 kernel_satp; // kernel page table
42 /* 8 */ uint64 kernel_sp; // top of process's kernel stack
43 /* 16 */ uint64 kernel_trap; // usertrap()
44 /* 24 */ uint64 epc; // saved user program counter
45 /* 32 */ uint64 kernel_hartid; // saved kernel tp
46 /* 40 */ uint64 ra;
47 /* 48 */ uint64 sp;
48 /* 56 */ uint64 gp;
49 /* 64 */ uint64 tp;
50 /* 72 */ uint64 t0;
51 /* 80 */ uint64 t1;
52 /* 88 */ uint64 t2;
53 /* 96 */ uint64 s0;
54 /* 104 */ uint64 s1;
55 /* 112 */ uint64 a0;
56 /* 120 */ uint64 a1;
57 /* 128 */ uint64 a2;
58 /* 136 */ uint64 a3;
59 /* 144 */ uint64 a4;
60 /* 152 */ uint64 a5;
61 /* 160 */ uint64 a6;
62 /* 168 */ uint64 a7;
63 /* 176 */ uint64 s2;
64 /* 184 */ uint64 s3;
65 /* 192 */ uint64 s4;
66 /* 200 */ uint64 s5;
67 /* 208 */ uint64 s6;
68 /* 216 */ uint64 s7;
69 /* 224 */ uint64 s8;
70 /* 232 */ uint64 s9;
71 /* 240 */ uint64 s10;
72 /* 248 */ uint64 s11;
73 /* 256 */ uint64 t3;
74 /* 264 */ uint64 t4;
75 /* 272 */ uint64 t5;
76 /* 280 */ uint64 t6;
77 };
78
79 enum procstate { UNUSED, USED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
80
81 // Per-process state
82 struct proc {
83 struct spinlock lock;
84
85 // p->lock must be held when using these:
86 enum procstate state; // Process state
87 void *chan; // If non-zero, sleeping on chan
88 int killed; // If non-zero, have been killed
89 int xstate; // Exit status to be returned to parent's wait
90 int pid; // Process ID
91
92 // wait_lock must be held when using this:
93 struct proc *parent; // Parent process
94
95 // these are private to the process, so p->lock need not be held.
96 uint64 kstack; // Virtual address of kernel stack
97 uint64 sz; // Size of process memory (bytes)
98 pagetable_t pagetable; // User page table
99 struct trapframe *trapframe; // data page for trampoline.S
100 struct context context; // swtch() here to run process
101 struct file *ofile[NOFILE]; // Open files
102 struct inode *cwd; // Current directory
103 char name[16]; // Process name (debugging)
104 };