linux-old/arch/alpha/kernel/process.c
<<
>>
Prefs
   1/*
   2 *  linux/arch/alpha/kernel/process.c
   3 *
   4 *  Copyright (C) 1995  Linus Torvalds
   5 */
   6
   7/*
   8 * This file handles the architecture-dependent parts of process handling.
   9 */
  10
  11#include <linux/config.h>
  12#include <linux/errno.h>
  13#include <linux/sched.h>
  14#include <linux/kernel.h>
  15#include <linux/mm.h>
  16#include <linux/smp.h>
  17#include <linux/smp_lock.h>
  18#include <linux/stddef.h>
  19#include <linux/unistd.h>
  20#include <linux/ptrace.h>
  21#include <linux/slab.h>
  22#include <linux/user.h>
  23#include <linux/a.out.h>
  24#include <linux/utsname.h>
  25#include <linux/time.h>
  26#include <linux/major.h>
  27#include <linux/stat.h>
  28#include <linux/mman.h>
  29#include <linux/elfcore.h>
  30#include <linux/reboot.h>
  31#include <linux/tty.h>
  32#include <linux/console.h>
  33
  34#include <asm/reg.h>
  35#include <asm/uaccess.h>
  36#include <asm/system.h>
  37#include <asm/io.h>
  38#include <asm/pgtable.h>
  39#include <asm/hwrpb.h>
  40#include <asm/fpu.h>
  41
  42#include "proto.h"
  43#include "pci_impl.h"
  44
  45/*
  46 * Initial task structure. Make this a per-architecture thing,
  47 * because different architectures tend to have different
  48 * alignment requirements and potentially different initial
  49 * setup.
  50 */
  51
  52unsigned long init_user_stack[1024] = { STACK_MAGIC, };
  53static struct fs_struct init_fs = INIT_FS;
  54static struct files_struct init_files = INIT_FILES;
  55static struct signal_struct init_signals = INIT_SIGNALS;
  56struct mm_struct init_mm = INIT_MM(init_mm);
  57
  58union task_union init_task_union __attribute__((section("init_task")))
  59         = { task: INIT_TASK(init_task_union.task) };
  60
  61/*
  62 * No need to acquire the kernel lock, we're entirely local..
  63 */
  64asmlinkage int
  65sys_sethae(unsigned long hae, unsigned long a1, unsigned long a2,
  66           unsigned long a3, unsigned long a4, unsigned long a5,
  67           struct pt_regs regs)
  68{
  69        (&regs)->hae = hae;
  70        return 0;
  71}
  72
  73void
  74cpu_idle(void)
  75{
  76        /* An endless idle loop with no priority at all.  */
  77        current->nice = 20;
  78        current->counter = -100;
  79
  80        while (1) {
  81                /* FIXME -- EV6 and LCA45 know how to power down
  82                   the CPU.  */
  83
  84                /* Although we are an idle CPU, we do not want to 
  85                   get into the scheduler unnecessarily.  */
  86                long oldval = xchg(&current->need_resched, -1UL);
  87                if (!oldval)
  88                        while (current->need_resched < 0);
  89                schedule();
  90                check_pgt_cache();
  91        }
  92}
  93
  94
  95struct halt_info {
  96        int mode;
  97        char *restart_cmd;
  98};
  99
 100static void
 101common_shutdown_1(void *generic_ptr)
 102{
 103        struct halt_info *how = (struct halt_info *)generic_ptr;
 104        struct percpu_struct *cpup;
 105        unsigned long *pflags, flags;
 106        int cpuid = smp_processor_id();
 107
 108        /* No point in taking interrupts anymore. */
 109        __cli();
 110
 111        cpup = (struct percpu_struct *)
 112                        ((unsigned long)hwrpb + hwrpb->processor_offset
 113                         + hwrpb->processor_size * cpuid);
 114        pflags = &cpup->flags;
 115        flags = *pflags;
 116
 117        /* Clear reason to "default"; clear "bootstrap in progress". */
 118        flags &= ~0x00ff0001UL;
 119
 120#ifdef CONFIG_SMP
 121        /* Secondaries halt here. */
 122        if (cpuid != boot_cpuid) {
 123                flags |= 0x00040000UL; /* "remain halted" */
 124                *pflags = flags;
 125                clear_bit(cpuid, &cpu_present_mask);
 126                halt();
 127        }
 128#endif
 129
 130        if (how->mode == LINUX_REBOOT_CMD_RESTART) {
 131                if (!how->restart_cmd) {
 132                        flags |= 0x00020000UL; /* "cold bootstrap" */
 133                } else {
 134                        /* For SRM, we could probably set environment
 135                           variables to get this to work.  We'd have to
 136                           delay this until after srm_paging_stop unless
 137                           we ever got srm_fixup working.
 138
 139                           At the moment, SRM will use the last boot device,
 140                           but the file and flags will be the defaults, when
 141                           doing a "warm" bootstrap.  */
 142                        flags |= 0x00030000UL; /* "warm bootstrap" */
 143                }
 144        } else {
 145                flags |= 0x00040000UL; /* "remain halted" */
 146        }
 147        *pflags = flags;
 148
 149#ifdef CONFIG_SMP
 150        /* Wait for the secondaries to halt. */
 151        clear_bit(boot_cpuid, &cpu_present_mask);
 152        while (cpu_present_mask)
 153                barrier();
 154#endif
 155
 156        /* If booted from SRM, reset some of the original environment. */
 157        if (alpha_using_srm) {
 158#ifdef CONFIG_DUMMY_CONSOLE
 159                /* This has the effect of resetting the VGA video origin.  */
 160                take_over_console(&dummy_con, 0, MAX_NR_CONSOLES-1, 1);
 161#endif
 162                /* reset_for_srm(); */
 163                set_hae(srm_hae);
 164        }
 165
 166        if (alpha_mv.kill_arch)
 167                alpha_mv.kill_arch(how->mode);
 168
 169        if (! alpha_using_srm && how->mode != LINUX_REBOOT_CMD_RESTART) {
 170                /* Unfortunately, since MILO doesn't currently understand
 171                   the hwrpb bits above, we can't reliably halt the 
 172                   processor and keep it halted.  So just loop.  */
 173                return;
 174        }
 175
 176        if (alpha_using_srm)
 177                srm_paging_stop();
 178
 179        halt();
 180}
 181
 182static void
 183common_shutdown(int mode, char *restart_cmd)
 184{
 185        struct halt_info args;
 186        args.mode = mode;
 187        args.restart_cmd = restart_cmd;
 188#ifdef CONFIG_SMP
 189        smp_call_function(common_shutdown_1, &args, 1, 0);
 190#endif
 191        common_shutdown_1(&args);
 192}
 193
 194void
 195machine_restart(char *restart_cmd)
 196{
 197        common_shutdown(LINUX_REBOOT_CMD_RESTART, restart_cmd);
 198}
 199
 200void
 201machine_halt(void)
 202{
 203        common_shutdown(LINUX_REBOOT_CMD_HALT, NULL);
 204}
 205
 206void
 207machine_power_off(void)
 208{
 209        common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
 210}
 211
 212void
 213show_regs(struct pt_regs * regs)
 214{
 215        printk("\n");
 216        printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
 217        printk("ps: %04lx pc: [<%016lx>] CPU %d    %s\n",
 218               regs->ps, regs->pc, smp_processor_id(), print_tainted());
 219        printk("rp: [<%016lx>] sp: %p\n", regs->r26, regs+1);
 220        printk(" r0: %016lx  r1: %016lx  r2: %016lx  r3: %016lx\n",
 221               regs->r0, regs->r1, regs->r2, regs->r3);
 222        printk(" r4: %016lx  r5: %016lx  r6: %016lx  r7: %016lx\n",
 223               regs->r4, regs->r5, regs->r6, regs->r7);
 224        printk(" r8: %016lx r16: %016lx r17: %016lx r18: %016lx\n",
 225               regs->r8, regs->r16, regs->r17, regs->r18);
 226        printk("r19: %016lx r20: %016lx r21: %016lx r22: %016lx\n",
 227               regs->r19, regs->r20, regs->r21, regs->r22);
 228        printk("r23: %016lx r24: %016lx r25: %016lx r26: %016lx\n",
 229               regs->r23, regs->r24, regs->r25, regs->r26);
 230        printk("r27: %016lx r28: %016lx r29: %016lx hae: %016lx\n",
 231               regs->r27, regs->r28, regs->gp, regs->hae);
 232}
 233
 234/*
 235 * Re-start a thread when doing execve()
 236 */
 237void
 238start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
 239{
 240        set_fs(USER_DS);
 241        regs->pc = pc;
 242        regs->ps = 8;
 243        wrusp(sp);
 244}
 245
 246/*
 247 * Free current thread data structures etc..
 248 */
 249void
 250exit_thread(void)
 251{
 252}
 253
 254void
 255flush_thread(void)
 256{
 257        /* Arrange for each exec'ed process to start off with a clean slate
 258           with respect to the FPU.  This is all exceptions disabled.  */
 259        current->thread.flags &= ~IEEE_SW_MASK;
 260        wrfpcr(FPCR_DYN_NORMAL | ieee_swcr_to_fpcr(0));
 261}
 262
 263void
 264release_thread(struct task_struct *dead_task)
 265{
 266}
 267
 268/*
 269 * "alpha_clone()".. By the time we get here, the
 270 * non-volatile registers have also been saved on the
 271 * stack. We do some ugly pointer stuff here.. (see
 272 * also copy_thread)
 273 *
 274 * Notice that "fork()" is implemented in terms of clone,
 275 * with parameters (SIGCHLD, 0).
 276 */
 277int
 278alpha_clone(unsigned long clone_flags, unsigned long usp,
 279            struct switch_stack * swstack)
 280{
 281        if (!usp)
 282                usp = rdusp();
 283        return do_fork(clone_flags, usp, (struct pt_regs *) (swstack+1), 0);
 284}
 285
 286int
 287alpha_vfork(struct switch_stack * swstack)
 288{
 289        return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(),
 290                        (struct pt_regs *) (swstack+1), 0);
 291}
 292
 293/*
 294 * Copy an alpha thread..
 295 *
 296 * Note the "stack_offset" stuff: when returning to kernel mode, we need
 297 * to have some extra stack-space for the kernel stack that still exists
 298 * after the "ret_from_sys_call". When returning to user mode, we only
 299 * want the space needed by the syscall stack frame (ie "struct pt_regs").
 300 * Use the passed "regs" pointer to determine how much space we need
 301 * for a kernel fork().
 302 */
 303
 304int
 305copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
 306            unsigned long unused,
 307            struct task_struct * p, struct pt_regs * regs)
 308{
 309        extern void ret_from_sys_call(void);
 310        extern void ret_from_fork(void);
 311
 312        struct pt_regs * childregs;
 313        struct switch_stack * childstack, *stack;
 314        unsigned long stack_offset;
 315
 316        stack_offset = PAGE_SIZE - sizeof(struct pt_regs);
 317        if (!(regs->ps & 8))
 318                stack_offset = (PAGE_SIZE-1) & (unsigned long) regs;
 319        childregs = (struct pt_regs *) (stack_offset + PAGE_SIZE + (long)p);
 320                
 321        *childregs = *regs;
 322        childregs->r0 = 0;
 323        childregs->r19 = 0;
 324        childregs->r20 = 1;     /* OSF/1 has some strange fork() semantics.  */
 325        regs->r20 = 0;
 326        stack = ((struct switch_stack *) regs) - 1;
 327        childstack = ((struct switch_stack *) childregs) - 1;
 328        *childstack = *stack;
 329        childstack->r26 = (unsigned long) ret_from_fork;
 330        p->thread.usp = usp;
 331        p->thread.ksp = (unsigned long) childstack;
 332        p->thread.pal_flags = 1;        /* set FEN, clear everything else */
 333        p->thread.flags = current->thread.flags;
 334
 335        return 0;
 336}
 337
 338/*
 339 * fill in the user structure for a core dump..
 340 */
 341void
 342dump_thread(struct pt_regs * pt, struct user * dump)
 343{
 344        /* switch stack follows right below pt_regs: */
 345        struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
 346
 347        dump->magic = CMAGIC;
 348        dump->start_code  = current->mm->start_code;
 349        dump->start_data  = current->mm->start_data;
 350        dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
 351        dump->u_tsize = ((current->mm->end_code - dump->start_code)
 352                         >> PAGE_SHIFT);
 353        dump->u_dsize = ((current->mm->brk + PAGE_SIZE-1 - dump->start_data)
 354                         >> PAGE_SHIFT);
 355        dump->u_ssize = (current->mm->start_stack - dump->start_stack
 356                         + PAGE_SIZE-1) >> PAGE_SHIFT;
 357
 358        /*
 359         * We store the registers in an order/format that is
 360         * compatible with DEC Unix/OSF/1 as this makes life easier
 361         * for gdb.
 362         */
 363        dump->regs[EF_V0]  = pt->r0;
 364        dump->regs[EF_T0]  = pt->r1;
 365        dump->regs[EF_T1]  = pt->r2;
 366        dump->regs[EF_T2]  = pt->r3;
 367        dump->regs[EF_T3]  = pt->r4;
 368        dump->regs[EF_T4]  = pt->r5;
 369        dump->regs[EF_T5]  = pt->r6;
 370        dump->regs[EF_T6]  = pt->r7;
 371        dump->regs[EF_T7]  = pt->r8;
 372        dump->regs[EF_S0]  = sw->r9;
 373        dump->regs[EF_S1]  = sw->r10;
 374        dump->regs[EF_S2]  = sw->r11;
 375        dump->regs[EF_S3]  = sw->r12;
 376        dump->regs[EF_S4]  = sw->r13;
 377        dump->regs[EF_S5]  = sw->r14;
 378        dump->regs[EF_S6]  = sw->r15;
 379        dump->regs[EF_A3]  = pt->r19;
 380        dump->regs[EF_A4]  = pt->r20;
 381        dump->regs[EF_A5]  = pt->r21;
 382        dump->regs[EF_T8]  = pt->r22;
 383        dump->regs[EF_T9]  = pt->r23;
 384        dump->regs[EF_T10] = pt->r24;
 385        dump->regs[EF_T11] = pt->r25;
 386        dump->regs[EF_RA]  = pt->r26;
 387        dump->regs[EF_T12] = pt->r27;
 388        dump->regs[EF_AT]  = pt->r28;
 389        dump->regs[EF_SP]  = rdusp();
 390        dump->regs[EF_PS]  = pt->ps;
 391        dump->regs[EF_PC]  = pt->pc;
 392        dump->regs[EF_GP]  = pt->gp;
 393        dump->regs[EF_A0]  = pt->r16;
 394        dump->regs[EF_A1]  = pt->r17;
 395        dump->regs[EF_A2]  = pt->r18;
 396        memcpy((char *)dump->regs + EF_SIZE, sw->fp, 32 * 8);
 397}
 398
 399int
 400dump_fpu(struct pt_regs * regs, elf_fpregset_t *r)
 401{
 402        /* switch stack follows right below pt_regs: */
 403        struct switch_stack * sw = ((struct switch_stack *) regs) - 1;
 404        memcpy(r, sw->fp, 32 * 8);
 405        return 1;
 406}
 407
 408/*
 409 * sys_execve() executes a new program.
 410 *
 411 * This works due to the alpha calling sequence: the first 6 args
 412 * are gotten from registers, while the rest is on the stack, so
 413 * we get a0-a5 for free, and then magically find "struct pt_regs"
 414 * on the stack for us..
 415 *
 416 * Don't do this at home.
 417 */
 418asmlinkage int
 419sys_execve(char *ufilename, char **argv, char **envp,
 420           unsigned long a3, unsigned long a4, unsigned long a5,
 421           struct pt_regs regs)
 422{
 423        int error;
 424        char *filename;
 425
 426        filename = getname(ufilename);
 427        error = PTR_ERR(filename);
 428        if (IS_ERR(filename))
 429                goto out;
 430        error = do_execve(filename, argv, envp, &regs);
 431        putname(filename);
 432out:
 433        return error;
 434}
 435
 436/*
 437 * These bracket the sleeping functions..
 438 */
 439extern void scheduling_functions_start_here(void);
 440extern void scheduling_functions_end_here(void);
 441#define first_sched     ((unsigned long) scheduling_functions_start_here)
 442#define last_sched      ((unsigned long) scheduling_functions_end_here)
 443
 444unsigned long
 445get_wchan(struct task_struct *p)
 446{
 447        unsigned long schedule_frame;
 448        unsigned long pc;
 449        if (!p || p == current || p->state == TASK_RUNNING)
 450                return 0;
 451        /*
 452         * This one depends on the frame size of schedule().  Do a
 453         * "disass schedule" in gdb to find the frame size.  Also, the
 454         * code assumes that sleep_on() follows immediately after
 455         * interruptible_sleep_on() and that add_timer() follows
 456         * immediately after interruptible_sleep().  Ugly, isn't it?
 457         * Maybe adding a wchan field to task_struct would be better,
 458         * after all...
 459         */
 460
 461        pc = thread_saved_pc(&p->thread);
 462        if (pc >= first_sched && pc < last_sched) {
 463                schedule_frame = ((unsigned long *)p->thread.ksp)[6];
 464                return ((unsigned long *)schedule_frame)[12];
 465        }
 466        return pc;
 467}
 468
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.