process.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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/sched/debug.h>
  22. #include <linux/sched/task.h>
  23. #include <linux/sched/task_stack.h>
  24. #include <linux/types.h>
  25. #include <linux/module.h>
  26. #include <linux/tick.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/slab.h>
  29. #include <linux/tracehook.h>
  30. /*
  31. * Program thread launch. Often defined as a macro in processor.h,
  32. * but we're shooting for a small footprint and it's not an inner-loop
  33. * performance-critical operation.
  34. *
  35. * The Hexagon ABI specifies that R28 is zero'ed before program launch,
  36. * so that gets automatically done here. If we ever stop doing that here,
  37. * we'll probably want to define the ELF_PLAT_INIT macro.
  38. */
  39. void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
  40. {
  41. /* We want to zero all data-containing registers. Is this overkill? */
  42. memset(regs, 0, sizeof(*regs));
  43. /* We might want to also zero all Processor registers here */
  44. pt_set_usermode(regs);
  45. pt_set_elr(regs, pc);
  46. pt_set_rte_sp(regs, sp);
  47. }
  48. /*
  49. * Spin, or better still, do a hardware or VM wait instruction
  50. * If hardware or VM offer wait termination even though interrupts
  51. * are disabled.
  52. */
  53. void arch_cpu_idle(void)
  54. {
  55. __vmwait();
  56. /* interrupts wake us up, but irqs are still disabled */
  57. local_irq_enable();
  58. }
  59. /*
  60. * Copy architecture-specific thread state
  61. */
  62. int copy_thread(unsigned long clone_flags, unsigned long usp,
  63. unsigned long arg, struct task_struct *p)
  64. {
  65. struct thread_info *ti = task_thread_info(p);
  66. struct hexagon_switch_stack *ss;
  67. struct pt_regs *childregs;
  68. asmlinkage void ret_from_fork(void);
  69. childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
  70. sizeof(*childregs));
  71. ti->regs = childregs;
  72. /*
  73. * Establish kernel stack pointer and initial PC for new thread
  74. * Note that unlike the usual situation, we do not copy the
  75. * parent's callee-saved here; those are in pt_regs and whatever
  76. * we leave here will be overridden on return to userland.
  77. */
  78. ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
  79. sizeof(*ss));
  80. ss->lr = (unsigned long)ret_from_fork;
  81. p->thread.switch_sp = ss;
  82. if (unlikely(p->flags & PF_KTHREAD)) {
  83. memset(childregs, 0, sizeof(struct pt_regs));
  84. /* r24 <- fn, r25 <- arg */
  85. ss->r24 = usp;
  86. ss->r25 = arg;
  87. pt_set_kmode(childregs);
  88. return 0;
  89. }
  90. memcpy(childregs, current_pt_regs(), sizeof(*childregs));
  91. ss->r2524 = 0;
  92. if (usp)
  93. pt_set_rte_sp(childregs, usp);
  94. /* Child sees zero return value */
  95. childregs->r00 = 0;
  96. /*
  97. * The clone syscall has the C signature:
  98. * int [r0] clone(int flags [r0],
  99. * void *child_frame [r1],
  100. * void *parent_tid [r2],
  101. * void *child_tid [r3],
  102. * void *thread_control_block [r4]);
  103. * ugp is used to provide TLS support.
  104. */
  105. if (clone_flags & CLONE_SETTLS)
  106. childregs->ugp = childregs->r04;
  107. /*
  108. * Parent sees new pid -- not necessary, not even possible at
  109. * this point in the fork process
  110. * Might also want to set things like ti->addr_limit
  111. */
  112. return 0;
  113. }
  114. /*
  115. * Release any architecture-specific resources locked by thread
  116. */
  117. void release_thread(struct task_struct *dead_task)
  118. {
  119. }
  120. /*
  121. * Some archs flush debug and FPU info here
  122. */
  123. void flush_thread(void)
  124. {
  125. }
  126. /*
  127. * The "wait channel" terminology is archaic, but what we want
  128. * is an identification of the point at which the scheduler
  129. * was invoked by a blocked thread.
  130. */
  131. unsigned long get_wchan(struct task_struct *p)
  132. {
  133. unsigned long fp, pc;
  134. unsigned long stack_page;
  135. int count = 0;
  136. if (!p || p == current || p->state == TASK_RUNNING)
  137. return 0;
  138. stack_page = (unsigned long)task_stack_page(p);
  139. fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
  140. do {
  141. if (fp < (stack_page + sizeof(struct thread_info)) ||
  142. fp >= (THREAD_SIZE - 8 + stack_page))
  143. return 0;
  144. pc = ((unsigned long *)fp)[1];
  145. if (!in_sched_functions(pc))
  146. return pc;
  147. fp = *(unsigned long *) fp;
  148. } while (count++ < 16);
  149. return 0;
  150. }
  151. /*
  152. * Required placeholder.
  153. */
  154. int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
  155. {
  156. return 0;
  157. }
  158. /*
  159. * Called on the exit path of event entry; see vm_entry.S
  160. *
  161. * Interrupts will already be disabled.
  162. *
  163. * Returns 0 if there's no need to re-check for more work.
  164. */
  165. int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
  166. {
  167. if (!(thread_info_flags & _TIF_WORK_MASK)) {
  168. return 0;
  169. } /* shortcut -- no work to be done */
  170. local_irq_enable();
  171. if (thread_info_flags & _TIF_NEED_RESCHED) {
  172. schedule();
  173. return 1;
  174. }
  175. if (thread_info_flags & _TIF_SIGPENDING) {
  176. do_signal(regs);
  177. return 1;
  178. }
  179. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  180. clear_thread_flag(TIF_NOTIFY_RESUME);
  181. tracehook_notify_resume(regs);
  182. return 1;
  183. }
  184. /* Should not even reach here */
  185. panic("%s: bad thread_info flags 0x%08x\n", __func__,
  186. thread_info_flags);
  187. }