process.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * linux/arch/ppc64/kernel/process.c
  3. *
  4. * Derived from "arch/i386/kernel/process.c"
  5. * Copyright (C) 1995 Linus Torvalds
  6. *
  7. * Updated and modified by Cort Dougan (cort@cs.nmt.edu) and
  8. * Paul Mackerras (paulus@cs.anu.edu.au)
  9. *
  10. * PowerPC version
  11. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. */
  18. #include <linux/config.h>
  19. #include <linux/module.h>
  20. #include <linux/errno.h>
  21. #include <linux/sched.h>
  22. #include <linux/kernel.h>
  23. #include <linux/mm.h>
  24. #include <linux/smp.h>
  25. #include <linux/smp_lock.h>
  26. #include <linux/stddef.h>
  27. #include <linux/unistd.h>
  28. #include <linux/slab.h>
  29. #include <linux/user.h>
  30. #include <linux/elf.h>
  31. #include <linux/init.h>
  32. #include <linux/init_task.h>
  33. #include <linux/prctl.h>
  34. #include <linux/ptrace.h>
  35. #include <linux/kallsyms.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/utsname.h>
  38. #include <linux/kprobes.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/uaccess.h>
  41. #include <asm/system.h>
  42. #include <asm/io.h>
  43. #include <asm/processor.h>
  44. #include <asm/mmu.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/prom.h>
  47. #include <asm/ppcdebug.h>
  48. #include <asm/machdep.h>
  49. #include <asm/iSeries/HvCallHpt.h>
  50. #include <asm/cputable.h>
  51. #include <asm/sections.h>
  52. #include <asm/tlbflush.h>
  53. #include <asm/time.h>
  54. #ifndef CONFIG_SMP
  55. struct task_struct *last_task_used_math = NULL;
  56. struct task_struct *last_task_used_altivec = NULL;
  57. #endif
  58. /*
  59. * Make sure the floating-point register state in the
  60. * the thread_struct is up to date for task tsk.
  61. */
  62. void flush_fp_to_thread(struct task_struct *tsk)
  63. {
  64. if (tsk->thread.regs) {
  65. /*
  66. * We need to disable preemption here because if we didn't,
  67. * another process could get scheduled after the regs->msr
  68. * test but before we have finished saving the FP registers
  69. * to the thread_struct. That process could take over the
  70. * FPU, and then when we get scheduled again we would store
  71. * bogus values for the remaining FP registers.
  72. */
  73. preempt_disable();
  74. if (tsk->thread.regs->msr & MSR_FP) {
  75. #ifdef CONFIG_SMP
  76. /*
  77. * This should only ever be called for current or
  78. * for a stopped child process. Since we save away
  79. * the FP register state on context switch on SMP,
  80. * there is something wrong if a stopped child appears
  81. * to still have its FP state in the CPU registers.
  82. */
  83. BUG_ON(tsk != current);
  84. #endif
  85. giveup_fpu(current);
  86. }
  87. preempt_enable();
  88. }
  89. }
  90. void enable_kernel_fp(void)
  91. {
  92. WARN_ON(preemptible());
  93. #ifdef CONFIG_SMP
  94. if (current->thread.regs && (current->thread.regs->msr & MSR_FP))
  95. giveup_fpu(current);
  96. else
  97. giveup_fpu(NULL); /* just enables FP for kernel */
  98. #else
  99. giveup_fpu(last_task_used_math);
  100. #endif /* CONFIG_SMP */
  101. }
  102. EXPORT_SYMBOL(enable_kernel_fp);
  103. int dump_task_fpu(struct task_struct *tsk, elf_fpregset_t *fpregs)
  104. {
  105. if (!tsk->thread.regs)
  106. return 0;
  107. flush_fp_to_thread(current);
  108. memcpy(fpregs, &tsk->thread.fpr[0], sizeof(*fpregs));
  109. return 1;
  110. }
  111. #ifdef CONFIG_ALTIVEC
  112. void enable_kernel_altivec(void)
  113. {
  114. WARN_ON(preemptible());
  115. #ifdef CONFIG_SMP
  116. if (current->thread.regs && (current->thread.regs->msr & MSR_VEC))
  117. giveup_altivec(current);
  118. else
  119. giveup_altivec(NULL); /* just enables FP for kernel */
  120. #else
  121. giveup_altivec(last_task_used_altivec);
  122. #endif /* CONFIG_SMP */
  123. }
  124. EXPORT_SYMBOL(enable_kernel_altivec);
  125. /*
  126. * Make sure the VMX/Altivec register state in the
  127. * the thread_struct is up to date for task tsk.
  128. */
  129. void flush_altivec_to_thread(struct task_struct *tsk)
  130. {
  131. if (tsk->thread.regs) {
  132. preempt_disable();
  133. if (tsk->thread.regs->msr & MSR_VEC) {
  134. #ifdef CONFIG_SMP
  135. BUG_ON(tsk != current);
  136. #endif
  137. giveup_altivec(current);
  138. }
  139. preempt_enable();
  140. }
  141. }
  142. int dump_task_altivec(struct pt_regs *regs, elf_vrregset_t *vrregs)
  143. {
  144. flush_altivec_to_thread(current);
  145. memcpy(vrregs, &current->thread.vr[0], sizeof(*vrregs));
  146. return 1;
  147. }
  148. #endif /* CONFIG_ALTIVEC */
  149. DEFINE_PER_CPU(struct cpu_usage, cpu_usage_array);
  150. struct task_struct *__switch_to(struct task_struct *prev,
  151. struct task_struct *new)
  152. {
  153. struct thread_struct *new_thread, *old_thread;
  154. unsigned long flags;
  155. struct task_struct *last;
  156. #ifdef CONFIG_SMP
  157. /* avoid complexity of lazy save/restore of fpu
  158. * by just saving it every time we switch out if
  159. * this task used the fpu during the last quantum.
  160. *
  161. * If it tries to use the fpu again, it'll trap and
  162. * reload its fp regs. So we don't have to do a restore
  163. * every switch, just a save.
  164. * -- Cort
  165. */
  166. if (prev->thread.regs && (prev->thread.regs->msr & MSR_FP))
  167. giveup_fpu(prev);
  168. #ifdef CONFIG_ALTIVEC
  169. if (prev->thread.regs && (prev->thread.regs->msr & MSR_VEC))
  170. giveup_altivec(prev);
  171. #endif /* CONFIG_ALTIVEC */
  172. #endif /* CONFIG_SMP */
  173. #if defined(CONFIG_ALTIVEC) && !defined(CONFIG_SMP)
  174. /* Avoid the trap. On smp this this never happens since
  175. * we don't set last_task_used_altivec -- Cort
  176. */
  177. if (new->thread.regs && last_task_used_altivec == new)
  178. new->thread.regs->msr |= MSR_VEC;
  179. #endif /* CONFIG_ALTIVEC */
  180. flush_tlb_pending();
  181. new_thread = &new->thread;
  182. old_thread = &current->thread;
  183. /* Collect purr utilization data per process and per processor wise */
  184. /* purr is nothing but processor time base */
  185. #if defined(CONFIG_PPC_PSERIES)
  186. if (cur_cpu_spec->firmware_features & FW_FEATURE_SPLPAR) {
  187. struct cpu_usage *cu = &__get_cpu_var(cpu_usage_array);
  188. long unsigned start_tb, current_tb;
  189. start_tb = old_thread->start_tb;
  190. cu->current_tb = current_tb = mfspr(SPRN_PURR);
  191. old_thread->accum_tb += (current_tb - start_tb);
  192. new_thread->start_tb = current_tb;
  193. }
  194. #endif
  195. local_irq_save(flags);
  196. last = _switch(old_thread, new_thread);
  197. local_irq_restore(flags);
  198. return last;
  199. }
  200. static int instructions_to_print = 16;
  201. static void show_instructions(struct pt_regs *regs)
  202. {
  203. int i;
  204. unsigned long pc = regs->nip - (instructions_to_print * 3 / 4 *
  205. sizeof(int));
  206. printk("Instruction dump:");
  207. for (i = 0; i < instructions_to_print; i++) {
  208. int instr;
  209. if (!(i % 8))
  210. printk("\n");
  211. if (((REGION_ID(pc) != KERNEL_REGION_ID) &&
  212. (REGION_ID(pc) != VMALLOC_REGION_ID)) ||
  213. __get_user(instr, (unsigned int *)pc)) {
  214. printk("XXXXXXXX ");
  215. } else {
  216. if (regs->nip == pc)
  217. printk("<%08x> ", instr);
  218. else
  219. printk("%08x ", instr);
  220. }
  221. pc += sizeof(int);
  222. }
  223. printk("\n");
  224. }
  225. void show_regs(struct pt_regs * regs)
  226. {
  227. int i;
  228. unsigned long trap;
  229. printk("NIP: %016lX XER: %08X LR: %016lX CTR: %016lX\n",
  230. regs->nip, (unsigned int)regs->xer, regs->link, regs->ctr);
  231. printk("REGS: %p TRAP: %04lx %s (%s)\n",
  232. regs, regs->trap, print_tainted(), system_utsname.release);
  233. printk("MSR: %016lx EE: %01x PR: %01x FP: %01x ME: %01x "
  234. "IR/DR: %01x%01x CR: %08X\n",
  235. regs->msr, regs->msr&MSR_EE ? 1 : 0, regs->msr&MSR_PR ? 1 : 0,
  236. regs->msr & MSR_FP ? 1 : 0,regs->msr&MSR_ME ? 1 : 0,
  237. regs->msr&MSR_IR ? 1 : 0,
  238. regs->msr&MSR_DR ? 1 : 0,
  239. (unsigned int)regs->ccr);
  240. trap = TRAP(regs);
  241. printk("DAR: %016lx DSISR: %016lx\n", regs->dar, regs->dsisr);
  242. printk("TASK: %p[%d] '%s' THREAD: %p",
  243. current, current->pid, current->comm, current->thread_info);
  244. #ifdef CONFIG_SMP
  245. printk(" CPU: %d", smp_processor_id());
  246. #endif /* CONFIG_SMP */
  247. for (i = 0; i < 32; i++) {
  248. if ((i % 4) == 0) {
  249. printk("\n" KERN_INFO "GPR%02d: ", i);
  250. }
  251. printk("%016lX ", regs->gpr[i]);
  252. if (i == 13 && !FULL_REGS(regs))
  253. break;
  254. }
  255. printk("\n");
  256. /*
  257. * Lookup NIP late so we have the best change of getting the
  258. * above info out without failing
  259. */
  260. printk("NIP [%016lx] ", regs->nip);
  261. print_symbol("%s\n", regs->nip);
  262. printk("LR [%016lx] ", regs->link);
  263. print_symbol("%s\n", regs->link);
  264. show_stack(current, (unsigned long *)regs->gpr[1]);
  265. if (!user_mode(regs))
  266. show_instructions(regs);
  267. }
  268. void exit_thread(void)
  269. {
  270. kprobe_flush_task(current);
  271. #ifndef CONFIG_SMP
  272. if (last_task_used_math == current)
  273. last_task_used_math = NULL;
  274. #ifdef CONFIG_ALTIVEC
  275. if (last_task_used_altivec == current)
  276. last_task_used_altivec = NULL;
  277. #endif /* CONFIG_ALTIVEC */
  278. #endif /* CONFIG_SMP */
  279. }
  280. void flush_thread(void)
  281. {
  282. struct thread_info *t = current_thread_info();
  283. kprobe_flush_task(current);
  284. if (t->flags & _TIF_ABI_PENDING)
  285. t->flags ^= (_TIF_ABI_PENDING | _TIF_32BIT);
  286. #ifndef CONFIG_SMP
  287. if (last_task_used_math == current)
  288. last_task_used_math = NULL;
  289. #ifdef CONFIG_ALTIVEC
  290. if (last_task_used_altivec == current)
  291. last_task_used_altivec = NULL;
  292. #endif /* CONFIG_ALTIVEC */
  293. #endif /* CONFIG_SMP */
  294. }
  295. void
  296. release_thread(struct task_struct *t)
  297. {
  298. }
  299. /*
  300. * This gets called before we allocate a new thread and copy
  301. * the current task into it.
  302. */
  303. void prepare_to_copy(struct task_struct *tsk)
  304. {
  305. flush_fp_to_thread(current);
  306. flush_altivec_to_thread(current);
  307. }
  308. /*
  309. * Copy a thread..
  310. */
  311. int
  312. copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
  313. unsigned long unused, struct task_struct *p, struct pt_regs *regs)
  314. {
  315. struct pt_regs *childregs, *kregs;
  316. extern void ret_from_fork(void);
  317. unsigned long sp = (unsigned long)p->thread_info + THREAD_SIZE;
  318. /* Copy registers */
  319. sp -= sizeof(struct pt_regs);
  320. childregs = (struct pt_regs *) sp;
  321. *childregs = *regs;
  322. if ((childregs->msr & MSR_PR) == 0) {
  323. /* for kernel thread, set stackptr in new task */
  324. childregs->gpr[1] = sp + sizeof(struct pt_regs);
  325. p->thread.regs = NULL; /* no user register state */
  326. clear_ti_thread_flag(p->thread_info, TIF_32BIT);
  327. } else {
  328. childregs->gpr[1] = usp;
  329. p->thread.regs = childregs;
  330. if (clone_flags & CLONE_SETTLS) {
  331. if (test_thread_flag(TIF_32BIT))
  332. childregs->gpr[2] = childregs->gpr[6];
  333. else
  334. childregs->gpr[13] = childregs->gpr[6];
  335. }
  336. }
  337. childregs->gpr[3] = 0; /* Result from fork() */
  338. sp -= STACK_FRAME_OVERHEAD;
  339. /*
  340. * The way this works is that at some point in the future
  341. * some task will call _switch to switch to the new task.
  342. * That will pop off the stack frame created below and start
  343. * the new task running at ret_from_fork. The new task will
  344. * do some house keeping and then return from the fork or clone
  345. * system call, using the stack frame created above.
  346. */
  347. sp -= sizeof(struct pt_regs);
  348. kregs = (struct pt_regs *) sp;
  349. sp -= STACK_FRAME_OVERHEAD;
  350. p->thread.ksp = sp;
  351. if (cpu_has_feature(CPU_FTR_SLB)) {
  352. unsigned long sp_vsid = get_kernel_vsid(sp);
  353. sp_vsid <<= SLB_VSID_SHIFT;
  354. sp_vsid |= SLB_VSID_KERNEL;
  355. if (cpu_has_feature(CPU_FTR_16M_PAGE))
  356. sp_vsid |= SLB_VSID_L;
  357. p->thread.ksp_vsid = sp_vsid;
  358. }
  359. /*
  360. * The PPC64 ABI makes use of a TOC to contain function
  361. * pointers. The function (ret_from_except) is actually a pointer
  362. * to the TOC entry. The first entry is a pointer to the actual
  363. * function.
  364. */
  365. kregs->nip = *((unsigned long *)ret_from_fork);
  366. return 0;
  367. }
  368. /*
  369. * Set up a thread for executing a new program
  370. */
  371. void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp)
  372. {
  373. unsigned long entry, toc, load_addr = regs->gpr[2];
  374. /* fdptr is a relocated pointer to the function descriptor for
  375. * the elf _start routine. The first entry in the function
  376. * descriptor is the entry address of _start and the second
  377. * entry is the TOC value we need to use.
  378. */
  379. set_fs(USER_DS);
  380. __get_user(entry, (unsigned long __user *)fdptr);
  381. __get_user(toc, (unsigned long __user *)fdptr+1);
  382. /* Check whether the e_entry function descriptor entries
  383. * need to be relocated before we can use them.
  384. */
  385. if (load_addr != 0) {
  386. entry += load_addr;
  387. toc += load_addr;
  388. }
  389. /*
  390. * If we exec out of a kernel thread then thread.regs will not be
  391. * set. Do it now.
  392. */
  393. if (!current->thread.regs) {
  394. unsigned long childregs = (unsigned long)current->thread_info +
  395. THREAD_SIZE;
  396. childregs -= sizeof(struct pt_regs);
  397. current->thread.regs = (struct pt_regs *)childregs;
  398. }
  399. regs->nip = entry;
  400. regs->gpr[1] = sp;
  401. regs->gpr[2] = toc;
  402. regs->msr = MSR_USER64;
  403. #ifndef CONFIG_SMP
  404. if (last_task_used_math == current)
  405. last_task_used_math = 0;
  406. #endif /* CONFIG_SMP */
  407. memset(current->thread.fpr, 0, sizeof(current->thread.fpr));
  408. current->thread.fpscr = 0;
  409. #ifdef CONFIG_ALTIVEC
  410. #ifndef CONFIG_SMP
  411. if (last_task_used_altivec == current)
  412. last_task_used_altivec = 0;
  413. #endif /* CONFIG_SMP */
  414. memset(current->thread.vr, 0, sizeof(current->thread.vr));
  415. current->thread.vscr.u[0] = 0;
  416. current->thread.vscr.u[1] = 0;
  417. current->thread.vscr.u[2] = 0;
  418. current->thread.vscr.u[3] = 0x00010000; /* Java mode disabled */
  419. current->thread.vrsave = 0;
  420. current->thread.used_vr = 0;
  421. #endif /* CONFIG_ALTIVEC */
  422. }
  423. EXPORT_SYMBOL(start_thread);
  424. int set_fpexc_mode(struct task_struct *tsk, unsigned int val)
  425. {
  426. struct pt_regs *regs = tsk->thread.regs;
  427. if (val > PR_FP_EXC_PRECISE)
  428. return -EINVAL;
  429. tsk->thread.fpexc_mode = __pack_fe01(val);
  430. if (regs != NULL && (regs->msr & MSR_FP) != 0)
  431. regs->msr = (regs->msr & ~(MSR_FE0|MSR_FE1))
  432. | tsk->thread.fpexc_mode;
  433. return 0;
  434. }
  435. int get_fpexc_mode(struct task_struct *tsk, unsigned long adr)
  436. {
  437. unsigned int val;
  438. val = __unpack_fe01(tsk->thread.fpexc_mode);
  439. return put_user(val, (unsigned int __user *) adr);
  440. }
  441. int sys_clone(unsigned long clone_flags, unsigned long p2, unsigned long p3,
  442. unsigned long p4, unsigned long p5, unsigned long p6,
  443. struct pt_regs *regs)
  444. {
  445. unsigned long parent_tidptr = 0;
  446. unsigned long child_tidptr = 0;
  447. if (p2 == 0)
  448. p2 = regs->gpr[1]; /* stack pointer for child */
  449. if (clone_flags & (CLONE_PARENT_SETTID | CLONE_CHILD_SETTID |
  450. CLONE_CHILD_CLEARTID)) {
  451. parent_tidptr = p3;
  452. child_tidptr = p5;
  453. if (test_thread_flag(TIF_32BIT)) {
  454. parent_tidptr &= 0xffffffff;
  455. child_tidptr &= 0xffffffff;
  456. }
  457. }
  458. return do_fork(clone_flags, p2, regs, 0,
  459. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  460. }
  461. int sys_fork(unsigned long p1, unsigned long p2, unsigned long p3,
  462. unsigned long p4, unsigned long p5, unsigned long p6,
  463. struct pt_regs *regs)
  464. {
  465. return do_fork(SIGCHLD, regs->gpr[1], regs, 0, NULL, NULL);
  466. }
  467. int sys_vfork(unsigned long p1, unsigned long p2, unsigned long p3,
  468. unsigned long p4, unsigned long p5, unsigned long p6,
  469. struct pt_regs *regs)
  470. {
  471. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gpr[1], regs, 0,
  472. NULL, NULL);
  473. }
  474. int sys_execve(unsigned long a0, unsigned long a1, unsigned long a2,
  475. unsigned long a3, unsigned long a4, unsigned long a5,
  476. struct pt_regs *regs)
  477. {
  478. int error;
  479. char * filename;
  480. filename = getname((char __user *) a0);
  481. error = PTR_ERR(filename);
  482. if (IS_ERR(filename))
  483. goto out;
  484. flush_fp_to_thread(current);
  485. flush_altivec_to_thread(current);
  486. error = do_execve(filename, (char __user * __user *) a1,
  487. (char __user * __user *) a2, regs);
  488. if (error == 0) {
  489. task_lock(current);
  490. current->ptrace &= ~PT_DTRACE;
  491. task_unlock(current);
  492. }
  493. putname(filename);
  494. out:
  495. return error;
  496. }
  497. static int kstack_depth_to_print = 64;
  498. static int validate_sp(unsigned long sp, struct task_struct *p,
  499. unsigned long nbytes)
  500. {
  501. unsigned long stack_page = (unsigned long)p->thread_info;
  502. if (sp >= stack_page + sizeof(struct thread_struct)
  503. && sp <= stack_page + THREAD_SIZE - nbytes)
  504. return 1;
  505. #ifdef CONFIG_IRQSTACKS
  506. stack_page = (unsigned long) hardirq_ctx[task_cpu(p)];
  507. if (sp >= stack_page + sizeof(struct thread_struct)
  508. && sp <= stack_page + THREAD_SIZE - nbytes)
  509. return 1;
  510. stack_page = (unsigned long) softirq_ctx[task_cpu(p)];
  511. if (sp >= stack_page + sizeof(struct thread_struct)
  512. && sp <= stack_page + THREAD_SIZE - nbytes)
  513. return 1;
  514. #endif
  515. return 0;
  516. }
  517. unsigned long get_wchan(struct task_struct *p)
  518. {
  519. unsigned long ip, sp;
  520. int count = 0;
  521. if (!p || p == current || p->state == TASK_RUNNING)
  522. return 0;
  523. sp = p->thread.ksp;
  524. if (!validate_sp(sp, p, 112))
  525. return 0;
  526. do {
  527. sp = *(unsigned long *)sp;
  528. if (!validate_sp(sp, p, 112))
  529. return 0;
  530. if (count > 0) {
  531. ip = *(unsigned long *)(sp + 16);
  532. if (!in_sched_functions(ip))
  533. return ip;
  534. }
  535. } while (count++ < 16);
  536. return 0;
  537. }
  538. EXPORT_SYMBOL(get_wchan);
  539. void show_stack(struct task_struct *p, unsigned long *_sp)
  540. {
  541. unsigned long ip, newsp, lr;
  542. int count = 0;
  543. unsigned long sp = (unsigned long)_sp;
  544. int firstframe = 1;
  545. if (sp == 0) {
  546. if (p) {
  547. sp = p->thread.ksp;
  548. } else {
  549. sp = __get_SP();
  550. p = current;
  551. }
  552. }
  553. lr = 0;
  554. printk("Call Trace:\n");
  555. do {
  556. if (!validate_sp(sp, p, 112))
  557. return;
  558. _sp = (unsigned long *) sp;
  559. newsp = _sp[0];
  560. ip = _sp[2];
  561. if (!firstframe || ip != lr) {
  562. printk("[%016lx] [%016lx] ", sp, ip);
  563. print_symbol("%s", ip);
  564. if (firstframe)
  565. printk(" (unreliable)");
  566. printk("\n");
  567. }
  568. firstframe = 0;
  569. /*
  570. * See if this is an exception frame.
  571. * We look for the "regshere" marker in the current frame.
  572. */
  573. if (validate_sp(sp, p, sizeof(struct pt_regs) + 400)
  574. && _sp[12] == 0x7265677368657265ul) {
  575. struct pt_regs *regs = (struct pt_regs *)
  576. (sp + STACK_FRAME_OVERHEAD);
  577. printk("--- Exception: %lx", regs->trap);
  578. print_symbol(" at %s\n", regs->nip);
  579. lr = regs->link;
  580. print_symbol(" LR = %s\n", lr);
  581. firstframe = 1;
  582. }
  583. sp = newsp;
  584. } while (count++ < kstack_depth_to_print);
  585. }
  586. void dump_stack(void)
  587. {
  588. show_stack(current, (unsigned long *)__get_SP());
  589. }
  590. EXPORT_SYMBOL(dump_stack);