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