packaging: Add python3-base dependency
[platform/upstream/gdb.git] / gdb / tilegx-linux-nat.c
1 /* Native-dependent code for GNU/Linux TILE-Gx.
2
3    Copyright (C) 2012-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 "inferior.h"
22 #include "gdbcore.h"
23 #include "regcache.h"
24 #include "linux-nat.h"
25 #include "inf-ptrace.h"
26
27 #include "nat/gdb_ptrace.h"
28
29 #include <sys/procfs.h>
30
31 /* Defines ps_err_e, struct ps_prochandle.  */
32 #include "gdb_proc_service.h"
33
34 /* Prototypes for supply_gregset etc.  */
35 #include "gregset.h"
36
37 class tilegx_linux_nat_target final : public linux_nat_target
38 {
39 public:
40   /* Add our register access methods.  */
41   void fetch_registers (struct regcache *, int) override;
42   void store_registers (struct regcache *, int) override;
43 };
44
45 static tilegx_linux_nat_target the_tilegx_linux_nat_target;
46
47 /* The register sets used in GNU/Linux ELF core-dumps are identical to
48    the register sets in `struct user' that is used for a.out
49    core-dumps, and is also used by `ptrace'.  The corresponding types
50    are `elf_gregset_t' for the general-purpose registers (with
51    `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
52    for the floating-point registers.
53
54    Those types used to be available under the names `gregset_t' and
55    `fpregset_t' too, and this file used those names in the past.  But
56    those names are now used for the register sets used in the
57    `mcontext_t' type, and have a different size and layout.  */
58
59 /* Mapping between the general-purpose registers in `struct user'
60    format and GDB's register array layout.  Note that we map the
61    first 56 registers (0 thru 55) one-to-one.  GDB maps the pc to
62    slot 64, but ptrace returns it in slot 56.  */
63 static const int regmap[] =
64 {
65    0,  1,  2,  3,  4,  5,  6,  7,
66    8,  9, 10, 11, 12, 13, 14, 15,
67   16, 17, 18, 19, 20, 21, 22, 23,
68   24, 25, 26, 27, 28, 29, 30, 31,
69   32, 33, 34, 35, 36, 37, 38, 39,
70   40, 41, 42, 43, 44, 45, 46, 47,
71   48, 49, 50, 51, 52, 53, 54, 55,
72   -1, -1, -1, -1, -1, -1, -1, -1,
73   56, 58
74 };
75
76 /* Transfering the general-purpose registers between GDB, inferiors
77    and core files.  */
78
79 /* Fill GDB's register array with the general-purpose register values
80    in *GREGSETP.  */
81
82 void
83 supply_gregset (struct regcache* regcache,
84                 const elf_gregset_t *gregsetp)
85 {
86   elf_greg_t *regp = (elf_greg_t *) gregsetp;
87   int i;
88
89   for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
90     if (regmap[i] >= 0)
91       regcache->raw_supply (i, regp + regmap[i]);
92 }
93
94 /* Fill registers in *GREGSETPS with the values in GDB's
95    register array.  */
96
97 void
98 fill_gregset (const struct regcache* regcache,
99               elf_gregset_t *gregsetp, int regno)
100 {
101   elf_greg_t *regp = (elf_greg_t *) gregsetp;
102   int i;
103
104   for (i = 0; i < sizeof (regmap) / sizeof (regmap[0]); i++)
105     if (regmap[i] >= 0)
106       regcache->raw_collect (i, regp + regmap[i]);
107 }
108
109 /* Transfering floating-point registers between GDB, inferiors and cores.  */
110
111 /* Fill GDB's register array with the floating-point register values in
112    *FPREGSETP.  */
113
114 void
115 supply_fpregset (struct regcache *regcache,
116                  const elf_fpregset_t *fpregsetp)
117 {
118   /* NOTE: There are no floating-point registers for TILE-Gx.  */
119 }
120
121 /* Fill register REGNO (if it is a floating-point register) in
122    *FPREGSETP with the value in GDB's register array.  If REGNO is -1,
123    do this for all registers.  */
124
125 void
126 fill_fpregset (const struct regcache *regcache,
127                elf_fpregset_t *fpregsetp, int regno)
128 {
129   /* NOTE: There are no floating-point registers for TILE-Gx.  */
130 }
131
132 /* Fetch register REGNUM from the inferior.  If REGNUM is -1, do this
133    for all registers.  */
134
135 void
136 tilegx_linux_nat_target::fetch_registers (struct regcache *regcache,
137                                           int regnum)
138 {
139   elf_gregset_t regs;
140   pid_t tid = get_ptrace_pid (regcache->ptid ());
141
142   if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
143     perror_with_name (_("Couldn't get registers"));
144
145   supply_gregset (regcache, (const elf_gregset_t *)&regs);
146 }
147
148 /* Store register REGNUM back into the inferior.  If REGNUM is -1, do
149    this for all registers.  */
150
151 void
152 tilegx_linux_nat_target::store_registers (struct regcache *regcache,
153                                           int regnum)
154 {
155   elf_gregset_t regs;
156   pid_t tid = get_ptrace_pid (regcache->ptid ());
157
158   if (ptrace (PTRACE_GETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
159     perror_with_name (_("Couldn't get registers"));
160
161   fill_gregset (regcache, &regs, regnum);
162
163   if (ptrace (PTRACE_SETREGS, tid, 0, (PTRACE_TYPE_ARG3) &regs) < 0)
164     perror_with_name (_("Couldn't write registers"));
165 }
166
167 void _initialize_tile_linux_nat ();
168 void
169 _initialize_tile_linux_nat ()
170 {
171   linux_target = &the_tilegx_linux_nat_target;
172   add_inf_child_target (&the_tilegx_linux_nat_target);
173 }