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/>. */
24 #include "linux-nat.h"
26 #include "nat/gdb_ptrace.h"
28 #include <sys/procfs.h>
29 #include "inf-ptrace.h"
31 /* Prototypes for supply_gregset etc. */
34 #include "m32r-tdep.h"
37 class m32r_linux_nat_target final : public linux_nat_target
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
60 #define BBPSW_REGMAP 21
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
73 /* Fill GDB's register array with the general-purpose register values
77 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
79 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
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++)
93 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
96 regval = ((psw >> 8) & 1);
99 regval = *(regp + regmap[i]);
103 if (i != M32R_SP_REGNUM)
104 regcache->raw_supply (i, ®val);
105 else if (psw & 0x8000)
106 regcache->raw_supply (i, regp + SPU_REGMAP);
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. */
116 fetch_regs (struct regcache *regcache, int tid)
120 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0)
121 perror_with_name (_("Couldn't get registers"));
123 supply_gregset (regcache, (const elf_gregset_t *) ®s);
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. */
131 fill_gregset (const struct regcache *regcache,
132 elf_gregset_t * gregsetp, int regno)
134 elf_greg_t *regp = (elf_greg_t *) gregsetp;
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)
146 if (i == CBR_REGNUM || i == PSW_REGNUM)
149 if (i == SPU_REGNUM || i == SPI_REGNUM)
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);
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. */
165 store_regs (const struct regcache *regcache, int tid, int regno)
169 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0)
170 perror_with_name (_("Couldn't get registers"));
172 fill_gregset (regcache, ®s, regno);
174 if (ptrace (PTRACE_SETREGS, tid, 0, (int) ®s) < 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. */
184 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
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
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
210 if (regno == -1 || GETREGS_SUPPLIES (regno))
212 fetch_regs (regcache, tid);
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
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);
236 internal_error (__FILE__, __LINE__,
237 _("Got request to store bad register number %d."), regno);
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);