process.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/module.h>
  4. #include <linux/sched.h>
  5. #include <linux/sched/task_stack.h>
  6. #include <linux/sched/debug.h>
  7. #include <linux/delay.h>
  8. #include <linux/kallsyms.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/ptrace.h>
  11. #include <linux/elfcore.h>
  12. #include <asm/elf.h>
  13. #include <abi/reg_ops.h>
  14. struct cpuinfo_csky cpu_data[NR_CPUS];
  15. #ifdef CONFIG_STACKPROTECTOR
  16. #include <linux/stackprotector.h>
  17. unsigned long __stack_chk_guard __read_mostly;
  18. EXPORT_SYMBOL(__stack_chk_guard);
  19. #endif
  20. asmlinkage void ret_from_fork(void);
  21. asmlinkage void ret_from_kernel_thread(void);
  22. /*
  23. * Some archs flush debug and FPU info here
  24. */
  25. void flush_thread(void){}
  26. int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
  27. {
  28. unsigned long clone_flags = args->flags;
  29. unsigned long usp = args->stack;
  30. unsigned long tls = args->tls;
  31. struct switch_stack *childstack;
  32. struct pt_regs *childregs = task_pt_regs(p);
  33. #ifdef CONFIG_CPU_HAS_FPU
  34. save_to_user_fp(&p->thread.user_fp);
  35. #endif
  36. childstack = ((struct switch_stack *) childregs) - 1;
  37. memset(childstack, 0, sizeof(struct switch_stack));
  38. /* setup thread.sp for switch_to !!! */
  39. p->thread.sp = (unsigned long)childstack;
  40. if (unlikely(args->fn)) {
  41. memset(childregs, 0, sizeof(struct pt_regs));
  42. childstack->r15 = (unsigned long) ret_from_kernel_thread;
  43. childstack->r10 = (unsigned long) args->fn_arg;
  44. childstack->r9 = (unsigned long) args->fn;
  45. childregs->sr = mfcr("psr");
  46. } else {
  47. *childregs = *(current_pt_regs());
  48. if (usp)
  49. childregs->usp = usp;
  50. if (clone_flags & CLONE_SETTLS)
  51. task_thread_info(p)->tp_value = childregs->tls
  52. = tls;
  53. childregs->a0 = 0;
  54. childstack->r15 = (unsigned long) ret_from_fork;
  55. }
  56. return 0;
  57. }
  58. /* Fill in the fpu structure for a core dump. */
  59. int elf_core_copy_task_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
  60. {
  61. memcpy(fpu, &current->thread.user_fp, sizeof(*fpu));
  62. return 1;
  63. }
  64. int dump_task_regs(struct task_struct *tsk, elf_gregset_t *pr_regs)
  65. {
  66. struct pt_regs *regs = task_pt_regs(tsk);
  67. /* NOTE: usp is error value. */
  68. ELF_CORE_COPY_REGS((*pr_regs), regs)
  69. return 1;
  70. }
  71. #ifndef CONFIG_CPU_PM_NONE
  72. void arch_cpu_idle(void)
  73. {
  74. #ifdef CONFIG_CPU_PM_WAIT
  75. asm volatile("wait\n");
  76. #endif
  77. #ifdef CONFIG_CPU_PM_DOZE
  78. asm volatile("doze\n");
  79. #endif
  80. #ifdef CONFIG_CPU_PM_STOP
  81. asm volatile("stop\n");
  82. #endif
  83. }
  84. #endif