process.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #include <linux/sched.h>
  4. #include <linux/sched/debug.h>
  5. #include <linux/sched/task_stack.h>
  6. #include <linux/delay.h>
  7. #include <linux/kallsyms.h>
  8. #include <linux/uaccess.h>
  9. #include <asm/elf.h>
  10. #include <asm/proc-fns.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/reboot.h>
  13. extern void setup_mm_for_reboot(char mode);
  14. #ifdef CONFIG_PROC_FS
  15. struct proc_dir_entry *proc_dir_cpu;
  16. EXPORT_SYMBOL(proc_dir_cpu);
  17. #endif
  18. extern inline void arch_reset(char mode)
  19. {
  20. if (mode == 's') {
  21. /* Use cpu handler, jump to 0 */
  22. cpu_reset(0);
  23. }
  24. }
  25. void (*pm_power_off) (void);
  26. EXPORT_SYMBOL(pm_power_off);
  27. static char reboot_mode_nds32 = 'h';
  28. int __init reboot_setup(char *str)
  29. {
  30. reboot_mode_nds32 = str[0];
  31. return 1;
  32. }
  33. static int cpub_pwroff(void)
  34. {
  35. return 0;
  36. }
  37. __setup("reboot=", reboot_setup);
  38. void machine_halt(void)
  39. {
  40. cpub_pwroff();
  41. }
  42. EXPORT_SYMBOL(machine_halt);
  43. void machine_power_off(void)
  44. {
  45. if (pm_power_off)
  46. pm_power_off();
  47. }
  48. EXPORT_SYMBOL(machine_power_off);
  49. void machine_restart(char *cmd)
  50. {
  51. /*
  52. * Clean and disable cache, and turn off interrupts
  53. */
  54. cpu_proc_fin();
  55. /*
  56. * Tell the mm system that we are going to reboot -
  57. * we may need it to insert some 1:1 mappings so that
  58. * soft boot works.
  59. */
  60. setup_mm_for_reboot(reboot_mode_nds32);
  61. /* Execute kernel restart handler call chain */
  62. do_kernel_restart(cmd);
  63. /*
  64. * Now call the architecture specific reboot code.
  65. */
  66. arch_reset(reboot_mode_nds32);
  67. /*
  68. * Whoops - the architecture was unable to reboot.
  69. * Tell the user!
  70. */
  71. mdelay(1000);
  72. pr_info("Reboot failed -- System halted\n");
  73. while (1) ;
  74. }
  75. EXPORT_SYMBOL(machine_restart);
  76. void show_regs(struct pt_regs *regs)
  77. {
  78. printk("PC is at %pS\n", (void *)instruction_pointer(regs));
  79. printk("LP is at %pS\n", (void *)regs->lp);
  80. pr_info("pc : [<%08lx>] lp : [<%08lx>] %s\n"
  81. "sp : %08lx fp : %08lx gp : %08lx\n",
  82. instruction_pointer(regs),
  83. regs->lp, print_tainted(), regs->sp, regs->fp, regs->gp);
  84. pr_info("r25: %08lx r24: %08lx\n", regs->uregs[25], regs->uregs[24]);
  85. pr_info("r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n",
  86. regs->uregs[23], regs->uregs[22],
  87. regs->uregs[21], regs->uregs[20]);
  88. pr_info("r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n",
  89. regs->uregs[19], regs->uregs[18],
  90. regs->uregs[17], regs->uregs[16]);
  91. pr_info("r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n",
  92. regs->uregs[15], regs->uregs[14],
  93. regs->uregs[13], regs->uregs[12]);
  94. pr_info("r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n",
  95. regs->uregs[11], regs->uregs[10],
  96. regs->uregs[9], regs->uregs[8]);
  97. pr_info("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
  98. regs->uregs[7], regs->uregs[6], regs->uregs[5], regs->uregs[4]);
  99. pr_info("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
  100. regs->uregs[3], regs->uregs[2], regs->uregs[1], regs->uregs[0]);
  101. pr_info(" IRQs o%s Segment %s\n",
  102. interrupts_enabled(regs) ? "n" : "ff",
  103. segment_eq(get_fs(), get_ds())? "kernel" : "user");
  104. }
  105. EXPORT_SYMBOL(show_regs);
  106. void flush_thread(void)
  107. {
  108. }
  109. DEFINE_PER_CPU(struct task_struct *, __entry_task);
  110. asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
  111. int copy_thread(unsigned long clone_flags, unsigned long stack_start,
  112. unsigned long stk_sz, struct task_struct *p)
  113. {
  114. struct pt_regs *childregs = task_pt_regs(p);
  115. memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
  116. if (unlikely(p->flags & PF_KTHREAD)) {
  117. memset(childregs, 0, sizeof(struct pt_regs));
  118. /* kernel thread fn */
  119. p->thread.cpu_context.r6 = stack_start;
  120. /* kernel thread argument */
  121. p->thread.cpu_context.r7 = stk_sz;
  122. } else {
  123. *childregs = *current_pt_regs();
  124. if (stack_start)
  125. childregs->sp = stack_start;
  126. /* child get zero as ret. */
  127. childregs->uregs[0] = 0;
  128. childregs->osp = 0;
  129. if (clone_flags & CLONE_SETTLS)
  130. childregs->uregs[25] = childregs->uregs[3];
  131. }
  132. /* cpu context switching */
  133. p->thread.cpu_context.pc = (unsigned long)ret_from_fork;
  134. p->thread.cpu_context.sp = (unsigned long)childregs;
  135. #ifdef CONFIG_HWZOL
  136. childregs->lb = 0;
  137. childregs->le = 0;
  138. childregs->lc = 0;
  139. #endif
  140. return 0;
  141. }
  142. /*
  143. * fill in the fpe structure for a core dump...
  144. */
  145. int dump_fpu(struct pt_regs *regs, elf_fpregset_t * fpu)
  146. {
  147. int fpvalid = 0;
  148. return fpvalid;
  149. }
  150. EXPORT_SYMBOL(dump_fpu);
  151. unsigned long get_wchan(struct task_struct *p)
  152. {
  153. unsigned long fp, lr;
  154. unsigned long stack_start, stack_end;
  155. int count = 0;
  156. if (!p || p == current || p->state == TASK_RUNNING)
  157. return 0;
  158. if (IS_ENABLED(CONFIG_FRAME_POINTER)) {
  159. stack_start = (unsigned long)end_of_stack(p);
  160. stack_end = (unsigned long)task_stack_page(p) + THREAD_SIZE;
  161. fp = thread_saved_fp(p);
  162. do {
  163. if (fp < stack_start || fp > stack_end)
  164. return 0;
  165. lr = ((unsigned long *)fp)[0];
  166. if (!in_sched_functions(lr))
  167. return lr;
  168. fp = *(unsigned long *)(fp + 4);
  169. } while (count++ < 16);
  170. }
  171. return 0;
  172. }
  173. EXPORT_SYMBOL(get_wchan);