linux-old/arch/cris/kernel/process.c
<<
>>
Prefs
   1/* $Id: process.c,v 1.22 2001/11/13 09:40:43 orjanf Exp $
   2 * 
   3 *  linux/arch/cris/kernel/process.c
   4 *
   5 *  Copyright (C) 1995  Linus Torvalds
   6 *  Copyright (C) 2000, 2001  Axis Communications AB
   7 *
   8 *  Authors:   Bjorn Wesen (bjornw@axis.com)
   9 *
  10 *  $Log: process.c,v $
  11 *  Revision 1.22  2001/11/13 09:40:43  orjanf
  12 *  Added dump_fpu (needed for core dumps).
  13 *
  14 *  Revision 1.21  2001/11/12 18:26:21  pkj
  15 *  Fixed compiler warnings.
  16 *
  17 *  Revision 1.20  2001/10/03 08:21:39  jonashg
  18 *  cause_of_death does not exist if CONFIG_SVINTO_SIM is defined.
  19 *
  20 *  Revision 1.19  2001/09/26 11:52:54  bjornw
  21 *  INIT_MMAP is gone in 2.4.10
  22 *
  23 *  Revision 1.18  2001/08/21 21:43:51  hp
  24 *  Move last watchdog fix inside #ifdef CONFIG_ETRAX_WATCHDOG
  25 *
  26 *  Revision 1.17  2001/08/21 13:48:01  jonashg
  27 *  Added fix by HP to avoid oops when doing a hard_reset_now.
  28 *
  29 *  Revision 1.16  2001/06/21 02:00:40  hp
  30 *      * entry.S: Include asm/unistd.h.
  31 *      (_sys_call_table): Use section .rodata, not .data.
  32 *      (_kernel_thread): Move from...
  33 *      * process.c: ... here.
  34 *      * entryoffsets.c (VAL): Break out from...
  35 *      (OF): Use VAL.
  36 *      (LCLONE_VM): New asmified value from CLONE_VM.
  37 *
  38 *  Revision 1.15  2001/06/20 16:31:57  hp
  39 *  Add comments to describe empty functions according to review.
  40 *
  41 *  Revision 1.14  2001/05/29 11:27:59  markusl
  42 *  Fixed so that hard_reset_now will do reset even if watchdog wasn't enabled
  43 *
  44 *  Revision 1.13  2001/03/20 19:44:06  bjornw
  45 *  Use the 7th syscall argument for regs instead of current_regs
  46 *
  47 */
  48
  49/*
  50 * This file handles the architecture-dependent parts of process handling..
  51 */
  52
  53#define __KERNEL_SYSCALLS__
  54#include <stdarg.h>
  55
  56#include <linux/errno.h>
  57#include <linux/sched.h>
  58#include <linux/kernel.h>
  59#include <linux/mm.h>
  60#include <linux/stddef.h>
  61#include <linux/unistd.h>
  62#include <linux/ptrace.h>
  63#include <linux/slab.h>
  64#include <linux/user.h>
  65#include <linux/a.out.h>
  66#include <linux/elfcore.h>
  67#include <linux/interrupt.h>
  68#include <linux/delay.h>
  69
  70#include <asm/uaccess.h>
  71#include <asm/pgtable.h>
  72#include <asm/system.h>
  73#include <asm/io.h>
  74#include <asm/processor.h>
  75
  76#include <linux/smp.h>
  77
  78//#define DEBUG
  79
  80/*
  81 * Initial task structure. Make this a per-architecture thing,
  82 * because different architectures tend to have different
  83 * alignment requirements and potentially different initial
  84 * setup.
  85 */
  86
  87static struct fs_struct init_fs = INIT_FS;
  88static struct files_struct init_files = INIT_FILES;
  89static struct signal_struct init_signals = INIT_SIGNALS;
  90struct mm_struct init_mm = INIT_MM(init_mm);
  91
  92/*
  93 * Initial task structure.
  94 *
  95 * We need to make sure that this is 8192-byte aligned due to the
  96 * way process stacks are handled. This is done by having a special
  97 * "init_task" linker map entry..
  98 */
  99
 100union task_union init_task_union 
 101      __attribute__((__section__(".data.init_task"))) =
 102             { INIT_TASK(init_task_union.task) };
 103
 104/*
 105 * The hlt_counter, disable_hlt and enable_hlt is just here as a hook if
 106 * there would ever be a halt sequence (for power save when idle) with
 107 * some largish delay when halting or resuming *and* a driver that can't
 108 * afford that delay.  The hlt_counter would then be checked before
 109 * executing the halt sequence, and the driver marks the unhaltable
 110 * region by enable_hlt/disable_hlt.
 111 */
 112
 113static int hlt_counter=0;
 114
 115void disable_hlt(void)
 116{
 117        hlt_counter++;
 118}
 119
 120void enable_hlt(void)
 121{
 122        hlt_counter--;
 123}
 124 
 125int cpu_idle(void *unused)
 126{
 127        while(1) {
 128                current->counter = -100;
 129                schedule();
 130        }
 131}
 132
 133/* if the watchdog is enabled, we can simply disable interrupts and go
 134 * into an eternal loop, and the watchdog will reset the CPU after 0.1s
 135 * if on the other hand the watchdog wasn't enabled, we just enable it and wait
 136 */
 137
 138void hard_reset_now (void)
 139{
 140        /*
 141         * Don't declare this variable elsewhere.  We don't want any other
 142         * code to know about it than the watchdog handler in entry.S and
 143         * this code, implementing hard reset through the watchdog.
 144         */
 145#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
 146        extern int cause_of_death;
 147#endif
 148
 149        printk("*** HARD RESET ***\n");
 150        cli();
 151
 152#if defined(CONFIG_ETRAX_WATCHDOG) && !defined(CONFIG_SVINTO_SIM)
 153        cause_of_death = 0xbedead;
 154#else
 155        /* Since we dont plan to keep on reseting the watchdog,
 156           the key can be arbitrary hence three */
 157        *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
 158                IO_STATE(R_WATCHDOG, enable, start);
 159#endif
 160
 161        while(1) /* waiting for RETRIBUTION! */ ;
 162}
 163
 164void machine_restart(void)
 165{
 166        hard_reset_now();
 167}
 168
 169/*
 170 * Similar to machine_power_off, but don't shut off power.  Add code
 171 * here to freeze the system for e.g. post-mortem debug purpose when
 172 * possible.  This halt has nothing to do with the idle halt.
 173 */
 174
 175void machine_halt(void)
 176{
 177}
 178
 179/* If or when software power-off is implemented, add code here.  */
 180
 181void machine_power_off(void)
 182{
 183}
 184
 185/*
 186 * When a process does an "exec", machine state like FPU and debug
 187 * registers need to be reset.  This is a hook function for that.
 188 * Currently we don't have any such state to reset, so this is empty.
 189 */
 190
 191void flush_thread(void)
 192{
 193}
 194
 195asmlinkage void ret_from_sys_call(void);
 196
 197/* setup the child's kernel stack with a pt_regs and switch_stack on it.
 198 * it will be un-nested during _resume and _ret_from_sys_call when the
 199 * new thread is scheduled.
 200 *
 201 * also setup the thread switching structure which is used to keep
 202 * thread-specific data during _resumes.
 203 *
 204 */
 205
 206int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 207                unsigned long unused,
 208                struct task_struct *p, struct pt_regs *regs)
 209{
 210        struct pt_regs * childregs;
 211        struct switch_stack *swstack;
 212        
 213        /* put the pt_regs structure at the end of the new kernel stack page and fix it up
 214         * remember that the task_struct doubles as the kernel stack for the task
 215         */
 216
 217        childregs = user_regs(p);
 218
 219        *childregs = *regs;  /* struct copy of pt_regs */
 220
 221        childregs->r10 = 0;  /* child returns 0 after a fork/clone */
 222        
 223        /* put the switch stack right below the pt_regs */
 224
 225        swstack = ((struct switch_stack *)childregs) - 1;
 226
 227        swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
 228
 229        /* we want to return into ret_from_sys_call after the _resume */
 230
 231        swstack->return_ip = (unsigned long) ret_from_sys_call;
 232        
 233        /* fix the user-mode stackpointer */
 234
 235        p->thread.usp = usp;    
 236
 237        /* and the kernel-mode one */
 238
 239        p->thread.ksp = (unsigned long) swstack;
 240
 241#ifdef DEBUG
 242        printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
 243        show_registers(childregs);
 244#endif
 245
 246        return 0;
 247}
 248
 249/*
 250 * fill in the user structure for a core dump..
 251 */
 252void dump_thread(struct pt_regs * regs, struct user * dump)
 253{
 254#if 0
 255        int i;
 256
 257        /* changed the size calculations - should hopefully work better. lbt */
 258        dump->magic = CMAGIC;
 259        dump->start_code = 0;
 260        dump->start_stack = regs->esp & ~(PAGE_SIZE - 1);
 261        dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
 262        dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
 263        dump->u_dsize -= dump->u_tsize;
 264        dump->u_ssize = 0;
 265        for (i = 0; i < 8; i++)
 266                dump->u_debugreg[i] = current->debugreg[i];  
 267
 268        if (dump->start_stack < TASK_SIZE)
 269                dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
 270
 271        dump->regs = *regs;
 272
 273        dump->u_fpvalid = dump_fpu (regs, &dump->i387);
 274#endif 
 275}
 276
 277/* Fill in the fpu structure for a core dump. */
 278int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
 279{
 280        return 0;
 281}
 282
 283/* 
 284 * Be aware of the "magic" 7th argument in the four system-calls below.
 285 * They need the latest stackframe, which is put as the 7th argument by
 286 * entry.S. The previous arguments are dummies or actually used, but need
 287 * to be defined to reach the 7th argument.
 288 *
 289 * N.B.: Another method to get the stackframe is to use current_regs(). But
 290 * it returns the latest stack-frame stacked when going from _user mode_ and
 291 * some of these (at least sys_clone) are called from kernel-mode sometimes
 292 * (for example during kernel_thread, above) and thus cannot use it. Thus,
 293 * to be sure not to get any surprises, we use the method for the other calls
 294 * as well.
 295 */
 296
 297asmlinkage int sys_fork(long r10, long r11, long r12, long r13, long mof, long srp,
 298                        struct pt_regs *regs)
 299{
 300        return do_fork(SIGCHLD, rdusp(), regs, 0);
 301}
 302
 303/* if newusp is 0, we just grab the old usp */
 304
 305asmlinkage int sys_clone(unsigned long newusp, unsigned long flags,
 306                         long r12, long r13, long mof, long srp,
 307                         struct pt_regs *regs)
 308{
 309        if (!newusp)
 310                newusp = rdusp();
 311        return do_fork(flags, newusp, regs, 0);
 312}
 313
 314/* vfork is a system call in i386 because of register-pressure - maybe
 315 * we can remove it and handle it in libc but we put it here until then.
 316 */
 317
 318asmlinkage int sys_vfork(long r10, long r11, long r12, long r13, long mof, long srp,
 319                         struct pt_regs *regs)
 320{
 321        return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0);
 322}
 323
 324/*
 325 * sys_execve() executes a new program.
 326 */
 327asmlinkage int sys_execve(const char *fname, char **argv, char **envp,
 328                          long r13, long mof, long srp, 
 329                          struct pt_regs *regs)
 330{
 331        int error;
 332        char *filename;
 333
 334        filename = getname(fname);
 335        error = PTR_ERR(filename);
 336
 337        if (IS_ERR(filename))
 338                goto out;
 339        error = do_execve(filename, argv, envp, regs);
 340        putname(filename);
 341 out:
 342        return error;
 343}
 344
 345/*
 346 * These bracket the sleeping functions..
 347 */
 348
 349extern void scheduling_functions_start_here(void);
 350extern void scheduling_functions_end_here(void);
 351#define first_sched     ((unsigned long) scheduling_functions_start_here)
 352#define last_sched      ((unsigned long) scheduling_functions_end_here)
 353
 354unsigned long get_wchan(struct task_struct *p)
 355{
 356#if 0
 357        /* YURGH. TODO. */
 358
 359        unsigned long ebp, esp, eip;
 360        unsigned long stack_page;
 361        int count = 0;
 362        if (!p || p == current || p->state == TASK_RUNNING)
 363                return 0;
 364        stack_page = (unsigned long)p;
 365        esp = p->thread.esp;
 366        if (!stack_page || esp < stack_page || esp > 8188+stack_page)
 367                return 0;
 368        /* include/asm-i386/system.h:switch_to() pushes ebp last. */
 369        ebp = *(unsigned long *) esp;
 370        do {
 371                if (ebp < stack_page || ebp > 8184+stack_page)
 372                        return 0;
 373                eip = *(unsigned long *) (ebp+4);
 374                if (eip < first_sched || eip >= last_sched)
 375                        return eip;
 376                ebp = *(unsigned long *) ebp;
 377        } while (count++ < 16);
 378#endif
 379        return 0;
 380}
 381#undef last_sched
 382#undef first_sched
 383
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.