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