process.c 17 KB

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