Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/perf_event.h>
0003 #include <linux/perf_regs.h>
0004 #include <linux/kernel.h>
0005 #include <linux/errno.h>
0006 #include <linux/bug.h>
0007 #include <asm/ptrace.h>
0008 #include <asm/fpu/api.h>
0009 #include <asm/fpu/types.h>
0010 
0011 u64 perf_reg_value(struct pt_regs *regs, int idx)
0012 {
0013     freg_t fp;
0014 
0015     if (idx >= PERF_REG_S390_R0 && idx <= PERF_REG_S390_R15)
0016         return regs->gprs[idx];
0017 
0018     if (idx >= PERF_REG_S390_FP0 && idx <= PERF_REG_S390_FP15) {
0019         if (!user_mode(regs))
0020             return 0;
0021 
0022         idx -= PERF_REG_S390_FP0;
0023         fp = MACHINE_HAS_VX ? *(freg_t *)(current->thread.fpu.vxrs + idx)
0024                     : current->thread.fpu.fprs[idx];
0025         return fp.ui;
0026     }
0027 
0028     if (idx == PERF_REG_S390_MASK)
0029         return regs->psw.mask;
0030     if (idx == PERF_REG_S390_PC)
0031         return regs->psw.addr;
0032 
0033     WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX);
0034     return 0;
0035 }
0036 
0037 #define REG_RESERVED (~((1UL << PERF_REG_S390_MAX) - 1))
0038 
0039 int perf_reg_validate(u64 mask)
0040 {
0041     if (!mask || mask & REG_RESERVED)
0042         return -EINVAL;
0043 
0044     return 0;
0045 }
0046 
0047 u64 perf_reg_abi(struct task_struct *task)
0048 {
0049     if (test_tsk_thread_flag(task, TIF_31BIT))
0050         return PERF_SAMPLE_REGS_ABI_32;
0051 
0052     return PERF_SAMPLE_REGS_ABI_64;
0053 }
0054 
0055 void perf_get_regs_user(struct perf_regs *regs_user,
0056             struct pt_regs *regs)
0057 {
0058     /*
0059      * Use the regs from the first interruption and let
0060      * perf_sample_regs_intr() handle interrupts (regs == get_irq_regs()).
0061      *
0062      * Also save FPU registers for user-space tasks only.
0063      */
0064     regs_user->regs = task_pt_regs(current);
0065     if (user_mode(regs_user->regs))
0066         save_fpu_regs();
0067     regs_user->abi = perf_reg_abi(current);
0068 }