Commit | Line | Data |
---|---|---|
65f479b6 PA |
1 | /* GNU/Linux/TILE-Gx specific low level interface, GDBserver. |
2 | ||
b811d2c2 | 3 | Copyright (C) 2012-2020 Free Software Foundation, Inc. |
65f479b6 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 | ||
20 | #include "server.h" | |
21 | #include "linux-low.h" | |
22 | ||
e1f58301 | 23 | #include <arch/abi.h> |
5826e159 | 24 | #include "nat/gdb_ptrace.h" |
65f479b6 | 25 | |
ef0478f6 TBA |
26 | /* Linux target op definitions for the TILE-Gx architecture. */ |
27 | ||
28 | class tile_target : public linux_process_target | |
29 | { | |
30 | public: | |
31 | ||
aa8d21c9 TBA |
32 | const regs_info *get_regs_info () override; |
33 | ||
797bcff5 TBA |
34 | protected: |
35 | ||
36 | void low_arch_setup () override; | |
daca57a7 TBA |
37 | |
38 | bool low_cannot_fetch_register (int regno) override; | |
39 | ||
40 | bool low_cannot_store_register (int regno) override; | |
bf9ae9d8 TBA |
41 | |
42 | bool low_supports_breakpoints () override; | |
43 | ||
44 | CORE_ADDR low_get_pc (regcache *regcache) override; | |
45 | ||
46 | void low_set_pc (regcache *regcache, CORE_ADDR newpc) override; | |
ef0478f6 TBA |
47 | }; |
48 | ||
49 | /* The singleton target ops object. */ | |
50 | ||
51 | static tile_target the_tile_target; | |
52 | ||
bf9ae9d8 TBA |
53 | bool |
54 | tile_target::low_supports_breakpoints () | |
55 | { | |
56 | return true; | |
57 | } | |
58 | ||
59 | CORE_ADDR | |
60 | tile_target::low_get_pc (regcache *regcache) | |
61 | { | |
62 | return linux_get_pc_64bit (regcache); | |
63 | } | |
64 | ||
65 | void | |
66 | tile_target::low_set_pc (regcache *regcache, CORE_ADDR pc) | |
67 | { | |
68 | linux_set_pc_64bit (regcache, pc); | |
69 | } | |
70 | ||
e1f58301 JW |
71 | /* Defined in auto-generated file reg-tilegx.c. */ |
72 | void init_registers_tilegx (void); | |
3aee8918 PA |
73 | extern const struct target_desc *tdesc_tilegx; |
74 | ||
e1f58301 JW |
75 | /* Defined in auto-generated file reg-tilegx32.c. */ |
76 | void init_registers_tilegx32 (void); | |
3aee8918 | 77 | extern const struct target_desc *tdesc_tilegx32; |
65f479b6 PA |
78 | |
79 | #define tile_num_regs 65 | |
80 | ||
81 | static int tile_regmap[] = | |
82 | { | |
83 | 0, 1, 2, 3, 4, 5, 6, 7, | |
84 | 8, 9, 10, 11, 12, 13, 14, 15, | |
85 | 16, 17, 18, 19, 20, 21, 22, 23, | |
86 | 24, 25, 26, 27, 28, 29, 30, 31, | |
87 | 32, 33, 34, 35, 36, 37, 38, 39, | |
88 | 40, 41, 42, 43, 44, 45, 46, 47, | |
89 | 48, 49, 50, 51, 52, 53, 54, 55, | |
90 | -1, -1, -1, -1, -1, -1, -1, -1, | |
91 | 56 | |
92 | }; | |
93 | ||
daca57a7 TBA |
94 | bool |
95 | tile_target::low_cannot_fetch_register (int regno) | |
65f479b6 PA |
96 | { |
97 | if (regno >= 0 && regno < 56) | |
daca57a7 | 98 | return false; |
65f479b6 | 99 | else if (regno == 64) |
daca57a7 | 100 | return false; |
65f479b6 | 101 | else |
daca57a7 | 102 | return true; |
65f479b6 PA |
103 | } |
104 | ||
daca57a7 TBA |
105 | bool |
106 | tile_target::low_cannot_store_register (int regno) | |
65f479b6 PA |
107 | { |
108 | if (regno >= 0 && regno < 56) | |
daca57a7 | 109 | return false; |
65f479b6 | 110 | else if (regno == 64) |
daca57a7 | 111 | return false; |
65f479b6 | 112 | else |
daca57a7 | 113 | return true; |
65f479b6 PA |
114 | } |
115 | ||
65f479b6 PA |
116 | static uint64_t tile_breakpoint = 0x400b3cae70166000ULL; |
117 | #define tile_breakpoint_len 8 | |
118 | ||
dd373349 AT |
119 | /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */ |
120 | ||
121 | static const gdb_byte * | |
122 | tile_sw_breakpoint_from_kind (int kind, int *size) | |
123 | { | |
124 | *size = tile_breakpoint_len; | |
125 | return (const gdb_byte *) &tile_breakpoint; | |
126 | } | |
127 | ||
65f479b6 PA |
128 | static int |
129 | tile_breakpoint_at (CORE_ADDR where) | |
130 | { | |
131 | uint64_t insn; | |
132 | ||
52405d85 | 133 | the_target->read_memory (where, (unsigned char *) &insn, 8); |
65f479b6 PA |
134 | if (insn == tile_breakpoint) |
135 | return 1; | |
136 | ||
137 | /* If necessary, recognize more trap instructions here. GDB only uses the | |
138 | one. */ | |
139 | return 0; | |
140 | } | |
141 | ||
142 | static void | |
143 | tile_fill_gregset (struct regcache *regcache, void *buf) | |
144 | { | |
145 | int i; | |
146 | ||
147 | for (i = 0; i < tile_num_regs; i++) | |
148 | if (tile_regmap[i] != -1) | |
e1f58301 | 149 | collect_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]); |
65f479b6 PA |
150 | } |
151 | ||
152 | static void | |
153 | tile_store_gregset (struct regcache *regcache, const void *buf) | |
154 | { | |
155 | int i; | |
156 | ||
157 | for (i = 0; i < tile_num_regs; i++) | |
158 | if (tile_regmap[i] != -1) | |
e1f58301 | 159 | supply_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]); |
65f479b6 PA |
160 | } |
161 | ||
3aee8918 | 162 | static struct regset_info tile_regsets[] = |
65f479b6 | 163 | { |
d6707650 | 164 | { PTRACE_GETREGS, PTRACE_SETREGS, 0, tile_num_regs * 8, |
65f479b6 | 165 | GENERAL_REGS, tile_fill_gregset, tile_store_gregset }, |
50bc912a | 166 | NULL_REGSET |
65f479b6 PA |
167 | }; |
168 | ||
3aee8918 PA |
169 | static struct regsets_info tile_regsets_info = |
170 | { | |
171 | tile_regsets, /* regsets */ | |
172 | 0, /* num_regsets */ | |
173 | NULL, /* disabled_regsets */ | |
174 | }; | |
175 | ||
176 | static struct usrregs_info tile_usrregs_info = | |
177 | { | |
178 | tile_num_regs, | |
179 | tile_regmap, | |
180 | }; | |
181 | ||
aa8d21c9 | 182 | static struct regs_info myregs_info = |
3aee8918 PA |
183 | { |
184 | NULL, /* regset_bitmap */ | |
185 | &tile_usrregs_info, | |
186 | &tile_regsets_info, | |
187 | }; | |
188 | ||
aa8d21c9 TBA |
189 | const regs_info * |
190 | tile_target::get_regs_info () | |
3aee8918 | 191 | { |
aa8d21c9 | 192 | return &myregs_info; |
3aee8918 PA |
193 | } |
194 | ||
797bcff5 TBA |
195 | void |
196 | tile_target::low_arch_setup () | |
e1f58301 | 197 | { |
0bfdf32f | 198 | int pid = pid_of (current_thread); |
e1f58301 JW |
199 | unsigned int machine; |
200 | int is_elf64 = linux_pid_exe_is_elf_64_file (pid, &machine); | |
201 | ||
202 | if (sizeof (void *) == 4) | |
203 | if (is_elf64 > 0) | |
204 | error (_("Can't debug 64-bit process with 32-bit GDBserver")); | |
205 | ||
206 | if (!is_elf64) | |
3aee8918 | 207 | current_process ()->tdesc = tdesc_tilegx32; |
e1f58301 | 208 | else |
3aee8918 | 209 | current_process ()->tdesc = tdesc_tilegx; |
e1f58301 JW |
210 | } |
211 | ||
7d00775e AT |
212 | /* Support for hardware single step. */ |
213 | ||
214 | static int | |
215 | tile_supports_hardware_single_step (void) | |
216 | { | |
217 | return 1; | |
218 | } | |
219 | ||
e1f58301 | 220 | |
65f479b6 PA |
221 | struct linux_target_ops the_low_target = |
222 | { | |
dd373349 | 223 | tile_sw_breakpoint_from_kind, |
65f479b6 PA |
224 | NULL, |
225 | 0, | |
226 | tile_breakpoint_at, | |
7d00775e AT |
227 | NULL, /* supports_z_point_type */ |
228 | NULL, /* insert_point */ | |
229 | NULL, /* remove_point */ | |
230 | NULL, /* stopped_by_watchpoint */ | |
231 | NULL, /* stopped_data_address */ | |
232 | NULL, /* collect_ptrace_register */ | |
233 | NULL, /* supply_ptrace_register */ | |
234 | NULL, /* siginfo_fixup */ | |
235 | NULL, /* new_process */ | |
04ec7890 | 236 | NULL, /* delete_process */ |
7d00775e | 237 | NULL, /* new_thread */ |
466eecee | 238 | NULL, /* delete_thread */ |
7d00775e AT |
239 | NULL, /* new_fork */ |
240 | NULL, /* prepare_to_resume */ | |
241 | NULL, /* process_qsupported */ | |
242 | NULL, /* supports_tracepoints */ | |
243 | NULL, /* get_thread_area */ | |
244 | NULL, /* install_fast_tracepoint_jump_pad */ | |
245 | NULL, /* emit_ops */ | |
246 | NULL, /* get_min_fast_tracepoint_insn_len */ | |
247 | NULL, /* supports_range_stepping */ | |
7d00775e | 248 | tile_supports_hardware_single_step, |
65f479b6 | 249 | }; |
3aee8918 | 250 | |
ef0478f6 TBA |
251 | /* The linux target ops object. */ |
252 | ||
253 | linux_process_target *the_linux_target = &the_tile_target; | |
254 | ||
3aee8918 PA |
255 | void |
256 | initialize_low_arch (void) | |
257 | { | |
258 | init_registers_tilegx32(); | |
259 | init_registers_tilegx(); | |
260 | ||
261 | initialize_regsets_info (&tile_regsets_info); | |
262 | } |