26
|
1 #include "typedefData.h"
|
0
|
2 #ifndef PROC_INCLUDE_
|
|
3 #define PROC_INCLUDE_
|
|
4
|
|
5 // Per-CPU state, now we only support one CPU
|
|
6 struct cpu {
|
|
7 uchar id; // index into cpus[] below
|
|
8 struct context* scheduler; // swtch() here to enter scheduler
|
|
9 volatile uint started; // Has the CPU started?
|
|
10
|
|
11 int ncli; // Depth of pushcli nesting.
|
|
12 int intena; // Were interrupts enabled before pushcli?
|
|
13
|
|
14 // Cpu-local storage variables; see below
|
|
15 struct cpu* cpu;
|
|
16 struct proc* proc; // The currently-running process.
|
|
17 };
|
|
18
|
|
19 extern struct cpu cpus[NCPU];
|
|
20 extern int ncpu;
|
|
21
|
|
22
|
|
23 extern struct cpu* cpu;
|
|
24 extern struct proc* proc;
|
|
25
|
|
26 //PAGEBREAK: 17
|
|
27 // Saved registers for kernel context switches. The context switcher
|
|
28 // needs to save the callee save register, as usually. For ARM, it is
|
|
29 // also necessary to save the banked sp (r13) and lr (r14) registers.
|
|
30 // There is, however, no need to save the user space pc (r15) because
|
|
31 // pc has been saved on the stack somewhere. We only include it here
|
|
32 // for debugging purpose. It will not be restored for the next process.
|
|
33 // According to ARM calling convension, r0-r3 is caller saved. We do
|
|
34 // not need to save sp_svc, as it will be saved in the pcb, neither
|
|
35 // pc_svc, as it will be always be the same value.
|
|
36 //
|
|
37 // Keep it in sync with swtch.S
|
|
38 //
|
|
39 struct context {
|
|
40 // svc mode registers
|
|
41 uint r4;
|
|
42 uint r5;
|
|
43 uint r6;
|
|
44 uint r7;
|
|
45 uint r8;
|
|
46 uint r9;
|
|
47 uint r10;
|
|
48 uint r11;
|
|
49 uint r12;
|
|
50 uint lr;
|
|
51 };
|
|
52
|
|
53
|
|
54 enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
|
|
55
|
|
56 // Per-process state
|
|
57 struct proc {
|
|
58 uint sz; // Size of process memory (bytes)
|
|
59 pde_t* pgdir; // Page table
|
|
60 char* kstack; // Bottom of kernel stack for this process
|
|
61 enum procstate state; // Process state
|
|
62 volatile int pid; // Process ID
|
|
63 struct proc* parent; // Parent process
|
|
64 struct trapframe* tf; // Trap frame for current syscall
|
|
65 struct context* context; // swtch() here to run process
|
|
66 void* chan; // If non-zero, sleeping on chan
|
|
67 int killed; // If non-zero, have been killed
|
|
68 struct file* ofile[NOFILE]; // Open files
|
|
69 struct inode* cwd; // Current directory
|
|
70 char name[16]; // Process name (debugging)
|
25
|
71 union cbc_arg {
|
|
72 struct cbc_console_arg {
|
|
73 int n;
|
26
|
74 int target;
|
25
|
75 char* dst;
|
|
76 struct inode *ip;
|
31
|
77 struct file *f;
|
26
|
78 __code (*next)(int ret);
|
|
79 } cbc_console_arg;
|
25
|
80 } cbc_arg;
|
|
81 __code (*cbc_next)();
|
27
|
82 struct spinlock *lk;
|
0
|
83 };
|
|
84
|
|
85 // Process memory is laid out contiguously, low addresses first:
|
|
86 // text
|
|
87 // original data and bss
|
|
88 // fixed-size stack
|
|
89 // expandable heap
|
|
90 #endif
|