process.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * linux/arch/h8300/kernel/process.c
  3. *
  4. * Yoshinori Sato <ysato@users.sourceforge.jp>
  5. *
  6. * Based on:
  7. *
  8. * linux/arch/m68knommu/kernel/process.c
  9. *
  10. * Copyright (C) 1998 D. Jeff Dionne <jeff@ryeham.ee.ryerson.ca>,
  11. * Kenneth Albanowski <kjahds@kjahds.com>,
  12. * The Silver Hammer Group, Ltd.
  13. *
  14. * linux/arch/m68k/kernel/process.c
  15. *
  16. * Copyright (C) 1995 Hamish Macdonald
  17. *
  18. * 68060 fixes by Jesper Skov
  19. */
  20. /*
  21. * This file handles the architecture-dependent parts of process handling..
  22. */
  23. #include <linux/errno.h>
  24. #include <linux/module.h>
  25. #include <linux/sched.h>
  26. #include <linux/kernel.h>
  27. #include <linux/mm.h>
  28. #include <linux/smp.h>
  29. #include <linux/stddef.h>
  30. #include <linux/unistd.h>
  31. #include <linux/ptrace.h>
  32. #include <linux/user.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/reboot.h>
  35. #include <linux/fs.h>
  36. #include <linux/slab.h>
  37. #include <asm/uaccess.h>
  38. #include <asm/traps.h>
  39. #include <asm/setup.h>
  40. #include <asm/pgtable.h>
  41. void (*pm_power_off)(void) = NULL;
  42. EXPORT_SYMBOL(pm_power_off);
  43. asmlinkage void ret_from_fork(void);
  44. /*
  45. * The idle loop on an H8/300..
  46. */
  47. #if !defined(CONFIG_H8300H_SIM) && !defined(CONFIG_H8S_SIM)
  48. static void default_idle(void)
  49. {
  50. local_irq_disable();
  51. if (!need_resched()) {
  52. local_irq_enable();
  53. /* XXX: race here! What if need_resched() gets set now? */
  54. __asm__("sleep");
  55. } else
  56. local_irq_enable();
  57. }
  58. #else
  59. static void default_idle(void)
  60. {
  61. cpu_relax();
  62. }
  63. #endif
  64. void (*idle)(void) = default_idle;
  65. /*
  66. * The idle thread. There's no useful work to be
  67. * done, so just try to conserve power and have a
  68. * low exit latency (ie sit in a loop waiting for
  69. * somebody to say that they'd like to reschedule)
  70. */
  71. void cpu_idle(void)
  72. {
  73. while (1) {
  74. while (!need_resched())
  75. idle();
  76. schedule_preempt_disabled();
  77. }
  78. }
  79. void machine_restart(char * __unused)
  80. {
  81. local_irq_disable();
  82. __asm__("jmp @@0");
  83. }
  84. void machine_halt(void)
  85. {
  86. local_irq_disable();
  87. __asm__("sleep");
  88. for (;;);
  89. }
  90. void machine_power_off(void)
  91. {
  92. local_irq_disable();
  93. __asm__("sleep");
  94. for (;;);
  95. }
  96. void show_regs(struct pt_regs * regs)
  97. {
  98. printk("\nPC: %08lx Status: %02x",
  99. regs->pc, regs->ccr);
  100. printk("\nORIG_ER0: %08lx ER0: %08lx ER1: %08lx",
  101. regs->orig_er0, regs->er0, regs->er1);
  102. printk("\nER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx",
  103. regs->er2, regs->er3, regs->er4, regs->er5);
  104. printk("\nER6' %08lx ",regs->er6);
  105. if (user_mode(regs))
  106. printk("USP: %08lx\n", rdusp());
  107. else
  108. printk("\n");
  109. }
  110. /*
  111. * Create a kernel thread
  112. */
  113. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  114. {
  115. long retval;
  116. long clone_arg;
  117. mm_segment_t fs;
  118. fs = get_fs();
  119. set_fs (KERNEL_DS);
  120. clone_arg = flags | CLONE_VM;
  121. __asm__("mov.l sp,er3\n\t"
  122. "sub.l er2,er2\n\t"
  123. "mov.l %2,er1\n\t"
  124. "mov.l %1,er0\n\t"
  125. "trapa #0\n\t"
  126. "cmp.l sp,er3\n\t"
  127. "beq 1f\n\t"
  128. "mov.l %4,er0\n\t"
  129. "mov.l %3,er1\n\t"
  130. "jsr @er1\n\t"
  131. "mov.l %5,er0\n\t"
  132. "trapa #0\n"
  133. "1:\n\t"
  134. "mov.l er0,%0"
  135. :"=r"(retval)
  136. :"i"(__NR_clone),"g"(clone_arg),"g"(fn),"g"(arg),"i"(__NR_exit)
  137. :"er0","er1","er2","er3");
  138. set_fs (fs);
  139. return retval;
  140. }
  141. void flush_thread(void)
  142. {
  143. }
  144. /*
  145. * "h8300_fork()".. By the time we get here, the
  146. * non-volatile registers have also been saved on the
  147. * stack. We do some ugly pointer stuff here.. (see
  148. * also copy_thread)
  149. */
  150. asmlinkage int h8300_fork(struct pt_regs *regs)
  151. {
  152. return -EINVAL;
  153. }
  154. asmlinkage int h8300_vfork(struct pt_regs *regs)
  155. {
  156. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
  157. }
  158. asmlinkage int h8300_clone(struct pt_regs *regs)
  159. {
  160. unsigned long clone_flags;
  161. unsigned long newsp;
  162. /* syscall2 puts clone_flags in er1 and usp in er2 */
  163. clone_flags = regs->er1;
  164. newsp = regs->er2;
  165. if (!newsp)
  166. newsp = rdusp();
  167. return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
  168. }
  169. int copy_thread(unsigned long clone_flags,
  170. unsigned long usp, unsigned long topstk,
  171. struct task_struct * p, struct pt_regs * regs)
  172. {
  173. struct pt_regs * childregs;
  174. childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
  175. *childregs = *regs;
  176. childregs->retpc = (unsigned long) ret_from_fork;
  177. childregs->er0 = 0;
  178. p->thread.usp = usp;
  179. p->thread.ksp = (unsigned long)childregs;
  180. return 0;
  181. }
  182. /*
  183. * sys_execve() executes a new program.
  184. */
  185. asmlinkage int sys_execve(const char *name,
  186. const char *const *argv,
  187. const char *const *envp,
  188. int dummy, ...)
  189. {
  190. int error;
  191. char * filename;
  192. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  193. filename = getname(name);
  194. error = PTR_ERR(filename);
  195. if (IS_ERR(filename))
  196. return error;
  197. error = do_execve(filename, argv, envp, regs);
  198. putname(filename);
  199. return error;
  200. }
  201. unsigned long thread_saved_pc(struct task_struct *tsk)
  202. {
  203. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  204. }
  205. unsigned long get_wchan(struct task_struct *p)
  206. {
  207. unsigned long fp, pc;
  208. unsigned long stack_page;
  209. int count = 0;
  210. if (!p || p == current || p->state == TASK_RUNNING)
  211. return 0;
  212. stack_page = (unsigned long)p;
  213. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  214. do {
  215. if (fp < stack_page+sizeof(struct thread_info) ||
  216. fp >= 8184+stack_page)
  217. return 0;
  218. pc = ((unsigned long *)fp)[1];
  219. if (!in_sched_functions(pc))
  220. return pc;
  221. fp = *(unsigned long *) fp;
  222. } while (count++ < 16);
  223. return 0;
  224. }