process.c 6.0 KB

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