root/arch/m68k/kernel/process.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_idle
  2. hard_reset_now
  3. show_regs
  4. exit_thread
  5. flush_thread
  6. m68k_fork
  7. m68k_clone
  8. release_thread
  9. copy_thread
  10. dump_fpu
  11. dump_thread
  12. sys_execve

   1 /*
   2  *  linux/arch/m68k/kernel/process.c
   3  *
   4  *  Copyright (C) 1995  Hamish Macdonald
   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/user.h>
  20 #include <linux/a.out.h>
  21 
  22 #include <asm/segment.h>
  23 #include <asm/system.h>
  24 #include <asm/traps.h>
  25 #include <asm/machdep.h>
  26 
  27 asmlinkage void ret_from_exception(void);
  28 
  29 /*
  30  * The idle loop on an m68k..
  31  */
  32 asmlinkage int sys_idle(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34         if (current->pid != 0)
  35                 return -EPERM;
  36 
  37         /* endless idle loop with no priority at all */
  38         current->counter = -100;
  39         for (;;)
  40                 schedule();
  41 }
  42 
  43 void hard_reset_now(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45         if (mach_reset)
  46                 mach_reset();
  47 }
  48 
  49 void show_regs(struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         printk("\n");
  52         printk("Format %02x  Vector: %04x  PC: %08lx  Status: %04x\n",
  53                regs->format, regs->vector, regs->pc, regs->sr);
  54         printk("ORIG_D0: %08lx  D0: %08lx  A1: %08lx\n",
  55                regs->orig_d0, regs->d0, regs->a1);
  56         printk("A0: %08lx  D5: %08lx  D4: %08lx\n",
  57                regs->a0, regs->d5, regs->d4);
  58         printk("D3: %08lx  D2: %08lx  D1: %08lx\n",
  59                regs->d3, regs->d2, regs->d1);
  60         if (!(regs->sr & PS_S))
  61                 printk("USP: %08lx\n", rdusp());
  62 }
  63 
  64 /*
  65  * Free current thread data structures etc..
  66  */
  67 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  68 {
  69 }
  70 
  71 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73         set_fs(USER_DS);
  74         current->tss.fs = USER_DS;
  75 }
  76 
  77 /*
  78  * "m68k_fork()".. By the time we get here, the
  79  * non-volatile registers have also been saved on the
  80  * stack. We do some ugly pointer stuff here.. (see
  81  * also copy_thread)
  82  */
  83 
  84 asmlinkage int m68k_fork(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86         return do_fork(SIGCHLD, rdusp(), regs);
  87 }
  88 
  89 asmlinkage int m68k_clone(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  90 {
  91         unsigned long clone_flags;
  92         unsigned long newsp;
  93 
  94         /* syscall2 puts clone_flags in d1 and usp in d2 */
  95         clone_flags = regs->d1;
  96         newsp = regs->d2;
  97         if (!newsp)
  98           newsp  = rdusp();
  99         return do_fork(clone_flags, newsp, regs);
 100 }
 101 
 102 void release_thread(struct task_struct *dead_task)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104 }
 105 
 106 void copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
     /* [previous][next][first][last][top][bottom][index][help] */
 107                  struct task_struct * p, struct pt_regs * regs)
 108 {
 109         struct pt_regs * childregs;
 110         struct switch_stack * childstack, *stack;
 111         unsigned long stack_offset, *retp;
 112 
 113         stack_offset = PAGE_SIZE - sizeof(struct pt_regs);
 114         childregs = (struct pt_regs *) (p->kernel_stack_page + stack_offset);
 115 
 116         *childregs = *regs;
 117         childregs->d0 = 0;
 118 
 119         retp = ((unsigned long *) regs);
 120         stack = ((struct switch_stack *) retp) - 1;
 121 
 122         childstack = ((struct switch_stack *) childregs) - 1;
 123         *childstack = *stack;
 124         childstack->retpc = (unsigned long) ret_from_exception;
 125 
 126         p->tss.usp = usp;
 127         p->tss.ksp = (unsigned long)childstack;
 128 
 129         /* Copy the current fpu state */
 130         asm volatile ("fsave %0" : : "m" (p->tss.fpstate[0]) : "memory");
 131         if (p->tss.fpstate[0])
 132           asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
 133                         "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
 134                         : : "m" (p->tss.fp[0]), "m" (p->tss.fpcntl[0])
 135                         : "memory");
 136         /* Restore the state in case the fpu was busy */
 137         asm volatile ("frestore %0" : : "m" (p->tss.fpstate[0]));
 138 }
 139 
 140 /* Fill in the fpu structure for a core dump.  */
 141 
 142 int dump_fpu (struct user_m68kfp_struct *fpu)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144   char fpustate[216];
 145 
 146   /* First dump the fpu context to avoid protocol violation.  */
 147   asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
 148   if (!fpustate[0])
 149     return 0;
 150 
 151   asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
 152                 :: "m" (fpu->fpcntl[0])
 153                 : "memory");
 154   asm volatile ("fmovemx %/fp0-%/fp7,%0"
 155                 :: "m" (fpu->fpregs[0])
 156                 : "memory");
 157   return 1;
 158 }
 159 
 160 /*
 161  * fill in the user structure for a core dump..
 162  */
 163 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 164 {
 165 /* changed the size calculations - should hopefully work better. lbt */
 166         dump->magic = CMAGIC;
 167         dump->start_code = 0;
 168         dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
 169         dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
 170         dump->u_dsize = ((unsigned long) (current->mm->brk +
 171                                           (PAGE_SIZE-1))) >> PAGE_SHIFT;
 172         dump->u_dsize -= dump->u_tsize;
 173         dump->u_ssize = 0;
 174 
 175         if (dump->start_stack < TASK_SIZE)
 176                 dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
 177 
 178         dump->u_ar0 = (struct pt_regs *)(((int)(&dump->regs)) -((int)(dump)));
 179         dump->regs = *regs;
 180         dump->regs2 = ((struct switch_stack *)regs)[-1];
 181         /* dump floating point stuff */
 182         dump->u_fpvalid = dump_fpu (&dump->m68kfp);
 183 }
 184 
 185 /*
 186  * sys_execve() executes a new program.
 187  */
 188 asmlinkage int sys_execve(char *name, char **argv, char **envp)
     /* [previous][next][first][last][top][bottom][index][help] */
 189 {
 190         int error;
 191         char * filename;
 192         struct pt_regs *regs = (struct pt_regs *) &name;
 193 
 194         error = getname(name, &filename);
 195         if (error)
 196                 return error;
 197         error = do_execve(filename, argv, envp, regs);
 198         putname(filename);
 199         return error;
 200 }

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