process_64.c 19 KB

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