1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <errno.h>
4 #include <libunwind.h>
5 #include "perf_regs.h"
6 #include "../../util/unwind.h"
7 #include "util/debug.h"
8 
9 int libunwind__arch_reg_id(int regnum)
10 {
11 	switch (regnum) {
12 	case UNW_LOONGARCH64_R1:
13 		return PERF_REG_LOONGARCH_R1;
14 	case UNW_LOONGARCH64_R2:
15 		return PERF_REG_LOONGARCH_R2;
16 	case UNW_LOONGARCH64_R3:
17 		return PERF_REG_LOONGARCH_R3;
18 	case UNW_LOONGARCH64_R4:
19 		return PERF_REG_LOONGARCH_R4;
20 	case UNW_LOONGARCH64_R5:
21 		return PERF_REG_LOONGARCH_R5;
22 	case UNW_LOONGARCH64_R6:
23 		return PERF_REG_LOONGARCH_R6;
24 	case UNW_LOONGARCH64_R7:
25 		return PERF_REG_LOONGARCH_R7;
26 	case UNW_LOONGARCH64_R8:
27 		return PERF_REG_LOONGARCH_R8;
28 	case UNW_LOONGARCH64_R9:
29 		return PERF_REG_LOONGARCH_R9;
30 	case UNW_LOONGARCH64_R10:
31 		return PERF_REG_LOONGARCH_R10;
32 	case UNW_LOONGARCH64_R11:
33 		return PERF_REG_LOONGARCH_R11;
34 	case UNW_LOONGARCH64_R12:
35 		return PERF_REG_LOONGARCH_R12;
36 	case UNW_LOONGARCH64_R13:
37 		return PERF_REG_LOONGARCH_R13;
38 	case UNW_LOONGARCH64_R14:
39 		return PERF_REG_LOONGARCH_R14;
40 	case UNW_LOONGARCH64_R15:
41 		return PERF_REG_LOONGARCH_R15;
42 	case UNW_LOONGARCH64_R16:
43 		return PERF_REG_LOONGARCH_R16;
44 	case UNW_LOONGARCH64_R17:
45 		return PERF_REG_LOONGARCH_R17;
46 	case UNW_LOONGARCH64_R18:
47 		return PERF_REG_LOONGARCH_R18;
48 	case UNW_LOONGARCH64_R19:
49 		return PERF_REG_LOONGARCH_R19;
50 	case UNW_LOONGARCH64_R20:
51 		return PERF_REG_LOONGARCH_R20;
52 	case UNW_LOONGARCH64_R21:
53 		return PERF_REG_LOONGARCH_R21;
54 	case UNW_LOONGARCH64_R22:
55 		return PERF_REG_LOONGARCH_R22;
56 	case UNW_LOONGARCH64_R23:
57 		return PERF_REG_LOONGARCH_R23;
58 	case UNW_LOONGARCH64_R24:
59 		return PERF_REG_LOONGARCH_R24;
60 	case UNW_LOONGARCH64_R25:
61 		return PERF_REG_LOONGARCH_R25;
62 	case UNW_LOONGARCH64_R26:
63 		return PERF_REG_LOONGARCH_R26;
64 	case UNW_LOONGARCH64_R27:
65 		return PERF_REG_LOONGARCH_R27;
66 	case UNW_LOONGARCH64_R28:
67 		return PERF_REG_LOONGARCH_R28;
68 	case UNW_LOONGARCH64_R29:
69 		return PERF_REG_LOONGARCH_R29;
70 	case UNW_LOONGARCH64_R30:
71 		return PERF_REG_LOONGARCH_R30;
72 	case UNW_LOONGARCH64_R31:
73 		return PERF_REG_LOONGARCH_R31;
74 	case UNW_LOONGARCH64_PC:
75 		return PERF_REG_LOONGARCH_PC;
76 	default:
77 		pr_err("unwind: invalid reg id %d\n", regnum);
78 		return -EINVAL;
79 	}
80 
81 	return -EINVAL;
82 }
83