166 #include <linux/string.h>
167 #include <linux/signal.h>
168 #include <linux/kernel.h>
170 #include <linux/linkage.h>
171 #include <linux/reboot.h>
173 #include <asm/setup.h>
174 #include <asm/ptrace.h>
177 #include <hwregs/reg_map.h>
179 #include <hwregs/intr_vect_defs.h>
187 static int kgdb_started = 0;
331 static int register_size[] =
360 static char *gdb_cris_strcpy(
char *
s1,
const char *
s2);
363 static int gdb_cris_strlen(
const char *
s);
366 static void *gdb_cris_memchr(
const void *
s,
int c,
int n);
369 static int gdb_cris_strtol(
const char *
s,
char **endptr,
int base);
375 static int write_register(
int regno,
char *
val);
379 static int read_register(
char regno,
unsigned int *valptr);
388 static int hex(
char ch);
393 static char *mem2hex(
char *
buf,
unsigned char *
mem,
int count);
398 static unsigned char *hex2mem(
unsigned char *
mem,
char *
buf,
int count);
403 static unsigned char *bin2mem(
unsigned char *
mem,
unsigned char *
buf,
int count);
407 static void getpacket(
char *
buffer);
410 static void putpacket(
char *
buffer);
414 static void stub_is_stopped(
int sigval);
422 static void kill_restart(
void);
433 #define USEDVAR(name) { if (name) { ; } }
434 #define USEDFUN(name) { void (*pf)(void) = (void *)name; USEDVAR(pf) }
446 static char input_buffer[
BUFMAX];
455 static char *error_message[] =
458 "E01 Set current or general thread - H[c,g] - internal error.",
459 "E02 Change register content - P - cannot change read-only register.",
460 "E03 Thread is not alive.",
461 "E04 The command is not supported - [s,C,S,!,R,d,r] - internal error.",
462 "E05 Change register content - P - the register is not implemented..",
463 "E06 Change memory content - M - internal error.",
470 #define INTERNAL_STACK_SIZE 1024
479 static int dynamic_bp = 0;
486 gdb_cris_strcpy(
char *
s1,
const char *
s2)
490 for (s = s1; (*s++ = *s2++) !=
'\0'; )
497 gdb_cris_strlen(
const char *
s)
501 for (sc = s; *sc !=
'\0'; sc++)
508 gdb_cris_memchr(
const void *s,
int c,
int n)
510 const unsigned char uc =
c;
511 const unsigned char *
su;
513 for (su = s; 0 <
n; ++
su, --
n)
522 gdb_cris_strtol(
const char *s,
char **endptr,
int base)
528 for (s1 = (
char*)s; (sd = gdb_cris_memchr(
hex_asc, *s1, base)) !=
NULL; ++
s1)
544 write_register(
int regno,
char *
val)
548 if (regno >=
R0 && regno <=
ACR) {
550 hex2mem((
unsigned char *)®.
r0 + (regno -
R0) *
sizeof(
unsigned int),
551 val,
sizeof(
unsigned int));
553 }
else if (regno ==
BZ || regno ==
VR || regno ==
WZ || regno ==
DZ) {
557 }
else if (regno ==
PID) {
560 hex2mem((
unsigned char *)®.
pid, val,
sizeof(
unsigned int));
562 }
else if (regno ==
SRS) {
564 hex2mem((
unsigned char *)®.
srs, val,
sizeof(
unsigned char));
566 }
else if (regno >=
EXS && regno <=
SPC) {
568 hex2mem((
unsigned char *)®.
exs + (regno -
EXS) *
sizeof(
unsigned int),
569 val,
sizeof(
unsigned int));
571 }
else if (regno ==
PC) {
575 }
else if (regno >=
S0 && regno <=
S15) {
577 hex2mem((
unsigned char *)&sreg.
s0_0 + (reg.
srs * 16 *
sizeof(
unsigned int)) + (regno -
S0) *
sizeof(
unsigned int), val,
sizeof(
unsigned int));
588 read_register(
char regno,
unsigned int *valptr)
595 if (regno >=
R0 && regno <=
ACR) {
597 *valptr = *(
unsigned int *)((
char *)®.
r0 + (regno -
R0) *
sizeof(
unsigned int));
599 }
else if (regno ==
BZ || regno ==
VR) {
601 *valptr = (
unsigned int)(*(
unsigned char *)
602 ((
char *)®.
bz + (regno -
BZ) *
sizeof(
char)));
604 }
else if (regno ==
PID) {
606 *valptr = *(
unsigned int *)((
char *)®.
pid);
608 }
else if (regno ==
SRS) {
610 *valptr = (
unsigned int)(*(
unsigned char *)((
char *)®.
srs));
612 }
else if (regno ==
WZ) {
614 *valptr = (
unsigned int)(*(
unsigned short *)(
char *)®.
wz);
616 }
else if (regno >=
EXS && regno <=
PC) {
618 *valptr = *(
unsigned int *)((
char *)®.
exs + (regno -
EXS) *
sizeof(
unsigned int));
620 }
else if (regno >=
S0 && regno <=
S15) {
622 *valptr = *(
unsigned int *)((
char *)&sreg.
s0_0 + (reg.
srs * 16 *
sizeof(
unsigned int)) + (regno -
S0) *
sizeof(
unsigned int));
637 if ((ch >=
'a') && (ch <=
'f'))
638 return (ch -
'a' + 10);
639 if ((ch >=
'0') && (ch <=
'9'))
641 if ((ch >=
'A') && (ch <=
'F'))
642 return (ch -
'A' + 10);
658 for (i = 0; i <
count; i++) {
664 for (i = 0; i <
count; i++) {
666 buf = hex_byte_pack(buf, ch);
676 mem2hex_nbo(
char *buf,
unsigned char *mem,
int count)
682 for (i = 0; i <
count; i++) {
684 buf = hex_byte_pack(buf, ch);
695 static unsigned char*
696 hex2mem(
unsigned char *mem,
char *buf,
int count)
700 for (i = 0; i <
count; i++) {
701 ch = hex (*buf++) << 4;
702 ch = ch + hex (*buf++);
712 static unsigned char*
713 bin2mem(
unsigned char *mem,
unsigned char *buf,
int count)
717 for (i = 0; i <
count; i++) {
722 if (*next == 0x3 || *next == 0x4 || *next == 0x5D) {
739 unsigned char xmitcsum;
755 checksum = checksum + ch;
768 if (checksum != xmitcsum) {
775 if (buffer[2] ==
':') {
779 count = gdb_cris_strlen(buffer);
780 for (i = 3; i <=
count; i++)
781 buffer[i - 3] = buffer[i];
785 }
while (checksum != xmitcsum);
791 putpacket(
char *buffer)
806 while (runlen <
RUNLENMAX && *src == src[runlen]) {
813 encode = runlen +
' ' - 4;
834 asm(
"move $spc, $r10");
835 asm(
"cmp.d spchere, $r10");
838 asm(
"move.d spccont, $r10");
839 asm(
"move $r10, $spc");
861 stub_is_stopped(
int sigval)
864 unsigned int reg_cont;
869 ptr = hex_byte_pack(ptr, sigval);
871 if (((reg.
exs & 0xff00) >> 8) == 0
xc) {
875 int S, bp, trig_bits = 0, rw_bits = 0;
877 unsigned int *bp_d_regs = &sreg.
s3_3;
881 unsigned int stopped_data_address;
883 S = (reg.
exs & 0xffff0000) >> 16;
890 for (bp = 0; bp < 6; bp++) {
893 int bitpos_trig = 1 + bp * 2;
895 int bitpos_config = 2 + bp * 4;
898 trig_bits = (S & (3 << bitpos_trig)) >> bitpos_trig;
901 rw_bits = (sreg.
s0_3 & (3 << bitpos_config)) >> bitpos_config;
905 if ((rw_bits == 0x1 && trig_bits != 0x1) ||
906 (rw_bits == 0x2 && trig_bits != 0x2))
907 panic(
"Invalid r/w trigging for this BP");
910 trig_mask |= (1 << bp);
912 if (reg.
eda >= bp_d_regs[bp * 2] &&
913 reg.
eda <= bp_d_regs[bp * 2 + 1]) {
916 stopped_data_address = reg.
eda;
923 }
else if (trig_mask) {
925 for (bp = 0; bp < 6; bp++) {
927 int bitpos_config = 2 + bp * 4;
930 rw_bits = (sreg.
s0_3 & (3 << bitpos_config)) >> bitpos_config;
932 if (trig_mask & (1 << bp)) {
934 if (reg.
eda + 31 >= bp_d_regs[bp * 2]) {
937 stopped_data_address = bp_d_regs[bp * 2];
941 printk(
"EDA doesn't match trigged BP's range");
953 if (rw_bits == 0x1) {
957 }
else if (rw_bits == 0x2) {
961 }
else if (rw_bits == 0x3) {
966 panic(
"Invalid r/w bits for this BP.");
971 ptr = mem2hex_nbo(ptr, (
unsigned char *)&stopped_data_address, register_size[
EDA]);
976 read_register(
PC, ®_cont);
977 ptr = hex_byte_pack(ptr,
PC);
979 ptr = mem2hex(ptr, (
unsigned char *)®_cont, register_size[
PC]);
982 read_register(
R8, ®_cont);
983 ptr = hex_byte_pack(ptr,
R8);
985 ptr = mem2hex(ptr, (
unsigned char *)®_cont, register_size[
R8]);
988 read_register(
SP, ®_cont);
989 ptr = hex_byte_pack(ptr,
SP);
991 ptr = mem2hex(ptr, (
unsigned char *)®_cont, register_size[
SP]);
995 read_register(
ERP, ®_cont);
996 ptr = hex_byte_pack(ptr,
ERP);
998 ptr = mem2hex(ptr, (
unsigned char *)®_cont, register_size[
ERP]);
1010 unsigned short opcode = *(
unsigned short *)pc;
1013 switch ((opcode & 0x0f00) >> 8) {
1025 if ((opcode & 0xff) == 0xff)
1031 panic(
"Couldn't find size of opcode 0x%x at 0x%lx\n", opcode, pc);
1044 if (reg.
erp & 0x1) {
1056 if ((reg.
exs & 0x3) == 0x0) {
1067 if (((reg.
exs & 0xff00) >> 8) == 0x18) {
1082 if (!(reg.
erp & 0x1)) {
1088 }
else if (((reg.
exs & 0xff00) >> 8) == 0x3) {
1092 }
else if (((reg.
exs & 0xff00) >> 8) == 0
xc) {
1103 }
else if (sigval ==
SIGINT) {
1108 static void insert_watchpoint(
char type,
int addr,
int len)
1131 if (sreg.
s0_3 & 0x1) {
1138 sreg.
s2_3 = (addr + len - 1);
1142 unsigned int *bp_d_regs = &sreg.
s3_3;
1152 for (bp = 0; bp < 6; bp++) {
1156 if (!(sreg.
s0_3 & (0x3 << (2 + (bp * 4))))) {
1168 if (type ==
'3' || type ==
'4') {
1170 sreg.
s0_3 |= (1 << (2 + bp * 4));
1172 if (type ==
'2' || type ==
'4') {
1174 sreg.
s0_3 |= (2 << (2 + bp * 4));
1178 bp_d_regs[bp * 2] =
addr;
1179 bp_d_regs[bp * 2 + 1] = (addr + len - 1);
1187 static void remove_watchpoint(
char type,
int addr,
int len)
1209 if (!(sreg.
s0_3 & 0x1)) {
1220 unsigned int *bp_d_regs = &sreg.
s3_3;
1228 for (bp = 0; bp < 6; bp++) {
1229 if (bp_d_regs[bp * 2] == addr &&
1230 bp_d_regs[bp * 2 + 1] == (addr + len - 1)) {
1232 int bitpos = 2 + bp * 4;
1236 rw_bits = (sreg.
s0_3 & (0x3 << bitpos)) >> bitpos;
1238 if ((type ==
'3' && rw_bits == 0x1) ||
1239 (type ==
'2' && rw_bits == 0x2) ||
1240 (type ==
'4' && rw_bits == 0x3)) {
1256 sreg.
s0_3 &= ~(3 << (2 + (bp * 4)));
1257 bp_d_regs[bp * 2] = 0;
1258 bp_d_regs[bp * 2 + 1] = 0;
1280 stub_is_stopped(sigval);
1284 getpacket(input_buffer);
1285 switch (input_buffer[0]) {
1299 (
char *)&sreg + (reg.
srs * 16 *
sizeof(
unsigned int)),
1300 16 *
sizeof(
unsigned int));
1309 hex2mem((
char *)®, &input_buffer[1],
sizeof(
registers));
1311 hex2mem((
char *)&sreg + (reg.
srs * 16 *
sizeof(
unsigned int)),
1313 16 *
sizeof(
unsigned int));
1327 int regno = gdb_cris_strtol(&input_buffer[1], &suffix, 16);
1330 status = write_register(regno, suffix+1);
1358 unsigned char *addr = (
unsigned char *)gdb_cris_strtol(&input_buffer[1],
1360 int len = gdb_cris_strtol(suffix+1, 0, 16);
1364 if (!((
unsigned int)addr >= 0xc0000000 &&
1365 (
unsigned int)addr < 0xd0000000))
1387 unsigned char *addr = (
unsigned char *)gdb_cris_strtol(&input_buffer[1],
1389 int len = gdb_cris_strtol(lenptr+1, &dataptr, 16);
1390 if (*lenptr ==
',' && *dataptr ==
':') {
1391 if (input_buffer[0] ==
'M') {
1392 hex2mem(addr, dataptr + 1, len);
1394 bin2mem(addr, dataptr + 1, len);
1411 if (input_buffer[1] !=
'\0') {
1424 if ((sreg.
s0_3 & 0x3fff) == 0) {
1436 if (input_buffer[1] !=
'\0') {
1459 int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);
1460 int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);
1461 char type = input_buffer[1];
1463 insert_watchpoint(type, addr, len);
1474 int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);
1475 int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);
1476 char type = input_buffer[1];
1478 remove_watchpoint(type, addr, len);
1544 #if defined(CONFIG_ETRAX_KGDB_PORT0)
1556 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
1568 #elif defined(CONFIG_ETRAX_KGDB_PORT2)
1580 #elif defined(CONFIG_ETRAX_KGDB_PORT3)