18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci#include <errno.h> 48c2ecf20Sopenharmony_ci#include "../../util/debug.h" 58c2ecf20Sopenharmony_ci#ifndef REMOTE_UNWIND_LIBUNWIND 68c2ecf20Sopenharmony_ci#include <libunwind.h> 78c2ecf20Sopenharmony_ci#include "perf_regs.h" 88c2ecf20Sopenharmony_ci#include "../../util/unwind.h" 98c2ecf20Sopenharmony_ci#endif 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifdef HAVE_ARCH_X86_64_SUPPORT 128c2ecf20Sopenharmony_ciint LIBUNWIND__ARCH_REG_ID(int regnum) 138c2ecf20Sopenharmony_ci{ 148c2ecf20Sopenharmony_ci int id; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci switch (regnum) { 178c2ecf20Sopenharmony_ci case UNW_X86_64_RAX: 188c2ecf20Sopenharmony_ci id = PERF_REG_X86_AX; 198c2ecf20Sopenharmony_ci break; 208c2ecf20Sopenharmony_ci case UNW_X86_64_RDX: 218c2ecf20Sopenharmony_ci id = PERF_REG_X86_DX; 228c2ecf20Sopenharmony_ci break; 238c2ecf20Sopenharmony_ci case UNW_X86_64_RCX: 248c2ecf20Sopenharmony_ci id = PERF_REG_X86_CX; 258c2ecf20Sopenharmony_ci break; 268c2ecf20Sopenharmony_ci case UNW_X86_64_RBX: 278c2ecf20Sopenharmony_ci id = PERF_REG_X86_BX; 288c2ecf20Sopenharmony_ci break; 298c2ecf20Sopenharmony_ci case UNW_X86_64_RSI: 308c2ecf20Sopenharmony_ci id = PERF_REG_X86_SI; 318c2ecf20Sopenharmony_ci break; 328c2ecf20Sopenharmony_ci case UNW_X86_64_RDI: 338c2ecf20Sopenharmony_ci id = PERF_REG_X86_DI; 348c2ecf20Sopenharmony_ci break; 358c2ecf20Sopenharmony_ci case UNW_X86_64_RBP: 368c2ecf20Sopenharmony_ci id = PERF_REG_X86_BP; 378c2ecf20Sopenharmony_ci break; 388c2ecf20Sopenharmony_ci case UNW_X86_64_RSP: 398c2ecf20Sopenharmony_ci id = PERF_REG_X86_SP; 408c2ecf20Sopenharmony_ci break; 418c2ecf20Sopenharmony_ci case UNW_X86_64_R8: 428c2ecf20Sopenharmony_ci id = PERF_REG_X86_R8; 438c2ecf20Sopenharmony_ci break; 448c2ecf20Sopenharmony_ci case UNW_X86_64_R9: 458c2ecf20Sopenharmony_ci id = PERF_REG_X86_R9; 468c2ecf20Sopenharmony_ci break; 478c2ecf20Sopenharmony_ci case UNW_X86_64_R10: 488c2ecf20Sopenharmony_ci id = PERF_REG_X86_R10; 498c2ecf20Sopenharmony_ci break; 508c2ecf20Sopenharmony_ci case UNW_X86_64_R11: 518c2ecf20Sopenharmony_ci id = PERF_REG_X86_R11; 528c2ecf20Sopenharmony_ci break; 538c2ecf20Sopenharmony_ci case UNW_X86_64_R12: 548c2ecf20Sopenharmony_ci id = PERF_REG_X86_R12; 558c2ecf20Sopenharmony_ci break; 568c2ecf20Sopenharmony_ci case UNW_X86_64_R13: 578c2ecf20Sopenharmony_ci id = PERF_REG_X86_R13; 588c2ecf20Sopenharmony_ci break; 598c2ecf20Sopenharmony_ci case UNW_X86_64_R14: 608c2ecf20Sopenharmony_ci id = PERF_REG_X86_R14; 618c2ecf20Sopenharmony_ci break; 628c2ecf20Sopenharmony_ci case UNW_X86_64_R15: 638c2ecf20Sopenharmony_ci id = PERF_REG_X86_R15; 648c2ecf20Sopenharmony_ci break; 658c2ecf20Sopenharmony_ci case UNW_X86_64_RIP: 668c2ecf20Sopenharmony_ci id = PERF_REG_X86_IP; 678c2ecf20Sopenharmony_ci break; 688c2ecf20Sopenharmony_ci default: 698c2ecf20Sopenharmony_ci pr_err("unwind: invalid reg id %d\n", regnum); 708c2ecf20Sopenharmony_ci return -EINVAL; 718c2ecf20Sopenharmony_ci } 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci return id; 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci#else 768c2ecf20Sopenharmony_ciint LIBUNWIND__ARCH_REG_ID(int regnum) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci int id; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci switch (regnum) { 818c2ecf20Sopenharmony_ci case UNW_X86_EAX: 828c2ecf20Sopenharmony_ci id = PERF_REG_X86_AX; 838c2ecf20Sopenharmony_ci break; 848c2ecf20Sopenharmony_ci case UNW_X86_EDX: 858c2ecf20Sopenharmony_ci id = PERF_REG_X86_DX; 868c2ecf20Sopenharmony_ci break; 878c2ecf20Sopenharmony_ci case UNW_X86_ECX: 888c2ecf20Sopenharmony_ci id = PERF_REG_X86_CX; 898c2ecf20Sopenharmony_ci break; 908c2ecf20Sopenharmony_ci case UNW_X86_EBX: 918c2ecf20Sopenharmony_ci id = PERF_REG_X86_BX; 928c2ecf20Sopenharmony_ci break; 938c2ecf20Sopenharmony_ci case UNW_X86_ESI: 948c2ecf20Sopenharmony_ci id = PERF_REG_X86_SI; 958c2ecf20Sopenharmony_ci break; 968c2ecf20Sopenharmony_ci case UNW_X86_EDI: 978c2ecf20Sopenharmony_ci id = PERF_REG_X86_DI; 988c2ecf20Sopenharmony_ci break; 998c2ecf20Sopenharmony_ci case UNW_X86_EBP: 1008c2ecf20Sopenharmony_ci id = PERF_REG_X86_BP; 1018c2ecf20Sopenharmony_ci break; 1028c2ecf20Sopenharmony_ci case UNW_X86_ESP: 1038c2ecf20Sopenharmony_ci id = PERF_REG_X86_SP; 1048c2ecf20Sopenharmony_ci break; 1058c2ecf20Sopenharmony_ci case UNW_X86_EIP: 1068c2ecf20Sopenharmony_ci id = PERF_REG_X86_IP; 1078c2ecf20Sopenharmony_ci break; 1088c2ecf20Sopenharmony_ci default: 1098c2ecf20Sopenharmony_ci pr_err("unwind: invalid reg id %d\n", regnum); 1108c2ecf20Sopenharmony_ci return -EINVAL; 1118c2ecf20Sopenharmony_ci } 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci return id; 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci#endif /* HAVE_ARCH_X86_64_SUPPORT */ 116