process.c 5.3 KB

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