process_64.c 17 KB

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