1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/module.h>
5 #include <linux/version.h>
6 #include <linux/sched.h>
7 #include <linux/sched/task_stack.h>
8 #include <linux/sched/debug.h>
9 #include <linux/delay.h>
10 #include <linux/kallsyms.h>
11 #include <linux/uaccess.h>
12 #include <linux/ptrace.h>
15 #include <abi/reg_ops.h>
17 struct cpuinfo_csky cpu_data
[NR_CPUS
];
19 #ifdef CONFIG_STACKPROTECTOR
20 #include <linux/stackprotector.h>
21 unsigned long __stack_chk_guard __read_mostly
;
22 EXPORT_SYMBOL(__stack_chk_guard
);
25 asmlinkage
void ret_from_fork(void);
26 asmlinkage
void ret_from_kernel_thread(void);
29 * Some archs flush debug and FPU info here
31 void flush_thread(void){}
34 * Return saved PC from a blocked thread
36 unsigned long thread_saved_pc(struct task_struct
*tsk
)
38 struct switch_stack
*sw
= (struct switch_stack
*)tsk
->thread
.ksp
;
43 int copy_thread_tls(unsigned long clone_flags
,
45 unsigned long kthread_arg
,
46 struct task_struct
*p
,
49 struct switch_stack
*childstack
;
50 struct pt_regs
*childregs
= task_pt_regs(p
);
52 #ifdef CONFIG_CPU_HAS_FPU
53 save_to_user_fp(&p
->thread
.user_fp
);
56 childstack
= ((struct switch_stack
*) childregs
) - 1;
57 memset(childstack
, 0, sizeof(struct switch_stack
));
59 /* setup ksp for switch_to !!! */
60 p
->thread
.ksp
= (unsigned long)childstack
;
62 if (unlikely(p
->flags
& PF_KTHREAD
)) {
63 memset(childregs
, 0, sizeof(struct pt_regs
));
64 childstack
->r15
= (unsigned long) ret_from_kernel_thread
;
65 childstack
->r10
= kthread_arg
;
67 childregs
->sr
= mfcr("psr");
69 *childregs
= *(current_pt_regs());
72 if (clone_flags
& CLONE_SETTLS
)
73 task_thread_info(p
)->tp_value
= childregs
->tls
77 childstack
->r15
= (unsigned long) ret_from_fork
;
83 /* Fill in the fpu structure for a core dump. */
84 int dump_fpu(struct pt_regs
*regs
, struct user_fp
*fpu
)
86 memcpy(fpu
, ¤t
->thread
.user_fp
, sizeof(*fpu
));
89 EXPORT_SYMBOL(dump_fpu
);
91 int dump_task_regs(struct task_struct
*tsk
, elf_gregset_t
*pr_regs
)
93 struct pt_regs
*regs
= task_pt_regs(tsk
);
95 /* NOTE: usp is error value. */
96 ELF_CORE_COPY_REGS((*pr_regs
), regs
)
101 unsigned long get_wchan(struct task_struct
*p
)
104 unsigned long *fp
, *stack_start
, *stack_end
;
107 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
110 stack_start
= (unsigned long *)end_of_stack(p
);
111 stack_end
= (unsigned long *)(task_stack_page(p
) + THREAD_SIZE
);
113 fp
= (unsigned long *) thread_saved_fp(p
);
115 if (fp
< stack_start
|| fp
> stack_end
)
117 #ifdef CONFIG_STACKTRACE
119 fp
= (unsigned long *)fp
[0];
123 if (!in_sched_functions(lr
) &&
124 __kernel_text_address(lr
))
126 } while (count
++ < 16);
130 EXPORT_SYMBOL(get_wchan
);
132 #ifndef CONFIG_CPU_PM_NONE
133 void arch_cpu_idle(void)
135 #ifdef CONFIG_CPU_PM_WAIT
136 asm volatile("wait\n");
139 #ifdef CONFIG_CPU_PM_DOZE
140 asm volatile("doze\n");
143 #ifdef CONFIG_CPU_PM_STOP
144 asm volatile("stop\n");