root/arch/ppc/kernel/process.c

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

DEFINITIONS

This source file includes following definitions.
  1. dump_fpu
  2. switch_to
  3. sys_idle
  4. hard_reset_now
  5. show_regs
  6. exit_thread
  7. flush_thread
  8. copy_thread
  9. dump_thread
  10. start_thread
  11. sys_newselect
  12. sys_fork
  13. sys_execve
  14. sys_clone
  15. print_backtrace

   1 /* * Last edited: Nov  8 12:32 1995 (cort) */
   2 /*
   3  *  linux/arch/ppc/kernel/process.c
   4  *
   5  *  Copyright (C) 1995  Linus Torvalds
   6  *  Adapted for PowerPC by Gary Thomas
   7  */
   8 
   9 /*
  10  * This file handles the architecture-dependent parts of process handling..
  11  */
  12 
  13 #include <linux/errno.h>
  14 #include <linux/sched.h>
  15 #include <linux/kernel.h>
  16 #include <linux/mm.h>
  17 #include <linux/stddef.h>
  18 #include <linux/unistd.h>
  19 #include <linux/ptrace.h>
  20 #include <linux/malloc.h>
  21 #include <linux/ldt.h>
  22 #include <linux/user.h>
  23 #include <linux/a.out.h>
  24 
  25 #include <asm/pgtable.h>
  26 #include <asm/segment.h>
  27 #include <asm/system.h>
  28 #include <asm/io.h>
  29 
  30 #include <asm/processor.h>
  31 
  32 int dump_fpu (struct user_i387_struct* fpu)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34   return 1;             /* all ppc's have a fpu */
  35 }
  36 
  37 void
  38 switch_to(struct task_struct *new)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         struct pt_regs *regs;
  41         struct thread_struct *new_tss, *old_tss;
  42         int s;
  43         regs = (struct pt_regs *)new->tss.ksp;
  44 /*
  45 printk("Task %x(%d) -> %x(%d)", current, current->pid, new, new->pid);
  46 printk(" - IP: %x, SR: %x, SP: %x\n", regs->nip, regs->msr, regs);
  47 */
  48         s = _disable_interrupts();
  49         new_tss = &new->tss;
  50         old_tss = &current->tss;
  51         current = new;
  52         _switch(old_tss, new_tss);
  53 
  54 /*      printk("Back in task %x(%d)\n", current, current->pid);*/
  55 
  56         _enable_interrupts(s);
  57 }
  58 
  59 asmlinkage int sys_idle(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  60 {
  61 
  62         if (current->pid != 0)
  63                 return -EPERM;
  64 /*panic("process.c: sys_idle()\n");*/
  65         /* endless idle loop with no priority at all */
  66         current->counter = -100;
  67         for (;;) {
  68 
  69                 schedule();
  70         }
  71 }
  72 
  73 void hard_reset_now(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  74 {
  75         halt();
  76 }
  77 
  78 void show_regs(struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         _panic("show_regs");
  81 }
  82 
  83 /*
  84  * Free current thread data structures etc..
  85  */
  86 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88 }
  89 
  90 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92 }
  93 
  94 /*
  95  * Copy a thread..
  96  */
  97 void copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
     /* [previous][next][first][last][top][bottom][index][help] */
  98         struct task_struct * p, struct pt_regs * regs)
  99 {
 100         int i;
 101         SEGREG *segs;
 102         struct pt_regs * childregs;
 103 
 104 /*printk("copy thread - NR: %d, Flags: %x, USP: %x, Task: %x, Regs: %x\n", nr, clone_flags, usp, p, regs);*/
 105 
 106         /* Construct segment registers */
 107         segs = (SEGREG *)p->tss.segs;
 108         for (i = 0;  i < 8;  i++)
 109         {
 110                 segs[i].ks = 0;
 111                 segs[i].kp = 1;
 112                 segs[i].vsid = i | (nr << 4);
 113         }
 114         /* Last 8 are shared with kernel & everybody else... */
 115         for (i = 8;  i < 16;  i++)
 116         {
 117                 segs[i].ks = 0;
 118                 segs[i].kp = 1;
 119                 segs[i].vsid = i;
 120         }
 121         /* Copy registers */
 122         childregs = ((struct pt_regs *) (p->kernel_stack_page + 2*PAGE_SIZE)) - 2;
 123         *childregs = *regs;     /* STRUCT COPY */
 124         childregs->gpr[3] = 0;  /* Result from fork() */
 125         p->tss.ksp = childregs;
 126         if (usp >= (unsigned long)regs)
 127         { /* Stack is in kernel space - must adjust */
 128                 childregs->gpr[1] = childregs+1;
 129         } else
 130         { /* Provided stack is in user space */
 131                 childregs->gpr[1] = usp;
 132         }
 133 }
 134 
 135 /*
 136  * fill in the user structure for a core dump..
 137  */
 138 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 139 {
 140 }
 141 
 142 #if 0 /* mfisk */
 143 /*
 144  * Do necessary setup to start up a newly executed thread.
 145  */
 146 void start_thread(struct pt_regs * regs, unsigned long eip, unsigned long esp)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148   regs->nip = eip;
 149   regs->gpr[1] = esp;
 150   regs->msr = MSR_USER;
 151 #if 0
 152 /*  printk("current = %x current->mm = %x\n", current, current->mm);
 153   printk("task[0] = %x task[0]->mm = %x\n", task[0],task[0]->mm);*/
 154   printk("Start thread [%x] at PC: %x, SR: %x, SP: %x\n",
 155     regs, eip, regs->msr, esp);
 156 /*  dump_buf(esp, 64);*/
 157 /*  dump_buf(eip, 64);*/
 158 #endif
 159 }
 160 #endif
 161 
 162 asmlinkage int sys_newselect(int p1, int p2, int p3, int p4, int p5, int p6, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164   panic("sys_newselect unimplemented");
 165 }
 166 
 167 asmlinkage int sys_fork(int p1, int p2, int p3, int p4, int p5, int p6, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 168 {
 169 printk("process.c: sys_fork() called\n");
 170         return do_fork( CLONE_VM|SIGCHLD, regs->gpr[1], regs);
 171 }
 172 
 173 asmlinkage int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
 174         unsigned long a3, unsigned long a4, unsigned long a5,
 175         struct pt_regs *regs)
 176 {
 177         int error;
 178         char * filename;
 179 /*      printk("process.c: sys_execve(a0 = %s, a1 = %x, a2 = %x)\n",a0,a1,a2);*/
 180 
 181 #if 1
 182         /* paranoia check.  I really don't trust head.S  -- Cort */
 183         if ( regs->marker != 0xDEADDEAD )
 184         {
 185           panic("process.c: sys_execve(): regs->marker != DEADDEAD\n");
 186         }
 187 #endif
 188         error = getname((char *) a0, &filename);
 189         if (error)
 190           return error;
 191         error = do_execve(filename, (char **) a1, (char **) a2, regs);
 192 #if 0
 193         if (error)
 194         {
 195           printk("EXECVE - file = '%s', error = %d\n", filename, error);
 196         }
 197 #endif
 198         putname(filename);
 199         return error;
 200 }
 201 
 202 
 203 asmlinkage int sys_clone(unsigned long clone_flags, unsigned long usp, unsigned long a2,
     /* [previous][next][first][last][top][bottom][index][help] */
 204         unsigned long a3, unsigned long a4, unsigned long a5,
 205         struct pt_regs *regs)
 206 {
 207   int i;
 208   
 209   if (!usp)
 210     usp = regs->gpr[1];
 211   
 212 
 213   i = do_fork(CLONE_VM/*clone_flags*/, /*usp*/regs->gpr[1], regs);
 214 /*  printk("sys_clone going to return %d\n", i);*/
 215   return i;
 216 }
 217 
 218 
 219 
 220 void
 221 print_backtrace(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 222 {
 223         unsigned long *sp = (unsigned long *)_get_SP();
 224         int cnt = 0;
 225         printk("... Call backtrace:\n");
 226         while (*sp)
 227         {
 228                 printk("%08X ", sp[2]);
 229                 sp = *sp;
 230                 if (++cnt == 8)
 231                 {
 232                         printk("\n");
 233                 }
 234                 if (cnt > 16) break;
 235         }
 236         printk("\n");
 237 }
 238 

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