root / gdbstub.c @ 9ea37780
History | View | Annotate | Download (64.6 kB)
1 | b4608c04 | bellard | /*
|
---|---|---|---|
2 | b4608c04 | bellard | * gdb server stub
|
3 | 5fafdf24 | ths | *
|
4 | 3475187d | bellard | * Copyright (c) 2003-2005 Fabrice Bellard
|
5 | b4608c04 | bellard | *
|
6 | b4608c04 | bellard | * This library is free software; you can redistribute it and/or
|
7 | b4608c04 | bellard | * modify it under the terms of the GNU Lesser General Public
|
8 | b4608c04 | bellard | * License as published by the Free Software Foundation; either
|
9 | b4608c04 | bellard | * version 2 of the License, or (at your option) any later version.
|
10 | b4608c04 | bellard | *
|
11 | b4608c04 | bellard | * This library is distributed in the hope that it will be useful,
|
12 | b4608c04 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | b4608c04 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | b4608c04 | bellard | * Lesser General Public License for more details.
|
15 | b4608c04 | bellard | *
|
16 | b4608c04 | bellard | * You should have received a copy of the GNU Lesser General Public
|
17 | 8167ee88 | Blue Swirl | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | b4608c04 | bellard | */
|
19 | 978efd6a | pbrook | #include "config.h" |
20 | 56aebc89 | pbrook | #include "qemu-common.h" |
21 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
22 | 1fddef4b | bellard | #include <stdlib.h> |
23 | 1fddef4b | bellard | #include <stdio.h> |
24 | 1fddef4b | bellard | #include <stdarg.h> |
25 | 1fddef4b | bellard | #include <string.h> |
26 | 1fddef4b | bellard | #include <errno.h> |
27 | 1fddef4b | bellard | #include <unistd.h> |
28 | 978efd6a | pbrook | #include <fcntl.h> |
29 | 1fddef4b | bellard | |
30 | 1fddef4b | bellard | #include "qemu.h" |
31 | 1fddef4b | bellard | #else
|
32 | 8a34a0fb | aliguori | #include "monitor.h" |
33 | 87ecb68b | pbrook | #include "qemu-char.h" |
34 | 87ecb68b | pbrook | #include "sysemu.h" |
35 | 87ecb68b | pbrook | #include "gdbstub.h" |
36 | 1fddef4b | bellard | #endif
|
37 | 67b915a5 | bellard | |
38 | 56aebc89 | pbrook | #define MAX_PACKET_LENGTH 4096 |
39 | 56aebc89 | pbrook | |
40 | 8f447cc7 | bellard | #include "qemu_socket.h" |
41 | e22a25c9 | aliguori | #include "kvm.h" |
42 | ca587a8e | aurel32 | |
43 | ca587a8e | aurel32 | |
44 | ca587a8e | aurel32 | enum {
|
45 | ca587a8e | aurel32 | GDB_SIGNAL_0 = 0,
|
46 | ca587a8e | aurel32 | GDB_SIGNAL_INT = 2,
|
47 | ca587a8e | aurel32 | GDB_SIGNAL_TRAP = 5,
|
48 | ca587a8e | aurel32 | GDB_SIGNAL_UNKNOWN = 143
|
49 | ca587a8e | aurel32 | }; |
50 | ca587a8e | aurel32 | |
51 | ca587a8e | aurel32 | #ifdef CONFIG_USER_ONLY
|
52 | ca587a8e | aurel32 | |
53 | ca587a8e | aurel32 | /* Map target signal numbers to GDB protocol signal numbers and vice
|
54 | ca587a8e | aurel32 | * versa. For user emulation's currently supported systems, we can
|
55 | ca587a8e | aurel32 | * assume most signals are defined.
|
56 | ca587a8e | aurel32 | */
|
57 | ca587a8e | aurel32 | |
58 | ca587a8e | aurel32 | static int gdb_signal_table[] = { |
59 | ca587a8e | aurel32 | 0,
|
60 | ca587a8e | aurel32 | TARGET_SIGHUP, |
61 | ca587a8e | aurel32 | TARGET_SIGINT, |
62 | ca587a8e | aurel32 | TARGET_SIGQUIT, |
63 | ca587a8e | aurel32 | TARGET_SIGILL, |
64 | ca587a8e | aurel32 | TARGET_SIGTRAP, |
65 | ca587a8e | aurel32 | TARGET_SIGABRT, |
66 | ca587a8e | aurel32 | -1, /* SIGEMT */ |
67 | ca587a8e | aurel32 | TARGET_SIGFPE, |
68 | ca587a8e | aurel32 | TARGET_SIGKILL, |
69 | ca587a8e | aurel32 | TARGET_SIGBUS, |
70 | ca587a8e | aurel32 | TARGET_SIGSEGV, |
71 | ca587a8e | aurel32 | TARGET_SIGSYS, |
72 | ca587a8e | aurel32 | TARGET_SIGPIPE, |
73 | ca587a8e | aurel32 | TARGET_SIGALRM, |
74 | ca587a8e | aurel32 | TARGET_SIGTERM, |
75 | ca587a8e | aurel32 | TARGET_SIGURG, |
76 | ca587a8e | aurel32 | TARGET_SIGSTOP, |
77 | ca587a8e | aurel32 | TARGET_SIGTSTP, |
78 | ca587a8e | aurel32 | TARGET_SIGCONT, |
79 | ca587a8e | aurel32 | TARGET_SIGCHLD, |
80 | ca587a8e | aurel32 | TARGET_SIGTTIN, |
81 | ca587a8e | aurel32 | TARGET_SIGTTOU, |
82 | ca587a8e | aurel32 | TARGET_SIGIO, |
83 | ca587a8e | aurel32 | TARGET_SIGXCPU, |
84 | ca587a8e | aurel32 | TARGET_SIGXFSZ, |
85 | ca587a8e | aurel32 | TARGET_SIGVTALRM, |
86 | ca587a8e | aurel32 | TARGET_SIGPROF, |
87 | ca587a8e | aurel32 | TARGET_SIGWINCH, |
88 | ca587a8e | aurel32 | -1, /* SIGLOST */ |
89 | ca587a8e | aurel32 | TARGET_SIGUSR1, |
90 | ca587a8e | aurel32 | TARGET_SIGUSR2, |
91 | c72d5bf8 | blueswir1 | #ifdef TARGET_SIGPWR
|
92 | ca587a8e | aurel32 | TARGET_SIGPWR, |
93 | c72d5bf8 | blueswir1 | #else
|
94 | c72d5bf8 | blueswir1 | -1,
|
95 | c72d5bf8 | blueswir1 | #endif
|
96 | ca587a8e | aurel32 | -1, /* SIGPOLL */ |
97 | ca587a8e | aurel32 | -1,
|
98 | ca587a8e | aurel32 | -1,
|
99 | ca587a8e | aurel32 | -1,
|
100 | ca587a8e | aurel32 | -1,
|
101 | ca587a8e | aurel32 | -1,
|
102 | ca587a8e | aurel32 | -1,
|
103 | ca587a8e | aurel32 | -1,
|
104 | ca587a8e | aurel32 | -1,
|
105 | ca587a8e | aurel32 | -1,
|
106 | ca587a8e | aurel32 | -1,
|
107 | ca587a8e | aurel32 | -1,
|
108 | c72d5bf8 | blueswir1 | #ifdef __SIGRTMIN
|
109 | ca587a8e | aurel32 | __SIGRTMIN + 1,
|
110 | ca587a8e | aurel32 | __SIGRTMIN + 2,
|
111 | ca587a8e | aurel32 | __SIGRTMIN + 3,
|
112 | ca587a8e | aurel32 | __SIGRTMIN + 4,
|
113 | ca587a8e | aurel32 | __SIGRTMIN + 5,
|
114 | ca587a8e | aurel32 | __SIGRTMIN + 6,
|
115 | ca587a8e | aurel32 | __SIGRTMIN + 7,
|
116 | ca587a8e | aurel32 | __SIGRTMIN + 8,
|
117 | ca587a8e | aurel32 | __SIGRTMIN + 9,
|
118 | ca587a8e | aurel32 | __SIGRTMIN + 10,
|
119 | ca587a8e | aurel32 | __SIGRTMIN + 11,
|
120 | ca587a8e | aurel32 | __SIGRTMIN + 12,
|
121 | ca587a8e | aurel32 | __SIGRTMIN + 13,
|
122 | ca587a8e | aurel32 | __SIGRTMIN + 14,
|
123 | ca587a8e | aurel32 | __SIGRTMIN + 15,
|
124 | ca587a8e | aurel32 | __SIGRTMIN + 16,
|
125 | ca587a8e | aurel32 | __SIGRTMIN + 17,
|
126 | ca587a8e | aurel32 | __SIGRTMIN + 18,
|
127 | ca587a8e | aurel32 | __SIGRTMIN + 19,
|
128 | ca587a8e | aurel32 | __SIGRTMIN + 20,
|
129 | ca587a8e | aurel32 | __SIGRTMIN + 21,
|
130 | ca587a8e | aurel32 | __SIGRTMIN + 22,
|
131 | ca587a8e | aurel32 | __SIGRTMIN + 23,
|
132 | ca587a8e | aurel32 | __SIGRTMIN + 24,
|
133 | ca587a8e | aurel32 | __SIGRTMIN + 25,
|
134 | ca587a8e | aurel32 | __SIGRTMIN + 26,
|
135 | ca587a8e | aurel32 | __SIGRTMIN + 27,
|
136 | ca587a8e | aurel32 | __SIGRTMIN + 28,
|
137 | ca587a8e | aurel32 | __SIGRTMIN + 29,
|
138 | ca587a8e | aurel32 | __SIGRTMIN + 30,
|
139 | ca587a8e | aurel32 | __SIGRTMIN + 31,
|
140 | ca587a8e | aurel32 | -1, /* SIGCANCEL */ |
141 | ca587a8e | aurel32 | __SIGRTMIN, |
142 | ca587a8e | aurel32 | __SIGRTMIN + 32,
|
143 | ca587a8e | aurel32 | __SIGRTMIN + 33,
|
144 | ca587a8e | aurel32 | __SIGRTMIN + 34,
|
145 | ca587a8e | aurel32 | __SIGRTMIN + 35,
|
146 | ca587a8e | aurel32 | __SIGRTMIN + 36,
|
147 | ca587a8e | aurel32 | __SIGRTMIN + 37,
|
148 | ca587a8e | aurel32 | __SIGRTMIN + 38,
|
149 | ca587a8e | aurel32 | __SIGRTMIN + 39,
|
150 | ca587a8e | aurel32 | __SIGRTMIN + 40,
|
151 | ca587a8e | aurel32 | __SIGRTMIN + 41,
|
152 | ca587a8e | aurel32 | __SIGRTMIN + 42,
|
153 | ca587a8e | aurel32 | __SIGRTMIN + 43,
|
154 | ca587a8e | aurel32 | __SIGRTMIN + 44,
|
155 | ca587a8e | aurel32 | __SIGRTMIN + 45,
|
156 | ca587a8e | aurel32 | __SIGRTMIN + 46,
|
157 | ca587a8e | aurel32 | __SIGRTMIN + 47,
|
158 | ca587a8e | aurel32 | __SIGRTMIN + 48,
|
159 | ca587a8e | aurel32 | __SIGRTMIN + 49,
|
160 | ca587a8e | aurel32 | __SIGRTMIN + 50,
|
161 | ca587a8e | aurel32 | __SIGRTMIN + 51,
|
162 | ca587a8e | aurel32 | __SIGRTMIN + 52,
|
163 | ca587a8e | aurel32 | __SIGRTMIN + 53,
|
164 | ca587a8e | aurel32 | __SIGRTMIN + 54,
|
165 | ca587a8e | aurel32 | __SIGRTMIN + 55,
|
166 | ca587a8e | aurel32 | __SIGRTMIN + 56,
|
167 | ca587a8e | aurel32 | __SIGRTMIN + 57,
|
168 | ca587a8e | aurel32 | __SIGRTMIN + 58,
|
169 | ca587a8e | aurel32 | __SIGRTMIN + 59,
|
170 | ca587a8e | aurel32 | __SIGRTMIN + 60,
|
171 | ca587a8e | aurel32 | __SIGRTMIN + 61,
|
172 | ca587a8e | aurel32 | __SIGRTMIN + 62,
|
173 | ca587a8e | aurel32 | __SIGRTMIN + 63,
|
174 | ca587a8e | aurel32 | __SIGRTMIN + 64,
|
175 | ca587a8e | aurel32 | __SIGRTMIN + 65,
|
176 | ca587a8e | aurel32 | __SIGRTMIN + 66,
|
177 | ca587a8e | aurel32 | __SIGRTMIN + 67,
|
178 | ca587a8e | aurel32 | __SIGRTMIN + 68,
|
179 | ca587a8e | aurel32 | __SIGRTMIN + 69,
|
180 | ca587a8e | aurel32 | __SIGRTMIN + 70,
|
181 | ca587a8e | aurel32 | __SIGRTMIN + 71,
|
182 | ca587a8e | aurel32 | __SIGRTMIN + 72,
|
183 | ca587a8e | aurel32 | __SIGRTMIN + 73,
|
184 | ca587a8e | aurel32 | __SIGRTMIN + 74,
|
185 | ca587a8e | aurel32 | __SIGRTMIN + 75,
|
186 | ca587a8e | aurel32 | __SIGRTMIN + 76,
|
187 | ca587a8e | aurel32 | __SIGRTMIN + 77,
|
188 | ca587a8e | aurel32 | __SIGRTMIN + 78,
|
189 | ca587a8e | aurel32 | __SIGRTMIN + 79,
|
190 | ca587a8e | aurel32 | __SIGRTMIN + 80,
|
191 | ca587a8e | aurel32 | __SIGRTMIN + 81,
|
192 | ca587a8e | aurel32 | __SIGRTMIN + 82,
|
193 | ca587a8e | aurel32 | __SIGRTMIN + 83,
|
194 | ca587a8e | aurel32 | __SIGRTMIN + 84,
|
195 | ca587a8e | aurel32 | __SIGRTMIN + 85,
|
196 | ca587a8e | aurel32 | __SIGRTMIN + 86,
|
197 | ca587a8e | aurel32 | __SIGRTMIN + 87,
|
198 | ca587a8e | aurel32 | __SIGRTMIN + 88,
|
199 | ca587a8e | aurel32 | __SIGRTMIN + 89,
|
200 | ca587a8e | aurel32 | __SIGRTMIN + 90,
|
201 | ca587a8e | aurel32 | __SIGRTMIN + 91,
|
202 | ca587a8e | aurel32 | __SIGRTMIN + 92,
|
203 | ca587a8e | aurel32 | __SIGRTMIN + 93,
|
204 | ca587a8e | aurel32 | __SIGRTMIN + 94,
|
205 | ca587a8e | aurel32 | __SIGRTMIN + 95,
|
206 | ca587a8e | aurel32 | -1, /* SIGINFO */ |
207 | ca587a8e | aurel32 | -1, /* UNKNOWN */ |
208 | ca587a8e | aurel32 | -1, /* DEFAULT */ |
209 | ca587a8e | aurel32 | -1,
|
210 | ca587a8e | aurel32 | -1,
|
211 | ca587a8e | aurel32 | -1,
|
212 | ca587a8e | aurel32 | -1,
|
213 | ca587a8e | aurel32 | -1,
|
214 | ca587a8e | aurel32 | -1
|
215 | c72d5bf8 | blueswir1 | #endif
|
216 | ca587a8e | aurel32 | }; |
217 | 8f447cc7 | bellard | #else
|
218 | ca587a8e | aurel32 | /* In system mode we only need SIGINT and SIGTRAP; other signals
|
219 | ca587a8e | aurel32 | are not yet supported. */
|
220 | ca587a8e | aurel32 | |
221 | ca587a8e | aurel32 | enum {
|
222 | ca587a8e | aurel32 | TARGET_SIGINT = 2,
|
223 | ca587a8e | aurel32 | TARGET_SIGTRAP = 5
|
224 | ca587a8e | aurel32 | }; |
225 | ca587a8e | aurel32 | |
226 | ca587a8e | aurel32 | static int gdb_signal_table[] = { |
227 | ca587a8e | aurel32 | -1,
|
228 | ca587a8e | aurel32 | -1,
|
229 | ca587a8e | aurel32 | TARGET_SIGINT, |
230 | ca587a8e | aurel32 | -1,
|
231 | ca587a8e | aurel32 | -1,
|
232 | ca587a8e | aurel32 | TARGET_SIGTRAP |
233 | ca587a8e | aurel32 | }; |
234 | ca587a8e | aurel32 | #endif
|
235 | ca587a8e | aurel32 | |
236 | ca587a8e | aurel32 | #ifdef CONFIG_USER_ONLY
|
237 | ca587a8e | aurel32 | static int target_signal_to_gdb (int sig) |
238 | ca587a8e | aurel32 | { |
239 | ca587a8e | aurel32 | int i;
|
240 | ca587a8e | aurel32 | for (i = 0; i < ARRAY_SIZE (gdb_signal_table); i++) |
241 | ca587a8e | aurel32 | if (gdb_signal_table[i] == sig)
|
242 | ca587a8e | aurel32 | return i;
|
243 | ca587a8e | aurel32 | return GDB_SIGNAL_UNKNOWN;
|
244 | ca587a8e | aurel32 | } |
245 | 8f447cc7 | bellard | #endif
|
246 | b4608c04 | bellard | |
247 | ca587a8e | aurel32 | static int gdb_signal_to_target (int sig) |
248 | ca587a8e | aurel32 | { |
249 | ca587a8e | aurel32 | if (sig < ARRAY_SIZE (gdb_signal_table))
|
250 | ca587a8e | aurel32 | return gdb_signal_table[sig];
|
251 | ca587a8e | aurel32 | else
|
252 | ca587a8e | aurel32 | return -1; |
253 | ca587a8e | aurel32 | } |
254 | ca587a8e | aurel32 | |
255 | 4abe615b | bellard | //#define DEBUG_GDB
|
256 | b4608c04 | bellard | |
257 | 56aebc89 | pbrook | typedef struct GDBRegisterState { |
258 | 56aebc89 | pbrook | int base_reg;
|
259 | 56aebc89 | pbrook | int num_regs;
|
260 | 56aebc89 | pbrook | gdb_reg_cb get_reg; |
261 | 56aebc89 | pbrook | gdb_reg_cb set_reg; |
262 | 56aebc89 | pbrook | const char *xml; |
263 | 56aebc89 | pbrook | struct GDBRegisterState *next;
|
264 | 56aebc89 | pbrook | } GDBRegisterState; |
265 | 56aebc89 | pbrook | |
266 | 858693c6 | bellard | enum RSState {
|
267 | 36556b20 | aliguori | RS_INACTIVE, |
268 | 858693c6 | bellard | RS_IDLE, |
269 | 858693c6 | bellard | RS_GETLINE, |
270 | 858693c6 | bellard | RS_CHKSUM1, |
271 | 858693c6 | bellard | RS_CHKSUM2, |
272 | a2d1ebaf | pbrook | RS_SYSCALL, |
273 | 858693c6 | bellard | }; |
274 | 858693c6 | bellard | typedef struct GDBState { |
275 | 880a7578 | aliguori | CPUState *c_cpu; /* current CPU for step/continue ops */
|
276 | 880a7578 | aliguori | CPUState *g_cpu; /* current CPU for other ops */
|
277 | 880a7578 | aliguori | CPUState *query_cpu; /* for q{f|s}ThreadInfo */
|
278 | 41625033 | bellard | enum RSState state; /* parsing state */ |
279 | 56aebc89 | pbrook | char line_buf[MAX_PACKET_LENGTH];
|
280 | 858693c6 | bellard | int line_buf_index;
|
281 | 858693c6 | bellard | int line_csum;
|
282 | 56aebc89 | pbrook | uint8_t last_packet[MAX_PACKET_LENGTH + 4];
|
283 | 4046d913 | pbrook | int last_packet_len;
|
284 | 1f487ee9 | edgar_igl | int signal;
|
285 | 41625033 | bellard | #ifdef CONFIG_USER_ONLY
|
286 | 4046d913 | pbrook | int fd;
|
287 | 41625033 | bellard | int running_state;
|
288 | 4046d913 | pbrook | #else
|
289 | 4046d913 | pbrook | CharDriverState *chr; |
290 | 8a34a0fb | aliguori | CharDriverState *mon_chr; |
291 | 41625033 | bellard | #endif
|
292 | 858693c6 | bellard | } GDBState; |
293 | b4608c04 | bellard | |
294 | 60897d36 | edgar_igl | /* By default use no IRQs and no timers while single stepping so as to
|
295 | 60897d36 | edgar_igl | * make single stepping like an ICE HW step.
|
296 | 60897d36 | edgar_igl | */
|
297 | 60897d36 | edgar_igl | static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; |
298 | 60897d36 | edgar_igl | |
299 | 880a7578 | aliguori | static GDBState *gdbserver_state;
|
300 | 880a7578 | aliguori | |
301 | 56aebc89 | pbrook | /* This is an ugly hack to cope with both new and old gdb.
|
302 | 56aebc89 | pbrook | If gdb sends qXfer:features:read then assume we're talking to a newish
|
303 | 56aebc89 | pbrook | gdb that understands target descriptions. */
|
304 | 56aebc89 | pbrook | static int gdb_has_xml; |
305 | 56aebc89 | pbrook | |
306 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
307 | 4046d913 | pbrook | /* XXX: This is not thread safe. Do we care? */
|
308 | 4046d913 | pbrook | static int gdbserver_fd = -1; |
309 | 4046d913 | pbrook | |
310 | 858693c6 | bellard | static int get_char(GDBState *s) |
311 | b4608c04 | bellard | { |
312 | b4608c04 | bellard | uint8_t ch; |
313 | b4608c04 | bellard | int ret;
|
314 | b4608c04 | bellard | |
315 | b4608c04 | bellard | for(;;) {
|
316 | 8f447cc7 | bellard | ret = recv(s->fd, &ch, 1, 0); |
317 | b4608c04 | bellard | if (ret < 0) { |
318 | 1f487ee9 | edgar_igl | if (errno == ECONNRESET)
|
319 | 1f487ee9 | edgar_igl | s->fd = -1;
|
320 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
321 | b4608c04 | bellard | return -1; |
322 | b4608c04 | bellard | } else if (ret == 0) { |
323 | 1f487ee9 | edgar_igl | close(s->fd); |
324 | 1f487ee9 | edgar_igl | s->fd = -1;
|
325 | b4608c04 | bellard | return -1; |
326 | b4608c04 | bellard | } else {
|
327 | b4608c04 | bellard | break;
|
328 | b4608c04 | bellard | } |
329 | b4608c04 | bellard | } |
330 | b4608c04 | bellard | return ch;
|
331 | b4608c04 | bellard | } |
332 | 4046d913 | pbrook | #endif
|
333 | b4608c04 | bellard | |
334 | a2d1ebaf | pbrook | static gdb_syscall_complete_cb gdb_current_syscall_cb;
|
335 | a2d1ebaf | pbrook | |
336 | 654efcf3 | blueswir1 | static enum { |
337 | a2d1ebaf | pbrook | GDB_SYS_UNKNOWN, |
338 | a2d1ebaf | pbrook | GDB_SYS_ENABLED, |
339 | a2d1ebaf | pbrook | GDB_SYS_DISABLED, |
340 | a2d1ebaf | pbrook | } gdb_syscall_mode; |
341 | a2d1ebaf | pbrook | |
342 | a2d1ebaf | pbrook | /* If gdb is connected when the first semihosting syscall occurs then use
|
343 | a2d1ebaf | pbrook | remote gdb syscalls. Otherwise use native file IO. */
|
344 | a2d1ebaf | pbrook | int use_gdb_syscalls(void) |
345 | a2d1ebaf | pbrook | { |
346 | a2d1ebaf | pbrook | if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
|
347 | 880a7578 | aliguori | gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED |
348 | 880a7578 | aliguori | : GDB_SYS_DISABLED); |
349 | a2d1ebaf | pbrook | } |
350 | a2d1ebaf | pbrook | return gdb_syscall_mode == GDB_SYS_ENABLED;
|
351 | a2d1ebaf | pbrook | } |
352 | a2d1ebaf | pbrook | |
353 | ba70a624 | edgar_igl | /* Resume execution. */
|
354 | ba70a624 | edgar_igl | static inline void gdb_continue(GDBState *s) |
355 | ba70a624 | edgar_igl | { |
356 | ba70a624 | edgar_igl | #ifdef CONFIG_USER_ONLY
|
357 | ba70a624 | edgar_igl | s->running_state = 1;
|
358 | ba70a624 | edgar_igl | #else
|
359 | ba70a624 | edgar_igl | vm_start(); |
360 | ba70a624 | edgar_igl | #endif
|
361 | ba70a624 | edgar_igl | } |
362 | ba70a624 | edgar_igl | |
363 | 858693c6 | bellard | static void put_buffer(GDBState *s, const uint8_t *buf, int len) |
364 | b4608c04 | bellard | { |
365 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
366 | b4608c04 | bellard | int ret;
|
367 | b4608c04 | bellard | |
368 | b4608c04 | bellard | while (len > 0) { |
369 | 8f447cc7 | bellard | ret = send(s->fd, buf, len, 0);
|
370 | b4608c04 | bellard | if (ret < 0) { |
371 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
372 | b4608c04 | bellard | return;
|
373 | b4608c04 | bellard | } else {
|
374 | b4608c04 | bellard | buf += ret; |
375 | b4608c04 | bellard | len -= ret; |
376 | b4608c04 | bellard | } |
377 | b4608c04 | bellard | } |
378 | 4046d913 | pbrook | #else
|
379 | 4046d913 | pbrook | qemu_chr_write(s->chr, buf, len); |
380 | 4046d913 | pbrook | #endif
|
381 | b4608c04 | bellard | } |
382 | b4608c04 | bellard | |
383 | b4608c04 | bellard | static inline int fromhex(int v) |
384 | b4608c04 | bellard | { |
385 | b4608c04 | bellard | if (v >= '0' && v <= '9') |
386 | b4608c04 | bellard | return v - '0'; |
387 | b4608c04 | bellard | else if (v >= 'A' && v <= 'F') |
388 | b4608c04 | bellard | return v - 'A' + 10; |
389 | b4608c04 | bellard | else if (v >= 'a' && v <= 'f') |
390 | b4608c04 | bellard | return v - 'a' + 10; |
391 | b4608c04 | bellard | else
|
392 | b4608c04 | bellard | return 0; |
393 | b4608c04 | bellard | } |
394 | b4608c04 | bellard | |
395 | b4608c04 | bellard | static inline int tohex(int v) |
396 | b4608c04 | bellard | { |
397 | b4608c04 | bellard | if (v < 10) |
398 | b4608c04 | bellard | return v + '0'; |
399 | b4608c04 | bellard | else
|
400 | b4608c04 | bellard | return v - 10 + 'a'; |
401 | b4608c04 | bellard | } |
402 | b4608c04 | bellard | |
403 | b4608c04 | bellard | static void memtohex(char *buf, const uint8_t *mem, int len) |
404 | b4608c04 | bellard | { |
405 | b4608c04 | bellard | int i, c;
|
406 | b4608c04 | bellard | char *q;
|
407 | b4608c04 | bellard | q = buf; |
408 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
409 | b4608c04 | bellard | c = mem[i]; |
410 | b4608c04 | bellard | *q++ = tohex(c >> 4);
|
411 | b4608c04 | bellard | *q++ = tohex(c & 0xf);
|
412 | b4608c04 | bellard | } |
413 | b4608c04 | bellard | *q = '\0';
|
414 | b4608c04 | bellard | } |
415 | b4608c04 | bellard | |
416 | b4608c04 | bellard | static void hextomem(uint8_t *mem, const char *buf, int len) |
417 | b4608c04 | bellard | { |
418 | b4608c04 | bellard | int i;
|
419 | b4608c04 | bellard | |
420 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
421 | b4608c04 | bellard | mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]); |
422 | b4608c04 | bellard | buf += 2;
|
423 | b4608c04 | bellard | } |
424 | b4608c04 | bellard | } |
425 | b4608c04 | bellard | |
426 | b4608c04 | bellard | /* return -1 if error, 0 if OK */
|
427 | 56aebc89 | pbrook | static int put_packet_binary(GDBState *s, const char *buf, int len) |
428 | b4608c04 | bellard | { |
429 | 56aebc89 | pbrook | int csum, i;
|
430 | 60fe76f3 | ths | uint8_t *p; |
431 | b4608c04 | bellard | |
432 | b4608c04 | bellard | for(;;) {
|
433 | 4046d913 | pbrook | p = s->last_packet; |
434 | 4046d913 | pbrook | *(p++) = '$';
|
435 | 4046d913 | pbrook | memcpy(p, buf, len); |
436 | 4046d913 | pbrook | p += len; |
437 | b4608c04 | bellard | csum = 0;
|
438 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
439 | b4608c04 | bellard | csum += buf[i]; |
440 | b4608c04 | bellard | } |
441 | 4046d913 | pbrook | *(p++) = '#';
|
442 | 4046d913 | pbrook | *(p++) = tohex((csum >> 4) & 0xf); |
443 | 4046d913 | pbrook | *(p++) = tohex((csum) & 0xf);
|
444 | b4608c04 | bellard | |
445 | 4046d913 | pbrook | s->last_packet_len = p - s->last_packet; |
446 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
447 | b4608c04 | bellard | |
448 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
449 | 4046d913 | pbrook | i = get_char(s); |
450 | 4046d913 | pbrook | if (i < 0) |
451 | b4608c04 | bellard | return -1; |
452 | 4046d913 | pbrook | if (i == '+') |
453 | b4608c04 | bellard | break;
|
454 | 4046d913 | pbrook | #else
|
455 | 4046d913 | pbrook | break;
|
456 | 4046d913 | pbrook | #endif
|
457 | b4608c04 | bellard | } |
458 | b4608c04 | bellard | return 0; |
459 | b4608c04 | bellard | } |
460 | b4608c04 | bellard | |
461 | 56aebc89 | pbrook | /* return -1 if error, 0 if OK */
|
462 | 56aebc89 | pbrook | static int put_packet(GDBState *s, const char *buf) |
463 | 56aebc89 | pbrook | { |
464 | 56aebc89 | pbrook | #ifdef DEBUG_GDB
|
465 | 56aebc89 | pbrook | printf("reply='%s'\n", buf);
|
466 | 56aebc89 | pbrook | #endif
|
467 | 79808573 | bellard | |
468 | 56aebc89 | pbrook | return put_packet_binary(s, buf, strlen(buf));
|
469 | 56aebc89 | pbrook | } |
470 | 56aebc89 | pbrook | |
471 | 56aebc89 | pbrook | /* The GDB remote protocol transfers values in target byte order. This means
|
472 | 56aebc89 | pbrook | we can use the raw memory access routines to access the value buffer.
|
473 | 56aebc89 | pbrook | Conveniently, these also handle the case where the buffer is mis-aligned.
|
474 | 56aebc89 | pbrook | */
|
475 | 56aebc89 | pbrook | #define GET_REG8(val) do { \ |
476 | 56aebc89 | pbrook | stb_p(mem_buf, val); \ |
477 | 56aebc89 | pbrook | return 1; \ |
478 | 56aebc89 | pbrook | } while(0) |
479 | 56aebc89 | pbrook | #define GET_REG16(val) do { \ |
480 | 56aebc89 | pbrook | stw_p(mem_buf, val); \ |
481 | 56aebc89 | pbrook | return 2; \ |
482 | 56aebc89 | pbrook | } while(0) |
483 | 56aebc89 | pbrook | #define GET_REG32(val) do { \ |
484 | 56aebc89 | pbrook | stl_p(mem_buf, val); \ |
485 | 56aebc89 | pbrook | return 4; \ |
486 | 56aebc89 | pbrook | } while(0) |
487 | 56aebc89 | pbrook | #define GET_REG64(val) do { \ |
488 | 56aebc89 | pbrook | stq_p(mem_buf, val); \ |
489 | 56aebc89 | pbrook | return 8; \ |
490 | 56aebc89 | pbrook | } while(0) |
491 | 56aebc89 | pbrook | |
492 | 56aebc89 | pbrook | #if TARGET_LONG_BITS == 64 |
493 | 56aebc89 | pbrook | #define GET_REGL(val) GET_REG64(val)
|
494 | 56aebc89 | pbrook | #define ldtul_p(addr) ldq_p(addr)
|
495 | 56aebc89 | pbrook | #else
|
496 | 56aebc89 | pbrook | #define GET_REGL(val) GET_REG32(val)
|
497 | 56aebc89 | pbrook | #define ldtul_p(addr) ldl_p(addr)
|
498 | 79808573 | bellard | #endif
|
499 | 79808573 | bellard | |
500 | 56aebc89 | pbrook | #if defined(TARGET_I386)
|
501 | 5ad265ee | balrog | |
502 | 5ad265ee | balrog | #ifdef TARGET_X86_64
|
503 | 56aebc89 | pbrook | static const int gpr_map[16] = { |
504 | 56aebc89 | pbrook | R_EAX, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI, R_EBP, R_ESP, |
505 | 56aebc89 | pbrook | 8, 9, 10, 11, 12, 13, 14, 15 |
506 | 56aebc89 | pbrook | }; |
507 | 79808573 | bellard | #else
|
508 | 5f30fa18 | Jan Kiszka | #define gpr_map gpr_map32
|
509 | 79808573 | bellard | #endif
|
510 | 5f30fa18 | Jan Kiszka | static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
511 | 79808573 | bellard | |
512 | 56aebc89 | pbrook | #define NUM_CORE_REGS (CPU_NB_REGS * 2 + 25) |
513 | 56aebc89 | pbrook | |
514 | b1631e7a | Jan Kiszka | #define IDX_IP_REG CPU_NB_REGS
|
515 | b1631e7a | Jan Kiszka | #define IDX_FLAGS_REG (IDX_IP_REG + 1) |
516 | b1631e7a | Jan Kiszka | #define IDX_SEG_REGS (IDX_FLAGS_REG + 1) |
517 | b1631e7a | Jan Kiszka | #define IDX_FP_REGS (IDX_SEG_REGS + 6) |
518 | b1631e7a | Jan Kiszka | #define IDX_XMM_REGS (IDX_FP_REGS + 16) |
519 | b1631e7a | Jan Kiszka | #define IDX_MXCSR_REG (IDX_XMM_REGS + CPU_NB_REGS)
|
520 | b1631e7a | Jan Kiszka | |
521 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
522 | 79808573 | bellard | { |
523 | 56aebc89 | pbrook | if (n < CPU_NB_REGS) {
|
524 | 5f30fa18 | Jan Kiszka | if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) { |
525 | 5f30fa18 | Jan Kiszka | GET_REG64(env->regs[gpr_map[n]]); |
526 | 5f30fa18 | Jan Kiszka | } else if (n < CPU_NB_REGS32) { |
527 | 5f30fa18 | Jan Kiszka | GET_REG32(env->regs[gpr_map32[n]]); |
528 | 5f30fa18 | Jan Kiszka | } |
529 | b1631e7a | Jan Kiszka | } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) { |
530 | 56aebc89 | pbrook | #ifdef USE_X86LDOUBLE
|
531 | b1631e7a | Jan Kiszka | /* FIXME: byteswap float values - after fixing fpregs layout. */
|
532 | b1631e7a | Jan Kiszka | memcpy(mem_buf, &env->fpregs[n - IDX_FP_REGS], 10);
|
533 | 79808573 | bellard | #else
|
534 | 56aebc89 | pbrook | memset(mem_buf, 0, 10); |
535 | 79808573 | bellard | #endif
|
536 | 56aebc89 | pbrook | return 10; |
537 | b1631e7a | Jan Kiszka | } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) { |
538 | b1631e7a | Jan Kiszka | n -= IDX_XMM_REGS; |
539 | 5f30fa18 | Jan Kiszka | if (n < CPU_NB_REGS32 ||
|
540 | 5f30fa18 | Jan Kiszka | (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK)) {
|
541 | 5f30fa18 | Jan Kiszka | stq_p(mem_buf, env->xmm_regs[n].XMM_Q(0));
|
542 | 5f30fa18 | Jan Kiszka | stq_p(mem_buf + 8, env->xmm_regs[n].XMM_Q(1)); |
543 | 5f30fa18 | Jan Kiszka | return 16; |
544 | 5f30fa18 | Jan Kiszka | } |
545 | 56aebc89 | pbrook | } else {
|
546 | 56aebc89 | pbrook | switch (n) {
|
547 | 5f30fa18 | Jan Kiszka | case IDX_IP_REG:
|
548 | 5f30fa18 | Jan Kiszka | if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) { |
549 | 5f30fa18 | Jan Kiszka | GET_REG64(env->eip); |
550 | 5f30fa18 | Jan Kiszka | } else {
|
551 | 5f30fa18 | Jan Kiszka | GET_REG32(env->eip); |
552 | 5f30fa18 | Jan Kiszka | } |
553 | b1631e7a | Jan Kiszka | case IDX_FLAGS_REG: GET_REG32(env->eflags);
|
554 | b1631e7a | Jan Kiszka | |
555 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS: GET_REG32(env->segs[R_CS].selector);
|
556 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS + 1: GET_REG32(env->segs[R_SS].selector); |
557 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS + 2: GET_REG32(env->segs[R_DS].selector); |
558 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS + 3: GET_REG32(env->segs[R_ES].selector); |
559 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS + 4: GET_REG32(env->segs[R_FS].selector); |
560 | b1631e7a | Jan Kiszka | case IDX_SEG_REGS + 5: GET_REG32(env->segs[R_GS].selector); |
561 | b1631e7a | Jan Kiszka | |
562 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 8: GET_REG32(env->fpuc); |
563 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 9: GET_REG32((env->fpus & ~0x3800) | |
564 | b1631e7a | Jan Kiszka | (env->fpstt & 0x7) << 11); |
565 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 10: GET_REG32(0); /* ftag */ |
566 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 11: GET_REG32(0); /* fiseg */ |
567 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 12: GET_REG32(0); /* fioff */ |
568 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 13: GET_REG32(0); /* foseg */ |
569 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 14: GET_REG32(0); /* fooff */ |
570 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 15: GET_REG32(0); /* fop */ |
571 | b1631e7a | Jan Kiszka | |
572 | b1631e7a | Jan Kiszka | case IDX_MXCSR_REG: GET_REG32(env->mxcsr);
|
573 | 56aebc89 | pbrook | } |
574 | 79808573 | bellard | } |
575 | 56aebc89 | pbrook | return 0; |
576 | 6da41eaf | bellard | } |
577 | 6da41eaf | bellard | |
578 | 84273177 | Jan Kiszka | static int cpu_x86_gdb_load_seg(CPUState *env, int sreg, uint8_t *mem_buf) |
579 | 84273177 | Jan Kiszka | { |
580 | 84273177 | Jan Kiszka | uint16_t selector = ldl_p(mem_buf); |
581 | 84273177 | Jan Kiszka | |
582 | 84273177 | Jan Kiszka | if (selector != env->segs[sreg].selector) {
|
583 | 84273177 | Jan Kiszka | #if defined(CONFIG_USER_ONLY)
|
584 | 84273177 | Jan Kiszka | cpu_x86_load_seg(env, sreg, selector); |
585 | 84273177 | Jan Kiszka | #else
|
586 | 84273177 | Jan Kiszka | unsigned int limit, flags; |
587 | 84273177 | Jan Kiszka | target_ulong base; |
588 | 84273177 | Jan Kiszka | |
589 | 84273177 | Jan Kiszka | if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { |
590 | 84273177 | Jan Kiszka | base = selector << 4;
|
591 | 84273177 | Jan Kiszka | limit = 0xffff;
|
592 | 84273177 | Jan Kiszka | flags = 0;
|
593 | 84273177 | Jan Kiszka | } else {
|
594 | 84273177 | Jan Kiszka | if (!cpu_x86_get_descr_debug(env, selector, &base, &limit, &flags))
|
595 | 84273177 | Jan Kiszka | return 4; |
596 | 84273177 | Jan Kiszka | } |
597 | 84273177 | Jan Kiszka | cpu_x86_load_seg_cache(env, sreg, selector, base, limit, flags); |
598 | 84273177 | Jan Kiszka | #endif
|
599 | 84273177 | Jan Kiszka | } |
600 | 84273177 | Jan Kiszka | return 4; |
601 | 84273177 | Jan Kiszka | } |
602 | 84273177 | Jan Kiszka | |
603 | b1631e7a | Jan Kiszka | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
604 | 6da41eaf | bellard | { |
605 | 56aebc89 | pbrook | uint32_t tmp; |
606 | 6da41eaf | bellard | |
607 | b1631e7a | Jan Kiszka | if (n < CPU_NB_REGS) {
|
608 | 5f30fa18 | Jan Kiszka | if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) { |
609 | 5f30fa18 | Jan Kiszka | env->regs[gpr_map[n]] = ldtul_p(mem_buf); |
610 | 5f30fa18 | Jan Kiszka | return sizeof(target_ulong); |
611 | 5f30fa18 | Jan Kiszka | } else if (n < CPU_NB_REGS32) { |
612 | 5f30fa18 | Jan Kiszka | n = gpr_map32[n]; |
613 | 5f30fa18 | Jan Kiszka | env->regs[n] &= ~0xffffffffUL;
|
614 | 5f30fa18 | Jan Kiszka | env->regs[n] |= (uint32_t)ldl_p(mem_buf); |
615 | 5f30fa18 | Jan Kiszka | return 4; |
616 | 5f30fa18 | Jan Kiszka | } |
617 | b1631e7a | Jan Kiszka | } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) { |
618 | 56aebc89 | pbrook | #ifdef USE_X86LDOUBLE
|
619 | b1631e7a | Jan Kiszka | /* FIXME: byteswap float values - after fixing fpregs layout. */
|
620 | b1631e7a | Jan Kiszka | memcpy(&env->fpregs[n - IDX_FP_REGS], mem_buf, 10);
|
621 | 79808573 | bellard | #endif
|
622 | 56aebc89 | pbrook | return 10; |
623 | b1631e7a | Jan Kiszka | } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) { |
624 | b1631e7a | Jan Kiszka | n -= IDX_XMM_REGS; |
625 | 5f30fa18 | Jan Kiszka | if (n < CPU_NB_REGS32 ||
|
626 | 5f30fa18 | Jan Kiszka | (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK)) {
|
627 | 5f30fa18 | Jan Kiszka | env->xmm_regs[n].XMM_Q(0) = ldq_p(mem_buf);
|
628 | 5f30fa18 | Jan Kiszka | env->xmm_regs[n].XMM_Q(1) = ldq_p(mem_buf + 8); |
629 | 5f30fa18 | Jan Kiszka | return 16; |
630 | 5f30fa18 | Jan Kiszka | } |
631 | 56aebc89 | pbrook | } else {
|
632 | b1631e7a | Jan Kiszka | switch (n) {
|
633 | b1631e7a | Jan Kiszka | case IDX_IP_REG:
|
634 | 5f30fa18 | Jan Kiszka | if (TARGET_LONG_BITS == 64 && env->hflags & HF_CS64_MASK) { |
635 | 5f30fa18 | Jan Kiszka | env->eip = ldq_p(mem_buf); |
636 | 5f30fa18 | Jan Kiszka | return 8; |
637 | 5f30fa18 | Jan Kiszka | } else {
|
638 | 5f30fa18 | Jan Kiszka | env->eip &= ~0xffffffffUL;
|
639 | 5f30fa18 | Jan Kiszka | env->eip |= (uint32_t)ldl_p(mem_buf); |
640 | 5f30fa18 | Jan Kiszka | return 4; |
641 | 5f30fa18 | Jan Kiszka | } |
642 | b1631e7a | Jan Kiszka | case IDX_FLAGS_REG:
|
643 | b1631e7a | Jan Kiszka | env->eflags = ldl_p(mem_buf); |
644 | b1631e7a | Jan Kiszka | return 4; |
645 | b1631e7a | Jan Kiszka | |
646 | 84273177 | Jan Kiszka | case IDX_SEG_REGS: return cpu_x86_gdb_load_seg(env, R_CS, mem_buf); |
647 | 84273177 | Jan Kiszka | case IDX_SEG_REGS + 1: return cpu_x86_gdb_load_seg(env, R_SS, mem_buf); |
648 | 84273177 | Jan Kiszka | case IDX_SEG_REGS + 2: return cpu_x86_gdb_load_seg(env, R_DS, mem_buf); |
649 | 84273177 | Jan Kiszka | case IDX_SEG_REGS + 3: return cpu_x86_gdb_load_seg(env, R_ES, mem_buf); |
650 | 84273177 | Jan Kiszka | case IDX_SEG_REGS + 4: return cpu_x86_gdb_load_seg(env, R_FS, mem_buf); |
651 | 84273177 | Jan Kiszka | case IDX_SEG_REGS + 5: return cpu_x86_gdb_load_seg(env, R_GS, mem_buf); |
652 | b1631e7a | Jan Kiszka | |
653 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 8: |
654 | b1631e7a | Jan Kiszka | env->fpuc = ldl_p(mem_buf); |
655 | b1631e7a | Jan Kiszka | return 4; |
656 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 9: |
657 | b1631e7a | Jan Kiszka | tmp = ldl_p(mem_buf); |
658 | b1631e7a | Jan Kiszka | env->fpstt = (tmp >> 11) & 7; |
659 | b1631e7a | Jan Kiszka | env->fpus = tmp & ~0x3800;
|
660 | b1631e7a | Jan Kiszka | return 4; |
661 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 10: /* ftag */ return 4; |
662 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 11: /* fiseg */ return 4; |
663 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 12: /* fioff */ return 4; |
664 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 13: /* foseg */ return 4; |
665 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 14: /* fooff */ return 4; |
666 | b1631e7a | Jan Kiszka | case IDX_FP_REGS + 15: /* fop */ return 4; |
667 | b1631e7a | Jan Kiszka | |
668 | b1631e7a | Jan Kiszka | case IDX_MXCSR_REG:
|
669 | b1631e7a | Jan Kiszka | env->mxcsr = ldl_p(mem_buf); |
670 | b1631e7a | Jan Kiszka | return 4; |
671 | 79808573 | bellard | } |
672 | 79808573 | bellard | } |
673 | 56aebc89 | pbrook | /* Unrecognised register. */
|
674 | 56aebc89 | pbrook | return 0; |
675 | 6da41eaf | bellard | } |
676 | 6da41eaf | bellard | |
677 | 9e62fd7f | bellard | #elif defined (TARGET_PPC)
|
678 | 9e62fd7f | bellard | |
679 | e571cb47 | aurel32 | /* Old gdb always expects FP registers. Newer (xml-aware) gdb only
|
680 | e571cb47 | aurel32 | expects whatever the target description contains. Due to a
|
681 | e571cb47 | aurel32 | historical mishap the FP registers appear in between core integer
|
682 | e571cb47 | aurel32 | regs and PC, MSR, CR, and so forth. We hack round this by giving the
|
683 | e571cb47 | aurel32 | FP regs zero size when talking to a newer gdb. */
|
684 | 56aebc89 | pbrook | #define NUM_CORE_REGS 71 |
685 | e571cb47 | aurel32 | #if defined (TARGET_PPC64)
|
686 | e571cb47 | aurel32 | #define GDB_CORE_XML "power64-core.xml" |
687 | e571cb47 | aurel32 | #else
|
688 | e571cb47 | aurel32 | #define GDB_CORE_XML "power-core.xml" |
689 | e571cb47 | aurel32 | #endif
|
690 | 9e62fd7f | bellard | |
691 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
692 | 9e62fd7f | bellard | { |
693 | 56aebc89 | pbrook | if (n < 32) { |
694 | 56aebc89 | pbrook | /* gprs */
|
695 | 56aebc89 | pbrook | GET_REGL(env->gpr[n]); |
696 | 56aebc89 | pbrook | } else if (n < 64) { |
697 | 56aebc89 | pbrook | /* fprs */
|
698 | e571cb47 | aurel32 | if (gdb_has_xml)
|
699 | e571cb47 | aurel32 | return 0; |
700 | 8d4acf9b | aurel32 | stfq_p(mem_buf, env->fpr[n-32]);
|
701 | 56aebc89 | pbrook | return 8; |
702 | 56aebc89 | pbrook | } else {
|
703 | 56aebc89 | pbrook | switch (n) {
|
704 | 56aebc89 | pbrook | case 64: GET_REGL(env->nip); |
705 | 56aebc89 | pbrook | case 65: GET_REGL(env->msr); |
706 | 56aebc89 | pbrook | case 66: |
707 | 56aebc89 | pbrook | { |
708 | 56aebc89 | pbrook | uint32_t cr = 0;
|
709 | 56aebc89 | pbrook | int i;
|
710 | 56aebc89 | pbrook | for (i = 0; i < 8; i++) |
711 | 56aebc89 | pbrook | cr |= env->crf[i] << (32 - ((i + 1) * 4)); |
712 | 56aebc89 | pbrook | GET_REG32(cr); |
713 | 56aebc89 | pbrook | } |
714 | 56aebc89 | pbrook | case 67: GET_REGL(env->lr); |
715 | 56aebc89 | pbrook | case 68: GET_REGL(env->ctr); |
716 | 3d7b417e | aurel32 | case 69: GET_REGL(env->xer); |
717 | e571cb47 | aurel32 | case 70: |
718 | e571cb47 | aurel32 | { |
719 | e571cb47 | aurel32 | if (gdb_has_xml)
|
720 | e571cb47 | aurel32 | return 0; |
721 | e571cb47 | aurel32 | GET_REG32(0); /* fpscr */ |
722 | e571cb47 | aurel32 | } |
723 | 56aebc89 | pbrook | } |
724 | 56aebc89 | pbrook | } |
725 | 56aebc89 | pbrook | return 0; |
726 | 56aebc89 | pbrook | } |
727 | 9e62fd7f | bellard | |
728 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
729 | 56aebc89 | pbrook | { |
730 | 56aebc89 | pbrook | if (n < 32) { |
731 | 56aebc89 | pbrook | /* gprs */
|
732 | 56aebc89 | pbrook | env->gpr[n] = ldtul_p(mem_buf); |
733 | 56aebc89 | pbrook | return sizeof(target_ulong); |
734 | 56aebc89 | pbrook | } else if (n < 64) { |
735 | 56aebc89 | pbrook | /* fprs */
|
736 | e571cb47 | aurel32 | if (gdb_has_xml)
|
737 | e571cb47 | aurel32 | return 0; |
738 | 8d4acf9b | aurel32 | env->fpr[n-32] = ldfq_p(mem_buf);
|
739 | 56aebc89 | pbrook | return 8; |
740 | 56aebc89 | pbrook | } else {
|
741 | 56aebc89 | pbrook | switch (n) {
|
742 | 56aebc89 | pbrook | case 64: |
743 | 56aebc89 | pbrook | env->nip = ldtul_p(mem_buf); |
744 | 56aebc89 | pbrook | return sizeof(target_ulong); |
745 | 56aebc89 | pbrook | case 65: |
746 | 56aebc89 | pbrook | ppc_store_msr(env, ldtul_p(mem_buf)); |
747 | 56aebc89 | pbrook | return sizeof(target_ulong); |
748 | 56aebc89 | pbrook | case 66: |
749 | 56aebc89 | pbrook | { |
750 | 56aebc89 | pbrook | uint32_t cr = ldl_p(mem_buf); |
751 | 56aebc89 | pbrook | int i;
|
752 | 56aebc89 | pbrook | for (i = 0; i < 8; i++) |
753 | 56aebc89 | pbrook | env->crf[i] = (cr >> (32 - ((i + 1) * 4))) & 0xF; |
754 | 56aebc89 | pbrook | return 4; |
755 | 56aebc89 | pbrook | } |
756 | 56aebc89 | pbrook | case 67: |
757 | 56aebc89 | pbrook | env->lr = ldtul_p(mem_buf); |
758 | 56aebc89 | pbrook | return sizeof(target_ulong); |
759 | 56aebc89 | pbrook | case 68: |
760 | 56aebc89 | pbrook | env->ctr = ldtul_p(mem_buf); |
761 | 56aebc89 | pbrook | return sizeof(target_ulong); |
762 | 56aebc89 | pbrook | case 69: |
763 | 3d7b417e | aurel32 | env->xer = ldtul_p(mem_buf); |
764 | 3d7b417e | aurel32 | return sizeof(target_ulong); |
765 | 56aebc89 | pbrook | case 70: |
766 | 56aebc89 | pbrook | /* fpscr */
|
767 | e571cb47 | aurel32 | if (gdb_has_xml)
|
768 | e571cb47 | aurel32 | return 0; |
769 | 56aebc89 | pbrook | return 4; |
770 | 56aebc89 | pbrook | } |
771 | 56aebc89 | pbrook | } |
772 | 56aebc89 | pbrook | return 0; |
773 | e95c8d51 | bellard | } |
774 | 56aebc89 | pbrook | |
775 | e95c8d51 | bellard | #elif defined (TARGET_SPARC)
|
776 | 56aebc89 | pbrook | |
777 | 56aebc89 | pbrook | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
|
778 | 56aebc89 | pbrook | #define NUM_CORE_REGS 86 |
779 | 96d19126 | blueswir1 | #else
|
780 | 5a377912 | blueswir1 | #define NUM_CORE_REGS 72 |
781 | 96d19126 | blueswir1 | #endif
|
782 | 56aebc89 | pbrook | |
783 | 96d19126 | blueswir1 | #ifdef TARGET_ABI32
|
784 | 56aebc89 | pbrook | #define GET_REGA(val) GET_REG32(val)
|
785 | 96d19126 | blueswir1 | #else
|
786 | 56aebc89 | pbrook | #define GET_REGA(val) GET_REGL(val)
|
787 | 96d19126 | blueswir1 | #endif
|
788 | e95c8d51 | bellard | |
789 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
790 | 56aebc89 | pbrook | { |
791 | 56aebc89 | pbrook | if (n < 8) { |
792 | 56aebc89 | pbrook | /* g0..g7 */
|
793 | 56aebc89 | pbrook | GET_REGA(env->gregs[n]); |
794 | e95c8d51 | bellard | } |
795 | 56aebc89 | pbrook | if (n < 32) { |
796 | 56aebc89 | pbrook | /* register window */
|
797 | 56aebc89 | pbrook | GET_REGA(env->regwptr[n - 8]);
|
798 | e95c8d51 | bellard | } |
799 | 56aebc89 | pbrook | #if defined(TARGET_ABI32) || !defined(TARGET_SPARC64)
|
800 | 56aebc89 | pbrook | if (n < 64) { |
801 | 56aebc89 | pbrook | /* fprs */
|
802 | 56aebc89 | pbrook | GET_REG32(*((uint32_t *)&env->fpr[n - 32]));
|
803 | e95c8d51 | bellard | } |
804 | e95c8d51 | bellard | /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
805 | 56aebc89 | pbrook | switch (n) {
|
806 | 56aebc89 | pbrook | case 64: GET_REGA(env->y); |
807 | 56aebc89 | pbrook | case 65: GET_REGA(GET_PSR(env)); |
808 | 56aebc89 | pbrook | case 66: GET_REGA(env->wim); |
809 | 56aebc89 | pbrook | case 67: GET_REGA(env->tbr); |
810 | 56aebc89 | pbrook | case 68: GET_REGA(env->pc); |
811 | 56aebc89 | pbrook | case 69: GET_REGA(env->npc); |
812 | 56aebc89 | pbrook | case 70: GET_REGA(env->fsr); |
813 | 56aebc89 | pbrook | case 71: GET_REGA(0); /* csr */ |
814 | 5a377912 | blueswir1 | default: GET_REGA(0); |
815 | 56aebc89 | pbrook | } |
816 | 3475187d | bellard | #else
|
817 | 56aebc89 | pbrook | if (n < 64) { |
818 | 56aebc89 | pbrook | /* f0-f31 */
|
819 | 56aebc89 | pbrook | GET_REG32(*((uint32_t *)&env->fpr[n - 32]));
|
820 | 56aebc89 | pbrook | } |
821 | 56aebc89 | pbrook | if (n < 80) { |
822 | 56aebc89 | pbrook | /* f32-f62 (double width, even numbers only) */
|
823 | 56aebc89 | pbrook | uint64_t val; |
824 | 9d9754a3 | bellard | |
825 | 56aebc89 | pbrook | val = (uint64_t)*((uint32_t *)&env->fpr[(n - 64) * 2 + 32]) << 32; |
826 | 56aebc89 | pbrook | val |= *((uint32_t *)&env->fpr[(n - 64) * 2 + 33]); |
827 | 56aebc89 | pbrook | GET_REG64(val); |
828 | 3475187d | bellard | } |
829 | 56aebc89 | pbrook | switch (n) {
|
830 | 56aebc89 | pbrook | case 80: GET_REGL(env->pc); |
831 | 56aebc89 | pbrook | case 81: GET_REGL(env->npc); |
832 | 56aebc89 | pbrook | case 82: GET_REGL(((uint64_t)GET_CCR(env) << 32) | |
833 | 17d996e1 | blueswir1 | ((env->asi & 0xff) << 24) | |
834 | 17d996e1 | blueswir1 | ((env->pstate & 0xfff) << 8) | |
835 | 17d996e1 | blueswir1 | GET_CWP64(env)); |
836 | 56aebc89 | pbrook | case 83: GET_REGL(env->fsr); |
837 | 56aebc89 | pbrook | case 84: GET_REGL(env->fprs); |
838 | 56aebc89 | pbrook | case 85: GET_REGL(env->y); |
839 | 56aebc89 | pbrook | } |
840 | 3475187d | bellard | #endif
|
841 | 56aebc89 | pbrook | return 0; |
842 | e95c8d51 | bellard | } |
843 | e95c8d51 | bellard | |
844 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
845 | e95c8d51 | bellard | { |
846 | 56aebc89 | pbrook | #if defined(TARGET_ABI32)
|
847 | 56aebc89 | pbrook | abi_ulong tmp; |
848 | 56aebc89 | pbrook | |
849 | 56aebc89 | pbrook | tmp = ldl_p(mem_buf); |
850 | 96d19126 | blueswir1 | #else
|
851 | 56aebc89 | pbrook | target_ulong tmp; |
852 | 56aebc89 | pbrook | |
853 | 56aebc89 | pbrook | tmp = ldtul_p(mem_buf); |
854 | 96d19126 | blueswir1 | #endif
|
855 | e95c8d51 | bellard | |
856 | 56aebc89 | pbrook | if (n < 8) { |
857 | 56aebc89 | pbrook | /* g0..g7 */
|
858 | 56aebc89 | pbrook | env->gregs[n] = tmp; |
859 | 56aebc89 | pbrook | } else if (n < 32) { |
860 | 56aebc89 | pbrook | /* register window */
|
861 | 56aebc89 | pbrook | env->regwptr[n - 8] = tmp;
|
862 | e95c8d51 | bellard | } |
863 | 56aebc89 | pbrook | #if defined(TARGET_ABI32) || !defined(TARGET_SPARC64)
|
864 | 56aebc89 | pbrook | else if (n < 64) { |
865 | 56aebc89 | pbrook | /* fprs */
|
866 | 56aebc89 | pbrook | *((uint32_t *)&env->fpr[n - 32]) = tmp;
|
867 | 56aebc89 | pbrook | } else {
|
868 | 56aebc89 | pbrook | /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
869 | 56aebc89 | pbrook | switch (n) {
|
870 | 56aebc89 | pbrook | case 64: env->y = tmp; break; |
871 | 56aebc89 | pbrook | case 65: PUT_PSR(env, tmp); break; |
872 | 56aebc89 | pbrook | case 66: env->wim = tmp; break; |
873 | 56aebc89 | pbrook | case 67: env->tbr = tmp; break; |
874 | 56aebc89 | pbrook | case 68: env->pc = tmp; break; |
875 | 56aebc89 | pbrook | case 69: env->npc = tmp; break; |
876 | 56aebc89 | pbrook | case 70: env->fsr = tmp; break; |
877 | 56aebc89 | pbrook | default: return 0; |
878 | 56aebc89 | pbrook | } |
879 | e95c8d51 | bellard | } |
880 | 56aebc89 | pbrook | return 4; |
881 | 3475187d | bellard | #else
|
882 | 56aebc89 | pbrook | else if (n < 64) { |
883 | 56aebc89 | pbrook | /* f0-f31 */
|
884 | 56aebc89 | pbrook | env->fpr[n] = ldfl_p(mem_buf); |
885 | 56aebc89 | pbrook | return 4; |
886 | 56aebc89 | pbrook | } else if (n < 80) { |
887 | 56aebc89 | pbrook | /* f32-f62 (double width, even numbers only) */
|
888 | 56aebc89 | pbrook | *((uint32_t *)&env->fpr[(n - 64) * 2 + 32]) = tmp >> 32; |
889 | 56aebc89 | pbrook | *((uint32_t *)&env->fpr[(n - 64) * 2 + 33]) = tmp; |
890 | 56aebc89 | pbrook | } else {
|
891 | 56aebc89 | pbrook | switch (n) {
|
892 | 56aebc89 | pbrook | case 80: env->pc = tmp; break; |
893 | 56aebc89 | pbrook | case 81: env->npc = tmp; break; |
894 | 56aebc89 | pbrook | case 82: |
895 | 56aebc89 | pbrook | PUT_CCR(env, tmp >> 32);
|
896 | 56aebc89 | pbrook | env->asi = (tmp >> 24) & 0xff; |
897 | 56aebc89 | pbrook | env->pstate = (tmp >> 8) & 0xfff; |
898 | 56aebc89 | pbrook | PUT_CWP64(env, tmp & 0xff);
|
899 | 56aebc89 | pbrook | break;
|
900 | 56aebc89 | pbrook | case 83: env->fsr = tmp; break; |
901 | 56aebc89 | pbrook | case 84: env->fprs = tmp; break; |
902 | 56aebc89 | pbrook | case 85: env->y = tmp; break; |
903 | 56aebc89 | pbrook | default: return 0; |
904 | 56aebc89 | pbrook | } |
905 | 17d996e1 | blueswir1 | } |
906 | 56aebc89 | pbrook | return 8; |
907 | 3475187d | bellard | #endif
|
908 | 9e62fd7f | bellard | } |
909 | 1fddef4b | bellard | #elif defined (TARGET_ARM)
|
910 | 6da41eaf | bellard | |
911 | 56aebc89 | pbrook | /* Old gdb always expect FPA registers. Newer (xml-aware) gdb only expect
|
912 | 56aebc89 | pbrook | whatever the target description contains. Due to a historical mishap
|
913 | 56aebc89 | pbrook | the FPA registers appear in between core integer regs and the CPSR.
|
914 | 56aebc89 | pbrook | We hack round this by giving the FPA regs zero size when talking to a
|
915 | 56aebc89 | pbrook | newer gdb. */
|
916 | 56aebc89 | pbrook | #define NUM_CORE_REGS 26 |
917 | 56aebc89 | pbrook | #define GDB_CORE_XML "arm-core.xml" |
918 | e6e5906b | pbrook | |
919 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
920 | e6e5906b | pbrook | { |
921 | 56aebc89 | pbrook | if (n < 16) { |
922 | 56aebc89 | pbrook | /* Core integer register. */
|
923 | 56aebc89 | pbrook | GET_REG32(env->regs[n]); |
924 | 56aebc89 | pbrook | } |
925 | 56aebc89 | pbrook | if (n < 24) { |
926 | 56aebc89 | pbrook | /* FPA registers. */
|
927 | 56aebc89 | pbrook | if (gdb_has_xml)
|
928 | 56aebc89 | pbrook | return 0; |
929 | 56aebc89 | pbrook | memset(mem_buf, 0, 12); |
930 | 56aebc89 | pbrook | return 12; |
931 | 56aebc89 | pbrook | } |
932 | 56aebc89 | pbrook | switch (n) {
|
933 | 56aebc89 | pbrook | case 24: |
934 | 56aebc89 | pbrook | /* FPA status register. */
|
935 | 56aebc89 | pbrook | if (gdb_has_xml)
|
936 | 56aebc89 | pbrook | return 0; |
937 | 56aebc89 | pbrook | GET_REG32(0);
|
938 | 56aebc89 | pbrook | case 25: |
939 | 56aebc89 | pbrook | /* CPSR */
|
940 | 56aebc89 | pbrook | GET_REG32(cpsr_read(env)); |
941 | 56aebc89 | pbrook | } |
942 | 56aebc89 | pbrook | /* Unknown register. */
|
943 | 56aebc89 | pbrook | return 0; |
944 | e6e5906b | pbrook | } |
945 | 6f970bd9 | bellard | |
946 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
947 | 56aebc89 | pbrook | { |
948 | 56aebc89 | pbrook | uint32_t tmp; |
949 | 6f970bd9 | bellard | |
950 | 56aebc89 | pbrook | tmp = ldl_p(mem_buf); |
951 | 6f970bd9 | bellard | |
952 | 56aebc89 | pbrook | /* Mask out low bit of PC to workaround gdb bugs. This will probably
|
953 | 56aebc89 | pbrook | cause problems if we ever implement the Jazelle DBX extensions. */
|
954 | 56aebc89 | pbrook | if (n == 15) |
955 | 56aebc89 | pbrook | tmp &= ~1;
|
956 | 6f970bd9 | bellard | |
957 | 56aebc89 | pbrook | if (n < 16) { |
958 | 56aebc89 | pbrook | /* Core integer register. */
|
959 | 56aebc89 | pbrook | env->regs[n] = tmp; |
960 | 56aebc89 | pbrook | return 4; |
961 | 56aebc89 | pbrook | } |
962 | 56aebc89 | pbrook | if (n < 24) { /* 16-23 */ |
963 | 56aebc89 | pbrook | /* FPA registers (ignored). */
|
964 | 56aebc89 | pbrook | if (gdb_has_xml)
|
965 | 56aebc89 | pbrook | return 0; |
966 | 56aebc89 | pbrook | return 12; |
967 | 56aebc89 | pbrook | } |
968 | 56aebc89 | pbrook | switch (n) {
|
969 | 56aebc89 | pbrook | case 24: |
970 | 56aebc89 | pbrook | /* FPA status register (ignored). */
|
971 | 56aebc89 | pbrook | if (gdb_has_xml)
|
972 | 56aebc89 | pbrook | return 0; |
973 | 56aebc89 | pbrook | return 4; |
974 | 56aebc89 | pbrook | case 25: |
975 | 56aebc89 | pbrook | /* CPSR */
|
976 | 56aebc89 | pbrook | cpsr_write (env, tmp, 0xffffffff);
|
977 | 56aebc89 | pbrook | return 4; |
978 | 56aebc89 | pbrook | } |
979 | 56aebc89 | pbrook | /* Unknown register. */
|
980 | 56aebc89 | pbrook | return 0; |
981 | 56aebc89 | pbrook | } |
982 | 6f970bd9 | bellard | |
983 | 56aebc89 | pbrook | #elif defined (TARGET_M68K)
|
984 | 6f970bd9 | bellard | |
985 | 56aebc89 | pbrook | #define NUM_CORE_REGS 18 |
986 | 6f970bd9 | bellard | |
987 | 56aebc89 | pbrook | #define GDB_CORE_XML "cf-core.xml" |
988 | 6f970bd9 | bellard | |
989 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
990 | 56aebc89 | pbrook | { |
991 | 56aebc89 | pbrook | if (n < 8) { |
992 | 56aebc89 | pbrook | /* D0-D7 */
|
993 | 56aebc89 | pbrook | GET_REG32(env->dregs[n]); |
994 | 56aebc89 | pbrook | } else if (n < 16) { |
995 | 56aebc89 | pbrook | /* A0-A7 */
|
996 | 56aebc89 | pbrook | GET_REG32(env->aregs[n - 8]);
|
997 | 56aebc89 | pbrook | } else {
|
998 | 56aebc89 | pbrook | switch (n) {
|
999 | 56aebc89 | pbrook | case 16: GET_REG32(env->sr); |
1000 | 56aebc89 | pbrook | case 17: GET_REG32(env->pc); |
1001 | 56aebc89 | pbrook | } |
1002 | 56aebc89 | pbrook | } |
1003 | 56aebc89 | pbrook | /* FP registers not included here because they vary between
|
1004 | 56aebc89 | pbrook | ColdFire and m68k. Use XML bits for these. */
|
1005 | 56aebc89 | pbrook | return 0; |
1006 | 56aebc89 | pbrook | } |
1007 | 8e33c08c | ths | |
1008 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1009 | 56aebc89 | pbrook | { |
1010 | 56aebc89 | pbrook | uint32_t tmp; |
1011 | 8e33c08c | ths | |
1012 | 56aebc89 | pbrook | tmp = ldl_p(mem_buf); |
1013 | 8e33c08c | ths | |
1014 | 56aebc89 | pbrook | if (n < 8) { |
1015 | 56aebc89 | pbrook | /* D0-D7 */
|
1016 | 56aebc89 | pbrook | env->dregs[n] = tmp; |
1017 | 56aebc89 | pbrook | } else if (n < 8) { |
1018 | 56aebc89 | pbrook | /* A0-A7 */
|
1019 | 56aebc89 | pbrook | env->aregs[n - 8] = tmp;
|
1020 | 56aebc89 | pbrook | } else {
|
1021 | 56aebc89 | pbrook | switch (n) {
|
1022 | 56aebc89 | pbrook | case 16: env->sr = tmp; break; |
1023 | 56aebc89 | pbrook | case 17: env->pc = tmp; break; |
1024 | 56aebc89 | pbrook | default: return 0; |
1025 | 56aebc89 | pbrook | } |
1026 | 56aebc89 | pbrook | } |
1027 | 56aebc89 | pbrook | return 4; |
1028 | 56aebc89 | pbrook | } |
1029 | 56aebc89 | pbrook | #elif defined (TARGET_MIPS)
|
1030 | 7ac256b8 | ths | |
1031 | 56aebc89 | pbrook | #define NUM_CORE_REGS 73 |
1032 | 7ac256b8 | ths | |
1033 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1034 | 56aebc89 | pbrook | { |
1035 | 56aebc89 | pbrook | if (n < 32) { |
1036 | 56aebc89 | pbrook | GET_REGL(env->active_tc.gpr[n]); |
1037 | 56aebc89 | pbrook | } |
1038 | 56aebc89 | pbrook | if (env->CP0_Config1 & (1 << CP0C1_FP)) { |
1039 | 56aebc89 | pbrook | if (n >= 38 && n < 70) { |
1040 | 56aebc89 | pbrook | if (env->CP0_Status & (1 << CP0St_FR)) |
1041 | 56aebc89 | pbrook | GET_REGL(env->active_fpu.fpr[n - 38].d);
|
1042 | 56aebc89 | pbrook | else
|
1043 | 56aebc89 | pbrook | GET_REGL(env->active_fpu.fpr[n - 38].w[FP_ENDIAN_IDX]);
|
1044 | 56aebc89 | pbrook | } |
1045 | 56aebc89 | pbrook | switch (n) {
|
1046 | 56aebc89 | pbrook | case 70: GET_REGL((int32_t)env->active_fpu.fcr31); |
1047 | 56aebc89 | pbrook | case 71: GET_REGL((int32_t)env->active_fpu.fcr0); |
1048 | 56aebc89 | pbrook | } |
1049 | 56aebc89 | pbrook | } |
1050 | 56aebc89 | pbrook | switch (n) {
|
1051 | 56aebc89 | pbrook | case 32: GET_REGL((int32_t)env->CP0_Status); |
1052 | 56aebc89 | pbrook | case 33: GET_REGL(env->active_tc.LO[0]); |
1053 | 56aebc89 | pbrook | case 34: GET_REGL(env->active_tc.HI[0]); |
1054 | 56aebc89 | pbrook | case 35: GET_REGL(env->CP0_BadVAddr); |
1055 | 56aebc89 | pbrook | case 36: GET_REGL((int32_t)env->CP0_Cause); |
1056 | 56aebc89 | pbrook | case 37: GET_REGL(env->active_tc.PC); |
1057 | 56aebc89 | pbrook | case 72: GET_REGL(0); /* fp */ |
1058 | 56aebc89 | pbrook | case 89: GET_REGL((int32_t)env->CP0_PRid); |
1059 | 56aebc89 | pbrook | } |
1060 | 56aebc89 | pbrook | if (n >= 73 && n <= 88) { |
1061 | 56aebc89 | pbrook | /* 16 embedded regs. */
|
1062 | 56aebc89 | pbrook | GET_REGL(0);
|
1063 | 56aebc89 | pbrook | } |
1064 | 6f970bd9 | bellard | |
1065 | 56aebc89 | pbrook | return 0; |
1066 | 6f970bd9 | bellard | } |
1067 | 6f970bd9 | bellard | |
1068 | 8e33c08c | ths | /* convert MIPS rounding mode in FCR31 to IEEE library */
|
1069 | 8e33c08c | ths | static unsigned int ieee_rm[] = |
1070 | 8e33c08c | ths | { |
1071 | 8e33c08c | ths | float_round_nearest_even, |
1072 | 8e33c08c | ths | float_round_to_zero, |
1073 | 8e33c08c | ths | float_round_up, |
1074 | 8e33c08c | ths | float_round_down |
1075 | 8e33c08c | ths | }; |
1076 | 8e33c08c | ths | #define RESTORE_ROUNDING_MODE \
|
1077 | f01be154 | ths | set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
|
1078 | 8e33c08c | ths | |
1079 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1080 | 6f970bd9 | bellard | { |
1081 | 56aebc89 | pbrook | target_ulong tmp; |
1082 | 6f970bd9 | bellard | |
1083 | 56aebc89 | pbrook | tmp = ldtul_p(mem_buf); |
1084 | 6f970bd9 | bellard | |
1085 | 56aebc89 | pbrook | if (n < 32) { |
1086 | 56aebc89 | pbrook | env->active_tc.gpr[n] = tmp; |
1087 | 56aebc89 | pbrook | return sizeof(target_ulong); |
1088 | 56aebc89 | pbrook | } |
1089 | 56aebc89 | pbrook | if (env->CP0_Config1 & (1 << CP0C1_FP) |
1090 | 56aebc89 | pbrook | && n >= 38 && n < 73) { |
1091 | 56aebc89 | pbrook | if (n < 70) { |
1092 | 7ac256b8 | ths | if (env->CP0_Status & (1 << CP0St_FR)) |
1093 | 56aebc89 | pbrook | env->active_fpu.fpr[n - 38].d = tmp;
|
1094 | 7ac256b8 | ths | else
|
1095 | 56aebc89 | pbrook | env->active_fpu.fpr[n - 38].w[FP_ENDIAN_IDX] = tmp;
|
1096 | 56aebc89 | pbrook | } |
1097 | 56aebc89 | pbrook | switch (n) {
|
1098 | 56aebc89 | pbrook | case 70: |
1099 | 56aebc89 | pbrook | env->active_fpu.fcr31 = tmp & 0xFF83FFFF;
|
1100 | 56aebc89 | pbrook | /* set rounding mode */
|
1101 | 56aebc89 | pbrook | RESTORE_ROUNDING_MODE; |
1102 | 8e33c08c | ths | #ifndef CONFIG_SOFTFLOAT
|
1103 | 56aebc89 | pbrook | /* no floating point exception for native float */
|
1104 | 56aebc89 | pbrook | SET_FP_ENABLE(env->active_fpu.fcr31, 0);
|
1105 | 8e33c08c | ths | #endif
|
1106 | 56aebc89 | pbrook | break;
|
1107 | 56aebc89 | pbrook | case 71: env->active_fpu.fcr0 = tmp; break; |
1108 | 56aebc89 | pbrook | } |
1109 | 56aebc89 | pbrook | return sizeof(target_ulong); |
1110 | 56aebc89 | pbrook | } |
1111 | 56aebc89 | pbrook | switch (n) {
|
1112 | 56aebc89 | pbrook | case 32: env->CP0_Status = tmp; break; |
1113 | 56aebc89 | pbrook | case 33: env->active_tc.LO[0] = tmp; break; |
1114 | 56aebc89 | pbrook | case 34: env->active_tc.HI[0] = tmp; break; |
1115 | 56aebc89 | pbrook | case 35: env->CP0_BadVAddr = tmp; break; |
1116 | 56aebc89 | pbrook | case 36: env->CP0_Cause = tmp; break; |
1117 | 56aebc89 | pbrook | case 37: env->active_tc.PC = tmp; break; |
1118 | 56aebc89 | pbrook | case 72: /* fp, ignored */ break; |
1119 | 56aebc89 | pbrook | default:
|
1120 | 56aebc89 | pbrook | if (n > 89) |
1121 | 56aebc89 | pbrook | return 0; |
1122 | 56aebc89 | pbrook | /* Other registers are readonly. Ignore writes. */
|
1123 | 56aebc89 | pbrook | break;
|
1124 | 56aebc89 | pbrook | } |
1125 | 56aebc89 | pbrook | |
1126 | 56aebc89 | pbrook | return sizeof(target_ulong); |
1127 | 6f970bd9 | bellard | } |
1128 | fdf9b3e8 | bellard | #elif defined (TARGET_SH4)
|
1129 | 6ef99fc5 | ths | |
1130 | 6ef99fc5 | ths | /* Hint: Use "set architecture sh4" in GDB to see fpu registers */
|
1131 | 56aebc89 | pbrook | /* FIXME: We should use XML for this. */
|
1132 | 56aebc89 | pbrook | |
1133 | 56aebc89 | pbrook | #define NUM_CORE_REGS 59 |
1134 | 6ef99fc5 | ths | |
1135 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1136 | fdf9b3e8 | bellard | { |
1137 | 56aebc89 | pbrook | if (n < 8) { |
1138 | 56aebc89 | pbrook | if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
1139 | 56aebc89 | pbrook | GET_REGL(env->gregs[n + 16]);
|
1140 | 56aebc89 | pbrook | } else {
|
1141 | 56aebc89 | pbrook | GET_REGL(env->gregs[n]); |
1142 | 56aebc89 | pbrook | } |
1143 | 56aebc89 | pbrook | } else if (n < 16) { |
1144 | 56aebc89 | pbrook | GET_REGL(env->gregs[n - 8]);
|
1145 | 56aebc89 | pbrook | } else if (n >= 25 && n < 41) { |
1146 | 56aebc89 | pbrook | GET_REGL(env->fregs[(n - 25) + ((env->fpscr & FPSCR_FR) ? 16 : 0)]); |
1147 | 56aebc89 | pbrook | } else if (n >= 43 && n < 51) { |
1148 | 56aebc89 | pbrook | GET_REGL(env->gregs[n - 43]);
|
1149 | 56aebc89 | pbrook | } else if (n >= 51 && n < 59) { |
1150 | 56aebc89 | pbrook | GET_REGL(env->gregs[n - (51 - 16)]); |
1151 | 56aebc89 | pbrook | } |
1152 | 56aebc89 | pbrook | switch (n) {
|
1153 | 56aebc89 | pbrook | case 16: GET_REGL(env->pc); |
1154 | 56aebc89 | pbrook | case 17: GET_REGL(env->pr); |
1155 | 56aebc89 | pbrook | case 18: GET_REGL(env->gbr); |
1156 | 56aebc89 | pbrook | case 19: GET_REGL(env->vbr); |
1157 | 56aebc89 | pbrook | case 20: GET_REGL(env->mach); |
1158 | 56aebc89 | pbrook | case 21: GET_REGL(env->macl); |
1159 | 56aebc89 | pbrook | case 22: GET_REGL(env->sr); |
1160 | 56aebc89 | pbrook | case 23: GET_REGL(env->fpul); |
1161 | 56aebc89 | pbrook | case 24: GET_REGL(env->fpscr); |
1162 | 56aebc89 | pbrook | case 41: GET_REGL(env->ssr); |
1163 | 56aebc89 | pbrook | case 42: GET_REGL(env->spc); |
1164 | 56aebc89 | pbrook | } |
1165 | 56aebc89 | pbrook | |
1166 | 56aebc89 | pbrook | return 0; |
1167 | fdf9b3e8 | bellard | } |
1168 | fdf9b3e8 | bellard | |
1169 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1170 | fdf9b3e8 | bellard | { |
1171 | 56aebc89 | pbrook | uint32_t tmp; |
1172 | 56aebc89 | pbrook | |
1173 | 56aebc89 | pbrook | tmp = ldl_p(mem_buf); |
1174 | 56aebc89 | pbrook | |
1175 | 56aebc89 | pbrook | if (n < 8) { |
1176 | 56aebc89 | pbrook | if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
1177 | 56aebc89 | pbrook | env->gregs[n + 16] = tmp;
|
1178 | 56aebc89 | pbrook | } else {
|
1179 | 56aebc89 | pbrook | env->gregs[n] = tmp; |
1180 | 56aebc89 | pbrook | } |
1181 | 56aebc89 | pbrook | return 4; |
1182 | 56aebc89 | pbrook | } else if (n < 16) { |
1183 | 56aebc89 | pbrook | env->gregs[n - 8] = tmp;
|
1184 | 56aebc89 | pbrook | return 4; |
1185 | 56aebc89 | pbrook | } else if (n >= 25 && n < 41) { |
1186 | 56aebc89 | pbrook | env->fregs[(n - 25) + ((env->fpscr & FPSCR_FR) ? 16 : 0)] = tmp; |
1187 | 56aebc89 | pbrook | } else if (n >= 43 && n < 51) { |
1188 | 56aebc89 | pbrook | env->gregs[n - 43] = tmp;
|
1189 | 56aebc89 | pbrook | return 4; |
1190 | 56aebc89 | pbrook | } else if (n >= 51 && n < 59) { |
1191 | 56aebc89 | pbrook | env->gregs[n - (51 - 16)] = tmp; |
1192 | 56aebc89 | pbrook | return 4; |
1193 | 56aebc89 | pbrook | } |
1194 | 56aebc89 | pbrook | switch (n) {
|
1195 | 56aebc89 | pbrook | case 16: env->pc = tmp; |
1196 | 56aebc89 | pbrook | case 17: env->pr = tmp; |
1197 | 56aebc89 | pbrook | case 18: env->gbr = tmp; |
1198 | 56aebc89 | pbrook | case 19: env->vbr = tmp; |
1199 | 56aebc89 | pbrook | case 20: env->mach = tmp; |
1200 | 56aebc89 | pbrook | case 21: env->macl = tmp; |
1201 | 56aebc89 | pbrook | case 22: env->sr = tmp; |
1202 | 56aebc89 | pbrook | case 23: env->fpul = tmp; |
1203 | 56aebc89 | pbrook | case 24: env->fpscr = tmp; |
1204 | 56aebc89 | pbrook | case 41: env->ssr = tmp; |
1205 | 56aebc89 | pbrook | case 42: env->spc = tmp; |
1206 | 56aebc89 | pbrook | default: return 0; |
1207 | 56aebc89 | pbrook | } |
1208 | 56aebc89 | pbrook | |
1209 | 56aebc89 | pbrook | return 4; |
1210 | fdf9b3e8 | bellard | } |
1211 | d74d6a99 | Edgar E. Iglesias | #elif defined (TARGET_MICROBLAZE)
|
1212 | d74d6a99 | Edgar E. Iglesias | |
1213 | d74d6a99 | Edgar E. Iglesias | #define NUM_CORE_REGS (32 + 5) |
1214 | d74d6a99 | Edgar E. Iglesias | |
1215 | d74d6a99 | Edgar E. Iglesias | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1216 | d74d6a99 | Edgar E. Iglesias | { |
1217 | d74d6a99 | Edgar E. Iglesias | if (n < 32) { |
1218 | d74d6a99 | Edgar E. Iglesias | GET_REG32(env->regs[n]); |
1219 | d74d6a99 | Edgar E. Iglesias | } else {
|
1220 | d74d6a99 | Edgar E. Iglesias | GET_REG32(env->sregs[n - 32]);
|
1221 | d74d6a99 | Edgar E. Iglesias | } |
1222 | d74d6a99 | Edgar E. Iglesias | return 0; |
1223 | d74d6a99 | Edgar E. Iglesias | } |
1224 | d74d6a99 | Edgar E. Iglesias | |
1225 | d74d6a99 | Edgar E. Iglesias | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1226 | d74d6a99 | Edgar E. Iglesias | { |
1227 | d74d6a99 | Edgar E. Iglesias | uint32_t tmp; |
1228 | d74d6a99 | Edgar E. Iglesias | |
1229 | d74d6a99 | Edgar E. Iglesias | if (n > NUM_CORE_REGS)
|
1230 | d74d6a99 | Edgar E. Iglesias | return 0; |
1231 | d74d6a99 | Edgar E. Iglesias | |
1232 | d74d6a99 | Edgar E. Iglesias | tmp = ldl_p(mem_buf); |
1233 | d74d6a99 | Edgar E. Iglesias | |
1234 | d74d6a99 | Edgar E. Iglesias | if (n < 32) { |
1235 | d74d6a99 | Edgar E. Iglesias | env->regs[n] = tmp; |
1236 | d74d6a99 | Edgar E. Iglesias | } else {
|
1237 | d74d6a99 | Edgar E. Iglesias | env->sregs[n - 32] = tmp;
|
1238 | d74d6a99 | Edgar E. Iglesias | } |
1239 | d74d6a99 | Edgar E. Iglesias | return 4; |
1240 | d74d6a99 | Edgar E. Iglesias | } |
1241 | f1ccf904 | ths | #elif defined (TARGET_CRIS)
|
1242 | f1ccf904 | ths | |
1243 | 56aebc89 | pbrook | #define NUM_CORE_REGS 49 |
1244 | 56aebc89 | pbrook | |
1245 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1246 | f1ccf904 | ths | { |
1247 | 56aebc89 | pbrook | uint8_t srs; |
1248 | 56aebc89 | pbrook | |
1249 | 56aebc89 | pbrook | srs = env->pregs[PR_SRS]; |
1250 | 56aebc89 | pbrook | if (n < 16) { |
1251 | 56aebc89 | pbrook | GET_REG32(env->regs[n]); |
1252 | 56aebc89 | pbrook | } |
1253 | 56aebc89 | pbrook | |
1254 | 56aebc89 | pbrook | if (n >= 21 && n < 32) { |
1255 | 56aebc89 | pbrook | GET_REG32(env->pregs[n - 16]);
|
1256 | 56aebc89 | pbrook | } |
1257 | 56aebc89 | pbrook | if (n >= 33 && n < 49) { |
1258 | 56aebc89 | pbrook | GET_REG32(env->sregs[srs][n - 33]);
|
1259 | 56aebc89 | pbrook | } |
1260 | 56aebc89 | pbrook | switch (n) {
|
1261 | 56aebc89 | pbrook | case 16: GET_REG8(env->pregs[0]); |
1262 | 56aebc89 | pbrook | case 17: GET_REG8(env->pregs[1]); |
1263 | 56aebc89 | pbrook | case 18: GET_REG32(env->pregs[2]); |
1264 | 56aebc89 | pbrook | case 19: GET_REG8(srs); |
1265 | 56aebc89 | pbrook | case 20: GET_REG16(env->pregs[4]); |
1266 | 56aebc89 | pbrook | case 32: GET_REG32(env->pc); |
1267 | 56aebc89 | pbrook | } |
1268 | 56aebc89 | pbrook | |
1269 | 56aebc89 | pbrook | return 0; |
1270 | f1ccf904 | ths | } |
1271 | 56aebc89 | pbrook | |
1272 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1273 | f1ccf904 | ths | { |
1274 | 56aebc89 | pbrook | uint32_t tmp; |
1275 | 56aebc89 | pbrook | |
1276 | 56aebc89 | pbrook | if (n > 49) |
1277 | 56aebc89 | pbrook | return 0; |
1278 | 56aebc89 | pbrook | |
1279 | 56aebc89 | pbrook | tmp = ldl_p(mem_buf); |
1280 | 56aebc89 | pbrook | |
1281 | 56aebc89 | pbrook | if (n < 16) { |
1282 | 56aebc89 | pbrook | env->regs[n] = tmp; |
1283 | 56aebc89 | pbrook | } |
1284 | 56aebc89 | pbrook | |
1285 | d7b6967a | edgar_igl | if (n >= 21 && n < 32) { |
1286 | d7b6967a | edgar_igl | env->pregs[n - 16] = tmp;
|
1287 | d7b6967a | edgar_igl | } |
1288 | d7b6967a | edgar_igl | |
1289 | d7b6967a | edgar_igl | /* FIXME: Should support function regs be writable? */
|
1290 | 56aebc89 | pbrook | switch (n) {
|
1291 | 56aebc89 | pbrook | case 16: return 1; |
1292 | 56aebc89 | pbrook | case 17: return 1; |
1293 | d7b6967a | edgar_igl | case 18: env->pregs[PR_PID] = tmp; break; |
1294 | 56aebc89 | pbrook | case 19: return 1; |
1295 | 56aebc89 | pbrook | case 20: return 2; |
1296 | 56aebc89 | pbrook | case 32: env->pc = tmp; break; |
1297 | 56aebc89 | pbrook | } |
1298 | 56aebc89 | pbrook | |
1299 | 56aebc89 | pbrook | return 4; |
1300 | f1ccf904 | ths | } |
1301 | 19bf517b | aurel32 | #elif defined (TARGET_ALPHA)
|
1302 | 19bf517b | aurel32 | |
1303 | 19bf517b | aurel32 | #define NUM_CORE_REGS 65 |
1304 | 19bf517b | aurel32 | |
1305 | 19bf517b | aurel32 | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1306 | 19bf517b | aurel32 | { |
1307 | 19bf517b | aurel32 | if (n < 31) { |
1308 | 19bf517b | aurel32 | GET_REGL(env->ir[n]); |
1309 | 19bf517b | aurel32 | } |
1310 | 19bf517b | aurel32 | else if (n == 31) { |
1311 | 19bf517b | aurel32 | GET_REGL(0);
|
1312 | 19bf517b | aurel32 | } |
1313 | 19bf517b | aurel32 | else if (n<63) { |
1314 | 19bf517b | aurel32 | uint64_t val; |
1315 | 19bf517b | aurel32 | |
1316 | 8f4bee23 | Michael S. Tsirkin | val = *((uint64_t *)&env->fir[n-32]);
|
1317 | 19bf517b | aurel32 | GET_REGL(val); |
1318 | 19bf517b | aurel32 | } |
1319 | 19bf517b | aurel32 | else if (n==63) { |
1320 | 19bf517b | aurel32 | GET_REGL(env->fpcr); |
1321 | 19bf517b | aurel32 | } |
1322 | 19bf517b | aurel32 | else if (n==64) { |
1323 | 19bf517b | aurel32 | GET_REGL(env->pc); |
1324 | 19bf517b | aurel32 | } |
1325 | 19bf517b | aurel32 | else {
|
1326 | 19bf517b | aurel32 | GET_REGL(0);
|
1327 | 19bf517b | aurel32 | } |
1328 | 19bf517b | aurel32 | |
1329 | 19bf517b | aurel32 | return 0; |
1330 | 19bf517b | aurel32 | } |
1331 | 19bf517b | aurel32 | |
1332 | 19bf517b | aurel32 | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1333 | 19bf517b | aurel32 | { |
1334 | 19bf517b | aurel32 | target_ulong tmp; |
1335 | 19bf517b | aurel32 | tmp = ldtul_p(mem_buf); |
1336 | 19bf517b | aurel32 | |
1337 | 19bf517b | aurel32 | if (n < 31) { |
1338 | 19bf517b | aurel32 | env->ir[n] = tmp; |
1339 | 19bf517b | aurel32 | } |
1340 | 19bf517b | aurel32 | |
1341 | 19bf517b | aurel32 | if (n > 31 && n < 63) { |
1342 | 19bf517b | aurel32 | env->fir[n - 32] = ldfl_p(mem_buf);
|
1343 | 19bf517b | aurel32 | } |
1344 | 19bf517b | aurel32 | |
1345 | 19bf517b | aurel32 | if (n == 64 ) { |
1346 | 19bf517b | aurel32 | env->pc=tmp; |
1347 | 19bf517b | aurel32 | } |
1348 | 19bf517b | aurel32 | |
1349 | 19bf517b | aurel32 | return 8; |
1350 | 19bf517b | aurel32 | } |
1351 | 56aebc89 | pbrook | #else
|
1352 | 56aebc89 | pbrook | |
1353 | 56aebc89 | pbrook | #define NUM_CORE_REGS 0 |
1354 | 56aebc89 | pbrook | |
1355 | 56aebc89 | pbrook | static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n) |
1356 | f1ccf904 | ths | { |
1357 | 56aebc89 | pbrook | return 0; |
1358 | f1ccf904 | ths | } |
1359 | f1ccf904 | ths | |
1360 | 56aebc89 | pbrook | static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) |
1361 | f1ccf904 | ths | { |
1362 | 56aebc89 | pbrook | return 0; |
1363 | 56aebc89 | pbrook | } |
1364 | f1ccf904 | ths | |
1365 | 56aebc89 | pbrook | #endif
|
1366 | f1ccf904 | ths | |
1367 | 56aebc89 | pbrook | static int num_g_regs = NUM_CORE_REGS; |
1368 | f1ccf904 | ths | |
1369 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
1370 | 56aebc89 | pbrook | /* Encode data using the encoding for 'x' packets. */
|
1371 | 56aebc89 | pbrook | static int memtox(char *buf, const char *mem, int len) |
1372 | 56aebc89 | pbrook | { |
1373 | 56aebc89 | pbrook | char *p = buf;
|
1374 | 56aebc89 | pbrook | char c;
|
1375 | 56aebc89 | pbrook | |
1376 | 56aebc89 | pbrook | while (len--) {
|
1377 | 56aebc89 | pbrook | c = *(mem++); |
1378 | 56aebc89 | pbrook | switch (c) {
|
1379 | 56aebc89 | pbrook | case '#': case '$': case '*': case '}': |
1380 | 56aebc89 | pbrook | *(p++) = '}';
|
1381 | 56aebc89 | pbrook | *(p++) = c ^ 0x20;
|
1382 | 56aebc89 | pbrook | break;
|
1383 | 56aebc89 | pbrook | default:
|
1384 | 56aebc89 | pbrook | *(p++) = c; |
1385 | 56aebc89 | pbrook | break;
|
1386 | 56aebc89 | pbrook | } |
1387 | 56aebc89 | pbrook | } |
1388 | 56aebc89 | pbrook | return p - buf;
|
1389 | 56aebc89 | pbrook | } |
1390 | f1ccf904 | ths | |
1391 | 3faf778e | aurel32 | static const char *get_feature_xml(const char *p, const char **newp) |
1392 | 56aebc89 | pbrook | { |
1393 | 56aebc89 | pbrook | extern const char *const xml_builtin[][2]; |
1394 | 56aebc89 | pbrook | size_t len; |
1395 | 56aebc89 | pbrook | int i;
|
1396 | 56aebc89 | pbrook | const char *name; |
1397 | 56aebc89 | pbrook | static char target_xml[1024]; |
1398 | 56aebc89 | pbrook | |
1399 | 56aebc89 | pbrook | len = 0;
|
1400 | 56aebc89 | pbrook | while (p[len] && p[len] != ':') |
1401 | 56aebc89 | pbrook | len++; |
1402 | 56aebc89 | pbrook | *newp = p + len; |
1403 | 56aebc89 | pbrook | |
1404 | 56aebc89 | pbrook | name = NULL;
|
1405 | 56aebc89 | pbrook | if (strncmp(p, "target.xml", len) == 0) { |
1406 | 56aebc89 | pbrook | /* Generate the XML description for this CPU. */
|
1407 | 56aebc89 | pbrook | if (!target_xml[0]) { |
1408 | 56aebc89 | pbrook | GDBRegisterState *r; |
1409 | 56aebc89 | pbrook | |
1410 | 5b3715bf | blueswir1 | snprintf(target_xml, sizeof(target_xml),
|
1411 | 5b3715bf | blueswir1 | "<?xml version=\"1.0\"?>"
|
1412 | 5b3715bf | blueswir1 | "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"
|
1413 | 5b3715bf | blueswir1 | "<target>"
|
1414 | 5b3715bf | blueswir1 | "<xi:include href=\"%s\"/>",
|
1415 | 5b3715bf | blueswir1 | GDB_CORE_XML); |
1416 | 56aebc89 | pbrook | |
1417 | 880a7578 | aliguori | for (r = first_cpu->gdb_regs; r; r = r->next) {
|
1418 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "<xi:include href=\""); |
1419 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), r->xml);
|
1420 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "\"/>"); |
1421 | 56aebc89 | pbrook | } |
1422 | 2dc766da | blueswir1 | pstrcat(target_xml, sizeof(target_xml), "</target>"); |
1423 | 56aebc89 | pbrook | } |
1424 | 56aebc89 | pbrook | return target_xml;
|
1425 | 56aebc89 | pbrook | } |
1426 | 56aebc89 | pbrook | for (i = 0; ; i++) { |
1427 | 56aebc89 | pbrook | name = xml_builtin[i][0];
|
1428 | 56aebc89 | pbrook | if (!name || (strncmp(name, p, len) == 0 && strlen(name) == len)) |
1429 | 56aebc89 | pbrook | break;
|
1430 | 56aebc89 | pbrook | } |
1431 | 56aebc89 | pbrook | return name ? xml_builtin[i][1] : NULL; |
1432 | 56aebc89 | pbrook | } |
1433 | 56aebc89 | pbrook | #endif
|
1434 | f1ccf904 | ths | |
1435 | 56aebc89 | pbrook | static int gdb_read_register(CPUState *env, uint8_t *mem_buf, int reg) |
1436 | 56aebc89 | pbrook | { |
1437 | 56aebc89 | pbrook | GDBRegisterState *r; |
1438 | f1ccf904 | ths | |
1439 | 56aebc89 | pbrook | if (reg < NUM_CORE_REGS)
|
1440 | 56aebc89 | pbrook | return cpu_gdb_read_register(env, mem_buf, reg);
|
1441 | f1ccf904 | ths | |
1442 | 56aebc89 | pbrook | for (r = env->gdb_regs; r; r = r->next) {
|
1443 | 56aebc89 | pbrook | if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
|
1444 | 56aebc89 | pbrook | return r->get_reg(env, mem_buf, reg - r->base_reg);
|
1445 | 56aebc89 | pbrook | } |
1446 | 56aebc89 | pbrook | } |
1447 | 56aebc89 | pbrook | return 0; |
1448 | f1ccf904 | ths | } |
1449 | f1ccf904 | ths | |
1450 | 56aebc89 | pbrook | static int gdb_write_register(CPUState *env, uint8_t *mem_buf, int reg) |
1451 | f1ccf904 | ths | { |
1452 | 56aebc89 | pbrook | GDBRegisterState *r; |
1453 | f1ccf904 | ths | |
1454 | 56aebc89 | pbrook | if (reg < NUM_CORE_REGS)
|
1455 | 56aebc89 | pbrook | return cpu_gdb_write_register(env, mem_buf, reg);
|
1456 | 56aebc89 | pbrook | |
1457 | 56aebc89 | pbrook | for (r = env->gdb_regs; r; r = r->next) {
|
1458 | 56aebc89 | pbrook | if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) {
|
1459 | 56aebc89 | pbrook | return r->set_reg(env, mem_buf, reg - r->base_reg);
|
1460 | 56aebc89 | pbrook | } |
1461 | 56aebc89 | pbrook | } |
1462 | 6da41eaf | bellard | return 0; |
1463 | 6da41eaf | bellard | } |
1464 | 6da41eaf | bellard | |
1465 | 56aebc89 | pbrook | /* Register a supplemental set of CPU registers. If g_pos is nonzero it
|
1466 | 56aebc89 | pbrook | specifies the first register number and these registers are included in
|
1467 | 56aebc89 | pbrook | a standard "g" packet. Direction is relative to gdb, i.e. get_reg is
|
1468 | 56aebc89 | pbrook | gdb reading a CPU register, and set_reg is gdb modifying a CPU register.
|
1469 | 56aebc89 | pbrook | */
|
1470 | 56aebc89 | pbrook | |
1471 | 56aebc89 | pbrook | void gdb_register_coprocessor(CPUState * env,
|
1472 | 56aebc89 | pbrook | gdb_reg_cb get_reg, gdb_reg_cb set_reg, |
1473 | 56aebc89 | pbrook | int num_regs, const char *xml, int g_pos) |
1474 | 6da41eaf | bellard | { |
1475 | 56aebc89 | pbrook | GDBRegisterState *s; |
1476 | 56aebc89 | pbrook | GDBRegisterState **p; |
1477 | 56aebc89 | pbrook | static int last_reg = NUM_CORE_REGS; |
1478 | 56aebc89 | pbrook | |
1479 | 56aebc89 | pbrook | s = (GDBRegisterState *)qemu_mallocz(sizeof(GDBRegisterState));
|
1480 | 56aebc89 | pbrook | s->base_reg = last_reg; |
1481 | 56aebc89 | pbrook | s->num_regs = num_regs; |
1482 | 56aebc89 | pbrook | s->get_reg = get_reg; |
1483 | 56aebc89 | pbrook | s->set_reg = set_reg; |
1484 | 56aebc89 | pbrook | s->xml = xml; |
1485 | 56aebc89 | pbrook | p = &env->gdb_regs; |
1486 | 56aebc89 | pbrook | while (*p) {
|
1487 | 56aebc89 | pbrook | /* Check for duplicates. */
|
1488 | 56aebc89 | pbrook | if (strcmp((*p)->xml, xml) == 0) |
1489 | 56aebc89 | pbrook | return;
|
1490 | 56aebc89 | pbrook | p = &(*p)->next; |
1491 | 56aebc89 | pbrook | } |
1492 | 56aebc89 | pbrook | /* Add to end of list. */
|
1493 | 56aebc89 | pbrook | last_reg += num_regs; |
1494 | 56aebc89 | pbrook | *p = s; |
1495 | 56aebc89 | pbrook | if (g_pos) {
|
1496 | 56aebc89 | pbrook | if (g_pos != s->base_reg) {
|
1497 | 56aebc89 | pbrook | fprintf(stderr, "Error: Bad gdb register numbering for '%s'\n"
|
1498 | 56aebc89 | pbrook | "Expected %d got %d\n", xml, g_pos, s->base_reg);
|
1499 | 56aebc89 | pbrook | } else {
|
1500 | 56aebc89 | pbrook | num_g_regs = last_reg; |
1501 | 56aebc89 | pbrook | } |
1502 | 56aebc89 | pbrook | } |
1503 | 6da41eaf | bellard | } |
1504 | 6da41eaf | bellard | |
1505 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
1506 | a1d1bb31 | aliguori | static const int xlat_gdb_type[] = { |
1507 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_WRITE] = BP_GDB | BP_MEM_WRITE, |
1508 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_READ] = BP_GDB | BP_MEM_READ, |
1509 | a1d1bb31 | aliguori | [GDB_WATCHPOINT_ACCESS] = BP_GDB | BP_MEM_ACCESS, |
1510 | a1d1bb31 | aliguori | }; |
1511 | a1d1bb31 | aliguori | #endif
|
1512 | a1d1bb31 | aliguori | |
1513 | 880a7578 | aliguori | static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type) |
1514 | a1d1bb31 | aliguori | { |
1515 | 880a7578 | aliguori | CPUState *env; |
1516 | 880a7578 | aliguori | int err = 0; |
1517 | 880a7578 | aliguori | |
1518 | e22a25c9 | aliguori | if (kvm_enabled())
|
1519 | e22a25c9 | aliguori | return kvm_insert_breakpoint(gdbserver_state->c_cpu, addr, len, type);
|
1520 | e22a25c9 | aliguori | |
1521 | a1d1bb31 | aliguori | switch (type) {
|
1522 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_SW:
|
1523 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_HW:
|
1524 | 880a7578 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1525 | 880a7578 | aliguori | err = cpu_breakpoint_insert(env, addr, BP_GDB, NULL);
|
1526 | 880a7578 | aliguori | if (err)
|
1527 | 880a7578 | aliguori | break;
|
1528 | 880a7578 | aliguori | } |
1529 | 880a7578 | aliguori | return err;
|
1530 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
1531 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_WRITE:
|
1532 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_READ:
|
1533 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_ACCESS:
|
1534 | 880a7578 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1535 | 880a7578 | aliguori | err = cpu_watchpoint_insert(env, addr, len, xlat_gdb_type[type], |
1536 | 880a7578 | aliguori | NULL);
|
1537 | 880a7578 | aliguori | if (err)
|
1538 | 880a7578 | aliguori | break;
|
1539 | 880a7578 | aliguori | } |
1540 | 880a7578 | aliguori | return err;
|
1541 | a1d1bb31 | aliguori | #endif
|
1542 | a1d1bb31 | aliguori | default:
|
1543 | a1d1bb31 | aliguori | return -ENOSYS;
|
1544 | a1d1bb31 | aliguori | } |
1545 | a1d1bb31 | aliguori | } |
1546 | a1d1bb31 | aliguori | |
1547 | 880a7578 | aliguori | static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) |
1548 | a1d1bb31 | aliguori | { |
1549 | 880a7578 | aliguori | CPUState *env; |
1550 | 880a7578 | aliguori | int err = 0; |
1551 | 880a7578 | aliguori | |
1552 | e22a25c9 | aliguori | if (kvm_enabled())
|
1553 | e22a25c9 | aliguori | return kvm_remove_breakpoint(gdbserver_state->c_cpu, addr, len, type);
|
1554 | e22a25c9 | aliguori | |
1555 | a1d1bb31 | aliguori | switch (type) {
|
1556 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_SW:
|
1557 | a1d1bb31 | aliguori | case GDB_BREAKPOINT_HW:
|
1558 | 880a7578 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1559 | 880a7578 | aliguori | err = cpu_breakpoint_remove(env, addr, BP_GDB); |
1560 | 880a7578 | aliguori | if (err)
|
1561 | 880a7578 | aliguori | break;
|
1562 | 880a7578 | aliguori | } |
1563 | 880a7578 | aliguori | return err;
|
1564 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
1565 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_WRITE:
|
1566 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_READ:
|
1567 | a1d1bb31 | aliguori | case GDB_WATCHPOINT_ACCESS:
|
1568 | 880a7578 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1569 | 880a7578 | aliguori | err = cpu_watchpoint_remove(env, addr, len, xlat_gdb_type[type]); |
1570 | 880a7578 | aliguori | if (err)
|
1571 | 880a7578 | aliguori | break;
|
1572 | 880a7578 | aliguori | } |
1573 | 880a7578 | aliguori | return err;
|
1574 | a1d1bb31 | aliguori | #endif
|
1575 | a1d1bb31 | aliguori | default:
|
1576 | a1d1bb31 | aliguori | return -ENOSYS;
|
1577 | a1d1bb31 | aliguori | } |
1578 | a1d1bb31 | aliguori | } |
1579 | a1d1bb31 | aliguori | |
1580 | 880a7578 | aliguori | static void gdb_breakpoint_remove_all(void) |
1581 | a1d1bb31 | aliguori | { |
1582 | 880a7578 | aliguori | CPUState *env; |
1583 | 880a7578 | aliguori | |
1584 | e22a25c9 | aliguori | if (kvm_enabled()) {
|
1585 | e22a25c9 | aliguori | kvm_remove_all_breakpoints(gdbserver_state->c_cpu); |
1586 | e22a25c9 | aliguori | return;
|
1587 | e22a25c9 | aliguori | } |
1588 | e22a25c9 | aliguori | |
1589 | 880a7578 | aliguori | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1590 | 880a7578 | aliguori | cpu_breakpoint_remove_all(env, BP_GDB); |
1591 | a1d1bb31 | aliguori | #ifndef CONFIG_USER_ONLY
|
1592 | 880a7578 | aliguori | cpu_watchpoint_remove_all(env, BP_GDB); |
1593 | a1d1bb31 | aliguori | #endif
|
1594 | 880a7578 | aliguori | } |
1595 | a1d1bb31 | aliguori | } |
1596 | a1d1bb31 | aliguori | |
1597 | fab9d284 | aurel32 | static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) |
1598 | fab9d284 | aurel32 | { |
1599 | fab9d284 | aurel32 | #if defined(TARGET_I386)
|
1600 | 4c0960c0 | Avi Kivity | cpu_synchronize_state(s->c_cpu); |
1601 | fab9d284 | aurel32 | s->c_cpu->eip = pc; |
1602 | fab9d284 | aurel32 | #elif defined (TARGET_PPC)
|
1603 | fab9d284 | aurel32 | s->c_cpu->nip = pc; |
1604 | fab9d284 | aurel32 | #elif defined (TARGET_SPARC)
|
1605 | fab9d284 | aurel32 | s->c_cpu->pc = pc; |
1606 | fab9d284 | aurel32 | s->c_cpu->npc = pc + 4;
|
1607 | fab9d284 | aurel32 | #elif defined (TARGET_ARM)
|
1608 | fab9d284 | aurel32 | s->c_cpu->regs[15] = pc;
|
1609 | fab9d284 | aurel32 | #elif defined (TARGET_SH4)
|
1610 | fab9d284 | aurel32 | s->c_cpu->pc = pc; |
1611 | fab9d284 | aurel32 | #elif defined (TARGET_MIPS)
|
1612 | fab9d284 | aurel32 | s->c_cpu->active_tc.PC = pc; |
1613 | d74d6a99 | Edgar E. Iglesias | #elif defined (TARGET_MICROBLAZE)
|
1614 | d74d6a99 | Edgar E. Iglesias | s->c_cpu->sregs[SR_PC] = pc; |
1615 | fab9d284 | aurel32 | #elif defined (TARGET_CRIS)
|
1616 | fab9d284 | aurel32 | s->c_cpu->pc = pc; |
1617 | fab9d284 | aurel32 | #elif defined (TARGET_ALPHA)
|
1618 | fab9d284 | aurel32 | s->c_cpu->pc = pc; |
1619 | fab9d284 | aurel32 | #endif
|
1620 | fab9d284 | aurel32 | } |
1621 | fab9d284 | aurel32 | |
1622 | 1e9fa730 | Nathan Froyd | static inline int gdb_id(CPUState *env) |
1623 | 1e9fa730 | Nathan Froyd | { |
1624 | 2f7bb878 | Juan Quintela | #if defined(CONFIG_USER_ONLY) && defined(CONFIG_USE_NPTL)
|
1625 | 1e9fa730 | Nathan Froyd | return env->host_tid;
|
1626 | 1e9fa730 | Nathan Froyd | #else
|
1627 | 1e9fa730 | Nathan Froyd | return env->cpu_index + 1; |
1628 | 1e9fa730 | Nathan Froyd | #endif
|
1629 | 1e9fa730 | Nathan Froyd | } |
1630 | 1e9fa730 | Nathan Froyd | |
1631 | 1e9fa730 | Nathan Froyd | static CPUState *find_cpu(uint32_t thread_id)
|
1632 | 1e9fa730 | Nathan Froyd | { |
1633 | 1e9fa730 | Nathan Froyd | CPUState *env; |
1634 | 1e9fa730 | Nathan Froyd | |
1635 | 1e9fa730 | Nathan Froyd | for (env = first_cpu; env != NULL; env = env->next_cpu) { |
1636 | 1e9fa730 | Nathan Froyd | if (gdb_id(env) == thread_id) {
|
1637 | 1e9fa730 | Nathan Froyd | return env;
|
1638 | 1e9fa730 | Nathan Froyd | } |
1639 | 1e9fa730 | Nathan Froyd | } |
1640 | 1e9fa730 | Nathan Froyd | |
1641 | 1e9fa730 | Nathan Froyd | return NULL; |
1642 | 1e9fa730 | Nathan Froyd | } |
1643 | 1e9fa730 | Nathan Froyd | |
1644 | 880a7578 | aliguori | static int gdb_handle_packet(GDBState *s, const char *line_buf) |
1645 | b4608c04 | bellard | { |
1646 | 880a7578 | aliguori | CPUState *env; |
1647 | b4608c04 | bellard | const char *p; |
1648 | 1e9fa730 | Nathan Froyd | uint32_t thread; |
1649 | 1e9fa730 | Nathan Froyd | int ch, reg_size, type, res;
|
1650 | 56aebc89 | pbrook | char buf[MAX_PACKET_LENGTH];
|
1651 | 56aebc89 | pbrook | uint8_t mem_buf[MAX_PACKET_LENGTH]; |
1652 | 56aebc89 | pbrook | uint8_t *registers; |
1653 | 9d9754a3 | bellard | target_ulong addr, len; |
1654 | 3b46e624 | ths | |
1655 | 858693c6 | bellard | #ifdef DEBUG_GDB
|
1656 | 858693c6 | bellard | printf("command='%s'\n", line_buf);
|
1657 | 858693c6 | bellard | #endif
|
1658 | 858693c6 | bellard | p = line_buf; |
1659 | 858693c6 | bellard | ch = *p++; |
1660 | 858693c6 | bellard | switch(ch) {
|
1661 | 858693c6 | bellard | case '?': |
1662 | 1fddef4b | bellard | /* TODO: Make this return the correct value for user-mode. */
|
1663 | ca587a8e | aurel32 | snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, |
1664 | 1e9fa730 | Nathan Froyd | gdb_id(s->c_cpu)); |
1665 | 858693c6 | bellard | put_packet(s, buf); |
1666 | 7d03f82f | edgar_igl | /* Remove all the breakpoints when this query is issued,
|
1667 | 7d03f82f | edgar_igl | * because gdb is doing and initial connect and the state
|
1668 | 7d03f82f | edgar_igl | * should be cleaned up.
|
1669 | 7d03f82f | edgar_igl | */
|
1670 | 880a7578 | aliguori | gdb_breakpoint_remove_all(); |
1671 | 858693c6 | bellard | break;
|
1672 | 858693c6 | bellard | case 'c': |
1673 | 858693c6 | bellard | if (*p != '\0') { |
1674 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1675 | fab9d284 | aurel32 | gdb_set_cpu_pc(s, addr); |
1676 | 858693c6 | bellard | } |
1677 | ca587a8e | aurel32 | s->signal = 0;
|
1678 | ba70a624 | edgar_igl | gdb_continue(s); |
1679 | 41625033 | bellard | return RS_IDLE;
|
1680 | 1f487ee9 | edgar_igl | case 'C': |
1681 | ca587a8e | aurel32 | s->signal = gdb_signal_to_target (strtoul(p, (char **)&p, 16)); |
1682 | ca587a8e | aurel32 | if (s->signal == -1) |
1683 | ca587a8e | aurel32 | s->signal = 0;
|
1684 | 1f487ee9 | edgar_igl | gdb_continue(s); |
1685 | 1f487ee9 | edgar_igl | return RS_IDLE;
|
1686 | dd32aa10 | Jan Kiszka | case 'v': |
1687 | dd32aa10 | Jan Kiszka | if (strncmp(p, "Cont", 4) == 0) { |
1688 | dd32aa10 | Jan Kiszka | int res_signal, res_thread;
|
1689 | dd32aa10 | Jan Kiszka | |
1690 | dd32aa10 | Jan Kiszka | p += 4;
|
1691 | dd32aa10 | Jan Kiszka | if (*p == '?') { |
1692 | dd32aa10 | Jan Kiszka | put_packet(s, "vCont;c;C;s;S");
|
1693 | dd32aa10 | Jan Kiszka | break;
|
1694 | dd32aa10 | Jan Kiszka | } |
1695 | dd32aa10 | Jan Kiszka | res = 0;
|
1696 | dd32aa10 | Jan Kiszka | res_signal = 0;
|
1697 | dd32aa10 | Jan Kiszka | res_thread = 0;
|
1698 | dd32aa10 | Jan Kiszka | while (*p) {
|
1699 | dd32aa10 | Jan Kiszka | int action, signal;
|
1700 | dd32aa10 | Jan Kiszka | |
1701 | dd32aa10 | Jan Kiszka | if (*p++ != ';') { |
1702 | dd32aa10 | Jan Kiszka | res = 0;
|
1703 | dd32aa10 | Jan Kiszka | break;
|
1704 | dd32aa10 | Jan Kiszka | } |
1705 | dd32aa10 | Jan Kiszka | action = *p++; |
1706 | dd32aa10 | Jan Kiszka | signal = 0;
|
1707 | dd32aa10 | Jan Kiszka | if (action == 'C' || action == 'S') { |
1708 | dd32aa10 | Jan Kiszka | signal = strtoul(p, (char **)&p, 16); |
1709 | dd32aa10 | Jan Kiszka | } else if (action != 'c' && action != 's') { |
1710 | dd32aa10 | Jan Kiszka | res = 0;
|
1711 | dd32aa10 | Jan Kiszka | break;
|
1712 | dd32aa10 | Jan Kiszka | } |
1713 | dd32aa10 | Jan Kiszka | thread = 0;
|
1714 | dd32aa10 | Jan Kiszka | if (*p == ':') { |
1715 | dd32aa10 | Jan Kiszka | thread = strtoull(p+1, (char **)&p, 16); |
1716 | dd32aa10 | Jan Kiszka | } |
1717 | dd32aa10 | Jan Kiszka | action = tolower(action); |
1718 | dd32aa10 | Jan Kiszka | if (res == 0 || (res == 'c' && action == 's')) { |
1719 | dd32aa10 | Jan Kiszka | res = action; |
1720 | dd32aa10 | Jan Kiszka | res_signal = signal; |
1721 | dd32aa10 | Jan Kiszka | res_thread = thread; |
1722 | dd32aa10 | Jan Kiszka | } |
1723 | dd32aa10 | Jan Kiszka | } |
1724 | dd32aa10 | Jan Kiszka | if (res) {
|
1725 | dd32aa10 | Jan Kiszka | if (res_thread != -1 && res_thread != 0) { |
1726 | dd32aa10 | Jan Kiszka | env = find_cpu(res_thread); |
1727 | dd32aa10 | Jan Kiszka | if (env == NULL) { |
1728 | dd32aa10 | Jan Kiszka | put_packet(s, "E22");
|
1729 | dd32aa10 | Jan Kiszka | break;
|
1730 | dd32aa10 | Jan Kiszka | } |
1731 | dd32aa10 | Jan Kiszka | s->c_cpu = env; |
1732 | dd32aa10 | Jan Kiszka | } |
1733 | dd32aa10 | Jan Kiszka | if (res == 's') { |
1734 | dd32aa10 | Jan Kiszka | cpu_single_step(s->c_cpu, sstep_flags); |
1735 | dd32aa10 | Jan Kiszka | } |
1736 | dd32aa10 | Jan Kiszka | s->signal = res_signal; |
1737 | dd32aa10 | Jan Kiszka | gdb_continue(s); |
1738 | dd32aa10 | Jan Kiszka | return RS_IDLE;
|
1739 | dd32aa10 | Jan Kiszka | } |
1740 | dd32aa10 | Jan Kiszka | break;
|
1741 | dd32aa10 | Jan Kiszka | } else {
|
1742 | dd32aa10 | Jan Kiszka | goto unknown_command;
|
1743 | dd32aa10 | Jan Kiszka | } |
1744 | 7d03f82f | edgar_igl | case 'k': |
1745 | 7d03f82f | edgar_igl | /* Kill the target */
|
1746 | 7d03f82f | edgar_igl | fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");
|
1747 | 7d03f82f | edgar_igl | exit(0);
|
1748 | 7d03f82f | edgar_igl | case 'D': |
1749 | 7d03f82f | edgar_igl | /* Detach packet */
|
1750 | 880a7578 | aliguori | gdb_breakpoint_remove_all(); |
1751 | 7d03f82f | edgar_igl | gdb_continue(s); |
1752 | 7d03f82f | edgar_igl | put_packet(s, "OK");
|
1753 | 7d03f82f | edgar_igl | break;
|
1754 | 858693c6 | bellard | case 's': |
1755 | 858693c6 | bellard | if (*p != '\0') { |
1756 | 8fac5803 | ths | addr = strtoull(p, (char **)&p, 16); |
1757 | fab9d284 | aurel32 | gdb_set_cpu_pc(s, addr); |
1758 | 858693c6 | bellard | } |
1759 | 880a7578 | aliguori | cpu_single_step(s->c_cpu, sstep_flags); |
1760 | ba70a624 | edgar_igl | gdb_continue(s); |
1761 | 41625033 | bellard | return RS_IDLE;
|
1762 | a2d1ebaf | pbrook | case 'F': |
1763 | a2d1ebaf | pbrook | { |
1764 | a2d1ebaf | pbrook | target_ulong ret; |
1765 | a2d1ebaf | pbrook | target_ulong err; |
1766 | a2d1ebaf | pbrook | |
1767 | a2d1ebaf | pbrook | ret = strtoull(p, (char **)&p, 16); |
1768 | a2d1ebaf | pbrook | if (*p == ',') { |
1769 | a2d1ebaf | pbrook | p++; |
1770 | a2d1ebaf | pbrook | err = strtoull(p, (char **)&p, 16); |
1771 | a2d1ebaf | pbrook | } else {
|
1772 | a2d1ebaf | pbrook | err = 0;
|
1773 | a2d1ebaf | pbrook | } |
1774 | a2d1ebaf | pbrook | if (*p == ',') |
1775 | a2d1ebaf | pbrook | p++; |
1776 | a2d1ebaf | pbrook | type = *p; |
1777 | a2d1ebaf | pbrook | if (gdb_current_syscall_cb)
|
1778 | 880a7578 | aliguori | gdb_current_syscall_cb(s->c_cpu, ret, err); |
1779 | a2d1ebaf | pbrook | if (type == 'C') { |
1780 | a2d1ebaf | pbrook | put_packet(s, "T02");
|
1781 | a2d1ebaf | pbrook | } else {
|
1782 | ba70a624 | edgar_igl | gdb_continue(s); |
1783 | a2d1ebaf | pbrook | } |
1784 | a2d1ebaf | pbrook | } |
1785 | a2d1ebaf | pbrook | break;
|
1786 | 858693c6 | bellard | case 'g': |
1787 | 4c0960c0 | Avi Kivity | cpu_synchronize_state(s->g_cpu); |
1788 | 56aebc89 | pbrook | len = 0;
|
1789 | 56aebc89 | pbrook | for (addr = 0; addr < num_g_regs; addr++) { |
1790 | 880a7578 | aliguori | reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr); |
1791 | 56aebc89 | pbrook | len += reg_size; |
1792 | 56aebc89 | pbrook | } |
1793 | 56aebc89 | pbrook | memtohex(buf, mem_buf, len); |
1794 | 858693c6 | bellard | put_packet(s, buf); |
1795 | 858693c6 | bellard | break;
|
1796 | 858693c6 | bellard | case 'G': |
1797 | 4c0960c0 | Avi Kivity | cpu_synchronize_state(s->g_cpu); |
1798 | 56aebc89 | pbrook | registers = mem_buf; |
1799 | 858693c6 | bellard | len = strlen(p) / 2;
|
1800 | 858693c6 | bellard | hextomem((uint8_t *)registers, p, len); |
1801 | 56aebc89 | pbrook | for (addr = 0; addr < num_g_regs && len > 0; addr++) { |
1802 | 880a7578 | aliguori | reg_size = gdb_write_register(s->g_cpu, registers, addr); |
1803 | 56aebc89 | pbrook | len -= reg_size; |
1804 | 56aebc89 | pbrook | registers += reg_size; |
1805 | 56aebc89 | pbrook | } |
1806 | 858693c6 | bellard | put_packet(s, "OK");
|
1807 | 858693c6 | bellard | break;
|
1808 | 858693c6 | bellard | case 'm': |
1809 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1810 | 858693c6 | bellard | if (*p == ',') |
1811 | 858693c6 | bellard | p++; |
1812 | 9d9754a3 | bellard | len = strtoull(p, NULL, 16); |
1813 | 880a7578 | aliguori | if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) { |
1814 | 6f970bd9 | bellard | put_packet (s, "E14");
|
1815 | 6f970bd9 | bellard | } else {
|
1816 | 6f970bd9 | bellard | memtohex(buf, mem_buf, len); |
1817 | 6f970bd9 | bellard | put_packet(s, buf); |
1818 | 6f970bd9 | bellard | } |
1819 | 858693c6 | bellard | break;
|
1820 | 858693c6 | bellard | case 'M': |
1821 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1822 | 858693c6 | bellard | if (*p == ',') |
1823 | 858693c6 | bellard | p++; |
1824 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1825 | b328f873 | bellard | if (*p == ':') |
1826 | 858693c6 | bellard | p++; |
1827 | 858693c6 | bellard | hextomem(mem_buf, p, len); |
1828 | 880a7578 | aliguori | if (cpu_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0) |
1829 | 905f20b1 | bellard | put_packet(s, "E14");
|
1830 | 858693c6 | bellard | else
|
1831 | 858693c6 | bellard | put_packet(s, "OK");
|
1832 | 858693c6 | bellard | break;
|
1833 | 56aebc89 | pbrook | case 'p': |
1834 | 56aebc89 | pbrook | /* Older gdb are really dumb, and don't use 'g' if 'p' is avaialable.
|
1835 | 56aebc89 | pbrook | This works, but can be very slow. Anything new enough to
|
1836 | 56aebc89 | pbrook | understand XML also knows how to use this properly. */
|
1837 | 56aebc89 | pbrook | if (!gdb_has_xml)
|
1838 | 56aebc89 | pbrook | goto unknown_command;
|
1839 | 56aebc89 | pbrook | addr = strtoull(p, (char **)&p, 16); |
1840 | 880a7578 | aliguori | reg_size = gdb_read_register(s->g_cpu, mem_buf, addr); |
1841 | 56aebc89 | pbrook | if (reg_size) {
|
1842 | 56aebc89 | pbrook | memtohex(buf, mem_buf, reg_size); |
1843 | 56aebc89 | pbrook | put_packet(s, buf); |
1844 | 56aebc89 | pbrook | } else {
|
1845 | 56aebc89 | pbrook | put_packet(s, "E14");
|
1846 | 56aebc89 | pbrook | } |
1847 | 56aebc89 | pbrook | break;
|
1848 | 56aebc89 | pbrook | case 'P': |
1849 | 56aebc89 | pbrook | if (!gdb_has_xml)
|
1850 | 56aebc89 | pbrook | goto unknown_command;
|
1851 | 56aebc89 | pbrook | addr = strtoull(p, (char **)&p, 16); |
1852 | 56aebc89 | pbrook | if (*p == '=') |
1853 | 56aebc89 | pbrook | p++; |
1854 | 56aebc89 | pbrook | reg_size = strlen(p) / 2;
|
1855 | 56aebc89 | pbrook | hextomem(mem_buf, p, reg_size); |
1856 | 880a7578 | aliguori | gdb_write_register(s->g_cpu, mem_buf, addr); |
1857 | 56aebc89 | pbrook | put_packet(s, "OK");
|
1858 | 56aebc89 | pbrook | break;
|
1859 | 858693c6 | bellard | case 'Z': |
1860 | 858693c6 | bellard | case 'z': |
1861 | 858693c6 | bellard | type = strtoul(p, (char **)&p, 16); |
1862 | 858693c6 | bellard | if (*p == ',') |
1863 | 858693c6 | bellard | p++; |
1864 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1865 | 858693c6 | bellard | if (*p == ',') |
1866 | 858693c6 | bellard | p++; |
1867 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1868 | a1d1bb31 | aliguori | if (ch == 'Z') |
1869 | 880a7578 | aliguori | res = gdb_breakpoint_insert(addr, len, type); |
1870 | a1d1bb31 | aliguori | else
|
1871 | 880a7578 | aliguori | res = gdb_breakpoint_remove(addr, len, type); |
1872 | a1d1bb31 | aliguori | if (res >= 0) |
1873 | a1d1bb31 | aliguori | put_packet(s, "OK");
|
1874 | a1d1bb31 | aliguori | else if (res == -ENOSYS) |
1875 | 0f459d16 | pbrook | put_packet(s, "");
|
1876 | a1d1bb31 | aliguori | else
|
1877 | a1d1bb31 | aliguori | put_packet(s, "E22");
|
1878 | 858693c6 | bellard | break;
|
1879 | 880a7578 | aliguori | case 'H': |
1880 | 880a7578 | aliguori | type = *p++; |
1881 | 880a7578 | aliguori | thread = strtoull(p, (char **)&p, 16); |
1882 | 880a7578 | aliguori | if (thread == -1 || thread == 0) { |
1883 | 880a7578 | aliguori | put_packet(s, "OK");
|
1884 | 880a7578 | aliguori | break;
|
1885 | 880a7578 | aliguori | } |
1886 | 1e9fa730 | Nathan Froyd | env = find_cpu(thread); |
1887 | 880a7578 | aliguori | if (env == NULL) { |
1888 | 880a7578 | aliguori | put_packet(s, "E22");
|
1889 | 880a7578 | aliguori | break;
|
1890 | 880a7578 | aliguori | } |
1891 | 880a7578 | aliguori | switch (type) {
|
1892 | 880a7578 | aliguori | case 'c': |
1893 | 880a7578 | aliguori | s->c_cpu = env; |
1894 | 880a7578 | aliguori | put_packet(s, "OK");
|
1895 | 880a7578 | aliguori | break;
|
1896 | 880a7578 | aliguori | case 'g': |
1897 | 880a7578 | aliguori | s->g_cpu = env; |
1898 | 880a7578 | aliguori | put_packet(s, "OK");
|
1899 | 880a7578 | aliguori | break;
|
1900 | 880a7578 | aliguori | default:
|
1901 | 880a7578 | aliguori | put_packet(s, "E22");
|
1902 | 880a7578 | aliguori | break;
|
1903 | 880a7578 | aliguori | } |
1904 | 880a7578 | aliguori | break;
|
1905 | 880a7578 | aliguori | case 'T': |
1906 | 880a7578 | aliguori | thread = strtoull(p, (char **)&p, 16); |
1907 | 1e9fa730 | Nathan Froyd | env = find_cpu(thread); |
1908 | 1e9fa730 | Nathan Froyd | |
1909 | 1e9fa730 | Nathan Froyd | if (env != NULL) { |
1910 | 1e9fa730 | Nathan Froyd | put_packet(s, "OK");
|
1911 | 1e9fa730 | Nathan Froyd | } else {
|
1912 | 880a7578 | aliguori | put_packet(s, "E22");
|
1913 | 1e9fa730 | Nathan Froyd | } |
1914 | 880a7578 | aliguori | break;
|
1915 | 978efd6a | pbrook | case 'q': |
1916 | 60897d36 | edgar_igl | case 'Q': |
1917 | 60897d36 | edgar_igl | /* parse any 'q' packets here */
|
1918 | 60897d36 | edgar_igl | if (!strcmp(p,"qemu.sstepbits")) { |
1919 | 60897d36 | edgar_igl | /* Query Breakpoint bit definitions */
|
1920 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", |
1921 | 363a37d5 | blueswir1 | SSTEP_ENABLE, |
1922 | 363a37d5 | blueswir1 | SSTEP_NOIRQ, |
1923 | 363a37d5 | blueswir1 | SSTEP_NOTIMER); |
1924 | 60897d36 | edgar_igl | put_packet(s, buf); |
1925 | 60897d36 | edgar_igl | break;
|
1926 | 60897d36 | edgar_igl | } else if (strncmp(p,"qemu.sstep",10) == 0) { |
1927 | 60897d36 | edgar_igl | /* Display or change the sstep_flags */
|
1928 | 60897d36 | edgar_igl | p += 10;
|
1929 | 60897d36 | edgar_igl | if (*p != '=') { |
1930 | 60897d36 | edgar_igl | /* Display current setting */
|
1931 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf), "0x%x", sstep_flags); |
1932 | 60897d36 | edgar_igl | put_packet(s, buf); |
1933 | 60897d36 | edgar_igl | break;
|
1934 | 60897d36 | edgar_igl | } |
1935 | 60897d36 | edgar_igl | p++; |
1936 | 60897d36 | edgar_igl | type = strtoul(p, (char **)&p, 16); |
1937 | 60897d36 | edgar_igl | sstep_flags = type; |
1938 | 60897d36 | edgar_igl | put_packet(s, "OK");
|
1939 | 60897d36 | edgar_igl | break;
|
1940 | 880a7578 | aliguori | } else if (strcmp(p,"C") == 0) { |
1941 | 880a7578 | aliguori | /* "Current thread" remains vague in the spec, so always return
|
1942 | 880a7578 | aliguori | * the first CPU (gdb returns the first thread). */
|
1943 | 880a7578 | aliguori | put_packet(s, "QC1");
|
1944 | 880a7578 | aliguori | break;
|
1945 | 880a7578 | aliguori | } else if (strcmp(p,"fThreadInfo") == 0) { |
1946 | 880a7578 | aliguori | s->query_cpu = first_cpu; |
1947 | 880a7578 | aliguori | goto report_cpuinfo;
|
1948 | 880a7578 | aliguori | } else if (strcmp(p,"sThreadInfo") == 0) { |
1949 | 880a7578 | aliguori | report_cpuinfo:
|
1950 | 880a7578 | aliguori | if (s->query_cpu) {
|
1951 | 1e9fa730 | Nathan Froyd | snprintf(buf, sizeof(buf), "m%x", gdb_id(s->query_cpu)); |
1952 | 880a7578 | aliguori | put_packet(s, buf); |
1953 | 880a7578 | aliguori | s->query_cpu = s->query_cpu->next_cpu; |
1954 | 880a7578 | aliguori | } else
|
1955 | 880a7578 | aliguori | put_packet(s, "l");
|
1956 | 880a7578 | aliguori | break;
|
1957 | 880a7578 | aliguori | } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) { |
1958 | 880a7578 | aliguori | thread = strtoull(p+16, (char **)&p, 16); |
1959 | 1e9fa730 | Nathan Froyd | env = find_cpu(thread); |
1960 | 1e9fa730 | Nathan Froyd | if (env != NULL) { |
1961 | 4c0960c0 | Avi Kivity | cpu_synchronize_state(env); |
1962 | 1e9fa730 | Nathan Froyd | len = snprintf((char *)mem_buf, sizeof(mem_buf), |
1963 | 1e9fa730 | Nathan Froyd | "CPU#%d [%s]", env->cpu_index,
|
1964 | 1e9fa730 | Nathan Froyd | env->halted ? "halted " : "running"); |
1965 | 1e9fa730 | Nathan Froyd | memtohex(buf, mem_buf, len); |
1966 | 1e9fa730 | Nathan Froyd | put_packet(s, buf); |
1967 | 1e9fa730 | Nathan Froyd | } |
1968 | 880a7578 | aliguori | break;
|
1969 | 60897d36 | edgar_igl | } |
1970 | 0b8a988c | blueswir1 | #ifdef CONFIG_USER_ONLY
|
1971 | 60897d36 | edgar_igl | else if (strncmp(p, "Offsets", 7) == 0) { |
1972 | 880a7578 | aliguori | TaskState *ts = s->c_cpu->opaque; |
1973 | 978efd6a | pbrook | |
1974 | 363a37d5 | blueswir1 | snprintf(buf, sizeof(buf),
|
1975 | 363a37d5 | blueswir1 | "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx |
1976 | 363a37d5 | blueswir1 | ";Bss=" TARGET_ABI_FMT_lx,
|
1977 | 363a37d5 | blueswir1 | ts->info->code_offset, |
1978 | 363a37d5 | blueswir1 | ts->info->data_offset, |
1979 | 363a37d5 | blueswir1 | ts->info->data_offset); |
1980 | 978efd6a | pbrook | put_packet(s, buf); |
1981 | 978efd6a | pbrook | break;
|
1982 | 978efd6a | pbrook | } |
1983 | 0b8a988c | blueswir1 | #else /* !CONFIG_USER_ONLY */ |
1984 | 8a34a0fb | aliguori | else if (strncmp(p, "Rcmd,", 5) == 0) { |
1985 | 8a34a0fb | aliguori | int len = strlen(p + 5); |
1986 | 8a34a0fb | aliguori | |
1987 | 8a34a0fb | aliguori | if ((len % 2) != 0) { |
1988 | 8a34a0fb | aliguori | put_packet(s, "E01");
|
1989 | 8a34a0fb | aliguori | break;
|
1990 | 8a34a0fb | aliguori | } |
1991 | 8a34a0fb | aliguori | hextomem(mem_buf, p + 5, len);
|
1992 | 8a34a0fb | aliguori | len = len / 2;
|
1993 | 8a34a0fb | aliguori | mem_buf[len++] = 0;
|
1994 | 8a34a0fb | aliguori | qemu_chr_read(s->mon_chr, mem_buf, len); |
1995 | 8a34a0fb | aliguori | put_packet(s, "OK");
|
1996 | 8a34a0fb | aliguori | break;
|
1997 | 8a34a0fb | aliguori | } |
1998 | 0b8a988c | blueswir1 | #endif /* !CONFIG_USER_ONLY */ |
1999 | 56aebc89 | pbrook | if (strncmp(p, "Supported", 9) == 0) { |
2000 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "PacketSize=%x", MAX_PACKET_LENGTH); |
2001 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
2002 | 2dc766da | blueswir1 | pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); |
2003 | 56aebc89 | pbrook | #endif
|
2004 | 56aebc89 | pbrook | put_packet(s, buf); |
2005 | 56aebc89 | pbrook | break;
|
2006 | 56aebc89 | pbrook | } |
2007 | 56aebc89 | pbrook | #ifdef GDB_CORE_XML
|
2008 | 56aebc89 | pbrook | if (strncmp(p, "Xfer:features:read:", 19) == 0) { |
2009 | 56aebc89 | pbrook | const char *xml; |
2010 | 56aebc89 | pbrook | target_ulong total_len; |
2011 | 56aebc89 | pbrook | |
2012 | 56aebc89 | pbrook | gdb_has_xml = 1;
|
2013 | 56aebc89 | pbrook | p += 19;
|
2014 | 880a7578 | aliguori | xml = get_feature_xml(p, &p); |
2015 | 56aebc89 | pbrook | if (!xml) {
|
2016 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "E00"); |
2017 | 56aebc89 | pbrook | put_packet(s, buf); |
2018 | 56aebc89 | pbrook | break;
|
2019 | 56aebc89 | pbrook | } |
2020 | 56aebc89 | pbrook | |
2021 | 56aebc89 | pbrook | if (*p == ':') |
2022 | 56aebc89 | pbrook | p++; |
2023 | 56aebc89 | pbrook | addr = strtoul(p, (char **)&p, 16); |
2024 | 56aebc89 | pbrook | if (*p == ',') |
2025 | 56aebc89 | pbrook | p++; |
2026 | 56aebc89 | pbrook | len = strtoul(p, (char **)&p, 16); |
2027 | 56aebc89 | pbrook | |
2028 | 56aebc89 | pbrook | total_len = strlen(xml); |
2029 | 56aebc89 | pbrook | if (addr > total_len) {
|
2030 | 5b3715bf | blueswir1 | snprintf(buf, sizeof(buf), "E00"); |
2031 | 56aebc89 | pbrook | put_packet(s, buf); |
2032 | 56aebc89 | pbrook | break;
|
2033 | 56aebc89 | pbrook | } |
2034 | 56aebc89 | pbrook | if (len > (MAX_PACKET_LENGTH - 5) / 2) |
2035 | 56aebc89 | pbrook | len = (MAX_PACKET_LENGTH - 5) / 2; |
2036 | 56aebc89 | pbrook | if (len < total_len - addr) {
|
2037 | 56aebc89 | pbrook | buf[0] = 'm'; |
2038 | 56aebc89 | pbrook | len = memtox(buf + 1, xml + addr, len);
|
2039 | 56aebc89 | pbrook | } else {
|
2040 | 56aebc89 | pbrook | buf[0] = 'l'; |
2041 | 56aebc89 | pbrook | len = memtox(buf + 1, xml + addr, total_len - addr);
|
2042 | 56aebc89 | pbrook | } |
2043 | 56aebc89 | pbrook | put_packet_binary(s, buf, len + 1);
|
2044 | 56aebc89 | pbrook | break;
|
2045 | 56aebc89 | pbrook | } |
2046 | 56aebc89 | pbrook | #endif
|
2047 | 56aebc89 | pbrook | /* Unrecognised 'q' command. */
|
2048 | 56aebc89 | pbrook | goto unknown_command;
|
2049 | 56aebc89 | pbrook | |
2050 | 858693c6 | bellard | default:
|
2051 | 56aebc89 | pbrook | unknown_command:
|
2052 | 858693c6 | bellard | /* put empty packet */
|
2053 | 858693c6 | bellard | buf[0] = '\0'; |
2054 | 858693c6 | bellard | put_packet(s, buf); |
2055 | 858693c6 | bellard | break;
|
2056 | 858693c6 | bellard | } |
2057 | 858693c6 | bellard | return RS_IDLE;
|
2058 | 858693c6 | bellard | } |
2059 | 858693c6 | bellard | |
2060 | 880a7578 | aliguori | void gdb_set_stop_cpu(CPUState *env)
|
2061 | 880a7578 | aliguori | { |
2062 | 880a7578 | aliguori | gdbserver_state->c_cpu = env; |
2063 | 880a7578 | aliguori | gdbserver_state->g_cpu = env; |
2064 | 880a7578 | aliguori | } |
2065 | 880a7578 | aliguori | |
2066 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
2067 | 9781e040 | aliguori | static void gdb_vm_state_change(void *opaque, int running, int reason) |
2068 | 858693c6 | bellard | { |
2069 | 880a7578 | aliguori | GDBState *s = gdbserver_state; |
2070 | 880a7578 | aliguori | CPUState *env = s->c_cpu; |
2071 | 858693c6 | bellard | char buf[256]; |
2072 | d6fc1b39 | aliguori | const char *type; |
2073 | 858693c6 | bellard | int ret;
|
2074 | 858693c6 | bellard | |
2075 | 9781e040 | aliguori | if (running || (reason != EXCP_DEBUG && reason != EXCP_INTERRUPT) ||
|
2076 | 36556b20 | aliguori | s->state == RS_INACTIVE || s->state == RS_SYSCALL) |
2077 | a2d1ebaf | pbrook | return;
|
2078 | a2d1ebaf | pbrook | |
2079 | 858693c6 | bellard | /* disable single step if it was enable */
|
2080 | 880a7578 | aliguori | cpu_single_step(env, 0);
|
2081 | 858693c6 | bellard | |
2082 | e80cfcfc | bellard | if (reason == EXCP_DEBUG) {
|
2083 | 880a7578 | aliguori | if (env->watchpoint_hit) {
|
2084 | 880a7578 | aliguori | switch (env->watchpoint_hit->flags & BP_MEM_ACCESS) {
|
2085 | a1d1bb31 | aliguori | case BP_MEM_READ:
|
2086 | d6fc1b39 | aliguori | type = "r";
|
2087 | d6fc1b39 | aliguori | break;
|
2088 | a1d1bb31 | aliguori | case BP_MEM_ACCESS:
|
2089 | d6fc1b39 | aliguori | type = "a";
|
2090 | d6fc1b39 | aliguori | break;
|
2091 | d6fc1b39 | aliguori | default:
|
2092 | d6fc1b39 | aliguori | type = "";
|
2093 | d6fc1b39 | aliguori | break;
|
2094 | d6fc1b39 | aliguori | } |
2095 | 880a7578 | aliguori | snprintf(buf, sizeof(buf),
|
2096 | 880a7578 | aliguori | "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";", |
2097 | 1e9fa730 | Nathan Froyd | GDB_SIGNAL_TRAP, gdb_id(env), type, |
2098 | 880a7578 | aliguori | env->watchpoint_hit->vaddr); |
2099 | 6658ffb8 | pbrook | put_packet(s, buf); |
2100 | 880a7578 | aliguori | env->watchpoint_hit = NULL;
|
2101 | 6658ffb8 | pbrook | return;
|
2102 | 6658ffb8 | pbrook | } |
2103 | 880a7578 | aliguori | tb_flush(env); |
2104 | ca587a8e | aurel32 | ret = GDB_SIGNAL_TRAP; |
2105 | bbeb7b5c | bellard | } else {
|
2106 | 9781e040 | aliguori | ret = GDB_SIGNAL_INT; |
2107 | bbeb7b5c | bellard | } |
2108 | 1e9fa730 | Nathan Froyd | snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, gdb_id(env)); |
2109 | 858693c6 | bellard | put_packet(s, buf); |
2110 | 858693c6 | bellard | } |
2111 | 1fddef4b | bellard | #endif
|
2112 | 858693c6 | bellard | |
2113 | a2d1ebaf | pbrook | /* Send a gdb syscall request.
|
2114 | a2d1ebaf | pbrook | This accepts limited printf-style format specifiers, specifically:
|
2115 | a87295e8 | pbrook | %x - target_ulong argument printed in hex.
|
2116 | a87295e8 | pbrook | %lx - 64-bit argument printed in hex.
|
2117 | a87295e8 | pbrook | %s - string pointer (target_ulong) and length (int) pair. */
|
2118 | 7ccfb2eb | blueswir1 | void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...) |
2119 | a2d1ebaf | pbrook | { |
2120 | a2d1ebaf | pbrook | va_list va; |
2121 | a2d1ebaf | pbrook | char buf[256]; |
2122 | a2d1ebaf | pbrook | char *p;
|
2123 | a2d1ebaf | pbrook | target_ulong addr; |
2124 | a87295e8 | pbrook | uint64_t i64; |
2125 | a2d1ebaf | pbrook | GDBState *s; |
2126 | a2d1ebaf | pbrook | |
2127 | 880a7578 | aliguori | s = gdbserver_state; |
2128 | a2d1ebaf | pbrook | if (!s)
|
2129 | a2d1ebaf | pbrook | return;
|
2130 | a2d1ebaf | pbrook | gdb_current_syscall_cb = cb; |
2131 | a2d1ebaf | pbrook | s->state = RS_SYSCALL; |
2132 | a2d1ebaf | pbrook | #ifndef CONFIG_USER_ONLY
|
2133 | a2d1ebaf | pbrook | vm_stop(EXCP_DEBUG); |
2134 | a2d1ebaf | pbrook | #endif
|
2135 | a2d1ebaf | pbrook | s->state = RS_IDLE; |
2136 | a2d1ebaf | pbrook | va_start(va, fmt); |
2137 | a2d1ebaf | pbrook | p = buf; |
2138 | a2d1ebaf | pbrook | *(p++) = 'F';
|
2139 | a2d1ebaf | pbrook | while (*fmt) {
|
2140 | a2d1ebaf | pbrook | if (*fmt == '%') { |
2141 | a2d1ebaf | pbrook | fmt++; |
2142 | a2d1ebaf | pbrook | switch (*fmt++) {
|
2143 | a2d1ebaf | pbrook | case 'x': |
2144 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
2145 | 363a37d5 | blueswir1 | p += snprintf(p, &buf[sizeof(buf)] - p, TARGET_FMT_lx, addr);
|
2146 | a2d1ebaf | pbrook | break;
|
2147 | a87295e8 | pbrook | case 'l': |
2148 | a87295e8 | pbrook | if (*(fmt++) != 'x') |
2149 | a87295e8 | pbrook | goto bad_format;
|
2150 | a87295e8 | pbrook | i64 = va_arg(va, uint64_t); |
2151 | 363a37d5 | blueswir1 | p += snprintf(p, &buf[sizeof(buf)] - p, "%" PRIx64, i64); |
2152 | a87295e8 | pbrook | break;
|
2153 | a2d1ebaf | pbrook | case 's': |
2154 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
2155 | 363a37d5 | blueswir1 | p += snprintf(p, &buf[sizeof(buf)] - p, TARGET_FMT_lx "/%x", |
2156 | 363a37d5 | blueswir1 | addr, va_arg(va, int));
|
2157 | a2d1ebaf | pbrook | break;
|
2158 | a2d1ebaf | pbrook | default:
|
2159 | a87295e8 | pbrook | bad_format:
|
2160 | a2d1ebaf | pbrook | fprintf(stderr, "gdbstub: Bad syscall format string '%s'\n",
|
2161 | a2d1ebaf | pbrook | fmt - 1);
|
2162 | a2d1ebaf | pbrook | break;
|
2163 | a2d1ebaf | pbrook | } |
2164 | a2d1ebaf | pbrook | } else {
|
2165 | a2d1ebaf | pbrook | *(p++) = *(fmt++); |
2166 | a2d1ebaf | pbrook | } |
2167 | a2d1ebaf | pbrook | } |
2168 | 8a93e02a | pbrook | *p = 0;
|
2169 | a2d1ebaf | pbrook | va_end(va); |
2170 | a2d1ebaf | pbrook | put_packet(s, buf); |
2171 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
2172 | 880a7578 | aliguori | gdb_handlesig(s->c_cpu, 0);
|
2173 | a2d1ebaf | pbrook | #else
|
2174 | 3098dba0 | aurel32 | cpu_exit(s->c_cpu); |
2175 | a2d1ebaf | pbrook | #endif
|
2176 | a2d1ebaf | pbrook | } |
2177 | a2d1ebaf | pbrook | |
2178 | 6a00d601 | bellard | static void gdb_read_byte(GDBState *s, int ch) |
2179 | 858693c6 | bellard | { |
2180 | 858693c6 | bellard | int i, csum;
|
2181 | 60fe76f3 | ths | uint8_t reply; |
2182 | 858693c6 | bellard | |
2183 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
2184 | 4046d913 | pbrook | if (s->last_packet_len) {
|
2185 | 4046d913 | pbrook | /* Waiting for a response to the last packet. If we see the start
|
2186 | 4046d913 | pbrook | of a new command then abandon the previous response. */
|
2187 | 4046d913 | pbrook | if (ch == '-') { |
2188 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
2189 | 4046d913 | pbrook | printf("Got NACK, retransmitting\n");
|
2190 | 4046d913 | pbrook | #endif
|
2191 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
2192 | 4046d913 | pbrook | } |
2193 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
2194 | 4046d913 | pbrook | else if (ch == '+') |
2195 | 4046d913 | pbrook | printf("Got ACK\n");
|
2196 | 4046d913 | pbrook | else
|
2197 | 4046d913 | pbrook | printf("Got '%c' when expecting ACK/NACK\n", ch);
|
2198 | 4046d913 | pbrook | #endif
|
2199 | 4046d913 | pbrook | if (ch == '+' || ch == '$') |
2200 | 4046d913 | pbrook | s->last_packet_len = 0;
|
2201 | 4046d913 | pbrook | if (ch != '$') |
2202 | 4046d913 | pbrook | return;
|
2203 | 4046d913 | pbrook | } |
2204 | 858693c6 | bellard | if (vm_running) {
|
2205 | 858693c6 | bellard | /* when the CPU is running, we cannot do anything except stop
|
2206 | 858693c6 | bellard | it when receiving a char */
|
2207 | 858693c6 | bellard | vm_stop(EXCP_INTERRUPT); |
2208 | 5fafdf24 | ths | } else
|
2209 | 1fddef4b | bellard | #endif
|
2210 | 41625033 | bellard | { |
2211 | 858693c6 | bellard | switch(s->state) {
|
2212 | 858693c6 | bellard | case RS_IDLE:
|
2213 | 858693c6 | bellard | if (ch == '$') { |
2214 | 858693c6 | bellard | s->line_buf_index = 0;
|
2215 | 858693c6 | bellard | s->state = RS_GETLINE; |
2216 | c33a346e | bellard | } |
2217 | b4608c04 | bellard | break;
|
2218 | 858693c6 | bellard | case RS_GETLINE:
|
2219 | 858693c6 | bellard | if (ch == '#') { |
2220 | 858693c6 | bellard | s->state = RS_CHKSUM1; |
2221 | 858693c6 | bellard | } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { |
2222 | 858693c6 | bellard | s->state = RS_IDLE; |
2223 | 4c3a88a2 | bellard | } else {
|
2224 | 858693c6 | bellard | s->line_buf[s->line_buf_index++] = ch; |
2225 | 4c3a88a2 | bellard | } |
2226 | 4c3a88a2 | bellard | break;
|
2227 | 858693c6 | bellard | case RS_CHKSUM1:
|
2228 | 858693c6 | bellard | s->line_buf[s->line_buf_index] = '\0';
|
2229 | 858693c6 | bellard | s->line_csum = fromhex(ch) << 4;
|
2230 | 858693c6 | bellard | s->state = RS_CHKSUM2; |
2231 | 858693c6 | bellard | break;
|
2232 | 858693c6 | bellard | case RS_CHKSUM2:
|
2233 | 858693c6 | bellard | s->line_csum |= fromhex(ch); |
2234 | 858693c6 | bellard | csum = 0;
|
2235 | 858693c6 | bellard | for(i = 0; i < s->line_buf_index; i++) { |
2236 | 858693c6 | bellard | csum += s->line_buf[i]; |
2237 | 858693c6 | bellard | } |
2238 | 858693c6 | bellard | if (s->line_csum != (csum & 0xff)) { |
2239 | 60fe76f3 | ths | reply = '-';
|
2240 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
2241 | 858693c6 | bellard | s->state = RS_IDLE; |
2242 | 4c3a88a2 | bellard | } else {
|
2243 | 60fe76f3 | ths | reply = '+';
|
2244 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
2245 | 880a7578 | aliguori | s->state = gdb_handle_packet(s, s->line_buf); |
2246 | 4c3a88a2 | bellard | } |
2247 | 4c3a88a2 | bellard | break;
|
2248 | a2d1ebaf | pbrook | default:
|
2249 | a2d1ebaf | pbrook | abort(); |
2250 | 858693c6 | bellard | } |
2251 | 858693c6 | bellard | } |
2252 | 858693c6 | bellard | } |
2253 | 858693c6 | bellard | |
2254 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
2255 | 1fddef4b | bellard | int
|
2256 | ca587a8e | aurel32 | gdb_queuesig (void)
|
2257 | ca587a8e | aurel32 | { |
2258 | ca587a8e | aurel32 | GDBState *s; |
2259 | ca587a8e | aurel32 | |
2260 | ca587a8e | aurel32 | s = gdbserver_state; |
2261 | ca587a8e | aurel32 | |
2262 | ca587a8e | aurel32 | if (gdbserver_fd < 0 || s->fd < 0) |
2263 | ca587a8e | aurel32 | return 0; |
2264 | ca587a8e | aurel32 | else
|
2265 | ca587a8e | aurel32 | return 1; |
2266 | ca587a8e | aurel32 | } |
2267 | ca587a8e | aurel32 | |
2268 | ca587a8e | aurel32 | int
|
2269 | 1fddef4b | bellard | gdb_handlesig (CPUState *env, int sig)
|
2270 | 1fddef4b | bellard | { |
2271 | 1fddef4b | bellard | GDBState *s; |
2272 | 1fddef4b | bellard | char buf[256]; |
2273 | 1fddef4b | bellard | int n;
|
2274 | 1fddef4b | bellard | |
2275 | 880a7578 | aliguori | s = gdbserver_state; |
2276 | 1f487ee9 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
2277 | 1f487ee9 | edgar_igl | return sig;
|
2278 | 1fddef4b | bellard | |
2279 | 1fddef4b | bellard | /* disable single step if it was enabled */
|
2280 | 1fddef4b | bellard | cpu_single_step(env, 0);
|
2281 | 1fddef4b | bellard | tb_flush(env); |
2282 | 1fddef4b | bellard | |
2283 | 1fddef4b | bellard | if (sig != 0) |
2284 | 1fddef4b | bellard | { |
2285 | ca587a8e | aurel32 | snprintf(buf, sizeof(buf), "S%02x", target_signal_to_gdb (sig)); |
2286 | 1fddef4b | bellard | put_packet(s, buf); |
2287 | 1fddef4b | bellard | } |
2288 | 1f487ee9 | edgar_igl | /* put_packet() might have detected that the peer terminated the
|
2289 | 1f487ee9 | edgar_igl | connection. */
|
2290 | 1f487ee9 | edgar_igl | if (s->fd < 0) |
2291 | 1f487ee9 | edgar_igl | return sig;
|
2292 | 1fddef4b | bellard | |
2293 | 1fddef4b | bellard | sig = 0;
|
2294 | 1fddef4b | bellard | s->state = RS_IDLE; |
2295 | 41625033 | bellard | s->running_state = 0;
|
2296 | 41625033 | bellard | while (s->running_state == 0) { |
2297 | 1fddef4b | bellard | n = read (s->fd, buf, 256);
|
2298 | 1fddef4b | bellard | if (n > 0) |
2299 | 1fddef4b | bellard | { |
2300 | 1fddef4b | bellard | int i;
|
2301 | 1fddef4b | bellard | |
2302 | 1fddef4b | bellard | for (i = 0; i < n; i++) |
2303 | 6a00d601 | bellard | gdb_read_byte (s, buf[i]); |
2304 | 1fddef4b | bellard | } |
2305 | 1fddef4b | bellard | else if (n == 0 || errno != EAGAIN) |
2306 | 1fddef4b | bellard | { |
2307 | 1fddef4b | bellard | /* XXX: Connection closed. Should probably wait for annother
|
2308 | 1fddef4b | bellard | connection before continuing. */
|
2309 | 1fddef4b | bellard | return sig;
|
2310 | 1fddef4b | bellard | } |
2311 | 41625033 | bellard | } |
2312 | 1f487ee9 | edgar_igl | sig = s->signal; |
2313 | 1f487ee9 | edgar_igl | s->signal = 0;
|
2314 | 1fddef4b | bellard | return sig;
|
2315 | 1fddef4b | bellard | } |
2316 | e9009676 | bellard | |
2317 | e9009676 | bellard | /* Tell the remote gdb that the process has exited. */
|
2318 | e9009676 | bellard | void gdb_exit(CPUState *env, int code) |
2319 | e9009676 | bellard | { |
2320 | e9009676 | bellard | GDBState *s; |
2321 | e9009676 | bellard | char buf[4]; |
2322 | e9009676 | bellard | |
2323 | 880a7578 | aliguori | s = gdbserver_state; |
2324 | 1f487ee9 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
2325 | 1f487ee9 | edgar_igl | return;
|
2326 | e9009676 | bellard | |
2327 | e9009676 | bellard | snprintf(buf, sizeof(buf), "W%02x", code); |
2328 | e9009676 | bellard | put_packet(s, buf); |
2329 | e9009676 | bellard | } |
2330 | e9009676 | bellard | |
2331 | ca587a8e | aurel32 | /* Tell the remote gdb that the process has exited due to SIG. */
|
2332 | ca587a8e | aurel32 | void gdb_signalled(CPUState *env, int sig) |
2333 | ca587a8e | aurel32 | { |
2334 | ca587a8e | aurel32 | GDBState *s; |
2335 | ca587a8e | aurel32 | char buf[4]; |
2336 | ca587a8e | aurel32 | |
2337 | ca587a8e | aurel32 | s = gdbserver_state; |
2338 | ca587a8e | aurel32 | if (gdbserver_fd < 0 || s->fd < 0) |
2339 | ca587a8e | aurel32 | return;
|
2340 | ca587a8e | aurel32 | |
2341 | ca587a8e | aurel32 | snprintf(buf, sizeof(buf), "X%02x", target_signal_to_gdb (sig)); |
2342 | ca587a8e | aurel32 | put_packet(s, buf); |
2343 | ca587a8e | aurel32 | } |
2344 | 1fddef4b | bellard | |
2345 | 880a7578 | aliguori | static void gdb_accept(void) |
2346 | 858693c6 | bellard | { |
2347 | 858693c6 | bellard | GDBState *s; |
2348 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
2349 | 858693c6 | bellard | socklen_t len; |
2350 | 858693c6 | bellard | int val, fd;
|
2351 | 858693c6 | bellard | |
2352 | 858693c6 | bellard | for(;;) {
|
2353 | 858693c6 | bellard | len = sizeof(sockaddr);
|
2354 | 858693c6 | bellard | fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
|
2355 | 858693c6 | bellard | if (fd < 0 && errno != EINTR) { |
2356 | 858693c6 | bellard | perror("accept");
|
2357 | 858693c6 | bellard | return;
|
2358 | 858693c6 | bellard | } else if (fd >= 0) { |
2359 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
2360 | 40ff6d7e | Kevin Wolf | fcntl(fd, F_SETFD, FD_CLOEXEC); |
2361 | 40ff6d7e | Kevin Wolf | #endif
|
2362 | b4608c04 | bellard | break;
|
2363 | b4608c04 | bellard | } |
2364 | b4608c04 | bellard | } |
2365 | 858693c6 | bellard | |
2366 | 858693c6 | bellard | /* set short latency */
|
2367 | 858693c6 | bellard | val = 1;
|
2368 | 8f447cc7 | bellard | setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); |
2369 | 3b46e624 | ths | |
2370 | 880a7578 | aliguori | s = qemu_mallocz(sizeof(GDBState));
|
2371 | 880a7578 | aliguori | s->c_cpu = first_cpu; |
2372 | 880a7578 | aliguori | s->g_cpu = first_cpu; |
2373 | 858693c6 | bellard | s->fd = fd; |
2374 | 56aebc89 | pbrook | gdb_has_xml = 0;
|
2375 | 858693c6 | bellard | |
2376 | 880a7578 | aliguori | gdbserver_state = s; |
2377 | a2d1ebaf | pbrook | |
2378 | 858693c6 | bellard | fcntl(fd, F_SETFL, O_NONBLOCK); |
2379 | 858693c6 | bellard | } |
2380 | 858693c6 | bellard | |
2381 | 858693c6 | bellard | static int gdbserver_open(int port) |
2382 | 858693c6 | bellard | { |
2383 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
2384 | 858693c6 | bellard | int fd, val, ret;
|
2385 | 858693c6 | bellard | |
2386 | 858693c6 | bellard | fd = socket(PF_INET, SOCK_STREAM, 0);
|
2387 | 858693c6 | bellard | if (fd < 0) { |
2388 | 858693c6 | bellard | perror("socket");
|
2389 | 858693c6 | bellard | return -1; |
2390 | 858693c6 | bellard | } |
2391 | 40ff6d7e | Kevin Wolf | #ifndef _WIN32
|
2392 | 40ff6d7e | Kevin Wolf | fcntl(fd, F_SETFD, FD_CLOEXEC); |
2393 | 40ff6d7e | Kevin Wolf | #endif
|
2394 | 858693c6 | bellard | |
2395 | 858693c6 | bellard | /* allow fast reuse */
|
2396 | 858693c6 | bellard | val = 1;
|
2397 | 8f447cc7 | bellard | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); |
2398 | 858693c6 | bellard | |
2399 | 858693c6 | bellard | sockaddr.sin_family = AF_INET; |
2400 | 858693c6 | bellard | sockaddr.sin_port = htons(port); |
2401 | 858693c6 | bellard | sockaddr.sin_addr.s_addr = 0;
|
2402 | 858693c6 | bellard | ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); |
2403 | 858693c6 | bellard | if (ret < 0) { |
2404 | 858693c6 | bellard | perror("bind");
|
2405 | 858693c6 | bellard | return -1; |
2406 | 858693c6 | bellard | } |
2407 | 858693c6 | bellard | ret = listen(fd, 0);
|
2408 | 858693c6 | bellard | if (ret < 0) { |
2409 | 858693c6 | bellard | perror("listen");
|
2410 | 858693c6 | bellard | return -1; |
2411 | 858693c6 | bellard | } |
2412 | 858693c6 | bellard | return fd;
|
2413 | 858693c6 | bellard | } |
2414 | 858693c6 | bellard | |
2415 | 858693c6 | bellard | int gdbserver_start(int port) |
2416 | 858693c6 | bellard | { |
2417 | 858693c6 | bellard | gdbserver_fd = gdbserver_open(port); |
2418 | 858693c6 | bellard | if (gdbserver_fd < 0) |
2419 | 858693c6 | bellard | return -1; |
2420 | 858693c6 | bellard | /* accept connections */
|
2421 | 880a7578 | aliguori | gdb_accept(); |
2422 | 4046d913 | pbrook | return 0; |
2423 | 4046d913 | pbrook | } |
2424 | 2b1319c8 | aurel32 | |
2425 | 2b1319c8 | aurel32 | /* Disable gdb stub for child processes. */
|
2426 | 2b1319c8 | aurel32 | void gdbserver_fork(CPUState *env)
|
2427 | 2b1319c8 | aurel32 | { |
2428 | 2b1319c8 | aurel32 | GDBState *s = gdbserver_state; |
2429 | 9f6164d6 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
2430 | 2b1319c8 | aurel32 | return;
|
2431 | 2b1319c8 | aurel32 | close(s->fd); |
2432 | 2b1319c8 | aurel32 | s->fd = -1;
|
2433 | 2b1319c8 | aurel32 | cpu_breakpoint_remove_all(env, BP_GDB); |
2434 | 2b1319c8 | aurel32 | cpu_watchpoint_remove_all(env, BP_GDB); |
2435 | 2b1319c8 | aurel32 | } |
2436 | 1fddef4b | bellard | #else
|
2437 | aa1f17c1 | ths | static int gdb_chr_can_receive(void *opaque) |
2438 | 4046d913 | pbrook | { |
2439 | 56aebc89 | pbrook | /* We can handle an arbitrarily large amount of data.
|
2440 | 56aebc89 | pbrook | Pick the maximum packet size, which is as good as anything. */
|
2441 | 56aebc89 | pbrook | return MAX_PACKET_LENGTH;
|
2442 | 4046d913 | pbrook | } |
2443 | 4046d913 | pbrook | |
2444 | aa1f17c1 | ths | static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) |
2445 | 4046d913 | pbrook | { |
2446 | 4046d913 | pbrook | int i;
|
2447 | 4046d913 | pbrook | |
2448 | 4046d913 | pbrook | for (i = 0; i < size; i++) { |
2449 | 880a7578 | aliguori | gdb_read_byte(gdbserver_state, buf[i]); |
2450 | 4046d913 | pbrook | } |
2451 | 4046d913 | pbrook | } |
2452 | 4046d913 | pbrook | |
2453 | 4046d913 | pbrook | static void gdb_chr_event(void *opaque, int event) |
2454 | 4046d913 | pbrook | { |
2455 | 4046d913 | pbrook | switch (event) {
|
2456 | b6b8df56 | Amit Shah | case CHR_EVENT_OPENED:
|
2457 | 4046d913 | pbrook | vm_stop(EXCP_INTERRUPT); |
2458 | 56aebc89 | pbrook | gdb_has_xml = 0;
|
2459 | 4046d913 | pbrook | break;
|
2460 | 4046d913 | pbrook | default:
|
2461 | 4046d913 | pbrook | break;
|
2462 | 4046d913 | pbrook | } |
2463 | 4046d913 | pbrook | } |
2464 | 4046d913 | pbrook | |
2465 | 8a34a0fb | aliguori | static void gdb_monitor_output(GDBState *s, const char *msg, int len) |
2466 | 8a34a0fb | aliguori | { |
2467 | 8a34a0fb | aliguori | char buf[MAX_PACKET_LENGTH];
|
2468 | 8a34a0fb | aliguori | |
2469 | 8a34a0fb | aliguori | buf[0] = 'O'; |
2470 | 8a34a0fb | aliguori | if (len > (MAX_PACKET_LENGTH/2) - 1) |
2471 | 8a34a0fb | aliguori | len = (MAX_PACKET_LENGTH/2) - 1; |
2472 | 8a34a0fb | aliguori | memtohex(buf + 1, (uint8_t *)msg, len);
|
2473 | 8a34a0fb | aliguori | put_packet(s, buf); |
2474 | 8a34a0fb | aliguori | } |
2475 | 8a34a0fb | aliguori | |
2476 | 8a34a0fb | aliguori | static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len) |
2477 | 8a34a0fb | aliguori | { |
2478 | 8a34a0fb | aliguori | const char *p = (const char *)buf; |
2479 | 8a34a0fb | aliguori | int max_sz;
|
2480 | 8a34a0fb | aliguori | |
2481 | 8a34a0fb | aliguori | max_sz = (sizeof(gdbserver_state->last_packet) - 2) / 2; |
2482 | 8a34a0fb | aliguori | for (;;) {
|
2483 | 8a34a0fb | aliguori | if (len <= max_sz) {
|
2484 | 8a34a0fb | aliguori | gdb_monitor_output(gdbserver_state, p, len); |
2485 | 8a34a0fb | aliguori | break;
|
2486 | 8a34a0fb | aliguori | } |
2487 | 8a34a0fb | aliguori | gdb_monitor_output(gdbserver_state, p, max_sz); |
2488 | 8a34a0fb | aliguori | p += max_sz; |
2489 | 8a34a0fb | aliguori | len -= max_sz; |
2490 | 8a34a0fb | aliguori | } |
2491 | 8a34a0fb | aliguori | return len;
|
2492 | 8a34a0fb | aliguori | } |
2493 | 8a34a0fb | aliguori | |
2494 | 59030a8c | aliguori | #ifndef _WIN32
|
2495 | 59030a8c | aliguori | static void gdb_sigterm_handler(int signal) |
2496 | 59030a8c | aliguori | { |
2497 | 59030a8c | aliguori | if (vm_running)
|
2498 | 59030a8c | aliguori | vm_stop(EXCP_INTERRUPT); |
2499 | 59030a8c | aliguori | } |
2500 | 59030a8c | aliguori | #endif
|
2501 | 59030a8c | aliguori | |
2502 | 59030a8c | aliguori | int gdbserver_start(const char *device) |
2503 | 4046d913 | pbrook | { |
2504 | 4046d913 | pbrook | GDBState *s; |
2505 | 59030a8c | aliguori | char gdbstub_device_name[128]; |
2506 | 36556b20 | aliguori | CharDriverState *chr = NULL;
|
2507 | 36556b20 | aliguori | CharDriverState *mon_chr; |
2508 | cfc3475a | pbrook | |
2509 | 59030a8c | aliguori | if (!device)
|
2510 | 59030a8c | aliguori | return -1; |
2511 | 59030a8c | aliguori | if (strcmp(device, "none") != 0) { |
2512 | 59030a8c | aliguori | if (strstart(device, "tcp:", NULL)) { |
2513 | 59030a8c | aliguori | /* enforce required TCP attributes */
|
2514 | 59030a8c | aliguori | snprintf(gdbstub_device_name, sizeof(gdbstub_device_name),
|
2515 | 59030a8c | aliguori | "%s,nowait,nodelay,server", device);
|
2516 | 59030a8c | aliguori | device = gdbstub_device_name; |
2517 | 36556b20 | aliguori | } |
2518 | 59030a8c | aliguori | #ifndef _WIN32
|
2519 | 59030a8c | aliguori | else if (strcmp(device, "stdio") == 0) { |
2520 | 59030a8c | aliguori | struct sigaction act;
|
2521 | 4046d913 | pbrook | |
2522 | 59030a8c | aliguori | memset(&act, 0, sizeof(act)); |
2523 | 59030a8c | aliguori | act.sa_handler = gdb_sigterm_handler; |
2524 | 59030a8c | aliguori | sigaction(SIGINT, &act, NULL);
|
2525 | 59030a8c | aliguori | } |
2526 | 59030a8c | aliguori | #endif
|
2527 | 59030a8c | aliguori | chr = qemu_chr_open("gdb", device, NULL); |
2528 | 36556b20 | aliguori | if (!chr)
|
2529 | 36556b20 | aliguori | return -1; |
2530 | 36556b20 | aliguori | |
2531 | 36556b20 | aliguori | qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, |
2532 | 36556b20 | aliguori | gdb_chr_event, NULL);
|
2533 | cfc3475a | pbrook | } |
2534 | cfc3475a | pbrook | |
2535 | 36556b20 | aliguori | s = gdbserver_state; |
2536 | 36556b20 | aliguori | if (!s) {
|
2537 | 36556b20 | aliguori | s = qemu_mallocz(sizeof(GDBState));
|
2538 | 36556b20 | aliguori | gdbserver_state = s; |
2539 | 4046d913 | pbrook | |
2540 | 36556b20 | aliguori | qemu_add_vm_change_state_handler(gdb_vm_state_change, NULL);
|
2541 | 36556b20 | aliguori | |
2542 | 36556b20 | aliguori | /* Initialize a monitor terminal for gdb */
|
2543 | 36556b20 | aliguori | mon_chr = qemu_mallocz(sizeof(*mon_chr));
|
2544 | 36556b20 | aliguori | mon_chr->chr_write = gdb_monitor_write; |
2545 | 36556b20 | aliguori | monitor_init(mon_chr, 0);
|
2546 | 36556b20 | aliguori | } else {
|
2547 | 36556b20 | aliguori | if (s->chr)
|
2548 | 36556b20 | aliguori | qemu_chr_close(s->chr); |
2549 | 36556b20 | aliguori | mon_chr = s->mon_chr; |
2550 | 36556b20 | aliguori | memset(s, 0, sizeof(GDBState)); |
2551 | 36556b20 | aliguori | } |
2552 | 880a7578 | aliguori | s->c_cpu = first_cpu; |
2553 | 880a7578 | aliguori | s->g_cpu = first_cpu; |
2554 | 4046d913 | pbrook | s->chr = chr; |
2555 | 36556b20 | aliguori | s->state = chr ? RS_IDLE : RS_INACTIVE; |
2556 | 36556b20 | aliguori | s->mon_chr = mon_chr; |
2557 | 8a34a0fb | aliguori | |
2558 | b4608c04 | bellard | return 0; |
2559 | b4608c04 | bellard | } |
2560 | 4046d913 | pbrook | #endif |