GDB (xrefs)
Loading...
Searching...
No Matches
xtensa-linux-nat.c
Go to the documentation of this file.
1/* Xtensa GNU/Linux native support.
2
3 Copyright (C) 2007-2023 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 "frame.h"
22#include "inferior.h"
23#include "gdbcore.h"
24#include "regcache.h"
25#include "target.h"
26#include "linux-nat.h"
27#include <sys/types.h>
28#include <signal.h>
29#include <sys/user.h>
30#include <sys/ioctl.h>
31#include "gdbsupport/gdb_wait.h"
32#include <fcntl.h>
33#include <sys/procfs.h>
34#include "nat/gdb_ptrace.h"
35#include <asm/ptrace.h>
36
37#include "gregset.h"
38#include "xtensa-tdep.h"
39
40/* Defines ps_err_e, struct ps_prochandle. */
41#include "gdb_proc_service.h"
42
43/* Extended register set depends on hardware configs.
44 Keeping these definitions separately allows to introduce
45 hardware-specific overlays. */
46#include "xtensa-xtregs.c"
47
49{
50public:
51 /* Add our register access methods. */
52 void fetch_registers (struct regcache *, int) override;
53 void store_registers (struct regcache *, int) override;
54};
55
57
58void
60 gdb_gregset_t *gregsetp, int regnum)
61{
62 int i;
63 xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
64 struct gdbarch *gdbarch = regcache->arch ();
65 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
66
67 if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
69 if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
71
72 if (regnum == tdep->wb_regnum || regnum == -1)
74 &regs->windowbase);
75 if (regnum == tdep->ws_regnum || regnum == -1)
77 &regs->windowstart);
78 if (regnum == tdep->lbeg_regnum || regnum == -1)
80 &regs->lbeg);
81 if (regnum == tdep->lend_regnum || regnum == -1)
83 &regs->lend);
84 if (regnum == tdep->lcount_regnum || regnum == -1)
86 &regs->lcount);
87 if (regnum == tdep->sar_regnum || regnum == -1)
89 &regs->sar);
90 if (regnum == tdep->threadptr_regnum || regnum == -1)
92 &regs->threadptr);
93 if (regnum >=tdep->ar_base
94 && regnum < tdep->ar_base
95 + tdep->num_aregs)
97 &regs->ar[regnum - tdep->ar_base]);
98 else if (regnum == -1)
99 {
100 for (i = 0; i < tdep->num_aregs; ++i)
101 regcache->raw_collect (tdep->ar_base + i,
102 &regs->ar[i]);
103 }
104 if (regnum >= tdep->a0_base
105 && regnum < tdep->a0_base + C0_NREGS)
107 &regs->ar[(4 * regs->windowbase + regnum
108 - tdep->a0_base)
109 % tdep->num_aregs]);
110 else if (regnum == -1)
111 {
112 for (i = 0; i < C0_NREGS; ++i)
113 regcache->raw_collect (tdep->a0_base + i,
114 (&regs->ar[(4 * regs->windowbase + i)
115 % tdep->num_aregs]));
116 }
117}
118
119static void
121 const gdb_gregset_t *gregsetp, int regnum)
122{
123 int i;
124 xtensa_elf_gregset_t *regs = (xtensa_elf_gregset_t *) gregsetp;
125
126 struct gdbarch *gdbarch = regcache->arch ();
127 xtensa_gdbarch_tdep *tdep = gdbarch_tdep<xtensa_gdbarch_tdep> (gdbarch);
128
129 if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
131 if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
133
134 if (regnum == tdep->wb_regnum || regnum == -1)
136 &regs->windowbase);
137 if (regnum == tdep->ws_regnum || regnum == -1)
139 &regs->windowstart);
140 if (regnum == tdep->lbeg_regnum || regnum == -1)
142 &regs->lbeg);
143 if (regnum == tdep->lend_regnum || regnum == -1)
145 &regs->lend);
146 if (regnum == tdep->lcount_regnum || regnum == -1)
148 &regs->lcount);
149 if (regnum == tdep->sar_regnum || regnum == -1)
151 &regs->sar);
152 if (regnum == tdep->threadptr_regnum || regnum == -1)
154 &regs->threadptr);
155 if (regnum >=tdep->ar_base
156 && regnum < tdep->ar_base
157 + tdep->num_aregs)
159 &regs->ar[regnum - tdep->ar_base]);
160 else if (regnum == -1)
161 {
162 for (i = 0; i < tdep->num_aregs; ++i)
163 regcache->raw_supply (tdep->ar_base + i,
164 &regs->ar[i]);
165 }
166 if (regnum >= tdep->a0_base
167 && regnum < tdep->a0_base + C0_NREGS)
169 &regs->ar[(4 * regs->windowbase + regnum
170 - tdep->a0_base)
171 % tdep->num_aregs]);
172 else if (regnum == -1)
173 {
174 for (i = 0; i < C0_NREGS; ++i)
175 regcache->raw_supply (tdep->a0_base + i,
176 &regs->ar[(4 * regs->windowbase + i)
177 % tdep->num_aregs]);
178 }
179}
180
181void
183{
184 supply_gregset_reg (regcache, gregsetp, -1);
185}
186
187void
189 gdb_fpregset_t *fpregsetp, int regnum)
190{
191 return;
192}
193
194void
196 const gdb_fpregset_t *fpregsetp)
197{
198 return;
199}
200
201/* Fetch greg-register(s) from process/thread TID
202 and store value(s) in GDB's register array. */
203
204static void
206{
207 int tid = regcache->ptid ().lwp ();
208 gdb_gregset_t regs;
209
210 if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
211 {
212 perror_with_name (_("Couldn't get registers"));
213 return;
214 }
215
217}
218
219/* Store greg-register(s) in GDB's register
220 array into the process/thread specified by TID. */
221
222static void
224{
225 int tid = regcache->ptid ().lwp ();
226 gdb_gregset_t regs;
227
228 if (ptrace (PTRACE_GETREGS, tid, 0, (long) &regs) < 0)
229 {
230 perror_with_name (_("Couldn't get registers"));
231 return;
232 }
233
234 fill_gregset (regcache, &regs, regnum);
235
236 if (ptrace (PTRACE_SETREGS, tid, 0, (long) &regs) < 0)
237 {
238 perror_with_name (_("Couldn't write registers"));
239 return;
240 }
241}
242
243static int xtreg_lo;
244static int xtreg_high;
245
246/* Fetch/Store Xtensa TIE registers. Xtensa GNU/Linux PTRACE
247 interface provides special requests for this. */
248
249static void
251{
252 int tid = regcache->ptid ().lwp ();
253 const xtensa_regtable_t *ptr;
254 char xtregs [XTENSA_ELF_XTREG_SIZE];
255
256 if (ptrace (PTRACE_GETXTREGS, tid, 0, (long)&xtregs) < 0)
257 perror_with_name (_("Couldn't get extended registers"));
258
259 for (ptr = xtensa_regmap_table; ptr->name; ptr++)
260 if (regnum == ptr->gdb_regnum || regnum == -1)
261 regcache->raw_supply (ptr->gdb_regnum, xtregs + ptr->ptrace_offset);
262}
263
264static void
266{
267 int tid = regcache->ptid ().lwp ();
268 const xtensa_regtable_t *ptr;
269 char xtregs [XTENSA_ELF_XTREG_SIZE];
270
271 if (ptrace (PTRACE_GETXTREGS, tid, 0, (long)&xtregs) < 0)
272 perror_with_name (_("Couldn't get extended registers"));
273
274 for (ptr = xtensa_regmap_table; ptr->name; ptr++)
275 if (regnum == ptr->gdb_regnum || regnum == -1)
276 regcache->raw_collect (ptr->gdb_regnum, xtregs + ptr->ptrace_offset);
277
278 if (ptrace (PTRACE_SETXTREGS, tid, 0, (long)&xtregs) < 0)
279 perror_with_name (_("Couldn't write extended registers"));
280}
281
282void
284 int regnum)
285{
286 if (regnum == -1)
287 {
290 }
291 else if ((regnum < xtreg_lo) || (regnum > xtreg_high))
293 else
295}
296
297void
299 int regnum)
300{
301 if (regnum == -1)
302 {
305 }
306 else if ((regnum < xtreg_lo) || (regnum > xtreg_high))
308 else
310}
311
312/* Called by libthread_db. */
313
314ps_err_e
316 lwpid_t lwpid, int idx, void **base)
317{
319
320 if (ptrace (PTRACE_GETREGS, lwpid, NULL, &regs) != 0)
321 return PS_ERR;
322
323 /* IDX is the bias from the thread pointer to the beginning of the
324 thread descriptor. It has to be subtracted due to implementation
325 quirks in libthread_db. */
326 *base = (void *) ((char *) regs.threadptr - idx);
327
328 return PS_OK;
329}
330
332void
334{
335 const xtensa_regtable_t *ptr;
336
337 /* Calculate the number range for extended registers. */
338 xtreg_lo = 1000000000;
339 xtreg_high = -1;
340 for (ptr = xtensa_regmap_table; ptr->name; ptr++)
341 {
342 if (ptr->gdb_regnum < xtreg_lo)
343 xtreg_lo = ptr->gdb_regnum;
344 if (ptr->gdb_regnum > xtreg_high)
345 xtreg_high = ptr->gdb_regnum;
346 }
347
350}
int regnum
gdbarch * arch() const
Definition regcache.c:231
void raw_collect(int regnum, void *buf) const override
Definition regcache.c:1127
void raw_supply(int regnum, const void *buf) override
Definition regcache.c:1062
ptid_t ptid() const
Definition regcache.h:408
void fetch_registers(struct regcache *, int) override
void store_registers(struct regcache *, int) override
#define ptrace(request, pid, addr, data)
Definition gdb_ptrace.h:141
int gdbarch_pc_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2054
int gdbarch_ps_regnum(struct gdbarch *gdbarch)
Definition gdbarch.c:2071
GDB_FPREGSET_T gdb_fpregset_t
Definition gregset.h:35
GDB_GREGSET_T gdb_gregset_t
Definition gregset.h:34
void add_inf_child_target(inf_child_target *target)
Definition inf-child.c:418
struct linux_nat_target * linux_target
Definition linux-nat.c:189
#define PTRACE_GETREGS
#define PTRACE_SETREGS
xtensa_elf_greg_t ar[64]
Definition xtensa.h:40
xtensa_elf_greg_t lcount
Definition xtensa.h:34
xtensa_elf_greg_t ps
Definition xtensa.h:31
xtensa_elf_greg_t pc
Definition xtensa.h:30
xtensa_elf_greg_t lbeg
Definition xtensa.h:32
xtensa_elf_greg_t windowstart
Definition xtensa.h:36
xtensa_elf_greg_t lend
Definition xtensa.h:33
xtensa_elf_greg_t sar
Definition xtensa.h:35
xtensa_elf_greg_t windowbase
Definition xtensa.h:37
xtensa_elf_greg_t threadptr
Definition xtensa.h:38
unsigned int num_aregs
const char * name
static void supply_gregset_reg(struct regcache *regcache, const gdb_gregset_t *gregsetp, int regnum)
static int xtreg_high
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
static xtensa_linux_nat_target the_xtensa_linux_nat_target
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
ps_err_e ps_get_thread_area(struct ps_prochandle *ph, lwpid_t lwpid, int idx, void **base)
void _initialize_xtensa_linux_nat()
static int xtreg_lo
static void store_xtregs(struct regcache *regcache, int regnum)
static void store_gregs(struct regcache *regcache, int regnum)
static void fetch_xtregs(struct regcache *regcache, int regnum)
static void fetch_gregs(struct regcache *regcache, int regnum)
#define XTENSA_ELF_XTREG_SIZE
const xtensa_regtable_t xtensa_regmap_table[]
#define C0_NREGS
Definition xtensa.h:46