kernel/proc.h
107 lines
1// Saved registers for kernel context switches.2struct context {3 uint64 ra;4 uint64 sp;56 // callee-saved7 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};2021// Per-CPU state.22struct 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};2829extern struct cpu cpus[NCPU];3031// per-process data for the trap handling code in trampoline.S.32// sits in a page by itself just under the trampoline page in the33// 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's36// kernel_sp, kernel_hartid, kernel_satp, and jumps to kernel_trap.37// usertrapret() and userret in trampoline.S set up38// the trapframe's kernel_*, restore user registers from the39// trapframe, switch to the user page table, and enter user space.40// the trapframe includes callee-saved user registers like s0-s11 because the41// return-to-user path via usertrapret() doesn't return through42// the entire kernel call stack.43struct trapframe {44 /* 0 */ uint64 kernel_satp; // kernel page table45 /* 8 */ uint64 kernel_sp; // top of process's kernel stack46 /* 16 */ uint64 kernel_trap; // usertrap()47 /* 24 */ uint64 epc; // saved user program counter48 /* 32 */ uint64 kernel_hartid; // saved kernel tp49 /* 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};8182enum procstate { UNUSED, USED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };8384// Per-process state85struct proc {86 struct spinlock lock;8788 // p->lock must be held when using these:89 enum procstate state; // Process state90 void *chan; // If non-zero, sleeping on chan91 int killed; // If non-zero, have been killed92 int xstate; // Exit status to be returned to parent's wait93 int pid; // Process ID9495 // wait_lock must be held when using this:96 struct proc *parent; // Parent process9798 // these are private to the process, so p->lock need not be held.99 uint64 kstack; // Virtual address of kernel stack100 uint64 sz; // Size of process memory (bytes)101 pagetable_t pagetable; // User page table102 struct trapframe *trapframe; // data page for trampoline.S103 struct context context; // swtch() here to run process104 struct file *ofile[NOFILE]; // Open files105 struct inode *cwd; // Current directory106 char name[16]; // Process name (debugging)107};108