Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 
0003 #include <linux/regset.h>
0004 
0005 #include <asm/switch_to.h>
0006 
0007 #include "ptrace-decl.h"
0008 
0009 int ptrace_get_fpr(struct task_struct *child, int index, unsigned long *data)
0010 {
0011 #ifdef CONFIG_PPC_FPU_REGS
0012     unsigned int fpidx = index - PT_FPR0;
0013 #endif
0014 
0015     if (index > PT_FPSCR)
0016         return -EIO;
0017 
0018 #ifdef CONFIG_PPC_FPU_REGS
0019     flush_fp_to_thread(child);
0020     if (fpidx < (PT_FPSCR - PT_FPR0)) {
0021         if (IS_ENABLED(CONFIG_PPC32))
0022             // On 32-bit the index we are passed refers to 32-bit words
0023             *data = ((u32 *)child->thread.fp_state.fpr)[fpidx];
0024         else
0025             memcpy(data, &child->thread.TS_FPR(fpidx), sizeof(long));
0026     } else
0027         *data = child->thread.fp_state.fpscr;
0028 #else
0029     *data = 0;
0030 #endif
0031 
0032     return 0;
0033 }
0034 
0035 int ptrace_put_fpr(struct task_struct *child, int index, unsigned long data)
0036 {
0037 #ifdef CONFIG_PPC_FPU_REGS
0038     unsigned int fpidx = index - PT_FPR0;
0039 #endif
0040 
0041     if (index > PT_FPSCR)
0042         return -EIO;
0043 
0044 #ifdef CONFIG_PPC_FPU_REGS
0045     flush_fp_to_thread(child);
0046     if (fpidx < (PT_FPSCR - PT_FPR0)) {
0047         if (IS_ENABLED(CONFIG_PPC32))
0048             // On 32-bit the index we are passed refers to 32-bit words
0049             ((u32 *)child->thread.fp_state.fpr)[fpidx] = data;
0050         else
0051             memcpy(&child->thread.TS_FPR(fpidx), &data, sizeof(long));
0052     } else
0053         child->thread.fp_state.fpscr = data;
0054 #endif
0055 
0056     return 0;
0057 }
0058