comparison include/proc.h @ 0:c450faca55f4

Init
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Sun, 22 Oct 2017 18:25:39 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c450faca55f4
1 /*****************************************************************
2 * proc.h
3 * adapted from MIT xv6 by Zhiyi Huang, hzy@cs.otago.ac.nz
4 * University of Otago
5 *
6 ********************************************************************/
7
8
9
10 // Segments in proc->gdt.
11 #define NSEGS 7
12
13 // Per-CPU state
14 struct cpu {
15 uchar id; // Local APIC ID; index into cpus[] below
16 struct context *scheduler; // swtch() here to enter scheduler
17 volatile uint started; // Has the CPU started?
18 int ncli; // Depth of pushcli nesting.
19 int intena; // Were interrupts enabled before pushcli?
20
21 // Cpu-local storage variables; see below
22 struct cpu *cpu;
23 struct proc *proc; // The currently-running process.
24 };
25
26 struct cpu cpus[NCPU];
27 //extern int ncpu;
28
29 // Per-CPU variables, holding pointers to the
30 // current cpu and to the current process.
31 // The asm suffix tells gcc to use "%gs:0" to refer to cpu
32 // and "%gs:4" to refer to proc. seginit sets up the
33 // %gs segment register so that %gs refers to the memory
34 // holding those two variables in the local cpu's struct cpu.
35 // This is similar to how thread-local variables are implemented
36 // in thread libraries such as Linux pthreads.
37 //extern struct cpu *cpu asm("%gs:0"); // &cpus[cpunum()]
38 //extern struct proc *proc asm("%gs:4"); // cpus[cpunum()].proc
39
40 #define curr_cpu (&cpus[0])
41 #define curr_proc (cpus[0].proc)
42
43 //PAGEBREAK: 17
44 // Saved registers for kernel context switches.
45 // Don't need to save all the segment registers (%cs, etc),
46 // because they are constant across kernel contexts.
47 // Don't need to save %eax, %ecx, %edx, because the
48 // x86 convention is that the caller has saved them.
49 // Contexts are stored at the bottom of the stack they
50 // describe; the stack pointer is the address of the context.
51 // The layout of the context matches the layout of the stack in swtch.S
52 // at the "Switch stacks" comment. Switch doesn't save eip explicitly,
53 // but it is on the stack and allocproc() manipulates it.
54 struct context {
55 uint r4;
56 uint r5;
57 uint r6;
58 uint r7;
59 uint r8;
60 uint r9;
61 uint r10;
62 uint r11;
63 uint r12;
64 uint lr;
65 uint pc;
66 };
67
68 enum procstate { UNUSED=0, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
69
70 // Per-process state
71 struct proc {
72 uint sz; // Size of process memory (bytes)
73 pde_t* pgdir; // Page table
74 char *kstack; // Bottom of kernel stack for this process
75 enum procstate state; // Process state
76 volatile int pid; // Process ID
77 struct proc *parent; // Parent process
78 struct trapframe *tf; // Trap frame for current syscall
79 struct context *context; // swtch() here to run process
80 void *chan; // If non-zero, sleeping on chan
81 int killed; // If non-zero, have been killed
82 struct file *ofile[NOFILE]; // Open files
83 struct inode *cwd; // Current directory
84 char name[16]; // Process name (debugging)
85 };
86
87 // Process memory is laid out contiguously, low addresses first:
88 // text
89 // original data and bss
90 // fixed-size stack
91 // expandable heap