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