process_64.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*
  2. * arch/sh/kernel/process_64.c
  3. *
  4. * This file handles the architecture-dependent parts of process handling..
  5. *
  6. * Copyright (C) 2000, 2001 Paolo Alberelli
  7. * Copyright (C) 2003 - 2007 Paul Mundt
  8. * Copyright (C) 2003, 2004 Richard Curnow
  9. *
  10. * Started from SH3/4 version:
  11. * Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  12. *
  13. * In turn started from i386 version:
  14. * Copyright (C) 1995 Linus Torvalds
  15. *
  16. * This file is subject to the terms and conditions of the GNU General Public
  17. * License. See the file "COPYING" in the main directory of this archive
  18. * for more details.
  19. */
  20. #include <linux/mm.h>
  21. #include <linux/fs.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/reboot.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/io.h>
  27. #include <asm/syscalls.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/pgtable.h>
  30. #include <asm/mmu_context.h>
  31. #include <asm/fpu.h>
  32. struct task_struct *last_task_used_math = NULL;
  33. void show_regs(struct pt_regs *regs)
  34. {
  35. unsigned long long ah, al, bh, bl, ch, cl;
  36. printk("\n");
  37. ah = (regs->pc) >> 32;
  38. al = (regs->pc) & 0xffffffff;
  39. bh = (regs->regs[18]) >> 32;
  40. bl = (regs->regs[18]) & 0xffffffff;
  41. ch = (regs->regs[15]) >> 32;
  42. cl = (regs->regs[15]) & 0xffffffff;
  43. printk("PC : %08Lx%08Lx LINK: %08Lx%08Lx SP : %08Lx%08Lx\n",
  44. ah, al, bh, bl, ch, cl);
  45. ah = (regs->sr) >> 32;
  46. al = (regs->sr) & 0xffffffff;
  47. asm volatile ("getcon " __TEA ", %0" : "=r" (bh));
  48. asm volatile ("getcon " __TEA ", %0" : "=r" (bl));
  49. bh = (bh) >> 32;
  50. bl = (bl) & 0xffffffff;
  51. asm volatile ("getcon " __KCR0 ", %0" : "=r" (ch));
  52. asm volatile ("getcon " __KCR0 ", %0" : "=r" (cl));
  53. ch = (ch) >> 32;
  54. cl = (cl) & 0xffffffff;
  55. printk("SR : %08Lx%08Lx TEA : %08Lx%08Lx KCR0: %08Lx%08Lx\n",
  56. ah, al, bh, bl, ch, cl);
  57. ah = (regs->regs[0]) >> 32;
  58. al = (regs->regs[0]) & 0xffffffff;
  59. bh = (regs->regs[1]) >> 32;
  60. bl = (regs->regs[1]) & 0xffffffff;
  61. ch = (regs->regs[2]) >> 32;
  62. cl = (regs->regs[2]) & 0xffffffff;
  63. printk("R0 : %08Lx%08Lx R1 : %08Lx%08Lx R2 : %08Lx%08Lx\n",
  64. ah, al, bh, bl, ch, cl);
  65. ah = (regs->regs[3]) >> 32;
  66. al = (regs->regs[3]) & 0xffffffff;
  67. bh = (regs->regs[4]) >> 32;
  68. bl = (regs->regs[4]) & 0xffffffff;
  69. ch = (regs->regs[5]) >> 32;
  70. cl = (regs->regs[5]) & 0xffffffff;
  71. printk("R3 : %08Lx%08Lx R4 : %08Lx%08Lx R5 : %08Lx%08Lx\n",
  72. ah, al, bh, bl, ch, cl);
  73. ah = (regs->regs[6]) >> 32;
  74. al = (regs->regs[6]) & 0xffffffff;
  75. bh = (regs->regs[7]) >> 32;
  76. bl = (regs->regs[7]) & 0xffffffff;
  77. ch = (regs->regs[8]) >> 32;
  78. cl = (regs->regs[8]) & 0xffffffff;
  79. printk("R6 : %08Lx%08Lx R7 : %08Lx%08Lx R8 : %08Lx%08Lx\n",
  80. ah, al, bh, bl, ch, cl);
  81. ah = (regs->regs[9]) >> 32;
  82. al = (regs->regs[9]) & 0xffffffff;
  83. bh = (regs->regs[10]) >> 32;
  84. bl = (regs->regs[10]) & 0xffffffff;
  85. ch = (regs->regs[11]) >> 32;
  86. cl = (regs->regs[11]) & 0xffffffff;
  87. printk("R9 : %08Lx%08Lx R10 : %08Lx%08Lx R11 : %08Lx%08Lx\n",
  88. ah, al, bh, bl, ch, cl);
  89. ah = (regs->regs[12]) >> 32;
  90. al = (regs->regs[12]) & 0xffffffff;
  91. bh = (regs->regs[13]) >> 32;
  92. bl = (regs->regs[13]) & 0xffffffff;
  93. ch = (regs->regs[14]) >> 32;
  94. cl = (regs->regs[14]) & 0xffffffff;
  95. printk("R12 : %08Lx%08Lx R13 : %08Lx%08Lx R14 : %08Lx%08Lx\n",
  96. ah, al, bh, bl, ch, cl);
  97. ah = (regs->regs[16]) >> 32;
  98. al = (regs->regs[16]) & 0xffffffff;
  99. bh = (regs->regs[17]) >> 32;
  100. bl = (regs->regs[17]) & 0xffffffff;
  101. ch = (regs->regs[19]) >> 32;
  102. cl = (regs->regs[19]) & 0xffffffff;
  103. printk("R16 : %08Lx%08Lx R17 : %08Lx%08Lx R19 : %08Lx%08Lx\n",
  104. ah, al, bh, bl, ch, cl);
  105. ah = (regs->regs[20]) >> 32;
  106. al = (regs->regs[20]) & 0xffffffff;
  107. bh = (regs->regs[21]) >> 32;
  108. bl = (regs->regs[21]) & 0xffffffff;
  109. ch = (regs->regs[22]) >> 32;
  110. cl = (regs->regs[22]) & 0xffffffff;
  111. printk("R20 : %08Lx%08Lx R21 : %08Lx%08Lx R22 : %08Lx%08Lx\n",
  112. ah, al, bh, bl, ch, cl);
  113. ah = (regs->regs[23]) >> 32;
  114. al = (regs->regs[23]) & 0xffffffff;
  115. bh = (regs->regs[24]) >> 32;
  116. bl = (regs->regs[24]) & 0xffffffff;
  117. ch = (regs->regs[25]) >> 32;
  118. cl = (regs->regs[25]) & 0xffffffff;
  119. printk("R23 : %08Lx%08Lx R24 : %08Lx%08Lx R25 : %08Lx%08Lx\n",
  120. ah, al, bh, bl, ch, cl);
  121. ah = (regs->regs[26]) >> 32;
  122. al = (regs->regs[26]) & 0xffffffff;
  123. bh = (regs->regs[27]) >> 32;
  124. bl = (regs->regs[27]) & 0xffffffff;
  125. ch = (regs->regs[28]) >> 32;
  126. cl = (regs->regs[28]) & 0xffffffff;
  127. printk("R26 : %08Lx%08Lx R27 : %08Lx%08Lx R28 : %08Lx%08Lx\n",
  128. ah, al, bh, bl, ch, cl);
  129. ah = (regs->regs[29]) >> 32;
  130. al = (regs->regs[29]) & 0xffffffff;
  131. bh = (regs->regs[30]) >> 32;
  132. bl = (regs->regs[30]) & 0xffffffff;
  133. ch = (regs->regs[31]) >> 32;
  134. cl = (regs->regs[31]) & 0xffffffff;
  135. printk("R29 : %08Lx%08Lx R30 : %08Lx%08Lx R31 : %08Lx%08Lx\n",
  136. ah, al, bh, bl, ch, cl);
  137. ah = (regs->regs[32]) >> 32;
  138. al = (regs->regs[32]) & 0xffffffff;
  139. bh = (regs->regs[33]) >> 32;
  140. bl = (regs->regs[33]) & 0xffffffff;
  141. ch = (regs->regs[34]) >> 32;
  142. cl = (regs->regs[34]) & 0xffffffff;
  143. printk("R32 : %08Lx%08Lx R33 : %08Lx%08Lx R34 : %08Lx%08Lx\n",
  144. ah, al, bh, bl, ch, cl);
  145. ah = (regs->regs[35]) >> 32;
  146. al = (regs->regs[35]) & 0xffffffff;
  147. bh = (regs->regs[36]) >> 32;
  148. bl = (regs->regs[36]) & 0xffffffff;
  149. ch = (regs->regs[37]) >> 32;
  150. cl = (regs->regs[37]) & 0xffffffff;
  151. printk("R35 : %08Lx%08Lx R36 : %08Lx%08Lx R37 : %08Lx%08Lx\n",
  152. ah, al, bh, bl, ch, cl);
  153. ah = (regs->regs[38]) >> 32;
  154. al = (regs->regs[38]) & 0xffffffff;
  155. bh = (regs->regs[39]) >> 32;
  156. bl = (regs->regs[39]) & 0xffffffff;
  157. ch = (regs->regs[40]) >> 32;
  158. cl = (regs->regs[40]) & 0xffffffff;
  159. printk("R38 : %08Lx%08Lx R39 : %08Lx%08Lx R40 : %08Lx%08Lx\n",
  160. ah, al, bh, bl, ch, cl);
  161. ah = (regs->regs[41]) >> 32;
  162. al = (regs->regs[41]) & 0xffffffff;
  163. bh = (regs->regs[42]) >> 32;
  164. bl = (regs->regs[42]) & 0xffffffff;
  165. ch = (regs->regs[43]) >> 32;
  166. cl = (regs->regs[43]) & 0xffffffff;
  167. printk("R41 : %08Lx%08Lx R42 : %08Lx%08Lx R43 : %08Lx%08Lx\n",
  168. ah, al, bh, bl, ch, cl);
  169. ah = (regs->regs[44]) >> 32;
  170. al = (regs->regs[44]) & 0xffffffff;
  171. bh = (regs->regs[45]) >> 32;
  172. bl = (regs->regs[45]) & 0xffffffff;
  173. ch = (regs->regs[46]) >> 32;
  174. cl = (regs->regs[46]) & 0xffffffff;
  175. printk("R44 : %08Lx%08Lx R45 : %08Lx%08Lx R46 : %08Lx%08Lx\n",
  176. ah, al, bh, bl, ch, cl);
  177. ah = (regs->regs[47]) >> 32;
  178. al = (regs->regs[47]) & 0xffffffff;
  179. bh = (regs->regs[48]) >> 32;
  180. bl = (regs->regs[48]) & 0xffffffff;
  181. ch = (regs->regs[49]) >> 32;
  182. cl = (regs->regs[49]) & 0xffffffff;
  183. printk("R47 : %08Lx%08Lx R48 : %08Lx%08Lx R49 : %08Lx%08Lx\n",
  184. ah, al, bh, bl, ch, cl);
  185. ah = (regs->regs[50]) >> 32;
  186. al = (regs->regs[50]) & 0xffffffff;
  187. bh = (regs->regs[51]) >> 32;
  188. bl = (regs->regs[51]) & 0xffffffff;
  189. ch = (regs->regs[52]) >> 32;
  190. cl = (regs->regs[52]) & 0xffffffff;
  191. printk("R50 : %08Lx%08Lx R51 : %08Lx%08Lx R52 : %08Lx%08Lx\n",
  192. ah, al, bh, bl, ch, cl);
  193. ah = (regs->regs[53]) >> 32;
  194. al = (regs->regs[53]) & 0xffffffff;
  195. bh = (regs->regs[54]) >> 32;
  196. bl = (regs->regs[54]) & 0xffffffff;
  197. ch = (regs->regs[55]) >> 32;
  198. cl = (regs->regs[55]) & 0xffffffff;
  199. printk("R53 : %08Lx%08Lx R54 : %08Lx%08Lx R55 : %08Lx%08Lx\n",
  200. ah, al, bh, bl, ch, cl);
  201. ah = (regs->regs[56]) >> 32;
  202. al = (regs->regs[56]) & 0xffffffff;
  203. bh = (regs->regs[57]) >> 32;
  204. bl = (regs->regs[57]) & 0xffffffff;
  205. ch = (regs->regs[58]) >> 32;
  206. cl = (regs->regs[58]) & 0xffffffff;
  207. printk("R56 : %08Lx%08Lx R57 : %08Lx%08Lx R58 : %08Lx%08Lx\n",
  208. ah, al, bh, bl, ch, cl);
  209. ah = (regs->regs[59]) >> 32;
  210. al = (regs->regs[59]) & 0xffffffff;
  211. bh = (regs->regs[60]) >> 32;
  212. bl = (regs->regs[60]) & 0xffffffff;
  213. ch = (regs->regs[61]) >> 32;
  214. cl = (regs->regs[61]) & 0xffffffff;
  215. printk("R59 : %08Lx%08Lx R60 : %08Lx%08Lx R61 : %08Lx%08Lx\n",
  216. ah, al, bh, bl, ch, cl);
  217. ah = (regs->regs[62]) >> 32;
  218. al = (regs->regs[62]) & 0xffffffff;
  219. bh = (regs->tregs[0]) >> 32;
  220. bl = (regs->tregs[0]) & 0xffffffff;
  221. ch = (regs->tregs[1]) >> 32;
  222. cl = (regs->tregs[1]) & 0xffffffff;
  223. printk("R62 : %08Lx%08Lx T0 : %08Lx%08Lx T1 : %08Lx%08Lx\n",
  224. ah, al, bh, bl, ch, cl);
  225. ah = (regs->tregs[2]) >> 32;
  226. al = (regs->tregs[2]) & 0xffffffff;
  227. bh = (regs->tregs[3]) >> 32;
  228. bl = (regs->tregs[3]) & 0xffffffff;
  229. ch = (regs->tregs[4]) >> 32;
  230. cl = (regs->tregs[4]) & 0xffffffff;
  231. printk("T2 : %08Lx%08Lx T3 : %08Lx%08Lx T4 : %08Lx%08Lx\n",
  232. ah, al, bh, bl, ch, cl);
  233. ah = (regs->tregs[5]) >> 32;
  234. al = (regs->tregs[5]) & 0xffffffff;
  235. bh = (regs->tregs[6]) >> 32;
  236. bl = (regs->tregs[6]) & 0xffffffff;
  237. ch = (regs->tregs[7]) >> 32;
  238. cl = (regs->tregs[7]) & 0xffffffff;
  239. printk("T5 : %08Lx%08Lx T6 : %08Lx%08Lx T7 : %08Lx%08Lx\n",
  240. ah, al, bh, bl, ch, cl);
  241. /*
  242. * If we're in kernel mode, dump the stack too..
  243. */
  244. if (!user_mode(regs)) {
  245. void show_stack(struct task_struct *tsk, unsigned long *sp);
  246. unsigned long sp = regs->regs[15] & 0xffffffff;
  247. struct task_struct *tsk = get_current();
  248. tsk->thread.kregs = regs;
  249. show_stack(tsk, (unsigned long *)sp);
  250. }
  251. }
  252. /*
  253. * Create a kernel thread
  254. */
  255. ATTRIB_NORET void kernel_thread_helper(void *arg, int (*fn)(void *))
  256. {
  257. do_exit(fn(arg));
  258. }
  259. /*
  260. * This is the mechanism for creating a new kernel thread.
  261. *
  262. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  263. * who haven't done an "execve()") should use this: it will work within
  264. * a system call from a "real" process, but the process memory space will
  265. * not be freed until both the parent and the child have exited.
  266. */
  267. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  268. {
  269. struct pt_regs regs;
  270. memset(&regs, 0, sizeof(regs));
  271. regs.regs[2] = (unsigned long)arg;
  272. regs.regs[3] = (unsigned long)fn;
  273. regs.pc = (unsigned long)kernel_thread_helper;
  274. regs.sr = (1 << 30);
  275. /* Ok, create the new process.. */
  276. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
  277. &regs, 0, NULL, NULL);
  278. }
  279. EXPORT_SYMBOL(kernel_thread);
  280. /*
  281. * Free current thread data structures etc..
  282. */
  283. void exit_thread(void)
  284. {
  285. /*
  286. * See arch/sparc/kernel/process.c for the precedent for doing
  287. * this -- RPC.
  288. *
  289. * The SH-5 FPU save/restore approach relies on
  290. * last_task_used_math pointing to a live task_struct. When
  291. * another task tries to use the FPU for the 1st time, the FPUDIS
  292. * trap handling (see arch/sh/kernel/cpu/sh5/fpu.c) will save the
  293. * existing FPU state to the FP regs field within
  294. * last_task_used_math before re-loading the new task's FPU state
  295. * (or initialising it if the FPU has been used before). So if
  296. * last_task_used_math is stale, and its page has already been
  297. * re-allocated for another use, the consequences are rather
  298. * grim. Unless we null it here, there is no other path through
  299. * which it would get safely nulled.
  300. */
  301. #ifdef CONFIG_SH_FPU
  302. if (last_task_used_math == current) {
  303. last_task_used_math = NULL;
  304. }
  305. #endif
  306. }
  307. void flush_thread(void)
  308. {
  309. /* Called by fs/exec.c (setup_new_exec) to remove traces of a
  310. * previously running executable. */
  311. #ifdef CONFIG_SH_FPU
  312. if (last_task_used_math == current) {
  313. last_task_used_math = NULL;
  314. }
  315. /* Force FPU state to be reinitialised after exec */
  316. clear_used_math();
  317. #endif
  318. /* if we are a kernel thread, about to change to user thread,
  319. * update kreg
  320. */
  321. if(current->thread.kregs==&fake_swapper_regs) {
  322. current->thread.kregs =
  323. ((struct pt_regs *)(THREAD_SIZE + (unsigned long) current) - 1);
  324. current->thread.uregs = current->thread.kregs;
  325. }
  326. }
  327. void release_thread(struct task_struct *dead_task)
  328. {
  329. /* do nothing */
  330. }
  331. /* Fill in the fpu structure for a core dump.. */
  332. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  333. {
  334. #ifdef CONFIG_SH_FPU
  335. int fpvalid;
  336. struct task_struct *tsk = current;
  337. fpvalid = !!tsk_used_math(tsk);
  338. if (fpvalid) {
  339. if (current == last_task_used_math) {
  340. enable_fpu();
  341. save_fpu(tsk);
  342. disable_fpu();
  343. last_task_used_math = 0;
  344. regs->sr |= SR_FD;
  345. }
  346. memcpy(fpu, &tsk->thread.xstate->hardfpu, sizeof(*fpu));
  347. }
  348. return fpvalid;
  349. #else
  350. return 0; /* Task didn't use the fpu at all. */
  351. #endif
  352. }
  353. EXPORT_SYMBOL(dump_fpu);
  354. asmlinkage void ret_from_fork(void);
  355. int copy_thread(unsigned long clone_flags, unsigned long usp,
  356. unsigned long unused,
  357. struct task_struct *p, struct pt_regs *regs)
  358. {
  359. struct pt_regs *childregs;
  360. #ifdef CONFIG_SH_FPU
  361. if(last_task_used_math == current) {
  362. enable_fpu();
  363. save_fpu(current);
  364. disable_fpu();
  365. last_task_used_math = NULL;
  366. regs->sr |= SR_FD;
  367. }
  368. #endif
  369. /* Copy from sh version */
  370. childregs = (struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1;
  371. *childregs = *regs;
  372. /*
  373. * Sign extend the edited stack.
  374. * Note that thread.pc and thread.pc will stay
  375. * 32-bit wide and context switch must take care
  376. * of NEFF sign extension.
  377. */
  378. if (user_mode(regs)) {
  379. childregs->regs[15] = neff_sign_extend(usp);
  380. p->thread.uregs = childregs;
  381. } else {
  382. childregs->regs[15] =
  383. neff_sign_extend((unsigned long)task_stack_page(p) +
  384. THREAD_SIZE);
  385. }
  386. childregs->regs[9] = 0; /* Set return value for child */
  387. childregs->sr |= SR_FD; /* Invalidate FPU flag */
  388. p->thread.sp = (unsigned long) childregs;
  389. p->thread.pc = (unsigned long) ret_from_fork;
  390. return 0;
  391. }
  392. asmlinkage int sys_fork(unsigned long r2, unsigned long r3,
  393. unsigned long r4, unsigned long r5,
  394. unsigned long r6, unsigned long r7,
  395. struct pt_regs *pregs)
  396. {
  397. return do_fork(SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  398. }
  399. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  400. unsigned long r4, unsigned long r5,
  401. unsigned long r6, unsigned long r7,
  402. struct pt_regs *pregs)
  403. {
  404. if (!newsp)
  405. newsp = pregs->regs[15];
  406. return do_fork(clone_flags, newsp, pregs, 0, 0, 0);
  407. }
  408. /*
  409. * This is trivial, and on the face of it looks like it
  410. * could equally well be done in user mode.
  411. *
  412. * Not so, for quite unobvious reasons - register pressure.
  413. * In user mode vfork() cannot have a stack frame, and if
  414. * done by calling the "clone()" system call directly, you
  415. * do not have enough call-clobbered registers to hold all
  416. * the information you need.
  417. */
  418. asmlinkage int sys_vfork(unsigned long r2, unsigned long r3,
  419. unsigned long r4, unsigned long r5,
  420. unsigned long r6, unsigned long r7,
  421. struct pt_regs *pregs)
  422. {
  423. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, pregs->regs[15], pregs, 0, 0, 0);
  424. }
  425. /*
  426. * sys_execve() executes a new program.
  427. */
  428. asmlinkage int sys_execve(char *ufilename, char **uargv,
  429. char **uenvp, unsigned long r5,
  430. unsigned long r6, unsigned long r7,
  431. struct pt_regs *pregs)
  432. {
  433. int error;
  434. char *filename;
  435. filename = getname((char __user *)ufilename);
  436. error = PTR_ERR(filename);
  437. if (IS_ERR(filename))
  438. goto out;
  439. error = do_execve(filename,
  440. (char __user * __user *)uargv,
  441. (char __user * __user *)uenvp,
  442. pregs);
  443. putname(filename);
  444. out:
  445. return error;
  446. }
  447. /*
  448. * These bracket the sleeping functions..
  449. */
  450. extern void interruptible_sleep_on(wait_queue_head_t *q);
  451. #define mid_sched ((unsigned long) interruptible_sleep_on)
  452. #ifdef CONFIG_FRAME_POINTER
  453. static int in_sh64_switch_to(unsigned long pc)
  454. {
  455. extern char __sh64_switch_to_end;
  456. /* For a sleeping task, the PC is somewhere in the middle of the function,
  457. so we don't have to worry about masking the LSB off */
  458. return (pc >= (unsigned long) sh64_switch_to) &&
  459. (pc < (unsigned long) &__sh64_switch_to_end);
  460. }
  461. #endif
  462. unsigned long get_wchan(struct task_struct *p)
  463. {
  464. unsigned long pc;
  465. if (!p || p == current || p->state == TASK_RUNNING)
  466. return 0;
  467. /*
  468. * The same comment as on the Alpha applies here, too ...
  469. */
  470. pc = thread_saved_pc(p);
  471. #ifdef CONFIG_FRAME_POINTER
  472. if (in_sh64_switch_to(pc)) {
  473. unsigned long schedule_fp;
  474. unsigned long sh64_switch_to_fp;
  475. unsigned long schedule_caller_pc;
  476. sh64_switch_to_fp = (long) p->thread.sp;
  477. /* r14 is saved at offset 4 in the sh64_switch_to frame */
  478. schedule_fp = *(unsigned long *) (long)(sh64_switch_to_fp + 4);
  479. /* and the caller of 'schedule' is (currently!) saved at offset 24
  480. in the frame of schedule (from disasm) */
  481. schedule_caller_pc = *(unsigned long *) (long)(schedule_fp + 24);
  482. return schedule_caller_pc;
  483. }
  484. #endif
  485. return pc;
  486. }