-
Notifications
You must be signed in to change notification settings - Fork 74
/
pdp18b_cpu.c
2429 lines (2162 loc) · 99.9 KB
/
pdp18b_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
/* pdp18b_cpu.c: 18b PDP CPU simulator
Copyright (c) 1993-2016, 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 PDP-4/7/9/15 central processor
10-Mar-16 RMS Added 3-cycle databreak set/show routines
07-Mar-16 RMS Revised to allocate memory dynamically
28-Mar-15 RMS Revised to use sim_printf
28-Apr-07 RMS Removed clock initialization
26-Dec-06 RMS Fixed boundary test in KT15/XVM (Andrew Warkentin)
30-Oct-06 RMS Added idle and infinite loop detection
08-Oct-06 RMS Added RDCLK instruction
Fixed bug, PC off by one on fetch mem mmgt error
PDP-15 sets API 3 on mem mmgt trap (like PI)
PDP-15 sets API 4 on CAL only if 0-3 inactive
CAF clears memory management mode register
27-Jun-06 RMS Reset clears AC, L, and MQ
22-Sep-05 RMS Fixed declarations (Sterling Garwood)
16-Aug-05 RMS Fixed C++ declaration and cast problems
22-Jul-05 RMS Removed AAS, error in V1 reference manual
06-Nov-04 RMS Added =n to SHOW HISTORY
26-Mar-04 RMS Fixed warning from -std=c99
14-Jan-04 RMS Fixed g_mode in XVM implementation
PDP-15 index, autoincrement generate 18b addresses
Revised IO device call interface
31-Dec-03 RMS Fixed bug in cpu_set_hist
02-Nov-03 RMS Changed PDP-9,-15 default to API
26-Oct-03 RMS Fixed bug in PDP-4,-7,-9 autoincrement addressing
19-Sep-03 RMS Changed instruction history to be dynamically sized
31-Aug-03 RMS Added instruction history
Fixed PDP-15-specific implementation of API priorities
16-Aug-03 RMS Fixed PDP-15-specific handling of EAE unsigned mul/div
27-Jul-03 RMS Added FP15 support
Added XVM support
Added EAE option to PDP-4
Added PDP-15 "re-entrancy ECO"
Fixed memory protect/skip interaction
Fixed CAF not to reset CPU
12-Mar-03 RMS Added logical name support
18-Feb-03 RMS Fixed three EAE bugs (Hans Pufal)
05-Oct-02 RMS Added DIBs, device number support
25-Jul-02 RMS Added DECtape support for PDP-4
06-Jan-02 RMS Revised enable/disable support
30-Dec-01 RMS Added old PC queue
30-Nov-01 RMS Added extended SET/SHOW support
25-Nov-01 RMS Revised interrupt structure
19-Sep-01 RMS Fixed bug in EAE (Dave Conroy)
17-Sep-01 RMS Fixed typo in conditional
10-Aug-01 RMS Removed register from declarations
17-Jul-01 RMS Moved function prototype
27-May-01 RMS Added second Teletype support, fixed bug in API
18-May-01 RMS Added PDP-9,-15 API option
16-May-01 RMS Fixed bugs in protection checks
26-Apr-01 RMS Added device enable/disable support
25-Jan-01 RMS Added DECtape support
18-Dec-00 RMS Added PDP-9,-15 memm init register
30-Nov-00 RMS Fixed numerous PDP-15 bugs
14-Apr-99 RMS Changed t_addr to unsigned
The 18b PDP family has five distinct architectural variants: PDP-1,
PDP-4, PDP-7, PDP-9, and PDP-15. Of these, the PDP-1 is so unique
as to require a different simulator. The PDP-4, PDP-7, PDP-9, and
PDP-15 are "upward compatible", with each new variant adding
distinct architectural features and incompatibilities.
The register state for the 18b PDP's is:
all AC<0:17> accumulator
all MQ<0:17> multiplier-quotient
all L link flag
all PC<0:x> program counter
all IORS I/O status register
PDP-7, PDP-9 EXTM extend mode
PDP-15 BANKM bank mode
PDP-7 USMD trap mode
PDP-9, PDP-15 USMD user mode
PDP-9, PDP-15 BR bounds register
PDP-15 RR relocation register
PDP-15 XVM MMR memory management register
PDP-15 XR index register
PDP-15 LR limit register
The PDP-4, PDP-7, and PDP-9 have five instruction formats: memory
reference, load immediate, I/O transfer, EAE, and operate. The PDP-15
adds a sixth, index operate, and a seventh, floating point. The memory
reference format for the PDP-4, PDP-7, and PDP-9, and for the PDP-15
in bank mode, is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| op |in| address | memory reference
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The PDP-15 in page mode trades an address bit for indexing capability:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| op |in| X| address | memory reference
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
<0:3> mnemonic action
00 CAL JMS with MA = 20
04 DAC M[MA] = AC
10 JMS M[MA] = L'mem'user'PC, PC = MA + 1
14 DZM M[MA] = 0
20 LAC AC = M[MA]
24 XOR AC = AC ^ M[MA]
30 ADD L'AC = AC + M[MA] one's complement
34 TAD L'AC = AC + M[MA]
40 XCT M[MA] is executed as an instruction
44 ISZ M[MA] = M[MA] + 1, skip if M[MA] == 0
50 AND AC = AC & M[MA]
54 SAD skip if AC != M[MA]
60 JMP PC = MA
On the PDP-4, PDP-7, and PDP-9, and the PDP-15 in bank mode, memory
reference instructions can access an address space of 32K words. The
address space is divided into four 8K word fields. An instruction can
directly address, via its 13b address, the entire current field. On the
PDP-4, PDP-7, and PDP-9, if extend mode is off, indirect addresses access
the current field; if on (or a PDP-15), they can access all 32K.
On the PDP-15 in page mode, memory reference instructions can access
an address space of 128K words. The address is divided into four 32K
word blocks, each of which consists of eight 4K pages. An instruction
can directly address, via its 12b address, the current page. Indirect
addresses can access the current block. Indexed and autoincrement
addresses can access all 128K.
On the PDP-4 and PDP-7, if an indirect address in in locations 00010-
00017 of any field, the indirect address is incremented and rewritten
to memory before use. On the PDP-9 and PDP-15, only locations 00010-
00017 of field zero autoincrement; special logic will redirect indirect
references to 00010-00017 to field zero, even if (on the PDP-9) extend
mode is off.
The EAE format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 0 1| | | | | | | | | | | | | | | EAE
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| | | | | | | | | | | | | |
| | | | | | | | | | | | | +- or SC (3)
| | | | | | | | | | | | +---- or MQ (3)
| | | | | | | | | | | +------- compl MQ (3)
| | | | | | | | \______________/
| | | | | | | | |
| | | | | \_____/ +--------- shift count
| | | | | |
| | | | | +---------------------- EAE command (3)
| | | | +---------------------------- clear AC (2)
| | | +------------------------------- or AC (2)
| | +---------------------------------- load EAE sign (1)
| +------------------------------------- clear MQ (1)
+---------------------------------------- load link (1)
The I/O transfer format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 1 0 0 0| device | sdv |cl| pulse | I/O transfer
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The IO transfer instruction sends the the specified pulse to the
specified I/O device and sub-device. The I/O device may take data
from the AC, return data to the AC, initiate or cancel operations,
or skip on status. On the PDP-4, PDP-7, and PDP-9, bits <4:5>
were designated as subdevice bits but were never used; the PDP-15
requires them to be zero.
On the PDP-15, the floating point format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 1 0 0 1| subopcode | floating point
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|in| address |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Indirection is always single level.
On the PDP-15, the index operate format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 1 0 1| subopcode | immediate | index operate
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
The index operate instructions provide various operations on the
index and limit registers.
The operate format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 1 1 0| | | | | | | | | | | | | | operate
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| | | | | | | | | | | | |
| | | | | | | | | | | | +- CMA (3)
| | | | | | | | | | | +---- CML (3)
| | | | | | | | | | +------- OAS (3)
| | | | | | | | | +---------- RAL (3)
| | | | | | | | +------------- RAR (3)
| | | | | | | +---------------- HLT (4)
| | | | | | +------------------- SMA (1)
| | | | | +---------------------- SZA (1)
| | | | +------------------------- SNL (1)
| | | +---------------------------- invert skip (1)
| | +------------------------------- rotate twice (2)
| +---------------------------------- CLL (2)
+------------------------------------- CLA (2)
The operate instruction can be microprogrammed to perform operations
on the AC and link.
The load immediate format is:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| 1 1 1 1 1| immediate | LAW
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
<0:4> mnemonic action
76 LAW AC = IR
This routine is the instruction decode routine for the 18b PDP's.
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
unimplemented instruction and STOP_INST flag set
nested XCT's
I/O error in I/O simulator
2. Interrupts. Interrupt requests are maintained in the int_hwre
array. int_hwre[0:3] corresponds to API levels 0-3; int_hwre[4]
holds PI requests.
3. Arithmetic. The 18b PDP's implements both 1's and 2's complement
arithmetic for signed numbers. In 1's complement arithmetic, a
negative number is represented by the complement (XOR 0777777) of
its absolute value. Addition of 1's complement numbers requires
propagating the carry out of the high order bit back to the low
order bit.
4. Adding I/O devices. Three modules must be modified:
pdp18b_defs.h add interrupt request definition
pdp18b_sys.c add sim_devices table entry
*/
#include "pdp18b_defs.h"
#define SEXT(x) ((int32) (((x) & SIGN)? (x) | ~DMASK: (x) & DMASK))
#define UNIT_V_NOEAE (UNIT_V_UF + 0) /* EAE absent */
#define UNIT_V_NOAPI (UNIT_V_UF + 1) /* API absent */
#define UNIT_V_PROT (UNIT_V_UF + 2) /* protection */
#define UNIT_V_RELOC (UNIT_V_UF + 3) /* relocation */
#define UNIT_V_XVM (UNIT_V_UF + 4) /* XVM */
#define UNIT_V_MSIZE (UNIT_V_UF + 5) /* dummy mask */
#define UNIT_NOEAE (1 << UNIT_V_NOEAE)
#define UNIT_NOAPI (1 << UNIT_V_NOAPI)
#define UNIT_PROT (1 << UNIT_V_PROT)
#define UNIT_RELOC (1 << UNIT_V_RELOC)
#define UNIT_XVM (1 << UNIT_V_XVM)
#define UNIT_MSIZE (1 << UNIT_V_MSIZE)
#define OP_KSF 0700301
#define HIST_API 0x40000000
#define HIST_PI 0x20000000
#define HIST_PC 0x10000000
#define HIST_MIN 64
#define HIST_MAX 65536
#define HIST_M_LVL 0x3F
#define HIST_V_LVL 6
typedef struct {
int32 pc;
int32 ir;
int32 ir1;
int32 lac;
int32 mq;
} InstHistory;
#define XVM (cpu_unit.flags & UNIT_XVM)
#define RELOC (cpu_unit.flags & UNIT_RELOC)
#define PROT (cpu_unit.flags & UNIT_PROT)
#if defined (PDP4)
#define EAE_DFLT UNIT_NOEAE
#else
#define EAE_DFLT 0
#endif
#if defined (PDP4) || defined (PDP7)
#define API_DFLT UNIT_NOAPI
#define PROT_DFLT 0
#define ASW_DFLT 017763
#else
#define API_DFLT 0
#define PROT_DFLT UNIT_PROT
#define ASW_DFLT 017720
#endif
int32 *M = NULL; /* memory */
int32 LAC = 0; /* link'AC */
int32 MQ = 0; /* MQ */
int32 PC = 0; /* PC */
int32 iors = 0; /* IORS */
int32 ion = 0; /* int on */
int32 ion_defer = 0; /* int defer */
int32 ion_inh = 0; /* int inhibit */
int32 int_pend = 0; /* int pending */
int32 int_hwre[API_HLVL+1] = { 0 }; /* int requests */
int32 api_enb = 0; /* API enable */
int32 api_req = 0; /* API requests */
int32 api_act = 0; /* API active */
int32 memm = 0; /* mem mode */
#if defined (PDP15)
int32 memm_init = 1; /* mem init */
#else
int32 memm_init = 0;
#endif
int32 usmd = 0; /* user mode */
int32 usmd_buf = 0; /* user mode buffer */
int32 usmd_defer = 0; /* user mode defer */
int32 trap_pending = 0; /* trap pending */
int32 emir_pending = 0; /* emir pending */
int32 rest_pending = 0; /* restore pending */
int32 BR = 0; /* mem mgt bounds */
int32 RR = 0; /* mem mgt reloc */
int32 MMR = 0; /* XVM mem mgt */
int32 nexm = 0; /* nx mem flag */
int32 prvn = 0; /* priv viol flag */
int32 SC = 0; /* shift count */
int32 eae_ac_sign = 0; /* EAE AC sign */
int32 SR = 0; /* switch register */
int32 ASW = ASW_DFLT; /* address switches */
int32 XR = 0; /* index register */
int32 LR = 0; /* limit register */
int32 stop_inst = 0; /* stop on rsrv inst */
int32 xct_max = 16; /* nested XCT limit */
#if defined (PDP15)
int32 pcq[PCQ_SIZE] = { 0 }; /* PC queue */
#else
int16 pcq[PCQ_SIZE] = { 0 }; /* PC queue */
#endif
int32 pcq_p = 0; /* PC queue ptr */
REG *pcq_r = NULL; /* PC queue reg ptr */
int32 hst_p = 0; /* history pointer */
int32 hst_lnt = 0; /* history length */
InstHistory *hst = NULL; /* instruction history */
t_bool build_dev_tab (void);
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_set_hist (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
t_stat cpu_show_hist (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
void cpu_caf (void);
void cpu_inst_hist (int32 addr, int32 inst);
void cpu_intr_hist (int32 flag, int32 lvl);
int32 upd_iors (void);
int32 api_eval (int32 *pend);
t_stat Read (int32 ma, int32 *dat, int32 cyc);
t_stat Write (int32 ma, int32 dat, int32 cyc);
t_stat Ia (int32 ma, int32 *ea, t_bool jmp);
int32 Incr_addr (int32 addr);
int32 Jms_word (int32 t);
#if defined (PDP15)
#define INDEX(i,x) if (!memm && ((i) & I_IDX)) \
x = ((x) + XR) & DMASK
int32 Prot15 (int32 ma, t_bool bndchk);
int32 Reloc15 (int32 ma, int32 acc);
int32 RelocXVM (int32 ma, int32 acc);
extern t_stat fp15 (int32 ir);
extern int32 clk_task_upd (t_bool clr);
#else
#define INDEX(i,x)
#endif
extern int32 clk (int32 dev, int32 pulse, int32 AC);
int32 (*dev_tab[DEV_MAX])(int32 dev, int32 pulse, int32 AC); /* device dispatch */
int32 (*dev_iors[DEV_MAX])(void); /* IORS dispatch */
static const int32 api_ffo[256] = {
8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
int32 api_vec[API_HLVL][32] = {
{ ACH_PWRFL }, /* API 0 */
{ ACH_DTA, ACH_MTA, ACH_DRM, ACH_RF, ACH_RP, ACH_RB }, /* API 1 */
{ ACH_PTR, ACH_LPT, ACH_LPT }, /* API 2 */
{ ACH_CLK, ACH_TTI1, ACH_TTO1 } /* API 3 */
};
/* CPU data structures
cpu_dev CPU device descriptor
cpu_unit CPU unit
cpu_reg CPU register list
cpu_mod CPU modifier list
*/
UNIT cpu_unit = {
UDATA (NULL, UNIT_FIX+UNIT_BINK+EAE_DFLT+API_DFLT+PROT_DFLT,
MAXMEMSIZE)
};
REG cpu_reg[] = {
{ ORDATAD (PC, PC, ADDRSIZE, "program counter") },
{ ORDATAD (AC, LAC, 18, "accumulator") },
{ FLDATAD (L, LAC, 18, "link") },
{ ORDATAD (MQ, MQ, 18, "multiplier-quotient") },
{ ORDATAD (SC, SC, 6, "shift counter") },
{ FLDATAD (EAE_AC_SIGN, eae_ac_sign, 18, "EAE AC sign") },
{ ORDATAD (SR, SR, 18, "front panel switches") },
{ ORDATAD (ASW, ASW, ADDRSIZE, "address switches for RIM load") },
{ ORDATAD (IORS, iors, 18, "IORS register"), REG_RO },
{ BRDATAD (INT, int_hwre, 8, 32, API_HLVL+1, "interrupt requests, 0:3 = API levels 0 to 3, 4 = PI level"), REG_RO },
{ FLDATAD (INT_PEND, int_pend, 0, "interrupt pending"), REG_RO },
{ FLDATAD (ION, ion, 0, "interrupt enable") },
{ ORDATAD (ION_DELAY, ion_defer, 2, "interrupt enable delay") },
#if defined (PDP7)
{ FLDATAD (TRAPM, usmd, 0, "trap mode") },
{ FLDATAD (TRAPP, trap_pending, 0, "trap pending") },
{ FLDATAD (EXTM, memm, 0, "extend mode") },
{ FLDATAD (EXTM_INIT, memm_init, 0, "exit mode value after reset") },
{ FLDATAD (EMIRP, emir_pending, 0, "EMIR instruction pending") },
#endif
#if defined (PDP9)
{ FLDATAD (APIENB, api_enb, 0, "api enable") },
{ ORDATAD (APIREQ, api_req, 8, "api requesting levels") },
{ ORDATAD (APIACT, api_act, 8, "api active levels") },
{ ORDATAD (BR, BR, ADDRSIZE, "memory protection bounds") },
{ FLDATAD (USMD, usmd, 0, "user mode") },
{ FLDATAD (USMDBUF, usmd_buf, 0, "user mode buffer") },
{ FLDATAD (USMDDEF, usmd_defer, 0, "user mode load defer") },
{ FLDATAD (NEXM, nexm, 0, "non-existent memory violation") },
{ FLDATAD (PRVN, prvn, 0, "privilege violation") },
{ FLDATAD (TRAPP, trap_pending, 0, "trap pending") },
{ FLDATAD (EXTM, memm, 0, "extend mode") },
{ FLDATAD (EXTM_INIT, memm_init, 0, "extend mode value after reset") },
{ FLDATAD (EMIRP, emir_pending, 0, "EMIR instruction pending") },
{ FLDATAD (RESTP, rest_pending, 0, "DBR or RES instruction pending") },
{ FLDATAD (PWRFL, int_hwre[API_PWRFL], INT_V_PWRFL, "power fail pending") },
#endif
#if defined (PDP15)
{ FLDATAD (ION_INH, ion_inh, 0, "interrupt inhibit") },
{ FLDATAD (APIENB, api_enb, 0, "API enable") },
{ ORDATAD (APIREQ, api_req, 8, "API requesting levels") },
{ ORDATAD (APIACT, api_act, 8, "API active levels") },
{ ORDATAD (XR, XR, 18, "index register") },
{ ORDATAD (LR, LR, 18, "limit register") },
{ ORDATAD (BR, BR, 18, "memory protection bounds") },
{ ORDATAD (RR, RR, 18, "memory protection relocation") },
{ ORDATAD (MMR, MMR, 18, "memory protection control") },
{ FLDATAD (USMD, usmd, 0, "user mode") },
{ FLDATAD (USMDBUF, usmd_buf, 0, "user mode buffer") },
{ FLDATAD (USMDDEF, usmd_defer, 0, "user mode load defer") },
{ FLDATAD (NEXM, nexm, 0, "non-existent memory violation") },
{ FLDATAD (PRVN, prvn, 0, "privilege violation") },
{ FLDATAD (TRAPP, trap_pending, 0, "trap pending") },
{ FLDATAD (BANKM, memm, 0, "bank mode") },
{ FLDATAD (BANKM_INIT, memm_init, 0, "bank mode value after reset") },
{ FLDATAD (RESTP, rest_pending, 0, "DBR or RES instruction pending") },
{ FLDATAD (PWRFL, int_hwre[API_PWRFL], INT_V_PWRFL, "power fail flag") },
#endif
{ BRDATAD (PCQ, pcq, 8, ADDRSIZE, PCQ_SIZE, "PC prior to last JMP, JMS, CAL or interrupt; most recent PC change first stop on undefineds instruction"), REG_RO+REG_CIRC },
{ ORDATA (PCQP, pcq_p, 6), REG_HRO },
{ FLDATAD (STOP_INST, stop_inst, 0, "stop on defined instruction") },
{ DRDATAD (XCT_MAX, xct_max, 8, "max numb of chained XCT's allowed"), PV_LEFT + REG_NZ },
{ ORDATAD (WRU, sim_int_char, 8, "interrupt character") },
{ NULL } };
MTAB cpu_mod[] = {
{ UNIT_NOEAE, UNIT_NOEAE, "no EAE", "NOEAE", NULL },
{ UNIT_NOEAE, 0, "EAE", "EAE", NULL },
#if defined (PDP9) || defined (PDP15)
{ UNIT_NOAPI, UNIT_NOAPI, "no API", "NOAPI", NULL },
{ UNIT_NOAPI, 0, "API", "API", NULL },
{ UNIT_PROT+UNIT_RELOC+UNIT_XVM, 0, "no memory protect",
"NOPROTECT", NULL },
{ UNIT_PROT+UNIT_RELOC+UNIT_XVM, UNIT_PROT, "memory protect",
"PROTECT", NULL },
#endif
#if defined (PDP15)
{ UNIT_PROT+UNIT_RELOC+UNIT_XVM, UNIT_PROT+UNIT_RELOC,
"memory relocation", "RELOCATION", NULL },
{ UNIT_PROT+UNIT_RELOC+UNIT_XVM, UNIT_PROT+UNIT_RELOC+UNIT_XVM,
"XVM", "XVM", NULL },
#endif
{ MTAB_XTD|MTAB_VDV, 0, "IDLE", "IDLE", &sim_set_idle, &sim_show_idle },
{ MTAB_XTD|MTAB_VDV, 0, NULL, "NOIDLE", &sim_clr_idle, NULL },
#if defined (PDP4)
{ UNIT_MSIZE, 4096, NULL, "4K", &cpu_set_size },
#endif
{ UNIT_MSIZE, 8192, NULL, "8K", &cpu_set_size },
#if (MAXMEMSIZE > 8192)
{ UNIT_MSIZE, 12288, NULL, "12K", &cpu_set_size },
{ UNIT_MSIZE, 16384, NULL, "16K", &cpu_set_size },
{ UNIT_MSIZE, 20480, NULL, "20K", &cpu_set_size },
{ UNIT_MSIZE, 24576, NULL, "24K", &cpu_set_size },
{ UNIT_MSIZE, 28672, NULL, "28K", &cpu_set_size },
{ UNIT_MSIZE, 32768, NULL, "32K", &cpu_set_size },
#endif
#if (MAXMEMSIZE > 32768)
{ UNIT_MSIZE, 49152, NULL, "48K", &cpu_set_size },
{ UNIT_MSIZE, 65536, NULL, "64K", &cpu_set_size },
{ UNIT_MSIZE, 81920, NULL, "80K", &cpu_set_size },
{ UNIT_MSIZE, 98304, NULL, "96K", &cpu_set_size },
{ UNIT_MSIZE, 114688, NULL, "112K", &cpu_set_size },
{ UNIT_MSIZE, 131072, NULL, "128K", &cpu_set_size },
#endif
{ MTAB_XTD|MTAB_VDV|MTAB_NMO|MTAB_SHP, 0, "HISTORY", "HISTORY",
&cpu_set_hist, &cpu_show_hist },
{ 0 }
};
DEVICE cpu_dev = {
"CPU", &cpu_unit, cpu_reg, cpu_mod,
1, 8, ADDRSIZE, 1, 8, 18,
&cpu_ex, &cpu_dep, &cpu_reset,
NULL, NULL, NULL
};
t_stat sim_instr (void)
{
int32 api_int, api_usmd, skp;
int32 iot_data, device, pulse;
int32 last_IR;
t_stat reason;
if (build_dev_tab ()) /* build, chk tables */
return SCPE_STOP;
PC = PC & AMASK; /* clean variables */
LAC = LAC & LACMASK;
MQ = MQ & DMASK;
reason = 0;
last_IR = -1;
if (cpu_unit.flags & UNIT_NOAPI) /* no API? */
api_enb = api_req = api_act = 0;
api_int = api_eval (&int_pend); /* eval API */
api_usmd = 0; /* not API user cycle */
/* Main instruction fetch/decode loop */
while (reason == 0) { /* loop until halted */
int32 IR, MA, MB, esc, t, xct_count;
int32 link_init, fill;
if (sim_interval <= 0) { /* check clock queue */
if ((reason = sim_process_event ()))
break;
api_int = api_eval (&int_pend); /* eval API */
}
/* PDP-4 and PDP-7 traps and interrupts
PDP-4 no trap
PDP-7 trap: extend mode forced on, M[0] = PC, PC = 2
PDP-4, PDP-7 programmable interrupts only */
#if defined (PDP4) || defined (PDP7)
#if defined (PDP7)
if (trap_pending) { /* trap pending? */
PCQ_ENTRY; /* save old PC */
MB = Jms_word (1); /* save state */
ion = 0; /* interrupts off */
memm = 1; /* extend on */
emir_pending = trap_pending = 0; /* emir, trap off */
usmd = usmd_buf = 0; /* user mode off */
Write (0, MB, WR); /* save in 0 */
PC = 2; /* fetch next from 2 */
}
#endif
if (int_pend && ion && !ion_defer) { /* interrupt? */
PCQ_ENTRY; /* save old PC */
MB = Jms_word (usmd); /* save state */
ion = 0; /* interrupts off */
memm = 0; /* extend off */
emir_pending = rest_pending = 0; /* emir, restore off */
usmd = usmd_buf = 0; /* user mode off */
Write (0, MB, WR); /* physical write */
PC = 1; /* fetch next from 1 */
}
if (sim_brk_summ && sim_brk_test (PC, SWMASK ('E'))) { /* breakpoint? */
reason = STOP_IBKPT; /* stop simulation */
break;
}
#endif /* end PDP-4/PDP-7 */
/* PDP-9 and PDP-15 traps and interrupts
PDP-9 trap: extend mode ???, M[0/20] = PC, PC = 0/21
PDP-15 trap: bank mode unchanged, M[0/20] = PC, PC = 0/21
PDP-9, PDP-15 API and program interrupts */
#if defined (PDP9) || defined (PDP15)
if (trap_pending) { /* trap pending? */
PCQ_ENTRY; /* save old PC */
MB = Jms_word (1); /* save state */
if (ion) { /* int on? */
ion = 0; /* interrupts off */
MA = 0; /* treat like PI */
#if defined (PDP15)
ion_defer = 2; /* free instruction */
if (!(cpu_unit.flags & UNIT_NOAPI)) { /* API? */
api_act = api_act | API_ML3; /* set lev 3 active */
api_int = api_eval (&int_pend); /* re-evaluate */
}
#endif
}
else MA = 020; /* sortof like CAL */
emir_pending = rest_pending = trap_pending = 0; /* emir,rest,trap off */
usmd = usmd_buf = 0; /* user mode off */
Write (MA, MB, WR); /* physical write */
PC = MA + 1; /* fetch next */
}
if (api_int && !ion_defer) { /* API intr? */
int32 i, lvl = api_int - 1; /* get req level */
if (hst_lnt) /* record */
cpu_intr_hist (HIST_API, lvl);
api_act = api_act | (API_ML0 >> lvl); /* set level active */
if (lvl >= API_HLVL) { /* software req? */
MA = ACH_SWRE + lvl - API_HLVL; /* vec = 40:43 */
api_req = api_req & ~(API_ML0 >> lvl); /* remove request */
}
else {
MA = 0; /* assume fails */
for (i = 0; i < 32; i++) { /* loop hi to lo */
if ((int_hwre[lvl] >> i) & 1) { /* int req set? */
MA = api_vec[lvl][i]; /* get vector */
break; /* and stop */
}
}
}
if (MA == 0) { /* bad channel? */
reason = STOP_API; /* API error */
break;
}
api_int = api_eval (&int_pend); /* no API int */
api_usmd = usmd; /* API user mode cycle */
usmd = usmd_buf = 0; /* user mode off */
emir_pending = rest_pending = 0; /* emir, restore off */
xct_count = 0;
Read (MA, &IR, FE); /* fetch instruction */
goto xct_instr;
}
if (int_pend && ion && !ion_defer && /* int pending, enabled? */
!(api_enb && (api_act & API_MASKPI))) { /* API off or not masking PI? */
PCQ_ENTRY; /* save old PC */
if (hst_lnt) /* record */
cpu_intr_hist (HIST_PI, 0);
MB = Jms_word (usmd); /* save state */
ion = 0; /* interrupts off */
ion_defer = 2; /* free instruction */
#if defined (PDP9) /* PDP-9, */
memm = 0; /* extend off */
#else /* PDP-15 */
if (!(cpu_unit.flags & UNIT_NOAPI)) { /* API? */
api_act = api_act | API_ML3; /* set lev 3 active */
api_int = api_eval (&int_pend); /* re-evaluate */
}
#endif
emir_pending = rest_pending = 0; /* emir, restore off */
usmd = usmd_buf = 0; /* user mode off */
Write (0, MB, WR); /* physical write */
PC = 1; /* fetch next from 1 */
}
if (sim_brk_summ && sim_brk_test (PC, SWMASK ('E'))) { /* breakpoint? */
reason = STOP_IBKPT; /* stop simulation */
break;
}
if (!usmd_defer) /* no IOT? load usmd */
usmd = usmd_buf;
else usmd_defer = 0; /* cancel defer */
#endif /* PDP-9/PDP-15 */
/* Instruction fetch and address decode */
xct_count = 0; /* track nested XCT's */
MA = PC; /* fetch at PC */
if (Read (MA, &IR, FE)) /* fetch instruction */
continue;
PC = Incr_addr (PC); /* increment PC */
xct_instr: /* label for API, XCT */
if (hst_lnt) /* history? */
cpu_inst_hist (MA, IR);
if (ion_defer) /* count down defer */
ion_defer = ion_defer - 1;
if (sim_interval)
sim_interval = sim_interval - 1;
#if defined (PDP15) /* PDP15 */
if (memm) /* bank mode dir addr */
MA = (MA & B_EPCMASK) | (IR & B_DAMASK);
else MA = (MA & P_EPCMASK) | (IR & P_DAMASK); /* page mode dir addr */
#else /* others */
MA = (MA & B_EPCMASK) | (IR & B_DAMASK); /* bank mode only */
#endif
switch ((IR >> 13) & 037) { /* decode IR<0:4> */
/* LAC: opcode 20 */
case 011: /* LAC, indir */
if (Ia (MA, &MA, 0))
break;
case 010: /* LAC, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
LAC = (LAC & LINK) | MB;
break;
/* DAC: opcode 04 */
case 003: /* DAC, indir */
if (Ia (MA, &MA, 0))
break;
case 002: /* DAC, dir */
INDEX (IR, MA);
Write (MA, LAC & DMASK, WR);
break;
/* DZM: opcode 14 */
case 007: /* DZM, indir */
if (Ia (MA, &MA, 0))
break;
case 006: /* DZM, direct */
INDEX (IR, MA);
Write (MA, 0, WR);
break;
/* AND: opcode 50 */
case 025: /* AND, ind */
if (Ia (MA, &MA, 0))
break;
case 024: /* AND, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
LAC = LAC & (MB | LINK);
break;
/* XOR: opcode 24 */
case 013: /* XOR, ind */
if (Ia (MA, &MA, 0))
break;
case 012: /* XOR, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
LAC = LAC ^ MB;
break;
/* ADD: opcode 30 */
case 015: /* ADD, indir */
if (Ia (MA, &MA, 0))
break;
case 014: /* ADD, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
t = (LAC & DMASK) + MB;
if (t > DMASK) /* end around carry */
t = (t + 1) & DMASK;
if (((~LAC ^ MB) & (LAC ^ t)) & SIGN) /* overflow? */
LAC = LINK | t; /* set link */
else LAC = (LAC & LINK) | t;
break;
/* TAD: opcode 34 */
case 017: /* TAD, indir */
if (Ia (MA, &MA, 0))
break;
case 016: /* TAD, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
LAC = (LAC + MB) & LACMASK;
break;
/* ISZ: opcode 44 */
case 023: /* ISZ, indir */
if (Ia (MA, &MA, 0))
break;
case 022: /* ISZ, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
MB = (MB + 1) & DMASK;
if (Write (MA, MB, WR))
break;
if (MB == 0)
PC = Incr_addr (PC);
break;
/* SAD: opcode 54 */
case 027: /* SAD, indir */
if (Ia (MA, &MA, 0))
break;
case 026: /* SAD, dir */
INDEX (IR, MA);
if (Read (MA, &MB, RD))
break;
if ((LAC & DMASK) != MB)
PC = Incr_addr (PC);
break;
/* XCT: opcode 40 */
case 021: /* XCT, indir */
if (Ia (MA, &MA, 0))
break;
case 020: /* XCT, dir */
INDEX (IR, MA);
if ((api_usmd | usmd) && (xct_count != 0)) { /* chained and usmd? */
if (usmd) /* trap if usmd */
prvn = trap_pending = 1;
break; /* nop if api_usmd */
}
if (xct_count >= xct_max) { /* too many XCT's? */
reason = STOP_XCT;
break;
}
xct_count = xct_count + 1; /* count XCT's */
#if defined (PDP9)
ion_defer = 1; /* defer intr */
#endif
if (Read (MA, &IR, FE)) /* fetch inst, mm err? */
break;
goto xct_instr; /* go execute */
/* CAL: opcode 00 - api_usmd records whether usmd = 1 at start of API cycle
On the PDP-4 and PDP-7, CAL (I) is exactly the same as JMS (I) 20
On the PDP-9 and PDP-15, CAL clears user mode
On the PDP-9 and PDP-15 with API, CAL activates level 4
On the PDP-15, CAL goes to absolute 20, regardless of mode */
case 001: case 000: /* CAL */
t = usmd; /* save user mode */
#if defined (PDP15) /* PDP15 */
MA = 020; /* MA = abs 20 */
ion_defer = 1; /* "free instruction" */
#else /* others */
if (memm) /* if ext, abs 20 */
MA = 020;
else MA = (PC & B_EPCMASK) | 020; /* else bank-rel 20 */
#endif
#if defined (PDP9) || defined (PDP15)
usmd = usmd_buf = 0; /* clear user mode */
if ((cpu_unit.flags & UNIT_NOAPI) == 0) { /* if API, act lvl 4 */
#if defined (PDP15) /* PDP15: if 0-3 inactive */
if ((api_act & (API_ML0|API_ML1|API_ML2|API_ML3)) == 0)
#endif
api_act = api_act | API_ML4;
api_int = api_eval (&int_pend);
}
#endif
if (IR & I_IND) { /* indirect? */
if (Ia (MA, &MA, 0))
break;
}
PCQ_ENTRY;
MB = Jms_word (api_usmd | t); /* save state */
Write (MA, MB, WR);
PC = Incr_addr (MA);
break;
/* JMS: opcode 010 - api_usmd records whether usmd = 1 at start of API cycle */
case 005: /* JMS, indir */
if (Ia (MA, &MA, 0))
break;
case 004: /* JMS, dir */
INDEX (IR, MA);
PCQ_ENTRY;
#if defined (PDP15) /* PDP15 */
if (!usmd) /* "free instruction" */
ion_defer = 1;
#endif
MB = Jms_word (api_usmd | usmd); /* save state */
if (Write (MA, MB, WR))
break;
PC = Incr_addr (MA) & AMASK;
break;
/* JMP: opcode 60 */
case 031: /* JMP, indir */
if (Ia (MA, &MA, 1))
break;
INDEX (IR, MA);
PCQ_ENTRY; /* save old PC */
PC = MA & AMASK;
break;
/* JMP direct - check for idle */
case 030: /* JMP, dir */
INDEX (IR, MA);
PCQ_ENTRY; /* save old PC */
if (sim_idle_enab) { /* idling enabled? */
t_bool iof = (ion_inh != 0) || /* IOF if inhibited */
((ion == 0) && (api_enb == 0)); /* or PI and api off */
if (((MA ^ (PC - 2)) & AMASK) == 0) { /* 1) JMP *-1? */
if (iof && (last_IR == OP_KSF) && /* iof, prv KSF, */
!TST_INT (TTI)) /* no TTI flag? */
sim_idle (0, FALSE); /* we're idle */
}
else if (((MA ^ (PC - 1)) & AMASK) == 0) { /* 2) JMP *? */
if (iof) /* iof? inf loop */
reason = STOP_LOOP;
else sim_idle (0, FALSE); /* ion? idle */
}
} /* end idle */
PC = MA & AMASK;
break;
/* OPR: opcode 74 */
case 037: /* OPR, indir */
LAC = (LAC & LINK) | IR; /* LAW */
break;