This source file includes following definitions.
- add_wait_queue
- remove_wait_queue
- select_wait
- down
- up
- _get_base
- get_limit
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
3
4 #define NEW_SWAP
5
6
7
8
9
10
11
12
13
14 #define HZ 100
15
16
17
18
19 extern int hard_math;
20 extern int x86;
21 extern int ignore_irq13;
22 extern int wp_works_ok;
23
24 extern unsigned long intr_count;
25
26 #define start_bh_atomic() \
27 __asm__ __volatile__("incl _intr_count")
28
29 #define end_bh_atomic() \
30 __asm__ __volatile__("decl _intr_count")
31
32
33
34
35
36 extern int EISA_bus;
37 #define MCA_bus 0
38
39 #include <linux/binfmts.h>
40 #include <linux/personality.h>
41 #include <linux/tasks.h>
42 #include <asm/system.h>
43
44
45
46
47
48 #define TASK_SIZE 0xc0000000
49
50
51
52
53 #define IO_BITMAP_SIZE 32
54
55
56
57
58
59
60
61
62
63
64
65 extern unsigned long avenrun[];
66
67 #define FSHIFT 11
68 #define FIXED_1 (1<<FSHIFT)
69 #define LOAD_FREQ (5*HZ)
70 #define EXP_1 1884
71 #define EXP_5 2014
72 #define EXP_15 2037
73
74 #define CALC_LOAD(load,exp,n) \
75 load *= exp; \
76 load += n*(FIXED_1-exp); \
77 load >>= FSHIFT;
78
79 #define CT_TO_SECS(x) ((x) / HZ)
80 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
81
82 #define FIRST_TASK task[0]
83 #define LAST_TASK task[NR_TASKS-1]
84
85 #include <linux/head.h>
86 #include <linux/fs.h>
87 #include <linux/mm.h>
88 #include <linux/signal.h>
89 #include <linux/time.h>
90 #include <linux/param.h>
91 #include <linux/resource.h>
92 #include <linux/vm86.h>
93 #include <linux/math_emu.h>
94 #include <linux/ptrace.h>
95
96 #define TASK_RUNNING 0
97 #define TASK_INTERRUPTIBLE 1
98 #define TASK_UNINTERRUPTIBLE 2
99 #define TASK_ZOMBIE 3
100 #define TASK_STOPPED 4
101 #define TASK_SWAPPING 5
102
103 #ifndef NULL
104 #define NULL ((void *) 0)
105 #endif
106
107 #ifdef __KERNEL__
108
109 extern void sched_init(void);
110 extern void show_state(void);
111 extern void trap_init(void);
112
113 asmlinkage void schedule(void);
114
115 #endif
116
117 struct i387_hard_struct {
118 long cwd;
119 long swd;
120 long twd;
121 long fip;
122 long fcs;
123 long foo;
124 long fos;
125 long st_space[20];
126 };
127
128 struct i387_soft_struct {
129 long cwd;
130 long swd;
131 long twd;
132 long fip;
133 long fcs;
134 long foo;
135 long fos;
136 long top;
137 struct fpu_reg regs[8];
138 unsigned char lookahead;
139 struct info *info;
140 unsigned long entry_eip;
141 };
142
143 union i387_union {
144 struct i387_hard_struct hard;
145 struct i387_soft_struct soft;
146 };
147
148 struct tss_struct {
149 unsigned short back_link,__blh;
150 unsigned long esp0;
151 unsigned short ss0,__ss0h;
152 unsigned long esp1;
153 unsigned short ss1,__ss1h;
154 unsigned long esp2;
155 unsigned short ss2,__ss2h;
156 unsigned long cr3;
157 unsigned long eip;
158 unsigned long eflags;
159 unsigned long eax,ecx,edx,ebx;
160 unsigned long esp;
161 unsigned long ebp;
162 unsigned long esi;
163 unsigned long edi;
164 unsigned short es, __esh;
165 unsigned short cs, __csh;
166 unsigned short ss, __ssh;
167 unsigned short ds, __dsh;
168 unsigned short fs, __fsh;
169 unsigned short gs, __gsh;
170 unsigned short ldt, __ldth;
171 unsigned short trace, bitmap;
172 unsigned long io_bitmap[IO_BITMAP_SIZE+1];
173 unsigned long tr;
174 unsigned long cr2, trap_no, error_code;
175 union i387_union i387;
176 };
177
178 #define INIT_TSS { \
179 0,0, \
180 sizeof(init_kernel_stack) + (long) &init_kernel_stack, \
181 KERNEL_DS, 0, \
182 0,0,0,0,0,0, \
183 (long) &swapper_pg_dir, \
184 0,0,0,0,0,0,0,0,0,0, \
185 USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0,USER_DS,0, \
186 _LDT(0),0, \
187 0, 0x8000, \
188 {~0, }, \
189 _TSS(0), 0, 0,0, \
190 { { 0, }, } \
191 }
192
193 struct files_struct {
194 int count;
195 fd_set close_on_exec;
196 struct file * fd[NR_OPEN];
197 };
198
199 #define INIT_FILES { \
200 0, \
201 { { 0, } }, \
202 { NULL, } \
203 }
204
205 struct fs_struct {
206 int count;
207 unsigned short umask;
208 struct inode * root, * pwd;
209 };
210
211 #define INIT_FS { \
212 0, \
213 0022, \
214 NULL, NULL \
215 }
216
217 struct mm_struct {
218 int count;
219 unsigned long start_code, end_code, end_data;
220 unsigned long start_brk, brk, start_stack, start_mmap;
221 unsigned long arg_start, arg_end, env_start, env_end;
222 unsigned long rss;
223 unsigned long min_flt, maj_flt, cmin_flt, cmaj_flt;
224 int swappable:1;
225 #ifdef NEW_SWAP
226 unsigned long old_maj_flt;
227 unsigned long dec_flt;
228 unsigned long swap_cnt;
229 short swap_table;
230 short swap_page;
231 #endif NEW_SWAP
232 struct vm_area_struct * mmap;
233 };
234
235 #define INIT_MM { \
236 0, \
237 0, 0, 0, \
238 0, 0, 0, 0, \
239 0, 0, 0, 0, \
240 0, \
241 0, 0, 0, 0, \
242 0, \
243 0, 0, 0, 0, 0, \
244 NULL }
245
246 struct task_struct {
247
248 volatile long state;
249 long counter;
250 long priority;
251 unsigned long signal;
252 unsigned long blocked;
253 unsigned long flags;
254 int errno;
255 int debugreg[8];
256 struct exec_domain *exec_domain;
257
258 struct linux_binfmt *binfmt;
259 struct task_struct *next_task, *prev_task;
260 struct sigaction sigaction[32];
261 unsigned long saved_kernel_stack;
262 unsigned long kernel_stack_page;
263 int exit_code, exit_signal;
264 unsigned long personality;
265 int dumpable:1;
266 int did_exec:1;
267 int pid,pgrp,session,leader;
268 int groups[NGROUPS];
269
270
271
272
273
274 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
275 struct wait_queue *wait_chldexit;
276 unsigned short uid,euid,suid;
277 unsigned short gid,egid,sgid;
278 unsigned long timeout;
279 unsigned long it_real_value, it_prof_value, it_virt_value;
280 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
281 long utime, stime, cutime, cstime, start_time;
282 struct rlimit rlim[RLIM_NLIMITS];
283 unsigned short used_math;
284 char comm[16];
285
286 struct vm86_struct * vm86_info;
287 unsigned long screen_bitmap;
288 unsigned long v86flags, v86mask, v86mode;
289
290 int link_count;
291 struct tty_struct *tty;
292 struct inode * executable;
293 struct shm_desc *shm;
294 struct sem_undo *semun;
295
296 struct desc_struct *ldt;
297
298 struct tss_struct tss;
299
300 struct fs_struct fs[1];
301
302 struct files_struct files[1];
303
304 struct mm_struct mm[1];
305 };
306
307
308
309
310 #define PF_ALIGNWARN 0x00000001
311
312 #define PF_PTRACED 0x00000010
313 #define PF_TRACESYS 0x00000020
314
315
316
317
318 #define CSIGNAL 0x000000ff
319 #define COPYVM 0x00000100
320 #define COPYFD 0x00000200
321
322
323
324
325
326 #define INIT_TASK \
327 { 0,15,15,0,0,0,0, \
328 { 0, }, \
329 &default_exec_domain, \
330 NULL, \
331 &init_task,&init_task, \
332 {{ 0, },}, \
333 0,(unsigned long) &init_kernel_stack, \
334 0,0,0,0,0, \
335 0,0,0,0, \
336 {NOGROUP,}, \
337 &init_task,&init_task,NULL,NULL,NULL,NULL, \
338 0,0,0,0,0,0, \
339 0,0,0,0,0,0,0,0,0,0,0,0, \
340 { {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
341 {LONG_MAX, LONG_MAX}, {LONG_MAX, LONG_MAX}, \
342 { 0, LONG_MAX}, {LONG_MAX, LONG_MAX}}, \
343 0, \
344 "swapper", \
345 NULL, 0, 0, 0, 0, \
346 0,NULL,NULL, \
347 NULL, NULL, \
348 NULL, \
349 INIT_TSS, \
350 { INIT_FS }, \
351 { INIT_FILES }, \
352 { INIT_MM } \
353 }
354
355 extern struct task_struct init_task;
356 extern struct task_struct *task[NR_TASKS];
357 extern struct task_struct *last_task_used_math;
358 extern struct task_struct *current;
359 extern unsigned long volatile jiffies;
360 extern unsigned long itimer_ticks;
361 extern unsigned long itimer_next;
362 extern struct timeval xtime;
363 extern int need_resched;
364
365 #define CURRENT_TIME (xtime.tv_sec)
366
367 extern void sleep_on(struct wait_queue ** p);
368 extern void interruptible_sleep_on(struct wait_queue ** p);
369 extern void wake_up(struct wait_queue ** p);
370 extern void wake_up_interruptible(struct wait_queue ** p);
371
372 extern void notify_parent(struct task_struct * tsk);
373 extern int send_sig(unsigned long sig,struct task_struct * p,int priv);
374 extern int in_group_p(gid_t grp);
375
376 extern int request_irq(unsigned int irq,void (*handler)(int));
377 extern void free_irq(unsigned int irq);
378 extern int irqaction(unsigned int irq,struct sigaction * sa);
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393 #define FIRST_TSS_ENTRY 8
394 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
395 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
396 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
397 #define load_TR(n) __asm__("ltr %%ax": :"a" (_TSS(n)))
398 #define load_ldt(n) __asm__("lldt %%ax": :"a" (_LDT(n)))
399 #define store_TR(n) \
400 __asm__("str %%ax\n\t" \
401 "subl %2,%%eax\n\t" \
402 "shrl $4,%%eax" \
403 :"=a" (n) \
404 :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
405
406
407
408
409
410
411 #define switch_to(tsk) \
412 __asm__("cli\n\t" \
413 "xchgl %%ecx,_current\n\t" \
414 "ljmp %0\n\t" \
415 "sti\n\t" \
416 "cmpl %%ecx,_last_task_used_math\n\t" \
417 "jne 1f\n\t" \
418 "clts\n" \
419 "1:" \
420 : \
421 :"m" (*(((char *)&tsk->tss.tr)-4)), \
422 "c" (tsk) \
423 :"cx")
424
425 #define _set_base(addr,base) \
426 __asm__("movw %%dx,%0\n\t" \
427 "rorl $16,%%edx\n\t" \
428 "movb %%dl,%1\n\t" \
429 "movb %%dh,%2" \
430 : \
431 :"m" (*((addr)+2)), \
432 "m" (*((addr)+4)), \
433 "m" (*((addr)+7)), \
434 "d" (base) \
435 :"dx")
436
437 #define _set_limit(addr,limit) \
438 __asm__("movw %%dx,%0\n\t" \
439 "rorl $16,%%edx\n\t" \
440 "movb %1,%%dh\n\t" \
441 "andb $0xf0,%%dh\n\t" \
442 "orb %%dh,%%dl\n\t" \
443 "movb %%dl,%1" \
444 : \
445 :"m" (*(addr)), \
446 "m" (*((addr)+6)), \
447 "d" (limit) \
448 :"dx")
449
450 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
451 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
452
453
454
455
456
457
458 extern inline void add_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
459 {
460 unsigned long flags;
461
462 #ifdef DEBUG
463 if (wait->next) {
464 unsigned long pc;
465 __asm__ __volatile__("call 1f\n"
466 "1:\tpopl %0":"=r" (pc));
467 printk("add_wait_queue (%08x): wait->next = %08x\n",pc,(unsigned long) wait->next);
468 }
469 #endif
470 save_flags(flags);
471 cli();
472 if (!*p) {
473 wait->next = wait;
474 *p = wait;
475 } else {
476 wait->next = (*p)->next;
477 (*p)->next = wait;
478 }
479 restore_flags(flags);
480 }
481
482 extern inline void remove_wait_queue(struct wait_queue ** p, struct wait_queue * wait)
483 {
484 unsigned long flags;
485 struct wait_queue * tmp;
486 #ifdef DEBUG
487 unsigned long ok = 0;
488 #endif
489
490 save_flags(flags);
491 cli();
492 if ((*p == wait) &&
493 #ifdef DEBUG
494 (ok = 1) &&
495 #endif
496 ((*p = wait->next) == wait)) {
497 *p = NULL;
498 } else {
499 tmp = wait;
500 while (tmp->next != wait) {
501 tmp = tmp->next;
502 #ifdef DEBUG
503 if (tmp == *p)
504 ok = 1;
505 #endif
506 }
507 tmp->next = wait->next;
508 }
509 wait->next = NULL;
510 restore_flags(flags);
511 #ifdef DEBUG
512 if (!ok) {
513 printk("removed wait_queue not on list.\n");
514 printk("list = %08x, queue = %08x\n",(unsigned long) p, (unsigned long) wait);
515 __asm__("call 1f\n1:\tpopl %0":"=r" (ok));
516 printk("eip = %08x\n",ok);
517 }
518 #endif
519 }
520
521 extern inline void select_wait(struct wait_queue ** wait_address, select_table * p)
522 {
523 struct select_table_entry * entry;
524
525 if (!p || !wait_address)
526 return;
527 if (p->nr >= __MAX_SELECT_TABLE_ENTRIES)
528 return;
529 entry = p->entry + p->nr;
530 entry->wait_address = wait_address;
531 entry->wait.task = current;
532 entry->wait.next = NULL;
533 add_wait_queue(wait_address,&entry->wait);
534 p->nr++;
535 }
536
537 extern void __down(struct semaphore * sem);
538
539
540
541
542 extern inline void down(struct semaphore * sem)
543 {
544 if (sem->count <= 0)
545 __down(sem);
546 sem->count--;
547 }
548
549 extern inline void up(struct semaphore * sem)
550 {
551 sem->count++;
552 wake_up(&sem->wait);
553 }
554
555 static inline unsigned long _get_base(char * addr)
556 {
557 unsigned long __base;
558 __asm__("movb %3,%%dh\n\t"
559 "movb %2,%%dl\n\t"
560 "shll $16,%%edx\n\t"
561 "movw %1,%%dx"
562 :"=&d" (__base)
563 :"m" (*((addr)+2)),
564 "m" (*((addr)+4)),
565 "m" (*((addr)+7)));
566 return __base;
567 }
568
569 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
570
571 static inline unsigned long get_limit(unsigned long segment)
572 {
573 unsigned long __limit;
574 __asm__("lsll %1,%0"
575 :"=r" (__limit):"r" (segment));
576 return __limit+1;
577 }
578
579 #define REMOVE_LINKS(p) do { unsigned long flags; \
580 save_flags(flags) ; cli(); \
581 (p)->next_task->prev_task = (p)->prev_task; \
582 (p)->prev_task->next_task = (p)->next_task; \
583 restore_flags(flags); \
584 if ((p)->p_osptr) \
585 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
586 if ((p)->p_ysptr) \
587 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
588 else \
589 (p)->p_pptr->p_cptr = (p)->p_osptr; \
590 } while (0)
591
592 #define SET_LINKS(p) do { unsigned long flags; \
593 save_flags(flags); cli(); \
594 (p)->next_task = &init_task; \
595 (p)->prev_task = init_task.prev_task; \
596 init_task.prev_task->next_task = (p); \
597 init_task.prev_task = (p); \
598 restore_flags(flags); \
599 (p)->p_ysptr = NULL; \
600 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
601 (p)->p_osptr->p_ysptr = p; \
602 (p)->p_pptr->p_cptr = p; \
603 } while (0)
604
605 #define for_each_task(p) \
606 for (p = &init_task ; (p = p->next_task) != &init_task ; )
607
608
609
610
611
612 extern struct desc_struct default_ldt;
613
614
615
616 #define loaddebug(register) \
617 __asm__("movl %0,%%edx\n\t" \
618 "movl %%edx,%%db" #register "\n\t" \
619 : \
620 :"m" (current->debugreg[register]) \
621 :"dx");
622
623 #endif