1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
4 *
5 * Copyright (C) 2013 Cavium, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19 #include <stdio.h>
20 #include <errno.h> /* for EINVAL */
21 #include <string.h> /* for strcmp */
22 #include <dwarf-regs.h>
23
24 struct pt_regs_dwarfnum {
25 const char *name;
26 unsigned int dwarfnum;
27 };
28
29 static struct pt_regs_dwarfnum loongarch_gpr_table[] = {
30 {"$0", 0}, {"$1", 1}, {"$2", 2}, {"$3", 3},
31 {"$4", 4}, {"$5", 5}, {"$6", 6}, {"$7", 7},
32 {"$8", 8}, {"$9", 9}, {"$10", 10}, {"$11", 11},
33 {"$12", 12}, {"$13", 13}, {"$14", 14}, {"$15", 15},
34 {"$16", 16}, {"$17", 17}, {"$18", 18}, {"$19", 19},
35 {"$20", 20}, {"$21", 21}, {"$22", 22}, {"$23", 23},
36 {"$24", 24}, {"$25", 25}, {"$26", 26}, {"$27", 27},
37 {"$28", 28}, {"$29", 29}, {"$30", 30}, {"$31", 31},
38 {NULL, 0}
39 };
40
get_arch_regstr(unsigned int n)41 const char *get_arch_regstr(unsigned int n)
42 {
43 n %= 32;
44 return loongarch_gpr_table[n].name;
45 }
46
regs_query_register_offset(const char *name)47 int regs_query_register_offset(const char *name)
48 {
49 const struct pt_regs_dwarfnum *roff;
50
51 for (roff = loongarch_gpr_table; roff->name != NULL; roff++)
52 if (!strcmp(roff->name, name))
53 return roff->dwarfnum;
54 return -EINVAL;
55 }
56