Automatic date update in version.in
[binutils-gdb.git] / gdb / riscv-ravenscar-thread.c
blobe28e17878c3ab5140e53c0d2b4b4b45818acb597
1 /* Ravenscar RISC-V target support.
3 Copyright (C) 2019-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
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 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "gdbarch.h"
22 #include "gdbcore.h"
23 #include "regcache.h"
24 #include "riscv-tdep.h"
25 #include "inferior.h"
26 #include "ravenscar-thread.h"
27 #include "riscv-ravenscar-thread.h"
29 #define LAST_REGISTER (RISCV_FIRST_FP_REGNUM + 14)
31 struct riscv_ravenscar_ops : public ravenscar_arch_ops
33 int reg_offsets[LAST_REGISTER + 1];
35 riscv_ravenscar_ops (struct gdbarch *arch);
38 riscv_ravenscar_ops::riscv_ravenscar_ops (struct gdbarch *arch)
39 : ravenscar_arch_ops (gdb::make_array_view (reg_offsets, LAST_REGISTER + 1))
41 int reg_size = riscv_isa_xlen (arch);
43 for (int regnum = 0; regnum <= LAST_REGISTER; ++regnum)
45 int offset;
46 if (regnum == RISCV_RA_REGNUM || regnum == RISCV_PC_REGNUM)
47 offset = 0;
48 else if (regnum == RISCV_SP_REGNUM)
49 offset = 1;
50 else if (regnum == RISCV_ZERO_REGNUM + 8) /* S0 */
51 offset = 2;
52 else if (regnum == RISCV_ZERO_REGNUM + 9) /* S1 */
53 offset = 3;
54 else if (regnum >= RISCV_ZERO_REGNUM + 19
55 && regnum <= RISCV_ZERO_REGNUM + 27) /* S2..S11 */
56 offset = regnum - (RISCV_ZERO_REGNUM + 19) + 4;
57 else if (regnum >= RISCV_FIRST_FP_REGNUM
58 && regnum <= RISCV_FIRST_FP_REGNUM + 11)
59 offset = regnum - RISCV_FIRST_FP_REGNUM + 14; /* FS0..FS11 */
60 else
61 offset = -1;
63 if (offset != -1)
64 offset *= reg_size;
66 reg_offsets[regnum] = offset;
70 /* Register riscv_ravenscar_ops in GDBARCH. */
72 void
73 register_riscv_ravenscar_ops (struct gdbarch *gdbarch)
75 set_gdbarch_ravenscar_ops (gdbarch, new riscv_ravenscar_ops (gdbarch));