forked from open-simh/simh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnova_cpu.c
1518 lines (1337 loc) · 59.7 KB
/
nova_cpu.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
/* nova_cpu.c: NOVA CPU simulator
Copyright (c) 1993-2017, Robert M. Supnik
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Robert M Supnik shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Robert M Supnik.
cpu Nova central processor
07-Sep-17 RMS Fixed sim_eval declaration in history routine (COVERITY)
17-Mar-13 RMS Added clarifying brances to IND_STEP macro (Dave Bryan)
04-Jul-07 BKR DEV_SET/CLR macros now used,
support for non-existant devices added
CPU bootstrap code warning: high-speed devices may not boot properly,
execution history facility added,
documented Nova 3 secret LDB/STB/SAVN behavior,
added support for secret Nova 3 LDB/STB/SAVN substitute actions,
'ind_max' changed from 16 to 65536 for better unmapped system compatibility,
INT_TRAP added for Nova 3, 4 trap instruction handling,
28-Apr-07 RMS Removed clock initialization
06-Feb-06 RMS Fixed bug in DIVS (Mark Hittinger)
22-Sep-05 RMS Fixed declarations (Sterling Garwood)
25-Aug-05 RMS Fixed DIVS case 2^31 / - 1
14-Jan-04 RMS Fixed device enable/disable support (Bruce Ray)
19-Jan-03 RMS Changed CMASK to CDMASK for Apple Dev Kit conflict
03-Oct-02 RMS Added DIB infrastructure
30-Dec-01 RMS Added old PC queue
07-Dec-01 RMS Revised to use breakpoint package
30-Nov-01 RMS Added extended SET/SHOW support
10-Aug-01 RMS Removed register in declarations
17-Jul-01 RMS Moved function prototype
26-Apr-01 RMS Added device enable/disable support
05-Mar-01 RMS Added clock calibration
22-Dec-00 RMS Added Bruce Ray's second terminal
15-Dec-00 RMS Added Charles Owen's CPU bootstrap
08-Dec-00 RMS Changes from Bruce Ray
-- fixed trap test to include Nova 3
-- fixed DIV and DIVS divide by 0
-- fixed RETN to set SP from FP
-- fixed IORST to preserve carry
-- added "secret" Nova 4 PSHN/SAVEN instructions
-- added plotter support
15-Oct-00 RMS Fixed bug in MDV test, added stack, byte, trap instructions
14-Apr-98 RMS Changed t_addr to unsigned
15-Sep-97 RMS Added read and write breakpoints
The register state for the NOVA CPU is:
AC[0:3]<0:15> general registers
C carry flag
PC<0:14> program counter
The NOVA has three instruction formats: memory reference, I/O transfer,
and operate. The memory reference format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 0| op | AC |in| mode| displacement | memory reference
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
<0:4> mnemonic action
00000 JMP PC = MA
00001 JMS AC3 = PC, PC = MA
00010 ISZ M[MA] = M[MA] + 1, skip if M[MA] == 0
00011 DSZ M[MA] = M[MA] - 1, skip if M[MA] == 0
001'n LDA ACn = M[MA]
010'n STA M[MA] = ACn
<5:7> mode action
000 page zero direct MA = zext (IR<8:15>)
001 PC relative direct MA = PC + sext (IR<8:15>)
010 AC2 relative direct MA = AC2 + sext (IR<8:15>)
011 AC3 relative direct MA = AC3 + sext (IR<8:15>)
100 page zero indirect MA = M[zext (IR<8:15>)]
101 PC relative indirect MA = M[PC + sext (IR<8:15>)]
110 AC2 relative indirect MA = M[AC2 + sext (IR<8:15>)]
111 AC3 relative indirect MA = M[AC3 + sext (IR<8:15>)]
Memory reference instructions can access an address space of 32K words.
An instruction can directly reference the first 256 words of memory
(called page zero), as well as 256 words relative to the PC, AC2, or
AC3; it can indirectly access all 32K words. If an indirect address
is in locations 00020-00027, the indirect address is incremented and
rewritten to memory before use; if in 00030-00037, decremented and
rewritten.
The I/O transfer format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 0 1 1| AC | opcode |pulse| device | I/O transfer
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The IOT instruction sends the opcode, pulse, and specified AC to the
specified I/O device. The device may accept data, provide data,
initiate or cancel operations, or skip on status.
The operate format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1|srcAC|dstAC| opcode |shift|carry|nl| skip | operate
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
\______/ \___/ \___/ | | | |
| | | | | | +--- reverse skip sense
| | | | | +--- skip if C == 0
| | | | +--- skip if result == 0
| | | +--- don't load result
| | +--- carry in (load as is,
| | set to Zero,
| | set to One,
| | load Complement)
| +--- shift (none,
| left one,
| right one,
| byte swap)
+--- operation (complement,
negate,
move,
increment,
add complement,
subtract,
add,
and)
The operate instruction can be microprogrammed to perform operations
on the source and destination AC's and the Carry flag.
Some notes from Bruce Ray:
1. DG uses the value of the autoindex location -before- the
modification to determine if additional indirect address
levels are to be performed. Most DG emulators conform to
this standard, but some vendor machines (i.e. Point 4 Mark 8)
do not.
2. Infinite indirect references may occur on unmapped systems
and can "hang" the hardware. Some DG diagnostics perform
10,000s of references during a single instruction.
3. Nova 3 adds the following instructions to the standard Nova
instruction set:
trap instructions
stack push/pop instructions
save/return instructions
stack register manipulation instructions
unsigned MUL/DIV
4. Nova 4 adds the following instructions to the Nova 3 instruction
set:
signed MUL/DIV
load/store byte
secret (undocumented) stack instructions [PSHN, SAVN]
5. Nova, Nova 3 and Nova 4 unsigned mul/div instructions are the
same instruction code values on all machines.
6. Undocumented Nova 3 behaviour for LDB, STB and SAVN has been
added to appropriate code.
7. Most 3rd party vendors had a user-controlled method to increase the
logical address space from 32 KW to 64 KW. This capability came at
the expense of disabling multi-level indirect addressing when the 64KW
mode is in effect, and keeping DG multi-level indirect compatibility
when 64KW mode is inactive. The most common implementation was to use
an "NIOP <ac>,CPU" instruction to control whether 32 KW or 64 KW
addressing mode was wanted, and <ac> bit 15 (the least-significant bit
of an accumulator) determined which mode was set:
0 = 32 KW (DG compatible), 1 = 64 KW.
This feature has been implemented in our Nova emulation for all to enjoy.
This routine is the instruction decode routine for the NOVA.
It is called from the simulator control program to execute
instructions in simulated memory, starting at the simulated PC.
It runs until 'reason' is set non-zero.
General notes:
1. Reasons to stop. The simulator can be stopped by:
HALT instruction
breakpoint encountered
infinite indirection loop
unknown I/O device and STOP_DEV flag set
I/O error in I/O simulator
2. Interrupts. Interrupts are maintained by four parallel variables:
dev_done device done flags
dev_disable device interrupt disable flags
dev_busy device busy flags
int_req interrupt requests
In addition, int_req contains the interrupt enable and ION pending
flags. If ION and ION pending are set, and at least one interrupt
request is pending, then an interrupt occurs. Note that the 16b PIO
mask must be mapped to the simulator's device bit mapping.
3. Non-existent memory. On the NOVA, reads to non-existent memory
return zero, and writes are ignored. In the simulator, the
largest possible memory is instantiated and initialized to zero.
Thus, only writes need be checked against actual memory size.
4. Adding I/O devices. These modules must be modified:
nova_defs.h add interrupt request definition
nova_sys.c add sim_devices entry
*/
#include "nova_defs.h"
#define PCQ_SIZE 64 /* must be 2**n */
#define PCQ_MASK (PCQ_SIZE - 1)
#define PCQ_ENTRY pcq[pcq_p = (pcq_p - 1) & PCQ_MASK] = PC
#define INCA(x) (((x) + 1) & AMASK)
#define DECA(x) (((x) - 1) & AMASK)
#define SEXT(x) (((x) & SIGN)? ((x) | ~DMASK): (x))
#define STK_CHECK(x,y) if (((x) & 0377) < (y)) \
int_req = int_req | INT_STK
#define IND_STEP(x) M[x] & A_IND; /* return next level indicator */ \
if ( ((x) <= AUTO_TOP) && ((x) >= AUTO_INC) ) { \
if ( (x) < AUTO_DEC ) \
M[x] = (M[x] + 1) & DMASK; \
else \
M[x] = (M[x] - 1) & DMASK; \
} \
x = M[x] & AMASK
#define INCREMENT_PC PC = (PC + 1) & AMASK /* increment PC */
#define UNIT_V_MDV (UNIT_V_UF + 0) /* MDV present */
#define UNIT_V_STK (UNIT_V_UF + 1) /* stack instr */
#define UNIT_V_BYT (UNIT_V_UF + 2) /* byte instr */
#define UNIT_V_64KW (UNIT_V_UF + 3) /* 64KW mem support */
#define UNIT_V_MSIZE (UNIT_V_UF + 4) /* dummy mask */
#define UNIT_MDV (1 << UNIT_V_MDV)
#define UNIT_STK (1 << UNIT_V_STK)
#define UNIT_BYT (1 << UNIT_V_BYT)
#define UNIT_64KW (1 << UNIT_V_64KW)
#define UNIT_MSIZE (1 << UNIT_V_MSIZE)
#define UNIT_IOPT (UNIT_MDV | UNIT_STK | UNIT_BYT | UNIT_64KW)
#define UNIT_NOVA3 (UNIT_MDV | UNIT_STK)
#define UNIT_NOVA4 (UNIT_MDV | UNIT_STK | UNIT_BYT)
#define UNIT_KERONIX (UNIT_MDV | UNIT_64KW)
#define MODE_64K (cpu_unit.flags & UNIT_64KW)
#define MODE_64K_ACTIVE ((cpu_unit.flags & UNIT_64KW) && (0xFFFF == AMASK))
typedef struct
{
int32 pc;
int16 ir;
int16 ac0 ;
int16 ac1 ;
int16 ac2 ;
int16 ac3 ;
int16 carry ;
int16 sp ;
int16 fp ;
int32 devDone ;
int32 devBusy ;
int32 devDisable ;
int32 devIntr ;
} Hist_entry ;
uint16 M[MAXMEMSIZE] = { 0 }; /* memory */
int32 AC[4] = { 0 }; /* accumulators */
int32 C = 0; /* carry flag */
int32 saved_PC = 0; /* program counter */
int32 SP = 0; /* stack pointer */
int32 FP = 0; /* frame pointer */
int32 SR = 0; /* switch register */
int32 dev_done = 0; /* device done flags */
int32 dev_busy = 0; /* device busy flags */
int32 dev_disable = 0; /* int disable flags */
int32 int_req = 0; /* interrupt requests */
int32 pimask = 0; /* priority int mask */
int32 pwr_low = 0; /* power fail flag */
int32 ind_max = 65536; /* iadr nest limit */
int32 stop_dev = 0; /* stop on ill dev */
uint16 pcq[PCQ_SIZE] = { 0 }; /* PC queue */
int32 pcq_p = 0; /* PC queue ptr */
REG *pcq_r = NULL; /* PC queue reg ptr */
struct ndev dev_table[64]; /* dispatch table */
int32 AMASK = 077777 ; /* current memory address mask */
/* (default to 32KW) */
static int32 hist_p = 0 ; /* history pointer */
static int32 hist_cnt = 0 ; /* history count */
static Hist_entry * hist = NULL ; /* instruction history */
t_stat cpu_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw);
t_stat cpu_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw);
t_stat cpu_reset (DEVICE *dptr);
t_stat cpu_set_size (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
t_stat cpu_boot (int32 unitno, DEVICE *dptr);
t_stat build_devtab (void);
t_stat hist_set( UNIT * uptr, int32 val, CONST char * cptr, void * desc ) ;
t_stat hist_show( FILE * st, UNIT * uptr, int32 val, CONST void * desc ) ;
static int hist_save( int32 pc, int32 our_ir ) ;
char * devBitNames( int32 flags, char * ptr, char * sepStr ) ;
void mask_out (int32 mask);
/* CPU data structures
cpu_dev CPU device descriptor
cpu_unit CPU unit descriptor
cpu_reg CPU register list
cpu_mod CPU modifiers list
*/
UNIT cpu_unit = {
UDATA (NULL, UNIT_FIX+UNIT_BINK+UNIT_MDV, DFTMEMSIZE /* MAXMEMSIZE */ )
};
REG cpu_reg[] = {
{ ORDATA (PC, saved_PC, 15) },
{ ORDATA (AC0, AC[0], 16) },
{ ORDATA (AC1, AC[1], 16) },
{ ORDATA (AC2, AC[2], 16) },
{ ORDATA (AC3, AC[3], 16) },
{ FLDATA (C, C, 16) },
{ ORDATA (SP, SP, 16) },
{ ORDATA (FP, FP, 16) },
{ ORDATA (SR, SR, 16) },
{ ORDATA (PI, pimask, 16) },
{ FLDATA (ION, int_req, INT_V_ION) },
{ FLDATA (ION_DELAY, int_req, INT_V_NO_ION_PENDING) },
{ FLDATA (STKOVF, int_req, INT_V_STK) },
{ FLDATA (PWR, pwr_low, 0) },
{ ORDATA (INT, int_req, INT_V_ION+1), REG_RO },
{ ORDATA (BUSY, dev_busy, INT_V_ION+1), REG_RO },
{ ORDATA (DONE, dev_done, INT_V_ION+1), REG_RO },
{ ORDATA (DISABLE, dev_disable, INT_V_ION+1), REG_RO },
{ FLDATA (STOP_DEV, stop_dev, 0) },
{ DRDATA (INDMAX, ind_max, 32), REG_NZ + PV_LEFT },
{ ORDATA (AMASK, AMASK, 16) },
{ DRDATA (MEMSIZE, cpu_unit.capac, 32), REG_NZ + PV_LEFT },
{ BRDATA (PCQ, pcq, 8, 16, PCQ_SIZE), REG_RO+REG_CIRC },
{ ORDATA (PCQP, pcq_p, 6), REG_HRO },
{ ORDATA (WRU, sim_int_char, 8) },
{ NULL }
};
MTAB cpu_mod[] = {
{ UNIT_IOPT, UNIT_NOVA3, "NOVA3", "NOVA3", NULL },
{ UNIT_IOPT, UNIT_NOVA4, "NOVA4", "NOVA4", NULL },
{ UNIT_IOPT, UNIT_KERONIX, "KERONIX", "KERONIX", NULL },
{ UNIT_IOPT, UNIT_MDV, "MDV", "MDV", NULL },
{ UNIT_IOPT, UNIT_64KW, "EXT64KW", "EXT64KW", NULL },
{ UNIT_IOPT, 0, "none", "NONE", NULL },
{ UNIT_MSIZE, ( 4 * 1024), NULL, "4K", &cpu_set_size },
{ UNIT_MSIZE, ( 8 * 1024), NULL, "8K", &cpu_set_size },
{ UNIT_MSIZE, (12 * 1024), NULL, "12K", &cpu_set_size },
{ UNIT_MSIZE, (16 * 1024), NULL, "16K", &cpu_set_size },
{ UNIT_MSIZE, (20 * 1024), NULL, "20K", &cpu_set_size },
{ UNIT_MSIZE, (24 * 1024), NULL, "24K", &cpu_set_size },
{ UNIT_MSIZE, (28 * 1024), NULL, "28K", &cpu_set_size },
{ UNIT_MSIZE, (32 * 1024), NULL, "32K", &cpu_set_size },
{ UNIT_MSIZE, (36 * 1024), NULL, "36K", &cpu_set_size },
{ UNIT_MSIZE, (40 * 1024), NULL, "40K", &cpu_set_size },
{ UNIT_MSIZE, (44 * 1024), NULL, "44K", &cpu_set_size },
{ UNIT_MSIZE, (48 * 1024), NULL, "48K", &cpu_set_size },
{ UNIT_MSIZE, (52 * 1024), NULL, "52K", &cpu_set_size },
{ UNIT_MSIZE, (56 * 1024), NULL, "56K", &cpu_set_size },
{ UNIT_MSIZE, (60 * 1024), NULL, "60K", &cpu_set_size },
{ UNIT_MSIZE, (64 * 1024), NULL, "64K", &cpu_set_size },
{ MTAB_XTD|MTAB_VDV|MTAB_NMO|MTAB_SHP, 0, "HISTORY", "HISTORY",
&hist_set, &hist_show },
{ 0 }
};
DEVICE cpu_dev = {
"CPU", &cpu_unit, cpu_reg, cpu_mod,
1, 8, 16 /* = 64 KW, 15 = 32KW */, 1, 8, 16,
&cpu_ex, &cpu_dep, &cpu_reset,
NULL, NULL, NULL
};
t_stat sim_instr (void)
{
int32 PC, IR, i;
t_stat reason;
/* Restore register state */
if (build_devtab () != SCPE_OK) /* build dispatch */
return SCPE_IERR;
PC = saved_PC & AMASK; /* load local PC */
C = C & CBIT;
mask_out (pimask); /* reset int system */
reason = 0;
/* Main instruction fetch/decode loop */
while (reason == 0) { /* loop until halted */
if (sim_interval <= 0) { /* check clock queue */
if ( (reason = sim_process_event ()) )
break;
}
if (int_req > INT_PENDING) { /* interrupt or exception? */
int32 MA, indf;
if (int_req & INT_TRAP) { /* trap instruction? */
int_req = int_req & ~INT_TRAP ; /* clear */
PCQ_ENTRY; /* save old PC */
M[TRP_SAV] = (PC - 1) & AMASK;
MA = TRP_JMP; /* jmp @47 */
}
else {
int_req = int_req & ~INT_ION; /* intr off */
PCQ_ENTRY; /* save old PC */
M[INT_SAV] = PC;
if (int_req & INT_STK) { /* stack overflow? */
int_req = int_req & ~INT_STK; /* clear */
MA = STK_JMP; /* jmp @3 */
}
else
MA = INT_JMP; /* intr: jmp @1 */
}
if ( MODE_64K_ACTIVE ) {
indf = IND_STEP (MA);
}
else
{
for (i = 0, indf = 1; indf && (i < ind_max); i++) {
indf = IND_STEP (MA); /* indirect loop */
}
if (i >= ind_max) {
reason = STOP_IND_INT;
break;
}
}
PC = MA;
} /* end interrupt */
if (sim_brk_summ && sim_brk_test (PC, SWMASK ('E'))) { /* breakpoint? */
reason = STOP_IBKPT; /* stop simulation */
break;
}
IR = M[PC]; /* fetch instr */
if ( hist_cnt )
{
hist_save( PC, IR ) ; /* PC, int_req unchanged */
}
INCREMENT_PC ;
int_req = int_req | INT_NO_ION_PENDING; /* clear ION delay */
sim_interval = sim_interval - 1;
/* Operate instruction */
if (IR & I_OPR) { /* operate? */
int32 src, srcAC, dstAC;
srcAC = I_GETSRC (IR); /* get reg decodes */
dstAC = I_GETDST (IR);
switch (I_GETCRY (IR)) { /* decode carry */
case 0: /* load */
src = AC[srcAC] | C;
break;
case 1: /* clear */
src = AC[srcAC];
break;
case 2: /* set */
src = AC[srcAC] | CBIT;
break;
case 3: /* complement */
src = AC[srcAC] | (C ^ CBIT);
break;
} /* end switch carry */
switch (I_GETALU (IR)) { /* decode ALU */
case 0: /* COM */
src = src ^ DMASK;
break;
case 1: /* NEG */
src = ((src ^ DMASK) + 1) & CDMASK;
break;
case 2: /* MOV */
break;
case 3: /* INC */
src = (src + 1) & CDMASK;
break;
case 4: /* ADC */
src = ((src ^ DMASK) + AC[dstAC]) & CDMASK;
break;
case 5: /* SUB */
src = ((src ^ DMASK) + AC[dstAC] + 1) & CDMASK;
break;
case 6: /* ADD */
src = (src + AC[dstAC]) & CDMASK;
break;
case 7: /* AND */
src = src & (AC[dstAC] | CBIT);
break;
} /* end switch oper */
switch (I_GETSHF (IR)) { /* decode shift */
case 0: /* nop */
break;
case 1: /* L */
src = ((src << 1) | (src >> 16)) & CDMASK;
break;
case 2: /* R */
src = ((src >> 1) | (src << 16)) & CDMASK;
break;
case 3: /* S */
src = ((src & 0377) << 8) | ((src >> 8) & 0377) |
(src & CBIT);
break;
} /* end switch shift */
switch (I_GETSKP (IR)) { /* decode skip */
case 0: /* nop */
if ((IR & I_NLD) && (cpu_unit.flags & UNIT_STK)) {
int_req = int_req | INT_TRAP ; /* Nova 3 or 4 trap */
continue ;
}
break;
case 1: /* SKP */
INCREMENT_PC ;
break;
case 2: /* SZC */
if (src < CBIT)
INCREMENT_PC ;
break;
case 3: /* SNC */
if (src >= CBIT)
INCREMENT_PC ;
break;
case 4: /* SZR */
if ((src & DMASK) == 0)
INCREMENT_PC ;
break;
case 5: /* SNR */
if ((src & DMASK) != 0)
INCREMENT_PC ;
break;
case 6: /* SEZ */
if (src <= CBIT)
INCREMENT_PC ;
break;
case 7: /* SBN */
if (src > CBIT)
INCREMENT_PC ;
break;
} /* end switch skip */
if ((IR & I_NLD) == 0) { /* load? */
AC[dstAC] = src & DMASK;
C = src & CBIT;
} /* end if load */
} /* end if operate */
/* Memory reference instructions */
else if (IR < 060000) { /* mem ref? */
int32 src, MA, indf;
MA = I_GETDISP (IR); /* get disp */
switch (I_GETMODE (IR)) { /* decode mode */
case 0: /* page zero */
break;
case 1: /* PC relative */
if (MA & DISPSIGN)
MA = 0177400 | MA;
MA = (MA + PC - 1) & AMASK;
break;
case 2: /* AC2 relative */
if (MA & DISPSIGN)
MA = 0177400 | MA;
MA = (MA + AC[2]) & AMASK;
break;
case 3: /* AC3 relative */
if (MA & DISPSIGN)
MA = 0177400 | MA;
MA = (MA + AC[3]) & AMASK;
break;
} /* end switch mode */
if ( (indf = IR & I_IND) ) { /* indirect? */
if ( MODE_64K_ACTIVE ) { /* 64k mode? */
indf = IND_STEP (MA);
}
else /* compat mode */
{
for (i = 0; indf && (i < ind_max); i++) { /* count */
indf = IND_STEP (MA); /* resolve indirect */
}
if (i >= ind_max) { /* too many? */
reason = STOP_IND;
break;
}
}
}
switch (I_GETOPAC (IR)) { /* decode op + AC */
case 001: /* JSR */
AC[3] = PC;
case 000: /* JMP */
PCQ_ENTRY;
PC = MA;
break;
case 002: /* ISZ */
src = (M[MA] + 1) & DMASK;
if (MEM_ADDR_OK(MA))
M[MA] = src;
if (src == 0)
INCREMENT_PC ;
break;
case 003: /* DSZ */
src = (M[MA] - 1) & DMASK;
if (MEM_ADDR_OK(MA))
M[MA] = src;
if (src == 0)
INCREMENT_PC ;
break;
case 004: /* LDA 0 */
AC[0] = M[MA];
break;
case 005: /* LDA 1 */
AC[1] = M[MA];
break;
case 006: /* LDA 2 */
AC[2] = M[MA];
break;
case 007: /* LDA 3 */
AC[3] = M[MA];
break;
case 010: /* STA 0 */
if (MEM_ADDR_OK(MA))
M[MA] = AC[0];
break;
case 011: /* STA 1 */
if (MEM_ADDR_OK(MA))
M[MA] = AC[1];
break;
case 012: /* STA 2 */
if (MEM_ADDR_OK(MA))
M[MA] = AC[2];
break;
case 013: /* STA 3 */
if (MEM_ADDR_OK(MA))
M[MA] = AC[3];
break;
} /* end switch */
} /* end mem ref */
/* IOT instruction */
else { /* IOT */
int32 dstAC, pulse, code, device, iodata;
dstAC = I_GETDST (IR); /* decode fields */
code = I_GETIOT (IR);
pulse = I_GETPULSE (IR);
device = I_GETDEV (IR);
if (code == ioSKP) { /* IO skip? */
switch (pulse) { /* decode IR<8:9> */
case 0: /* skip if busy */
if ((device == DEV_CPU)? (int_req & INT_ION) != 0:
(dev_busy & dev_table[device].mask) != 0)
INCREMENT_PC ;
break;
case 1: /* skip if not busy */
if ((device == DEV_CPU)? (int_req & INT_ION) == 0:
(dev_busy & dev_table[device].mask) == 0)
INCREMENT_PC ;
break;
case 2: /* skip if done */
if ((device == DEV_CPU)? pwr_low != 0:
(dev_done & dev_table[device].mask) != 0)
INCREMENT_PC ;
break;
case 3: /* skip if not done */
if ((device == DEV_CPU)? pwr_low == 0:
(dev_done & dev_table[device].mask) == 0)
INCREMENT_PC ;
break;
} /* end switch */
} /* end IO skip */
/* Hmm, this means a Nova 3 _must_ have DEV_MDV enabled - not true in DG land */
else if (device == DEV_MDV) {
switch (code) { /* case on opcode */
case ioNIO: /* frame ptr */
if (cpu_unit.flags & UNIT_STK) {
if (pulse == iopN)
FP = AC[dstAC] & AMASK ;
if (pulse == iopC)
AC[dstAC] = FP & AMASK ;
}
break;
case ioDIA: /* load byte */
if (cpu_unit.flags & UNIT_BYT)
{
AC[dstAC] = (M[AC[pulse] >> 1] >> ((AC[pulse] & 1)? 0: 8)) & 0377 ;
}
else if (cpu_unit.flags & UNIT_STK) /* if Nova 3 this is really a SAV... 2007-Jun-01, BKR */
{
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[0];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[1];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[2];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = FP;
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = (C >> 1) | (AC[3] & AMASK);
AC[3] = FP = SP & AMASK;
STK_CHECK (SP, 5);
}
else
{
AC[dstAC] = 0;
}
break;
case ioDOA: /* stack ptr */
if (cpu_unit.flags & UNIT_STK) {
if (pulse == iopN)
SP = AC[dstAC] & AMASK;
if (pulse == iopC)
AC[dstAC] = SP & AMASK;
}
break;
case ioDIB: /* push, pop */
if (cpu_unit.flags & UNIT_STK) {
if (pulse == iopN) { /* push (PSHA) */
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[dstAC];
STK_CHECK (SP, 1);
}
if ((pulse == iopS) && /* Nova 4 pshn (PSHN) */
(cpu_unit.flags & UNIT_BYT)) {
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[dstAC];
if ( (SP & 0xFFFF) > (M[042] & 0xFFFF) )
{
int_req = int_req | INT_STK ;
}
}
if (pulse == iopC) { /* pop (POPA) */
AC[dstAC] = M[SP];
SP = DECA (SP);
}
}
break;
case ioDOB: /* store byte */
if (cpu_unit.flags & UNIT_BYT)
{
int32 MA, val;
MA = AC[pulse] >> 1;
val = AC[dstAC] & 0377;
if (MEM_ADDR_OK (MA)) M[MA] = (AC[pulse] & 1)?
((M[MA] & ~0377) | val)
: ((M[MA] & 0377) | (val << 8));
}
else if (cpu_unit.flags & UNIT_STK) /* if Nova 3 this is really a SAV... 2007-Jun-01, BKR */
{
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[0];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[1];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[2];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = FP;
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = (C >> 1) | (AC[3] & AMASK);
AC[3] = FP = SP & AMASK;
STK_CHECK (SP, 5);
}
break;
case ioDIC: /* save, return */
if (cpu_unit.flags & UNIT_STK) {
if (pulse == iopN) { /* save */
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[0];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[1];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[2];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = FP;
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = (C >> 1) | (AC[3] & AMASK);
AC[3] = FP = SP & AMASK;
STK_CHECK (SP, 5);
}
else if (pulse == iopC) { /* retn */
PCQ_ENTRY;
SP = FP & AMASK;
C = (M[SP] << 1) & CBIT;
PC = M[SP] & AMASK;
SP = DECA (SP);
AC[3] = M[SP];
SP = DECA (SP);
AC[2] = M[SP];
SP = DECA (SP);
AC[1] = M[SP];
SP = DECA (SP);
AC[0] = M[SP];
SP = DECA (SP);
FP = AC[3] & AMASK;
}
else if ((pulse == iopS) && /* Nova 4 SAVN */
(cpu_unit.flags & UNIT_BYT)) {
int32 frameSz = M[PC] ;
PC = INCA (PC) ;
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[0];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[1];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[2];
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = FP;
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = (C >> 1) | (AC[3] & AMASK);
AC[3] = FP = SP & AMASK ;
SP = (SP + frameSz) & AMASK ;
if (SP > M[042])
{
int_req = int_req | INT_STK;
}
}
}
break;
case ioDOC:
if ((dstAC == 2) && (cpu_unit.flags & UNIT_MDV))
{ /* Nova, Nova3 or Nova 4 */
uint32 mddata, uAC0, uAC1, uAC2;
uAC0 = (uint32) AC[0];
uAC1 = (uint32) AC[1];
uAC2 = (uint32) AC[2];
if (pulse == iopP)
{ /* mul */
mddata = (uAC1 * uAC2) + uAC0;
AC[0] = (mddata >> 16) & DMASK;
AC[1] = mddata & DMASK;
}
if (pulse == iopS)
{ /* div */
if ((uAC0 >= uAC2) || (uAC2 == 0))
{
C = CBIT;
}
else
{
C = 0;
mddata = (uAC0 << 16) | uAC1;
AC[1] = mddata / uAC2;
AC[0] = mddata % uAC2;
}
}
}
else if ((dstAC == 3) && (cpu_unit.flags & UNIT_BYT) /* assuming UNIT_BYT = Nova 4 */)
{
int32 mddata;
if (pulse == iopC)
{ /* muls */
mddata = (SEXT (AC[1]) * SEXT (AC[2])) + SEXT (AC[0]);
AC[0] = (mddata >> 16) & DMASK;
AC[1] = mddata & DMASK;
}
else if (pulse == iopN)
{ /* divs */
if ((AC[2] == 0) || /* overflow? */
((AC[0] == 0100000) && (AC[1] == 0) && (AC[2] == 0177777)))
{
C = CBIT;
}
else
{
mddata = (SEXT (AC[0]) << 16) | AC[1];
AC[1] = mddata / SEXT (AC[2]);
AC[0] = mddata % SEXT (AC[2]);
if ((AC[1] > 077777) || (AC[1] < -0100000))
{
C = CBIT;
}
else
{
C = 0;
}
AC[0] = AC[0] & DMASK;
}
}
}
else if ((dstAC == 3) && (cpu_unit.flags & UNIT_STK)) /* if Nova 3 this is really a PSHA... 2007-Jun-01, BKR */
{
SP = INCA (SP);
if (MEM_ADDR_OK (SP))
M[SP] = AC[dstAC];
STK_CHECK (SP, 1);
}
break;
} /* end case code */
} /* end if mul/div */
else if (device == DEV_CPU) { /* CPU control */
switch (code) { /* decode IR<5:7> */
case ioNIO: /* NIOP <x> CPU ? */
if ( pulse == iopP )
if ( MODE_64K )
{
/* Keronix/Point4/SCI/INI/IDP (and others) */
/* 64 KW memory extension: */
/* NIOP - set memory mode (32/64 KW) per AC: */
/* B15: 0 = 32 KW, 1 = 64 KW mode */
AMASK = (AC[dstAC] & 0x0001) ? 0177777 : 077777 ;
}
break ;
case ioDIA: /* read switches */
AC[dstAC] = SR;
break;
case ioDIB: /* int ack */
AC[dstAC] = 0;
DEV_UPDATE_INTR ;
iodata = int_req & (-int_req);
for (i = DEV_LOW; i <= DEV_HIGH; i++) {
if (iodata & dev_table[i].mask) {
AC[dstAC] = i;
break;
}