process_32.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /* linux/arch/sparc/kernel/process.c
  2. *
  3. * Copyright (C) 1995, 2008 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/mm.h>
  15. #include <linux/stddef.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/slab.h>
  18. #include <linux/user.h>
  19. #include <linux/smp.h>
  20. #include <linux/reboot.h>
  21. #include <linux/delay.h>
  22. #include <linux/pm.h>
  23. #include <linux/init.h>
  24. #include <asm/auxio.h>
  25. #include <asm/oplib.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/system.h>
  28. #include <asm/page.h>
  29. #include <asm/pgalloc.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/delay.h>
  32. #include <asm/processor.h>
  33. #include <asm/psr.h>
  34. #include <asm/elf.h>
  35. #include <asm/prom.h>
  36. #include <asm/unistd.h>
  37. /*
  38. * Power management idle function
  39. * Set in pm platform drivers (apc.c and pmc.c)
  40. */
  41. void (*pm_idle)(void);
  42. /*
  43. * Power-off handler instantiation for pm.h compliance
  44. * This is done via auxio, but could be used as a fallback
  45. * handler when auxio is not present-- unused for now...
  46. */
  47. void (*pm_power_off)(void) = machine_power_off;
  48. EXPORT_SYMBOL(pm_power_off);
  49. /*
  50. * sysctl - toggle power-off restriction for serial console
  51. * systems in machine_power_off()
  52. */
  53. int scons_pwroff = 1;
  54. extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
  55. struct task_struct *last_task_used_math = NULL;
  56. struct thread_info *current_set[NR_CPUS];
  57. #ifndef CONFIG_SMP
  58. #define SUN4C_FAULT_HIGH 100
  59. /*
  60. * the idle loop on a Sparc... ;)
  61. */
  62. void cpu_idle(void)
  63. {
  64. /* endless idle loop with no priority at all */
  65. for (;;) {
  66. if (ARCH_SUN4C) {
  67. static int count = HZ;
  68. static unsigned long last_jiffies;
  69. static unsigned long last_faults;
  70. static unsigned long fps;
  71. unsigned long now;
  72. unsigned long faults;
  73. extern unsigned long sun4c_kernel_faults;
  74. extern void sun4c_grow_kernel_ring(void);
  75. local_irq_disable();
  76. now = jiffies;
  77. count -= (now - last_jiffies);
  78. last_jiffies = now;
  79. if (count < 0) {
  80. count += HZ;
  81. faults = sun4c_kernel_faults;
  82. fps = (fps + (faults - last_faults)) >> 1;
  83. last_faults = faults;
  84. #if 0
  85. printk("kernel faults / second = %ld\n", fps);
  86. #endif
  87. if (fps >= SUN4C_FAULT_HIGH) {
  88. sun4c_grow_kernel_ring();
  89. }
  90. }
  91. local_irq_enable();
  92. }
  93. if (pm_idle) {
  94. while (!need_resched())
  95. (*pm_idle)();
  96. } else {
  97. while (!need_resched())
  98. cpu_relax();
  99. }
  100. preempt_enable_no_resched();
  101. schedule();
  102. preempt_disable();
  103. check_pgt_cache();
  104. }
  105. }
  106. #else
  107. /* This is being executed in task 0 'user space'. */
  108. void cpu_idle(void)
  109. {
  110. set_thread_flag(TIF_POLLING_NRFLAG);
  111. /* endless idle loop with no priority at all */
  112. while(1) {
  113. while (!need_resched())
  114. cpu_relax();
  115. preempt_enable_no_resched();
  116. schedule();
  117. preempt_disable();
  118. check_pgt_cache();
  119. }
  120. }
  121. #endif
  122. /* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
  123. void machine_halt(void)
  124. {
  125. local_irq_enable();
  126. mdelay(8);
  127. local_irq_disable();
  128. prom_halt();
  129. panic("Halt failed!");
  130. }
  131. void machine_restart(char * cmd)
  132. {
  133. char *p;
  134. local_irq_enable();
  135. mdelay(8);
  136. local_irq_disable();
  137. p = strchr (reboot_command, '\n');
  138. if (p) *p = 0;
  139. if (cmd)
  140. prom_reboot(cmd);
  141. if (*reboot_command)
  142. prom_reboot(reboot_command);
  143. prom_feval ("reset");
  144. panic("Reboot failed!");
  145. }
  146. void machine_power_off(void)
  147. {
  148. if (auxio_power_register &&
  149. (strcmp(of_console_device->type, "serial") || scons_pwroff))
  150. *auxio_power_register |= AUXIO_POWER_OFF;
  151. machine_halt();
  152. }
  153. #if 0
  154. static DEFINE_SPINLOCK(sparc_backtrace_lock);
  155. void __show_backtrace(unsigned long fp)
  156. {
  157. struct reg_window32 *rw;
  158. unsigned long flags;
  159. int cpu = smp_processor_id();
  160. spin_lock_irqsave(&sparc_backtrace_lock, flags);
  161. rw = (struct reg_window32 *)fp;
  162. while(rw && (((unsigned long) rw) >= PAGE_OFFSET) &&
  163. !(((unsigned long) rw) & 0x7)) {
  164. printk("CPU[%d]: ARGS[%08lx,%08lx,%08lx,%08lx,%08lx,%08lx] "
  165. "FP[%08lx] CALLER[%08lx]: ", cpu,
  166. rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  167. rw->ins[4], rw->ins[5],
  168. rw->ins[6],
  169. rw->ins[7]);
  170. printk("%pS\n", (void *) rw->ins[7]);
  171. rw = (struct reg_window32 *) rw->ins[6];
  172. }
  173. spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
  174. }
  175. #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
  176. #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
  177. #define __GET_FP(fp) __asm__ __volatile__("mov %%i6, %0" : "=r" (fp))
  178. void show_backtrace(void)
  179. {
  180. unsigned long fp;
  181. __SAVE; __SAVE; __SAVE; __SAVE;
  182. __SAVE; __SAVE; __SAVE; __SAVE;
  183. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  184. __RESTORE; __RESTORE; __RESTORE; __RESTORE;
  185. __GET_FP(fp);
  186. __show_backtrace(fp);
  187. }
  188. #ifdef CONFIG_SMP
  189. void smp_show_backtrace_all_cpus(void)
  190. {
  191. xc0((smpfunc_t) show_backtrace);
  192. show_backtrace();
  193. }
  194. #endif
  195. void show_stackframe(struct sparc_stackf *sf)
  196. {
  197. unsigned long size;
  198. unsigned long *stk;
  199. int i;
  200. printk("l0: %08lx l1: %08lx l2: %08lx l3: %08lx "
  201. "l4: %08lx l5: %08lx l6: %08lx l7: %08lx\n",
  202. sf->locals[0], sf->locals[1], sf->locals[2], sf->locals[3],
  203. sf->locals[4], sf->locals[5], sf->locals[6], sf->locals[7]);
  204. printk("i0: %08lx i1: %08lx i2: %08lx i3: %08lx "
  205. "i4: %08lx i5: %08lx fp: %08lx i7: %08lx\n",
  206. sf->ins[0], sf->ins[1], sf->ins[2], sf->ins[3],
  207. sf->ins[4], sf->ins[5], (unsigned long)sf->fp, sf->callers_pc);
  208. printk("sp: %08lx x0: %08lx x1: %08lx x2: %08lx "
  209. "x3: %08lx x4: %08lx x5: %08lx xx: %08lx\n",
  210. (unsigned long)sf->structptr, sf->xargs[0], sf->xargs[1],
  211. sf->xargs[2], sf->xargs[3], sf->xargs[4], sf->xargs[5],
  212. sf->xxargs[0]);
  213. size = ((unsigned long)sf->fp) - ((unsigned long)sf);
  214. size -= STACKFRAME_SZ;
  215. stk = (unsigned long *)((unsigned long)sf + STACKFRAME_SZ);
  216. i = 0;
  217. do {
  218. printk("s%d: %08lx\n", i++, *stk++);
  219. } while ((size -= sizeof(unsigned long)));
  220. }
  221. #endif
  222. void show_regs(struct pt_regs *r)
  223. {
  224. struct reg_window32 *rw = (struct reg_window32 *) r->u_regs[14];
  225. printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
  226. r->psr, r->pc, r->npc, r->y, print_tainted());
  227. printk("PC: <%pS>\n", (void *) r->pc);
  228. printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  229. r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
  230. r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
  231. printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  232. r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
  233. r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
  234. printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
  235. printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  236. rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
  237. rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
  238. printk("%%I: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
  239. rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
  240. rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
  241. }
  242. /*
  243. * The show_stack is an external API which we do not use ourselves.
  244. * The oops is printed in die_if_kernel.
  245. */
  246. void show_stack(struct task_struct *tsk, unsigned long *_ksp)
  247. {
  248. unsigned long pc, fp;
  249. unsigned long task_base;
  250. struct reg_window32 *rw;
  251. int count = 0;
  252. if (tsk != NULL)
  253. task_base = (unsigned long) task_stack_page(tsk);
  254. else
  255. task_base = (unsigned long) current_thread_info();
  256. fp = (unsigned long) _ksp;
  257. do {
  258. /* Bogus frame pointer? */
  259. if (fp < (task_base + sizeof(struct thread_info)) ||
  260. fp >= (task_base + (PAGE_SIZE << 1)))
  261. break;
  262. rw = (struct reg_window32 *) fp;
  263. pc = rw->ins[7];
  264. printk("[%08lx : ", pc);
  265. printk("%pS ] ", (void *) pc);
  266. fp = rw->ins[6];
  267. } while (++count < 16);
  268. printk("\n");
  269. }
  270. void dump_stack(void)
  271. {
  272. unsigned long *ksp;
  273. __asm__ __volatile__("mov %%fp, %0"
  274. : "=r" (ksp));
  275. show_stack(current, ksp);
  276. }
  277. EXPORT_SYMBOL(dump_stack);
  278. /*
  279. * Note: sparc64 has a pretty intricated thread_saved_pc, check it out.
  280. */
  281. unsigned long thread_saved_pc(struct task_struct *tsk)
  282. {
  283. return task_thread_info(tsk)->kpc;
  284. }
  285. /*
  286. * Free current thread data structures etc..
  287. */
  288. void exit_thread(void)
  289. {
  290. #ifndef CONFIG_SMP
  291. if(last_task_used_math == current) {
  292. #else
  293. if (test_thread_flag(TIF_USEDFPU)) {
  294. #endif
  295. /* Keep process from leaving FPU in a bogon state. */
  296. put_psr(get_psr() | PSR_EF);
  297. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  298. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  299. #ifndef CONFIG_SMP
  300. last_task_used_math = NULL;
  301. #else
  302. clear_thread_flag(TIF_USEDFPU);
  303. #endif
  304. }
  305. }
  306. void flush_thread(void)
  307. {
  308. current_thread_info()->w_saved = 0;
  309. #ifndef CONFIG_SMP
  310. if(last_task_used_math == current) {
  311. #else
  312. if (test_thread_flag(TIF_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. clear_thread_flag(TIF_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. /* XXX This was not fixed for ti for a while, worked. Unused? */
  330. current->thread.kregs = (struct pt_regs *)
  331. (task_stack_page(current) + (THREAD_SIZE - TRACEREG_SZ));
  332. }
  333. }
  334. static inline struct sparc_stackf __user *
  335. clone_stackframe(struct sparc_stackf __user *dst,
  336. struct sparc_stackf __user *src)
  337. {
  338. unsigned long size, fp;
  339. struct sparc_stackf *tmp;
  340. struct sparc_stackf __user *sp;
  341. if (get_user(tmp, &src->fp))
  342. return NULL;
  343. fp = (unsigned long) tmp;
  344. size = (fp - ((unsigned long) src));
  345. fp = (unsigned long) dst;
  346. sp = (struct sparc_stackf __user *)(fp - size);
  347. /* do_fork() grabs the parent semaphore, we must release it
  348. * temporarily so we can build the child clone stack frame
  349. * without deadlocking.
  350. */
  351. if (__copy_user(sp, src, size))
  352. sp = NULL;
  353. else if (put_user(fp, &sp->fp))
  354. sp = NULL;
  355. return sp;
  356. }
  357. asmlinkage int sparc_do_fork(unsigned long clone_flags,
  358. unsigned long stack_start,
  359. struct pt_regs *regs,
  360. unsigned long stack_size)
  361. {
  362. unsigned long parent_tid_ptr, child_tid_ptr;
  363. unsigned long orig_i1 = regs->u_regs[UREG_I1];
  364. long ret;
  365. parent_tid_ptr = regs->u_regs[UREG_I2];
  366. child_tid_ptr = regs->u_regs[UREG_I4];
  367. ret = do_fork(clone_flags, stack_start,
  368. regs, stack_size,
  369. (int __user *) parent_tid_ptr,
  370. (int __user *) child_tid_ptr);
  371. /* If we get an error and potentially restart the system
  372. * call, we're screwed because copy_thread() clobbered
  373. * the parent's %o1. So detect that case and restore it
  374. * here.
  375. */
  376. if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
  377. regs->u_regs[UREG_I1] = orig_i1;
  378. return ret;
  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 = task_thread_info(p);
  399. struct pt_regs *childregs;
  400. char *new_stack;
  401. #ifndef CONFIG_SMP
  402. if(last_task_used_math == current) {
  403. #else
  404. if (test_thread_flag(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. clear_thread_flag(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 = task_stack_page(p) + 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 fpu structure for a core dump.
  490. */
  491. int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
  492. {
  493. if (used_math()) {
  494. memset(fpregs, 0, sizeof(*fpregs));
  495. fpregs->pr_q_entrysize = 8;
  496. return 1;
  497. }
  498. #ifdef CONFIG_SMP
  499. if (test_thread_flag(TIF_USEDFPU)) {
  500. put_psr(get_psr() | PSR_EF);
  501. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  502. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  503. if (regs != NULL) {
  504. regs->psr &= ~(PSR_EF);
  505. clear_thread_flag(TIF_USEDFPU);
  506. }
  507. }
  508. #else
  509. if (current == last_task_used_math) {
  510. put_psr(get_psr() | PSR_EF);
  511. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  512. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  513. if (regs != NULL) {
  514. regs->psr &= ~(PSR_EF);
  515. last_task_used_math = NULL;
  516. }
  517. }
  518. #endif
  519. memcpy(&fpregs->pr_fr.pr_regs[0],
  520. &current->thread.float_regs[0],
  521. (sizeof(unsigned long) * 32));
  522. fpregs->pr_fsr = current->thread.fsr;
  523. fpregs->pr_qcnt = current->thread.fpqdepth;
  524. fpregs->pr_q_entrysize = 8;
  525. fpregs->pr_en = 1;
  526. if(fpregs->pr_qcnt != 0) {
  527. memcpy(&fpregs->pr_q[0],
  528. &current->thread.fpqueue[0],
  529. sizeof(struct fpq) * fpregs->pr_qcnt);
  530. }
  531. /* Zero out the rest. */
  532. memset(&fpregs->pr_q[fpregs->pr_qcnt], 0,
  533. sizeof(struct fpq) * (32 - fpregs->pr_qcnt));
  534. return 1;
  535. }
  536. /*
  537. * sparc_execve() executes a new program after the asm stub has set
  538. * things up for us. This should basically do what I want it to.
  539. */
  540. asmlinkage int sparc_execve(struct pt_regs *regs)
  541. {
  542. int error, base = 0;
  543. char *filename;
  544. /* Check for indirect call. */
  545. if(regs->u_regs[UREG_G1] == 0)
  546. base = 1;
  547. filename = getname((char __user *)regs->u_regs[base + UREG_I0]);
  548. error = PTR_ERR(filename);
  549. if(IS_ERR(filename))
  550. goto out;
  551. error = do_execve(filename,
  552. (char __user * __user *)regs->u_regs[base + UREG_I1],
  553. (char __user * __user *)regs->u_regs[base + UREG_I2],
  554. regs);
  555. putname(filename);
  556. out:
  557. return error;
  558. }
  559. /*
  560. * This is the mechanism for creating a new kernel thread.
  561. *
  562. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  563. * who haven't done an "execve()") should use this: it will work within
  564. * a system call from a "real" process, but the process memory space will
  565. * not be freed until both the parent and the child have exited.
  566. */
  567. pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  568. {
  569. long retval;
  570. __asm__ __volatile__("mov %4, %%g2\n\t" /* Set aside fn ptr... */
  571. "mov %5, %%g3\n\t" /* and arg. */
  572. "mov %1, %%g1\n\t"
  573. "mov %2, %%o0\n\t" /* Clone flags. */
  574. "mov 0, %%o1\n\t" /* usp arg == 0 */
  575. "t 0x10\n\t" /* Linux/Sparc clone(). */
  576. "cmp %%o1, 0\n\t"
  577. "be 1f\n\t" /* The parent, just return. */
  578. " nop\n\t" /* Delay slot. */
  579. "jmpl %%g2, %%o7\n\t" /* Call the function. */
  580. " mov %%g3, %%o0\n\t" /* Get back the arg in delay. */
  581. "mov %3, %%g1\n\t"
  582. "t 0x10\n\t" /* Linux/Sparc exit(). */
  583. /* Notreached by child. */
  584. "1: mov %%o0, %0\n\t" :
  585. "=r" (retval) :
  586. "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
  587. "i" (__NR_exit), "r" (fn), "r" (arg) :
  588. "g1", "g2", "g3", "o0", "o1", "memory", "cc");
  589. return retval;
  590. }
  591. unsigned long get_wchan(struct task_struct *task)
  592. {
  593. unsigned long pc, fp, bias = 0;
  594. unsigned long task_base = (unsigned long) task;
  595. unsigned long ret = 0;
  596. struct reg_window32 *rw;
  597. int count = 0;
  598. if (!task || task == current ||
  599. task->state == TASK_RUNNING)
  600. goto out;
  601. fp = task_thread_info(task)->ksp + bias;
  602. do {
  603. /* Bogus frame pointer? */
  604. if (fp < (task_base + sizeof(struct thread_info)) ||
  605. fp >= (task_base + (2 * PAGE_SIZE)))
  606. break;
  607. rw = (struct reg_window32 *) fp;
  608. pc = rw->ins[7];
  609. if (!in_sched_functions(pc)) {
  610. ret = pc;
  611. goto out;
  612. }
  613. fp = rw->ins[6] + bias;
  614. } while (++count < 16);
  615. out:
  616. return ret;
  617. }