process.c 8.1 KB

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