process_64.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* arch/sparc64/kernel/process.c
  3. *
  4. * Copyright (C) 1995, 1996, 2008 David S. Miller ([email protected])
  5. * Copyright (C) 1996 Eddie C. Dost ([email protected])
  6. * Copyright (C) 1997, 1998 Jakub Jelinek ([email protected])
  7. */
  8. /*
  9. * This file handles the architecture-dependent parts of process handling..
  10. */
  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/signal.h>
  36. #include <linux/uaccess.h>
  37. #include <asm/page.h>
  38. #include <asm/pgalloc.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. raw_local_irq_enable();
  59. } else {
  60. unsigned long pstate;
  61. raw_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. /* If resumed by cpu_poke then we need to explicitly
  74. * call scheduler_ipi().
  75. */
  76. scheduler_poke();
  77. }
  78. /* Re-enable interrupts. */
  79. __asm__ __volatile__(
  80. "rdpr %%pstate, %0\n\t"
  81. "or %0, %1, %0\n\t"
  82. "wrpr %0, %%g0, %%pstate"
  83. : "=&r" (pstate)
  84. : "i" (PSTATE_IE));
  85. }
  86. }
  87. #ifdef CONFIG_HOTPLUG_CPU
  88. void arch_cpu_idle_dead(void)
  89. {
  90. sched_preempt_enable_no_resched();
  91. cpu_play_dead();
  92. }
  93. #endif
  94. #ifdef CONFIG_COMPAT
  95. static void show_regwindow32(struct pt_regs *regs)
  96. {
  97. struct reg_window32 __user *rw;
  98. struct reg_window32 r_w;
  99. __asm__ __volatile__ ("flushw");
  100. rw = compat_ptr((unsigned int)regs->u_regs[14]);
  101. if (copy_from_user (&r_w, rw, sizeof(r_w))) {
  102. return;
  103. }
  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. if ((regs->tstate & TSTATE_PRIV) || !(test_thread_flag(TIF_32BIT))) {
  122. __asm__ __volatile__ ("flushw");
  123. rw = (struct reg_window __user *)
  124. (regs->u_regs[14] + STACK_BIAS);
  125. rwk = (struct reg_window *)
  126. (regs->u_regs[14] + STACK_BIAS);
  127. if (!(regs->tstate & TSTATE_PRIV)) {
  128. if (copy_from_user (&r_w, rw, sizeof(r_w))) {
  129. return;
  130. }
  131. rwk = &r_w;
  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], KERN_DEFAULT);
  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_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
  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. this_cpu = raw_smp_processor_id();
  222. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  223. if (cpumask_test_cpu(this_cpu, mask) && !exclude_self)
  224. __global_reg_self(tp, regs, this_cpu);
  225. smp_fetch_global_regs();
  226. for_each_cpu(cpu, mask) {
  227. struct global_reg_snapshot *gp;
  228. if (exclude_self && cpu == this_cpu)
  229. continue;
  230. gp = &global_cpu_snapshot[cpu].reg;
  231. __global_reg_poll(gp);
  232. tp = gp->thread;
  233. printk("%c CPU[%3d]: TSTATE[%016lx] TPC[%016lx] TNPC[%016lx] TASK[%s:%d]\n",
  234. (cpu == this_cpu ? '*' : ' '), cpu,
  235. gp->tstate, gp->tpc, gp->tnpc,
  236. ((tp && tp->task) ? tp->task->comm : "NULL"),
  237. ((tp && tp->task) ? tp->task->pid : -1));
  238. if (gp->tstate & TSTATE_PRIV) {
  239. printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
  240. (void *) gp->tpc,
  241. (void *) gp->o7,
  242. (void *) gp->i7,
  243. (void *) gp->rpc);
  244. } else {
  245. printk(" TPC[%lx] O7[%lx] I7[%lx] RPC[%lx]\n",
  246. gp->tpc, gp->o7, gp->i7, gp->rpc);
  247. }
  248. touch_nmi_watchdog();
  249. }
  250. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  251. spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
  252. }
  253. #ifdef CONFIG_MAGIC_SYSRQ
  254. static void sysrq_handle_globreg(int key)
  255. {
  256. trigger_all_cpu_backtrace();
  257. }
  258. static const struct sysrq_key_op sparc_globalreg_op = {
  259. .handler = sysrq_handle_globreg,
  260. .help_msg = "global-regs(y)",
  261. .action_msg = "Show Global CPU Regs",
  262. };
  263. static void __global_pmu_self(int this_cpu)
  264. {
  265. struct global_pmu_snapshot *pp;
  266. int i, num;
  267. if (!pcr_ops)
  268. return;
  269. pp = &global_cpu_snapshot[this_cpu].pmu;
  270. num = 1;
  271. if (tlb_type == hypervisor &&
  272. sun4v_chip_type >= SUN4V_CHIP_NIAGARA4)
  273. num = 4;
  274. for (i = 0; i < num; i++) {
  275. pp->pcr[i] = pcr_ops->read_pcr(i);
  276. pp->pic[i] = pcr_ops->read_pic(i);
  277. }
  278. }
  279. static void __global_pmu_poll(struct global_pmu_snapshot *pp)
  280. {
  281. int limit = 0;
  282. while (!pp->pcr[0] && ++limit < 100) {
  283. barrier();
  284. udelay(1);
  285. }
  286. }
  287. static void pmu_snapshot_all_cpus(void)
  288. {
  289. unsigned long flags;
  290. int this_cpu, cpu;
  291. spin_lock_irqsave(&global_cpu_snapshot_lock, flags);
  292. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  293. this_cpu = raw_smp_processor_id();
  294. __global_pmu_self(this_cpu);
  295. smp_fetch_global_pmu();
  296. for_each_online_cpu(cpu) {
  297. struct global_pmu_snapshot *pp = &global_cpu_snapshot[cpu].pmu;
  298. __global_pmu_poll(pp);
  299. printk("%c CPU[%3d]: PCR[%08lx:%08lx:%08lx:%08lx] PIC[%08lx:%08lx:%08lx:%08lx]\n",
  300. (cpu == this_cpu ? '*' : ' '), cpu,
  301. pp->pcr[0], pp->pcr[1], pp->pcr[2], pp->pcr[3],
  302. pp->pic[0], pp->pic[1], pp->pic[2], pp->pic[3]);
  303. touch_nmi_watchdog();
  304. }
  305. memset(global_cpu_snapshot, 0, sizeof(global_cpu_snapshot));
  306. spin_unlock_irqrestore(&global_cpu_snapshot_lock, flags);
  307. }
  308. static void sysrq_handle_globpmu(int key)
  309. {
  310. pmu_snapshot_all_cpus();
  311. }
  312. static const struct sysrq_key_op sparc_globalpmu_op = {
  313. .handler = sysrq_handle_globpmu,
  314. .help_msg = "global-pmu(x)",
  315. .action_msg = "Show Global PMU Regs",
  316. };
  317. static int __init sparc_sysrq_init(void)
  318. {
  319. int ret = register_sysrq_key('y', &sparc_globalreg_op);
  320. if (!ret)
  321. ret = register_sysrq_key('x', &sparc_globalpmu_op);
  322. return ret;
  323. }
  324. core_initcall(sparc_sysrq_init);
  325. #endif
  326. /* Free current thread data structures etc.. */
  327. void exit_thread(struct task_struct *tsk)
  328. {
  329. struct thread_info *t = task_thread_info(tsk);
  330. if (t->utraps) {
  331. if (t->utraps[0] < 2)
  332. kfree (t->utraps);
  333. else
  334. t->utraps[0]--;
  335. }
  336. }
  337. void flush_thread(void)
  338. {
  339. struct thread_info *t = current_thread_info();
  340. struct mm_struct *mm;
  341. mm = t->task->mm;
  342. if (mm)
  343. tsb_context_switch(mm);
  344. set_thread_wsaved(0);
  345. /* Clear FPU register state. */
  346. t->fpsaved[0] = 0;
  347. }
  348. /* It's a bit more tricky when 64-bit tasks are involved... */
  349. static unsigned long clone_stackframe(unsigned long csp, unsigned long psp)
  350. {
  351. bool stack_64bit = test_thread_64bit_stack(psp);
  352. unsigned long fp, distance, rval;
  353. if (stack_64bit) {
  354. csp += STACK_BIAS;
  355. psp += STACK_BIAS;
  356. __get_user(fp, &(((struct reg_window __user *)psp)->ins[6]));
  357. fp += STACK_BIAS;
  358. if (test_thread_flag(TIF_32BIT))
  359. fp &= 0xffffffff;
  360. } else
  361. __get_user(fp, &(((struct reg_window32 __user *)psp)->ins[6]));
  362. /* Now align the stack as this is mandatory in the Sparc ABI
  363. * due to how register windows work. This hides the
  364. * restriction from thread libraries etc.
  365. */
  366. csp &= ~15UL;
  367. distance = fp - psp;
  368. rval = (csp - distance);
  369. if (raw_copy_in_user((void __user *)rval, (void __user *)psp, distance))
  370. rval = 0;
  371. else if (!stack_64bit) {
  372. if (put_user(((u32)csp),
  373. &(((struct reg_window32 __user *)rval)->ins[6])))
  374. rval = 0;
  375. } else {
  376. if (put_user(((u64)csp - STACK_BIAS),
  377. &(((struct reg_window __user *)rval)->ins[6])))
  378. rval = 0;
  379. else
  380. rval = rval - STACK_BIAS;
  381. }
  382. return rval;
  383. }
  384. /* Standard stuff. */
  385. static inline void shift_window_buffer(int first_win, int last_win,
  386. struct thread_info *t)
  387. {
  388. int i;
  389. for (i = first_win; i < last_win; i++) {
  390. t->rwbuf_stkptrs[i] = t->rwbuf_stkptrs[i+1];
  391. memcpy(&t->reg_window[i], &t->reg_window[i+1],
  392. sizeof(struct reg_window));
  393. }
  394. }
  395. void synchronize_user_stack(void)
  396. {
  397. struct thread_info *t = current_thread_info();
  398. unsigned long window;
  399. flush_user_windows();
  400. if ((window = get_thread_wsaved()) != 0) {
  401. window -= 1;
  402. do {
  403. struct reg_window *rwin = &t->reg_window[window];
  404. int winsize = sizeof(struct reg_window);
  405. unsigned long sp;
  406. sp = t->rwbuf_stkptrs[window];
  407. if (test_thread_64bit_stack(sp))
  408. sp += STACK_BIAS;
  409. else
  410. winsize = sizeof(struct reg_window32);
  411. if (!copy_to_user((char __user *)sp, rwin, winsize)) {
  412. shift_window_buffer(window, get_thread_wsaved() - 1, t);
  413. set_thread_wsaved(get_thread_wsaved() - 1);
  414. }
  415. } while (window--);
  416. }
  417. }
  418. static void stack_unaligned(unsigned long sp)
  419. {
  420. force_sig_fault(SIGBUS, BUS_ADRALN, (void __user *) sp);
  421. }
  422. static const char uwfault32[] = KERN_INFO \
  423. "%s[%d]: bad register window fault: SP %08lx (orig_sp %08lx) TPC %08lx O7 %08lx\n";
  424. static const char uwfault64[] = KERN_INFO \
  425. "%s[%d]: bad register window fault: SP %016lx (orig_sp %016lx) TPC %08lx O7 %016lx\n";
  426. void fault_in_user_windows(struct pt_regs *regs)
  427. {
  428. struct thread_info *t = current_thread_info();
  429. unsigned long window;
  430. flush_user_windows();
  431. window = get_thread_wsaved();
  432. if (likely(window != 0)) {
  433. window -= 1;
  434. do {
  435. struct reg_window *rwin = &t->reg_window[window];
  436. int winsize = sizeof(struct reg_window);
  437. unsigned long sp, orig_sp;
  438. orig_sp = sp = t->rwbuf_stkptrs[window];
  439. if (test_thread_64bit_stack(sp))
  440. sp += STACK_BIAS;
  441. else
  442. winsize = sizeof(struct reg_window32);
  443. if (unlikely(sp & 0x7UL))
  444. stack_unaligned(sp);
  445. if (unlikely(copy_to_user((char __user *)sp,
  446. rwin, winsize))) {
  447. if (show_unhandled_signals)
  448. printk_ratelimited(is_compat_task() ?
  449. uwfault32 : uwfault64,
  450. current->comm, current->pid,
  451. sp, orig_sp,
  452. regs->tpc,
  453. regs->u_regs[UREG_I7]);
  454. goto barf;
  455. }
  456. } while (window--);
  457. }
  458. set_thread_wsaved(0);
  459. return;
  460. barf:
  461. set_thread_wsaved(window + 1);
  462. force_sig(SIGSEGV);
  463. }
  464. /* Copy a Sparc thread. The fork() return value conventions
  465. * under SunOS are nothing short of bletcherous:
  466. * Parent --> %o0 == childs pid, %o1 == 0
  467. * Child --> %o0 == parents pid, %o1 == 1
  468. */
  469. int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
  470. {
  471. unsigned long clone_flags = args->flags;
  472. unsigned long sp = args->stack;
  473. unsigned long tls = args->tls;
  474. struct thread_info *t = task_thread_info(p);
  475. struct pt_regs *regs = current_pt_regs();
  476. struct sparc_stackf *parent_sf;
  477. unsigned long child_stack_sz;
  478. char *child_trap_frame;
  479. /* Calculate offset to stack_frame & pt_regs */
  480. child_stack_sz = (STACKFRAME_SZ + TRACEREG_SZ);
  481. child_trap_frame = (task_stack_page(p) +
  482. (THREAD_SIZE - child_stack_sz));
  483. t->new_child = 1;
  484. t->ksp = ((unsigned long) child_trap_frame) - STACK_BIAS;
  485. t->kregs = (struct pt_regs *) (child_trap_frame +
  486. sizeof(struct sparc_stackf));
  487. t->fpsaved[0] = 0;
  488. if (unlikely(args->fn)) {
  489. memset(child_trap_frame, 0, child_stack_sz);
  490. __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =
  491. (current_pt_regs()->tstate + 1) & TSTATE_CWP;
  492. t->kregs->u_regs[UREG_G1] = (unsigned long) args->fn;
  493. t->kregs->u_regs[UREG_G2] = (unsigned long) args->fn_arg;
  494. return 0;
  495. }
  496. parent_sf = ((struct sparc_stackf *) regs) - 1;
  497. memcpy(child_trap_frame, parent_sf, child_stack_sz);
  498. if (t->flags & _TIF_32BIT) {
  499. sp &= 0x00000000ffffffffUL;
  500. regs->u_regs[UREG_FP] &= 0x00000000ffffffffUL;
  501. }
  502. t->kregs->u_regs[UREG_FP] = sp;
  503. __thread_flag_byte_ptr(t)[TI_FLAG_BYTE_CWP] =
  504. (regs->tstate + 1) & TSTATE_CWP;
  505. if (sp != regs->u_regs[UREG_FP]) {
  506. unsigned long csp;
  507. csp = clone_stackframe(sp, regs->u_regs[UREG_FP]);
  508. if (!csp)
  509. return -EFAULT;
  510. t->kregs->u_regs[UREG_FP] = csp;
  511. }
  512. if (t->utraps)
  513. t->utraps[0]++;
  514. /* Set the return value for the child. */
  515. t->kregs->u_regs[UREG_I0] = current->pid;
  516. t->kregs->u_regs[UREG_I1] = 1;
  517. /* Set the second return value for the parent. */
  518. regs->u_regs[UREG_I1] = 0;
  519. if (clone_flags & CLONE_SETTLS)
  520. t->kregs->u_regs[UREG_G7] = tls;
  521. return 0;
  522. }
  523. /* TIF_MCDPER in thread info flags for current task is updated lazily upon
  524. * a context switch. Update this flag in current task's thread flags
  525. * before dup so the dup'd task will inherit the current TIF_MCDPER flag.
  526. */
  527. int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
  528. {
  529. if (adi_capable()) {
  530. register unsigned long tmp_mcdper;
  531. __asm__ __volatile__(
  532. ".word 0x83438000\n\t" /* rd %mcdper, %g1 */
  533. "mov %%g1, %0\n\t"
  534. : "=r" (tmp_mcdper)
  535. :
  536. : "g1");
  537. if (tmp_mcdper)
  538. set_thread_flag(TIF_MCDPER);
  539. else
  540. clear_thread_flag(TIF_MCDPER);
  541. }
  542. *dst = *src;
  543. return 0;
  544. }
  545. unsigned long __get_wchan(struct task_struct *task)
  546. {
  547. unsigned long pc, fp, bias = 0;
  548. struct thread_info *tp;
  549. struct reg_window *rw;
  550. unsigned long ret = 0;
  551. int count = 0;
  552. tp = task_thread_info(task);
  553. bias = STACK_BIAS;
  554. fp = task_thread_info(task)->ksp + bias;
  555. do {
  556. if (!kstack_valid(tp, fp))
  557. break;
  558. rw = (struct reg_window *) fp;
  559. pc = rw->ins[7];
  560. if (!in_sched_functions(pc)) {
  561. ret = pc;
  562. goto out;
  563. }
  564. fp = rw->ins[6] + bias;
  565. } while (++count < 16);
  566. out:
  567. return ret;
  568. }