process_32.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * arch/sh/kernel/process.c
  3. *
  4. * This file handles the architecture-dependent parts of process handling..
  5. *
  6. * Copyright (C) 1995 Linus Torvalds
  7. *
  8. * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  9. * Copyright (C) 2006 Lineo Solutions Inc. support SH4A UBC
  10. * Copyright (C) 2002 - 2008 Paul Mundt
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file "COPYING" in the main directory of this archive
  14. * for more details.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/mm.h>
  18. #include <linux/slab.h>
  19. #include <linux/elfcore.h>
  20. #include <linux/kallsyms.h>
  21. #include <linux/fs.h>
  22. #include <linux/ftrace.h>
  23. #include <linux/hw_breakpoint.h>
  24. #include <linux/prefetch.h>
  25. #include <linux/stackprotector.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/mmu_context.h>
  28. #include <asm/fpu.h>
  29. #include <asm/syscalls.h>
  30. #include <asm/switch_to.h>
  31. void show_regs(struct pt_regs * regs)
  32. {
  33. printk("\n");
  34. show_regs_print_info(KERN_DEFAULT);
  35. print_symbol("PC is at %s\n", instruction_pointer(regs));
  36. print_symbol("PR is at %s\n", regs->pr);
  37. printk("PC : %08lx SP : %08lx SR : %08lx ",
  38. regs->pc, regs->regs[15], regs->sr);
  39. #ifdef CONFIG_MMU
  40. printk("TEA : %08x\n", __raw_readl(MMU_TEA));
  41. #else
  42. printk("\n");
  43. #endif
  44. printk("R0 : %08lx R1 : %08lx R2 : %08lx R3 : %08lx\n",
  45. regs->regs[0],regs->regs[1],
  46. regs->regs[2],regs->regs[3]);
  47. printk("R4 : %08lx R5 : %08lx R6 : %08lx R7 : %08lx\n",
  48. regs->regs[4],regs->regs[5],
  49. regs->regs[6],regs->regs[7]);
  50. printk("R8 : %08lx R9 : %08lx R10 : %08lx R11 : %08lx\n",
  51. regs->regs[8],regs->regs[9],
  52. regs->regs[10],regs->regs[11]);
  53. printk("R12 : %08lx R13 : %08lx R14 : %08lx\n",
  54. regs->regs[12],regs->regs[13],
  55. regs->regs[14]);
  56. printk("MACH: %08lx MACL: %08lx GBR : %08lx PR : %08lx\n",
  57. regs->mach, regs->macl, regs->gbr, regs->pr);
  58. show_trace(NULL, (unsigned long *)regs->regs[15], regs);
  59. show_code(regs);
  60. }
  61. void start_thread(struct pt_regs *regs, unsigned long new_pc,
  62. unsigned long new_sp)
  63. {
  64. regs->pr = 0;
  65. regs->sr = SR_FD;
  66. regs->pc = new_pc;
  67. regs->regs[15] = new_sp;
  68. free_thread_xstate(current);
  69. }
  70. EXPORT_SYMBOL(start_thread);
  71. void flush_thread(void)
  72. {
  73. struct task_struct *tsk = current;
  74. flush_ptrace_hw_breakpoint(tsk);
  75. #if defined(CONFIG_SH_FPU)
  76. /* Forget lazy FPU state */
  77. clear_fpu(tsk, task_pt_regs(tsk));
  78. clear_used_math();
  79. #endif
  80. }
  81. void release_thread(struct task_struct *dead_task)
  82. {
  83. /* do nothing */
  84. }
  85. /* Fill in the fpu structure for a core dump.. */
  86. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  87. {
  88. int fpvalid = 0;
  89. #if defined(CONFIG_SH_FPU)
  90. struct task_struct *tsk = current;
  91. fpvalid = !!tsk_used_math(tsk);
  92. if (fpvalid)
  93. fpvalid = !fpregs_get(tsk, NULL, 0,
  94. sizeof(struct user_fpu_struct),
  95. fpu, NULL);
  96. #endif
  97. return fpvalid;
  98. }
  99. EXPORT_SYMBOL(dump_fpu);
  100. asmlinkage void ret_from_fork(void);
  101. asmlinkage void ret_from_kernel_thread(void);
  102. int copy_thread(unsigned long clone_flags, unsigned long usp,
  103. unsigned long arg, struct task_struct *p)
  104. {
  105. struct thread_info *ti = task_thread_info(p);
  106. struct pt_regs *childregs;
  107. #if defined(CONFIG_SH_DSP)
  108. struct task_struct *tsk = current;
  109. if (is_dsp_enabled(tsk)) {
  110. /* We can use the __save_dsp or just copy the struct:
  111. * __save_dsp(p);
  112. * p->thread.dsp_status.status |= SR_DSP
  113. */
  114. p->thread.dsp_status = tsk->thread.dsp_status;
  115. }
  116. #endif
  117. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  118. childregs = task_pt_regs(p);
  119. p->thread.sp = (unsigned long) childregs;
  120. if (unlikely(p->flags & PF_KTHREAD)) {
  121. memset(childregs, 0, sizeof(struct pt_regs));
  122. p->thread.pc = (unsigned long) ret_from_kernel_thread;
  123. childregs->regs[4] = arg;
  124. childregs->regs[5] = usp;
  125. childregs->sr = SR_MD;
  126. #if defined(CONFIG_SH_FPU)
  127. childregs->sr |= SR_FD;
  128. #endif
  129. ti->addr_limit = KERNEL_DS;
  130. ti->status &= ~TS_USEDFPU;
  131. p->thread.fpu_counter = 0;
  132. return 0;
  133. }
  134. *childregs = *current_pt_regs();
  135. if (usp)
  136. childregs->regs[15] = usp;
  137. ti->addr_limit = USER_DS;
  138. if (clone_flags & CLONE_SETTLS)
  139. childregs->gbr = childregs->regs[0];
  140. childregs->regs[0] = 0; /* Set return value for child */
  141. p->thread.pc = (unsigned long) ret_from_fork;
  142. return 0;
  143. }
  144. /*
  145. * switch_to(x,y) should switch tasks from x to y.
  146. *
  147. */
  148. __notrace_funcgraph struct task_struct *
  149. __switch_to(struct task_struct *prev, struct task_struct *next)
  150. {
  151. struct thread_struct *next_t = &next->thread;
  152. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  153. __stack_chk_guard = next->stack_canary;
  154. #endif
  155. unlazy_fpu(prev, task_pt_regs(prev));
  156. /* we're going to use this soon, after a few expensive things */
  157. if (next->thread.fpu_counter > 5)
  158. prefetch(next_t->xstate);
  159. #ifdef CONFIG_MMU
  160. /*
  161. * Restore the kernel mode register
  162. * k7 (r7_bank1)
  163. */
  164. asm volatile("ldc %0, r7_bank"
  165. : /* no output */
  166. : "r" (task_thread_info(next)));
  167. #endif
  168. /*
  169. * If the task has used fpu the last 5 timeslices, just do a full
  170. * restore of the math state immediately to avoid the trap; the
  171. * chances of needing FPU soon are obviously high now
  172. */
  173. if (next->thread.fpu_counter > 5)
  174. __fpu_state_restore();
  175. return prev;
  176. }
  177. unsigned long get_wchan(struct task_struct *p)
  178. {
  179. unsigned long pc;
  180. if (!p || p == current || p->state == TASK_RUNNING)
  181. return 0;
  182. /*
  183. * The same comment as on the Alpha applies here, too ...
  184. */
  185. pc = thread_saved_pc(p);
  186. #ifdef CONFIG_FRAME_POINTER
  187. if (in_sched_functions(pc)) {
  188. unsigned long schedule_frame = (unsigned long)p->thread.sp;
  189. return ((unsigned long *)schedule_frame)[21];
  190. }
  191. #endif
  192. return pc;
  193. }