process.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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/module.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/unistd.h>
  24. #include <linux/slab.h>
  25. #include <linux/hardirq.h>
  26. #include <asm/io.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/elf.h>
  30. #include <asm/m32r.h>
  31. #include <linux/err.h>
  32. /*
  33. * Return saved PC of a blocked thread.
  34. */
  35. unsigned long thread_saved_pc(struct task_struct *tsk)
  36. {
  37. return tsk->thread.lr;
  38. }
  39. /*
  40. * Powermanagement idle function, if any..
  41. */
  42. static void (*pm_idle)(void) = NULL;
  43. void (*pm_power_off)(void) = NULL;
  44. EXPORT_SYMBOL(pm_power_off);
  45. /*
  46. * We use this is we don't have any better
  47. * idle routine..
  48. */
  49. static void default_idle(void)
  50. {
  51. /* M32R_FIXME: Please use "cpu_sleep" mode. */
  52. cpu_relax();
  53. }
  54. /*
  55. * On SMP it's slightly faster (but much more power-consuming!)
  56. * to poll the ->work.need_resched flag instead of waiting for the
  57. * cross-CPU IPI to arrive. Use this option with caution.
  58. */
  59. static void poll_idle (void)
  60. {
  61. /* M32R_FIXME */
  62. cpu_relax();
  63. }
  64. /*
  65. * The idle thread. There's no useful work to be
  66. * done, so just try to conserve power and have a
  67. * low exit latency (ie sit in a loop waiting for
  68. * somebody to say that they'd like to reschedule)
  69. */
  70. void cpu_idle (void)
  71. {
  72. /* endless idle loop with no priority at all */
  73. while (1) {
  74. while (!need_resched()) {
  75. void (*idle)(void) = pm_idle;
  76. if (!idle)
  77. idle = default_idle;
  78. idle();
  79. }
  80. preempt_enable_no_resched();
  81. schedule();
  82. preempt_disable();
  83. }
  84. }
  85. void machine_restart(char *__unused)
  86. {
  87. #if defined(CONFIG_PLAT_MAPPI3)
  88. outw(1, (unsigned long)PLD_REBOOT);
  89. #endif
  90. printk("Please push reset button!\n");
  91. while (1)
  92. cpu_relax();
  93. }
  94. void machine_halt(void)
  95. {
  96. printk("Please push reset button!\n");
  97. while (1)
  98. cpu_relax();
  99. }
  100. void machine_power_off(void)
  101. {
  102. /* M32R_FIXME */
  103. }
  104. static int __init idle_setup (char *str)
  105. {
  106. if (!strncmp(str, "poll", 4)) {
  107. printk("using poll in idle threads.\n");
  108. pm_idle = poll_idle;
  109. } else if (!strncmp(str, "sleep", 4)) {
  110. printk("using sleep in idle threads.\n");
  111. pm_idle = default_idle;
  112. }
  113. return 1;
  114. }
  115. __setup("idle=", idle_setup);
  116. void show_regs(struct pt_regs * regs)
  117. {
  118. printk("\n");
  119. printk("BPC[%08lx]:PSW[%08lx]:LR [%08lx]:FP [%08lx]\n", \
  120. regs->bpc, regs->psw, regs->lr, regs->fp);
  121. printk("BBPC[%08lx]:BBPSW[%08lx]:SPU[%08lx]:SPI[%08lx]\n", \
  122. regs->bbpc, regs->bbpsw, regs->spu, regs->spi);
  123. printk("R0 [%08lx]:R1 [%08lx]:R2 [%08lx]:R3 [%08lx]\n", \
  124. regs->r0, regs->r1, regs->r2, regs->r3);
  125. printk("R4 [%08lx]:R5 [%08lx]:R6 [%08lx]:R7 [%08lx]\n", \
  126. regs->r4, regs->r5, regs->r6, regs->r7);
  127. printk("R8 [%08lx]:R9 [%08lx]:R10[%08lx]:R11[%08lx]\n", \
  128. regs->r8, regs->r9, regs->r10, regs->r11);
  129. printk("R12[%08lx]\n", \
  130. regs->r12);
  131. #if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
  132. printk("ACC0H[%08lx]:ACC0L[%08lx]\n", \
  133. regs->acc0h, regs->acc0l);
  134. printk("ACC1H[%08lx]:ACC1L[%08lx]\n", \
  135. regs->acc1h, regs->acc1l);
  136. #elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
  137. printk("ACCH[%08lx]:ACCL[%08lx]\n", \
  138. regs->acc0h, regs->acc0l);
  139. #else
  140. #error unknown isa configuration
  141. #endif
  142. }
  143. /*
  144. * Create a kernel thread
  145. */
  146. /*
  147. * This is the mechanism for creating a new kernel thread.
  148. *
  149. * NOTE! Only a kernel-only process(ie the swapper or direct descendants
  150. * who haven't done an "execve()") should use this: it will work within
  151. * a system call from a "real" process, but the process memory space will
  152. * not be free'd until both the parent and the child have exited.
  153. */
  154. static void kernel_thread_helper(void *nouse, int (*fn)(void *), void *arg)
  155. {
  156. fn(arg);
  157. do_exit(-1);
  158. }
  159. int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
  160. {
  161. struct pt_regs regs;
  162. memset(&regs, 0, sizeof (regs));
  163. regs.r1 = (unsigned long)fn;
  164. regs.r2 = (unsigned long)arg;
  165. regs.bpc = (unsigned long)kernel_thread_helper;
  166. regs.psw = M32R_PSW_BIE;
  167. /* Ok, create the new process. */
  168. return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
  169. NULL);
  170. }
  171. /*
  172. * Free current thread data structures etc..
  173. */
  174. void exit_thread(void)
  175. {
  176. /* Nothing to do. */
  177. DPRINTK("pid = %d\n", current->pid);
  178. }
  179. void flush_thread(void)
  180. {
  181. DPRINTK("pid = %d\n", current->pid);
  182. memset(&current->thread.debug_trap, 0, sizeof(struct debug_trap));
  183. }
  184. void release_thread(struct task_struct *dead_task)
  185. {
  186. /* do nothing */
  187. DPRINTK("pid = %d\n", dead_task->pid);
  188. }
  189. /* Fill in the fpu structure for a core dump.. */
  190. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  191. {
  192. return 0; /* Task didn't use the fpu at all. */
  193. }
  194. int copy_thread(unsigned long clone_flags, unsigned long spu,
  195. unsigned long unused, struct task_struct *tsk, struct pt_regs *regs)
  196. {
  197. struct pt_regs *childregs = task_pt_regs(tsk);
  198. extern void ret_from_fork(void);
  199. /* Copy registers */
  200. *childregs = *regs;
  201. childregs->spu = spu;
  202. childregs->r0 = 0; /* Child gets zero as return value */
  203. regs->r0 = tsk->pid;
  204. tsk->thread.sp = (unsigned long)childregs;
  205. tsk->thread.lr = (unsigned long)ret_from_fork;
  206. return 0;
  207. }
  208. asmlinkage int sys_fork(unsigned long r0, unsigned long r1, unsigned long r2,
  209. unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
  210. struct pt_regs regs)
  211. {
  212. #ifdef CONFIG_MMU
  213. return do_fork(SIGCHLD, regs.spu, &regs, 0, NULL, NULL);
  214. #else
  215. return -EINVAL;
  216. #endif /* CONFIG_MMU */
  217. }
  218. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  219. unsigned long parent_tidptr,
  220. unsigned long child_tidptr,
  221. unsigned long r4, unsigned long r5, unsigned long r6,
  222. struct pt_regs regs)
  223. {
  224. if (!newsp)
  225. newsp = regs.spu;
  226. return do_fork(clone_flags, newsp, &regs, 0,
  227. (int __user *)parent_tidptr, (int __user *)child_tidptr);
  228. }
  229. /*
  230. * This is trivial, and on the face of it looks like it
  231. * could equally well be done in user mode.
  232. *
  233. * Not so, for quite unobvious reasons - register pressure.
  234. * In user mode vfork() cannot have a stack frame, and if
  235. * done by calling the "clone()" system call directly, you
  236. * do not have enough call-clobbered registers to hold all
  237. * the information you need.
  238. */
  239. asmlinkage int sys_vfork(unsigned long r0, unsigned long r1, unsigned long r2,
  240. unsigned long r3, unsigned long r4, unsigned long r5, unsigned long r6,
  241. struct pt_regs regs)
  242. {
  243. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs.spu, &regs, 0,
  244. NULL, NULL);
  245. }
  246. /*
  247. * sys_execve() executes a new program.
  248. */
  249. asmlinkage int sys_execve(char __user *ufilename, char __user * __user *uargv,
  250. char __user * __user *uenvp,
  251. unsigned long r3, unsigned long r4, unsigned long r5,
  252. unsigned long r6, struct pt_regs regs)
  253. {
  254. int error;
  255. char *filename;
  256. filename = getname(ufilename);
  257. error = PTR_ERR(filename);
  258. if (IS_ERR(filename))
  259. goto out;
  260. error = do_execve(filename, uargv, uenvp, &regs);
  261. putname(filename);
  262. out:
  263. return error;
  264. }
  265. /*
  266. * These bracket the sleeping functions..
  267. */
  268. #define first_sched ((unsigned long) scheduling_functions_start_here)
  269. #define last_sched ((unsigned long) scheduling_functions_end_here)
  270. unsigned long get_wchan(struct task_struct *p)
  271. {
  272. /* M32R_FIXME */
  273. return (0);
  274. }