18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#include <errno.h>
48c2ecf20Sopenharmony_ci#include <libunwind.h>
58c2ecf20Sopenharmony_ci#include "perf_regs.h"
68c2ecf20Sopenharmony_ci#include "../../util/unwind.h"
78c2ecf20Sopenharmony_ci#include "util/debug.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciint libunwind__arch_reg_id(int regnum)
108c2ecf20Sopenharmony_ci{
118c2ecf20Sopenharmony_ci	switch (regnum) {
128c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R1:
138c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R1;
148c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R2:
158c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R2;
168c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R3:
178c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R3;
188c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R4:
198c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R4;
208c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R5:
218c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R5;
228c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R6:
238c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R6;
248c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R7:
258c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R7;
268c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R8:
278c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R8;
288c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R9:
298c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R9;
308c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R10:
318c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R10;
328c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R11:
338c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R11;
348c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R12:
358c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R12;
368c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R13:
378c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R13;
388c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R14:
398c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R14;
408c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R15:
418c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R15;
428c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R16:
438c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R16;
448c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R17:
458c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R17;
468c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R18:
478c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R18;
488c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R19:
498c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R19;
508c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R20:
518c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R20;
528c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R21:
538c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R21;
548c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R22:
558c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R22;
568c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R23:
578c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R23;
588c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R24:
598c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R24;
608c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R25:
618c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R25;
628c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R26:
638c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R26;
648c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R27:
658c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R27;
668c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R28:
678c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R28;
688c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R29:
698c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R29;
708c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R30:
718c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R30;
728c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_R31:
738c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_R31;
748c2ecf20Sopenharmony_ci	case UNW_LOONGARCH64_PC:
758c2ecf20Sopenharmony_ci		return PERF_REG_LOONGARCH_PC;
768c2ecf20Sopenharmony_ci	default:
778c2ecf20Sopenharmony_ci		pr_err("unwind: invalid reg id %d\n", regnum);
788c2ecf20Sopenharmony_ci		return -EINVAL;
798c2ecf20Sopenharmony_ci	}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	return -EINVAL;
828c2ecf20Sopenharmony_ci}
83