process.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:19k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*  $Id: process.c,v 1.158 2001/11/26 23:45:00 davem Exp $
  2.  *  linux/arch/sparc/kernel/process.c
  3.  *
  4.  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  5.  *  Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
  6.  */
  7. /*
  8.  * This file handles the architecture-dependent parts of process handling..
  9.  */
  10. #define __KERNEL_SYSCALLS__
  11. #include <stdarg.h>
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/stddef.h>
  17. #include <linux/unistd.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/slab.h>
  20. #include <linux/user.h>
  21. #include <linux/a.out.h>
  22. #include <linux/config.h>
  23. #include <linux/smp.h>
  24. #include <linux/smp_lock.h>
  25. #include <linux/reboot.h>
  26. #include <linux/delay.h>
  27. #include <linux/pm.h>
  28. #include <asm/auxio.h>
  29. #include <asm/oplib.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/system.h>
  32. #include <asm/page.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/delay.h>
  36. #include <asm/processor.h>
  37. #include <asm/psr.h>
  38. #include <asm/elf.h>
  39. /* 
  40.  * Power management idle function 
  41.  * Set in pm platform drivers
  42.  */
  43. void (*pm_idle)(void);
  44. /* 
  45.  * Power-off handler instantiation for pm.h compliance
  46.  * This is done via auxio, but could be used as a fallback
  47.  * handler when auxio is not present-- unused for now...
  48.  */
  49. void (*pm_power_off)(void);
  50. extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
  51. struct task_struct *last_task_used_math = NULL;
  52. struct task_struct *current_set[NR_CPUS] = {&init_task, };
  53. #ifndef CONFIG_SMP
  54. #define SUN4C_FAULT_HIGH 100
  55. /*
  56.  * the idle loop on a Sparc... ;)
  57.  */
  58. int cpu_idle(void)
  59. {
  60. int ret = -EPERM;
  61. if (current->pid != 0)
  62. goto out;
  63. /* endless idle loop with no priority at all */
  64. current->nice = 20;
  65. current->counter = -100;
  66. init_idle();
  67. for (;;) {
  68. if (ARCH_SUN4C_SUN4) {
  69. static int count = HZ;
  70. static unsigned long last_jiffies;
  71. static unsigned long last_faults;
  72. static unsigned long fps;
  73. unsigned long now;
  74. unsigned long faults;
  75. unsigned long flags;
  76. extern unsigned long sun4c_kernel_faults;
  77. extern void sun4c_grow_kernel_ring(void);
  78. save_and_cli(flags);
  79. now = jiffies;
  80. count -= (now - last_jiffies);
  81. last_jiffies = now;
  82. if (count < 0) {
  83. count += HZ;
  84. faults = sun4c_kernel_faults;
  85. fps = (fps + (faults - last_faults)) >> 1;
  86. last_faults = faults;
  87. #if 0
  88. printk("kernel faults / second = %ldn", fps);
  89. #endif
  90. if (fps >= SUN4C_FAULT_HIGH) {
  91. sun4c_grow_kernel_ring();
  92. }
  93. }
  94. restore_flags(flags);
  95. }
  96. while((!current->need_resched) && pm_idle) {
  97. (*pm_idle)();
  98. }
  99. schedule();
  100. check_pgt_cache();
  101. }
  102. ret = 0;
  103. out:
  104. return ret;
  105. }
  106. #else
  107. /* This is being executed in task 0 'user space'. */
  108. int cpu_idle(void)
  109. {
  110. /* endless idle loop with no priority at all */
  111. current->nice = 20;
  112. current->counter = -100;
  113. init_idle();
  114. while(1) {
  115. if(current->need_resched) {
  116. schedule();
  117. check_pgt_cache();
  118. }
  119. barrier(); /* or else gcc optimizes... */
  120. }
  121. }
  122. #endif
  123. extern char reboot_command [];
  124. extern int serial_console;
  125. #ifdef CONFIG_SUN_CONSOLE
  126. extern void (*prom_palette)(int);
  127. #endif
  128. void machine_halt(void)
  129. {
  130. sti();
  131. mdelay(8);
  132. cli();
  133. #ifdef CONFIG_SUN_CONSOLE
  134. if (!serial_console && prom_palette)
  135. prom_palette (1);
  136. #endif
  137. prom_halt();
  138. panic("Halt failed!");
  139. }
  140. void machine_restart(char * cmd)
  141. {
  142. char *p;
  143. sti();
  144. mdelay(8);
  145. cli();
  146. p = strchr (reboot_command, 'n');
  147. if (p) *p = 0;
  148. #ifdef CONFIG_SUN_CONSOLE
  149. if (!serial_console && prom_palette)
  150. prom_palette (1);
  151. #endif
  152. if (cmd)
  153. prom_reboot(cmd);
  154. if (*reboot_command)
  155. prom_reboot(reboot_command);
  156. prom_feval ("reset");
  157. panic("Reboot failed!");
  158. }
  159. void machine_power_off(void)
  160. {
  161. #ifdef CONFIG_SUN_AUXIO
  162. if (auxio_power_register && !serial_console)
  163. *auxio_power_register |= AUXIO_POWER_OFF;
  164. #endif
  165. machine_halt();
  166. }
  167. void show_regwindow(struct reg_window *rw)
  168. {
  169. printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
  170.        "l4: %08lx l5: %08lx l6: %08lx l7: %08lxn",
  171.        rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
  172.        rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
  173. printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
  174.        "i4: %08lx i5: %08lx fp: %08lx i7: %08lxn",
  175.        rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  176.        rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
  177. }
  178. static spinlock_t sparc_backtrace_lock = SPIN_LOCK_UNLOCKED;
  179. void __show_backtrace(unsigned long fp)
  180. {
  181. struct reg_window *rw;
  182. unsigned long flags;
  183. int cpu = smp_processor_id();
  184. spin_lock_irqsave(&sparc_backtrace_lock, flags);
  185. rw = (struct reg_window *)fp;
  186.         while(rw && (((unsigned long) rw) >= PAGE_OFFSET) &&
  187.             !(((unsigned long) rw) & 0x7)) {
  188. printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] "
  189.        "FP[%08lx] CALLER[%08lx]n", cpu,
  190.        rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  191.        rw->ins[4], rw->ins[5],
  192.        rw->ins[6],
  193.        rw->ins[7]);
  194. rw = (struct reg_window *) rw->ins[6];
  195. }
  196. spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
  197. }
  198. #define __SAVE __asm__ __volatile__("save %sp, -0x40, %spnt")
  199. #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0nt")
  200. #define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))
  201. void show_backtrace(void)
  202. {
  203. unsigned long fp;
  204. __SAVE; __SAVE; __SAVE; __SAVE;
  205. __SAVE; __SAVE; __SAVE; __SAVE;
  206. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  207. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  208. __GET_FP(fp);
  209. __show_backtrace(fp);
  210. }
  211. #ifdef CONFIG_SMP
  212. void smp_show_backtrace_all_cpus(void)
  213. {
  214. xc0((smpfunc_t) show_backtrace);
  215. show_backtrace();
  216. }
  217. #endif
  218. void show_stackframe(struct sparc_stackf *sf)
  219. {
  220. unsigned long size;
  221. unsigned long *stk;
  222. int i;
  223. printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
  224.        "l4: %08lx l5: %08lx l6: %08lx l7: %08lxn",
  225.        sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
  226.        sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
  227. printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
  228.        "i4: %08lx i5: %08lx fp: %08lx i7: %08lxn",
  229.        sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
  230.        sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
  231. printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx "
  232.        "x3: %08lx x4: %08lx x5: %08lx xx: %08lxn",
  233.        (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
  234.        sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
  235.        sf->xxargs[0]);
  236. size = ((unsigned long)sf->fp) - ((unsigned long)sf);
  237. size -= STACKFRAME_SZ;
  238. stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
  239. i = 0;
  240. do {
  241. printk("s%d: %08lxn", i++, *stk++);
  242. } while ((size -= sizeof(unsigned long)));
  243. }
  244. void show_regs(struct pt_regs * regs)
  245. {
  246.         printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx    %sn", regs->psr,
  247.        regs->pc, regs->npc, regs->y, print_tainted());
  248. printk("g0: %08lx g1: %08lx g2: %08lx g3: %08lx ",
  249.        regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
  250.        regs->u_regs[3]);
  251. printk("g4: %08lx g5: %08lx g6: %08lx g7: %08lxn",
  252.        regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
  253.        regs->u_regs[7]);
  254. printk("o0: %08lx o1: %08lx o2: %08lx o3: %08lx ",
  255.        regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
  256.        regs->u_regs[11]);
  257. printk("o4: %08lx o5: %08lx sp: %08lx o7: %08lxn",
  258.        regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
  259.        regs->u_regs[15]);
  260. show_regwindow((struct reg_window *)regs->u_regs[14]);
  261. }
  262. void show_trace_task(struct task_struct *tsk)
  263. {
  264. unsigned long pc, fp;
  265. unsigned long task_base = (unsigned long) tsk;
  266. struct reg_window *rw;
  267. int count = 0;
  268. if (!tsk)
  269. return;
  270. fp = tsk->thread.ksp;
  271. do {
  272. /* Bogus frame pointer? */
  273. if (fp < (task_base + sizeof(struct task_struct)) ||
  274.     fp >= (task_base + (PAGE_SIZE << 1)))
  275. break;
  276. rw = (struct reg_window *) fp;
  277. pc = rw->ins[7];
  278. printk("[%08lx] ", pc);
  279. fp = rw->ins[6];
  280. } while (++count < 16);
  281. printk("n");
  282. }
  283. /*
  284.  * Free current thread data structures etc..
  285.  */
  286. void exit_thread(void)
  287. {
  288. #ifndef CONFIG_SMP
  289. if(last_task_used_math == current) {
  290. #else
  291. if(current->flags & PF_USEDFPU) {
  292. #endif
  293. /* Keep process from leaving FPU in a bogon state. */
  294. put_psr(get_psr() | PSR_EF);
  295. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  296.        &current->thread.fpqueue[0], &current->thread.fpqdepth);
  297. #ifndef CONFIG_SMP
  298. last_task_used_math = NULL;
  299. #else
  300. current->flags &= ~PF_USEDFPU;
  301. #endif
  302. }
  303. }
  304. void flush_thread(void)
  305. {
  306. current->thread.w_saved = 0;
  307. /* No new signal delivery by default */
  308. current->thread.new_signal = 0;
  309. #ifndef CONFIG_SMP
  310. if(last_task_used_math == current) {
  311. #else
  312. if(current->flags & PF_USEDFPU) {
  313. #endif
  314. /* Clean the fpu. */
  315. put_psr(get_psr() | PSR_EF);
  316. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  317.        &current->thread.fpqueue[0], &current->thread.fpqdepth);
  318. #ifndef CONFIG_SMP
  319. last_task_used_math = NULL;
  320. #else
  321. current->flags &= ~PF_USEDFPU;
  322. #endif
  323. }
  324. /* Now, this task is no longer a kernel thread. */
  325. current->thread.current_ds = USER_DS;
  326. if (current->thread.flags & SPARC_FLAG_KTHREAD) {
  327. current->thread.flags &= ~SPARC_FLAG_KTHREAD;
  328. /* We must fixup kregs as well. */
  329. current->thread.kregs = (struct pt_regs *)
  330. (((unsigned long)current) +
  331.  (TASK_UNION_SIZE - TRACEREG_SZ));
  332. }
  333. }
  334. static __inline__ void copy_regs(struct pt_regs *dst, struct pt_regs *src)
  335. {
  336. __asm__ __volatile__("lddt[%1 + 0x00], %%g2nt"
  337.      "lddt[%1 + 0x08], %%g4nt"
  338.      "lddt[%1 + 0x10], %%o4nt"
  339.      "stdt%%g2, [%0 + 0x00]nt"
  340.      "stdt%%g4, [%0 + 0x08]nt"
  341.      "stdt%%o4, [%0 + 0x10]nt"
  342.      "lddt[%1 + 0x18], %%g2nt"
  343.      "lddt[%1 + 0x20], %%g4nt"
  344.      "lddt[%1 + 0x28], %%o4nt"
  345.      "stdt%%g2, [%0 + 0x18]nt"
  346.      "stdt%%g4, [%0 + 0x20]nt"
  347.      "stdt%%o4, [%0 + 0x28]nt"
  348.      "lddt[%1 + 0x30], %%g2nt"
  349.      "lddt[%1 + 0x38], %%g4nt"
  350.      "lddt[%1 + 0x40], %%o4nt"
  351.      "stdt%%g2, [%0 + 0x30]nt"
  352.      "stdt%%g4, [%0 + 0x38]nt"
  353.      "lddt[%1 + 0x48], %%g2nt"
  354.      "stdt%%o4, [%0 + 0x40]nt"
  355.      "stdt%%g2, [%0 + 0x48]nt" : :
  356.      "r" (dst), "r" (src) :
  357.      "g2", "g3", "g4", "g5", "o4", "o5");
  358. }
  359. static __inline__ void copy_regwin(struct reg_window *dst, struct reg_window *src)
  360. {
  361. __asm__ __volatile__("lddt[%1 + 0x00], %%g2nt"
  362.      "lddt[%1 + 0x08], %%g4nt"
  363.      "lddt[%1 + 0x10], %%o4nt"
  364.      "stdt%%g2, [%0 + 0x00]nt"
  365.      "stdt%%g4, [%0 + 0x08]nt"
  366.      "stdt%%o4, [%0 + 0x10]nt"
  367.      "lddt[%1 + 0x18], %%g2nt"
  368.      "lddt[%1 + 0x20], %%g4nt"
  369.      "lddt[%1 + 0x28], %%o4nt"
  370.      "stdt%%g2, [%0 + 0x18]nt"
  371.      "stdt%%g4, [%0 + 0x20]nt"
  372.      "stdt%%o4, [%0 + 0x28]nt"
  373.      "lddt[%1 + 0x30], %%g2nt"
  374.      "lddt[%1 + 0x38], %%g4nt"
  375.      "stdt%%g2, [%0 + 0x30]nt"
  376.      "stdt%%g4, [%0 + 0x38]nt" : :
  377.      "r" (dst), "r" (src) :
  378.      "g2", "g3", "g4", "g5", "o4", "o5");
  379. }
  380. static __inline__ struct sparc_stackf *
  381. clone_stackframe(struct sparc_stackf *dst, struct sparc_stackf *src)
  382. {
  383. unsigned long size;
  384. struct sparc_stackf *sp;
  385. size = ((unsigned long)src->fp) - ((unsigned long)src);
  386. sp = (struct sparc_stackf *)(((unsigned long)dst) - size); 
  387. /* do_fork() grabs the parent semaphore, we must release it
  388.  * temporarily so we can build the child clone stack frame
  389.  * without deadlocking.
  390.  */
  391. if (copy_to_user(sp, src, size))
  392. sp = (struct sparc_stackf *) 0;
  393. else if (put_user(dst, &sp->fp))
  394. sp = (struct sparc_stackf *) 0;
  395. return sp;
  396. }
  397. /* Copy a Sparc thread.  The fork() return value conventions
  398.  * under SunOS are nothing short of bletcherous:
  399.  * Parent -->  %o0 == childs  pid, %o1 == 0
  400.  * Child  -->  %o0 == parents pid, %o1 == 1
  401.  *
  402.  * NOTE: We have a separate fork kpsr/kwim because
  403.  *       the parent could change these values between
  404.  *       sys_fork invocation and when we reach here
  405.  *       if the parent should sleep while trying to
  406.  *       allocate the task_struct and kernel stack in
  407.  *       do_fork().
  408.  */
  409. extern void ret_from_fork(void);
  410. int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
  411. unsigned long unused,
  412. struct task_struct *p, struct pt_regs *regs)
  413. {
  414. struct pt_regs *childregs;
  415. struct reg_window *new_stack;
  416. unsigned long stack_offset;
  417. #ifndef CONFIG_SMP
  418. if(last_task_used_math == current) {
  419. #else
  420. if(current->flags & PF_USEDFPU) {
  421. #endif
  422. put_psr(get_psr() | PSR_EF);
  423. fpsave(&p->thread.float_regs[0], &p->thread.fsr,
  424.        &p->thread.fpqueue[0], &p->thread.fpqdepth);
  425. #ifdef CONFIG_SMP
  426. current->flags &= ~PF_USEDFPU;
  427. #endif
  428. }
  429. /* Calculate offset to stack_frame & pt_regs */
  430. stack_offset = TASK_UNION_SIZE - TRACEREG_SZ;
  431. if(regs->psr & PSR_PS)
  432. stack_offset -= REGWIN_SZ;
  433. childregs = ((struct pt_regs *) (((unsigned long)p) + stack_offset));
  434. copy_regs(childregs, regs);
  435. new_stack = (((struct reg_window *) childregs) - 1);
  436. copy_regwin(new_stack, (((struct reg_window *) regs) - 1));
  437. p->thread.ksp = (unsigned long) new_stack;
  438. p->thread.kpc = (((unsigned long) ret_from_fork) - 0x8);
  439. p->thread.kpsr = current->thread.fork_kpsr;
  440. p->thread.kwim = current->thread.fork_kwim;
  441. /* This is used for sun4c only */
  442. atomic_set(&p->thread.refcount, 1);
  443. if(regs->psr & PSR_PS) {
  444. extern struct pt_regs fake_swapper_regs;
  445. p->thread.kregs = &fake_swapper_regs;
  446. new_stack = (struct reg_window *)
  447. ((((unsigned long)p) +
  448.   (TASK_UNION_SIZE)) -
  449.  (REGWIN_SZ));
  450. childregs->u_regs[UREG_FP] = (unsigned long) new_stack;
  451. p->thread.flags |= SPARC_FLAG_KTHREAD;
  452. p->thread.current_ds = KERNEL_DS;
  453. memcpy((void *)new_stack,
  454.        (void *)regs->u_regs[UREG_FP],
  455.        sizeof(struct reg_window));
  456. childregs->u_regs[UREG_G6] = (unsigned long) p;
  457. } else {
  458. p->thread.kregs = childregs;
  459. childregs->u_regs[UREG_FP] = sp;
  460. p->thread.flags &= ~SPARC_FLAG_KTHREAD;
  461. p->thread.current_ds = USER_DS;
  462. if (sp != regs->u_regs[UREG_FP]) {
  463. struct sparc_stackf *childstack;
  464. struct sparc_stackf *parentstack;
  465. /*
  466.  * This is a clone() call with supplied user stack.
  467.  * Set some valid stack frames to give to the child.
  468.  */
  469. childstack = (struct sparc_stackf *) (sp & ~0x7UL);
  470. parentstack = (struct sparc_stackf *) regs->u_regs[UREG_FP];
  471. #if 0
  472. printk("clone: parent stack:n");
  473. show_stackframe(parentstack);
  474. #endif
  475. childstack = clone_stackframe(childstack, parentstack);
  476. if (!childstack)
  477. return -EFAULT;
  478. #if 0
  479. printk("clone: child stack:n");
  480. show_stackframe(childstack);
  481. #endif
  482. childregs->u_regs[UREG_FP] = (unsigned long)childstack;
  483. }
  484. }
  485. /* Set the return value for the child. */
  486. childregs->u_regs[UREG_I0] = current->pid;
  487. childregs->u_regs[UREG_I1] = 1;
  488. /* Set the return value for the parent. */
  489. regs->u_regs[UREG_I1] = 0;
  490. return 0;
  491. }
  492. /*
  493.  * fill in the user structure for a core dump..
  494.  */
  495. void dump_thread(struct pt_regs * regs, struct user * dump)
  496. {
  497. unsigned long first_stack_page;
  498. dump->magic = SUNOS_CORE_MAGIC;
  499. dump->len = sizeof(struct user);
  500. dump->regs.psr = regs->psr;
  501. dump->regs.pc = regs->pc;
  502. dump->regs.npc = regs->npc;
  503. dump->regs.y = regs->y;
  504. /* fuck me plenty */
  505. memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
  506. dump->uexec = current->thread.core_exec;
  507. dump->u_tsize = (((unsigned long) current->mm->end_code) -
  508. ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
  509. dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
  510. dump->u_dsize -= dump->u_tsize;
  511. dump->u_dsize &= ~(PAGE_SIZE - 1);
  512. first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
  513. dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
  514. memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
  515. dump->fpu.fpstatus.fsr = current->thread.fsr;
  516. dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
  517. dump->fpu.fpstatus.fpq_count = current->thread.fpqdepth;
  518. memcpy(&dump->fpu.fpstatus.fpq[0], &current->thread.fpqueue[0],
  519.        ((sizeof(unsigned long) * 2) * 16));
  520. dump->sigcode = 0;
  521. }
  522. /*
  523.  * fill in the fpu structure for a core dump.
  524.  */
  525. int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
  526. {
  527. if (current->used_math == 0) {
  528. memset(fpregs, 0, sizeof(*fpregs));
  529. fpregs->pr_q_entrysize = 8;
  530. return 1;
  531. }
  532. #ifdef CONFIG_SMP
  533. if (current->flags & PF_USEDFPU) {
  534. put_psr(get_psr() | PSR_EF);
  535. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  536.        &current->thread.fpqueue[0], &current->thread.fpqdepth);
  537. regs->psr &= ~(PSR_EF);
  538. current->flags &= ~(PF_USEDFPU);
  539. }
  540. #else
  541. if (current == last_task_used_math) {
  542. put_psr(get_psr() | PSR_EF);
  543. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  544.        &current->thread.fpqueue[0], &current->thread.fpqdepth);
  545. last_task_used_math = 0;
  546. regs->psr &= ~(PSR_EF);
  547. }
  548. #endif
  549. memcpy(&fpregs->pr_fr.pr_regs[0],
  550.        &current->thread.float_regs[0],
  551.        (sizeof(unsigned long) * 32));
  552. fpregs->pr_fsr = current->thread.fsr;
  553. fpregs->pr_qcnt = current->thread.fpqdepth;
  554. fpregs->pr_q_entrysize = 8;
  555. fpregs->pr_en = 1;
  556. if(fpregs->pr_qcnt != 0) {
  557. memcpy(&fpregs->pr_q[0],
  558.        &current->thread.fpqueue[0],
  559.        sizeof(struct fpq) * fpregs->pr_qcnt);
  560. }
  561. /* Zero out the rest. */
  562. memset(&fpregs->pr_q[fpregs->pr_qcnt], 0,
  563.        sizeof(struct fpq) * (32 - fpregs->pr_qcnt));
  564. return 1;
  565. }
  566. /*
  567.  * sparc_execve() executes a new program after the asm stub has set
  568.  * things up for us.  This should basically do what I want it to.
  569.  */
  570. asmlinkage int sparc_execve(struct pt_regs *regs)
  571. {
  572. int error, base = 0;
  573. char *filename;
  574. /* Check for indirect call. */
  575. if(regs->u_regs[UREG_G1] == 0)
  576. base = 1;
  577. filename = getname((char *)regs->u_regs[base + UREG_I0]);
  578. error = PTR_ERR(filename);
  579. if(IS_ERR(filename))
  580. goto out;
  581. error = do_execve(filename, (char **) regs->u_regs[base + UREG_I1],
  582.   (char **) regs->u_regs[base + UREG_I2], regs);
  583. putname(filename);
  584. out:
  585. return error;
  586. }
  587. /*
  588.  * This is the mechanism for creating a new kernel thread.
  589.  *
  590.  * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  591.  * who haven't done an "execve()") should use this: it will work within
  592.  * a system call from a "real" process, but the process memory space will
  593.  * not be free'd until both the parent and the child have exited.
  594.  */
  595. pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  596. {
  597. long retval;
  598. __asm__ __volatile("mov %4, %%g2nt"    /* Set aside fn ptr... */
  599.    "mov %5, %%g3nt"    /* and arg. */
  600.    "mov %1, %%g1nt"
  601.    "mov %2, %%o0nt"    /* Clone flags. */
  602.    "mov 0, %%o1nt"     /* usp arg == 0 */
  603.    "t 0x10nt"          /* Linux/Sparc clone(). */
  604.    "cmp %%o1, 0nt"
  605.    "be 1fnt"           /* The parent, just return. */
  606.    " nopnt"            /* Delay slot. */
  607.    "jmpl %%g2, %%o7nt" /* Call the function. */
  608.    " mov %%g3, %%o0nt" /* Get back the arg in delay. */
  609.    "mov %3, %%g1nt"
  610.    "t 0x10nt"          /* Linux/Sparc exit(). */
  611.    /* Notreached by child. */
  612.    "1: mov %%o0, %0nt" :
  613.    "=r" (retval) :
  614.    "i" (__NR_clone), "r" (flags | CLONE_VM),
  615.    "i" (__NR_exit),  "r" (fn), "r" (arg) :
  616.    "g1", "g2", "g3", "o0", "o1", "memory", "cc");
  617. return retval;
  618. }