process.c 20 KB

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