process.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <asm/elf.h>
  12. #include <abi/reg_ops.h>
  13. struct cpuinfo_csky cpu_data[NR_CPUS];
  14. #ifdef CONFIG_STACKPROTECTOR
  15. #include <linux/stackprotector.h>
  16. unsigned long __stack_chk_guard __read_mostly;
  17. EXPORT_SYMBOL(__stack_chk_guard);
  18. #endif
  19. asmlinkage void ret_from_fork(void);
  20. asmlinkage void ret_from_kernel_thread(void);
  21. /*
  22. * Some archs flush debug and FPU info here
  23. */
  24. void flush_thread(void){}
  25. int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
  26. {
  27. unsigned long clone_flags = args->flags;
  28. unsigned long usp = args->stack;
  29. unsigned long tls = args->tls;
  30. struct switch_stack *childstack;
  31. struct pt_regs *childregs = task_pt_regs(p);
  32. #ifdef CONFIG_CPU_HAS_FPU
  33. save_to_user_fp(&p->thread.user_fp);
  34. #endif
  35. childstack = ((struct switch_stack *) childregs) - 1;
  36. memset(childstack, 0, sizeof(struct switch_stack));
  37. /* setup thread.sp for switch_to !!! */
  38. p->thread.sp = (unsigned long)childstack;
  39. if (unlikely(args->fn)) {
  40. memset(childregs, 0, sizeof(struct pt_regs));
  41. childstack->r15 = (unsigned long) ret_from_kernel_thread;
  42. childstack->r10 = (unsigned long) args->fn_arg;
  43. childstack->r9 = (unsigned long) args->fn;
  44. childregs->sr = mfcr("psr");
  45. } else {
  46. *childregs = *(current_pt_regs());
  47. if (usp)
  48. childregs->usp = usp;
  49. if (clone_flags & CLONE_SETTLS)
  50. task_thread_info(p)->tp_value = childregs->tls
  51. = tls;
  52. childregs->a0 = 0;
  53. childstack->r15 = (unsigned long) ret_from_fork;
  54. }
  55. return 0;
  56. }
  57. /* Fill in the fpu structure for a core dump. */
  58. int dump_fpu(struct pt_regs *regs, struct user_fp *fpu)
  59. {
  60. memcpy(fpu, &current->thread.user_fp, sizeof(*fpu));
  61. return 1;
  62. }
  63. EXPORT_SYMBOL(dump_fpu);
  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. raw_local_irq_enable();
  84. }
  85. #endif