18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013 Cavium, Inc.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
88c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
98c2ecf20Sopenharmony_ci * the Free Software Foundation; either version 2 of the License, or
108c2ecf20Sopenharmony_ci * (at your option) any later version.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful,
138c2ecf20Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
148c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
158c2ecf20Sopenharmony_ci * GNU General Public License for more details.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <stdio.h>
208c2ecf20Sopenharmony_ci#include <errno.h> /* for EINVAL */
218c2ecf20Sopenharmony_ci#include <string.h> /* for strcmp */
228c2ecf20Sopenharmony_ci#include <dwarf-regs.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistruct pt_regs_dwarfnum {
258c2ecf20Sopenharmony_ci	const char *name;
268c2ecf20Sopenharmony_ci	unsigned int dwarfnum;
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic struct pt_regs_dwarfnum loongarch_gpr_table[] = {
308c2ecf20Sopenharmony_ci	{"$0", 0}, {"$1", 1}, {"$2", 2}, {"$3", 3},
318c2ecf20Sopenharmony_ci	{"$4", 4}, {"$5", 5}, {"$6", 6}, {"$7", 7},
328c2ecf20Sopenharmony_ci	{"$8", 8}, {"$9", 9}, {"$10", 10}, {"$11", 11},
338c2ecf20Sopenharmony_ci	{"$12", 12}, {"$13", 13}, {"$14", 14}, {"$15", 15},
348c2ecf20Sopenharmony_ci	{"$16", 16}, {"$17", 17}, {"$18", 18}, {"$19", 19},
358c2ecf20Sopenharmony_ci	{"$20", 20}, {"$21", 21}, {"$22", 22}, {"$23", 23},
368c2ecf20Sopenharmony_ci	{"$24", 24}, {"$25", 25}, {"$26", 26}, {"$27", 27},
378c2ecf20Sopenharmony_ci	{"$28", 28}, {"$29", 29}, {"$30", 30}, {"$31", 31},
388c2ecf20Sopenharmony_ci	{NULL, 0}
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciconst char *get_arch_regstr(unsigned int n)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	n %= 32;
448c2ecf20Sopenharmony_ci	return loongarch_gpr_table[n].name;
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciint regs_query_register_offset(const char *name)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	const struct pt_regs_dwarfnum *roff;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	for (roff = loongarch_gpr_table; roff->name != NULL; roff++)
528c2ecf20Sopenharmony_ci		if (!strcmp(roff->name, name))
538c2ecf20Sopenharmony_ci			return roff->dwarfnum;
548c2ecf20Sopenharmony_ci	return -EINVAL;
558c2ecf20Sopenharmony_ci}
56