process.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /* process.c: FRV specific parts of process handling
  2. *
  3. * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. * - Derived from arch/m68k/kernel/process.c
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/smp.h>
  18. #include <linux/stddef.h>
  19. #include <linux/unistd.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/slab.h>
  22. #include <linux/user.h>
  23. #include <linux/elf.h>
  24. #include <linux/reboot.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/rcupdate.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/setup.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/tlb.h>
  33. #include <asm/gdb-stub.h>
  34. #include <asm/mb-regs.h>
  35. #include "local.h"
  36. asmlinkage void ret_from_fork(void);
  37. #include <asm/pgalloc.h>
  38. void (*pm_power_off)(void);
  39. EXPORT_SYMBOL(pm_power_off);
  40. static void core_sleep_idle(void)
  41. {
  42. #ifdef LED_DEBUG_SLEEP
  43. /* Show that we're sleeping... */
  44. __set_LEDS(0x55aa);
  45. #endif
  46. frv_cpu_core_sleep();
  47. #ifdef LED_DEBUG_SLEEP
  48. /* ... and that we woke up */
  49. __set_LEDS(0);
  50. #endif
  51. mb();
  52. }
  53. void (*idle)(void) = core_sleep_idle;
  54. /*
  55. * The idle thread. There's no useful work to be
  56. * done, so just try to conserve power and have a
  57. * low exit latency (ie sit in a loop waiting for
  58. * somebody to say that they'd like to reschedule)
  59. */
  60. void cpu_idle(void)
  61. {
  62. /* endless idle loop with no priority at all */
  63. while (1) {
  64. rcu_idle_enter();
  65. while (!need_resched()) {
  66. check_pgt_cache();
  67. if (!frv_dma_inprogress && idle)
  68. idle();
  69. }
  70. rcu_idle_exit();
  71. schedule_preempt_disabled();
  72. }
  73. }
  74. void machine_restart(char * __unused)
  75. {
  76. unsigned long reset_addr;
  77. #ifdef CONFIG_GDBSTUB
  78. gdbstub_exit(0);
  79. #endif
  80. if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
  81. reset_addr = 0xfefff500;
  82. else
  83. reset_addr = 0xfeff0500;
  84. /* Software reset. */
  85. asm volatile(" dcef @(gr0,gr0),1 ! membar !"
  86. " sti %1,@(%0,0) !"
  87. " nop ! nop ! nop ! nop ! nop ! "
  88. " nop ! nop ! nop ! nop ! nop ! "
  89. " nop ! nop ! nop ! nop ! nop ! "
  90. " nop ! nop ! nop ! nop ! nop ! "
  91. : : "r" (reset_addr), "r" (1) );
  92. for (;;)
  93. ;
  94. }
  95. void machine_halt(void)
  96. {
  97. #ifdef CONFIG_GDBSTUB
  98. gdbstub_exit(0);
  99. #endif
  100. for (;;);
  101. }
  102. void machine_power_off(void)
  103. {
  104. #ifdef CONFIG_GDBSTUB
  105. gdbstub_exit(0);
  106. #endif
  107. for (;;);
  108. }
  109. void flush_thread(void)
  110. {
  111. /* nothing */
  112. }
  113. inline unsigned long user_stack(const struct pt_regs *regs)
  114. {
  115. while (regs->next_frame)
  116. regs = regs->next_frame;
  117. return user_mode(regs) ? regs->sp : 0;
  118. }
  119. asmlinkage int sys_fork(void)
  120. {
  121. #ifndef CONFIG_MMU
  122. /* fork almost works, enough to trick you into looking elsewhere:-( */
  123. return -EINVAL;
  124. #else
  125. return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
  126. #endif
  127. }
  128. asmlinkage int sys_vfork(void)
  129. {
  130. return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
  131. NULL, NULL);
  132. }
  133. /*****************************************************************************/
  134. /*
  135. * clone a process
  136. * - tlsptr is retrieved by copy_thread()
  137. */
  138. asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
  139. int __user *parent_tidptr, int __user *child_tidptr,
  140. int __user *tlsptr)
  141. {
  142. if (!newsp)
  143. newsp = user_stack(__frame);
  144. return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
  145. } /* end sys_clone() */
  146. /*****************************************************************************/
  147. /*
  148. * This gets called before we allocate a new thread and copy
  149. * the current task into it.
  150. */
  151. void prepare_to_copy(struct task_struct *tsk)
  152. {
  153. //unlazy_fpu(tsk);
  154. } /* end prepare_to_copy() */
  155. /*****************************************************************************/
  156. /*
  157. * set up the kernel stack and exception frames for a new process
  158. */
  159. int copy_thread(unsigned long clone_flags,
  160. unsigned long usp, unsigned long topstk,
  161. struct task_struct *p, struct pt_regs *regs)
  162. {
  163. struct pt_regs *childregs0, *childregs, *regs0;
  164. regs0 = __kernel_frame0_ptr;
  165. childregs0 = (struct pt_regs *)
  166. (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
  167. childregs = childregs0;
  168. /* set up the userspace frame (the only place that the USP is stored) */
  169. *childregs0 = *regs0;
  170. childregs0->gr8 = 0;
  171. childregs0->sp = usp;
  172. childregs0->next_frame = NULL;
  173. /* set up the return kernel frame if called from kernel_thread() */
  174. if (regs != regs0) {
  175. childregs--;
  176. *childregs = *regs;
  177. childregs->sp = (unsigned long) childregs0;
  178. childregs->next_frame = childregs0;
  179. childregs->gr15 = (unsigned long) task_thread_info(p);
  180. childregs->gr29 = (unsigned long) p;
  181. }
  182. p->set_child_tid = p->clear_child_tid = NULL;
  183. p->thread.frame = childregs;
  184. p->thread.curr = p;
  185. p->thread.sp = (unsigned long) childregs;
  186. p->thread.fp = 0;
  187. p->thread.lr = 0;
  188. p->thread.pc = (unsigned long) ret_from_fork;
  189. p->thread.frame0 = childregs0;
  190. /* the new TLS pointer is passed in as arg #5 to sys_clone() */
  191. if (clone_flags & CLONE_SETTLS)
  192. childregs->gr29 = childregs->gr12;
  193. save_user_regs(p->thread.user);
  194. return 0;
  195. } /* end copy_thread() */
  196. /*
  197. * sys_execve() executes a new program.
  198. */
  199. asmlinkage int sys_execve(const char __user *name,
  200. const char __user *const __user *argv,
  201. const char __user *const __user *envp)
  202. {
  203. int error;
  204. char * filename;
  205. filename = getname(name);
  206. error = PTR_ERR(filename);
  207. if (IS_ERR(filename))
  208. return error;
  209. error = do_execve(filename, argv, envp, __frame);
  210. putname(filename);
  211. return error;
  212. }
  213. unsigned long get_wchan(struct task_struct *p)
  214. {
  215. struct pt_regs *regs0;
  216. unsigned long fp, pc;
  217. unsigned long stack_limit;
  218. int count = 0;
  219. if (!p || p == current || p->state == TASK_RUNNING)
  220. return 0;
  221. stack_limit = (unsigned long) (p + 1);
  222. fp = p->thread.fp;
  223. regs0 = p->thread.frame0;
  224. do {
  225. if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
  226. return 0;
  227. pc = ((unsigned long *) fp)[2];
  228. /* FIXME: This depends on the order of these functions. */
  229. if (!in_sched_functions(pc))
  230. return pc;
  231. fp = *(unsigned long *) fp;
  232. } while (count++ < 16);
  233. return 0;
  234. }
  235. unsigned long thread_saved_pc(struct task_struct *tsk)
  236. {
  237. /* Check whether the thread is blocked in resume() */
  238. if (in_sched_functions(tsk->thread.pc))
  239. return ((unsigned long *)tsk->thread.fp)[2];
  240. else
  241. return tsk->thread.pc;
  242. }
  243. int elf_check_arch(const struct elf32_hdr *hdr)
  244. {
  245. unsigned long hsr0 = __get_HSR(0);
  246. unsigned long psr = __get_PSR();
  247. if (hdr->e_machine != EM_FRV)
  248. return 0;
  249. switch (hdr->e_flags & EF_FRV_GPR_MASK) {
  250. case EF_FRV_GPR64:
  251. if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
  252. return 0;
  253. case EF_FRV_GPR32:
  254. case 0:
  255. break;
  256. default:
  257. return 0;
  258. }
  259. switch (hdr->e_flags & EF_FRV_FPR_MASK) {
  260. case EF_FRV_FPR64:
  261. if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
  262. return 0;
  263. case EF_FRV_FPR32:
  264. case EF_FRV_FPR_NONE:
  265. case 0:
  266. break;
  267. default:
  268. return 0;
  269. }
  270. if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
  271. if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
  272. PSR_IMPLE(psr) != PSR_IMPLE_FR451)
  273. return 0;
  274. switch (hdr->e_flags & EF_FRV_CPU_MASK) {
  275. case EF_FRV_CPU_GENERIC:
  276. break;
  277. case EF_FRV_CPU_FR300:
  278. case EF_FRV_CPU_SIMPLE:
  279. case EF_FRV_CPU_TOMCAT:
  280. default:
  281. return 0;
  282. case EF_FRV_CPU_FR400:
  283. if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
  284. PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
  285. PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
  286. PSR_IMPLE(psr) != PSR_IMPLE_FR551)
  287. return 0;
  288. break;
  289. case EF_FRV_CPU_FR450:
  290. if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
  291. return 0;
  292. break;
  293. case EF_FRV_CPU_FR500:
  294. if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
  295. return 0;
  296. break;
  297. case EF_FRV_CPU_FR550:
  298. if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
  299. return 0;
  300. break;
  301. }
  302. return 1;
  303. }
  304. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
  305. {
  306. memcpy(fpregs,
  307. &current->thread.user->f,
  308. sizeof(current->thread.user->f));
  309. return 1;
  310. }