process.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. void arch_cpu_idle(void)
  50. {
  51. local_irq_enable();
  52. __asm__("sleep");
  53. }
  54. void machine_restart(char *__unused)
  55. {
  56. local_irq_disable();
  57. __asm__("jmp @@0");
  58. }
  59. void machine_halt(void)
  60. {
  61. local_irq_disable();
  62. __asm__("sleep");
  63. for (;;)
  64. ;
  65. }
  66. void machine_power_off(void)
  67. {
  68. local_irq_disable();
  69. __asm__("sleep");
  70. for (;;)
  71. ;
  72. }
  73. void show_regs(struct pt_regs *regs)
  74. {
  75. show_regs_print_info(KERN_DEFAULT);
  76. pr_notice("\n");
  77. pr_notice("PC: %08lx Status: %02x\n",
  78. regs->pc, regs->ccr);
  79. pr_notice("ORIG_ER0: %08lx ER0: %08lx ER1: %08lx\n",
  80. regs->orig_er0, regs->er0, regs->er1);
  81. pr_notice("ER2: %08lx ER3: %08lx ER4: %08lx ER5: %08lx\n",
  82. regs->er2, regs->er3, regs->er4, regs->er5);
  83. pr_notice("ER6' %08lx ", regs->er6);
  84. if (user_mode(regs))
  85. printk("USP: %08lx\n", rdusp());
  86. else
  87. printk("\n");
  88. }
  89. void flush_thread(void)
  90. {
  91. }
  92. int copy_thread(unsigned long clone_flags,
  93. unsigned long usp, unsigned long topstk,
  94. struct task_struct *p)
  95. {
  96. struct pt_regs *childregs;
  97. childregs = (struct pt_regs *) (THREAD_SIZE + task_stack_page(p)) - 1;
  98. if (unlikely(p->flags & PF_KTHREAD)) {
  99. memset(childregs, 0, sizeof(struct pt_regs));
  100. childregs->retpc = (unsigned long) ret_from_kernel_thread;
  101. childregs->er4 = topstk; /* arg */
  102. childregs->er5 = usp; /* fn */
  103. } else {
  104. *childregs = *current_pt_regs();
  105. childregs->er0 = 0;
  106. childregs->retpc = (unsigned long) ret_from_fork;
  107. p->thread.usp = usp ?: rdusp();
  108. }
  109. p->thread.ksp = (unsigned long)childregs;
  110. return 0;
  111. }
  112. unsigned long thread_saved_pc(struct task_struct *tsk)
  113. {
  114. return ((struct pt_regs *)tsk->thread.esp0)->pc;
  115. }
  116. unsigned long get_wchan(struct task_struct *p)
  117. {
  118. unsigned long fp, pc;
  119. unsigned long stack_page;
  120. int count = 0;
  121. if (!p || p == current || p->state == TASK_RUNNING)
  122. return 0;
  123. stack_page = (unsigned long)p;
  124. fp = ((struct pt_regs *)p->thread.ksp)->er6;
  125. do {
  126. if (fp < stack_page+sizeof(struct thread_info) ||
  127. fp >= 8184+stack_page)
  128. return 0;
  129. pc = ((unsigned long *)fp)[1];
  130. if (!in_sched_functions(pc))
  131. return pc;
  132. fp = *(unsigned long *) fp;
  133. } while (count++ < 16);
  134. return 0;
  135. }
  136. /* generic sys_clone is not enough registers */
  137. asmlinkage int sys_clone(unsigned long __user *args)
  138. {
  139. unsigned long clone_flags;
  140. unsigned long newsp;
  141. uintptr_t parent_tidptr;
  142. uintptr_t child_tidptr;
  143. get_user(clone_flags, &args[0]);
  144. get_user(newsp, &args[1]);
  145. get_user(parent_tidptr, &args[2]);
  146. get_user(child_tidptr, &args[3]);
  147. return do_fork(clone_flags, newsp, 0,
  148. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  149. }