process.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * linux/arch/m32r/kernel/process.c
  3. *
  4. * Copyright (c) 2001, 2002 Hiroyuki Kondo, Hirokazu Takata,
  5. * Hitoshi Yamamoto
  6. * Taken from sh version.
  7. * Copyright (C) 1995 Linus Torvalds
  8. * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  9. */
  10. #undef DEBUG_PROCESS
  11. #ifdef DEBUG_PROCESS
  12. #define DPRINTK(fmt, args...) printk("%s:%d:%s: " fmt, __FILE__, __LINE__, \
  13. __func__, ##args)
  14. #else
  15. #define DPRINTK(fmt, args...)
  16. #endif
  17. /*
  18. * This file handles the architecture-dependent parts of process handling..
  19. */
  20. #include <linux/fs.h>
  21. #include <linux/slab.h>
  22. #include <linux/module.h>
  23. #include <linux/ptrace.h>
  24. #include <linux/unistd.h>
  25. #include <linux/hardirq.h>
  26. #include <linux/rcupdate.h>
  27. #include <asm/io.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/mmu_context.h>
  30. #include <asm/elf.h>
  31. #include <asm/m32r.h>
  32. #include <linux/err.h>
  33. /*
  34. * Return saved PC of a blocked thread.
  35. */
  36. unsigned long thread_saved_pc(struct task_struct *tsk)
  37. {
  38. return tsk->thread.lr;
  39. }
  40. /*
  41. * Powermanagement idle function, if any..
  42. */
  43. static void (*pm_idle)(void) = NULL;
  44. void (*pm_power_off)(void) = NULL;
  45. EXPORT_SYMBOL(pm_power_off);
  46. /*
  47. * We use this is we don't have any better
  48. * idle routine..
  49. */
  50. static void default_idle(void)
  51. {
  52. /* M32R_FIXME: Please use "cpu_sleep" mode. */
  53. cpu_relax();
  54. }
  55. /*
  56. * On SMP it's slightly faster (but much more power-consuming!)
  57. * to poll the ->work.need_resched flag instead of waiting for the
  58. * cross-CPU IPI to arrive. Use this option with caution.
  59. */
  60. static void poll_idle (void)
  61. {
  62. /* M32R_FIXME */
  63. cpu_relax();
  64. }
  65. /*
  66. * The idle thread. There's no useful work to be
  67. * done, so just try to conserve power and have a
  68. * low exit latency (ie sit in a loop waiting for
  69. * somebody to say that they'd like to reschedule)
  70. */
  71. void cpu_idle (void)
  72. {
  73. /* endless idle loop with no priority at all */
  74. while (1) {
  75. rcu_idle_enter();
  76. while (!need_resched()) {
  77. void (*idle)(void) = pm_idle;
  78. if (!idle)
  79. idle = default_idle;
  80. idle();
  81. }
  82. rcu_idle_exit();
  83. schedule_preempt_disabled();
  84. }
  85. }
  86. void machine_restart(char *__unused)
  87. {
  88. #if defined(CONFIG_PLAT_MAPPI3)
  89. outw(1, (unsigned long)PLD_REBOOT);
  90. #endif
  91. printk("Please push reset button!\n");
  92. while (1)
  93. cpu_relax();
  94. }
  95. void machine_halt(void)
  96. {
  97. printk("Please push reset button!\n");
  98. while (1)
  99. cpu_relax();
  100. }
  101. void machine_power_off(void)
  102. {
  103. /* M32R_FIXME */
  104. }
  105. static int __init idle_setup (char *str)
  106. {
  107. if (!strncmp(str, "poll", 4)) {
  108. printk("using poll in idle threads.\n");
  109. pm_idle = poll_idle;
  110. } else if (!strncmp(str, "sleep", 4)) {
  111. printk("using sleep in idle threads.\n");
  112. pm_idle = default_idle;
  113. }
  114. return 1;
  115. }
  116. __setup("idle=", idle_setup);
  117. void show_regs(struct pt_regs * regs)
  118. {
  119. printk("\n");
  120. printk("BPC[%08lx]:PSW[%08lx]:LR [%08lx]:FP [%08lx]\n", \
  121. regs->bpc, regs->psw, regs->lr, regs->fp);
  122. printk("BBPC[%08lx]:BBPSW[%08lx]:SPU[%08lx]:SPI[%08lx]\n", \
  123. regs->bbpc, regs->bbpsw, regs->spu, regs->spi);
  124. printk("R0 [%08lx]:R1 [%08lx]:R2 [%08lx]:R3 [%08lx]\n", \
  125. regs->r0, regs->r1, regs->r2, regs->r3);
  126. printk("R4 [%08lx]:R5 [%08lx]:R6 [%08lx]:R7 [%08lx]\n", \
  127. regs->r4, regs->r5, regs->r6, regs->r7);
  128. printk("R8 [%08lx]:R9 [%08lx]:R10[%08lx]:R11[%08lx]\n", \
  129. regs->r8, regs->r9, regs->r10, regs->r11);
  130. printk("R12[%08lx]\n", \
  131. regs->r12);
  132. #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  133. printk("ACC0H[%08lx]:ACC0L[%08lx]\n", \
  134. regs->acc0h, regs->acc0l);
  135. printk("ACC1H[%08lx]:ACC1L[%08lx]\n", \
  136. regs->acc1h, regs->acc1l);
  137. #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  138. printk("ACCH[%08lx]:ACCL[%08lx]\n", \
  139. regs->acc0h, regs->acc0l);
  140. #else
  141. #error unknown isa configuration
  142. #endif
  143. }
  144. /*
  145. * Free current thread data structures etc..
  146. */
  147. void exit_thread(void)
  148. {
  149. /* Nothing to do. */
  150. DPRINTK("pid = %d\n", current->pid);
  151. }
  152. void flush_thread(void)
  153. {
  154. DPRINTK("pid = %d\n", current->pid);
  155. memset(&current->thread.debug_trap, 0, sizeof(struct debug_trap));
  156. }
  157. void release_thread(struct task_struct *dead_task)
  158. {
  159. /* do nothing */
  160. DPRINTK("pid = %d\n", dead_task->pid);
  161. }
  162. /* Fill in the fpu structure for a core dump.. */
  163. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  164. {
  165. return 0; /* Task didn't use the fpu at all. */
  166. }
  167. int copy_thread(unsigned long clone_flags, unsigned long spu,
  168. unsigned long arg, struct task_struct *tsk, struct pt_regs *regs)
  169. {
  170. struct pt_regs *childregs = task_pt_regs(tsk);
  171. extern void ret_from_fork(void);
  172. extern void ret_from_kernel_thread(void);
  173. if (unlikely(tsk->flags & PF_KTHREAD)) {
  174. memset(childregs, 0, sizeof(struct pt_regs));
  175. childregs->psw = M32R_PSW_BIE;
  176. childregs->r1 = spu; /* fn */
  177. childregs->r0 = arg;
  178. tsk->thread.lr = (unsigned long)ret_from_kernel_thread;
  179. } else {
  180. /* Copy registers */
  181. *childregs = *regs;
  182. childregs->spu = spu;
  183. childregs->r0 = 0; /* Child gets zero as return value */
  184. tsk->thread.lr = (unsigned long)ret_from_fork;
  185. }
  186. tsk->thread.sp = (unsigned long)childregs;
  187. return 0;
  188. }
  189. asmlinkage int sys_fork(void)
  190. {
  191. #ifdef CONFIG_MMU
  192. struct pt_regs *regs = current_pt_regs();
  193. return do_fork(SIGCHLD, regs->spu, regs, 0, NULL, NULL);
  194. #else
  195. return -EINVAL;
  196. #endif /* CONFIG_MMU */
  197. }
  198. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  199. unsigned long parent_tidptr,
  200. unsigned long child_tidptr)
  201. {
  202. struct pt_regs *regs = current_pt_regs();
  203. if (!newsp)
  204. newsp = regs->spu;
  205. return do_fork(clone_flags, newsp, regs, 0,
  206. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  207. }
  208. /*
  209. * This is trivial, and on the face of it looks like it
  210. * could equally well be done in user mode.
  211. *
  212. * Not so, for quite unobvious reasons - register pressure.
  213. * In user mode vfork() cannot have a stack frame, and if
  214. * done by calling the "clone()" system call directly, you
  215. * do not have enough call-clobbered registers to hold all
  216. * the information you need.
  217. */
  218. asmlinkage int sys_vfork(void)
  219. {
  220. struct pt_regs *regs = current_pt_regs();
  221. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->spu, regs, 0,
  222. NULL, NULL);
  223. }
  224. /*
  225. * These bracket the sleeping functions..
  226. */
  227. #define first_sched ((unsigned long) scheduling_functions_start_here)
  228. #define last_sched ((unsigned long) scheduling_functions_end_here)
  229. unsigned long get_wchan(struct task_struct *p)
  230. {
  231. /* M32R_FIXME */
  232. return (0);
  233. }