process.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 <linux/rcupdate.h>
  38. #include <asm/uaccess.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. asmlinkage void ret_from_kernel_thread(void);
  46. /*
  47. * The idle loop on an H8/300..
  48. */
  49. #if !defined(CONFIG_H8300H_SIM) && !defined(CONFIG_H8S_SIM)
  50. void arch_cpu_idle(void)
  51. {
  52. local_irq_enable();
  53. /* XXX: race here! What if need_resched() gets set now? */
  54. __asm__("sleep");
  55. }
  56. #endif
  57. void machine_restart(char * __unused)
  58. {
  59. local_irq_disable();
  60. __asm__("jmp @@0");
  61. }
  62. void machine_halt(void)
  63. {
  64. local_irq_disable();
  65. __asm__("sleep");
  66. for (;;);
  67. }
  68. void machine_power_off(void)
  69. {
  70. local_irq_disable();
  71. __asm__("sleep");
  72. for (;;);
  73. }
  74. void show_regs(struct pt_regs * regs)
  75. {
  76. printk("\nPC: %08lx Status: %02x",
  77. regs->pc, regs->ccr);
  78. printk("\nORIG_ER0: %08lx ER0: %08lx ER1: %08lx",
  79. regs->orig_er0, regs->er0, regs->er1);
  80. printk("\nER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx",
  81. regs->er2, regs->er3, regs->er4, regs->er5);
  82. printk("\nER6' %08lx ",regs->er6);
  83. if (user_mode(regs))
  84. printk("USP: %08lx\n", rdusp());
  85. else
  86. printk("\n");
  87. }
  88. void flush_thread(void)
  89. {
  90. }
  91. int copy_thread(unsigned long clone_flags,
  92. unsigned long usp, unsigned long topstk,
  93. struct task_struct * p)
  94. {
  95. struct pt_regs * childregs;
  96. childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
  97. if (unlikely(p->flags & PF_KTHREAD)) {
  98. memset(childregs, 0, sizeof(struct pt_regs));
  99. childregs->retpc = (unsigned long) ret_from_kernel_thread;
  100. childregs->er4 = topstk; /* arg */
  101. childregs->er5 = usp; /* fn */
  102. p->thread.ksp = (unsigned long)childregs;
  103. }
  104. *childregs = *current_pt_regs();
  105. childregs->retpc = (unsigned long) ret_from_fork;
  106. childregs->er0 = 0;
  107. p->thread.usp = usp ?: rdusp();
  108. p->thread.ksp = (unsigned long)childregs;
  109. return 0;
  110. }
  111. unsigned long thread_saved_pc(struct task_struct *tsk)
  112. {
  113. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  114. }
  115. unsigned long get_wchan(struct task_struct *p)
  116. {
  117. unsigned long fp, pc;
  118. unsigned long stack_page;
  119. int count = 0;
  120. if (!p || p == current || p->state == TASK_RUNNING)
  121. return 0;
  122. stack_page = (unsigned long)p;
  123. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  124. do {
  125. if (fp < stack_page+sizeof(struct thread_info) ||
  126. fp >= 8184+stack_page)
  127. return 0;
  128. pc = ((unsigned long *)fp)[1];
  129. if (!in_sched_functions(pc))
  130. return pc;
  131. fp = *(unsigned long *) fp;
  132. } while (count++ < 16);
  133. return 0;
  134. }