]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/cris/arch-v10/kernel/process.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-bionic-kernel.git] / arch / cris / arch-v10 / kernel / process.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/cris/kernel/process.c
4 *
5 * Copyright (C) 1995 Linus Torvalds
6 * Copyright (C) 2000-2002 Axis Communications AB
7 *
8 * Authors: Bjorn Wesen (bjornw@axis.com)
9 * Mikael Starvik (starvik@axis.com)
10 *
11 * This file handles the architecture-dependent parts of process handling..
12 */
13
14 #include <linux/sched.h>
15 #include <linux/sched/debug.h>
16 #include <linux/sched/task.h>
17 #include <linux/sched/task_stack.h>
18 #include <linux/slab.h>
19 #include <linux/err.h>
20 #include <linux/fs.h>
21 #include <arch/svinto.h>
22 #include <linux/init.h>
23 #include <arch/system.h>
24 #include <linux/ptrace.h>
25
26 #ifdef CONFIG_ETRAX_GPIO
27 void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
28 #endif
29
30 /*
31 * We use this if we don't have any better
32 * idle routine..
33 */
34 void default_idle(void)
35 {
36 #ifdef CONFIG_ETRAX_GPIO
37 etrax_gpio_wake_up_check();
38 #endif
39 local_irq_enable();
40 }
41
42 /* if the watchdog is enabled, we can simply disable interrupts and go
43 * into an eternal loop, and the watchdog will reset the CPU after 0.1s
44 * if on the other hand the watchdog wasn't enabled, we just enable it and wait
45 */
46
47 void hard_reset_now (void)
48 {
49 /*
50 * Don't declare this variable elsewhere. We don't want any other
51 * code to know about it than the watchdog handler in entry.S and
52 * this code, implementing hard reset through the watchdog.
53 */
54 #if defined(CONFIG_ETRAX_WATCHDOG)
55 extern int cause_of_death;
56 #endif
57
58 printk("*** HARD RESET ***\n");
59 local_irq_disable();
60
61 #if defined(CONFIG_ETRAX_WATCHDOG)
62 cause_of_death = 0xbedead;
63 #else
64 /* Since we dont plan to keep on resetting the watchdog,
65 the key can be arbitrary hence three */
66 *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
67 IO_STATE(R_WATCHDOG, enable, start);
68 #endif
69
70 while(1) /* waiting for RETRIBUTION! */ ;
71 }
72
73 /* setup the child's kernel stack with a pt_regs and switch_stack on it.
74 * it will be un-nested during _resume and _ret_from_sys_call when the
75 * new thread is scheduled.
76 *
77 * also setup the thread switching structure which is used to keep
78 * thread-specific data during _resumes.
79 *
80 */
81 asmlinkage void ret_from_fork(void);
82 asmlinkage void ret_from_kernel_thread(void);
83
84 int copy_thread(unsigned long clone_flags, unsigned long usp,
85 unsigned long arg, struct task_struct *p)
86 {
87 struct pt_regs *childregs = task_pt_regs(p);
88 struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
89
90 /* put the pt_regs structure at the end of the new kernel stack page and fix it up
91 * remember that the task_struct doubles as the kernel stack for the task
92 */
93
94 if (unlikely(p->flags & PF_KTHREAD)) {
95 memset(swstack, 0,
96 sizeof(struct switch_stack) + sizeof(struct pt_regs));
97 swstack->r1 = usp;
98 swstack->r2 = arg;
99 childregs->dccr = 1 << I_DCCR_BITNR;
100 swstack->return_ip = (unsigned long) ret_from_kernel_thread;
101 p->thread.ksp = (unsigned long) swstack;
102 p->thread.usp = 0;
103 return 0;
104 }
105 *childregs = *current_pt_regs(); /* struct copy of pt_regs */
106
107 childregs->r10 = 0; /* child returns 0 after a fork/clone */
108
109 /* put the switch stack right below the pt_regs */
110
111 swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
112
113 /* we want to return into ret_from_sys_call after the _resume */
114
115 swstack->return_ip = (unsigned long) ret_from_fork; /* Will call ret_from_sys_call */
116
117 /* fix the user-mode stackpointer */
118
119 p->thread.usp = usp ?: rdusp();
120
121 /* and the kernel-mode one */
122
123 p->thread.ksp = (unsigned long) swstack;
124
125 #ifdef DEBUG
126 printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
127 show_registers(childregs);
128 #endif
129
130 return 0;
131 }
132
133 unsigned long get_wchan(struct task_struct *p)
134 {
135 #if 0
136 /* YURGH. TODO. */
137
138 unsigned long ebp, esp, eip;
139 unsigned long stack_page;
140 int count = 0;
141 if (!p || p == current || p->state == TASK_RUNNING)
142 return 0;
143 stack_page = (unsigned long)p;
144 esp = p->thread.esp;
145 if (!stack_page || esp < stack_page || esp > 8188+stack_page)
146 return 0;
147 /* include/asm-i386/system.h:switch_to() pushes ebp last. */
148 ebp = *(unsigned long *) esp;
149 do {
150 if (ebp < stack_page || ebp > 8184+stack_page)
151 return 0;
152 eip = *(unsigned long *) (ebp+4);
153 if (!in_sched_functions(eip))
154 return eip;
155 ebp = *(unsigned long *) ebp;
156 } while (count++ < 16);
157 #endif
158 return 0;
159 }
160 #undef last_sched
161 #undef first_sched
162
163 void show_regs(struct pt_regs * regs)
164 {
165 unsigned long usp = rdusp();
166
167 show_regs_print_info(KERN_DEFAULT);
168
169 printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
170 regs->irp, regs->srp, regs->dccr, usp, regs->mof );
171 printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
172 regs->r0, regs->r1, regs->r2, regs->r3);
173 printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
174 regs->r4, regs->r5, regs->r6, regs->r7);
175 printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
176 regs->r8, regs->r9, regs->r10, regs->r11);
177 printk("r12: %08lx r13: %08lx oR10: %08lx\n",
178 regs->r12, regs->r13, regs->orig_r10);
179 }
180