process.c 5.3 KB

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