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