1d8828817SAustin Clements // Per-CPU state 2d8828817SAustin Clements struct cpu { 3ae15515dSFrans Kaashoek uchar apicid; // Local APIC ID 4faad047aSRobert Morris struct context *scheduler; // swtch() here to enter scheduler 5d8828817SAustin Clements struct taskstate ts; // Used by x86 to find stack for interrupt 6d8828817SAustin Clements struct segdesc gdt[NSEGS]; // x86 global descriptor table 7a4b213cfSFrans Kaashoek volatile uint started; // Has the CPU started? 8d8828817SAustin Clements int ncli; // Depth of pushcli nesting. 9d8828817SAustin Clements int intena; // Were interrupts enabled before pushcli? 10*ed396c06SFrans Kaashoek struct proc *proc; // The process running on this cpu or null 11d8828817SAustin Clements }; 12d8828817SAustin Clements 13d8828817SAustin Clements extern struct cpu cpus[NCPU]; 14d8828817SAustin Clements extern int ncpu; 15d8828817SAustin Clements 16d8828817SAustin Clements //PAGEBREAK: 17 1731085bb4Srsc // Saved registers for kernel context switches. 18c100d9eeSkolya // Don't need to save all the segment registers (%cs, etc), 1931085bb4Srsc // because they are constant across kernel contexts. 2019333efbSrsc // Don't need to save %eax, %ecx, %edx, because the 2119333efbSrsc // x86 convention is that the caller has saved them. 2219333efbSrsc // Contexts are stored at the bottom of the stack they 2319333efbSrsc // describe; the stack pointer is the address of the context. 24fb486874SFrans Kaashoek // The layout of the context matches the layout of the stack in swtch.S 25c4cc10daSRobert Morris // at the "Switch stacks" comment. Switch doesn't save eip explicitly, 26ab777a9aSFrans Kaashoek // but it is on the stack and allocproc() manipulates it. 27818fc012Srsc struct context { 28c100d9eeSkolya uint edi; 29c100d9eeSkolya uint esi; 30c100d9eeSkolya uint ebx; 31c100d9eeSkolya uint ebp; 32c100d9eeSkolya uint eip; 335ce9751cSrsc }; 345ce9751cSrsc 3534295f46Srsc enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; 364e8f237bSrtm 3731085bb4Srsc // Per-process state 3855e95b16Srtm struct proc { 3931085bb4Srsc uint sz; // Size of process memory (bytes) 40faad047aSRobert Morris pde_t* pgdir; // Page table 4131085bb4Srsc char *kstack; // Bottom of kernel stack for this process 4234295f46Srsc enum procstate state; // Process state 43020c8e23SRobert Morris int pid; // Process ID 44b1fb19b6Srsc struct proc *parent; // Parent process 4519333efbSrsc struct trapframe *tf; // Trap frame for current syscall 46faad047aSRobert Morris struct context *context; // swtch() here to run process 4731085bb4Srsc void *chan; // If non-zero, sleeping on chan 4831085bb4Srsc int killed; // If non-zero, have been killed 4931085bb4Srsc struct file *ofile[NOFILE]; // Open files 5007090dd7Srsc struct inode *cwd; // Current directory 517366e042Srsc char name[16]; // Process name (debugging) 5231085bb4Srsc }; 5331085bb4Srsc 5420365348Srtm // Process memory is laid out contiguously, low addresses first: 55f5527388Srsc // text 56f5527388Srsc // original data and bss 57f5527388Srsc // fixed-size stack 58f5527388Srsc // expandable heap 59