gdbserver/linux-low: turn 'breakpoint_kind_from_{pc, current_state}' into methods
[deliverable/binutils-gdb.git] / gdbserver / linux-tile-low.cc
1 /* GNU/Linux/TILE-Gx specific low level interface, GDBserver.
2
3 Copyright (C) 2012-2020 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 "server.h"
21 #include "linux-low.h"
22
23 #include <arch/abi.h>
24 #include "nat/gdb_ptrace.h"
25
26 /* Linux target op definitions for the TILE-Gx architecture. */
27
28 class tile_target : public linux_process_target
29 {
30 public:
31
32 const regs_info *get_regs_info () override;
33
34 protected:
35
36 void low_arch_setup () override;
37
38 bool low_cannot_fetch_register (int regno) override;
39
40 bool low_cannot_store_register (int regno) override;
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;
47 };
48
49 /* The singleton target ops object. */
50
51 static tile_target the_tile_target;
52
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
71 /* Defined in auto-generated file reg-tilegx.c. */
72 void init_registers_tilegx (void);
73 extern const struct target_desc *tdesc_tilegx;
74
75 /* Defined in auto-generated file reg-tilegx32.c. */
76 void init_registers_tilegx32 (void);
77 extern const struct target_desc *tdesc_tilegx32;
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
94 bool
95 tile_target::low_cannot_fetch_register (int regno)
96 {
97 if (regno >= 0 && regno < 56)
98 return false;
99 else if (regno == 64)
100 return false;
101 else
102 return true;
103 }
104
105 bool
106 tile_target::low_cannot_store_register (int regno)
107 {
108 if (regno >= 0 && regno < 56)
109 return false;
110 else if (regno == 64)
111 return false;
112 else
113 return true;
114 }
115
116 static uint64_t tile_breakpoint = 0x400b3cae70166000ULL;
117 #define tile_breakpoint_len 8
118
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
128 static int
129 tile_breakpoint_at (CORE_ADDR where)
130 {
131 uint64_t insn;
132
133 the_target->read_memory (where, (unsigned char *) &insn, 8);
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)
149 collect_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
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)
159 supply_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
160 }
161
162 static struct regset_info tile_regsets[] =
163 {
164 { PTRACE_GETREGS, PTRACE_SETREGS, 0, tile_num_regs * 8,
165 GENERAL_REGS, tile_fill_gregset, tile_store_gregset },
166 NULL_REGSET
167 };
168
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
182 static struct regs_info myregs_info =
183 {
184 NULL, /* regset_bitmap */
185 &tile_usrregs_info,
186 &tile_regsets_info,
187 };
188
189 const regs_info *
190 tile_target::get_regs_info ()
191 {
192 return &myregs_info;
193 }
194
195 void
196 tile_target::low_arch_setup ()
197 {
198 int pid = pid_of (current_thread);
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)
207 current_process ()->tdesc = tdesc_tilegx32;
208 else
209 current_process ()->tdesc = tdesc_tilegx;
210 }
211
212 /* Support for hardware single step. */
213
214 static int
215 tile_supports_hardware_single_step (void)
216 {
217 return 1;
218 }
219
220
221 struct linux_target_ops the_low_target =
222 {
223 tile_sw_breakpoint_from_kind,
224 NULL,
225 0,
226 tile_breakpoint_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 */
236 NULL, /* delete_process */
237 NULL, /* new_thread */
238 NULL, /* delete_thread */
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 */
248 tile_supports_hardware_single_step,
249 };
250
251 /* The linux target ops object. */
252
253 linux_process_target *the_linux_target = &the_tile_target;
254
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 }
This page took 0.034661 seconds and 4 git commands to generate.