162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#include <errno.h>
462306a36Sopenharmony_ci#include <libunwind.h>
562306a36Sopenharmony_ci#include "perf_regs.h"
662306a36Sopenharmony_ci#include "../../util/unwind.h"
762306a36Sopenharmony_ci#include "util/debug.h"
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciint libunwind__arch_reg_id(int regnum)
1062306a36Sopenharmony_ci{
1162306a36Sopenharmony_ci	switch (regnum) {
1262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R1:
1362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R1;
1462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R2:
1562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R2;
1662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R3:
1762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R3;
1862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R4:
1962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R4;
2062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R5:
2162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R5;
2262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R6:
2362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R6;
2462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R7:
2562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R7;
2662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R8:
2762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R8;
2862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R9:
2962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R9;
3062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R10:
3162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R10;
3262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R11:
3362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R11;
3462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R12:
3562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R12;
3662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R13:
3762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R13;
3862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R14:
3962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R14;
4062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R15:
4162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R15;
4262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R16:
4362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R16;
4462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R17:
4562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R17;
4662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R18:
4762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R18;
4862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R19:
4962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R19;
5062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R20:
5162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R20;
5262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R21:
5362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R21;
5462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R22:
5562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R22;
5662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R23:
5762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R23;
5862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R24:
5962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R24;
6062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R25:
6162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R25;
6262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R26:
6362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R26;
6462306a36Sopenharmony_ci	case UNW_LOONGARCH64_R27:
6562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R27;
6662306a36Sopenharmony_ci	case UNW_LOONGARCH64_R28:
6762306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R28;
6862306a36Sopenharmony_ci	case UNW_LOONGARCH64_R29:
6962306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R29;
7062306a36Sopenharmony_ci	case UNW_LOONGARCH64_R30:
7162306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R30;
7262306a36Sopenharmony_ci	case UNW_LOONGARCH64_R31:
7362306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_R31;
7462306a36Sopenharmony_ci	case UNW_LOONGARCH64_PC:
7562306a36Sopenharmony_ci		return PERF_REG_LOONGARCH_PC;
7662306a36Sopenharmony_ci	default:
7762306a36Sopenharmony_ci		pr_err("unwind: invalid reg id %d\n", regnum);
7862306a36Sopenharmony_ci		return -EINVAL;
7962306a36Sopenharmony_ci	}
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci	return -EINVAL;
8262306a36Sopenharmony_ci}
83