process.c 5.3 KB

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