process.c 20 KB

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