process.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. asmlinkage void ret_from_kernel_thread(void);
  38. #include <asm/pgalloc.h>
  39. void (*pm_power_off)(void);
  40. EXPORT_SYMBOL(pm_power_off);
  41. static void core_sleep_idle(void)
  42. {
  43. #ifdef LED_DEBUG_SLEEP
  44. /* Show that we're sleeping... */
  45. __set_LEDS(0x55aa);
  46. #endif
  47. frv_cpu_core_sleep();
  48. #ifdef LED_DEBUG_SLEEP
  49. /* ... and that we woke up */
  50. __set_LEDS(0);
  51. #endif
  52. mb();
  53. }
  54. void (*idle)(void) = core_sleep_idle;
  55. /*
  56. * The idle thread. There's no useful work to be
  57. * done, so just try to conserve power and have a
  58. * low exit latency (ie sit in a loop waiting for
  59. * somebody to say that they'd like to reschedule)
  60. */
  61. void cpu_idle(void)
  62. {
  63. /* endless idle loop with no priority at all */
  64. while (1) {
  65. rcu_idle_enter();
  66. while (!need_resched()) {
  67. check_pgt_cache();
  68. if (!frv_dma_inprogress && idle)
  69. idle();
  70. }
  71. rcu_idle_exit();
  72. schedule_preempt_disabled();
  73. }
  74. }
  75. void machine_restart(char * __unused)
  76. {
  77. unsigned long reset_addr;
  78. #ifdef CONFIG_GDBSTUB
  79. gdbstub_exit(0);
  80. #endif
  81. if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
  82. reset_addr = 0xfefff500;
  83. else
  84. reset_addr = 0xfeff0500;
  85. /* Software reset. */
  86. asm volatile(" dcef @(gr0,gr0),1 ! membar !"
  87. " sti %1,@(%0,0) !"
  88. " nop ! nop ! nop ! nop ! nop ! "
  89. " nop ! nop ! nop ! nop ! nop ! "
  90. " nop ! nop ! nop ! nop ! nop ! "
  91. " nop ! nop ! nop ! nop ! nop ! "
  92. : : "r" (reset_addr), "r" (1) );
  93. for (;;)
  94. ;
  95. }
  96. void machine_halt(void)
  97. {
  98. #ifdef CONFIG_GDBSTUB
  99. gdbstub_exit(0);
  100. #endif
  101. for (;;);
  102. }
  103. void machine_power_off(void)
  104. {
  105. #ifdef CONFIG_GDBSTUB
  106. gdbstub_exit(0);
  107. #endif
  108. for (;;);
  109. }
  110. void flush_thread(void)
  111. {
  112. /* nothing */
  113. }
  114. inline unsigned long user_stack(const struct pt_regs *regs)
  115. {
  116. while (regs->next_frame)
  117. regs = regs->next_frame;
  118. return user_mode(regs) ? regs->sp : 0;
  119. }
  120. /*
  121. * set up the kernel stack and exception frames for a new process
  122. */
  123. int copy_thread(unsigned long clone_flags,
  124. unsigned long usp, unsigned long arg,
  125. struct task_struct *p)
  126. {
  127. struct pt_regs *childregs;
  128. childregs = (struct pt_regs *)
  129. (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
  130. /* set up the userspace frame (the only place that the USP is stored) */
  131. *childregs = *current_pt_regs();
  132. p->thread.frame = childregs;
  133. p->thread.curr = p;
  134. p->thread.sp = (unsigned long) childregs;
  135. p->thread.fp = 0;
  136. p->thread.lr = 0;
  137. p->thread.frame0 = childregs;
  138. if (unlikely(p->flags & PF_KTHREAD)) {
  139. childregs->gr9 = usp; /* function */
  140. childregs->gr8 = arg;
  141. p->thread.pc = (unsigned long) ret_from_kernel_thread;
  142. save_user_regs(p->thread.user);
  143. return 0;
  144. }
  145. if (usp)
  146. childregs->sp = usp;
  147. childregs->next_frame = NULL;
  148. p->thread.pc = (unsigned long) ret_from_fork;
  149. /* the new TLS pointer is passed in as arg #5 to sys_clone() */
  150. if (clone_flags & CLONE_SETTLS)
  151. childregs->gr29 = childregs->gr12;
  152. save_user_regs(p->thread.user);
  153. return 0;
  154. } /* end copy_thread() */
  155. unsigned long get_wchan(struct task_struct *p)
  156. {
  157. struct pt_regs *regs0;
  158. unsigned long fp, pc;
  159. unsigned long stack_limit;
  160. int count = 0;
  161. if (!p || p == current || p->state == TASK_RUNNING)
  162. return 0;
  163. stack_limit = (unsigned long) (p + 1);
  164. fp = p->thread.fp;
  165. regs0 = p->thread.frame0;
  166. do {
  167. if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
  168. return 0;
  169. pc = ((unsigned long *) fp)[2];
  170. /* FIXME: This depends on the order of these functions. */
  171. if (!in_sched_functions(pc))
  172. return pc;
  173. fp = *(unsigned long *) fp;
  174. } while (count++ < 16);
  175. return 0;
  176. }
  177. unsigned long thread_saved_pc(struct task_struct *tsk)
  178. {
  179. /* Check whether the thread is blocked in resume() */
  180. if (in_sched_functions(tsk->thread.pc))
  181. return ((unsigned long *)tsk->thread.fp)[2];
  182. else
  183. return tsk->thread.pc;
  184. }
  185. int elf_check_arch(const struct elf32_hdr *hdr)
  186. {
  187. unsigned long hsr0 = __get_HSR(0);
  188. unsigned long psr = __get_PSR();
  189. if (hdr->e_machine != EM_FRV)
  190. return 0;
  191. switch (hdr->e_flags & EF_FRV_GPR_MASK) {
  192. case EF_FRV_GPR64:
  193. if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
  194. return 0;
  195. case EF_FRV_GPR32:
  196. case 0:
  197. break;
  198. default:
  199. return 0;
  200. }
  201. switch (hdr->e_flags & EF_FRV_FPR_MASK) {
  202. case EF_FRV_FPR64:
  203. if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
  204. return 0;
  205. case EF_FRV_FPR32:
  206. case EF_FRV_FPR_NONE:
  207. case 0:
  208. break;
  209. default:
  210. return 0;
  211. }
  212. if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
  213. if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
  214. PSR_IMPLE(psr) != PSR_IMPLE_FR451)
  215. return 0;
  216. switch (hdr->e_flags & EF_FRV_CPU_MASK) {
  217. case EF_FRV_CPU_GENERIC:
  218. break;
  219. case EF_FRV_CPU_FR300:
  220. case EF_FRV_CPU_SIMPLE:
  221. case EF_FRV_CPU_TOMCAT:
  222. default:
  223. return 0;
  224. case EF_FRV_CPU_FR400:
  225. if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
  226. PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
  227. PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
  228. PSR_IMPLE(psr) != PSR_IMPLE_FR551)
  229. return 0;
  230. break;
  231. case EF_FRV_CPU_FR450:
  232. if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
  233. return 0;
  234. break;
  235. case EF_FRV_CPU_FR500:
  236. if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
  237. return 0;
  238. break;
  239. case EF_FRV_CPU_FR550:
  240. if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
  241. return 0;
  242. break;
  243. }
  244. return 1;
  245. }
  246. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
  247. {
  248. memcpy(fpregs,
  249. &current->thread.user->f,
  250. sizeof(current->thread.user->f));
  251. return 1;
  252. }