process_32.c 18 KB

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