process_32.c 5.7 KB

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