diff options
Diffstat (limited to 'src/include/linux/sched.h')
-rw-r--r-- | src/include/linux/sched.h | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/src/include/linux/sched.h b/src/include/linux/sched.h new file mode 100644 index 0000000..e1b35be --- /dev/null +++ b/src/include/linux/sched.h | |||
@@ -0,0 +1,256 @@ | |||
1 | #ifndef _SCHED_H | ||
2 | #define _SCHED_H | ||
3 | |||
4 | #define NR_TASKS 64 | ||
5 | #define HZ 100 | ||
6 | |||
7 | #define FIRST_TASK task[0] | ||
8 | #define LAST_TASK task[NR_TASKS-1] | ||
9 | |||
10 | #include <linux/head.h> | ||
11 | #include <linux/fs.h> | ||
12 | #include <linux/mm.h> | ||
13 | #include <signal.h> | ||
14 | |||
15 | #if (NR_OPEN > 32) | ||
16 | #error "Currently the close-on-exec-flags are in one word, max 32 files/proc" | ||
17 | #endif | ||
18 | |||
19 | #define TASK_RUNNING 0 | ||
20 | #define TASK_INTERRUPTIBLE 1 | ||
21 | #define TASK_UNINTERRUPTIBLE 2 | ||
22 | #define TASK_ZOMBIE 3 | ||
23 | #define TASK_STOPPED 4 | ||
24 | |||
25 | #ifndef NULL | ||
26 | #define NULL ((void *) 0) | ||
27 | #endif | ||
28 | |||
29 | extern int copy_page_tables(unsigned long from, unsigned long to, long size); | ||
30 | extern int free_page_tables(unsigned long from, unsigned long size); | ||
31 | |||
32 | extern void sched_init(void); | ||
33 | extern void schedule(void); | ||
34 | extern void trap_init(void); | ||
35 | #ifndef PANIC | ||
36 | void panic(const char * str); | ||
37 | #endif | ||
38 | extern int tty_write(unsigned minor,char * buf,int count); | ||
39 | |||
40 | typedef int (*fn_ptr)(); | ||
41 | |||
42 | struct i387_struct { | ||
43 | long cwd; | ||
44 | long swd; | ||
45 | long twd; | ||
46 | long fip; | ||
47 | long fcs; | ||
48 | long foo; | ||
49 | long fos; | ||
50 | long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */ | ||
51 | }; | ||
52 | |||
53 | struct tss_struct { | ||
54 | long back_link; /* 16 high bits zero */ | ||
55 | long esp0; | ||
56 | long ss0; /* 16 high bits zero */ | ||
57 | long esp1; | ||
58 | long ss1; /* 16 high bits zero */ | ||
59 | long esp2; | ||
60 | long ss2; /* 16 high bits zero */ | ||
61 | long cr3; | ||
62 | long eip; | ||
63 | long eflags; | ||
64 | long eax,ecx,edx,ebx; | ||
65 | long esp; | ||
66 | long ebp; | ||
67 | long esi; | ||
68 | long edi; | ||
69 | long es; /* 16 high bits zero */ | ||
70 | long cs; /* 16 high bits zero */ | ||
71 | long ss; /* 16 high bits zero */ | ||
72 | long ds; /* 16 high bits zero */ | ||
73 | long fs; /* 16 high bits zero */ | ||
74 | long gs; /* 16 high bits zero */ | ||
75 | long ldt; /* 16 high bits zero */ | ||
76 | long trace_bitmap; /* bits: trace 0, bitmap 16-31 */ | ||
77 | struct i387_struct i387; | ||
78 | }; | ||
79 | |||
80 | struct task_struct { | ||
81 | /* these are hardcoded - don't touch */ | ||
82 | long state; /* -1 unrunnable, 0 runnable, >0 stopped */ | ||
83 | long counter; | ||
84 | long priority; | ||
85 | long signal; | ||
86 | struct sigaction sigaction[32]; | ||
87 | long blocked; /* bitmap of masked signals */ | ||
88 | /* various fields */ | ||
89 | int exit_code; | ||
90 | unsigned long start_code,end_code,end_data,brk,start_stack; | ||
91 | long pid,father,pgrp,session,leader; | ||
92 | unsigned short uid,euid,suid; | ||
93 | unsigned short gid,egid,sgid; | ||
94 | long alarm; | ||
95 | long utime,stime,cutime,cstime,start_time; | ||
96 | unsigned short used_math; | ||
97 | /* file system info */ | ||
98 | int tty; /* -1 if no tty, so it must be signed */ | ||
99 | unsigned short umask; | ||
100 | struct m_inode * pwd; | ||
101 | struct m_inode * root; | ||
102 | struct m_inode * executable; | ||
103 | unsigned long close_on_exec; | ||
104 | struct file * filp[NR_OPEN]; | ||
105 | /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */ | ||
106 | struct desc_struct ldt[3]; | ||
107 | /* tss for this task */ | ||
108 | struct tss_struct tss; | ||
109 | }; | ||
110 | |||
111 | /* | ||
112 | * INIT_TASK is used to set up the first task table, touch at | ||
113 | * your own risk!. Base=0, limit=0x9ffff (=640kB) | ||
114 | */ | ||
115 | #define INIT_TASK \ | ||
116 | /* state etc */ { 0,15,15, \ | ||
117 | /* signals */ 0,{{},},0, \ | ||
118 | /* ec,brk... */ 0,0,0,0,0,0, \ | ||
119 | /* pid etc.. */ 0,-1,0,0,0, \ | ||
120 | /* uid etc */ 0,0,0,0,0,0, \ | ||
121 | /* alarm */ 0,0,0,0,0,0, \ | ||
122 | /* math */ 0, \ | ||
123 | /* fs info */ -1,0022,NULL,NULL,NULL,0, \ | ||
124 | /* filp */ {NULL,}, \ | ||
125 | { \ | ||
126 | {0,0}, \ | ||
127 | /* ldt */ {0x9f,0xc0fa00}, \ | ||
128 | {0x9f,0xc0f200}, \ | ||
129 | }, \ | ||
130 | /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\ | ||
131 | 0,0,0,0,0,0,0,0, \ | ||
132 | 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \ | ||
133 | _LDT(0),0x80000000, \ | ||
134 | {} \ | ||
135 | }, \ | ||
136 | } | ||
137 | |||
138 | extern struct task_struct *task[NR_TASKS]; | ||
139 | extern struct task_struct *last_task_used_math; | ||
140 | extern struct task_struct *current; | ||
141 | extern long volatile jiffies; | ||
142 | extern long startup_time; | ||
143 | |||
144 | #define CURRENT_TIME (startup_time+jiffies/HZ) | ||
145 | |||
146 | extern void add_timer(long jiffies, void (*fn)(void)); | ||
147 | extern void sleep_on(struct task_struct ** p); | ||
148 | extern void interruptible_sleep_on(struct task_struct ** p); | ||
149 | extern void wake_up(struct task_struct ** p); | ||
150 | |||
151 | /* | ||
152 | * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall | ||
153 | * 4-TSS0, 5-LDT0, 6-TSS1 etc ... | ||
154 | */ | ||
155 | #define FIRST_TSS_ENTRY 4 | ||
156 | #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1) | ||
157 | #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3)) | ||
158 | #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3)) | ||
159 | #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n))) | ||
160 | #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n))) | ||
161 | #define str(n) \ | ||
162 | __asm__("str %%ax\n\t" \ | ||
163 | "subl %2,%%eax\n\t" \ | ||
164 | "shrl $4,%%eax" \ | ||
165 | :"=a" (n) \ | ||
166 | :"a" (0),"i" (FIRST_TSS_ENTRY<<3)) | ||
167 | /* | ||
168 | * switch_to(n) should switch tasks to task nr n, first | ||
169 | * checking that n isn't the current task, in which case it does nothing. | ||
170 | * This also clears the TS-flag if the task we switched to has used | ||
171 | * tha math co-processor latest. | ||
172 | */ | ||
173 | #define switch_to(n) {\ | ||
174 | struct {long a,b;} __tmp; \ | ||
175 | __asm__("cmpl %%ecx,current\n\t" \ | ||
176 | "je 1f\n\t" \ | ||
177 | "movw %%dx,%1\n\t" \ | ||
178 | "xchgl %%ecx,current\n\t" \ | ||
179 | "ljmp *%0\n\t" \ | ||
180 | "cmpl %%ecx,last_task_used_math\n\t" \ | ||
181 | "jne 1f\n\t" \ | ||
182 | "clts\n" \ | ||
183 | "1:" \ | ||
184 | ::"m" (*&__tmp.a),"m" (*&__tmp.b), \ | ||
185 | "d" (_TSS(n)),"c" ((long) task[n])); \ | ||
186 | } | ||
187 | |||
188 | #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000) | ||
189 | |||
190 | #define _set_base(addr,base) \ | ||
191 | __asm__ ("push %%edx\n\t" \ | ||
192 | "movw %%dx,%0\n\t" \ | ||
193 | "rorl $16,%%edx\n\t" \ | ||
194 | "movb %%dl,%1\n\t" \ | ||
195 | "movb %%dh,%2\n\t" \ | ||
196 | "pop %%edx" \ | ||
197 | ::"m" (*((addr)+2)), \ | ||
198 | "m" (*((addr)+4)), \ | ||
199 | "m" (*((addr)+7)), \ | ||
200 | "d" (base) \ | ||
201 | ) | ||
202 | |||
203 | #define _set_limit(addr,limit) \ | ||
204 | __asm__ ("push %%edx\n\t" \ | ||
205 | "movw %%dx,%0\n\t" \ | ||
206 | "rorl $16,%%edx\n\t" \ | ||
207 | "movb %1,%%dh\n\t" \ | ||
208 | "andb $0xf0,%%dh\n\t" \ | ||
209 | "orb %%dh,%%dl\n\t" \ | ||
210 | "movb %%dl,%1\n\t" \ | ||
211 | "pop %%edx" \ | ||
212 | ::"m" (*(addr)), \ | ||
213 | "m" (*((addr)+6)), \ | ||
214 | "d" (limit) \ | ||
215 | ) | ||
216 | |||
217 | #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , (base) ) | ||
218 | #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 ) | ||
219 | |||
220 | /** | ||
221 | #define _get_base(addr) ({\ | ||
222 | unsigned long __base; \ | ||
223 | __asm__("movb %3,%%dh\n\t" \ | ||
224 | "movb %2,%%dl\n\t" \ | ||
225 | "shll $16,%%edx\n\t" \ | ||
226 | "movw %1,%%dx" \ | ||
227 | :"=d" (__base) \ | ||
228 | :"m" (*((addr)+2)), \ | ||
229 | "m" (*((addr)+4)), \ | ||
230 | "m" (*((addr)+7)) \ | ||
231 | :"memory"); \ | ||
232 | __base;}) | ||
233 | **/ | ||
234 | |||
235 | static inline unsigned long _get_base(char * addr) | ||
236 | { | ||
237 | unsigned long __base; | ||
238 | __asm__("movb %3,%%dh\n\t" | ||
239 | "movb %2,%%dl\n\t" | ||
240 | "shll $16,%%edx\n\t" | ||
241 | "movw %1,%%dx" | ||
242 | :"=&d" (__base) | ||
243 | :"m" (*((addr)+2)), | ||
244 | "m" (*((addr)+4)), | ||
245 | "m" (*((addr)+7))); | ||
246 | return __base; | ||
247 | } | ||
248 | |||
249 | #define get_base(ldt) _get_base( ((char *)&(ldt)) ) | ||
250 | |||
251 | #define get_limit(segment) ({ \ | ||
252 | unsigned long __limit; \ | ||
253 | __asm__("lsll %1,%0\n\tincl %0":"=r" (__limit):"r" (segment)); \ | ||
254 | __limit;}) | ||
255 | |||
256 | #endif | ||