* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / arch / sparc64 / kernel / process.c
blob0e0f540b7064e88f623cc01a41373f0e3f501e31
1 /* $Id: process.c,v 1.100 1999/08/31 04:39:39 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/pgtable.h>
37 #include <asm/processor.h>
38 #include <asm/pstate.h>
39 #include <asm/elf.h>
40 #include <asm/fpumacro.h>
42 /* #define VERBOSE_SHOWREGS */
44 #ifndef __SMP__
47 * the idle loop on a Sparc... ;)
49 int cpu_idle(void)
51 if (current->pid != 0)
52 return -EPERM;
54 /* endless idle loop with no priority at all */
55 current->priority = 0;
56 current->counter = -100;
57 init_idle();
59 for (;;) {
60 /* If current->need_resched is zero we should really
61 * setup for a system wakup event and execute a shutdown
62 * instruction.
64 * But this requires writing back the contents of the
65 * L2 cache etc. so implement this later. -DaveM
67 schedule();
68 check_pgt_cache();
70 return 0;
73 #else
76 * the idle loop on a UltraMultiPenguin...
78 #define idle_me_harder() (cpu_data[current->processor].idle_volume += 1)
79 #define unidle_me() (cpu_data[current->processor].idle_volume = 0)
80 int cpu_idle(void)
82 current->priority = 0;
83 current->counter = -100;
84 init_idle();
86 while(1) {
87 if (current->need_resched != 0) {
88 unidle_me();
89 schedule();
90 check_pgt_cache();
92 idle_me_harder();
94 /* The store ordering is so that IRQ handlers on
95 * other cpus see our increasing idleness for the buddy
96 * redistribution algorithm. -DaveM
98 membar("#StoreStore | #StoreLoad");
102 #endif
104 extern char reboot_command [];
106 #ifdef CONFIG_SUN_CONSOLE
107 extern void (*prom_palette)(int);
108 extern int serial_console;
109 #endif
111 void machine_halt(void)
113 sti();
114 mdelay(8);
115 cli();
116 #ifdef CONFIG_SUN_CONSOLE
117 if (!serial_console && prom_palette)
118 prom_palette (1);
119 #endif
120 prom_halt();
121 panic("Halt failed!");
124 void machine_restart(char * cmd)
126 char *p;
128 sti();
129 mdelay(8);
130 cli();
132 p = strchr (reboot_command, '\n');
133 if (p) *p = 0;
134 #ifdef CONFIG_SUN_CONSOLE
135 if (!serial_console && prom_palette)
136 prom_palette (1);
137 #endif
138 if (cmd)
139 prom_reboot(cmd);
140 if (*reboot_command)
141 prom_reboot(reboot_command);
142 prom_reboot("");
143 panic("Reboot failed!");
146 static void show_regwindow32(struct pt_regs *regs)
148 struct reg_window32 *rw;
149 struct reg_window32 r_w;
150 mm_segment_t old_fs;
152 __asm__ __volatile__ ("flushw");
153 rw = (struct reg_window32 *)((long)(unsigned)regs->u_regs[14]);
154 old_fs = get_fs();
155 set_fs (USER_DS);
156 if (copy_from_user (&r_w, rw, sizeof(r_w))) {
157 set_fs (old_fs);
158 return;
160 rw = &r_w;
161 set_fs (old_fs);
162 printk("l0: %08x l1: %08x l2: %08x l3: %08x "
163 "l4: %08x l5: %08x l6: %08x l7: %08x\n",
164 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
165 rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
166 printk("i0: %08x i1: %08x i2: %08x i3: %08x "
167 "i4: %08x i5: %08x i6: %08x i7: %08x\n",
168 rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
169 rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
172 static void show_regwindow(struct pt_regs *regs)
174 struct reg_window *rw;
175 struct reg_window r_w;
176 mm_segment_t old_fs;
178 if ((regs->tstate & TSTATE_PRIV) || !(current->thread.flags & SPARC_FLAG_32BIT)) {
179 __asm__ __volatile__ ("flushw");
180 rw = (struct reg_window *)(regs->u_regs[14] + STACK_BIAS);
181 if (!(regs->tstate & TSTATE_PRIV)) {
182 old_fs = get_fs();
183 set_fs (USER_DS);
184 if (copy_from_user (&r_w, rw, sizeof(r_w))) {
185 set_fs (old_fs);
186 return;
188 rw = &r_w;
189 set_fs (old_fs);
191 } else {
192 show_regwindow32(regs);
193 return;
195 printk("l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n",
196 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3]);
197 printk("l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
198 rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
199 printk("i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n",
200 rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3]);
201 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
202 rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
205 void show_stackframe(struct sparc_stackf *sf)
207 unsigned long size;
208 unsigned long *stk;
209 int i;
211 printk("l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n"
212 "l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
213 sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
214 sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
215 printk("i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n"
216 "i4: %016lx i5: %016lx fp: %016lx ret_pc: %016lx\n",
217 sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
218 sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
219 printk("sp: %016lx x0: %016lx x1: %016lx x2: %016lx\n"
220 "x3: %016lx x4: %016lx x5: %016lx xx: %016lx\n",
221 (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
222 sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
223 sf->xxargs[0]);
224 size = ((unsigned long)sf->fp) - ((unsigned long)sf);
225 size -= STACKFRAME_SZ;
226 stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
227 i = 0;
228 do {
229 printk("s%d: %016lx\n", i++, *stk++);
230 } while ((size -= sizeof(unsigned long)));
233 void show_stackframe32(struct sparc_stackf32 *sf)
235 unsigned long size;
236 unsigned *stk;
237 int i;
239 printk("l0: %08x l1: %08x l2: %08x l3: %08x\n",
240 sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3]);
241 printk("l4: %08x l5: %08x l6: %08x l7: %08x\n",
242 sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
243 printk("i0: %08x i1: %08x i2: %08x i3: %08x\n",
244 sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3]);
245 printk("i4: %08x i5: %08x fp: %08x ret_pc: %08x\n",
246 sf->ins[4], sf->ins[5], sf->fp, sf->callers_pc);
247 printk("sp: %08x x0: %08x x1: %08x x2: %08x\n"
248 "x3: %08x x4: %08x x5: %08x xx: %08x\n",
249 sf->structptr, sf->xargs[0], sf->xargs[1],
250 sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
251 sf->xxargs[0]);
252 size = ((unsigned long)sf->fp) - ((unsigned long)sf);
253 size -= STACKFRAME32_SZ;
254 stk = (unsigned *)((unsigned long)sf + STACKFRAME32_SZ);
255 i = 0;
256 do {
257 printk("s%d: %08x\n", i++, *stk++);
258 } while ((size -= sizeof(unsigned)));
261 #ifdef __SMP__
262 static spinlock_t regdump_lock = SPIN_LOCK_UNLOCKED;
263 #endif
265 void __show_regs(struct pt_regs * regs)
267 #ifdef __SMP__
268 unsigned long flags;
270 spin_lock_irqsave(&regdump_lock, flags);
271 printk("CPU[%d]: local_irq_count[%ld] global_irq_count[%d]\n",
272 smp_processor_id(), local_irq_count,
273 atomic_read(&global_irq_count));
274 #endif
275 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x\n", regs->tstate,
276 regs->tpc, regs->tnpc, regs->y);
277 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
278 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
279 regs->u_regs[3]);
280 printk("g4: %016lx g5: %016lx g6: %016lx g7: %016lx\n",
281 regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
282 regs->u_regs[7]);
283 printk("o0: %016lx o1: %016lx o2: %016lx o3: %016lx\n",
284 regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
285 regs->u_regs[11]);
286 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
287 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
288 regs->u_regs[15]);
289 show_regwindow(regs);
290 #ifdef __SMP__
291 spin_unlock_irqrestore(&regdump_lock, flags);
292 #endif
295 #ifdef VERBOSE_SHOWREGS
296 static void idump_from_user (unsigned int *pc)
298 int i;
299 int code;
301 if((((unsigned long) pc) & 3))
302 return;
304 pc -= 3;
305 for(i = -3; i < 6; i++) {
306 get_user(code, pc);
307 printk("%c%08x%c",i?' ':'<',code,i?' ':'>');
308 pc++;
310 printk("\n");
312 #endif
314 void show_regs(struct pt_regs *regs)
316 #ifdef VERBOSE_SHOWREGS
317 extern long etrap, etraptl1;
318 #endif
319 __show_regs(regs);
320 #ifdef __SMP__
322 extern void smp_report_regs(void);
324 smp_report_regs();
326 #endif
328 #ifdef VERBOSE_SHOWREGS
329 if (regs->tpc >= &etrap && regs->tpc < &etraptl1 &&
330 regs->u_regs[14] >= (long)current - PAGE_SIZE &&
331 regs->u_regs[14] < (long)current + 6 * PAGE_SIZE) {
332 printk ("*********parent**********\n");
333 __show_regs((struct pt_regs *)(regs->u_regs[14] + STACK_BIAS + REGWIN_SZ));
334 idump_from_user(((struct pt_regs *)(regs->u_regs[14] + STACK_BIAS + REGWIN_SZ))->tpc);
335 printk ("*********endpar**********\n");
337 #endif
340 void show_regs32(struct pt_regs32 *regs)
342 printk("PSR: %08x PC: %08x NPC: %08x Y: %08x\n", regs->psr,
343 regs->pc, regs->npc, regs->y);
344 printk("g0: %08x g1: %08x g2: %08x g3: %08x ",
345 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
346 regs->u_regs[3]);
347 printk("g4: %08x g5: %08x g6: %08x g7: %08x\n",
348 regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
349 regs->u_regs[7]);
350 printk("o0: %08x o1: %08x o2: %08x o3: %08x ",
351 regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
352 regs->u_regs[11]);
353 printk("o4: %08x o5: %08x sp: %08x ret_pc: %08x\n",
354 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
355 regs->u_regs[15]);
358 void show_thread(struct thread_struct *thread)
360 int i;
362 #if 0
363 printk("kregs: 0x%016lx\n", (unsigned long)thread->kregs);
364 show_regs(thread->kregs);
365 #endif
366 printk("sig_address: 0x%016lx\n", thread->sig_address);
367 printk("sig_desc: 0x%016lx\n", thread->sig_desc);
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;
538 flush_user_windows();
539 window = t->w_saved;
540 if(window != 0) {
541 window -= 1;
542 do {
543 unsigned long sp = (t->rwbuf_stkptrs[window] + bias);
544 struct reg_window *rwin = &t->reg_window[window];
546 if(copy_to_user((char *)sp, rwin, winsize))
547 goto barf;
548 } while(window--);
550 t->w_saved = 0;
551 return;
552 barf:
553 do_exit(SIGILL);
556 /* Copy a Sparc thread. The fork() return value conventions
557 * under SunOS are nothing short of bletcherous:
558 * Parent --> %o0 == childs pid, %o1 == 0
559 * Child --> %o0 == parents pid, %o1 == 1
561 * NOTE: We have a separate fork kpsr/kwim because
562 * the parent could change these values between
563 * sys_fork invocation and when we reach here
564 * if the parent should sleep while trying to
565 * allocate the task_struct and kernel stack in
566 * do_fork().
568 int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
569 struct task_struct *p, struct pt_regs *regs)
571 struct thread_struct *t = &p->thread;
572 char *child_trap_frame;
574 /* Calculate offset to stack_frame & pt_regs */
575 child_trap_frame = ((char *)p) + ((PAGE_SIZE << 1) - (TRACEREG_SZ+REGWIN_SZ));
576 memcpy(child_trap_frame, (((struct reg_window *)regs)-1), (TRACEREG_SZ+REGWIN_SZ));
577 t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
578 t->flags |= SPARC_FLAG_NEWCHILD;
579 t->kregs = (struct pt_regs *)(child_trap_frame+sizeof(struct reg_window));
580 t->cwp = (regs->tstate + 1) & TSTATE_CWP;
581 t->fpsaved[0] = 0;
582 if(regs->tstate & TSTATE_PRIV) {
583 /* Special case, if we are spawning a kernel thread from
584 * a userspace task (via KMOD, NFS, or similar) we must
585 * disable performance counters in the child because the
586 * address space and protection realm are changing.
588 if (t->flags & SPARC_FLAG_PERFCTR) {
589 t->user_cntd0 = t->user_cntd1 = NULL;
590 t->pcr_reg = 0;
591 t->flags &= ~(SPARC_FLAG_PERFCTR);
593 t->kregs->u_regs[UREG_FP] = p->thread.ksp;
594 t->current_ds = KERNEL_DS;
595 flush_register_windows();
596 memcpy((void *)(t->ksp + STACK_BIAS),
597 (void *)(regs->u_regs[UREG_FP] + STACK_BIAS),
598 sizeof(struct reg_window));
599 t->kregs->u_regs[UREG_G6] = (unsigned long) p;
600 } else {
601 if(t->flags & SPARC_FLAG_32BIT) {
602 sp &= 0x00000000ffffffffUL;
603 regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
605 t->kregs->u_regs[UREG_FP] = sp;
606 t->current_ds = USER_DS;
607 if (sp != regs->u_regs[UREG_FP]) {
608 unsigned long csp;
610 csp = clone_stackframe(sp, regs->u_regs[UREG_FP]);
611 if(!csp)
612 return -EFAULT;
613 t->kregs->u_regs[UREG_FP] = csp;
615 if (t->utraps)
616 t->utraps[0]++;
619 /* Set the return value for the child. */
620 t->kregs->u_regs[UREG_I0] = current->pid;
621 t->kregs->u_regs[UREG_I1] = 1;
623 /* Set the second return value for the parent. */
624 regs->u_regs[UREG_I1] = 0;
625 #if 0
626 printk("\ncopy_thread: c(%p[mm(%p:%p)]) p(%p[mm(%p:%p)])\n",
627 current, current->mm, current->active_mm,
628 p, p->mm, p->active_mm);
629 printk("copy_thread: c MM_ctx(%016lx) MM_pgd(%016lx)\n",
630 (current->mm ? current->mm->context : 0),
631 (current->mm ? pgd_val(current->mm->pgd[0]) : 0));
632 printk("copy_thread: p MM_ctx(%016lx) MM_pgd(%08x)\n",
633 (p->mm ? p->mm->context : 0),
634 (p->mm ? pgd_val(p->mm->pgd[0]) : 0));
635 printk("copy_thread: c->flags(%x) p->flags(%x) ",
636 current->thread.flags, p->thread.flags);
637 #endif
638 return 0;
642 * This is the mechanism for creating a new kernel thread.
644 * NOTE! Only a kernel-only process(ie the swapper or direct descendants
645 * who haven't done an "execve()") should use this: it will work within
646 * a system call from a "real" process, but the process memory space will
647 * not be free'd until both the parent and the child have exited.
649 pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
651 long retval;
653 __asm__ __volatile("mov %1, %%g1\n\t"
654 "mov %2, %%o0\n\t" /* Clone flags. */
655 "mov 0, %%o1\n\t" /* usp arg == 0 */
656 "t 0x6d\n\t" /* Linux/Sparc clone(). */
657 "brz,a,pn %%o1, 1f\n\t" /* Parent, just return. */
658 " mov %%o0, %0\n\t"
659 "jmpl %4, %%o7\n\t" /* Call the function. */
660 " mov %5, %%o0\n\t" /* Set arg in delay. */
661 "mov %3, %%g1\n\t"
662 "t 0x6d\n\t" /* Linux/Sparc exit(). */
663 /* Notreached by child. */
664 "1:" :
665 "=r" (retval) :
666 "i" (__NR_clone), "r" (flags | CLONE_VM),
667 "i" (__NR_exit), "r" (fn), "r" (arg) :
668 "g1", "o0", "o1", "memory", "cc");
669 return retval;
673 * fill in the user structure for a core dump..
675 void dump_thread(struct pt_regs * regs, struct user * dump)
677 #if 1
678 /* Only should be used for SunOS and ancient a.out
679 * SparcLinux binaries... Fixme some day when bored.
680 * But for now at least plug the security hole :-)
682 memset(dump, 0, sizeof(struct user));
683 #else
684 unsigned long first_stack_page;
685 dump->magic = SUNOS_CORE_MAGIC;
686 dump->len = sizeof(struct user);
687 dump->regs.psr = regs->psr;
688 dump->regs.pc = regs->pc;
689 dump->regs.npc = regs->npc;
690 dump->regs.y = regs->y;
691 /* fuck me plenty */
692 memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
693 dump->u_tsize = (((unsigned long) current->mm->end_code) -
694 ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
695 dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
696 dump->u_dsize -= dump->u_tsize;
697 dump->u_dsize &= ~(PAGE_SIZE - 1);
698 first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
699 dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
700 memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
701 dump->fpu.fpstatus.fsr = current->thread.fsr;
702 dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
703 dump->sigcode = current->thread.sig_desc;
704 #endif
707 typedef struct {
708 union {
709 unsigned int pr_regs[32];
710 unsigned long pr_dregs[16];
711 } pr_fr;
712 unsigned int __unused;
713 unsigned int pr_fsr;
714 unsigned char pr_qcnt;
715 unsigned char pr_q_entrysize;
716 unsigned char pr_en;
717 unsigned int pr_q[64];
718 } elf_fpregset_t32;
721 * fill in the fpu structure for a core dump.
723 int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
725 unsigned long *kfpregs = (unsigned long *)(((char *)current) + AOFF_task_fpregs);
726 unsigned long fprs = current->thread.fpsaved[0];
728 if ((current->thread.flags & SPARC_FLAG_32BIT) != 0) {
729 elf_fpregset_t32 *fpregs32 = (elf_fpregset_t32 *)fpregs;
731 if (fprs & FPRS_DL)
732 memcpy(&fpregs32->pr_fr.pr_regs[0], kfpregs,
733 sizeof(unsigned int) * 32);
734 else
735 memset(&fpregs32->pr_fr.pr_regs[0], 0,
736 sizeof(unsigned int) * 32);
737 fpregs32->pr_qcnt = 0;
738 fpregs32->pr_q_entrysize = 8;
739 memset(&fpregs32->pr_q[0], 0,
740 (sizeof(unsigned int) * 64));
741 if (fprs & FPRS_FEF) {
742 fpregs32->pr_fsr = (unsigned int) current->thread.xfsr[0];
743 fpregs32->pr_en = 1;
744 } else {
745 fpregs32->pr_fsr = 0;
746 fpregs32->pr_en = 0;
748 } else {
749 if(fprs & FPRS_DL)
750 memcpy(&fpregs->pr_regs[0], kfpregs,
751 sizeof(unsigned int) * 32);
752 else
753 memset(&fpregs->pr_regs[0], 0,
754 sizeof(unsigned int) * 32);
755 if(fprs & FPRS_DU)
756 memcpy(&fpregs->pr_regs[16], kfpregs+16,
757 sizeof(unsigned int) * 32);
758 else
759 memset(&fpregs->pr_regs[16], 0,
760 sizeof(unsigned int) * 32);
761 if(fprs & FPRS_FEF) {
762 fpregs->pr_fsr = current->thread.xfsr[0];
763 fpregs->pr_gsr = current->thread.gsr[0];
764 } else {
765 fpregs->pr_fsr = fpregs->pr_gsr = 0;
767 fpregs->pr_fprs = fprs;
769 return 1;
773 * sparc_execve() executes a new program after the asm stub has set
774 * things up for us. This should basically do what I want it to.
776 asmlinkage int sparc_execve(struct pt_regs *regs)
778 int error, base = 0;
779 char *filename;
781 /* User register window flush is done by entry.S */
783 /* Check for indirect call. */
784 if(regs->u_regs[UREG_G1] == 0)
785 base = 1;
787 lock_kernel();
788 filename = getname((char *)regs->u_regs[base + UREG_I0]);
789 error = PTR_ERR(filename);
790 if(IS_ERR(filename))
791 goto out;
792 error = do_execve(filename, (char **) regs->u_regs[base + UREG_I1],
793 (char **) regs->u_regs[base + UREG_I2], regs);
794 putname(filename);
795 if(!error) {
796 fprs_write(0);
797 current->thread.xfsr[0] = 0;
798 current->thread.fpsaved[0] = 0;
799 regs->tstate &= ~TSTATE_PEF;
801 out:
802 unlock_kernel();
803 return error;