1 /* Target-dependent code for GNU/Linux on RISC-V processors.
2 Copyright (C) 2018 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "riscv-tdep.h"
22 #include "glibc-tdep.h"
23 #include "linux-tdep.h"
24 #include "solib-svr4.h"
27 /* Define the general register mapping. The kernel puts the PC at offset 0,
28 gdb puts it at offset 32. Register x0 is always 0 and can be ignored.
29 Registers x1 to x31 are in the same place. */
31 static const struct regcache_map_entry riscv_linux_gregmap
[] =
33 { 1, RISCV_PC_REGNUM
, 0 },
34 { 31, RISCV_RA_REGNUM
, 0 }, /* x1 to x31 */
38 /* Define the general register regset. */
40 static const struct regset riscv_linux_gregset
=
42 riscv_linux_gregmap
, regcache_supply_regset
, regcache_collect_regset
45 /* Define hook for core file support. */
48 riscv_linux_iterate_over_regset_sections (struct gdbarch
*gdbarch
,
49 iterate_over_regset_sections_cb
*cb
,
51 const struct regcache
*regcache
)
53 cb (".reg", (32 * riscv_isa_xlen (gdbarch
)), (32 * riscv_isa_xlen (gdbarch
)),
54 &riscv_linux_gregset
, NULL
, cb_data
);
56 /* TODO: Add FP register support. */
59 /* Initialize RISC-V Linux ABI info. */
62 riscv_linux_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
64 linux_init_abi (info
, gdbarch
);
66 set_gdbarch_software_single_step (gdbarch
, riscv_software_single_step
);
68 set_solib_svr4_fetch_link_map_offsets (gdbarch
,
69 (riscv_isa_xlen (gdbarch
) == 4
70 ? svr4_ilp32_fetch_link_map_offsets
71 : svr4_lp64_fetch_link_map_offsets
));
73 /* GNU/Linux uses SVR4-style shared libraries. */
74 set_gdbarch_skip_trampoline_code (gdbarch
, find_solib_trampoline_target
);
76 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
77 set_gdbarch_skip_solib_resolver (gdbarch
, glibc_skip_solib_resolver
);
79 /* Enable TLS support. */
80 set_gdbarch_fetch_tls_load_module_address (gdbarch
,
81 svr4_fetch_objfile_link_map
);
83 set_gdbarch_iterate_over_regset_sections
84 (gdbarch
, riscv_linux_iterate_over_regset_sections
);
87 /* Initialize RISC-V Linux target support. */
90 _initialize_riscv_linux_tdep (void)
92 gdbarch_register_osabi (bfd_arch_riscv
, 0, GDB_OSABI_LINUX
,
93 riscv_linux_init_abi
);