process.c 18 KB

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