process.c 6.6 KB

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