process.c 8.0 KB

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