root / gdbstub.c @ 0fead125
History | View | Annotate | Download (39.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 | b4608c04 | bellard | * License along with this library; if not, write to the Free Software
|
18 | b4608c04 | bellard | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 | b4608c04 | bellard | */
|
20 | 978efd6a | pbrook | #include "config.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 | 87ecb68b | pbrook | #include "qemu-common.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 | 8f447cc7 | bellard | #include "qemu_socket.h" |
39 | 8f447cc7 | bellard | #ifdef _WIN32
|
40 | 8f447cc7 | bellard | /* XXX: these constants may be independent of the host ones even for Unix */
|
41 | 8f447cc7 | bellard | #ifndef SIGTRAP
|
42 | 8f447cc7 | bellard | #define SIGTRAP 5 |
43 | 8f447cc7 | bellard | #endif
|
44 | 8f447cc7 | bellard | #ifndef SIGINT
|
45 | 8f447cc7 | bellard | #define SIGINT 2 |
46 | 8f447cc7 | bellard | #endif
|
47 | 8f447cc7 | bellard | #else
|
48 | b4608c04 | bellard | #include <signal.h> |
49 | 8f447cc7 | bellard | #endif
|
50 | b4608c04 | bellard | |
51 | 4abe615b | bellard | //#define DEBUG_GDB
|
52 | b4608c04 | bellard | |
53 | 858693c6 | bellard | enum RSState {
|
54 | 858693c6 | bellard | RS_IDLE, |
55 | 858693c6 | bellard | RS_GETLINE, |
56 | 858693c6 | bellard | RS_CHKSUM1, |
57 | 858693c6 | bellard | RS_CHKSUM2, |
58 | a2d1ebaf | pbrook | RS_SYSCALL, |
59 | 858693c6 | bellard | }; |
60 | 858693c6 | bellard | typedef struct GDBState { |
61 | 6a00d601 | bellard | CPUState *env; /* current CPU */
|
62 | 41625033 | bellard | enum RSState state; /* parsing state */ |
63 | 858693c6 | bellard | char line_buf[4096]; |
64 | 858693c6 | bellard | int line_buf_index;
|
65 | 858693c6 | bellard | int line_csum;
|
66 | 60fe76f3 | ths | uint8_t last_packet[4100];
|
67 | 4046d913 | pbrook | int last_packet_len;
|
68 | 1f487ee9 | edgar_igl | int signal;
|
69 | 41625033 | bellard | #ifdef CONFIG_USER_ONLY
|
70 | 4046d913 | pbrook | int fd;
|
71 | 41625033 | bellard | int running_state;
|
72 | 4046d913 | pbrook | #else
|
73 | 4046d913 | pbrook | CharDriverState *chr; |
74 | 41625033 | bellard | #endif
|
75 | 858693c6 | bellard | } GDBState; |
76 | b4608c04 | bellard | |
77 | 60897d36 | edgar_igl | /* By default use no IRQs and no timers while single stepping so as to
|
78 | 60897d36 | edgar_igl | * make single stepping like an ICE HW step.
|
79 | 60897d36 | edgar_igl | */
|
80 | 60897d36 | edgar_igl | static int sstep_flags = SSTEP_ENABLE|SSTEP_NOIRQ|SSTEP_NOTIMER; |
81 | 60897d36 | edgar_igl | |
82 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
83 | 4046d913 | pbrook | /* XXX: This is not thread safe. Do we care? */
|
84 | 4046d913 | pbrook | static int gdbserver_fd = -1; |
85 | 4046d913 | pbrook | |
86 | 1fddef4b | bellard | /* XXX: remove this hack. */
|
87 | 1fddef4b | bellard | static GDBState gdbserver_state;
|
88 | 1fddef4b | bellard | |
89 | 858693c6 | bellard | static int get_char(GDBState *s) |
90 | b4608c04 | bellard | { |
91 | b4608c04 | bellard | uint8_t ch; |
92 | b4608c04 | bellard | int ret;
|
93 | b4608c04 | bellard | |
94 | b4608c04 | bellard | for(;;) {
|
95 | 8f447cc7 | bellard | ret = recv(s->fd, &ch, 1, 0); |
96 | b4608c04 | bellard | if (ret < 0) { |
97 | 1f487ee9 | edgar_igl | if (errno == ECONNRESET)
|
98 | 1f487ee9 | edgar_igl | s->fd = -1;
|
99 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
100 | b4608c04 | bellard | return -1; |
101 | b4608c04 | bellard | } else if (ret == 0) { |
102 | 1f487ee9 | edgar_igl | close(s->fd); |
103 | 1f487ee9 | edgar_igl | s->fd = -1;
|
104 | b4608c04 | bellard | return -1; |
105 | b4608c04 | bellard | } else {
|
106 | b4608c04 | bellard | break;
|
107 | b4608c04 | bellard | } |
108 | b4608c04 | bellard | } |
109 | b4608c04 | bellard | return ch;
|
110 | b4608c04 | bellard | } |
111 | 4046d913 | pbrook | #endif
|
112 | b4608c04 | bellard | |
113 | a2d1ebaf | pbrook | /* GDB stub state for use by semihosting syscalls. */
|
114 | a2d1ebaf | pbrook | static GDBState *gdb_syscall_state;
|
115 | a2d1ebaf | pbrook | static gdb_syscall_complete_cb gdb_current_syscall_cb;
|
116 | a2d1ebaf | pbrook | |
117 | a2d1ebaf | pbrook | enum {
|
118 | a2d1ebaf | pbrook | GDB_SYS_UNKNOWN, |
119 | a2d1ebaf | pbrook | GDB_SYS_ENABLED, |
120 | a2d1ebaf | pbrook | GDB_SYS_DISABLED, |
121 | a2d1ebaf | pbrook | } gdb_syscall_mode; |
122 | a2d1ebaf | pbrook | |
123 | a2d1ebaf | pbrook | /* If gdb is connected when the first semihosting syscall occurs then use
|
124 | a2d1ebaf | pbrook | remote gdb syscalls. Otherwise use native file IO. */
|
125 | a2d1ebaf | pbrook | int use_gdb_syscalls(void) |
126 | a2d1ebaf | pbrook | { |
127 | a2d1ebaf | pbrook | if (gdb_syscall_mode == GDB_SYS_UNKNOWN) {
|
128 | a2d1ebaf | pbrook | gdb_syscall_mode = (gdb_syscall_state ? GDB_SYS_ENABLED |
129 | a2d1ebaf | pbrook | : GDB_SYS_DISABLED); |
130 | a2d1ebaf | pbrook | } |
131 | a2d1ebaf | pbrook | return gdb_syscall_mode == GDB_SYS_ENABLED;
|
132 | a2d1ebaf | pbrook | } |
133 | a2d1ebaf | pbrook | |
134 | ba70a624 | edgar_igl | /* Resume execution. */
|
135 | ba70a624 | edgar_igl | static inline void gdb_continue(GDBState *s) |
136 | ba70a624 | edgar_igl | { |
137 | ba70a624 | edgar_igl | #ifdef CONFIG_USER_ONLY
|
138 | ba70a624 | edgar_igl | s->running_state = 1;
|
139 | ba70a624 | edgar_igl | #else
|
140 | ba70a624 | edgar_igl | vm_start(); |
141 | ba70a624 | edgar_igl | #endif
|
142 | ba70a624 | edgar_igl | } |
143 | ba70a624 | edgar_igl | |
144 | 858693c6 | bellard | static void put_buffer(GDBState *s, const uint8_t *buf, int len) |
145 | b4608c04 | bellard | { |
146 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
147 | b4608c04 | bellard | int ret;
|
148 | b4608c04 | bellard | |
149 | b4608c04 | bellard | while (len > 0) { |
150 | 8f447cc7 | bellard | ret = send(s->fd, buf, len, 0);
|
151 | b4608c04 | bellard | if (ret < 0) { |
152 | b4608c04 | bellard | if (errno != EINTR && errno != EAGAIN)
|
153 | b4608c04 | bellard | return;
|
154 | b4608c04 | bellard | } else {
|
155 | b4608c04 | bellard | buf += ret; |
156 | b4608c04 | bellard | len -= ret; |
157 | b4608c04 | bellard | } |
158 | b4608c04 | bellard | } |
159 | 4046d913 | pbrook | #else
|
160 | 4046d913 | pbrook | qemu_chr_write(s->chr, buf, len); |
161 | 4046d913 | pbrook | #endif
|
162 | b4608c04 | bellard | } |
163 | b4608c04 | bellard | |
164 | b4608c04 | bellard | static inline int fromhex(int v) |
165 | b4608c04 | bellard | { |
166 | b4608c04 | bellard | if (v >= '0' && v <= '9') |
167 | b4608c04 | bellard | return v - '0'; |
168 | b4608c04 | bellard | else if (v >= 'A' && v <= 'F') |
169 | b4608c04 | bellard | return v - 'A' + 10; |
170 | b4608c04 | bellard | else if (v >= 'a' && v <= 'f') |
171 | b4608c04 | bellard | return v - 'a' + 10; |
172 | b4608c04 | bellard | else
|
173 | b4608c04 | bellard | return 0; |
174 | b4608c04 | bellard | } |
175 | b4608c04 | bellard | |
176 | b4608c04 | bellard | static inline int tohex(int v) |
177 | b4608c04 | bellard | { |
178 | b4608c04 | bellard | if (v < 10) |
179 | b4608c04 | bellard | return v + '0'; |
180 | b4608c04 | bellard | else
|
181 | b4608c04 | bellard | return v - 10 + 'a'; |
182 | b4608c04 | bellard | } |
183 | b4608c04 | bellard | |
184 | b4608c04 | bellard | static void memtohex(char *buf, const uint8_t *mem, int len) |
185 | b4608c04 | bellard | { |
186 | b4608c04 | bellard | int i, c;
|
187 | b4608c04 | bellard | char *q;
|
188 | b4608c04 | bellard | q = buf; |
189 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
190 | b4608c04 | bellard | c = mem[i]; |
191 | b4608c04 | bellard | *q++ = tohex(c >> 4);
|
192 | b4608c04 | bellard | *q++ = tohex(c & 0xf);
|
193 | b4608c04 | bellard | } |
194 | b4608c04 | bellard | *q = '\0';
|
195 | b4608c04 | bellard | } |
196 | b4608c04 | bellard | |
197 | b4608c04 | bellard | static void hextomem(uint8_t *mem, const char *buf, int len) |
198 | b4608c04 | bellard | { |
199 | b4608c04 | bellard | int i;
|
200 | b4608c04 | bellard | |
201 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
202 | b4608c04 | bellard | mem[i] = (fromhex(buf[0]) << 4) | fromhex(buf[1]); |
203 | b4608c04 | bellard | buf += 2;
|
204 | b4608c04 | bellard | } |
205 | b4608c04 | bellard | } |
206 | b4608c04 | bellard | |
207 | b4608c04 | bellard | /* return -1 if error, 0 if OK */
|
208 | 858693c6 | bellard | static int put_packet(GDBState *s, char *buf) |
209 | b4608c04 | bellard | { |
210 | 4046d913 | pbrook | int len, csum, i;
|
211 | 60fe76f3 | ths | uint8_t *p; |
212 | b4608c04 | bellard | |
213 | b4608c04 | bellard | #ifdef DEBUG_GDB
|
214 | b4608c04 | bellard | printf("reply='%s'\n", buf);
|
215 | b4608c04 | bellard | #endif
|
216 | b4608c04 | bellard | |
217 | b4608c04 | bellard | for(;;) {
|
218 | 4046d913 | pbrook | p = s->last_packet; |
219 | 4046d913 | pbrook | *(p++) = '$';
|
220 | b4608c04 | bellard | len = strlen(buf); |
221 | 4046d913 | pbrook | memcpy(p, buf, len); |
222 | 4046d913 | pbrook | p += len; |
223 | b4608c04 | bellard | csum = 0;
|
224 | b4608c04 | bellard | for(i = 0; i < len; i++) { |
225 | b4608c04 | bellard | csum += buf[i]; |
226 | b4608c04 | bellard | } |
227 | 4046d913 | pbrook | *(p++) = '#';
|
228 | 4046d913 | pbrook | *(p++) = tohex((csum >> 4) & 0xf); |
229 | 4046d913 | pbrook | *(p++) = tohex((csum) & 0xf);
|
230 | b4608c04 | bellard | |
231 | 4046d913 | pbrook | s->last_packet_len = p - s->last_packet; |
232 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
233 | b4608c04 | bellard | |
234 | 4046d913 | pbrook | #ifdef CONFIG_USER_ONLY
|
235 | 4046d913 | pbrook | i = get_char(s); |
236 | 4046d913 | pbrook | if (i < 0) |
237 | b4608c04 | bellard | return -1; |
238 | 4046d913 | pbrook | if (i == '+') |
239 | b4608c04 | bellard | break;
|
240 | 4046d913 | pbrook | #else
|
241 | 4046d913 | pbrook | break;
|
242 | 4046d913 | pbrook | #endif
|
243 | b4608c04 | bellard | } |
244 | b4608c04 | bellard | return 0; |
245 | b4608c04 | bellard | } |
246 | b4608c04 | bellard | |
247 | fde3fd61 | edgar_igl | #if defined(TARGET_I386)
|
248 | 79808573 | bellard | |
249 | 79808573 | bellard | #ifdef TARGET_X86_64
|
250 | 79808573 | bellard | static const uint8_t gdb_x86_64_regs[16] = { |
251 | 79808573 | bellard | R_EAX, R_EBX, R_ECX, R_EDX, R_ESI, R_EDI, R_EBP, R_ESP, |
252 | 79808573 | bellard | 8, 9, 10, 11, 12, 13, 14, 15, |
253 | 79808573 | bellard | }; |
254 | 79808573 | bellard | #endif
|
255 | 79808573 | bellard | |
256 | 6da41eaf | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
257 | 6da41eaf | bellard | { |
258 | 79808573 | bellard | int i, fpus, nb_regs;
|
259 | 79808573 | bellard | uint8_t *p; |
260 | 5ad265ee | balrog | |
261 | 79808573 | bellard | p = mem_buf; |
262 | 5ad265ee | balrog | #ifdef TARGET_X86_64
|
263 | 5ad265ee | balrog | if (env->hflags & HF_CS64_MASK) {
|
264 | 79808573 | bellard | nb_regs = 16;
|
265 | 79808573 | bellard | for(i = 0; i < 16; i++) { |
266 | 79808573 | bellard | *(uint64_t *)p = tswap64(env->regs[gdb_x86_64_regs[i]]); |
267 | 79808573 | bellard | p += 8;
|
268 | 5ad265ee | balrog | } |
269 | 79808573 | bellard | *(uint64_t *)p = tswap64(env->eip); |
270 | 79808573 | bellard | p += 8;
|
271 | 79808573 | bellard | } else
|
272 | 79808573 | bellard | #endif
|
273 | 79808573 | bellard | { |
274 | 79808573 | bellard | nb_regs = 8;
|
275 | 5ad265ee | balrog | for(i = 0; i < 8; i++) { |
276 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->regs[i]); |
277 | 79808573 | bellard | p += 4;
|
278 | 5ad265ee | balrog | } |
279 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->eip); |
280 | 79808573 | bellard | p += 4;
|
281 | 5ad265ee | balrog | } |
282 | 6da41eaf | bellard | |
283 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->eflags); |
284 | 79808573 | bellard | p += 4;
|
285 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_CS].selector); |
286 | 79808573 | bellard | p += 4;
|
287 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_SS].selector); |
288 | 79808573 | bellard | p += 4;
|
289 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_DS].selector); |
290 | 79808573 | bellard | p += 4;
|
291 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_ES].selector); |
292 | 79808573 | bellard | p += 4;
|
293 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_FS].selector); |
294 | 79808573 | bellard | p += 4;
|
295 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->segs[R_GS].selector); |
296 | 79808573 | bellard | p += 4;
|
297 | 6da41eaf | bellard | for(i = 0; i < 8; i++) { |
298 | 79808573 | bellard | /* XXX: convert floats */
|
299 | 79808573 | bellard | #ifdef USE_X86LDOUBLE
|
300 | 79808573 | bellard | memcpy(p, &env->fpregs[i], 10);
|
301 | 79808573 | bellard | #else
|
302 | 79808573 | bellard | memset(p, 0, 10); |
303 | 79808573 | bellard | #endif
|
304 | 79808573 | bellard | p += 10;
|
305 | 6da41eaf | bellard | } |
306 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->fpuc); /* fctrl */
|
307 | 79808573 | bellard | p += 4;
|
308 | 6da41eaf | bellard | fpus = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11; |
309 | 79808573 | bellard | *(uint32_t *)p = tswap32(fpus); /* fstat */
|
310 | 79808573 | bellard | p += 4;
|
311 | 79808573 | bellard | *(uint32_t *)p = 0; /* ftag */ |
312 | 79808573 | bellard | p += 4;
|
313 | 79808573 | bellard | *(uint32_t *)p = 0; /* fiseg */ |
314 | 79808573 | bellard | p += 4;
|
315 | 79808573 | bellard | *(uint32_t *)p = 0; /* fioff */ |
316 | 79808573 | bellard | p += 4;
|
317 | 79808573 | bellard | *(uint32_t *)p = 0; /* foseg */ |
318 | 79808573 | bellard | p += 4;
|
319 | 79808573 | bellard | *(uint32_t *)p = 0; /* fooff */ |
320 | 79808573 | bellard | p += 4;
|
321 | 79808573 | bellard | *(uint32_t *)p = 0; /* fop */ |
322 | 79808573 | bellard | p += 4;
|
323 | 79808573 | bellard | for(i = 0; i < nb_regs; i++) { |
324 | 79808573 | bellard | *(uint64_t *)p = tswap64(env->xmm_regs[i].XMM_Q(0));
|
325 | 79808573 | bellard | p += 8;
|
326 | 79808573 | bellard | *(uint64_t *)p = tswap64(env->xmm_regs[i].XMM_Q(1));
|
327 | 79808573 | bellard | p += 8;
|
328 | 79808573 | bellard | } |
329 | 79808573 | bellard | *(uint32_t *)p = tswap32(env->mxcsr); |
330 | 79808573 | bellard | p += 4;
|
331 | 79808573 | bellard | return p - mem_buf;
|
332 | 79808573 | bellard | } |
333 | 79808573 | bellard | |
334 | 79808573 | bellard | static inline void cpu_gdb_load_seg(CPUState *env, const uint8_t **pp, |
335 | 79808573 | bellard | int sreg)
|
336 | 79808573 | bellard | { |
337 | 79808573 | bellard | const uint8_t *p;
|
338 | 79808573 | bellard | uint32_t sel; |
339 | 79808573 | bellard | p = *pp; |
340 | 79808573 | bellard | sel = tswap32(*(uint32_t *)p); |
341 | 79808573 | bellard | p += 4;
|
342 | 79808573 | bellard | if (sel != env->segs[sreg].selector) {
|
343 | 79808573 | bellard | #if defined(CONFIG_USER_ONLY)
|
344 | 79808573 | bellard | cpu_x86_load_seg(env, sreg, sel); |
345 | 79808573 | bellard | #else
|
346 | 79808573 | bellard | /* XXX: do it with a debug function which does not raise an
|
347 | 79808573 | bellard | exception */
|
348 | 79808573 | bellard | #endif
|
349 | 79808573 | bellard | } |
350 | 79808573 | bellard | *pp = p; |
351 | 6da41eaf | bellard | } |
352 | 6da41eaf | bellard | |
353 | 6da41eaf | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
354 | 6da41eaf | bellard | { |
355 | 79808573 | bellard | const uint8_t *p = mem_buf;
|
356 | 79808573 | bellard | int i, nb_regs;
|
357 | 79808573 | bellard | uint16_t fpus; |
358 | 6da41eaf | bellard | |
359 | 79808573 | bellard | #ifdef TARGET_X86_64
|
360 | 79808573 | bellard | if (env->hflags & HF_CS64_MASK) {
|
361 | 79808573 | bellard | nb_regs = 16;
|
362 | 79808573 | bellard | for(i = 0; i < 16; i++) { |
363 | 79808573 | bellard | env->regs[gdb_x86_64_regs[i]] = tswap64(*(uint64_t *)p); |
364 | 79808573 | bellard | p += 8;
|
365 | 79808573 | bellard | } |
366 | 79808573 | bellard | env->eip = tswap64(*(uint64_t *)p); |
367 | 79808573 | bellard | p += 8;
|
368 | 79808573 | bellard | } else
|
369 | 79808573 | bellard | #endif
|
370 | 79808573 | bellard | { |
371 | 79808573 | bellard | nb_regs = 8;
|
372 | 79808573 | bellard | for(i = 0; i < 8; i++) { |
373 | 79808573 | bellard | env->regs[i] = tswap32(*(uint32_t *)p); |
374 | 79808573 | bellard | p += 4;
|
375 | 79808573 | bellard | } |
376 | 79808573 | bellard | env->eip = tswap32(*(uint32_t *)p); |
377 | 79808573 | bellard | p += 4;
|
378 | 6da41eaf | bellard | } |
379 | 79808573 | bellard | env->eflags = tswap32(*(uint32_t *)p); |
380 | 79808573 | bellard | p += 4;
|
381 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_CS); |
382 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_SS); |
383 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_DS); |
384 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_ES); |
385 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_FS); |
386 | 79808573 | bellard | cpu_gdb_load_seg(env, &p, R_GS); |
387 | 79808573 | bellard | |
388 | 79808573 | bellard | /* FPU state */
|
389 | 79808573 | bellard | for(i = 0; i < 8; i++) { |
390 | 79808573 | bellard | /* XXX: convert floats */
|
391 | 79808573 | bellard | #ifdef USE_X86LDOUBLE
|
392 | 79808573 | bellard | memcpy(&env->fpregs[i], p, 10);
|
393 | 6da41eaf | bellard | #endif
|
394 | 79808573 | bellard | p += 10;
|
395 | 79808573 | bellard | } |
396 | 79808573 | bellard | env->fpuc = tswap32(*(uint32_t *)p); /* fctrl */
|
397 | 79808573 | bellard | p += 4;
|
398 | 79808573 | bellard | fpus = tswap32(*(uint32_t *)p); |
399 | 79808573 | bellard | p += 4;
|
400 | 79808573 | bellard | env->fpstt = (fpus >> 11) & 7; |
401 | 79808573 | bellard | env->fpus = fpus & ~0x3800;
|
402 | 79808573 | bellard | p += 4 * 6; |
403 | 79808573 | bellard | |
404 | 79808573 | bellard | if (size >= ((p - mem_buf) + 16 * nb_regs + 4)) { |
405 | 79808573 | bellard | /* SSE state */
|
406 | 79808573 | bellard | for(i = 0; i < nb_regs; i++) { |
407 | 79808573 | bellard | env->xmm_regs[i].XMM_Q(0) = tswap64(*(uint64_t *)p);
|
408 | 79808573 | bellard | p += 8;
|
409 | 79808573 | bellard | env->xmm_regs[i].XMM_Q(1) = tswap64(*(uint64_t *)p);
|
410 | 79808573 | bellard | p += 8;
|
411 | 79808573 | bellard | } |
412 | 79808573 | bellard | env->mxcsr = tswap32(*(uint32_t *)p); |
413 | 79808573 | bellard | p += 4;
|
414 | 79808573 | bellard | } |
415 | 6da41eaf | bellard | } |
416 | 6da41eaf | bellard | |
417 | 9e62fd7f | bellard | #elif defined (TARGET_PPC)
|
418 | 9e62fd7f | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
419 | 9e62fd7f | bellard | { |
420 | a541f297 | bellard | uint32_t *registers = (uint32_t *)mem_buf, tmp; |
421 | 9e62fd7f | bellard | int i;
|
422 | 9e62fd7f | bellard | |
423 | 9e62fd7f | bellard | /* fill in gprs */
|
424 | a541f297 | bellard | for(i = 0; i < 32; i++) { |
425 | e95c8d51 | bellard | registers[i] = tswapl(env->gpr[i]); |
426 | 9e62fd7f | bellard | } |
427 | 9e62fd7f | bellard | /* fill in fprs */
|
428 | 9e62fd7f | bellard | for (i = 0; i < 32; i++) { |
429 | e95c8d51 | bellard | registers[(i * 2) + 32] = tswapl(*((uint32_t *)&env->fpr[i])); |
430 | e95c8d51 | bellard | registers[(i * 2) + 33] = tswapl(*((uint32_t *)&env->fpr[i] + 1)); |
431 | 9e62fd7f | bellard | } |
432 | 9e62fd7f | bellard | /* nip, msr, ccr, lnk, ctr, xer, mq */
|
433 | e95c8d51 | bellard | registers[96] = tswapl(env->nip);
|
434 | 0411a972 | j_mayer | registers[97] = tswapl(env->msr);
|
435 | 9e62fd7f | bellard | tmp = 0;
|
436 | 9e62fd7f | bellard | for (i = 0; i < 8; i++) |
437 | a541f297 | bellard | tmp |= env->crf[i] << (32 - ((i + 1) * 4)); |
438 | e95c8d51 | bellard | registers[98] = tswapl(tmp);
|
439 | e95c8d51 | bellard | registers[99] = tswapl(env->lr);
|
440 | e95c8d51 | bellard | registers[100] = tswapl(env->ctr);
|
441 | 76a66253 | j_mayer | registers[101] = tswapl(ppc_load_xer(env));
|
442 | e95c8d51 | bellard | registers[102] = 0; |
443 | a541f297 | bellard | |
444 | a541f297 | bellard | return 103 * 4; |
445 | 9e62fd7f | bellard | } |
446 | 9e62fd7f | bellard | |
447 | 9e62fd7f | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
448 | 9e62fd7f | bellard | { |
449 | 9e62fd7f | bellard | uint32_t *registers = (uint32_t *)mem_buf; |
450 | 9e62fd7f | bellard | int i;
|
451 | 9e62fd7f | bellard | |
452 | 9e62fd7f | bellard | /* fill in gprs */
|
453 | 9e62fd7f | bellard | for (i = 0; i < 32; i++) { |
454 | e95c8d51 | bellard | env->gpr[i] = tswapl(registers[i]); |
455 | 9e62fd7f | bellard | } |
456 | 9e62fd7f | bellard | /* fill in fprs */
|
457 | 9e62fd7f | bellard | for (i = 0; i < 32; i++) { |
458 | e95c8d51 | bellard | *((uint32_t *)&env->fpr[i]) = tswapl(registers[(i * 2) + 32]); |
459 | e95c8d51 | bellard | *((uint32_t *)&env->fpr[i] + 1) = tswapl(registers[(i * 2) + 33]); |
460 | 9e62fd7f | bellard | } |
461 | 9e62fd7f | bellard | /* nip, msr, ccr, lnk, ctr, xer, mq */
|
462 | e95c8d51 | bellard | env->nip = tswapl(registers[96]);
|
463 | 0411a972 | j_mayer | ppc_store_msr(env, tswapl(registers[97]));
|
464 | e95c8d51 | bellard | registers[98] = tswapl(registers[98]); |
465 | 9e62fd7f | bellard | for (i = 0; i < 8; i++) |
466 | a541f297 | bellard | env->crf[i] = (registers[98] >> (32 - ((i + 1) * 4))) & 0xF; |
467 | e95c8d51 | bellard | env->lr = tswapl(registers[99]);
|
468 | e95c8d51 | bellard | env->ctr = tswapl(registers[100]);
|
469 | 76a66253 | j_mayer | ppc_store_xer(env, tswapl(registers[101]));
|
470 | e95c8d51 | bellard | } |
471 | e95c8d51 | bellard | #elif defined (TARGET_SPARC)
|
472 | e95c8d51 | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
473 | e95c8d51 | bellard | { |
474 | 3475187d | bellard | target_ulong *registers = (target_ulong *)mem_buf; |
475 | e95c8d51 | bellard | int i;
|
476 | e95c8d51 | bellard | |
477 | e95c8d51 | bellard | /* fill in g0..g7 */
|
478 | 48b2c193 | bellard | for(i = 0; i < 8; i++) { |
479 | e95c8d51 | bellard | registers[i] = tswapl(env->gregs[i]); |
480 | e95c8d51 | bellard | } |
481 | e95c8d51 | bellard | /* fill in register window */
|
482 | e95c8d51 | bellard | for(i = 0; i < 24; i++) { |
483 | e95c8d51 | bellard | registers[i + 8] = tswapl(env->regwptr[i]);
|
484 | e95c8d51 | bellard | } |
485 | 9d9754a3 | bellard | #ifndef TARGET_SPARC64
|
486 | e95c8d51 | bellard | /* fill in fprs */
|
487 | e95c8d51 | bellard | for (i = 0; i < 32; i++) { |
488 | e95c8d51 | bellard | registers[i + 32] = tswapl(*((uint32_t *)&env->fpr[i]));
|
489 | e95c8d51 | bellard | } |
490 | e95c8d51 | bellard | /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
491 | e95c8d51 | bellard | registers[64] = tswapl(env->y);
|
492 | 3475187d | bellard | { |
493 | 3475187d | bellard | target_ulong tmp; |
494 | 3475187d | bellard | |
495 | 3475187d | bellard | tmp = GET_PSR(env); |
496 | 3475187d | bellard | registers[65] = tswapl(tmp);
|
497 | 3475187d | bellard | } |
498 | e95c8d51 | bellard | registers[66] = tswapl(env->wim);
|
499 | e95c8d51 | bellard | registers[67] = tswapl(env->tbr);
|
500 | e95c8d51 | bellard | registers[68] = tswapl(env->pc);
|
501 | e95c8d51 | bellard | registers[69] = tswapl(env->npc);
|
502 | e95c8d51 | bellard | registers[70] = tswapl(env->fsr);
|
503 | e95c8d51 | bellard | registers[71] = 0; /* csr */ |
504 | e95c8d51 | bellard | registers[72] = 0; |
505 | 3475187d | bellard | return 73 * sizeof(target_ulong); |
506 | 3475187d | bellard | #else
|
507 | 9d9754a3 | bellard | /* fill in fprs */
|
508 | 9d9754a3 | bellard | for (i = 0; i < 64; i += 2) { |
509 | 9d9754a3 | bellard | uint64_t tmp; |
510 | 9d9754a3 | bellard | |
511 | 8979596d | blueswir1 | tmp = ((uint64_t)*(uint32_t *)&env->fpr[i]) << 32;
|
512 | 8979596d | blueswir1 | tmp |= *(uint32_t *)&env->fpr[i + 1];
|
513 | 8979596d | blueswir1 | registers[i / 2 + 32] = tswap64(tmp); |
514 | 3475187d | bellard | } |
515 | 9d9754a3 | bellard | registers[64] = tswapl(env->pc);
|
516 | 9d9754a3 | bellard | registers[65] = tswapl(env->npc);
|
517 | 17d996e1 | blueswir1 | registers[66] = tswapl(((uint64_t)GET_CCR(env) << 32) | |
518 | 17d996e1 | blueswir1 | ((env->asi & 0xff) << 24) | |
519 | 17d996e1 | blueswir1 | ((env->pstate & 0xfff) << 8) | |
520 | 17d996e1 | blueswir1 | GET_CWP64(env)); |
521 | 9d9754a3 | bellard | registers[67] = tswapl(env->fsr);
|
522 | 9d9754a3 | bellard | registers[68] = tswapl(env->fprs);
|
523 | 9d9754a3 | bellard | registers[69] = tswapl(env->y);
|
524 | 9d9754a3 | bellard | return 70 * sizeof(target_ulong); |
525 | 3475187d | bellard | #endif
|
526 | e95c8d51 | bellard | } |
527 | e95c8d51 | bellard | |
528 | e95c8d51 | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
529 | e95c8d51 | bellard | { |
530 | 3475187d | bellard | target_ulong *registers = (target_ulong *)mem_buf; |
531 | e95c8d51 | bellard | int i;
|
532 | e95c8d51 | bellard | |
533 | e95c8d51 | bellard | /* fill in g0..g7 */
|
534 | e95c8d51 | bellard | for(i = 0; i < 7; i++) { |
535 | e95c8d51 | bellard | env->gregs[i] = tswapl(registers[i]); |
536 | e95c8d51 | bellard | } |
537 | e95c8d51 | bellard | /* fill in register window */
|
538 | e95c8d51 | bellard | for(i = 0; i < 24; i++) { |
539 | 3475187d | bellard | env->regwptr[i] = tswapl(registers[i + 8]);
|
540 | e95c8d51 | bellard | } |
541 | 9d9754a3 | bellard | #ifndef TARGET_SPARC64
|
542 | e95c8d51 | bellard | /* fill in fprs */
|
543 | e95c8d51 | bellard | for (i = 0; i < 32; i++) { |
544 | e95c8d51 | bellard | *((uint32_t *)&env->fpr[i]) = tswapl(registers[i + 32]);
|
545 | e95c8d51 | bellard | } |
546 | e95c8d51 | bellard | /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
|
547 | e95c8d51 | bellard | env->y = tswapl(registers[64]);
|
548 | e80cfcfc | bellard | PUT_PSR(env, tswapl(registers[65]));
|
549 | e95c8d51 | bellard | env->wim = tswapl(registers[66]);
|
550 | e95c8d51 | bellard | env->tbr = tswapl(registers[67]);
|
551 | e95c8d51 | bellard | env->pc = tswapl(registers[68]);
|
552 | e95c8d51 | bellard | env->npc = tswapl(registers[69]);
|
553 | e95c8d51 | bellard | env->fsr = tswapl(registers[70]);
|
554 | 3475187d | bellard | #else
|
555 | 9d9754a3 | bellard | for (i = 0; i < 64; i += 2) { |
556 | 8979596d | blueswir1 | uint64_t tmp; |
557 | 8979596d | blueswir1 | |
558 | 8979596d | blueswir1 | tmp = tswap64(registers[i / 2 + 32]); |
559 | 8979596d | blueswir1 | *((uint32_t *)&env->fpr[i]) = tmp >> 32;
|
560 | 8979596d | blueswir1 | *((uint32_t *)&env->fpr[i + 1]) = tmp & 0xffffffff; |
561 | 3475187d | bellard | } |
562 | 9d9754a3 | bellard | env->pc = tswapl(registers[64]);
|
563 | 9d9754a3 | bellard | env->npc = tswapl(registers[65]);
|
564 | 17d996e1 | blueswir1 | { |
565 | 17d996e1 | blueswir1 | uint64_t tmp = tswapl(registers[66]);
|
566 | 17d996e1 | blueswir1 | |
567 | 17d996e1 | blueswir1 | PUT_CCR(env, tmp >> 32);
|
568 | 17d996e1 | blueswir1 | env->asi = (tmp >> 24) & 0xff; |
569 | 17d996e1 | blueswir1 | env->pstate = (tmp >> 8) & 0xfff; |
570 | 17d996e1 | blueswir1 | PUT_CWP64(env, tmp & 0xff);
|
571 | 17d996e1 | blueswir1 | } |
572 | 9d9754a3 | bellard | env->fsr = tswapl(registers[67]);
|
573 | 9d9754a3 | bellard | env->fprs = tswapl(registers[68]);
|
574 | 9d9754a3 | bellard | env->y = tswapl(registers[69]);
|
575 | 3475187d | bellard | #endif
|
576 | 9e62fd7f | bellard | } |
577 | 1fddef4b | bellard | #elif defined (TARGET_ARM)
|
578 | 1fddef4b | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
579 | 1fddef4b | bellard | { |
580 | 1fddef4b | bellard | int i;
|
581 | 1fddef4b | bellard | uint8_t *ptr; |
582 | 1fddef4b | bellard | |
583 | 1fddef4b | bellard | ptr = mem_buf; |
584 | 1fddef4b | bellard | /* 16 core integer registers (4 bytes each). */
|
585 | 1fddef4b | bellard | for (i = 0; i < 16; i++) |
586 | 1fddef4b | bellard | { |
587 | 1fddef4b | bellard | *(uint32_t *)ptr = tswapl(env->regs[i]); |
588 | 1fddef4b | bellard | ptr += 4;
|
589 | 1fddef4b | bellard | } |
590 | 1fddef4b | bellard | /* 8 FPA registers (12 bytes each), FPS (4 bytes).
|
591 | 1fddef4b | bellard | Not yet implemented. */
|
592 | 1fddef4b | bellard | memset (ptr, 0, 8 * 12 + 4); |
593 | 1fddef4b | bellard | ptr += 8 * 12 + 4; |
594 | 1fddef4b | bellard | /* CPSR (4 bytes). */
|
595 | b5ff1b31 | bellard | *(uint32_t *)ptr = tswapl (cpsr_read(env)); |
596 | 1fddef4b | bellard | ptr += 4;
|
597 | 1fddef4b | bellard | |
598 | 1fddef4b | bellard | return ptr - mem_buf;
|
599 | 1fddef4b | bellard | } |
600 | 6da41eaf | bellard | |
601 | 1fddef4b | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
602 | 1fddef4b | bellard | { |
603 | 1fddef4b | bellard | int i;
|
604 | 1fddef4b | bellard | uint8_t *ptr; |
605 | 1fddef4b | bellard | |
606 | 1fddef4b | bellard | ptr = mem_buf; |
607 | 1fddef4b | bellard | /* Core integer registers. */
|
608 | 1fddef4b | bellard | for (i = 0; i < 16; i++) |
609 | 1fddef4b | bellard | { |
610 | 1fddef4b | bellard | env->regs[i] = tswapl(*(uint32_t *)ptr); |
611 | 1fddef4b | bellard | ptr += 4;
|
612 | 1fddef4b | bellard | } |
613 | 1fddef4b | bellard | /* Ignore FPA regs and scr. */
|
614 | 1fddef4b | bellard | ptr += 8 * 12 + 4; |
615 | b5ff1b31 | bellard | cpsr_write (env, tswapl(*(uint32_t *)ptr), 0xffffffff);
|
616 | 1fddef4b | bellard | } |
617 | e6e5906b | pbrook | #elif defined (TARGET_M68K)
|
618 | e6e5906b | pbrook | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
619 | e6e5906b | pbrook | { |
620 | e6e5906b | pbrook | int i;
|
621 | e6e5906b | pbrook | uint8_t *ptr; |
622 | e6e5906b | pbrook | CPU_DoubleU u; |
623 | e6e5906b | pbrook | |
624 | e6e5906b | pbrook | ptr = mem_buf; |
625 | e6e5906b | pbrook | /* D0-D7 */
|
626 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
627 | e6e5906b | pbrook | *(uint32_t *)ptr = tswapl(env->dregs[i]); |
628 | e6e5906b | pbrook | ptr += 4;
|
629 | e6e5906b | pbrook | } |
630 | e6e5906b | pbrook | /* A0-A7 */
|
631 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
632 | e6e5906b | pbrook | *(uint32_t *)ptr = tswapl(env->aregs[i]); |
633 | e6e5906b | pbrook | ptr += 4;
|
634 | e6e5906b | pbrook | } |
635 | e6e5906b | pbrook | *(uint32_t *)ptr = tswapl(env->sr); |
636 | e6e5906b | pbrook | ptr += 4;
|
637 | e6e5906b | pbrook | *(uint32_t *)ptr = tswapl(env->pc); |
638 | e6e5906b | pbrook | ptr += 4;
|
639 | e6e5906b | pbrook | /* F0-F7. The 68881/68040 have 12-bit extended precision registers.
|
640 | e6e5906b | pbrook | ColdFire has 8-bit double precision registers. */
|
641 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
642 | e6e5906b | pbrook | u.d = env->fregs[i]; |
643 | e6e5906b | pbrook | *(uint32_t *)ptr = tswap32(u.l.upper); |
644 | e6e5906b | pbrook | *(uint32_t *)ptr = tswap32(u.l.lower); |
645 | e6e5906b | pbrook | } |
646 | e6e5906b | pbrook | /* FP control regs (not implemented). */
|
647 | e6e5906b | pbrook | memset (ptr, 0, 3 * 4); |
648 | e6e5906b | pbrook | ptr += 3 * 4; |
649 | e6e5906b | pbrook | |
650 | e6e5906b | pbrook | return ptr - mem_buf;
|
651 | e6e5906b | pbrook | } |
652 | e6e5906b | pbrook | |
653 | e6e5906b | pbrook | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
654 | e6e5906b | pbrook | { |
655 | e6e5906b | pbrook | int i;
|
656 | e6e5906b | pbrook | uint8_t *ptr; |
657 | e6e5906b | pbrook | CPU_DoubleU u; |
658 | e6e5906b | pbrook | |
659 | e6e5906b | pbrook | ptr = mem_buf; |
660 | e6e5906b | pbrook | /* D0-D7 */
|
661 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
662 | e6e5906b | pbrook | env->dregs[i] = tswapl(*(uint32_t *)ptr); |
663 | e6e5906b | pbrook | ptr += 4;
|
664 | e6e5906b | pbrook | } |
665 | e6e5906b | pbrook | /* A0-A7 */
|
666 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
667 | e6e5906b | pbrook | env->aregs[i] = tswapl(*(uint32_t *)ptr); |
668 | e6e5906b | pbrook | ptr += 4;
|
669 | e6e5906b | pbrook | } |
670 | e6e5906b | pbrook | env->sr = tswapl(*(uint32_t *)ptr); |
671 | e6e5906b | pbrook | ptr += 4;
|
672 | e6e5906b | pbrook | env->pc = tswapl(*(uint32_t *)ptr); |
673 | e6e5906b | pbrook | ptr += 4;
|
674 | e6e5906b | pbrook | /* F0-F7. The 68881/68040 have 12-bit extended precision registers.
|
675 | e6e5906b | pbrook | ColdFire has 8-bit double precision registers. */
|
676 | e6e5906b | pbrook | for (i = 0; i < 8; i++) { |
677 | 5fafdf24 | ths | u.l.upper = tswap32(*(uint32_t *)ptr); |
678 | e6e5906b | pbrook | u.l.lower = tswap32(*(uint32_t *)ptr); |
679 | e6e5906b | pbrook | env->fregs[i] = u.d; |
680 | e6e5906b | pbrook | } |
681 | e6e5906b | pbrook | /* FP control regs (not implemented). */
|
682 | e6e5906b | pbrook | ptr += 3 * 4; |
683 | e6e5906b | pbrook | } |
684 | 6f970bd9 | bellard | #elif defined (TARGET_MIPS)
|
685 | 6f970bd9 | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
686 | 6f970bd9 | bellard | { |
687 | 6f970bd9 | bellard | int i;
|
688 | 6f970bd9 | bellard | uint8_t *ptr; |
689 | 6f970bd9 | bellard | |
690 | 6f970bd9 | bellard | ptr = mem_buf; |
691 | 6f970bd9 | bellard | for (i = 0; i < 32; i++) |
692 | 6f970bd9 | bellard | { |
693 | d0dc7dc3 | ths | *(target_ulong *)ptr = tswapl(env->gpr[env->current_tc][i]); |
694 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
695 | 6f970bd9 | bellard | } |
696 | 6f970bd9 | bellard | |
697 | 7ac256b8 | ths | *(target_ulong *)ptr = (int32_t)tswap32(env->CP0_Status); |
698 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
699 | 6f970bd9 | bellard | |
700 | d0dc7dc3 | ths | *(target_ulong *)ptr = tswapl(env->LO[env->current_tc][0]);
|
701 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
702 | 6f970bd9 | bellard | |
703 | d0dc7dc3 | ths | *(target_ulong *)ptr = tswapl(env->HI[env->current_tc][0]);
|
704 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
705 | 6f970bd9 | bellard | |
706 | 2052caa7 | ths | *(target_ulong *)ptr = tswapl(env->CP0_BadVAddr); |
707 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
708 | 6f970bd9 | bellard | |
709 | 7ac256b8 | ths | *(target_ulong *)ptr = (int32_t)tswap32(env->CP0_Cause); |
710 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
711 | 6f970bd9 | bellard | |
712 | ead9360e | ths | *(target_ulong *)ptr = tswapl(env->PC[env->current_tc]); |
713 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
714 | 6f970bd9 | bellard | |
715 | 36d23958 | ths | if (env->CP0_Config1 & (1 << CP0C1_FP)) |
716 | 8e33c08c | ths | { |
717 | 36d23958 | ths | for (i = 0; i < 32; i++) |
718 | 36d23958 | ths | { |
719 | 7ac256b8 | ths | if (env->CP0_Status & (1 << CP0St_FR)) |
720 | 7ac256b8 | ths | *(target_ulong *)ptr = tswapl(env->fpu->fpr[i].d); |
721 | 7ac256b8 | ths | else
|
722 | 7ac256b8 | ths | *(target_ulong *)ptr = tswap32(env->fpu->fpr[i].w[FP_ENDIAN_IDX]); |
723 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
724 | 36d23958 | ths | } |
725 | 8e33c08c | ths | |
726 | 7ac256b8 | ths | *(target_ulong *)ptr = (int32_t)tswap32(env->fpu->fcr31); |
727 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
728 | 8e33c08c | ths | |
729 | 7ac256b8 | ths | *(target_ulong *)ptr = (int32_t)tswap32(env->fpu->fcr0); |
730 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
731 | 36d23958 | ths | } |
732 | 8e33c08c | ths | |
733 | 7ac256b8 | ths | /* "fp", pseudo frame pointer. Not yet implemented in gdb. */
|
734 | 7ac256b8 | ths | *(target_ulong *)ptr = 0;
|
735 | 7ac256b8 | ths | ptr += sizeof(target_ulong);
|
736 | 7ac256b8 | ths | |
737 | 7ac256b8 | ths | /* Registers for embedded use, we just pad them. */
|
738 | 7ac256b8 | ths | for (i = 0; i < 16; i++) |
739 | 7ac256b8 | ths | { |
740 | 7ac256b8 | ths | *(target_ulong *)ptr = 0;
|
741 | 7ac256b8 | ths | ptr += sizeof(target_ulong);
|
742 | 7ac256b8 | ths | } |
743 | 7ac256b8 | ths | |
744 | 7ac256b8 | ths | /* Processor ID. */
|
745 | 7ac256b8 | ths | *(target_ulong *)ptr = (int32_t)tswap32(env->CP0_PRid); |
746 | 7ac256b8 | ths | ptr += sizeof(target_ulong);
|
747 | 6f970bd9 | bellard | |
748 | 6f970bd9 | bellard | return ptr - mem_buf;
|
749 | 6f970bd9 | bellard | } |
750 | 6f970bd9 | bellard | |
751 | 8e33c08c | ths | /* convert MIPS rounding mode in FCR31 to IEEE library */
|
752 | 8e33c08c | ths | static unsigned int ieee_rm[] = |
753 | 8e33c08c | ths | { |
754 | 8e33c08c | ths | float_round_nearest_even, |
755 | 8e33c08c | ths | float_round_to_zero, |
756 | 8e33c08c | ths | float_round_up, |
757 | 8e33c08c | ths | float_round_down |
758 | 8e33c08c | ths | }; |
759 | 8e33c08c | ths | #define RESTORE_ROUNDING_MODE \
|
760 | ead9360e | ths | set_float_rounding_mode(ieee_rm[env->fpu->fcr31 & 3], &env->fpu->fp_status)
|
761 | 8e33c08c | ths | |
762 | 6f970bd9 | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
763 | 6f970bd9 | bellard | { |
764 | 6f970bd9 | bellard | int i;
|
765 | 6f970bd9 | bellard | uint8_t *ptr; |
766 | 6f970bd9 | bellard | |
767 | 6f970bd9 | bellard | ptr = mem_buf; |
768 | 6f970bd9 | bellard | for (i = 0; i < 32; i++) |
769 | 6f970bd9 | bellard | { |
770 | d0dc7dc3 | ths | env->gpr[env->current_tc][i] = tswapl(*(target_ulong *)ptr); |
771 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
772 | 6f970bd9 | bellard | } |
773 | 6f970bd9 | bellard | |
774 | 2052caa7 | ths | env->CP0_Status = tswapl(*(target_ulong *)ptr); |
775 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
776 | 6f970bd9 | bellard | |
777 | d0dc7dc3 | ths | env->LO[env->current_tc][0] = tswapl(*(target_ulong *)ptr);
|
778 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
779 | 6f970bd9 | bellard | |
780 | d0dc7dc3 | ths | env->HI[env->current_tc][0] = tswapl(*(target_ulong *)ptr);
|
781 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
782 | 6f970bd9 | bellard | |
783 | 2052caa7 | ths | env->CP0_BadVAddr = tswapl(*(target_ulong *)ptr); |
784 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
785 | 6f970bd9 | bellard | |
786 | 2052caa7 | ths | env->CP0_Cause = tswapl(*(target_ulong *)ptr); |
787 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
788 | 6f970bd9 | bellard | |
789 | ead9360e | ths | env->PC[env->current_tc] = tswapl(*(target_ulong *)ptr); |
790 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
791 | 8e33c08c | ths | |
792 | 36d23958 | ths | if (env->CP0_Config1 & (1 << CP0C1_FP)) |
793 | 8e33c08c | ths | { |
794 | 36d23958 | ths | for (i = 0; i < 32; i++) |
795 | 36d23958 | ths | { |
796 | 7ac256b8 | ths | if (env->CP0_Status & (1 << CP0St_FR)) |
797 | 7ac256b8 | ths | env->fpu->fpr[i].d = tswapl(*(target_ulong *)ptr); |
798 | 7ac256b8 | ths | else
|
799 | 7ac256b8 | ths | env->fpu->fpr[i].w[FP_ENDIAN_IDX] = tswapl(*(target_ulong *)ptr); |
800 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
801 | 36d23958 | ths | } |
802 | 8e33c08c | ths | |
803 | 7ac256b8 | ths | env->fpu->fcr31 = tswapl(*(target_ulong *)ptr) & 0xFF83FFFF;
|
804 | 2052caa7 | ths | ptr += sizeof(target_ulong);
|
805 | 8e33c08c | ths | |
806 | 7ac256b8 | ths | /* The remaining registers are assumed to be read-only. */
|
807 | 8e33c08c | ths | |
808 | 36d23958 | ths | /* set rounding mode */
|
809 | 36d23958 | ths | RESTORE_ROUNDING_MODE; |
810 | 8e33c08c | ths | |
811 | 8e33c08c | ths | #ifndef CONFIG_SOFTFLOAT
|
812 | 36d23958 | ths | /* no floating point exception for native float */
|
813 | 36d23958 | ths | SET_FP_ENABLE(env->fcr31, 0);
|
814 | 8e33c08c | ths | #endif
|
815 | 36d23958 | ths | } |
816 | 6f970bd9 | bellard | } |
817 | fdf9b3e8 | bellard | #elif defined (TARGET_SH4)
|
818 | 6ef99fc5 | ths | |
819 | 6ef99fc5 | ths | /* Hint: Use "set architecture sh4" in GDB to see fpu registers */
|
820 | 6ef99fc5 | ths | |
821 | fdf9b3e8 | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
822 | fdf9b3e8 | bellard | { |
823 | fdf9b3e8 | bellard | uint32_t *ptr = (uint32_t *)mem_buf; |
824 | fdf9b3e8 | bellard | int i;
|
825 | fdf9b3e8 | bellard | |
826 | fdf9b3e8 | bellard | #define SAVE(x) *ptr++=tswapl(x)
|
827 | 9c2a9ea1 | pbrook | if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
828 | 9c2a9ea1 | pbrook | for (i = 0; i < 8; i++) SAVE(env->gregs[i + 16]); |
829 | 9c2a9ea1 | pbrook | } else {
|
830 | 9c2a9ea1 | pbrook | for (i = 0; i < 8; i++) SAVE(env->gregs[i]); |
831 | 9c2a9ea1 | pbrook | } |
832 | 9c2a9ea1 | pbrook | for (i = 8; i < 16; i++) SAVE(env->gregs[i]); |
833 | fdf9b3e8 | bellard | SAVE (env->pc); |
834 | fdf9b3e8 | bellard | SAVE (env->pr); |
835 | fdf9b3e8 | bellard | SAVE (env->gbr); |
836 | fdf9b3e8 | bellard | SAVE (env->vbr); |
837 | fdf9b3e8 | bellard | SAVE (env->mach); |
838 | fdf9b3e8 | bellard | SAVE (env->macl); |
839 | fdf9b3e8 | bellard | SAVE (env->sr); |
840 | 6ef99fc5 | ths | SAVE (env->fpul); |
841 | 6ef99fc5 | ths | SAVE (env->fpscr); |
842 | 6ef99fc5 | ths | for (i = 0; i < 16; i++) |
843 | 6ef99fc5 | ths | SAVE(env->fregs[i + ((env->fpscr & FPSCR_FR) ? 16 : 0)]); |
844 | 6ef99fc5 | ths | SAVE (env->ssr); |
845 | 6ef99fc5 | ths | SAVE (env->spc); |
846 | 6ef99fc5 | ths | for (i = 0; i < 8; i++) SAVE(env->gregs[i]); |
847 | 6ef99fc5 | ths | for (i = 0; i < 8; i++) SAVE(env->gregs[i + 16]); |
848 | fdf9b3e8 | bellard | return ((uint8_t *)ptr - mem_buf);
|
849 | fdf9b3e8 | bellard | } |
850 | fdf9b3e8 | bellard | |
851 | fdf9b3e8 | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
852 | fdf9b3e8 | bellard | { |
853 | fdf9b3e8 | bellard | uint32_t *ptr = (uint32_t *)mem_buf; |
854 | fdf9b3e8 | bellard | int i;
|
855 | fdf9b3e8 | bellard | |
856 | fdf9b3e8 | bellard | #define LOAD(x) (x)=*ptr++;
|
857 | 9c2a9ea1 | pbrook | if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
|
858 | 9c2a9ea1 | pbrook | for (i = 0; i < 8; i++) LOAD(env->gregs[i + 16]); |
859 | 9c2a9ea1 | pbrook | } else {
|
860 | 9c2a9ea1 | pbrook | for (i = 0; i < 8; i++) LOAD(env->gregs[i]); |
861 | 9c2a9ea1 | pbrook | } |
862 | 9c2a9ea1 | pbrook | for (i = 8; i < 16; i++) LOAD(env->gregs[i]); |
863 | fdf9b3e8 | bellard | LOAD (env->pc); |
864 | fdf9b3e8 | bellard | LOAD (env->pr); |
865 | fdf9b3e8 | bellard | LOAD (env->gbr); |
866 | fdf9b3e8 | bellard | LOAD (env->vbr); |
867 | fdf9b3e8 | bellard | LOAD (env->mach); |
868 | fdf9b3e8 | bellard | LOAD (env->macl); |
869 | fdf9b3e8 | bellard | LOAD (env->sr); |
870 | 6ef99fc5 | ths | LOAD (env->fpul); |
871 | 6ef99fc5 | ths | LOAD (env->fpscr); |
872 | 6ef99fc5 | ths | for (i = 0; i < 16; i++) |
873 | 6ef99fc5 | ths | LOAD(env->fregs[i + ((env->fpscr & FPSCR_FR) ? 16 : 0)]); |
874 | 6ef99fc5 | ths | LOAD (env->ssr); |
875 | 6ef99fc5 | ths | LOAD (env->spc); |
876 | 6ef99fc5 | ths | for (i = 0; i < 8; i++) LOAD(env->gregs[i]); |
877 | 6ef99fc5 | ths | for (i = 0; i < 8; i++) LOAD(env->gregs[i + 16]); |
878 | fdf9b3e8 | bellard | } |
879 | f1ccf904 | ths | #elif defined (TARGET_CRIS)
|
880 | f1ccf904 | ths | |
881 | f1ccf904 | ths | static int cris_save_32 (unsigned char *d, uint32_t value) |
882 | f1ccf904 | ths | { |
883 | f1ccf904 | ths | *d++ = (value); |
884 | f1ccf904 | ths | *d++ = (value >>= 8);
|
885 | f1ccf904 | ths | *d++ = (value >>= 8);
|
886 | f1ccf904 | ths | *d++ = (value >>= 8);
|
887 | f1ccf904 | ths | return 4; |
888 | f1ccf904 | ths | } |
889 | f1ccf904 | ths | static int cris_save_16 (unsigned char *d, uint32_t value) |
890 | f1ccf904 | ths | { |
891 | f1ccf904 | ths | *d++ = (value); |
892 | f1ccf904 | ths | *d++ = (value >>= 8);
|
893 | f1ccf904 | ths | return 2; |
894 | f1ccf904 | ths | } |
895 | f1ccf904 | ths | static int cris_save_8 (unsigned char *d, uint32_t value) |
896 | f1ccf904 | ths | { |
897 | f1ccf904 | ths | *d++ = (value); |
898 | f1ccf904 | ths | return 1; |
899 | f1ccf904 | ths | } |
900 | f1ccf904 | ths | |
901 | f1ccf904 | ths | /* FIXME: this will bug on archs not supporting unaligned word accesses. */
|
902 | f1ccf904 | ths | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
903 | f1ccf904 | ths | { |
904 | f1ccf904 | ths | uint8_t *ptr = mem_buf; |
905 | f1ccf904 | ths | uint8_t srs; |
906 | f1ccf904 | ths | int i;
|
907 | f1ccf904 | ths | |
908 | f1ccf904 | ths | for (i = 0; i < 16; i++) |
909 | f1ccf904 | ths | ptr += cris_save_32 (ptr, env->regs[i]); |
910 | f1ccf904 | ths | |
911 | 9004627f | edgar_igl | srs = env->pregs[PR_SRS]; |
912 | f1ccf904 | ths | |
913 | f1ccf904 | ths | ptr += cris_save_8 (ptr, env->pregs[0]);
|
914 | f1ccf904 | ths | ptr += cris_save_8 (ptr, env->pregs[1]);
|
915 | f1ccf904 | ths | ptr += cris_save_32 (ptr, env->pregs[2]);
|
916 | f1ccf904 | ths | ptr += cris_save_8 (ptr, srs); |
917 | f1ccf904 | ths | ptr += cris_save_16 (ptr, env->pregs[4]);
|
918 | f1ccf904 | ths | |
919 | f1ccf904 | ths | for (i = 5; i < 16; i++) |
920 | f1ccf904 | ths | ptr += cris_save_32 (ptr, env->pregs[i]); |
921 | f1ccf904 | ths | |
922 | f1ccf904 | ths | ptr += cris_save_32 (ptr, env->pc); |
923 | f1ccf904 | ths | |
924 | f1ccf904 | ths | for (i = 0; i < 16; i++) |
925 | f1ccf904 | ths | ptr += cris_save_32 (ptr, env->sregs[srs][i]); |
926 | f1ccf904 | ths | |
927 | f1ccf904 | ths | return ((uint8_t *)ptr - mem_buf);
|
928 | f1ccf904 | ths | } |
929 | f1ccf904 | ths | |
930 | f1ccf904 | ths | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
931 | f1ccf904 | ths | { |
932 | f1ccf904 | ths | uint32_t *ptr = (uint32_t *)mem_buf; |
933 | f1ccf904 | ths | int i;
|
934 | f1ccf904 | ths | |
935 | f1ccf904 | ths | #define LOAD(x) (x)=*ptr++;
|
936 | f1ccf904 | ths | for (i = 0; i < 16; i++) LOAD(env->regs[i]); |
937 | f1ccf904 | ths | LOAD (env->pc); |
938 | f1ccf904 | ths | } |
939 | 1fddef4b | bellard | #else
|
940 | 6da41eaf | bellard | static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf) |
941 | 6da41eaf | bellard | { |
942 | 6da41eaf | bellard | return 0; |
943 | 6da41eaf | bellard | } |
944 | 6da41eaf | bellard | |
945 | 6da41eaf | bellard | static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size) |
946 | 6da41eaf | bellard | { |
947 | 6da41eaf | bellard | } |
948 | 6da41eaf | bellard | |
949 | 6da41eaf | bellard | #endif
|
950 | b4608c04 | bellard | |
951 | 1fddef4b | bellard | static int gdb_handle_packet(GDBState *s, CPUState *env, const char *line_buf) |
952 | b4608c04 | bellard | { |
953 | b4608c04 | bellard | const char *p; |
954 | 858693c6 | bellard | int ch, reg_size, type;
|
955 | b4608c04 | bellard | char buf[4096]; |
956 | f1ccf904 | ths | uint8_t mem_buf[4096];
|
957 | b4608c04 | bellard | uint32_t *registers; |
958 | 9d9754a3 | bellard | target_ulong addr, len; |
959 | 3b46e624 | ths | |
960 | 858693c6 | bellard | #ifdef DEBUG_GDB
|
961 | 858693c6 | bellard | printf("command='%s'\n", line_buf);
|
962 | 858693c6 | bellard | #endif
|
963 | 858693c6 | bellard | p = line_buf; |
964 | 858693c6 | bellard | ch = *p++; |
965 | 858693c6 | bellard | switch(ch) {
|
966 | 858693c6 | bellard | case '?': |
967 | 1fddef4b | bellard | /* TODO: Make this return the correct value for user-mode. */
|
968 | 858693c6 | bellard | snprintf(buf, sizeof(buf), "S%02x", SIGTRAP); |
969 | 858693c6 | bellard | put_packet(s, buf); |
970 | 7d03f82f | edgar_igl | /* Remove all the breakpoints when this query is issued,
|
971 | 7d03f82f | edgar_igl | * because gdb is doing and initial connect and the state
|
972 | 7d03f82f | edgar_igl | * should be cleaned up.
|
973 | 7d03f82f | edgar_igl | */
|
974 | 7d03f82f | edgar_igl | cpu_breakpoint_remove_all(env); |
975 | 7d03f82f | edgar_igl | cpu_watchpoint_remove_all(env); |
976 | 858693c6 | bellard | break;
|
977 | 858693c6 | bellard | case 'c': |
978 | 858693c6 | bellard | if (*p != '\0') { |
979 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
980 | 4c3a88a2 | bellard | #if defined(TARGET_I386)
|
981 | 858693c6 | bellard | env->eip = addr; |
982 | 5be1a8e0 | bellard | #elif defined (TARGET_PPC)
|
983 | 858693c6 | bellard | env->nip = addr; |
984 | 8d5f07fa | bellard | #elif defined (TARGET_SPARC)
|
985 | 8d5f07fa | bellard | env->pc = addr; |
986 | 8d5f07fa | bellard | env->npc = addr + 4;
|
987 | b5ff1b31 | bellard | #elif defined (TARGET_ARM)
|
988 | b5ff1b31 | bellard | env->regs[15] = addr;
|
989 | fdf9b3e8 | bellard | #elif defined (TARGET_SH4)
|
990 | 8fac5803 | ths | env->pc = addr; |
991 | 8fac5803 | ths | #elif defined (TARGET_MIPS)
|
992 | ead9360e | ths | env->PC[env->current_tc] = addr; |
993 | f1ccf904 | ths | #elif defined (TARGET_CRIS)
|
994 | f1ccf904 | ths | env->pc = addr; |
995 | 4c3a88a2 | bellard | #endif
|
996 | 858693c6 | bellard | } |
997 | ba70a624 | edgar_igl | gdb_continue(s); |
998 | 41625033 | bellard | return RS_IDLE;
|
999 | 1f487ee9 | edgar_igl | case 'C': |
1000 | 1f487ee9 | edgar_igl | s->signal = strtoul(p, (char **)&p, 16); |
1001 | 1f487ee9 | edgar_igl | gdb_continue(s); |
1002 | 1f487ee9 | edgar_igl | return RS_IDLE;
|
1003 | 7d03f82f | edgar_igl | case 'k': |
1004 | 7d03f82f | edgar_igl | /* Kill the target */
|
1005 | 7d03f82f | edgar_igl | fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");
|
1006 | 7d03f82f | edgar_igl | exit(0);
|
1007 | 7d03f82f | edgar_igl | case 'D': |
1008 | 7d03f82f | edgar_igl | /* Detach packet */
|
1009 | 7d03f82f | edgar_igl | cpu_breakpoint_remove_all(env); |
1010 | 7d03f82f | edgar_igl | cpu_watchpoint_remove_all(env); |
1011 | 7d03f82f | edgar_igl | gdb_continue(s); |
1012 | 7d03f82f | edgar_igl | put_packet(s, "OK");
|
1013 | 7d03f82f | edgar_igl | break;
|
1014 | 858693c6 | bellard | case 's': |
1015 | 858693c6 | bellard | if (*p != '\0') { |
1016 | 8fac5803 | ths | addr = strtoull(p, (char **)&p, 16); |
1017 | c33a346e | bellard | #if defined(TARGET_I386)
|
1018 | 858693c6 | bellard | env->eip = addr; |
1019 | 5be1a8e0 | bellard | #elif defined (TARGET_PPC)
|
1020 | 858693c6 | bellard | env->nip = addr; |
1021 | 8d5f07fa | bellard | #elif defined (TARGET_SPARC)
|
1022 | 8d5f07fa | bellard | env->pc = addr; |
1023 | 8d5f07fa | bellard | env->npc = addr + 4;
|
1024 | b5ff1b31 | bellard | #elif defined (TARGET_ARM)
|
1025 | b5ff1b31 | bellard | env->regs[15] = addr;
|
1026 | fdf9b3e8 | bellard | #elif defined (TARGET_SH4)
|
1027 | 8fac5803 | ths | env->pc = addr; |
1028 | 8fac5803 | ths | #elif defined (TARGET_MIPS)
|
1029 | ead9360e | ths | env->PC[env->current_tc] = addr; |
1030 | f1ccf904 | ths | #elif defined (TARGET_CRIS)
|
1031 | f1ccf904 | ths | env->pc = addr; |
1032 | c33a346e | bellard | #endif
|
1033 | 858693c6 | bellard | } |
1034 | 60897d36 | edgar_igl | cpu_single_step(env, sstep_flags); |
1035 | ba70a624 | edgar_igl | gdb_continue(s); |
1036 | 41625033 | bellard | return RS_IDLE;
|
1037 | a2d1ebaf | pbrook | case 'F': |
1038 | a2d1ebaf | pbrook | { |
1039 | a2d1ebaf | pbrook | target_ulong ret; |
1040 | a2d1ebaf | pbrook | target_ulong err; |
1041 | a2d1ebaf | pbrook | |
1042 | a2d1ebaf | pbrook | ret = strtoull(p, (char **)&p, 16); |
1043 | a2d1ebaf | pbrook | if (*p == ',') { |
1044 | a2d1ebaf | pbrook | p++; |
1045 | a2d1ebaf | pbrook | err = strtoull(p, (char **)&p, 16); |
1046 | a2d1ebaf | pbrook | } else {
|
1047 | a2d1ebaf | pbrook | err = 0;
|
1048 | a2d1ebaf | pbrook | } |
1049 | a2d1ebaf | pbrook | if (*p == ',') |
1050 | a2d1ebaf | pbrook | p++; |
1051 | a2d1ebaf | pbrook | type = *p; |
1052 | a2d1ebaf | pbrook | if (gdb_current_syscall_cb)
|
1053 | a2d1ebaf | pbrook | gdb_current_syscall_cb(s->env, ret, err); |
1054 | a2d1ebaf | pbrook | if (type == 'C') { |
1055 | a2d1ebaf | pbrook | put_packet(s, "T02");
|
1056 | a2d1ebaf | pbrook | } else {
|
1057 | ba70a624 | edgar_igl | gdb_continue(s); |
1058 | a2d1ebaf | pbrook | } |
1059 | a2d1ebaf | pbrook | } |
1060 | a2d1ebaf | pbrook | break;
|
1061 | 858693c6 | bellard | case 'g': |
1062 | 858693c6 | bellard | reg_size = cpu_gdb_read_registers(env, mem_buf); |
1063 | 858693c6 | bellard | memtohex(buf, mem_buf, reg_size); |
1064 | 858693c6 | bellard | put_packet(s, buf); |
1065 | 858693c6 | bellard | break;
|
1066 | 858693c6 | bellard | case 'G': |
1067 | 858693c6 | bellard | registers = (void *)mem_buf;
|
1068 | 858693c6 | bellard | len = strlen(p) / 2;
|
1069 | 858693c6 | bellard | hextomem((uint8_t *)registers, p, len); |
1070 | 858693c6 | bellard | cpu_gdb_write_registers(env, mem_buf, len); |
1071 | 858693c6 | bellard | put_packet(s, "OK");
|
1072 | 858693c6 | bellard | break;
|
1073 | 858693c6 | bellard | case 'm': |
1074 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1075 | 858693c6 | bellard | if (*p == ',') |
1076 | 858693c6 | bellard | p++; |
1077 | 9d9754a3 | bellard | len = strtoull(p, NULL, 16); |
1078 | 6f970bd9 | bellard | if (cpu_memory_rw_debug(env, addr, mem_buf, len, 0) != 0) { |
1079 | 6f970bd9 | bellard | put_packet (s, "E14");
|
1080 | 6f970bd9 | bellard | } else {
|
1081 | 6f970bd9 | bellard | memtohex(buf, mem_buf, len); |
1082 | 6f970bd9 | bellard | put_packet(s, buf); |
1083 | 6f970bd9 | bellard | } |
1084 | 858693c6 | bellard | break;
|
1085 | 858693c6 | bellard | case 'M': |
1086 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1087 | 858693c6 | bellard | if (*p == ',') |
1088 | 858693c6 | bellard | p++; |
1089 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1090 | b328f873 | bellard | if (*p == ':') |
1091 | 858693c6 | bellard | p++; |
1092 | 858693c6 | bellard | hextomem(mem_buf, p, len); |
1093 | 858693c6 | bellard | if (cpu_memory_rw_debug(env, addr, mem_buf, len, 1) != 0) |
1094 | 905f20b1 | bellard | put_packet(s, "E14");
|
1095 | 858693c6 | bellard | else
|
1096 | 858693c6 | bellard | put_packet(s, "OK");
|
1097 | 858693c6 | bellard | break;
|
1098 | 858693c6 | bellard | case 'Z': |
1099 | 858693c6 | bellard | type = strtoul(p, (char **)&p, 16); |
1100 | 858693c6 | bellard | if (*p == ',') |
1101 | 858693c6 | bellard | p++; |
1102 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1103 | 858693c6 | bellard | if (*p == ',') |
1104 | 858693c6 | bellard | p++; |
1105 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1106 | 858693c6 | bellard | if (type == 0 || type == 1) { |
1107 | 858693c6 | bellard | if (cpu_breakpoint_insert(env, addr) < 0) |
1108 | 858693c6 | bellard | goto breakpoint_error;
|
1109 | 858693c6 | bellard | put_packet(s, "OK");
|
1110 | 6658ffb8 | pbrook | #ifndef CONFIG_USER_ONLY
|
1111 | 6658ffb8 | pbrook | } else if (type == 2) { |
1112 | 6658ffb8 | pbrook | if (cpu_watchpoint_insert(env, addr) < 0) |
1113 | 6658ffb8 | pbrook | goto breakpoint_error;
|
1114 | 6658ffb8 | pbrook | put_packet(s, "OK");
|
1115 | 6658ffb8 | pbrook | #endif
|
1116 | 858693c6 | bellard | } else {
|
1117 | 858693c6 | bellard | breakpoint_error:
|
1118 | 905f20b1 | bellard | put_packet(s, "E22");
|
1119 | 858693c6 | bellard | } |
1120 | 858693c6 | bellard | break;
|
1121 | 858693c6 | bellard | case 'z': |
1122 | 858693c6 | bellard | type = strtoul(p, (char **)&p, 16); |
1123 | 858693c6 | bellard | if (*p == ',') |
1124 | 858693c6 | bellard | p++; |
1125 | 9d9754a3 | bellard | addr = strtoull(p, (char **)&p, 16); |
1126 | 858693c6 | bellard | if (*p == ',') |
1127 | 858693c6 | bellard | p++; |
1128 | 9d9754a3 | bellard | len = strtoull(p, (char **)&p, 16); |
1129 | 858693c6 | bellard | if (type == 0 || type == 1) { |
1130 | 858693c6 | bellard | cpu_breakpoint_remove(env, addr); |
1131 | 858693c6 | bellard | put_packet(s, "OK");
|
1132 | 6658ffb8 | pbrook | #ifndef CONFIG_USER_ONLY
|
1133 | 6658ffb8 | pbrook | } else if (type == 2) { |
1134 | 6658ffb8 | pbrook | cpu_watchpoint_remove(env, addr); |
1135 | 6658ffb8 | pbrook | put_packet(s, "OK");
|
1136 | 6658ffb8 | pbrook | #endif
|
1137 | 858693c6 | bellard | } else {
|
1138 | 858693c6 | bellard | goto breakpoint_error;
|
1139 | 858693c6 | bellard | } |
1140 | 858693c6 | bellard | break;
|
1141 | 978efd6a | pbrook | case 'q': |
1142 | 60897d36 | edgar_igl | case 'Q': |
1143 | 60897d36 | edgar_igl | /* parse any 'q' packets here */
|
1144 | 60897d36 | edgar_igl | if (!strcmp(p,"qemu.sstepbits")) { |
1145 | 60897d36 | edgar_igl | /* Query Breakpoint bit definitions */
|
1146 | 60897d36 | edgar_igl | sprintf(buf,"ENABLE=%x,NOIRQ=%x,NOTIMER=%x",
|
1147 | 60897d36 | edgar_igl | SSTEP_ENABLE, |
1148 | 60897d36 | edgar_igl | SSTEP_NOIRQ, |
1149 | 60897d36 | edgar_igl | SSTEP_NOTIMER); |
1150 | 60897d36 | edgar_igl | put_packet(s, buf); |
1151 | 60897d36 | edgar_igl | break;
|
1152 | 60897d36 | edgar_igl | } else if (strncmp(p,"qemu.sstep",10) == 0) { |
1153 | 60897d36 | edgar_igl | /* Display or change the sstep_flags */
|
1154 | 60897d36 | edgar_igl | p += 10;
|
1155 | 60897d36 | edgar_igl | if (*p != '=') { |
1156 | 60897d36 | edgar_igl | /* Display current setting */
|
1157 | 60897d36 | edgar_igl | sprintf(buf,"0x%x", sstep_flags);
|
1158 | 60897d36 | edgar_igl | put_packet(s, buf); |
1159 | 60897d36 | edgar_igl | break;
|
1160 | 60897d36 | edgar_igl | } |
1161 | 60897d36 | edgar_igl | p++; |
1162 | 60897d36 | edgar_igl | type = strtoul(p, (char **)&p, 16); |
1163 | 60897d36 | edgar_igl | sstep_flags = type; |
1164 | 60897d36 | edgar_igl | put_packet(s, "OK");
|
1165 | 60897d36 | edgar_igl | break;
|
1166 | 60897d36 | edgar_igl | } |
1167 | 60897d36 | edgar_igl | #ifdef CONFIG_LINUX_USER
|
1168 | 60897d36 | edgar_igl | else if (strncmp(p, "Offsets", 7) == 0) { |
1169 | 978efd6a | pbrook | TaskState *ts = env->opaque; |
1170 | 978efd6a | pbrook | |
1171 | fe834d04 | ths | sprintf(buf, |
1172 | cd041681 | pbrook | "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx |
1173 | cd041681 | pbrook | ";Bss=" TARGET_ABI_FMT_lx,
|
1174 | fe834d04 | ths | ts->info->code_offset, |
1175 | fe834d04 | ths | ts->info->data_offset, |
1176 | fe834d04 | ths | ts->info->data_offset); |
1177 | 978efd6a | pbrook | put_packet(s, buf); |
1178 | 978efd6a | pbrook | break;
|
1179 | 978efd6a | pbrook | } |
1180 | 978efd6a | pbrook | #endif
|
1181 | 60897d36 | edgar_igl | /* Fall through. */
|
1182 | 858693c6 | bellard | default:
|
1183 | 858693c6 | bellard | /* put empty packet */
|
1184 | 858693c6 | bellard | buf[0] = '\0'; |
1185 | 858693c6 | bellard | put_packet(s, buf); |
1186 | 858693c6 | bellard | break;
|
1187 | 858693c6 | bellard | } |
1188 | 858693c6 | bellard | return RS_IDLE;
|
1189 | 858693c6 | bellard | } |
1190 | 858693c6 | bellard | |
1191 | 612458f5 | bellard | extern void tb_flush(CPUState *env); |
1192 | 612458f5 | bellard | |
1193 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
1194 | 858693c6 | bellard | static void gdb_vm_stopped(void *opaque, int reason) |
1195 | 858693c6 | bellard | { |
1196 | 858693c6 | bellard | GDBState *s = opaque; |
1197 | 858693c6 | bellard | char buf[256]; |
1198 | 858693c6 | bellard | int ret;
|
1199 | 858693c6 | bellard | |
1200 | a2d1ebaf | pbrook | if (s->state == RS_SYSCALL)
|
1201 | a2d1ebaf | pbrook | return;
|
1202 | a2d1ebaf | pbrook | |
1203 | 858693c6 | bellard | /* disable single step if it was enable */
|
1204 | 6a00d601 | bellard | cpu_single_step(s->env, 0);
|
1205 | 858693c6 | bellard | |
1206 | e80cfcfc | bellard | if (reason == EXCP_DEBUG) {
|
1207 | 6658ffb8 | pbrook | if (s->env->watchpoint_hit) {
|
1208 | aa6290b7 | pbrook | snprintf(buf, sizeof(buf), "T%02xwatch:" TARGET_FMT_lx ";", |
1209 | aa6290b7 | pbrook | SIGTRAP, |
1210 | 6658ffb8 | pbrook | s->env->watchpoint[s->env->watchpoint_hit - 1].vaddr);
|
1211 | 6658ffb8 | pbrook | put_packet(s, buf); |
1212 | 6658ffb8 | pbrook | s->env->watchpoint_hit = 0;
|
1213 | 6658ffb8 | pbrook | return;
|
1214 | 6658ffb8 | pbrook | } |
1215 | 6a00d601 | bellard | tb_flush(s->env); |
1216 | 858693c6 | bellard | ret = SIGTRAP; |
1217 | bbeb7b5c | bellard | } else if (reason == EXCP_INTERRUPT) { |
1218 | bbeb7b5c | bellard | ret = SIGINT; |
1219 | bbeb7b5c | bellard | } else {
|
1220 | 858693c6 | bellard | ret = 0;
|
1221 | bbeb7b5c | bellard | } |
1222 | 858693c6 | bellard | snprintf(buf, sizeof(buf), "S%02x", ret); |
1223 | 858693c6 | bellard | put_packet(s, buf); |
1224 | 858693c6 | bellard | } |
1225 | 1fddef4b | bellard | #endif
|
1226 | 858693c6 | bellard | |
1227 | a2d1ebaf | pbrook | /* Send a gdb syscall request.
|
1228 | a2d1ebaf | pbrook | This accepts limited printf-style format specifiers, specifically:
|
1229 | a87295e8 | pbrook | %x - target_ulong argument printed in hex.
|
1230 | a87295e8 | pbrook | %lx - 64-bit argument printed in hex.
|
1231 | a87295e8 | pbrook | %s - string pointer (target_ulong) and length (int) pair. */
|
1232 | a2d1ebaf | pbrook | void gdb_do_syscall(gdb_syscall_complete_cb cb, char *fmt, ...) |
1233 | a2d1ebaf | pbrook | { |
1234 | a2d1ebaf | pbrook | va_list va; |
1235 | a2d1ebaf | pbrook | char buf[256]; |
1236 | a2d1ebaf | pbrook | char *p;
|
1237 | a2d1ebaf | pbrook | target_ulong addr; |
1238 | a87295e8 | pbrook | uint64_t i64; |
1239 | a2d1ebaf | pbrook | GDBState *s; |
1240 | a2d1ebaf | pbrook | |
1241 | a2d1ebaf | pbrook | s = gdb_syscall_state; |
1242 | a2d1ebaf | pbrook | if (!s)
|
1243 | a2d1ebaf | pbrook | return;
|
1244 | a2d1ebaf | pbrook | gdb_current_syscall_cb = cb; |
1245 | a2d1ebaf | pbrook | s->state = RS_SYSCALL; |
1246 | a2d1ebaf | pbrook | #ifndef CONFIG_USER_ONLY
|
1247 | a2d1ebaf | pbrook | vm_stop(EXCP_DEBUG); |
1248 | a2d1ebaf | pbrook | #endif
|
1249 | a2d1ebaf | pbrook | s->state = RS_IDLE; |
1250 | a2d1ebaf | pbrook | va_start(va, fmt); |
1251 | a2d1ebaf | pbrook | p = buf; |
1252 | a2d1ebaf | pbrook | *(p++) = 'F';
|
1253 | a2d1ebaf | pbrook | while (*fmt) {
|
1254 | a2d1ebaf | pbrook | if (*fmt == '%') { |
1255 | a2d1ebaf | pbrook | fmt++; |
1256 | a2d1ebaf | pbrook | switch (*fmt++) {
|
1257 | a2d1ebaf | pbrook | case 'x': |
1258 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
1259 | a2d1ebaf | pbrook | p += sprintf(p, TARGET_FMT_lx, addr); |
1260 | a2d1ebaf | pbrook | break;
|
1261 | a87295e8 | pbrook | case 'l': |
1262 | a87295e8 | pbrook | if (*(fmt++) != 'x') |
1263 | a87295e8 | pbrook | goto bad_format;
|
1264 | a87295e8 | pbrook | i64 = va_arg(va, uint64_t); |
1265 | a87295e8 | pbrook | p += sprintf(p, "%" PRIx64, i64);
|
1266 | a87295e8 | pbrook | break;
|
1267 | a2d1ebaf | pbrook | case 's': |
1268 | a2d1ebaf | pbrook | addr = va_arg(va, target_ulong); |
1269 | a2d1ebaf | pbrook | p += sprintf(p, TARGET_FMT_lx "/%x", addr, va_arg(va, int)); |
1270 | a2d1ebaf | pbrook | break;
|
1271 | a2d1ebaf | pbrook | default:
|
1272 | a87295e8 | pbrook | bad_format:
|
1273 | a2d1ebaf | pbrook | fprintf(stderr, "gdbstub: Bad syscall format string '%s'\n",
|
1274 | a2d1ebaf | pbrook | fmt - 1);
|
1275 | a2d1ebaf | pbrook | break;
|
1276 | a2d1ebaf | pbrook | } |
1277 | a2d1ebaf | pbrook | } else {
|
1278 | a2d1ebaf | pbrook | *(p++) = *(fmt++); |
1279 | a2d1ebaf | pbrook | } |
1280 | a2d1ebaf | pbrook | } |
1281 | 8a93e02a | pbrook | *p = 0;
|
1282 | a2d1ebaf | pbrook | va_end(va); |
1283 | a2d1ebaf | pbrook | put_packet(s, buf); |
1284 | a2d1ebaf | pbrook | #ifdef CONFIG_USER_ONLY
|
1285 | a2d1ebaf | pbrook | gdb_handlesig(s->env, 0);
|
1286 | a2d1ebaf | pbrook | #else
|
1287 | a2d1ebaf | pbrook | cpu_interrupt(s->env, CPU_INTERRUPT_EXIT); |
1288 | a2d1ebaf | pbrook | #endif
|
1289 | a2d1ebaf | pbrook | } |
1290 | a2d1ebaf | pbrook | |
1291 | 6a00d601 | bellard | static void gdb_read_byte(GDBState *s, int ch) |
1292 | 858693c6 | bellard | { |
1293 | 6a00d601 | bellard | CPUState *env = s->env; |
1294 | 858693c6 | bellard | int i, csum;
|
1295 | 60fe76f3 | ths | uint8_t reply; |
1296 | 858693c6 | bellard | |
1297 | 1fddef4b | bellard | #ifndef CONFIG_USER_ONLY
|
1298 | 4046d913 | pbrook | if (s->last_packet_len) {
|
1299 | 4046d913 | pbrook | /* Waiting for a response to the last packet. If we see the start
|
1300 | 4046d913 | pbrook | of a new command then abandon the previous response. */
|
1301 | 4046d913 | pbrook | if (ch == '-') { |
1302 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
1303 | 4046d913 | pbrook | printf("Got NACK, retransmitting\n");
|
1304 | 4046d913 | pbrook | #endif
|
1305 | ffe8ab83 | ths | put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); |
1306 | 4046d913 | pbrook | } |
1307 | 4046d913 | pbrook | #ifdef DEBUG_GDB
|
1308 | 4046d913 | pbrook | else if (ch == '+') |
1309 | 4046d913 | pbrook | printf("Got ACK\n");
|
1310 | 4046d913 | pbrook | else
|
1311 | 4046d913 | pbrook | printf("Got '%c' when expecting ACK/NACK\n", ch);
|
1312 | 4046d913 | pbrook | #endif
|
1313 | 4046d913 | pbrook | if (ch == '+' || ch == '$') |
1314 | 4046d913 | pbrook | s->last_packet_len = 0;
|
1315 | 4046d913 | pbrook | if (ch != '$') |
1316 | 4046d913 | pbrook | return;
|
1317 | 4046d913 | pbrook | } |
1318 | 858693c6 | bellard | if (vm_running) {
|
1319 | 858693c6 | bellard | /* when the CPU is running, we cannot do anything except stop
|
1320 | 858693c6 | bellard | it when receiving a char */
|
1321 | 858693c6 | bellard | vm_stop(EXCP_INTERRUPT); |
1322 | 5fafdf24 | ths | } else
|
1323 | 1fddef4b | bellard | #endif
|
1324 | 41625033 | bellard | { |
1325 | 858693c6 | bellard | switch(s->state) {
|
1326 | 858693c6 | bellard | case RS_IDLE:
|
1327 | 858693c6 | bellard | if (ch == '$') { |
1328 | 858693c6 | bellard | s->line_buf_index = 0;
|
1329 | 858693c6 | bellard | s->state = RS_GETLINE; |
1330 | c33a346e | bellard | } |
1331 | b4608c04 | bellard | break;
|
1332 | 858693c6 | bellard | case RS_GETLINE:
|
1333 | 858693c6 | bellard | if (ch == '#') { |
1334 | 858693c6 | bellard | s->state = RS_CHKSUM1; |
1335 | 858693c6 | bellard | } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { |
1336 | 858693c6 | bellard | s->state = RS_IDLE; |
1337 | 4c3a88a2 | bellard | } else {
|
1338 | 858693c6 | bellard | s->line_buf[s->line_buf_index++] = ch; |
1339 | 4c3a88a2 | bellard | } |
1340 | 4c3a88a2 | bellard | break;
|
1341 | 858693c6 | bellard | case RS_CHKSUM1:
|
1342 | 858693c6 | bellard | s->line_buf[s->line_buf_index] = '\0';
|
1343 | 858693c6 | bellard | s->line_csum = fromhex(ch) << 4;
|
1344 | 858693c6 | bellard | s->state = RS_CHKSUM2; |
1345 | 858693c6 | bellard | break;
|
1346 | 858693c6 | bellard | case RS_CHKSUM2:
|
1347 | 858693c6 | bellard | s->line_csum |= fromhex(ch); |
1348 | 858693c6 | bellard | csum = 0;
|
1349 | 858693c6 | bellard | for(i = 0; i < s->line_buf_index; i++) { |
1350 | 858693c6 | bellard | csum += s->line_buf[i]; |
1351 | 858693c6 | bellard | } |
1352 | 858693c6 | bellard | if (s->line_csum != (csum & 0xff)) { |
1353 | 60fe76f3 | ths | reply = '-';
|
1354 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
1355 | 858693c6 | bellard | s->state = RS_IDLE; |
1356 | 4c3a88a2 | bellard | } else {
|
1357 | 60fe76f3 | ths | reply = '+';
|
1358 | 60fe76f3 | ths | put_buffer(s, &reply, 1);
|
1359 | 1fddef4b | bellard | s->state = gdb_handle_packet(s, env, s->line_buf); |
1360 | 4c3a88a2 | bellard | } |
1361 | 4c3a88a2 | bellard | break;
|
1362 | a2d1ebaf | pbrook | default:
|
1363 | a2d1ebaf | pbrook | abort(); |
1364 | 858693c6 | bellard | } |
1365 | 858693c6 | bellard | } |
1366 | 858693c6 | bellard | } |
1367 | 858693c6 | bellard | |
1368 | 1fddef4b | bellard | #ifdef CONFIG_USER_ONLY
|
1369 | 1fddef4b | bellard | int
|
1370 | 1fddef4b | bellard | gdb_handlesig (CPUState *env, int sig)
|
1371 | 1fddef4b | bellard | { |
1372 | 1fddef4b | bellard | GDBState *s; |
1373 | 1fddef4b | bellard | char buf[256]; |
1374 | 1fddef4b | bellard | int n;
|
1375 | 1fddef4b | bellard | |
1376 | 1fddef4b | bellard | s = &gdbserver_state; |
1377 | 1f487ee9 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
1378 | 1f487ee9 | edgar_igl | return sig;
|
1379 | 1fddef4b | bellard | |
1380 | 1fddef4b | bellard | /* disable single step if it was enabled */
|
1381 | 1fddef4b | bellard | cpu_single_step(env, 0);
|
1382 | 1fddef4b | bellard | tb_flush(env); |
1383 | 1fddef4b | bellard | |
1384 | 1fddef4b | bellard | if (sig != 0) |
1385 | 1fddef4b | bellard | { |
1386 | 1fddef4b | bellard | snprintf(buf, sizeof(buf), "S%02x", sig); |
1387 | 1fddef4b | bellard | put_packet(s, buf); |
1388 | 1fddef4b | bellard | } |
1389 | 1f487ee9 | edgar_igl | /* put_packet() might have detected that the peer terminated the
|
1390 | 1f487ee9 | edgar_igl | connection. */
|
1391 | 1f487ee9 | edgar_igl | if (s->fd < 0) |
1392 | 1f487ee9 | edgar_igl | return sig;
|
1393 | 1fddef4b | bellard | |
1394 | 1fddef4b | bellard | sig = 0;
|
1395 | 1fddef4b | bellard | s->state = RS_IDLE; |
1396 | 41625033 | bellard | s->running_state = 0;
|
1397 | 41625033 | bellard | while (s->running_state == 0) { |
1398 | 1fddef4b | bellard | n = read (s->fd, buf, 256);
|
1399 | 1fddef4b | bellard | if (n > 0) |
1400 | 1fddef4b | bellard | { |
1401 | 1fddef4b | bellard | int i;
|
1402 | 1fddef4b | bellard | |
1403 | 1fddef4b | bellard | for (i = 0; i < n; i++) |
1404 | 6a00d601 | bellard | gdb_read_byte (s, buf[i]); |
1405 | 1fddef4b | bellard | } |
1406 | 1fddef4b | bellard | else if (n == 0 || errno != EAGAIN) |
1407 | 1fddef4b | bellard | { |
1408 | 1fddef4b | bellard | /* XXX: Connection closed. Should probably wait for annother
|
1409 | 1fddef4b | bellard | connection before continuing. */
|
1410 | 1fddef4b | bellard | return sig;
|
1411 | 1fddef4b | bellard | } |
1412 | 41625033 | bellard | } |
1413 | 1f487ee9 | edgar_igl | sig = s->signal; |
1414 | 1f487ee9 | edgar_igl | s->signal = 0;
|
1415 | 1fddef4b | bellard | return sig;
|
1416 | 1fddef4b | bellard | } |
1417 | e9009676 | bellard | |
1418 | e9009676 | bellard | /* Tell the remote gdb that the process has exited. */
|
1419 | e9009676 | bellard | void gdb_exit(CPUState *env, int code) |
1420 | e9009676 | bellard | { |
1421 | e9009676 | bellard | GDBState *s; |
1422 | e9009676 | bellard | char buf[4]; |
1423 | e9009676 | bellard | |
1424 | e9009676 | bellard | s = &gdbserver_state; |
1425 | 1f487ee9 | edgar_igl | if (gdbserver_fd < 0 || s->fd < 0) |
1426 | 1f487ee9 | edgar_igl | return;
|
1427 | e9009676 | bellard | |
1428 | e9009676 | bellard | snprintf(buf, sizeof(buf), "W%02x", code); |
1429 | e9009676 | bellard | put_packet(s, buf); |
1430 | e9009676 | bellard | } |
1431 | e9009676 | bellard | |
1432 | 1fddef4b | bellard | |
1433 | 7c9d8e07 | bellard | static void gdb_accept(void *opaque) |
1434 | 858693c6 | bellard | { |
1435 | 858693c6 | bellard | GDBState *s; |
1436 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
1437 | 858693c6 | bellard | socklen_t len; |
1438 | 858693c6 | bellard | int val, fd;
|
1439 | 858693c6 | bellard | |
1440 | 858693c6 | bellard | for(;;) {
|
1441 | 858693c6 | bellard | len = sizeof(sockaddr);
|
1442 | 858693c6 | bellard | fd = accept(gdbserver_fd, (struct sockaddr *)&sockaddr, &len);
|
1443 | 858693c6 | bellard | if (fd < 0 && errno != EINTR) { |
1444 | 858693c6 | bellard | perror("accept");
|
1445 | 858693c6 | bellard | return;
|
1446 | 858693c6 | bellard | } else if (fd >= 0) { |
1447 | b4608c04 | bellard | break;
|
1448 | b4608c04 | bellard | } |
1449 | b4608c04 | bellard | } |
1450 | 858693c6 | bellard | |
1451 | 858693c6 | bellard | /* set short latency */
|
1452 | 858693c6 | bellard | val = 1;
|
1453 | 8f447cc7 | bellard | setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val)); |
1454 | 3b46e624 | ths | |
1455 | 1fddef4b | bellard | s = &gdbserver_state; |
1456 | 1fddef4b | bellard | memset (s, 0, sizeof (GDBState)); |
1457 | 6a00d601 | bellard | s->env = first_cpu; /* XXX: allow to change CPU */
|
1458 | 858693c6 | bellard | s->fd = fd; |
1459 | 858693c6 | bellard | |
1460 | a2d1ebaf | pbrook | gdb_syscall_state = s; |
1461 | a2d1ebaf | pbrook | |
1462 | 858693c6 | bellard | fcntl(fd, F_SETFL, O_NONBLOCK); |
1463 | 858693c6 | bellard | } |
1464 | 858693c6 | bellard | |
1465 | 858693c6 | bellard | static int gdbserver_open(int port) |
1466 | 858693c6 | bellard | { |
1467 | 858693c6 | bellard | struct sockaddr_in sockaddr;
|
1468 | 858693c6 | bellard | int fd, val, ret;
|
1469 | 858693c6 | bellard | |
1470 | 858693c6 | bellard | fd = socket(PF_INET, SOCK_STREAM, 0);
|
1471 | 858693c6 | bellard | if (fd < 0) { |
1472 | 858693c6 | bellard | perror("socket");
|
1473 | 858693c6 | bellard | return -1; |
1474 | 858693c6 | bellard | } |
1475 | 858693c6 | bellard | |
1476 | 858693c6 | bellard | /* allow fast reuse */
|
1477 | 858693c6 | bellard | val = 1;
|
1478 | 8f447cc7 | bellard | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)); |
1479 | 858693c6 | bellard | |
1480 | 858693c6 | bellard | sockaddr.sin_family = AF_INET; |
1481 | 858693c6 | bellard | sockaddr.sin_port = htons(port); |
1482 | 858693c6 | bellard | sockaddr.sin_addr.s_addr = 0;
|
1483 | 858693c6 | bellard | ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); |
1484 | 858693c6 | bellard | if (ret < 0) { |
1485 | 858693c6 | bellard | perror("bind");
|
1486 | 858693c6 | bellard | return -1; |
1487 | 858693c6 | bellard | } |
1488 | 858693c6 | bellard | ret = listen(fd, 0);
|
1489 | 858693c6 | bellard | if (ret < 0) { |
1490 | 858693c6 | bellard | perror("listen");
|
1491 | 858693c6 | bellard | return -1; |
1492 | 858693c6 | bellard | } |
1493 | 858693c6 | bellard | return fd;
|
1494 | 858693c6 | bellard | } |
1495 | 858693c6 | bellard | |
1496 | 858693c6 | bellard | int gdbserver_start(int port) |
1497 | 858693c6 | bellard | { |
1498 | 858693c6 | bellard | gdbserver_fd = gdbserver_open(port); |
1499 | 858693c6 | bellard | if (gdbserver_fd < 0) |
1500 | 858693c6 | bellard | return -1; |
1501 | 858693c6 | bellard | /* accept connections */
|
1502 | 7c9d8e07 | bellard | gdb_accept (NULL);
|
1503 | 4046d913 | pbrook | return 0; |
1504 | 4046d913 | pbrook | } |
1505 | 1fddef4b | bellard | #else
|
1506 | aa1f17c1 | ths | static int gdb_chr_can_receive(void *opaque) |
1507 | 4046d913 | pbrook | { |
1508 | 4046d913 | pbrook | return 1; |
1509 | 4046d913 | pbrook | } |
1510 | 4046d913 | pbrook | |
1511 | aa1f17c1 | ths | static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) |
1512 | 4046d913 | pbrook | { |
1513 | 4046d913 | pbrook | GDBState *s = opaque; |
1514 | 4046d913 | pbrook | int i;
|
1515 | 4046d913 | pbrook | |
1516 | 4046d913 | pbrook | for (i = 0; i < size; i++) { |
1517 | 4046d913 | pbrook | gdb_read_byte(s, buf[i]); |
1518 | 4046d913 | pbrook | } |
1519 | 4046d913 | pbrook | } |
1520 | 4046d913 | pbrook | |
1521 | 4046d913 | pbrook | static void gdb_chr_event(void *opaque, int event) |
1522 | 4046d913 | pbrook | { |
1523 | 4046d913 | pbrook | switch (event) {
|
1524 | 4046d913 | pbrook | case CHR_EVENT_RESET:
|
1525 | 4046d913 | pbrook | vm_stop(EXCP_INTERRUPT); |
1526 | a2d1ebaf | pbrook | gdb_syscall_state = opaque; |
1527 | 4046d913 | pbrook | break;
|
1528 | 4046d913 | pbrook | default:
|
1529 | 4046d913 | pbrook | break;
|
1530 | 4046d913 | pbrook | } |
1531 | 4046d913 | pbrook | } |
1532 | 4046d913 | pbrook | |
1533 | cfc3475a | pbrook | int gdbserver_start(const char *port) |
1534 | 4046d913 | pbrook | { |
1535 | 4046d913 | pbrook | GDBState *s; |
1536 | cfc3475a | pbrook | char gdbstub_port_name[128]; |
1537 | cfc3475a | pbrook | int port_num;
|
1538 | cfc3475a | pbrook | char *p;
|
1539 | cfc3475a | pbrook | CharDriverState *chr; |
1540 | cfc3475a | pbrook | |
1541 | cfc3475a | pbrook | if (!port || !*port)
|
1542 | cfc3475a | pbrook | return -1; |
1543 | 4046d913 | pbrook | |
1544 | cfc3475a | pbrook | port_num = strtol(port, &p, 10);
|
1545 | cfc3475a | pbrook | if (*p == 0) { |
1546 | cfc3475a | pbrook | /* A numeric value is interpreted as a port number. */
|
1547 | cfc3475a | pbrook | snprintf(gdbstub_port_name, sizeof(gdbstub_port_name),
|
1548 | cfc3475a | pbrook | "tcp::%d,nowait,nodelay,server", port_num);
|
1549 | cfc3475a | pbrook | port = gdbstub_port_name; |
1550 | cfc3475a | pbrook | } |
1551 | cfc3475a | pbrook | |
1552 | cfc3475a | pbrook | chr = qemu_chr_open(port); |
1553 | 4046d913 | pbrook | if (!chr)
|
1554 | 4046d913 | pbrook | return -1; |
1555 | 4046d913 | pbrook | |
1556 | 4046d913 | pbrook | s = qemu_mallocz(sizeof(GDBState));
|
1557 | 4046d913 | pbrook | if (!s) {
|
1558 | 4046d913 | pbrook | return -1; |
1559 | 4046d913 | pbrook | } |
1560 | 4046d913 | pbrook | s->env = first_cpu; /* XXX: allow to change CPU */
|
1561 | 4046d913 | pbrook | s->chr = chr; |
1562 | aa1f17c1 | ths | qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive, |
1563 | 4046d913 | pbrook | gdb_chr_event, s); |
1564 | 4046d913 | pbrook | qemu_add_vm_stop_handler(gdb_vm_stopped, s); |
1565 | b4608c04 | bellard | return 0; |
1566 | b4608c04 | bellard | } |
1567 | 4046d913 | pbrook | #endif |