xref: /openbmc/linux/arch/powerpc/kernel/ptrace/ptrace-fpu.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
14d90eb97SChristophe Leroy // SPDX-License-Identifier: GPL-2.0-or-later
24d90eb97SChristophe Leroy 
34d90eb97SChristophe Leroy #include <linux/regset.h>
44d90eb97SChristophe Leroy 
54d90eb97SChristophe Leroy #include <asm/switch_to.h>
64d90eb97SChristophe Leroy 
74d90eb97SChristophe Leroy #include "ptrace-decl.h"
84d90eb97SChristophe Leroy 
ptrace_get_fpr(struct task_struct * child,int index,unsigned long * data)94d90eb97SChristophe Leroy int ptrace_get_fpr(struct task_struct *child, int index, unsigned long *data)
104d90eb97SChristophe Leroy {
113618250cSChristophe Leroy #ifdef CONFIG_PPC_FPU_REGS
124d90eb97SChristophe Leroy 	unsigned int fpidx = index - PT_FPR0;
133618250cSChristophe Leroy #endif
144d90eb97SChristophe Leroy 
154d90eb97SChristophe Leroy 	if (index > PT_FPSCR)
164d90eb97SChristophe Leroy 		return -EIO;
174d90eb97SChristophe Leroy 
183618250cSChristophe Leroy #ifdef CONFIG_PPC_FPU_REGS
194d90eb97SChristophe Leroy 	flush_fp_to_thread(child);
20*8e127844SMichael Ellerman 	if (fpidx < (PT_FPSCR - PT_FPR0)) {
21*8e127844SMichael Ellerman 		if (IS_ENABLED(CONFIG_PPC32))
22*8e127844SMichael Ellerman 			// On 32-bit the index we are passed refers to 32-bit words
23*8e127844SMichael Ellerman 			*data = ((u32 *)child->thread.fp_state.fpr)[fpidx];
244d90eb97SChristophe Leroy 		else
25*8e127844SMichael Ellerman 			memcpy(data, &child->thread.TS_FPR(fpidx), sizeof(long));
26*8e127844SMichael Ellerman 	} else
274d90eb97SChristophe Leroy 		*data = child->thread.fp_state.fpscr;
283618250cSChristophe Leroy #else
293618250cSChristophe Leroy 	*data = 0;
303618250cSChristophe Leroy #endif
314d90eb97SChristophe Leroy 
324d90eb97SChristophe Leroy 	return 0;
334d90eb97SChristophe Leroy }
344d90eb97SChristophe Leroy 
ptrace_put_fpr(struct task_struct * child,int index,unsigned long data)354d90eb97SChristophe Leroy int ptrace_put_fpr(struct task_struct *child, int index, unsigned long data)
364d90eb97SChristophe Leroy {
373618250cSChristophe Leroy #ifdef CONFIG_PPC_FPU_REGS
384d90eb97SChristophe Leroy 	unsigned int fpidx = index - PT_FPR0;
393618250cSChristophe Leroy #endif
404d90eb97SChristophe Leroy 
414d90eb97SChristophe Leroy 	if (index > PT_FPSCR)
424d90eb97SChristophe Leroy 		return -EIO;
434d90eb97SChristophe Leroy 
443618250cSChristophe Leroy #ifdef CONFIG_PPC_FPU_REGS
454d90eb97SChristophe Leroy 	flush_fp_to_thread(child);
46*8e127844SMichael Ellerman 	if (fpidx < (PT_FPSCR - PT_FPR0)) {
47*8e127844SMichael Ellerman 		if (IS_ENABLED(CONFIG_PPC32))
48*8e127844SMichael Ellerman 			// On 32-bit the index we are passed refers to 32-bit words
49*8e127844SMichael Ellerman 			((u32 *)child->thread.fp_state.fpr)[fpidx] = data;
504d90eb97SChristophe Leroy 		else
51*8e127844SMichael Ellerman 			memcpy(&child->thread.TS_FPR(fpidx), &data, sizeof(long));
52*8e127844SMichael Ellerman 	} else
534d90eb97SChristophe Leroy 		child->thread.fp_state.fpscr = data;
543618250cSChristophe Leroy #endif
554d90eb97SChristophe Leroy 
564d90eb97SChristophe Leroy 	return 0;
574d90eb97SChristophe Leroy }
584d90eb97SChristophe Leroy 
59