/arch/sparc/kernel/process.c

https://bitbucket.org/evzijst/gittest · C · 746 lines · 543 code · 94 blank · 109 comment · 70 complexity · fa61dd856e85a6f2ee1b3dc7762803d2 MD5 · raw file

  1. /* $Id: process.c,v 1.161 2002/01/23 11:27:32 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. #include <stdarg.h>
  11. #include <linux/errno.h>
  12. #include <linux/module.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/mm.h>
  17. #include <linux/stddef.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 <linux/init.h>
  29. #include <asm/auxio.h>
  30. #include <asm/oplib.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/system.h>
  33. #include <asm/page.h>
  34. #include <asm/pgalloc.h>
  35. #include <asm/pgtable.h>
  36. #include <asm/delay.h>
  37. #include <asm/processor.h>
  38. #include <asm/psr.h>
  39. #include <asm/elf.h>
  40. #include <asm/unistd.h>
  41. /*
  42. * Power management idle function
  43. * Set in pm platform drivers (apc.c and pmc.c)
  44. */
  45. void (*pm_idle)(void);
  46. /*
  47. * Power-off handler instantiation for pm.h compliance
  48. * This is done via auxio, but could be used as a fallback
  49. * handler when auxio is not present-- unused for now...
  50. */
  51. void (*pm_power_off)(void);
  52. /*
  53. * sysctl - toggle power-off restriction for serial console
  54. * systems in machine_power_off()
  55. */
  56. int scons_pwroff = 1;
  57. extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
  58. struct task_struct *last_task_used_math = NULL;
  59. struct thread_info *current_set[NR_CPUS];
  60. /*
  61. * default_idle is new in 2.5. XXX Review, currently stolen from sparc64.
  62. */
  63. void default_idle(void)
  64. {
  65. }
  66. #ifndef CONFIG_SMP
  67. #define SUN4C_FAULT_HIGH 100
  68. /*
  69. * the idle loop on a Sparc... ;)
  70. */
  71. void cpu_idle(void)
  72. {
  73. if (current->pid != 0)
  74. goto out;
  75. /* endless idle loop with no priority at all */
  76. for (;;) {
  77. if (ARCH_SUN4C_SUN4) {
  78. static int count = HZ;
  79. static unsigned long last_jiffies;
  80. static unsigned long last_faults;
  81. static unsigned long fps;
  82. unsigned long now;
  83. unsigned long faults;
  84. unsigned long flags;
  85. extern unsigned long sun4c_kernel_faults;
  86. extern void sun4c_grow_kernel_ring(void);
  87. local_irq_save(flags);
  88. now = jiffies;
  89. count -= (now - last_jiffies);
  90. last_jiffies = now;
  91. if (count < 0) {
  92. count += HZ;
  93. faults = sun4c_kernel_faults;
  94. fps = (fps + (faults - last_faults)) >> 1;
  95. last_faults = faults;
  96. #if 0
  97. printk("kernel faults / second = %ld\n", fps);
  98. #endif
  99. if (fps >= SUN4C_FAULT_HIGH) {
  100. sun4c_grow_kernel_ring();
  101. }
  102. }
  103. local_irq_restore(flags);
  104. }
  105. while((!need_resched()) && pm_idle) {
  106. (*pm_idle)();
  107. }
  108. schedule();
  109. check_pgt_cache();
  110. }
  111. out:
  112. return;
  113. }
  114. #else
  115. /* This is being executed in task 0 'user space'. */
  116. void cpu_idle(void)
  117. {
  118. /* endless idle loop with no priority at all */
  119. while(1) {
  120. if(need_resched()) {
  121. schedule();
  122. check_pgt_cache();
  123. }
  124. barrier(); /* or else gcc optimizes... */
  125. }
  126. }
  127. #endif
  128. extern char reboot_command [];
  129. extern void (*prom_palette)(int);
  130. /* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
  131. void machine_halt(void)
  132. {
  133. local_irq_enable();
  134. mdelay(8);
  135. local_irq_disable();
  136. if (!serial_console && prom_palette)
  137. prom_palette (1);
  138. prom_halt();
  139. panic("Halt failed!");
  140. }
  141. EXPORT_SYMBOL(machine_halt);
  142. void machine_restart(char * cmd)
  143. {
  144. char *p;
  145. local_irq_enable();
  146. mdelay(8);
  147. local_irq_disable();
  148. p = strchr (reboot_command, '\n');
  149. if (p) *p = 0;
  150. if (!serial_console && prom_palette)
  151. prom_palette (1);
  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. EXPORT_SYMBOL(machine_restart);
  160. void machine_power_off(void)
  161. {
  162. #ifdef CONFIG_SUN_AUXIO
  163. if (auxio_power_register && (!serial_console || scons_pwroff))
  164. *auxio_power_register |= AUXIO_POWER_OFF;
  165. #endif
  166. machine_halt();
  167. }
  168. EXPORT_SYMBOL(machine_power_off);
  169. static DEFINE_SPINLOCK(sparc_backtrace_lock);
  170. void __show_backtrace(unsigned long fp)
  171. {
  172. struct reg_window *rw;
  173. unsigned long flags;
  174. int cpu = smp_processor_id();
  175. spin_lock_irqsave(&sparc_backtrace_lock, flags);
  176. rw = (struct reg_window *)fp;
  177. while(rw && (((unsigned long) rw) >= PAGE_OFFSET) &&
  178. !(((unsigned long) rw) & 0x7)) {
  179. printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] "
  180. "FP[%08lx] CALLER[%08lx]: ", cpu,
  181. rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  182. rw->ins[4], rw->ins[5],
  183. rw->ins[6],
  184. rw->ins[7]);
  185. print_symbol("%s\n", rw->ins[7]);
  186. rw = (struct reg_window *) rw->ins[6];
  187. }
  188. spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
  189. }
  190. #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
  191. #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
  192. #define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))
  193. void show_backtrace(void)
  194. {
  195. unsigned long fp;
  196. __SAVE; __SAVE; __SAVE; __SAVE;
  197. __SAVE; __SAVE; __SAVE; __SAVE;
  198. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  199. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  200. __GET_FP(fp);
  201. __show_backtrace(fp);
  202. }
  203. #ifdef CONFIG_SMP
  204. void smp_show_backtrace_all_cpus(void)
  205. {
  206. xc0((smpfunc_t) show_backtrace);
  207. show_backtrace();
  208. }
  209. #endif
  210. #if 0
  211. void show_stackframe(struct sparc_stackf *sf)
  212. {
  213. unsigned long size;
  214. unsigned long *stk;
  215. int i;
  216. printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
  217. "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n",
  218. sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
  219. sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
  220. printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
  221. "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n",
  222. sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
  223. sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
  224. printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx "
  225. "x3: %08lx x4: %08lx x5: %08lx xx: %08lx\n",
  226. (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
  227. sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
  228. sf->xxargs[0]);
  229. size = ((unsigned long)sf->fp) - ((unsigned long)sf);
  230. size -= STACKFRAME_SZ;
  231. stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
  232. i = 0;
  233. do {
  234. printk("s%d: %08lx\n", i++, *stk++);
  235. } while ((size -= sizeof(unsigned long)));
  236. }
  237. #endif
  238. void show_regs(struct pt_regs *r)
  239. {
  240. struct reg_window *rw = (struct reg_window *) r->u_regs[14];
  241. printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
  242. r->psr, r->pc, r->npc, r->y, print_tainted());
  243. print_symbol("PC: <%s>\n", r->pc);
  244. printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  245. r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
  246. r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
  247. printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  248. r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
  249. r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
  250. print_symbol("RPC: <%s>\n", r->u_regs[15]);
  251. printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  252. rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
  253. rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
  254. printk("%%I: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  255. rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  256. rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
  257. }
  258. /*
  259. * The show_stack is an external API which we do not use ourselves.
  260. * The oops is printed in die_if_kernel.
  261. */
  262. void show_stack(struct task_struct *tsk, unsigned long *_ksp)
  263. {
  264. unsigned long pc, fp;
  265. unsigned long task_base;
  266. struct reg_window *rw;
  267. int count = 0;
  268. if (tsk != NULL)
  269. task_base = (unsigned long) tsk->thread_info;
  270. else
  271. task_base = (unsigned long) current_thread_info();
  272. fp = (unsigned long) _ksp;
  273. do {
  274. /* Bogus frame pointer? */
  275. if (fp < (task_base + sizeof(struct thread_info)) ||
  276. fp >= (task_base + (PAGE_SIZE << 1)))
  277. break;
  278. rw = (struct reg_window *) fp;
  279. pc = rw->ins[7];
  280. printk("[%08lx : ", pc);
  281. print_symbol("%s ] ", pc);
  282. fp = rw->ins[6];
  283. } while (++count < 16);
  284. printk("\n");
  285. }
  286. /*
  287. * Note: sparc64 has a pretty intricated thread_saved_pc, check it out.
  288. */
  289. unsigned long thread_saved_pc(struct task_struct *tsk)
  290. {
  291. return tsk->thread_info->kpc;
  292. }
  293. /*
  294. * Free current thread data structures etc..
  295. */
  296. void exit_thread(void)
  297. {
  298. #ifndef CONFIG_SMP
  299. if(last_task_used_math == current) {
  300. #else
  301. if(current_thread_info()->flags & _TIF_USEDFPU) {
  302. #endif
  303. /* Keep process from leaving FPU in a bogon state. */
  304. put_psr(get_psr() | PSR_EF);
  305. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  306. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  307. #ifndef CONFIG_SMP
  308. last_task_used_math = NULL;
  309. #else
  310. current_thread_info()->flags &= ~_TIF_USEDFPU;
  311. #endif
  312. }
  313. }
  314. void flush_thread(void)
  315. {
  316. current_thread_info()->w_saved = 0;
  317. /* No new signal delivery by default */
  318. current->thread.new_signal = 0;
  319. #ifndef CONFIG_SMP
  320. if(last_task_used_math == current) {
  321. #else
  322. if(current_thread_info()->flags & _TIF_USEDFPU) {
  323. #endif
  324. /* Clean the fpu. */
  325. put_psr(get_psr() | PSR_EF);
  326. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  327. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  328. #ifndef CONFIG_SMP
  329. last_task_used_math = NULL;
  330. #else
  331. current_thread_info()->flags &= ~_TIF_USEDFPU;
  332. #endif
  333. }
  334. /* Now, this task is no longer a kernel thread. */
  335. current->thread.current_ds = USER_DS;
  336. if (current->thread.flags & SPARC_FLAG_KTHREAD) {
  337. current->thread.flags &= ~SPARC_FLAG_KTHREAD;
  338. /* We must fixup kregs as well. */
  339. /* XXX This was not fixed for ti for a while, worked. Unused? */
  340. current->thread.kregs = (struct pt_regs *)
  341. ((char *)current->thread_info + (THREAD_SIZE - TRACEREG_SZ));
  342. }
  343. }
  344. static __inline__ struct sparc_stackf __user *
  345. clone_stackframe(struct sparc_stackf __user *dst,
  346. struct sparc_stackf __user *src)
  347. {
  348. unsigned long size, fp;
  349. struct sparc_stackf *tmp;
  350. struct sparc_stackf __user *sp;
  351. if (get_user(tmp, &src->fp))
  352. return NULL;
  353. fp = (unsigned long) tmp;
  354. size = (fp - ((unsigned long) src));
  355. fp = (unsigned long) dst;
  356. sp = (struct sparc_stackf __user *)(fp - size);
  357. /* do_fork() grabs the parent semaphore, we must release it
  358. * temporarily so we can build the child clone stack frame
  359. * without deadlocking.
  360. */
  361. if (__copy_user(sp, src, size))
  362. sp = NULL;
  363. else if (put_user(fp, &sp->fp))
  364. sp = NULL;
  365. return sp;
  366. }
  367. asmlinkage int sparc_do_fork(unsigned long clone_flags,
  368. unsigned long stack_start,
  369. struct pt_regs *regs,
  370. unsigned long stack_size)
  371. {
  372. unsigned long parent_tid_ptr, child_tid_ptr;
  373. parent_tid_ptr = regs->u_regs[UREG_I2];
  374. child_tid_ptr = regs->u_regs[UREG_I4];
  375. return do_fork(clone_flags, stack_start,
  376. regs, stack_size,
  377. (int __user *) parent_tid_ptr,
  378. (int __user *) child_tid_ptr);
  379. }
  380. /* Copy a Sparc thread. The fork() return value conventions
  381. * under SunOS are nothing short of bletcherous:
  382. * Parent --> %o0 == childs pid, %o1 == 0
  383. * Child --> %o0 == parents pid, %o1 == 1
  384. *
  385. * NOTE: We have a separate fork kpsr/kwim because
  386. * the parent could change these values between
  387. * sys_fork invocation and when we reach here
  388. * if the parent should sleep while trying to
  389. * allocate the task_struct and kernel stack in
  390. * do_fork().
  391. * XXX See comment above sys_vfork in sparc64. todo.
  392. */
  393. extern void ret_from_fork(void);
  394. int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
  395. unsigned long unused,
  396. struct task_struct *p, struct pt_regs *regs)
  397. {
  398. struct thread_info *ti = p->thread_info;
  399. struct pt_regs *childregs;
  400. char *new_stack;
  401. #ifndef CONFIG_SMP
  402. if(last_task_used_math == current) {
  403. #else
  404. if(current_thread_info()->flags & _TIF_USEDFPU) {
  405. #endif
  406. put_psr(get_psr() | PSR_EF);
  407. fpsave(&p->thread.float_regs[0], &p->thread.fsr,
  408. &p->thread.fpqueue[0], &p->thread.fpqdepth);
  409. #ifdef CONFIG_SMP
  410. current_thread_info()->flags &= ~_TIF_USEDFPU;
  411. #endif
  412. }
  413. /*
  414. * p->thread_info new_stack childregs
  415. * ! ! ! {if(PSR_PS) }
  416. * V V (stk.fr.) V (pt_regs) { (stk.fr.) }
  417. * +----- - - - - - ------+===========+============={+==========}+
  418. */
  419. new_stack = (char*)ti + THREAD_SIZE;
  420. if (regs->psr & PSR_PS)
  421. new_stack -= STACKFRAME_SZ;
  422. new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
  423. memcpy(new_stack, (char *)regs - STACKFRAME_SZ, STACKFRAME_SZ + TRACEREG_SZ);
  424. childregs = (struct pt_regs *) (new_stack + STACKFRAME_SZ);
  425. /*
  426. * A new process must start with interrupts closed in 2.5,
  427. * because this is how Mingo's scheduler works (see schedule_tail
  428. * and finish_arch_switch). If we do not do it, a timer interrupt hits
  429. * before we unlock, attempts to re-take the rq->lock, and then we die.
  430. * Thus, kpsr|=PSR_PIL.
  431. */
  432. ti->ksp = (unsigned long) new_stack;
  433. ti->kpc = (((unsigned long) ret_from_fork) - 0x8);
  434. ti->kpsr = current->thread.fork_kpsr | PSR_PIL;
  435. ti->kwim = current->thread.fork_kwim;
  436. if(regs->psr & PSR_PS) {
  437. extern struct pt_regs fake_swapper_regs;
  438. p->thread.kregs = &fake_swapper_regs;
  439. new_stack += STACKFRAME_SZ + TRACEREG_SZ;
  440. childregs->u_regs[UREG_FP] = (unsigned long) new_stack;
  441. p->thread.flags |= SPARC_FLAG_KTHREAD;
  442. p->thread.current_ds = KERNEL_DS;
  443. memcpy(new_stack, (void *)regs->u_regs[UREG_FP], STACKFRAME_SZ);
  444. childregs->u_regs[UREG_G6] = (unsigned long) ti;
  445. } else {
  446. p->thread.kregs = childregs;
  447. childregs->u_regs[UREG_FP] = sp;
  448. p->thread.flags &= ~SPARC_FLAG_KTHREAD;
  449. p->thread.current_ds = USER_DS;
  450. if (sp != regs->u_regs[UREG_FP]) {
  451. struct sparc_stackf __user *childstack;
  452. struct sparc_stackf __user *parentstack;
  453. /*
  454. * This is a clone() call with supplied user stack.
  455. * Set some valid stack frames to give to the child.
  456. */
  457. childstack = (struct sparc_stackf __user *)
  458. (sp & ~0x7UL);
  459. parentstack = (struct sparc_stackf __user *)
  460. regs->u_regs[UREG_FP];
  461. #if 0
  462. printk("clone: parent stack:\n");
  463. show_stackframe(parentstack);
  464. #endif
  465. childstack = clone_stackframe(childstack, parentstack);
  466. if (!childstack)
  467. return -EFAULT;
  468. #if 0
  469. printk("clone: child stack:\n");
  470. show_stackframe(childstack);
  471. #endif
  472. childregs->u_regs[UREG_FP] = (unsigned long)childstack;
  473. }
  474. }
  475. #ifdef CONFIG_SMP
  476. /* FPU must be disabled on SMP. */
  477. childregs->psr &= ~PSR_EF;
  478. #endif
  479. /* Set the return value for the child. */
  480. childregs->u_regs[UREG_I0] = current->pid;
  481. childregs->u_regs[UREG_I1] = 1;
  482. /* Set the return value for the parent. */
  483. regs->u_regs[UREG_I1] = 0;
  484. if (clone_flags & CLONE_SETTLS)
  485. childregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3];
  486. return 0;
  487. }
  488. /*
  489. * fill in the user structure for a core dump..
  490. */
  491. void dump_thread(struct pt_regs * regs, struct user * dump)
  492. {
  493. unsigned long first_stack_page;
  494. dump->magic = SUNOS_CORE_MAGIC;
  495. dump->len = sizeof(struct user);
  496. dump->regs.psr = regs->psr;
  497. dump->regs.pc = regs->pc;
  498. dump->regs.npc = regs->npc;
  499. dump->regs.y = regs->y;
  500. /* fuck me plenty */
  501. memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
  502. dump->uexec = current->thread.core_exec;
  503. dump->u_tsize = (((unsigned long) current->mm->end_code) -
  504. ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
  505. dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
  506. dump->u_dsize -= dump->u_tsize;
  507. dump->u_dsize &= ~(PAGE_SIZE - 1);
  508. first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
  509. dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
  510. memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
  511. dump->fpu.fpstatus.fsr = current->thread.fsr;
  512. dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
  513. dump->fpu.fpstatus.fpq_count = current->thread.fpqdepth;
  514. memcpy(&dump->fpu.fpstatus.fpq[0], &current->thread.fpqueue[0],
  515. ((sizeof(unsigned long) * 2) * 16));
  516. dump->sigcode = 0;
  517. }
  518. /*
  519. * fill in the fpu structure for a core dump.
  520. */
  521. int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
  522. {
  523. if (used_math()) {
  524. memset(fpregs, 0, sizeof(*fpregs));
  525. fpregs->pr_q_entrysize = 8;
  526. return 1;
  527. }
  528. #ifdef CONFIG_SMP
  529. if (current_thread_info()->flags & _TIF_USEDFPU) {
  530. put_psr(get_psr() | PSR_EF);
  531. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  532. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  533. if (regs != NULL) {
  534. regs->psr &= ~(PSR_EF);
  535. current_thread_info()->flags &= ~(_TIF_USEDFPU);
  536. }
  537. }
  538. #else
  539. if (current == last_task_used_math) {
  540. put_psr(get_psr() | PSR_EF);
  541. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  542. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  543. if (regs != NULL) {
  544. regs->psr &= ~(PSR_EF);
  545. last_task_used_math = NULL;
  546. }
  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 __user *)regs->u_regs[base + UREG_I0]);
  578. error = PTR_ERR(filename);
  579. if(IS_ERR(filename))
  580. goto out;
  581. error = do_execve(filename,
  582. (char __user * __user *)regs->u_regs[base + UREG_I1],
  583. (char __user * __user *)regs->u_regs[base + UREG_I2],
  584. regs);
  585. putname(filename);
  586. if (error == 0) {
  587. task_lock(current);
  588. current->ptrace &= ~PT_DTRACE;
  589. task_unlock(current);
  590. }
  591. out:
  592. return error;
  593. }
  594. /*
  595. * This is the mechanism for creating a new kernel thread.
  596. *
  597. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  598. * who haven't done an "execve()") should use this: it will work within
  599. * a system call from a "real" process, but the process memory space will
  600. * not be free'd until both the parent and the child have exited.
  601. */
  602. pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  603. {
  604. long retval;
  605. __asm__ __volatile__("mov %4, %%g2\n\t" /* Set aside fn ptr... */
  606. "mov %5, %%g3\n\t" /* and arg. */
  607. "mov %1, %%g1\n\t"
  608. "mov %2, %%o0\n\t" /* Clone flags. */
  609. "mov 0, %%o1\n\t" /* usp arg == 0 */
  610. "t 0x10\n\t" /* Linux/Sparc clone(). */
  611. "cmp %%o1, 0\n\t"
  612. "be 1f\n\t" /* The parent, just return. */
  613. " nop\n\t" /* Delay slot. */
  614. "jmpl %%g2, %%o7\n\t" /* Call the function. */
  615. " mov %%g3, %%o0\n\t" /* Get back the arg in delay. */
  616. "mov %3, %%g1\n\t"
  617. "t 0x10\n\t" /* Linux/Sparc exit(). */
  618. /* Notreached by child. */
  619. "1: mov %%o0, %0\n\t" :
  620. "=r" (retval) :
  621. "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
  622. "i" (__NR_exit), "r" (fn), "r" (arg) :
  623. "g1", "g2", "g3", "o0", "o1", "memory", "cc");
  624. return retval;
  625. }
  626. unsigned long get_wchan(struct task_struct *task)
  627. {
  628. unsigned long pc, fp, bias = 0;
  629. unsigned long task_base = (unsigned long) task;
  630. unsigned long ret = 0;
  631. struct reg_window *rw;
  632. int count = 0;
  633. if (!task || task == current ||
  634. task->state == TASK_RUNNING)
  635. goto out;
  636. fp = task->thread_info->ksp + bias;
  637. do {
  638. /* Bogus frame pointer? */
  639. if (fp < (task_base + sizeof(struct thread_info)) ||
  640. fp >= (task_base + (2 * PAGE_SIZE)))
  641. break;
  642. rw = (struct reg_window *) fp;
  643. pc = rw->ins[7];
  644. if (!in_sched_functions(pc)) {
  645. ret = pc;
  646. goto out;
  647. }
  648. fp = rw->ins[6] + bias;
  649. } while (++count < 16);
  650. out:
  651. return ret;
  652. }