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

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