xref: /linux/tools/perf/arch/powerpc/util/unwind-libunwind.c (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /*
2  * Copyright 2016 Chandan Kumar, IBM Corporation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 
10 #include <errno.h>
11 #include <libunwind.h>
12 #include <asm/perf_regs.h>
13 #include "../../util/unwind.h"
14 #include "../../util/debug.h"
15 
16 int libunwind__arch_reg_id(int regnum)
17 {
18 	switch (regnum) {
19 	case UNW_PPC64_R0:
20 		return PERF_REG_POWERPC_R0;
21 	case UNW_PPC64_R1:
22 		return PERF_REG_POWERPC_R1;
23 	case UNW_PPC64_R2:
24 		return PERF_REG_POWERPC_R2;
25 	case UNW_PPC64_R3:
26 		return PERF_REG_POWERPC_R3;
27 	case UNW_PPC64_R4:
28 		return PERF_REG_POWERPC_R4;
29 	case UNW_PPC64_R5:
30 		return PERF_REG_POWERPC_R5;
31 	case UNW_PPC64_R6:
32 		return PERF_REG_POWERPC_R6;
33 	case UNW_PPC64_R7:
34 		return PERF_REG_POWERPC_R7;
35 	case UNW_PPC64_R8:
36 		return PERF_REG_POWERPC_R8;
37 	case UNW_PPC64_R9:
38 		return PERF_REG_POWERPC_R9;
39 	case UNW_PPC64_R10:
40 		return PERF_REG_POWERPC_R10;
41 	case UNW_PPC64_R11:
42 		return PERF_REG_POWERPC_R11;
43 	case UNW_PPC64_R12:
44 		return PERF_REG_POWERPC_R12;
45 	case UNW_PPC64_R13:
46 		return PERF_REG_POWERPC_R13;
47 	case UNW_PPC64_R14:
48 		return PERF_REG_POWERPC_R14;
49 	case UNW_PPC64_R15:
50 		return PERF_REG_POWERPC_R15;
51 	case UNW_PPC64_R16:
52 		return PERF_REG_POWERPC_R16;
53 	case UNW_PPC64_R17:
54 		return PERF_REG_POWERPC_R17;
55 	case UNW_PPC64_R18:
56 		return PERF_REG_POWERPC_R18;
57 	case UNW_PPC64_R19:
58 		return PERF_REG_POWERPC_R19;
59 	case UNW_PPC64_R20:
60 		return PERF_REG_POWERPC_R20;
61 	case UNW_PPC64_R21:
62 		return PERF_REG_POWERPC_R21;
63 	case UNW_PPC64_R22:
64 		return PERF_REG_POWERPC_R22;
65 	case UNW_PPC64_R23:
66 		return PERF_REG_POWERPC_R23;
67 	case UNW_PPC64_R24:
68 		return PERF_REG_POWERPC_R24;
69 	case UNW_PPC64_R25:
70 		return PERF_REG_POWERPC_R25;
71 	case UNW_PPC64_R26:
72 		return PERF_REG_POWERPC_R26;
73 	case UNW_PPC64_R27:
74 		return PERF_REG_POWERPC_R27;
75 	case UNW_PPC64_R28:
76 		return PERF_REG_POWERPC_R28;
77 	case UNW_PPC64_R29:
78 		return PERF_REG_POWERPC_R29;
79 	case UNW_PPC64_R30:
80 		return PERF_REG_POWERPC_R30;
81 	case UNW_PPC64_R31:
82 		return PERF_REG_POWERPC_R31;
83 	case UNW_PPC64_LR:
84 		return PERF_REG_POWERPC_LINK;
85 	case UNW_PPC64_CTR:
86 		return PERF_REG_POWERPC_CTR;
87 	case UNW_PPC64_XER:
88 		return PERF_REG_POWERPC_XER;
89 	case UNW_PPC64_NIP:
90 		return PERF_REG_POWERPC_NIP;
91 	default:
92 		pr_err("unwind: invalid reg id %d\n", regnum);
93 		return -EINVAL;
94 	}
95 	return -EINVAL;
96 }
97