-
Notifications
You must be signed in to change notification settings - Fork 0
/
fx68k.sv
6268 lines (5470 loc) · 240 KB
/
fx68k.sv
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
/* verilator lint_off WIDTH */
//
// FX68K
//
// M68000 cycle accurate, fully synchronous
// Copyright (c) 2018 by Jorge Cwik
//
// TODO:
// - Everything except bus retry already implemented.
`timescale 1 ns / 1 ns
`default_nettype wire
// Define this to run a self contained compilation test build
// `define FX68K_TEST
localparam CF = 0, VF = 1, ZF = 2, NF = 3, XF = 4, SF = 13;
localparam UADDR_WIDTH = 10;
localparam UROM_WIDTH = 17;
localparam UROM_DEPTH = 1024;
localparam NADDR_WIDTH = 9;
localparam NANO_WIDTH = 68;
localparam NANO_DEPTH = 336;
localparam BSER1_NMA = 'h003;
localparam RSTP0_NMA = 'h002;
localparam HALT1_NMA = 'h001;
localparam TRAC1_NMA = 'h1C0;
localparam ITLX1_NMA = 'h1C4;
localparam TVN_SPURIOUS = 12;
localparam TVN_AUTOVEC = 13;
localparam TVN_INTERRUPT = 15;
localparam NANO_DOB_DBD = 2'b01;
localparam NANO_DOB_ADB = 2'b10;
localparam NANO_DOB_ALU = 2'b11;
module fx68k(
input wire clk,
// These two signals don't need to be registered. They are not async reset.
input wire extReset, // External sync reset on emulated system
input wire pwrUp, // Asserted together with reset on emulated system coldstart
input wire enPhi1, enPhi2, // Clock enables. Next cycle is PHI1 or PHI2
output wire eRWn, output wire ASn, output wire LDSn, output wire UDSn,
output reg E, output wire VMAn,
output wire FC0, output wire FC1, output wire FC2,
output wire BGn,
output wire oRESETn, output wire oHALTEDn,
input wire DTACKn,
input wire VPAn,
input wire BERRn,
input wire BRn, BGACKn,
input wire IPL0n, input IPL1n, input IPL2n,
input wire [15:0] iEdb,
output wire [15:0] oEdb,
output wire [23:1] eab
);
wire wClk;
// Internal sub clocks T1-T4
enum int unsigned { T0 = 0, T1, T2, T3, T4} tState;
wire enT1 = enPhi1 & (tState == T4) & ~wClk;
wire enT2 = enPhi2 & (tState == T1);
wire enT3 = enPhi1 & (tState == T2);
wire enT4 = enPhi2 & ((tState == T0) | (tState == T3));
// T4 continues ticking during reset and group0 exception.
// We also need it to erase ucode output latched on T4.
always_ff @( posedge clk) begin
if( pwrUp)
tState <= T0;
else begin
case( tState)
T0: if( enPhi2) tState <= T4;
T1: if( enPhi2) tState <= T2;
T2: if( enPhi1) tState <= T3;
T3: if( enPhi2) tState <= T4;
T4: if( enPhi1) tState <= wClk ? T0 : T1;
endcase
end
end
// The following signals are synchronized with 3 couplers, phi1-phi2-phi1.
// Will be valid internally one cycle later if changed at the rasing edge of the clock.
//
// DTACK, BERR
// DTACK valid at S6 if changed at the rasing edge of S4 to avoid wait states.
// SNC (sncClkEn) is deasserted together (unless DTACK asserted too early).
//
// We synchronize some signals half clock earlier. We compensate later
reg rDtack, rBerr;
reg [2:0] rIpl, iIpl;
reg Vpai, BeI, BRi, BgackI, BeiDelay;
// reg rBR;
wire BeDebounced = ~( BeI | BeiDelay);
always_ff @( posedge clk) begin
if( pwrUp) begin
rBerr <= 1'b0;
BeI <= 1'b0;
end
else if( enPhi2) begin
rDtack <= DTACKn;
rBerr <= BERRn;
rIpl <= ~{ IPL2n, IPL1n, IPL0n};
iIpl <= rIpl;
// rBR <= BRn; // Needed for cycle accuracy but only if BR is changed on the wrong edge of the clock
end
else if( enPhi1) begin
Vpai <= VPAn;
BeI <= rBerr;
BeiDelay <= BeI;
BRi <= BRn;
BgackI <= BGACKn;
// BRi <= rBR;
end
end
// Instantiate micro and nano rom
logic [NANO_WIDTH-1:0] nanoLatch;
logic [NANO_WIDTH-1:0] nanoOutput;
logic [UROM_WIDTH-1:0] microLatch;
logic [UROM_WIDTH-1:0] microOutput;
logic [UADDR_WIDTH-1:0] microAddr, nma;
logic [NADDR_WIDTH-1:0] nanoAddr, orgAddr;
wire rstUrom;
// For the time being, address translation is done for nanorom only.
microToNanoAddr microToNanoAddr( .uAddr( nma), .orgAddr);
// Output of these modules will be updated at T2 at the latest (depending on clock division)
nanoRom nanoRom( .clk( clk), .nanoAddr, .nanoOutput);
uRom uRom( .clk( clk), .microAddr, .microOutput);
always_ff @( posedge clk) begin
// uaddr originally latched on T1, except bits 6 & 7, the conditional bits, on T2
// Seems we can latch whole address at either T1 or T2
// Originally it's invalid on hardware reset, and forced later when coming out of reset
if( pwrUp) begin
microAddr <= RSTP0_NMA;
nanoAddr <= RSTP0_NMA;
end
else if( enT1) begin
microAddr <= nma;
nanoAddr <= orgAddr; // Register translated uaddr to naddr
end
if( extReset) begin
microLatch <= '0;
nanoLatch <= '0;
end
else if( rstUrom) begin
// Originally reset these bits only. Not strictly needed like this.
// Can reset the whole register if it is important.
{ microLatch[16], microLatch[15], microLatch[0]} <= '0;
nanoLatch <= '0;
end
else if( enT3) begin
microLatch <= microOutput;
nanoLatch <= nanoOutput;
end
end
// Decoded nanocode signals
logic Nanod_permStart;
logic Nanod_waitBusFinish;
logic Nanod_isWrite;
logic Nanod_busByte;
logic Nanod_isRmc;
logic Nanod_noLowByte, Nanod_noHighByte;
logic Nanod_updTpend, Nanod_clrTpend;
logic Nanod_tvn2Ftu, Nanod_const2Ftu;
logic Nanod_ftu2Dbl, Nanod_ftu2Abl;
logic Nanod_abl2Pren, Nanod_updPren;
logic Nanod_inl2psw, Nanod_ftu2Sr, Nanod_sr2Ftu, Nanod_ftu2Ccr, Nanod_pswIToFtu;
logic Nanod_ird2Ftu, Nanod_ssw2Ftu;
logic Nanod_initST;
logic Nanod_Ir2Ird;
logic Nanod_auClkEn, Nanod_noSpAlign;
logic [2:0] Nanod_auCntrl;
logic Nanod_todbin, Nanod_toIrc;
logic Nanod_dbl2Atl, Nanod_abl2Atl, Nanod_atl2Abl, Nanod_atl2Dbl;
logic Nanod_abh2Ath, Nanod_dbh2Ath;
logic Nanod_ath2Dbh, Nanod_ath2Abh;
logic Nanod_db2Aob, Nanod_ab2Aob, Nanod_au2Aob;
logic Nanod_aob2Ab, Nanod_updSsw;
// logic Nanod_adb2Dob, Nanod_dbd2Dob, Nanod_alu2Dob;
logic [1:0] Nanod_dobCtrl;
logic Nanod_abh2reg, Nanod_abl2reg;
logic Nanod_reg2abl, Nanod_reg2abh;
logic Nanod_dbh2reg, Nanod_dbl2reg;
logic Nanod_reg2dbl, Nanod_reg2dbh;
logic Nanod_ssp, Nanod_pchdbh, Nanod_pcldbl, Nanod_pclabl, Nanod_pchabh;
logic Nanod_rxh2dbh, Nanod_rxh2abh;
logic Nanod_dbl2rxl, Nanod_dbh2rxh;
logic Nanod_rxl2db, Nanod_rxl2ab;
logic Nanod_abl2rxl, Nanod_abh2rxh;
logic Nanod_dbh2ryh, Nanod_abh2ryh;
logic Nanod_ryl2db, Nanod_ryl2ab;
logic Nanod_ryh2dbh, Nanod_ryh2abh;
logic Nanod_dbl2ryl, Nanod_abl2ryl;
logic Nanod_rz;
logic Nanod_rxlDbl;
logic [2:0] Nanod_aluColumn;
logic [1:0] Nanod_aluDctrl;
logic Nanod_aluActrl;
logic Nanod_aluInit, Nanod_aluFinish;
logic Nanod_abd2Dcr, Nanod_dcr2Dbd;
logic Nanod_dbd2Alue, Nanod_alue2Dbd;
logic Nanod_dbd2Alub, Nanod_abd2Alub;
logic Nanod_alu2Dbd, Nanod_alu2Abd;
logic Nanod_au2Db, Nanod_au2Ab, Nanod_au2Pc;
logic Nanod_dbin2Abd, Nanod_dbin2Dbd;
logic Nanod_extDbh, Nanod_extAbh;
logic Nanod_ablAbd, Nanod_ablAbh;
logic Nanod_dblDbd, Nanod_dblDbh;
logic Nanod_abdIsByte;
// IRD decoded control signals
logic Irdecod_isPcRel;
logic Irdecod_isTas;
logic Irdecod_implicitSp;
logic Irdecod_toCcr;
logic Irdecod_rxIsDt, Irdecod_ryIsDt;
logic Irdecod_rxIsUsp, Irdecod_rxIsMovem, Irdecod_movemPreDecr;
logic Irdecod_isByte;
logic Irdecod_isMovep;
logic [2:0] Irdecod_rx, Irdecod_ry;
logic Irdecod_rxIsAreg, Irdecod_ryIsAreg;
logic [15:0] Irdecod_ftuConst;
logic [5:0] Irdecod_macroTvn;
logic Irdecod_inhibitCcr;
//
reg Tpend;
reg intPend; // Interrupt pending
reg pswT, pswS;
reg [ 2:0] pswI;
wire [7:0] ccr;
wire [15:0] psw = { pswT, 1'b0, pswS, 2'b00, pswI, ccr};
reg [15:0] ftu;
reg [15:0] Irc, Ir, Ird;
wire [15:0] alue;
wire [15:0] Abl;
wire prenEmpty, au05z, dcr4, ze;
wire [UADDR_WIDTH-1:0] a1, a2, a3;
wire isPriv, isIllegal, isLineA, isLineF;
// IR & IRD forwarding
always_ff @( posedge clk) begin
if( enT1) begin
if( Nanod_Ir2Ird)
Ird <= Ir;
else if(microLatch[0]) // prevented by IR => IRD !
Ir <= Irc;
end
end
wire [3:0] tvn;
wire waitBusCycle, busStarting;
wire BusRetry = 1'b0;
wire busAddrErr;
wire bciWrite; // Last bus cycle was write
wire bgBlock, busAvail;
wire addrOe;
wire busIsByte = Nanod_busByte & (Irdecod_isByte | Irdecod_isMovep);
wire aob0;
reg iStop; // Internal signal for ending bus cycle
reg A0Err; // Force bus/address error ucode
reg excRst; // Signal reset exception to sequencer
reg BerrA;
reg Spuria, Avia;
wire Iac;
reg rAddrErr, iBusErr, Err6591;
wire iAddrErr = rAddrErr & addrOe; // To simulate async reset
wire enErrClk;
// Reset micro/nano latch after T4 of the current ublock.
assign rstUrom = enPhi1 & enErrClk;
uaddrDecode uaddrDecode( .opcode( Ir), .a1, .a2, .a3, .isPriv, .isIllegal, .isLineA, .isLineF, .lineBmap());
sequencer sequencer(.alue01( alue[1:0]), .i11( Irc[ 11]), /*AUTOINST*/
// Outputs
.tvn (tvn[3:0]),
.nma (nma[UADDR_WIDTH-1:0]),
// Inputs
.clk (clk),
.enPhi1 (enPhi1),
.enPhi2 (enPhi2),
.extReset (extReset),
.pwrUp (pwrUp),
.enT3 (enT3),
.microLatch (microLatch[UROM_WIDTH-1:0]),
.A0Err (A0Err),
.BerrA (BerrA),
.busAddrErr (busAddrErr),
.Spuria (Spuria),
.Avia (Avia),
.Tpend (Tpend),
.intPend (intPend),
.isIllegal (isIllegal),
.isPriv (isPriv),
.excRst (excRst),
.isLineA (isLineA),
.isLineF (isLineF),
.psw (psw[15:0]),
.prenEmpty (prenEmpty),
.au05z (au05z),
.dcr4 (dcr4),
.ze (ze),
.Ird (Ird[15:0]),
.a1 (a1[UADDR_WIDTH-1:0]),
.a2 (a2[UADDR_WIDTH-1:0]),
.a3 (a3[UADDR_WIDTH-1:0]));
excUnit excUnit( .AblOut( Abl), /*AUTOINST*/
// Outputs
.ccr (ccr[7:0]),
.alue (alue[15:0]),
.prenEmpty (prenEmpty),
.au05z (au05z),
.dcr4 (dcr4),
.ze (ze),
.aob0 (aob0),
.Irc (Irc[15:0]),
.oEdb (oEdb[15:0]),
.eab (eab[23:1]),
// Inputs
.clk (clk),
.enPhi1 (enPhi1),
.enPhi2 (enPhi2),
.extReset (extReset),
.pwrUp (pwrUp),
.enT1 (enT1),
.enT2 (enT2),
.enT3 (enT3),
.enT4 (enT4),
.Nanod_permStart(Nanod_permStart),
.Nanod_waitBusFinish(Nanod_waitBusFinish),
.Nanod_isWrite (Nanod_isWrite),
.Nanod_busByte (Nanod_busByte),
.Nanod_isRmc (Nanod_isRmc),
.Nanod_noLowByte(Nanod_noLowByte),
.Nanod_noHighByte(Nanod_noHighByte),
.Nanod_updTpend (Nanod_updTpend),
.Nanod_clrTpend (Nanod_clrTpend),
.Nanod_tvn2Ftu (Nanod_tvn2Ftu),
.Nanod_const2Ftu(Nanod_const2Ftu),
.Nanod_ftu2Dbl (Nanod_ftu2Dbl),
.Nanod_ftu2Abl (Nanod_ftu2Abl),
.Nanod_abl2Pren (Nanod_abl2Pren),
.Nanod_updPren (Nanod_updPren),
.Nanod_inl2psw (Nanod_inl2psw),
.Nanod_ftu2Sr (Nanod_ftu2Sr),
.Nanod_sr2Ftu (Nanod_sr2Ftu),
.Nanod_ftu2Ccr (Nanod_ftu2Ccr),
.Nanod_pswIToFtu(Nanod_pswIToFtu),
.Nanod_ird2Ftu (Nanod_ird2Ftu),
.Nanod_ssw2Ftu (Nanod_ssw2Ftu),
.Nanod_initST (Nanod_initST),
.Nanod_Ir2Ird (Nanod_Ir2Ird),
.Nanod_auClkEn (Nanod_auClkEn),
.Nanod_noSpAlign(Nanod_noSpAlign),
.Nanod_auCntrl (Nanod_auCntrl[2:0]),
.Nanod_todbin (Nanod_todbin),
.Nanod_toIrc (Nanod_toIrc),
.Nanod_dbl2Atl (Nanod_dbl2Atl),
.Nanod_abl2Atl (Nanod_abl2Atl),
.Nanod_atl2Abl (Nanod_atl2Abl),
.Nanod_atl2Dbl (Nanod_atl2Dbl),
.Nanod_abh2Ath (Nanod_abh2Ath),
.Nanod_dbh2Ath (Nanod_dbh2Ath),
.Nanod_ath2Dbh (Nanod_ath2Dbh),
.Nanod_ath2Abh (Nanod_ath2Abh),
.Nanod_db2Aob (Nanod_db2Aob),
.Nanod_ab2Aob (Nanod_ab2Aob),
.Nanod_au2Aob (Nanod_au2Aob),
.Nanod_aob2Ab (Nanod_aob2Ab),
.Nanod_updSsw (Nanod_updSsw),
.Nanod_dobCtrl (Nanod_dobCtrl[1:0]),
.Nanod_abh2reg (Nanod_abh2reg),
.Nanod_abl2reg (Nanod_abl2reg),
.Nanod_reg2abl (Nanod_reg2abl),
.Nanod_reg2abh (Nanod_reg2abh),
.Nanod_dbh2reg (Nanod_dbh2reg),
.Nanod_dbl2reg (Nanod_dbl2reg),
.Nanod_reg2dbl (Nanod_reg2dbl),
.Nanod_reg2dbh (Nanod_reg2dbh),
.Nanod_ssp (Nanod_ssp),
.Nanod_pchdbh (Nanod_pchdbh),
.Nanod_pcldbl (Nanod_pcldbl),
.Nanod_pclabl (Nanod_pclabl),
.Nanod_pchabh (Nanod_pchabh),
.Nanod_rxh2dbh (Nanod_rxh2dbh),
.Nanod_rxh2abh (Nanod_rxh2abh),
.Nanod_dbl2rxl (Nanod_dbl2rxl),
.Nanod_dbh2rxh (Nanod_dbh2rxh),
.Nanod_rxl2db (Nanod_rxl2db),
.Nanod_rxl2ab (Nanod_rxl2ab),
.Nanod_abl2rxl (Nanod_abl2rxl),
.Nanod_abh2rxh (Nanod_abh2rxh),
.Nanod_dbh2ryh (Nanod_dbh2ryh),
.Nanod_abh2ryh (Nanod_abh2ryh),
.Nanod_ryl2db (Nanod_ryl2db),
.Nanod_ryl2ab (Nanod_ryl2ab),
.Nanod_ryh2dbh (Nanod_ryh2dbh),
.Nanod_ryh2abh (Nanod_ryh2abh),
.Nanod_dbl2ryl (Nanod_dbl2ryl),
.Nanod_abl2ryl (Nanod_abl2ryl),
.Nanod_rz (Nanod_rz),
.Nanod_rxlDbl (Nanod_rxlDbl),
.Nanod_aluColumn(Nanod_aluColumn[2:0]),
.Nanod_aluDctrl (Nanod_aluDctrl[1:0]),
.Nanod_aluActrl (Nanod_aluActrl),
.Nanod_aluInit (Nanod_aluInit),
.Nanod_aluFinish(Nanod_aluFinish),
.Nanod_abd2Dcr (Nanod_abd2Dcr),
.Nanod_dcr2Dbd (Nanod_dcr2Dbd),
.Nanod_dbd2Alue (Nanod_dbd2Alue),
.Nanod_alue2Dbd (Nanod_alue2Dbd),
.Nanod_dbd2Alub (Nanod_dbd2Alub),
.Nanod_abd2Alub (Nanod_abd2Alub),
.Nanod_alu2Dbd (Nanod_alu2Dbd),
.Nanod_alu2Abd (Nanod_alu2Abd),
.Nanod_au2Db (Nanod_au2Db),
.Nanod_au2Ab (Nanod_au2Ab),
.Nanod_au2Pc (Nanod_au2Pc),
.Nanod_dbin2Abd (Nanod_dbin2Abd),
.Nanod_dbin2Dbd (Nanod_dbin2Dbd),
.Nanod_extDbh (Nanod_extDbh),
.Nanod_extAbh (Nanod_extAbh),
.Nanod_ablAbd (Nanod_ablAbd),
.Nanod_ablAbh (Nanod_ablAbh),
.Nanod_dblDbd (Nanod_dblDbd),
.Nanod_dblDbh (Nanod_dblDbh),
.Nanod_abdIsByte(Nanod_abdIsByte),
.Irdecod_isPcRel(Irdecod_isPcRel),
.Irdecod_isTas (Irdecod_isTas),
.Irdecod_implicitSp(Irdecod_implicitSp),
.Irdecod_toCcr (Irdecod_toCcr),
.Irdecod_rxIsDt (Irdecod_rxIsDt),
.Irdecod_ryIsDt (Irdecod_ryIsDt),
.Irdecod_rxIsUsp(Irdecod_rxIsUsp),
.Irdecod_rxIsMovem(Irdecod_rxIsMovem),
.Irdecod_movemPreDecr(Irdecod_movemPreDecr),
.Irdecod_isByte (Irdecod_isByte),
.Irdecod_isMovep(Irdecod_isMovep),
.Irdecod_rx (Irdecod_rx[2:0]),
.Irdecod_ry (Irdecod_ry[2:0]),
.Irdecod_rxIsAreg(Irdecod_rxIsAreg),
.Irdecod_ryIsAreg(Irdecod_ryIsAreg),
.Irdecod_ftuConst(Irdecod_ftuConst[15:0]),
.Irdecod_macroTvn(Irdecod_macroTvn[5:0]),
.Irdecod_inhibitCcr(Irdecod_inhibitCcr),
.Ird (Ird[15:0]),
.pswS (pswS),
.ftu (ftu[15:0]),
.iEdb (iEdb[15:0]));
nDecoder3 nDecoder( /*AUTOINST*/
// Outputs
.Nanod_permStart (Nanod_permStart),
.Nanod_waitBusFinish (Nanod_waitBusFinish),
.Nanod_isWrite (Nanod_isWrite),
.Nanod_busByte (Nanod_busByte),
.Nanod_isRmc (Nanod_isRmc),
.Nanod_noLowByte (Nanod_noLowByte),
.Nanod_noHighByte (Nanod_noHighByte),
.Nanod_updTpend (Nanod_updTpend),
.Nanod_clrTpend (Nanod_clrTpend),
.Nanod_tvn2Ftu (Nanod_tvn2Ftu),
.Nanod_const2Ftu (Nanod_const2Ftu),
.Nanod_ftu2Dbl (Nanod_ftu2Dbl),
.Nanod_ftu2Abl (Nanod_ftu2Abl),
.Nanod_abl2Pren (Nanod_abl2Pren),
.Nanod_updPren (Nanod_updPren),
.Nanod_inl2psw (Nanod_inl2psw),
.Nanod_ftu2Sr (Nanod_ftu2Sr),
.Nanod_sr2Ftu (Nanod_sr2Ftu),
.Nanod_ftu2Ccr (Nanod_ftu2Ccr),
.Nanod_pswIToFtu (Nanod_pswIToFtu),
.Nanod_ird2Ftu (Nanod_ird2Ftu),
.Nanod_ssw2Ftu (Nanod_ssw2Ftu),
.Nanod_initST (Nanod_initST),
.Nanod_Ir2Ird (Nanod_Ir2Ird),
.Nanod_auClkEn (Nanod_auClkEn),
.Nanod_noSpAlign (Nanod_noSpAlign),
.Nanod_auCntrl (Nanod_auCntrl[2:0]),
.Nanod_todbin (Nanod_todbin),
.Nanod_toIrc (Nanod_toIrc),
.Nanod_dbl2Atl (Nanod_dbl2Atl),
.Nanod_abl2Atl (Nanod_abl2Atl),
.Nanod_atl2Abl (Nanod_atl2Abl),
.Nanod_atl2Dbl (Nanod_atl2Dbl),
.Nanod_abh2Ath (Nanod_abh2Ath),
.Nanod_dbh2Ath (Nanod_dbh2Ath),
.Nanod_ath2Dbh (Nanod_ath2Dbh),
.Nanod_ath2Abh (Nanod_ath2Abh),
.Nanod_db2Aob (Nanod_db2Aob),
.Nanod_ab2Aob (Nanod_ab2Aob),
.Nanod_au2Aob (Nanod_au2Aob),
.Nanod_aob2Ab (Nanod_aob2Ab),
.Nanod_updSsw (Nanod_updSsw),
.Nanod_dobCtrl (Nanod_dobCtrl[1:0]),
.Nanod_abh2reg (Nanod_abh2reg),
.Nanod_abl2reg (Nanod_abl2reg),
.Nanod_reg2abl (Nanod_reg2abl),
.Nanod_reg2abh (Nanod_reg2abh),
.Nanod_dbh2reg (Nanod_dbh2reg),
.Nanod_dbl2reg (Nanod_dbl2reg),
.Nanod_reg2dbl (Nanod_reg2dbl),
.Nanod_reg2dbh (Nanod_reg2dbh),
.Nanod_ssp (Nanod_ssp),
.Nanod_pchdbh (Nanod_pchdbh),
.Nanod_pcldbl (Nanod_pcldbl),
.Nanod_pclabl (Nanod_pclabl),
.Nanod_pchabh (Nanod_pchabh),
.Nanod_rxh2dbh (Nanod_rxh2dbh),
.Nanod_rxh2abh (Nanod_rxh2abh),
.Nanod_dbl2rxl (Nanod_dbl2rxl),
.Nanod_dbh2rxh (Nanod_dbh2rxh),
.Nanod_rxl2db (Nanod_rxl2db),
.Nanod_rxl2ab (Nanod_rxl2ab),
.Nanod_abl2rxl (Nanod_abl2rxl),
.Nanod_abh2rxh (Nanod_abh2rxh),
.Nanod_dbh2ryh (Nanod_dbh2ryh),
.Nanod_abh2ryh (Nanod_abh2ryh),
.Nanod_ryl2db (Nanod_ryl2db),
.Nanod_ryl2ab (Nanod_ryl2ab),
.Nanod_ryh2dbh (Nanod_ryh2dbh),
.Nanod_ryh2abh (Nanod_ryh2abh),
.Nanod_dbl2ryl (Nanod_dbl2ryl),
.Nanod_abl2ryl (Nanod_abl2ryl),
.Nanod_rz (Nanod_rz),
.Nanod_rxlDbl (Nanod_rxlDbl),
.Nanod_aluColumn (Nanod_aluColumn[2:0]),
.Nanod_aluDctrl (Nanod_aluDctrl[1:0]),
.Nanod_aluActrl (Nanod_aluActrl),
.Nanod_aluInit (Nanod_aluInit),
.Nanod_aluFinish (Nanod_aluFinish),
.Nanod_abd2Dcr (Nanod_abd2Dcr),
.Nanod_dcr2Dbd (Nanod_dcr2Dbd),
.Nanod_dbd2Alue (Nanod_dbd2Alue),
.Nanod_alue2Dbd (Nanod_alue2Dbd),
.Nanod_dbd2Alub (Nanod_dbd2Alub),
.Nanod_abd2Alub (Nanod_abd2Alub),
.Nanod_alu2Dbd (Nanod_alu2Dbd),
.Nanod_alu2Abd (Nanod_alu2Abd),
.Nanod_au2Db (Nanod_au2Db),
.Nanod_au2Ab (Nanod_au2Ab),
.Nanod_au2Pc (Nanod_au2Pc),
.Nanod_dbin2Abd (Nanod_dbin2Abd),
.Nanod_dbin2Dbd (Nanod_dbin2Dbd),
.Nanod_extDbh (Nanod_extDbh),
.Nanod_extAbh (Nanod_extAbh),
.Nanod_ablAbd (Nanod_ablAbd),
.Nanod_ablAbh (Nanod_ablAbh),
.Nanod_dblDbd (Nanod_dblDbd),
.Nanod_dblDbh (Nanod_dblDbh),
.Nanod_abdIsByte (Nanod_abdIsByte),
// Inputs
.clk (clk),
.Irdecod_isPcRel (Irdecod_isPcRel),
.Irdecod_isTas (Irdecod_isTas),
.Irdecod_implicitSp (Irdecod_implicitSp),
.Irdecod_toCcr (Irdecod_toCcr),
.Irdecod_rxIsDt (Irdecod_rxIsDt),
.Irdecod_ryIsDt (Irdecod_ryIsDt),
.Irdecod_rxIsUsp (Irdecod_rxIsUsp),
.Irdecod_rxIsMovem (Irdecod_rxIsMovem),
.Irdecod_movemPreDecr(Irdecod_movemPreDecr),
.Irdecod_isByte (Irdecod_isByte),
.Irdecod_isMovep (Irdecod_isMovep),
.Irdecod_rx (Irdecod_rx[2:0]),
.Irdecod_ry (Irdecod_ry[2:0]),
.Irdecod_rxIsAreg (Irdecod_rxIsAreg),
.Irdecod_ryIsAreg (Irdecod_ryIsAreg),
.Irdecod_ftuConst (Irdecod_ftuConst[15:0]),
.Irdecod_macroTvn (Irdecod_macroTvn[5:0]),
.Irdecod_inhibitCcr (Irdecod_inhibitCcr),
.enT2 (enT2),
.enT4 (enT4),
.microLatch (microLatch[UROM_WIDTH-1:0]),
.nanoLatch (nanoLatch[NANO_WIDTH-1:0]));
irdDecode irdDecode( .ird( Ird), /*AUTOINST*/
// Outputs
.Irdecod_isPcRel (Irdecod_isPcRel),
.Irdecod_isTas (Irdecod_isTas),
.Irdecod_implicitSp (Irdecod_implicitSp),
.Irdecod_toCcr (Irdecod_toCcr),
.Irdecod_rxIsDt (Irdecod_rxIsDt),
.Irdecod_ryIsDt (Irdecod_ryIsDt),
.Irdecod_rxIsUsp (Irdecod_rxIsUsp),
.Irdecod_rxIsMovem (Irdecod_rxIsMovem),
.Irdecod_movemPreDecr(Irdecod_movemPreDecr),
.Irdecod_isByte (Irdecod_isByte),
.Irdecod_isMovep (Irdecod_isMovep),
.Irdecod_rx (Irdecod_rx[2:0]),
.Irdecod_ry (Irdecod_ry[2:0]),
.Irdecod_rxIsAreg (Irdecod_rxIsAreg),
.Irdecod_ryIsAreg (Irdecod_ryIsAreg),
.Irdecod_ftuConst (Irdecod_ftuConst[15:0]),
.Irdecod_macroTvn (Irdecod_macroTvn[5:0]),
.Irdecod_inhibitCcr (Irdecod_inhibitCcr));
busControl busControl( .permStart( Nanod_permStart), .permStop( Nanod_waitBusFinish),
.isWrite( Nanod_isWrite), .isRmc( Nanod_isRmc), .isByte( busIsByte), /*AUTOINST*/
// Outputs
.bgBlock (bgBlock),
.busAddrErr (busAddrErr),
.waitBusCycle (waitBusCycle),
.busStarting (busStarting),
.addrOe (addrOe),
.bciWrite (bciWrite),
.ASn (ASn),
.LDSn (LDSn),
.UDSn (UDSn),
.eRWn (eRWn),
// Inputs
.clk (clk),
.enPhi1 (enPhi1),
.enPhi2 (enPhi2),
.extReset (extReset),
.pwrUp (pwrUp),
.enT1 (enT1),
.enT4 (enT4),
.iStop (iStop),
.aob0 (aob0),
.busAvail (busAvail),
.rDtack (rDtack),
.BeDebounced (BeDebounced),
.Vpai (Vpai));
busArbiter busArbiter( .Halti( 1'b1), /*AUTOINST*/
// Outputs
.busAvail (busAvail),
.BGn (BGn),
// Inputs
.clk (clk),
.enPhi1 (enPhi1),
.enPhi2 (enPhi2),
.extReset (extReset),
.pwrUp (pwrUp),
.BRi (BRi),
.BgackI (BgackI),
.bgBlock (bgBlock));
// Output reset & halt control
wire [1:0] uFc = microLatch[ 16:15];
logic oReset, oHalted;
assign oRESETn = !oReset;
assign oHALTEDn = !oHalted;
// FC without permStart is special, either reset or halt
always_ff @( posedge clk) begin
if( pwrUp) begin
oReset <= 1'b0;
oHalted <= 1'b0;
end
else if( enT1) begin
oReset <= (uFc == 2'b01) & !Nanod_permStart;
oHalted <= (uFc == 2'b10) & !Nanod_permStart;
end
end
logic [2:0] rFC;
assign { FC2, FC1, FC0} = rFC; // ~rFC;
assign Iac = {rFC == 3'b111}; // & Control output enable !!
always_ff @( posedge clk) begin
if( extReset)
rFC <= '0;
else if( enT1 & Nanod_permStart) begin // S0 phase of bus cycle
rFC[2] <= pswS;
// PC relativ access is marked as FC type 'n' (0) at ucode.
// We don't care about RZ in this case. Those uinstructions with RZ don't start a bus cycle.
rFC[1] <= microLatch[ 16] | ( ~microLatch[ 15] & ~Irdecod_isPcRel);
rFC[0] <= microLatch[ 15] | ( ~microLatch[ 16] & Irdecod_isPcRel);
end
end
// IPL interface
reg [2:0] inl; // Int level latch
reg updIll;
reg prevNmi;
wire nmi = (iIpl == 3'b111);
wire iplStable = (iIpl == rIpl);
wire iplComp = iIpl > pswI;
always_ff @( posedge clk) begin
if( extReset) begin
intPend <= 1'b0;
prevNmi <= 1'b0;
end
else begin
if( enPhi2)
prevNmi <= nmi;
// Originally async RS-Latch on PHI2, followed by a transparent latch on T2
// Tricky because they might change simultaneously
// Syncronous on PHI2 is equivalent as long as the output is read on T3!
// Set on stable & NMI edge or compare
// Clear on: NMI Iack or (stable & !NMI & !Compare)
if( enPhi2) begin
if( iplStable & ((nmi & ~prevNmi) | iplComp) )
intPend <= 1'b1;
else if( ((inl == 3'b111) & Iac) | (iplStable & !nmi & !iplComp) )
intPend <= 1'b0;
end
end
if( extReset) begin
inl <= '1;
updIll <= 1'b0;
end
else if( enT4)
updIll <= microLatch[0]; // Update on any IRC->IR
else if( enT1 & updIll)
inl <= iIpl; // Timing is correct.
// Spurious interrupt, BERR on Interrupt Ack.
// Autovector interrupt. VPA on IACK.
// Timing is tight. Spuria is deasserted just after exception exception is recorded.
if( enT4) begin
Spuria <= ~BeiDelay & Iac;
Avia <= ~Vpai & Iac;
end
end
assign enErrClk = iAddrErr | iBusErr;
assign wClk = waitBusCycle | ~BeI | iAddrErr | Err6591;
// E clock and counter, VMA
reg [3:0] eCntr;
reg rVma;
assign VMAn = rVma;
// Internal stop just one cycle before E falling edge
wire xVma = ~rVma & (eCntr == 8);
always_ff @( posedge clk) begin
if( pwrUp) begin
E <= 1'b0;
eCntr <='0;
rVma <= 1'b1;
end
if( enPhi2) begin
if( eCntr == 9)
E <= 1'b0;
else if( eCntr == 5)
E <= 1'b1;
if( eCntr == 9)
eCntr <= '0;
else
eCntr <= eCntr + 1'b1;
end
if( enPhi2 & addrOe & ~Vpai & (eCntr == 3))
rVma <= 1'b0;
else if( enPhi1 & eCntr == '0)
rVma <= 1'b1;
end
always_ff @( posedge clk) begin
// This timing is critical to stop the clock phases at the exact point on bus/addr error.
// Timing should be such that current ublock completes (up to T3 or T4).
// But T1 for the next ublock shouldn't happen. Next T1 only after resetting ucode and ncode latches.
if( extReset)
rAddrErr <= 1'b0;
else if( enPhi1) begin
if( busAddrErr & addrOe) // Not on T1 ?!
rAddrErr <= 1'b1;
else if( ~addrOe) // Actually async reset!
rAddrErr <= 1'b0;
end
if( extReset)
iBusErr <= 1'b0;
else if( enPhi1) begin
iBusErr <= ( BerrA & ~BeI & ~Iac & !BusRetry);
end
if( extReset)
BerrA <= 1'b0;
else if( enPhi2) begin
if( ~BeI & ~Iac & addrOe)
BerrA <= 1'b1;
// else if( BeI & addrOe) // Bad, async reset since addrOe raising edge
else if( BeI & busStarting) // So replaced with this that raises one cycle earlier
BerrA <= 1'b0;
end
// Signal reset exception to sequencer.
// Originally cleared on 1st T2 after permstart. Must keep it until TVN latched.
if( extReset)
excRst <= 1'b1;
else if( enT2 & Nanod_permStart)
excRst <= 1'b0;
if( extReset)
A0Err <= 1'b1; // A0 Reset
else if( enT3) // Keep set until new urom words are being latched
A0Err <= 1'b0;
else if( enPhi1 & enErrClk & (busAddrErr | BerrA)) // Check bus error timing
A0Err <= 1'b1;
if( extReset) begin
iStop <= 1'b0;
Err6591 <= 1'b0;
end
else if( enPhi1)
Err6591 <= enErrClk;
else if( enPhi2)
iStop <= xVma | (Vpai & (iAddrErr | ~rBerr));
end
// PSW
logic irdToCcr_t4;
always_ff @( posedge clk) begin
if( pwrUp) begin
Tpend <= 1'b0;
{pswT, pswS, pswI } <= '0;
irdToCcr_t4 <= '0;
end
else if( enT4) begin
irdToCcr_t4 <= Irdecod_toCcr;
end
else if( enT3) begin
// UNIQUE IF !!
if( Nanod_updTpend)
Tpend <= pswT;
else if( Nanod_clrTpend)
Tpend <= 1'b0;
// UNIQUE IF !!
if( Nanod_ftu2Sr & !irdToCcr_t4)
{pswT, pswS, pswI } <= { ftu[ 15], ftu[13], ftu[10:8]};
else begin
if( Nanod_initST) begin
pswS <= 1'b1;
pswT <= 1'b0;
end
if( Nanod_inl2psw)
pswI <= inl;
end
end
end
// FTU
reg [4:0] ssw;
reg [3:0] tvnLatch;
logic [15:0] tvnMux;
reg inExcept01;
// Seems CPU has a buglet here.
// Flagging group 0 exceptions from TVN might not work because some bus cycles happen before TVN is updated.
// But doesn't matter because a group 0 exception inside another one will halt the CPU anyway and won't save the SSW.
always_ff @( posedge clk) begin
// Updated at the start of the exception ucode
if( Nanod_updSsw & enT3) begin
ssw <= { ~bciWrite, inExcept01, rFC};
end
// Update TVN on T1 & IR=>IRD
if( enT1 & Nanod_Ir2Ird) begin
tvnLatch <= tvn;
inExcept01 <= (tvn != 1);
end
if( pwrUp)
ftu <= '0;
else if( enT3) begin
unique case( 1'b1)
Nanod_tvn2Ftu: ftu <= tvnMux;
// 0 on unused bits seem to come from ftuConst PLA previously clearing FBUS
Nanod_sr2Ftu: ftu <= {pswT, 1'b0, pswS, 2'b00, pswI, 3'b000, ccr[4:0] };
Nanod_ird2Ftu: ftu <= Ird;
Nanod_ssw2Ftu: ftu[4:0] <= ssw; // Undoc. Other bits must be preserved from IRD saved above!
Nanod_pswIToFtu: ftu <= { 12'hFFF, pswI, 1'b0}; // Interrupt level shifted
Nanod_const2Ftu: ftu <= Irdecod_ftuConst;
Nanod_abl2Pren: ftu <= Abl; // From ALU or datareg. Used for SR modify
default: ftu <= ftu;
endcase
end
end
always_comb begin
if( inExcept01) begin
// Unique IF !!!
if( tvnLatch == TVN_SPURIOUS)
tvnMux = {9'b0, 5'd24, 2'b00};
else if( tvnLatch == TVN_AUTOVEC)
tvnMux = {9'b0, 2'b11, pswI, 2'b00}; // Set TVN PLA decoder
else if( tvnLatch == TVN_INTERRUPT)
tvnMux = {6'b0, Ird[7:0], 2'b00}; // Interrupt vector was read and transferred to IRD
else
tvnMux = {10'b0, tvnLatch, 2'b00};
end
else
tvnMux = { 8'h0, Irdecod_macroTvn, 2'b00};
end
endmodule
// Nanorom (plus) decoder for die nanocode
module nDecoder3( input clk,
output logic Nanod_permStart,
output logic Nanod_waitBusFinish,
output logic Nanod_isWrite,
output logic Nanod_busByte,
output logic Nanod_isRmc,
output logic Nanod_noLowByte, Nanod_noHighByte,
output logic Nanod_updTpend, Nanod_clrTpend,
output logic Nanod_tvn2Ftu, Nanod_const2Ftu,
output logic Nanod_ftu2Dbl, Nanod_ftu2Abl,
output logic Nanod_abl2Pren, Nanod_updPren,
output logic Nanod_inl2psw, Nanod_ftu2Sr, Nanod_sr2Ftu, Nanod_ftu2Ccr, Nanod_pswIToFtu,
output logic Nanod_ird2Ftu, Nanod_ssw2Ftu,
output logic Nanod_initST,
output logic Nanod_Ir2Ird,
output logic Nanod_auClkEn, Nanod_noSpAlign,
output logic [2:0] Nanod_auCntrl,
output logic Nanod_todbin, Nanod_toIrc,
output logic Nanod_dbl2Atl, Nanod_abl2Atl, Nanod_atl2Abl, Nanod_atl2Dbl,
output logic Nanod_abh2Ath, Nanod_dbh2Ath,
output logic Nanod_ath2Dbh, Nanod_ath2Abh,
output logic Nanod_db2Aob, Nanod_ab2Aob, Nanod_au2Aob,
output logic Nanod_aob2Ab, Nanod_updSsw,
output logic [1:0] Nanod_dobCtrl,
output logic Nanod_abh2reg, Nanod_abl2reg,
output logic Nanod_reg2abl, Nanod_reg2abh,
output logic Nanod_dbh2reg, Nanod_dbl2reg,
output logic Nanod_reg2dbl, Nanod_reg2dbh,
output logic Nanod_ssp, Nanod_pchdbh, Nanod_pcldbl, Nanod_pclabl, Nanod_pchabh,
output logic Nanod_rxh2dbh, Nanod_rxh2abh,
output logic Nanod_dbl2rxl, Nanod_dbh2rxh,
output logic Nanod_rxl2db, Nanod_rxl2ab,
output logic Nanod_abl2rxl, Nanod_abh2rxh,
output logic Nanod_dbh2ryh, Nanod_abh2ryh,
output logic Nanod_ryl2db, Nanod_ryl2ab,
output logic Nanod_ryh2dbh, Nanod_ryh2abh,
output logic Nanod_dbl2ryl, Nanod_abl2ryl,
output logic Nanod_rz,
output logic Nanod_rxlDbl,