root/arch/sparc/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_regwindow
  4. show_regs
  5. exit_thread
  6. release_thread
  7. flush_thread
  8. copy_thread
  9. dump_thread
  10. dump_fpu
  11. sparc_execve

   1 /*  $Id: process.c,v 1.42 1996/02/20 07:45:08 davem Exp $
   2  *  linux/arch/sparc/kernel/process.c
   3  *
   4  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
   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/auxio.h>
  24 #include <asm/oplib.h>
  25 #include <asm/segment.h>
  26 #include <asm/system.h>
  27 #include <asm/page.h>
  28 #include <asm/pgtable.h>
  29 #include <asm/delay.h>
  30 #include <asm/processor.h>
  31 #include <asm/psr.h>
  32 
  33 extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
  34 
  35 int active_ds = USER_DS;
  36 
  37 /*
  38  * the idle loop on a Sparc... ;)
  39  */
  40 asmlinkage int sys_idle(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42         if (current->pid != 0)
  43                 return -EPERM;
  44 
  45         /* endless idle loop with no priority at all */
  46         current->counter = -100;
  47         for (;;) {
  48                 schedule();
  49         }
  50 }
  51 
  52 extern char saved_command_line[];
  53 
  54 void hard_reset_now(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56         sti();
  57         udelay(8000);
  58         cli();
  59         prom_feval("reset");
  60         panic("Reboot failed!");
  61 }
  62 
  63 void show_regwindow(struct reg_window *rw)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65         printk("l0:%08lx l1:%08lx l2:%08lx l3:%08lx l4:%08lx l5:%08lx l6:%08lx l7:%08lx\n",
  66                rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
  67                rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
  68         printk("i0:%08lx i1:%08lx i2:%08lx i3:%08lx i4:%08lx i5:%08lx i6:%08lx i7:%08lx\n",
  69                rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  70                rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
  71 }
  72 
  73 void show_regs(struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  74 {
  75         printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx\n", regs->psr,
  76                regs->pc, regs->npc, regs->y);
  77         printk("%%g0: %08lx %%g1: %08lx %%g2: %08lx %%g3: %08lx\n",
  78                regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
  79                regs->u_regs[3]);
  80         printk("%%g4: %08lx %%g5: %08lx %%g6: %08lx %%g7: %08lx\n",
  81                regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
  82                regs->u_regs[7]);
  83         printk("%%o0: %08lx %%o1: %08lx %%o2: %08lx %%o3: %08lx\n",
  84                regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
  85                regs->u_regs[11]);
  86         printk("%%o4: %08lx %%o5: %08lx %%sp: %08lx %%ret_pc: %08lx\n",
  87                regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
  88                regs->u_regs[15]);
  89 }
  90 
  91 /*
  92  * Free current thread data structures etc..
  93  */
  94 void exit_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         flush_user_windows();
  97         if(last_task_used_math == current) {
  98                 /* Keep process from leaving FPU in a bogon state. */
  99                 put_psr(get_psr() | PSR_EF);
 100                 fpsave(&current->tss.float_regs[0], &current->tss.fsr,
 101                        &current->tss.fpqueue[0], &current->tss.fpqdepth);
 102                 last_task_used_math = NULL;
 103         }
 104         mmu_exit_hook();
 105 }
 106 
 107 /*
 108  * Free old dead task when we know it can never be on the cpu again.
 109  */
 110 void release_thread(struct task_struct *dead_task)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112 }
 113 
 114 void flush_thread(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116         /* Make sure old user windows don't get in the way. */
 117         flush_user_windows();
 118         current->tss.w_saved = 0;
 119         current->tss.uwinmask = 0;
 120         current->tss.sig_address = 0;
 121         current->tss.sig_desc = 0;
 122         current->tss.sstk_info.cur_status = 0;
 123         current->tss.sstk_info.the_stack = 0;
 124 
 125         if(last_task_used_math == current) {
 126                 /* Clean the fpu. */
 127                 put_psr(get_psr() | PSR_EF);
 128                 fpsave(&current->tss.float_regs[0], &current->tss.fsr,
 129                        &current->tss.fpqueue[0], &current->tss.fpqdepth);
 130         }
 131 
 132         memset(&current->tss.reg_window[0], 0,
 133                (sizeof(struct reg_window) * NSWINS));
 134         memset(&current->tss.rwbuf_stkptrs[0], 0,
 135                (sizeof(unsigned long) * NSWINS));
 136         mmu_flush_hook();
 137         /* Now, this task is no longer a kernel thread. */
 138         current->tss.flags &= ~SPARC_FLAG_KTHREAD;
 139 }
 140 
 141 /*
 142  * Copy a Sparc thread.  The fork() return value conventions
 143  * under SunOS are nothing short of bletcherous:
 144  * Parent -->  %o0 == childs  pid, %o1 == 0
 145  * Child  -->  %o0 == parents pid, %o1 == 1
 146  *
 147  * NOTE: We have a seperate fork kpsr/kwim because
 148  *       the parent could change these values between
 149  *       sys_fork invocation and when we reach here
 150  *       if the parent should sleep while trying to
 151  *       allocate the task_struct and kernel stack in
 152  *       do_fork().
 153  */
 154 extern void ret_sys_call(void);
 155 
 156 void copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
     /* [previous][next][first][last][top][bottom][index][help] */
 157                  struct task_struct *p, struct pt_regs *regs)
 158 {
 159         struct pt_regs *childregs;
 160         struct reg_window *old_stack, *new_stack;
 161         unsigned long stack_offset;
 162 
 163         if(last_task_used_math == current) {
 164                 put_psr(get_psr() | PSR_EF);
 165                 fpsave(&p->tss.float_regs[0], &p->tss.fsr,
 166                        &p->tss.fpqueue[0], &p->tss.fpqdepth);
 167         }
 168 
 169         /* Calculate offset to stack_frame & pt_regs */
 170         stack_offset = ((PAGE_SIZE*2) - TRACEREG_SZ);
 171         if(regs->psr & PSR_PS)
 172                 stack_offset -= REGWIN_SZ;
 173         childregs = ((struct pt_regs *) (p->kernel_stack_page + stack_offset));
 174         *childregs = *regs;
 175         new_stack = (((struct reg_window *) childregs) - 1);
 176         old_stack = (((struct reg_window *) regs) - 1);
 177         *new_stack = *old_stack;
 178         p->tss.ksp = p->saved_kernel_stack = (unsigned long) new_stack;
 179         p->tss.kpc = (((unsigned long) ret_sys_call) - 0x8);
 180         p->tss.kpsr = current->tss.fork_kpsr;
 181         p->tss.kwim = current->tss.fork_kwim;
 182         p->tss.kregs = childregs;
 183         childregs->u_regs[UREG_FP] = sp;
 184 
 185         if(regs->psr & PSR_PS) {
 186                 stack_offset += TRACEREG_SZ;
 187                 childregs->u_regs[UREG_FP] = p->kernel_stack_page + stack_offset;
 188                 p->tss.flags |= SPARC_FLAG_KTHREAD;
 189         } else
 190                 p->tss.flags &= ~SPARC_FLAG_KTHREAD;
 191 
 192         /* Set the return value for the child. */
 193         childregs->u_regs[UREG_I0] = current->pid;
 194         childregs->u_regs[UREG_I1] = 1;
 195 
 196         /* Set the return value for the parent. */
 197         regs->u_regs[UREG_I1] = 0;
 198 }
 199 
 200 /*
 201  * fill in the user structure for a core dump..
 202  */
 203 void dump_thread(struct pt_regs * regs, struct user * dump)
     /* [previous][next][first][last][top][bottom][index][help] */
 204 {
 205         unsigned long first_stack_page;
 206 
 207         dump->magic = SUNOS_CORE_MAGIC;
 208         dump->len = sizeof(struct user);
 209         dump->regs.psr = regs->psr;
 210         dump->regs.pc = regs->pc;
 211         dump->regs.npc = regs->npc;
 212         dump->regs.y = regs->y;
 213         /* fuck me plenty */
 214         memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
 215         dump->uexec = current->tss.core_exec;
 216         dump->u_tsize = (((unsigned long) current->mm->end_code) -
 217                 ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
 218         dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
 219         dump->u_dsize -= dump->u_tsize;
 220         dump->u_dsize &= ~(PAGE_SIZE - 1);
 221         first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
 222         dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
 223         memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->tss.float_regs[0], (sizeof(unsigned long) * 32));
 224         dump->fpu.fpstatus.fsr = current->tss.fsr;
 225         dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
 226         dump->fpu.fpstatus.fpq_count = current->tss.fpqdepth;
 227         memcpy(&dump->fpu.fpstatus.fpq[0], &current->tss.fpqueue[0],
 228                ((sizeof(unsigned long) * 2) * 16));
 229         dump->sigcode = current->tss.sig_desc;
 230 }
 231 
 232 /*
 233  * fill in the fpu structure for a core dump.
 234  */
 235 int dump_fpu (void *fpu_structure)
     /* [previous][next][first][last][top][bottom][index][help] */
 236 {
 237         /* Currently we report that we couldn't dump the fpu structure */
 238         return 0;
 239 }
 240 
 241 /*
 242  * sparc_execve() executes a new program after the asm stub has set
 243  * things up for us.  This should basically do what I want it to.
 244  */
 245 asmlinkage int sparc_execve(struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 246 {
 247         int error;
 248         char *filename;
 249 
 250         flush_user_windows();
 251         error = getname((char *) regs->u_regs[UREG_I0], &filename);
 252         if(error)
 253                 return error;
 254         error = do_execve(filename, (char **) regs->u_regs[UREG_I1],
 255                           (char **) regs->u_regs[UREG_I2], regs);
 256         putname(filename);
 257         return error;
 258 }

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