123 #include <linux/string.h>
124 #include <linux/kernel.h>
125 #include <linux/signal.h>
126 #include <linux/sched.h>
132 #include <asm/pgtable.h>
133 #include <asm/gdb-stub.h>
134 #include <asm/exceptions.h>
136 #include <asm/serial-regs.h>
137 #include <asm/busctl-regs.h>
138 #include <unit/leds.h>
139 #include <unit/serial.h>
142 #undef GDBSTUB_USE_F7F7_AS_BREAKPOINT
150 static const char gdbstub_banner[] =
151 "Linux/MN10300 GDB Stub (c) RedHat 2007\n";
160 static u8 gdbstub_flush_caches;
161 static char input_buffer[
BUFMAX];
163 static char trans_buffer[
BUFMAX];
176 static void getpacket(
char *
buffer);
177 static int putpacket(
char *
buffer);
179 static int hex(
unsigned char ch);
180 static int hexToInt(
char **
ptr,
int *intValue);
181 static unsigned char *mem2hex(
const void *
mem,
char *
buf,
int count,
183 static const char *hex2mem(
const char *
buf,
void *_mem,
int count,
189 static int hex(
unsigned char ch)
191 if (ch >=
'a' && ch <=
'f')
192 return ch -
'a' + 10;
193 if (ch >=
'0' && ch <=
'9')
195 if (ch >=
'A' && ch <=
'F')
196 return ch -
'A' + 10;
200 #ifdef CONFIG_GDBSTUB_DEBUGGING
204 __debug_to_serial(p, n);
215 len =
vsnprintf(trans_buffer,
sizeof(trans_buffer), fmt, args);
222 static inline char *gdbstub_strcpy(
char *
dst,
const char *
src)
225 while ((dst[loop] = src[loop]))
233 static void getpacket(
char *
buffer)
236 unsigned char xmitcsum;
277 if (count >=
BUFMAX || error)
286 xmitcsum = hex(ch) << 4;
296 " Skipping packet\n");
303 if (checksum != xmitcsum) {
309 gdbstub_proto(
"### GDB Rx '$%s#%02x' ###\n", buffer, checksum);
317 if (buffer[2] ==
':') {
325 while (buffer[count])
327 for (i = 3; i <=
count; i++)
328 buffer[i - 3] = buffer[i];
340 static int putpacket(
char *buffer)
356 while ((ch = buffer[count]) != 0) {
367 ch ==
'-' && (
gdbstub_io(
"### GDB Rx NAK\n"), 0),
368 ch !=
'-' && ch !=
'+' &&
370 ch !=
'+' && ch !=
'$');
378 gdbstub_rx_unget = ch;
386 static int hexToInt(
char **
ptr,
int *intValue)
394 hexValue = hex(**ptr);
398 *intValue = (*intValue << 4) | hexValue;
407 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
415 static struct gdb_bp_save {
420 static const unsigned char gdbstub_insn_sizes[256] =
423 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3,
424 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
425 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3,
426 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1,
427 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2,
428 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
429 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
430 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
431 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
432 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
433 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
434 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
435 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2,
436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
437 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
438 0, 2, 2, 2, 2, 2, 2, 4, 0, 3, 0, 4, 0, 6, 7, 1
441 static int __gdbstub_mark_bp(
u8 *
addr,
int ix)
447 if (((
u8 *) 0x80000000UL <= addr) && (addr < (
u8 *) 0xa0000000UL))
456 step_bp[ix].addr =
addr;
460 static inline void __gdbstub_restore_bp(
void)
462 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
463 if (step_bp[0].addr) {
467 if (step_bp[1].addr) {
478 gdbstub_flush_caches = 1;
480 step_bp[0].addr =
NULL;
481 step_bp[0].opcode[0] = 0;
482 step_bp[0].opcode[1] = 0;
483 step_bp[1].addr =
NULL;
484 step_bp[1].opcode[0] = 0;
485 step_bp[1].opcode[1] = 0;
491 static int gdbstub_single_step(
struct pt_regs *
regs)
497 step_bp[0].addr =
NULL;
498 step_bp[0].opcode[0] = 0;
499 step_bp[0].opcode[1] = 0;
500 step_bp[1].addr =
NULL;
501 step_bp[1].opcode[0] = 0;
502 step_bp[1].opcode[1] = 0;
505 pc = (
u8 *) regs->
pc;
506 sp = (
u8 *) (regs + 1);
510 gdbstub_bkpt(
"Single Step from %p { %02x }\n", pc, cur);
512 gdbstub_flush_caches = 1;
514 size = gdbstub_insn_sizes[
cur];
516 if (!__gdbstub_mark_bp(pc + size, 0))
524 if (!__gdbstub_mark_bp(pc + 2, 0))
526 if ((x < 0 || x > 2) &&
527 !__gdbstub_mark_bp(pc + (
s8) x, 1))
533 if (!__gdbstub_mark_bp(pc + 1, 0))
535 if (regs->
pc != regs->
lar &&
536 !__gdbstub_mark_bp((
u8 *) regs->
lar, 1))
543 if (!__gdbstub_mark_bp(pc + 1, 0))
553 if (!__gdbstub_mark_bp(pc + (
s16) x, 0))
565 if (!__gdbstub_mark_bp(pc + (
s32) x, 0))
571 if (!__gdbstub_mark_bp((
u8 *) regs->
mdr, 0))
585 if (!__gdbstub_mark_bp((
u8 *) x, 0))
593 if (cur >= 0xf0 && cur <= 0xf7) {
596 case 0: x = regs->
a0;
break;
597 case 1: x = regs->
a1;
break;
598 case 2: x = regs->
a2;
break;
599 case 3: x = regs->
a3;
break;
601 if (!__gdbstub_mark_bp((
u8 *) x, 0))
603 }
else if (cur == 0xfc) {
606 sp + 0, ((
u8 *) &x) + 0) < 0 ||
608 sp + 1, ((
u8 *) &x) + 1) < 0 ||
610 sp + 2, ((
u8 *) &x) + 2) < 0 ||
612 sp + 3, ((
u8 *) &x) + 3) < 0)
614 if (!__gdbstub_mark_bp((
u8 *) x, 0))
616 }
else if (cur == 0xfd) {
619 sp + 4, ((
u8 *) &x) + 0) < 0 ||
621 sp + 5, ((
u8 *) &x) + 1) < 0 ||
623 sp + 6, ((
u8 *) &x) + 2) < 0 ||
625 sp + 7, ((
u8 *) &x) + 3) < 0)
627 if (!__gdbstub_mark_bp((
u8 *) x, 0))
630 if (!__gdbstub_mark_bp(pc + 2, 0))
640 if (!__gdbstub_mark_bp(pc + 3, 0))
643 if (cur >= 0xe8 && cur <= 0xeb) {
645 pc + 2, ((
u8 *) &x) + 0) < 0)
647 if ((x < 0 || x > 3) &&
648 !__gdbstub_mark_bp(pc + (
s8) x, 1))
660 pc + 2, ((
u8 *) &x) + 0) < 0 ||
662 pc + 3, ((
u8 *) &x) + 1) < 0)
664 if (!__gdbstub_mark_bp(pc + (
s16) x, 0))
667 if (!__gdbstub_mark_bp(pc + 4, 0))
678 pc + 2, ((
u8 *) &x) + 0) < 0 ||
680 pc + 3, ((
u8 *) &x) + 1) < 0 ||
682 pc + 4, ((
u8 *) &x) + 2) < 0 ||
684 pc + 5, ((
u8 *) &x) + 3) < 0)
686 if (!__gdbstub_mark_bp(
690 if (!__gdbstub_mark_bp(
700 step_bp[0].opcode[0], step_bp[0].addr,
701 step_bp[1].opcode[0], step_bp[1].addr);
703 if (step_bp[0].addr) {
704 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
714 if (step_bp[1].addr) {
715 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
729 __gdbstub_restore_bp();
734 #ifdef CONFIG_GDBSTUB_CONSOLE
738 static const char gdbstub_cr[] = { 0x0d };
751 while (n > 0 && qty < 20) {
752 mem2hex(p, outbuf + qty, 2, 0);
755 mem2hex(gdbstub_cr, outbuf + qty, 2, 0);
769 static kdev_t gdbstub_console_dev(
struct console *con)
774 static struct console gdbstub_console = {
777 .device = gdbstub_console_dev,
792 unsigned char *mem2hex(
const void *_mem,
char *
buf,
int count,
int may_fault)
794 const u8 *
mem = _mem;
797 if ((
u32) mem & 1 && count >= 1) {
800 buf = hex_byte_pack(buf, ch[0]);
805 if ((
u32) mem & 3 && count >= 2) {
808 buf = hex_byte_pack(buf, ch[0]);
809 buf = hex_byte_pack(buf, ch[1]);
817 buf = hex_byte_pack(buf, ch[0]);
818 buf = hex_byte_pack(buf, ch[1]);
819 buf = hex_byte_pack(buf, ch[2]);
820 buf = hex_byte_pack(buf, ch[3]);
828 buf = hex_byte_pack(buf, ch[0]);
829 buf = hex_byte_pack(buf, ch[1]);
837 buf = hex_byte_pack(buf, ch[0]);
851 const char *hex2mem(
const char *buf,
void *_mem,
int count,
int may_fault)
859 if ((
u32) mem & 1 && count >= 1) {
860 ch.b[0] = hex(*buf++) << 4;
861 ch.b[0] |= hex(*buf++);
868 if ((
u32) mem & 3 && count >= 2) {
869 ch.b[0] = hex(*buf++) << 4;
870 ch.b[0] |= hex(*buf++);
871 ch.b[1] = hex(*buf++) << 4;
872 ch.b[1] |= hex(*buf++);
880 ch.b[0] = hex(*buf++) << 4;
881 ch.b[0] |= hex(*buf++);
882 ch.b[1] = hex(*buf++) << 4;
883 ch.b[1] |= hex(*buf++);
884 ch.b[2] = hex(*buf++) << 4;
885 ch.b[2] |= hex(*buf++);
886 ch.b[3] = hex(*buf++) << 4;
887 ch.b[3] |= hex(*buf++);
895 ch.b[0] = hex(*buf++) << 4;
896 ch.b[0] |= hex(*buf++);
897 ch.b[1] = hex(*buf++) << 4;
898 ch.b[1] |= hex(*buf++);
906 ch.b[0] = hex(*buf++) << 4;
907 ch.b[0] |= hex(*buf++);
920 static const struct excep_to_sig_map {
923 } excep_to_sig_map[] = {
960 const struct excep_to_sig_map *
map;
962 for (map = excep_to_sig_map; map->signo; map++)
963 if (map->excep == excep)
969 static u32 gdbstub_fpcr, gdbstub_fpufs_array[32];
974 static void gdbstub_store_fpu(
void)
980 #ifdef CONFIG_MN10300_PROC_MN103E010
1000 "fmov fs15, (a1+)\n"
1001 "fmov fs16, (a1+)\n"
1002 "fmov fs17, (a1+)\n"
1003 "fmov fs18, (a1+)\n"
1004 "fmov fs19, (a1+)\n"
1005 "fmov fs20, (a1+)\n"
1006 "fmov fs21, (a1+)\n"
1007 "fmov fs22, (a1+)\n"
1008 "fmov fs23, (a1+)\n"
1009 "fmov fs24, (a1+)\n"
1010 "fmov fs25, (a1+)\n"
1011 "fmov fs26, (a1+)\n"
1012 "fmov fs27, (a1+)\n"
1013 "fmov fs28, (a1+)\n"
1014 "fmov fs29, (a1+)\n"
1015 "fmov fs30, (a1+)\n"
1016 "fmov fs31, (a1+)\n"
1018 :
"=d"(gdbstub_fpcr)
1019 :
"g" (&gdbstub_fpufs_array),
"i"(EPSW_FE)
1028 static void gdbstub_load_fpu(
void)
1034 #ifdef CONFIG_MN10300_PROC_MN103E010
1049 "fmov (a1+), fs10\n"
1050 "fmov (a1+), fs11\n"
1051 "fmov (a1+), fs12\n"
1052 "fmov (a1+), fs13\n"
1053 "fmov (a1+), fs14\n"
1054 "fmov (a1+), fs15\n"
1055 "fmov (a1+), fs16\n"
1056 "fmov (a1+), fs17\n"
1057 "fmov (a1+), fs18\n"
1058 "fmov (a1+), fs19\n"
1059 "fmov (a1+), fs20\n"
1060 "fmov (a1+), fs21\n"
1061 "fmov (a1+), fs22\n"
1062 "fmov (a1+), fs23\n"
1063 "fmov (a1+), fs24\n"
1064 "fmov (a1+), fs25\n"
1065 "fmov (a1+), fs26\n"
1066 "fmov (a1+), fs27\n"
1067 "fmov (a1+), fs28\n"
1068 "fmov (a1+), fs29\n"
1069 "fmov (a1+), fs30\n"
1070 "fmov (a1+), fs31\n"
1073 :
"g" (&gdbstub_fpufs_array),
"i"(EPSW_FE),
"d"(gdbstub_fpcr)
1084 int bkpt, loop, xloop;
1086 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1087 len = (len + 1) & ~1;
1092 for (bkpt = 255; bkpt >= 0; bkpt--)
1093 if (!gdbstub_bkpts[bkpt].addr)
1098 for (loop = 0; loop < len; loop++)
1100 &gdbstub_bkpts[bkpt].origbytes[loop]
1104 gdbstub_flush_caches = 1;
1106 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1107 for (loop = 0; loop < len; loop++)
1111 for (loop = 0; loop < len; loop++)
1116 gdbstub_bkpts[bkpt].addr =
addr;
1117 gdbstub_bkpts[bkpt].len = len;
1119 gdbstub_bkpt(
"Set BKPT[%02x]: %p-%p {%02x%02x%02x%02x%02x%02x%02x}\n",
1121 gdbstub_bkpts[bkpt].addr,
1122 gdbstub_bkpts[bkpt].addr + gdbstub_bkpts[bkpt].len - 1,
1123 gdbstub_bkpts[bkpt].origbytes[0],
1124 gdbstub_bkpts[bkpt].origbytes[1],
1125 gdbstub_bkpts[bkpt].origbytes[2],
1126 gdbstub_bkpts[bkpt].origbytes[3],
1127 gdbstub_bkpts[bkpt].origbytes[4],
1128 gdbstub_bkpts[bkpt].origbytes[5],
1129 gdbstub_bkpts[bkpt].origbytes[6]
1135 for (xloop = 0; xloop < loop; xloop++)
1148 #ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
1149 len = (len + 1) & ~1;
1154 for (bkpt = 255; bkpt >= 0; bkpt--)
1155 if (gdbstub_bkpts[bkpt].addr == addr &&
1156 gdbstub_bkpts[bkpt].len == len)
1161 gdbstub_bkpts[bkpt].addr =
NULL;
1163 gdbstub_flush_caches = 1;
1165 for (loop = 0; loop < len; loop++)
1179 unsigned long *
stack;
1180 unsigned long epsw, mdr;
1192 gdbstub_flush_caches = 0;
1196 asm volatile(
"mov mdr,%0" :
"=d"(mdr));
1198 arch_local_change_intr_mask_level(
1199 NUM2EPSW_IM(CONFIG_DEBUGGER_IRQ_LEVEL + 1));
1201 gdbstub_store_fpu();
1203 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1212 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
1213 if ((step_bp[0].addr && step_bp[0].addr == (
u8 *) regs->
pc) ||
1214 (step_bp[1].addr && step_bp[1].addr == (
u8 *) regs->
pc))
1217 __gdbstub_restore_bp();
1220 if (gdbstub_rx_unget) {
1222 if (gdbstub_rx_unget != 3)
1223 goto packet_waiting;
1224 gdbstub_rx_unget = 0;
1227 stack = (
unsigned long *) regs->
sp;
1228 sigval = broke ?
SIGTRAP : computeSignal(excep);
1232 const struct bug_entry *bug;
1237 length =
snprintf(trans_buffer,
sizeof(trans_buffer),
1238 "BUG() at address %lx\n", regs->
pc);
1242 length =
snprintf(trans_buffer,
sizeof(trans_buffer),
1243 "BUG() at address %lx (%s:%d)\n",
1244 regs->
pc, bug->file, bug->line);
1249 ptr = mem2hex(trans_buffer, ptr, length, 0);
1251 putpacket(output_buffer);
1256 regs->
pc = regs->
mdr;
1265 static const char title[] =
"Excep ", tbcberr[] =
"BCBERR ";
1266 static const char crlf[] =
"\r\n";
1268 u32 bcberr = BCBERR;
1272 ptr = mem2hex(title, ptr,
sizeof(title) - 1, 0);
1275 ptr = hex_byte_pack(ptr, hx);
1277 ptr = hex_byte_pack(ptr, hx);
1279 ptr = hex_byte_pack(ptr, hx);
1281 ptr = hex_byte_pack(ptr, hx);
1283 ptr = mem2hex(crlf, ptr,
sizeof(crlf) - 1, 0);
1285 putpacket(output_buffer);
1290 ptr = mem2hex(tbcberr, ptr,
sizeof(tbcberr) - 1, 0);
1293 ptr = hex_byte_pack(ptr, hx);
1295 ptr = hex_byte_pack(ptr, hx);
1297 ptr = hex_byte_pack(ptr, hx);
1299 ptr = hex_byte_pack(ptr, hx);
1301 ptr = hex_byte_pack(ptr, hx);
1303 ptr = hex_byte_pack(ptr, hx);
1305 ptr = hex_byte_pack(ptr, hx);
1307 ptr = hex_byte_pack(ptr, hx);
1309 ptr = mem2hex(crlf, ptr,
sizeof(crlf) - 1, 0);
1311 putpacket(output_buffer);
1323 ptr = hex_byte_pack(ptr, sigval);
1330 ptr = mem2hex(®s->
pc, ptr, 4, 0);
1338 ptr = mem2hex(®s->
a3, ptr, 4, 0);
1344 ssp = (
unsigned long) (regs + 1);
1347 ptr = mem2hex(&ssp, ptr, 4, 0);
1351 putpacket(output_buffer);
1358 output_buffer[0] = 0;
1359 getpacket(input_buffer);
1361 switch (input_buffer[0]) {
1364 output_buffer[0] =
'S';
1367 output_buffer[3] = 0;
1379 ssp = (
u32) (regs + 1);
1381 ptr = mem2hex(®s->
d0, ptr, 4, 0);
1382 ptr = mem2hex(®s->
d1, ptr, 4, 0);
1383 ptr = mem2hex(®s->
d2, ptr, 4, 0);
1384 ptr = mem2hex(®s->
d3, ptr, 4, 0);
1385 ptr = mem2hex(®s->
a0, ptr, 4, 0);
1386 ptr = mem2hex(®s->
a1, ptr, 4, 0);
1387 ptr = mem2hex(®s->
a2, ptr, 4, 0);
1388 ptr = mem2hex(®s->
a3, ptr, 4, 0);
1390 ptr = mem2hex(&ssp, ptr, 4, 0);
1391 ptr = mem2hex(®s->
pc, ptr, 4, 0);
1392 ptr = mem2hex(®s->
mdr, ptr, 4, 0);
1393 ptr = mem2hex(®s->
epsw, ptr, 4, 0);
1394 ptr = mem2hex(®s->
lir, ptr, 4, 0);
1395 ptr = mem2hex(®s->
lar, ptr, 4, 0);
1396 ptr = mem2hex(®s->
mdrq, ptr, 4, 0);
1398 ptr = mem2hex(®s->
e0, ptr, 4, 0);
1399 ptr = mem2hex(®s->
e1, ptr, 4, 0);
1400 ptr = mem2hex(®s->
e2, ptr, 4, 0);
1401 ptr = mem2hex(®s->
e3, ptr, 4, 0);
1402 ptr = mem2hex(®s->
e4, ptr, 4, 0);
1403 ptr = mem2hex(®s->
e5, ptr, 4, 0);
1404 ptr = mem2hex(®s->
e6, ptr, 4, 0);
1405 ptr = mem2hex(®s->
e7, ptr, 4, 0);
1407 ptr = mem2hex(&ssp, ptr, 4, 0);
1408 ptr = mem2hex(®s, ptr, 4, 0);
1409 ptr = mem2hex(®s->
sp, ptr, 4, 0);
1410 ptr = mem2hex(®s->
mcrh, ptr, 4, 0);
1411 ptr = mem2hex(®s->
mcrl, ptr, 4, 0);
1412 ptr = mem2hex(®s->
mcvf, ptr, 4, 0);
1414 ptr = mem2hex(&gdbstub_fpcr, ptr, 4, 0);
1415 ptr = mem2hex(&zero, ptr, 4, 0);
1416 ptr = mem2hex(&zero, ptr, 4, 0);
1417 for (loop = 0; loop < 32; loop++)
1418 ptr = mem2hex(&gdbstub_fpufs_array[loop],
1430 ptr = &input_buffer[1];
1431 ptr = hex2mem(ptr, ®s->
d0, 4, 0);
1432 ptr = hex2mem(ptr, ®s->
d1, 4, 0);
1433 ptr = hex2mem(ptr, ®s->
d2, 4, 0);
1434 ptr = hex2mem(ptr, ®s->
d3, 4, 0);
1435 ptr = hex2mem(ptr, ®s->
a0, 4, 0);
1436 ptr = hex2mem(ptr, ®s->
a1, 4, 0);
1437 ptr = hex2mem(ptr, ®s->
a2, 4, 0);
1438 ptr = hex2mem(ptr, ®s->
a3, 4, 0);
1440 ptr = hex2mem(ptr, &ssp, 4, 0);
1441 ptr = hex2mem(ptr, ®s->
pc, 4, 0);
1442 ptr = hex2mem(ptr, ®s->
mdr, 4, 0);
1443 ptr = hex2mem(ptr, ®s->
epsw, 4, 0);
1444 ptr = hex2mem(ptr, ®s->
lir, 4, 0);
1445 ptr = hex2mem(ptr, ®s->
lar, 4, 0);
1446 ptr = hex2mem(ptr, ®s->
mdrq, 4, 0);
1448 ptr = hex2mem(ptr, ®s->
e0, 4, 0);
1449 ptr = hex2mem(ptr, ®s->
e1, 4, 0);
1450 ptr = hex2mem(ptr, ®s->
e2, 4, 0);
1451 ptr = hex2mem(ptr, ®s->
e3, 4, 0);
1452 ptr = hex2mem(ptr, ®s->
e4, 4, 0);
1453 ptr = hex2mem(ptr, ®s->
e5, 4, 0);
1454 ptr = hex2mem(ptr, ®s->
e6, 4, 0);
1455 ptr = hex2mem(ptr, ®s->
e7, 4, 0);
1457 ptr = hex2mem(ptr, &ssp, 4, 0);
1458 ptr = hex2mem(ptr, &zero, 4, 0);
1459 ptr = hex2mem(ptr, ®s->
sp, 4, 0);
1460 ptr = hex2mem(ptr, ®s->
mcrh, 4, 0);
1461 ptr = hex2mem(ptr, ®s->
mcrl, 4, 0);
1462 ptr = hex2mem(ptr, ®s->
mcvf, 4, 0);
1464 ptr = hex2mem(ptr, &zero, 4, 0);
1465 ptr = hex2mem(ptr, &zero, 4, 0);
1466 ptr = hex2mem(ptr, &zero, 4, 0);
1467 for (loop = 0; loop < 32; loop++)
1468 ptr = hex2mem(ptr, &zero, 4, 0);
1475 unsigned long *newsp = (
unsigned long *)
registers[
SP];
1477 sp =
memcpy(newsp, sp, 16 * 4);
1480 gdbstub_strcpy(output_buffer,
"OK");
1488 ptr = &input_buffer[1];
1490 if (hexToInt(&ptr, &addr) &&
1492 hexToInt(&ptr, &length)
1494 if (mem2hex((
char *) addr, output_buffer,
1497 gdbstub_strcpy(output_buffer,
"E03");
1499 gdbstub_strcpy(output_buffer,
"E01");
1508 ptr = &input_buffer[1];
1510 if (hexToInt(&ptr, &addr) &&
1512 hexToInt(&ptr, &length) &&
1515 if (hex2mem(ptr, (
char *) addr, length, 1))
1516 gdbstub_strcpy(output_buffer,
"OK");
1518 gdbstub_strcpy(output_buffer,
"E03");
1520 gdbstub_flush_caches = 1;
1522 gdbstub_strcpy(output_buffer,
"E02");
1533 ptr = &input_buffer[1];
1534 if (hexToInt(&ptr, &addr))
1559 #ifdef CONFIG_GDBSTUB_ALLOW_SINGLE_STEP
1560 if (gdbstub_single_step(regs) < 0)
1566 gdbstub_strcpy(output_buffer,
"E01");
1577 ptr = &input_buffer[1];
1578 if (!hexToInt(&ptr, &baudrate)) {
1579 gdbstub_strcpy(output_buffer,
"B01");
1595 ptr = &input_buffer[1];
1597 if (!hexToInt(&ptr, &loop) || *ptr++ !=
',' ||
1598 !hexToInt(&ptr, &addr) || *ptr++ !=
',' ||
1599 !hexToInt(&ptr, &length)
1601 gdbstub_strcpy(output_buffer,
"E01");
1606 gdbstub_strcpy(output_buffer,
"E03");
1610 (
unsigned long) addr < 4096)
1616 gdbstub_strcpy(output_buffer,
"OK");
1623 ptr = &input_buffer[1];
1625 if (!hexToInt(&ptr, &loop) || *ptr++ !=
',' ||
1626 !hexToInt(&ptr, &addr) || *ptr++ !=
',' ||
1627 !hexToInt(&ptr, &length)
1629 gdbstub_strcpy(output_buffer,
"E01");
1634 gdbstub_strcpy(output_buffer,
"E03");
1638 (
unsigned long) addr < 4096)
1644 gdbstub_strcpy(output_buffer,
"OK");
1654 putpacket(output_buffer);
1666 if (gdbstub_flush_caches)
1667 debugger_local_cache_flushinv();
1693 int signo,
int si_code,
struct pt_regs *regs)
1695 static u8 notfirst = 1;
1704 asm(
"mov mdr,%0" :
"=d"(mdr));
1707 "--> debugger_intercept(%p,%04x) [MDR=%lx PC=%lx]\n",
1708 regs, excep, mdr, regs->
pc);
1711 "PC: %08lx EPSW: %08lx SSP: %08lx mode: %s\n",
1712 regs->
pc, regs->
epsw, (
unsigned long) &ret,
1715 "d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
1716 regs->
d0, regs->
d1, regs->
d2, regs->
d3);
1718 "a0: %08lx a1: %08lx a2: %08lx a3: %08lx\n",
1719 regs->
a0, regs->
a1, regs->
a2, regs->
a3);
1721 "e0: %08lx e1: %08lx e2: %08lx e3: %08lx\n",
1722 regs->
e0, regs->
e1, regs->
e2, regs->
e3);
1724 "e4: %08lx e5: %08lx e6: %08lx e7: %08lx\n",
1725 regs->
e4, regs->
e5, regs->
e6, regs->
e7);
1727 "lar: %08lx lir: %08lx mdr: %08lx usp: %08lx\n",
1730 "cvf: %08lx crl: %08lx crh: %08lx drq: %08lx\n",
1733 "threadinfo=%p task=%p)\n",
1754 asm(
"mov mdr,%0" :
"=d"(mdr));
1755 gdbstub_entry(
"--> gdbstub exception({%p},%04x) [MDR=%lx]\n",
1758 while ((
unsigned long) regs == 0xffffffff) {}
1797 panic(
"GDB Stub caused an unexpected exception - can't continue\n");
1816 output_buffer[0] =
'W';
1819 output_buffer[3] = 0;
1825 while ((ch = output_buffer[count]) != 0) {
1846 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1864 #ifdef CONFIG_GDBSTUB_IMMEDIATE
1881 printk(
"GDB Stub ready\n");
1891 #ifdef CONFIG_GDBSTUB_CONSOLE
1892 static int __init gdbstub_postinit(
void)
1917 gdbstub_rx_unget = ch;
1920 }
while (ret != -
EAGAIN);