This source file includes following definitions.
- add_wait_queue
- remove_wait_queue
- select_wait
- _get_base
- get_limit
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
3
4 #define HZ 100
5
6 #define NR_TASKS 64
7 #define TASK_SIZE 0x04000000
8 #define LIBRARY_SIZE 0x00400000
9
10
11
12
13 #define IO_BITMAP_SIZE 32
14
15 #if (TASK_SIZE & 0x3fffff)
16 #error "TASK_SIZE must be multiple of 4M"
17 #endif
18
19 #if (LIBRARY_SIZE & 0x3fffff)
20 #error "LIBRARY_SIZE must be a multiple of 4M"
21 #endif
22
23 #if (LIBRARY_SIZE >= (TASK_SIZE/2))
24 #error "LIBRARY_SIZE too damn big!"
25 #endif
26
27 #if (((TASK_SIZE>>16)*NR_TASKS) != 0x10000)
28 #error "TASK_SIZE*NR_TASKS must be 4GB"
29 #endif
30
31 #define LIBRARY_OFFSET (TASK_SIZE - LIBRARY_SIZE)
32
33 #define CT_TO_SECS(x) ((x) / HZ)
34 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
35
36 #define FIRST_TASK task[0]
37 #define LAST_TASK task[NR_TASKS-1]
38
39 #include <linux/head.h>
40 #include <linux/fs.h>
41 #include <linux/mm.h>
42 #include <linux/signal.h>
43 #include <linux/time.h>
44 #include <linux/param.h>
45 #include <linux/resource.h>
46
47 #if (NR_OPEN > 32)
48 #error "Currently the close-on-exec-flags and select masks are in one long, max 32 files/proc"
49 #endif
50
51 #define TASK_RUNNING 0
52 #define TASK_INTERRUPTIBLE 1
53 #define TASK_UNINTERRUPTIBLE 2
54 #define TASK_ZOMBIE 3
55 #define TASK_STOPPED 4
56
57 #ifndef NULL
58 #define NULL ((void *) 0)
59 #endif
60
61 #define MAX_SHARED_LIBS 6
62
63 extern void sched_init(void);
64 extern void show_state(void);
65 extern void schedule(void);
66 extern void trap_init(void);
67 extern void panic(const char * str);
68
69 typedef int (*fn_ptr)();
70
71 struct i387_struct {
72 long cwd;
73 long swd;
74 long twd;
75 long fip;
76 long fcs;
77 long foo;
78 long fos;
79 long st_space[20];
80 };
81
82 struct tss_struct {
83 unsigned long back_link;
84 unsigned long esp0;
85 unsigned long ss0;
86 unsigned long esp1;
87 unsigned long ss1;
88 unsigned long esp2;
89 unsigned long ss2;
90 unsigned long cr3;
91 unsigned long eip;
92 unsigned long eflags;
93 unsigned long eax,ecx,edx,ebx;
94 unsigned long esp;
95 unsigned long ebp;
96 unsigned long esi;
97 unsigned long edi;
98 unsigned long es;
99 unsigned long cs;
100 unsigned long ss;
101 unsigned long ds;
102 unsigned long fs;
103 unsigned long gs;
104 unsigned long ldt;
105 unsigned long trace_bitmap;
106 unsigned long io_bitmap[IO_BITMAP_SIZE];
107 struct i387_struct i387;
108 };
109
110 struct task_struct {
111
112 long state;
113 long counter;
114 long priority;
115 long signal;
116 struct sigaction sigaction[32];
117 long blocked;
118
119 int exit_code;
120 int dumpable:1;
121 int swappable:1;
122 unsigned long start_code,end_code,end_data,brk,start_stack;
123 long pid,pgrp,session,leader;
124 int groups[NGROUPS];
125
126
127
128
129
130 struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
131
132
133
134
135 struct wait_queue wait;
136 unsigned short uid,euid,suid;
137 unsigned short gid,egid,sgid;
138 unsigned long timeout;
139 unsigned long it_real_value, it_prof_value, it_virt_value;
140 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
141 long utime,stime,cutime,cstime,start_time;
142 unsigned long min_flt, maj_flt;
143 unsigned long cmin_flt, cmaj_flt;
144 struct rlimit rlim[RLIM_NLIMITS];
145 unsigned int flags;
146 unsigned short used_math;
147 unsigned short rss;
148 char comm[8];
149
150 int link_count;
151 int tty;
152 unsigned short umask;
153 struct inode * pwd;
154 struct inode * root;
155 struct inode * executable;
156 struct {
157 struct inode * library;
158 unsigned long start;
159 unsigned long length;
160 } libraries[MAX_SHARED_LIBS];
161 int numlibraries;
162 struct file * filp[NR_OPEN];
163 unsigned long close_on_exec;
164
165 struct desc_struct ldt[3];
166
167 struct tss_struct tss;
168 };
169
170
171
172
173 #define PF_ALIGNWARN 0x00000001
174
175 #define PF_PTRACED 0x00000010
176 #define PF_VM86 0x00000020
177
178
179
180
181
182
183
184 #define INIT_TASK \
185 { 0,15,15, \
186 0,{{},},0, \
187 0,0,0,0,0,0,0,0, \
188 0,0,0,0, \
189 {NOGROUP,}, \
190 &init_task.task,&init_task.task,NULL,NULL,NULL, \
191 {&init_task.task,NULL}, \
192 0,0,0,0,0,0, \
193 0,0,0,0,0,0,0,0,0,0,0,0, \
194 0,0,0,0, \
195 { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
196 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
197 {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
198 0, \
199 0, \
200 2, \
201 "swapper", \
202 0,-1,0022,NULL,NULL,NULL, \
203 { { NULL, 0, 0}, }, 0, \
204 {NULL,}, 0, \
205 { \
206 {0,0}, \
207 {0x9f,0xc0fa00}, \
208 {0x9f,0xc0f200} \
209 }, \
210 {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
211 0,0,0,0,0,0,0,0, \
212 0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
213 _LDT(0),0x80000000,{0xffffffff}, \
214 {} \
215 }, \
216 }
217
218 extern struct task_struct *task[NR_TASKS];
219 extern struct task_struct *last_task_used_math;
220 extern struct task_struct *current;
221 extern unsigned long volatile jiffies;
222 extern unsigned long startup_time;
223 extern int jiffies_offset;
224
225 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
226
227 extern void add_timer(long jiffies, void (*fn)(void));
228
229 extern void sleep_on(struct wait_queue ** p);
230 extern void interruptible_sleep_on(struct wait_queue ** p);
231 extern void wake_up(struct wait_queue ** p);
232 extern void wake_one_task(struct task_struct * p);
233
234 extern int send_sig(long sig,struct task_struct * p,int priv);
235 extern int in_group_p(gid_t grp);
236
237 extern int request_irq(unsigned int irq,void (*handler)(int));
238 extern void free_irq(unsigned int irq);
239 extern int irqaction(unsigned int irq,struct sigaction * new);
240
241
242
243
244
245 #define FIRST_TSS_ENTRY 4
246 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
247 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
248 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
249 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
250 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
251 #define str(n) \
252 __asm__("str %%ax\n\t" \
253 "subl %2,%%eax\n\t" \
254 "shrl $4,%%eax" \
255 :"=a" (n) \
256 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
257
258
259
260
261
262
263 #define switch_to(n) {\
264 struct {long a,b;} __tmp; \
265 __asm__("cmpl %%ecx,_current\n\t" \
266 "je 1f\n\t" \
267 "movw %%dx,%1\n\t" \
268 "cli\n\t" \
269 "xchgl %%ecx,_current\n\t" \
270 "ljmp %0\n\t" \
271 "sti\n\t" \
272 "cmpl %%ecx,_last_task_used_math\n\t" \
273 "jne 1f\n\t" \
274 "clts\n" \
275 "1:" \
276 ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
277 "d" (_TSS(n)),"c" ((long) task[n]) \
278 :"cx"); \
279 }
280
281 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
282
283 #define _set_base(addr,base) \
284 __asm__("movw %%dx,%0\n\t" \
285 "rorl $16,%%edx\n\t" \
286 "movb %%dl,%1\n\t" \
287 "movb %%dh,%2" \
288 ::"m" (*((addr)+2)), \
289 "m" (*((addr)+4)), \
290 "m" (*((addr)+7)), \
291 "d" (base) \
292 :"dx")
293
294 #define _set_limit(addr,limit) \
295 __asm__("movw %%dx,%0\n\t" \
296 "rorl $16,%%edx\n\t" \
297 "movb %1,%%dh\n\t" \
298 "andb $0xf0,%%dh\n\t" \
299 "orb %%dh,%%dl\n\t" \
300 "movb %%dl,%1" \
301 ::"m" (*(addr)), \
302 "m" (*((addr)+6)), \
303 "d" (limit) \
304 :"dx")
305
306 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
307 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
308
309 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
310 {
311 unsigned long flags;
312 struct wait_queue * tmp;
313
314 __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
315 wait->next = *p;
316 tmp = wait;
317 while (tmp->next)
318 if ((tmp = tmp->next)->next == *p)
319 break;
320 *p = tmp->next = wait;
321 __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
322 }
323
324 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
325 {
326 unsigned long flags;
327 struct wait_queue * tmp;
328
329 __asm__ __volatile__("pushfl ; popl %0 ; cli":"=r" (flags));
330 if (*p == wait)
331 if ((*p = wait->next) == wait)
332 *p = NULL;
333 tmp = wait;
334 while (tmp && tmp->next != wait)
335 tmp = tmp->next;
336 if (tmp)
337 tmp->next = wait->next;
338 wait->next = NULL;
339 __asm__ __volatile__("pushl %0 ; popfl"::"r" (flags));
340 }
341
342 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
343 {
344 struct select_table_entry * entry = p->entry + p->nr;
345
346 if (!wait_address)
347 return;
348 entry->wait_address = wait_address;
349 entry->wait.task = current;
350 add_wait_queue(wait_address,&entry->wait);
351 p->nr++;
352 }
353
354 static unsigned long inline _get_base(char * addr)
355 {
356 unsigned long __base;
357 __asm__("movb %3,%%dh\n\t"
358 "movb %2,%%dl\n\t"
359 "shll $16,%%edx\n\t"
360 "movw %1,%%dx"
361 :"=&d" (__base)
362 :"m" (*((addr)+2)),
363 "m" (*((addr)+4)),
364 "m" (*((addr)+7)));
365 return __base;
366 }
367
368 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
369
370 static unsigned long inline get_limit(unsigned long segment)
371 {
372 unsigned long __limit;
373 __asm__("lsll %1,%0"
374 :"=r" (__limit):"r" (segment));
375 return __limit+1;
376 }
377
378 #define REMOVE_LINKS(p) \
379 if ((p)->p_osptr) \
380 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
381 if ((p)->p_ysptr) \
382 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
383 else \
384 (p)->p_pptr->p_cptr = (p)->p_osptr
385
386 #define SET_LINKS(p) \
387 (p)->p_ysptr = NULL; \
388 if ((p)->p_osptr = (p)->p_pptr->p_cptr) \
389 (p)->p_osptr->p_ysptr = p; \
390 (p)->p_pptr->p_cptr = p
391
392 #endif