Commit | Line | Data |
---|---|---|
65f479b6 PA |
1 | /* GNU/Linux/TILE-Gx specific low level interface, GDBserver. |
2 | ||
61baf725 | 3 | Copyright (C) 2012-2017 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 | |
e1f58301 JW |
26 | /* Defined in auto-generated file reg-tilegx.c. */ |
27 | void init_registers_tilegx (void); | |
3aee8918 PA |
28 | extern const struct target_desc *tdesc_tilegx; |
29 | ||
e1f58301 JW |
30 | /* Defined in auto-generated file reg-tilegx32.c. */ |
31 | void init_registers_tilegx32 (void); | |
3aee8918 | 32 | extern const struct target_desc *tdesc_tilegx32; |
65f479b6 PA |
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 | ||
65f479b6 PA |
71 | static uint64_t tile_breakpoint = 0x400b3cae70166000ULL; |
72 | #define tile_breakpoint_len 8 | |
73 | ||
dd373349 AT |
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 | ||
65f479b6 PA |
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) | |
e1f58301 | 104 | collect_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]); |
65f479b6 PA |
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) | |
e1f58301 | 114 | supply_register (regcache, i, ((uint_reg_t *) buf) + tile_regmap[i]); |
65f479b6 PA |
115 | } |
116 | ||
3aee8918 | 117 | static struct regset_info tile_regsets[] = |
65f479b6 | 118 | { |
d6707650 | 119 | { PTRACE_GETREGS, PTRACE_SETREGS, 0, tile_num_regs * 8, |
65f479b6 | 120 | GENERAL_REGS, tile_fill_gregset, tile_store_gregset }, |
50bc912a | 121 | NULL_REGSET |
65f479b6 PA |
122 | }; |
123 | ||
3aee8918 PA |
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 ®s_info; | |
148 | } | |
149 | ||
e1f58301 JW |
150 | static void |
151 | tile_arch_setup (void) | |
152 | { | |
0bfdf32f | 153 | int pid = pid_of (current_thread); |
e1f58301 JW |
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) | |
3aee8918 | 162 | current_process ()->tdesc = tdesc_tilegx32; |
e1f58301 | 163 | else |
3aee8918 | 164 | current_process ()->tdesc = tdesc_tilegx; |
e1f58301 JW |
165 | } |
166 | ||
7d00775e AT |
167 | /* Support for hardware single step. */ |
168 | ||
169 | static int | |
170 | tile_supports_hardware_single_step (void) | |
171 | { | |
172 | return 1; | |
173 | } | |
174 | ||
e1f58301 | 175 | |
65f479b6 PA |
176 | struct linux_target_ops the_low_target = |
177 | { | |
e1f58301 | 178 | tile_arch_setup, |
3aee8918 | 179 | tile_regs_info, |
65f479b6 PA |
180 | tile_cannot_fetch_register, |
181 | tile_cannot_store_register, | |
182 | NULL, | |
6f69e520 YQ |
183 | linux_get_pc_64bit, |
184 | linux_set_pc_64bit, | |
dd373349 AT |
185 | NULL, /* breakpoint_kind_from_pc */ |
186 | tile_sw_breakpoint_from_kind, | |
65f479b6 PA |
187 | NULL, |
188 | 0, | |
189 | tile_breakpoint_at, | |
7d00775e 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, /* new_thread */ | |
200 | NULL, /* new_fork */ | |
201 | NULL, /* prepare_to_resume */ | |
202 | NULL, /* process_qsupported */ | |
203 | NULL, /* supports_tracepoints */ | |
204 | NULL, /* get_thread_area */ | |
205 | NULL, /* install_fast_tracepoint_jump_pad */ | |
206 | NULL, /* emit_ops */ | |
207 | NULL, /* get_min_fast_tracepoint_insn_len */ | |
208 | NULL, /* supports_range_stepping */ | |
209 | NULL, /* breakpoint_kind_from_current_state */ | |
210 | tile_supports_hardware_single_step, | |
65f479b6 | 211 | }; |
3aee8918 PA |
212 | |
213 | void | |
214 | initialize_low_arch (void) | |
215 | { | |
216 | init_registers_tilegx32(); | |
217 | init_registers_tilegx(); | |
218 | ||
219 | initialize_regsets_info (&tile_regsets_info); | |
220 | } |