Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * This file is subject to the terms and conditions of the GNU General Public
0004  * License.  See the file "COPYING" in the main directory of this archive
0005  * for more details.
0006  *
0007  * Some parts derived from x86 version of this file.
0008  *
0009  * Copyright (C) 2013 Cavium, Inc.
0010  */
0011 
0012 #include <linux/perf_event.h>
0013 
0014 #include <asm/ptrace.h>
0015 
0016 #ifdef CONFIG_32BIT
0017 u64 perf_reg_abi(struct task_struct *tsk)
0018 {
0019     return PERF_SAMPLE_REGS_ABI_32;
0020 }
0021 #else /* Must be CONFIG_64BIT */
0022 u64 perf_reg_abi(struct task_struct *tsk)
0023 {
0024     if (test_tsk_thread_flag(tsk, TIF_32BIT_REGS))
0025         return PERF_SAMPLE_REGS_ABI_32;
0026     else
0027         return PERF_SAMPLE_REGS_ABI_64;
0028 }
0029 #endif /* CONFIG_32BIT */
0030 
0031 int perf_reg_validate(u64 mask)
0032 {
0033     if (!mask)
0034         return -EINVAL;
0035     if (mask & ~((1ull << PERF_REG_MIPS_MAX) - 1))
0036         return -EINVAL;
0037     return 0;
0038 }
0039 
0040 u64 perf_reg_value(struct pt_regs *regs, int idx)
0041 {
0042     long v;
0043 
0044     switch (idx) {
0045     case PERF_REG_MIPS_PC:
0046         v = regs->cp0_epc;
0047         break;
0048     case PERF_REG_MIPS_R1 ... PERF_REG_MIPS_R25:
0049         v = regs->regs[idx - PERF_REG_MIPS_R1 + 1];
0050         break;
0051     case PERF_REG_MIPS_R28 ... PERF_REG_MIPS_R31:
0052         v = regs->regs[idx - PERF_REG_MIPS_R28 + 28];
0053         break;
0054 
0055     default:
0056         WARN_ON_ONCE(1);
0057         return 0;
0058     }
0059 
0060     return (s64)v; /* Sign extend if 32-bit. */
0061 }
0062 
0063 void perf_get_regs_user(struct perf_regs *regs_user,
0064             struct pt_regs *regs)
0065 {
0066     regs_user->regs = task_pt_regs(current);
0067     regs_user->abi = perf_reg_abi(current);
0068 }