2 * linux/arch/alpha/kernel/process.c
4 * Copyright (C) 1995 Linus Torvalds
8 * This file handles the architecture-dependent parts of process handling.
11 #include <linux/config.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/kernel.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>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
38 #include <asm/pgtable.h>
39 #include <asm/hwrpb.h>
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
52 unsigned long init_user_stack[1024] = { STACK_MAGIC, };
53 static struct fs_struct init_fs = INIT_FS;
54 static struct files_struct init_files = INIT_FILES;
55 static struct signal_struct init_signals = INIT_SIGNALS;
56 struct mm_struct init_mm = INIT_MM(init_mm);
58 union task_union init_task_union __attribute__((section("init_task")))
59 = { task: INIT_TASK(init_task_union.task) };
62 * No need to acquire the kernel lock, we're entirely local..
65 sys_sethae(unsigned long hae, unsigned long a1, unsigned long a2,
66 unsigned long a3, unsigned long a4, unsigned long a5,
76 /* An endless idle loop with no priority at all. */
78 current->counter = -100;
81 /* FIXME -- EV6 and LCA45 know how to power down
84 /* Although we are an idle CPU, we do not want to
85 get into the scheduler unnecessarily. */
86 long oldval = xchg(¤t->need_resched, -1UL);
88 while (current->need_resched < 0);
101 common_shutdown_1(void *generic_ptr)
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();
108 /* No point in taking interrupts anymore. */
111 cpup = (struct percpu_struct *)
112 ((unsigned long)hwrpb + hwrpb->processor_offset
113 + hwrpb->processor_size * cpuid);
114 pflags = &cpup->flags;
117 /* Clear reason to "default"; clear "bootstrap in progress". */
118 flags &= ~0x00ff0001UL;
121 /* Secondaries halt here. */
122 if (cpuid != boot_cpuid) {
123 flags |= 0x00040000UL; /* "remain halted" */
125 clear_bit(cpuid, &cpu_present_mask);
130 if (how->mode == LINUX_REBOOT_CMD_RESTART) {
131 if (!how->restart_cmd) {
132 flags |= 0x00020000UL; /* "cold bootstrap" */
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.
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" */
145 flags |= 0x00040000UL; /* "remain halted" */
150 /* Wait for the secondaries to halt. */
151 clear_bit(boot_cpuid, &cpu_present_mask);
152 while (cpu_present_mask)
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);
162 /* reset_for_srm(); */
166 if (alpha_mv.kill_arch)
167 alpha_mv.kill_arch(how->mode);
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. */
183 common_shutdown(int mode, char *restart_cmd)
185 struct halt_info args;
187 args.restart_cmd = restart_cmd;
189 smp_call_function(common_shutdown_1, &args, 1, 0);
191 common_shutdown_1(&args);
195 machine_restart(char *restart_cmd)
197 common_shutdown(LINUX_REBOOT_CMD_RESTART, restart_cmd);
203 common_shutdown(LINUX_REBOOT_CMD_HALT, NULL);
207 machine_power_off(void)
209 common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
213 show_regs(struct pt_regs * regs)
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);
235 * Re-start a thread when doing execve()
238 start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
247 * Free current thread data structures etc..
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));
264 release_thread(struct task_struct *dead_task)
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
274 * Notice that "fork()" is implemented in terms of clone,
275 * with parameters (SIGCHLD, 0).
278 alpha_clone(unsigned long clone_flags, unsigned long usp,
279 struct switch_stack * swstack)
283 return do_fork(clone_flags, usp, (struct pt_regs *) (swstack+1), 0);
287 alpha_vfork(struct switch_stack * swstack)
289 return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(),
290 (struct pt_regs *) (swstack+1), 0);
294 * Copy an alpha thread..
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().
305 copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
306 unsigned long unused,
307 struct task_struct * p, struct pt_regs * regs)
309 extern void ret_from_sys_call(void);
310 extern void ret_from_fork(void);
312 struct pt_regs * childregs;
313 struct switch_stack * childstack, *stack;
314 unsigned long stack_offset;
316 stack_offset = PAGE_SIZE - sizeof(struct pt_regs);
318 stack_offset = (PAGE_SIZE-1) & (unsigned long) regs;
319 childregs = (struct pt_regs *) (stack_offset + PAGE_SIZE + (long)p);
324 childregs->r20 = 1; /* OSF/1 has some strange fork() semantics. */
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;
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;
339 * Fill in the user structure for an ECOFF core dump.
342 dump_thread(struct pt_regs * pt, struct user * dump)
344 /* switch stack follows right below pt_regs: */
345 struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
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)
353 dump->u_dsize = ((current->mm->brk + PAGE_SIZE-1 - dump->start_data)
355 dump->u_ssize = (current->mm->start_stack - dump->start_stack
356 + PAGE_SIZE-1) >> PAGE_SHIFT;
359 * We store the registers in an order/format that is
360 * compatible with DEC Unix/OSF/1 as this makes life easier
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);
400 * Fill in the user structure for a ELF core dump.
403 dump_elf_thread(elf_gregset_t dest, struct pt_regs *pt,
404 struct task_struct *task)
406 /* switch stack follows right below pt_regs: */
407 struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
442 /* Once upon a time this was the PS value. Which is stupid
443 since that is always 8 for usermode. Usurped for the more
444 useful value of the thread's UNIQUE field. */
445 dest[32] = task->thread.unique;
449 dump_fpu(struct pt_regs * regs, elf_fpregset_t *r)
451 /* switch stack follows right below pt_regs: */
452 struct switch_stack * sw = ((struct switch_stack *) regs) - 1;
453 memcpy(r, sw->fp, 32 * 8);
458 * sys_execve() executes a new program.
460 * This works due to the alpha calling sequence: the first 6 args
461 * are gotten from registers, while the rest is on the stack, so
462 * we get a0-a5 for free, and then magically find "struct pt_regs"
463 * on the stack for us..
465 * Don't do this at home.
468 sys_execve(char *ufilename, char **argv, char **envp,
469 unsigned long a3, unsigned long a4, unsigned long a5,
475 filename = getname(ufilename);
476 error = PTR_ERR(filename);
477 if (IS_ERR(filename))
479 error = do_execve(filename, argv, envp, ®s);
486 * These bracket the sleeping functions..
488 extern void scheduling_functions_start_here(void);
489 extern void scheduling_functions_end_here(void);
490 #define first_sched ((unsigned long) scheduling_functions_start_here)
491 #define last_sched ((unsigned long) scheduling_functions_end_here)
494 get_wchan(struct task_struct *p)
496 unsigned long schedule_frame;
498 if (!p || p == current || p->state == TASK_RUNNING)
501 * This one depends on the frame size of schedule(). Do a
502 * "disass schedule" in gdb to find the frame size. Also, the
503 * code assumes that sleep_on() follows immediately after
504 * interruptible_sleep_on() and that add_timer() follows
505 * immediately after interruptible_sleep(). Ugly, isn't it?
506 * Maybe adding a wchan field to task_struct would be better,
510 pc = thread_saved_pc(&p->thread);
511 if (pc >= first_sched && pc < last_sched) {
512 schedule_frame = ((unsigned long *)p->thread.ksp)[6];
513 return ((unsigned long *)schedule_frame)[12];