blob: 4f16661cbdbb507a34390df99202e5a73431ea5e [file] [log] [blame]
Jiri Olsa71ad0f52012-08-07 15:20:46 +02001
He Kuang52ffe0f2016-06-03 03:33:22 +00002#ifndef REMOTE_UNWIND_LIBUNWIND
Jiri Olsa71ad0f52012-08-07 15:20:46 +02003#include <errno.h>
4#include <libunwind.h>
5#include "perf_regs.h"
6#include "../../util/unwind.h"
Jiri Olsa84f5d362014-07-14 23:46:48 +02007#include "../../util/debug.h"
He Kuang52ffe0f2016-06-03 03:33:22 +00008#endif
Jiri Olsa71ad0f52012-08-07 15:20:46 +02009
Ingo Molnar89fe8082013-09-30 12:07:11 +020010#ifdef HAVE_ARCH_X86_64_SUPPORT
He Kuang52ffe0f2016-06-03 03:33:22 +000011int LIBUNWIND__ARCH_REG_ID(int regnum)
Jiri Olsa71ad0f52012-08-07 15:20:46 +020012{
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
He Kuang52ffe0f2016-06-03 03:33:22 +000075int LIBUNWIND__ARCH_REG_ID(int regnum)
Jiri Olsa71ad0f52012-08-07 15:20:46 +020076{
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}
Ingo Molnar89fe8082013-09-30 12:07:11 +0200114#endif /* HAVE_ARCH_X86_64_SUPPORT */