process.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * Architecture-dependent parts of process handling.
  3. *
  4. * Copyright (C) 2013 Altera Corporation
  5. * Copyright (C) 2010 Tobias Klauser <[email protected]>
  6. * Copyright (C) 2009 Wind River Systems Inc
  7. * Implemented by [email protected] and [email protected]
  8. * Copyright (C) 2004 Microtronix Datacom Ltd
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/export.h>
  15. #include <linux/sched.h>
  16. #include <linux/sched/debug.h>
  17. #include <linux/sched/task.h>
  18. #include <linux/sched/task_stack.h>
  19. #include <linux/mm_types.h>
  20. #include <linux/tick.h>
  21. #include <linux/uaccess.h>
  22. #include <asm/unistd.h>
  23. #include <asm/traps.h>
  24. #include <asm/cpuinfo.h>
  25. asmlinkage void ret_from_fork(void);
  26. asmlinkage void ret_from_kernel_thread(void);
  27. void (*pm_power_off)(void) = NULL;
  28. EXPORT_SYMBOL(pm_power_off);
  29. void arch_cpu_idle(void)
  30. {
  31. raw_local_irq_enable();
  32. }
  33. /*
  34. * The development boards have no way to pull a board reset. Just jump to the
  35. * cpu reset address and let the boot loader or the code in head.S take care of
  36. * resetting peripherals.
  37. */
  38. void machine_restart(char *__unused)
  39. {
  40. pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);
  41. local_irq_disable();
  42. __asm__ __volatile__ (
  43. "jmp %0\n\t"
  44. :
  45. : "r" (cpuinfo.reset_addr)
  46. : "r4");
  47. }
  48. void machine_halt(void)
  49. {
  50. pr_notice("Machine halt...\n");
  51. local_irq_disable();
  52. for (;;)
  53. ;
  54. }
  55. /*
  56. * There is no way to power off the development boards. So just spin for now. If
  57. * we ever have a way of resetting a board using a GPIO we should add that here.
  58. */
  59. void machine_power_off(void)
  60. {
  61. pr_notice("Machine power off...\n");
  62. local_irq_disable();
  63. for (;;)
  64. ;
  65. }
  66. void show_regs(struct pt_regs *regs)
  67. {
  68. pr_notice("\n");
  69. show_regs_print_info(KERN_DEFAULT);
  70. pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",
  71. regs->r1, regs->r2, regs->r3, regs->r4);
  72. pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",
  73. regs->r5, regs->r6, regs->r7, regs->r8);
  74. pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",
  75. regs->r9, regs->r10, regs->r11, regs->r12);
  76. pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",
  77. regs->r13, regs->r14, regs->r15);
  78. pr_notice("ra: %08lx fp: %08lx sp: %08lx gp: %08lx\n",
  79. regs->ra, regs->fp, regs->sp, regs->gp);
  80. pr_notice("ea: %08lx estatus: %08lx\n",
  81. regs->ea, regs->estatus);
  82. }
  83. void flush_thread(void)
  84. {
  85. }
  86. int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
  87. {
  88. unsigned long clone_flags = args->flags;
  89. unsigned long usp = args->stack;
  90. unsigned long tls = args->tls;
  91. struct pt_regs *childregs = task_pt_regs(p);
  92. struct pt_regs *regs;
  93. struct switch_stack *stack;
  94. struct switch_stack *childstack =
  95. ((struct switch_stack *)childregs) - 1;
  96. if (unlikely(args->fn)) {
  97. memset(childstack, 0,
  98. sizeof(struct switch_stack) + sizeof(struct pt_regs));
  99. childstack->r16 = (unsigned long) args->fn;
  100. childstack->r17 = (unsigned long) args->fn_arg;
  101. childstack->ra = (unsigned long) ret_from_kernel_thread;
  102. childregs->estatus = STATUS_PIE;
  103. childregs->sp = (unsigned long) childstack;
  104. p->thread.ksp = (unsigned long) childstack;
  105. p->thread.kregs = childregs;
  106. return 0;
  107. }
  108. regs = current_pt_regs();
  109. *childregs = *regs;
  110. childregs->r2 = 0; /* Set the return value for the child. */
  111. childregs->r7 = 0;
  112. stack = ((struct switch_stack *) regs) - 1;
  113. *childstack = *stack;
  114. childstack->ra = (unsigned long)ret_from_fork;
  115. p->thread.kregs = childregs;
  116. p->thread.ksp = (unsigned long) childstack;
  117. if (usp)
  118. childregs->sp = usp;
  119. /* Initialize tls register. */
  120. if (clone_flags & CLONE_SETTLS)
  121. childstack->r23 = tls;
  122. return 0;
  123. }
  124. /*
  125. * Generic dumping code. Used for panic and debug.
  126. */
  127. void dump(struct pt_regs *fp)
  128. {
  129. unsigned long *sp;
  130. unsigned char *tp;
  131. int i;
  132. pr_emerg("\nCURRENT PROCESS:\n\n");
  133. pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);
  134. if (current->mm) {
  135. pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
  136. (int) current->mm->start_code,
  137. (int) current->mm->end_code,
  138. (int) current->mm->start_data,
  139. (int) current->mm->end_data,
  140. (int) current->mm->end_data,
  141. (int) current->mm->brk);
  142. pr_emerg("USER-STACK=%08x KERNEL-STACK=%08x\n\n",
  143. (int) current->mm->start_stack,
  144. (int)(((unsigned long) current) + THREAD_SIZE));
  145. }
  146. pr_emerg("PC: %08lx\n", fp->ea);
  147. pr_emerg("SR: %08lx SP: %08lx\n",
  148. (long) fp->estatus, (long) fp);
  149. pr_emerg("r1: %08lx r2: %08lx r3: %08lx\n",
  150. fp->r1, fp->r2, fp->r3);
  151. pr_emerg("r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
  152. fp->r4, fp->r5, fp->r6, fp->r7);
  153. pr_emerg("r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
  154. fp->r8, fp->r9, fp->r10, fp->r11);
  155. pr_emerg("r12: %08lx r13: %08lx r14: %08lx r15: %08lx\n",
  156. fp->r12, fp->r13, fp->r14, fp->r15);
  157. pr_emerg("or2: %08lx ra: %08lx fp: %08lx sp: %08lx\n",
  158. fp->orig_r2, fp->ra, fp->fp, fp->sp);
  159. pr_emerg("\nUSP: %08x TRAPFRAME: %08x\n",
  160. (unsigned int) fp->sp, (unsigned int) fp);
  161. pr_emerg("\nCODE:");
  162. tp = ((unsigned char *) fp->ea) - 0x20;
  163. for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
  164. if ((i % 0x10) == 0)
  165. pr_emerg("\n%08x: ", (int) (tp + i));
  166. pr_emerg("%08x ", (int) *sp++);
  167. }
  168. pr_emerg("\n");
  169. pr_emerg("\nKERNEL STACK:");
  170. tp = ((unsigned char *) fp) - 0x40;
  171. for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
  172. if ((i % 0x10) == 0)
  173. pr_emerg("\n%08x: ", (int) (tp + i));
  174. pr_emerg("%08x ", (int) *sp++);
  175. }
  176. pr_emerg("\n");
  177. pr_emerg("\n");
  178. pr_emerg("\nUSER STACK:");
  179. tp = (unsigned char *) (fp->sp - 0x10);
  180. for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
  181. if ((i % 0x10) == 0)
  182. pr_emerg("\n%08x: ", (int) (tp + i));
  183. pr_emerg("%08x ", (int) *sp++);
  184. }
  185. pr_emerg("\n\n");
  186. }
  187. unsigned long __get_wchan(struct task_struct *p)
  188. {
  189. unsigned long fp, pc;
  190. unsigned long stack_page;
  191. int count = 0;
  192. stack_page = (unsigned long)p;
  193. fp = ((struct switch_stack *)p->thread.ksp)->fp; /* ;dgt2 */
  194. do {
  195. if (fp < stack_page+sizeof(struct task_struct) ||
  196. fp >= 8184+stack_page) /* ;dgt2;tmp */
  197. return 0;
  198. pc = ((unsigned long *)fp)[1];
  199. if (!in_sched_functions(pc))
  200. return pc;
  201. fp = *(unsigned long *) fp;
  202. } while (count++ < 16); /* ;dgt2;tmp */
  203. return 0;
  204. }
  205. /*
  206. * Do necessary setup to start up a newly executed thread.
  207. * Will startup in user mode (status_extension = 0).
  208. */
  209. void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
  210. {
  211. memset((void *) regs, 0, sizeof(struct pt_regs));
  212. regs->estatus = ESTATUS_EPIE | ESTATUS_EU;
  213. regs->ea = pc;
  214. regs->sp = sp;
  215. }
  216. asmlinkage int nios2_clone(unsigned long clone_flags, unsigned long newsp,
  217. int __user *parent_tidptr, int __user *child_tidptr,
  218. unsigned long tls)
  219. {
  220. struct kernel_clone_args args = {
  221. .flags = (lower_32_bits(clone_flags) & ~CSIGNAL),
  222. .pidfd = parent_tidptr,
  223. .child_tid = child_tidptr,
  224. .parent_tid = parent_tidptr,
  225. .exit_signal = (lower_32_bits(clone_flags) & CSIGNAL),
  226. .stack = newsp,
  227. .tls = tls,
  228. };
  229. return kernel_clone(&args);
  230. }