Merge with Linux 2.4.0-test4-pre3.
[linux-2.6/linux-mips.git] / arch / sparc64 / kernel / process.c
blob2d5d8145282c7b67286760fa00f5fd49f60da31b
1 /* $Id: process.c,v 1.109 2000/07/11 01:38:57 davem Exp $
2 * arch/sparc64/kernel/process.c
4 * Copyright (C) 1995, 1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6 * Copyright (C) 1997, 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
9 /*
10 * This file handles the architecture-dependent parts of process handling..
13 #define __KERNEL_SYSCALLS__
14 #include <stdarg.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/smp.h>
21 #include <linux/smp_lock.h>
22 #include <linux/stddef.h>
23 #include <linux/unistd.h>
24 #include <linux/ptrace.h>
25 #include <linux/malloc.h>
26 #include <linux/user.h>
27 #include <linux/a.out.h>
28 #include <linux/config.h>
29 #include <linux/reboot.h>
30 #include <linux/delay.h>
32 #include <asm/oplib.h>
33 #include <asm/uaccess.h>
34 #include <asm/system.h>
35 #include <asm/page.h>
36 #include <asm/pgalloc.h>
37 #include <asm/pgtable.h>
38 #include <asm/processor.h>
39 #include <asm/pstate.h>
40 #include <asm/elf.h>
41 #include <asm/fpumacro.h>
43 /* #define VERBOSE_SHOWREGS */
45 #ifndef CONFIG_SMP
48 * the idle loop on a Sparc... ;)
50 int cpu_idle(void)
52 if (current->pid != 0)
53 return -EPERM;
55 /* endless idle loop with no priority at all */
56 current->nice = 20;
57 current->counter = -100;
58 init_idle();
60 for (;;) {
61 /* If current->need_resched is zero we should really
62 * setup for a system wakup event and execute a shutdown
63 * instruction.
65 * But this requires writing back the contents of the
66 * L2 cache etc. so implement this later. -DaveM
68 schedule();
69 check_pgt_cache();
71 return 0;
74 #else
77 * the idle loop on a UltraMultiPenguin...
79 #define idle_me_harder() (cpu_data[current->processor].idle_volume += 1)
80 #define unidle_me() (cpu_data[current->processor].idle_volume = 0)
81 int cpu_idle(void)
83 current->nice = 20;
84 current->counter = -100;
85 init_idle();
87 while(1) {
88 if (current->need_resched != 0) {
89 unidle_me();
90 schedule();
91 check_pgt_cache();
93 idle_me_harder();
95 /* The store ordering is so that IRQ handlers on
96 * other cpus see our increasing idleness for the buddy
97 * redistribution algorithm. -DaveM
99 membar("#StoreStore | #StoreLoad");
103 #endif
105 extern char reboot_command [];
107 #ifdef CONFIG_SUN_CONSOLE
108 extern void (*prom_palette)(int);
109 extern int serial_console;
110 #endif
112 void machine_halt(void)
114 sti();
115 mdelay(8);
116 cli();
117 #ifdef CONFIG_SUN_CONSOLE
118 if (!serial_console && prom_palette)
119 prom_palette (1);
120 #endif
121 prom_halt();
122 panic("Halt failed!");
125 void machine_restart(char * cmd)
127 char *p;
129 sti();
130 mdelay(8);
131 cli();
133 p = strchr (reboot_command, '\n');
134 if (p) *p = 0;
135 #ifdef CONFIG_SUN_CONSOLE
136 if (!serial_console && prom_palette)
137 prom_palette (1);
138 #endif
139 if (cmd)
140 prom_reboot(cmd);
141 if (*reboot_command)
142 prom_reboot(reboot_command);
143 prom_reboot("");
144 panic("Reboot failed!");
147 static void show_regwindow32(struct pt_regs *regs)
149 struct reg_window32 *rw;
150 struct reg_window32 r_w;
151 mm_segment_t old_fs;
153 __asm__ __volatile__ ("flushw");
154 rw = (struct reg_window32 *)((long)(unsigned)regs->u_regs[14]);
155 old_fs = get_fs();
156 set_fs (USER_DS);
157 if (copy_from_user (&r_w, rw, sizeof(r_w))) {
158 set_fs (old_fs);
159 return;
161 rw = &r_w;
162 set_fs (old_fs);
163 printk("l0: %08x l1: %08x l2: %08x l3: %08x "
164 "l4: %08x l5: %08x l6: %08x l7: %08x\n",
165 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
166 rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
167 printk("i0: %08x i1: %08x i2: %08x i3: %08x "
168 "i4: %08x i5: %08x i6: %08x i7: %08x\n",
169 rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
170 rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
173 static void show_regwindow(struct pt_regs *regs)
175 struct reg_window *rw;
176 struct reg_window r_w;
177 mm_segment_t old_fs;
179 if ((regs->tstate & TSTATE_PRIV) || !(current->thread.flags & SPARC_FLAG_32BIT)) {
180 __asm__ __volatile__ ("flushw");
181 rw = (struct reg_window *)(regs->u_regs[14] + STACK_BIAS);
182 if (!(regs->tstate & TSTATE_PRIV)) {
183 old_fs = get_fs();
184 set_fs (USER_DS);
185 if (copy_from_user (&r_w, rw, sizeof(r_w))) {
186 set_fs (old_fs);
187 return;
189 rw = &r_w;
190 set_fs (old_fs);
192 } else {
193 show_regwindow32(regs);
194 return;
196 printk("l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n",
197 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3]);
198 printk("l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
199 rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
200 printk("i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n",
201 rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3]);
202 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
203 rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
206 void show_stackframe(struct sparc_stackf *sf)
208 unsigned long size;
209 unsigned long *stk;
210 int i;
212 printk("l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n"
213 "l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
214 sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
215 sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
216 printk("i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n"
217 "i4: %016lx i5: %016lx fp: %016lx ret_pc: %016lx\n",
218 sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
219 sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
220 printk("sp: %016lx x0: %016lx x1: %016lx x2: %016lx\n"
221 "x3: %016lx x4: %016lx x5: %016lx xx: %016lx\n",
222 (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
223 sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
224 sf->xxargs[0]);
225 size = ((unsigned long)sf->fp) - ((unsigned long)sf);
226 size -= STACKFRAME_SZ;
227 stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
228 i = 0;
229 do {
230 printk("s%d: %016lx\n", i++, *stk++);
231 } while ((size -= sizeof(unsigned long)));
234 void show_stackframe32(struct sparc_stackf32 *sf)
236 unsigned long size;
237 unsigned *stk;
238 int i;
240 printk("l0: %08x l1: %08x l2: %08x l3: %08x\n",
241 sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3]);
242 printk("l4: %08x l5: %08x l6: %08x l7: %08x\n",
243 sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
244 printk("i0: %08x i1: %08x i2: %08x i3: %08x\n",
245 sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3]);
246 printk("i4: %08x i5: %08x fp: %08x ret_pc: %08x\n",
247 sf->ins[4], sf->ins[5], sf->fp, sf->callers_pc);
248 printk("sp: %08x x0: %08x x1: %08x x2: %08x\n"
249 "x3: %08x x4: %08x x5: %08x xx: %08x\n",
250 sf->structptr, sf->xargs[0], sf->xargs[1],
251 sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
252 sf->xxargs[0]);
253 size = ((unsigned long)sf->fp) - ((unsigned long)sf);
254 size -= STACKFRAME32_SZ;
255 stk = (unsigned *)((unsigned long)sf + STACKFRAME32_SZ);
256 i = 0;
257 do {
258 printk("s%d: %08x\n", i++, *stk++);
259 } while ((size -= sizeof(unsigned)));
262 #ifdef CONFIG_SMP
263 static spinlock_t regdump_lock = SPIN_LOCK_UNLOCKED;
264 #endif
266 void __show_regs(struct pt_regs * regs)
268 #ifdef CONFIG_SMP
269 unsigned long flags;
271 spin_lock_irqsave(&regdump_lock, flags);
272 printk("CPU[%d]: local_irq_count[%u] irqs_running[%d]\n",
273 smp_processor_id(),
274 local_irq_count(smp_processor_id()),
275 irqs_running());
276 #endif
277 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x\n", regs->tstate,
278 regs->tpc, regs->tnpc, regs->y);
279 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
280 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
281 regs->u_regs[3]);
282 printk("g4: %016lx g5: %016lx g6: %016lx g7: %016lx\n",
283 regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
284 regs->u_regs[7]);
285 printk("o0: %016lx o1: %016lx o2: %016lx o3: %016lx\n",
286 regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
287 regs->u_regs[11]);
288 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
289 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
290 regs->u_regs[15]);
291 show_regwindow(regs);
292 #ifdef CONFIG_SMP
293 spin_unlock_irqrestore(&regdump_lock, flags);
294 #endif
297 #ifdef VERBOSE_SHOWREGS
298 static void idump_from_user (unsigned int *pc)
300 int i;
301 int code;
303 if((((unsigned long) pc) & 3))
304 return;
306 pc -= 3;
307 for(i = -3; i < 6; i++) {
308 get_user(code, pc);
309 printk("%c%08x%c",i?' ':'<',code,i?' ':'>');
310 pc++;
312 printk("\n");
314 #endif
316 void show_regs(struct pt_regs *regs)
318 #ifdef VERBOSE_SHOWREGS
319 extern long etrap, etraptl1;
320 #endif
321 __show_regs(regs);
322 #ifdef CONFIG_SMP
324 extern void smp_report_regs(void);
326 smp_report_regs();
328 #endif
330 #ifdef VERBOSE_SHOWREGS
331 if (regs->tpc >= &etrap && regs->tpc < &etraptl1 &&
332 regs->u_regs[14] >= (long)current - PAGE_SIZE &&
333 regs->u_regs[14] < (long)current + 6 * PAGE_SIZE) {
334 printk ("*********parent**********\n");
335 __show_regs((struct pt_regs *)(regs->u_regs[14] + STACK_BIAS + REGWIN_SZ));
336 idump_from_user(((struct pt_regs *)(regs->u_regs[14] + STACK_BIAS + REGWIN_SZ))->tpc);
337 printk ("*********endpar**********\n");
339 #endif
342 void show_regs32(struct pt_regs32 *regs)
344 printk("PSR: %08x PC: %08x NPC: %08x Y: %08x\n", regs->psr,
345 regs->pc, regs->npc, regs->y);
346 printk("g0: %08x g1: %08x g2: %08x g3: %08x ",
347 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
348 regs->u_regs[3]);
349 printk("g4: %08x g5: %08x g6: %08x g7: %08x\n",
350 regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
351 regs->u_regs[7]);
352 printk("o0: %08x o1: %08x o2: %08x o3: %08x ",
353 regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
354 regs->u_regs[11]);
355 printk("o4: %08x o5: %08x sp: %08x ret_pc: %08x\n",
356 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
357 regs->u_regs[15]);
360 void show_thread(struct thread_struct *thread)
362 int i;
364 #if 0
365 printk("kregs: 0x%016lx\n", (unsigned long)thread->kregs);
366 show_regs(thread->kregs);
367 #endif
368 printk("ksp: 0x%016lx\n", thread->ksp);
370 if (thread->w_saved) {
371 for (i = 0; i < NSWINS; i++) {
372 if (!thread->rwbuf_stkptrs[i])
373 continue;
374 printk("reg_window[%d]:\n", i);
375 printk("stack ptr: 0x%016lx\n", thread->rwbuf_stkptrs[i]);
377 printk("w_saved: 0x%04x\n", thread->w_saved);
380 printk("flags: 0x%08x\n", thread->flags);
381 printk("current_ds: 0x%x\n", thread->current_ds.seg);
384 /* Free current thread data structures etc.. */
385 void exit_thread(void)
387 struct thread_struct *t = &current->thread;
389 if (t->utraps) {
390 if (t->utraps[0] < 2)
391 kfree (t->utraps);
392 else
393 t->utraps[0]--;
396 /* Turn off performance counters if on. */
397 if (t->flags & SPARC_FLAG_PERFCTR) {
398 t->user_cntd0 = t->user_cntd1 = NULL;
399 t->pcr_reg = 0;
400 t->flags &= ~(SPARC_FLAG_PERFCTR);
401 write_pcr(0);
405 void flush_thread(void)
407 struct thread_struct *t = &current->thread;
409 if (current->mm) {
410 if (t->flags & SPARC_FLAG_32BIT) {
411 struct mm_struct *mm = current->mm;
412 pgd_t *pgd0 = &mm->pgd[0];
413 unsigned long pgd_cache;
415 if (pgd_none(*pgd0)) {
416 pmd_t *page = get_pmd_fast();
417 if (!page)
418 (void) get_pmd_slow(pgd0, 0);
419 else
420 pgd_set(pgd0, page);
422 pgd_cache = pgd_val(*pgd0) << 11UL;
423 __asm__ __volatile__("stxa %0, [%1] %2"
424 : /* no outputs */
425 : "r" (pgd_cache),
426 "r" (TSB_REG),
427 "i" (ASI_DMMU));
430 t->w_saved = 0;
432 /* Turn off performance counters if on. */
433 if (t->flags & SPARC_FLAG_PERFCTR) {
434 t->user_cntd0 = t->user_cntd1 = NULL;
435 t->pcr_reg = 0;
436 t->flags &= ~(SPARC_FLAG_PERFCTR);
437 write_pcr(0);
440 /* Clear FPU register state. */
441 t->fpsaved[0] = 0;
443 if (t->current_ds.seg != ASI_AIUS)
444 set_fs(USER_DS);
446 /* Init new signal delivery disposition. */
447 t->flags &= ~SPARC_FLAG_NEWSIGNALS;
450 /* It's a bit more tricky when 64-bit tasks are involved... */
451 static unsigned long clone_stackframe(unsigned long csp, unsigned long psp)
453 unsigned long fp, distance, rval;
455 if (!(current->thread.flags & SPARC_FLAG_32BIT)) {
456 csp += STACK_BIAS;
457 psp += STACK_BIAS;
458 __get_user(fp, &(((struct reg_window *)psp)->ins[6]));
459 } else
460 __get_user(fp, &(((struct reg_window32 *)psp)->ins[6]));
462 /* Now 8-byte align the stack as this is mandatory in the
463 * Sparc ABI due to how register windows work. This hides
464 * the restriction from thread libraries etc. -DaveM
466 csp &= ~7UL;
468 distance = fp - psp;
469 rval = (csp - distance);
470 if (copy_in_user(rval, psp, distance))
471 rval = 0;
472 else if (current->thread.flags & SPARC_FLAG_32BIT) {
473 if (put_user(((u32)csp), &(((struct reg_window32 *)rval)->ins[6])))
474 rval = 0;
475 } else {
476 if (put_user(((u64)csp - STACK_BIAS),
477 &(((struct reg_window *)rval)->ins[6])))
478 rval = 0;
479 else
480 rval = rval - STACK_BIAS;
483 return rval;
486 /* Standard stuff. */
487 static inline void shift_window_buffer(int first_win, int last_win,
488 struct thread_struct *t)
490 int i;
492 for (i = first_win; i < last_win; i++) {
493 t->rwbuf_stkptrs[i] = t->rwbuf_stkptrs[i+1];
494 memcpy(&t->reg_window[i], &t->reg_window[i+1],
495 sizeof(struct reg_window));
499 void synchronize_user_stack(void)
501 struct thread_struct *t = &current->thread;
502 unsigned long window;
504 flush_user_windows();
505 if ((window = t->w_saved) != 0) {
506 int winsize = REGWIN_SZ;
507 int bias = 0;
509 if (t->flags & SPARC_FLAG_32BIT)
510 winsize = REGWIN32_SZ;
511 else
512 bias = STACK_BIAS;
514 window -= 1;
515 do {
516 unsigned long sp = (t->rwbuf_stkptrs[window] + bias);
517 struct reg_window *rwin = &t->reg_window[window];
519 if (!copy_to_user((char *)sp, rwin, winsize)) {
520 shift_window_buffer(window, t->w_saved - 1, t);
521 t->w_saved--;
523 } while (window--);
527 void fault_in_user_windows(struct pt_regs *regs)
529 struct thread_struct *t = &current->thread;
530 unsigned long window;
531 int winsize = REGWIN_SZ;
532 int bias = 0;
534 if (t->flags & SPARC_FLAG_32BIT)
535 winsize = REGWIN32_SZ;
536 else
537 bias = STACK_BIAS;
539 flush_user_windows();
540 window = t->w_saved;
542 if (window != 0) {
543 window -= 1;
544 do {
545 unsigned long sp = (t->rwbuf_stkptrs[window] + bias);
546 struct reg_window *rwin = &t->reg_window[window];
548 if (copy_to_user((char *)sp, rwin, winsize))
549 goto barf;
550 } while (window--);
552 t->w_saved = 0;
553 return;
555 barf:
556 t->w_saved = window + 1;
557 do_exit(SIGILL);
560 /* Copy a Sparc thread. The fork() return value conventions
561 * under SunOS are nothing short of bletcherous:
562 * Parent --> %o0 == childs pid, %o1 == 0
563 * Child --> %o0 == parents pid, %o1 == 1
565 * NOTE: We have a separate fork kpsr/kwim because
566 * the parent could change these values between
567 * sys_fork invocation and when we reach here
568 * if the parent should sleep while trying to
569 * allocate the task_struct and kernel stack in
570 * do_fork().
572 int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
573 struct task_struct *p, struct pt_regs *regs)
575 struct thread_struct *t = &p->thread;
576 char *child_trap_frame;
578 /* Calculate offset to stack_frame & pt_regs */
579 child_trap_frame = ((char *)p) + ((PAGE_SIZE << 1) - (TRACEREG_SZ+REGWIN_SZ));
580 memcpy(child_trap_frame, (((struct reg_window *)regs)-1), (TRACEREG_SZ+REGWIN_SZ));
581 t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
582 t->flags |= SPARC_FLAG_NEWCHILD;
583 t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct reg_window));
584 t->cwp = (regs->tstate + 1) & TSTATE_CWP;
585 t->fpsaved[0] = 0;
587 if (regs->tstate & TSTATE_PRIV) {
588 /* Special case, if we are spawning a kernel thread from
589 * a userspace task (via KMOD, NFS, or similar) we must
590 * disable performance counters in the child because the
591 * address space and protection realm are changing.
593 if (t->flags & SPARC_FLAG_PERFCTR) {
594 t->user_cntd0 = t->user_cntd1 = NULL;
595 t->pcr_reg = 0;
596 t->flags &= ~(SPARC_FLAG_PERFCTR);
598 t->kregs->u_regs[UREG_FP] = p->thread.ksp;
599 t->current_ds = KERNEL_DS;
600 flush_register_windows();
601 memcpy((void *)(t->ksp + STACK_BIAS),
602 (void *)(regs->u_regs[UREG_FP] + STACK_BIAS),
603 sizeof(struct reg_window));
604 t->kregs->u_regs[UREG_G6] = (unsigned long) p;
605 } else {
606 if (t->flags & SPARC_FLAG_32BIT) {
607 sp &= 0x00000000ffffffffUL;
608 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
610 t->kregs->u_regs[UREG_FP] = sp;
611 t->current_ds = USER_DS;
612 if (sp != regs->u_regs[UREG_FP]) {
613 unsigned long csp;
615 csp = clone_stackframe(sp, regs->u_regs[UREG_FP]);
616 if (!csp)
617 return -EFAULT;
618 t->kregs->u_regs[UREG_FP] = csp;
620 if (t->utraps)
621 t->utraps[0]++;
624 /* Set the return value for the child. */
625 t->kregs->u_regs[UREG_I0] = current->pid;
626 t->kregs->u_regs[UREG_I1] = 1;
628 /* Set the second return value for the parent. */
629 regs->u_regs[UREG_I1] = 0;
631 return 0;
635 * This is the mechanism for creating a new kernel thread.
637 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
638 * who haven't done an "execve()") should use this: it will work within
639 * a system call from a "real" process, but the process memory space will
640 * not be free'd until both the parent and the child have exited.
642 pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
644 long retval;
646 __asm__ __volatile("mov %1, %%g1\n\t"
647 "mov %2, %%o0\n\t" /* Clone flags. */
648 "mov 0, %%o1\n\t" /* usp arg == 0 */
649 "t 0x6d\n\t" /* Linux/Sparc clone(). */
650 "brz,a,pn %%o1, 1f\n\t" /* Parent, just return. */
651 " mov %%o0, %0\n\t"
652 "jmpl %4, %%o7\n\t" /* Call the function. */
653 " mov %5, %%o0\n\t" /* Set arg in delay. */
654 "mov %3, %%g1\n\t"
655 "t 0x6d\n\t" /* Linux/Sparc exit(). */
656 /* Notreached by child. */
657 "1:" :
658 "=r" (retval) :
659 "i" (__NR_clone), "r" (flags | CLONE_VM),
660 "i" (__NR_exit), "r" (fn), "r" (arg) :
661 "g1", "o0", "o1", "memory", "cc");
662 return retval;
666 * fill in the user structure for a core dump..
668 void dump_thread(struct pt_regs * regs, struct user * dump)
670 #if 1
671 /* Only should be used for SunOS and ancient a.out
672 * SparcLinux binaries... Fixme some day when bored.
673 * But for now at least plug the security hole :-)
675 memset(dump, 0, sizeof(struct user));
676 #else
677 unsigned long first_stack_page;
678 dump->magic = SUNOS_CORE_MAGIC;
679 dump->len = sizeof(struct user);
680 dump->regs.psr = regs->psr;
681 dump->regs.pc = regs->pc;
682 dump->regs.npc = regs->npc;
683 dump->regs.y = regs->y;
684 /* fuck me plenty */
685 memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
686 dump->u_tsize = (((unsigned long) current->mm->end_code) -
687 ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
688 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
689 dump->u_dsize -= dump->u_tsize;
690 dump->u_dsize &= ~(PAGE_SIZE - 1);
691 first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
692 dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
693 memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
694 dump->fpu.fpstatus.fsr = current->thread.fsr;
695 dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
696 #endif
699 typedef struct {
700 union {
701 unsigned int pr_regs[32];
702 unsigned long pr_dregs[16];
703 } pr_fr;
704 unsigned int __unused;
705 unsigned int pr_fsr;
706 unsigned char pr_qcnt;
707 unsigned char pr_q_entrysize;
708 unsigned char pr_en;
709 unsigned int pr_q[64];
710 } elf_fpregset_t32;
713 * fill in the fpu structure for a core dump.
715 int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
717 unsigned long *kfpregs = (unsigned long *)(((char *)current) + AOFF_task_fpregs);
718 unsigned long fprs = current->thread.fpsaved[0];
720 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
721 elf_fpregset_t32 *fpregs32 = (elf_fpregset_t32 *)fpregs;
723 if (fprs & FPRS_DL)
724 memcpy(&fpregs32->pr_fr.pr_regs[0], kfpregs,
725 sizeof(unsigned int) * 32);
726 else
727 memset(&fpregs32->pr_fr.pr_regs[0], 0,
728 sizeof(unsigned int) * 32);
729 fpregs32->pr_qcnt = 0;
730 fpregs32->pr_q_entrysize = 8;
731 memset(&fpregs32->pr_q[0], 0,
732 (sizeof(unsigned int) * 64));
733 if (fprs & FPRS_FEF) {
734 fpregs32->pr_fsr = (unsigned int) current->thread.xfsr[0];
735 fpregs32->pr_en = 1;
736 } else {
737 fpregs32->pr_fsr = 0;
738 fpregs32->pr_en = 0;
740 } else {
741 if(fprs & FPRS_DL)
742 memcpy(&fpregs->pr_regs[0], kfpregs,
743 sizeof(unsigned int) * 32);
744 else
745 memset(&fpregs->pr_regs[0], 0,
746 sizeof(unsigned int) * 32);
747 if(fprs & FPRS_DU)
748 memcpy(&fpregs->pr_regs[16], kfpregs+16,
749 sizeof(unsigned int) * 32);
750 else
751 memset(&fpregs->pr_regs[16], 0,
752 sizeof(unsigned int) * 32);
753 if(fprs & FPRS_FEF) {
754 fpregs->pr_fsr = current->thread.xfsr[0];
755 fpregs->pr_gsr = current->thread.gsr[0];
756 } else {
757 fpregs->pr_fsr = fpregs->pr_gsr = 0;
759 fpregs->pr_fprs = fprs;
761 return 1;
765 * sparc_execve() executes a new program after the asm stub has set
766 * things up for us. This should basically do what I want it to.
768 asmlinkage int sparc_execve(struct pt_regs *regs)
770 int error, base = 0;
771 char *filename;
773 /* User register window flush is done by entry.S */
775 /* Check for indirect call. */
776 if (regs->u_regs[UREG_G1] == 0)
777 base = 1;
779 filename = getname((char *)regs->u_regs[base + UREG_I0]);
780 error = PTR_ERR(filename);
781 if (IS_ERR(filename))
782 goto out;
783 error = do_execve(filename, (char **) regs->u_regs[base + UREG_I1],
784 (char **) regs->u_regs[base + UREG_I2], regs);
785 putname(filename);
786 if (!error) {
787 fprs_write(0);
788 current->thread.xfsr[0] = 0;
789 current->thread.fpsaved[0] = 0;
790 regs->tstate &= ~TSTATE_PEF;
792 out:
793 return error;