process.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * linux/arch/m68k/kernel/process.c
  3. *
  4. * Copyright (C) 1995 Hamish Macdonald
  5. *
  6. * 68060 fixes by Jesper Skov
  7. */
  8. /*
  9. * This file handles the architecture-dependent parts of process handling..
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/module.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/slab.h>
  17. #include <linux/fs.h>
  18. #include <linux/smp.h>
  19. #include <linux/stddef.h>
  20. #include <linux/unistd.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/user.h>
  23. #include <linux/reboot.h>
  24. #include <linux/init_task.h>
  25. #include <linux/mqueue.h>
  26. #include <linux/rcupdate.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/traps.h>
  29. #include <asm/machdep.h>
  30. #include <asm/setup.h>
  31. #include <asm/pgtable.h>
  32. asmlinkage void ret_from_fork(void);
  33. asmlinkage void ret_from_kernel_thread(void);
  34. /*
  35. * Return saved PC from a blocked thread
  36. */
  37. unsigned long thread_saved_pc(struct task_struct *tsk)
  38. {
  39. struct switch_stack *sw = (struct switch_stack *)tsk->thread.ksp;
  40. /* Check whether the thread is blocked in resume() */
  41. if (in_sched_functions(sw->retpc))
  42. return ((unsigned long *)sw->a6)[1];
  43. else
  44. return sw->retpc;
  45. }
  46. void arch_cpu_idle(void)
  47. {
  48. #if defined(MACH_ATARI_ONLY)
  49. /* block out HSYNC on the atari (falcon) */
  50. __asm__("stop #0x2200" : : : "cc");
  51. #else
  52. __asm__("stop #0x2000" : : : "cc");
  53. #endif
  54. }
  55. void machine_restart(char * __unused)
  56. {
  57. if (mach_reset)
  58. mach_reset();
  59. for (;;);
  60. }
  61. void machine_halt(void)
  62. {
  63. if (mach_halt)
  64. mach_halt();
  65. for (;;);
  66. }
  67. void machine_power_off(void)
  68. {
  69. if (mach_power_off)
  70. mach_power_off();
  71. for (;;);
  72. }
  73. void (*pm_power_off)(void) = machine_power_off;
  74. EXPORT_SYMBOL(pm_power_off);
  75. void show_regs(struct pt_regs * regs)
  76. {
  77. printk("\n");
  78. printk("Format %02x Vector: %04x PC: %08lx Status: %04x %s\n",
  79. regs->format, regs->vector, regs->pc, regs->sr, print_tainted());
  80. printk("ORIG_D0: %08lx D0: %08lx A2: %08lx A1: %08lx\n",
  81. regs->orig_d0, regs->d0, regs->a2, regs->a1);
  82. printk("A0: %08lx D5: %08lx D4: %08lx\n",
  83. regs->a0, regs->d5, regs->d4);
  84. printk("D3: %08lx D2: %08lx D1: %08lx\n",
  85. regs->d3, regs->d2, regs->d1);
  86. if (!(regs->sr & PS_S))
  87. printk("USP: %08lx\n", rdusp());
  88. }
  89. void flush_thread(void)
  90. {
  91. current->thread.fs = __USER_DS;
  92. #ifdef CONFIG_FPU
  93. if (!FPU_IS_EMU) {
  94. unsigned long zero = 0;
  95. asm volatile("frestore %0": :"m" (zero));
  96. }
  97. #endif
  98. }
  99. /*
  100. * Why not generic sys_clone, you ask? m68k passes all arguments on stack.
  101. * And we need all registers saved, which means a bunch of stuff pushed
  102. * on top of pt_regs, which means that sys_clone() arguments would be
  103. * buried. We could, of course, copy them, but it's too costly for no
  104. * good reason - generic clone() would have to copy them *again* for
  105. * do_fork() anyway. So in this case it's actually better to pass pt_regs *
  106. * and extract arguments for do_fork() from there. Eventually we might
  107. * go for calling do_fork() directly from the wrapper, but only after we
  108. * are finished with do_fork() prototype conversion.
  109. */
  110. asmlinkage int m68k_clone(struct pt_regs *regs)
  111. {
  112. /* regs will be equal to current_pt_regs() */
  113. return do_fork(regs->d1, regs->d2, 0,
  114. (int __user *)regs->d3, (int __user *)regs->d4);
  115. }
  116. int copy_thread(unsigned long clone_flags, unsigned long usp,
  117. unsigned long arg, struct task_struct *p)
  118. {
  119. struct fork_frame {
  120. struct switch_stack sw;
  121. struct pt_regs regs;
  122. } *frame;
  123. frame = (struct fork_frame *) (task_stack_page(p) + THREAD_SIZE) - 1;
  124. p->thread.ksp = (unsigned long)frame;
  125. p->thread.esp0 = (unsigned long)&frame->regs;
  126. /*
  127. * Must save the current SFC/DFC value, NOT the value when
  128. * the parent was last descheduled - RGH 10-08-96
  129. */
  130. p->thread.fs = get_fs().seg;
  131. if (unlikely(p->flags & PF_KTHREAD)) {
  132. /* kernel thread */
  133. memset(frame, 0, sizeof(struct fork_frame));
  134. frame->regs.sr = PS_S;
  135. frame->sw.a3 = usp; /* function */
  136. frame->sw.d7 = arg;
  137. frame->sw.retpc = (unsigned long)ret_from_kernel_thread;
  138. p->thread.usp = 0;
  139. return 0;
  140. }
  141. memcpy(frame, container_of(current_pt_regs(), struct fork_frame, regs),
  142. sizeof(struct fork_frame));
  143. frame->regs.d0 = 0;
  144. frame->sw.retpc = (unsigned long)ret_from_fork;
  145. p->thread.usp = usp ?: rdusp();
  146. if (clone_flags & CLONE_SETTLS)
  147. task_thread_info(p)->tp_value = frame->regs.d5;
  148. #ifdef CONFIG_FPU
  149. if (!FPU_IS_EMU) {
  150. /* Copy the current fpu state */
  151. asm volatile ("fsave %0" : : "m" (p->thread.fpstate[0]) : "memory");
  152. if (!CPU_IS_060 ? p->thread.fpstate[0] : p->thread.fpstate[2]) {
  153. if (CPU_IS_COLDFIRE) {
  154. asm volatile ("fmovemd %/fp0-%/fp7,%0\n\t"
  155. "fmovel %/fpiar,%1\n\t"
  156. "fmovel %/fpcr,%2\n\t"
  157. "fmovel %/fpsr,%3"
  158. :
  159. : "m" (p->thread.fp[0]),
  160. "m" (p->thread.fpcntl[0]),
  161. "m" (p->thread.fpcntl[1]),
  162. "m" (p->thread.fpcntl[2])
  163. : "memory");
  164. } else {
  165. asm volatile ("fmovemx %/fp0-%/fp7,%0\n\t"
  166. "fmoveml %/fpiar/%/fpcr/%/fpsr,%1"
  167. :
  168. : "m" (p->thread.fp[0]),
  169. "m" (p->thread.fpcntl[0])
  170. : "memory");
  171. }
  172. }
  173. /* Restore the state in case the fpu was busy */
  174. asm volatile ("frestore %0" : : "m" (p->thread.fpstate[0]));
  175. }
  176. #endif /* CONFIG_FPU */
  177. return 0;
  178. }
  179. /* Fill in the fpu structure for a core dump. */
  180. #ifdef CONFIG_FPU
  181. int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
  182. {
  183. char fpustate[216];
  184. if (FPU_IS_EMU) {
  185. int i;
  186. memcpy(fpu->fpcntl, current->thread.fpcntl, 12);
  187. memcpy(fpu->fpregs, current->thread.fp, 96);
  188. /* Convert internal fpu reg representation
  189. * into long double format
  190. */
  191. for (i = 0; i < 24; i += 3)
  192. fpu->fpregs[i] = ((fpu->fpregs[i] & 0xffff0000) << 15) |
  193. ((fpu->fpregs[i] & 0x0000ffff) << 16);
  194. return 1;
  195. }
  196. /* First dump the fpu context to avoid protocol violation. */
  197. asm volatile ("fsave %0" :: "m" (fpustate[0]) : "memory");
  198. if (!CPU_IS_060 ? !fpustate[0] : !fpustate[2])
  199. return 0;
  200. if (CPU_IS_COLDFIRE) {
  201. asm volatile ("fmovel %/fpiar,%0\n\t"
  202. "fmovel %/fpcr,%1\n\t"
  203. "fmovel %/fpsr,%2\n\t"
  204. "fmovemd %/fp0-%/fp7,%3"
  205. :
  206. : "m" (fpu->fpcntl[0]),
  207. "m" (fpu->fpcntl[1]),
  208. "m" (fpu->fpcntl[2]),
  209. "m" (fpu->fpregs[0])
  210. : "memory");
  211. } else {
  212. asm volatile ("fmovem %/fpiar/%/fpcr/%/fpsr,%0"
  213. :
  214. : "m" (fpu->fpcntl[0])
  215. : "memory");
  216. asm volatile ("fmovemx %/fp0-%/fp7,%0"
  217. :
  218. : "m" (fpu->fpregs[0])
  219. : "memory");
  220. }
  221. return 1;
  222. }
  223. EXPORT_SYMBOL(dump_fpu);
  224. #endif /* CONFIG_FPU */
  225. unsigned long get_wchan(struct task_struct *p)
  226. {
  227. unsigned long fp, pc;
  228. unsigned long stack_page;
  229. int count = 0;
  230. if (!p || p == current || p->state == TASK_RUNNING)
  231. return 0;
  232. stack_page = (unsigned long)task_stack_page(p);
  233. fp = ((struct switch_stack *)p->thread.ksp)->a6;
  234. do {
  235. if (fp < stack_page+sizeof(struct thread_info) ||
  236. fp >= 8184+stack_page)
  237. return 0;
  238. pc = ((unsigned long *)fp)[1];
  239. if (!in_sched_functions(pc))
  240. return pc;
  241. fp = *(unsigned long *) fp;
  242. } while (count++ < 16);
  243. return 0;
  244. }