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 {
|
37
|
73 int n;
|
32
|
74 int target;
|
|
75 char* dst;
|
|
76 struct inode *ip;
|
|
77 struct file *f;
|
|
78 int num;
|
37
|
79 struct pipe *p;
|
|
80 char *addr;
|
|
81 int i;
|
32
|
82 __code (*next)(int ret);
|
26
|
83 } cbc_console_arg;
|
25
|
84 } cbc_arg;
|
|
85 __code (*cbc_next)();
|
27
|
86 struct spinlock *lk;
|
0
|
87 };
|
|
88
|
80
|
89 // typedef struct context_interface<Type,Imple>{
|
|
90 // // union Data* stack;
|
|
91 // // union Data* data;
|
|
92 //
|
|
93 // // __code push(Impl* stack,Type* data, __code next(...));
|
|
94 // // __code next(...);
|
|
95 //
|
|
96 // union Data* stack;
|
|
97 // union Data* data;
|
|
98 // union Data* data1;
|
|
99 // enum Code whenEmpty;
|
|
100 // enum Code clear;
|
|
101 // enum Code push;
|
|
102 // enum Code pop;
|
|
103 // enum Code pop2;
|
|
104 // enum Code isEmpty;
|
|
105 // enum Code get;
|
|
106 // enum Code get2;
|
|
107 // enum Code next;
|
|
108 // }context_interface;
|
|
109
|
|
110
|
0
|
111 // Process memory is laid out contiguously, low addresses first:
|
|
112 // text
|
|
113 // original data and bss
|
|
114 // fixed-size stack
|
|
115 // expandable heap
|
|
116 #endif
|