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. sys_idle
  3. cpu_idle
  4. hard_reset_now
  5. show_regwindow
  6. show_regs
  7. exit_thread
  8. release_thread
  9. flush_thread
  10. copy_thread
  11. dump_thread
  12. dump_fpu
  13. sparc_execve

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

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