-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcc.c
1254 lines (1053 loc) · 22.8 KB
/
cc.c
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// cc --- crude version of CC
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>
#include "ucode.h"
#include "decode.h"
int fd;
int debug;
int verbose;
#define WRITE 1
#define rd_spy_ir_low 0
#define rd_spy_ir_med 1
#define rd_spy_ir_high 2
#define rd_spy_scratch 3
#define rd_spy_opc 4
#define rd_spy_pc 5
#define rd_spy_ob_low 6
#define rd_spy_ob_high 7
#define rd_spy_flag_1 010
#define rd_spy_flag_2 011
#define rd_spy_m_low 012
#define rd_spy_m_high 013
#define rd_spy_a_low 014
#define rd_spy_a_high 015
#define rd_spy_stat_low 016
#define rd_spy_stat_high 017
#define rd_spy_md_low 020
#define rd_spy_md_high 021
#define rd_spy_vma_low 022
#define rd_spy_vma_high 023
#define rd_spy_disk 026
#define rd_spy_bd 027
#define wr_spy_ir_low 0
#define wr_spy_ir_med 1
#define wr_spy_ir_high 2
#define wr_spy_clk 3
#define wr_spy_opc_control 4
#define wr_spy_mode 5
#define wr_spy_scratch 7
#define wr_spy_md_low 010
#define wr_spy_md_high 011
#define wr_spy_vma_low 012
#define wr_spy_vma_high 013
#include "lcadmc.h"
uint32_t cc_read_md(void);
int cc_noop_debug_clock(void);
int cc_debug_clock(void);
int cc_noop_clock(void);
int cc_clock(void);
int
cc_send(unsigned char *b, int len)
{
int ret;
// Send slowly so as not to confuse hardware.
for (int i = 0; i < len; i++) {
ret = write(fd, b + i, 1);
if (ret != 1)
perror("write");
tcflush(fd, TCOFLUSH);
usleep(50);
usleep(2000);
}
usleep(10000);
return len;
}
uint16_t
reg_get(int base, int reg)
{
unsigned char buffer[64];
unsigned char nibs[4];
int ret;
int mask;
int loops;
int off;
uint16_t v;
again:
buffer[0] = base | (reg & 0x1f);
if (debug)
printf("send %02x\n", buffer[0]);
cc_send(buffer, 1);
usleep(1000 * 100);
memset(buffer, 0, 64);
loops = 0;
off = 0;
while (1) {
ret = read(fd, buffer + off, 64 - off);
if (ret > 0)
off += ret;
if (off == 4)
break;
if (ret < 0 && errno == 11) {
usleep(100);
loops++;
if (loops > 5)
goto again;
continue;
}
}
if (debug) {
printf("response %d\n", ret);
printf("%02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3]);
}
if (off < 4) {
printf("spy register read failed (ret=%d, off=%d, errno=%d)\n", ret, off, errno);
return -1;
}
// Response should be 0x3x, 0x4x, 0x5x, 0x6x, but hardware can
// sometimes repeat characters.
mask = 0;
for (int i = 0; i < ret; i++) {
int nib;
nib = (buffer[i] & 0xf0) >> 4;
switch (nib) {
case 3:
mask |= 8;
nibs[0] = buffer[i];
break;
case 4:
mask |= 4;
nibs[1] = buffer[i];
break;
case 5:
mask |= 2;
nibs[2] = buffer[i];
break;
case 6:
mask |= 1;
nibs[3] = buffer[i];
break;
}
}
if (mask == 0xf) {
if (debug)
printf("response ok\n");
v = ((nibs[0] & 0x0f) << 12) | ((nibs[1] & 0x0f) << 8) | ((nibs[2] & 0x0f) << 4) | ((nibs[3] & 0x0f) << 0);
if (debug)
printf("reg %o = 0x%04x (0%o)\n", reg, v, v);
return v;
}
return 0;
}
int
reg_set(int base, int reg, int v)
{
unsigned char buffer[64];
int ret;
if (debug)
printf("cc_set(r=%d, v=%o)\n", reg, v);
buffer[0] = 0x30 | ((v >> 12) & 0xf);
buffer[1] = 0x40 | ((v >> 8) & 0xf);
buffer[2] = 0x50 | ((v >> 4) & 0xf);
buffer[3] = 0x60 | ((v >> 0) & 0xf);
buffer[4] = base | (reg & 0x1f);
if (debug) {
printf("writing, fd=%d\n", fd);
printf("%02x %02x %02x %02x %02x\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
}
ret = cc_send(buffer, 5);
if (debug)
printf("ret %d\n", ret);
if (ret != 5)
printf("cc_set: write error%d\n", ret);
return 0;
}
uint16_t
cc_get(int reg)
{
return reg_get(0x80, reg);
}
int
cc_set(int reg, int v)
{
return reg_set(0xa0, reg, v);
}
uint16_t
mmc_get(int reg)
{
return reg_get(0xc0, reg);
}
int
mmc_set(int reg, int v)
{
return reg_set(0xd0, reg, v);
}
int
cc_stop(void)
{
return cc_set(wr_spy_clk, 0);
}
int
cc_go(void)
{
return cc_set(wr_spy_clk, 0001);
}
uint32_t
_cc_read_pair(int r1, int r2)
{
uint32_t v1;
uint32_t v2;
v1 = cc_get(r1);
v2 = cc_get(r2);
return (v1 << 16) | v2;
}
uint64_t
_cc_read_triple(int r1, int r2, int r3)
{
uint64_t v1;
uint32_t v2;
uint32_t v3;
v1 = cc_get(r1);
v2 = cc_get(r2);
v3 = cc_get(r3);
return (v1 << 32) | (v2 << 16) | v3;
}
// See SYS; LCADR: LCADRD LISP and SYS;LCADR:LCADMC LISP for details.
//
// ---!!! Split this into "lcadrd.c", and add comments from LCADMC LISP.
uint32_t
cc_read_obus(void)
{
return _cc_read_pair(rd_spy_ob_high, rd_spy_ob_low);
}
uint32_t
cc_read_obus_(void)
{
return _cc_read_pair(025, 024);
}
uint32_t
cc_read_a_bus(void)
{
return _cc_read_pair(rd_spy_a_high, rd_spy_a_low);
}
uint32_t
cc_read_m_bus(void)
{
return _cc_read_pair(rd_spy_m_high, rd_spy_m_low);
}
uint64_t
cc_read_ir(void)
{
return _cc_read_triple(rd_spy_ir_high, rd_spy_ir_med, rd_spy_ir_low);
}
uint16_t
cc_read_pc(void)
{
return cc_get(rd_spy_pc);
}
uint16_t
cc_read_scratch(void)
{
return cc_get(rd_spy_scratch);
}
uint32_t
cc_read_status(void)
{
uint16_t v1;
uint16_t v2;
uint16_t v3;
v1 = cc_get(rd_spy_flag_1);
v2 = cc_get(rd_spy_flag_2);
v3 = cc_get(rd_spy_ir_low);
if (v3 & 0100)
v2 ^= 4; // Hardware reads JC-TRUE incorrectly.
return (v1 << 16) | v2;
}
int
cc_write_diag_ir(uint64_t ir)
{
if (debug || verbose)
disassemble_ucode_loc(ir);
cc_set(wr_spy_ir_high, (uint16_t) ((ir >> 32) & 0xffff));
cc_set(wr_spy_ir_med, (uint16_t) ((ir >> 16) & 0xffff));
cc_set(wr_spy_ir_low, (uint16_t) ((ir >> 0) & 0xffff));
cc_set(wr_spy_ir_high, (uint16_t) ((ir >> 32) & 0xffff));
cc_set(wr_spy_ir_med, (uint16_t) ((ir >> 16) & 0xffff));
cc_set(wr_spy_ir_low, (uint16_t) ((ir >> 0) & 0xffff));
return 0;
}
int
cc_write_ir(uint64_t ir)
{
if (debug || verbose)
printf("ir %" PRIu64 " (0x%016llx)\n", ir, ir);
cc_write_diag_ir(ir);
return cc_noop_debug_clock();
}
int
cc_execute_r(uint64_t ir)
{
int ret;
if (debug || verbose)
printf("ir %" PRIu64 " (0x%016" PRIx64 ")\n", ir, ir);
again:
cc_write_diag_ir(ir);
cc_noop_debug_clock();
if (cc_read_ir() != ir) {
printf("ir reread failed; retry\n");
goto again;
}
ret = cc_debug_clock();
return ret;
}
int
cc_execute_w(uint64_t ir)
{
int ret;
if (debug || verbose)
printf("ir %" PRIu64 " (0x%016" PRIx64 ")\n", ir, ir);
again:
cc_write_diag_ir(ir);
cc_noop_debug_clock();
if (cc_read_ir() != ir) {
printf("ir reread failed; retry\n");
goto again;
}
cc_clock();
ret = cc_noop_clock();
return ret;
}
int
cc_execute(int op, uint64_t ir)
{
if (debug)
disassemble_ucode_loc(ir);
if (op == WRITE) {
return cc_execute_w(ir);
}
return cc_execute_r(ir);
}
uint32_t
bitmask(int wid)
{
uint32_t m;
m = 0;
for (int i = 0; i < wid; i++) {
m <<= 1;
m |= 1;
}
return m;
}
uint64_t
ir_pair(int field, uint32_t val)
{
uint64_t ir;
uint32_t mask;
int shift;
int width;
shift = field >> 6;
width = field & 077;
mask = bitmask(width);
val &= mask;
ir = ((uint64_t) val) << shift;
if (debug)
printf("ir_pair field=%o, shift=%d, width=%d, mask=%x, val=%x\n", field, shift, width, mask, val);
return ir;
}
uint32_t
cc_read_md(void)
{
return _cc_read_pair(rd_spy_md_high, rd_spy_md_low);
}
int
cc_write_md(uint32_t md)
{
cc_set(wr_spy_md_high, (uint16_t) (md >> 16) & 0xffff);
cc_set(wr_spy_md_low, (uint16_t) (md >> 0) & 0xffff);
while (1) {
uint32_t v;
v = cc_read_md();
if (v == md)
break;
printf("md readback failed, retry got %x want %x\n", v, md);
cc_set(wr_spy_md_high, (uint16_t) (md >> 16) & 0xffff);
cc_set(wr_spy_md_low, (uint16_t) (md >> 0) & 0xffff);
}
return 0;
}
uint32_t
cc_read_vma(void)
{
return _cc_read_pair(rd_spy_vma_high, rd_spy_vma_low);
}
int
cc_write_vma(uint32_t vma)
{
cc_set(wr_spy_vma_high, (uint16_t) (vma >> 16) & 0xffff);
cc_set(wr_spy_vma_low, (uint16_t) (vma >> 0) & 0xffff);
while (cc_read_vma() != vma) {
printf("vma readback failed, retry\n");
cc_set(wr_spy_vma_high, (uint16_t) (vma >> 16) & 0xffff);
cc_set(wr_spy_vma_low, (uint16_t) (vma >> 0) & 0xffff);
}
return 0;
}
int
cc_write_md_1s(void)
{
cc_write_md(0xffffffff);
return 0;
}
int
cc_write_md_0s(void)
{
cc_write_md(0x00000000);
return 0;
}
uint32_t
cc_read_a_mem(uint32_t adr)
{
cc_execute(0,
ir_pair(CONS_IR_A_SRC, adr) |
ir_pair(CONS_IR_ALUF, CONS_ALU_SETA) |
ir_pair(CONS_IR_OB, CONS_OB_ALU));
return cc_read_obus();
}
uint32_t
cc_write_a_mem(uint32_t loc, uint32_t val)
{
uint32_t v2;
cc_write_md(val);
v2 = cc_read_md();
if (v2 != val) {
printf("cc_write_a_mem; md readback error (got=%o wanted=%o)\n", v2, val);
}
cc_execute(WRITE,
ir_pair(CONS_IR_M_SRC, CONS_M_SRC_MD) |
ir_pair(CONS_IR_ALUF, CONS_ALU_SETM) |
ir_pair(CONS_IR_OB, CONS_OB_ALU) |
ir_pair(CONS_IR_A_MEM_DEST, CONS_A_MEM_DEST_INDICATOR + loc));
return 0;
}
uint32_t
cc_read_m_mem(uint32_t adr)
{
cc_execute(0,
ir_pair(CONS_IR_M_SRC, adr) |
ir_pair(CONS_IR_ALUF, CONS_ALU_SETM) |
ir_pair(CONS_IR_OB, CONS_OB_ALU));
return cc_read_obus();
}
int
cc_debug_clock(void)
{
cc_set(wr_spy_clk, 012);
cc_set(wr_spy_clk, 0);
return 0;
}
int
cc_noop_debug_clock(void)
{
cc_set(wr_spy_clk, 016);
cc_set(wr_spy_clk, 0);
return 0;
}
int
cc_clock(void)
{
cc_set(wr_spy_clk, 2);
cc_set(wr_spy_clk, 0);
return 0;
}
int
cc_noop_clock(void)
{
cc_set(wr_spy_clk, 6);
cc_set(wr_spy_clk, 0);
return 0;
}
int
cc_single_step(void)
{
cc_set(wr_spy_clk, 6);
cc_set(wr_spy_clk, 0);
return 0;
}
int
cc_report_basic_regs(void)
{
uint32_t A;
uint32_t M;
uint32_t PC;
uint32_t MD;
uint32_t VMA;
A = cc_read_a_bus();
printf("A = %011o (%08x)\n", A, A);
M = cc_read_m_bus();
printf("M = %011o (%08x)\n", M, M);
PC = cc_read_pc();
printf("PC = %011o (%08x)\n", PC, PC);
MD = cc_read_md();
printf("MD = %011o (%08x)\n", MD, MD);
VMA = cc_read_vma();
printf("VMA= %011o (%08x)\n", VMA, VMA);
{
uint32_t disk;
uint32_t bd;
uint32_t mmc;
disk = cc_get(rd_spy_disk);
bd = cc_get(rd_spy_bd);
mmc = bd >> 6;
bd &= 0x3f;
printf("disk-state %d (0x%04x)\n", disk, disk);
printf("bd-state %d (0x%04x)\n", bd, bd);
printf("mmc-state %d (0x%04x)\n", mmc, mmc);
}
return 0;
}
int
cc_report_pc(uint32_t *ppc)
{
uint32_t PC;
PC = cc_read_pc();
printf("PC = %011o (%08x)\n", PC, PC);
*ppc = PC;
return 0;
}
int
cc_report_pc_and_md(uint32_t *ppc)
{
uint32_t PC;
uint32_t MD;
PC = cc_read_pc();
MD = cc_read_md();
printf("PC=%011o (%08x) MD=%011o (%08x)\n", PC, PC, MD, MD);
*ppc = PC;
return 0;
}
int
cc_report_pc_and_ir(uint32_t *ppc)
{
uint32_t PC;
uint64_t ir;
PC = cc_read_pc();
ir = cc_read_ir();
printf("PC=%011o (%08x) ir=%" PRIu64 " ", PC, PC, ir);
disassemble_ucode_loc(ir);
*ppc = PC;
return 0;
}
int
cc_report_pc_md_ir(uint32_t *ppc)
{
uint32_t PC;
uint32_t MD;
uint64_t ir;
PC = cc_read_pc();
MD = cc_read_md();
ir = cc_read_ir();
printf("PC=%011o MD=%011o (%08x) ir=%" PRIu64 " ", PC, MD, MD, ir);
disassemble_ucode_loc(ir);
*ppc = PC;
return 0;
}
int
cc_report_status(void)
{
uint32_t s;
uint32_t f1;
uint32_t f2;
s = cc_read_status();
f1 = s >> 16;
f2 = s & 0xffff;
printf("flags1: %04x (", f1);
if (f1 & (1 << 15))
printf("waiting ");
if (f1 & (1 << 12))
printf("promdisable ");
if (f1 & (1 << 11))
printf("stathalt ");
if (f1 & (1 << 10))
printf("err ");
if (f1 & (1 << 9))
printf("ssdone ");
if (f1 & (1 << 8))
printf("srun ");
printf(") ");
printf("flags2: %04x (", f2);
if (f2 & (1 << 2))
printf("jcond ");
if (f2 & (1 << 3))
printf("vmaok ");
if (f2 & (1 << 4))
printf("nop ");
printf(") ");
return 0;
}
int
cc_pipe(void)
{
uint64_t isn;
for (int i = 0; i < 8; i++) {
printf("addr %o:\n", i);
isn =
ir_pair(CONS_IR_M_SRC, i) |
ir_pair(CONS_IR_ALUF, CONS_ALU_SETM) |
ir_pair(CONS_IR_OB, CONS_OB_ALU);
printf("%" PRIu64 " ", isn);
disassemble_ucode_loc(isn);
cc_write_diag_ir(isn);
cc_noop_debug_clock();
printf(" obus1 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus2 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus3 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_clock();
printf(" obus4 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_clock();
printf(" obus5 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
}
return 0;
}
int
cc_pipe2(void)
{
uint64_t isn;
uint32_t v2;
for (int i = 0; i < 8; i++) {
printf("val %o:\n", i);
cc_write_md(i);
v2 = cc_read_md();
if (v2 != i) {
printf("cc_pipe2; md readback error (got=%o wanted=%o)\n", v2, i);
}
isn =
ir_pair(CONS_IR_M_SRC, CONS_M_SRC_MD) |
ir_pair(CONS_IR_ALUF, CONS_ALU_SETM) |
ir_pair(CONS_IR_OB, CONS_OB_ALU) |
ir_pair(CONS_IR_M_MEM_DEST, i);
printf("%" PRIu64 " ", isn);
disassemble_ucode_loc(isn);
cc_write_diag_ir(isn);
cc_noop_debug_clock();
printf(" obus1 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus2 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus3 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus4 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
cc_debug_clock();
printf(" obus5 %o %o %o\n", cc_read_obus(), cc_read_obus_(), cc_read_m_bus());
}
return 0;
}
uint64_t setup_map_inst[] = {
04000000000110003, // (alu) SETZ a=0 m=0 m[0] C=0 alu-> Q-R -><none>,m[2]
00000000000150173, // (alu) SETO a=0 m=0 m[0] C=0 alu-> Q-R -><none>,m[3]
00600101602370010, // (byte) a=2 m=m[3] dpb pos=10, width=1 ->a_mem[47]
04600101446230166, // (byte) a=2 m=m[3] dpb pos=26, width=4 ->VMA,write-map ,m[4]
04600201400270400, // (byte) a=4 m=m[3] dpb pos=0, width=11 -><none>,m[5]
00002340060010050, // (alu) SETA a=47 m=0 m[0] C=0 alu-> ->MD ,m[0]
00600241446030152, // (byte) a=5 m=m[3] dpb pos=12, width=4 ->VMA,write-map ,m[0]
00002365060010310, // (alu) M+A [ADD] a=47 m=52 MD C=0 alu-> ->MD ,m[0]
00600201400270041, // (byte) a=4 m=m[3] dpb pos=1, width=2 -><none>,m[5]
04600241446030444, // (byte) a=5 m=m[3] dpb pos=4, width=12 ->VMA,write-map ,m[0]
00002365060010310, // (alu) M+A [ADD] a=47 m=52 MD C=0 alu-> ->MD ,m[0]
04600201446030000, // (byte) a=4 m=m[3] dpb pos=0, width=1 ->VMA,write-map ,m[0]
0
};
int
cc_setup_map(void)
{
for (int i = 0; 1; i++) {
if (setup_map_inst[i] == 0)
break;
printf("%d ", i);
fflush(stdout);
cc_execute_r(setup_map_inst[i]);
}
return 0;
}
int
cc_report_ide_regs(void)
{
uint32_t v;
printf("setting up map...\n");
cc_setup_map();
printf("read ide...\n");
cc_write_a_mem(2, 01333);
cc_write_a_mem(3, 0773);
cc_write_a_mem(4, 0774);
cc_write_a_mem(5, 0777);
for (int i = 0; i < 8; i++) {
cc_write_a_mem(1, i | 020);
cc_execute_r(0000040060010050); // alu seta a=1 ->md
cc_execute_r(0000140044010050); // alu seta a=3 alu-> ->vma+write
cc_execute_w(0000100060010050); // alu seta a=2 ->md
cc_execute_w(0000200044010050); // alu seta a=4 alu-> ->vma+write
cc_execute_w(0000240044010050); // alu seta a=5 alu-> ->vma+write
cc_execute_w(0000140042010050); // alu seta a=3 alu-> ->vma+read */
v = cc_read_md();
printf("ide[%d] = 0x%08x 0x%02x\n", i, v, v & 0xff);
}
printf("a[1]=%0o\n", cc_read_a_mem(1));
printf("a[2]=%0o\n", cc_read_a_mem(2));
printf("a[3]=%0o\n", cc_read_a_mem(3));
printf("a[4]=%0o\n", cc_read_a_mem(4));
printf("a[5]=%0o\n", cc_read_a_mem(5));
printf("a[6]=%0o\n", cc_read_a_mem(6));
return 0;
}
int
_test_scratch(uint16_t v)
{
uint16_t s1;
uint16_t s2;
s1 = cc_read_scratch();
cc_set(wr_spy_scratch, v);
s2 = cc_read_scratch();
printf("write 0%o; scratch %o -> %o (0x%x) ", v, s1, s2, s2);
if (s2 == v) {
printf("ok\n");
} else {
printf("BAD\n");
s2 = cc_read_scratch();
printf(" reread; scratch %o -> %o (0x%x) ", s1, s2, s2);
if (s2 == v) {
printf("ok\n");
} else {
printf("BAD\n");
s1 = cc_read_scratch();
cc_set(wr_spy_scratch, v);
s2 = cc_read_scratch();
printf(" rewrite 0%o; scratch %o -> %o (0x%x) ", v, s1, s2, s2);
if (s2 == v) {
printf("ok\n");
} else {
printf("BAD\n");
return -1;
}
}
}
return 0;
}
int vv = 0;
int
cc_test_scratch(void)
{
_test_scratch(01234);
_test_scratch(04321);
_test_scratch(0);
_test_scratch(07777);
_test_scratch(0123456);
_test_scratch(0x2222);
_test_scratch(++vv);
return 0;
}
int
_test_ir(uint64_t isn)
{
uint64_t iv;
printf("test ir %" PRIu64 " ", isn);
cc_write_ir(isn);
iv = cc_read_ir();
if (iv == isn) {
printf("ok\n");
} else {
printf("bad (want 0x%" PRIx64 " got 0x%" PRIx64 ")\n", isn, iv);
printf(" reread; ");
iv = cc_read_ir();
if (iv == isn) {
printf("ok\n");
} else {
printf("bad\n");
printf(" rewrite; ");
cc_write_ir(isn);
iv = cc_read_ir();
if (iv == isn) {
printf("ok\n");
} else {
printf("bad\n");
return -1;
}
}
}
return 0;
}
int
cc_test_ir(void)
{
_test_ir(0);
_test_ir(1);
_test_ir(0x000022220000);
_test_ir(0x011133332222);
_test_ir(2);
_test_ir(0x011155552222);
return 0;
}
char *serial_devicename = "/dev/ttyUSB1";
void
usage(void)
{
fprintf(stderr, "usage: cc [OPTION]...\n");
fprintf(stderr, "\n");
fprintf(stderr, " -d extra debug output\n");
}
int
main(int argc, char *argv[])
{
int ret;
int done;
int c;
struct termios oldtio;
struct termios newtio;
while ((c = getopt(argc, argv, "dh")) != -1) {
switch (c) {
case 'd':
debug++;
break;
case 'h':
usage();
exit(0);
default:
continue;
}