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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * ptrace for 32-bit processes running on a 64-bit kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  PowerPC version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Derived from "arch/m68k/kernel/ptrace.c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 1994 by Hamish Macdonald
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  Taken from linux/kernel/ptrace.c and modified for M680x0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Modified by Cort Dougan (cort@hq.fsmlabs.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * and Paul Mackerras (paulus@samba.org).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Public License.  See the file COPYING in the main directory of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * this archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/regset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * does not yet catch signals sent when the child dies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * in exit.c or in signal.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /* Macros to workout the correct index for the FPR in the thread struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define FPRHALF(i) (((i) - PT_FPR0) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			compat_ulong_t caddr, compat_ulong_t cdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned long addr = caddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	unsigned long data = cdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	switch (request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	 * Read 4 bytes of the other process' storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	 *  data is a pointer specifying where the user wants the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 *	4 bytes copied into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 *  addr is a pointer in the user's storage that contains an 8 byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 *	address in the other process of the 4 bytes that is to be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 * (this is run in a 32-bit process looking at a 64-bit process)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * when I and D space are separate, these will need to be fixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case PPC_PTRACE_PEEKTEXT_3264:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	case PPC_PTRACE_PEEKDATA_3264: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		u32 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		u32 __user * addrOthers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		/* Get the addr in the other process that we want to read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		copied = ptrace_access_vm(child, (u64)addrOthers, &tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				sizeof(tmp), FOLL_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (copied != sizeof(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		ret = put_user(tmp, (u32 __user *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* Read a register (specified by ADDR) out of the "user area" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	case PTRACE_PEEKUSR: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		/* convert to index and check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		index = (unsigned long) addr >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		if ((addr & 3) || (index > PT_FPSCR32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		CHECK_FULL_REGS(child->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (index < PT_FPR0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			ret = ptrace_get_reg(child, index, &tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			flush_fp_to_thread(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			 * the user space code considers the floating point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			 * to be an array of unsigned int (32 bits) - the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			 * index passed in is based on this assumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			tmp = ((unsigned int *)child->thread.fp_state.fpr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				[FPRINDEX(index)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		ret = put_user((unsigned int)tmp, (u32 __user *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		break;
^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) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * Read 4 bytes out of the other process' pt_regs area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 *  data is a pointer specifying where the user wants the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 *	4 bytes copied into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 *  addr is the offset into the other process' pt_regs structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	 *	that is to be read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	 * (this is run in a 32-bit process looking at a 64-bit process)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case PPC_PTRACE_PEEKUSR_3264: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		u32 reg32bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		u64 tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		u32 numReg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		u32 part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		/* Determine which register the user wants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		index = (u64)addr >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		numReg = index / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		/* Determine which part of the register the user wants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if (index % 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			part = 1;  /* want the 2nd half of the register (right-most). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			part = 0;  /* want the 1st half of the register (left-most). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		/* Validate the input - check to see if address is on the wrong boundary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		 * or beyond the end of the user area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		if ((addr & 3) || numReg > PT_FPSCR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		CHECK_FULL_REGS(child->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		if (numReg >= PT_FPR0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			flush_fp_to_thread(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			/* get 64 bit FPR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			tmp = child->thread.fp_state.fpr[numReg - PT_FPR0][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		} else { /* register within PT_REGS struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			unsigned long tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			ret = ptrace_get_reg(child, numReg, &tmp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			tmp = tmp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		} 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		reg32bits = ((u32*)&tmp)[part];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		ret = put_user(reg32bits, (u32 __user *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	 * Write 4 bytes into the other process' storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 *  data is the 4 bytes that the user wants written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 *  addr is a pointer in the user's storage that contains an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 *	8 byte address in the other process where the 4 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 *	that is to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * (this is run in a 32-bit process looking at a 64-bit process)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * when I and D space are separate, these will need to be fixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	case PPC_PTRACE_POKETEXT_3264:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	case PPC_PTRACE_POKEDATA_3264: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		u32 tmp = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		u32 __user * addrOthers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		/* Get the addr in the other process that we want to write into */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (ptrace_access_vm(child, (u64)addrOthers, &tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 					sizeof(tmp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					FOLL_FORCE | FOLL_WRITE) == sizeof(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* write the word at location addr in the USER area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	case PTRACE_POKEUSR: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		/* convert to index and check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		index = (unsigned long) addr >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		if ((addr & 3) || (index > PT_FPSCR32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		CHECK_FULL_REGS(child->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		if (index < PT_FPR0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			ret = ptrace_put_reg(child, index, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			flush_fp_to_thread(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			 * the user space code considers the floating point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			 * to be an array of unsigned int (32 bits) - the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			 * index passed in is based on this assumption.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			((unsigned int *)child->thread.fp_state.fpr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				[FPRINDEX(index)] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		break;
^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) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 * Write 4 bytes into the other process' pt_regs area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 *  data is the 4 bytes that the user wants written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 *  addr is the offset into the other process' pt_regs structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 *	that is to be written into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 * (this is run in a 32-bit process looking at a 64-bit process)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	case PPC_PTRACE_POKEUSR_3264: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		u32 index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		u32 numReg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		/* Determine which register the user wants */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		index = (u64)addr >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		numReg = index / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		 * Validate the input - check to see if address is on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		 * wrong boundary or beyond the end of the user area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if ((addr & 3) || (numReg > PT_FPSCR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		CHECK_FULL_REGS(child->thread.regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (numReg < PT_FPR0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			unsigned long freg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			ret = ptrace_get_reg(child, numReg, &freg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			if (index % 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				freg = (freg & ~0xfffffffful) | (data & 0xfffffffful);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				freg = (freg & 0xfffffffful) | (data << 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			ret = ptrace_put_reg(child, numReg, freg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			u64 *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			flush_fp_to_thread(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			/* get 64 bit FPR ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			tmp = &child->thread.fp_state.fpr[numReg - PT_FPR0][0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			/* ... write the 32 bit part we want */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			((u32 *)tmp)[index % 2] = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	case PTRACE_GET_DEBUGREG: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #ifndef CONFIG_PPC_ADV_DEBUG_REGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		unsigned long dabr_fake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		/* We only support one DABR and no IABRS at the moment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (addr > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #ifdef CONFIG_PPC_ADV_DEBUG_REGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		ret = put_user(child->thread.debug.dac1, (u32 __user *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		dabr_fake = (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 			(child->thread.hw_brk[0].address & (~HW_BRK_TYPE_DABR)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			(child->thread.hw_brk[0].type & HW_BRK_TYPE_DABR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		ret = put_user(dabr_fake, (u32 __user *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		break;
^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) 	case PTRACE_GETREGS:	/* Get all pt_regs from the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return copy_regset_to_user(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			child, task_user_regset_view(current), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			0, PT_REGS_COUNT * sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			compat_ptr(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	case PTRACE_SETREGS:	/* Set all gp regs in the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return copy_regset_from_user(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			child, task_user_regset_view(current), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			0, PT_REGS_COUNT * sizeof(compat_long_t),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			compat_ptr(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	case PTRACE_GETFPREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	case PTRACE_SETFPREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	case PTRACE_GETVRREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	case PTRACE_SETVRREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	case PTRACE_GETVSRREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	case PTRACE_SETVSRREGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	case PTRACE_GETREGS64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	case PTRACE_SETREGS64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	case PTRACE_KILL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	case PTRACE_SINGLESTEP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	case PTRACE_DETACH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	case PTRACE_SET_DEBUGREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	case PTRACE_SYSCALL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	case PTRACE_CONT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	case PPC_PTRACE_GETHWDBGINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	case PPC_PTRACE_SETHWDEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	case PPC_PTRACE_DELHWDEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		ret = arch_ptrace(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		ret = compat_ptrace_request(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }