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 #if (TASK_SIZE & 0x3fffff)
  11 #error "TASK_SIZE must be multiple of 4M"
  12 #endif
  13 
  14 #if (LIBRARY_SIZE & 0x3fffff)
  15 #error "LIBRARY_SIZE must be a multiple of 4M"
  16 #endif
  17 
  18 #if (LIBRARY_SIZE >= (TASK_SIZE/2))
  19 #error "LIBRARY_SIZE too damn big!"
  20 #endif
  21 
  22 #if (((TASK_SIZE>>16)*NR_TASKS) != 0x10000)
  23 #error "TASK_SIZE*NR_TASKS must be 4GB"
  24 #endif
  25 
  26 #define LIBRARY_OFFSET (TASK_SIZE - LIBRARY_SIZE)
  27 
  28 #define CT_TO_SECS(x)   ((x) / HZ)
  29 #define CT_TO_USECS(x)  (((x) % HZ) * 1000000/HZ)
  30 
  31 #define FIRST_TASK task[0]
  32 #define LAST_TASK task[NR_TASKS-1]
  33 
  34 #include <linux/head.h>
  35 #include <linux/fs.h>
  36 #include <linux/mm.h>
  37 #include <sys/param.h>
  38 #include <sys/time.h>
  39 #include <sys/resource.h>
  40 #include <signal.h>
  41 
  42 #if (NR_OPEN > 32)
  43 #error "Currently the close-on-exec-flags and select masks are in one long, max 32 files/proc"
  44 #endif
  45 
  46 #define TASK_RUNNING            0
  47 #define TASK_INTERRUPTIBLE      1
  48 #define TASK_UNINTERRUPTIBLE    2
  49 #define TASK_ZOMBIE             3
  50 #define TASK_STOPPED            4
  51 
  52 #ifndef NULL
  53 #define NULL ((void *) 0)
  54 #endif
  55 
  56 extern int copy_page_tables(unsigned long from, unsigned long to, long size);
  57 extern int free_page_tables(unsigned long from, unsigned long size);
  58 
  59 extern void sched_init(void);
  60 extern void schedule(void);
  61 extern void trap_init(void);
  62 extern void panic(const char * str);
  63 extern int tty_write(unsigned minor,char * buf,int count);
  64 
  65 typedef int (*fn_ptr)();
  66 
  67 struct i387_struct {
  68         long    cwd;
  69         long    swd;
  70         long    twd;
  71         long    fip;
  72         long    fcs;
  73         long    foo;
  74         long    fos;
  75         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
  76 };
  77 
  78 struct tss_struct {
  79         long    back_link;      /* 16 high bits zero */
  80         long    esp0;
  81         long    ss0;            /* 16 high bits zero */
  82         long    esp1;
  83         long    ss1;            /* 16 high bits zero */
  84         long    esp2;
  85         long    ss2;            /* 16 high bits zero */
  86         long    cr3;
  87         long    eip;
  88         long    eflags;
  89         long    eax,ecx,edx,ebx;
  90         long    esp;
  91         long    ebp;
  92         long    esi;
  93         long    edi;
  94         long    es;             /* 16 high bits zero */
  95         long    cs;             /* 16 high bits zero */
  96         long    ss;             /* 16 high bits zero */
  97         long    ds;             /* 16 high bits zero */
  98         long    fs;             /* 16 high bits zero */
  99         long    gs;             /* 16 high bits zero */
 100         long    ldt;            /* 16 high bits zero */
 101         long    trace_bitmap;   /* bits: trace 0, bitmap 16-31 */
 102         struct i387_struct i387;
 103 };
 104 
 105 struct task_struct {
 106 /* these are hardcoded - don't touch */
 107         long state;     /* -1 unrunnable, 0 runnable, >0 stopped */
 108         long counter;
 109         long priority;
 110         long signal;
 111         struct sigaction sigaction[32];
 112         long blocked;   /* bitmap of masked signals */
 113 /* various fields */
 114         int exit_code;
 115         unsigned long start_code,end_code,end_data,brk,start_stack;
 116         long pid,pgrp,session,leader;
 117         int     groups[NGROUPS];
 118         /* 
 119          * pointers to parent process, youngest child, younger sibling,
 120          * older sibling, respectively.  (p->father can be replaced with 
 121          * p->p_pptr->pid)
 122          */
 123         struct task_struct *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
 124         /*
 125          * sleep makes a singly linked list with this.
 126          */
 127         struct task_struct *next_wait;
 128         unsigned short uid,euid,suid;
 129         unsigned short gid,egid,sgid;
 130         unsigned long timeout,alarm;
 131         long utime,stime,cutime,cstime,start_time;
 132         unsigned long min_flt, maj_flt;
 133         unsigned long cmin_flt, cmaj_flt;
 134         struct rlimit rlim[RLIM_NLIMITS]; 
 135         unsigned int flags;     /* per process flags, defined below */
 136         unsigned short used_math;
 137         unsigned short rss;     /* number of resident pages */
 138         char comm[8];
 139 /* file system info */
 140         int link_count;
 141         int tty;                /* -1 if no tty, so it must be signed */
 142         unsigned short umask;
 143         struct inode * pwd;
 144         struct inode * root;
 145         struct inode * executable;
 146         struct inode * library;
 147         unsigned long close_on_exec;
 148         struct file * filp[NR_OPEN];
 149 /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
 150         struct desc_struct ldt[3];
 151 /* tss for this task */
 152         struct tss_struct tss;
 153 };
 154 
 155 /*
 156  * Per process flags
 157  */
 158 #define PF_ALIGNWARN    0x00000001      /* Print alignment warning msgs */
 159                                         /* Not implemented yet, only for 486*/
 160 #define PF_PTRACED      0x00000010      /* set if ptrace (0) has been called. */
 161 #define PF_VM86         0x00000020      /* set if process can execute a vm86 */
 162                                         /* task. */
 163                                         /* not impelmented. */
 164 
 165 /*
 166  *  INIT_TASK is used to set up the first task table, touch at
 167  * your own risk!. Base=0, limit=0x9ffff (=640kB)
 168  */
 169 #define INIT_TASK \
 170 /* state etc */ { 0,15,15, \
 171 /* signals */   0,{{},},0, \
 172 /* ec,brk... */ 0,0,0,0,0,0, \
 173 /* pid etc.. */ 0,0,0,0, \
 174 /* suppl grps*/ {NOGROUP,}, \
 175 /* proc links*/ &init_task.task,NULL,NULL,NULL,NULL, \
 176 /* uid etc */   0,0,0,0,0,0, \
 177 /* timeout */   0,0,0,0,0,0,0, \
 178 /* min_flt */   0,0,0,0, \
 179 /* rlimits */   { {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff},  \
 180                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}, \
 181                   {0x7fffffff, 0x7fffffff}, {0x7fffffff, 0x7fffffff}}, \
 182 /* flags */     0, \
 183 /* math */      0, \
 184 /* rss */       2, \
 185 /* comm */      "swapper", \
 186 /* fs info */   0,-1,0022,NULL,NULL,NULL,NULL,0, \
 187 /* filp */      {NULL,}, \
 188         { \
 189                 {0,0}, \
 190 /* ldt */       {0x9f,0xc0fa00}, \
 191                 {0x9f,0xc0f200}, \
 192         }, \
 193 /*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
 194          0,0,0,0,0,0,0,0, \
 195          0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
 196          _LDT(0),0x80000000, \
 197                 {} \
 198         }, \
 199 }
 200 
 201 extern struct task_struct *task[NR_TASKS];
 202 extern struct task_struct *last_task_used_math;
 203 extern struct task_struct *current;
 204 extern unsigned long volatile jiffies;
 205 extern unsigned long startup_time;
 206 extern int jiffies_offset;
 207 
 208 #define CURRENT_TIME (startup_time+(jiffies+jiffies_offset)/HZ)
 209 
 210 extern void add_timer(long jiffies, void (*fn)(void));
 211 extern void sleep_on(struct task_struct ** p);
 212 extern void interruptible_sleep_on(struct task_struct ** p);
 213 extern void wake_up(struct task_struct ** p);
 214 extern int in_group_p(gid_t grp);
 215 
 216 /*
 217  * Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
 218  * 4-TSS0, 5-LDT0, 6-TSS1 etc ...
 219  */
 220 #define FIRST_TSS_ENTRY 4
 221 #define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
 222 #define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
 223 #define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
 224 #define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
 225 #define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
 226 #define str(n) \
 227 __asm__("str %%ax\n\t" \
 228         "subl %2,%%eax\n\t" \
 229         "shrl $4,%%eax" \
 230         :"=a" (n) \
 231         :"0" (0),"i" (FIRST_TSS_ENTRY<<3))
 232 /*
 233  *      switch_to(n) should switch tasks to task nr n, first
 234  * checking that n isn't the current task, in which case it does nothing.
 235  * This also clears the TS-flag if the task we switched to has used
 236  * tha math co-processor latest.
 237  */
 238 #define switch_to(n) {\
 239 struct {long a,b;} __tmp; \
 240 __asm__("cmpl %%ecx,_current\n\t" \
 241         "je 1f\n\t" \
 242         "movw %%dx,%1\n\t" \
 243         "xchgl %%ecx,_current\n\t" \
 244         "ljmp %0\n\t" \
 245         "cmpl %%ecx,_last_task_used_math\n\t" \
 246         "jne 1f\n\t" \
 247         "clts\n" \
 248         "1:" \
 249         ::"m" (*&__tmp.a),"m" (*&__tmp.b), \
 250         "d" (_TSS(n)),"c" ((long) task[n]) \
 251         :"cx"); \
 252 }
 253 
 254 #define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
 255 
 256 #define _set_base(addr,base) \
 257 __asm__("movw %%dx,%0\n\t" \
 258         "rorl $16,%%edx\n\t" \
 259         "movb %%dl,%1\n\t" \
 260         "movb %%dh,%2" \
 261         ::"m" (*((addr)+2)), \
 262           "m" (*((addr)+4)), \
 263           "m" (*((addr)+7)), \
 264           "d" (base) \
 265         :"dx")
 266 
 267 #define _set_limit(addr,limit) \
 268 __asm__("movw %%dx,%0\n\t" \
 269         "rorl $16,%%edx\n\t" \
 270         "movb %1,%%dh\n\t" \
 271         "andb $0xf0,%%dh\n\t" \
 272         "orb %%dh,%%dl\n\t" \
 273         "movb %%dl,%1" \
 274         ::"m" (*(addr)), \
 275           "m" (*((addr)+6)), \
 276           "d" (limit) \
 277         :"dx")
 278 
 279 #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
 280 #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
 281 
 282 static unsigned long inline _get_base(char * addr)
     /* [previous][next][first][last][top][bottom][index][help] */
 283 {
 284         unsigned long __base;
 285         __asm__("movb %3,%%dh\n\t"
 286                 "movb %2,%%dl\n\t"
 287                 "shll $16,%%edx\n\t"
 288                 "movw %1,%%dx"
 289                 :"=&d" (__base)
 290                 :"m" (*((addr)+2)),
 291                  "m" (*((addr)+4)),
 292                  "m" (*((addr)+7)));
 293         return __base;
 294 }
 295 
 296 #define get_base(ldt) _get_base( ((char *)&(ldt)) )
 297 
 298 static unsigned long inline get_limit(unsigned long segment)
     /* [previous][next][first][last][top][bottom][index][help] */
 299 {
 300         unsigned long __limit;
 301         __asm__("lsll %1,%0"
 302                 :"=r" (__limit):"r" (segment));
 303         return __limit+1;
 304 }
 305 
 306 #endif

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