process.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. 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. 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. 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. preempt_enable_no_resched();
  78. schedule();
  79. preempt_disable();
  80. }
  81. }
  82. void machine_restart(char * __unused)
  83. {
  84. local_irq_disable();
  85. __asm__("jmp @@0");
  86. }
  87. void machine_halt(void)
  88. {
  89. local_irq_disable();
  90. __asm__("sleep");
  91. for (;;);
  92. }
  93. void machine_power_off(void)
  94. {
  95. local_irq_disable();
  96. __asm__("sleep");
  97. for (;;);
  98. }
  99. void show_regs(struct pt_regs * regs)
  100. {
  101. printk("\nPC: %08lx Status: %02x",
  102. regs->pc, regs->ccr);
  103. printk("\nORIG_ER0: %08lx ER0: %08lx ER1: %08lx",
  104. regs->orig_er0, regs->er0, regs->er1);
  105. printk("\nER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx",
  106. regs->er2, regs->er3, regs->er4, regs->er5);
  107. printk("\nER6' %08lx ",regs->er6);
  108. if (user_mode(regs))
  109. printk("USP: %08lx\n", rdusp());
  110. else
  111. printk("\n");
  112. }
  113. /*
  114. * Create a kernel thread
  115. */
  116. int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
  117. {
  118. long retval;
  119. long clone_arg;
  120. mm_segment_t fs;
  121. fs = get_fs();
  122. set_fs (KERNEL_DS);
  123. clone_arg = flags | CLONE_VM;
  124. __asm__("mov.l sp,er3\n\t"
  125. "sub.l er2,er2\n\t"
  126. "mov.l %2,er1\n\t"
  127. "mov.l %1,er0\n\t"
  128. "trapa #0\n\t"
  129. "cmp.l sp,er3\n\t"
  130. "beq 1f\n\t"
  131. "mov.l %4,er0\n\t"
  132. "mov.l %3,er1\n\t"
  133. "jsr @er1\n\t"
  134. "mov.l %5,er0\n\t"
  135. "trapa #0\n"
  136. "1:\n\t"
  137. "mov.l er0,%0"
  138. :"=r"(retval)
  139. :"i"(__NR_clone),"g"(clone_arg),"g"(fn),"g"(arg),"i"(__NR_exit)
  140. :"er0","er1","er2","er3");
  141. set_fs (fs);
  142. return retval;
  143. }
  144. void flush_thread(void)
  145. {
  146. }
  147. /*
  148. * "h8300_fork()".. By the time we get here, the
  149. * non-volatile registers have also been saved on the
  150. * stack. We do some ugly pointer stuff here.. (see
  151. * also copy_thread)
  152. */
  153. asmlinkage int h8300_fork(struct pt_regs *regs)
  154. {
  155. return -EINVAL;
  156. }
  157. asmlinkage int h8300_vfork(struct pt_regs *regs)
  158. {
  159. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0, NULL, NULL);
  160. }
  161. asmlinkage int h8300_clone(struct pt_regs *regs)
  162. {
  163. unsigned long clone_flags;
  164. unsigned long newsp;
  165. /* syscall2 puts clone_flags in er1 and usp in er2 */
  166. clone_flags = regs->er1;
  167. newsp = regs->er2;
  168. if (!newsp)
  169. newsp = rdusp();
  170. return do_fork(clone_flags, newsp, regs, 0, NULL, NULL);
  171. }
  172. int copy_thread(int nr, unsigned long clone_flags,
  173. unsigned long usp, unsigned long topstk,
  174. struct task_struct * p, struct pt_regs * regs)
  175. {
  176. struct pt_regs * childregs;
  177. childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
  178. *childregs = *regs;
  179. childregs->retpc = (unsigned long) ret_from_fork;
  180. childregs->er0 = 0;
  181. p->thread.usp = usp;
  182. p->thread.ksp = (unsigned long)childregs;
  183. return 0;
  184. }
  185. /*
  186. * sys_execve() executes a new program.
  187. */
  188. asmlinkage int sys_execve(char *name, char **argv, char **envp,int dummy,...)
  189. {
  190. int error;
  191. char * filename;
  192. struct pt_regs *regs = (struct pt_regs *) ((unsigned char *)&dummy-4);
  193. lock_kernel();
  194. filename = getname(name);
  195. error = PTR_ERR(filename);
  196. if (IS_ERR(filename))
  197. goto out;
  198. error = do_execve(filename, argv, envp, regs);
  199. putname(filename);
  200. out:
  201. unlock_kernel();
  202. return error;
  203. }
  204. unsigned long thread_saved_pc(struct task_struct *tsk)
  205. {
  206. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  207. }
  208. unsigned long get_wchan(struct task_struct *p)
  209. {
  210. unsigned long fp, pc;
  211. unsigned long stack_page;
  212. int count = 0;
  213. if (!p || p == current || p->state == TASK_RUNNING)
  214. return 0;
  215. stack_page = (unsigned long)p;
  216. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  217. do {
  218. if (fp < stack_page+sizeof(struct thread_info) ||
  219. fp >= 8184+stack_page)
  220. return 0;
  221. pc = ((unsigned long *)fp)[1];
  222. if (!in_sched_functions(pc))
  223. return pc;
  224. fp = *(unsigned long *) fp;
  225. } while (count++ < 16);
  226. return 0;
  227. }