process.c 5.9 KB

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