root/include/linux/sched.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. _get_base
  2. get_limit

   1 #ifndef _SCHED_H
   2 #define _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  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
  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 <sys/param.h>
  43 #include <sys/time.h>
  44 #include <sys/resource.h>
  45 #include <signal.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];   /* 8*10 bytes for each FP-reg = 80 bytes */
  80 };
  81 
  82 struct tss_struct {
  83         unsigned long   back_link;      /* 16 high bits zero */
  84         unsigned long   esp0;
  85         unsigned long   ss0;            /* 16 high bits zero */
  86         unsigned long   esp1;
  87         unsigned long   ss1;            /* 16 high bits zero */
  88         unsigned long   esp2;
  89         unsigned long   ss2;            /* 16 high bits zero */
  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;             /* 16 high bits zero */
  99         unsigned long   cs;             /* 16 high bits zero */
 100         unsigned long   ss;             /* 16 high bits zero */
 101         unsigned long   ds;             /* 16 high bits zero */
 102         unsigned long   fs;             /* 16 high bits zero */
 103         unsigned long   gs;             /* 16 high bits zero */
 104         unsigned long   ldt;            /* 16 high bits zero */
 105         unsigned long   trace_bitmap;   /* bits: trace 0, bitmap 16-31 */
 106         unsigned long   io_bitmap[IO_BITMAP_SIZE];
 107         struct i387_struct i387;
 108 };
 109 
 110 struct task_struct {
 111 /* these are hardcoded - don't touch */
 112         long state;     /* -1 unrunnable, 0 runnable, >0 stopped */
 113         long counter;
 114         long priority;
 115         long signal;
 116         struct sigaction sigaction[32];
 117         long blocked;   /* bitmap of masked signals */
 118 /* various fields */
 119         int exit_code;
 120         int dumpable;
 121         unsigned long start_code,end_code,end_data,brk,start_stack;
 122         long pid,pgrp,session,leader;
 123         int     groups[NGROUPS];
 124         /* 
 125          * pointers to (original) parent process, youngest child, younger sibling,
 126          * older sibling, respectively.  (p->father can be replaced with 
 127          * p->p_pptr->pid)
 128          */
 129         struct task_struct *p_opptr,*p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 130         /*
 131          * sleep makes a singly linked list with this.
 132          */
 133         struct task_struct *next_wait;
 134         unsigned short uid,euid,suid;
 135         unsigned short gid,egid,sgid;
 136         unsigned long timeout;
 137         unsigned long it_real_value, it_prof_value, it_virt_value;
 138         unsigned long it_real_incr, it_prof_incr, it_virt_incr;
 139         long utime,stime,cutime,cstime,start_time;
 140         unsigned long min_flt, maj_flt;
 141         unsigned long cmin_flt, cmaj_flt;
 142         struct rlimit rlim[RLIM_NLIMITS]; 
 143         unsigned int flags;     /* per process flags, defined below */
 144         unsigned short used_math;
 145         unsigned short rss;     /* number of resident pages */
 146         char comm[8];
 147 /* file system info */
 148         int link_count;
 149         int tty;                /* -1 if no tty, so it must be signed */
 150         unsigned short umask;
 151         struct inode * pwd;
 152         struct inode * root;
 153         struct inode * executable;
 154         struct {
 155                 struct inode * library;
 156                 unsigned long start;
 157                 unsigned long length;
 158         } libraries[MAX_SHARED_LIBS];
 159         int numlibraries;
 160         struct file * filp[NR_OPEN];
 161         unsigned long close_on_exec;
 162 /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
 163         struct desc_struct ldt[3];
 164 /* tss for this task */
 165         struct tss_struct tss;
 166 };
 167 
 168 /*
 169  * Per process flags
 170  */
 171 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 172                                         /* Not implemented yet, only for 486*/
 173 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 174 #define PF_VM86         0x00000020      /* set if process can execute a vm86 */
 175                                         /* task. */
 176                                         /* not impelmented. */
 177 
 178 /*
 179  *  INIT_TASK is used to set up the first task table, touch at
 180  * your own risk!. Base=0, limit=0x9ffff (=640kB)
 181  */
 182 #define INIT_TASK \
 183 /* state etc */ { 0,15,15, \
 184 /* signals */   0,{{},},0, \
 185 /* ec,brk... */ 0,0,0,0,0,0,0, \
 186 /* pid etc.. */ 0,0,0,0, \
 187 /* suppl grps*/ {NOGROUP,}, \
 188 /* proc links*/ &init_task.task,&init_task.task,NULL,NULL,NULL,NULL, \
 189 /* uid etc */   0,0,0,0,0,0, \
 190 /* timeout */   0,0,0,0,0,0,0,0,0,0,0,0, \
 191 /* min_flt */   0,0,0,0, \
 192 /* rlimits */   { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff},  \
 193                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
 194                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
 195 /* flags */     0, \
 196 /* math */      0, \
 197 /* rss */       2, \
 198 /* comm */      "swapper", \
 199 /* fs info */   0,-1,0022,NULL,NULL,NULL, \
 200 /* libraries */ { { NULL, 0, 0}, }, 0, \
 201 /* filp */      {NULL,}, 0, \
 202                 { \
 203                         {0,0}, \
 204 /* ldt */               {0x9f,0xc0fa00}, \
 205                         {0x9f,0xc0f200} \
 206                 }, \
 207 /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
 208          0,0,0,0,0,0,0,0, \
 209          0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
 210          _LDT(0),0x80000000,{0xffffffff}, \
 211                 {} \
 212         }, \
 213 }
 214 
 215 extern struct task_struct *task[NR_TASKS];
 216 extern struct task_struct *last_task_used_math;
 217 extern struct task_struct *current;
 218 extern unsigned long volatile jiffies;
 219 extern unsigned long startup_time;
 220 extern int jiffies_offset;
 221 
 222 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
 223 
 224 extern void add_timer(long jiffies, void (*fn)(void));
 225 extern void sleep_on(struct task_struct ** p);
 226 extern int send_sig(long sig,struct task_struct * p,int priv);
 227 extern void interruptible_sleep_on(struct task_struct ** p);
 228 extern void wake_up(struct task_struct ** p);
 229 extern int in_group_p(gid_t grp);
 230 
 231 /*
 232  * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
 233  * 4-TSS0, 5-LDT0, 6-TSS1 etc ...
 234  */
 235 #define FIRST_TSS_ENTRY 4
 236 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 237 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 238 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 239 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
 240 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
 241 #define str(n) \
 242 __asm__("str %%ax\n\t" \
 243         "subl %2,%%eax\n\t" \
 244         "shrl $4,%%eax" \
 245         :"=a" (n) \
 246         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 247 /*
 248  *      switch_to(n) should switch tasks to task nr n, first
 249  * checking that n isn't the current task, in which case it does nothing.
 250  * This also clears the TS-flag if the task we switched to has used
 251  * tha math co-processor latest.
 252  */
 253 #define switch_to(n) {\
 254 struct {long a,b;} __tmp; \
 255 __asm__("cmpl %%ecx,_current\n\t" \
 256         "je 1f\n\t" \
 257         "movw %%dx,%1\n\t" \
 258         "xchgl %%ecx,_current\n\t" \
 259         "ljmp %0\n\t" \
 260         "cmpl %%ecx,_last_task_used_math\n\t" \
 261         "jne 1f\n\t" \
 262         "clts\n" \
 263         "1:" \
 264         ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
 265         "d" (_TSS(n)),"c" ((long) task[n]) \
 266         :"cx"); \
 267 }
 268 
 269 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
 270 
 271 #define _set_base(addr,base) \
 272 __asm__("movw %%dx,%0\n\t" \
 273         "rorl $16,%%edx\n\t" \
 274         "movb %%dl,%1\n\t" \
 275         "movb %%dh,%2" \
 276         ::"m" (*((addr)+2)), \
 277           "m" (*((addr)+4)), \
 278           "m" (*((addr)+7)), \
 279           "d" (base) \
 280         :"dx")
 281 
 282 #define _set_limit(addr,limit) \
 283 __asm__("movw %%dx,%0\n\t" \
 284         "rorl $16,%%edx\n\t" \
 285         "movb %1,%%dh\n\t" \
 286         "andb $0xf0,%%dh\n\t" \
 287         "orb %%dh,%%dl\n\t" \
 288         "movb %%dl,%1" \
 289         ::"m" (*(addr)), \
 290           "m" (*((addr)+6)), \
 291           "d" (limit) \
 292         :"dx")
 293 
 294 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 295 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 296 
 297 static unsigned long inline _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 298 {
 299         unsigned long __base;
 300         __asm__("movb %3,%%dh\n\t"
 301                 "movb %2,%%dl\n\t"
 302                 "shll $16,%%edx\n\t"
 303                 "movw %1,%%dx"
 304                 :"=&d" (__base)
 305                 :"m" (*((addr)+2)),
 306                  "m" (*((addr)+4)),
 307                  "m" (*((addr)+7)));
 308         return __base;
 309 }
 310 
 311 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 312 
 313 static unsigned long inline get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 314 {
 315         unsigned long __limit;
 316         __asm__("lsll %1,%0"
 317                 :"=r" (__limit):"r" (segment));
 318         return __limit+1;
 319 }
 320 
 321 #define REMOVE_LINKS(p) \
 322         if ((p)->p_osptr) \
 323                 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
 324         if ((p)->p_ysptr) \
 325                 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
 326         else \
 327                 (p)->p_pptr->p_cptr = (p)->p_osptr
 328 
 329 #define SET_LINKS(p) \
 330         (p)->p_ysptr = NULL; \
 331         if ((p)->p_osptr = (p)->p_pptr->p_cptr) \
 332                 (p)->p_osptr->p_ysptr = p; \
 333         (p)->p_pptr->p_cptr = p
 334 
 335 #endif

/* [previous][next][first][last][top][bottom][index][help] */