GDBserver

linux-tile-low.c
Go to the documentation of this file.
1 /* GNU/Linux/TILE-Gx specific low level interface, GDBserver.
2
3 Copyright (C) 2012-2018 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 /* Defined in auto-generated file reg-tilegx.c. */
27 void init_registers_tilegx (void);
28 extern const struct target_desc *tdesc_tilegx;
29
30 /* Defined in auto-generated file reg-tilegx32.c. */
31 void init_registers_tilegx32 (void);
32 extern const struct target_desc *tdesc_tilegx32;
33
34 #define tile_num_regs 65
35
36 static int tile_regmap[] =
37 {
38 0, 1, 2, 3, 4, 5, 6, 7,
39 8, 9, 10, 11, 12, 13, 14, 15,
40 16, 17, 18, 19, 20, 21, 22, 23,
41 24, 25, 26, 27, 28, 29, 30, 31,
42 32, 33, 34, 35, 36, 37, 38, 39,
43 40, 41, 42, 43, 44, 45, 46, 47,
44 48, 49, 50, 51, 52, 53, 54, 55,
45 -1, -1, -1, -1, -1, -1, -1, -1,
46 56
47 };
48
49 static int
50 tile_cannot_fetch_register (int regno)
51 {
52 if (regno >= 0 && regno < 56)
53 return 0;
54 else if (regno == 64)
55 return 0;
56 else
57 return 1;
58 }
59
60 static int
61 tile_cannot_store_register (int regno)
62 {
63 if (regno >= 0 && regno < 56)
64 return 0;
65 else if (regno == 64)
66 return 0;
67 else
68 return 1;
69 }
70
71 static uint64_t tile_breakpoint = 0x400b3cae70166000ULL;
72 #define tile_breakpoint_len 8
73
74 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
75
76 static const gdb_byte *
77 tile_sw_breakpoint_from_kind (int kind, int *size)
78 {
79 *size = tile_breakpoint_len;
80 return (const gdb_byte *) &tile_breakpoint;
81 }
82
83 static int
84 tile_breakpoint_at (CORE_ADDR where)
85 {
86 uint64_t insn;
87
88 (*the_target->read_memory) (where, (unsigned char *) &insn, 8);
89 if (insn == tile_breakpoint)
90 return 1;
91
92 /* If necessary, recognize more trap instructions here. GDB only uses the
93 one. */
94 return 0;
95 }
96
97 static void
98 tile_fill_gregset (struct regcache *regcache, void *buf)
99 {
100 int i;
101
102 for (i = 0; i < tile_num_regs; i++)
103 if (tile_regmap[i] != -1)
104 collect_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
105 }
106
107 static void
108 tile_store_gregset (struct regcache *regcache, const void *buf)
109 {
110 int i;
111
112 for (i = 0; i < tile_num_regs; i++)
113 if (tile_regmap[i] != -1)
114 supply_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]);
115 }
116
117 static struct regset_info tile_regsets[] =
118 {
119 { PTRACE_GETREGS, PTRACE_SETREGS, 0, tile_num_regs * 8,
120 GENERAL_REGS, tile_fill_gregset, tile_store_gregset },
121 NULL_REGSET
122 };
123
124 static struct regsets_info tile_regsets_info =
125 {
126 tile_regsets, /* regsets */
127 0, /* num_regsets */
128 NULL, /* disabled_regsets */
129 };
130
131 static struct usrregs_info tile_usrregs_info =
132 {
133 tile_num_regs,
134 tile_regmap,
135 };
136
137 static struct regs_info regs_info =
138 {
139 NULL, /* regset_bitmap */
140 &tile_usrregs_info,
141 &tile_regsets_info,
142 };
143
144 static const struct regs_info *
145 tile_regs_info (void)
146 {
147 return &regs_info;
148 }
149
150 static void
151 tile_arch_setup (void)
152 {
153 int pid = pid_of (current_thread);
154 unsigned int machine;
155 int is_elf64 = linux_pid_exe_is_elf_64_file (pid, &machine);
156
157 if (sizeof (void *) == 4)
158 if (is_elf64 > 0)
159 error (_("Can't debug 64-bit process with 32-bit GDBserver"));
160
161 if (!is_elf64)
162 current_process ()->tdesc = tdesc_tilegx32;
163 else
164 current_process ()->tdesc = tdesc_tilegx;
165 }
166
167 /* Support for hardware single step. */
168
169 static int
170 tile_supports_hardware_single_step (void)
171 {
172 return 1;
173 }
174
175
176 struct linux_target_ops the_low_target =
177 {
178 tile_arch_setup,
179 tile_regs_info,
180 tile_cannot_fetch_register,
181 tile_cannot_store_register,
182 NULL,
183 linux_get_pc_64bit,
184 linux_set_pc_64bit,
185 NULL, /* breakpoint_kind_from_pc */
186 tile_sw_breakpoint_from_kind,
187 NULL,
188 0,
189 tile_breakpoint_at,
190 NULL, /* supports_z_point_type */
191 NULL, /* insert_point */
192 NULL, /* remove_point */
193 NULL, /* stopped_by_watchpoint */
194 NULL, /* stopped_data_address */
195 NULL, /* collect_ptrace_register */
196 NULL, /* supply_ptrace_register */
197 NULL, /* siginfo_fixup */
198 NULL, /* new_process */
199 NULL, /* delete_process */
200 NULL, /* new_thread */
201 NULL, /* delete_thread */
202 NULL, /* new_fork */
203 NULL, /* prepare_to_resume */
204 NULL, /* process_qsupported */
205 NULL, /* supports_tracepoints */
206 NULL, /* get_thread_area */
207 NULL, /* install_fast_tracepoint_jump_pad */
208 NULL, /* emit_ops */
209 NULL, /* get_min_fast_tracepoint_insn_len */
210 NULL, /* supports_range_stepping */
211 NULL, /* breakpoint_kind_from_current_state */
212 tile_supports_hardware_single_step,
213 };
214
215 void
216 initialize_low_arch (void)
217 {
218 init_registers_tilegx32();
219 init_registers_tilegx();
220
221 initialize_regsets_info (&tile_regsets_info);
222 }
linux_get_pc_64bit
CORE_ADDR linux_get_pc_64bit(struct regcache *regcache)
Definition: linux-low.c:7436
current_thread
struct thread_info * current_thread
Definition: inferiors.c:28
collect_register
void collect_register(struct regcache *regcache, int n, void *buf)
Definition: regcache.c:402
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
tile_sw_breakpoint_from_kind
static const gdb_byte * tile_sw_breakpoint_from_kind(int kind, int *size)
Definition: linux-tile-low.c:77
linux_set_pc_64bit
void linux_set_pc_64bit(struct regcache *regcache, CORE_ADDR pc)
Definition: linux-low.c:7425
_
#define _(String)
Definition: gdb_locale.h:35
linux_target_ops
Definition: linux-low.h:128
tile_arch_setup
static void tile_arch_setup(void)
Definition: linux-tile-low.c:151
pid_of
static int pid_of(const thread_info *thread)
Definition: gdbthread.h:214
the_target
struct target_ops * the_target
Definition: target.c:24
process_info::tdesc
const struct target_desc * tdesc
Definition: inferiors.h:67
regcache
Definition: regcache.h:31
tile_breakpoint
static uint64_t tile_breakpoint
Definition: linux-tile-low.c:71
the_low_target
struct linux_target_ops the_low_target
Definition: linux-tile-low.c:176
tile_regs_info
static const struct regs_info * tile_regs_info(void)
Definition: linux-tile-low.c:145
tile_num_regs
#define tile_num_regs
Definition: linux-tile-low.c:34
tile_regmap
static int tile_regmap[]
Definition: linux-tile-low.c:36
linux-low.h
regs_info
Definition: linux-low.h:94
initialize_low_arch
void initialize_low_arch(void)
Definition: linux-tile-low.c:216
tdesc_tilegx
const struct target_desc * tdesc_tilegx
tile_cannot_fetch_register
static int tile_cannot_fetch_register(int regno)
Definition: linux-tile-low.c:50
server.h
tile_usrregs_info
static struct usrregs_info tile_usrregs_info
Definition: linux-tile-low.c:131
regs_info
static struct regs_info regs_info
Definition: linux-tile-low.c:137
current_process
struct process_info * current_process(void)
Definition: inferiors.c:210
tdesc_tilegx32
const struct target_desc * tdesc_tilegx32
usrregs_info
Definition: linux-low.h:83
tile_store_gregset
static void tile_store_gregset(struct regcache *regcache, const void *buf)
Definition: linux-tile-low.c:108
linux_pid_exe_is_elf_64_file
int linux_pid_exe_is_elf_64_file(int pid, unsigned int *machine)
Definition: linux-low.c:400
init_registers_tilegx32
void init_registers_tilegx32(void)
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
tile_cannot_store_register
static int tile_cannot_store_register(int regno)
Definition: linux-tile-low.c:61
target_desc
Definition: tdesc.h:33
target_ops::read_memory
int(* read_memory)(CORE_ADDR memaddr, unsigned char *myaddr, int len)
Definition: target.h:166
tile_supports_hardware_single_step
static int tile_supports_hardware_single_step(void)
Definition: linux-tile-low.c:170
gdb_ptrace.h
init_registers_tilegx
void init_registers_tilegx(void)
tile_regsets
static struct regset_info tile_regsets[]
Definition: linux-tile-low.c:117
tile_breakpoint_len
#define tile_breakpoint_len
Definition: linux-tile-low.c:72
tile_breakpoint_at
static int tile_breakpoint_at(CORE_ADDR where)
Definition: linux-tile-low.c:84
supply_register
void supply_register(struct regcache *regcache, int n, const void *buf)
Definition: regcache.c:318
error
void error(const char *fmt,...)
Definition: errors.c:38
tile_fill_gregset
static void tile_fill_gregset(struct regcache *regcache, void *buf)
Definition: linux-tile-low.c:98
tile_regsets_info
static struct regsets_info tile_regsets_info
Definition: linux-tile-low.c:124