process_32.c 5.8 KB

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