process.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Process creation support for Hexagon
  3. *
  4. * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <linux/sched.h>
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/tick.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/slab.h>
  26. /*
  27. * Program thread launch. Often defined as a macro in processor.h,
  28. * but we're shooting for a small footprint and it's not an inner-loop
  29. * performance-critical operation.
  30. *
  31. * The Hexagon ABI specifies that R28 is zero'ed before program launch,
  32. * so that gets automatically done here. If we ever stop doing that here,
  33. * we'll probably want to define the ELF_PLAT_INIT macro.
  34. */
  35. void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
  36. {
  37. /* Set to run with user-mode data segmentation */
  38. set_fs(USER_DS);
  39. /* We want to zero all data-containing registers. Is this overkill? */
  40. memset(regs, 0, sizeof(*regs));
  41. /* We might want to also zero all Processor registers here */
  42. pt_set_usermode(regs);
  43. pt_set_elr(regs, pc);
  44. pt_set_rte_sp(regs, sp);
  45. }
  46. /*
  47. * Spin, or better still, do a hardware or VM wait instruction
  48. * If hardware or VM offer wait termination even though interrupts
  49. * are disabled.
  50. */
  51. static void default_idle(void)
  52. {
  53. __vmwait();
  54. }
  55. void (*idle_sleep)(void) = default_idle;
  56. void cpu_idle(void)
  57. {
  58. while (1) {
  59. tick_nohz_idle_enter();
  60. local_irq_disable();
  61. while (!need_resched()) {
  62. idle_sleep();
  63. /* interrupts wake us up, but aren't serviced */
  64. local_irq_enable(); /* service interrupt */
  65. local_irq_disable();
  66. }
  67. local_irq_enable();
  68. tick_nohz_idle_exit();
  69. schedule();
  70. }
  71. }
  72. /*
  73. * Return saved PC of a blocked thread
  74. */
  75. unsigned long thread_saved_pc(struct task_struct *tsk)
  76. {
  77. return 0;
  78. }
  79. /*
  80. * Copy architecture-specific thread state
  81. */
  82. int copy_thread(unsigned long clone_flags, unsigned long usp,
  83. unsigned long arg, struct task_struct *p)
  84. {
  85. struct thread_info *ti = task_thread_info(p);
  86. struct hexagon_switch_stack *ss;
  87. struct pt_regs *childregs;
  88. asmlinkage void ret_from_fork(void);
  89. childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
  90. sizeof(*childregs));
  91. ti->regs = childregs;
  92. /*
  93. * Establish kernel stack pointer and initial PC for new thread
  94. * Note that unlike the usual situation, we do not copy the
  95. * parent's callee-saved here; those are in pt_regs and whatever
  96. * we leave here will be overridden on return to userland.
  97. */
  98. ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
  99. sizeof(*ss));
  100. ss->lr = (unsigned long)ret_from_fork;
  101. p->thread.switch_sp = ss;
  102. if (unlikely(p->flags & PF_KTHREAD)) {
  103. memset(childregs, 0, sizeof(struct pt_regs));
  104. /* r24 <- fn, r25 <- arg */
  105. ss->r2524 = usp | ((u64)arg << 32);
  106. pt_set_kmode(childregs);
  107. return 0;
  108. }
  109. memcpy(childregs, current_pt_regs(), sizeof(*childregs));
  110. ss->r2524 = 0;
  111. if (usp)
  112. pt_set_rte_sp(childregs, usp);
  113. /* Child sees zero return value */
  114. childregs->r00 = 0;
  115. /*
  116. * The clone syscall has the C signature:
  117. * int [r0] clone(int flags [r0],
  118. * void *child_frame [r1],
  119. * void *parent_tid [r2],
  120. * void *child_tid [r3],
  121. * void *thread_control_block [r4]);
  122. * ugp is used to provide TLS support.
  123. */
  124. if (clone_flags & CLONE_SETTLS)
  125. childregs->ugp = childregs->r04;
  126. /*
  127. * Parent sees new pid -- not necessary, not even possible at
  128. * this point in the fork process
  129. * Might also want to set things like ti->addr_limit
  130. */
  131. return 0;
  132. }
  133. /*
  134. * Release any architecture-specific resources locked by thread
  135. */
  136. void release_thread(struct task_struct *dead_task)
  137. {
  138. }
  139. /*
  140. * Free any architecture-specific thread data structures, etc.
  141. */
  142. void exit_thread(void)
  143. {
  144. }
  145. /*
  146. * Some archs flush debug and FPU info here
  147. */
  148. void flush_thread(void)
  149. {
  150. }
  151. /*
  152. * The "wait channel" terminology is archaic, but what we want
  153. * is an identification of the point at which the scheduler
  154. * was invoked by a blocked thread.
  155. */
  156. unsigned long get_wchan(struct task_struct *p)
  157. {
  158. unsigned long fp, pc;
  159. unsigned long stack_page;
  160. int count = 0;
  161. if (!p || p == current || p->state == TASK_RUNNING)
  162. return 0;
  163. stack_page = (unsigned long)task_stack_page(p);
  164. fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
  165. do {
  166. if (fp < (stack_page + sizeof(struct thread_info)) ||
  167. fp >= (THREAD_SIZE - 8 + stack_page))
  168. return 0;
  169. pc = ((unsigned long *)fp)[1];
  170. if (!in_sched_functions(pc))
  171. return pc;
  172. fp = *(unsigned long *) fp;
  173. } while (count++ < 16);
  174. return 0;
  175. }
  176. /*
  177. * Required placeholder.
  178. */
  179. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  180. {
  181. return 0;
  182. }