1 2 #ifndef REMOTE_UNWIND_LIBUNWIND 3 #include <errno.h> 4 #include <libunwind.h> 5 #include "perf_regs.h" 6 #include "../../util/unwind.h" 7 #include "../../util/debug.h" 8 #endif 9 10 #ifdef HAVE_ARCH_X86_64_SUPPORT 11 int LIBUNWIND__ARCH_REG_ID(int regnum) 12 { 13 int id; 14 15 switch (regnum) { 16 case UNW_X86_64_RAX: 17 id = PERF_REG_X86_AX; 18 break; 19 case UNW_X86_64_RDX: 20 id = PERF_REG_X86_DX; 21 break; 22 case UNW_X86_64_RCX: 23 id = PERF_REG_X86_CX; 24 break; 25 case UNW_X86_64_RBX: 26 id = PERF_REG_X86_BX; 27 break; 28 case UNW_X86_64_RSI: 29 id = PERF_REG_X86_SI; 30 break; 31 case UNW_X86_64_RDI: 32 id = PERF_REG_X86_DI; 33 break; 34 case UNW_X86_64_RBP: 35 id = PERF_REG_X86_BP; 36 break; 37 case UNW_X86_64_RSP: 38 id = PERF_REG_X86_SP; 39 break; 40 case UNW_X86_64_R8: 41 id = PERF_REG_X86_R8; 42 break; 43 case UNW_X86_64_R9: 44 id = PERF_REG_X86_R9; 45 break; 46 case UNW_X86_64_R10: 47 id = PERF_REG_X86_R10; 48 break; 49 case UNW_X86_64_R11: 50 id = PERF_REG_X86_R11; 51 break; 52 case UNW_X86_64_R12: 53 id = PERF_REG_X86_R12; 54 break; 55 case UNW_X86_64_R13: 56 id = PERF_REG_X86_R13; 57 break; 58 case UNW_X86_64_R14: 59 id = PERF_REG_X86_R14; 60 break; 61 case UNW_X86_64_R15: 62 id = PERF_REG_X86_R15; 63 break; 64 case UNW_X86_64_RIP: 65 id = PERF_REG_X86_IP; 66 break; 67 default: 68 pr_err("unwind: invalid reg id %d\n", regnum); 69 return -EINVAL; 70 } 71 72 return id; 73 } 74 #else 75 int LIBUNWIND__ARCH_REG_ID(int regnum) 76 { 77 int id; 78 79 switch (regnum) { 80 case UNW_X86_EAX: 81 id = PERF_REG_X86_AX; 82 break; 83 case UNW_X86_EDX: 84 id = PERF_REG_X86_DX; 85 break; 86 case UNW_X86_ECX: 87 id = PERF_REG_X86_CX; 88 break; 89 case UNW_X86_EBX: 90 id = PERF_REG_X86_BX; 91 break; 92 case UNW_X86_ESI: 93 id = PERF_REG_X86_SI; 94 break; 95 case UNW_X86_EDI: 96 id = PERF_REG_X86_DI; 97 break; 98 case UNW_X86_EBP: 99 id = PERF_REG_X86_BP; 100 break; 101 case UNW_X86_ESP: 102 id = PERF_REG_X86_SP; 103 break; 104 case UNW_X86_EIP: 105 id = PERF_REG_X86_IP; 106 break; 107 default: 108 pr_err("unwind: invalid reg id %d\n", regnum); 109 return -EINVAL; 110 } 111 112 return id; 113 } 114 #endif /* HAVE_ARCH_X86_64_SUPPORT */ 115