3 * Originally written by Glenn Engel, Lake Stevens Instrument Division
5 * Contributed by HP Systems
7 * Modified for SPARC by Stu Grossman, Cygnus Support.
9 * Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
10 * Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
12 * Copyright (C) 1995 Andreas Busse
14 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
15 * Modified for Linux/mn10300 by David Howells <dhowells@redhat.com>
19 * To enable debugger support, two things need to happen. One, a
20 * call to set_debug_traps() is necessary in order to allow any breakpoints
21 * or error conditions to be properly intercepted and reported to gdb.
22 * Two, a breakpoint needs to be generated to begin communication. This
23 * is most easily accomplished by a call to breakpoint(). Breakpoint()
24 * simulates a breakpoint by executing a BREAK instruction.
27 * The following gdb commands are supported:
29 * command function Return value
31 * g return the value of the CPU registers hex data or ENN
32 * G set the value of the CPU registers OK or ENN
34 * mAA..AA,LLLL Read LLLL bytes at address AA..AA hex data or ENN
35 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA OK or ENN
37 * c Resume at current address SNN ( signal NN)
38 * cAA..AA Continue at address AA..AA SNN
40 * s Step one instruction SNN
41 * sAA..AA Step one instruction from AA..AA SNN
45 * ? What was the last sigval ? SNN (signal NN)
47 * bBB..BB Set baud rate to BB..BB OK or BNN, then sets
50 * All commands and responses are sent with a packet which includes a
51 * checksum. A packet consists of
53 * $<packet info>#<checksum>.
56 * <packet info> :: <characters representing the command or response>
57 * <checksum> :: < two hex digits computed as modulo 256 sum of <packetinfo>>
59 * When a packet is received, it is first acknowledged with either '+' or '-'.
60 * '+' indicates a successful transfer. '-' indicates a failed transfer.
65 * $m0,10#2a +$00010203040506070809101112131415#42
72 * For reference -- the following are the steps that one
73 * company took (RidgeRun Inc) to get remote gdb debugging
74 * going. In this scenario the host machine was a PC and the
75 * target platform was a Galileo EVB64120A MIPS evaluation
79 * First download gdb-5.0.tar.gz from the internet.
80 * and then build/install the package.
83 * $ tar zxf gdb-5.0.tar.gz
85 * $ ./configure --target=am33_2.0-linux-gnu
88 * am33_2.0-linux-gnu-gdb
91 * Configure linux for remote debugging and build it.
95 * $ make menuconfig <go to "Kernel Hacking" and turn on remote debugging>
96 * $ make dep; make vmlinux
99 * Download the kernel to the remote target and start
100 * the kernel running. It will promptly halt and wait
101 * for the host gdb session to connect. It does this
102 * since the "Kernel Hacking" option has defined
103 * CONFIG_REMOTE_DEBUG which in turn enables your calls
109 * Start the gdb session on the host.
112 * $ am33_2.0-linux-gnu-gdb vmlinux
113 * (gdb) set remotebaud 115200
114 * (gdb) target remote /dev/ttyS1
115 * ...at this point you are connected to
116 * the remote target and can use gdb
117 * in the normal fasion. Setting
118 * breakpoints, single stepping,
119 * printing variables, etc.
123 #include <linux/string.h>
124 #include <linux/kernel.h>
125 #include <linux/signal.h>
126 #include <linux/sched.h>
127 #include <linux/mm.h>
128 #include <linux/console.h>
129 #include <linux/init.h>
130 #include <linux/bug.h>
132 #include <asm/pgtable.h>
133 #include <asm/system.h>
134 #include <asm/gdb-stub.h>
135 #include <asm/exceptions.h>
136 #include <asm/debugger.h>
137 #include <asm/serial-regs.h>
138 #include <asm/busctl-regs.h>
139 #include <unit/leds.h>
140 #include <unit/serial.h>
142 /* define to use F7F7 rather than FF which is subverted by JTAG debugger */
143 #undef GDBSTUB_USE_F7F7_AS_BREAKPOINT
146 * BUFMAX defines the maximum number of characters in inbound/outbound buffers
147 * at least NUMREGBYTES*2 are needed for register packets
151 static const char gdbstub_banner
[] =
152 "Linux/MN10300 GDB Stub (c) RedHat 2007\n";
154 u8 gdbstub_rx_buffer
[PAGE_SIZE
] __attribute__((aligned(PAGE_SIZE
)));
158 u8 gdbstub_rx_overflow
;
161 static u8 gdbstub_flush_caches
;
162 static char input_buffer
[BUFMAX
];
163 static char output_buffer
[BUFMAX
];
164 static char trans_buffer
[BUFMAX
];
166 struct gdbstub_bkpt
{
167 u8
*addr
; /* address of breakpoint */
168 u8 len
; /* size of breakpoint */
169 u8 origbytes
[7]; /* original bytes */
172 static struct gdbstub_bkpt gdbstub_bkpts
[256];
177 static void getpacket(char *buffer
);
178 static int putpacket(char *buffer
);
179 static int computeSignal(enum exception_code excep
);
180 static int hex(unsigned char ch
);
181 static int hexToInt(char **ptr
, int *intValue
);
182 static unsigned char *mem2hex(const void *mem
, char *buf
, int count
,
184 static const char *hex2mem(const char *buf
, void *_mem
, int count
,
188 * Convert ch from a hex digit to an int
190 static int hex(unsigned char ch
)
192 if (ch
>= 'a' && ch
<= 'f')
193 return ch
- 'a' + 10;
194 if (ch
>= '0' && ch
<= '9')
196 if (ch
>= 'A' && ch
<= 'F')
197 return ch
- 'A' + 10;
201 #ifdef CONFIG_GDBSTUB_DEBUGGING
203 void debug_to_serial(const char *p
, int n
)
205 __debug_to_serial(p
, n
);
206 /* gdbstub_console_write(NULL, p, n); */
209 void gdbstub_printk(const char *fmt
, ...)
214 /* Emit the output into the temporary buffer */
216 len
= vsnprintf(trans_buffer
, sizeof(trans_buffer
), fmt
, args
);
218 debug_to_serial(trans_buffer
, len
);
223 static inline char *gdbstub_strcpy(char *dst
, const char *src
)
226 while ((dst
[loop
] = src
[loop
]))
232 * scan for the sequence $<data>#<checksum>
234 static void getpacket(char *buffer
)
236 unsigned char checksum
;
237 unsigned char xmitcsum
;
239 int count
, i
, ret
, error
;
243 * wait around for the start character,
244 * ignore all other characters
247 gdbstub_io_rx_char(&ch
, 0);
256 * now, read until a # or end of buffer is found
258 while (count
< BUFMAX
) {
259 ret
= gdbstub_io_rx_char(&ch
, 0);
271 gdbstub_proto("### GDB Rx Error - Skipping packet"
273 gdbstub_proto("### GDB Tx NAK\n");
274 gdbstub_io_tx_char('-');
278 if (count
>= BUFMAX
|| error
)
283 /* read the checksum */
284 ret
= gdbstub_io_rx_char(&ch
, 0);
287 xmitcsum
= hex(ch
) << 4;
289 ret
= gdbstub_io_rx_char(&ch
, 0);
296 gdbstub_io("### GDB Rx Error -"
297 " Skipping packet\n");
298 gdbstub_io("### GDB Tx NAK\n");
299 gdbstub_io_tx_char('-');
303 /* check the checksum */
304 if (checksum
!= xmitcsum
) {
305 gdbstub_io("### GDB Tx NAK\n");
306 gdbstub_io_tx_char('-'); /* failed checksum */
310 gdbstub_proto("### GDB Rx '$%s#%02x' ###\n", buffer
, checksum
);
311 gdbstub_io("### GDB Tx ACK\n");
312 gdbstub_io_tx_char('+'); /* successful transfer */
315 * if a sequence char is present,
316 * reply the sequence ID
318 if (buffer
[2] == ':') {
319 gdbstub_io_tx_char(buffer
[0]);
320 gdbstub_io_tx_char(buffer
[1]);
323 * remove sequence chars from buffer
326 while (buffer
[count
])
328 for (i
= 3; i
<= count
; i
++)
329 buffer
[i
- 3] = buffer
[i
];
337 * send the packet in buffer.
338 * - return 0 if successfully ACK'd
339 * - return 1 if abandoned due to new incoming packet
341 static int putpacket(char *buffer
)
343 unsigned char checksum
;
348 * $<packet info>#<checksum>.
350 gdbstub_proto("### GDB Tx $'%s'#?? ###\n", buffer
);
353 gdbstub_io_tx_char('$');
357 while ((ch
= buffer
[count
]) != 0) {
358 gdbstub_io_tx_char(ch
);
363 gdbstub_io_tx_char('#');
364 gdbstub_io_tx_char(hex_asc_hi(checksum
));
365 gdbstub_io_tx_char(hex_asc_lo(checksum
));
367 } while (gdbstub_io_rx_char(&ch
, 0),
368 ch
== '-' && (gdbstub_io("### GDB Rx NAK\n"), 0),
369 ch
!= '-' && ch
!= '+' &&
370 (gdbstub_io("### GDB Rx ??? %02x\n", ch
), 0),
371 ch
!= '+' && ch
!= '$');
374 gdbstub_io("### GDB Rx ACK\n");
378 gdbstub_io("### GDB Tx Abandoned\n");
379 gdbstub_rx_unget
= ch
;
384 * While we find nice hex chars, build an int.
385 * Return number of chars processed.
387 static int hexToInt(char **ptr
, int *intValue
)
395 hexValue
= hex(**ptr
);
399 *intValue
= (*intValue
<< 4) | hexValue
;
408 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
410 * We single-step by setting breakpoints. When an exception
411 * is handled, we need to restore the instructions hoisted
412 * when the breakpoints were set.
414 * This is where we save the original instructions.
416 static struct gdb_bp_save
{
421 static const unsigned char gdbstub_insn_sizes
[256] =
423 /* 1 2 3 4 5 6 7 8 9 a b c d e f */
424 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, /* 0 */
425 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 1 */
426 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, /* 2 */
427 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, /* 3 */
428 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, /* 4 */
429 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, /* 5 */
430 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6 */
431 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */
432 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 8 */
433 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 9 */
434 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* a */
435 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* b */
436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, /* c */
437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
438 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */
439 0, 2, 2, 2, 2, 2, 2, 4, 0, 3, 0, 4, 0, 6, 7, 1 /* f */
442 static int __gdbstub_mark_bp(u8
*addr
, int ix
)
445 if (((u8
*) VMALLOC_START
<= addr
) && (addr
< (u8
*) VMALLOC_END
))
448 if (((u8
*) 0x80000000UL
<= addr
) && (addr
< (u8
*) 0xa0000000UL
))
453 if (gdbstub_read_byte(addr
+ 0, &step_bp
[ix
].opcode
[0]) < 0 ||
454 gdbstub_read_byte(addr
+ 1, &step_bp
[ix
].opcode
[1]) < 0)
457 step_bp
[ix
].addr
= addr
;
461 static inline void __gdbstub_restore_bp(void)
463 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
464 if (step_bp
[0].addr
) {
465 gdbstub_write_byte(step_bp
[0].opcode
[0], step_bp
[0].addr
+ 0);
466 gdbstub_write_byte(step_bp
[0].opcode
[1], step_bp
[0].addr
+ 1);
468 if (step_bp
[1].addr
) {
469 gdbstub_write_byte(step_bp
[1].opcode
[0], step_bp
[1].addr
+ 0);
470 gdbstub_write_byte(step_bp
[1].opcode
[1], step_bp
[1].addr
+ 1);
474 gdbstub_write_byte(step_bp
[0].opcode
[0], step_bp
[0].addr
+ 0);
476 gdbstub_write_byte(step_bp
[1].opcode
[0], step_bp
[1].addr
+ 0);
479 gdbstub_flush_caches
= 1;
481 step_bp
[0].addr
= NULL
;
482 step_bp
[0].opcode
[0] = 0;
483 step_bp
[0].opcode
[1] = 0;
484 step_bp
[1].addr
= NULL
;
485 step_bp
[1].opcode
[0] = 0;
486 step_bp
[1].opcode
[1] = 0;
490 * emulate single stepping by means of breakpoint instructions
492 static int gdbstub_single_step(struct pt_regs
*regs
)
496 uint8_t cur
, *pc
, *sp
;
498 step_bp
[0].addr
= NULL
;
499 step_bp
[0].opcode
[0] = 0;
500 step_bp
[0].opcode
[1] = 0;
501 step_bp
[1].addr
= NULL
;
502 step_bp
[1].opcode
[0] = 0;
503 step_bp
[1].opcode
[1] = 0;
506 pc
= (u8
*) regs
->pc
;
507 sp
= (u8
*) (regs
+ 1);
508 if (gdbstub_read_byte(pc
, &cur
) < 0)
511 gdbstub_bkpt("Single Step from %p { %02x }\n", pc
, cur
);
513 gdbstub_flush_caches
= 1;
515 size
= gdbstub_insn_sizes
[cur
];
517 if (!__gdbstub_mark_bp(pc
+ size
, 0))
523 if (gdbstub_read_byte(pc
+ 1, (u8
*) &x
) < 0)
525 if (!__gdbstub_mark_bp(pc
+ 2, 0))
527 if ((x
< 0 || x
> 2) &&
528 !__gdbstub_mark_bp(pc
+ (s8
) x
, 1))
534 if (!__gdbstub_mark_bp(pc
+ 1, 0))
536 if (regs
->pc
!= regs
->lar
&&
537 !__gdbstub_mark_bp((u8
*) regs
->lar
, 1))
541 /* SETLB - loads the next for bytes into the LIR
544 if (!__gdbstub_mark_bp(pc
+ 1, 0))
548 /* JMP (d16,PC) or CALL (d16,PC) */
551 if (gdbstub_read_byte(pc
+ 1, ((u8
*) &x
) + 0) < 0 ||
552 gdbstub_read_byte(pc
+ 2, ((u8
*) &x
) + 1) < 0)
554 if (!__gdbstub_mark_bp(pc
+ (s16
) x
, 0))
558 /* JMP (d32,PC) or CALL (d32,PC) */
561 if (gdbstub_read_byte(pc
+ 1, ((u8
*) &x
) + 0) < 0 ||
562 gdbstub_read_byte(pc
+ 2, ((u8
*) &x
) + 1) < 0 ||
563 gdbstub_read_byte(pc
+ 3, ((u8
*) &x
) + 2) < 0 ||
564 gdbstub_read_byte(pc
+ 4, ((u8
*) &x
) + 3) < 0)
566 if (!__gdbstub_mark_bp(pc
+ (s32
) x
, 0))
572 if (!__gdbstub_mark_bp((u8
*) regs
->mdr
, 0))
578 if (gdbstub_read_byte(pc
+ 2, (u8
*) &x
) < 0)
581 if (gdbstub_read_byte(sp
+ 0, ((u8
*) &x
) + 0) < 0 ||
582 gdbstub_read_byte(sp
+ 1, ((u8
*) &x
) + 1) < 0 ||
583 gdbstub_read_byte(sp
+ 2, ((u8
*) &x
) + 2) < 0 ||
584 gdbstub_read_byte(sp
+ 3, ((u8
*) &x
) + 3) < 0)
586 if (!__gdbstub_mark_bp((u8
*) x
, 0))
591 if (gdbstub_read_byte(pc
+ 1, &cur
) < 0)
594 if (cur
>= 0xf0 && cur
<= 0xf7) {
595 /* JMP (An) / CALLS (An) */
597 case 0: x
= regs
->a0
; break;
598 case 1: x
= regs
->a1
; break;
599 case 2: x
= regs
->a2
; break;
600 case 3: x
= regs
->a3
; break;
602 if (!__gdbstub_mark_bp((u8
*) x
, 0))
604 } else if (cur
== 0xfc) {
606 if (gdbstub_read_byte(
607 sp
+ 0, ((u8
*) &x
) + 0) < 0 ||
609 sp
+ 1, ((u8
*) &x
) + 1) < 0 ||
611 sp
+ 2, ((u8
*) &x
) + 2) < 0 ||
613 sp
+ 3, ((u8
*) &x
) + 3) < 0)
615 if (!__gdbstub_mark_bp((u8
*) x
, 0))
617 } else if (cur
== 0xfd) {
619 if (gdbstub_read_byte(
620 sp
+ 4, ((u8
*) &x
) + 0) < 0 ||
622 sp
+ 5, ((u8
*) &x
) + 1) < 0 ||
624 sp
+ 6, ((u8
*) &x
) + 2) < 0 ||
626 sp
+ 7, ((u8
*) &x
) + 3) < 0)
628 if (!__gdbstub_mark_bp((u8
*) x
, 0))
631 if (!__gdbstub_mark_bp(pc
+ 2, 0))
637 /* potential 3-byte conditional branches */
639 if (gdbstub_read_byte(pc
+ 1, &cur
) < 0)
641 if (!__gdbstub_mark_bp(pc
+ 3, 0))
644 if (cur
>= 0xe8 && cur
<= 0xeb) {
645 if (gdbstub_read_byte(
646 pc
+ 2, ((u8
*) &x
) + 0) < 0)
648 if ((x
< 0 || x
> 3) &&
649 !__gdbstub_mark_bp(pc
+ (s8
) x
, 1))
655 if (gdbstub_read_byte(pc
+ 1, &cur
) < 0)
660 if (gdbstub_read_byte(
661 pc
+ 2, ((u8
*) &x
) + 0) < 0 ||
663 pc
+ 3, ((u8
*) &x
) + 1) < 0)
665 if (!__gdbstub_mark_bp(pc
+ (s16
) x
, 0))
668 if (!__gdbstub_mark_bp(pc
+ 4, 0))
674 if (gdbstub_read_byte(pc
+ 1, &cur
) < 0)
678 if (gdbstub_read_byte(
679 pc
+ 2, ((u8
*) &x
) + 0) < 0 ||
681 pc
+ 3, ((u8
*) &x
) + 1) < 0 ||
683 pc
+ 4, ((u8
*) &x
) + 2) < 0 ||
685 pc
+ 5, ((u8
*) &x
) + 3) < 0)
687 if (!__gdbstub_mark_bp(
691 if (!__gdbstub_mark_bp(
700 gdbstub_bkpt("Step: %02x at %p; %02x at %p\n",
701 step_bp
[0].opcode
[0], step_bp
[0].addr
,
702 step_bp
[1].opcode
[0], step_bp
[1].addr
);
704 if (step_bp
[0].addr
) {
705 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
706 if (gdbstub_write_byte(0xF7, step_bp
[0].addr
+ 0) < 0 ||
707 gdbstub_write_byte(0xF7, step_bp
[0].addr
+ 1) < 0)
710 if (gdbstub_write_byte(0xFF, step_bp
[0].addr
+ 0) < 0)
715 if (step_bp
[1].addr
) {
716 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
717 if (gdbstub_write_byte(0xF7, step_bp
[1].addr
+ 0) < 0 ||
718 gdbstub_write_byte(0xF7, step_bp
[1].addr
+ 1) < 0)
721 if (gdbstub_write_byte(0xFF, step_bp
[1].addr
+ 0) < 0)
729 /* uh-oh - silly address alert, try and restore things */
730 __gdbstub_restore_bp();
733 #endif /* CONFIG_GDBSTUB_ALLOW_SINGLE_STEP */
735 #ifdef CONFIG_GDBSTUB_CONSOLE
737 void gdbstub_console_write(struct console
*con
, const char *p
, unsigned n
)
739 static const char gdbstub_cr
[] = { 0x0d };
752 while (n
> 0 && qty
< 20) {
753 mem2hex(p
, outbuf
+ qty
, 2, 0);
756 mem2hex(gdbstub_cr
, outbuf
+ qty
, 2, 0);
770 static kdev_t
gdbstub_console_dev(struct console
*con
)
772 return MKDEV(1, 3); /* /dev/null */
775 static struct console gdbstub_console
= {
777 .write
= gdbstub_console_write
,
778 .device
= gdbstub_console_dev
,
779 .flags
= CON_PRINTBUFFER
,
786 * Convert the memory pointed to by mem into hex, placing result in buf.
787 * - if successful, return a pointer to the last char put in buf (NUL)
788 * - in case of mem fault, return NULL
789 * may_fault is non-zero if we are reading from arbitrary memory, but is
790 * currently not used.
793 unsigned char *mem2hex(const void *_mem
, char *buf
, int count
, int may_fault
)
795 const u8
*mem
= _mem
;
798 if ((u32
) mem
& 1 && count
>= 1) {
799 if (gdbstub_read_byte(mem
, ch
) != 0)
801 buf
= hex_byte_pack(buf
, ch
[0]);
806 if ((u32
) mem
& 3 && count
>= 2) {
807 if (gdbstub_read_word(mem
, ch
) != 0)
809 buf
= hex_byte_pack(buf
, ch
[0]);
810 buf
= hex_byte_pack(buf
, ch
[1]);
816 if (gdbstub_read_dword(mem
, ch
) != 0)
818 buf
= hex_byte_pack(buf
, ch
[0]);
819 buf
= hex_byte_pack(buf
, ch
[1]);
820 buf
= hex_byte_pack(buf
, ch
[2]);
821 buf
= hex_byte_pack(buf
, ch
[3]);
827 if (gdbstub_read_word(mem
, ch
) != 0)
829 buf
= hex_byte_pack(buf
, ch
[0]);
830 buf
= hex_byte_pack(buf
, ch
[1]);
836 if (gdbstub_read_byte(mem
, ch
) != 0)
838 buf
= hex_byte_pack(buf
, ch
[0]);
846 * convert the hex array pointed to by buf into binary to be placed in mem
847 * return a pointer to the character AFTER the last byte written
848 * may_fault is non-zero if we are reading from arbitrary memory, but is
849 * currently not used.
852 const char *hex2mem(const char *buf
, void *_mem
, int count
, int may_fault
)
860 if ((u32
) mem
& 1 && count
>= 1) {
861 ch
.b
[0] = hex(*buf
++) << 4;
862 ch
.b
[0] |= hex(*buf
++);
863 if (gdbstub_write_byte(ch
.val
, mem
) != 0)
869 if ((u32
) mem
& 3 && count
>= 2) {
870 ch
.b
[0] = hex(*buf
++) << 4;
871 ch
.b
[0] |= hex(*buf
++);
872 ch
.b
[1] = hex(*buf
++) << 4;
873 ch
.b
[1] |= hex(*buf
++);
874 if (gdbstub_write_word(ch
.val
, mem
) != 0)
881 ch
.b
[0] = hex(*buf
++) << 4;
882 ch
.b
[0] |= hex(*buf
++);
883 ch
.b
[1] = hex(*buf
++) << 4;
884 ch
.b
[1] |= hex(*buf
++);
885 ch
.b
[2] = hex(*buf
++) << 4;
886 ch
.b
[2] |= hex(*buf
++);
887 ch
.b
[3] = hex(*buf
++) << 4;
888 ch
.b
[3] |= hex(*buf
++);
889 if (gdbstub_write_dword(ch
.val
, mem
) != 0)
896 ch
.b
[0] = hex(*buf
++) << 4;
897 ch
.b
[0] |= hex(*buf
++);
898 ch
.b
[1] = hex(*buf
++) << 4;
899 ch
.b
[1] |= hex(*buf
++);
900 if (gdbstub_write_word(ch
.val
, mem
) != 0)
907 ch
.b
[0] = hex(*buf
++) << 4;
908 ch
.b
[0] |= hex(*buf
++);
909 if (gdbstub_write_byte(ch
.val
, mem
) != 0)
917 * This table contains the mapping between MN10300 exception codes, and
918 * signals, which are primarily what GDB understands. It also indicates
919 * which hardware traps we need to commandeer when initializing the stub.
921 static const struct excep_to_sig_map
{
922 enum exception_code excep
; /* MN10300 exception code */
923 unsigned char signo
; /* Signal that we map this into */
924 } excep_to_sig_map
[] = {
925 { EXCEP_ITLBMISS
, SIGSEGV
},
926 { EXCEP_DTLBMISS
, SIGSEGV
},
927 { EXCEP_TRAP
, SIGTRAP
},
928 { EXCEP_ISTEP
, SIGTRAP
},
929 { EXCEP_IBREAK
, SIGTRAP
},
930 { EXCEP_OBREAK
, SIGTRAP
},
931 { EXCEP_UNIMPINS
, SIGILL
},
932 { EXCEP_UNIMPEXINS
, SIGILL
},
933 { EXCEP_MEMERR
, SIGSEGV
},
934 { EXCEP_MISALIGN
, SIGSEGV
},
935 { EXCEP_BUSERROR
, SIGBUS
},
936 { EXCEP_ILLINSACC
, SIGSEGV
},
937 { EXCEP_ILLDATACC
, SIGSEGV
},
938 { EXCEP_IOINSACC
, SIGSEGV
},
939 { EXCEP_PRIVINSACC
, SIGSEGV
},
940 { EXCEP_PRIVDATACC
, SIGSEGV
},
941 { EXCEP_FPU_DISABLED
, SIGFPE
},
942 { EXCEP_FPU_UNIMPINS
, SIGFPE
},
943 { EXCEP_FPU_OPERATION
, SIGFPE
},
944 { EXCEP_WDT
, SIGALRM
},
945 { EXCEP_NMI
, SIGQUIT
},
946 { EXCEP_IRQ_LEVEL0
, SIGINT
},
947 { EXCEP_IRQ_LEVEL1
, SIGINT
},
948 { EXCEP_IRQ_LEVEL2
, SIGINT
},
949 { EXCEP_IRQ_LEVEL3
, SIGINT
},
950 { EXCEP_IRQ_LEVEL4
, SIGINT
},
951 { EXCEP_IRQ_LEVEL5
, SIGINT
},
952 { EXCEP_IRQ_LEVEL6
, SIGINT
},
957 * convert the MN10300 exception code into a UNIX signal number
959 static int computeSignal(enum exception_code excep
)
961 const struct excep_to_sig_map
*map
;
963 for (map
= excep_to_sig_map
; map
->signo
; map
++)
964 if (map
->excep
== excep
)
967 return SIGHUP
; /* default for things we don't know about */
970 static u32 gdbstub_fpcr
, gdbstub_fpufs_array
[32];
975 static void gdbstub_store_fpu(void)
981 #ifdef CONFIG_MN10300_PROC_MN103E010
1000 "fmov fs14, (a1+)\n"
1001 "fmov fs15, (a1+)\n"
1002 "fmov fs16, (a1+)\n"
1003 "fmov fs17, (a1+)\n"
1004 "fmov fs18, (a1+)\n"
1005 "fmov fs19, (a1+)\n"
1006 "fmov fs20, (a1+)\n"
1007 "fmov fs21, (a1+)\n"
1008 "fmov fs22, (a1+)\n"
1009 "fmov fs23, (a1+)\n"
1010 "fmov fs24, (a1+)\n"
1011 "fmov fs25, (a1+)\n"
1012 "fmov fs26, (a1+)\n"
1013 "fmov fs27, (a1+)\n"
1014 "fmov fs28, (a1+)\n"
1015 "fmov fs29, (a1+)\n"
1016 "fmov fs30, (a1+)\n"
1017 "fmov fs31, (a1+)\n"
1019 : "=d"(gdbstub_fpcr
)
1020 : "g" (&gdbstub_fpufs_array
), "i"(EPSW_FE
)
1029 static void gdbstub_load_fpu(void)
1035 #ifdef CONFIG_MN10300_PROC_MN103E010
1050 "fmov (a1+), fs10\n"
1051 "fmov (a1+), fs11\n"
1052 "fmov (a1+), fs12\n"
1053 "fmov (a1+), fs13\n"
1054 "fmov (a1+), fs14\n"
1055 "fmov (a1+), fs15\n"
1056 "fmov (a1+), fs16\n"
1057 "fmov (a1+), fs17\n"
1058 "fmov (a1+), fs18\n"
1059 "fmov (a1+), fs19\n"
1060 "fmov (a1+), fs20\n"
1061 "fmov (a1+), fs21\n"
1062 "fmov (a1+), fs22\n"
1063 "fmov (a1+), fs23\n"
1064 "fmov (a1+), fs24\n"
1065 "fmov (a1+), fs25\n"
1066 "fmov (a1+), fs26\n"
1067 "fmov (a1+), fs27\n"
1068 "fmov (a1+), fs28\n"
1069 "fmov (a1+), fs29\n"
1070 "fmov (a1+), fs30\n"
1071 "fmov (a1+), fs31\n"
1074 : "g" (&gdbstub_fpufs_array
), "i"(EPSW_FE
), "d"(gdbstub_fpcr
)
1081 * set a software breakpoint
1083 int gdbstub_set_breakpoint(u8
*addr
, int len
)
1085 int bkpt
, loop
, xloop
;
1087 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1088 len
= (len
+ 1) & ~1;
1091 gdbstub_bkpt("setbkpt(%p,%d)\n", addr
, len
);
1093 for (bkpt
= 255; bkpt
>= 0; bkpt
--)
1094 if (!gdbstub_bkpts
[bkpt
].addr
)
1099 for (loop
= 0; loop
< len
; loop
++)
1100 if (gdbstub_read_byte(&addr
[loop
],
1101 &gdbstub_bkpts
[bkpt
].origbytes
[loop
]
1105 gdbstub_flush_caches
= 1;
1107 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1108 for (loop
= 0; loop
< len
; loop
++)
1109 if (gdbstub_write_byte(0xF7, &addr
[loop
]) < 0)
1112 for (loop
= 0; loop
< len
; loop
++)
1113 if (gdbstub_write_byte(0xFF, &addr
[loop
]) < 0)
1117 gdbstub_bkpts
[bkpt
].addr
= addr
;
1118 gdbstub_bkpts
[bkpt
].len
= len
;
1120 gdbstub_bkpt("Set BKPT[%02x]: %p-%p {%02x%02x%02x%02x%02x%02x%02x}\n",
1122 gdbstub_bkpts
[bkpt
].addr
,
1123 gdbstub_bkpts
[bkpt
].addr
+ gdbstub_bkpts
[bkpt
].len
- 1,
1124 gdbstub_bkpts
[bkpt
].origbytes
[0],
1125 gdbstub_bkpts
[bkpt
].origbytes
[1],
1126 gdbstub_bkpts
[bkpt
].origbytes
[2],
1127 gdbstub_bkpts
[bkpt
].origbytes
[3],
1128 gdbstub_bkpts
[bkpt
].origbytes
[4],
1129 gdbstub_bkpts
[bkpt
].origbytes
[5],
1130 gdbstub_bkpts
[bkpt
].origbytes
[6]
1136 for (xloop
= 0; xloop
< loop
; xloop
++)
1137 gdbstub_write_byte(gdbstub_bkpts
[bkpt
].origbytes
[xloop
],
1143 * clear a software breakpoint
1145 int gdbstub_clear_breakpoint(u8
*addr
, int len
)
1149 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1150 len
= (len
+ 1) & ~1;
1153 gdbstub_bkpt("clearbkpt(%p,%d)\n", addr
, len
);
1155 for (bkpt
= 255; bkpt
>= 0; bkpt
--)
1156 if (gdbstub_bkpts
[bkpt
].addr
== addr
&&
1157 gdbstub_bkpts
[bkpt
].len
== len
)
1162 gdbstub_bkpts
[bkpt
].addr
= NULL
;
1164 gdbstub_flush_caches
= 1;
1166 for (loop
= 0; loop
< len
; loop
++)
1167 if (gdbstub_write_byte(gdbstub_bkpts
[bkpt
].origbytes
[loop
],
1175 * This function does all command processing for interfacing to gdb
1176 * - returns 0 if the exception should be skipped, -ERROR otherwise.
1178 static int gdbstub(struct pt_regs
*regs
, enum exception_code excep
)
1180 unsigned long *stack
;
1181 unsigned long epsw
, mdr
;
1190 if (excep
== EXCEP_FPU_DISABLED
)
1193 gdbstub_flush_caches
= 0;
1195 mn10300_set_gdbleds(1);
1197 asm volatile("mov mdr,%0" : "=d"(mdr
));
1198 local_save_flags(epsw
);
1199 arch_local_change_intr_mask_level(
1200 NUM2EPSW_IM(CONFIG_DEBUGGER_IRQ_LEVEL
+ 1));
1202 gdbstub_store_fpu();
1204 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1205 /* skip the initial pause loop */
1206 if (regs
->pc
== (unsigned long) __gdbstub_pause
)
1207 regs
->pc
= (unsigned long) start_kernel
;
1210 /* if we were single stepping, restore the opcodes hoisted for the
1213 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
1214 if ((step_bp
[0].addr
&& step_bp
[0].addr
== (u8
*) regs
->pc
) ||
1215 (step_bp
[1].addr
&& step_bp
[1].addr
== (u8
*) regs
->pc
))
1218 __gdbstub_restore_bp();
1221 if (gdbstub_rx_unget
) {
1223 if (gdbstub_rx_unget
!= 3)
1224 goto packet_waiting
;
1225 gdbstub_rx_unget
= 0;
1228 stack
= (unsigned long *) regs
->sp
;
1229 sigval
= broke
? SIGTRAP
: computeSignal(excep
);
1231 /* send information about a BUG() */
1232 if (!user_mode(regs
) && excep
== EXCEP_SYSCALL15
) {
1233 const struct bug_entry
*bug
;
1235 bug
= find_bug(regs
->pc
);
1238 length
= snprintf(trans_buffer
, sizeof(trans_buffer
),
1239 "BUG() at address %lx\n", regs
->pc
);
1243 length
= snprintf(trans_buffer
, sizeof(trans_buffer
),
1244 "BUG() at address %lx (%s:%d)\n",
1245 regs
->pc
, bug
->file
, bug
->line
);
1248 ptr
= output_buffer
;
1250 ptr
= mem2hex(trans_buffer
, ptr
, length
, 0);
1252 putpacket(output_buffer
);
1256 } else if (regs
->pc
== (unsigned long) __gdbstub_bug_trap
) {
1257 regs
->pc
= regs
->mdr
;
1262 * send a message to the debugger's user saying what happened if it may
1263 * not be clear cut (we can't map exceptions onto signals properly)
1265 if (sigval
!= SIGINT
&& sigval
!= SIGTRAP
&& sigval
!= SIGILL
) {
1266 static const char title
[] = "Excep ", tbcberr
[] = "BCBERR ";
1267 static const char crlf
[] = "\r\n";
1269 u32 bcberr
= BCBERR
;
1271 ptr
= output_buffer
;
1273 ptr
= mem2hex(title
, ptr
, sizeof(title
) - 1, 0);
1275 hx
= hex_asc_hi(excep
>> 8);
1276 ptr
= hex_byte_pack(ptr
, hx
);
1277 hx
= hex_asc_lo(excep
>> 8);
1278 ptr
= hex_byte_pack(ptr
, hx
);
1279 hx
= hex_asc_hi(excep
);
1280 ptr
= hex_byte_pack(ptr
, hx
);
1281 hx
= hex_asc_lo(excep
);
1282 ptr
= hex_byte_pack(ptr
, hx
);
1284 ptr
= mem2hex(crlf
, ptr
, sizeof(crlf
) - 1, 0);
1286 putpacket(output_buffer
); /* send it off... */
1289 ptr
= output_buffer
;
1291 ptr
= mem2hex(tbcberr
, ptr
, sizeof(tbcberr
) - 1, 0);
1293 hx
= hex_asc_hi(bcberr
>> 24);
1294 ptr
= hex_byte_pack(ptr
, hx
);
1295 hx
= hex_asc_lo(bcberr
>> 24);
1296 ptr
= hex_byte_pack(ptr
, hx
);
1297 hx
= hex_asc_hi(bcberr
>> 16);
1298 ptr
= hex_byte_pack(ptr
, hx
);
1299 hx
= hex_asc_lo(bcberr
>> 16);
1300 ptr
= hex_byte_pack(ptr
, hx
);
1301 hx
= hex_asc_hi(bcberr
>> 8);
1302 ptr
= hex_byte_pack(ptr
, hx
);
1303 hx
= hex_asc_lo(bcberr
>> 8);
1304 ptr
= hex_byte_pack(ptr
, hx
);
1305 hx
= hex_asc_hi(bcberr
);
1306 ptr
= hex_byte_pack(ptr
, hx
);
1307 hx
= hex_asc_lo(bcberr
);
1308 ptr
= hex_byte_pack(ptr
, hx
);
1310 ptr
= mem2hex(crlf
, ptr
, sizeof(crlf
) - 1, 0);
1312 putpacket(output_buffer
); /* send it off... */
1316 * tell the debugger that an exception has occurred
1318 ptr
= output_buffer
;
1321 * Send trap type (converted to signal)
1324 ptr
= hex_byte_pack(ptr
, sigval
);
1329 ptr
= hex_byte_pack(ptr
, GDB_REGID_PC
);
1331 ptr
= mem2hex(®s
->pc
, ptr
, 4, 0);
1335 * Send frame pointer
1337 ptr
= hex_byte_pack(ptr
, GDB_REGID_FP
);
1339 ptr
= mem2hex(®s
->a3
, ptr
, 4, 0);
1343 * Send stack pointer
1345 ssp
= (unsigned long) (regs
+ 1);
1346 ptr
= hex_byte_pack(ptr
, GDB_REGID_SP
);
1348 ptr
= mem2hex(&ssp
, ptr
, 4, 0);
1352 putpacket(output_buffer
); /* send it off... */
1356 * Wait for input from remote GDB
1359 output_buffer
[0] = 0;
1360 getpacket(input_buffer
);
1362 switch (input_buffer
[0]) {
1363 /* request repeat of last signal number */
1365 output_buffer
[0] = 'S';
1366 output_buffer
[1] = hex_asc_hi(sigval
);
1367 output_buffer
[2] = hex_asc_lo(sigval
);
1368 output_buffer
[3] = 0;
1372 /* toggle debug flag */
1376 * Return the value of the CPU registers
1380 ssp
= (u32
) (regs
+ 1);
1381 ptr
= output_buffer
;
1382 ptr
= mem2hex(®s
->d0
, ptr
, 4, 0);
1383 ptr
= mem2hex(®s
->d1
, ptr
, 4, 0);
1384 ptr
= mem2hex(®s
->d2
, ptr
, 4, 0);
1385 ptr
= mem2hex(®s
->d3
, ptr
, 4, 0);
1386 ptr
= mem2hex(®s
->a0
, ptr
, 4, 0);
1387 ptr
= mem2hex(®s
->a1
, ptr
, 4, 0);
1388 ptr
= mem2hex(®s
->a2
, ptr
, 4, 0);
1389 ptr
= mem2hex(®s
->a3
, ptr
, 4, 0);
1391 ptr
= mem2hex(&ssp
, ptr
, 4, 0); /* 8 */
1392 ptr
= mem2hex(®s
->pc
, ptr
, 4, 0);
1393 ptr
= mem2hex(®s
->mdr
, ptr
, 4, 0);
1394 ptr
= mem2hex(®s
->epsw
, ptr
, 4, 0);
1395 ptr
= mem2hex(®s
->lir
, ptr
, 4, 0);
1396 ptr
= mem2hex(®s
->lar
, ptr
, 4, 0);
1397 ptr
= mem2hex(®s
->mdrq
, ptr
, 4, 0);
1399 ptr
= mem2hex(®s
->e0
, ptr
, 4, 0); /* 15 */
1400 ptr
= mem2hex(®s
->e1
, ptr
, 4, 0);
1401 ptr
= mem2hex(®s
->e2
, ptr
, 4, 0);
1402 ptr
= mem2hex(®s
->e3
, ptr
, 4, 0);
1403 ptr
= mem2hex(®s
->e4
, ptr
, 4, 0);
1404 ptr
= mem2hex(®s
->e5
, ptr
, 4, 0);
1405 ptr
= mem2hex(®s
->e6
, ptr
, 4, 0);
1406 ptr
= mem2hex(®s
->e7
, ptr
, 4, 0);
1408 ptr
= mem2hex(&ssp
, ptr
, 4, 0);
1409 ptr
= mem2hex(®s
, ptr
, 4, 0);
1410 ptr
= mem2hex(®s
->sp
, ptr
, 4, 0);
1411 ptr
= mem2hex(®s
->mcrh
, ptr
, 4, 0); /* 26 */
1412 ptr
= mem2hex(®s
->mcrl
, ptr
, 4, 0);
1413 ptr
= mem2hex(®s
->mcvf
, ptr
, 4, 0);
1415 ptr
= mem2hex(&gdbstub_fpcr
, ptr
, 4, 0); /* 29 - FPCR */
1416 ptr
= mem2hex(&zero
, ptr
, 4, 0);
1417 ptr
= mem2hex(&zero
, ptr
, 4, 0);
1418 for (loop
= 0; loop
< 32; loop
++)
1419 ptr
= mem2hex(&gdbstub_fpufs_array
[loop
],
1420 ptr
, 4, 0); /* 32 - FS0-31 */
1425 * set the value of the CPU registers - return OK
1431 ptr
= &input_buffer
[1];
1432 ptr
= hex2mem(ptr
, ®s
->d0
, 4, 0);
1433 ptr
= hex2mem(ptr
, ®s
->d1
, 4, 0);
1434 ptr
= hex2mem(ptr
, ®s
->d2
, 4, 0);
1435 ptr
= hex2mem(ptr
, ®s
->d3
, 4, 0);
1436 ptr
= hex2mem(ptr
, ®s
->a0
, 4, 0);
1437 ptr
= hex2mem(ptr
, ®s
->a1
, 4, 0);
1438 ptr
= hex2mem(ptr
, ®s
->a2
, 4, 0);
1439 ptr
= hex2mem(ptr
, ®s
->a3
, 4, 0);
1441 ptr
= hex2mem(ptr
, &ssp
, 4, 0); /* 8 */
1442 ptr
= hex2mem(ptr
, ®s
->pc
, 4, 0);
1443 ptr
= hex2mem(ptr
, ®s
->mdr
, 4, 0);
1444 ptr
= hex2mem(ptr
, ®s
->epsw
, 4, 0);
1445 ptr
= hex2mem(ptr
, ®s
->lir
, 4, 0);
1446 ptr
= hex2mem(ptr
, ®s
->lar
, 4, 0);
1447 ptr
= hex2mem(ptr
, ®s
->mdrq
, 4, 0);
1449 ptr
= hex2mem(ptr
, ®s
->e0
, 4, 0); /* 15 */
1450 ptr
= hex2mem(ptr
, ®s
->e1
, 4, 0);
1451 ptr
= hex2mem(ptr
, ®s
->e2
, 4, 0);
1452 ptr
= hex2mem(ptr
, ®s
->e3
, 4, 0);
1453 ptr
= hex2mem(ptr
, ®s
->e4
, 4, 0);
1454 ptr
= hex2mem(ptr
, ®s
->e5
, 4, 0);
1455 ptr
= hex2mem(ptr
, ®s
->e6
, 4, 0);
1456 ptr
= hex2mem(ptr
, ®s
->e7
, 4, 0);
1458 ptr
= hex2mem(ptr
, &ssp
, 4, 0);
1459 ptr
= hex2mem(ptr
, &zero
, 4, 0);
1460 ptr
= hex2mem(ptr
, ®s
->sp
, 4, 0);
1461 ptr
= hex2mem(ptr
, ®s
->mcrh
, 4, 0); /* 26 */
1462 ptr
= hex2mem(ptr
, ®s
->mcrl
, 4, 0);
1463 ptr
= hex2mem(ptr
, ®s
->mcvf
, 4, 0);
1465 ptr
= hex2mem(ptr
, &zero
, 4, 0); /* 29 - FPCR */
1466 ptr
= hex2mem(ptr
, &zero
, 4, 0);
1467 ptr
= hex2mem(ptr
, &zero
, 4, 0);
1468 for (loop
= 0; loop
< 32; loop
++) /* 32 - FS0-31 */
1469 ptr
= hex2mem(ptr
, &zero
, 4, 0);
1473 * See if the stack pointer has moved. If so, then copy
1474 * the saved locals and ins to the new location.
1476 unsigned long *newsp
= (unsigned long *) registers
[SP
];
1478 sp
= memcpy(newsp
, sp
, 16 * 4);
1481 gdbstub_strcpy(output_buffer
, "OK");
1486 * mAA..AA,LLLL Read LLLL bytes at address AA..AA
1489 ptr
= &input_buffer
[1];
1491 if (hexToInt(&ptr
, &addr
) &&
1493 hexToInt(&ptr
, &length
)
1495 if (mem2hex((char *) addr
, output_buffer
,
1498 gdbstub_strcpy(output_buffer
, "E03");
1500 gdbstub_strcpy(output_buffer
, "E01");
1505 * MAA..AA,LLLL: Write LLLL bytes at address AA.AA
1509 ptr
= &input_buffer
[1];
1511 if (hexToInt(&ptr
, &addr
) &&
1513 hexToInt(&ptr
, &length
) &&
1516 if (hex2mem(ptr
, (char *) addr
, length
, 1))
1517 gdbstub_strcpy(output_buffer
, "OK");
1519 gdbstub_strcpy(output_buffer
, "E03");
1521 gdbstub_flush_caches
= 1;
1523 gdbstub_strcpy(output_buffer
, "E02");
1528 * cAA..AA Continue at address AA..AA(optional)
1531 /* try to read optional parameter, pc unchanged if no
1534 ptr
= &input_buffer
[1];
1535 if (hexToInt(&ptr
, &addr
))
1543 goto done
; /* just continue */
1546 * Reset the whole machine (FIXME: system dependent)
1552 * Step to next instruction
1555 /* Using the T flag doesn't seem to perform single
1556 * stepping (it seems to wind up being caught by the
1557 * JTAG unit), so we have to use breakpoints and
1560 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
1561 if (gdbstub_single_step(regs
) < 0)
1562 /* ignore any fault error for now */
1563 gdbstub_printk("unable to set single-step"
1567 gdbstub_strcpy(output_buffer
, "E01");
1572 * Set baud rate (bBB)
1578 ptr
= &input_buffer
[1];
1579 if (!hexToInt(&ptr
, &baudrate
)) {
1580 gdbstub_strcpy(output_buffer
, "B01");
1585 /* ACK before changing speed */
1587 gdbstub_io_set_baud(baudrate
);
1596 ptr
= &input_buffer
[1];
1598 if (!hexToInt(&ptr
, &loop
) || *ptr
++ != ',' ||
1599 !hexToInt(&ptr
, &addr
) || *ptr
++ != ',' ||
1600 !hexToInt(&ptr
, &length
)
1602 gdbstub_strcpy(output_buffer
, "E01");
1606 /* only support software breakpoints */
1607 gdbstub_strcpy(output_buffer
, "E03");
1611 (unsigned long) addr
< 4096)
1614 if (gdbstub_set_breakpoint((u8
*) addr
, length
) < 0)
1617 gdbstub_strcpy(output_buffer
, "OK");
1624 ptr
= &input_buffer
[1];
1626 if (!hexToInt(&ptr
, &loop
) || *ptr
++ != ',' ||
1627 !hexToInt(&ptr
, &addr
) || *ptr
++ != ',' ||
1628 !hexToInt(&ptr
, &length
)
1630 gdbstub_strcpy(output_buffer
, "E01");
1634 /* only support software breakpoints */
1635 gdbstub_strcpy(output_buffer
, "E03");
1639 (unsigned long) addr
< 4096)
1642 if (gdbstub_clear_breakpoint((u8
*) addr
, length
) < 0)
1645 gdbstub_strcpy(output_buffer
, "OK");
1649 gdbstub_proto("### GDB Unsupported Cmd '%s'\n",
1654 /* reply to the request */
1655 putpacket(output_buffer
);
1660 * Need to flush the instruction cache here, as we may
1661 * have deposited a breakpoint, and the icache probably
1662 * has no way of knowing that a data ref to some location
1663 * may have changed something that is in the instruction
1665 * NB: We flush both caches, just to be sure...
1667 if (gdbstub_flush_caches
)
1668 debugger_local_cache_flushinv();
1671 mn10300_set_gdbleds(0);
1672 if (excep
== EXCEP_NMI
)
1675 touch_softlockup_watchdog();
1677 local_irq_restore(epsw
);
1682 * Determine if we hit a debugger special breakpoint that needs skipping over
1685 int at_debugger_breakpoint(struct pt_regs
*regs
)
1691 * handle event interception
1693 asmlinkage
int debugger_intercept(enum exception_code excep
,
1694 int signo
, int si_code
, struct pt_regs
*regs
)
1696 static u8 notfirst
= 1;
1700 gdbstub_printk("--> gdbstub reentered itself\n");
1705 asm("mov mdr,%0" : "=d"(mdr
));
1708 "--> debugger_intercept(%p,%04x) [MDR=%lx PC=%lx]\n",
1709 regs
, excep
, mdr
, regs
->pc
);
1712 "PC: %08lx EPSW: %08lx SSP: %08lx mode: %s\n",
1713 regs
->pc
, regs
->epsw
, (unsigned long) &ret
,
1714 user_mode(regs
) ? "User" : "Super");
1716 "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
1717 regs
->d0
, regs
->d1
, regs
->d2
, regs
->d3
);
1719 "a0: %08lx a1: %08lx a2: %08lx a3: %08lx\n",
1720 regs
->a0
, regs
->a1
, regs
->a2
, regs
->a3
);
1722 "e0: %08lx e1: %08lx e2: %08lx e3: %08lx\n",
1723 regs
->e0
, regs
->e1
, regs
->e2
, regs
->e3
);
1725 "e4: %08lx e5: %08lx e6: %08lx e7: %08lx\n",
1726 regs
->e4
, regs
->e5
, regs
->e6
, regs
->e7
);
1728 "lar: %08lx lir: %08lx mdr: %08lx usp: %08lx\n",
1729 regs
->lar
, regs
->lir
, regs
->mdr
, regs
->sp
);
1731 "cvf: %08lx crl: %08lx crh: %08lx drq: %08lx\n",
1732 regs
->mcvf
, regs
->mcrl
, regs
->mcrh
, regs
->mdrq
);
1734 "threadinfo=%p task=%p)\n",
1735 current_thread_info(), current
);
1740 ret
= gdbstub(regs
, excep
);
1742 gdbstub_entry("<-- debugger_intercept()\n");
1748 * handle the GDB stub itself causing an exception
1750 asmlinkage
void gdbstub_exception(struct pt_regs
*regs
,
1751 enum exception_code excep
)
1755 asm("mov mdr,%0" : "=d"(mdr
));
1756 gdbstub_entry("--> gdbstub exception({%p},%04x) [MDR=%lx]\n",
1759 while ((unsigned long) regs
== 0xffffffff) {}
1761 /* handle guarded memory accesses where we know it might fault */
1762 if (regs
->pc
== (unsigned) gdbstub_read_byte_guard
) {
1763 regs
->pc
= (unsigned) gdbstub_read_byte_cont
;
1767 if (regs
->pc
== (unsigned) gdbstub_read_word_guard
) {
1768 regs
->pc
= (unsigned) gdbstub_read_word_cont
;
1772 if (regs
->pc
== (unsigned) gdbstub_read_dword_guard
) {
1773 regs
->pc
= (unsigned) gdbstub_read_dword_cont
;
1777 if (regs
->pc
== (unsigned) gdbstub_write_byte_guard
) {
1778 regs
->pc
= (unsigned) gdbstub_write_byte_cont
;
1782 if (regs
->pc
== (unsigned) gdbstub_write_word_guard
) {
1783 regs
->pc
= (unsigned) gdbstub_write_word_cont
;
1787 if (regs
->pc
== (unsigned) gdbstub_write_dword_guard
) {
1788 regs
->pc
= (unsigned) gdbstub_write_dword_cont
;
1792 gdbstub_printk("\n### GDB stub caused an exception ###\n");
1794 /* something went horribly wrong */
1796 show_registers(regs
);
1798 panic("GDB Stub caused an unexpected exception - can't continue\n");
1800 /* we caught an attempt by the stub to access silly memory */
1802 gdbstub_entry("<-- gdbstub exception() = EFAULT\n");
1808 * send an exit message to GDB
1810 void gdbstub_exit(int status
)
1812 unsigned char checksum
;
1817 output_buffer
[0] = 'W';
1818 output_buffer
[1] = hex_asc_hi(status
);
1819 output_buffer
[2] = hex_asc_lo(status
);
1820 output_buffer
[3] = 0;
1822 gdbstub_io_tx_char('$');
1826 while ((ch
= output_buffer
[count
]) != 0) {
1827 gdbstub_io_tx_char(ch
);
1832 gdbstub_io_tx_char('#');
1833 gdbstub_io_tx_char(hex_asc_hi(checksum
));
1834 gdbstub_io_tx_char(hex_asc_lo(checksum
));
1836 /* make sure the output is flushed, or else RedBoot might clobber it */
1837 gdbstub_io_tx_flush();
1843 * initialise the GDB stub
1845 asmlinkage
void __init
gdbstub_init(void)
1847 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1854 printk(KERN_INFO
"%s", gdbstub_banner
);
1858 gdbstub_entry("--> gdbstub_init\n");
1860 /* try to talk to GDB (or anyone insane enough to want to type GDB
1861 * protocol by hand) */
1862 gdbstub_io("### GDB Tx ACK\n");
1863 gdbstub_io_tx_char('+'); /* 'hello world' */
1865 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1866 gdbstub_printk("GDB Stub waiting for packet\n");
1868 /* in case GDB is started before us, ACK any packets that are already
1869 * sitting there (presumably "$?#xx")
1871 do { gdbstub_io_rx_char(&ch
, 0); } while (ch
!= '$');
1872 do { gdbstub_io_rx_char(&ch
, 0); } while (ch
!= '#');
1873 /* eat first csum byte */
1874 do { ret
= gdbstub_io_rx_char(&ch
, 0); } while (ret
!= 0);
1875 /* eat second csum byte */
1876 do { ret
= gdbstub_io_rx_char(&ch
, 0); } while (ret
!= 0);
1878 gdbstub_io("### GDB Tx NAK\n");
1879 gdbstub_io_tx_char('-'); /* NAK it */
1882 printk("GDB Stub ready\n");
1886 gdbstub_entry("<-- gdbstub_init\n");
1890 * register the console at a more appropriate time
1892 #ifdef CONFIG_GDBSTUB_CONSOLE
1893 static int __init
gdbstub_postinit(void)
1895 printk(KERN_NOTICE
"registering console\n");
1896 register_console(&gdbstub_console
);
1900 __initcall(gdbstub_postinit
);
1904 * handle character reception on GDB serial port
1905 * - jump into the GDB stub if BREAK is detected on the serial line
1907 asmlinkage
void gdbstub_rx_irq(struct pt_regs
*regs
, enum exception_code excep
)
1912 gdbstub_entry("--> gdbstub_rx_irq\n");
1915 ret
= gdbstub_io_rx_char(&ch
, 1);
1916 if (ret
!= -EIO
&& ret
!= -EAGAIN
) {
1918 gdbstub_rx_unget
= ch
;
1919 gdbstub(regs
, excep
);
1921 } while (ret
!= -EAGAIN
);
1923 gdbstub_entry("<-- gdbstub_rx_irq\n");