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
388
389
390static char *mem2hex(char *buf, unsigned char *mem, int count);
391
392
393
394
395static unsigned char *bin2mem(unsigned char *mem, unsigned char *buf, int count);
396
397
398
399static void getpacket(char *buffer);
400
401
402static void putpacket(char *buffer);
403
404
405
406static void stub_is_stopped(int sigval);
407
408
409
410
411void handle_exception(int sigval);
412
413
414static void kill_restart(void);
415
416
417
418
419void putDebugString(const unsigned char *str, int len);
420
421
422void breakpoint(void);
423
424
425#define USEDVAR(name) { if (name) { ; } }
426#define USEDFUN(name) { void (*pf)(void) = (void *)name; USEDVAR(pf) }
427
428
429
430
431
432#define BUFMAX 512
433
434
435#define RUNLENMAX 64
436
437
438static char input_buffer[BUFMAX];
439static char output_buffer[BUFMAX];
440
441
442enum error_type
443{
444 SUCCESS, E01, E02, E03, E04, E05, E06, E07, E08
445};
446
447static char *error_message[] =
448{
449 "",
450 "E01 Set current or general thread - H[c,g] - internal error.",
451 "E02 Change register content - P - cannot change read-only register.",
452 "E03 Thread is not alive.",
453 "E04 The command is not supported - [s,C,S,!,R,d,r] - internal error.",
454 "E05 Change register content - P - the register is not implemented..",
455 "E06 Change memory content - M - internal error.",
456 "E07 Change register content - P - the register is not stored on the stack",
457 "E08 Invalid parameter"
458};
459
460
461
462
463
464#define INTERNAL_STACK_SIZE 1024
465char internal_stack[INTERNAL_STACK_SIZE];
466
467
468
469
470
471
472
473static int dynamic_bp = 0;
474
475
476
477
478
479static char*
480gdb_cris_strcpy(char *s1, const char *s2)
481{
482 char *s = s1;
483
484 for (s = s1; (*s++ = *s2++) != '\0'; )
485 ;
486 return s1;
487}
488
489
490static int
491gdb_cris_strlen(const char *s)
492{
493 const char *sc;
494
495 for (sc = s; *sc != '\0'; sc++)
496 ;
497 return (sc - s);
498}
499
500
501static void*
502gdb_cris_memchr(const void *s, int c, int n)
503{
504 const unsigned char uc = c;
505 const unsigned char *su;
506
507 for (su = s; 0 < n; ++su, --n)
508 if (*su == uc)
509 return (void *)su;
510 return NULL;
511}
512
513
514
515static int
516gdb_cris_strtol(const char *s, char **endptr, int base)
517{
518 char *s1;
519 char *sd;
520 int x = 0;
521
522 for (s1 = (char*)s; (sd = gdb_cris_memchr(hex_asc, *s1, base)) != NULL; ++s1)
523 x = x * base + (sd - hex_asc);
524
525 if (endptr) {
526
527 *endptr = s1;
528 }
529
530 return x;
531}
532
533
534
535
536
537static int
538write_register(int regno, char *val)
539{
540 int status = SUCCESS;
541
542 if (regno >= R0 && regno <= ACR) {
543
544 if (hex2bin((unsigned char *)®.r0 + (regno - R0) * sizeof(unsigned int),
545 val, sizeof(unsigned int)))
546 status = E08;
547
548 } else if (regno == BZ || regno == VR || regno == WZ || regno == DZ) {
549
550 status = E02;
551
552 } else if (regno == PID) {
553
554
555 if (hex2bin((unsigned char *)®.pid, val, sizeof(unsigned int)))
556 status = E08;
557
558 } else if (regno == SRS) {
559
560 if (hex2bin((unsigned char *)®.srs, val, sizeof(unsigned char)))
561 status = E08;
562
563 } else if (regno >= EXS && regno <= SPC) {
564
565 if (hex2bin((unsigned char *)®.exs + (regno - EXS) * sizeof(unsigned int),
566 val, sizeof(unsigned int)))
567 status = E08;
568
569 } else if (regno == PC) {
570
571 status = E02;
572
573 } else if (regno >= S0 && regno <= S15) {
574
575 if (hex2bin((unsigned char *)&sreg.s0_0 + (reg.srs * 16 * sizeof(unsigned int)) + (regno - S0) * sizeof(unsigned int),
576 val, sizeof(unsigned int)))
577 status = E08;
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
634
635
636
637static char *
638mem2hex(char *buf, unsigned char *mem, int count)
639{
640 int i;
641 int ch;
642
643 if (mem == NULL) {
644
645 for (i = 0; i < count; i++) {
646 *buf++ = '0';
647 *buf++ = '0';
648 }
649 } else {
650
651 for (i = 0; i < count; i++) {
652 ch = *mem++;
653 buf = hex_byte_pack(buf, ch);
654 }
655 }
656
657 *buf = '\0';
658 return buf;
659}
660
661
662static char *
663mem2hex_nbo(char *buf, unsigned char *mem, int count)
664{
665 int i;
666 int ch;
667
668 mem += count - 1;
669 for (i = 0; i < count; i++) {
670 ch = *mem--;
671 buf = hex_byte_pack(buf, ch);
672 }
673
674
675 *buf = '\0';
676 return buf;
677}
678
679
680
681
682
683static unsigned char*
684bin2mem(unsigned char *mem, unsigned char *buf, int count)
685{
686 int i;
687 unsigned char *next;
688 for (i = 0; i < count; i++) {
689
690
691 if (*buf == 0x7d) {
692 next = buf + 1;
693 if (*next == 0x3 || *next == 0x4 || *next == 0x5D) {
694
695 buf++;
696 *buf += 0x20;
697 }
698 }
699 *mem++ = *buf++;
700 }
701 return mem;
702}
703
704
705
706static void
707getpacket(char *buffer)
708{
709 unsigned char checksum;
710 unsigned char xmitcsum;
711 int i;
712 int count;
713 char ch;
714
715 do {
716 while((ch = getDebugChar ()) != '$')
717 ;
718 checksum = 0;
719 xmitcsum = -1;
720 count = 0;
721
722 while (count < BUFMAX) {
723 ch = getDebugChar();
724 if (ch == '#')
725 break;
726 checksum = checksum + ch;
727 buffer[count] = ch;
728 count = count + 1;
729 }
730
731 if (count >= BUFMAX)
732 continue;
733
734 buffer[count] = 0;
735
736 if (ch == '#') {
737 xmitcsum = hex_to_bin(getDebugChar()) << 4;
738 xmitcsum += hex_to_bin(getDebugChar());
739 if (checksum != xmitcsum) {
740
741 putDebugChar('-');
742 } else {
743
744 putDebugChar('+');
745
746 if (buffer[2] == ':') {
747 putDebugChar(buffer[0]);
748 putDebugChar(buffer[1]);
749
750 count = gdb_cris_strlen(buffer);
751 for (i = 3; i <= count; i++)
752 buffer[i - 3] = buffer[i];
753 }
754 }
755 }
756 } while (checksum != xmitcsum);
757}
758
759
760
761static void
762putpacket(char *buffer)
763{
764 int checksum;
765 int runlen;
766 int encode;
767
768 do {
769 char *src = buffer;
770 putDebugChar('$');
771 checksum = 0;
772 while (*src) {
773
774 putDebugChar(*src);
775 checksum += *src;
776 runlen = 0;
777 while (runlen < RUNLENMAX && *src == src[runlen]) {
778 runlen++;
779 }
780 if (runlen > 3) {
781
782 putDebugChar ('*');
783 checksum += '*';
784 encode = runlen + ' ' - 4;
785 putDebugChar(encode);
786 checksum += encode;
787 src += runlen;
788 } else {
789 src++;
790 }
791 }
792 putDebugChar('#');
793 putDebugChar(hex_asc_hi(checksum));
794 putDebugChar(hex_asc_lo(checksum));
795 } while(kgdb_started && (getDebugChar() != '+'));
796}
797
798
799
800void
801putDebugString(const unsigned char *str, int len)
802{
803
804 asm("spchere:");
805 asm("move $spc, $r10");
806 asm("cmp.d spchere, $r10");
807 asm("bne nosstep");
808 asm("nop");
809 asm("move.d spccont, $r10");
810 asm("move $r10, $spc");
811 asm("nosstep:");
812
813 output_buffer[0] = 'O';
814 mem2hex(&output_buffer[1], (unsigned char *)str, len);
815 putpacket(output_buffer);
816
817 asm("spccont:");
818}
819
820
821
822
823
824
825
826
827
828
829
830
831static void
832stub_is_stopped(int sigval)
833{
834 char *ptr = output_buffer;
835 unsigned int reg_cont;
836
837
838
839 *ptr++ = 'T';
840 ptr = hex_byte_pack(ptr, sigval);
841
842 if (((reg.exs & 0xff00) >> 8) == 0xc) {
843
844
845
846 int S, bp, trig_bits = 0, rw_bits = 0;
847 int trig_mask = 0;
848 unsigned int *bp_d_regs = &sreg.s3_3;
849
850
851
852 unsigned int stopped_data_address;
853
854 S = (reg.exs & 0xffff0000) >> 16;
855
856 if (S & 1) {
857
858
859 } else {
860
861 for (bp = 0; bp < 6; bp++) {
862
863
864 int bitpos_trig = 1 + bp * 2;
865
866 int bitpos_config = 2 + bp * 4;
867
868
869 trig_bits = (S & (3 << bitpos_trig)) >> bitpos_trig;
870
871
872 rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;
873 if (trig_bits) {
874
875
876 if ((rw_bits == 0x1 && trig_bits != 0x1) ||
877 (rw_bits == 0x2 && trig_bits != 0x2))
878 panic("Invalid r/w trigging for this BP");
879
880
881 trig_mask |= (1 << bp);
882
883 if (reg.eda >= bp_d_regs[bp * 2] &&
884 reg.eda <= bp_d_regs[bp * 2 + 1]) {
885
886
887 stopped_data_address = reg.eda;
888 break;
889 }
890 }
891 }
892 if (bp < 6) {
893
894 } else if (trig_mask) {
895
896 for (bp = 0; bp < 6; bp++) {
897
898 int bitpos_config = 2 + bp * 4;
899
900
901 rw_bits = (sreg.s0_3 & (3 << bitpos_config)) >> bitpos_config;
902
903 if (trig_mask & (1 << bp)) {
904
905 if (reg.eda + 31 >= bp_d_regs[bp * 2]) {
906
907
908 stopped_data_address = bp_d_regs[bp * 2];
909 break;
910 } else {
911
912 printk("EDA doesn't match trigged BP's range");
913 }
914 }
915 }
916 }
917
918
919 BUG_ON(bp >= 6);
920
921
922
923
924 if (rw_bits == 0x1) {
925
926 strncpy(ptr, "rwatch", 6);
927 ptr += 6;
928 } else if (rw_bits == 0x2) {
929
930 strncpy(ptr, "watch", 5);
931 ptr += 5;
932 } else if (rw_bits == 0x3) {
933
934 strncpy(ptr, "awatch", 6);
935 ptr += 6;
936 } else {
937 panic("Invalid r/w bits for this BP.");
938 }
939
940 *ptr++ = ':';
941
942 ptr = mem2hex_nbo(ptr, (unsigned char *)&stopped_data_address, register_size[EDA]);
943 *ptr++ = ';';
944 }
945 }
946
947 read_register(PC, ®_cont);
948 ptr = hex_byte_pack(ptr, PC);
949 *ptr++ = ':';
950 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[PC]);
951 *ptr++ = ';';
952
953 read_register(R8, ®_cont);
954 ptr = hex_byte_pack(ptr, R8);
955 *ptr++ = ':';
956 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[R8]);
957 *ptr++ = ';';
958
959 read_register(SP, ®_cont);
960 ptr = hex_byte_pack(ptr, SP);
961 *ptr++ = ':';
962 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[SP]);
963 *ptr++ = ';';
964
965
966 read_register(ERP, ®_cont);
967 ptr = hex_byte_pack(ptr, ERP);
968 *ptr++ = ':';
969 ptr = mem2hex(ptr, (unsigned char *)®_cont, register_size[ERP]);
970 *ptr++ = ';';
971
972
973 *ptr = 0;
974 putpacket(output_buffer);
975}
976
977
978
979int insn_size(unsigned long pc)
980{
981 unsigned short opcode = *(unsigned short *)pc;
982 int size = 0;
983
984 switch ((opcode & 0x0f00) >> 8) {
985 case 0x0:
986 case 0x9:
987 case 0xb:
988 size = 2;
989 break;
990 case 0xe:
991 case 0xf:
992 size = 6;
993 break;
994 case 0xd:
995
996 if ((opcode & 0xff) == 0xff)
997 size = 4;
998 else
999 size = 6;
1000 break;
1001 default:
1002 panic("Couldn't find size of opcode 0x%x at 0x%lx\n", opcode, pc);
1003 }
1004
1005 return size;
1006}
1007
1008void register_fixup(int sigval)
1009{
1010
1011 reg.sp += 4;
1012
1013
1014 reg.pc = reg.erp;
1015 if (reg.erp & 0x1) {
1016
1017 if (reg.spc) {
1018
1019 reg.pc = reg.spc;
1020 } else {
1021
1022
1023 reg.pc += insn_size(reg.erp & ~1) - 1 ;
1024 }
1025 }
1026
1027 if ((reg.exs & 0x3) == 0x0) {
1028
1029
1030
1031 reg.eda = 0;
1032 }
1033
1034 if (sigval == SIGTRAP) {
1035
1036
1037
1038 if (((reg.exs & 0xff00) >> 8) == 0x18) {
1039
1040
1041
1042
1043
1044
1045
1046
1047 if (!dynamic_bp) {
1048
1049 dynamic_bp = 1;
1050 } else {
1051
1052
1053 if (!(reg.erp & 0x1)) {
1054 reg.erp -= 2;
1055 reg.pc -= 2;
1056 }
1057 }
1058
1059 } else if (((reg.exs & 0xff00) >> 8) == 0x3) {
1060
1061
1062
1063 } else if (((reg.exs & 0xff00) >> 8) == 0xc) {
1064
1065
1066
1067
1068
1069 reg.spc = 0;
1070
1071
1072 }
1073
1074 } else if (sigval == SIGINT) {
1075
1076 }
1077}
1078
1079static void insert_watchpoint(char type, int addr, int len)
1080{
1081
1082
1083
1084
1085
1086
1087
1088
1089 if (type < '1' || type > '4') {
1090 output_buffer[0] = 0;
1091 return;
1092 }
1093
1094
1095
1096 if (type == '3')
1097 type = '4';
1098
1099 if (type == '1') {
1100
1101
1102 if (sreg.s0_3 & 0x1) {
1103
1104 gdb_cris_strcpy(output_buffer, error_message[E04]);
1105 return;
1106 }
1107
1108 sreg.s1_3 = addr;
1109 sreg.s2_3 = (addr + len - 1);
1110 sreg.s0_3 |= 1;
1111 } else {
1112 int bp;
1113 unsigned int *bp_d_regs = &sreg.s3_3;
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123 for (bp = 0; bp < 6; bp++) {
1124
1125
1126
1127 if (!(sreg.s0_3 & (0x3 << (2 + (bp * 4))))) {
1128 break;
1129 }
1130 }
1131
1132 if (bp > 5) {
1133
1134 gdb_cris_strcpy(output_buffer, error_message[E04]);
1135 return;
1136 }
1137
1138
1139 if (type == '3' || type == '4') {
1140
1141 sreg.s0_3 |= (1 << (2 + bp * 4));
1142 }
1143 if (type == '2' || type == '4') {
1144
1145 sreg.s0_3 |= (2 << (2 + bp * 4));
1146 }
1147
1148
1149 bp_d_regs[bp * 2] = addr;
1150 bp_d_regs[bp * 2 + 1] = (addr + len - 1);
1151 }
1152
1153
1154 reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
1155 gdb_cris_strcpy(output_buffer, "OK");
1156}
1157
1158static void remove_watchpoint(char type, int addr, int len)
1159{
1160
1161
1162
1163
1164
1165
1166
1167 if (type < '1' || type > '4') {
1168 output_buffer[0] = 0;
1169 return;
1170 }
1171
1172
1173
1174 if (type == '3')
1175 type = '4';
1176
1177 if (type == '1') {
1178
1179
1180 if (!(sreg.s0_3 & 0x1)) {
1181
1182 gdb_cris_strcpy(output_buffer, error_message[E04]);
1183 return;
1184 }
1185
1186 sreg.s1_3 = 0;
1187 sreg.s2_3 = 0;
1188 sreg.s0_3 &= ~1;
1189 } else {
1190 int bp;
1191 unsigned int *bp_d_regs = &sreg.s3_3;
1192
1193
1194
1195
1196
1197
1198
1199 for (bp = 0; bp < 6; bp++) {
1200 if (bp_d_regs[bp * 2] == addr &&
1201 bp_d_regs[bp * 2 + 1] == (addr + len - 1)) {
1202
1203 int bitpos = 2 + bp * 4;
1204 int rw_bits;
1205
1206
1207 rw_bits = (sreg.s0_3 & (0x3 << bitpos)) >> bitpos;
1208
1209 if ((type == '3' && rw_bits == 0x1) ||
1210 (type == '2' && rw_bits == 0x2) ||
1211 (type == '4' && rw_bits == 0x3)) {
1212
1213 break;
1214 }
1215 }
1216 }
1217
1218 if (bp > 5) {
1219
1220 gdb_cris_strcpy(output_buffer, error_message[E04]);
1221 return;
1222 }
1223
1224
1225
1226
1227 sreg.s0_3 &= ~(3 << (2 + (bp * 4)));
1228 bp_d_regs[bp * 2] = 0;
1229 bp_d_regs[bp * 2 + 1] = 0;
1230 }
1231
1232
1233 gdb_cris_strcpy(output_buffer, "OK");
1234}
1235
1236
1237
1238
1239
1240void
1241handle_exception(int sigval)
1242{
1243
1244
1245 USEDFUN(handle_exception);
1246 USEDVAR(internal_stack[0]);
1247
1248 register_fixup(sigval);
1249
1250
1251 stub_is_stopped(sigval);
1252
1253 for (;;) {
1254 output_buffer[0] = '\0';
1255 getpacket(input_buffer);
1256 switch (input_buffer[0]) {
1257 case 'g':
1258
1259
1260
1261
1262
1263 {
1264 char *buf;
1265
1266 buf = mem2hex(output_buffer, (char *)®, sizeof(registers));
1267
1268
1269 mem2hex(buf,
1270 (char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),
1271 16 * sizeof(unsigned int));
1272 break;
1273 }
1274 case 'G':
1275
1276
1277
1278
1279
1280 if (hex2bin((char *)®, &input_buffer[1], sizeof(registers)))
1281 gdb_cris_strcpy(output_buffer, error_message[E08]);
1282
1283 else if (hex2bin((char *)&sreg + (reg.srs * 16 * sizeof(unsigned int)),
1284 &input_buffer[1] + sizeof(registers),
1285 16 * sizeof(unsigned int)))
1286 gdb_cris_strcpy(output_buffer, error_message[E08]);
1287 else
1288 gdb_cris_strcpy(output_buffer, "OK");
1289 break;
1290
1291 case 'P':
1292
1293
1294
1295
1296
1297
1298
1299 {
1300 char *suffix;
1301 int regno = gdb_cris_strtol(&input_buffer[1], &suffix, 16);
1302 int status;
1303
1304 status = write_register(regno, suffix+1);
1305
1306 switch (status) {
1307 case E02:
1308
1309 gdb_cris_strcpy(output_buffer, error_message[E02]);
1310 break;
1311 case E05:
1312
1313 gdb_cris_strcpy(output_buffer, error_message[E05]);
1314 break;
1315 case E08:
1316
1317 gdb_cris_strcpy(output_buffer, error_message[E08]);
1318 break;
1319 default:
1320
1321 gdb_cris_strcpy(output_buffer, "OK");
1322 break;
1323 }
1324 }
1325 break;
1326
1327 case 'm':
1328
1329
1330
1331
1332
1333
1334 {
1335 char *suffix;
1336 unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],
1337 &suffix, 16);
1338 int len = gdb_cris_strtol(suffix+1, 0, 16);
1339
1340
1341
1342 if (!((unsigned int)addr >= 0xc0000000 &&
1343 (unsigned int)addr < 0xd0000000))
1344 addr = NULL;
1345
1346 mem2hex(output_buffer, addr, len);
1347 }
1348 break;
1349
1350 case 'X':
1351
1352
1353
1354
1355
1356 case 'M':
1357
1358
1359
1360
1361
1362 {
1363 char *lenptr;
1364 char *dataptr;
1365 unsigned char *addr = (unsigned char *)gdb_cris_strtol(&input_buffer[1],
1366 &lenptr, 16);
1367 int len = gdb_cris_strtol(lenptr+1, &dataptr, 16);
1368 if (*lenptr == ',' && *dataptr == ':') {
1369 if (input_buffer[0] == 'M') {
1370 if (hex2bin(addr, dataptr + 1, len))
1371 gdb_cris_strcpy(output_buffer, error_message[E08]);
1372 else
1373 gdb_cris_strcpy(output_buffer, "OK");
1374 } else {
1375 bin2mem(addr, dataptr + 1, len);
1376 gdb_cris_strcpy(output_buffer, "OK");
1377 }
1378 } else {
1379 gdb_cris_strcpy(output_buffer, error_message[E06]);
1380 }
1381 }
1382 break;
1383
1384 case 'c':
1385
1386
1387
1388
1389
1390
1391 if (input_buffer[1] != '\0') {
1392
1393 gdb_cris_strcpy(output_buffer, error_message[E04]);
1394 break;
1395 }
1396
1397
1398
1399
1400 reg.spc = 0;
1401
1402
1403
1404 if ((sreg.s0_3 & 0x3fff) == 0) {
1405 reg.ccs &= ~(1 << (S_CCS_BITNR + CCS_SHIFT));
1406 }
1407
1408 return;
1409
1410 case 's':
1411
1412
1413
1414
1415
1416 if (input_buffer[1] != '\0') {
1417
1418 gdb_cris_strcpy(output_buffer, error_message[E04]);
1419 break;
1420 }
1421
1422
1423
1424 reg.spc = reg.pc;
1425
1426
1427
1428 reg.ccs |= (1 << (S_CCS_BITNR + CCS_SHIFT));
1429 return;
1430
1431 case 'Z':
1432
1433
1434
1435
1436 {
1437 char *lenptr;
1438 char *dataptr;
1439 int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);
1440 int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);
1441 char type = input_buffer[1];
1442
1443 insert_watchpoint(type, addr, len);
1444 break;
1445 }
1446
1447 case 'z':
1448
1449
1450
1451 {
1452 char *lenptr;
1453 char *dataptr;
1454 int addr = gdb_cris_strtol(&input_buffer[3], &lenptr, 16);
1455 int len = gdb_cris_strtol(lenptr + 1, &dataptr, 16);
1456 char type = input_buffer[1];
1457
1458 remove_watchpoint(type, addr, len);
1459 break;
1460 }
1461
1462
1463 case '?':
1464
1465
1466
1467 output_buffer[0] = 'S';
1468 output_buffer[1] = hex_asc_hi(sigval);
1469 output_buffer[2] = hex_asc_lo(sigval);
1470 output_buffer[3] = 0;
1471 break;
1472
1473 case 'D':
1474
1475
1476
1477 putpacket("OK");
1478 return;
1479
1480 case 'k':
1481 case 'r':
1482
1483
1484
1485 kill_restart();
1486 break;
1487
1488 case 'C':
1489 case 'S':
1490 case '!':
1491 case 'R':
1492 case 'd':
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503 gdb_cris_strcpy(output_buffer, error_message[E04]);
1504 break;
1505
1506 default:
1507
1508
1509
1510 output_buffer[0] = 0;
1511 break;
1512 }
1513 putpacket(output_buffer);
1514 }
1515}
1516
1517void
1518kgdb_init(void)
1519{
1520 reg_intr_vect_rw_mask intr_mask;
1521 reg_ser_rw_intr_mask ser_intr_mask;
1522
1523
1524#if defined(CONFIG_ETRAX_KGDB_PORT0)
1525
1526
1527 set_exception_vector(SER0_INTR_VECT, kgdb_handle_exception);
1528
1529 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1530 intr_mask.ser0 = 1;
1531 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1532
1533 ser_intr_mask = REG_RD(ser, regi_ser0, rw_intr_mask);
1534 ser_intr_mask.dav = regk_ser_yes;
1535 REG_WR(ser, regi_ser0, rw_intr_mask, ser_intr_mask);
1536#elif defined(CONFIG_ETRAX_KGDB_PORT1)
1537
1538
1539 set_exception_vector(SER1_INTR_VECT, kgdb_handle_exception);
1540
1541 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1542 intr_mask.ser1 = 1;
1543 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1544
1545 ser_intr_mask = REG_RD(ser, regi_ser1, rw_intr_mask);
1546 ser_intr_mask.dav = regk_ser_yes;
1547 REG_WR(ser, regi_ser1, rw_intr_mask, ser_intr_mask);
1548#elif defined(CONFIG_ETRAX_KGDB_PORT2)
1549
1550
1551 set_exception_vector(SER2_INTR_VECT, kgdb_handle_exception);
1552
1553 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1554 intr_mask.ser2 = 1;
1555 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1556
1557 ser_intr_mask = REG_RD(ser, regi_ser2, rw_intr_mask);
1558 ser_intr_mask.dav = regk_ser_yes;
1559 REG_WR(ser, regi_ser2, rw_intr_mask, ser_intr_mask);
1560#elif defined(CONFIG_ETRAX_KGDB_PORT3)
1561
1562
1563 set_exception_vector(SER3_INTR_VECT, kgdb_handle_exception);
1564
1565 intr_mask = REG_RD(intr_vect, regi_irq, rw_mask);
1566 intr_mask.ser3 = 1;
1567 REG_WR(intr_vect, regi_irq, rw_mask, intr_mask);
1568
1569 ser_intr_mask = REG_RD(ser, regi_ser3, rw_intr_mask);
1570 ser_intr_mask.dav = regk_ser_yes;
1571 REG_WR(ser, regi_ser3, rw_intr_mask, ser_intr_mask);
1572#endif
1573
1574}
1575
1576static void
1577kill_restart(void)
1578{
1579 machine_restart("");
1580}
1581
1582
1583
1584void
1585breakpoint(void)
1586{
1587 kgdb_started = 1;
1588 dynamic_bp = 0;
1589 __asm__ volatile ("break 8");
1590}
1591
1592
1593