process_32.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. /*
  72. * Free current thread data structures etc..
  73. */
  74. void exit_thread(void)
  75. {
  76. }
  77. void flush_thread(void)
  78. {
  79. struct task_struct *tsk = current;
  80. flush_ptrace_hw_breakpoint(tsk);
  81. #if defined(CONFIG_SH_FPU)
  82. /* Forget lazy FPU state */
  83. clear_fpu(tsk, task_pt_regs(tsk));
  84. clear_used_math();
  85. #endif
  86. }
  87. void release_thread(struct task_struct *dead_task)
  88. {
  89. /* do nothing */
  90. }
  91. /* Fill in the fpu structure for a core dump.. */
  92. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  93. {
  94. int fpvalid = 0;
  95. #if defined(CONFIG_SH_FPU)
  96. struct task_struct *tsk = current;
  97. fpvalid = !!tsk_used_math(tsk);
  98. if (fpvalid)
  99. fpvalid = !fpregs_get(tsk, NULL, 0,
  100. sizeof(struct user_fpu_struct),
  101. fpu, NULL);
  102. #endif
  103. return fpvalid;
  104. }
  105. EXPORT_SYMBOL(dump_fpu);
  106. asmlinkage void ret_from_fork(void);
  107. asmlinkage void ret_from_kernel_thread(void);
  108. int copy_thread(unsigned long clone_flags, unsigned long usp,
  109. unsigned long arg, struct task_struct *p)
  110. {
  111. struct thread_info *ti = task_thread_info(p);
  112. struct pt_regs *childregs;
  113. #if defined(CONFIG_SH_DSP)
  114. struct task_struct *tsk = current;
  115. if (is_dsp_enabled(tsk)) {
  116. /* We can use the __save_dsp or just copy the struct:
  117. * __save_dsp(p);
  118. * p->thread.dsp_status.status |= SR_DSP
  119. */
  120. p->thread.dsp_status = tsk->thread.dsp_status;
  121. }
  122. #endif
  123. memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
  124. childregs = task_pt_regs(p);
  125. p->thread.sp = (unsigned long) childregs;
  126. if (unlikely(p->flags & PF_KTHREAD)) {
  127. memset(childregs, 0, sizeof(struct pt_regs));
  128. p->thread.pc = (unsigned long) ret_from_kernel_thread;
  129. childregs->regs[4] = arg;
  130. childregs->regs[5] = usp;
  131. childregs->sr = SR_MD;
  132. #if defined(CONFIG_SH_FPU)
  133. childregs->sr |= SR_FD;
  134. #endif
  135. ti->addr_limit = KERNEL_DS;
  136. ti->status &= ~TS_USEDFPU;
  137. p->thread.fpu_counter = 0;
  138. return 0;
  139. }
  140. *childregs = *current_pt_regs();
  141. if (usp)
  142. childregs->regs[15] = usp;
  143. ti->addr_limit = USER_DS;
  144. if (clone_flags & CLONE_SETTLS)
  145. childregs->gbr = childregs->regs[0];
  146. childregs->regs[0] = 0; /* Set return value for child */
  147. p->thread.pc = (unsigned long) ret_from_fork;
  148. return 0;
  149. }
  150. /*
  151. * switch_to(x,y) should switch tasks from x to y.
  152. *
  153. */
  154. __notrace_funcgraph struct task_struct *
  155. __switch_to(struct task_struct *prev, struct task_struct *next)
  156. {
  157. struct thread_struct *next_t = &next->thread;
  158. #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
  159. __stack_chk_guard = next->stack_canary;
  160. #endif
  161. unlazy_fpu(prev, task_pt_regs(prev));
  162. /* we're going to use this soon, after a few expensive things */
  163. if (next->thread.fpu_counter > 5)
  164. prefetch(next_t->xstate);
  165. #ifdef CONFIG_MMU
  166. /*
  167. * Restore the kernel mode register
  168. * k7 (r7_bank1)
  169. */
  170. asm volatile("ldc %0, r7_bank"
  171. : /* no output */
  172. : "r" (task_thread_info(next)));
  173. #endif
  174. /*
  175. * If the task has used fpu the last 5 timeslices, just do a full
  176. * restore of the math state immediately to avoid the trap; the
  177. * chances of needing FPU soon are obviously high now
  178. */
  179. if (next->thread.fpu_counter > 5)
  180. __fpu_state_restore();
  181. return prev;
  182. }
  183. unsigned long get_wchan(struct task_struct *p)
  184. {
  185. unsigned long pc;
  186. if (!p || p == current || p->state == TASK_RUNNING)
  187. return 0;
  188. /*
  189. * The same comment as on the Alpha applies here, too ...
  190. */
  191. pc = thread_saved_pc(p);
  192. #ifdef CONFIG_FRAME_POINTER
  193. if (in_sched_functions(pc)) {
  194. unsigned long schedule_frame = (unsigned long)p->thread.sp;
  195. return ((unsigned long *)schedule_frame)[21];
  196. }
  197. #endif
  198. return pc;
  199. }