Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/arch/alpha/kernel/process.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 1995  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This file handles the architecture-dependent parts of process handling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/vt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/elfcore.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/hwrpb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/fpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include "proto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include "pci_impl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Power off function, if any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) void (*pm_power_off)(void) = machine_power_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #ifdef CONFIG_ALPHA_WTINT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * Sleep the CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * EV6, LCA45 and QEMU know how to power down, skipping N timer interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	wtint(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	raw_local_irq_enable();
^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) void arch_cpu_idle_dead(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	wtint(INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #endif /* ALPHA_WTINT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) struct halt_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	char *restart_cmd;
^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) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) common_shutdown_1(void *generic_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct halt_info *how = (struct halt_info *)generic_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct percpu_struct *cpup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long *pflags, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int cpuid = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* No point in taking interrupts anymore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	cpup = (struct percpu_struct *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			((unsigned long)hwrpb + hwrpb->processor_offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			 + hwrpb->processor_size * cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	pflags = &cpup->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	flags = *pflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/* Clear reason to "default"; clear "bootstrap in progress". */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	flags &= ~0x00ff0001UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	/* Secondaries halt here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	if (cpuid != boot_cpuid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		flags |= 0x00040000UL; /* "remain halted" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		*pflags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		set_cpu_present(cpuid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		set_cpu_possible(cpuid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (how->mode == LINUX_REBOOT_CMD_RESTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		if (!how->restart_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			flags |= 0x00020000UL; /* "cold bootstrap" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			/* For SRM, we could probably set environment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			   variables to get this to work.  We'd have to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			   delay this until after srm_paging_stop unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			   we ever got srm_fixup working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			   At the moment, SRM will use the last boot device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			   but the file and flags will be the defaults, when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			   doing a "warm" bootstrap.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			flags |= 0x00030000UL; /* "warm bootstrap" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		flags |= 0x00040000UL; /* "remain halted" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	*pflags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/* Wait for the secondaries to halt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	set_cpu_present(boot_cpuid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	set_cpu_possible(boot_cpuid, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	while (cpumask_weight(cpu_present_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* If booted from SRM, reset some of the original environment. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (alpha_using_srm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #ifdef CONFIG_DUMMY_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		/* If we've gotten here after SysRq-b, leave interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		   context before taking over the console. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (in_interrupt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		/* This has the effect of resetting the VGA video origin.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		console_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		do_take_over_console(&dummy_con, 0, MAX_NR_CONSOLES-1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		console_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		pci_restore_srm_config();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		set_hae(srm_hae);
^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) 	if (alpha_mv.kill_arch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		alpha_mv.kill_arch(how->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (! alpha_using_srm && how->mode != LINUX_REBOOT_CMD_RESTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		/* Unfortunately, since MILO doesn't currently understand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		   the hwrpb bits above, we can't reliably halt the 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		   processor and keep it halted.  So just loop.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (alpha_using_srm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		srm_paging_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) common_shutdown(int mode, char *restart_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct halt_info args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	args.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	args.restart_cmd = restart_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	on_each_cpu(common_shutdown_1, &args, 0);
^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) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) machine_restart(char *restart_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	common_shutdown(LINUX_REBOOT_CMD_RESTART, restart_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) machine_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	common_shutdown(LINUX_REBOOT_CMD_HALT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) machine_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	common_shutdown(LINUX_REBOOT_CMD_POWER_OFF, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) /* Used by sysrq-p, among others.  I don't believe r9-r15 are ever
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)    saved in the context it's used.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) show_regs(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	show_regs_print_info(KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	dik_show_regs(regs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * Re-start a thread when doing execve()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	regs->pc = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	regs->ps = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	wrusp(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) EXPORT_SYMBOL(start_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) flush_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* Arrange for each exec'ed process to start off with a clean slate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	   with respect to the FPU.  This is all exceptions disabled.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	current_thread_info()->ieee_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	wrfpcr(FPCR_DYN_NORMAL | ieee_swcr_to_fpcr(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* Clean slate for TLS.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	current_thread_info()->pcb.unique = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) release_thread(struct task_struct *dead_task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * Copy architecture-specific thread state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int copy_thread(unsigned long clone_flags, unsigned long usp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		unsigned long kthread_arg, struct task_struct *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	extern void ret_from_fork(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	extern void ret_from_kernel_thread(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct thread_info *childti = task_thread_info(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct pt_regs *childregs = task_pt_regs(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct switch_stack *childstack, *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	childstack = ((struct switch_stack *) childregs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	childti->pcb.ksp = (unsigned long) childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	childti->pcb.flags = 1;	/* set FEN, clear everything else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		/* kernel thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		memset(childstack, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			sizeof(struct switch_stack) + sizeof(struct pt_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		childstack->r26 = (unsigned long) ret_from_kernel_thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		childstack->r9 = usp;	/* function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		childstack->r10 = kthread_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		childregs->hae = alpha_mv.hae_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		childti->pcb.usp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/* Note: if CLONE_SETTLS is not set, then we must inherit the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	   value from the parent, which will have been set by the block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	   copy in dup_task_struct.  This is non-intuitive, but is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	   required for proper operation in the case of a threaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	   application calling fork.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (clone_flags & CLONE_SETTLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		childti->pcb.unique = tls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		regs->r20 = 0;	/* OSF/1 has some strange fork() semantics.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	childti->pcb.usp = usp ?: rdusp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	*childregs = *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	childregs->r0 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	childregs->r19 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	childregs->r20 = 1;	/* OSF/1 has some strange fork() semantics.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	stack = ((struct switch_stack *) regs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	*childstack = *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	childstack->r26 = (unsigned long) ret_from_fork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * Fill in the user structure for a ELF core dump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dump_elf_thread(elf_greg_t *dest, struct pt_regs *pt, struct thread_info *ti)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/* switch stack follows right below pt_regs: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	dest[ 0] = pt->r0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	dest[ 1] = pt->r1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	dest[ 2] = pt->r2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	dest[ 3] = pt->r3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	dest[ 4] = pt->r4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	dest[ 5] = pt->r5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	dest[ 6] = pt->r6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	dest[ 7] = pt->r7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	dest[ 8] = pt->r8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	dest[ 9] = sw->r9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	dest[10] = sw->r10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	dest[11] = sw->r11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	dest[12] = sw->r12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	dest[13] = sw->r13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	dest[14] = sw->r14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	dest[15] = sw->r15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	dest[16] = pt->r16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	dest[17] = pt->r17;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	dest[18] = pt->r18;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	dest[19] = pt->r19;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	dest[20] = pt->r20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	dest[21] = pt->r21;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	dest[22] = pt->r22;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	dest[23] = pt->r23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	dest[24] = pt->r24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	dest[25] = pt->r25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	dest[26] = pt->r26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	dest[27] = pt->r27;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	dest[28] = pt->r28;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	dest[29] = pt->gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	dest[30] = ti == current_thread_info() ? rdusp() : ti->pcb.usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	dest[31] = pt->pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	/* Once upon a time this was the PS value.  Which is stupid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	   since that is always 8 for usermode.  Usurped for the more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	   useful value of the thread's UNIQUE field.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	dest[32] = ti->pcb.unique;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) EXPORT_SYMBOL(dump_elf_thread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) dump_elf_task(elf_greg_t *dest, struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dump_elf_thread(dest, task_pt_regs(task), task_thread_info(task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) EXPORT_SYMBOL(dump_elf_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) dump_elf_task_fp(elf_fpreg_t *dest, struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct switch_stack *sw = (struct switch_stack *)task_pt_regs(task) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	memcpy(dest, sw->fp, 32 * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) EXPORT_SYMBOL(dump_elf_task_fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * Return saved PC of a blocked thread.  This assumes the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * pointer is the 6th saved long on the kernel stack and that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * saved return address is the first long in the frame.  This all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * holds provided the thread blocked through a call to schedule() ($15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * is the frame pointer in schedule() and $15 is saved at offset 48 by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * entry.S:do_switch_stack).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * Under heavy swap load I've seen this lose in an ugly way.  So do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * some extra sanity checking on the ranges we expect these pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * to be in so that we can fail gracefully.  This is just for ps after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * all.  -- r~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) thread_saved_pc(struct task_struct *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	unsigned long base = (unsigned long)task_stack_page(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	unsigned long fp, sp = task_thread_info(t)->pcb.ksp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (sp > base && sp+6*8 < base + 16*1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		fp = ((unsigned long*)sp)[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		if (fp > sp && fp < base + 16*1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			return *(unsigned long *)fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) get_wchan(struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	unsigned long schedule_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	unsigned long pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (!p || p == current || p->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * This one depends on the frame size of schedule().  Do a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 * "disass schedule" in gdb to find the frame size.  Also, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	 * code assumes that sleep_on() follows immediately after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	 * interruptible_sleep_on() and that add_timer() follows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	 * immediately after interruptible_sleep().  Ugly, isn't it?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	 * Maybe adding a wchan field to task_struct would be better,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	 * after all...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	pc = thread_saved_pc(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	if (in_sched_functions(pc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		schedule_frame = ((unsigned long *)task_thread_info(p)->pcb.ksp)[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return ((unsigned long *)schedule_frame)[12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }