process_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /* arch/sparc64/kernel/process.c
  2. *
  3. * Copyright (C) 1995, 1996, 2008 David S. Miller (davem@davemloft.net)
  4. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  5. * Copyright (C) 1997, 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  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/export.h>
  13. #include <linux/sched.h>
  14. #include <linux/sched/debug.h>
  15. #include <linux/sched/task.h>
  16. #include <linux/sched/task_stack.h>
  17. #include <linux/kernel.h>
  18. #include <linux/mm.h>
  19. #include <linux/fs.h>
  20. #include <linux/smp.h>
  21. #include <linux/stddef.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/slab.h>
  24. #include <linux/user.h>
  25. #include <linux/delay.h>
  26. #include <linux/compat.h>
  27. #include <linux/tick.h>
  28. #include <linux/init.h>
  29. #include <linux/cpu.h>
  30. #include <linux/perf_event.h>
  31. #include <linux/elfcore.h>
  32. #include <linux/sysrq.h>
  33. #include <linux/nmi.h>
  34. #include <linux/context_tracking.h>
  35. #include <linux/uaccess.h>
  36. #include <asm/page.h>
  37. #include <asm/pgalloc.h>
  38. #include <asm/pgtable.h>
  39. #include <asm/processor.h>
  40. #include <asm/pstate.h>
  41. #include <asm/elf.h>
  42. #include <asm/fpumacro.h>
  43. #include <asm/head.h>
  44. #include <asm/cpudata.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/unistd.h>
  47. #include <asm/hypervisor.h>
  48. #include <asm/syscalls.h>
  49. #include <asm/irq_regs.h>
  50. #include <asm/smp.h>
  51. #include <asm/pcr.h>
  52. #include "kstack.h"
  53. /* Idle loop support on sparc64. */
  54. void arch_cpu_idle(void)
  55. {
  56. if (tlb_type != hypervisor) {
  57. touch_nmi_watchdog();
  58. local_irq_enable();
  59. } else {
  60. unsigned long pstate;
  61. local_irq_enable();
  62. /* The sun4v sleeping code requires that we have PSTATE.IE cleared over
  63. * the cpu sleep hypervisor call.
  64. */
  65. __asm__ __volatile__(
  66. "rdpr %%pstate, %0\n\t"
  67. "andn %0, %1, %0\n\t"
  68. "wrpr %0, %%g0, %%pstate"
  69. : "=&r" (pstate)
  70. : "i" (PSTATE_IE));
  71. if (!need_resched() && !cpu_is_offline(smp_processor_id()))
  72. sun4v_cpu_yield();
  73. /* Re-enable interrupts. */
  74. __asm__ __volatile__(
  75. "rdpr %%pstate, %0\n\t"
  76. "or %0, %1, %0\n\t"
  77. "wrpr %0, %%g0, %%pstate"
  78. : "=&r" (pstate)
  79. : "i" (PSTATE_IE));
  80. }
  81. }
  82. #ifdef CONFIG_HOTPLUG_CPU
  83. void arch_cpu_idle_dead(void)
  84. {
  85. sched_preempt_enable_no_resched();
  86. cpu_play_dead();
  87. }
  88. #endif
  89. #ifdef CONFIG_COMPAT
  90. static void show_regwindow32(struct pt_regs *regs)
  91. {
  92. struct reg_window32 __user *rw;
  93. struct reg_window32 r_w;
  94. mm_segment_t old_fs;
  95. __asm__ __volatile__ ("flushw");
  96. rw = compat_ptr((unsigned int)regs->u_regs[14]);
  97. old_fs = get_fs();
  98. set_fs (USER_DS);
  99. if (copy_from_user (&r_w, rw, sizeof(r_w))) {
  100. set_fs (old_fs);
  101. return;
  102. }
  103. set_fs (old_fs);
  104. printk("l0: %08x l1: %08x l2: %08x l3: %08x "
  105. "l4: %08x l5: %08x l6: %08x l7: %08x\n",
  106. r_w.locals[0], r_w.locals[1], r_w.locals[2], r_w.locals[3],
  107. r_w.locals[4], r_w.locals[5], r_w.locals[6], r_w.locals[7]);
  108. printk("i0: %08x i1: %08x i2: %08x i3: %08x "
  109. "i4: %08x i5: %08x i6: %08x i7: %08x\n",
  110. r_w.ins[0], r_w.ins[1], r_w.ins[2], r_w.ins[3],
  111. r_w.ins[4], r_w.ins[5], r_w.ins[6], r_w.ins[7]);
  112. }
  113. #else
  114. #define show_regwindow32(regs) do { } while (0)
  115. #endif
  116. static void show_regwindow(struct pt_regs *regs)
  117. {
  118. struct reg_window __user *rw;
  119. struct reg_window *rwk;
  120. struct reg_window r_w;
  121. mm_segment_t old_fs;
  122. if ((regs->tstate & TSTATE_PRIV) || !(test_thread_flag(TIF_32BIT))) {
  123. __asm__ __volatile__ ("flushw");
  124. rw = (struct reg_window __user *)
  125. (regs->u_regs[14] + STACK_BIAS);
  126. rwk = (struct reg_window *)
  127. (regs->u_regs[14] + STACK_BIAS);
  128. if (!(regs->tstate & TSTATE_PRIV)) {
  129. old_fs = get_fs();
  130. set_fs (USER_DS);
  131. if (copy_from_user (&r_w, rw, sizeof(r_w))) {
  132. set_fs (old_fs);
  133. return;
  134. }
  135. rwk = &r_w;
  136. set_fs (old_fs);
  137. }
  138. } else {
  139. show_regwindow32(regs);
  140. return;
  141. }
  142. printk("l0: %016lx l1: %016lx l2: %016lx l3: %016lx\n",
  143. rwk->locals[0], rwk->locals[1], rwk->locals[2], rwk->locals[3]);
  144. printk("l4: %016lx l5: %016lx l6: %016lx l7: %016lx\n",
  145. rwk->locals[4], rwk->locals[5], rwk->locals[6], rwk->locals[7]);
  146. printk("i0: %016lx i1: %016lx i2: %016lx i3: %016lx\n",
  147. rwk->ins[0], rwk->ins[1], rwk->ins[2], rwk->ins[3]);
  148. printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
  149. rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
  150. if (regs->tstate & TSTATE_PRIV)
  151. printk("I7: <%pS>\n", (void *) rwk->ins[7]);
  152. }
  153. void show_regs(struct pt_regs *regs)
  154. {
  155. show_regs_print_info(KERN_DEFAULT);
  156. printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
  157. regs->tpc, regs->tnpc, regs->y, print_tainted());
  158. printk("TPC: <%pS>\n", (void *) regs->tpc);
  159. printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
  160. regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
  161. regs->u_regs[3]);
  162. printk("g4: %016lx g5: %016lx g6: %016lx g7: %016lx\n",
  163. regs->u_regs[4], regs->u_regs[5], regs->u_regs[6],
  164. regs->u_regs[7]);
  165. printk("o0: %016lx o1: %016lx o2: %016lx o3: %016lx\n",
  166. regs->u_regs[8], regs->u_regs[9], regs->u_regs[10],
  167. regs->u_regs[11]);
  168. printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
  169. regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
  170. regs->u_regs[15]);
  171. printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
  172. show_regwindow(regs);
  173. show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
  174. }
  175. union global_cpu_snapshot global_cpu_snapshot[NR_CPUS];
  176. static DEFINE_SPINLOCK(global_cpu_snapshot_lock);
  177. static void __global_reg_self(struct thread_info *tp, struct pt_regs *regs,
  178. int this_cpu)
  179. {
  180. struct global_reg_snapshot *rp;
  181. flushw_all();
  182. rp = &global_cpu_snapshot[this_cpu].reg;
  183. rp->tstate = regs->tstate;
  184. rp->tpc = regs->tpc;
  185. rp->tnpc = regs->tnpc;
  186. rp->o7 = regs->u_regs[UREG_I7];
  187. if (regs->tstate & TSTATE_PRIV) {
  188. struct reg_window *rw;
  189. rw = (struct reg_window *)
  190. (regs->u_regs[UREG_FP] + STACK_BIAS);
  191. if (kstack_valid(tp, (unsigned long) rw)) {
  192. rp->i7 = rw->ins[7];
  193. rw = (struct reg_window *)
  194. (rw->ins[6] + STACK_BIAS);
  195. if (kstack_valid(tp, (unsigned long) rw))
  196. rp->rpc = rw->ins[7];
  197. }
  198. } else {
  199. rp->i7 = 0;
  200. rp->rpc = 0;
  201. }
  202. rp->thread = tp;
  203. }
  204. /* In order to avoid hangs we do not try to synchronize with the
  205. * global register dump client cpus. The last store they make is to
  206. * the thread pointer, so do a short poll waiting for that to become
  207. * non-NULL.
  208. */
  209. static void __global_reg_poll(struct global_reg_snapshot *gp)
  210. {
  211. int limit = 0;
  212. while (!gp->thread && ++limit < 100) {
  213. barrier();
  214. udelay(1);
  215. }
  216. }
  217. void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
  218. {
  219. struct thread_info *tp = current_thread_info();
  220. struct pt_regs *regs = get_irq_regs();
  221. unsigned long flags;
  222. int this_cpu, cpu;
  223. if (!regs)
  224. regs = tp->kregs;
  225. spin_lock_irqsave(&global_cpu_snapshot_lock, flags);
  226. this_cpu = raw_smp_processor_id();
  227. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  228. if (cpumask_test_cpu(this_cpu, mask) && !exclude_self)
  229. __global_reg_self(tp, regs, this_cpu);
  230. smp_fetch_global_regs();
  231. for_each_cpu(cpu, mask) {
  232. struct global_reg_snapshot *gp;
  233. if (exclude_self && cpu == this_cpu)
  234. continue;
  235. gp = &global_cpu_snapshot[cpu].reg;
  236. __global_reg_poll(gp);
  237. tp = gp->thread;
  238. printk("%c CPU[%3d]: TSTATE[%016lx] TPC[%016lx] TNPC[%016lx] TASK[%s:%d]\n",
  239. (cpu == this_cpu ? '*' : ' '), cpu,
  240. gp->tstate, gp->tpc, gp->tnpc,
  241. ((tp && tp->task) ? tp->task->comm : "NULL"),
  242. ((tp && tp->task) ? tp->task->pid : -1));
  243. if (gp->tstate & TSTATE_PRIV) {
  244. printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
  245. (void *) gp->tpc,
  246. (void *) gp->o7,
  247. (void *) gp->i7,
  248. (void *) gp->rpc);
  249. } else {
  250. printk(" TPC[%lx] O7[%lx] I7[%lx] RPC[%lx]\n",
  251. gp->tpc, gp->o7, gp->i7, gp->rpc);
  252. }
  253. touch_nmi_watchdog();
  254. }
  255. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  256. spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
  257. }
  258. #ifdef CONFIG_MAGIC_SYSRQ
  259. static void sysrq_handle_globreg(int key)
  260. {
  261. trigger_all_cpu_backtrace();
  262. }
  263. static struct sysrq_key_op sparc_globalreg_op = {
  264. .handler = sysrq_handle_globreg,
  265. .help_msg = "global-regs(y)",
  266. .action_msg = "Show Global CPU Regs",
  267. };
  268. static void __global_pmu_self(int this_cpu)
  269. {
  270. struct global_pmu_snapshot *pp;
  271. int i, num;
  272. if (!pcr_ops)
  273. return;
  274. pp = &global_cpu_snapshot[this_cpu].pmu;
  275. num = 1;
  276. if (tlb_type == hypervisor &&
  277. sun4v_chip_type >= SUN4V_CHIP_NIAGARA4)
  278. num = 4;
  279. for (i = 0; i < num; i++) {
  280. pp->pcr[i] = pcr_ops->read_pcr(i);
  281. pp->pic[i] = pcr_ops->read_pic(i);
  282. }
  283. }
  284. static void __global_pmu_poll(struct global_pmu_snapshot *pp)
  285. {
  286. int limit = 0;
  287. while (!pp->pcr[0] && ++limit < 100) {
  288. barrier();
  289. udelay(1);
  290. }
  291. }
  292. static void pmu_snapshot_all_cpus(void)
  293. {
  294. unsigned long flags;
  295. int this_cpu, cpu;
  296. spin_lock_irqsave(&global_cpu_snapshot_lock, flags);
  297. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  298. this_cpu = raw_smp_processor_id();
  299. __global_pmu_self(this_cpu);
  300. smp_fetch_global_pmu();
  301. for_each_online_cpu(cpu) {
  302. struct global_pmu_snapshot *pp = &global_cpu_snapshot[cpu].pmu;
  303. __global_pmu_poll(pp);
  304. printk("%c CPU[%3d]: PCR[%08lx:%08lx:%08lx:%08lx] PIC[%08lx:%08lx:%08lx:%08lx]\n",
  305. (cpu == this_cpu ? '*' : ' '), cpu,
  306. pp->pcr[0], pp->pcr[1], pp->pcr[2], pp->pcr[3],
  307. pp->pic[0], pp->pic[1], pp->pic[2], pp->pic[3]);
  308. touch_nmi_watchdog();
  309. }
  310. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  311. spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
  312. }
  313. static void sysrq_handle_globpmu(int key)
  314. {
  315. pmu_snapshot_all_cpus();
  316. }
  317. static struct sysrq_key_op sparc_globalpmu_op = {
  318. .handler = sysrq_handle_globpmu,
  319. .help_msg = "global-pmu(x)",
  320. .action_msg = "Show Global PMU Regs",
  321. };
  322. static int __init sparc_sysrq_init(void)
  323. {
  324. int ret = register_sysrq_key('y', &sparc_globalreg_op);
  325. if (!ret)
  326. ret = register_sysrq_key('x', &sparc_globalpmu_op);
  327. return ret;
  328. }
  329. core_initcall(sparc_sysrq_init);
  330. #endif
  331. unsigned long thread_saved_pc(struct task_struct *tsk)
  332. {
  333. struct thread_info *ti = task_thread_info(tsk);
  334. unsigned long ret = 0xdeadbeefUL;
  335. if (ti && ti->ksp) {
  336. unsigned long *sp;
  337. sp = (unsigned long *)(ti->ksp + STACK_BIAS);
  338. if (((unsigned long)sp & (sizeof(long) - 1)) == 0UL &&
  339. sp[14]) {
  340. unsigned long *fp;
  341. fp = (unsigned long *)(sp[14] + STACK_BIAS);
  342. if (((unsigned long)fp & (sizeof(long) - 1)) == 0UL)
  343. ret = fp[15];
  344. }
  345. }
  346. return ret;
  347. }
  348. /* Free current thread data structures etc.. */
  349. void exit_thread(struct task_struct *tsk)
  350. {
  351. struct thread_info *t = task_thread_info(tsk);
  352. if (t->utraps) {
  353. if (t->utraps[0] < 2)
  354. kfree (t->utraps);
  355. else
  356. t->utraps[0]--;
  357. }
  358. }
  359. void flush_thread(void)
  360. {
  361. struct thread_info *t = current_thread_info();
  362. struct mm_struct *mm;
  363. mm = t->task->mm;
  364. if (mm)
  365. tsb_context_switch(mm);
  366. set_thread_wsaved(0);
  367. /* Clear FPU register state. */
  368. t->fpsaved[0] = 0;
  369. }
  370. /* It's a bit more tricky when 64-bit tasks are involved... */
  371. static unsigned long clone_stackframe(unsigned long csp, unsigned long psp)
  372. {
  373. bool stack_64bit = test_thread_64bit_stack(psp);
  374. unsigned long fp, distance, rval;
  375. if (stack_64bit) {
  376. csp += STACK_BIAS;
  377. psp += STACK_BIAS;
  378. __get_user(fp, &(((struct reg_window __user *)psp)->ins[6]));
  379. fp += STACK_BIAS;
  380. if (test_thread_flag(TIF_32BIT))
  381. fp &= 0xffffffff;
  382. } else
  383. __get_user(fp, &(((struct reg_window32 __user *)psp)->ins[6]));
  384. /* Now align the stack as this is mandatory in the Sparc ABI
  385. * due to how register windows work. This hides the
  386. * restriction from thread libraries etc.
  387. */
  388. csp &= ~15UL;
  389. distance = fp - psp;
  390. rval = (csp - distance);
  391. if (copy_in_user((void __user *) rval, (void __user *) psp, distance))
  392. rval = 0;
  393. else if (!stack_64bit) {
  394. if (put_user(((u32)csp),
  395. &(((struct reg_window32 __user *)rval)->ins[6])))
  396. rval = 0;
  397. } else {
  398. if (put_user(((u64)csp - STACK_BIAS),
  399. &(((struct reg_window __user *)rval)->ins[6])))
  400. rval = 0;
  401. else
  402. rval = rval - STACK_BIAS;
  403. }
  404. return rval;
  405. }
  406. /* Standard stuff. */
  407. static inline void shift_window_buffer(int first_win, int last_win,
  408. struct thread_info *t)
  409. {
  410. int i;
  411. for (i = first_win; i < last_win; i++) {
  412. t->rwbuf_stkptrs[i] = t->rwbuf_stkptrs[i+1];
  413. memcpy(&t->reg_window[i], &t->reg_window[i+1],
  414. sizeof(struct reg_window));
  415. }
  416. }
  417. void synchronize_user_stack(void)
  418. {
  419. struct thread_info *t = current_thread_info();
  420. unsigned long window;
  421. flush_user_windows();
  422. if ((window = get_thread_wsaved()) != 0) {
  423. window -= 1;
  424. do {
  425. struct reg_window *rwin = &t->reg_window[window];
  426. int winsize = sizeof(struct reg_window);
  427. unsigned long sp;
  428. sp = t->rwbuf_stkptrs[window];
  429. if (test_thread_64bit_stack(sp))
  430. sp += STACK_BIAS;
  431. else
  432. winsize = sizeof(struct reg_window32);
  433. if (!copy_to_user((char __user *)sp, rwin, winsize)) {
  434. shift_window_buffer(window, get_thread_wsaved() - 1, t);
  435. set_thread_wsaved(get_thread_wsaved() - 1);
  436. }
  437. } while (window--);
  438. }
  439. }
  440. static void stack_unaligned(unsigned long sp)
  441. {
  442. siginfo_t info;
  443. info.si_signo = SIGBUS;
  444. info.si_errno = 0;
  445. info.si_code = BUS_ADRALN;
  446. info.si_addr = (void __user *) sp;
  447. info.si_trapno = 0;
  448. force_sig_info(SIGBUS, &info, current);
  449. }
  450. void fault_in_user_windows(void)
  451. {
  452. struct thread_info *t = current_thread_info();
  453. unsigned long window;
  454. flush_user_windows();
  455. window = get_thread_wsaved();
  456. if (likely(window != 0)) {
  457. window -= 1;
  458. do {
  459. struct reg_window *rwin = &t->reg_window[window];
  460. int winsize = sizeof(struct reg_window);
  461. unsigned long sp;
  462. sp = t->rwbuf_stkptrs[window];
  463. if (test_thread_64bit_stack(sp))
  464. sp += STACK_BIAS;
  465. else
  466. winsize = sizeof(struct reg_window32);
  467. if (unlikely(sp & 0x7UL))
  468. stack_unaligned(sp);
  469. if (unlikely(copy_to_user((char __user *)sp,
  470. rwin, winsize)))
  471. goto barf;
  472. } while (window--);
  473. }
  474. set_thread_wsaved(0);
  475. return;
  476. barf:
  477. set_thread_wsaved(window + 1);
  478. user_exit();
  479. do_exit(SIGILL);
  480. }
  481. asmlinkage long sparc_do_fork(unsigned long clone_flags,
  482. unsigned long stack_start,
  483. struct pt_regs *regs,
  484. unsigned long stack_size)
  485. {
  486. int __user *parent_tid_ptr, *child_tid_ptr;
  487. unsigned long orig_i1 = regs->u_regs[UREG_I1];
  488. long ret;
  489. #ifdef CONFIG_COMPAT
  490. if (test_thread_flag(TIF_32BIT)) {
  491. parent_tid_ptr = compat_ptr(regs->u_regs[UREG_I2]);
  492. child_tid_ptr = compat_ptr(regs->u_regs[UREG_I4]);
  493. } else
  494. #endif
  495. {
  496. parent_tid_ptr = (int __user *) regs->u_regs[UREG_I2];
  497. child_tid_ptr = (int __user *) regs->u_regs[UREG_I4];
  498. }
  499. ret = do_fork(clone_flags, stack_start, stack_size,
  500. parent_tid_ptr, child_tid_ptr);
  501. /* If we get an error and potentially restart the system
  502. * call, we're screwed because copy_thread() clobbered
  503. * the parent's %o1. So detect that case and restore it
  504. * here.
  505. */
  506. if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
  507. regs->u_regs[UREG_I1] = orig_i1;
  508. return ret;
  509. }
  510. /* Copy a Sparc thread. The fork() return value conventions
  511. * under SunOS are nothing short of bletcherous:
  512. * Parent --> %o0 == childs pid, %o1 == 0
  513. * Child --> %o0 == parents pid, %o1 == 1
  514. */
  515. int copy_thread(unsigned long clone_flags, unsigned long sp,
  516. unsigned long arg, struct task_struct *p)
  517. {
  518. struct thread_info *t = task_thread_info(p);
  519. struct pt_regs *regs = current_pt_regs();
  520. struct sparc_stackf *parent_sf;
  521. unsigned long child_stack_sz;
  522. char *child_trap_frame;
  523. /* Calculate offset to stack_frame & pt_regs */
  524. child_stack_sz = (STACKFRAME_SZ + TRACEREG_SZ);
  525. child_trap_frame = (task_stack_page(p) +
  526. (THREAD_SIZE - child_stack_sz));
  527. t->new_child = 1;
  528. t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
  529. t->kregs = (struct pt_regs *) (child_trap_frame +
  530. sizeof(struct sparc_stackf));
  531. t->fpsaved[0] = 0;
  532. if (unlikely(p->flags & PF_KTHREAD)) {
  533. memset(child_trap_frame, 0, child_stack_sz);
  534. __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =
  535. (current_pt_regs()->tstate + 1) & TSTATE_CWP;
  536. t->current_ds = ASI_P;
  537. t->kregs->u_regs[UREG_G1] = sp; /* function */
  538. t->kregs->u_regs[UREG_G2] = arg;
  539. return 0;
  540. }
  541. parent_sf = ((struct sparc_stackf *) regs) - 1;
  542. memcpy(child_trap_frame, parent_sf, child_stack_sz);
  543. if (t->flags & _TIF_32BIT) {
  544. sp &= 0x00000000ffffffffUL;
  545. regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
  546. }
  547. t->kregs->u_regs[UREG_FP] = sp;
  548. __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =
  549. (regs->tstate + 1) & TSTATE_CWP;
  550. t->current_ds = ASI_AIUS;
  551. if (sp != regs->u_regs[UREG_FP]) {
  552. unsigned long csp;
  553. csp = clone_stackframe(sp, regs->u_regs[UREG_FP]);
  554. if (!csp)
  555. return -EFAULT;
  556. t->kregs->u_regs[UREG_FP] = csp;
  557. }
  558. if (t->utraps)
  559. t->utraps[0]++;
  560. /* Set the return value for the child. */
  561. t->kregs->u_regs[UREG_I0] = current->pid;
  562. t->kregs->u_regs[UREG_I1] = 1;
  563. /* Set the second return value for the parent. */
  564. regs->u_regs[UREG_I1] = 0;
  565. if (clone_flags & CLONE_SETTLS)
  566. t->kregs->u_regs[UREG_G7] = regs->u_regs[UREG_I3];
  567. return 0;
  568. }
  569. typedef struct {
  570. union {
  571. unsigned int pr_regs[32];
  572. unsigned long pr_dregs[16];
  573. } pr_fr;
  574. unsigned int __unused;
  575. unsigned int pr_fsr;
  576. unsigned char pr_qcnt;
  577. unsigned char pr_q_entrysize;
  578. unsigned char pr_en;
  579. unsigned int pr_q[64];
  580. } elf_fpregset_t32;
  581. /*
  582. * fill in the fpu structure for a core dump.
  583. */
  584. int dump_fpu (struct pt_regs * regs, elf_fpregset_t * fpregs)
  585. {
  586. unsigned long *kfpregs = current_thread_info()->fpregs;
  587. unsigned long fprs = current_thread_info()->fpsaved[0];
  588. if (test_thread_flag(TIF_32BIT)) {
  589. elf_fpregset_t32 *fpregs32 = (elf_fpregset_t32 *)fpregs;
  590. if (fprs & FPRS_DL)
  591. memcpy(&fpregs32->pr_fr.pr_regs[0], kfpregs,
  592. sizeof(unsigned int) * 32);
  593. else
  594. memset(&fpregs32->pr_fr.pr_regs[0], 0,
  595. sizeof(unsigned int) * 32);
  596. fpregs32->pr_qcnt = 0;
  597. fpregs32->pr_q_entrysize = 8;
  598. memset(&fpregs32->pr_q[0], 0,
  599. (sizeof(unsigned int) * 64));
  600. if (fprs & FPRS_FEF) {
  601. fpregs32->pr_fsr = (unsigned int) current_thread_info()->xfsr[0];
  602. fpregs32->pr_en = 1;
  603. } else {
  604. fpregs32->pr_fsr = 0;
  605. fpregs32->pr_en = 0;
  606. }
  607. } else {
  608. if(fprs & FPRS_DL)
  609. memcpy(&fpregs->pr_regs[0], kfpregs,
  610. sizeof(unsigned int) * 32);
  611. else
  612. memset(&fpregs->pr_regs[0], 0,
  613. sizeof(unsigned int) * 32);
  614. if(fprs & FPRS_DU)
  615. memcpy(&fpregs->pr_regs[16], kfpregs+16,
  616. sizeof(unsigned int) * 32);
  617. else
  618. memset(&fpregs->pr_regs[16], 0,
  619. sizeof(unsigned int) * 32);
  620. if(fprs & FPRS_FEF) {
  621. fpregs->pr_fsr = current_thread_info()->xfsr[0];
  622. fpregs->pr_gsr = current_thread_info()->gsr[0];
  623. } else {
  624. fpregs->pr_fsr = fpregs->pr_gsr = 0;
  625. }
  626. fpregs->pr_fprs = fprs;
  627. }
  628. return 1;
  629. }
  630. EXPORT_SYMBOL(dump_fpu);
  631. unsigned long get_wchan(struct task_struct *task)
  632. {
  633. unsigned long pc, fp, bias = 0;
  634. struct thread_info *tp;
  635. struct reg_window *rw;
  636. unsigned long ret = 0;
  637. int count = 0;
  638. if (!task || task == current ||
  639. task->state == TASK_RUNNING)
  640. goto out;
  641. tp = task_thread_info(task);
  642. bias = STACK_BIAS;
  643. fp = task_thread_info(task)->ksp + bias;
  644. do {
  645. if (!kstack_valid(tp, fp))
  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. }