aboutsummaryrefslogtreecommitdiff
path: root/tools/perf/arch/x86/util/unwind-libunwind.c
blob: db25e93d989ced4f74f2f9b61b56a00ea1e429b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

#include <errno.h>
#include <libunwind.h>
#include "perf_regs.h"
#include "../../util/unwind.h"
#include "../../util/debug.h"

#ifdef HAVE_ARCH_X86_64_SUPPORT
int libunwind__arch_reg_id(int regnum)
{
	int id;

	switch (regnum) {
	case UNW_X86_64_RAX:
		id = PERF_REG_X86_AX;
		break;
	case UNW_X86_64_RDX:
		id = PERF_REG_X86_DX;
		break;
	case UNW_X86_64_RCX:
		id = PERF_REG_X86_CX;
		break;
	case UNW_X86_64_RBX:
		id = PERF_REG_X86_BX;
		break;
	case UNW_X86_64_RSI:
		id = PERF_REG_X86_SI;
		break;
	case UNW_X86_64_RDI:
		id = PERF_REG_X86_DI;
		break;
	case UNW_X86_64_RBP:
		id = PERF_REG_X86_BP;
		break;
	case UNW_X86_64_RSP:
		id = PERF_REG_X86_SP;
		break;
	case UNW_X86_64_R8:
		id = PERF_REG_X86_R8;
		break;
	case UNW_X86_64_R9:
		id = PERF_REG_X86_R9;
		break;
	case UNW_X86_64_R10:
		id = PERF_REG_X86_R10;
		break;
	case UNW_X86_64_R11:
		id = PERF_REG_X86_R11;
		break;
	case UNW_X86_64_R12:
		id = PERF_REG_X86_R12;
		break;
	case UNW_X86_64_R13:
		id = PERF_REG_X86_R13;
		break;
	case UNW_X86_64_R14:
		id = PERF_REG_X86_R14;
		break;
	case UNW_X86_64_R15:
		id = PERF_REG_X86_R15;
		break;
	case UNW_X86_64_RIP:
		id = PERF_REG_X86_IP;
		break;
	default:
		pr_err("unwind: invalid reg id %d\n", regnum);
		return -EINVAL;
	}

	return id;
}
#else
int libunwind__arch_reg_id(int regnum)
{
	int id;

	switch (regnum) {
	case UNW_X86_EAX:
		id = PERF_REG_X86_AX;
		break;
	case UNW_X86_EDX:
		id = PERF_REG_X86_DX;
		break;
	case UNW_X86_ECX:
		id = PERF_REG_X86_CX;
		break;
	case UNW_X86_EBX:
		id = PERF_REG_X86_BX;
		break;
	case UNW_X86_ESI:
		id = PERF_REG_X86_SI;
		break;
	case UNW_X86_EDI:
		id = PERF_REG_X86_DI;
		break;
	case UNW_X86_EBP:
		id = PERF_REG_X86_BP;
		break;
	case UNW_X86_ESP:
		id = PERF_REG_X86_SP;
		break;
	case UNW_X86_EIP:
		id = PERF_REG_X86_IP;
		break;
	default:
		pr_err("unwind: invalid reg id %d\n", regnum);
		return -EINVAL;
	}

	return id;
}
#endif /* HAVE_ARCH_X86_64_SUPPORT */