process.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. * Create a kernel thread
  146. */
  147. /*
  148. * This is the mechanism for creating a new kernel thread.
  149. *
  150. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  151. * who haven't done an "execve()") should use this: it will work within
  152. * a system call from a "real" process, but the process memory space will
  153. * not be free'd until both the parent and the child have exited.
  154. */
  155. static void kernel_thread_helper(void *nouse, int (*fn)(void *), void *arg)
  156. {
  157. fn(arg);
  158. do_exit(-1);
  159. }
  160. int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
  161. {
  162. struct pt_regs regs;
  163. memset(&regs, 0, sizeof (regs));
  164. regs.r1 = (unsigned long)fn;
  165. regs.r2 = (unsigned long)arg;
  166. regs.bpc = (unsigned long)kernel_thread_helper;
  167. regs.psw = M32R_PSW_BIE;
  168. /* Ok, create the new process. */
  169. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
  170. NULL);
  171. }
  172. /*
  173. * Free current thread data structures etc..
  174. */
  175. void exit_thread(void)
  176. {
  177. /* Nothing to do. */
  178. DPRINTK("pid = %d\n", current->pid);
  179. }
  180. void flush_thread(void)
  181. {
  182. DPRINTK("pid = %d\n", current->pid);
  183. memset(&current->thread.debug_trap, 0, sizeof(struct debug_trap));
  184. }
  185. void release_thread(struct task_struct *dead_task)
  186. {
  187. /* do nothing */
  188. DPRINTK("pid = %d\n", dead_task->pid);
  189. }
  190. /* Fill in the fpu structure for a core dump.. */
  191. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  192. {
  193. return 0; /* Task didn't use the fpu at all. */
  194. }
  195. int copy_thread(unsigned long clone_flags, unsigned long spu,
  196. unsigned long unused, struct task_struct *tsk, struct pt_regs *regs)
  197. {
  198. struct pt_regs *childregs = task_pt_regs(tsk);
  199. extern void ret_from_fork(void);
  200. /* Copy registers */
  201. *childregs = *regs;
  202. childregs->spu = spu;
  203. childregs->r0 = 0; /* Child gets zero as return value */
  204. regs->r0 = tsk->pid;
  205. tsk->thread.sp = (unsigned long)childregs;
  206. tsk->thread.lr = (unsigned long)ret_from_fork;
  207. return 0;
  208. }
  209. asmlinkage int sys_fork(unsigned long r0, unsigned long r1, unsigned long r2,
  210. unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
  211. struct pt_regs regs)
  212. {
  213. #ifdef CONFIG_MMU
  214. return do_fork(SIGCHLD, regs.spu, &regs, 0, NULL, NULL);
  215. #else
  216. return -EINVAL;
  217. #endif /* CONFIG_MMU */
  218. }
  219. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  220. unsigned long parent_tidptr,
  221. unsigned long child_tidptr,
  222. unsigned long r4, unsigned long r5, unsigned long r6,
  223. struct pt_regs regs)
  224. {
  225. if (!newsp)
  226. newsp = regs.spu;
  227. return do_fork(clone_flags, newsp, &regs, 0,
  228. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  229. }
  230. /*
  231. * This is trivial, and on the face of it looks like it
  232. * could equally well be done in user mode.
  233. *
  234. * Not so, for quite unobvious reasons - register pressure.
  235. * In user mode vfork() cannot have a stack frame, and if
  236. * done by calling the "clone()" system call directly, you
  237. * do not have enough call-clobbered registers to hold all
  238. * the information you need.
  239. */
  240. asmlinkage int sys_vfork(unsigned long r0, unsigned long r1, unsigned long r2,
  241. unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
  242. struct pt_regs regs)
  243. {
  244. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.spu, &regs, 0,
  245. NULL, NULL);
  246. }
  247. /*
  248. * sys_execve() executes a new program.
  249. */
  250. asmlinkage int sys_execve(const char __user *ufilename,
  251. const char __user *const __user *uargv,
  252. const char __user *const __user *uenvp,
  253. unsigned long r3, unsigned long r4, unsigned long r5,
  254. unsigned long r6, struct pt_regs regs)
  255. {
  256. int error;
  257. char *filename;
  258. filename = getname(ufilename);
  259. error = PTR_ERR(filename);
  260. if (IS_ERR(filename))
  261. goto out;
  262. error = do_execve(filename, uargv, uenvp, &regs);
  263. putname(filename);
  264. out:
  265. return error;
  266. }
  267. /*
  268. * These bracket the sleeping functions..
  269. */
  270. #define first_sched ((unsigned long) scheduling_functions_start_here)
  271. #define last_sched ((unsigned long) scheduling_functions_end_here)
  272. unsigned long get_wchan(struct task_struct *p)
  273. {
  274. /* M32R_FIXME */
  275. return (0);
  276. }