root/arch/i386/kernel/process.c

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

DEFINITIONS

This source file includes following definitions.
  1. ret_from_sys_call
  2. start_thread
  3. exit_thread
  4. flush_thread
  5. copy_thread
  6. dump_thread
  7. sys_execve

   1 /*
   2  *  linux/arch/i386/kernel/process.c
   3  *
   4  *  Copyright (C) 1995  Linus Torvalds
   5  */
   6 
   7 /*
   8  * This file handles the architecture-dependent parts of process handling..
   9  */
  10 
  11 #include <linux/errno.h>
  12 #include <linux/sched.h>
  13 #include <linux/kernel.h>
  14 #include <linux/mm.h>
  15 #include <linux/stddef.h>
  16 #include <linux/unistd.h>
  17 #include <linux/ptrace.h>
  18 #include <linux/malloc.h>
  19 #include <linux/ldt.h>
  20 #include <linux/user.h>
  21 #include <linux/a.out.h>
  22 
  23 #include <asm/segment.h>
  24 #include <asm/system.h>
  25 
  26 /*
  27  * Tell us the machine setup..
  28  */
  29 char hard_math = 0;             /* set by boot/head.S */
  30 char x86 = 0;                   /* set by boot/head.S to 3 or 4 */
  31 char x86_model = 0;             /* set by boot/head.S */
  32 char x86_mask = 0;              /* set by boot/head.S */
  33 int x86_capability = 0;         /* set by boot/head.S */
  34 int fdiv_bug = 0;               /* set if Pentium(TM) with FP bug */
  35 
  36 char x86_vendor_id[13] = "Unknown";
  37 
  38 char ignore_irq13 = 0;          /* set if exception 16 works */
  39 char wp_works_ok = 0;           /* set if paging hardware honours WP */ 
  40 char hlt_works_ok = 1;          /* set if the "hlt" instruction works */
  41 
  42 /*
  43  * Bus types ..
  44  */
  45 int EISA_bus = 0;
  46 
  47 asmlinkage void ret_from_sys_call(void) __asm__("ret_from_sys_call");
     /* [previous][next][first][last][top][bottom][index][help] */
  48 
  49 /*
  50  * The idle loop on a i386..
  51  */
  52 asmlinkage int sys_idle(void)
  53 {
  54         int i;
  55 
  56         if (current->pid != 0)
  57                 return -EPERM;
  58 
  59         /* Map out the low memory: it's no longer needed */
  60         for (i = 0 ; i < 768 ; i++)
  61                 swapper_pg_dir[i] = 0;
  62 
  63         /* endless idle loop with no priority at all */
  64         current->counter = -100;
  65         for (;;) {
  66                 if (hlt_works_ok && !need_resched)
  67                         __asm__("hlt");
  68                 schedule();
  69         }
  70 }
  71 
  72 /*
  73  * Do necessary setup to start up a newly executed thread.
  74  */
  75 void start_thread(struct pt_regs * regs, unsigned long eip, unsigned long esp)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77         regs->eip = eip;
  78         regs->esp = esp;
  79 }
  80 
  81 /*
  82  * Free current thread data structures etc..
  83  */
  84 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         /* forget local segments */
  87         __asm__ __volatile__("mov %w0,%%fs ; mov %w0,%%gs ; lldt %w0"
  88                 : /* no outputs */
  89                 : "r" (0));
  90         current->tss.ldt = 0;
  91         if (current->ldt) {
  92                 void * ldt = current->ldt;
  93                 current->ldt = NULL;
  94                 vfree(ldt);
  95         }
  96 }
  97 
  98 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  99 {
 100         int i;
 101 
 102         if (current->ldt) {
 103                 free_page((unsigned long) current->ldt);
 104                 current->ldt = NULL;
 105                 for (i=1 ; i<NR_TASKS ; i++) {
 106                         if (task[i] == current)  {
 107                                 set_ldt_desc(gdt+(i<<1)+
 108                                              FIRST_LDT_ENTRY,&default_ldt, 1);
 109                                 load_ldt(i);
 110                         }
 111                 }       
 112         }
 113 
 114         for (i=0 ; i<8 ; i++)
 115                 current->debugreg[i] = 0;
 116 }
 117 
 118 #define IS_CLONE (regs->orig_eax == __NR_clone)
 119 
 120 unsigned long copy_thread(int nr, unsigned long clone_flags, struct task_struct * p, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 121 {
 122         int i;
 123         struct pt_regs * childregs;
 124 
 125         p->tss.es = KERNEL_DS;
 126         p->tss.cs = KERNEL_CS;
 127         p->tss.ss = KERNEL_DS;
 128         p->tss.ds = KERNEL_DS;
 129         p->tss.fs = USER_DS;
 130         p->tss.gs = KERNEL_DS;
 131         p->tss.ss0 = KERNEL_DS;
 132         p->tss.esp0 = p->kernel_stack_page + PAGE_SIZE;
 133         p->tss.tr = _TSS(nr);
 134         childregs = ((struct pt_regs *) (p->kernel_stack_page + PAGE_SIZE)) - 1;
 135         p->tss.esp = (unsigned long) childregs;
 136         p->tss.eip = (unsigned long) ret_from_sys_call;
 137         *childregs = *regs;
 138         childregs->eax = 0;
 139         p->tss.back_link = 0;
 140         p->tss.eflags = regs->eflags & 0xffffcfff;      /* iopl is always 0 for a new process */
 141         if (IS_CLONE) {
 142                 if (regs->ebx)
 143                         childregs->esp = regs->ebx;
 144                 clone_flags = regs->ecx;
 145                 if (childregs->esp == regs->esp)
 146                         clone_flags |= COPYVM;
 147         }
 148         p->tss.ldt = _LDT(nr);
 149         if (p->ldt) {
 150                 p->ldt = (struct desc_struct*) vmalloc(LDT_ENTRIES*LDT_ENTRY_SIZE);
 151                 if (p->ldt != NULL)
 152                         memcpy(p->ldt, current->ldt, LDT_ENTRIES*LDT_ENTRY_SIZE);
 153         }
 154         set_tss_desc(gdt+(nr<<1)+FIRST_TSS_ENTRY,&(p->tss));
 155         if (p->ldt)
 156                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,p->ldt, 512);
 157         else
 158                 set_ldt_desc(gdt+(nr<<1)+FIRST_LDT_ENTRY,&default_ldt, 1);
 159         p->tss.bitmap = offsetof(struct thread_struct,io_bitmap);
 160         for (i = 0; i < IO_BITMAP_SIZE+1 ; i++) /* IO bitmap is actually SIZE+1 */
 161                 p->tss.io_bitmap[i] = ~0;
 162         if (last_task_used_math == current)
 163                 __asm__("clts ; fnsave %0 ; frstor %0":"=m" (p->tss.i387));
 164         return clone_flags;
 165 }
 166 
 167 /*
 168  * fill in the user structure for a core dump..
 169  */
 170 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 171 {
 172         int i;
 173 
 174 /* changed the size calculations - should hopefully work better. lbt */
 175         dump->magic = CMAGIC;
 176         dump->start_code = 0;
 177         dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
 178         dump->u_tsize = ((unsigned long) current->mm->end_code) >> 12;
 179         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> 12;
 180         dump->u_dsize -= dump->u_tsize;
 181         dump->u_ssize = 0;
 182         for (i = 0; i < 8; i++)
 183                 dump->u_debugreg[i] = current->debugreg[i];  
 184 
 185         if (dump->start_stack < TASK_SIZE)
 186                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> 12;
 187 
 188         dump->regs = *regs;
 189 
 190 /* Flag indicating the math stuff is valid. We don't support this for the
 191    soft-float routines yet */
 192         if (hard_math) {
 193                 if ((dump->u_fpvalid = current->used_math) != 0) {
 194                         if (last_task_used_math == current)
 195                                 __asm__("clts ; fnsave %0": :"m" (dump->i387));
 196                         else
 197                                 memcpy(&dump->i387,&current->tss.i387.hard,sizeof(dump->i387));
 198                 }
 199         } else {
 200                 /* we should dump the emulator state here, but we need to
 201                    convert it into standard 387 format first.. */
 202                 dump->u_fpvalid = 0;
 203         }
 204 }
 205 
 206 /*
 207  * sys_execve() executes a new program.
 208  */
 209 asmlinkage int sys_execve(struct pt_regs regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 210 {
 211         int error;
 212         char * filename;
 213 
 214         error = getname((char *) regs.ebx, &filename);
 215         if (error)
 216                 return error;
 217         error = do_execve(filename, (char **) regs.ecx, (char **) regs.edx, &regs);
 218         putname(filename);
 219         return error;
 220 }

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