1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2d670bd4fSSam Ravnborg /* linux/arch/sparc/kernel/process.c
3d670bd4fSSam Ravnborg *
4d670bd4fSSam Ravnborg * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
5d670bd4fSSam Ravnborg * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
6d670bd4fSSam Ravnborg */
7d670bd4fSSam Ravnborg
8d670bd4fSSam Ravnborg /*
9d670bd4fSSam Ravnborg * This file handles the architecture-dependent parts of process handling..
10d670bd4fSSam Ravnborg */
118bdd5a1bSSam Ravnborg #include <linux/elfcore.h>
12d670bd4fSSam Ravnborg #include <linux/errno.h>
13d670bd4fSSam Ravnborg #include <linux/module.h>
14d670bd4fSSam Ravnborg #include <linux/sched.h>
15b17b0153SIngo Molnar #include <linux/sched/debug.h>
1629930025SIngo Molnar #include <linux/sched/task.h>
1768db0cf1SIngo Molnar #include <linux/sched/task_stack.h>
18d670bd4fSSam Ravnborg #include <linux/kernel.h>
19d670bd4fSSam Ravnborg #include <linux/mm.h>
20d670bd4fSSam Ravnborg #include <linux/stddef.h>
21d670bd4fSSam Ravnborg #include <linux/ptrace.h>
22d670bd4fSSam Ravnborg #include <linux/user.h>
23d670bd4fSSam Ravnborg #include <linux/smp.h>
24d670bd4fSSam Ravnborg #include <linux/reboot.h>
25d670bd4fSSam Ravnborg #include <linux/delay.h>
26d670bd4fSSam Ravnborg #include <linux/pm.h>
275a0e3ad6STejun Heo #include <linux/slab.h>
288bdd5a1bSSam Ravnborg #include <linux/cpu.h>
29d670bd4fSSam Ravnborg
30d670bd4fSSam Ravnborg #include <asm/auxio.h>
31d670bd4fSSam Ravnborg #include <asm/oplib.h>
327c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
33d670bd4fSSam Ravnborg #include <asm/page.h>
34d670bd4fSSam Ravnborg #include <asm/delay.h>
35d670bd4fSSam Ravnborg #include <asm/processor.h>
36d670bd4fSSam Ravnborg #include <asm/psr.h>
37d670bd4fSSam Ravnborg #include <asm/elf.h>
38d670bd4fSSam Ravnborg #include <asm/prom.h>
39d670bd4fSSam Ravnborg #include <asm/unistd.h>
40d550bbd4SDavid Howells #include <asm/setup.h>
41d670bd4fSSam Ravnborg
428bdd5a1bSSam Ravnborg #include "kernel.h"
438bdd5a1bSSam Ravnborg
44d670bd4fSSam Ravnborg /*
45d670bd4fSSam Ravnborg * Power management idle function
46d670bd4fSSam Ravnborg * Set in pm platform drivers (apc.c and pmc.c)
47d670bd4fSSam Ravnborg */
48d472ba84SLen Brown void (*sparc_idle)(void);
49d670bd4fSSam Ravnborg
50d670bd4fSSam Ravnborg /*
51d670bd4fSSam Ravnborg * Power-off handler instantiation for pm.h compliance
52d670bd4fSSam Ravnborg * This is done via auxio, but could be used as a fallback
53d670bd4fSSam Ravnborg * handler when auxio is not present-- unused for now...
54d670bd4fSSam Ravnborg */
55d670bd4fSSam Ravnborg void (*pm_power_off)(void) = machine_power_off;
56d670bd4fSSam Ravnborg EXPORT_SYMBOL(pm_power_off);
57d670bd4fSSam Ravnborg
58d670bd4fSSam Ravnborg /*
59d670bd4fSSam Ravnborg * sysctl - toggle power-off restriction for serial console
60d670bd4fSSam Ravnborg * systems in machine_power_off()
61d670bd4fSSam Ravnborg */
62d670bd4fSSam Ravnborg int scons_pwroff = 1;
63d670bd4fSSam Ravnborg
64d670bd4fSSam Ravnborg extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
65d670bd4fSSam Ravnborg
66d670bd4fSSam Ravnborg struct task_struct *last_task_used_math = NULL;
67d670bd4fSSam Ravnborg struct thread_info *current_set[NR_CPUS];
68d670bd4fSSam Ravnborg
6987fa05aeSSam Ravnborg /* Idle loop support. */
arch_cpu_idle(void)7087fa05aeSSam Ravnborg void arch_cpu_idle(void)
71d670bd4fSSam Ravnborg {
72d472ba84SLen Brown if (sparc_idle)
73d472ba84SLen Brown (*sparc_idle)();
74d670bd4fSSam Ravnborg }
75d670bd4fSSam Ravnborg
76d670bd4fSSam Ravnborg /* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
machine_halt(void)77d670bd4fSSam Ravnborg void machine_halt(void)
78d670bd4fSSam Ravnborg {
79d670bd4fSSam Ravnborg local_irq_enable();
80d670bd4fSSam Ravnborg mdelay(8);
81d670bd4fSSam Ravnborg local_irq_disable();
82d670bd4fSSam Ravnborg prom_halt();
83d670bd4fSSam Ravnborg panic("Halt failed!");
84d670bd4fSSam Ravnborg }
85d670bd4fSSam Ravnborg
machine_restart(char * cmd)86d670bd4fSSam Ravnborg void machine_restart(char * cmd)
87d670bd4fSSam Ravnborg {
88d670bd4fSSam Ravnborg char *p;
89d670bd4fSSam Ravnborg
90d670bd4fSSam Ravnborg local_irq_enable();
91d670bd4fSSam Ravnborg mdelay(8);
92d670bd4fSSam Ravnborg local_irq_disable();
93d670bd4fSSam Ravnborg
94d670bd4fSSam Ravnborg p = strchr (reboot_command, '\n');
95d670bd4fSSam Ravnborg if (p) *p = 0;
96d670bd4fSSam Ravnborg if (cmd)
97d670bd4fSSam Ravnborg prom_reboot(cmd);
98d670bd4fSSam Ravnborg if (*reboot_command)
99d670bd4fSSam Ravnborg prom_reboot(reboot_command);
100d670bd4fSSam Ravnborg prom_feval ("reset");
101d670bd4fSSam Ravnborg panic("Reboot failed!");
102d670bd4fSSam Ravnborg }
103d670bd4fSSam Ravnborg
machine_power_off(void)104d670bd4fSSam Ravnborg void machine_power_off(void)
105d670bd4fSSam Ravnborg {
106d670bd4fSSam Ravnborg if (auxio_power_register &&
10788ca0557SRob Herring (!of_node_is_type(of_console_device, "serial") || scons_pwroff)) {
108d2aca8f9SSam Ravnborg u8 power_register = sbus_readb(auxio_power_register);
109d2aca8f9SSam Ravnborg power_register |= AUXIO_POWER_OFF;
110d2aca8f9SSam Ravnborg sbus_writeb(power_register, auxio_power_register);
111d2aca8f9SSam Ravnborg }
112d2aca8f9SSam Ravnborg
113d670bd4fSSam Ravnborg machine_halt();
114d670bd4fSSam Ravnborg }
115d670bd4fSSam Ravnborg
show_regs(struct pt_regs * r)116d670bd4fSSam Ravnborg void show_regs(struct pt_regs *r)
117d670bd4fSSam Ravnborg {
1184d7b92adSSam Ravnborg struct reg_window32 *rw = (struct reg_window32 *) r->u_regs[14];
119d670bd4fSSam Ravnborg
120a43cb95dSTejun Heo show_regs_print_info(KERN_DEFAULT);
121a43cb95dSTejun Heo
122d670bd4fSSam Ravnborg printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
123d670bd4fSSam Ravnborg r->psr, r->pc, r->npc, r->y, print_tainted());
124d670bd4fSSam Ravnborg printk("PC: <%pS>\n", (void *) r->pc);
125d670bd4fSSam Ravnborg printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
126d670bd4fSSam Ravnborg r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
127d670bd4fSSam Ravnborg r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
128d670bd4fSSam Ravnborg printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
129d670bd4fSSam Ravnborg r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
130d670bd4fSSam Ravnborg r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
131d670bd4fSSam Ravnborg printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
132d670bd4fSSam Ravnborg
133d670bd4fSSam Ravnborg printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
134d670bd4fSSam Ravnborg rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
135d670bd4fSSam Ravnborg rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
136d670bd4fSSam Ravnborg printk("%%I: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
137d670bd4fSSam Ravnborg rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
138d670bd4fSSam Ravnborg rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
139d670bd4fSSam Ravnborg }
140d670bd4fSSam Ravnborg
141d670bd4fSSam Ravnborg /*
1429cb8f069SDmitry Safonov * The show_stack() is external API which we do not use ourselves.
143d670bd4fSSam Ravnborg * The oops is printed in die_if_kernel.
144d670bd4fSSam Ravnborg */
show_stack(struct task_struct * tsk,unsigned long * _ksp,const char * loglvl)1459cb8f069SDmitry Safonov void show_stack(struct task_struct *tsk, unsigned long *_ksp, const char *loglvl)
146d670bd4fSSam Ravnborg {
147d670bd4fSSam Ravnborg unsigned long pc, fp;
148d670bd4fSSam Ravnborg unsigned long task_base;
1494d7b92adSSam Ravnborg struct reg_window32 *rw;
150d670bd4fSSam Ravnborg int count = 0;
151d670bd4fSSam Ravnborg
15289e3f23dSTejun Heo if (!tsk)
15389e3f23dSTejun Heo tsk = current;
154d670bd4fSSam Ravnborg
15589e3f23dSTejun Heo if (tsk == current && !_ksp)
15689e3f23dSTejun Heo __asm__ __volatile__("mov %%fp, %0" : "=r" (_ksp));
15789e3f23dSTejun Heo
15889e3f23dSTejun Heo task_base = (unsigned long) task_stack_page(tsk);
159d670bd4fSSam Ravnborg fp = (unsigned long) _ksp;
160d670bd4fSSam Ravnborg do {
161d670bd4fSSam Ravnborg /* Bogus frame pointer? */
162d670bd4fSSam Ravnborg if (fp < (task_base + sizeof(struct thread_info)) ||
163d670bd4fSSam Ravnborg fp >= (task_base + (PAGE_SIZE << 1)))
164d670bd4fSSam Ravnborg break;
1654d7b92adSSam Ravnborg rw = (struct reg_window32 *) fp;
166d670bd4fSSam Ravnborg pc = rw->ins[7];
16713c6371aSDmitry Safonov printk("%s[%08lx : ", loglvl, pc);
16813c6371aSDmitry Safonov printk("%s%pS ] ", loglvl, (void *) pc);
169d670bd4fSSam Ravnborg fp = rw->ins[6];
170d670bd4fSSam Ravnborg } while (++count < 16);
17113c6371aSDmitry Safonov printk("%s\n", loglvl);
17213c6371aSDmitry Safonov }
17313c6371aSDmitry Safonov
174d670bd4fSSam Ravnborg /*
175d670bd4fSSam Ravnborg * Free current thread data structures etc..
176d670bd4fSSam Ravnborg */
exit_thread(struct task_struct * tsk)177e6464694SJiri Slaby void exit_thread(struct task_struct *tsk)
178d670bd4fSSam Ravnborg {
179d670bd4fSSam Ravnborg #ifndef CONFIG_SMP
180e6464694SJiri Slaby if (last_task_used_math == tsk) {
181d670bd4fSSam Ravnborg #else
1828befe028STiezhu Yang if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {
183d670bd4fSSam Ravnborg #endif
184d670bd4fSSam Ravnborg /* Keep process from leaving FPU in a bogon state. */
185d670bd4fSSam Ravnborg put_psr(get_psr() | PSR_EF);
186e6464694SJiri Slaby fpsave(&tsk->thread.float_regs[0], &tsk->thread.fsr,
187e6464694SJiri Slaby &tsk->thread.fpqueue[0], &tsk->thread.fpqdepth);
188d670bd4fSSam Ravnborg #ifndef CONFIG_SMP
189d670bd4fSSam Ravnborg last_task_used_math = NULL;
190d670bd4fSSam Ravnborg #else
191e6464694SJiri Slaby clear_ti_thread_flag(task_thread_info(tsk), TIF_USEDFPU);
192d670bd4fSSam Ravnborg #endif
193d670bd4fSSam Ravnborg }
194d670bd4fSSam Ravnborg }
195d670bd4fSSam Ravnborg
196d670bd4fSSam Ravnborg void flush_thread(void)
197d670bd4fSSam Ravnborg {
198d670bd4fSSam Ravnborg current_thread_info()->w_saved = 0;
199d670bd4fSSam Ravnborg
200d670bd4fSSam Ravnborg #ifndef CONFIG_SMP
201d670bd4fSSam Ravnborg if(last_task_used_math == current) {
202d670bd4fSSam Ravnborg #else
203d670bd4fSSam Ravnborg if (test_thread_flag(TIF_USEDFPU)) {
204d670bd4fSSam Ravnborg #endif
205d670bd4fSSam Ravnborg /* Clean the fpu. */
206d670bd4fSSam Ravnborg put_psr(get_psr() | PSR_EF);
207d670bd4fSSam Ravnborg fpsave(¤t->thread.float_regs[0], ¤t->thread.fsr,
208d670bd4fSSam Ravnborg ¤t->thread.fpqueue[0], ¤t->thread.fpqdepth);
209d670bd4fSSam Ravnborg #ifndef CONFIG_SMP
210d670bd4fSSam Ravnborg last_task_used_math = NULL;
211d670bd4fSSam Ravnborg #else
212d670bd4fSSam Ravnborg clear_thread_flag(TIF_USEDFPU);
213d670bd4fSSam Ravnborg #endif
214d670bd4fSSam Ravnborg }
215d670bd4fSSam Ravnborg }
216d670bd4fSSam Ravnborg
217d670bd4fSSam Ravnborg static inline struct sparc_stackf __user *
218d670bd4fSSam Ravnborg clone_stackframe(struct sparc_stackf __user *dst,
219d670bd4fSSam Ravnborg struct sparc_stackf __user *src)
220d670bd4fSSam Ravnborg {
221d670bd4fSSam Ravnborg unsigned long size, fp;
222d670bd4fSSam Ravnborg struct sparc_stackf *tmp;
223d670bd4fSSam Ravnborg struct sparc_stackf __user *sp;
224d670bd4fSSam Ravnborg
225d670bd4fSSam Ravnborg if (get_user(tmp, &src->fp))
226d670bd4fSSam Ravnborg return NULL;
227d670bd4fSSam Ravnborg
228d670bd4fSSam Ravnborg fp = (unsigned long) tmp;
229d670bd4fSSam Ravnborg size = (fp - ((unsigned long) src));
230d670bd4fSSam Ravnborg fp = (unsigned long) dst;
231d670bd4fSSam Ravnborg sp = (struct sparc_stackf __user *)(fp - size);
232d670bd4fSSam Ravnborg
233d670bd4fSSam Ravnborg /* do_fork() grabs the parent semaphore, we must release it
234d670bd4fSSam Ravnborg * temporarily so we can build the child clone stack frame
235d670bd4fSSam Ravnborg * without deadlocking.
236d670bd4fSSam Ravnborg */
237d670bd4fSSam Ravnborg if (__copy_user(sp, src, size))
238d670bd4fSSam Ravnborg sp = NULL;
239d670bd4fSSam Ravnborg else if (put_user(fp, &sp->fp))
240d670bd4fSSam Ravnborg sp = NULL;
241d670bd4fSSam Ravnborg
242d670bd4fSSam Ravnborg return sp;
243d670bd4fSSam Ravnborg }
244d670bd4fSSam Ravnborg
245d670bd4fSSam Ravnborg /* Copy a Sparc thread. The fork() return value conventions
246d670bd4fSSam Ravnborg * under SunOS are nothing short of bletcherous:
247d670bd4fSSam Ravnborg * Parent --> %o0 == childs pid, %o1 == 0
248d670bd4fSSam Ravnborg * Child --> %o0 == parents pid, %o1 == 1
249d670bd4fSSam Ravnborg *
250d670bd4fSSam Ravnborg * NOTE: We have a separate fork kpsr/kwim because
251d670bd4fSSam Ravnborg * the parent could change these values between
252d670bd4fSSam Ravnborg * sys_fork invocation and when we reach here
253d670bd4fSSam Ravnborg * if the parent should sleep while trying to
254d670bd4fSSam Ravnborg * allocate the task_struct and kernel stack in
255d670bd4fSSam Ravnborg * do_fork().
256d670bd4fSSam Ravnborg * XXX See comment above sys_vfork in sparc64. todo.
257d670bd4fSSam Ravnborg */
258d670bd4fSSam Ravnborg extern void ret_from_fork(void);
259c78e0643SAl Viro extern void ret_from_kernel_thread(void);
260d670bd4fSSam Ravnborg
261c5febea0SEric W. Biederman int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
262d670bd4fSSam Ravnborg {
263c5febea0SEric W. Biederman unsigned long clone_flags = args->flags;
264c5febea0SEric W. Biederman unsigned long sp = args->stack;
265c5febea0SEric W. Biederman unsigned long tls = args->tls;
266d670bd4fSSam Ravnborg struct thread_info *ti = task_thread_info(p);
267afa86fc4SAl Viro struct pt_regs *childregs, *regs = current_pt_regs();
268d670bd4fSSam Ravnborg char *new_stack;
269d670bd4fSSam Ravnborg
270d670bd4fSSam Ravnborg #ifndef CONFIG_SMP
271d670bd4fSSam Ravnborg if(last_task_used_math == current) {
272d670bd4fSSam Ravnborg #else
273d670bd4fSSam Ravnborg if (test_thread_flag(TIF_USEDFPU)) {
274d670bd4fSSam Ravnborg #endif
275d670bd4fSSam Ravnborg put_psr(get_psr() | PSR_EF);
276d670bd4fSSam Ravnborg fpsave(&p->thread.float_regs[0], &p->thread.fsr,
277d670bd4fSSam Ravnborg &p->thread.fpqueue[0], &p->thread.fpqdepth);
278d670bd4fSSam Ravnborg }
279d670bd4fSSam Ravnborg
280d670bd4fSSam Ravnborg /*
281c78e0643SAl Viro * p->thread_info new_stack childregs stack bottom
282c78e0643SAl Viro * ! ! ! !
283c78e0643SAl Viro * V V (stk.fr.) V (pt_regs) V
284c78e0643SAl Viro * +----- - - - - - ------+===========+=============+
285d670bd4fSSam Ravnborg */
286d670bd4fSSam Ravnborg new_stack = task_stack_page(p) + THREAD_SIZE;
287d670bd4fSSam Ravnborg new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
288d670bd4fSSam Ravnborg childregs = (struct pt_regs *) (new_stack + STACKFRAME_SZ);
289d670bd4fSSam Ravnborg
290d670bd4fSSam Ravnborg /*
291bef033a3SIngo Molnar * A new process must start with interrupts disabled, see schedule_tail()
292bef033a3SIngo Molnar * and finish_task_switch(). (If we do not do it and if a timer interrupt
293bef033a3SIngo Molnar * hits before we unlock and attempts to take the rq->lock, we deadlock.)
294bef033a3SIngo Molnar *
295d670bd4fSSam Ravnborg * Thus, kpsr |= PSR_PIL.
296d670bd4fSSam Ravnborg */
297d670bd4fSSam Ravnborg ti->ksp = (unsigned long) new_stack;
298c78e0643SAl Viro p->thread.kregs = childregs;
299d670bd4fSSam Ravnborg
300*5bd2e97cSEric W. Biederman if (unlikely(args->fn)) {
301c78e0643SAl Viro extern int nwindows;
302c78e0643SAl Viro unsigned long psr;
303c78e0643SAl Viro memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ);
304c78e0643SAl Viro ti->kpc = (((unsigned long) ret_from_kernel_thread) - 0x8);
305*5bd2e97cSEric W. Biederman childregs->u_regs[UREG_G1] = (unsigned long) args->fn;
306*5bd2e97cSEric W. Biederman childregs->u_regs[UREG_G2] = (unsigned long) args->fn_arg;
307c78e0643SAl Viro psr = childregs->psr = get_psr();
308c78e0643SAl Viro ti->kpsr = psr | PSR_PIL;
309c78e0643SAl Viro ti->kwim = 1 << (((psr & PSR_CWP) + 1) % nwindows);
310c78e0643SAl Viro return 0;
311c78e0643SAl Viro }
312c78e0643SAl Viro memcpy(new_stack, (char *)regs - STACKFRAME_SZ, STACKFRAME_SZ + TRACEREG_SZ);
313d670bd4fSSam Ravnborg childregs->u_regs[UREG_FP] = sp;
314c78e0643SAl Viro ti->kpc = (((unsigned long) ret_from_fork) - 0x8);
315c78e0643SAl Viro ti->kpsr = current->thread.fork_kpsr | PSR_PIL;
316c78e0643SAl Viro ti->kwim = current->thread.fork_kwim;
317d670bd4fSSam Ravnborg
318d670bd4fSSam Ravnborg if (sp != regs->u_regs[UREG_FP]) {
319d670bd4fSSam Ravnborg struct sparc_stackf __user *childstack;
320d670bd4fSSam Ravnborg struct sparc_stackf __user *parentstack;
321d670bd4fSSam Ravnborg
322d670bd4fSSam Ravnborg /*
323d670bd4fSSam Ravnborg * This is a clone() call with supplied user stack.
324d670bd4fSSam Ravnborg * Set some valid stack frames to give to the child.
325d670bd4fSSam Ravnborg */
326d670bd4fSSam Ravnborg childstack = (struct sparc_stackf __user *)
327440ab7acSDavid S. Miller (sp & ~0xfUL);
328d670bd4fSSam Ravnborg parentstack = (struct sparc_stackf __user *)
329d670bd4fSSam Ravnborg regs->u_regs[UREG_FP];
330d670bd4fSSam Ravnborg
331d670bd4fSSam Ravnborg #if 0
332d670bd4fSSam Ravnborg printk("clone: parent stack:\n");
333d670bd4fSSam Ravnborg show_stackframe(parentstack);
334d670bd4fSSam Ravnborg #endif
335d670bd4fSSam Ravnborg
336d670bd4fSSam Ravnborg childstack = clone_stackframe(childstack, parentstack);
337d670bd4fSSam Ravnborg if (!childstack)
338d670bd4fSSam Ravnborg return -EFAULT;
339d670bd4fSSam Ravnborg
340d670bd4fSSam Ravnborg #if 0
341d670bd4fSSam Ravnborg printk("clone: child stack:\n");
342d670bd4fSSam Ravnborg show_stackframe(childstack);
343d670bd4fSSam Ravnborg #endif
344d670bd4fSSam Ravnborg
345d670bd4fSSam Ravnborg childregs->u_regs[UREG_FP] = (unsigned long)childstack;
346d670bd4fSSam Ravnborg }
347d670bd4fSSam Ravnborg
348d670bd4fSSam Ravnborg #ifdef CONFIG_SMP
349d670bd4fSSam Ravnborg /* FPU must be disabled on SMP. */
350d670bd4fSSam Ravnborg childregs->psr &= ~PSR_EF;
351427f23cbSTkhai Kirill clear_tsk_thread_flag(p, TIF_USEDFPU);
352d670bd4fSSam Ravnborg #endif
353d670bd4fSSam Ravnborg
354d670bd4fSSam Ravnborg /* Set the return value for the child. */
355d670bd4fSSam Ravnborg childregs->u_regs[UREG_I0] = current->pid;
356d670bd4fSSam Ravnborg childregs->u_regs[UREG_I1] = 1;
357d670bd4fSSam Ravnborg
358d670bd4fSSam Ravnborg /* Set the return value for the parent. */
359d670bd4fSSam Ravnborg regs->u_regs[UREG_I1] = 0;
360d670bd4fSSam Ravnborg
361d670bd4fSSam Ravnborg if (clone_flags & CLONE_SETTLS)
3627694f514SChristian Brauner childregs->u_regs[UREG_G7] = tls;
363d670bd4fSSam Ravnborg
364d670bd4fSSam Ravnborg return 0;
365d670bd4fSSam Ravnborg }
366d670bd4fSSam Ravnborg
36742a20f86SKees Cook unsigned long __get_wchan(struct task_struct *task)
368d670bd4fSSam Ravnborg {
369d670bd4fSSam Ravnborg unsigned long pc, fp, bias = 0;
370d670bd4fSSam Ravnborg unsigned long task_base = (unsigned long) task;
371d670bd4fSSam Ravnborg unsigned long ret = 0;
3724d7b92adSSam Ravnborg struct reg_window32 *rw;
373d670bd4fSSam Ravnborg int count = 0;
374d670bd4fSSam Ravnborg
375d670bd4fSSam Ravnborg fp = task_thread_info(task)->ksp + bias;
376d670bd4fSSam Ravnborg do {
377d670bd4fSSam Ravnborg /* Bogus frame pointer? */
378d670bd4fSSam Ravnborg if (fp < (task_base + sizeof(struct thread_info)) ||
379d670bd4fSSam Ravnborg fp >= (task_base + (2 * PAGE_SIZE)))
380d670bd4fSSam Ravnborg break;
3814d7b92adSSam Ravnborg rw = (struct reg_window32 *) fp;
382d670bd4fSSam Ravnborg pc = rw->ins[7];
383d670bd4fSSam Ravnborg if (!in_sched_functions(pc)) {
384d670bd4fSSam Ravnborg ret = pc;
385d670bd4fSSam Ravnborg goto out;
386d670bd4fSSam Ravnborg }
387d670bd4fSSam Ravnborg fp = rw->ins[6] + bias;
388d670bd4fSSam Ravnborg } while (++count < 16);
389d670bd4fSSam Ravnborg
390d670bd4fSSam Ravnborg out:
391d670bd4fSSam Ravnborg return ret;
392d670bd4fSSam Ravnborg }
393d670bd4fSSam Ravnborg
394