GDB (xrefs)

/tmp/gdb-8.1/gdb/m32r-linux-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for GNU/Linux m32r.
2
3 Copyright (C) 2004-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
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"
30
31 /* Prototypes for supply_gregset etc. */
32 #include "gregset.h"
33
34 #include "m32r-tdep.h"
35
36
37
38
39 /* Since EVB register is not available for native debug, we reduce
40 the number of registers. */
41 #define M32R_LINUX_NUM_REGS (M32R_NUM_REGS - 1)
42
43 /* Mapping between the general-purpose registers in `struct user'
44 format and GDB's register array layout. */
45 static int regmap[] = {
46 4, 5, 6, 7, 0, 1, 2, 8,
47 9, 10, 11, 12, 13, 24, 25, 23,
48 19, 19, 26, 23, 22, 20, 16, 15
49 };
50
51 #define PSW_REGMAP 19
52 #define BBPSW_REGMAP 21
53 #define SPU_REGMAP 23
54 #define SPI_REGMAP 26
55
56 /* Doee (??) apply to the corresponding SET requests as well. */
57 #define GETREGS_SUPPLIES(regno) (0 <= (regno) \
58 && (regno) <= M32R_LINUX_NUM_REGS)
59
60
61
62 /* Transfering the general-purpose registers between GDB, inferiors
63 and core files. */
64
65 /* Fill GDB's register array with the general-purpose register values
66 in *GREGSETP. */
67
68 void
69 supply_gregset (struct regcache *regcache, const elf_gregset_t * gregsetp)
70 {
71 const elf_greg_t *regp = (const elf_greg_t *) gregsetp;
72 int i;
73 unsigned long psw, bbpsw;
74
75 psw = *(regp + PSW_REGMAP);
76 bbpsw = *(regp + BBPSW_REGMAP);
77
78 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
79 {
80 elf_greg_t regval;
81
82 switch (i)
83 {
84 case PSW_REGNUM:
85 regval = ((0x00c1 & bbpsw) << 8) | ((0xc100 & psw) >> 8);
86 break;
87 case CBR_REGNUM:
88 regval = ((psw >> 8) & 1);
89 break;
90 default:
91 regval = *(regp + regmap[i]);
92 break;
93 }
94
95 if (i != M32R_SP_REGNUM)
96 regcache_raw_supply (regcache, i, &regval);
97 else if (psw & 0x8000)
98 regcache_raw_supply (regcache, i, regp + SPU_REGMAP);
99 else
100 regcache_raw_supply (regcache, i, regp + SPI_REGMAP);
101 }
102 }
103
104 /* Fetch all general-purpose registers from process/thread TID and
105 store their values in GDB's register array. */
106
107 static void
108 fetch_regs (struct regcache *regcache, int tid)
109 {
110 elf_gregset_t regs;
111
112 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
113 perror_with_name (_("Couldn't get registers"));
114
115 supply_gregset (regcache, (const elf_gregset_t *) &regs);
116 }
117
118 /* Fill register REGNO (if it is a general-purpose register) in
119 *GREGSETPS with the value in GDB's register array. If REGNO is -1,
120 do this for all registers. */
121
122 void
123 fill_gregset (const struct regcache *regcache,
124 elf_gregset_t * gregsetp, int regno)
125 {
126 elf_greg_t *regp = (elf_greg_t *) gregsetp;
127 int i;
128 unsigned long psw, bbpsw, tmp;
129
130 psw = *(regp + PSW_REGMAP);
131 bbpsw = *(regp + BBPSW_REGMAP);
132
133 for (i = 0; i < M32R_LINUX_NUM_REGS; i++)
134 {
135 if (regno != -1 && regno != i)
136 continue;
137
138 if (i == CBR_REGNUM || i == PSW_REGNUM)
139 continue;
140
141 if (i == SPU_REGNUM || i == SPI_REGNUM)
142 continue;
143
144 if (i != M32R_SP_REGNUM)
145 regcache_raw_collect (regcache, i, regp + regmap[i]);
146 else if (psw & 0x8000)
147 regcache_raw_collect (regcache, i, regp + SPU_REGMAP);
148 else
149 regcache_raw_collect (regcache, i, regp + SPI_REGMAP);
150 }
151 }
152
153 /* Store all valid general-purpose registers in GDB's register array
154 into the process/thread specified by TID. */
155
156 static void
157 store_regs (const struct regcache *regcache, int tid, int regno)
158 {
159 elf_gregset_t regs;
160
161 if (ptrace (PTRACE_GETREGS, tid, 0, (int) &regs) < 0)
162 perror_with_name (_("Couldn't get registers"));
163
164 fill_gregset (regcache, &regs, regno);
165
166 if (ptrace (PTRACE_SETREGS, tid, 0, (int) &regs) < 0)
167 perror_with_name (_("Couldn't write registers"));
168 }
169
170
171
172 /* Transfering floating-point registers between GDB, inferiors and cores.
173 Since M32R has no floating-point registers, these functions do nothing. */
174
175 void
176 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregs)
177 {
178 }
179
180 void
181 fill_fpregset (const struct regcache *regcache,
182 gdb_fpregset_t *fpregs, int regno)
183 {
184 }
185
186
187
188 /* Transferring arbitrary registers between GDB and inferior. */
189
190 /* Fetch register REGNO from the child process. If REGNO is -1, do
191 this for all registers (including the floating point and SSE
192 registers). */
193
194 static void
195 m32r_linux_fetch_inferior_registers (struct target_ops *ops,
196 struct regcache *regcache, int regno)
197 {
198 pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
199
200 /* Use the PTRACE_GETREGS request whenever possible, since it
201 transfers more registers in one system call, and we'll cache the
202 results. */
203 if (regno == -1 || GETREGS_SUPPLIES (regno))
204 {
205 fetch_regs (regcache, tid);
206 return;
207 }
208
209 internal_error (__FILE__, __LINE__,
210 _("Got request for bad register number %d."), regno);
211 }
212
213 /* Store register REGNO back into the child process. If REGNO is -1,
214 do this for all registers (including the floating point and SSE
215 registers). */
216 static void
217 m32r_linux_store_inferior_registers (struct target_ops *ops,
218 struct regcache *regcache, int regno)
219 {
220 pid_t tid = get_ptrace_pid (regcache_get_ptid (regcache));
221
222 /* Use the PTRACE_SETREGS request whenever possible, since it
223 transfers more registers in one system call. */
224 if (regno == -1 || GETREGS_SUPPLIES (regno))
225 {
226 store_regs (regcache, tid, regno);
227 return;
228 }
229
230 internal_error (__FILE__, __LINE__,
231 _("Got request to store bad register number %d."), regno);
232 }
233
234 void
235 _initialize_m32r_linux_nat (void)
236 {
237 struct target_ops *t;
238
239 /* Fill in the generic GNU/Linux methods. */
240 t = linux_target ();
241
242 /* Add our register access methods. */
243 t->to_fetch_registers = m32r_linux_fetch_inferior_registers;
244 t->to_store_registers = m32r_linux_store_inferior_registers;
245
246 /* Register the target. */
247 linux_nat_add_target (t);
248 }
_initialize_m32r_linux_nat
void _initialize_m32r_linux_nat(void)
Definition: m32r-linux-nat.c:235
selftests::ptid::tid
static constexpr ptid_t tid
Definition: ptid-selftests.c:43
m32r_linux_fetch_inferior_registers
static void m32r_linux_fetch_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: m32r-linux-nat.c:195
regcache_get_ptid
ptid_t regcache_get_ptid(const struct regcache *regcache)
Definition: regcache.c:229
internal_error
void internal_error(const char *file, int line, const char *fmt,...)
Definition: errors.c:50
M32R_LINUX_NUM_REGS
#define M32R_LINUX_NUM_REGS
Definition: m32r-linux-nat.c:41
_
#define _(String)
Definition: gdb_locale.h:35
SPU_REGMAP
#define SPU_REGMAP
Definition: m32r-linux-nat.c:53
regmap
static int regmap[]
Definition: m32r-linux-nat.c:45
defs.h
SPI_REGMAP
#define SPI_REGMAP
Definition: m32r-linux-nat.c:54
store_regs
static void store_regs(const struct regcache *regcache, int tid, int regno)
Definition: m32r-linux-nat.c:157
ptrace
PTRACE_TYPE_RET ptrace()
SPI_REGNUM
Definition: m32r-tdep.h:40
fill_gregset
void fill_gregset(const struct regcache *regcache, elf_gregset_t *gregsetp, int regno)
Definition: m32r-linux-nat.c:123
inf-ptrace.h
target_ops
Definition: target.h:412
PSW_REGMAP
#define PSW_REGMAP
Definition: m32r-linux-nat.c:51
regcache.h
gdb_fpregset_t
GDB_FPREGSET_T gdb_fpregset_t
Definition: gregset.h:35
inferior.h
SPU_REGNUM
Definition: m32r-tdep.h:39
GETREGS_SUPPLIES
#define GETREGS_SUPPLIES(regno)
Definition: m32r-linux-nat.c:57
m32r_linux_store_inferior_registers
static void m32r_linux_store_inferior_registers(struct target_ops *ops, struct regcache *regcache, int regno)
Definition: m32r-linux-nat.c:217
M32R_SP_REGNUM
Definition: m32r-tdep.h:36
linux_nat_add_target
void linux_nat_add_target(struct target_ops *t)
Definition: linux-nat.c:4804
linux_target
struct target_ops * linux_target(void)
Definition: linux-nat.c:4377
gregset.h
supply_fpregset
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregs)
Definition: m32r-linux-nat.c:176
target_ops::to_fetch_registers
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
Definition: target.h:457
fill_fpregset
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregs, int regno)
Definition: m32r-linux-nat.c:181
perror_with_name
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
Definition: utils.c:692
gdbcore.h
supply_gregset
void supply_gregset(struct regcache *regcache, const elf_gregset_t *gregsetp)
Definition: m32r-linux-nat.c:69
m32r-tdep.h
PTRACE_SETREGS
#define PTRACE_SETREGS
Definition: ppc-linux-nat.c:139
target.h
BBPSW_REGMAP
#define BBPSW_REGMAP
Definition: m32r-linux-nat.c:52
PSW_REGNUM
Definition: m32r-tdep.h:37
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
fetch_regs
static void fetch_regs(struct regcache *regcache, int tid)
Definition: m32r-linux-nat.c:108
regcache
Definition: regcache.h:232
gdb_ptrace.h
regcache_raw_collect
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085
get_ptrace_pid
pid_t get_ptrace_pid(ptid_t ptid)
Definition: inf-ptrace.c:320
target_ops::to_store_registers
void(* to_store_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_NORETURN(noprocess())
Definition: target.h:459
CBR_REGNUM
Definition: m32r-tdep.h:38
PTRACE_GETREGS
#define PTRACE_GETREGS
Definition: ppc-linux-nat.c:136
linux-nat.h