(Ada) Fix resolving of homonym components in tagged types
[binutils-gdb.git] / gdb / m32r-linux-nat.c
blob8740af588f82f30e6f01c967f615d139912741e4
1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright (C) 2004-2018 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 "inferior.h"
22 #include "gdbcore.h"
23 #include "regcache.h"
24 #include "linux-nat.h"
25 #include "target.h"
26 #include "nat/gdb_ptrace.h"
27 #include <sys/user.h>
28 #include <sys/procfs.h>
29 #include "inf-ptrace.h"
31 /* Prototypes for supply_gregset etc. */
32 #include "gregset.h"
34 #include "m32r-tdep.h"
37 class m32r_linux_nat_target final : public linux_nat_target
39 public:
40 /* Add our register access methods. */
41 void fetch_registers (struct regcache *, int) override;
42 void store_registers (struct regcache *, int) override;
45 static m32r_linux_nat_target the_m32r_linux_nat_target;
47 /* Since EVB register is not available for native debug, we reduce
48 the number of registers. */
49 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
51 /* Mapping between the general-purpose registers in `struct user'
52 format and GDB's register array layout. */
53 static int regmap[] = {
54 4, 5, 6, 7, 0, 1, 2, 8,
55 9, 10, 11, 12, 13, 24, 25, 23,
56 19, 19, 26, 23, 22, 20, 16, 15
59 #define PSW_REGMAP 19
60 #define BBPSW_REGMAP 21
61 #define SPU_REGMAP 23
62 #define SPI_REGMAP 26
64 /* Doee (??) apply to the corresponding SET requests as well. */
65 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \
66 && (regno) <= M32R_LINUX_NUM_REGS)
70 /* Transfering the general-purpose registers between GDB, inferiors
71 and core files. */
73 /* Fill GDB's register array with the general-purpose register values
74 in *GREGSETP. */
76 void
77 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
79 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
80 int i;
81 unsigned long psw, bbpsw;
83 psw = *(regp + PSW_REGMAP);
84 bbpsw = *(regp + BBPSW_REGMAP);
86 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
88 elf_greg_t regval;
90 switch (i)
92 case PSW_REGNUM:
93 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
94 break;
95 case CBR_REGNUM:
96 regval = ((psw >> 8) & 1);
97 break;
98 default:
99 regval = *(regp + regmap[i]);
100 break;
103 if (i != M32R_SP_REGNUM)
104 regcache->raw_supply (i, &regval);
105 else if (psw & 0x8000)
106 regcache->raw_supply (i, regp + SPU_REGMAP);
107 else
108 regcache->raw_supply (i, regp + SPI_REGMAP);
112 /* Fetch all general-purpose registers from process/thread TID and
113 store their values in GDB's register array. */
115 static void
116 fetch_regs (struct regcache *regcache, int tid)
118 elf_gregset_t regs;
120 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
121 perror_with_name (_("Couldn't get registers"));
123 supply_gregset (regcache, (const elf_gregset_t *) &regs);
126 /* Fill register REGNO (if it is a general-purpose register) in
127 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
128 do this for all registers. */
130 void
131 fill_gregset (const struct regcache *regcache,
132 elf_gregset_t * gregsetp, int regno)
134 elf_greg_t *regp = (elf_greg_t *) gregsetp;
135 int i;
136 unsigned long psw, bbpsw, tmp;
138 psw = *(regp + PSW_REGMAP);
139 bbpsw = *(regp + BBPSW_REGMAP);
141 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
143 if (regno != -1 && regno != i)
144 continue;
146 if (i == CBR_REGNUM || i == PSW_REGNUM)
147 continue;
149 if (i == SPU_REGNUM || i == SPI_REGNUM)
150 continue;
152 if (i != M32R_SP_REGNUM)
153 regcache->raw_collect (i, regp + regmap[i]);
154 else if (psw & 0x8000)
155 regcache->raw_collect (i, regp + SPU_REGMAP);
156 else
157 regcache->raw_collect (i, regp + SPI_REGMAP);
161 /* Store all valid general-purpose registers in GDB's register array
162 into the process/thread specified by TID. */
164 static void
165 store_regs (const struct regcache *regcache, int tid, int regno)
167 elf_gregset_t regs;
169 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
170 perror_with_name (_("Couldn't get registers"));
172 fill_gregset (regcache, &regs, regno);
174 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
175 perror_with_name (_("Couldn't write registers"));
180 /* Transfering floating-point registers between GDB, inferiors and cores.
181 Since M32R has no floating-point registers, these functions do nothing. */
183 void
184 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
188 void
189 fill_fpregset (const struct regcache *regcache,
190 gdb_fpregset_t *fpregs, int regno)
196 /* Transferring arbitrary registers between GDB and inferior. */
198 /* Fetch register REGNO from the child process. If REGNO is -1, do
199 this for all registers (including the floating point and SSE
200 registers). */
202 void
203 m32r_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
205 pid_t tid = get_ptrace_pid (regcache->ptid ());
207 /* Use the PTRACE_GETREGS request whenever possible, since it
208 transfers more registers in one system call, and we'll cache the
209 results. */
210 if (regno == -1 || GETREGS_SUPPLIES (regno))
212 fetch_regs (regcache, tid);
213 return;
216 internal_error (__FILE__, __LINE__,
217 _("Got request for bad register number %d."), regno);
220 /* Store register REGNO back into the child process. If REGNO is -1,
221 do this for all registers (including the floating point and SSE
222 registers). */
223 void
224 m32r_linux_nat_target::store_registers (struct regcache *regcache, int regno)
226 pid_t tid = get_ptrace_pid (regcache->ptid ());
228 /* Use the PTRACE_SETREGS request whenever possible, since it
229 transfers more registers in one system call. */
230 if (regno == -1 || GETREGS_SUPPLIES (regno))
232 store_regs (regcache, tid, regno);
233 return;
236 internal_error (__FILE__, __LINE__,
237 _("Got request to store bad register number %d."), regno);
240 void
241 _initialize_m32r_linux_nat (void)
243 /* Register the target. */
244 linux_target = &the_m32r_linux_nat_target;
245 add_inf_child_target (&the_m32r_linux_nat_target);