Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / nat / riscv-linux-tdesc.c
blob837b1707e0fb27210ba630bdd14db614602e2356
1 /* GNU/Linux/RISC-V native target description support for GDB.
2 Copyright (C) 2020-2021 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/>. */
19 #include "gdbsupport/common-defs.h"
21 #include "gdb_proc_service.h"
22 #include "arch/riscv.h"
23 #include "elf/common.h"
24 #include "nat/gdb_ptrace.h"
25 #include "nat/riscv-linux-tdesc.h"
27 #include <sys/uio.h>
29 /* Work around glibc header breakage causing ELF_NFPREG not to be usable. */
30 #ifndef NFPREG
31 # define NFPREG 33
32 #endif
34 /* See nat/riscv-linux-tdesc.h. */
36 struct riscv_gdbarch_features
37 riscv_linux_read_features (int tid)
39 struct riscv_gdbarch_features features;
40 elf_fpregset_t regs;
41 int flen;
43 /* Figuring out xlen is easy. */
44 features.xlen = sizeof (elf_greg_t);
46 /* Start with no f-registers. */
47 features.flen = 0;
49 /* How much worth of f-registers can we fetch if any? */
50 for (flen = sizeof (regs.__f.__f[0]); ; flen *= 2)
52 size_t regset_size;
53 struct iovec iov;
55 /* Regsets have a uniform slot size, so we count FSCR like
56 an FP data register. */
57 regset_size = ELF_NFPREG * flen;
58 if (regset_size > sizeof (regs))
59 break;
61 iov.iov_base = &regs;
62 iov.iov_len = regset_size;
63 if (ptrace (PTRACE_GETREGSET, tid, NT_FPREGSET,
64 (PTRACE_TYPE_ARG3) &iov) == -1)
66 switch (errno)
68 case EINVAL:
69 continue;
70 case EIO:
71 break;
72 default:
73 perror_with_name (_("Couldn't get registers"));
74 break;
77 else
78 features.flen = flen;
79 break;
82 return features;