16496a23aSMichal Simek /*
26496a23aSMichal Simek * Copyright (C) 2008-2009 Michal Simek <[email protected]>
36496a23aSMichal Simek * Copyright (C) 2008-2009 PetaLogix
46496a23aSMichal Simek * Copyright (C) 2006 Atmark Techno, Inc.
56496a23aSMichal Simek *
66496a23aSMichal Simek * This file is subject to the terms and conditions of the GNU General Public
76496a23aSMichal Simek * License. See the file "COPYING" in the main directory of this archive
86496a23aSMichal Simek * for more details.
96496a23aSMichal Simek */
106496a23aSMichal Simek
11579907e6SMichal Simek #include <linux/cpu.h>
12d64af918SMichal Simek #include <linux/export.h>
136496a23aSMichal Simek #include <linux/sched.h>
14b17b0153SIngo Molnar #include <linux/sched/debug.h>
1529930025SIngo Molnar #include <linux/sched/task.h>
1668db0cf1SIngo Molnar #include <linux/sched/task_stack.h>
176496a23aSMichal Simek #include <linux/pm.h>
186496a23aSMichal Simek #include <linux/tick.h>
196496a23aSMichal Simek #include <linux/bitops.h>
20f3268edbSAl Viro #include <linux/ptrace.h>
21a1f55113SMichal Simek #include <asm/cacheflush.h>
226496a23aSMichal Simek
show_regs(struct pt_regs * regs)236496a23aSMichal Simek void show_regs(struct pt_regs *regs)
246496a23aSMichal Simek {
25a43cb95dSTejun Heo show_regs_print_info(KERN_INFO);
26a43cb95dSTejun Heo
276bd55f0bSMichal Simek pr_info(" Registers dump: mode=%X\r\n", regs->pt_mode);
286bd55f0bSMichal Simek pr_info(" r1=%08lX, r2=%08lX, r3=%08lX, r4=%08lX\n",
296496a23aSMichal Simek regs->r1, regs->r2, regs->r3, regs->r4);
306bd55f0bSMichal Simek pr_info(" r5=%08lX, r6=%08lX, r7=%08lX, r8=%08lX\n",
316496a23aSMichal Simek regs->r5, regs->r6, regs->r7, regs->r8);
326bd55f0bSMichal Simek pr_info(" r9=%08lX, r10=%08lX, r11=%08lX, r12=%08lX\n",
336496a23aSMichal Simek regs->r9, regs->r10, regs->r11, regs->r12);
346bd55f0bSMichal Simek pr_info(" r13=%08lX, r14=%08lX, r15=%08lX, r16=%08lX\n",
356496a23aSMichal Simek regs->r13, regs->r14, regs->r15, regs->r16);
366bd55f0bSMichal Simek pr_info(" r17=%08lX, r18=%08lX, r19=%08lX, r20=%08lX\n",
376496a23aSMichal Simek regs->r17, regs->r18, regs->r19, regs->r20);
386bd55f0bSMichal Simek pr_info(" r21=%08lX, r22=%08lX, r23=%08lX, r24=%08lX\n",
396496a23aSMichal Simek regs->r21, regs->r22, regs->r23, regs->r24);
406bd55f0bSMichal Simek pr_info(" r25=%08lX, r26=%08lX, r27=%08lX, r28=%08lX\n",
416496a23aSMichal Simek regs->r25, regs->r26, regs->r27, regs->r28);
426bd55f0bSMichal Simek pr_info(" r29=%08lX, r30=%08lX, r31=%08lX, rPC=%08lX\n",
436496a23aSMichal Simek regs->r29, regs->r30, regs->r31, regs->pc);
446bd55f0bSMichal Simek pr_info(" msr=%08lX, ear=%08lX, esr=%08lX, fsr=%08lX\n",
456496a23aSMichal Simek regs->msr, regs->ear, regs->esr, regs->fsr);
466496a23aSMichal Simek }
476496a23aSMichal Simek
486496a23aSMichal Simek void (*pm_power_off)(void) = NULL;
496496a23aSMichal Simek EXPORT_SYMBOL(pm_power_off);
506496a23aSMichal Simek
flush_thread(void)516496a23aSMichal Simek void flush_thread(void)
526496a23aSMichal Simek {
536496a23aSMichal Simek }
546496a23aSMichal Simek
copy_thread(struct task_struct * p,const struct kernel_clone_args * args)55c5febea0SEric W. Biederman int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
566496a23aSMichal Simek {
57c5febea0SEric W. Biederman unsigned long clone_flags = args->flags;
58c5febea0SEric W. Biederman unsigned long usp = args->stack;
59c5febea0SEric W. Biederman unsigned long tls = args->tls;
606496a23aSMichal Simek struct pt_regs *childregs = task_pt_regs(p);
616496a23aSMichal Simek struct thread_info *ti = task_thread_info(p);
626496a23aSMichal Simek
635bd2e97cSEric W. Biederman if (unlikely(args->fn)) {
645233806dSMichal Simek /* if we're creating a new kernel thread then just zeroing all
655233806dSMichal Simek * the registers. That's OK for a brand new thread.*/
662319295dSAl Viro memset(childregs, 0, sizeof(struct pt_regs));
675233806dSMichal Simek memset(&ti->cpu_context, 0, sizeof(struct cpu_context));
686e83557cSMichal Simek ti->cpu_context.r1 = (unsigned long)childregs;
695bd2e97cSEric W. Biederman ti->cpu_context.r20 = (unsigned long)args->fn;
705bd2e97cSEric W. Biederman ti->cpu_context.r19 = (unsigned long)args->fn_arg;
712319295dSAl Viro childregs->pt_mode = 1;
722319295dSAl Viro local_save_flags(childregs->msr);
732319295dSAl Viro ti->cpu_context.msr = childregs->msr & ~MSR_IE;
742319295dSAl Viro ti->cpu_context.r15 = (unsigned long)ret_from_kernel_thread - 8;
752319295dSAl Viro return 0;
762319295dSAl Viro }
77f3268edbSAl Viro *childregs = *current_pt_regs();
78f3268edbSAl Viro if (usp)
792319295dSAl Viro childregs->r1 = usp;
802319295dSAl Viro
812319295dSAl Viro memset(&ti->cpu_context, 0, sizeof(struct cpu_context));
822319295dSAl Viro ti->cpu_context.r1 = (unsigned long)childregs;
832319295dSAl Viro childregs->msr |= MSR_UMS;
842319295dSAl Viro
855233806dSMichal Simek /* we should consider the fact that childregs is a copy of the parent
865233806dSMichal Simek * regs which were saved immediately after entering the kernel state
875233806dSMichal Simek * before enabling VM. This MSR will be restored in switch_to and
885233806dSMichal Simek * RETURN() and we want to have the right machine state there
895233806dSMichal Simek * specifically this state must have INTs disabled before and enabled
905233806dSMichal Simek * after performing rtbd
915233806dSMichal Simek * compose the right MSR for RETURN(). It will work for switch_to also
925233806dSMichal Simek * excepting for VM and UMS
935233806dSMichal Simek * don't touch UMS , CARRY and cache bits
945233806dSMichal Simek * right now MSR is a copy of parent one */
955233806dSMichal Simek childregs->msr &= ~MSR_EIP;
965233806dSMichal Simek childregs->msr |= MSR_IE;
975233806dSMichal Simek childregs->msr &= ~MSR_VM;
985233806dSMichal Simek childregs->msr |= MSR_VMS;
995233806dSMichal Simek childregs->msr |= MSR_EE; /* exceptions will be enabled*/
1005233806dSMichal Simek
1015233806dSMichal Simek ti->cpu_context.msr = (childregs->msr|MSR_VM);
1025233806dSMichal Simek ti->cpu_context.msr &= ~MSR_UMS; /* switch_to to kernel mode */
10384ac218fSPeter Zijlstra ti->cpu_context.msr &= ~MSR_IE;
1046496a23aSMichal Simek ti->cpu_context.r15 = (unsigned long)ret_from_fork - 8;
1056496a23aSMichal Simek
106d5c15f17SEdgar E. Iglesias /*
107d5c15f17SEdgar E. Iglesias * r21 is the thread reg, r10 is 6th arg to clone
108d5c15f17SEdgar E. Iglesias * which contains TLS area
109d5c15f17SEdgar E. Iglesias */
1106496a23aSMichal Simek if (clone_flags & CLONE_SETTLS)
111ad1bb82cSChristian Brauner childregs->r21 = tls;
1126496a23aSMichal Simek
1136496a23aSMichal Simek return 0;
1146496a23aSMichal Simek }
1156496a23aSMichal Simek
__get_wchan(struct task_struct * p)11642a20f86SKees Cook unsigned long __get_wchan(struct task_struct *p)
1176496a23aSMichal Simek {
1186496a23aSMichal Simek /* TBD (used by procfs) */
1196496a23aSMichal Simek return 0;
1206496a23aSMichal Simek }
121e1c4bd08SMichal Simek
122e1c4bd08SMichal Simek /* Set up a thread for executing a new program */
start_thread(struct pt_regs * regs,unsigned long pc,unsigned long usp)123e1c4bd08SMichal Simek void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long usp)
124e1c4bd08SMichal Simek {
125e1c4bd08SMichal Simek regs->pc = pc;
126e1c4bd08SMichal Simek regs->r1 = usp;
127e1c4bd08SMichal Simek regs->pt_mode = 0;
128866d7229SJohn Williams regs->msr |= MSR_UMS;
12999c59f60SAl Viro regs->msr &= ~MSR_VM;
130e1c4bd08SMichal Simek }
1315233806dSMichal Simek
1325233806dSMichal Simek #include <linux/elfcore.h>
1335233806dSMichal Simek /*
1345233806dSMichal Simek * Set up a thread for executing a new program
1355233806dSMichal Simek */
elf_core_copy_task_fpregs(struct task_struct * t,elf_fpregset_t * fpu)136*bdbadfccSAl Viro int elf_core_copy_task_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
1375233806dSMichal Simek {
1385233806dSMichal Simek return 0; /* MicroBlaze has no separate FPU registers */
1395233806dSMichal Simek }
140a047775eSMichal Simek
arch_cpu_idle(void)141a047775eSMichal Simek void arch_cpu_idle(void)
142a047775eSMichal Simek {
143a047775eSMichal Simek }
144