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