process.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/sched/debug.h>
  27. #include <linux/sched/task.h>
  28. #include <linux/sched/task_stack.h>
  29. #include <linux/kernel.h>
  30. #include <linux/mm.h>
  31. #include <linux/smp.h>
  32. #include <linux/stddef.h>
  33. #include <linux/unistd.h>
  34. #include <linux/ptrace.h>
  35. #include <linux/user.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/reboot.h>
  38. #include <linux/fs.h>
  39. #include <linux/slab.h>
  40. #include <linux/rcupdate.h>
  41. #include <linux/uaccess.h>
  42. #include <asm/traps.h>
  43. #include <asm/setup.h>
  44. #include <asm/pgtable.h>
  45. void (*pm_power_off)(void) = NULL;
  46. EXPORT_SYMBOL(pm_power_off);
  47. asmlinkage void ret_from_fork(void);
  48. asmlinkage void ret_from_kernel_thread(void);
  49. /*
  50. * The idle loop on an H8/300..
  51. */
  52. void arch_cpu_idle(void)
  53. {
  54. local_irq_enable();
  55. __asm__("sleep");
  56. }
  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. }
  69. void machine_power_off(void)
  70. {
  71. local_irq_disable();
  72. __asm__("sleep");
  73. for (;;)
  74. ;
  75. }
  76. void show_regs(struct pt_regs *regs)
  77. {
  78. show_regs_print_info(KERN_DEFAULT);
  79. pr_notice("\n");
  80. pr_notice("PC: %08lx Status: %02x\n",
  81. regs->pc, regs->ccr);
  82. pr_notice("ORIG_ER0: %08lx ER0: %08lx ER1: %08lx\n",
  83. regs->orig_er0, regs->er0, regs->er1);
  84. pr_notice("ER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx\n",
  85. regs->er2, regs->er3, regs->er4, regs->er5);
  86. pr_notice("ER6' %08lx ", regs->er6);
  87. if (user_mode(regs))
  88. printk("USP: %08lx\n", rdusp());
  89. else
  90. printk("\n");
  91. }
  92. void flush_thread(void)
  93. {
  94. }
  95. int copy_thread(unsigned long clone_flags,
  96. unsigned long usp, unsigned long topstk,
  97. struct task_struct *p)
  98. {
  99. struct pt_regs *childregs;
  100. childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
  101. if (unlikely(p->flags & PF_KTHREAD)) {
  102. memset(childregs, 0, sizeof(struct pt_regs));
  103. childregs->retpc = (unsigned long) ret_from_kernel_thread;
  104. childregs->er4 = topstk; /* arg */
  105. childregs->er5 = usp; /* fn */
  106. } else {
  107. *childregs = *current_pt_regs();
  108. childregs->er0 = 0;
  109. childregs->retpc = (unsigned long) ret_from_fork;
  110. p->thread.usp = usp ?: rdusp();
  111. }
  112. p->thread.ksp = (unsigned long)childregs;
  113. return 0;
  114. }
  115. unsigned long thread_saved_pc(struct task_struct *tsk)
  116. {
  117. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  118. }
  119. unsigned long get_wchan(struct task_struct *p)
  120. {
  121. unsigned long fp, pc;
  122. unsigned long stack_page;
  123. int count = 0;
  124. if (!p || p == current || p->state == TASK_RUNNING)
  125. return 0;
  126. stack_page = (unsigned long)p;
  127. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  128. do {
  129. if (fp < stack_page+sizeof(struct thread_info) ||
  130. fp >= 8184+stack_page)
  131. return 0;
  132. pc = ((unsigned long *)fp)[1];
  133. if (!in_sched_functions(pc))
  134. return pc;
  135. fp = *(unsigned long *) fp;
  136. } while (count++ < 16);
  137. return 0;
  138. }
  139. /* generic sys_clone is not enough registers */
  140. asmlinkage int sys_clone(unsigned long __user *args)
  141. {
  142. unsigned long clone_flags;
  143. unsigned long newsp;
  144. uintptr_t parent_tidptr;
  145. uintptr_t child_tidptr;
  146. get_user(clone_flags, &args[0]);
  147. get_user(newsp, &args[1]);
  148. get_user(parent_tidptr, &args[2]);
  149. get_user(child_tidptr, &args[3]);
  150. return do_fork(clone_flags, newsp, 0,
  151. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  152. }