Merge branch 'acpi-pm'
[linux-2.6-microblaze.git] / arch / powerpc / kernel / ptrace / ptrace-fpu.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 #include <linux/regset.h>
4
5 #include <asm/switch_to.h>
6
7 #include "ptrace-decl.h"
8
9 int ptrace_get_fpr(struct task_struct *child, int index, unsigned long *data)
10 {
11 #ifdef CONFIG_PPC_FPU_REGS
12         unsigned int fpidx = index - PT_FPR0;
13 #endif
14
15         if (index > PT_FPSCR)
16                 return -EIO;
17
18 #ifdef CONFIG_PPC_FPU_REGS
19         flush_fp_to_thread(child);
20         if (fpidx < (PT_FPSCR - PT_FPR0))
21                 memcpy(data, &child->thread.TS_FPR(fpidx), sizeof(long));
22         else
23                 *data = child->thread.fp_state.fpscr;
24 #else
25         *data = 0;
26 #endif
27
28         return 0;
29 }
30
31 int ptrace_put_fpr(struct task_struct *child, int index, unsigned long data)
32 {
33 #ifdef CONFIG_PPC_FPU_REGS
34         unsigned int fpidx = index - PT_FPR0;
35 #endif
36
37         if (index > PT_FPSCR)
38                 return -EIO;
39
40 #ifdef CONFIG_PPC_FPU_REGS
41         flush_fp_to_thread(child);
42         if (fpidx < (PT_FPSCR - PT_FPR0))
43                 memcpy(&child->thread.TS_FPR(fpidx), &data, sizeof(long));
44         else
45                 child->thread.fp_state.fpscr = data;
46 #endif
47
48         return 0;
49 }
50