gdb/riscv: make riscv target description names global
[deliverable/binutils-gdb.git] / gdb / riscv-none-tdep.c
CommitLineData
fb8f3fc0
AB
1/* Copyright (C) 2020-2021 Free Software Foundation, Inc.
2
3 This file is part of GDB.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* This file contain code that is specific for bare-metal RISC-V targets. */
19
20#include "defs.h"
21#include "arch-utils.h"
22#include "regcache.h"
23#include "riscv-tdep.h"
24#include "elf-bfd.h"
25#include "regset.h"
26
27#ifdef HAVE_ELF
28#include "elf-none-tdep.h"
29#endif
30
31/* Define the general register mapping. This follows the same format as
32 the RISC-V linux corefile. The linux kernel puts the PC at offset 0,
33 gdb puts it at offset 32. Register x0 is always 0 and can be ignored.
34 Registers x1 to x31 are in the same place. */
35
36static const struct regcache_map_entry riscv_gregmap[] =
37{
38 { 1, RISCV_PC_REGNUM, 0 },
39 { 31, RISCV_RA_REGNUM, 0 }, /* x1 to x31 */
40 { 0 }
41};
42
43/* Define the FP register mapping. This follows the same format as the
44 RISC-V linux corefile. The kernel puts the 32 FP regs first, and then
45 FCSR. */
46
47static const struct regcache_map_entry riscv_fregmap[] =
48{
49 { 32, RISCV_FIRST_FP_REGNUM, 0 },
50 { 1, RISCV_CSR_FCSR_REGNUM, 4 }, /* Always stored as 4-bytes. */
51 { 0 }
52};
53
54/* Define the general register regset. */
55
56static const struct regset riscv_gregset =
57{
58 riscv_gregmap, riscv_supply_regset, regcache_collect_regset
59};
60
61/* Define the FP register regset. */
62
63static const struct regset riscv_fregset =
64{
65 riscv_fregmap, riscv_supply_regset, regcache_collect_regset
66};
67
68/* Implement the "iterate_over_regset_sections" gdbarch method. */
69
70static void
71riscv_iterate_over_regset_sections (struct gdbarch *gdbarch,
72 iterate_over_regset_sections_cb *cb,
73 void *cb_data,
74 const struct regcache *regcache)
75{
76 /* Write out the GPRs. */
77 int sz = 32 * riscv_isa_xlen (gdbarch);
78 cb (".reg", sz, sz, &riscv_gregset, NULL, cb_data);
79
80 /* Write out the FPRs, but only if present. */
81 if (riscv_isa_flen (gdbarch) > 0)
82 {
83 sz = (32 * riscv_isa_flen (gdbarch)
84 + register_size (gdbarch, RISCV_CSR_FCSR_REGNUM));
85 cb (".reg2", sz, sz, &riscv_fregset, NULL, cb_data);
86 }
87}
88
89/* Initialize RISC-V bare-metal ABI info. */
90
91static void
92riscv_none_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
93{
94#ifdef HAVE_ELF
95 elf_none_init_abi (gdbarch);
96#endif
97
98 /* Iterate over registers for reading and writing bare metal RISC-V core
99 files. */
100 set_gdbarch_iterate_over_regset_sections
101 (gdbarch, riscv_iterate_over_regset_sections);
102
103}
104
105/* Initialize RISC-V bare-metal target support. */
106
107void _initialize_riscv_none_tdep ();
108void
109_initialize_riscv_none_tdep ()
110{
111 gdbarch_register_osabi (bfd_arch_riscv, 0, GDB_OSABI_NONE,
112 riscv_none_init_abi);
113}
This page took 0.026305 seconds and 4 git commands to generate.