kgdb_stub.c revision 1.7.2.7 1 1.7.2.7 nathanw /* $NetBSD: kgdb_stub.c,v 1.7.2.7 2002/02/28 04:14:45 nathanw Exp $ */
2 1.1 gwr
3 1.1 gwr /*
4 1.1 gwr * Copyright (c) 1990, 1993
5 1.1 gwr * The Regents of the University of California. All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This software was developed by the Computer Systems Engineering group
8 1.1 gwr * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 gwr * contributed to Berkeley.
10 1.1 gwr *
11 1.1 gwr * All advertising materials mentioning features or use of this software
12 1.1 gwr * must display the following acknowledgement:
13 1.1 gwr * This product includes software developed by the University of
14 1.1 gwr * California, Lawrence Berkeley Laboratories.
15 1.1 gwr *
16 1.1 gwr * Redistribution and use in source and binary forms, with or without
17 1.1 gwr * modification, are permitted provided that the following conditions
18 1.1 gwr * are met:
19 1.1 gwr * 1. Redistributions of source code must retain the above copyright
20 1.1 gwr * notice, this list of conditions and the following disclaimer.
21 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 gwr * notice, this list of conditions and the following disclaimer in the
23 1.1 gwr * documentation and/or other materials provided with the distribution.
24 1.1 gwr * 3. All advertising materials mentioning features or use of this software
25 1.1 gwr * must display the following acknowledgement:
26 1.1 gwr * This product includes software developed by the University of
27 1.1 gwr * California, Berkeley and its contributors.
28 1.1 gwr * 4. Neither the name of the University nor the names of its contributors
29 1.1 gwr * may be used to endorse or promote products derived from this software
30 1.1 gwr * without specific prior written permission.
31 1.1 gwr *
32 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 gwr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 gwr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 gwr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 gwr * SUCH DAMAGE.
43 1.1 gwr *
44 1.1 gwr * @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
45 1.1 gwr */
46 1.1 gwr
47 1.1 gwr /*
48 1.1 gwr * "Stub" to allow remote cpu to debug over a serial line using gdb.
49 1.1 gwr */
50 1.7.2.4 nathanw
51 1.7.2.4 nathanw #include <sys/cdefs.h>
52 1.7.2.7 nathanw __KERNEL_RCSID(0, "$NetBSD: kgdb_stub.c,v 1.7.2.7 2002/02/28 04:14:45 nathanw Exp $");
53 1.7.2.5 nathanw
54 1.7.2.5 nathanw #include "opt_kgdb.h"
55 1.1 gwr
56 1.1 gwr #include <sys/param.h>
57 1.1 gwr #include <sys/systm.h>
58 1.1 gwr #include <sys/kgdb.h>
59 1.1 gwr
60 1.7.2.1 nathanw #undef DEBUG_KGDB
61 1.7.2.1 nathanw
62 1.7.2.1 nathanw #ifdef DEBUG_KGDB
63 1.7.2.1 nathanw #define DPRINTF(x) printf x
64 1.7.2.1 nathanw #else
65 1.7.2.1 nathanw #define DPRINTF(x)
66 1.7.2.1 nathanw #endif
67 1.1 gwr
68 1.1 gwr /* XXX: Maybe these should be in the MD files? */
69 1.7.2.5 nathanw #ifndef KGDB_DEV
70 1.7.2.5 nathanw #define KGDB_DEV NODEV
71 1.1 gwr #endif
72 1.7.2.5 nathanw #ifndef KGDB_DEVRATE
73 1.7.2.5 nathanw #define KGDB_DEVRATE 19200
74 1.1 gwr #endif
75 1.1 gwr
76 1.7.2.5 nathanw int kgdb_dev = KGDB_DEV; /* remote debugging device (NODEV if none) */
77 1.7.2.5 nathanw int kgdb_rate = KGDB_DEVRATE; /* remote debugging baud rate */
78 1.1 gwr int kgdb_active = 0; /* remote debugging active if != 0 */
79 1.1 gwr int kgdb_debug_init = 0; /* != 0 waits for remote at system init */
80 1.1 gwr int kgdb_debug_panic = 0; /* != 0 waits for remote on panic */
81 1.1 gwr label_t *kgdb_recover = 0;
82 1.1 gwr
83 1.1 gwr static void kgdb_copy __P((void *, void *, int));
84 1.1 gwr /* static void kgdb_zero __P((void *, int)); */
85 1.1 gwr static void kgdb_send __P((u_char *));
86 1.1 gwr static int kgdb_recv __P((u_char *, int));
87 1.1 gwr static int digit2i __P((u_char));
88 1.1 gwr static u_char i2digit __P((int));
89 1.1 gwr static void mem2hex __P((void *, void *, int));
90 1.1 gwr static u_char *hex2mem __P((void *, u_char *, int));
91 1.5 eeh static vaddr_t hex2i __P((u_char **));
92 1.1 gwr
93 1.1 gwr static int (*kgdb_getc) __P((void *));
94 1.1 gwr static void (*kgdb_putc) __P((void *, int));
95 1.1 gwr static void *kgdb_ioarg;
96 1.1 gwr
97 1.7.2.6 nathanw /* KGDB_BUFLEN must be at least (2*KGDB_NUMREGS*sizeof(kgdb_reg_t)+1) */
98 1.1 gwr static u_char buffer[KGDB_BUFLEN];
99 1.1 gwr static kgdb_reg_t gdb_regs[KGDB_NUMREGS];
100 1.1 gwr
101 1.1 gwr #define GETC() ((*kgdb_getc)(kgdb_ioarg))
102 1.1 gwr #define PUTC(c) ((*kgdb_putc)(kgdb_ioarg, c))
103 1.1 gwr
104 1.1 gwr /*
105 1.7 jeffs * db_trap_callback can be hooked by MD port code to handle special
106 1.7 jeffs * cases such as disabling hardware watchdogs while in kgdb. Name
107 1.7 jeffs * is shared with DDB.
108 1.7 jeffs */
109 1.7 jeffs void (*db_trap_callback)(int);
110 1.7 jeffs
111 1.7 jeffs /*
112 1.1 gwr * This little routine exists simply so that bcopy() can be debugged.
113 1.1 gwr */
114 1.1 gwr static void
115 1.1 gwr kgdb_copy(vsrc, vdst, len)
116 1.1 gwr void *vsrc, *vdst;
117 1.1 gwr int len;
118 1.1 gwr {
119 1.1 gwr char *src = vsrc;
120 1.1 gwr char *dst = vdst;
121 1.1 gwr
122 1.1 gwr while (--len >= 0)
123 1.1 gwr *dst++ = *src++;
124 1.1 gwr }
125 1.1 gwr
126 1.1 gwr #if 0
127 1.1 gwr /* ditto for bzero */
128 1.1 gwr static void
129 1.1 gwr kgdb_zero(vptr, len)
130 1.1 gwr void *vptr;
131 1.1 gwr int len;
132 1.1 gwr {
133 1.1 gwr char *ptr = vptr;
134 1.1 gwr
135 1.1 gwr while (--len >= 0)
136 1.1 gwr *ptr++ = (char) 0;
137 1.1 gwr }
138 1.1 gwr #endif
139 1.1 gwr
140 1.1 gwr /*
141 1.1 gwr * Convert a hex digit into an integer.
142 1.1 gwr * This returns -1 if the argument passed is no
143 1.1 gwr * valid hex digit.
144 1.1 gwr */
145 1.1 gwr static int
146 1.1 gwr digit2i(c)
147 1.1 gwr u_char c;
148 1.1 gwr {
149 1.1 gwr if (c >= '0' && c <= '9')
150 1.6 scottr return (c - '0');
151 1.1 gwr else if (c >= 'a' && c <= 'f')
152 1.6 scottr return (c - 'a' + 10);
153 1.1 gwr else if (c >= 'A' && c <= 'F')
154 1.1 gwr
155 1.6 scottr return (c - 'A' + 10);
156 1.1 gwr else
157 1.6 scottr return (-1);
158 1.1 gwr }
159 1.1 gwr
160 1.1 gwr /*
161 1.1 gwr * Convert the low 4 bits of an integer into
162 1.1 gwr * an hex digit.
163 1.1 gwr */
164 1.1 gwr static u_char
165 1.1 gwr i2digit(n)
166 1.1 gwr int n;
167 1.1 gwr {
168 1.6 scottr return ("0123456789abcdef"[n & 0x0f]);
169 1.1 gwr }
170 1.1 gwr
171 1.1 gwr /*
172 1.1 gwr * Convert a byte array into an hex string.
173 1.1 gwr */
174 1.1 gwr static void
175 1.1 gwr mem2hex(vdst, vsrc, len)
176 1.1 gwr void *vdst, *vsrc;
177 1.1 gwr int len;
178 1.1 gwr {
179 1.1 gwr u_char *dst = vdst;
180 1.1 gwr u_char *src = vsrc;
181 1.1 gwr
182 1.1 gwr while (len--) {
183 1.1 gwr *dst++ = i2digit(*src >> 4);
184 1.1 gwr *dst++ = i2digit(*src++);
185 1.1 gwr }
186 1.1 gwr *dst = '\0';
187 1.1 gwr }
188 1.1 gwr
189 1.1 gwr /*
190 1.1 gwr * Convert an hex string into a byte array.
191 1.1 gwr * This returns a pointer to the character following
192 1.1 gwr * the last valid hex digit. If the string ends in
193 1.1 gwr * the middle of a byte, NULL is returned.
194 1.1 gwr */
195 1.1 gwr static u_char *
196 1.1 gwr hex2mem(vdst, src, maxlen)
197 1.1 gwr void *vdst;
198 1.1 gwr u_char *src;
199 1.1 gwr int maxlen;
200 1.1 gwr {
201 1.1 gwr u_char *dst = vdst;
202 1.1 gwr int msb, lsb;
203 1.1 gwr
204 1.1 gwr while (*src && maxlen--) {
205 1.1 gwr msb = digit2i(*src++);
206 1.1 gwr if (msb < 0)
207 1.6 scottr return (src - 1);
208 1.1 gwr lsb = digit2i(*src++);
209 1.1 gwr if (lsb < 0)
210 1.6 scottr return (NULL);
211 1.1 gwr *dst++ = (msb << 4) | lsb;
212 1.1 gwr }
213 1.6 scottr return (src);
214 1.1 gwr }
215 1.1 gwr
216 1.1 gwr /*
217 1.1 gwr * Convert an hex string into an integer.
218 1.1 gwr * This returns a pointer to the character following
219 1.1 gwr * the last valid hex digit.
220 1.1 gwr */
221 1.5 eeh static vaddr_t
222 1.1 gwr hex2i(srcp)
223 1.1 gwr u_char **srcp;
224 1.1 gwr {
225 1.1 gwr char *src = *srcp;
226 1.5 eeh vaddr_t r = 0;
227 1.1 gwr int nibble;
228 1.1 gwr
229 1.1 gwr while ((nibble = digit2i(*src)) >= 0) {
230 1.1 gwr r *= 16;
231 1.1 gwr r += nibble;
232 1.1 gwr src++;
233 1.1 gwr }
234 1.1 gwr *srcp = src;
235 1.6 scottr return (r);
236 1.1 gwr }
237 1.1 gwr
238 1.1 gwr /*
239 1.1 gwr * Send a packet.
240 1.1 gwr */
241 1.1 gwr static void
242 1.1 gwr kgdb_send(bp)
243 1.1 gwr u_char *bp;
244 1.1 gwr {
245 1.1 gwr u_char *p;
246 1.1 gwr u_char csum, c;
247 1.1 gwr
248 1.7.2.1 nathanw DPRINTF(("kgdb_send: %s\n", bp));
249 1.1 gwr do {
250 1.1 gwr p = bp;
251 1.1 gwr PUTC(KGDB_START);
252 1.1 gwr for (csum = 0; (c = *p); p++) {
253 1.1 gwr PUTC(c);
254 1.1 gwr csum += c;
255 1.1 gwr }
256 1.1 gwr PUTC(KGDB_END);
257 1.1 gwr PUTC(i2digit(csum >> 4));
258 1.1 gwr PUTC(i2digit(csum));
259 1.1 gwr } while ((c = GETC() & 0x7f) == KGDB_BADP);
260 1.1 gwr }
261 1.1 gwr
262 1.1 gwr /*
263 1.1 gwr * Receive a packet.
264 1.1 gwr */
265 1.1 gwr static int
266 1.1 gwr kgdb_recv(bp, maxlen)
267 1.1 gwr u_char *bp;
268 1.1 gwr int maxlen;
269 1.1 gwr {
270 1.1 gwr u_char *p;
271 1.7.2.1 nathanw int c, csum, tmpcsum;
272 1.1 gwr int len;
273 1.1 gwr
274 1.7.2.1 nathanw DPRINTF(("kgdb_recv: "));
275 1.1 gwr do {
276 1.1 gwr p = bp;
277 1.1 gwr csum = len = 0;
278 1.1 gwr while ((c = GETC()) != KGDB_START)
279 1.7.2.1 nathanw DPRINTF(("%c",c));
280 1.7.2.1 nathanw DPRINTF(("%c Start ",c));
281 1.1 gwr
282 1.1 gwr while ((c = GETC()) != KGDB_END && len < maxlen) {
283 1.7.2.1 nathanw DPRINTF(("%c",c));
284 1.1 gwr c &= 0x7f;
285 1.1 gwr csum += c;
286 1.1 gwr *p++ = c;
287 1.1 gwr len++;
288 1.1 gwr }
289 1.1 gwr csum &= 0xff;
290 1.1 gwr *p = '\0';
291 1.7.2.1 nathanw DPRINTF(("%c End ", c));
292 1.1 gwr
293 1.1 gwr if (len >= maxlen) {
294 1.7.2.1 nathanw DPRINTF(("Long- "));
295 1.1 gwr PUTC(KGDB_BADP);
296 1.1 gwr continue;
297 1.1 gwr }
298 1.7.2.1 nathanw tmpcsum = csum;
299 1.1 gwr
300 1.7.2.1 nathanw c = GETC();
301 1.7.2.1 nathanw DPRINTF(("%c",c));
302 1.7.2.1 nathanw csum -= digit2i(c) * 16;
303 1.7.2.1 nathanw c = GETC();
304 1.7.2.1 nathanw DPRINTF(("%c",c));
305 1.7.2.1 nathanw csum -= digit2i(c);
306 1.1 gwr
307 1.1 gwr if (csum == 0) {
308 1.7.2.1 nathanw DPRINTF(("Good+ "));
309 1.1 gwr PUTC(KGDB_GOODP);
310 1.1 gwr /* Sequence present? */
311 1.1 gwr if (bp[2] == ':') {
312 1.7.2.1 nathanw DPRINTF(("Seq %c%c ", bp[0], bp[1]));
313 1.1 gwr PUTC(bp[0]);
314 1.1 gwr PUTC(bp[1]);
315 1.1 gwr len -= 3;
316 1.1 gwr kgdb_copy(bp + 3, bp, len);
317 1.1 gwr }
318 1.1 gwr break;
319 1.1 gwr }
320 1.7.2.1 nathanw DPRINTF((" Bad(wanted %x, off by %d)- ", tmpcsum, csum));
321 1.1 gwr PUTC(KGDB_BADP);
322 1.1 gwr } while (1);
323 1.7.2.1 nathanw DPRINTF(("kgdb_recv: %s\n", bp));
324 1.6 scottr return (len);
325 1.1 gwr }
326 1.1 gwr
327 1.1 gwr /*
328 1.6 scottr * This is called by the appropriate tty driver.
329 1.1 gwr */
330 1.1 gwr void
331 1.1 gwr kgdb_attach(getfn, putfn, ioarg)
332 1.1 gwr int (*getfn) __P((void *));
333 1.1 gwr void (*putfn) __P((void *, int));
334 1.1 gwr void *ioarg;
335 1.1 gwr {
336 1.1 gwr kgdb_getc = getfn;
337 1.1 gwr kgdb_putc = putfn;
338 1.1 gwr kgdb_ioarg = ioarg;
339 1.1 gwr }
340 1.1 gwr
341 1.1 gwr /*
342 1.6 scottr * This function does all command processing for interfacing to
343 1.1 gwr * a remote gdb. Note that the error codes are ignored by gdb
344 1.1 gwr * at present, but might eventually become meaningful. (XXX)
345 1.1 gwr * It might makes sense to use POSIX errno values, because
346 1.1 gwr * that is what the gdb/remote.c functions want to return.
347 1.1 gwr */
348 1.1 gwr int
349 1.1 gwr kgdb_trap(type, regs)
350 1.1 gwr int type;
351 1.1 gwr db_regs_t *regs;
352 1.1 gwr {
353 1.1 gwr label_t jmpbuf;
354 1.5 eeh vaddr_t addr;
355 1.1 gwr size_t len;
356 1.1 gwr u_char *p;
357 1.1 gwr
358 1.7.2.1 nathanw printf("kgdb_trap 1\n");
359 1.7.2.1 nathanw
360 1.1 gwr if (kgdb_dev < 0 || kgdb_getc == NULL) {
361 1.1 gwr /* not debugging */
362 1.1 gwr return (0);
363 1.1 gwr }
364 1.7.2.2 nathanw
365 1.7.2.2 nathanw db_clear_single_step(regs);
366 1.1 gwr
367 1.7 jeffs if (db_trap_callback) db_trap_callback(1);
368 1.7 jeffs
369 1.1 gwr /* Detect and recover from unexpected traps. */
370 1.1 gwr if (kgdb_recover != 0) {
371 1.1 gwr printf("kgdb: caught trap 0x%x at %p\n",
372 1.1 gwr type, (void*)PC_REGS(regs));
373 1.1 gwr kgdb_send("E0E"); /* 14==EFAULT */
374 1.1 gwr longjmp(kgdb_recover);
375 1.1 gwr }
376 1.1 gwr
377 1.1 gwr /*
378 1.2 gwr * The first entry to this function is normally through
379 1.2 gwr * a breakpoint trap in kgdb_connect(), in which case we
380 1.2 gwr * must advance past the breakpoint because gdb will not.
381 1.2 gwr *
382 1.2 gwr * Machines vary as to where they leave the PC after a
383 1.2 gwr * breakpoint trap. Those that leave the PC set to the
384 1.2 gwr * address of the trap instruction (i.e. pc532) will not
385 1.2 gwr * define FIXUP_PC_AFTER_BREAK(), and therefore will just
386 1.2 gwr * advance the PC. On machines that leave the PC set to
387 1.2 gwr * the instruction after the trap, FIXUP_PC_AFTER_BREAK
388 1.2 gwr * will be defined to back-up the PC, so that after the
389 1.2 gwr * "first-time" part of the if statement below has run,
390 1.2 gwr * the PC will be the same as it was on entry.
391 1.2 gwr *
392 1.1 gwr * On the first entry here, we expect that gdb is not yet
393 1.1 gwr * listening to us, so just enter the interaction loop.
394 1.2 gwr * After the debugger is "active" (connected) it will be
395 1.1 gwr * waiting for a "signaled" message from us.
396 1.1 gwr */
397 1.1 gwr if (kgdb_active == 0) {
398 1.1 gwr if (!IS_BREAKPOINT_TRAP(type, 0)) {
399 1.1 gwr /* No debugger active -- let trap handle this. */
400 1.7 jeffs if (db_trap_callback) db_trap_callback(0);
401 1.1 gwr return (0);
402 1.1 gwr }
403 1.2 gwr /* Make the PC point at the breakpoint... */
404 1.2 gwr #ifdef FIXUP_PC_AFTER_BREAK
405 1.2 gwr FIXUP_PC_AFTER_BREAK(regs);
406 1.2 gwr #endif
407 1.2 gwr /* ... and then advance past it. */
408 1.4 pk #ifdef PC_ADVANCE
409 1.4 pk PC_ADVANCE(regs);
410 1.4 pk #else
411 1.2 gwr PC_REGS(regs) += BKPT_SIZE;
412 1.4 pk #endif
413 1.1 gwr kgdb_active = 1;
414 1.1 gwr } else {
415 1.7.2.3 nathanw /* Tell remote host that an exception has occurred. */
416 1.1 gwr sprintf(buffer, "S%02x", kgdb_signal(type));
417 1.1 gwr kgdb_send(buffer);
418 1.1 gwr }
419 1.1 gwr
420 1.1 gwr /* Stick frame regs into our reg cache. */
421 1.1 gwr kgdb_getregs(regs, gdb_regs);
422 1.1 gwr
423 1.1 gwr /*
424 1.1 gwr * Interact with gdb until it lets us go.
425 1.1 gwr * If we cause a trap, resume here.
426 1.1 gwr */
427 1.6 scottr (void)setjmp((kgdb_recover = &jmpbuf));
428 1.1 gwr for (;;) {
429 1.1 gwr kgdb_recv(buffer, sizeof(buffer));
430 1.1 gwr switch (buffer[0]) {
431 1.1 gwr
432 1.1 gwr default:
433 1.1 gwr /* Unknown command. */
434 1.1 gwr kgdb_send("");
435 1.1 gwr continue;
436 1.1 gwr
437 1.1 gwr case KGDB_SIGNAL:
438 1.1 gwr /*
439 1.1 gwr * if this command came from a running gdb,
440 1.1 gwr * answer it -- the other guy has no way of
441 1.1 gwr * knowing if we're in or out of this loop
442 1.1 gwr * when he issues a "remote-signal".
443 1.1 gwr */
444 1.1 gwr sprintf(buffer, "S%02x", kgdb_signal(type));
445 1.1 gwr kgdb_send(buffer);
446 1.1 gwr continue;
447 1.1 gwr
448 1.1 gwr case KGDB_REG_R:
449 1.1 gwr mem2hex(buffer, gdb_regs, sizeof(gdb_regs));
450 1.1 gwr kgdb_send(buffer);
451 1.1 gwr continue;
452 1.1 gwr
453 1.1 gwr case KGDB_REG_W:
454 1.1 gwr p = hex2mem(gdb_regs, buffer + 1, sizeof(gdb_regs));
455 1.1 gwr if (p == NULL || *p != '\0')
456 1.1 gwr kgdb_send("E01");
457 1.1 gwr else {
458 1.1 gwr kgdb_setregs(regs, gdb_regs);
459 1.1 gwr kgdb_send("OK");
460 1.1 gwr }
461 1.1 gwr continue;
462 1.1 gwr
463 1.1 gwr case KGDB_MEM_R:
464 1.1 gwr p = buffer + 1;
465 1.1 gwr addr = hex2i(&p);
466 1.1 gwr if (*p++ != ',') {
467 1.1 gwr kgdb_send("E02");
468 1.1 gwr continue;
469 1.1 gwr }
470 1.1 gwr len = hex2i(&p);
471 1.1 gwr if (*p != '\0') {
472 1.1 gwr kgdb_send("E03");
473 1.1 gwr continue;
474 1.1 gwr }
475 1.1 gwr if (len > sizeof(buffer) / 2) {
476 1.1 gwr kgdb_send("E04");
477 1.1 gwr continue;
478 1.1 gwr }
479 1.1 gwr if (kgdb_acc(addr, len) == 0) {
480 1.1 gwr kgdb_send("E05");
481 1.1 gwr continue;
482 1.1 gwr }
483 1.1 gwr db_read_bytes(addr, (size_t)len,
484 1.1 gwr (char *)buffer + sizeof(buffer) / 2);
485 1.1 gwr mem2hex(buffer, buffer + sizeof(buffer) / 2, len);
486 1.1 gwr kgdb_send(buffer);
487 1.1 gwr continue;
488 1.1 gwr
489 1.1 gwr case KGDB_MEM_W:
490 1.1 gwr p = buffer + 1;
491 1.1 gwr addr = hex2i(&p);
492 1.1 gwr if (*p++ != ',') {
493 1.1 gwr kgdb_send("E06");
494 1.1 gwr continue;
495 1.1 gwr }
496 1.1 gwr len = hex2i(&p);
497 1.1 gwr if (*p++ != ':') {
498 1.1 gwr kgdb_send("E07");
499 1.1 gwr continue;
500 1.1 gwr }
501 1.1 gwr if (len > (sizeof(buffer) - (p - buffer))) {
502 1.1 gwr kgdb_send("E08");
503 1.1 gwr continue;
504 1.1 gwr }
505 1.1 gwr p = hex2mem(buffer, p, sizeof(buffer));
506 1.1 gwr if (p == NULL) {
507 1.1 gwr kgdb_send("E09");
508 1.1 gwr continue;
509 1.1 gwr }
510 1.1 gwr if (kgdb_acc(addr, len) == 0) {
511 1.1 gwr kgdb_send("E0A");
512 1.1 gwr continue;
513 1.1 gwr }
514 1.1 gwr db_write_bytes(addr, (size_t)len, (char *)buffer);
515 1.1 gwr kgdb_send("OK");
516 1.1 gwr continue;
517 1.1 gwr
518 1.7.2.6 nathanw case KGDB_DETACH:
519 1.1 gwr case KGDB_KILL:
520 1.1 gwr kgdb_active = 0;
521 1.1 gwr printf("kgdb detached\n");
522 1.1 gwr db_clear_single_step(regs);
523 1.7.2.6 nathanw kgdb_send("OK");
524 1.1 gwr goto out;
525 1.1 gwr
526 1.1 gwr case KGDB_CONT:
527 1.1 gwr if (buffer[1]) {
528 1.1 gwr p = buffer + 1;
529 1.1 gwr addr = hex2i(&p);
530 1.1 gwr if (*p) {
531 1.1 gwr kgdb_send("E0B");
532 1.1 gwr continue;
533 1.1 gwr }
534 1.1 gwr PC_REGS(regs) = addr;
535 1.7.2.1 nathanw DPRINTF(("kgdb: continuing at %08lx\n", addr))
536 1.7.2.1 nathanw
537 1.7.2.1 nathanw } else {
538 1.7.2.1 nathanw DPRINTF((
539 1.7.2.1 nathanw "kgdb: continuing at old address %08lx\n",
540 1.7.2.1 nathanw PC_REGS(regs)));
541 1.1 gwr }
542 1.7.2.1 nathanw
543 1.1 gwr db_clear_single_step(regs);
544 1.1 gwr goto out;
545 1.1 gwr
546 1.1 gwr case KGDB_STEP:
547 1.1 gwr if (buffer[1]) {
548 1.1 gwr p = buffer + 1;
549 1.1 gwr addr = hex2i(&p);
550 1.1 gwr if (*p) {
551 1.1 gwr kgdb_send("E0B");
552 1.1 gwr continue;
553 1.1 gwr }
554 1.1 gwr PC_REGS(regs) = addr;
555 1.1 gwr }
556 1.1 gwr db_set_single_step(regs);
557 1.1 gwr goto out;
558 1.1 gwr }
559 1.1 gwr }
560 1.1 gwr out:
561 1.7 jeffs if (db_trap_callback) db_trap_callback(0);
562 1.1 gwr kgdb_recover = 0;
563 1.1 gwr return (1);
564 1.1 gwr }
565