1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166#include <linux/string.h>
167#include <linux/signal.h>
168#include <linux/kernel.h>
169#include <linux/delay.h>
170#include <linux/linkage.h>
171#include <linux/reboot.h>
172
173#include <asm/setup.h>
174#include <asm/ptrace.h>
175
176#include <asm/irq.h>
177#include <hwregs/reg_map.h>
178#include <hwregs/reg_rdwr.h>
179#include <hwregs/intr_vect_defs.h>
180#include <hwregs/ser_defs.h>
181
182
183extern void gdb_handle_exception(void);
184
185extern void kgdb_handle_exception(void);
186
187static int kgdb_started = 0;
188
189
190
191typedef
192struct register_image
193{
194
195 unsigned int r0;
196 unsigned int r1;
197 unsigned int r2;
198 unsigned int r3;
199 unsigned int r4;
200 unsigned int r5;
201 unsigned int r6;
202 unsigned int r7;
203 unsigned int r8;
204 unsigned int r9;
205 unsigned int r10;
206 unsigned int r11;
207 unsigned int r12;
208 unsigned int r13;
209 unsigned int sp;
210 unsigned int acr;
211
212 unsigned char bz;
213 unsigned char vr;
214 unsigned int pid;
215 unsigned char srs;
216 unsigned short wz;
217 unsigned int exs;
218 unsigned int eda;
219 unsigned int mof;
220 unsigned int dz;
221 unsigned int ebp;
222 unsigned int erp;
223 unsigned int srp;
224 unsigned int nrp;
225 unsigned int ccs;
226 unsigned int usp;
227 unsigned int spc;
228 unsigned int pc;
229
230} registers;
231
232typedef
233struct bp_register_image
234{
235
236 unsigned int s0_0;
237 unsigned int s1_0;
238 unsigned int s2_0;
239 unsigned int s3_0;
240 unsigned int s4_0;
241 unsigned int s5_0;
242 unsigned int s6_0;
243 unsigned int s7_0;
244 unsigned int s8_0;
245 unsigned int s9_0;
246 unsigned int s10_0;
247 unsigned int s11_0;
248 unsigned int s12_0;
249 unsigned int s13_0;
250 unsigned int s14_0;
251 unsigned int s15_0;
252
253
254 unsigned int s0_1;
255 unsigned int s1_1;
256 unsigned int s2_1;
257 unsigned int s3_1;
258 unsigned int s4_1;
259 unsigned int s5_1;
260 unsigned int s6_1;
261 unsigned int s7_1;
262 unsigned int s8_1;
263 unsigned int s9_1;
264 unsigned int s10_1;
265 unsigned int s11_1;
266 unsigned int s12_1;
267 unsigned int s13_1;
268 unsigned int s14_1;
269 unsigned int s15_1;
270
271
272 unsigned int s0_2;
273 unsigned int s1_2;
274 unsigned int s2_2;
275 unsigned int s3_2;
276 unsigned int s4_2;
277 unsigned int s5_2;
278 unsigned int s6_2;
279 unsigned int s7_2;
280 unsigned int s8_2;
281 unsigned int s9_2;
282 unsigned int s10_2;
283 unsigned int s11_2;
284 unsigned int s12_2;
285 unsigned int s13_2;
286 unsigned int s14_2;
287 unsigned int s15_2;
288
289
290 unsigned int s0_3;
291 unsigned int s1_3;
292 unsigned int s2_3;
293 unsigned int s3_3;
294 unsigned int s4_3;
295 unsigned int s5_3;
296 unsigned int s6_3;
297 unsigned int s7_3;
298 unsigned int s8_3;
299 unsigned int s9_3;
300 unsigned int s10_3;
301 unsigned int s11_3;
302 unsigned int s12_3;
303 unsigned int s13_3;
304 unsigned int s14_3;
305 unsigned int s15_3;
306
307} support_registers;
308
309enum register_name
310{
311 R0, R1, R2, R3,
312 R4, R5, R6, R7,
313 R8, R9, R10, R11,
314 R12, R13, SP, ACR,
315
316 BZ, VR, PID, SRS,
317 WZ, EXS, EDA, MOF,
318 DZ, EBP, ERP, SRP,
319 NRP, CCS, USP, SPC,
320 PC,
321
322 S0, S1, S2, S3,
323 S4, S5, S6, S7,
324 S8, S9, S10, S11,
325 S12, S13, S14, S15
326
327};
328
329
330
331static int register_size[] =
332{
333 4, 4, 4, 4,
334 4, 4, 4, 4,
335 4, 4, 4, 4,
336 4, 4, 4, 4,
337
338 1, 1, 4, 1,
339 2, 4, 4, 4,
340 4, 4, 4, 4,
341 4, 4, 4, 4,
342
343 4,
344
345 4, 4, 4, 4,
346 4, 4, 4, 4,
347 4, 4, 4, 4,
348 4, 4, 4
349
350};
351
352
353
354registers reg;
355support_registers sreg;
356
357
358
359
360static char *gdb_cris_strcpy(char *s1, const char *s2);
361
362
363static int gdb_cris_strlen(const char *s);
364
365
366static void *gdb_cris_memchr(const void *s, int c, int n);
367
368
369static int gdb_cris_strtol(const char *s, char **endptr, int base);
370
371
372
373
374
375static int write_register(int regno, char *val);
376
377
378
379static int read_register(char regno, unsigned int *valptr);
380
381
382int getDebugChar(void);
383
384
385void putDebugChar(int val);
386
387
388static int hex(char ch);
389
390
391
392
393static char *mem2hex(char *buf, unsigned char *mem, int count);
394
395
396
397
398static unsigned char *hex2mem(unsigned char *mem, char *buf, int count);
399
400
401
402
403static unsigned char *bin2mem(unsigned char *mem, unsigned char *buf, int count);
404
405
406
407static void getpacket(char *buffer);
408
409
410static void putpacket(char *buffer);
411
412
413
414static void stub_is_stopped(int sigval);
415
416
417
418
419void handle_exception(int sigval);
420
421
422static void kill_restart(void);
423
424
425
426
427void putDebugString(const unsigned char *str, int len);
428
429
430void breakpoint(void);
431
432
433#define USEDVAR(name) { if (name) { ; } }
434#define USEDFUN(name) { void (*pf)(void) = (void *)name; USEDVAR(pf) }
435
436
437
438
439
440#define BUFMAX 512
441
442
443#define RUNLENMAX 64
444
445
446static char input_buffer[BUFMAX];
447static char output_buffer[BUFMAX];
448
449
450enum error_type
451{
452 SUCCESS, E01, E02, E03, E04, E05, E06,
453};
454
455static char *error_message[] =
456{
457 "",
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.",
464};
465
466
467
468
469
470#define INTERNAL_STACK_SIZE 1024
471char internal_stack[INTERNAL_STACK_SIZE];
472
473
474
475
476
477
478
479static int dynamic_bp = 0;
480
481
482
483
484
485static char*
486gdb_cris_strcpy(char *s1, const char *s2)
487{
488 char *s = s1;
489
490 for (s = s1; (*s++ = *s2++) != '\0'; )
491 ;
492 return s1;
493}
494
495
496static int
497gdb_cris_strlen(const char *s)
498{
499 const char *sc;
500
501 for (sc = s; *sc != '\0'; sc++)
502 ;
503 return (sc - s);
504}
505
506
507static void*
508gdb_cris_memchr(const void *s, int c, int n)
509{
510 const unsigned char uc = c;
511 const unsigned char *su;
512
513 for (su = s; 0 < n; ++su, --n)
514 if (*su == uc)
515 return (void *)su;
516 return NULL;
517}
518
519
520
521static int
522gdb_cris_strtol(const char *s, char **endptr, int base)
523{
524 char *s1;
525 char *sd;
526 int x = 0;
527
528 for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
529 x = x * base + (sd - hex_asc);
530
531 if (endptr) {
532
533 *endptr = s1;
534 }
535
536 return x;
537}
538
539
540
541
542
543static int
544write_register(int regno, char *val)
545{
546 int status = SUCCESS;
547
548 if (regno >= R0 && regno <= ACR) {
549
550 hex2mem((unsigned char *)®.r0 + (regno - R0) * sizeof(unsigned int),
551 val, sizeof(unsigned int));
552
553 } else if (regno == BZ || regno == VR || regno == WZ || regno == DZ) {
554
555 status = E02;
556
557 } else if (regno == PID) {
558
559
560 hex2mem((unsigned char *)®.pid, val, sizeof(unsigned int));
561
562 } else if (regno == SRS) {
563
564 hex2mem((unsigned char *)®.srs, val, sizeof(unsigned char));
565
566 } else if (regno >= EXS && regno <= SPC) {
567
568 hex2mem((unsigned char *)®.exs + (regno - EXS) * sizeof(unsigned int),
569 val, sizeof(unsigned int));
570
571 } else if (regno == PC) {
572
573 status = E02;
574
575 } else if (regno >= S0 && regno <= S15) {
576
577 hex2mem((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int), val, sizeof(unsigned int));
578 } else {
579
580 status = E05;
581 }
582 return status;
583}
584
585
586
587static int
588read_register(char regno, unsigned int *valptr)
589{
590 int status = SUCCESS;
591
592
593
594
595 if (regno >= R0 && regno <= ACR) {
596
597 *valptr = *(unsigned int *)((char *)®.r0 + (regno - R0) * sizeof(unsigned int));
598
599 } else if (regno == BZ || regno == VR) {
600
601 *valptr = (unsigned int)(*(unsigned char *)
602 ((char *)®.bz + (regno - BZ) * sizeof(char)));
603
604 } else if (regno == PID) {
605
606 *valptr = *(unsigned int *)((char *)®.pid);
607
608 } else if (regno == SRS) {
609
610 *valptr = (unsigned int)(*(unsigned char *)((char *)®.srs));
611
612 } else if (regno == WZ) {
613
614 *valptr = (unsigned int)(*(unsigned short *)(char *)®.wz);
615
616 } else if (regno >= EXS && regno <= PC) {
617
618 *valptr = *(unsigned int *)((char *)®.exs + (regno - EXS) * sizeof(unsigned int));
619
620 } else if (regno >= S0 && regno <= S15) {
621
622 *valptr = *(unsigned int *)((char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int));
623
624 } else {
625
626 status = E05;
627 }
628 return status;
629
630}
631
632
633
634static int
635hex(char ch)
636{
637 if ((ch >= 'a') && (ch <= 'f'))
638 return (ch - 'a' + 10);
639 if ((ch >= '0') && (ch <= '9'))
640 return (ch - '0');
641 if ((ch >= 'A') && (ch <= 'F'))
642 return (ch - 'A' + 10);
643 return -1;
644}
645
646
647
648
649
650static char *
651mem2hex(char *buf, unsigned char *mem, int count)
652{
653 int i;
654 int ch;
655
656 if (mem == NULL) {
657
658 for (i = 0; i < count; i++) {
659 *buf++ = '0';
660 *buf++ = '0';
661 }
662 } else {
663
664 for (i = 0; i < count; i++) {
665 ch = *mem++;
666 buf = hex_byte_pack(buf, ch);
667 }
668 }
669
670 *buf = '\0';
671 return buf;
672}
673
674
675static char *
676mem2hex_nbo(char *buf, unsigned char *mem, int count)
677{
678 int i;
679 int ch;
680
681 mem += count - 1;
682 for (i = 0; i < count; i++) {
683 ch = *mem--;
684 buf = hex_byte_pack(buf, ch);
685 }
686
687
688 *buf = '\0';
689 return buf;
690}
691
692
693
694
695static unsigned char*
696hex2mem(unsigned char *mem, char *buf, int count)
697{
698 int i;
699 unsigned char ch;
700 for (i = 0; i < count; i++) {
701 ch = hex (*buf++) << 4;
702 ch = ch + hex (*buf++);
703 *mem++ = ch;
704 }
705 return mem;
706}
707
708
709
710
711
712static unsigned char*
713bin2mem(unsigned char *mem, unsigned char *buf, int count)
714{
715 int i;
716 unsigned char *next;
717 for (i = 0; i < count; i++) {
718
719
720 if (*buf == 0x7d) {
721 next = buf + 1;
722 if (*next == 0x3 || *next == 0x4 || *next == 0x5D) {
723
724 buf++;
725 *buf += 0x20;
726 }
727 }
728 *mem++ = *buf++;
729 }
730 return mem;
731}
732
733
734
735static void
736getpacket(char *buffer)
737{
738 unsigned char checksum;
739 unsigned char xmitcsum;
740 int i;
741 int count;
742 char ch;
743
744 do {
745 while((ch = getDebugChar ()) != '$')
746 ;
747 checksum = 0;
748 xmitcsum = -1;
749 count = 0;
750
751 while (count < BUFMAX) {
752 ch = getDebugChar();
753 if (ch == '#')
754 break;
755 checksum = checksum + ch;
756 buffer[count] = ch;
757 count = count + 1;
758 }
759
760 if (count >= BUFMAX)
761 continue;
762
763 buffer[count] = 0;
764
765 if (ch == '#') {
766 xmitcsum = hex(getDebugChar()) << 4;
767 xmitcsum += hex(getDebugChar());
768 if (checksum != xmitcsum) {
769
770 putDebugChar('-');
771 } else {
772
773 putDebugChar('+');
774
775 if (buffer[2] == ':') {
776 putDebugChar(buffer[0]);
777 putDebugChar(buffer[1]);
778
779 count = gdb_cris_strlen(buffer);
780 for (i = 3; i <= count; i++)
781 buffer[i - 3] = buffer[i];
782 }
783 }
784 }
785 } while (checksum != xmitcsum);
786}
787
788
789
790static void
791putpacket(char *buffer)
792{
793 int checksum;
794 int runlen;
795 int encode;
796
797 do {
798 char *src = buffer;
799 putDebugChar('$');
800 checksum = 0;
801 while (*src) {
802
803 putDebugChar(*src);
804 checksum += *src;
805 runlen = 0;
806 while (runlen < RUNLENMAX && *src == src[runlen]) {
807 runlen++;
808 }
809 if (runlen > 3) {
810
811 putDebugChar ('*');
812 checksum += '*';
813 encode = runlen + ' ' - 4;
814 putDebugChar(encode);
815 checksum += encode;
816 src += runlen;
817 } else {
818 src++;
819 }
820 }
821 putDebugChar('#');
822 putDebugChar(hex_asc_hi(checksum));
823 putDebugChar(hex_asc_lo(checksum));
824 } while(kgdb_started && (getDebugChar() != '+'));
825}
826
827
828
829void
830putDebugString(const unsigned char *str, int len)
831{
832
833 asm("spchere:");
834 asm("move $spc, $r10");
835 asm("cmp.d spchere, $r10");
836 asm("bne nosstep");
837 asm("nop");
838 asm("move.d spccont, $r10");
839 asm("move $r10, $spc");
840 asm("nosstep:");
841
842 output_buffer[0] = 'O';
843 mem2hex(&output_buffer[1], (unsigned char *)str, len);
844 putpacket(output_buffer);
845
846 asm("spccont:");
847}
848
849
850
851
852
853
854
855
856
857
858
859
860static void
861stub_is_stopped(int sigval)
862{
863 char *ptr = output_buffer;
864 unsigned int reg_cont;
865
866
867
868 *ptr++ = 'T';
869 ptr = hex_byte_pack(ptr, sigval);
870
871 if (((reg.exs & 0xff00) >> 8) == 0xc) {
872
873
874
875 int S, bp, trig_bits = 0, rw_bits = 0;
876 int trig_mask = 0;
877 unsigned int *bp_d_regs = &sreg.s3_3;
878
879
880
881 unsigned int stopped_data_address;
882
883 S = (reg.exs & 0xffff0000) >> 16;
884
885 if (S & 1) {
886
887
888 } else {
889
890 for (bp = 0; bp < 6; bp++) {
891
892
893 int bitpos_trig = 1 + bp * 2;
894
895 int bitpos_config = 2 + bp * 4;
896
897
898 trig_bits = (S & (3 << bitpos_trig)) >> bitpos_trig;
899
900
901 rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;
902 if (trig_bits) {
903
904
905 if ((rw_bits == 0x1 && trig_bits != 0x1) ||
906 (rw_bits == 0x2 && trig_bits != 0x2))
907 panic("Invalid r/w trigging for this BP");
908
909
910 trig_mask |= (1 << bp);
911
912 if (reg.eda >= bp_d_regs[bp * 2] &&
913 reg.eda <= bp_d_regs[bp * 2 + 1]) {
914
915
916 stopped_data_address = reg.eda;
917 break;
918 }
919 }
920 }
921 if (bp < 6) {
922
923 } else if (trig_mask) {
924
925 for (bp = 0; bp < 6; bp++) {
926
927 int bitpos_config = 2 + bp * 4;
928
929
930 rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;
931
932 if (trig_mask & (1 << bp)) {
933
934 if (reg.eda + 31 >= bp_d_regs[bp * 2]) {
935
936
937 stopped_data_address = bp_d_regs[bp * 2];
938 break;
939 } else {
940
941 printk("EDA doesn't match trigged BP's range");
942 }
943 }
944 }
945 }
946
947
948 BUG_ON(bp >= 6);
949
950
951
952
953 if (rw_bits == 0x1) {
954
955 strncpy(ptr, "rwatch", 6);
956 ptr += 6;
957 } else if (rw_bits == 0x2) {
958
959 strncpy(ptr, "watch", 5);
960 ptr += 5;
961 } else if (rw_bits == 0x3) {
962
963 strncpy(ptr, "awatch", 6);
964 ptr += 6;
965 } else {
966 panic("Invalid r/w bits for this BP.");
967 }
968
969 *ptr++ = ':';
970
971 ptr = mem2hex_nbo(ptr, (unsigned char *)&stopped_data_address, register_size[EDA]);
972 *ptr++ = ';';
973 }
974 }
975
976 read_register(PC, ®_cont);
977 ptr = hex_byte_pack(ptr, PC);
978 *ptr++ = ':';
979 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[PC]);
980 *ptr++ = ';';
981
982 read_register(R8, ®_cont);
983 ptr = hex_byte_pack(ptr, R8);
984 *ptr++ = ':';
985 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[R8]);
986 *ptr++ = ';';
987
988 read_register(SP, ®_cont);
989 ptr = hex_byte_pack(ptr, SP);
990 *ptr++ = ':';
991 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[SP]);
992 *ptr++ = ';';
993
994
995 read_register(ERP, ®_cont);
996 ptr = hex_byte_pack(ptr, ERP);
997 *ptr++ = ':';
998 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[ERP]);
999 *ptr++ = ';';
1000
1001
1002 *ptr = 0;
1003 putpacket(output_buffer);
1004}
1005
1006
1007
1008int insn_size(unsigned long pc)
1009{
1010 unsigned short opcode = *(unsigned short *)pc;
1011 int size = 0;
1012
1013 switch ((opcode & 0x0f00) >> 8) {
1014 case 0x0:
1015 case 0x9:
1016 case 0xb:
1017 size = 2;
1018 break;
1019 case 0xe:
1020 case 0xf:
1021 size = 6;
1022 break;
1023 case 0xd:
1024
1025 if ((opcode & 0xff) == 0xff)
1026 size = 4;
1027 else
1028 size = 6;
1029 break;
1030 default:
1031 panic("Couldn't find size of opcode 0x%x at 0x%lx\n", opcode, pc);
1032 }
1033
1034 return size;
1035}
1036
1037void register_fixup(int sigval)
1038{
1039
1040 reg.sp += 4;
1041
1042
1043 reg.pc = reg.erp;
1044 if (reg.erp & 0x1) {
1045
1046 if (reg.spc) {
1047
1048 reg.pc = reg.spc;
1049 } else {
1050
1051
1052 reg.pc += insn_size(reg.erp & ~1) - 1 ;
1053 }
1054 }
1055
1056 if ((reg.exs & 0x3) == 0x0) {
1057
1058
1059
1060 reg.eda = 0;
1061 }
1062
1063 if (sigval == SIGTRAP) {
1064
1065
1066
1067 if (((reg.exs & 0xff00) >> 8) == 0x18) {
1068
1069
1070
1071
1072
1073
1074
1075
1076 if (!dynamic_bp) {
1077
1078 dynamic_bp = 1;
1079 } else {
1080
1081
1082 if (!(reg.erp & 0x1)) {
1083 reg.erp -= 2;
1084 reg.pc -= 2;
1085 }
1086 }
1087
1088 } else if (((reg.exs & 0xff00) >> 8) == 0x3) {
1089
1090
1091
1092 } else if (((reg.exs & 0xff00) >> 8) == 0xc) {
1093
1094
1095
1096
1097
1098 reg.spc = 0;
1099
1100
1101 }
1102
1103 } else if (sigval == SIGINT) {
1104
1105 }
1106}
1107
1108static void insert_watchpoint(char type, int addr, int len)
1109{
1110
1111
1112
1113
1114
1115
1116
1117
1118 if (type < '1' || type > '4') {
1119 output_buffer[0] = 0;
1120 return;
1121 }
1122
1123
1124
1125 if (type == '3')
1126 type = '4';
1127
1128 if (type == '1') {
1129
1130
1131 if (sreg.s0_3 & 0x1) {
1132
1133 gdb_cris_strcpy(output_buffer, error_message[E04]);
1134 return;
1135 }
1136
1137 sreg.s1_3 = addr;
1138 sreg.s2_3 = (addr + len - 1);
1139 sreg.s0_3 |= 1;
1140 } else {
1141 int bp;
1142 unsigned int *bp_d_regs = &sreg.s3_3;
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152 for (bp = 0; bp < 6; bp++) {
1153
1154
1155
1156 if (!(sreg.s0_3 & (0x3 << (2 + (bp * 4))))) {
1157 break;
1158 }
1159 }
1160
1161 if (bp > 5) {
1162
1163 gdb_cris_strcpy(output_buffer, error_message[E04]);
1164 return;
1165 }
1166
1167
1168 if (type == '3' || type == '4') {
1169
1170 sreg.s0_3 |= (1 << (2 + bp * 4));
1171 }
1172 if (type == '2' || type == '4') {
1173
1174 sreg.s0_3 |= (2 << (2 + bp * 4));
1175 }
1176
1177
1178 bp_d_regs[bp * 2] = addr;
1179 bp_d_regs[bp * 2 + 1] = (addr + len - 1);
1180 }
1181
1182
1183 reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
1184 gdb_cris_strcpy(output_buffer, "OK");
1185}
1186
1187static void remove_watchpoint(char type, int addr, int len)
1188{
1189
1190
1191
1192
1193
1194
1195
1196 if (type < '1' || type > '4') {
1197 output_buffer[0] = 0;
1198 return;
1199 }
1200
1201
1202
1203 if (type == '3')
1204 type = '4';
1205
1206 if (type == '1') {
1207
1208
1209 if (!(sreg.s0_3 & 0x1)) {
1210
1211 gdb_cris_strcpy(output_buffer, error_message[E04]);
1212 return;
1213 }
1214
1215 sreg.s1_3 = 0;
1216 sreg.s2_3 = 0;
1217 sreg.s0_3 &= ~1;
1218 } else {
1219 int bp;
1220 unsigned int *bp_d_regs = &sreg.s3_3;
1221
1222
1223
1224
1225
1226
1227
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)) {
1231
1232 int bitpos = 2 + bp * 4;
1233 int rw_bits;
1234
1235
1236 rw_bits = (sreg.s0_3 & (0x3 << bitpos)) >> bitpos;
1237
1238 if ((type == '3' && rw_bits == 0x1) ||
1239 (type == '2' && rw_bits == 0x2) ||
1240 (type == '4' && rw_bits == 0x3)) {
1241
1242 break;
1243 }
1244 }
1245 }
1246
1247 if (bp > 5) {
1248
1249 gdb_cris_strcpy(output_buffer, error_message[E04]);
1250 return;
1251 }
1252
1253
1254
1255
1256 sreg.s0_3 &= ~(3 << (2 + (bp * 4)));
1257 bp_d_regs[bp * 2] = 0;
1258 bp_d_regs[bp * 2 + 1] = 0;
1259 }
1260
1261
1262 gdb_cris_strcpy(output_buffer, "OK");
1263}
1264
1265
1266
1267
1268
1269void
1270handle_exception(int sigval)
1271{
1272
1273
1274 USEDFUN(handle_exception);
1275 USEDVAR(internal_stack[0]);
1276
1277 register_fixup(sigval);
1278
1279
1280 stub_is_stopped(sigval);
1281
1282 for (;;) {
1283 output_buffer[0] = '\0';
1284 getpacket(input_buffer);
1285 switch (input_buffer[0]) {
1286 case 'g':
1287
1288
1289
1290
1291
1292 {
1293 char *buf;
1294
1295 buf = mem2hex(output_buffer, (char *)®, sizeof(registers));
1296
1297
1298 mem2hex(buf,
1299 (char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),
1300 16 * sizeof(unsigned int));
1301 break;
1302 }
1303 case 'G':
1304
1305
1306
1307
1308
1309 hex2mem((char *)®, &input_buffer[1], sizeof(registers));
1310
1311 hex2mem((char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),
1312 &input_buffer[1] + sizeof(registers),
1313 16 * sizeof(unsigned int));
1314 gdb_cris_strcpy(output_buffer, "OK");
1315 break;
1316
1317 case 'P':
1318
1319
1320
1321
1322
1323
1324
1325 {
1326 char *suffix;
1327 int regno = gdb_cris_strtol(&input_buffer[1], &suffix, 16);
1328 int status;
1329
1330 status = write_register(regno, suffix+1);
1331
1332 switch (status) {
1333 case E02:
1334
1335 gdb_cris_strcpy(output_buffer, error_message[E02]);
1336 break;
1337 case E05:
1338
1339 gdb_cris_strcpy(output_buffer, error_message[E05]);
1340 break;
1341 default:
1342
1343 gdb_cris_strcpy(output_buffer, "OK");
1344 break;
1345 }
1346 }
1347 break;
1348
1349 case 'm':
1350
1351
1352
1353
1354
1355
1356 {
1357 char *suffix;
1358 unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],
1359 &suffix, 16);
1360 int len = gdb_cris_strtol(suffix+1, 0, 16);
1361
1362
1363
1364 if (!((unsigned int)addr >= 0xc0000000 &&
1365 (unsigned int)addr < 0xd0000000))
1366 addr = NULL;
1367
1368 mem2hex(output_buffer, addr, len);
1369 }
1370 break;
1371
1372 case 'X':
1373
1374
1375
1376
1377
1378 case 'M':
1379
1380
1381
1382
1383
1384 {
1385 char *lenptr;
1386 char *dataptr;
1387 unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],
1388 &lenptr, 16);
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);
1393 } else {
1394 bin2mem(addr, dataptr + 1, len);
1395 }
1396 gdb_cris_strcpy(output_buffer, "OK");
1397 }
1398 else {
1399 gdb_cris_strcpy(output_buffer, error_message[E06]);
1400 }
1401 }
1402 break;
1403
1404 case 'c':
1405
1406
1407
1408
1409
1410
1411 if (input_buffer[1] != '\0') {
1412
1413 gdb_cris_strcpy(output_buffer, error_message[E04]);
1414 break;
1415 }
1416
1417
1418
1419
1420 reg.spc = 0;
1421
1422
1423
1424 if ((sreg.s0_3 & 0x3fff) == 0) {
1425 reg.ccs &= ~(1 << (S_CCS_BITNR + CCS_SHIFT));
1426 }
1427
1428 return;
1429
1430 case 's':
1431
1432
1433
1434
1435
1436 if (input_buffer[1] != '\0') {
1437
1438 gdb_cris_strcpy(output_buffer, error_message[E04]);
1439 break;
1440 }
1441
1442
1443
1444 reg.spc = reg.pc;
1445
1446
1447
1448 reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
1449 return;
1450
1451 case 'Z':
1452
1453
1454
1455
1456 {
1457 char *lenptr;
1458 char *dataptr;
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];
1462
1463 insert_watchpoint(type, addr, len);
1464 break;
1465 }
1466
1467 case 'z':
1468
1469
1470
1471 {
1472 char *lenptr;
1473 char *dataptr;
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];
1477
1478 remove_watchpoint(type, addr, len);
1479 break;
1480 }
1481
1482
1483 case '?':
1484
1485
1486
1487 output_buffer[0] = 'S';
1488 output_buffer[1] = hex_asc_hi(sigval);
1489 output_buffer[2] = hex_asc_lo(sigval);
1490 output_buffer[3] = 0;
1491 break;
1492
1493 case 'D':
1494
1495
1496
1497 putpacket("OK");
1498 return;
1499
1500 case 'k':
1501 case 'r':
1502
1503
1504
1505 kill_restart();
1506 break;
1507
1508 case 'C':
1509 case 'S':
1510 case '!':
1511 case 'R':
1512 case 'd':
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523 gdb_cris_strcpy(output_buffer, error_message[E04]);
1524 break;
1525
1526 default:
1527
1528
1529
1530 output_buffer[0] = 0;
1531 break;
1532 }
1533 putpacket(output_buffer);
1534 }
1535}
1536
1537void
1538kgdb_init(void)
1539{
1540 reg_intr_vect_rw_mask intr_mask;
1541 reg_ser_rw_intr_mask ser_intr_mask;
1542
1543
1544#if defined(CONFIG_ETRAX_KGDB_PORT0)
1545
1546
1547 set_exception_vector(SER0_INTR_VECT, kgdb_handle_exception);
1548
1549 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1550 intr_mask.ser0 = 1;
1551 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1552
1553 ser_intr_mask = REG_RD(ser, regi_ser0, rw_intr_mask);
1554 ser_intr_mask.dav = regk_ser_yes;
1555 REG_WR(ser, regi_ser0, rw_intr_mask, ser_intr_mask);
1556#elif defined(CONFIG_ETRAX_KGDB_PORT1)
1557
1558
1559 set_exception_vector(SER1_INTR_VECT, kgdb_handle_exception);
1560
1561 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1562 intr_mask.ser1 = 1;
1563 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1564
1565 ser_intr_mask = REG_RD(ser, regi_ser1, rw_intr_mask);
1566 ser_intr_mask.dav = regk_ser_yes;
1567 REG_WR(ser, regi_ser1, rw_intr_mask, ser_intr_mask);
1568#elif defined(CONFIG_ETRAX_KGDB_PORT2)
1569
1570
1571 set_exception_vector(SER2_INTR_VECT, kgdb_handle_exception);
1572
1573 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1574 intr_mask.ser2 = 1;
1575 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1576
1577 ser_intr_mask = REG_RD(ser, regi_ser2, rw_intr_mask);
1578 ser_intr_mask.dav = regk_ser_yes;
1579 REG_WR(ser, regi_ser2, rw_intr_mask, ser_intr_mask);
1580#elif defined(CONFIG_ETRAX_KGDB_PORT3)
1581
1582
1583 set_exception_vector(SER3_INTR_VECT, kgdb_handle_exception);
1584
1585 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1586 intr_mask.ser3 = 1;
1587 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1588
1589 ser_intr_mask = REG_RD(ser, regi_ser3, rw_intr_mask);
1590 ser_intr_mask.dav = regk_ser_yes;
1591 REG_WR(ser, regi_ser3, rw_intr_mask, ser_intr_mask);
1592#endif
1593
1594}
1595
1596static void
1597kill_restart(void)
1598{
1599 machine_restart("");
1600}
1601
1602
1603
1604void
1605breakpoint(void)
1606{
1607 kgdb_started = 1;
1608 dynamic_bp = 0;
1609 __asm__ volatile ("break 8");
1610}
1611
1612
1613