S390: Add target descriptions for vector register sets
[binutils-gdb.git] / gdb / m32r-linux-nat.c
blobe5e867b34911f70e8179c4dd0e2e344e2a71250c
1 /* Native-dependent code for GNU/Linux m32r.
3 Copyright (C) 2004-2015 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 <sys/ptrace.h>
27 #include <sys/user.h>
28 #include <sys/procfs.h>
30 /* Prototypes for supply_gregset etc. */
31 #include "gregset.h"
33 #include "m32r-tdep.h"
38 /* Since EVB register is not available for native debug, we reduce
39 the number of registers. */
40 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
42 /* Mapping between the general-purpose registers in `struct user'
43 format and GDB's register array layout. */
44 static int regmap[] = {
45 4, 5, 6, 7, 0, 1, 2, 8,
46 9, 10, 11, 12, 13, 24, 25, 23,
47 19, 19, 26, 23, 22, 20, 16, 15
50 #define PSW_REGMAP 19
51 #define BBPSW_REGMAP 21
52 #define SPU_REGMAP 23
53 #define SPI_REGMAP 26
55 /* Doee (??) apply to the corresponding SET requests as well. */
56 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \
57 && (regno) <= M32R_LINUX_NUM_REGS)
61 /* Transfering the general-purpose registers between GDB, inferiors
62 and core files. */
64 /* Fill GDB's register array with the general-purpose register values
65 in *GREGSETP. */
67 void
68 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
70 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
71 int i;
72 unsigned long psw, bbpsw;
74 psw = *(regp + PSW_REGMAP);
75 bbpsw = *(regp + BBPSW_REGMAP);
77 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
79 elf_greg_t regval;
81 switch (i)
83 case PSW_REGNUM:
84 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
85 break;
86 case CBR_REGNUM:
87 regval = ((psw >> 8) & 1);
88 break;
89 default:
90 regval = *(regp + regmap[i]);
91 break;
94 if (i != M32R_SP_REGNUM)
95 regcache_raw_supply (regcache, i, &regval);
96 else if (psw & 0x8000)
97 regcache_raw_supply (regcache, i, regp + SPU_REGMAP);
98 else
99 regcache_raw_supply (regcache, i, regp + SPI_REGMAP);
103 /* Fetch all general-purpose registers from process/thread TID and
104 store their values in GDB's register array. */
106 static void
107 fetch_regs (struct regcache *regcache, int tid)
109 elf_gregset_t regs;
111 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
112 perror_with_name (_("Couldn't get registers"));
114 supply_gregset (regcache, (const elf_gregset_t *) &regs);
117 /* Fill register REGNO (if it is a general-purpose register) in
118 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
119 do this for all registers. */
121 void
122 fill_gregset (const struct regcache *regcache,
123 elf_gregset_t * gregsetp, int regno)
125 elf_greg_t *regp = (elf_greg_t *) gregsetp;
126 int i;
127 unsigned long psw, bbpsw, tmp;
129 psw = *(regp + PSW_REGMAP);
130 bbpsw = *(regp + BBPSW_REGMAP);
132 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
134 if (regno != -1 && regno != i)
135 continue;
137 if (i == CBR_REGNUM || i == PSW_REGNUM)
138 continue;
140 if (i == SPU_REGNUM || i == SPI_REGNUM)
141 continue;
143 if (i != M32R_SP_REGNUM)
144 regcache_raw_collect (regcache, i, regp + regmap[i]);
145 else if (psw & 0x8000)
146 regcache_raw_collect (regcache, i, regp + SPU_REGMAP);
147 else
148 regcache_raw_collect (regcache, i, regp + SPI_REGMAP);
152 /* Store all valid general-purpose registers in GDB's register array
153 into the process/thread specified by TID. */
155 static void
156 store_regs (const struct regcache *regcache, int tid, int regno)
158 elf_gregset_t regs;
160 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
161 perror_with_name (_("Couldn't get registers"));
163 fill_gregset (regcache, &regs, regno);
165 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
166 perror_with_name (_("Couldn't write registers"));
171 /* Transfering floating-point registers between GDB, inferiors and cores.
172 Since M32R has no floating-point registers, these functions do nothing. */
174 void
175 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
179 void
180 fill_fpregset (const struct regcache *regcache,
181 gdb_fpregset_t *fpregs, int regno)
187 /* Transferring arbitrary registers between GDB and inferior. */
189 /* Fetch register REGNO from the child process. If REGNO is -1, do
190 this for all registers (including the floating point and SSE
191 registers). */
193 static void
194 m32r_linux_fetch_inferior_registers (struct target_ops *ops,
195 struct regcache *regcache, int regno)
197 int tid;
199 /* GNU/Linux LWP ID's are process ID's. */
200 tid = ptid_get_lwp (inferior_ptid);
201 if (tid == 0)
202 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
204 /* Use the PTRACE_GETREGS request whenever possible, since it
205 transfers more registers in one system call, and we'll cache the
206 results. */
207 if (regno == -1 || GETREGS_SUPPLIES (regno))
209 fetch_regs (regcache, tid);
210 return;
213 internal_error (__FILE__, __LINE__,
214 _("Got request for bad register number %d."), regno);
217 /* Store register REGNO back into the child process. If REGNO is -1,
218 do this for all registers (including the floating point and SSE
219 registers). */
220 static void
221 m32r_linux_store_inferior_registers (struct target_ops *ops,
222 struct regcache *regcache, int regno)
224 int tid;
226 /* GNU/Linux LWP ID's are process ID's. */
227 if ((tid = ptid_get_lwp (inferior_ptid)) == 0)
228 tid = ptid_get_pid (inferior_ptid); /* Not a threaded program. */
230 /* Use the PTRACE_SETREGS request whenever possible, since it
231 transfers more registers in one system call. */
232 if (regno == -1 || GETREGS_SUPPLIES (regno))
234 store_regs (regcache, tid, regno);
235 return;
238 internal_error (__FILE__, __LINE__,
239 _("Got request to store bad register number %d."), regno);
242 void _initialize_m32r_linux_nat (void);
244 void
245 _initialize_m32r_linux_nat (void)
247 struct target_ops *t;
249 /* Fill in the generic GNU/Linux methods. */
250 t = linux_target ();
252 /* Add our register access methods. */
253 t->to_fetch_registers = m32r_linux_fetch_inferior_registers;
254 t->to_store_registers = m32r_linux_store_inferior_registers;
256 /* Register the target. */
257 linux_nat_add_target (t);