1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright (C) 2004-2014 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"
28 #include <sys/ptrace.h>
30 #include <sys/procfs.h>
32 /* Prototypes for supply_gregset etc. */
35 #include "m32r-tdep.h"
40 /* Since EVB register is not available for native debug, we reduce
41 the number of registers. */
42 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
44 /* Mapping between the general-purpose registers in `struct user'
45 format and GDB's register array layout. */
46 static int regmap[] = {
47 4, 5, 6, 7, 0, 1, 2, 8,
48 9, 10, 11, 12, 13, 24, 25, 23,
49 19, 19, 26, 23, 22, 20, 16, 15
53 #define BBPSW_REGMAP 21
57 /* Doee (??) apply to the corresponding SET requests as well. */
58 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \
59 && (regno) <= M32R_LINUX_NUM_REGS)
63 /* Transfering the general-purpose registers between GDB, inferiors
66 /* Fill GDB's register array with the general-purpose register values
70 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
72 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
74 unsigned long psw, bbpsw;
76 psw = *(regp + PSW_REGMAP);
77 bbpsw = *(regp + BBPSW_REGMAP);
79 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
86 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
89 regval = ((psw >> 8) & 1);
92 regval = *(regp + regmap[i]);
96 if (i != M32R_SP_REGNUM)
97 regcache_raw_supply (regcache, i, ®val);
98 else if (psw & 0x8000)
99 regcache_raw_supply (regcache, i, regp + SPU_REGMAP);
101 regcache_raw_supply (regcache, i, regp + SPI_REGMAP);
105 /* Fetch all general-purpose registers from process/thread TID and
106 store their values in GDB's register array. */
109 fetch_regs (struct regcache *regcache, int tid)
113 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0)
114 perror_with_name (_("Couldn't get registers"));
116 supply_gregset (regcache, (const elf_gregset_t *) ®s);
119 /* Fill register REGNO (if it is a general-purpose register) in
120 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
121 do this for all registers. */
124 fill_gregset (const struct regcache *regcache,
125 elf_gregset_t * gregsetp, int regno)
127 elf_greg_t *regp = (elf_greg_t *) gregsetp;
129 unsigned long psw, bbpsw, tmp;
131 psw = *(regp + PSW_REGMAP);
132 bbpsw = *(regp + BBPSW_REGMAP);
134 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
136 if (regno != -1 && regno != i)
139 if (i == CBR_REGNUM || i == PSW_REGNUM)
142 if (i == SPU_REGNUM || i == SPI_REGNUM)
145 if (i != M32R_SP_REGNUM)
146 regcache_raw_collect (regcache, i, regp + regmap[i]);
147 else if (psw & 0x8000)
148 regcache_raw_collect (regcache, i, regp + SPU_REGMAP);
150 regcache_raw_collect (regcache, i, regp + SPI_REGMAP);
154 /* Store all valid general-purpose registers in GDB's register array
155 into the process/thread specified by TID. */
158 store_regs (const struct regcache *regcache, int tid, int regno)
162 if (ptrace (PTRACE_GETREGS, tid, 0, (int) ®s) < 0)
163 perror_with_name (_("Couldn't get registers"));
165 fill_gregset (regcache, ®s, regno);
167 if (ptrace (PTRACE_SETREGS, tid, 0, (int) ®s) < 0)
168 perror_with_name (_("Couldn't write registers"));
173 /* Transfering floating-point registers between GDB, inferiors and cores.
174 Since M32R has no floating-point registers, these functions do nothing. */
177 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
182 fill_fpregset (const struct regcache *regcache,
183 gdb_fpregset_t *fpregs, int regno)
189 /* Transferring arbitrary registers between GDB and inferior. */
191 /* Fetch register REGNO from the child process. If REGNO is -1, do
192 this for all registers (including the floating point and SSE
196 m32r_linux_fetch_inferior_registers (struct target_ops *ops,
197 struct regcache *regcache, int regno)
201 /* GNU/Linux LWP ID's are process ID's. */
202 tid = ptid_get_lwp (inferior_ptid);
204 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
206 /* Use the PTRACE_GETREGS request whenever possible, since it
207 transfers more registers in one system call, and we'll cache the
209 if (regno == -1 || GETREGS_SUPPLIES (regno))
211 fetch_regs (regcache, tid);
215 internal_error (__FILE__, __LINE__,
216 _("Got request for bad register number %d."), regno);
219 /* Store register REGNO back into the child process. If REGNO is -1,
220 do this for all registers (including the floating point and SSE
223 m32r_linux_store_inferior_registers (struct target_ops *ops,
224 struct regcache *regcache, int regno)
228 /* GNU/Linux LWP ID's are process ID's. */
229 if ((tid = ptid_get_lwp (inferior_ptid)) == 0)
230 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
232 /* Use the PTRACE_SETREGS request whenever possible, since it
233 transfers more registers in one system call. */
234 if (regno == -1 || GETREGS_SUPPLIES (regno))
236 store_regs (regcache, tid, regno);
240 internal_error (__FILE__, __LINE__,
241 _("Got request to store bad register number %d."), regno);
244 void _initialize_m32r_linux_nat (void);
247 _initialize_m32r_linux_nat (void)
249 struct target_ops *t;
251 /* Fill in the generic GNU/Linux methods. */
254 /* Add our register access methods. */
255 t->to_fetch_registers = m32r_linux_fetch_inferior_registers;
256 t->to_store_registers = m32r_linux_store_inferior_registers;
258 /* Register the target. */
259 linux_nat_add_target (t);