process_64.c 19 KB

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