^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Architecture-dependent parts of process handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2013 Altera Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2009 Wind River Systems Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2004 Microtronix Datacom Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/cpuinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) asmlinkage void ret_from_fork(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) asmlinkage void ret_from_kernel_thread(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) void (*pm_power_off)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) raw_local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * The development boards have no way to pull a board reset. Just jump to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * cpu reset address and let the boot loader or the code in head.S take care of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * resetting peripherals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void machine_restart(char *__unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __asm__ __volatile__ (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) "jmp %0\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) : "r" (cpuinfo.reset_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) : "r4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void machine_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) pr_notice("Machine halt...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) for (;;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * There is no way to power off the development boards. So just spin for now. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * we ever have a way of resetting a board using a GPIO we should add that here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) void machine_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) pr_notice("Machine power off...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) for (;;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void show_regs(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) pr_notice("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) show_regs_print_info(KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) regs->r1, regs->r2, regs->r3, regs->r4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) regs->r5, regs->r6, regs->r7, regs->r8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) regs->r9, regs->r10, regs->r11, regs->r12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) regs->r13, regs->r14, regs->r15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) pr_notice("ra: %08lx fp: %08lx sp: %08lx gp: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) regs->ra, regs->fp, regs->sp, regs->gp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pr_notice("ea: %08lx estatus: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) regs->ea, regs->estatus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void flush_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct task_struct *p, unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct pt_regs *childregs = task_pt_regs(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct pt_regs *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct switch_stack *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct switch_stack *childstack =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ((struct switch_stack *)childregs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) memset(childstack, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) sizeof(struct switch_stack) + sizeof(struct pt_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) childstack->r16 = usp; /* fn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) childstack->r17 = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) childstack->ra = (unsigned long) ret_from_kernel_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) childregs->estatus = STATUS_PIE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) childregs->sp = (unsigned long) childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) p->thread.ksp = (unsigned long) childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) p->thread.kregs = childregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) *childregs = *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) childregs->r2 = 0; /* Set the return value for the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) childregs->r7 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) stack = ((struct switch_stack *) regs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *childstack = *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) childstack->ra = (unsigned long)ret_from_fork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) p->thread.kregs = childregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) p->thread.ksp = (unsigned long) childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (usp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) childregs->sp = usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Initialize tls register. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) if (clone_flags & CLONE_SETTLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) childstack->r23 = tls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Generic dumping code. Used for panic and debug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void dump(struct pt_regs *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned long *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsigned char *tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) pr_emerg("\nCURRENT PROCESS:\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (current->mm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) (int) current->mm->start_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) (int) current->mm->end_code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) (int) current->mm->start_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) (int) current->mm->end_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) (int) current->mm->end_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) (int) current->mm->brk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) pr_emerg("USER-STACK=%08x KERNEL-STACK=%08x\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) (int) current->mm->start_stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) (int)(((unsigned long) current) + THREAD_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pr_emerg("PC: %08lx\n", fp->ea);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) pr_emerg("SR: %08lx SP: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) (long) fp->estatus, (long) fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pr_emerg("r1: %08lx r2: %08lx r3: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fp->r1, fp->r2, fp->r3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) pr_emerg("r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) fp->r4, fp->r5, fp->r6, fp->r7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_emerg("r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) fp->r8, fp->r9, fp->r10, fp->r11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pr_emerg("r12: %08lx r13: %08lx r14: %08lx r15: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) fp->r12, fp->r13, fp->r14, fp->r15);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pr_emerg("or2: %08lx ra: %08lx fp: %08lx sp: %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) fp->orig_r2, fp->ra, fp->fp, fp->sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) pr_emerg("\nUSP: %08x TRAPFRAME: %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) (unsigned int) fp->sp, (unsigned int) fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) pr_emerg("\nCODE:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) tp = ((unsigned char *) fp->ea) - 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if ((i % 0x10) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) pr_emerg("\n%08x: ", (int) (tp + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pr_emerg("%08x ", (int) *sp++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) pr_emerg("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) pr_emerg("\nKERNEL STACK:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) tp = ((unsigned char *) fp) - 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if ((i % 0x10) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) pr_emerg("\n%08x: ", (int) (tp + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pr_emerg("%08x ", (int) *sp++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) pr_emerg("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pr_emerg("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pr_emerg("\nUSER STACK:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) tp = (unsigned char *) (fp->sp - 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if ((i % 0x10) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pr_emerg("\n%08x: ", (int) (tp + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) pr_emerg("%08x ", (int) *sp++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) pr_emerg("\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) unsigned long get_wchan(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) unsigned long fp, pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long stack_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!p || p == current || p->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) stack_page = (unsigned long)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) fp = ((struct switch_stack *)p->thread.ksp)->fp; /* ;dgt2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (fp < stack_page+sizeof(struct task_struct) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) fp >= 8184+stack_page) /* ;dgt2;tmp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pc = ((unsigned long *)fp)[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (!in_sched_functions(pc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) fp = *(unsigned long *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) } while (count++ < 16); /* ;dgt2;tmp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * Do necessary setup to start up a newly executed thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * Will startup in user mode (status_extension = 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) memset((void *) regs, 0, sizeof(struct pt_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) regs->estatus = ESTATUS_EPIE | ESTATUS_EU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) regs->ea = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) regs->sp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) asmlinkage int nios2_clone(unsigned long clone_flags, unsigned long newsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int __user *parent_tidptr, int __user *child_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .flags = (lower_32_bits(clone_flags) & ~CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) .pidfd = parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .child_tid = child_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .parent_tid = parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .exit_signal = (lower_32_bits(clone_flags) & CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .stack = newsp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .tls = tls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }