1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
4 #include <linux/sched.h>
5 #include <linux/sched/debug.h>
6 #include <linux/sched/task_stack.h>
7 #include <linux/delay.h>
8 #include <linux/kallsyms.h>
9 #include <linux/uaccess.h>
11 #include <asm/proc-fns.h>
12 #include <linux/ptrace.h>
13 #include <linux/reboot.h>
15 extern void setup_mm_for_reboot(char mode);
17 struct proc_dir_entry *proc_dir_cpu;
18 EXPORT_SYMBOL(proc_dir_cpu);
21 extern inline void arch_reset(char mode)
24 /* Use cpu handler, jump to 0 */
29 void (*pm_power_off) (void);
30 EXPORT_SYMBOL(pm_power_off);
32 static char reboot_mode_nds32 = 'h';
34 int __init reboot_setup(char *str)
36 reboot_mode_nds32 = str[0];
40 static int cpub_pwroff(void)
45 __setup("reboot=", reboot_setup);
47 void machine_halt(void)
52 EXPORT_SYMBOL(machine_halt);
54 void machine_power_off(void)
60 EXPORT_SYMBOL(machine_power_off);
62 void machine_restart(char *cmd)
65 * Clean and disable cache, and turn off interrupts
70 * Tell the mm system that we are going to reboot -
71 * we may need it to insert some 1:1 mappings so that
74 setup_mm_for_reboot(reboot_mode_nds32);
76 /* Execute kernel restart handler call chain */
77 do_kernel_restart(cmd);
80 * Now call the architecture specific reboot code.
82 arch_reset(reboot_mode_nds32);
85 * Whoops - the architecture was unable to reboot.
89 pr_info("Reboot failed -- System halted\n");
93 EXPORT_SYMBOL(machine_restart);
95 void show_regs(struct pt_regs *regs)
97 printk("PC is at %pS\n", (void *)instruction_pointer(regs));
98 printk("LP is at %pS\n", (void *)regs->lp);
99 pr_info("pc : [<%08lx>] lp : [<%08lx>] %s\n"
100 "sp : %08lx fp : %08lx gp : %08lx\n",
101 instruction_pointer(regs),
102 regs->lp, print_tainted(), regs->sp, regs->fp, regs->gp);
103 pr_info("r25: %08lx r24: %08lx\n", regs->uregs[25], regs->uregs[24]);
105 pr_info("r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n",
106 regs->uregs[23], regs->uregs[22],
107 regs->uregs[21], regs->uregs[20]);
108 pr_info("r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n",
109 regs->uregs[19], regs->uregs[18],
110 regs->uregs[17], regs->uregs[16]);
111 pr_info("r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n",
112 regs->uregs[15], regs->uregs[14],
113 regs->uregs[13], regs->uregs[12]);
114 pr_info("r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n",
115 regs->uregs[11], regs->uregs[10],
116 regs->uregs[9], regs->uregs[8]);
117 pr_info("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
118 regs->uregs[7], regs->uregs[6], regs->uregs[5], regs->uregs[4]);
119 pr_info("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
120 regs->uregs[3], regs->uregs[2], regs->uregs[1], regs->uregs[0]);
121 pr_info(" IRQs o%s Segment %s\n",
122 interrupts_enabled(regs) ? "n" : "ff",
123 segment_eq(get_fs(), get_ds())? "kernel" : "user");
126 EXPORT_SYMBOL(show_regs);
128 void flush_thread(void)
132 DEFINE_PER_CPU(struct task_struct *, __entry_task);
134 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
135 int copy_thread(unsigned long clone_flags, unsigned long stack_start,
136 unsigned long stk_sz, struct task_struct *p)
138 struct pt_regs *childregs = task_pt_regs(p);
140 memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
142 if (unlikely(p->flags & PF_KTHREAD)) {
143 memset(childregs, 0, sizeof(struct pt_regs));
144 /* kernel thread fn */
145 p->thread.cpu_context.r6 = stack_start;
146 /* kernel thread argument */
147 p->thread.cpu_context.r7 = stk_sz;
149 *childregs = *current_pt_regs();
151 childregs->sp = stack_start;
152 /* child get zero as ret. */
153 childregs->uregs[0] = 0;
155 if (clone_flags & CLONE_SETTLS)
156 childregs->uregs[25] = childregs->uregs[3];
158 /* cpu context switching */
159 p->thread.cpu_context.pc = (unsigned long)ret_from_fork;
160 p->thread.cpu_context.sp = (unsigned long)childregs;
172 * fill in the fpe structure for a core dump...
174 int dump_fpu(struct pt_regs *regs, elf_fpregset_t * fpu)
180 EXPORT_SYMBOL(dump_fpu);
182 unsigned long get_wchan(struct task_struct *p)
184 unsigned long fp, lr;
185 unsigned long stack_start, stack_end;
188 if (!p || p == current || p->state == TASK_RUNNING)
191 if (IS_ENABLED(CONFIG_FRAME_POINTER)) {
192 stack_start = (unsigned long)end_of_stack(p);
193 stack_end = (unsigned long)task_stack_page(p) + THREAD_SIZE;
195 fp = thread_saved_fp(p);
197 if (fp < stack_start || fp > stack_end)
199 lr = ((unsigned long *)fp)[0];
200 if (!in_sched_functions(lr))
202 fp = *(unsigned long *)(fp + 4);
203 } while (count++ < 16);
208 EXPORT_SYMBOL(get_wchan);