arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / or1k-linux-nat.c
blob21392245f4844beb0ed1dcfdf6cf7dedd9b74db3
1 /* Native-dependent code for GNU/Linux OpenRISC.
2 Copyright (C) 2021-2024 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 "regcache.h"
20 #include "gregset.h"
21 #include "linux-nat.h"
22 #include "or1k-tdep.h"
23 #include "or1k-linux-tdep.h"
24 #include "inferior.h"
26 #include "elf/common.h"
28 #include <sys/ptrace.h>
30 /* OpenRISC Linux native additions to the default linux support. */
32 class or1k_linux_nat_target final : public linux_nat_target
34 public:
35 /* Add our register access methods. */
36 void fetch_registers (struct regcache *regcache, int regnum) override;
37 void store_registers (struct regcache *regcache, int regnum) override;
39 /* Read suitable target description. */
40 const struct target_desc *read_description () override;
43 static or1k_linux_nat_target the_or1k_linux_nat_target;
45 /* Copy general purpose register REGNUM (or all gp regs if REGNUM == -1)
46 from regset GREGS into REGCACHE. */
48 static void
49 supply_gregset_regnum (struct regcache *regcache, const prgregset_t *gregs,
50 int regnum)
52 int i;
53 const elf_greg_t *regp = *gregs;
55 /* Access all registers */
56 if (regnum == -1)
58 /* We fill the general purpose registers. */
59 for (i = OR1K_ZERO_REGNUM + 1; i < OR1K_MAX_GPR_REGS; i++)
60 regcache->raw_supply (i, regp + i);
62 /* Supply OR1K_NPC_REGNUM from index 32. */
63 regcache->raw_supply (OR1K_NPC_REGNUM, regp + 32);
65 /* Fill the inaccessible zero register with zero. */
66 regcache->raw_supply_zeroed (0);
68 else if (regnum == OR1K_ZERO_REGNUM)
69 regcache->raw_supply_zeroed (0);
70 else if (regnum == OR1K_NPC_REGNUM)
71 regcache->raw_supply (OR1K_NPC_REGNUM, regp + 32);
72 else if (regnum > OR1K_ZERO_REGNUM && regnum < OR1K_MAX_GPR_REGS)
73 regcache->raw_supply (regnum, regp + regnum);
76 /* Copy all general purpose registers from regset GREGS into REGCACHE. */
78 void
79 supply_gregset (struct regcache *regcache, const prgregset_t *gregs)
81 supply_gregset_regnum (regcache, gregs, -1);
84 /* Copy general purpose register REGNUM (or all gp regs if REGNUM == -1)
85 from REGCACHE into regset GREGS. */
87 void
88 fill_gregset (const struct regcache *regcache, prgregset_t *gregs, int regnum)
90 elf_greg_t *regp = *gregs;
92 if (regnum == -1)
94 /* We fill the general purpose registers. */
95 for (int i = OR1K_ZERO_REGNUM + 1; i < OR1K_MAX_GPR_REGS; i++)
96 regcache->raw_collect (i, regp + i);
98 regcache->raw_collect (OR1K_NPC_REGNUM, regp + 32);
100 else if (regnum == OR1K_ZERO_REGNUM)
101 /* Nothing to do here. */
103 else if (regnum > OR1K_ZERO_REGNUM && regnum < OR1K_MAX_GPR_REGS)
104 regcache->raw_collect (regnum, regp + regnum);
105 else if (regnum == OR1K_NPC_REGNUM)
106 regcache->raw_collect (OR1K_NPC_REGNUM, regp + 32);
109 /* Transfering floating-point registers between GDB, inferiors and cores.
110 Since OpenRISC floating-point registers are the same as GPRs these do
111 nothing. */
113 void
114 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
118 void
119 fill_fpregset (const struct regcache *regcache,
120 gdb_fpregset_t *fpregs, int regno)
124 /* Return a target description for the current target. */
126 const struct target_desc *
127 or1k_linux_nat_target::read_description ()
129 return tdesc_or1k_linux;
132 /* Fetch REGNUM (or all registers if REGNUM == -1) from the target
133 into REGCACHE using PTRACE_GETREGSET. */
135 void
136 or1k_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum)
138 int tid;
140 tid = get_ptrace_pid (regcache->ptid());
142 if ((regnum >= OR1K_ZERO_REGNUM && regnum < OR1K_MAX_GPR_REGS)
143 || (regnum == OR1K_NPC_REGNUM)
144 || (regnum == -1))
146 struct iovec iov;
147 elf_gregset_t regs;
149 iov.iov_base = &regs;
150 iov.iov_len = sizeof (regs);
152 if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS,
153 (PTRACE_TYPE_ARG3) &iov) == -1)
154 perror_with_name (_("Couldn't get registers"));
155 else
156 supply_gregset_regnum (regcache, &regs, regnum);
159 /* Access to other SPRs has potential security issues, don't support them for
160 now. */
163 /* Store REGNUM (or all registers if REGNUM == -1) to the target
164 from REGCACHE using PTRACE_SETREGSET. */
166 void
167 or1k_linux_nat_target::store_registers (struct regcache *regcache, int regnum)
169 int tid;
171 tid = get_ptrace_pid (regcache->ptid ());
173 if ((regnum >= OR1K_ZERO_REGNUM && regnum < OR1K_MAX_GPR_REGS)
174 || (regnum == OR1K_NPC_REGNUM)
175 || (regnum == -1))
177 struct iovec iov;
178 elf_gregset_t regs;
180 iov.iov_base = &regs;
181 iov.iov_len = sizeof (regs);
183 if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS,
184 (PTRACE_TYPE_ARG3) &iov) == -1)
185 perror_with_name (_("Couldn't get registers"));
186 else
188 fill_gregset (regcache, &regs, regnum);
190 if (ptrace (PTRACE_SETREGSET, tid, NT_PRSTATUS,
191 (PTRACE_TYPE_ARG3) &iov) == -1)
192 perror_with_name (_("Couldn't set registers"));
196 /* Access to SPRs has potential security issues, don't support them for
197 now. */
200 /* Initialize OpenRISC Linux native support. */
202 void _initialize_or1k_linux_nat ();
203 void
204 _initialize_or1k_linux_nat ()
206 /* Register the target. */
207 linux_target = &the_or1k_linux_nat_target;
208 add_inf_child_target (&the_or1k_linux_nat_target);