This source file includes following definitions.
- get4
- get6
- get9
- put4
- put6
- put9
- getCrAR
- getMFReg18
- getMFReg36
- EISWriteCache
- EISReadCache
- EISWriteIdx
- EISReadIdx
- EISRead
- EISReadPage
- EISWritePage
- EISget469
- EISput469
- EISget49
- EISgetBitRWN
- setupOperandDescriptorCache
- setupOperandDescriptor
- setupEISoperands
- parseAlphanumericOperandDescriptor
- parseArgOperandDescriptor
- parseNumericOperandDescriptor
- parseBitstringOperandDescriptor
- cleanupOperandDescriptor
- tandd_eis_interruptible
- tandd_eis_sample
- a4bd
- s4bd
- axbd
- abd
- awd
- sbd
- swd
- s9bd
- asxbd
- cmpc
- scd
- scdr
- scm
- scmr
- xlate
- tct
- tctr
- isGBCDOvp
- mlr
- mrl
- EISloadInputBufferNumeric
- EISloadInputBufferAlphnumeric
- EISwriteOutputBufferToMemory
- writeToOutputBuffer
- mopCHT
- mopENF
- mopIGN
- mopINSA
- mopINSB
- mopINSM
- mopINSN
- mopINSP
- mopLTE
- mopMFLC
- mopMFLS
- mopMORS
- mopMVC
- mopMSES
- mopMVZA
- mopMVZB
- mopSES
- EISgetMop
- mopExecutor
- mve
- mvne
- mvt
- cmpn
- EISwrite4
- EISwrite9
- EISwrite49
- mvn
- csl
- getBitOffsets
- EISgetBitRWNR
- csr
- sztl
- sztr
- EISgetBit
- cmpb
- sign9n
- signExt9
- load9x
- btd
- dtb
- eisWindow
- eisWindowOperands
- eisWindowLow
- eisFloatAlignTrunc
- eisFloatWindowOperands
- ad2d
- ad3d
- sb2d
- sb3d
- mp2d
- mp3d
- dv2d
- dv3d
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 #if defined(EIS_PTR)
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 #endif
52
53 #include <ctype.h>
54
55 #include "dps8.h"
56 #include "dps8_sys.h"
57 #include "dps8_iom.h"
58 #include "dps8_cable.h"
59 #include "dps8_cpu.h"
60 #include "dps8_faults.h"
61 #include "dps8_scu.h"
62 #include "dps8_iefp.h"
63 #include "dps8_decimal.h"
64 #include "dps8_ins.h"
65 #include "dps8_eis.h"
66 #include "dps8_utils.h"
67
68 #define DBG_CTR cpu.cycleCnt
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 #define ABD_BITS
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 static word4 get4 (word36 w, int pos)
131 {
132 switch (pos)
133 {
134 case 0:
135 return getbits36_4 (w, 1);
136
137 case 1:
138 return getbits36_4 (w, 5);
139
140 case 2:
141 return getbits36_4 (w, 10);
142
143 case 3:
144 return getbits36_4 (w, 14);
145
146 case 4:
147 return getbits36_4 (w, 19);
148
149 case 5:
150 return getbits36_4 (w, 23);
151
152 case 6:
153 return getbits36_4 (w, 28);
154
155 case 7:
156 return getbits36_4 (w, 32);
157
158 }
159 sim_printf ("get4(): How'd we get here?\r\n");
160 return 0;
161 }
162
163
164 static word4 get6 (word36 w, int pos)
165 {
166 switch (pos)
167 {
168 case 0:
169 return getbits36_6 (w, 0);
170
171 case 1:
172 return getbits36_6 (w, 6);
173
174 case 2:
175 return getbits36_6 (w, 12);
176
177 case 3:
178 return getbits36_6 (w, 18);
179
180 case 4:
181 return getbits36_6 (w, 24);
182
183 case 5:
184 return getbits36_6 (w, 30);
185
186 }
187 sim_printf ("get6(): How'd we get here?\r\n");
188 return 0;
189 }
190
191
192 static word9 get9(word36 w, int pos)
193 {
194 switch (pos)
195 {
196 case 0:
197 return getbits36_9 (w, 0);
198
199 case 1:
200 return getbits36_9 (w, 9);
201
202 case 2:
203 return getbits36_9 (w, 18);
204
205 case 3:
206 return getbits36_9 (w, 27);
207
208 }
209 sim_printf ("get9(): How'd we get here?\r\n");
210 return 0;
211 }
212
213
214 static word36 put4 (word36 w, int pos, word4 c)
215 {
216
217
218
219
220
221 c &= MASK4;
222 switch (pos)
223 {
224 case 0:
225
226 return setbits36_5 (w, 0, c);
227
228 case 1:
229 return setbits36_4 (w, 5, c);
230
231 case 2:
232
233 return setbits36_5 (w, 9, c);
234
235 case 3:
236 return setbits36_4 (w, 14, c);
237
238 case 4:
239
240 return setbits36_5 (w, 18, c);
241
242 case 5:
243 return setbits36_4 (w, 23, c);
244
245 case 6:
246
247 return setbits36_5 (w, 27, c);
248
249 case 7:
250 return setbits36_4 (w, 32, c);
251 }
252 sim_printf ("put4(): How'd we get here?\r\n");
253 return 0;
254 }
255
256
257 static word36 put6 (word36 w, int pos, word6 c)
258 {
259 switch (pos)
260 {
261 case 0:
262
263 return setbits36_6 (w, 0, c);
264
265 case 1:
266
267 return setbits36_6 (w, 6, c);
268
269 case 2:
270
271 return setbits36_6 (w, 12, c);
272
273 case 3:
274
275 return setbits36_6 (w, 18, c);
276
277 case 4:
278
279 return setbits36_6 (w, 24, c);
280
281 case 5:
282
283 return setbits36_6 (w, 30, c);
284
285 }
286 sim_printf ("put6(): How'd we get here?\r\n");
287 return 0;
288 }
289
290
291 static word36 put9 (word36 w, int pos, word9 c)
292 {
293 switch (pos)
294 {
295 case 0:
296
297 return setbits36_9 (w, 0, c);
298
299 case 1:
300
301 return setbits36_9 (w, 9, c);
302
303 case 2:
304
305 return setbits36_9 (w, 18, c);
306
307 case 3:
308
309 return setbits36_9 (w, 27, c);
310
311 }
312 sim_printf ("put9(): How'd we get here?\r\n");
313 return 0;
314 }
315
316
317
318
319
320
321 static word36 getCrAR (cpu_state_t * cpup, word4 reg)
322 {
323 if (reg == 0)
324 return 0;
325
326 if (reg & 010)
327 return cpu.rX [X (reg)];
328
329 switch (reg)
330 {
331 case TD_N:
332 return 0;
333
334 case TD_AU:
335 #if defined(TESTING)
336 HDBGRegAR ("au");
337 #endif
338 return GETHI (cpu.rA);
339
340 case TD_QU:
341 #if defined(TESTING)
342 HDBGRegAR ("qu");
343 #endif
344 return GETHI (cpu.rQ);
345
346 case TD_IC:
347 return cpu.PPR.IC;
348
349 case TD_AL:
350 #if defined(TESTING)
351 HDBGRegAR ("al");
352 #endif
353 return cpu.rA;
354
355 case TD_QL:
356 #if defined(TESTING)
357 HDBGRegAR ("ql");
358 #endif
359 return cpu.rQ;
360 }
361 return 0;
362 }
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 static word18 getMFReg18 (cpu_state_t * cpup, uint n, bool allowDU, bool allowNIC, fault_ipr_subtype_ *mod_fault)
385 {
386 switch (n)
387 {
388 case 0:
389 if (! allowNIC)
390 {
391
392 *mod_fault |= FR_ILL_MOD;
393
394 }
395 return 0;
396
397 case 1:
398 #if defined(TESTING)
399 HDBGRegAR ("au");
400 #endif
401 return GETHI (cpu.rA);
402
403 case 2:
404 #if defined(TESTING)
405 HDBGRegAR ("qu");
406 #endif
407 return GETHI (cpu.rQ);
408
409 case 3:
410
411
412
413 if (! allowDU)
414 {
415
416
417
418
419
420
421
422
423
424
425
426
427
428 *mod_fault |= FR_ILL_MOD;
429
430 }
431 return 0;
432
433 case 4:
434
435
436
437
438 if (! allowNIC)
439 {
440
441 *mod_fault |= FR_ILL_MOD;
442
443 }
444 return cpu.PPR.IC;
445
446 case 5:
447 #if defined(TESTING)
448 HDBGRegAR ("al/a");
449 #endif
450 return GETLO (cpu.rA);
451
452 case 6:
453 #if defined(TESTING)
454 HDBGRegAR ("ql/a");
455 #endif
456 return GETLO (cpu.rQ);
457
458 case 7:
459 *mod_fault |= FR_ILL_MOD;
460
461 return 0;
462
463 case 8:
464 case 9:
465 case 10:
466 case 11:
467 case 12:
468 case 13:
469 case 14:
470 case 15:
471 return cpu.rX [n - 8];
472 }
473 sim_printf ("getMFReg18(cpup, ): How'd we get here? n=%d\r\n", n);
474 return 0;
475 }
476
477 static word36 getMFReg36 (cpu_state_t * cpup, uint n, bool allowDU, bool allowNIC, fault_ipr_subtype_ *mod_fault)
478 {
479 switch (n)
480 {
481 case 0:
482 if (! allowNIC)
483 {
484
485 *mod_fault |= FR_ILL_MOD;
486
487 }
488 return 0;
489 case 1:
490 #if defined(TESTING)
491 HDBGRegAR ("au");
492 #endif
493 return GETHI (cpu.rA);
494
495 case 2:
496 #if defined(TESTING)
497 HDBGRegAR ("qu");
498 #endif
499 return GETHI (cpu.rQ);
500
501 case 3:
502
503 if (! allowDU)
504 *mod_fault |= FR_ILL_MOD;
505
506 return 0;
507
508 case 4:
509
510
511
512
513 if (! allowNIC)
514 {
515
516 *mod_fault |= FR_ILL_MOD;
517
518 }
519 return cpu.PPR.IC;
520
521 case 5:
522 #if defined(TESTING)
523 HDBGRegAR ("al/a");
524 #endif
525 return cpu.rA;
526
527 case 6:
528 #if defined(TESTING)
529 HDBGRegAR ("ql/a");
530 #endif
531 return cpu.rQ;
532
533 case 7:
534 *mod_fault |= FR_ILL_MOD;
535
536 return 0;
537
538 case 8:
539 case 9:
540 case 10:
541 case 11:
542 case 12:
543 case 13:
544 case 14:
545 case 15:
546 return cpu.rX [n - 8];
547 }
548 sim_printf ("getMFReg36(cpup, ): How'd we get here? n=%d\r\n", n);
549 return 0;
550 }
551
552 #define EISADDR_IDX(p) ((p) - cpu.currentEISinstruction.addr)
553
554 static void EISWriteCache (cpu_state_t * cpup, EISaddr * p)
555 {
556 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISWriteCache addr %06o\r\n", p->cachedAddr);
557 word3 saveTRR = cpu.TPR.TRR;
558
559 if (p -> cacheValid && p -> cacheDirty)
560 {
561 if (p -> mat == viaPR)
562 {
563 cpu.TPR.TRR = p -> RNR;
564 cpu.TPR.TSR = p -> SNR;
565 cpu.cu.XSF = 0;
566 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
567 {
568 for (uint i = 0; i < 8; i ++)
569 if (p->wordDirty[i])
570 {
571 sim_debug (DBG_TRACEEXT, & cpu_dev,
572 "%s: writeCache (PR) %012"PRIo64"@%o:%06o\r\n",
573 __func__, p -> cachedParagraph [i], p -> SNR, p -> cachedAddr + i);
574 }
575 }
576 { long eisaddr_idx = EISADDR_IDX (p);
577 sim_debug (DBG_TRACEEXT, & cpu_dev, "EIS %ld Write8 TRR %o TSR %05o\r\n", eisaddr_idx, cpu.TPR.TRR, cpu.TPR.TSR); }
578 for (uint i = 0; i < 8; i ++)
579 if (p->wordDirty[i])
580 {
581 Write1 (cpup, p->cachedAddr+i, p -> cachedParagraph[i], true);
582 p->wordDirty[i] = false;
583 }
584 }
585 else
586 {
587
588
589 cpu.TPR.TRR = cpu.PPR.PRR;
590 cpu.TPR.TSR = cpu.PPR.PSR;
591 cpu.cu.XSF = 0;
592
593
594 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
595 {
596 for (uint i = 0; i < 8; i ++)
597 if (p->wordDirty[i])
598 {
599 sim_debug (DBG_TRACEEXT, & cpu_dev,
600 "%s: writeCache %012"PRIo64"@%o:%06o\r\n",
601 __func__, p -> cachedParagraph [i], cpu.TPR.TSR, p -> cachedAddr + i);
602 }
603 }
604 { long eisaddr_idx = EISADDR_IDX (p);
605 sim_debug (DBG_TRACEEXT, & cpu_dev, "EIS %ld Write8 NO PR TRR %o TSR %05o\r\n", eisaddr_idx, cpu.TPR.TRR, cpu.TPR.TSR); }
606 for (uint i = 0; i < 8; i ++)
607 if (p->wordDirty[i])
608 {
609 Write1 (cpup, p->cachedAddr+i, p -> cachedParagraph[i], false);
610 p->wordDirty[i] = false;
611 }
612 }
613 }
614 p -> cacheDirty = false;
615 cpu.TPR.TRR = saveTRR;
616 }
617
618 static void EISReadCache (cpu_state_t * cpup, EISaddr * p, word18 address)
619 {
620 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISReadCache addr %06o\r\n", address);
621 word3 saveTRR = cpu.TPR.TRR;
622
623 address &= AMASK;
624
625 word18 paragraphAddress = address & paragraphMask;
626
627
628 if (p -> cacheValid && p -> cachedAddr == paragraphAddress)
629 {
630 return;
631 }
632
633 if (p -> cacheValid && p -> cacheDirty && p -> cachedAddr != paragraphAddress)
634 {
635 EISWriteCache (cpup, p);
636 }
637
638 if (p -> mat == viaPR)
639 {
640 cpu.TPR.TRR = p -> RNR;
641 cpu.TPR.TSR = p -> SNR;
642 cpu.cu.XSF = 0;
643 { long eisaddr_idx = EISADDR_IDX (p);
644 sim_debug (DBG_TRACEEXT, & cpu_dev, "EIS %ld Read8 TRR %o TSR %05o\r\n", eisaddr_idx, cpu.TPR.TRR, cpu.TPR.TSR); }
645 Read8 (cpup, paragraphAddress, p -> cachedParagraph, true);
646
647 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
648 {
649 for (uint i = 0; i < 8; i ++)
650 sim_debug (DBG_TRACEEXT, & cpu_dev,
651 "%s: readCache (PR) %012"PRIo64"@%o:%06o\r\n",
652 __func__, p -> cachedParagraph [i], p -> SNR, paragraphAddress + i);
653 }
654 }
655 else
656 {
657
658
659 cpu.TPR.TRR = cpu.PPR.PRR;
660 cpu.TPR.TSR = cpu.PPR.PSR;
661 cpu.cu.XSF = 0;
662
663
664 { long eisaddr_idx = EISADDR_IDX (p);
665 sim_debug (DBG_TRACEEXT, & cpu_dev, "EIS %ld Read8 NO PR TRR %o TSR %05o\r\n", eisaddr_idx, cpu.TPR.TRR, cpu.TPR.TSR); }
666 Read8 (cpup, paragraphAddress, p -> cachedParagraph, false);
667 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
668 {
669 for (uint i = 0; i < 8; i ++)
670 sim_debug (DBG_TRACEEXT, & cpu_dev,
671 "%s: readCache %012"PRIo64"@%o:%06o\r\n",
672 __func__, p -> cachedParagraph [i], cpu.TPR.TSR, paragraphAddress + i);
673 }
674 }
675 p -> cacheValid = true;
676 p -> cacheDirty = false;
677 for (uint i = 0; i < 8; i ++)
678 p->wordDirty[i] = false;
679 p -> cachedAddr = paragraphAddress;
680 cpu.TPR.TRR = saveTRR;
681 }
682
683 static void EISWriteIdx (cpu_state_t * cpup, EISaddr *p, uint n, word36 data, bool flush)
684 {
685 #if defined(EIS_PTR)
686 long eisaddr_idx = EISADDR_IDX (p);
687 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
688 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISWriteIdx addr %06o n %u\r\n", cpu.du.Dk_PTR_W[eisaddr_idx], n);
689 word18 addressN = (cpu.du.Dk_PTR_W[eisaddr_idx] + n) & AMASK;
690 #else
691 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISWriteIdx addr %06o n %u\r\n", p->address, n);
692 word18 addressN = p -> address + n;
693 #endif
694 addressN &= AMASK;
695
696 word18 paragraphAddress = addressN & paragraphMask;
697 word3 paragraphOffset = addressN & paragraphOffsetMask;
698
699 if (p -> cacheValid && p -> cacheDirty && p -> cachedAddr != paragraphAddress)
700 {
701 EISWriteCache (cpup, p);
702 }
703 if ((! p -> cacheValid) || p -> cachedAddr != paragraphAddress)
704 {
705 EISReadCache (cpup, p, paragraphAddress);
706 }
707 p -> cacheDirty = true;
708 p -> wordDirty[paragraphOffset] = true;
709 p -> cachedParagraph [paragraphOffset] = data;
710 p -> cachedAddr = paragraphAddress;
711
712
713
714
715 if (flush)
716 {
717 EISWriteCache (cpup, p);
718 }
719 }
720
721 static word36 EISReadIdx (cpu_state_t * cpup, EISaddr * p, uint n)
722 {
723 #if defined(EIS_PTR)
724 long eisaddr_idx = EISADDR_IDX (p);
725 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
726
727 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISReadIdx addr %06o n %u\r\n", cpu.du.Dk_PTR_W[eisaddr_idx], n);
728 word18 addressN = (cpu.du.Dk_PTR_W[eisaddr_idx] + n) & AMASK;
729 #else
730 long eisaddr_idx = EISADDR_IDX (p);
731 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISReadIdx %ld addr %06o n %u\r\n", eisaddr_idx, p->address, n);
732 word18 addressN = p -> address + n;
733 #endif
734 addressN &= AMASK;
735
736 word18 paragraphAddress = addressN & paragraphMask;
737 word3 paragraphOffset = addressN & paragraphOffsetMask;
738
739 if (p -> cacheValid && p -> cachedAddr == paragraphAddress)
740 {
741 return p -> cachedParagraph [paragraphOffset];
742 }
743 if (p -> cacheValid && p -> cacheDirty)
744 {
745 EISWriteCache (cpup, p);
746 }
747 EISReadCache (cpup, p, paragraphAddress);
748 return p -> cachedParagraph [paragraphOffset];
749 }
750
751 static word36 EISRead (cpu_state_t * cpup, EISaddr * p)
752 {
753 #if defined(EIS_PTR)
754 long eisaddr_idx = EISADDR_IDX (p);
755 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
756
757 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISRead addr %06o\r\n", cpu.du.Dk_PTR_W[eisaddr_idx]);
758 #else
759 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISRead addr %06o\r\n", p->address);
760 #endif
761 return EISReadIdx (cpup, p, 0);
762 }
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781 static void EISReadPage (cpu_state_t * cpup, EISaddr * p, uint n, word36 * data)
782 {
783 #if defined(EIS_PTR)
784 long eisaddr_idx = EISADDR_IDX (p);
785 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
786 word18 addressN = (cpu.du.Dk_PTR_W[eisaddr_idx] + n) & AMASK;
787 #else
788 word18 addressN = p -> address + n;
789 #endif
790 addressN &= AMASK;
791
792 sim_debug (DBG_TRACEEXT, & cpu_dev, "%s addr %06o\r\n", __func__, addressN);
793 if ((addressN & PGMK) != 0)
794 {
795 sim_warn ("EISReadPage not aligned %06o\r\n", addressN);
796 addressN &= (word18) ~PGMK;
797 }
798
799 word3 saveTRR = cpu.TPR.TRR;
800
801 if (p -> mat == viaPR)
802 {
803 cpu.TPR.TRR = p -> RNR;
804 cpu.TPR.TSR = p -> SNR;
805 cpu.cu.XSF = 0;
806 ReadPage (cpup, addressN, data, true);
807
808 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
809 {
810 for (uint i = 0; i < PGSZ; i ++)
811 #if defined(EIS_PTR)
812 sim_debug (DBG_TRACEEXT, & cpu_dev,
813 "%s: (PR) %012"PRIo64"@%o:%06o\r\n",
814 __func__, data [i], cpu.TPR.TSR, addressN + i);
815 #else
816 sim_debug (DBG_TRACEEXT, & cpu_dev,
817 "%s: (PR) %012"PRIo64"@%o:%06o\r\n",
818 __func__, data [i], p -> SNR, addressN + i);
819 #endif
820 }
821 }
822 else
823 {
824
825
826 cpu.TPR.TRR = cpu.PPR.PRR;
827 cpu.TPR.TSR = cpu.PPR.PSR;
828 cpu.cu.XSF = 0;
829
830
831 ReadPage (cpup, addressN, data, false);
832 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
833 {
834 for (uint i = 0; i < PGSZ; i ++)
835 sim_debug (DBG_TRACEEXT, & cpu_dev,
836 "%s: %012"PRIo64"@%o:%06o\r\n",
837 __func__, data [i], cpu.TPR.TSR, addressN + i);
838 }
839 }
840 cpu.TPR.TRR = saveTRR;
841 }
842
843 static void EISWritePage (cpu_state_t * cpup, EISaddr * p, uint n, word36 * data)
844 {
845 #if defined(EIS_PTR)
846 long eisaddr_idx = EISADDR_IDX (p);
847 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
848 word18 addressN = (cpu.du.Dk_PTR_W[eisaddr_idx] + n) & AMASK;
849 #else
850 word18 addressN = p -> address + n;
851 #endif
852 addressN &= AMASK;
853
854 sim_debug (DBG_TRACEEXT, & cpu_dev, "%s addr %06o\r\n", __func__, addressN);
855 if ((addressN & PGMK) != 0)
856 {
857 sim_warn ("EISWritePage not aligned %06o\r\n", addressN);
858 addressN &= (uint) ~PGMK;
859 }
860
861 word3 saveTRR = cpu.TPR.TRR;
862
863 if (p -> mat == viaPR)
864 {
865 cpu.TPR.TRR = p -> RNR;
866 cpu.TPR.TSR = p -> SNR;
867 cpu.cu.XSF = 0;
868 WritePage (cpup, addressN, data, true);
869
870 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
871 {
872 for (uint i = 0; i < PGSZ; i ++)
873 #if defined(EIS_PTR)
874 sim_debug (DBG_TRACEEXT, & cpu_dev,
875 "%s: (PR) %012"PRIo64"@%o:%06o\r\n",
876 __func__, data [i], cpu.TPR.TSR, addressN + i);
877 #else
878 sim_debug (DBG_TRACEEXT, & cpu_dev,
879 "%s: (PR) %012"PRIo64"@%o:%06o\r\n",
880 __func__, data [i], p -> SNR, addressN + i);
881 #endif
882 }
883 }
884 else
885 {
886
887
888 cpu.TPR.TRR = cpu.PPR.PRR;
889 cpu.TPR.TSR = cpu.PPR.PSR;
890 cpu.cu.XSF = 0;
891
892
893 WritePage (cpup, addressN, data, false);
894 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
895 {
896 for (uint i = 0; i < PGSZ; i ++)
897 sim_debug (DBG_TRACEEXT, & cpu_dev,
898 "%s: %012"PRIo64"@%o:%06o\r\n",
899 __func__, data [i], cpu.TPR.TSR, addressN + i);
900 }
901 }
902 cpu.TPR.TRR = saveTRR;
903 }
904
905 static word9 EISget469 (cpu_state_t * cpup, int k, uint i)
906 {
907 EISstruct * e = & cpu.currentEISinstruction;
908
909 uint nPos = 4;
910 #if defined(EIS_PTR3)
911 switch (cpu.du.TAk[k-1])
912 #else
913 switch (e -> TA [k - 1])
914 #endif
915 {
916 case CTA4:
917 nPos = 8;
918 break;
919
920 case CTA6:
921 nPos = 6;
922 break;
923 }
924
925 word18 address = e -> WN [k - 1];
926 uint nChars = i + e -> CN [k - 1];
927
928 address += nChars / nPos;
929 uint residue = nChars % nPos;
930
931 PNL (cpu.du.Dk_PTR_W[k-1] = address);
932 #if defined(EIS_PTR)
933 cpu.du.Dk_PTR_W[k-1] = address;
934 #else
935 e -> addr [k - 1].address = address;
936 #endif
937 word36 data = EISRead (cpup, & e -> addr [k - 1]);
938
939 word9 c = 0;
940 #if defined(EIS_PTR3)
941 switch (cpu.du.TAk[k-1])
942 #else
943 switch (e -> TA [k - 1])
944 #endif
945 {
946 case CTA4:
947 c = (word9) get4 (data, (int) residue);
948 break;
949
950 case CTA6:
951 c = (word9) get6 (data, (int) residue);
952 break;
953
954 case CTA9:
955 c = get9 (data, (int) residue);
956 break;
957 }
958 #if defined(EIS_PTR3)
959 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISGet469 : k: %u TAk %u coffset %u c %o\r\n", k, cpu.du.TAk[k - 1], residue, c);
960 #else
961 sim_debug (DBG_TRACEEXT, & cpu_dev, "EISGet469 : k: %u TAk %u coffset %u c %o\r\n", k, e -> TA [k - 1], residue, c);
962 #endif
963
964 return c;
965 }
966
967 static void EISput469 (cpu_state_t * cpup, int k, uint i, word9 c469)
968 {
969 EISstruct * e = & cpu.currentEISinstruction;
970
971 uint nPos = 4;
972 #if defined(EIS_PTR3)
973 switch (cpu.du.TAk[k-1])
974 #else
975 switch (e -> TA [k - 1])
976 #endif
977 {
978 case CTA4:
979 nPos = 8;
980 break;
981
982 case CTA6:
983 nPos = 6;
984 break;
985 }
986
987 word18 address = e -> WN [k - 1];
988 uint nChars = i + e -> CN [k - 1];
989
990 address += nChars / nPos;
991 uint residue = nChars % nPos;
992
993 PNL (cpu.du.Dk_PTR_W[k-1] = address);
994 #if defined(EIS_PTR)
995 cpu.du.Dk_PTR_W[k-1] = address;
996 #else
997 e -> addr [k - 1].address = address;
998 #endif
999 word36 data = EISRead (cpup, & e -> addr [k - 1]);
1000
1001 word36 w = 0;
1002 #if defined(EIS_PTR3)
1003 switch (cpu.du.TAk[k-1])
1004 #else
1005 switch (e -> TA [k - 1])
1006 #endif
1007 {
1008 case CTA4:
1009 w = put4 (data, (int) residue, (word4) c469);
1010 break;
1011
1012 case CTA6:
1013 w = put6 (data, (int) residue, (word6) c469);
1014 break;
1015
1016 case CTA9:
1017 w = put9 (data, (int) residue, c469);
1018 break;
1019 }
1020 EISWriteIdx (cpup, & e -> addr [k - 1], 0, w, true);
1021 }
1022
1023
1024
1025
1026
1027
1028 static word9 EISget49 (cpu_state_t * cpup, EISaddr * p, int * pos, int tn)
1029 {
1030 int maxPos = tn == CTN4 ? 7 : 3;
1031
1032 if (* pos > maxPos)
1033 {
1034 * pos = 0;
1035
1036 #if defined(EIS_PTR)
1037 long eisaddr_idx = EISADDR_IDX (p);
1038 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
1039 cpu.du.Dk_PTR_W[eisaddr_idx] = (cpu.du.Dk_PTR_W[eisaddr_idx] + 1) & AMASK;
1040 #else
1041 p -> address = (p -> address + 1) & AMASK;
1042 #endif
1043 p -> data = EISRead (cpup, p);
1044 }
1045 else
1046 {
1047 p -> data = EISRead (cpup, p);
1048 }
1049
1050 word9 c = 0;
1051 switch (tn)
1052 {
1053 case CTN4:
1054 c = get4 (p -> data, * pos);
1055 break;
1056 case CTN9:
1057 c = get9 (p -> data, * pos);
1058 break;
1059 }
1060
1061 (* pos) ++;
1062 return c;
1063 }
1064
1065 static bool EISgetBitRWN (cpu_state_t * cpup, EISaddr * p, bool flush)
1066 {
1067 #if defined(EIS_PTR)
1068 long eisaddr_idx = EISADDR_IDX (p);
1069 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
1070
1071 #endif
1072 int baseCharPosn = (p -> cPos * 9);
1073 int baseBitPosn = baseCharPosn + p -> bPos;
1074 baseBitPosn += (int) cpu.du.CHTALLY;
1075
1076 int bitPosn = baseBitPosn % 36;
1077 int woff = baseBitPosn / 36;
1078
1079 #if defined(EIS_PTR)
1080 word18 saveAddr = cpu.du.Dk_PTR_W[eisaddr_idx];
1081 cpu.du.Dk_PTR_W[eisaddr_idx] += (uint) woff;
1082 cpu.du.Dk_PTR_W[eisaddr_idx] &= AMASK;
1083 #else
1084 word18 saveAddr = p -> address;
1085 p -> address += (uint) woff;
1086 #endif
1087
1088 p -> data = EISRead (cpup, p);
1089
1090 if (p -> mode == eRWreadBit)
1091 {
1092 p -> bit = getbits36_1 (p -> data, (uint) bitPosn);
1093 }
1094 else if (p -> mode == eRWwriteBit)
1095 {
1096 p -> data = setbits36_1 (p -> data, (uint) bitPosn, p -> bit);
1097
1098 EISWriteIdx (cpup, p, 0, p -> data, flush);
1099 }
1100
1101 p->last_bit_posn = bitPosn;
1102
1103 #if defined(EIS_PTR)
1104 cpu.du.Dk_PTR_W[eisaddr_idx] = saveAddr;
1105 #else
1106 p -> address = saveAddr;
1107 #endif
1108 return p -> bit;
1109 }
1110
1111 static void setupOperandDescriptorCache (cpu_state_t * cpup, int k)
1112 {
1113 EISstruct * e = & cpu.currentEISinstruction;
1114 e -> addr [k - 1]. cacheValid = false;
1115 }
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151 static void setupOperandDescriptor (cpu_state_t * cpup, int k, fault_ipr_subtype_ *mod_fault)
1152 {
1153 EISstruct * e = & cpu.currentEISinstruction;
1154 switch (k)
1155 {
1156 case 1:
1157 PNL (L68_ (DU_CYCLE_FA_I1;))
1158 PNL (L68_ (DU_CYCLE_GDLDA;))
1159 e -> MF1 = getbits36_7 (cpu.cu.IWB, 29);
1160 break;
1161 case 2:
1162 PNL (L68_ (DU_CYCLE_FA_I2;))
1163 PNL (L68_ (DU_CYCLE_GDLDB;))
1164 e -> MF2 = getbits36_7 (cpu.cu.IWB, 11);
1165 break;
1166 case 3:
1167 PNL (L68_ (DU_CYCLE_FA_I3;))
1168 PNL (L68_ (DU_CYCLE_GDLDC;))
1169 e -> MF3 = getbits36_7 (cpu.cu.IWB, 2);
1170 break;
1171 }
1172
1173 word18 MFk = e -> MF [k - 1];
1174
1175 if (MFk & MFkID)
1176 {
1177 PNL (L68_ (if (k == 1)
1178 DU_CYCLE_LDWRT1;
1179 if (k == 2)
1180 DU_CYCLE_LDWRT2;))
1181
1182 word36 opDesc = e -> op [k - 1];
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216 if (opDesc & 060)
1217 {
1218 *mod_fault |= FR_ILL_MOD;
1219
1220 }
1221
1222
1223 word18 address = GETHI (opDesc);
1224 PNL (cpu.du.Dk_PTR_W[k-1] = address);
1225 #if defined(EIS_PTR)
1226 cpu.du.Dk_PTR_W[k-1] = address;
1227 #else
1228 e -> addr [k - 1].address = address;
1229 #endif
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250 bool a = opDesc & (1 << 6);
1251 if (a)
1252 {
1253
1254
1255 word3 n = (word3) getbits18 (address, 0, 3);
1256 CPTUR (cptUsePRn + n);
1257 word15 offset = address & MASK15;
1258 address = (cpu.AR [n].WORDNO + SIGNEXT15_18 (offset)) & AMASK;
1259
1260 PNL (cpu.du.Dk_PTR_W[k-1] = address);
1261 #if defined(EIS_PTR)
1262 cpu.du.Dk_PTR_W[k-1] = address;
1263 #else
1264 e -> addr [k - 1].address = address;
1265 #endif
1266 cpu.cu.TSN_PRNO[k-1] = n;
1267 cpu.cu.TSN_VALID[k-1] = 1;
1268 e -> addr [k - 1].SNR = cpu.PR [n].SNR;
1269 e -> addr [k - 1].RNR = max3 (cpu.PR [n].RNR,
1270 cpu.TPR.TRR,
1271 cpu.PPR.PRR);
1272
1273 e -> addr [k - 1].mat = viaPR;
1274 sim_debug (DBG_TRACEEXT, & cpu_dev, "AR n %u k %u\r\n", n, k - 1);
1275 }
1276 else
1277 {
1278 e->addr [k - 1].mat = OperandRead;
1279 sim_debug (DBG_TRACEEXT, & cpu_dev, "No ARb %u\r\n", k - 1);
1280 }
1281
1282
1283
1284
1285
1286
1287 uint reg = opDesc & 017;
1288
1289 address += getMFReg18 (cpup, reg, false, true, mod_fault);
1290 address &= AMASK;
1291
1292 PNL (cpu.du.Dk_PTR_W[k-1] = address);
1293
1294 #if defined(EIS_PTR)
1295 cpu.du.Dk_PTR_W[k-1] = address;
1296 #else
1297 e -> addr [k - 1].address = address;
1298 #endif
1299
1300
1301 e -> op [k - 1] = EISRead (cpup, & e -> addr [k - 1]);
1302 }
1303 else
1304 {
1305 e->addr [k - 1].mat = OperandRead;
1306 sim_debug (DBG_TRACEEXT, & cpu_dev, "No ARa %u\r\n", k - 1);
1307 }
1308 setupOperandDescriptorCache (cpup, k);
1309 }
1310
1311 void setupEISoperands (cpu_state_t * cpup)
1312 {
1313 PNL (cpu.du.POP = 0);
1314 PNL (cpu.du.POL = 0);
1315
1316 #if defined(EIS_SETUP)
1317 for (int i = 0; i < 3; i ++)
1318 {
1319 if (i < cpu.currentInstruction.info -> ndes)
1320 setupOperandDescriptor (cpup, i + 1);
1321 else
1322 setupOperandDescriptorCache (cpup, i + 1);
1323 }
1324 #endif
1325 }
1326
1327 static void parseAlphanumericOperandDescriptor (cpu_state_t * cpup, uint k, uint useTA, bool allowDU, fault_ipr_subtype_ *mod_fault)
1328 {
1329 EISstruct * e = & cpu.currentEISinstruction;
1330 word18 MFk = e -> MF [k - 1];
1331
1332 PNL (L68_ (if (k == 1)
1333 DU_CYCLE_ANLD1;
1334 else if (k == 2)
1335 DU_CYCLE_ANLD2;
1336 else if (k == 3)
1337 DU_CYCLE_ANSTR;))
1338
1339 PNL (cpu.du.POP = 1);
1340
1341 word36 opDesc = e -> op [k - 1];
1342
1343 word8 ARn_CHAR = 0;
1344 word6 ARn_BITNO = 0;
1345
1346 word18 address = GETHI (opDesc);
1347
1348 #if defined(EIS_PTR3)
1349 if (useTA != k)
1350 cpu.du.TAk[k-1] = cpu.du.TAk[useTA-1];
1351 else
1352 cpu.du.TAk[k-1] = getbits36_2 (opDesc, 21);
1353 #else
1354 if (useTA != k)
1355 e -> TA [k - 1] = e -> TA [useTA - 1];
1356 else
1357 e -> TA [k - 1] = getbits36_2 (opDesc, 21);
1358 #endif
1359
1360 #if defined(PANEL68)
1361 if (k == 1)
1362 {
1363 switch (e->TA[0])
1364 {
1365 case CTA9:
1366 cpu.dataMode = 0102;
1367 cpu.ou.opsz = is_9 >> 12;
1368 break;
1369 case CTA6:
1370 cpu.dataMode = 0042;
1371 cpu.ou.opsz = is_6 >> 12;
1372 break;
1373 case CTA4:
1374 cpu.dataMode = 0022;
1375 cpu.ou.opsz = is_4 >> 12;
1376 break;
1377 }
1378 }
1379 #endif
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403 if (MFk & MFkAR)
1404 {
1405
1406
1407
1408 word3 n = (word3) getbits18 (address, 0, 3);
1409 CPTUR (cptUsePRn + n);
1410 word18 offset = SIGNEXT15_18 ((word15) address);
1411 address = (cpu.AR [n].WORDNO + offset) & AMASK;
1412
1413 ARn_CHAR = GET_AR_CHAR (n);
1414 ARn_BITNO = GET_AR_BITNO (n);
1415
1416
1417
1418
1419 if (ARn_BITNO > 8)
1420 ARn_BITNO = 8;
1421
1422 cpu.cu.TSN_PRNO[k-1] = n;
1423 cpu.cu.TSN_VALID[k-1] = 1;
1424 e -> addr [k - 1].SNR = cpu.PR [n].SNR;
1425 e -> addr [k - 1].RNR = max3 (cpu.PR [n].RNR, cpu.TPR.TRR, cpu.PPR.PRR);
1426
1427 e -> addr [k - 1].mat = viaPR;
1428 sim_debug (DBG_TRACEEXT, & cpu_dev, "AR n %u k %u\r\n", n, k - 1);
1429 }
1430
1431 PNL (cpu.du.POL = 1);
1432
1433 uint CN = getbits36_3 (opDesc, 18);
1434
1435 sim_debug (DBG_TRACEEXT, & cpu_dev, "initial CN%u %u\r\n", k, CN);
1436
1437 if (MFk & MFkRL)
1438 {
1439 uint reg = opDesc & 017;
1440
1441 e -> N [k - 1] = (uint) getMFReg36 (cpup, reg, false, false, mod_fault);
1442 #if defined(EIS_PTR3)
1443 switch (cpu.du.TAk[k-1])
1444 #else
1445 switch (e -> TA [k - 1])
1446 #endif
1447 {
1448 case CTA4:
1449 e -> N [k - 1] &= 017777777;
1450 break;
1451
1452 case CTA6:
1453 case CTA9:
1454 e -> N [k - 1] &= 07777777;
1455 break;
1456
1457 default:
1458 L68_ (doFault (FAULT_IPR, fst_ill_proc, "parseAlphanumericOperandDescriptor TA 3");)
1459
1460 *mod_fault |= FR_ILL_PROC;
1461 break;
1462 }
1463 }
1464 else
1465 e -> N [k - 1] = opDesc & 07777;
1466
1467
1468
1469
1470 sim_debug (DBG_TRACEEXT, & cpu_dev, "N%u %o\r\n", k, e->N[k-1]);
1471
1472 word36 r = getMFReg36 (cpup, MFk & 017, allowDU, true, mod_fault);
1473
1474 if ((MFk & 017) == 4)
1475 {
1476 address += r;
1477 address &= AMASK;
1478 r = 0;
1479 }
1480
1481
1482
1483
1484 uint effBITNO = 0;
1485 uint effCHAR = 0;
1486 uint effWORDNO = 0;
1487
1488 #if defined(EIS_PTR3)
1489 switch (cpu.du.TAk[k-1])
1490 #else
1491 switch (e -> TA [k - 1])
1492 #endif
1493 {
1494 case CTA4:
1495 {
1496
1497
1498
1499
1500 uint arn_char4 = ARn_CHAR * 2u + (ARn_BITNO >= 5u ? 1u : 0u);
1501
1502
1503
1504 uint nchars = address * 8 + (uint) r + arn_char4 + CN;
1505
1506 effWORDNO = nchars / 8;
1507 effCHAR = nchars % 8;
1508
1509 effBITNO = (nchars & 1) ? 5 : 0;
1510
1511 effWORDNO &= AMASK;
1512
1513 e -> CN [k - 1] = effCHAR;
1514 e -> WN [k - 1] = effWORDNO;
1515
1516 sim_debug (DBG_TRACEEXT, & cpu_dev, "CN%d set to %d by CTA4\r\n",
1517 k, e -> CN [k - 1]);
1518 }
1519 break;
1520
1521 case CTA6:
1522 if (CN >= 6) {
1523 L68_ (doFault (FAULT_IPR, fst_ill_proc, "parseAlphanumericOperandDescriptor TAn CTA6 CN >= 6");)
1524
1525 *mod_fault |= FR_ILL_PROC;
1526 }
1527 {
1528
1529
1530
1531
1532
1533
1534
1535 uint rbits = (k == 3 &&
1536 cpu.currentInstruction.opcode == 024 &&
1537 cpu.currentInstruction.opcodeX == 1) ? 9u : 6u;
1538 effBITNO = (9u * ARn_CHAR + rbits * r + ARn_BITNO) % 9u;
1539 effCHAR = ((6u * CN +
1540 9u * ARn_CHAR +
1541 rbits * r + ARn_BITNO) % 36u) / 6u;
1542 effWORDNO = (uint) (address +
1543 (6u * CN +
1544 9u * ARn_CHAR +
1545 rbits * r +
1546 ARn_BITNO) / 36u);
1547 }
1548 effWORDNO &= AMASK;
1549
1550 e -> CN [k - 1] = effCHAR;
1551 e -> WN [k - 1] = effWORDNO;
1552 sim_debug (DBG_TRACEEXT, & cpu_dev, "CN%d set to %d by CTA6\r\n",
1553 k, e -> CN [k - 1]);
1554 break;
1555
1556 case CTA9:
1557 if (CN & 01) {
1558 L68_ (doFault(FAULT_IPR, fst_ill_proc, "parseAlphanumericOperandDescriptor CTA9 & CN odd");)
1559
1560 *mod_fault |= FR_ILL_PROC;
1561 }
1562 CN = (CN >> 1);
1563
1564 effBITNO = 0;
1565 effCHAR = (CN + ARn_CHAR + r) % 4;
1566 sim_debug (DBG_TRACEEXT, & cpu_dev,
1567 "effCHAR %d = (CN %d + ARn_CHAR %d + r %"PRId64") %% 4)\r\n",
1568 effCHAR, CN, ARn_CHAR, r);
1569
1570
1571 effWORDNO = (uint) (address +
1572 ((9u * CN +
1573 9u * ARn_CHAR +
1574 9u * r) / 36u));
1575 effWORDNO &= AMASK;
1576
1577 e -> CN [k - 1] = effCHAR;
1578 e -> WN [k - 1] = effWORDNO;
1579 sim_debug (DBG_TRACEEXT, & cpu_dev, "CN%d set to %d by CTA9\r\n",
1580 k, e -> CN [k - 1]);
1581 break;
1582
1583 default:
1584 L68_ (doFault (FAULT_IPR, fst_ill_proc, "parseAlphanumericOperandDescriptor TA1 3");)
1585
1586 *mod_fault |= FR_ILL_PROC;
1587 break;
1588 }
1589
1590 EISaddr * a = & e -> addr [k - 1];
1591 PNL (cpu.du.Dk_PTR_W[k-1] = effWORDNO);
1592 #if defined(EIS_PTR)
1593 cpu.du.Dk_PTR_W[k-1] = effWORDNO;
1594 #else
1595 a -> address = effWORDNO;
1596 #endif
1597 a -> cPos= (int) effCHAR;
1598 a -> bPos = (int) effBITNO;
1599
1600 #if !defined(EIS_PTR3)
1601
1602 a -> TA = (int) e -> TA [k - 1];
1603 #endif
1604 }
1605
1606 static void parseArgOperandDescriptor (cpu_state_t * cpup, uint k, fault_ipr_subtype_ *mod_fault)
1607 {
1608 PNL (L68_ (if (k == 1)
1609 DU_CYCLE_NLD1;
1610 else if (k == 2)
1611 DU_CYCLE_NLD2;
1612 else if (k == 3)
1613 DU_CYCLE_GSTR;))
1614
1615 EISstruct * e = & cpu.currentEISinstruction;
1616 word36 opDesc = e -> op [k - 1];
1617 word18 y = GETHI (opDesc);
1618 word1 yA = GET_A (opDesc);
1619
1620 uint yREG = opDesc & 0xf;
1621
1622 word36 r = getMFReg36 (cpup, yREG, false, true, mod_fault);
1623
1624 word8 ARn_CHAR = 0;
1625 word6 ARn_BITNO = 0;
1626
1627 PNL (cpu.du.POP = 1);
1628
1629 if (yA)
1630 {
1631
1632
1633
1634 word3 n = GET_ARN (opDesc);
1635 CPTUR (cptUsePRn + n);
1636 word15 offset = y & MASK15;
1637 y = (cpu.AR [n].WORDNO + SIGNEXT15_18 (offset)) & AMASK;
1638
1639 ARn_CHAR = GET_AR_CHAR (n);
1640 ARn_BITNO = GET_AR_BITNO (n);
1641
1642 cpu.cu.TSN_PRNO[k-1] = n;
1643 cpu.cu.TSN_VALID[k-1] = 1;
1644 e -> addr [k - 1].SNR = cpu.PR[n].SNR;
1645 e -> addr [k - 1].RNR = max3 (cpu.PR [n].RNR, cpu.TPR.TRR, cpu.PPR.PRR);
1646 e -> addr [k - 1].mat = viaPR;
1647 }
1648
1649
1650
1651 (void) ARn_CHAR;
1652 (void) ARn_BITNO;
1653 y += (word18) r;
1654 y &= AMASK;
1655
1656 PNL (cpu.du.Dk_PTR_W[k-1] = y);
1657
1658 #if defined(EIS_PTR)
1659 cpu.du.Dk_PTR_W[k-1] = y;
1660 #else
1661 e -> addr [k - 1].address = y;
1662 #endif
1663 }
1664
1665 static void parseNumericOperandDescriptor (cpu_state_t * cpup, int k, fault_ipr_subtype_ *mod_fault)
1666 {
1667 PNL (L68_ (if (k == 1)
1668 DU_CYCLE_NLD1;
1669 else if (k == 2)
1670 DU_CYCLE_NLD2;
1671 else if (k == 3)
1672 DU_CYCLE_GSTR;))
1673
1674 EISstruct * e = & cpu.currentEISinstruction;
1675 word18 MFk = e->MF[k-1];
1676
1677 PNL (cpu.du.POP = 1);
1678
1679 word36 opDesc = e->op[k-1];
1680
1681 word8 ARn_CHAR = 0;
1682 word6 ARn_BITNO = 0;
1683
1684 word18 address = GETHI(opDesc);
1685 if (MFk & MFkAR)
1686 {
1687
1688
1689
1690 word3 n = (word3) getbits18 (address, 0, 3);
1691 CPTUR (cptUsePRn + n);
1692 word15 offset = address & MASK15;
1693 address = (cpu.AR[n].WORDNO + SIGNEXT15_18(offset)) & AMASK;
1694
1695 ARn_CHAR = GET_AR_CHAR (n);
1696 ARn_BITNO = GET_AR_BITNO (n);
1697
1698 cpu.cu.TSN_PRNO[k-1] = n;
1699 cpu.cu.TSN_VALID[k-1] = 1;
1700 e->addr[k-1].SNR = cpu.PR[n].SNR;
1701 e->addr[k-1].RNR = max3(cpu.PR[n].RNR, cpu.TPR.TRR, cpu.PPR.PRR);
1702
1703 e->addr[k-1].mat = viaPR;
1704 }
1705
1706 PNL (cpu.du.POL = 1);
1707
1708 word3 CN = getbits36_3 (opDesc, 18);
1709 e->TN[k-1] = getbits36_1 (opDesc, 21);
1710
1711 #if defined(PANEL68)
1712 if (k == 1)
1713 {
1714 if (e->TN[0])
1715 cpu.dataMode = 0021;
1716 else
1717 cpu.dataMode = 0101;
1718 }
1719 #endif
1720
1721 e->S[k-1] = getbits36_2 (opDesc, 22);
1722 e->SF[k-1] = SIGNEXT6_int (getbits36_6 (opDesc, 24));
1723
1724
1725
1726
1727
1728
1729
1730 if (MFk & MFkRL)
1731 {
1732 uint reg = opDesc & 017;
1733 e->N[k-1] = getMFReg18 (cpup,reg, false, false, mod_fault) & 077;
1734 }
1735 else
1736 e->N[k-1] = opDesc & 077;
1737
1738 sim_debug (DBG_TRACEEXT, & cpu_dev, "parseNumericOperandDescriptor(cpup, ): N%u %0o\r\n", k, e->N[k-1]);
1739
1740 word36 r = getMFReg36(cpup, MFk & 017, false, true, mod_fault);
1741 if ((MFk & 017) == 4)
1742 {
1743 address += r;
1744 address &= AMASK;
1745 r = 0;
1746 }
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765 uint effBITNO = 0;
1766 uint effCHAR = 0;
1767 uint effWORDNO = 0;
1768
1769
1770
1771
1772
1773
1774 switch (e->TN[k-1])
1775 {
1776 case CTN4:
1777 {
1778
1779
1780
1781
1782 uint arn_char4 = ARn_CHAR * 2u + (ARn_BITNO >= 5u ? 1u : 0u);
1783
1784
1785
1786
1787
1788 uint nchars = (uint) (address * 8u + r + arn_char4 + CN);
1789
1790 effWORDNO = nchars / 8u;
1791 effCHAR = nchars % 8u;
1792 effBITNO = (nchars & 1u) ? 5u : 0u;
1793 effWORDNO &= AMASK;
1794
1795 e->CN[k-1] = effCHAR;
1796 }
1797 break;
1798
1799 case CTN9:
1800 if (CN & 1u) {
1801 L68_ (doFault(FAULT_IPR, fst_ill_proc, "parseNumericOperandDescriptor CTA9 & CN odd");)
1802
1803 *mod_fault |= FR_ILL_PROC;
1804 }
1805 CN = (CN >> 1u) & 03u;
1806
1807 effBITNO = 0;
1808 effCHAR = ((word36) CN + (word36) ARn_CHAR + r) % 4u;
1809
1810 effWORDNO = (uint) (address + (9u*CN + 9u*ARn_CHAR + 9u*r) / 36);
1811 effWORDNO &= AMASK;
1812
1813 e->CN[k-1] = effCHAR;
1814
1815 break;
1816 default:
1817 #if defined(EIS_PTR3)
1818 sim_printf ("parseNumericOperandDescriptor(cpup, ta=%d) How'd we get here 2?\r\n",
1819 cpu.du.TAk[k-1]);
1820 #else
1821 sim_printf ("parseNumericOperandDescriptor(cpup, ta=%d) How'd we get here 2?\r\n",
1822 e->TA[k-1]);
1823 #endif
1824 break;
1825 }
1826
1827 EISaddr *a = &e->addr[k-1];
1828 PNL (cpu.du.Dk_PTR_W[k-1] = effWORDNO);
1829 #if defined(EIS_PTR)
1830 cpu.du.Dk_PTR_W[k-1] = effWORDNO;
1831 #else
1832 a->address = effWORDNO;
1833 #endif
1834 a->cPos = (int) effCHAR;
1835 a->bPos = (int) effBITNO;
1836
1837
1838 a->TN = (int) e->TN[k-1];
1839
1840 #if defined(EIS_PTR)
1841 sim_debug (DBG_TRACEEXT, & cpu_dev,
1842 "parseNumericOperandDescriptor(cpup, ): address:%06o cPos:%d bPos:%d N%u %u\r\n",
1843 cpu.du.Dk_PTR_W[k-1], a->cPos, a->bPos, k, e->N[k-1]);
1844 #else
1845 sim_debug (DBG_TRACEEXT, & cpu_dev,
1846 "parseNumericOperandDescriptor(cpup, ): address:%06o cPos:%d bPos:%d N%u %u\r\n",
1847 a->address, a->cPos, a->bPos, k, e->N[k-1]);
1848 #endif
1849 }
1850
1851 static void parseBitstringOperandDescriptor (cpu_state_t * cpup, int k, fault_ipr_subtype_ *mod_fault)
1852 {
1853 PNL (L68_ (if (k == 1)
1854 DU_CYCLE_ANLD1;
1855 else if (k == 2)
1856 DU_CYCLE_ANLD2;
1857 else if (k == 3)
1858 DU_CYCLE_ANSTR;))
1859
1860 EISstruct * e = & cpu.currentEISinstruction;
1861 word18 MFk = e->MF[k-1];
1862 word36 opDesc = e->op[k-1];
1863
1864 #if defined(PANEL68)
1865 if (k == 1)
1866 cpu.dataMode = 0010;
1867 #endif
1868 word8 ARn_CHAR = 0;
1869 word6 ARn_BITNO = 0;
1870
1871 PNL (cpu.du.POP = 1);
1872
1873 word18 address = GETHI(opDesc);
1874 if (MFk & MFkAR)
1875 {
1876
1877
1878
1879 word3 n = (word3) getbits18 (address, 0, 3);
1880 CPTUR (cptUsePRn + n);
1881 word15 offset = address & MASK15;
1882 address = (cpu.AR[n].WORDNO + SIGNEXT15_18(offset)) & AMASK;
1883
1884 sim_debug (DBG_TRACEEXT, & cpu_dev, "bitstring k %d AR%d\r\n", k, n);
1885
1886 ARn_CHAR = GET_AR_CHAR (n);
1887 ARn_BITNO = GET_AR_BITNO (n);
1888
1889
1890 if (ARn_BITNO > 8)
1891 ARn_BITNO = 8;
1892 cpu.cu.TSN_PRNO[k-1] = n;
1893 cpu.cu.TSN_VALID[k-1] = 1;
1894 e->addr[k-1].SNR = cpu.PR[n].SNR;
1895 e->addr[k-1].RNR = max3(cpu.PR[n].RNR, cpu.TPR.TRR, cpu.PPR.PRR);
1896 e->addr[k-1].mat = viaPR;
1897 }
1898 PNL (cpu.du.POL = 1);
1899
1900
1901
1902
1903
1904 if (MFk & MFkRL)
1905 {
1906 uint reg = opDesc & 017;
1907 e->N[k-1] = getMFReg36(cpup, reg, false, false, mod_fault) & 077777777;
1908 sim_debug (DBG_TRACEEXT, & cpu_dev, "bitstring k %d RL reg %u val %"PRIo64"\r\n", k, reg, (word36)e->N[k-1]);
1909 }
1910 else
1911 {
1912 e ->N[k-1] = opDesc & 07777;
1913 }
1914
1915 sim_debug (DBG_TRACEEXT, & cpu_dev, "bitstring k %d opdesc %012"PRIo64"\r\n", k, opDesc);
1916 sim_debug (DBG_TRACEEXT, & cpu_dev, "N%u %u\r\n", k, e->N[k-1]);
1917
1918 word4 B = getbits36_4(opDesc, 20);
1919 word2 C = getbits36_2 (opDesc, 18);
1920
1921 if (B >= 9) {
1922 L68_ (doFault (FAULT_IPR, fst_ill_proc, "parseBitstringOperandDescriptor B >= 9");)
1923
1924 *mod_fault |= FR_ILL_PROC;
1925 }
1926
1927 word36 r = getMFReg36(cpup, MFk & 017, false, true, mod_fault);
1928 if ((MFk & 017) == 4)
1929 {
1930
1931
1932 address += r;
1933 address &= AMASK;
1934 r = 0;
1935 }
1936
1937 uint effBITNO = (9u*ARn_CHAR + r + ARn_BITNO + B + 9u*C) % 9u;
1938 uint effCHAR = ((9u*ARn_CHAR + r + ARn_BITNO + B + 9u*C) % 36u) / 9u;
1939 uint effWORDNO = (uint) (address + (9u*ARn_CHAR + r + ARn_BITNO + B + 9u*C) / 36u);
1940 effWORDNO &= AMASK;
1941
1942 e->B[k-1] = effBITNO;
1943 e->C[k-1] = effCHAR;
1944
1945 EISaddr *a = &e->addr[k-1];
1946 PNL (cpu.du.Dk_PTR_W[k-1] = effWORDNO);
1947 #if defined(EIS_PTR)
1948 cpu.du.Dk_PTR_W[k-1] = effWORDNO;
1949 #else
1950 a->address = effWORDNO;
1951 #endif
1952 a->cPos = (int) effCHAR;
1953 a->bPos = (int) effBITNO;
1954 }
1955
1956 static void cleanupOperandDescriptor (cpu_state_t * cpup, int k)
1957 {
1958 EISstruct * e = & cpu.currentEISinstruction;
1959 if (e -> addr [k - 1].cacheValid && e -> addr [k - 1].cacheDirty)
1960 {
1961 EISWriteCache(cpup, & e -> addr [k - 1]);
1962 }
1963 e -> addr [k - 1].cacheDirty = false;
1964 }
1965
1966
1967
1968 bool tandd_eis_interruptible (cpu_state_t * cpup)
1969 {
1970 DCDstruct * i = & cpu.currentInstruction;
1971 if (! i -> opcodeX)
1972 return false;
1973 switch (i -> opcode)
1974 {
1975 case 0100:
1976 case 0101:
1977 case 0160:
1978 case 0106:
1979 case 0120:
1980 case 0121:
1981 case 0124:
1982 case 0125:
1983 case 0164:
1984 case 0165:
1985 case 0060:
1986 case 0061:
1987 case 0064:
1988 case 0065:
1989 case 0066:
1990 return true;
1991 }
1992 return false;
1993 }
1994
1995
1996 #define TDPER(ta) ((ta) == CTA6 ? 6u : (ta) == CTA4 ? 8u : 4u)
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006 void tandd_eis_sample (cpu_state_t * cpup, uint unit, uint perWord)
2007 {
2008 if (! cpu.tweaks.tandd_mode || cpu.currentInstruction.i ||
2009 unit <= cpu.tanddEISstart || unit % (2 * perWord))
2010 return;
2011 if (++ cpu.rTRlsb >= 4)
2012 {
2013 cpu.rTRlsb = 0;
2014 cpu.rTR --;
2015 cpu.lufTicks ++;
2016 cpu.tanddTRTicks ++;
2017 }
2018 if (cpu.rTR & ~MASK27)
2019 {
2020 cpu.rTR &= MASK27;
2021 if (cpu.tweaks.tro_enable)
2022 setG7fault (current_running_cpu_idx, FAULT_TRO);
2023 }
2024 advanceG7Faults (cpup);
2025 bool noCheckTR = is_priv_mode (cpup);
2026
2027
2028
2029 bool g7 = noCheckTR ? (cpu.g7Faults & ~(1u << FAULT_TRO)) != 0
2030 : cpu.g7Faults != 0;
2031 if (! g7 && ! sample_interrupts (cpup))
2032 return;
2033 for (int k = 1; k <= 3; k ++)
2034 cleanupOperandDescriptor (cpup, k);
2035 cpu.du.CHTALLY = unit;
2036 SC_I_MIF (1);
2037 if (g7)
2038 doG7Fault (cpup, ! noCheckTR);
2039 cpu.interrupt_flag = true;
2040 cpu.cycle = INTERRUPT_cycle;
2041 longjmp (cpu.jmpMain, JMP_REENTRY);
2042 }
2043
2044
2045
2046 #define n4bits (1 << 23)
2047
2048
2049 #define n4chars (1 << 21)
2050
2051
2052 #define nxbits ((1 << 18) * 36)
2053
2054
2055 static unsigned int cntFromBit[36] = {
2056 0, 0, 0, 0, 0, 1, 1, 1, 1,
2057 2, 2, 2, 2, 2, 3, 3, 3, 3,
2058 4, 4, 4, 4, 4, 5, 5, 5, 5,
2059 6, 6, 6, 6, 6, 7, 7, 7, 7
2060 };
2061
2062 static word6 bitFromCnt[8] = {1, 5, 10, 14, 19, 23, 28, 32};
2063
2064 void a4bd (cpu_state_t * cpup)
2065 {
2066
2067
2068 uint ARn = GET_ARN (cpu.cu.IWB);
2069 CPTUR (cptUsePRn + ARn);
2070 int32_t address = SIGNEXT15_32 (GET_OFFSET (cpu.cu.IWB));
2071
2072
2073
2074 word4 reg = GET_TD (cpu.cu.IWB);
2075
2076
2077 word36 ur = getCrAR (cpup, reg);
2078 int32 r = SIGNEXT22_32 ((word22) ur);
2079
2080
2081
2082 uint augend = 0;
2083 if (GET_A (cpu.cu.IWB))
2084 {
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094 augend = cpu.AR[ARn].WORDNO * 8u + GET_AR_CHAR (ARn) * 2u;
2095
2096
2097 if (GET_AR_BITNO (ARn) >= 5u)
2098 augend ++;
2099 }
2100
2101
2102
2103
2104 int32_t addend = address * 8 + r;
2105
2106
2107
2108
2109 int32_t sum = (int32_t) augend + addend;
2110
2111
2112
2113
2114 while (sum < 0)
2115 sum += n4chars;
2116 sum = sum % n4chars;
2117
2118
2119
2120 cpu.AR[ARn].WORDNO = (word18) (sum / 8) & AMASK;
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136 uint char4no = (uint) (sum % 8);
2137
2138
2139
2140 SET_AR_CHAR_BITNO (ARn, (word2) (char4no / 2), (char4no % 2) ? 5 : 0);
2141 #if defined(TESTING)
2142 HDBGRegARW (ARn, "a4bd");
2143 #endif
2144
2145
2146
2147
2148 }
2149
2150 void s4bd (cpu_state_t * cpup)
2151 {
2152 uint ARn = GET_ARN (cpu.cu.IWB);
2153 CPTUR (cptUsePRn + ARn);
2154 int32_t address = SIGNEXT15_32 (GET_OFFSET (cpu.cu.IWB));
2155 word4 reg = GET_TD (cpu.cu.IWB);
2156
2157
2158 word36 ur = getCrAR (cpup, reg);
2159 int32 r = SIGNEXT22_32 ((word22) ur);
2160
2161 uint minuend = 0;
2162 if (GET_A (cpu.cu.IWB))
2163 {
2164
2165 minuend = cpu.AR [ARn].WORDNO * 32 + cntFromBit [GET_AR_CHAR (ARn) * 9 + GET_AR_BITNO (ARn)];
2166
2167 minuend = minuend & (unsigned int) ~3;
2168 }
2169 int32_t subtractend = address * 32 + r * 4;
2170 int32_t difference = (int32_t) minuend - subtractend;
2171
2172
2173 while (difference < 0)
2174 difference += n4bits;
2175 difference = difference % n4bits;
2176
2177 cpu.AR [ARn].WORDNO = (word18) (difference / 32) & AMASK;
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188 uint bitno = (uint) (difference % 32);
2189
2190
2191 SET_AR_CHAR_BITNO (ARn, bitFromCnt[bitno % 8] / 9, bitFromCnt[bitno % 8] % 9);
2192 #if defined(TESTING)
2193 HDBGRegARW (ARn, "s4bd");
2194 #endif
2195 }
2196
2197 void axbd (cpu_state_t * cpup, uint sz)
2198 {
2199 uint ARn = GET_ARN (cpu.cu.IWB);
2200 CPTUR (cptUsePRn + ARn);
2201 int32_t address = SIGNEXT15_32 (GET_OFFSET (cpu.cu.IWB));
2202 word6 reg = GET_TD (cpu.cu.IWB);
2203
2204
2205 word36 rcnt = getCrAR (cpup, reg);
2206 int32_t r;
2207
2208 if (sz == 1)
2209 r = SIGNEXT24_32 ((word24) rcnt);
2210 else if (sz == 4)
2211 r = SIGNEXT22_32 ((word22) rcnt);
2212 else if (sz == 6)
2213 r = SIGNEXT21_32 ((word21) rcnt);
2214 else if (sz == 9)
2215 r = SIGNEXT21_32 ((word21) rcnt);
2216 else
2217 r = SIGNEXT18_32 ((word18) rcnt);
2218
2219 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2220 "axbd sz %d ARn 0%o address 0%o reg 0%o r 0%o\r\n",
2221 sz, ARn, address, reg, r);
2222
2223 uint augend = 0;
2224 if (GET_A (cpu.cu.IWB))
2225 {
2226 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2227 "axbd ARn %d WORDNO %o CHAR %o BITNO %0o %d.\r\n",
2228 ARn, cpu.PAR[ARn].WORDNO, GET_AR_CHAR (ARn),
2229 GET_AR_BITNO (ARn), GET_AR_BITNO (ARn));
2230 augend = cpu.AR[ARn].WORDNO * 36u + GET_AR_CHAR (ARn) * 9u + GET_AR_BITNO (ARn);
2231 }
2232 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2233 "axbd augend 0%o\r\n",
2234 augend);
2235
2236
2237 if (sz == 9 || GET_A (cpu.cu.IWB))
2238 {
2239 augend = (augend / sz) * sz;
2240 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2241 "axbd force augend 0%o\r\n",
2242 augend);
2243 }
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253 int32_t addend = address * 36 + r * (int32_t) sz;
2254 int32_t sum = (int32_t) augend + addend;
2255
2256
2257 while (sum < 0)
2258 sum += nxbits;
2259 sum = sum % nxbits;
2260
2261 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "axbd augend 0%o addend 0%o sum 0%o\r\n", augend, addend, sum);
2262
2263 cpu.AR [ARn].WORDNO = (word18) (sum / 36) & AMASK;
2264
2265 #if defined(TESTING)
2266 HDBGRegARR (ARn, "axbd");
2267 #endif
2268 SET_AR_CHAR_BITNO (ARn, (word2)((sum % 36) / 9), (word2)(sum % 9));
2269 #if defined(TESTING)
2270 HDBGRegARW (ARn, "axbd");
2271 #endif
2272 }
2273
2274
2275 void abd (cpu_state_t * cpup)
2276 {
2277 uint ARn = GET_ARN (cpu.cu.IWB);
2278 CPTUR (cptUsePRn + ARn);
2279
2280 word18 address = SIGNEXT15_18 (GET_OFFSET (cpu.cu.IWB));
2281
2282
2283 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2284
2285 word24 r = getCrAR (cpup, (word4) reg) & MASK24;
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295 if (GET_AR_BITNO (ARn) > 8)
2296 SET_AR_CHAR_BITNO (ARn, GET_AR_CHAR (ARn), 8);
2297
2298 if (GET_A (cpu.cu.IWB))
2299 {
2300
2301
2302
2303 word24 bits = 9u * GET_AR_CHAR (ARn) + GET_AR_BITNO (ARn) + r;
2304
2305
2306 cpu.AR[ARn].WORDNO = (cpu.AR[ARn].WORDNO + address +
2307 bits / 36) & MASK18;
2308 if (r % 36)
2309 {
2310
2311
2312 SET_AR_CHAR_BITNO (ARn, (bits % 36) / 9,
2313 bits % 9);
2314 }
2315 }
2316 else
2317 {
2318
2319
2320 cpu.AR[ARn].WORDNO = (address + r / 36) & MASK18;
2321 if (r % 36)
2322 {
2323
2324
2325 SET_AR_CHAR_BITNO (ARn, (r % 36) / 9,
2326 r % 9);
2327 }
2328 }
2329 # if defined(TESTING)
2330 HDBGRegARW (ARn, "abd");
2331 # endif
2332
2333
2334
2335
2336 }
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485 void awd (cpu_state_t * cpup)
2486 {
2487 uint ARn = GET_ARN (cpu.cu.IWB);
2488 CPTUR (cptUsePRn + ARn);
2489 int32_t address = SIGNEXT15_32 (GET_OFFSET (cpu.cu.IWB));
2490
2491
2492 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2493
2494
2495 int32_t r = (int32_t) (getCrAR (cpup, reg) & MASK18);
2496 r = SIGNEXT18_32 ((word18) r);
2497
2498 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2499 "awd ARn 0%o address 0%o reg 0%o r 0%o\r\n",
2500 ARn, address, reg, r);
2501
2502 uint augend = 0;
2503 if (GET_A (cpu.cu.IWB))
2504 {
2505 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2506 "awd ARn %d WORDNO %o CHAR %o BITNO %0o %d.\r\n",
2507 ARn, cpu.PAR[ARn].WORDNO, GET_AR_CHAR (ARn),
2508 GET_AR_BITNO (ARn), GET_AR_BITNO (ARn));
2509
2510
2511 augend = cpu.AR [ARn].WORDNO;
2512 }
2513
2514 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2515 "awd augend 0%o\r\n",
2516 augend);
2517
2518 int32_t addend = address + r;
2519 int32_t sum = (int32_t) augend + addend;
2520
2521 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2522 "awd augend 0%o addend 0%o sum 0%o\r\n",
2523 augend, addend, sum);
2524
2525 cpu.AR[ARn].WORDNO = (word18) sum & AMASK;
2526 SET_AR_CHAR_BITNO (ARn, 0, 0);
2527 #if defined(TESTING)
2528 HDBGRegARW (ARn, "awd");
2529 #endif
2530 }
2531
2532 void sbd (cpu_state_t * cpup)
2533 {
2534 uint ARn = GET_ARN (cpu.cu.IWB);
2535
2536 word18 address = SIGNEXT15_18 (GET_OFFSET (cpu.cu.IWB));
2537 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2538
2539 word24 r = getCrAR (cpup, (word4) reg) & MASK24;
2540 if (GET_AR_BITNO (ARn) > 8)
2541 SET_AR_CHAR_BITNO (ARn, GET_AR_CHAR (ARn), 8);
2542
2543 if (GET_A (cpu.cu.IWB))
2544 {
2545 word24 bits = 9u * GET_AR_CHAR (ARn) + GET_AR_BITNO (ARn) - r;
2546 cpu.AR[ARn].WORDNO = (cpu.AR[ARn].WORDNO -
2547 address + bits / 36) & MASK18;
2548 if (r % 36)
2549 {
2550 SET_AR_CHAR_BITNO (ARn, (- ((bits % 36) / 9)) & MASK2,
2551 (- (bits % 9)) & MASK4);
2552 }
2553 }
2554 else
2555 {
2556 cpu.AR[ARn].WORDNO = (- (address + r / 36)) & MASK18;
2557 if (r % 36)
2558 {
2559 SET_AR_CHAR_BITNO (ARn, (- ((r % 36) / 9)) & MASK2,
2560 (- (r % 9)) & MASK4);
2561 }
2562 }
2563 #if defined(TESTING)
2564 HDBGRegARW (ARn, "sbd");
2565 #endif
2566 }
2567
2568 void swd (cpu_state_t * cpup)
2569 {
2570 uint ARn = GET_ARN (cpu.cu.IWB);
2571 CPTUR (cptUsePRn + ARn);
2572 int32_t address = SIGNEXT15_32 (GET_OFFSET (cpu.cu.IWB));
2573
2574
2575 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2576
2577
2578 int32_t r = (int32_t) (getCrAR (cpup, reg) & MASK18);
2579 r = SIGNEXT18_32 ((word18) r);
2580
2581 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2582 "swd ARn 0%o address 0%o reg 0%o r 0%o\r\n",
2583 ARn, address, reg, r);
2584
2585 uint minued = 0;
2586 if (GET_A (cpu.cu.IWB))
2587 {
2588 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2589 "swd ARn %d WORDNO %o CHAR %o BITNO %0o %d.\r\n",
2590 ARn, cpu.PAR[ARn].WORDNO, GET_AR_CHAR (ARn),
2591 GET_AR_BITNO (ARn), GET_AR_BITNO (ARn));
2592
2593
2594 minued = cpu.AR [ARn].WORDNO;
2595 }
2596
2597 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2598 "swd minued 0%o\r\n", minued);
2599
2600 int32_t subtractend = address + r;
2601 int32_t difference = (int32_t) minued - subtractend;
2602
2603 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev,
2604 "swd minued 0%o subtractend 0%o difference 0%o\r\n",
2605 minued, subtractend, difference);
2606
2607 cpu.AR [ARn].WORDNO = (word18) difference & AMASK;
2608 SET_AR_CHAR_BITNO (ARn, 0, 0);
2609 #if defined(TESTING)
2610 HDBGRegARW (ARn, "swd");
2611 #endif
2612 }
2613
2614 void s9bd (cpu_state_t * cpup)
2615 {
2616 uint ARn = GET_ARN (cpu.cu.IWB);
2617 CPTUR (cptUsePRn + ARn);
2618 word18 address = SIGNEXT15_18 (GET_OFFSET (cpu.cu.IWB));
2619
2620
2621 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2622
2623
2624 word21 r = getCrAR (cpup, reg) & MASK21;;
2625
2626 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "s9bd r 0%o\r\n", r);
2627
2628 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "s9bd ARn 0%o address 0%o reg 0%o r 0%o\r\n", ARn, address, reg, r);
2629
2630 if (GET_A (cpu.cu.IWB))
2631 {
2632
2633
2634
2635 cpu.AR[ARn].WORDNO = (cpu.AR[ARn].WORDNO -
2636 address +
2637 (GET_AR_CHAR (ARn) - r) / 4) & MASK18;
2638
2639
2640
2641
2642 SET_AR_CHAR_BITNO (ARn, (GET_AR_CHAR (ARn) - r) & MASK2, 0);
2643
2644 }
2645 else
2646 {
2647 cpu.AR[ARn].WORDNO = (- (address + (r + 3) / 4)) & MASK18;
2648
2649
2650
2651 SET_AR_CHAR_BITNO (ARn, (-r) & MASK2, 0);
2652
2653 }
2654
2655 #if defined(TESTING)
2656 HDBGRegARW (ARn, "s9bd");
2657 #endif
2658
2659
2660
2661
2662 }
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691 void asxbd (cpu_state_t * cpup, uint sz, bool sub)
2692 {
2693
2694 uint map4 [64] =
2695 {
2696 0,
2697 0,
2698 0,
2699 0,
2700 0,
2701 5,
2702 5,
2703 5,
2704 5,
2705 5,
2706 5,
2707 5,
2708 5,
2709 5,
2710 5,
2711 5,
2712 9,
2713 9,
2714 9,
2715 9,
2716 9,
2717 14,
2718 14,
2719 14,
2720 14,
2721 14,
2722 14,
2723 14,
2724 14,
2725 14,
2726 14,
2727 14,
2728 18,
2729 18,
2730 18,
2731 18,
2732 18,
2733 23,
2734 23,
2735 23,
2736 23,
2737 23,
2738 23,
2739 23,
2740 23,
2741 23,
2742 23,
2743 23,
2744 27,
2745 27,
2746 27,
2747 27,
2748 27,
2749 32,
2750 32,
2751 32,
2752 32,
2753 32,
2754 32,
2755 32,
2756 32,
2757 32,
2758 32,
2759 32
2760 };
2761
2762 uint map6 [64] =
2763 {
2764 0,
2765 1,
2766 2,
2767 3,
2768 4,
2769 5,
2770 6,
2771 7,
2772 8,
2773 6,
2774 6,
2775 6,
2776 6,
2777 6,
2778 6,
2779 6,
2780 9,
2781 10,
2782 11,
2783 12,
2784 13,
2785 14,
2786 15,
2787 16,
2788 17,
2789 12,
2790 12,
2791 12,
2792 12,
2793 12,
2794 12,
2795 12,
2796 18,
2797 19,
2798 20,
2799 21,
2800 22,
2801 23,
2802 24,
2803 25,
2804 26,
2805 24,
2806 24,
2807 24,
2808 24,
2809 24,
2810 24,
2811 24,
2812 27,
2813 28,
2814 29,
2815 30,
2816 31,
2817 32,
2818 33,
2819 34,
2820 35,
2821 30,
2822 30,
2823 30,
2824 30,
2825 30,
2826 30,
2827 30
2828 };
2829
2830 uint map9 [64] =
2831 {
2832 0,
2833 1,
2834 2,
2835 3,
2836 4,
2837 5,
2838 6,
2839 7,
2840 8,
2841 8,
2842 8,
2843 8,
2844 8,
2845 8,
2846 8,
2847 8,
2848 9,
2849 10,
2850 11,
2851 12,
2852 13,
2853 14,
2854 15,
2855 16,
2856 17,
2857 17,
2858 17,
2859 17,
2860 17,
2861 17,
2862 17,
2863 17,
2864 18,
2865 19,
2866 20,
2867 21,
2868 22,
2869 23,
2870 24,
2871 25,
2872 26,
2873 26,
2874 26,
2875 26,
2876 26,
2877 26,
2878 26,
2879 26,
2880 27,
2881 28,
2882 29,
2883 30,
2884 31,
2885 32,
2886 33,
2887 34,
2888 35,
2889 35,
2890 35,
2891 35,
2892 35,
2893 35,
2894 35,
2895 35
2896 };
2897
2898
2899
2900
2901
2902 uint ARn = GET_ARN (cpu.cu.IWB);
2903 uint address = SIGNEXT15_18 (GET_OFFSET (cpu.cu.IWB));
2904 word4 reg = (word4) GET_TD (cpu.cu.IWB);
2905
2906
2907
2908
2909
2910
2911
2912 word36 rcnt = getCrAR (cpup, reg);
2913
2914 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "asxbd sz %d r 0%"PRIo64"\r\n", sz, rcnt);
2915
2916
2917 uint r = 0;
2918
2919 if (sz == 1)
2920 r = (uint) (rcnt & MASK24);
2921 else if (sz == 4)
2922 r = (uint) (rcnt & MASK22);
2923 else if (sz == 6)
2924 r = (uint) (rcnt & MASK21);
2925 else if (sz == 9)
2926 r = (uint) (rcnt & MASK21);
2927 else
2928 r = (uint) (rcnt & MASK18);
2929
2930 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "asxbd sz %d ARn 0%o address 0%o reg 0%o r 0%o\r\n", sz, ARn, address, reg, r);
2931
2932
2933
2934
2935
2936
2937 uint augend = 0;
2938 if (GET_A (cpu.cu.IWB))
2939 {
2940
2941 if (sz == 36)
2942 {
2943 augend = cpu.AR[ARn].WORDNO * 36u;
2944 }
2945 else
2946 {
2947 uint bitno = GET_AR_BITNO (ARn);
2948 uint charno = GET_AR_CHAR (ARn);
2949
2950
2951
2952
2953
2954 uint * map;
2955 if (sz == 4)
2956 map = map4;
2957 else if (sz == 6)
2958 map = map6;
2959 else
2960 map = map9;
2961
2962 augend = cpu.AR[ARn].WORDNO * 36u + map [charno * 16 + bitno];
2963 augend = augend % nxbits;
2964 }
2965 }
2966
2967
2968
2969
2970
2971 uint addend = 0;
2972 if (sz == 4)
2973 {
2974
2975
2976 addend = address * 36u + (r * 9) / 2;
2977
2978
2979
2980 if ((! sub) && r % 2)
2981 addend ++;
2982 }
2983 else
2984 addend = address * 36u + r * sz;
2985
2986
2987 addend = addend % nxbits;
2988
2989
2990
2991
2992
2993 uint sum = 0;
2994 if (sub)
2995 {
2996
2997 if (addend > augend)
2998 augend += nxbits;
2999 sum = augend - addend;
3000 }
3001 else
3002 {
3003 sum = augend + addend;
3004 sum %= nxbits;
3005 }
3006
3007 sim_debug (DBG_TRACEEXT|DBG_CAC, & cpu_dev, "asxbd augend 0%o addend 0%o sum 0%o\r\n", augend, addend, sum);
3008
3009
3010
3011
3012
3013 if (sz == 6 || sz == 9)
3014 {
3015 sum = (sum / sz) * sz;
3016 }
3017
3018
3019
3020
3021
3022 cpu.AR [ARn].WORDNO = (word18) (sum / 36u) & AMASK;
3023
3024
3025
3026 if (sz == 36)
3027 {
3028 SET_AR_CHAR_BITNO (ARn, 0, 0);
3029 }
3030 else
3031 {
3032 if (sz == 4)
3033 {
3034 static uint tab [36] [2] =
3035 {
3036
3037 { 0, 0 },
3038 { 0, 0 },
3039 { 0, 0 },
3040 { 0, 0 },
3041 { 0, 0 },
3042
3043 { 0, 5 },
3044 { 0, 5 },
3045 { 0, 5 },
3046 { 0, 5 },
3047
3048 { 1, 0 },
3049 { 1, 0 },
3050 { 1, 0 },
3051 { 1, 0 },
3052 { 1, 0 },
3053
3054 { 1, 5 },
3055 { 1, 5 },
3056 { 1, 5 },
3057 { 1, 5 },
3058
3059 { 2, 0 },
3060 { 2, 0 },
3061 { 2, 0 },
3062 { 2, 0 },
3063 { 2, 0 },
3064
3065 { 2, 5 },
3066 { 2, 5 },
3067 { 2, 5 },
3068 { 2, 5 },
3069
3070 { 3, 0 },
3071 { 3, 0 },
3072 { 3, 0 },
3073 { 3, 0 },
3074 { 3, 0 },
3075
3076 { 3, 5 },
3077 { 3, 5 },
3078 { 3, 5 },
3079 { 3, 5 }
3080 };
3081 uint charno = tab [sum % 36u] [0];
3082 uint bitno = tab [sum % 36u] [1];
3083 SET_AR_CHAR_BITNO (ARn, (word2) charno, (word4) bitno);
3084 }
3085 else
3086 {
3087 uint charno = (sum % 36u) / 9;
3088 uint bitno = sum % 9;
3089 SET_AR_CHAR_BITNO (ARn, (word2) charno, (word4) bitno);
3090 }
3091 }
3092 #if defined(TESTING)
3093 HDBGRegARW (ARn, "asxbd");
3094 #endif
3095 }
3096
3097 void cmpc (cpu_state_t * cpup)
3098 {
3099 EISstruct * e = & cpu.currentEISinstruction;
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125 fault_ipr_subtype_ mod_fault = 0;
3126
3127 #if !defined(EIS_SETUP)
3128 setupOperandDescriptor (cpup, 1, &mod_fault);
3129 setupOperandDescriptor (cpup, 2, &mod_fault);
3130 #endif
3131 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
3132 parseAlphanumericOperandDescriptor (cpup, 2, 1, false, &mod_fault);
3133
3134 L68_ (
3135
3136 if (mod_fault)
3137 {
3138 doFault (FAULT_IPR,
3139 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3140 "Illegal modifier");
3141 }
3142 )
3143
3144
3145 if (IWB_IRODD & 0000600000000)
3146 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "cmpc 9-10 MBZ");
3147
3148
3149 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
3150 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "cmpc op1 23 MBZ");
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164 DPS8M_ (
3165
3166 if (mod_fault)
3167 {
3168 doFault (FAULT_IPR,
3169 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3170 "Illegal modifier");
3171 }
3172 )
3173
3174 word9 fill = getbits36_9 (cpu.cu.IWB, 0);
3175
3176 SET_I_ZERO;
3177 SET_I_CARRY;
3178
3179 PNL (L68_ (if (max (e->N1, e->N2) < 128)
3180 DU_CYCLE_FLEN_128;))
3181
3182 for (; cpu.du.CHTALLY < min (e->N1, e->N2); cpu.du.CHTALLY ++)
3183 {
3184 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA1));
3185 word9 c1 = EISget469 (cpup, 1, cpu.du.CHTALLY);
3186 word9 c2 = EISget469 (cpup, 2, cpu.du.CHTALLY);
3187 sim_debug (DBG_TRACEEXT, & cpu_dev, "cmpc tally %d c1 %03o c2 %03o\r\n", cpu.du.CHTALLY, c1, c2);
3188 if (c1 != c2)
3189 {
3190 CLR_I_ZERO;
3191 SC_I_CARRY (c1 > c2);
3192 cleanupOperandDescriptor (cpup, 1);
3193 cleanupOperandDescriptor (cpup, 2);
3194 return;
3195 }
3196 }
3197
3198 if (e -> N1 < e -> N2)
3199 {
3200 for( ; cpu.du.CHTALLY < e->N2; cpu.du.CHTALLY ++)
3201 {
3202 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA1));
3203 word9 c1 = fill;
3204 word9 c2 = EISget469 (cpup, 2, cpu.du.CHTALLY);
3205
3206 if (c1 != c2)
3207 {
3208 CLR_I_ZERO;
3209 SC_I_CARRY (c1 > c2);
3210 cleanupOperandDescriptor (cpup, 1);
3211 cleanupOperandDescriptor (cpup, 2);
3212 return;
3213 }
3214 }
3215 }
3216 else if (e->N1 > e->N2)
3217 {
3218 for ( ; cpu.du.CHTALLY < e->N1; cpu.du.CHTALLY ++)
3219 {
3220 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA1));
3221 word9 c1 = EISget469 (cpup, 1, cpu.du.CHTALLY);
3222 word9 c2 = fill;
3223
3224 if (c1 != c2)
3225 {
3226 CLR_I_ZERO;
3227 SC_I_CARRY (c1 > c2);
3228 cleanupOperandDescriptor (cpup, 1);
3229 cleanupOperandDescriptor (cpup, 2);
3230 return;
3231 }
3232 }
3233 }
3234
3235 cleanupOperandDescriptor (cpup, 1);
3236 cleanupOperandDescriptor (cpup, 2);
3237 }
3238
3239
3240
3241
3242
3243 void scd (cpu_state_t * cpup)
3244 {
3245 EISstruct * e = & cpu.currentEISinstruction;
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263 fault_ipr_subtype_ mod_fault = 0;
3264
3265 #if !defined(EIS_SETUP)
3266 setupOperandDescriptor (cpup, 1, &mod_fault);
3267 setupOperandDescriptor (cpup, 2, &mod_fault);
3268 setupOperandDescriptorCache (cpup,3);
3269 #endif
3270
3271 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
3272 parseAlphanumericOperandDescriptor (cpup, 2, 1, true, &mod_fault);
3273 parseArgOperandDescriptor (cpup, 3, &mod_fault);
3274
3275 L68_ (
3276
3277 if (mod_fault)
3278 {
3279 doFault (FAULT_IPR,
3280 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3281 "Illegal modifier");
3282 }
3283 )
3284
3285
3286 if (IWB_IRODD & 0777600000000)
3287 {
3288
3289 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "scd 0-10 MBZ");
3290 }
3291
3292
3293 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
3294 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scd op1 23 MBZ");
3295
3296
3297 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
3298 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scd op3 18-28. 30-31 MBZ");
3299
3300 DPS8M_ (
3301
3302 if (mod_fault)
3303 {
3304 doFault (FAULT_IPR,
3305 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3306 "Illegal modifier");
3307 }
3308 )
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320 word9 c1 = 0;
3321 word9 c2 = 0;
3322
3323 if (! (e -> MF2 & MFkID) && ((e -> MF2 & MFkREGMASK) == 3))
3324 {
3325
3326 #if defined(EIS_PTR3)
3327 switch (TA1)
3328 #else
3329 switch (e -> TA1)
3330 #endif
3331 {
3332 case CTA4:
3333 #if defined(EIS_PTR)
3334 c1 = (cpu.du.D2_PTR_W >> 13) & 017;
3335 c2 = (cpu.du.D2_PTR_W >> 9) & 017;
3336 #else
3337 c1 = (e -> ADDR2.address >> 13) & 017;
3338 c2 = (e -> ADDR2.address >> 9) & 017;
3339 #endif
3340 break;
3341
3342 case CTA6:
3343 #if defined(EIS_PTR)
3344 c1 = (cpu.du.D2_PTR_W >> 12) & 077;
3345 c2 = (cpu.du.D2_PTR_W >> 6) & 077;
3346 #else
3347 c1 = (e -> ADDR2.address >> 12) & 077;
3348 c2 = (e -> ADDR2.address >> 6) & 077;
3349 #endif
3350 break;
3351
3352 case CTA9:
3353 #if defined(EIS_PTR)
3354 c1 = (cpu.du.D2_PTR_W >> 9) & 0777;
3355 c2 = (cpu.du.D2_PTR_W ) & 0777;
3356 #else
3357 c1 = (e -> ADDR2.address >> 9) & 0777;
3358 c2 = (e -> ADDR2.address ) & 0777;
3359 #endif
3360 break;
3361 }
3362 }
3363 else
3364 {
3365 c1 = EISget469 (cpup, 2, 0);
3366 c2 = EISget469 (cpup, 2, 1);
3367 }
3368
3369 #if defined(EIS_PTR3)
3370 switch (TA1)
3371 #else
3372 switch (e -> TA1)
3373 #endif
3374 {
3375 case CTA4:
3376 c1 &= 017;
3377 c2 &= 017;
3378 break;
3379
3380 case CTA6:
3381 c1 &= 077;
3382 c2 &= 077;
3383 break;
3384
3385 case CTA9:
3386 c1 &= 0777;
3387 c2 &= 0777;
3388 break;
3389 }
3390
3391 PNL (L68_ (if (e->N1 < 128)
3392 DU_CYCLE_FLEN_128;))
3393
3394 word9 yCharn11;
3395 word9 yCharn12;
3396
3397
3398
3399
3400
3401
3402 bool l68Res = cpu.tweaks.l68_mode && cpu.tweaks.tandd_mode;
3403 if (l68Res && cpu.tanddEISstart > 0)
3404 e -> N1 = cpu.du.CHTALLY + cpu.du.D1_RES;
3405 if (e -> N1)
3406 {
3407 uint limit = e -> N1 - 1;
3408 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY ++)
3409 {
3410 if (l68Res)
3411 cpu.du.D1_RES = (e -> N1 - cpu.du.CHTALLY) & MASK24;
3412 tandd_eis_sample (cpup, cpu.du.CHTALLY, 3);
3413 yCharn11 = EISget469 (cpup, 1, cpu.du.CHTALLY);
3414 yCharn12 = EISget469 (cpup, 1, cpu.du.CHTALLY + 1);
3415 if (yCharn11 == c1 && yCharn12 == c2)
3416 break;
3417 }
3418 SC_I_TALLY (cpu.du.CHTALLY == limit);
3419 }
3420 else
3421 {
3422 SET_I_TALLY;
3423 }
3424
3425
3426 word36 CY3 = setbits36_24 (0, 12, cpu.du.CHTALLY);
3427 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
3428
3429 cleanupOperandDescriptor (cpup, 1);
3430 cleanupOperandDescriptor (cpup, 2);
3431 cleanupOperandDescriptor (cpup, 3);
3432 }
3433
3434
3435
3436
3437
3438 void scdr (cpu_state_t * cpup)
3439 {
3440 EISstruct * e = & cpu.currentEISinstruction;
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458 fault_ipr_subtype_ mod_fault = 0;
3459
3460 #if !defined(EIS_SETUP)
3461 setupOperandDescriptor(cpup, 1, &mod_fault);
3462 setupOperandDescriptor(cpup, 2, &mod_fault);
3463 setupOperandDescriptorCache(cpup,3);
3464 #endif
3465
3466 parseAlphanumericOperandDescriptor(cpup, 1, 1, false, &mod_fault);
3467 parseAlphanumericOperandDescriptor(cpup, 2, 1, true, &mod_fault);
3468 parseArgOperandDescriptor (cpup, 3, &mod_fault);
3469
3470 L68_ (
3471
3472 if (mod_fault)
3473 {
3474 doFault (FAULT_IPR,
3475 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3476 "Illegal modifier");
3477 }
3478 )
3479
3480
3481 if (IWB_IRODD & 0777600000000)
3482 {
3483
3484 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "scdr 0-10 MBZ");
3485 }
3486
3487
3488 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
3489 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scdr op1 23 MBZ");
3490
3491
3492 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
3493 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scdr op3 18-28. 30-31 MBZ");
3494
3495 DPS8M_ (
3496
3497 if (mod_fault)
3498 {
3499 doFault (FAULT_IPR,
3500 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3501 "Illegal modifier");
3502 }
3503 )
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515 word9 c1 = 0;
3516 word9 c2 = 0;
3517
3518 if (! (e -> MF2 & MFkID) && ((e -> MF2 & MFkREGMASK) == 3))
3519 {
3520
3521 #if defined(EIS_PTR3)
3522 switch (TA1)
3523 #else
3524 switch (e -> TA1)
3525 #endif
3526 {
3527 case CTA4:
3528 #if defined(EIS_PTR)
3529 c1 = (cpu.du.D2_PTR_W >> 13) & 017;
3530 c2 = (cpu.du.D2_PTR_W >> 9) & 017;
3531 #else
3532 c1 = (e -> ADDR2.address >> 13) & 017;
3533 c2 = (e -> ADDR2.address >> 9) & 017;
3534 #endif
3535 break;
3536
3537 case CTA6:
3538 #if defined(EIS_PTR)
3539 c1 = (cpu.du.D2_PTR_W >> 12) & 077;
3540 c2 = (cpu.du.D2_PTR_W >> 6) & 077;
3541 #else
3542 c1 = (e -> ADDR2.address >> 12) & 077;
3543 c2 = (e -> ADDR2.address >> 6) & 077;
3544 #endif
3545 break;
3546
3547 case CTA9:
3548 #if defined(EIS_PTR)
3549 c1 = (cpu.du.D2_PTR_W >> 9) & 0777;
3550 c2 = (cpu.du.D2_PTR_W ) & 0777;
3551 #else
3552 c1 = (e -> ADDR2.address >> 9) & 0777;
3553 c2 = (e -> ADDR2.address ) & 0777;
3554 #endif
3555 break;
3556 }
3557 }
3558 else
3559 {
3560 c1 = EISget469 (cpup, 2, 0);
3561 c2 = EISget469 (cpup, 2, 1);
3562 }
3563
3564 #if defined(EIS_PTR3)
3565 switch (TA1)
3566 #else
3567 switch (e -> TA1)
3568 #endif
3569 {
3570 case CTA4:
3571 c1 &= 017;
3572 c2 &= 017;
3573 break;
3574
3575 case CTA6:
3576 c1 &= 077;
3577 c2 &= 077;
3578 break;
3579
3580 case CTA9:
3581 c1 &= 0777;
3582 c2 &= 0777;
3583 break;
3584 }
3585
3586 word9 yCharn11;
3587 word9 yCharn12;
3588
3589 PNL (L68_ (if (e->N1 < 128)
3590 DU_CYCLE_FLEN_128;))
3591
3592 if (e -> N1)
3593 {
3594 uint limit = e -> N1 - 1;
3595
3596 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY ++)
3597 {
3598 tandd_eis_sample (cpup, cpu.du.CHTALLY, 3);
3599 yCharn11 = EISget469 (cpup, 1, limit - cpu.du.CHTALLY - 1);
3600 yCharn12 = EISget469 (cpup, 1, limit - cpu.du.CHTALLY);
3601
3602 if (yCharn11 == c1 && yCharn12 == c2)
3603 break;
3604 }
3605 SC_I_TALLY (cpu.du.CHTALLY == limit);
3606 }
3607 else
3608 {
3609 SET_I_TALLY;
3610 }
3611
3612
3613 word36 CY3 = setbits36_24 (0, 12, cpu.du.CHTALLY);
3614 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
3615
3616 cleanupOperandDescriptor (cpup, 1);
3617 cleanupOperandDescriptor (cpup, 2);
3618 cleanupOperandDescriptor (cpup, 3);
3619 }
3620
3621
3622
3623
3624
3625 void scm (cpu_state_t * cpup)
3626 {
3627 EISstruct * e = & cpu.currentEISinstruction;
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661 fault_ipr_subtype_ mod_fault = 0;
3662
3663 #if !defined(EIS_SETUP)
3664 setupOperandDescriptor (cpup, 1, &mod_fault);
3665 setupOperandDescriptor (cpup, 2, &mod_fault);
3666 setupOperandDescriptorCache (cpup,3);
3667 #endif
3668
3669 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
3670 parseAlphanumericOperandDescriptor (cpup, 2, 1, true, &mod_fault);
3671 parseArgOperandDescriptor (cpup, 3, &mod_fault);
3672
3673 L68_ (
3674
3675 if (mod_fault)
3676 {
3677 doFault (FAULT_IPR,
3678 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3679 "Illegal modifier");
3680 }
3681 )
3682
3683
3684 if (IWB_IRODD & 0000600000000)
3685 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "scm 9-10 MBZ");
3686
3687
3688 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
3689 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scm op1 23 MBZ");
3690
3691
3692 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
3693 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scm op3 18-28, 39-31 MBZ");
3694
3695 DPS8M_ (
3696
3697 if (mod_fault)
3698 {
3699 doFault (FAULT_IPR,
3700 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3701 "Illegal modifier");
3702 }
3703 )
3704
3705
3706
3707
3708
3709
3710 uint mask = (uint) getbits36_9 (cpu.cu.IWB, 0);
3711
3712
3713
3714
3715
3716
3717
3718 word9 ctest = 0;
3719 if (! (e -> MF2 & MFkID) && ((e -> MF2 & MFkREGMASK) == 3))
3720 {
3721 word18 duo = GETHI (e -> OP2);
3722
3723 #if defined(EIS_PTR3)
3724 switch (TA1)
3725 #else
3726 switch (e -> TA1)
3727 #endif
3728 {
3729 case CTA4:
3730 ctest = (duo >> 13) & 017;
3731 break;
3732 case CTA6:
3733 ctest = (duo >> 12) & 077;
3734 break;
3735 case CTA9:
3736 ctest = (duo >> 9) & 0777;
3737 break;
3738 }
3739 }
3740 else
3741 {
3742 ctest = EISget469 (cpup, 2, 0);
3743 }
3744
3745 #if defined(EIS_PTR3)
3746 switch (TA1)
3747 #else
3748 switch (e -> TA1)
3749 #endif
3750 {
3751 case CTA4:
3752 ctest &= 017;
3753 break;
3754 case CTA6:
3755 ctest &= 077;
3756 break;
3757 case CTA9:
3758 ctest &= 0777;
3759 }
3760
3761 PNL (L68_ (if (e->N1 < 128)
3762 DU_CYCLE_FLEN_128;))
3763
3764 uint limit = e -> N1;
3765
3766 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY ++)
3767 {
3768 tandd_eis_sample (cpup, cpu.du.CHTALLY, 3);
3769 word9 yCharn1 = EISget469 (cpup, 1, cpu.du.CHTALLY);
3770 word9 c = ((~mask) & (yCharn1 ^ ctest)) & 0777;
3771 if (c == 0)
3772 {
3773
3774
3775
3776 break;
3777 }
3778 }
3779
3780 word36 CY3 = setbits36_24 (0, 12, cpu.du.CHTALLY);
3781
3782 SC_I_TALLY (cpu.du.CHTALLY == limit);
3783
3784 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
3785
3786 cleanupOperandDescriptor (cpup, 1);
3787 cleanupOperandDescriptor (cpup, 2);
3788 cleanupOperandDescriptor (cpup, 3);
3789 }
3790
3791
3792
3793
3794 void scmr (cpu_state_t * cpup)
3795 {
3796 EISstruct * e = & cpu.currentEISinstruction;
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830 fault_ipr_subtype_ mod_fault = 0;
3831
3832 #if !defined(EIS_SETUP)
3833 setupOperandDescriptor (cpup, 1, &mod_fault);
3834 setupOperandDescriptor (cpup, 2, &mod_fault);
3835 setupOperandDescriptorCache (cpup,3);
3836 #endif
3837
3838 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
3839 parseAlphanumericOperandDescriptor (cpup, 2, 1, true, &mod_fault);
3840 parseArgOperandDescriptor (cpup, 3, &mod_fault);
3841
3842 L68_ (
3843
3844 if (mod_fault)
3845 {
3846 doFault (FAULT_IPR,
3847 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3848 "Illegal modifier");
3849 }
3850 )
3851
3852
3853 if (IWB_IRODD & 0000600000000)
3854 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "scmr 9-10 MBZ");
3855
3856
3857 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
3858 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scmr op1 23 MBZ");
3859
3860
3861
3862
3863
3864
3865 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
3866 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "scmr op3 18-28, 39-31 MBZ");
3867
3868 DPS8M_ (
3869
3870 if (mod_fault)
3871 {
3872 doFault (FAULT_IPR,
3873 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
3874 "Illegal modifier");
3875 }
3876 )
3877
3878
3879
3880
3881
3882
3883 uint mask = (uint) getbits36_9 (cpu.cu.IWB, 0);
3884
3885
3886
3887
3888
3889
3890
3891 word9 ctest = 0;
3892 if (! (e -> MF2 & MFkID) && ((e -> MF2 & MFkREGMASK) == 3))
3893 {
3894 word18 duo = GETHI (e -> OP2);
3895
3896 #if defined(EIS_PTR3)
3897 switch (TA1)
3898 #else
3899 switch (e -> TA1)
3900 #endif
3901 {
3902 case CTA4:
3903 ctest = (duo >> 13) & 017;
3904 break;
3905 case CTA6:
3906 ctest = (duo >> 12) & 077;
3907 break;
3908 case CTA9:
3909 ctest = (duo >> 9) & 0777;
3910 break;
3911 }
3912 }
3913 else
3914 {
3915 ctest = EISget469 (cpup, 2, 0);
3916 }
3917
3918 #if defined(EIS_PTR3)
3919 switch (TA1)
3920 #else
3921 switch (e -> TA1)
3922 #endif
3923 {
3924 case CTA4:
3925 ctest &= 017;
3926 break;
3927 case CTA6:
3928 ctest &= 077;
3929 break;
3930 case CTA9:
3931 ctest &= 0777;
3932 }
3933
3934 PNL (L68_ (if (e->N1 < 128)
3935 DU_CYCLE_FLEN_128;))
3936
3937 uint limit = e -> N1;
3938 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY ++)
3939 {
3940 tandd_eis_sample (cpup, cpu.du.CHTALLY, 3);
3941 word9 yCharn1 = EISget469 (cpup, 1, limit - cpu.du.CHTALLY - 1);
3942 word9 c = ((~mask) & (yCharn1 ^ ctest)) & 0777;
3943 if (c == 0)
3944 {
3945
3946
3947
3948 break;
3949 }
3950 }
3951
3952 word36 CY3 = setbits36_24 (0, 12, cpu.du.CHTALLY);
3953
3954 SC_I_TALLY (cpu.du.CHTALLY == limit);
3955
3956 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
3957
3958 cleanupOperandDescriptor (cpup, 1);
3959 cleanupOperandDescriptor (cpup, 2);
3960 cleanupOperandDescriptor (cpup, 3);
3961 }
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988 static word9 xlate (cpu_state_t * cpup, EISaddr * xlatTbl, uint dstTA, uint c)
3989 {
3990 uint idx = (c / 4) & 0177;
3991 word36 entry = EISReadIdx(cpup, xlatTbl, idx);
3992
3993 uint pos9 = c % 4;
3994 word9 cout = GETBYTE (entry, pos9);
3995 switch (dstTA)
3996 {
3997 case CTA4:
3998 return cout & 017;
3999 case CTA6:
4000 return cout & 077;
4001 case CTA9:
4002 return cout;
4003 }
4004 return 0;
4005 }
4006
4007 void tct (cpu_state_t * cpup)
4008 {
4009 EISstruct * e = & cpu.currentEISinstruction;
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032 fault_ipr_subtype_ mod_fault = 0;
4033
4034 #if !defined(EIS_SETUP)
4035 setupOperandDescriptor (cpup, 1, &mod_fault);
4036 setupOperandDescriptorCache (cpup,2);
4037 setupOperandDescriptorCache (cpup,3);
4038 #endif
4039
4040 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
4041 parseArgOperandDescriptor (cpup, 2, &mod_fault);
4042 parseArgOperandDescriptor (cpup, 3, &mod_fault);
4043
4044 L68_ (
4045
4046 if (mod_fault)
4047 {
4048 doFault (FAULT_IPR,
4049 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4050 "Illegal modifier");
4051 }
4052 )
4053
4054
4055 if (IWB_IRODD & 0777777000000)
4056 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "tct 0-17 MBZ");
4057
4058
4059 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
4060 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tct op1 23 MBZ");
4061
4062
4063 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000777660)
4064 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tct op2 18-28, 39-31 MBZ");
4065
4066
4067 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
4068 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tct op3 18-28, 39-31 MBZ");
4069
4070 DPS8M_ (
4071
4072 if (mod_fault)
4073 {
4074 doFault (FAULT_IPR,
4075 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4076 "Illegal modifier");
4077 }
4078 )
4079
4080 #if defined(EIS_PTR3)
4081 sim_debug (DBG_TRACEEXT, & cpu_dev,
4082 "TCT CN1: %d TA1: %d\r\n", e -> CN1, TA1);
4083 #else
4084 sim_debug (DBG_TRACEEXT, & cpu_dev,
4085 "TCT CN1: %d TA1: %d\r\n", e -> CN1, e -> TA1);
4086 #endif
4087
4088 uint srcSZ = 0;
4089
4090 #if defined(EIS_PTR3)
4091 switch (TA1)
4092 #else
4093 switch (e -> TA1)
4094 #endif
4095 {
4096 case CTA4:
4097 srcSZ = 4;
4098 break;
4099 case CTA6:
4100 srcSZ = 6;
4101 break;
4102 case CTA9:
4103 srcSZ = 9;
4104 break;
4105 }
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146 word36 CY3 = 0;
4147
4148 sim_debug (DBG_TRACEEXT, & cpu_dev,
4149 "TCT N1 %d\r\n", e -> N1);
4150
4151 PNL (L68_ (if (e->N1 < 128)
4152 DU_CYCLE_FLEN_128;))
4153
4154 for ( ; cpu.du.CHTALLY < e -> N1; cpu.du.CHTALLY ++)
4155 {
4156 tandd_eis_sample (cpup, cpu.du.CHTALLY, 2);
4157 word9 c = EISget469 (cpup, 1, cpu.du.CHTALLY);
4158
4159 uint m = 0;
4160
4161 switch (srcSZ)
4162 {
4163 case 4:
4164 m = c & 017;
4165 break;
4166 case 6:
4167 m = c & 077;
4168 break;
4169 case 9:
4170 m = c;
4171 break;
4172 }
4173
4174 word9 cout = xlate (cpup, &e->ADDR2, CTA9, m);
4175
4176 sim_debug (DBG_TRACEEXT, & cpu_dev,
4177 "TCT c %03o %c cout %03o %c\r\n",
4178 m, isprint ((int) m) ? '?' : (char) m,
4179 cout, isprint ((int) cout) ? '?' : (char) cout);
4180
4181 if (cout)
4182 {
4183
4184 CY3 = setbits36_9 (0, 0, cout);
4185 break;
4186 }
4187 }
4188
4189 SC_I_TALLY (cpu.du.CHTALLY == e -> N1);
4190
4191
4192 putbits36_24 (& CY3, 12, cpu.du.CHTALLY);
4193 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
4194
4195 cleanupOperandDescriptor (cpup, 1);
4196 cleanupOperandDescriptor (cpup, 2);
4197 cleanupOperandDescriptor (cpup, 3);
4198 }
4199
4200 void tctr (cpu_state_t * cpup)
4201 {
4202 EISstruct * e = & cpu.currentEISinstruction;
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228 fault_ipr_subtype_ mod_fault = 0;
4229
4230 #if !defined(EIS_SETUP)
4231 setupOperandDescriptor (cpup, 1, &mod_fault);
4232 setupOperandDescriptorCache (cpup,2);
4233 setupOperandDescriptorCache (cpup,3);
4234 #endif
4235
4236 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
4237 parseArgOperandDescriptor (cpup, 2, &mod_fault);
4238 parseArgOperandDescriptor (cpup, 3, &mod_fault);
4239
4240 L68_ (
4241
4242 if (mod_fault)
4243 {
4244 doFault (FAULT_IPR,
4245 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4246 "Illegal modifier");
4247 }
4248 )
4249
4250
4251 if (IWB_IRODD & 0777777000000)
4252 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "tctr 0-17 MBZ");
4253
4254
4255 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
4256 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tctr op1 23 MBZ");
4257
4258
4259 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000777660)
4260 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tctr op2 18-28, 39-31 MBZ");
4261
4262
4263 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777660)
4264 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "tctr op3 18-28, 39-31 MBZ");
4265
4266 DPS8M_ (
4267
4268 if (mod_fault)
4269 {
4270 doFault (FAULT_IPR,
4271 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4272 "Illegal modifier");
4273 }
4274 )
4275
4276 #if defined(EIS_PTR3)
4277 sim_debug (DBG_TRACEEXT, & cpu_dev,
4278 "TCTR CN1: %d TA1: %d\r\n", e -> CN1, TA1);
4279 #else
4280 sim_debug (DBG_TRACEEXT, & cpu_dev,
4281 "TCTR CN1: %d TA1: %d\r\n", e -> CN1, e -> TA1);
4282 #endif
4283
4284 uint srcSZ = 0;
4285
4286 #if defined(EIS_PTR3)
4287 switch (TA1)
4288 #else
4289 switch (e -> TA1)
4290 #endif
4291 {
4292 case CTA4:
4293 srcSZ = 4;
4294 break;
4295 case CTA6:
4296 srcSZ = 6;
4297 break;
4298 case CTA9:
4299 srcSZ = 9;
4300 break;
4301 }
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342 word36 CY3 = 0;
4343
4344 sim_debug (DBG_TRACEEXT, & cpu_dev,
4345 "TCT N1 %d\r\n", e -> N1);
4346
4347 PNL (L68_ (if (e->N1 < 128)
4348 DU_CYCLE_FLEN_128;))
4349
4350 uint limit = e -> N1;
4351 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY ++)
4352 {
4353 tandd_eis_sample (cpup, cpu.du.CHTALLY, 2);
4354 word9 c = EISget469 (cpup, 1, limit - cpu.du.CHTALLY - 1);
4355
4356 uint m = 0;
4357
4358 switch (srcSZ)
4359 {
4360 case 4:
4361 m = c & 017;
4362 break;
4363 case 6:
4364 m = c & 077;
4365 break;
4366 case 9:
4367 m = c;
4368 break;
4369 }
4370
4371 word9 cout = xlate (cpup, &e->ADDR2, CTA9, m);
4372
4373 sim_debug (DBG_TRACEEXT, & cpu_dev,
4374 "TCT c %03o %c cout %03o %c\r\n",
4375 m, isprint ((int) m) ? '?' : (char) m,
4376 cout, isprint ((int) cout) ? '?' : (char) cout);
4377
4378 if (cout)
4379 {
4380
4381 CY3 = setbits36_9 (0, 0, cout);
4382 break;
4383 }
4384 }
4385
4386 SC_I_TALLY (cpu.du.CHTALLY == e -> N1);
4387
4388
4389 putbits36_24 (& CY3, 12, cpu.du.CHTALLY);
4390 EISWriteIdx (cpup, & e -> ADDR3, 0, CY3, true);
4391
4392 cleanupOperandDescriptor (cpup, 1);
4393 cleanupOperandDescriptor (cpup, 2);
4394 cleanupOperandDescriptor (cpup, 3);
4395 }
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433 static bool isGBCDOvp (uint c, bool * isNeg)
4434 {
4435 if (c & 020)
4436 {
4437 * isNeg = false;
4438 return true;
4439 }
4440 if (c & 040)
4441 {
4442 * isNeg = true;
4443 return true;
4444 }
4445 return false;
4446 }
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459 void mlr (cpu_state_t * cpup)
4460 {
4461 EISstruct * e = & cpu.currentEISinstruction;
4462
4463
4464
4465
4466
4467
4468
4469 fault_ipr_subtype_ mod_fault = 0;
4470
4471 #if !defined(EIS_SETUP)
4472 setupOperandDescriptor (cpup, 1, &mod_fault);
4473 setupOperandDescriptor (cpup, 2, &mod_fault);
4474
4475 #endif
4476
4477 parseAlphanumericOperandDescriptor(cpup, 1, 1, false, &mod_fault);
4478 parseAlphanumericOperandDescriptor(cpup, 2, 2, false, &mod_fault);
4479
4480 L68_ (
4481
4482 if (mod_fault)
4483 {
4484 doFault (FAULT_IPR,
4485 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4486 "Illegal modifier");
4487 }
4488 )
4489
4490
4491 if (IWB_IRODD & 0000200000000)
4492 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mlr 10 MBZ");
4493
4494
4495 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
4496 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mlr op1 23 MBZ");
4497
4498
4499 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000010000)
4500 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mlr op2 23 MBZ");
4501
4502 DPS8M_ (
4503
4504 if (mod_fault)
4505 {
4506 doFault (FAULT_IPR,
4507 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4508 "Illegal modifier");
4509 }
4510 )
4511
4512 int srcSZ = 0, dstSZ = 0;
4513
4514 #if defined(EIS_PTR3)
4515 switch (TA1)
4516 #else
4517 switch (e -> TA1)
4518 #endif
4519 {
4520 case CTA4:
4521 srcSZ = 4;
4522 break;
4523 case CTA6:
4524 srcSZ = 6;
4525 break;
4526 case CTA9:
4527 srcSZ = 9;
4528 break;
4529 }
4530
4531 #if defined(EIS_PTR3)
4532 switch (TA2)
4533 #else
4534 switch (e -> TA2)
4535 #endif
4536 {
4537 case CTA4:
4538 dstSZ = 4;
4539 break;
4540 case CTA6:
4541 dstSZ = 6;
4542 break;
4543 case CTA9:
4544 dstSZ = 9;
4545 break;
4546 }
4547
4548 word1 T = getbits36_1 (cpu.cu.IWB, 9);
4549
4550 word9 fill = getbits36_9 (cpu.cu.IWB, 0);
4551 word9 fillT = fill;
4552
4553
4554 switch (dstSZ)
4555 {
4556 case 4:
4557 fillT = fill & 017;
4558 break;
4559 case 6:
4560 fillT = fill & 077;
4561 break;
4562 }
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586 PNL (L68_ (if (max (e->N1, e->N2) < 128)
4587 DU_CYCLE_FLEN_128;))
4588
4589 #if defined(EIS_PTR3)
4590 bool ovp = (e -> N1 < e -> N2) && (fill & 0400) && (TA1 == 1) &&
4591 (TA2 == 2);
4592 #else
4593 bool ovp = (e -> N1 < e -> N2) && (fill & 0400) && (e -> TA1 == 1) &&
4594 (e -> TA2 == 2);
4595 #endif
4596
4597 bool isNeg = false;
4598
4599
4600
4601 #if defined(EIS_PTR3)
4602 sim_debug (DBG_TRACEEXT, & cpu_dev,
4603 "MLR TALLY %u TA1 %u TA2 %u N1 %u N2 %u CN1 %u CN2 %u\r\n",
4604 cpu.du.CHTALLY, TA1, TA2, e -> N1, e -> N2, e -> CN1, e -> CN2);
4605 #else
4606 sim_debug (DBG_TRACEEXT, & cpu_dev,
4607 "MLR TALLY %u TA1 %u TA2 %u N1 %u N2 %u CN1 %u CN2 %u\r\n",
4608 cpu.du.CHTALLY, e -> TA1, e -> TA2, e -> N1, e -> N2, e -> CN1, e -> CN2);
4609 #endif
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623 if ((cpu.du.CHTALLY % PGSZ) == 0 &&
4624 #if defined(EIS_PTR3)
4625 TA1 == CTA9 &&
4626 TA2 == CTA9 &&
4627 #else
4628 e -> TA1 == CTA9 &&
4629 e -> TA2 == CTA9 &&
4630 #endif
4631 (e -> N1 % (PGSZ * 4)) == 0 &&
4632 e -> N2 == e -> N1 &&
4633 e -> CN1 == 0 &&
4634 e -> CN2 == 0 &&
4635 #if defined(EIS_PTR)
4636 (cpu.du.D1_PTR_W & PGMK) == 0 &&
4637 (cpu.du.D2_PTR_W & PGMK) == 0)
4638 #else
4639 (e -> ADDR1.address & PGMK) == 0 &&
4640 (e -> ADDR2.address & PGMK) == 0)
4641 #endif
4642 {
4643 sim_debug (DBG_TRACEEXT, & cpu_dev, "MLR special case #3\r\n");
4644 while (cpu.du.CHTALLY < e -> N1)
4645 {
4646 word36 pg [PGSZ];
4647 EISReadPage (cpup, & e -> ADDR1, cpu.du.CHTALLY / 4, pg);
4648 EISWritePage (cpup, & e -> ADDR2, cpu.du.CHTALLY / 4, pg);
4649 cpu.du.CHTALLY += PGSZ * 4;
4650 }
4651 cleanupOperandDescriptor (cpup, 1);
4652 cleanupOperandDescriptor (cpup, 2);
4653
4654
4655 CLR_I_TRUNC;
4656 return;
4657 }
4658
4659
4660
4661
4662
4663 if ((cpu.du.CHTALLY % PGSZ) == 0 &&
4664 #if defined(EIS_PTR3)
4665 TA1 == CTA9 &&
4666 TA2 == CTA9 &&
4667 #else
4668 e -> TA1 == CTA9 &&
4669 e -> TA2 == CTA9 &&
4670 #endif
4671 e -> N1 == 0 &&
4672 (e -> N2 % (PGSZ * 4)) == 0 &&
4673 e -> CN1 == 0 &&
4674 e -> CN2 == 0 &&
4675 #if defined(EIS_PTR)
4676 (cpu.du.D1_PTR_W & PGMK) == 0 &&
4677 (cpu.du.D2_PTR_W& PGMK) == 0)
4678 #else
4679 (e -> ADDR1.address & PGMK) == 0 &&
4680 (e -> ADDR2.address & PGMK) == 0)
4681 #endif
4682 {
4683 sim_debug (DBG_TRACEEXT, & cpu_dev, "MLR special case #4\r\n");
4684 word36 pg [PGSZ];
4685 if (fill)
4686 {
4687 word36 w = (word36) fill | ((word36) fill << 9) | ((word36) fill << 18) | ((word36) fill << 27);
4688 for (uint i = 0; i < PGSZ; i ++)
4689 pg [i] = w;
4690 }
4691 else
4692 {
4693 (void)memset (pg, 0, sizeof (pg));
4694 }
4695 while (cpu.du.CHTALLY < e -> N2)
4696 {
4697 EISWritePage (cpup, & e -> ADDR2, cpu.du.CHTALLY / 4, pg);
4698 cpu.du.CHTALLY += PGSZ * 4;
4699 }
4700 cleanupOperandDescriptor (cpup, 1);
4701 cleanupOperandDescriptor (cpup, 2);
4702
4703
4704 CLR_I_TRUNC;
4705 return;
4706 }
4707
4708
4709
4710
4711 #if defined(EIS_PTR3)
4712 if (TA1 == CTA9 &&
4713 TA2 == CTA9 &&
4714 #else
4715 if (e -> TA1 == CTA9 &&
4716 e -> TA2 == CTA9 &&
4717 #endif
4718 e -> N1 % 4 == 0 &&
4719 e -> N2 == e -> N1 &&
4720 e -> CN1 == 0 &&
4721 e -> CN2 == 0)
4722 {
4723 sim_debug (DBG_TRACEEXT, & cpu_dev, "MLR special case #1\r\n");
4724 for ( ; cpu.du.CHTALLY < e -> N2; cpu.du.CHTALLY += 4)
4725 {
4726 tandd_eis_sample (cpup, cpu.du.CHTALLY, 4);
4727 uint n = cpu.du.CHTALLY / 4;
4728 word36 w = EISReadIdx (cpup, & e -> ADDR1, n);
4729 EISWriteIdx (cpup, & e -> ADDR2, n, w, true);
4730 }
4731 cleanupOperandDescriptor (cpup, 1);
4732 cleanupOperandDescriptor (cpup, 2);
4733
4734
4735 CLR_I_TRUNC;
4736 return;
4737 }
4738
4739
4740
4741
4742 #if defined(EIS_PTR3)
4743 if (TA1 == CTA9 &&
4744 TA2 == CTA9 &&
4745 #else
4746 if (e -> TA1 == CTA9 &&
4747 e -> TA2 == CTA9 &&
4748 #endif
4749 e -> N1 == 0 &&
4750 e -> N2 % 4 == 0 &&
4751 e -> CN1 == 0 &&
4752 e -> CN2 == 0)
4753 {
4754 sim_debug (DBG_TRACEEXT, & cpu_dev, "MLR special case #2\r\n");
4755 word36 w = (word36) fill | ((word36) fill << 9) | ((word36) fill << 18) | ((word36) fill << 27);
4756 for ( ; cpu.du.CHTALLY < e -> N2; cpu.du.CHTALLY += 4)
4757 {
4758 tandd_eis_sample (cpup, cpu.du.CHTALLY, 4);
4759 uint n = cpu.du.CHTALLY / 4;
4760 EISWriteIdx (cpup, & e -> ADDR2, n, w, true);
4761 }
4762 cleanupOperandDescriptor (cpup, 1);
4763 cleanupOperandDescriptor (cpup, 2);
4764
4765
4766 CLR_I_TRUNC;
4767 return;
4768 }
4769
4770 uint tdPer = TDPER (e -> TA2);
4771 for ( ; cpu.du.CHTALLY < min (e->N1, e->N2); cpu.du.CHTALLY ++)
4772 {
4773 tandd_eis_sample (cpup, cpu.du.CHTALLY, tdPer);
4774 word9 c = EISget469 (cpup, 1, cpu.du.CHTALLY);
4775 word9 cout = 0;
4776
4777 #if defined(EIS_PTR3)
4778 if (TA1 == TA2)
4779 #else
4780 if (e -> TA1 == e -> TA2)
4781 #endif
4782 EISput469 (cpup, 2, cpu.du.CHTALLY, c);
4783 else
4784 {
4785
4786
4787
4788 cout = c;
4789 switch (srcSZ)
4790 {
4791 case 6:
4792 switch(dstSZ)
4793 {
4794 case 4:
4795 cout = c & 017;
4796 break;
4797 case 9:
4798 break;
4799 }
4800 break;
4801 case 9:
4802 switch(dstSZ)
4803 {
4804 case 4:
4805 cout = c & 017;
4806 break;
4807 case 6:
4808 cout = c & 077;
4809 break;
4810 }
4811 break;
4812 }
4813
4814
4815
4816
4817
4818
4819
4820 if (ovp && (cpu.du.CHTALLY == e -> N1 - 1))
4821 {
4822
4823
4824 isGBCDOvp (c, & isNeg);
4825 }
4826 EISput469 (cpup, 2, cpu.du.CHTALLY, cout);
4827 }
4828 }
4829
4830
4831
4832
4833
4834
4835
4836 if (e -> N1 < e -> N2)
4837 {
4838 for ( ; cpu.du.CHTALLY < e -> N2 ; cpu.du.CHTALLY ++)
4839 {
4840 tandd_eis_sample (cpup, cpu.du.CHTALLY, tdPer);
4841
4842 if (ovp && (cpu.du.CHTALLY == e -> N2 - 1))
4843 {
4844 if (isNeg)
4845 EISput469 (cpup, 2, cpu.du.CHTALLY, 015);
4846 else
4847 EISput469 (cpup, 2, cpu.du.CHTALLY, 014);
4848 }
4849 else
4850 EISput469 (cpup, 2, cpu.du.CHTALLY, fillT);
4851 }
4852 }
4853 cleanupOperandDescriptor (cpup, 1);
4854 cleanupOperandDescriptor (cpup, 2);
4855
4856 if (e -> N1 > e -> N2)
4857 {
4858 SET_I_TRUNC;
4859 if (T && ! TST_I_OMASK)
4860 doFault (FAULT_OFL, fst_zero, "mlr truncation fault");
4861 }
4862 else
4863 CLR_I_TRUNC;
4864 }
4865
4866 void mrl (cpu_state_t * cpup)
4867 {
4868 EISstruct * e = & cpu.currentEISinstruction;
4869
4870
4871
4872
4873
4874
4875
4876 fault_ipr_subtype_ mod_fault = 0;
4877
4878 #if !defined(EIS_SETUP)
4879 setupOperandDescriptor (cpup, 1, &mod_fault);
4880 setupOperandDescriptor (cpup, 2, &mod_fault);
4881
4882 #endif
4883
4884 parseAlphanumericOperandDescriptor(cpup, 1, 1, false, &mod_fault);
4885 parseAlphanumericOperandDescriptor(cpup, 2, 2, false, &mod_fault);
4886
4887 L68_ (
4888
4889 if (mod_fault)
4890 {
4891 doFault (FAULT_IPR,
4892 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4893 "Illegal modifier");
4894 }
4895 )
4896
4897
4898 if (IWB_IRODD & 0000200000000)
4899 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mrl 10 MBZ");
4900
4901
4902 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
4903 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mrl op1 23 MBZ");
4904
4905
4906 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000010000)
4907 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mrl op2 23 MBZ");
4908
4909 DPS8M_ (
4910
4911 if (mod_fault)
4912 {
4913 doFault (FAULT_IPR,
4914 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
4915 "Illegal modifier");
4916 }
4917 )
4918
4919 int srcSZ = 0, dstSZ = 0;
4920
4921 #if defined(EIS_PTR3)
4922 switch (TA1)
4923 #else
4924 switch (e -> TA1)
4925 #endif
4926 {
4927 case CTA4:
4928 srcSZ = 4;
4929 break;
4930 case CTA6:
4931 srcSZ = 6;
4932 break;
4933 case CTA9:
4934 srcSZ = 9;
4935 break;
4936 }
4937
4938 #if defined(EIS_PTR3)
4939 switch (TA2)
4940 #else
4941 switch (e -> TA2)
4942 #endif
4943 {
4944 case CTA4:
4945 dstSZ = 4;
4946 break;
4947 case CTA6:
4948 dstSZ = 6;
4949 break;
4950 case CTA9:
4951 dstSZ = 9;
4952 break;
4953 }
4954
4955 word1 T = getbits36_1 (cpu.cu.IWB, 9);
4956
4957 word9 fill = getbits36_9 (cpu.cu.IWB, 0);
4958 word9 fillT = fill;
4959
4960
4961 switch (dstSZ)
4962 {
4963 case 4:
4964 fillT = fill & 017;
4965 break;
4966 case 6:
4967 fillT = fill & 077;
4968 break;
4969 }
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993 #if defined(EIS_PTR3)
4994 bool ovp = (e -> N1 < e -> N2) && (fill & 0400) && (TA1 == 1) &&
4995 (TA2 == 2);
4996 #else
4997 bool ovp = (e -> N1 < e -> N2) && (fill & 0400) && (e -> TA1 == 1) &&
4998 (e -> TA2 == 2);
4999 #endif
5000 bool isNeg = false;
5001
5002
5003
5004 PNL (L68_ (if (max (e->N1, e->N2) < 128)
5005 DU_CYCLE_FLEN_128;))
5006
5007
5008
5009
5010
5011 #if defined(EIS_PTR3)
5012 if (TA1 == CTA9 &&
5013 TA2 == CTA9 &&
5014 #else
5015 if (e -> TA1 == CTA9 &&
5016 e -> TA2 == CTA9 &&
5017 #endif
5018 e -> N1 % 4 == 0 &&
5019 e -> N2 == e -> N1 &&
5020 e -> CN1 == 0 &&
5021 e -> CN2 == 0)
5022 {
5023 sim_debug (DBG_TRACEEXT, & cpu_dev, "MRL special case #1\r\n");
5024 uint limit = e -> N2;
5025 for ( ; cpu.du.CHTALLY < limit; cpu.du.CHTALLY += 4)
5026 {
5027 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
5028 uint n = (limit - cpu.du.CHTALLY - 1) / 4;
5029 word36 w = EISReadIdx (cpup, & e -> ADDR1, n);
5030 EISWriteIdx (cpup, & e -> ADDR2, n, w, true);
5031 }
5032 cleanupOperandDescriptor (cpup, 1);
5033 cleanupOperandDescriptor (cpup, 2);
5034
5035
5036 CLR_I_TRUNC;
5037 return;
5038 }
5039
5040
5041
5042
5043 #if defined(EIS_PTR3)
5044 if (TA1 == CTA9 &&
5045 TA2 == CTA9 &&
5046 #else
5047 if (e -> TA1 == CTA9 &&
5048 e -> TA2 == CTA9 &&
5049 #endif
5050 e -> N1 == 0 &&
5051 e -> N2 % 4 == 0 &&
5052 e -> CN1 == 0 &&
5053 e -> CN2 == 0)
5054 {
5055 sim_debug (DBG_TRACEEXT, & cpu_dev, "MRL special case #2\r\n");
5056 word36 w = (word36) fill |
5057 ((word36) fill << 9) |
5058 ((word36) fill << 18) |
5059 ((word36) fill << 27);
5060 uint limit = e -> N2;
5061 for ( ; cpu.du.CHTALLY < e -> N2; cpu.du.CHTALLY += 4)
5062 {
5063 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
5064 uint n = (limit - cpu.du.CHTALLY - 1) / 4;
5065 EISWriteIdx (cpup, & e -> ADDR2, n, w, true);
5066 }
5067 cleanupOperandDescriptor (cpup, 1);
5068 cleanupOperandDescriptor (cpup, 2);
5069
5070
5071 CLR_I_TRUNC;
5072 return;
5073 }
5074
5075 for ( ; cpu.du.CHTALLY < min (e -> N1, e -> N2); cpu.du.CHTALLY ++)
5076 {
5077 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
5078 word9 c = EISget469 (cpup, 1, e -> N1 - cpu.du.CHTALLY - 1);
5079 word9 cout = 0;
5080
5081 #if defined(EIS_PTR3)
5082 if (TA1 == TA2)
5083 #else
5084 if (e -> TA1 == e -> TA2)
5085 #endif
5086 EISput469 (cpup, 2, e -> N2 - cpu.du.CHTALLY - 1, c);
5087 else
5088 {
5089
5090
5091
5092 cout = c;
5093 switch (srcSZ)
5094 {
5095 case 6:
5096 switch(dstSZ)
5097 {
5098 case 4:
5099 cout = c & 017;
5100 break;
5101 case 9:
5102 break;
5103 }
5104 break;
5105 case 9:
5106 switch(dstSZ)
5107 {
5108 case 4:
5109 cout = c & 017;
5110 break;
5111 case 6:
5112 cout = c & 077;
5113 break;
5114 }
5115 break;
5116 }
5117
5118
5119
5120
5121
5122
5123
5124
5125 if (ovp && (cpu.du.CHTALLY == 0))
5126 {
5127
5128 isGBCDOvp (c, & isNeg);
5129 }
5130 EISput469 (cpup, 2, e -> N2 - cpu.du.CHTALLY - 1, cout);
5131 }
5132 }
5133
5134
5135
5136
5137
5138
5139
5140 if (e -> N1 < e -> N2)
5141 {
5142 for ( ; cpu.du.CHTALLY < e -> N2 ; cpu.du.CHTALLY ++)
5143 {
5144 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
5145
5146 if (ovp && (cpu.du.CHTALLY == e -> N2 - 1))
5147 {
5148 if (isNeg)
5149 EISput469 (cpup, 2, e -> N2 - cpu.du.CHTALLY - 1, 015);
5150 else
5151 EISput469 (cpup, 2, e -> N2 - cpu.du.CHTALLY - 1, 014);
5152 }
5153 else
5154 {
5155 EISput469 (cpup, 2, e -> N2 - cpu.du.CHTALLY - 1, fillT);
5156 }
5157 }
5158 }
5159 cleanupOperandDescriptor (cpup, 1);
5160 cleanupOperandDescriptor (cpup, 2);
5161
5162 if (e -> N1 > e -> N2)
5163 {
5164 SET_I_TRUNC;
5165 if (T && ! TST_I_OMASK)
5166 doFault (FAULT_OFL, fst_zero, "mrl truncation fault");
5167 }
5168 else
5169 CLR_I_TRUNC;
5170 }
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187 #define isDecimalZero(c) ((e->srcTA == CTA9) ? \
5188 ((c) == '0') : \
5189 (((c) & 017) == 0))
5190
5191
5192
5193
5194
5195
5196
5197
5198 static void EISloadInputBufferNumeric (cpu_state_t * cpup, int k)
5199 {
5200 EISstruct * e = & cpu.currentEISinstruction;
5201
5202 word9 *p = e->inBuffer;
5203 (void)memset(e->inBuffer, 0, sizeof(e->inBuffer));
5204
5205 int pos = (int) e->CN[k-1];
5206
5207 int TN = (int) e->TN[k-1];
5208 int S = (int) e->S[k-1];
5209
5210
5211 int N = (int) e->N[k-1];
5212
5213 EISaddr *a = &e->addr[k-1];
5214
5215 e->sign = 1;
5216 e->exponent = 0;
5217
5218 for(int n = 0 ; n < N ; n += 1)
5219 {
5220 word9 c = EISget49(cpup, a, &pos, TN);
5221 sim_debug (DBG_TRACEEXT, & cpu_dev, "src: %d: %o\r\n", n, c);
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231 switch(S)
5232 {
5233 case CSFL:
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251 if (n == 0)
5252 {
5253 c &= 0xf;
5254
5255 if (c < 012 || c > 017)
5256 doFault (FAULT_IPR,
5257 fst_ill_dig,
5258 "loadInputBufferNumeric(1): illegal char in "
5259 "input");
5260
5261 if (c == 015)
5262 e->sign = -1;
5263
5264 e->srcTally -= 1;
5265 }
5266 else if (TN == CTN9 && n == N-1)
5267 {
5268 e->exponent = (signed char)(c & 0377);
5269 e->srcTally -= 1;
5270 }
5271 else if (TN == CTN4 && n == N-2)
5272 {
5273 e->exponent = (c & 0xf);
5274 e->exponent <<= 4;
5275 e->srcTally -= 1;
5276 }
5277 else if (TN == CTN4 && n == N-1)
5278 {
5279 e->exponent |= (c & 0xf);
5280
5281 signed char ce = (signed char) (e->exponent & 0xff);
5282 e->exponent = ce;
5283
5284 e->srcTally -= 1;
5285 }
5286 else
5287 {
5288 c &= 0xf;
5289 if (c > 011)
5290 doFault(FAULT_IPR, fst_ill_dig, "loadInputBufferNumeric(2): illegal char in input");
5291
5292 *p++ = c;
5293 }
5294 break;
5295
5296 case CSLS:
5297
5298
5299
5300 c &= 0xf;
5301
5302 if (n == 0)
5303 {
5304 if (c < 012 || c > 017)
5305 doFault(FAULT_IPR, fst_ill_dig, "loadInputBufferNumeric(3): illegal char in input");
5306
5307 if (c == 015)
5308 e->sign = -1;
5309 e->srcTally -= 1;
5310 }
5311 else
5312 {
5313 if (c > 011)
5314 doFault(FAULT_IPR, fst_ill_dig, "loadInputBufferNumeric(4): illegal char in input");
5315 *p++ = c;
5316 }
5317 break;
5318
5319 case CSTS:
5320 c &= 0xf;
5321
5322 if (n == N-1)
5323 {
5324 if (c < 012 || c > 017)
5325 doFault(FAULT_IPR, fst_ill_dig, "loadInputBufferNumeric(5): illegal char in input");
5326 if (c == 015)
5327 e->sign = -1;
5328 e->srcTally -= 1;
5329 }
5330 else
5331 {
5332 if (c > 011)
5333 doFault(FAULT_IPR, fst_ill_dig, "loadInputBufferNumeric(6): illegal char in input");
5334 *p++ = c;
5335 }
5336 break;
5337
5338 case CSNS:
5339 c &= 0xf;
5340
5341 *p++ = c;
5342 break;
5343 }
5344 }
5345 if_sim_debug (DBG_TRACEEXT, & cpu_dev)
5346 {
5347 sim_debug (DBG_TRACEEXT, & cpu_dev, "inBuffer:");
5348 for (word9 *q = e->inBuffer; q < p; q ++)
5349 sim_debug (DBG_TRACEEXT, & cpu_dev, " %02o", * q);
5350 sim_debug (DBG_TRACEEXT, & cpu_dev, "\r\n");
5351 }
5352 }
5353
5354
5355
5356
5357
5358
5359
5360
5361 static void EISloadInputBufferAlphnumeric (cpu_state_t * cpup, int k)
5362 {
5363 EISstruct * e = & cpu.currentEISinstruction;
5364
5365 word9 * p = e -> inBuffer;
5366 (void)memset (e -> inBuffer, 0, sizeof (e -> inBuffer));
5367
5368
5369
5370
5371
5372
5373
5374 uint N = min (e-> N1, 63);
5375
5376 for (uint n = 0 ; n < N ; n ++)
5377 {
5378 word9 c = EISget469 (cpup, k, n);
5379 * p ++ = c;
5380 }
5381 }
5382
5383 static void EISwriteOutputBufferToMemory (cpu_state_t * cpup, int k)
5384 {
5385 EISstruct * e = & cpu.currentEISinstruction;
5386
5387 for (uint n = 0 ; n < (uint) e -> dstTally; n ++)
5388 {
5389 word9 c49 = e -> outBuffer [n];
5390 EISput469 (cpup, k, n, c49);
5391 }
5392 }
5393
5394 static void writeToOutputBuffer (cpu_state_t *cpup, word9 **dstAddr, int szSrc, int szDst, word9 c49)
5395 {
5396 EISstruct * e = & cpu.currentEISinstruction;
5397
5398
5399
5400
5401
5402
5403
5404
5405 if (e -> mvne)
5406 {
5407 switch (szSrc)
5408
5409 {
5410 case 4:
5411 switch (szDst)
5412 {
5413 case 4:
5414 ** dstAddr = c49 & 0xf;
5415 break;
5416 case 6:
5417 ** dstAddr = c49 & 077;
5418 break;
5419 case 9:
5420 ** dstAddr = c49 | (e -> editInsertionTable [7] & 0760);
5421 break;
5422 }
5423 break;
5424 case 6:
5425 switch (szDst)
5426 {
5427 case 4:
5428 ** dstAddr = c49 & 0xf;
5429 break;
5430 case 6:
5431 ** dstAddr = c49;
5432 break;
5433 case 9:
5434 ** dstAddr = c49;
5435 break;
5436 }
5437 break;
5438
5439
5440
5441 case 9:
5442 switch(szDst)
5443 {
5444 case 4:
5445 ** dstAddr = c49 & 0xf;
5446 break;
5447 case 6:
5448 ** dstAddr = c49 & 077;
5449 break;
5450 case 9:
5451 ** dstAddr = c49;
5452 break;
5453 }
5454 break;
5455 }
5456 }
5457 else
5458 {
5459 switch(szDst)
5460 {
5461 case 4:
5462 ** dstAddr = c49 & 0xf;
5463 break;
5464 case 6:
5465 ** dstAddr = c49 & 077;
5466 break;
5467 case 9:
5468 ** dstAddr = c49;
5469 break;
5470 }
5471 }
5472 e->dstTally -= 1;
5473 *dstAddr += 1;
5474 }
5475
5476
5477
5478
5479
5480 static char* defaultEditInsertionTable = " *+-$,.0";
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513 static int mopCHT (cpu_state_t * cpup)
5514 {
5515 EISstruct * e = & cpu.currentEISinstruction;
5516 (void)memset(&e->editInsertionTable, 0, sizeof(e->editInsertionTable));
5517 for(int i = 0 ; i < 8 ; i += 1)
5518 {
5519 if (e->mopTally == 0)
5520 {
5521 e->_faults |= FAULT_IPR;
5522 break;
5523 }
5524 #if defined(EIS_PTR2)
5525 word9 entry = EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5526 #else
5527 word9 entry = EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5528 #endif
5529 e->editInsertionTable[i] = entry & 0777;
5530 e->mopTally -= 1;
5531 }
5532 return 0;
5533 }
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557 static int mopENF (cpu_state_t * cpup)
5558 {
5559 EISstruct * e = & cpu.currentEISinstruction;
5560
5561 if (!(e->mopIF & 010))
5562 {
5563
5564 if (!e->mopES && !e->mopSN)
5565 {
5566 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[2]);
5567 e->mopES = true;
5568 }
5569
5570 if (!e->mopES && e->mopSN)
5571 {
5572 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[3]);
5573 e->mopES = true;
5574 }
5575
5576 } else {
5577 if (!e->mopES)
5578 {
5579
5580 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[4]);
5581 e->mopES = true;
5582 }
5583
5584 }
5585
5586
5587 if (e->mopIF & 04)
5588 e->mopBZ = true;
5589
5590 return 0;
5591 }
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603 static int mopIGN (cpu_state_t * cpup)
5604 {
5605 EISstruct * e = & cpu.currentEISinstruction;
5606
5607
5608 if (e->mopIF == 0)
5609 e->mopIF = 16;
5610
5611 for(int n = 0 ; n < e->mopIF ; n += 1)
5612 {
5613 if (e->dstTally == 0)
5614 break;
5615 if (e->srcTally == 0)
5616 {
5617
5618 e->_faults |= FAULT_IPR;
5619 break;
5620 }
5621
5622 e->srcTally -= 1;
5623 e->in += 1;
5624 }
5625 return 0;
5626 }
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637 static int mopINSA (cpu_state_t * cpup)
5638 {
5639 EISstruct * e = & cpu.currentEISinstruction;
5640
5641 if (e->mopIF >= 9 )
5642 {
5643 e->_faults |= FAULT_IPR;
5644 return 0;
5645 }
5646
5647
5648
5649
5650
5651
5652 if (!e->mopES)
5653 {
5654 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[1]);
5655
5656 if (e->mopIF == 0)
5657 {
5658 if (e->mopTally == 0)
5659 {
5660 e->_faults |= FAULT_IPR;
5661 return 0;
5662 }
5663 # if defined(EIS_PTR2)
5664 EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5665 # else
5666 EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5667 # endif
5668 e->mopTally -= 1;
5669 }
5670 }
5671
5672
5673
5674 else
5675 {
5676 if (e->mopIF == 0)
5677 {
5678 if (e->mopTally == 0)
5679 {
5680 e->_faults |= FAULT_IPR;
5681 return 0;
5682 }
5683 # if defined(EIS_PTR2)
5684 word9 c = EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5685 # else
5686 word9 c = EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5687 # endif
5688 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, c);
5689 e->mopTally -= 1;
5690 }
5691
5692
5693 else
5694 {
5695 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[e->mopIF-1]);
5696 }
5697 }
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747 return 0;
5748 }
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768 static int mopINSB (cpu_state_t * cpup)
5769 {
5770 EISstruct * e = & cpu.currentEISinstruction;
5771
5772 if (e->mopIF >= 9 )
5773 {
5774 e->_faults |= FAULT_IPR;
5775 return 0;
5776 }
5777
5778 if (!e->mopES)
5779 {
5780
5781
5782
5783 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5784
5785 if (e->mopIF == 0)
5786 {
5787 if (e->mopTally == 0)
5788 {
5789 e->_faults |= FAULT_IPR;
5790 return 0;
5791 }
5792 #if defined(EIS_PTR2)
5793 EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5794 #else
5795 EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5796 #endif
5797 e->mopTally -= 1;
5798 }
5799
5800 } else {
5801
5802
5803
5804 if (e->mopIF)
5805 {
5806
5807
5808
5809 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[e->mopIF - 1]);
5810 } else {
5811
5812
5813
5814 if (e->mopTally == 0)
5815 {
5816 e->_faults |= FAULT_IPR;
5817 return 0;
5818 }
5819 #if defined(EIS_PTR2)
5820 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9));
5821
5822 #else
5823 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, e->mopAddress, &e->mopPos, CTN9));
5824
5825 #endif
5826 e->mopTally -= 1;
5827
5828 }
5829 }
5830 return 0;
5831 }
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843 static int mopINSM (cpu_state_t * cpup)
5844 {
5845 EISstruct * e = & cpu.currentEISinstruction;
5846 if (e->mopIF == 0)
5847 e->mopIF = 16;
5848 for(int n = 0 ; n < e->mopIF ; n += 1)
5849 {
5850 if (e->dstTally == 0)
5851 break;
5852 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5853 }
5854 return 0;
5855 }
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874 static int mopINSN (cpu_state_t * cpup)
5875 {
5876 EISstruct * e = & cpu.currentEISinstruction;
5877
5878 if (e->mopIF >= 9 )
5879 {
5880 e->_faults |= FAULT_IPR;
5881 return 0;
5882 }
5883
5884
5885
5886
5887
5888 if (e->mopIF == 0)
5889 {
5890 if (e->mopTally == 0)
5891 {
5892 e->_faults |= FAULT_IPR;
5893 return 0;
5894 }
5895 if (!e->mopSN)
5896 {
5897
5898
5899
5900 #if defined(EIS_PTR2)
5901 EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5902 #else
5903 EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5904 #endif
5905 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5906 e->mopTally -= 1;
5907 } else {
5908
5909
5910
5911 #if defined(EIS_PTR2)
5912 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9));
5913 #else
5914 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, e->mopAddress, &e->mopPos, CTN9));
5915 #endif
5916
5917 e->mopTally -= 1;
5918 }
5919 }
5920 else
5921 {
5922 if (e->mopSN)
5923 {
5924
5925
5926 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[e->mopIF - 1]);
5927 } else {
5928 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5929 }
5930 }
5931 return 0;
5932 }
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943 static int mopINSP (cpu_state_t * cpup)
5944 {
5945 EISstruct * e = & cpu.currentEISinstruction;
5946
5947 if (e->mopIF >= 9 )
5948 {
5949 e->_faults |= FAULT_IPR;
5950 return 0;
5951 }
5952
5953 if (e->mopIF == 0)
5954 {
5955 if (e->mopTally == 0)
5956 {
5957 e->_faults |= FAULT_IPR;
5958 return 0;
5959 }
5960 if (e->mopSN)
5961 {
5962 #if defined(EIS_PTR2)
5963 EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
5964 #else
5965 EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
5966 #endif
5967 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5968 e->mopTally -= 1;
5969 } else {
5970 #if defined(EIS_PTR2)
5971 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9));
5972 #else
5973 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, EISget49(cpup, e->mopAddress, &e->mopPos, CTN9));
5974 #endif
5975 e->mopTally -= 1;
5976 }
5977 }
5978 else
5979 {
5980 if (!e->mopSN)
5981 {
5982 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[e->mopIF - 1]);
5983 } else {
5984 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
5985 }
5986 }
5987
5988 return 0;
5989 }
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001 static int mopLTE (cpu_state_t * cpup)
6002 {
6003 EISstruct * e = & cpu.currentEISinstruction;
6004 if (e->mopIF == 0 || (e->mopIF >= 9 && e->mopIF <= 15))
6005 {
6006 e->_faults |= FAULT_IPR;
6007 return 0;
6008 }
6009 if (e->mopTally == 0)
6010 {
6011 e->_faults |= FAULT_IPR;
6012 return 0;
6013 }
6014 #if defined(EIS_PTR2)
6015 word9 next = EISget49(cpup, &e->ADDR2, &e->mopPos, CTN9);
6016 #else
6017 word9 next = EISget49(cpup, e->mopAddress, &e->mopPos, CTN9);
6018 #endif
6019 e->mopTally -= 1;
6020
6021
6022 if (e->mopIF - 1 >= 0 &&
6023 e->mopIF - 1 < sizeof(e->editInsertionTable) / sizeof(e->editInsertionTable[0])) {
6024 e->editInsertionTable[e->mopIF - 1] = next;
6025 } else {
6026 e->_faults |= FAULT_IPR;
6027 sim_warn("mopIF %d OOB in %s!\r\n", e->mopIF, __func__);
6028 return 0;
6029 }
6030 sim_debug (DBG_TRACEEXT, & cpu_dev, "LTE IT[%d]<=%d\r\n", e -> mopIF - 1, next);
6031 return 0;
6032 }
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072 static int mopMFLC (cpu_state_t * cpup)
6073 {
6074 EISstruct * e = & cpu.currentEISinstruction;
6075 if (e->mopIF == 0)
6076 e->mopIF = 16;
6077
6078
6079
6080
6081 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC IF %d, srcTally %d, dstTally %d\r\n", e->mopIF, e->srcTally, e->dstTally);
6082 for(int n = 0 ; n < e->mopIF ; n += 1)
6083 {
6084 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC n %d, srcTally %d, dstTally %d\r\n", n, e->srcTally, e->dstTally);
6085 if (e->dstTally == 0)
6086 break;
6087 if (e->srcTally == 0)
6088 return -1;
6089
6090
6091
6092
6093
6094
6095 word9 c = *(e->in);
6096 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC c %d (0%o)\r\n", c, c);
6097 if (!e->mopES) {
6098
6099 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC ES off\r\n");
6100 if (isDecimalZero (c)) {
6101 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC is zero\r\n");
6102
6103
6104 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
6105 e->in += 1;
6106 e->srcTally -= 1;
6107 } else {
6108 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC is not zero\r\n");
6109
6110
6111
6112 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[4]);
6113
6114 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6115 e->mopZ = false;
6116 e->in += 1;
6117 e->srcTally -= 1;
6118
6119 e->mopES = true;
6120 }
6121 } else {
6122 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLC ES on\r\n");
6123
6124 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6125
6126 if (! isDecimalZero (c))
6127 e->mopZ = false;
6128 e->in += 1;
6129 e->srcTally -= 1;
6130 }
6131 }
6132
6133 return 0;
6134 }
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178 static int mopMFLS (cpu_state_t * cpup)
6179 {
6180 EISstruct * e = & cpu.currentEISinstruction;
6181 if (e->mopIF == 0)
6182 e->mopIF = 16;
6183
6184 for(int n = 0 ; n < e->mopIF; n += 1)
6185 {
6186 if (e->dstTally == 0)
6187 break;
6188 if (e->srcTally == 0)
6189 return -1;
6190
6191 word9 c = *(e->in);
6192 sim_debug (DBG_TRACEEXT, & cpu_dev, "MFLS n %d c %o\r\n", n, c);
6193 if (!e->mopES) {
6194 if (isDecimalZero (c))
6195 {
6196
6197
6198 sim_debug (DBG_TRACEEXT, & cpu_dev,
6199 "ES is off, c is zero; edit insertion table entry 1"
6200 " is moved to the receiving field in place of the character.\r\n");
6201 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
6202 e->in += 1;
6203 e->srcTally -= 1;
6204 } else {
6205
6206 if (!e->mopSN)
6207 {
6208
6209
6210
6211 sim_debug (DBG_TRACEEXT, & cpu_dev,
6212 "ES is off, c is non-zero, SN is off; edit insertion table entry 3"
6213 " is moved to the receiving field; the character is also moved to"
6214 " the receiving field, and ES is set ON.\r\n");
6215 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[2]);
6216
6217 e->in += 1;
6218 e->srcTally -= 1;
6219 e->mopZ = false;
6220
6221
6222
6223
6224
6225
6226
6227
6228 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6229
6230 e->mopES = true;
6231 } else {
6232
6233
6234
6235 sim_debug (DBG_TRACEEXT, & cpu_dev,
6236 "ES is off, c is non-zero, SN is OFF; edit insertion table entry 4"
6237 " is moved to the receiving field; the character is also moved to"
6238 " the receiving field, and ES is set ON.\r\n");
6239 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[3]);
6240
6241 e->in += 1;
6242 e->srcTally -= 1;
6243 e->mopZ = false;
6244
6245 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6246
6247 e->mopES = true;
6248 }
6249 }
6250 } else {
6251
6252 sim_debug (DBG_TRACEEXT, & cpu_dev, "ES is ON, the character is moved to the receiving field.\r\n");
6253 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6254
6255 if (! isDecimalZero (c))
6256 e->mopZ = false;
6257 e->in += 1;
6258 e->srcTally -= 1;
6259 }
6260 }
6261
6262
6263
6264
6265
6266 return 0;
6267 }
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288 static int mopMORS (cpu_state_t * cpup)
6289 {
6290 EISstruct * e = & cpu.currentEISinstruction;
6291 if (e->mopIF == 0)
6292 e->mopIF = 16;
6293
6294 sim_debug (DBG_TRACEEXT, & cpu_dev, "MORS mopIF %d src %d dst %d\r\n", e->mopIF, e->srcTally, e->dstTally);
6295 for(int n = 0 ; n < e->mopIF ; n += 1)
6296 {
6297
6298
6299
6300
6301
6302 if (e->dstTally == 0)
6303 break;
6304 if (e->srcTally == 0)
6305 return -1;
6306
6307
6308 word9 c = (*e->in | (!e->mopSN ? e->editInsertionTable[2] : e->editInsertionTable[3]));
6309 if (! isDecimalZero (*e->in))
6310 e->mopZ = false;
6311 e->in += 1;
6312 e->srcTally -= 1;
6313
6314 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6315 }
6316
6317 return 0;
6318 }
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330 static int mopMVC (cpu_state_t * cpup)
6331 {
6332 EISstruct * e = & cpu.currentEISinstruction;
6333 if (e->mopIF == 0)
6334 e->mopIF = 16;
6335
6336 sim_debug (DBG_TRACEEXT, & cpu_dev, "MVC mopIF %d\r\n", e->mopIF);
6337
6338 for(int n = 0 ; n < e->mopIF ; n += 1)
6339 {
6340 sim_debug (DBG_TRACEEXT, & cpu_dev, "MVC n %d srcTally %d dstTally %d\r\n", n, e->srcTally, e->dstTally);
6341
6342
6343 if (e->dstTally == 0)
6344 break;
6345 if (e->srcTally == 0)
6346 return -1;
6347
6348 sim_debug (DBG_TRACEEXT, & cpu_dev, "MVC write to output buffer %o\r\n", *e->in);
6349 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, *e->in);
6350 if (! isDecimalZero (*e->in))
6351 e->mopZ = false;
6352 e->in += 1;
6353
6354 e->srcTally -= 1;
6355 }
6356
6357 sim_debug (DBG_TRACEEXT, & cpu_dev, "MVC done\r\n");
6358 return 0;
6359 }
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387 static int mopMSES (cpu_state_t * cpup)
6388 {
6389 EISstruct * e = & cpu.currentEISinstruction;
6390 if (e->mvne == true)
6391 return mopMVC (cpup);
6392
6393 if (e->mopIF == 0)
6394 e->mopIF = 16;
6395
6396 int overpunch = false;
6397
6398 for(int n = 0 ; n < e->mopIF ; n += 1)
6399 {
6400 if (e->dstTally == 0)
6401 break;
6402 if (e->srcTally == 0)
6403 return -1;
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417 word9 c = *(e->in);
6418
6419 if (!overpunch) {
6420 if (c & e->editInsertionTable[2])
6421 overpunch = true;
6422
6423 else if (c & e->editInsertionTable[3])
6424 {
6425 e->mopSN = true;
6426 overpunch = true;
6427 }
6428 }
6429
6430 e->in += 1;
6431 e->srcTally -= 1;
6432 if (! isDecimalZero (c))
6433 e->mopZ = false;
6434 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6435 }
6436
6437 return 0;
6438 }
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450 static int mopMVZA (cpu_state_t * cpup)
6451 {
6452 EISstruct * e = & cpu.currentEISinstruction;
6453 if (e->mopIF == 0)
6454 e->mopIF = 16;
6455
6456 for(int n = 0 ; n < e->mopIF ; n += 1)
6457 {
6458 if (e->dstTally == 0)
6459 break;
6460 if (e->srcTally == 0)
6461 return -1;
6462
6463 word9 c = *e->in;
6464 e->in += 1;
6465 e->srcTally -= 1;
6466
6467
6468
6469 if (!e->mopES && isDecimalZero (c))
6470 {
6471
6472
6473
6474 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[1]);
6475
6476
6477 }
6478 else if ((! e->mopES) && (! isDecimalZero (c)))
6479 {
6480
6481
6482 e->mopZ = false;
6483 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6484
6485 e->mopES = true;
6486 } else if (e->mopES)
6487 {
6488
6489 if (! isDecimalZero (c))
6490 e->mopZ = false;
6491 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6492 }
6493 }
6494
6495 return 0;
6496 }
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516 static int mopMVZB (cpu_state_t * cpup)
6517 {
6518 EISstruct * e = & cpu.currentEISinstruction;
6519 if (e->mopIF == 0)
6520 e->mopIF = 16;
6521
6522 for(int n = 0 ; n < e->mopIF ; n += 1)
6523 {
6524 if (e->dstTally == 0)
6525 break;
6526 if (e->srcTally == 0)
6527 return -1;
6528
6529 word9 c = *e->in;
6530 e->srcTally -= 1;
6531 e->in += 1;
6532
6533
6534
6535 if ((!e->mopES) && isDecimalZero (c))
6536 {
6537
6538
6539
6540 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
6541
6542
6543 }
6544 if ((! e->mopES) && (! isDecimalZero (c)))
6545 {
6546
6547
6548 e->mopZ = false;
6549 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6550
6551 e->mopES = true;
6552 } else if (e->mopES)
6553 {
6554
6555 if (! isDecimalZero (c))
6556 e->mopZ = false;
6557 writeToOutputBuffer(cpup, &e->out, e->srcSZ, e->dstSZ, c);
6558 }
6559 }
6560
6561 return 0;
6562 }
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577 static int mopSES (cpu_state_t * cpup)
6578 {
6579 EISstruct * e = & cpu.currentEISinstruction;
6580 if (e->mopIF & 010)
6581 e->mopES = true;
6582 else
6583 e->mopES = false;
6584
6585 if (e->mopIF & 04)
6586 e->mopBZ = true;
6587
6588 return 0;
6589 }
6590
6591
6592 #if !defined(QUIET_UNUSED)
6593 static char * mopCodes [040] =
6594 {
6595
6596 0, "insm", "enf", "ses", "mvzb", "mvza", "mfls", "mflc",
6597 "insb", "insa", "insn", "insp", "ign", "mvc", "mses", "mors",
6598 "lte", "cht", 0, 0, 0, 0, 0, 0,
6599 0, 0, 0, 0, 0, 0, 0, 0
6600 };
6601 #endif
6602
6603 static MOP_struct mopTab[040] = {
6604 {NULL, 0},
6605 {"insm", mopINSM },
6606 {"enf", mopENF },
6607 {"ses", mopSES },
6608 {"mvzb", mopMVZB },
6609 {"mvza", mopMVZA },
6610 {"mfls", mopMFLS },
6611 {"mflc", mopMFLC },
6612 {"insb", mopINSB },
6613 {"insa", mopINSA },
6614 {"insn", mopINSN },
6615 {"insp", mopINSP },
6616 {"ign", mopIGN },
6617 {"mvc", mopMVC },
6618 {"mses", mopMSES },
6619 {"mors", mopMORS },
6620 {"lte", mopLTE },
6621 {"cht", mopCHT },
6622 {NULL, 0},
6623 {NULL, 0},
6624 {NULL, 0},
6625 {NULL, 0},
6626 {NULL, 0},
6627 {NULL, 0},
6628 {NULL, 0},
6629 {NULL, 0},
6630 {NULL, 0},
6631 {NULL, 0},
6632 {NULL, 0},
6633 {NULL, 0},
6634 {NULL, 0},
6635 {NULL, 0}
6636 };
6637
6638
6639
6640
6641
6642 static MOP_struct* EISgetMop (cpu_state_t * cpup)
6643 {
6644 EISstruct * e = & cpu.currentEISinstruction;
6645
6646
6647
6648 if (e == NULL)
6649
6650
6651
6652 return NULL;
6653
6654
6655 #if defined(EIS_PTR2)
6656 EISaddr *p = &e->ADDR2;
6657 #else
6658 EISaddr *p = e->mopAddress;
6659 #endif
6660
6661
6662 p->data = EISRead(cpup, p);
6663
6664 if (e->mopPos > 3)
6665 {
6666 e->mopPos = 0;
6667 #if defined(EIS_PTR2)
6668 cpu.du.Dk_PTR_W[KMOP] = (cpu.du.Dk_PTR_W[KMOP] + 1) & AMASK;
6669 p->data = EISRead(cpup, &e->ADDR2);
6670 #else
6671 PNL (cpu.du.Dk_PTR_W[1] = (cpu.du.Dk_PTR_W[1] + 1) & AMASK);
6672 PNL (p->data = EISRead(cpup, e->mopAddress));
6673 # if defined(EIS_PTR)
6674 cpu.du.Dk_PTR_W[1] = (cpu.du.Dk_PTR_W[1] + 1) & AMASK;
6675 p->data = EISRead(cpup, e->mopAddress);
6676 # else
6677 e->mopAddress->address = (e->mopAddress->address + 1) & AMASK;
6678 p->data = EISRead(cpup, e->mopAddress);
6679 # endif
6680 #endif
6681 }
6682
6683 word9 mop9 = (word9) get9 (p -> data, e -> mopPos);
6684 word5 mop = (mop9 >> 4) & 037;
6685 e->mopIF = mop9 & 0xf;
6686
6687 MOP_struct *m = &mopTab[mop];
6688 sim_debug (DBG_TRACEEXT, & cpu_dev, "MOP %s(%o) %o\r\n", m -> mopName, mop, e->mopIF);
6689 e->m = m;
6690 if (e->m == NULL || e->m->f == NULL)
6691 {
6692 sim_debug (DBG_TRACEEXT, & cpu_dev, "getMop(e->m == NULL || e->m->f == NULL): mop:%d IF:%d\r\n", mop, e->mopIF);
6693 return NULL;
6694 }
6695
6696 e->mopPos += 1;
6697 e->mopTally -= 1;
6698
6699
6700
6701 return m;
6702 }
6703
6704 #if defined(EIS_PTR2)
6705 static void mopExecutor (cpu_state_t * cpup)
6706 #else
6707 static void mopExecutor (cpu_state_t * cpup, int kMop)
6708 #endif
6709 {
6710 EISstruct * e = & cpu.currentEISinstruction;
6711 PNL (L68_ (DU_CYCLE_FEXOP;))
6712 #if defined(EIS_PTR2)
6713 e->mopTally = (int) e->N[KMOP];
6714 e->mopPos = (int) e->CN[KMOP];
6715 #else
6716 e->mopAddress = &e->addr[kMop-1];
6717 e->mopTally = (int) e->N[kMop-1];
6718 e->mopPos = (int) e->CN[kMop-1];
6719 #endif
6720
6721 word9 *p9 = e->editInsertionTable;
6722 char *q = defaultEditInsertionTable;
6723 while((*p9++ = (word9) (*q++)))
6724 ;
6725
6726 e->in = e->inBuffer;
6727 e->out = e->outBuffer;
6728
6729 e->_faults = 0;
6730
6731
6732
6733
6734
6735
6736
6737
6738 while (e->dstTally)
6739 {
6740 sim_debug (DBG_TRACEEXT, & cpu_dev,
6741 "mopExecutor srcTally %d dstTally %d mopTally %d\r\n",
6742 e->srcTally, e->dstTally, e->mopTally);
6743 MOP_struct *m = EISgetMop(cpup);
6744 if (! m)
6745 {
6746 sim_debug (DBG_TRACEEXT, & cpu_dev, "mopExecutor EISgetMop forced break\r\n");
6747 e->_faults |= FAULT_IPR;
6748 break;
6749 }
6750 int mres = m->f(cpup);
6751
6752
6753 if (e->_faults & FAULT_IPR)
6754 break;
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775 if (e->mopTally == 0 || mres)
6776 {
6777 sim_debug (DBG_TRACEEXT, & cpu_dev,
6778 "mopExecutor N1 or N2 exhausted\r\n");
6779
6780 if (e->mopZ && e->mopBZ)
6781 {
6782 e->out = e->outBuffer;
6783 e->dstTally = (int) e->N3;
6784 while (e->dstTally)
6785 {
6786 writeToOutputBuffer(cpup, &e->out, 9, e->dstSZ, e->editInsertionTable[0]);
6787 }
6788 }
6789 else if (mres || e->dstTally)
6790 {
6791 e->_faults |= FAULT_IPR;
6792 }
6793 break;
6794 }
6795 }
6796
6797 sim_debug (DBG_TRACEEXT, & cpu_dev, "mop faults %o src %d dst %d mop %d\r\n",
6798 e->_faults, e->srcTally, e->dstTally, e->mopTally);
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846 if (e -> _faults)
6847 doFault (FAULT_IPR, fst_ill_proc, "mopExecutor");
6848 }
6849
6850 void mve (cpu_state_t * cpup)
6851 {
6852 EISstruct * e = & cpu.currentEISinstruction;
6853
6854 sim_debug(DBG_TRACEEXT, & cpu_dev, "mve\r\n");
6855
6856 fault_ipr_subtype_ mod_fault = 0;
6857
6858 #if !defined(EIS_SETUP)
6859 setupOperandDescriptor(cpup, 1, &mod_fault);
6860 setupOperandDescriptor(cpup, 2, &mod_fault);
6861 setupOperandDescriptor(cpup, 3, &mod_fault);
6862 #endif
6863
6864 parseAlphanumericOperandDescriptor(cpup, 1, 1, false, &mod_fault);
6865 parseAlphanumericOperandDescriptor(cpup, 2, 2, false, &mod_fault);
6866 parseAlphanumericOperandDescriptor(cpup, 3, 3, false, &mod_fault);
6867
6868 L68_ (
6869
6870 if (mod_fault)
6871 {
6872 doFault (FAULT_IPR,
6873 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
6874 "Illegal modifier");
6875 }
6876 )
6877
6878
6879
6880 if (IWB_IRODD & 0600600000000)
6881 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mve: 0, 1, 9, 10 MBZ");
6882
6883
6884 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
6885 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mve op1 23 MBZ");
6886
6887
6888
6889
6890
6891
6892
6893 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000010000)
6894 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mve op2 23 MBZ");
6895
6896
6897 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000010000)
6898 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mve op3 23 MBZ");
6899
6900 DPS8M_ (
6901
6902 if (mod_fault)
6903 {
6904 doFault (FAULT_IPR,
6905 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
6906 "Illegal modifier");
6907 }
6908 )
6909
6910
6911 e->mopES = false;
6912 e->mopSN = false;
6913 e->mopBZ = false;
6914 e->mopZ = true;
6915
6916 e->srcTally = (int) e->N1;
6917 e->dstTally = (int) e->N3;
6918
6919 #if defined(EIS_PTR3)
6920 e->srcTA = (int) TA1;
6921 #else
6922 e->srcTA = (int) e->TA1;
6923 #endif
6924
6925 switch (e -> srcTA)
6926 {
6927 case CTA4:
6928 e -> srcSZ = 4;
6929 break;
6930 case CTA6:
6931 e -> srcSZ = 6;
6932 break;
6933 case CTA9:
6934 e -> srcSZ = 9;
6935 break;
6936 }
6937
6938 #if defined(EIS_PTR3)
6939 uint dstTA = TA3;
6940 #else
6941 uint dstTA = e -> TA3;
6942 #endif
6943
6944 switch (dstTA)
6945 {
6946 case CTA4:
6947 e -> dstSZ = 4;
6948 break;
6949 case CTA6:
6950 e -> dstSZ = 6;
6951 break;
6952 case CTA9:
6953 e -> dstSZ = 9;
6954 break;
6955 }
6956
6957
6958 EISloadInputBufferAlphnumeric (cpup, 1);
6959
6960
6961 e -> mvne = false;
6962
6963 #if defined(EIS_PTR2)
6964 mopExecutor (cpup);
6965 #else
6966 mopExecutor (cpup, 2);
6967 #endif
6968
6969 e -> dstTally = (int) e -> N3;
6970
6971 EISwriteOutputBufferToMemory (cpup, 3);
6972 cleanupOperandDescriptor (cpup, 1);
6973 cleanupOperandDescriptor (cpup, 2);
6974 cleanupOperandDescriptor (cpup, 3);
6975 }
6976
6977 void mvne (cpu_state_t * cpup)
6978 {
6979 EISstruct * e = & cpu.currentEISinstruction;
6980
6981 fault_ipr_subtype_ mod_fault = 0;
6982
6983 #if !defined(EIS_SETUP)
6984 setupOperandDescriptor (cpup, 1, &mod_fault);
6985 setupOperandDescriptor (cpup, 2, &mod_fault);
6986 setupOperandDescriptor (cpup, 3, &mod_fault);
6987 #endif
6988
6989 parseNumericOperandDescriptor (cpup, 1, &mod_fault);
6990 parseAlphanumericOperandDescriptor (cpup, 2, 2, false, &mod_fault);
6991 parseAlphanumericOperandDescriptor (cpup, 3, 3, false, &mod_fault);
6992
6993 L68_ (
6994
6995 if (mod_fault)
6996 {
6997 doFault (FAULT_IPR,
6998 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
6999 "Illegal modifier");
7000 }
7001 )
7002
7003
7004 if (IWB_IRODD & 0600600000000)
7005 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mvne: 0, 1, 9, 10 MBZ");
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000070000)
7019 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mvne op2 21-23 MBZ");
7020
7021
7022
7023
7024
7025
7026
7027 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000010000)
7028 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mvne op3 23 MBZ");
7029
7030 DPS8M_ (
7031
7032 if (mod_fault)
7033 {
7034 doFault (FAULT_IPR,
7035 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7036 "Illegal modifier");
7037 }
7038 )
7039
7040 uint srcTN = e -> TN1;
7041
7042 int n1 = 0;
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054 switch(e->S1)
7055 {
7056 case CSFL:
7057 n1 = (int) e->N1 - 1;
7058 if (srcTN == CTN4)
7059 n1 -= 2;
7060 else
7061 n1 -= 1;
7062 break;
7063
7064 case CSLS:
7065 case CSTS:
7066 n1 = (int) e->N1 - 1;
7067 break;
7068
7069 case CSNS:
7070 n1 = (int) e->N1;
7071 break;
7072 }
7073
7074 if (n1 < 1)
7075 doFault (FAULT_IPR, fst_ill_proc, "mvne adjusted n1<1");
7076
7077
7078
7079
7080 if (e->N[1] == 0)
7081 doFault (FAULT_IPR, fst_ill_proc, "mvne N2 0");
7082
7083
7084
7085 if (e->N[2] == 0)
7086 doFault (FAULT_IPR, fst_ill_proc, "mvne N3 0");
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103 e->mopES = false;
7104 e->mopSN = false;
7105 e->mopBZ = false;
7106 e->mopZ = true;
7107
7108 e -> srcTally = (int) e -> N1;
7109 e -> dstTally = (int) e -> N3;
7110
7111
7112
7113
7114
7115 e->srcTA = CTA4;
7116
7117 switch(srcTN)
7118 {
7119 case CTN4:
7120
7121 e->srcSZ = 4;
7122 break;
7123 case CTN9:
7124
7125 e->srcSZ = 4;
7126 break;
7127 }
7128
7129 #if defined(EIS_PTR3)
7130 uint dstTA = TA3;
7131 #else
7132 uint dstTA = e->TA3;
7133 #endif
7134 switch(dstTA)
7135 {
7136 case CTA4:
7137
7138 e->dstSZ = 4;
7139 break;
7140 case CTA6:
7141
7142 e->dstSZ = 6;
7143 break;
7144 case CTA9:
7145
7146 e->dstSZ = 9;
7147 break;
7148 }
7149
7150 #if defined(EIS_PTR3)
7151 sim_debug (DBG_TRACEEXT, & cpu_dev,
7152 "mvne N1 %d N2 %d N3 %d TN1 %d CN1 %d TA3 %d CN3 %d\r\n",
7153 e->N1, e->N2, e->N3, e->TN1, e->CN1, TA3, e->CN3);
7154 #else
7155 sim_debug (DBG_TRACEEXT, & cpu_dev,
7156 "mvne N1 %d N2 %d N3 %d TN1 %d CN1 %d TA3 %d CN3 %d\r\n",
7157 e->N1, e->N2, e->N3, e->TN1, e->CN1, e->TA3, e->CN3);
7158 #endif
7159
7160
7161 EISloadInputBufferNumeric (cpup, 1);
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172 int sum = 0;
7173 for(int n = 0 ; n < e -> srcTally ; n ++)
7174 sum += e -> inBuffer [n];
7175 if ((e -> sign == -1) && sum)
7176 e -> mopSN = true;
7177
7178
7179 e -> mvne = true;
7180
7181 #if defined(EIS_PTR2)
7182 mopExecutor (cpup);
7183 #else
7184 mopExecutor (cpup, 2);
7185 #endif
7186
7187 e -> dstTally = (int) e -> N3;
7188
7189 EISwriteOutputBufferToMemory (cpup, 3);
7190 cleanupOperandDescriptor (cpup, 1);
7191 cleanupOperandDescriptor (cpup, 2);
7192 cleanupOperandDescriptor (cpup, 3);
7193 }
7194
7195
7196
7197
7198
7199 void mvt (cpu_state_t * cpup)
7200 {
7201 EISstruct * e = & cpu.currentEISinstruction;
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212 fault_ipr_subtype_ mod_fault = 0;
7213
7214 #if !defined(EIS_SETUP)
7215 setupOperandDescriptor (cpup, 1, &mod_fault);
7216 setupOperandDescriptor (cpup, 2, &mod_fault);
7217 setupOperandDescriptorCache (cpup,3);
7218 #endif
7219
7220 parseAlphanumericOperandDescriptor (cpup, 1, 1, false, &mod_fault);
7221 parseAlphanumericOperandDescriptor (cpup, 2, 2, false, &mod_fault);
7222 parseArgOperandDescriptor (cpup, 3, &mod_fault);
7223
7224 L68_ (
7225
7226 if (mod_fault)
7227 {
7228 doFault (FAULT_IPR,
7229 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7230 "Illegal modifier");
7231 }
7232 )
7233
7234
7235
7236
7237
7238 if (IWB_IRODD & 0000200000000)
7239 {
7240
7241 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mvt 10 MBZ");
7242 }
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000010000)
7254 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mvt op1 23 MBZ");
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264 if (!(e->MF[2] & MFkID) && e -> op [2] & 0000000777600)
7265 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "mvt op3 18-28 MBZ");
7266
7267 DPS8M_ (
7268
7269 if (mod_fault)
7270 {
7271 doFault (FAULT_IPR,
7272 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7273 "Illegal modifier");
7274 }
7275 )
7276
7277 #if defined(EIS_PTR3)
7278 e->srcTA = (int) TA1;
7279 uint dstTA = TA2;
7280
7281 switch (TA1)
7282 #else
7283 e->srcTA = (int) e->TA1;
7284 uint dstTA = e->TA2;
7285
7286 switch (e -> TA1)
7287 #endif
7288 {
7289 case CTA4:
7290 e -> srcSZ = 4;
7291 break;
7292 case CTA6:
7293 e -> srcSZ = 6;
7294 break;
7295 case CTA9:
7296 e -> srcSZ = 9;
7297 break;
7298 }
7299
7300 #if defined(EIS_PTR3)
7301 switch (TA2)
7302 #else
7303 switch (e -> TA2)
7304 #endif
7305 {
7306 case CTA4:
7307 e -> dstSZ = 4;
7308 break;
7309 case CTA6:
7310 e -> dstSZ = 6;
7311 break;
7312 case CTA9:
7313 e -> dstSZ = 9;
7314 break;
7315 }
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330 uint xlatSize = 0;
7331 #if defined(EIS_PTR3)
7332 switch(TA1)
7333 #else
7334 switch(e->TA1)
7335 #endif
7336 {
7337 case CTA4:
7338 xlatSize = 4;
7339 break;
7340 case CTA6:
7341 xlatSize = 16;
7342 break;
7343 case CTA9:
7344 xlatSize = 128;
7345 break;
7346 }
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358 int lastpageidx = ((int)e->N1 + (int)e->CN1 -1) / e->srcSZ;
7359 if (lastpageidx>0)
7360 EISReadIdx(cpup, &e->ADDR1, (uint)lastpageidx);
7361
7362 if (xlatSize > 0)
7363 {
7364 EISReadIdx(cpup, &e->ADDR3, 0);
7365 EISReadIdx(cpup, &e->ADDR3, xlatSize-1);
7366 }
7367
7368 word1 T = getbits36_1 (cpu.cu.IWB, 9);
7369
7370 word9 fill = getbits36_9 (cpu.cu.IWB, 0);
7371 word9 fillT = fill;
7372
7373 switch(e->srcSZ)
7374 {
7375 case 4:
7376 fillT = fill & 017;
7377 break;
7378 case 6:
7379 fillT = fill & 077;
7380 break;
7381 }
7382
7383 sim_debug (DBG_TRACEEXT, & cpu_dev,
7384 "%s srcCN:%d dstCN:%d srcSZ:%d dstSZ:%d T:%d fill:%03o/%03o N1:%d N2:%d",
7385 __func__, e -> CN1, e -> CN2, e -> srcSZ, e -> dstSZ, T,
7386 fill, fillT, e -> N1, e -> N2);
7387
7388 PNL (L68_ (if (max (e->N1, e->N2) < 128)
7389 DU_CYCLE_FLEN_128;))
7390
7391 for ( ; cpu.du.CHTALLY < min(e->N1, e->N2); cpu.du.CHTALLY ++)
7392 {
7393 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
7394 word9 c = EISget469(cpup, 1, cpu.du.CHTALLY);
7395 int cidx = 0;
7396
7397 #if defined(EIS_PTR3)
7398 if (TA1 == TA2)
7399 #else
7400 if (e->TA1 == e->TA2)
7401 #endif
7402 EISput469(cpup, 2, cpu.du.CHTALLY, xlate (cpup, &e->ADDR3, dstTA, c));
7403 else
7404 {
7405
7406
7407
7408 cidx = c;
7409
7410 word9 cout = xlate(cpup, &e->ADDR3, dstTA, (uint) cidx);
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422 switch (e->srcSZ)
7423 {
7424 case 6:
7425 switch(e->dstSZ)
7426 {
7427 case 4:
7428 cout &= 017;
7429 break;
7430 case 9:
7431 break;
7432 }
7433 break;
7434 case 9:
7435 switch(e->dstSZ)
7436 {
7437 case 4:
7438 cout &= 017;
7439 break;
7440 case 6:
7441 cout &= 077;
7442 break;
7443 }
7444 break;
7445 }
7446
7447 EISput469 (cpup, 2, cpu.du.CHTALLY, cout);
7448 }
7449 }
7450
7451
7452
7453
7454
7455 if (e->N1 < e->N2)
7456 {
7457
7458
7459
7460
7461
7462
7463 word9 cfill = xlate(cpup, &e->ADDR3, dstTA, fill);
7464 switch (e->srcSZ)
7465 {
7466 case 6:
7467 switch(e->dstSZ)
7468 {
7469 case 4:
7470 cfill &= 017;
7471 break;
7472 case 9:
7473 break;
7474 }
7475 break;
7476 case 9:
7477 switch(e->dstSZ)
7478 {
7479 case 4:
7480 cfill &= 017;
7481 break;
7482 case 6:
7483 cfill &= 077;
7484 break;
7485 }
7486 break;
7487 }
7488
7489 for( ; cpu.du.CHTALLY < e->N2 ; cpu.du.CHTALLY ++)
7490 {
7491 tandd_eis_sample (cpup, cpu.du.CHTALLY, TDPER (e -> TA2));
7492 EISput469 (cpup, 2, cpu.du.CHTALLY, cfill);
7493 }
7494 }
7495
7496 cleanupOperandDescriptor (cpup, 1);
7497 cleanupOperandDescriptor (cpup, 2);
7498 cleanupOperandDescriptor (cpup, 3);
7499
7500 if (e->N1 > e->N2)
7501 {
7502 SET_I_TRUNC;
7503 if (T && ! TST_I_OMASK)
7504 doFault(FAULT_OFL, fst_zero, "mvt truncation fault");
7505 }
7506 else
7507 CLR_I_TRUNC;
7508 }
7509
7510
7511
7512
7513
7514 void cmpn (cpu_state_t * cpup)
7515 {
7516 EISstruct * e = & cpu.currentEISinstruction;
7517
7518
7519
7520
7521
7522
7523
7524 fault_ipr_subtype_ mod_fault = 0;
7525
7526 #if !defined(EIS_SETUP)
7527 setupOperandDescriptor(cpup, 1, &mod_fault);
7528 setupOperandDescriptor(cpup, 2, &mod_fault);
7529 #endif
7530
7531 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
7532 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
7533
7534 L68_ (
7535
7536 if (mod_fault)
7537 {
7538 doFault (FAULT_IPR,
7539 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7540 "Illegal modifier");
7541 }
7542 )
7543
7544
7545 if (IWB_IRODD & 0777600000000)
7546 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "cmpn 0-10 MBZ");
7547
7548 DPS8M_ (
7549
7550 if (mod_fault)
7551 {
7552 doFault (FAULT_IPR,
7553 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7554 "Illegal modifier");
7555 }
7556 )
7557
7558 uint srcTN = e->TN1;
7559
7560 int n1 = 0, n2 = 0, sc1 = 0, sc2 = 0;
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572 switch(e->S1)
7573 {
7574 case CSFL:
7575 n1 = (int) e->N1 - 1;
7576 if (srcTN == CTN4)
7577 n1 -= 2;
7578 else
7579 n1 -= 1;
7580 sc1 = 0;
7581 break;
7582
7583 case CSLS:
7584 case CSTS:
7585 n1 = (int) e->N1 - 1;
7586 sc1 = -e->SF1;
7587 break;
7588
7589 case CSNS:
7590 n1 = (int) e->N1;
7591 sc1 = -e->SF1;
7592 break;
7593 }
7594
7595 if (n1 < 1)
7596 doFault (FAULT_IPR, fst_ill_proc, "cmpn adjusted n1<1");
7597
7598 switch(e->S2)
7599 {
7600 case CSFL:
7601 n2 = (int) e->N2 - 1;
7602 if (e->TN2 == CTN4)
7603 n2 -= 2;
7604 else
7605 n2 -= 1;
7606 sc2 = 0;
7607 break;
7608
7609 case CSLS:
7610 case CSTS:
7611 n2 = (int) e->N2 - 1;
7612 sc2 = -e->SF2;
7613 break;
7614
7615 case CSNS:
7616 n2 = (int) e->N2;
7617 sc2 = -e->SF2;
7618 break;
7619 }
7620
7621 if (n2 < 1)
7622 doFault (FAULT_IPR, fst_ill_proc, "cmpn adjusted n2<1");
7623
7624 decContext set;
7625
7626 decContextDefaultDPS8(&set);
7627
7628 set.traps=0;
7629
7630 decNumber _1, _2, _3;
7631
7632 EISloadInputBufferNumeric (cpup, 1);
7633
7634 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
7635 if (e->sign == -1)
7636 op1->bits |= DECNEG;
7637 if (e->S1 == CSFL)
7638 op1->exponent = e->exponent;
7639
7640 EISloadInputBufferNumeric (cpup, 2);
7641
7642 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
7643 if (e->sign == -1)
7644 op2->bits |= DECNEG;
7645 if (e->S2 == CSFL)
7646 op2->exponent = e->exponent;
7647
7648
7649 decNumber *cmp = decNumberCompare(&_3, op1, op2, &set);
7650 int cSigned = decNumberToInt32(cmp, &set);
7651
7652
7653 op1 = decNumberAbs(op1, op1, &set);
7654 op2 = decNumberAbs(op2, op2, &set);
7655
7656
7657 decNumber *mcmp = decNumberCompare(&_3, op1, op2, &set);
7658 int cMag = decNumberToInt32(mcmp, &set);
7659
7660
7661
7662
7663
7664 SC_I_ZERO (cSigned == 0);
7665 SC_I_NEG (cSigned == 1);
7666 SC_I_CARRY (cMag != 1);
7667
7668 cleanupOperandDescriptor (cpup, 1);
7669 cleanupOperandDescriptor (cpup, 2);
7670 }
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680 static void EISwrite4(cpu_state_t * cpup, EISaddr *p, int *pos, word4 char4)
7681 {
7682 word36 w;
7683 if (*pos > 7)
7684 {
7685 *pos = 0;
7686 #if defined(EIS_PTR)
7687 long eisaddr_idx = EISADDR_IDX (p);
7688 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
7689 cpu.du.Dk_PTR_W[eisaddr_idx] = (cpu.du.Dk_PTR_W[eisaddr_idx] + 1) & AMASK;
7690 #else
7691 p->address = (p->address + 1) & AMASK;
7692 #endif
7693 }
7694
7695 w = EISRead(cpup, p);
7696
7697
7698
7699
7700
7701 char4 &= MASK4;
7702 switch (*pos)
7703 {
7704 case 0:
7705
7706 w = setbits36_5 (w, 0, char4);
7707 break;
7708 case 1:
7709
7710 w = setbits36_4 (w, 5, char4);
7711 break;
7712 case 2:
7713
7714 w = setbits36_5 (w, 9, char4);
7715 break;
7716 case 3:
7717
7718 w = setbits36_4 (w, 14, char4);
7719 break;
7720 case 4:
7721
7722 w = setbits36_5 (w, 18, char4);
7723 break;
7724 case 5:
7725
7726 w = setbits36_4 (w, 23, char4);
7727 break;
7728 case 6:
7729
7730 w = setbits36_5 (w, 27, char4);
7731 break;
7732 case 7:
7733
7734 w = setbits36_4 (w, 32, char4);
7735 break;
7736 }
7737
7738 EISWriteIdx(cpup, p, 0, w, true);
7739
7740 *pos += 1;
7741 }
7742
7743
7744
7745
7746
7747 static void EISwrite9(cpu_state_t *cpup, EISaddr *p, int *pos, word9 char9)
7748 {
7749 word36 w;
7750 if (*pos > 3)
7751 {
7752 *pos = 0;
7753 #if defined(EIS_PTR)
7754 long eisaddr_idx = EISADDR_IDX (p);
7755 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
7756 cpu.du.Dk_PTR_W[eisaddr_idx] = (cpu.du.Dk_PTR_W[eisaddr_idx] + 1) & AMASK;
7757 #else
7758 p->address = (p->address + 1) & AMASK;
7759 #endif
7760 }
7761
7762 w = EISRead(cpup, p);
7763
7764
7765 switch (*pos)
7766 {
7767 case 0:
7768
7769 w = setbits36_9 (w, 0, char9);
7770 break;
7771 case 1:
7772
7773 w = setbits36_9 (w, 9, char9);
7774 break;
7775 case 2:
7776
7777 w = setbits36_9 (w, 18, char9);
7778 break;
7779 case 3:
7780
7781 w = setbits36_9 (w, 27, char9);
7782 break;
7783 }
7784
7785 EISWriteIdx (cpup, p, 0, w, true);
7786
7787 *pos += 1;
7788 }
7789
7790
7791
7792
7793
7794 static void EISwrite49(cpu_state_t * cpup, EISaddr *p, int *pos, int tn, word9 c49)
7795 {
7796 switch(tn)
7797 {
7798 case CTN4:
7799 EISwrite4(cpup, p, pos, (word4) c49);
7800 return;
7801 case CTN9:
7802 EISwrite9(cpup, p, pos, c49);
7803 return;
7804 }
7805 }
7806
7807 void mvn (cpu_state_t * cpup)
7808 {
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826 EISstruct * e = & cpu.currentEISinstruction;
7827
7828 fault_ipr_subtype_ mod_fault = 0;
7829
7830 #if !defined(EIS_SETUP)
7831 setupOperandDescriptor(cpup, 1, &mod_fault);
7832 setupOperandDescriptor(cpup, 2, &mod_fault);
7833 #endif
7834
7835 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
7836 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
7837
7838 L68_ (
7839
7840 if (mod_fault)
7841 {
7842 doFault (FAULT_IPR,
7843 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7844 "Illegal modifier");
7845 }
7846 )
7847
7848
7849 if (IWB_IRODD & 0377000000000)
7850 doFault (FAULT_IPR,
7851 (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault},
7852 "mvn 2-8 MBZ");
7853
7854 DPS8M_ (
7855
7856 if (mod_fault)
7857 {
7858 doFault (FAULT_IPR,
7859 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
7860 "Illegal modifier");
7861 }
7862 )
7863
7864 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
7865
7866 word1 T = getbits36_1 (cpu.cu.IWB, 9);
7867 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
7868 PNL (L68_ (if (R)
7869 DU_CYCLE_FRND;))
7870
7871 uint srcTN = e->TN1;
7872
7873 uint dstTN = e->TN2;
7874 uint dstCN = e->CN2;
7875
7876 sim_debug (DBG_CAC, & cpu_dev,
7877 "mvn(1): TN1 %d CN1 %d N1 %d TN2 %d CN2 %d N2 %d\r\n",
7878 e->TN1, e->CN1, e->N1, e->TN2, e->CN2, e->N2);
7879 sim_debug (DBG_CAC, & cpu_dev,
7880 "mvn(2): SF1 %d SF2 %d\r\n",
7881 e->SF1, e->SF2);
7882 sim_debug (DBG_CAC, & cpu_dev,
7883 "mvn(3): OP1 %012"PRIo64" OP2 %012"PRIo64"\r\n",
7884 e->OP1, e->OP2);
7885
7886 int n1 = 0, n2 = 0, sc1 = 0;
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898 switch(e->S1)
7899 {
7900 case CSFL:
7901 n1 = (int) e->N1 - 1;
7902 if (srcTN == CTN4)
7903 n1 -= 2;
7904 else
7905 n1 -= 1;
7906 sc1 = 0;
7907 break;
7908
7909 case CSLS:
7910 case CSTS:
7911 n1 = (int) e->N1 - 1;
7912 sc1 = -e->SF1;
7913 break;
7914
7915 case CSNS:
7916 n1 = (int) e->N1;
7917 sc1 = -e->SF1;
7918 break;
7919 }
7920
7921 sim_debug (DBG_CAC, & cpu_dev, "n1 %d sc1 %d\r\n", n1, sc1);
7922
7923
7924
7925
7926
7927
7928
7929 if (n1 < 1)
7930 doFault (FAULT_IPR, fst_ill_proc, "mvn adjusted n1<1");
7931
7932 switch(e->S2)
7933 {
7934 case CSFL:
7935 n2 = (int) e->N2 - 1;
7936 if (dstTN == CTN4)
7937 n2 -= 2;
7938 else
7939 n2 -= 1;
7940 break;
7941
7942 case CSLS:
7943 case CSTS:
7944 n2 = (int) e->N2 - 1;
7945 break;
7946
7947 case CSNS:
7948 n2 = (int) e->N2;
7949 break;
7950 }
7951
7952 sim_debug (DBG_CAC, & cpu_dev, "n2 %d\r\n", n2);
7953
7954 if (n2 < 1)
7955 doFault (FAULT_IPR, fst_ill_proc, "mvn adjusted n2<1");
7956
7957 decContext set;
7958 decContextDefaultDPS8(&set);
7959 set.traps=0;
7960
7961 decNumber _1;
7962
7963 EISloadInputBufferNumeric (cpup, 1);
7964
7965 decNumber *op1 = decBCD9ToNumber (e->inBuffer, n1, sc1, &_1);
7966
7967 if (e->sign == -1)
7968 op1->bits |= DECNEG;
7969 if (e->S1 == CSFL)
7970 op1->exponent = e->exponent;
7971 if (decNumberIsZero (op1))
7972 op1->exponent = 127;
7973
7974 if_sim_debug (DBG_CAC, & cpu_dev)
7975 {
7976 PRINTDEC ("mvn input (op1)", op1);
7977 }
7978
7979 bool Ovr = false, EOvr = false, Trunc = false;
7980
7981 uint8_t out [256];
7982 char * res = formatDecimal (out, & set, op1, n2, (int) e->S2, e->SF2, R,
7983 & Ovr, & Trunc);
7984
7985 sim_debug (DBG_CAC, & cpu_dev, "mvn res: '%s'\r\n", res);
7986
7987
7988
7989
7990 int pos = (int) dstCN;
7991
7992
7993 switch(e->S2)
7994 {
7995 case CSFL:
7996 case CSLS:
7997 switch(dstTN)
7998 {
7999 case CTN4:
8000
8001
8002
8003 if (e->P)
8004
8005 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8006 (decNumberIsNegative (op1) &&
8007 ! decNumberIsZero(op1)) ? 015 : 013);
8008 else
8009
8010 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8011 (decNumberIsNegative (op1) &&
8012 ! decNumberIsZero (op1)) ? 015 : 014);
8013 break;
8014 case CTN9:
8015 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8016 (decNumberIsNegative (op1) &&
8017 ! decNumberIsZero (op1)) ? '-' : '+');
8018 break;
8019 }
8020 break;
8021
8022 case CSTS:
8023 case CSNS:
8024 break;
8025 }
8026
8027
8028 for (int i = 0 ; i < n2 ; i ++)
8029 switch (dstTN)
8030 {
8031 case CTN4:
8032 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8033 (word9) (res[i] - '0'));
8034 break;
8035 case CTN9:
8036 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN, (word9) res[i]);
8037 break;
8038 }
8039
8040
8041 switch(e->S2)
8042 {
8043 case CSTS:
8044 switch(dstTN)
8045 {
8046 case CTN4:
8047
8048
8049
8050 if (e->P)
8051
8052 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8053 (decNumberIsNegative (op1) &&
8054 ! decNumberIsZero(op1)) ? 015 : 013);
8055 else
8056
8057 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8058 (decNumberIsNegative (op1) &&
8059 ! decNumberIsZero (op1)) ? 015 : 014);
8060 break;
8061
8062 case CTN9:
8063 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8064 (decNumberIsNegative (op1) &&
8065 ! decNumberIsZero(op1)) ? '-' : '+');
8066 break;
8067 }
8068 break;
8069
8070 case CSFL:
8071
8072 switch(dstTN)
8073 {
8074 case CTN4:
8075 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8076 (op1->exponent >> 4) & 0xf);
8077 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8078 op1->exponent & 0xf);
8079 break;
8080 case CTN9:
8081 EISwrite49 (cpup, & e->ADDR2, & pos, (int) dstTN,
8082 op1->exponent & 0xff);
8083 break;
8084 }
8085 break;
8086
8087 case CSLS:
8088 case CSNS:
8089 break;
8090 }
8091
8092
8093 if (e->S2 == CSFL)
8094 {
8095 if (op1->exponent > 127)
8096 {
8097 SET_I_EOFL;
8098 EOvr = true;
8099 }
8100 if (op1->exponent < -128)
8101 {
8102 SET_I_EUFL;
8103 EOvr = true;
8104 }
8105 }
8106
8107 sim_debug (DBG_CAC, & cpu_dev, "is neg %o\r\n", decNumberIsNegative(op1));
8108 sim_debug (DBG_CAC, & cpu_dev, "is zero %o\r\n", decNumberIsZero(op1));
8109 sim_debug (DBG_CAC, & cpu_dev, "R %o\r\n", R);
8110 sim_debug (DBG_CAC, & cpu_dev, "Trunc %o\r\n", Trunc);
8111 sim_debug (DBG_CAC, & cpu_dev, "TRUNC %o\r\n", TST_I_TRUNC);
8112 sim_debug (DBG_CAC, & cpu_dev, "OMASK %o\r\n", TST_I_OMASK);
8113 sim_debug (DBG_CAC, & cpu_dev, "tstOVFfault %o\r\n", tstOVFfault (cpup));
8114 sim_debug (DBG_CAC, & cpu_dev, "T %o\r\n", T);
8115 sim_debug (DBG_CAC, & cpu_dev, "EOvr %o\r\n", EOvr);
8116 sim_debug (DBG_CAC, & cpu_dev, "Ovr %o\r\n", Ovr);
8117
8118 SC_I_NEG (decNumberIsNegative(op1) && !decNumberIsZero(op1));
8119
8120
8121 SC_I_ZERO (decNumberIsZero(op1));
8122
8123
8124
8125 SC_I_TRUNC (!R && Trunc);
8126
8127 cleanupOperandDescriptor (cpup, 1);
8128 cleanupOperandDescriptor (cpup, 2);
8129
8130 if (TST_I_TRUNC && T && tstOVFfault (cpup))
8131 doFault (FAULT_OFL, fst_zero, "mvn truncation(overflow) fault");
8132 if (EOvr && tstOVFfault (cpup))
8133 doFault (FAULT_OFL, fst_zero, "mvn over/underflow fault");
8134 if (Ovr)
8135 {
8136 SET_I_OFLOW;
8137 if (tstOVFfault (cpup))
8138 doFault (FAULT_OFL, fst_zero, "mvn overflow fault");
8139 }
8140 }
8141
8142 void csl (cpu_state_t * cpup)
8143 {
8144 EISstruct * e = & cpu.currentEISinstruction;
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201 fault_ipr_subtype_ mod_fault = 0;
8202
8203 #if !defined(EIS_SETUP)
8204 setupOperandDescriptor (cpup, 1, & mod_fault);
8205 setupOperandDescriptor (cpup, 2, & mod_fault);
8206 #endif
8207
8208 parseBitstringOperandDescriptor (cpup, 1, & mod_fault);
8209 parseBitstringOperandDescriptor (cpup, 2, & mod_fault);
8210
8211 L68_ (
8212
8213 if (mod_fault)
8214 doFault (FAULT_IPR,
8215 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8216 "Illegal modifier");
8217 )
8218
8219
8220 if (IWB_IRODD & 0360200000000)
8221 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "csl 1-4,10 MBZ");
8222
8223 DPS8M_ (
8224
8225 if (mod_fault)
8226 doFault (FAULT_IPR,
8227 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8228 "Illegal modifier");
8229 )
8230
8231 e->ADDR1.cPos = (int) e->C1;
8232 e->ADDR2.cPos = (int) e->C2;
8233
8234 e->ADDR1.bPos = (int) e->B1;
8235 e->ADDR2.bPos = (int) e->B2;
8236
8237 bool F = getbits36_1 (cpu.cu.IWB, 0) != 0;
8238 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
8239
8240 uint BOLR = getbits36_4 (cpu.cu.IWB, 5);
8241 bool B5 = !! (BOLR & 8);
8242 bool B6 = !! (BOLR & 4);
8243 bool B7 = !! (BOLR & 2);
8244 bool B8 = !! (BOLR & 1);
8245
8246 e->ADDR1.mode = eRWreadBit;
8247
8248 #if !defined(EIS_PTR)
8249 sim_debug (DBG_TRACEEXT, & cpu_dev,
8250 "CSL N1 %d N2 %d\r\n"
8251 "CSL C1 %d C2 %d B1 %d B2 %d F %o T %d\r\n"
8252 "CSL BOLR %u%u%u%u\r\n"
8253 "CSL op1 SNR %06o WORDNO %06o CHAR %d BITNO %d\r\n"
8254 "CSL op2 SNR %06o WORDNO %06o CHAR %d BITNO %d\r\n",
8255 e -> N1, e -> N2,
8256 e -> C1, e -> C2, e -> B1, e -> B2, F, T,
8257 B5, B6, B7, B8,
8258 e -> addr [0].SNR, e -> addr [0].address,
8259 e -> addr [0].cPos, e -> addr [0].bPos,
8260 e -> addr [1].SNR, e -> addr [1].address,
8261 e -> addr [1].cPos, e -> addr [1].bPos);
8262 #endif
8263
8264 bool bR = false;
8265
8266 PNL (L68_ (if (max (e->N1, e->N2) < 128)
8267 DU_CYCLE_FLEN_128;))
8268
8269 for( ; cpu.du.CHTALLY < min(e->N1, e->N2); cpu.du.CHTALLY += 1)
8270 {
8271 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8272 bool b1 = EISgetBitRWN(cpup, &e->ADDR1, true);
8273 e->ADDR2.mode = eRWreadBit;
8274 bool b2 = EISgetBitRWN(cpup, &e->ADDR2, true);
8275
8276 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8277
8278 if (bR)
8279 {
8280
8281 cpu.du.Z = 0;
8282 }
8283
8284
8285 e->ADDR2.bit = bR ? 1 : 0;
8286 e->ADDR2.mode = eRWwriteBit;
8287
8288
8289 EISgetBitRWN(cpup, &e->ADDR2, e->ADDR1.last_bit_posn == 35);
8290 }
8291
8292 if (e->N1 < e->N2)
8293 {
8294 for(; cpu.du.CHTALLY < e->N2; cpu.du.CHTALLY += 1)
8295 {
8296 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8297 bool b1 = F;
8298
8299 e->ADDR2.mode = eRWreadBit;
8300 bool b2 = EISgetBitRWN(cpup, &e->ADDR2, true);
8301
8302 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8303
8304 if (bR)
8305 {
8306
8307 cpu.du.Z = 0;
8308 }
8309
8310
8311 e->ADDR2.bit = bR ? 1 : 0;
8312 e->ADDR2.mode = eRWwriteBit;
8313
8314
8315 EISgetBitRWN(cpup, &e->ADDR2, e->ADDR1.last_bit_posn == 35);
8316 }
8317 }
8318
8319 EISWriteCache (cpup, &e->ADDR2);
8320
8321 cleanupOperandDescriptor (cpup, 1);
8322 cleanupOperandDescriptor (cpup, 2);
8323
8324 SC_I_ZERO (cpu.du.Z);
8325 if (e->N1 > e->N2)
8326 {
8327
8328
8329
8330
8331
8332
8333 SET_I_TRUNC;
8334 if (T && tstOVFfault (cpup))
8335 doFault(FAULT_OFL, fst_zero, "csl truncation fault");
8336 }
8337 else
8338 {
8339 CLR_I_TRUNC;
8340 }
8341 }
8342
8343
8344
8345
8346
8347
8348
8349
8350 static void getBitOffsets(int length, int initC, int initB, int *nWords, int *newC, int *newB)
8351 {
8352 if (length == 0)
8353 return;
8354
8355 int endBit = (length + 9 * initC + initB - 1) % 36;
8356
8357
8358 int numWords = (length + 9 * initC + initB + 35) / 36;
8359 int lastWordOffset = numWords - 1;
8360
8361 if (lastWordOffset > 0)
8362 *nWords = lastWordOffset;
8363 else
8364 *nWords = 0;
8365
8366 *newC = endBit / 9;
8367 *newB = endBit % 9;
8368 }
8369
8370 static bool EISgetBitRWNR (cpu_state_t * cpup, EISaddr * p, bool flush)
8371 {
8372 int baseCharPosn = (p -> cPos * 9);
8373 int baseBitPosn = baseCharPosn + p -> bPos;
8374 baseBitPosn -= (int) cpu.du.CHTALLY;
8375
8376 int bitPosn = baseBitPosn % 36;
8377 int woff = baseBitPosn / 36;
8378 while (bitPosn < 0)
8379 {
8380 bitPosn += 36;
8381 woff -= 1;
8382 }
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393 #if defined(EIS_PTR)
8394 long eisaddr_idx = EISADDR_IDX (p);
8395 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
8396 word18 saveAddr = cpu.du.Dk_PTR_W[eisaddr_idx];
8397 cpu.du.Dk_PTR_W[eisaddr_idx] += (word18) woff;
8398 cpu.du.Dk_PTR_W[eisaddr_idx] &= AMASK;
8399 #else
8400 word18 saveAddr = p -> address;
8401
8402
8403 p->address = (word18) (((word18s) p->address) + (word18s) woff);
8404 #endif
8405
8406 p -> data = EISRead (cpup, p);
8407
8408 if (p -> mode == eRWreadBit)
8409 {
8410 p -> bit = getbits36_1 (p -> data, (uint) bitPosn);
8411 }
8412 else if (p -> mode == eRWwriteBit)
8413 {
8414
8415 p -> data = setbits36_1 (p -> data, (uint) bitPosn, p -> bit);
8416
8417 EISWriteIdx (cpup, p, 0, p -> data, flush);
8418 }
8419
8420 p->last_bit_posn = bitPosn;
8421
8422 #if defined(EIS_PTR)
8423 cpu.du.Dk_PTR_W[eisaddr_idx] = saveAddr;
8424 #else
8425 p -> address = saveAddr;
8426 #endif
8427 return p -> bit;
8428 }
8429
8430 void csr (cpu_state_t * cpup)
8431 {
8432 EISstruct * e = & cpu.currentEISinstruction;
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471 fault_ipr_subtype_ mod_fault = 0;
8472
8473 #if !defined(EIS_SETUP)
8474 setupOperandDescriptor(cpup, 1, &mod_fault);
8475 setupOperandDescriptor(cpup, 2, &mod_fault);
8476 #endif
8477
8478 parseBitstringOperandDescriptor(cpup, 1, &mod_fault);
8479 parseBitstringOperandDescriptor(cpup, 2, &mod_fault);
8480
8481 L68_ (
8482
8483 if (mod_fault)
8484 doFault (FAULT_IPR,
8485 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8486 "Illegal modifier");
8487 )
8488
8489
8490 if (IWB_IRODD & 0360200000000)
8491 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "csr 1-4,10 MBZ");
8492
8493 DPS8M_ (
8494
8495 if (mod_fault)
8496 doFault (FAULT_IPR,
8497 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8498 "Illegal modifier");
8499 )
8500
8501 e->ADDR1.cPos = (int) e->C1;
8502 e->ADDR2.cPos = (int) e->C2;
8503
8504 e->ADDR1.bPos = (int) e->B1;
8505 e->ADDR2.bPos = (int) e->B2;
8506
8507
8508 int numWords1=0, numWords2=0;
8509
8510 getBitOffsets((int) e->N1, (int) e->C1, (int) e->B1, &numWords1, &e->ADDR1.cPos, &e->ADDR1.bPos);
8511 PNL (cpu.du.D1_PTR_W += (word18) numWords1);
8512 PNL (cpu.du.D1_PTR_W &= AMASK);
8513 #if defined(EIS_PTR)
8514 cpu.du.D1_PTR_W += (word18) numWords1;
8515 cpu.du.D1_PTR_W &= AMASK;
8516 #else
8517 e->ADDR1.address += (word18) numWords1;
8518 #endif
8519
8520 sim_debug (DBG_TRACEEXT, & cpu_dev,
8521 "CSR N1 %d C1 %d B1 %d numWords1 %d cPos %d bPos %d\r\n",
8522 e->N1, e->C1, e->B1, numWords1, e->ADDR1.cPos, e->ADDR1.bPos);
8523 getBitOffsets((int) e->N2, (int) e->C2, (int) e->B2, &numWords2, &e->ADDR2.cPos, &e->ADDR2.bPos);
8524 sim_debug (DBG_TRACEEXT, & cpu_dev,
8525 "CSR N2 %d C2 %d B2 %d numWords2 %d cPos %d bPos %d\r\n",
8526 e->N2, e->C2, e->B2, numWords2, e->ADDR2.cPos, e->ADDR2.bPos);
8527 PNL (cpu.du.D2_PTR_W += (word18) numWords1);
8528 PNL (cpu.du.D2_PTR_W &= AMASK);
8529 #if defined(EIS_PTR)
8530 cpu.du.D2_PTR_W += (word18) numWords1;
8531 cpu.du.D2_PTR_W &= AMASK;
8532 #else
8533 e->ADDR2.address += (word18) numWords2;
8534 #endif
8535
8536 bool F = getbits36_1 (cpu.cu.IWB, 0) != 0;
8537 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
8538
8539 uint BOLR = getbits36_4 (cpu.cu.IWB, 5);
8540 bool B5 = !! (BOLR & 8);
8541 bool B6 = !! (BOLR & 4);
8542 bool B7 = !! (BOLR & 2);
8543 bool B8 = !! (BOLR & 1);
8544
8545 e->ADDR1.mode = eRWreadBit;
8546
8547 CLR_I_TRUNC;
8548
8549 bool bR = false;
8550
8551 PNL (L68_ (if (max (e->N1, e->N2) < 128)
8552 DU_CYCLE_FLEN_128;))
8553
8554 for( ; cpu.du.CHTALLY < min(e->N1, e->N2); cpu.du.CHTALLY += 1)
8555 {
8556 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8557 bool b1 = EISgetBitRWNR(cpup, &e->ADDR1, true);
8558
8559 e->ADDR2.mode = eRWreadBit;
8560 bool b2 = EISgetBitRWNR(cpup, &e->ADDR2, true);
8561
8562 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8563
8564 if (bR)
8565 cpu.du.Z = 0;
8566
8567
8568 e->ADDR2.bit = bR ? 1 : 0;
8569 e->ADDR2.mode = eRWwriteBit;
8570
8571
8572 EISgetBitRWNR(cpup, &e->ADDR2, e->ADDR1.last_bit_posn == 0);
8573 }
8574
8575 if (e->N1 < e->N2)
8576 {
8577 for(; cpu.du.CHTALLY < e->N2; cpu.du.CHTALLY += 1)
8578 {
8579 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8580 bool b1 = F;
8581
8582 e->ADDR2.mode = eRWreadBit;
8583 bool b2 = EISgetBitRWNR(cpup, &e->ADDR2, true);
8584
8585 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8586
8587 if (bR)
8588 {
8589
8590 cpu.du.Z = 0;
8591 }
8592
8593
8594 e->ADDR2.bit = bR ? 1 : 0;
8595 e->ADDR2.mode = eRWwriteBit;
8596
8597
8598 EISgetBitRWNR(cpup, &e->ADDR2, e->ADDR1.last_bit_posn == 0);
8599 }
8600 }
8601
8602 EISWriteCache (cpup, &e->ADDR2);
8603
8604 cleanupOperandDescriptor (cpup, 1);
8605 cleanupOperandDescriptor (cpup, 2);
8606
8607 SC_I_ZERO (cpu.du.Z);
8608 if (e->N1 > e->N2)
8609 {
8610
8611
8612
8613
8614
8615
8616 SET_I_TRUNC;
8617 if (T && tstOVFfault (cpup))
8618 doFault(FAULT_OFL, fst_zero, "csr truncation fault");
8619 }
8620 else
8621 {
8622 CLR_I_TRUNC;
8623 }
8624 }
8625
8626 void sztl (cpu_state_t * cpup)
8627 {
8628
8629
8630
8631
8632 EISstruct * e = & cpu.currentEISinstruction;
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689 fault_ipr_subtype_ mod_fault = 0;
8690
8691 #if !defined(EIS_SETUP)
8692 setupOperandDescriptor (cpup, 1, &mod_fault);
8693 setupOperandDescriptor (cpup, 2, &mod_fault);
8694 #endif
8695
8696 parseBitstringOperandDescriptor (cpup, 1, &mod_fault);
8697 parseBitstringOperandDescriptor (cpup, 2, &mod_fault);
8698
8699 L68_ (
8700
8701 if (mod_fault)
8702 doFault (FAULT_IPR,
8703 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8704 "Illegal modifier");
8705 )
8706
8707
8708 if (IWB_IRODD & 0360200000000)
8709 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "csl 1-4,10 MBZ");
8710
8711 DPS8M_ (
8712
8713 if (mod_fault)
8714 doFault (FAULT_IPR,
8715 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8716 "Illegal modifier");
8717 )
8718
8719 e->ADDR1.cPos = (int) e->C1;
8720 e->ADDR2.cPos = (int) e->C2;
8721
8722 e->ADDR1.bPos = (int) e->B1;
8723 e->ADDR2.bPos = (int) e->B2;
8724
8725 bool F = getbits36_1 (cpu.cu.IWB, 0) != 0;
8726 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
8727
8728 uint BOLR = getbits36_4 (cpu.cu.IWB, 5);
8729 bool B5 = !! (BOLR & 8);
8730 bool B6 = !! (BOLR & 4);
8731 bool B7 = !! (BOLR & 2);
8732 bool B8 = !! (BOLR & 1);
8733
8734 e->ADDR1.mode = eRWreadBit;
8735 e->ADDR2.mode = eRWreadBit;
8736
8737 #if !defined(EIS_PTR)
8738 sim_debug (DBG_TRACEEXT, & cpu_dev,
8739 "SZTL N1 %d N2 %d\r\n"
8740 "SZTL C1 %d C2 %d B1 %d B2 %d F %o T %d\r\n"
8741 "SZTL BOLR %u%u%u%u\r\n"
8742 "SZTL op1 SNR %06o WORDNO %06o CHAR %d BITNO %d\r\n"
8743 "SZTL op2 SNR %06o WORDNO %06o CHAR %d BITNO %d\r\n",
8744 e -> N1, e -> N2,
8745 e -> C1, e -> C2, e -> B1, e -> B2, F, T,
8746 B5, B6, B7, B8,
8747 e -> addr [0].SNR, e -> addr [0].address,
8748 e -> addr [0].cPos, e -> addr [0].bPos,
8749 e -> addr [1].SNR, e -> addr [1].address,
8750 e -> addr [1].cPos, e -> addr [1].bPos);
8751 #endif
8752
8753 bool bR = false;
8754
8755 PNL (L68_ (if (max (e->N1, e->N2) < 128)
8756 DU_CYCLE_FLEN_128;))
8757
8758 for( ; cpu.du.CHTALLY < min (e->N1, e->N2); cpu.du.CHTALLY += 1)
8759 {
8760 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8761 bool b1 = EISgetBitRWN (cpup, & e->ADDR1, true);
8762 bool b2 = EISgetBitRWN (cpup, & e->ADDR2, true);
8763
8764 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8765
8766 if (bR)
8767 {
8768
8769 cpu.du.Z = 0;
8770 break;
8771 }
8772 }
8773
8774 if (e->N1 < e->N2)
8775 {
8776 for (; cpu.du.CHTALLY < e->N2; cpu.du.CHTALLY += 1)
8777 {
8778 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8779 bool b1 = F;
8780 bool b2 = EISgetBitRWN (cpup, & e->ADDR2, true);
8781
8782 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8783
8784 if (bR)
8785 {
8786
8787 cpu.du.Z = 0;
8788 break;
8789 }
8790 }
8791 }
8792
8793 cleanupOperandDescriptor (cpup, 1);
8794 cleanupOperandDescriptor (cpup, 2);
8795
8796 SC_I_ZERO (cpu.du.Z);
8797 if (e->N1 > e->N2)
8798 {
8799
8800
8801
8802
8803
8804
8805 SET_I_TRUNC;
8806 if (T && tstOVFfault (cpup))
8807 doFault(FAULT_OFL, fst_zero, "csl truncation fault");
8808 }
8809 else
8810 {
8811 CLR_I_TRUNC;
8812 }
8813 }
8814
8815 void sztr (cpu_state_t * cpup)
8816 {
8817
8818
8819
8820
8821 EISstruct * e = & cpu.currentEISinstruction;
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860 fault_ipr_subtype_ mod_fault = 0;
8861
8862 #if !defined(EIS_SETUP)
8863 setupOperandDescriptor(cpup, 1, &mod_fault);
8864 setupOperandDescriptor(cpup, 2, &mod_fault);
8865 #endif
8866
8867 parseBitstringOperandDescriptor(cpup, 1, &mod_fault);
8868 parseBitstringOperandDescriptor(cpup, 2, &mod_fault);
8869
8870 L68_ (
8871
8872 if (mod_fault)
8873 doFault (FAULT_IPR,
8874 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8875 "Illegal modifier");
8876 )
8877
8878
8879 if (IWB_IRODD & 0360200000000)
8880 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "csr 1-4,10 MBZ");
8881
8882 DPS8M_ (
8883
8884 if (mod_fault)
8885 doFault (FAULT_IPR,
8886 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
8887 "Illegal modifier");
8888 )
8889
8890 e->ADDR1.cPos = (int) e->C1;
8891 e->ADDR2.cPos = (int) e->C2;
8892
8893 e->ADDR1.bPos = (int) e->B1;
8894 e->ADDR2.bPos = (int) e->B2;
8895
8896
8897 int numWords1=0, numWords2=0;
8898
8899 getBitOffsets((int) e->N1, (int) e->C1, (int) e->B1, &numWords1, &e->ADDR1.cPos, &e->ADDR1.bPos);
8900 PNL (cpu.du.D1_PTR_W += (word18) numWords1);
8901 PNL (cpu.du.D1_PTR_W &= AMASK);
8902 #if defined(EIS_PTR)
8903 cpu.du.D1_PTR_W += (word18) numWords1;
8904 cpu.du.D1_PTR_W &= AMASK;
8905 #else
8906 e->ADDR1.address += (word18) numWords1;
8907 #endif
8908
8909 sim_debug (DBG_TRACEEXT, & cpu_dev,
8910 "CSR N1 %d C1 %d B1 %d numWords1 %d cPos %d bPos %d\r\n",
8911 e->N1, e->C1, e->B1, numWords1, e->ADDR1.cPos, e->ADDR1.bPos);
8912 getBitOffsets((int) e->N2, (int) e->C2, (int) e->B2, &numWords2, &e->ADDR2.cPos, &e->ADDR2.bPos);
8913 sim_debug (DBG_TRACEEXT, & cpu_dev,
8914 "CSR N2 %d C2 %d B2 %d numWords2 %d cPos %d bPos %d\r\n",
8915 e->N2, e->C2, e->B2, numWords2, e->ADDR2.cPos, e->ADDR2.bPos);
8916 PNL (cpu.du.D2_PTR_W += (word18) numWords1);
8917 PNL (cpu.du.D2_PTR_W &= AMASK);
8918 #if defined(EIS_PTR)
8919 cpu.du.D2_PTR_W += (word18) numWords1;
8920 cpu.du.D2_PTR_W &= AMASK;
8921 #else
8922 e->ADDR2.address += (word18) numWords2;
8923 #endif
8924
8925 bool F = getbits36_1 (cpu.cu.IWB, 0) != 0;
8926 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
8927
8928 uint BOLR = getbits36_4 (cpu.cu.IWB, 5);
8929 bool B5 = !! (BOLR & 8);
8930 bool B6 = !! (BOLR & 4);
8931 bool B7 = !! (BOLR & 2);
8932 bool B8 = !! (BOLR & 1);
8933
8934 e->ADDR1.mode = eRWreadBit;
8935
8936 CLR_I_TRUNC;
8937
8938 bool bR = false;
8939
8940 PNL (L68_ (if (max (e->N1, e->N2) < 128)
8941 DU_CYCLE_FLEN_128;))
8942
8943 for( ; cpu.du.CHTALLY < min(e->N1, e->N2); cpu.du.CHTALLY += 1)
8944 {
8945 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8946 bool b1 = EISgetBitRWNR(cpup, &e->ADDR1, true);
8947
8948 e->ADDR2.mode = eRWreadBit;
8949 bool b2 = EISgetBitRWNR(cpup, &e->ADDR2, true);
8950
8951 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8952
8953 if (bR)
8954 {
8955 cpu.du.Z = 0;
8956 break;
8957 }
8958
8959 }
8960
8961 if (e->N1 < e->N2)
8962 {
8963 for(; cpu.du.CHTALLY < e->N2; cpu.du.CHTALLY += 1)
8964 {
8965 tandd_eis_sample (cpup, cpu.du.CHTALLY, 36);
8966 bool b1 = F;
8967
8968 e->ADDR2.mode = eRWreadBit;
8969 bool b2 = EISgetBitRWNR(cpup, &e->ADDR2, true);
8970
8971 if (b1) if (b2) bR = B8; else bR = B7; else if (b2) bR = B6; else bR = B5;
8972
8973 if (bR)
8974 {
8975
8976 cpu.du.Z = 0;
8977 break;
8978 }
8979
8980 }
8981 }
8982
8983 cleanupOperandDescriptor (cpup, 1);
8984 cleanupOperandDescriptor (cpup, 2);
8985
8986 SC_I_ZERO (cpu.du.Z);
8987 if (e->N1 > e->N2)
8988 {
8989
8990
8991
8992
8993
8994
8995 SET_I_TRUNC;
8996 if (T && tstOVFfault (cpup))
8997 doFault(FAULT_OFL, fst_zero, "csr truncation fault");
8998 }
8999 else
9000 {
9001 CLR_I_TRUNC;
9002 }
9003 }
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014 static bool EISgetBit(cpu_state_t * cpup, EISaddr *p, int *cpos, int *bpos)
9015 {
9016 #if defined(EIS_PTR)
9017 long eisaddr_idx = EISADDR_IDX (p);
9018 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
9019 #endif
9020
9021 if (!p)
9022 {
9023
9024 return 0;
9025 }
9026
9027 if (*bpos > 8)
9028 {
9029 *bpos = 0;
9030 *cpos += 1;
9031 if (*cpos > 3)
9032 {
9033 *cpos = 0;
9034 #if defined(EIS_PTR)
9035 cpu.du.Dk_PTR_W[eisaddr_idx] += 1;
9036 cpu.du.Dk_PTR_W[eisaddr_idx] &= AMASK;
9037 #else
9038 p->address += 1;
9039 p->address &= AMASK;
9040 #endif
9041 }
9042 }
9043
9044 p->data = EISRead(cpup, p);
9045
9046 int charPosn = *cpos * 9;
9047 int bitPosn = charPosn + *bpos;
9048 bool b = getbits36_1 (p->data, (uint) bitPosn) != 0;
9049
9050 *bpos += 1;
9051
9052 return b;
9053 }
9054
9055 void cmpb (cpu_state_t * cpup)
9056 {
9057 EISstruct * e = & cpu.currentEISinstruction;
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070 fault_ipr_subtype_ mod_fault = 0;
9071
9072 #if !defined(EIS_SETUP)
9073 setupOperandDescriptor(cpup, 1, &mod_fault);
9074 setupOperandDescriptor(cpup, 2, &mod_fault);
9075 #endif
9076
9077 parseBitstringOperandDescriptor(cpup, 1, &mod_fault);
9078 parseBitstringOperandDescriptor(cpup, 2, &mod_fault);
9079
9080 L68_ (
9081
9082 if (mod_fault)
9083 {
9084 doFault (FAULT_IPR,
9085 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
9086 "Illegal modifier");
9087 }
9088 )
9089
9090
9091 if (IWB_IRODD & 0377200000000)
9092 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "cmpb 1-8,10 MBZ");
9093
9094 DPS8M_ (
9095
9096 if (mod_fault)
9097 {
9098 doFault (FAULT_IPR,
9099 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
9100 "Illegal modifier");
9101 }
9102 )
9103
9104 int charPosn1 = (int) e->C1;
9105 int charPosn2 = (int) e->C2;
9106
9107 int bitPosn1 = (int) e->B1;
9108 int bitPosn2 = (int) e->B2;
9109
9110 bool F = getbits36_1 (cpu.cu.IWB, 0) != 0;
9111
9112 SET_I_ZERO;
9113 SET_I_CARRY;
9114
9115 sim_debug (DBG_TRACEEXT, & cpu_dev, "cmpb N1 %d N2 %d\r\n", e -> N1, e -> N2);
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133 PNL (L68_ (if (max (e->N1, e->N2) < 128)
9134 DU_CYCLE_FLEN_128;))
9135
9136 uint i = 0;
9137
9138
9139 if (cpu.tweaks.tandd_mode)
9140 for ( ; i < cpu.du.CHTALLY; i ++)
9141 {
9142 if (i < e->N1)
9143 (void) EISgetBit (cpup, &e->ADDR1, &charPosn1, &bitPosn1);
9144 if (i < e->N2)
9145 (void) EISgetBit (cpup, &e->ADDR2, &charPosn2, &bitPosn2);
9146 }
9147 for( ; i < min(e->N1, e->N2) ; i += 1)
9148 {
9149 tandd_eis_sample (cpup, i, 36);
9150 bool b1 = EISgetBit (cpup, &e->ADDR1, &charPosn1, &bitPosn1);
9151 bool b2 = EISgetBit (cpup, &e->ADDR2, &charPosn2, &bitPosn2);
9152
9153 sim_debug (DBG_TRACEEXT, & cpu_dev, "cmpb(min(e->N1, e->N2)) i %d b1 %d b2 %d\r\n", i, b1, b2);
9154 if (b1 != b2)
9155 {
9156 CLR_I_ZERO;
9157 if (!b1 && b2)
9158 CLR_I_CARRY;
9159
9160 cleanupOperandDescriptor (cpup, 1);
9161 cleanupOperandDescriptor (cpup, 2);
9162
9163 return;
9164 }
9165
9166 }
9167 if (e->N1 < e->N2)
9168 {
9169 for(; i < e->N2 ; i += 1)
9170 {
9171 tandd_eis_sample (cpup, i, 36);
9172 bool b1 = F;
9173 bool b2 = EISgetBit(cpup, &e->ADDR2, &charPosn2, &bitPosn2);
9174 sim_debug (DBG_TRACEEXT, & cpu_dev, "cmpb(e->N1 < e->N2) i %d b1fill %d b2 %d\r\n", i, b1, b2);
9175
9176 if (b1 != b2)
9177 {
9178 CLR_I_ZERO;
9179 if (!b1 && b2)
9180 CLR_I_CARRY;
9181
9182 cleanupOperandDescriptor (cpup, 1);
9183 cleanupOperandDescriptor (cpup, 2);
9184
9185 return;
9186 }
9187 }
9188 } else if (e->N1 > e->N2)
9189 {
9190 for(; i < e->N1 ; i += 1)
9191 {
9192 tandd_eis_sample (cpup, i, 36);
9193 bool b1 = EISgetBit(cpup, &e->ADDR1, &charPosn1, &bitPosn1);
9194 bool b2 = F;
9195 sim_debug (DBG_TRACEEXT, & cpu_dev, "cmpb(e->N1 > e->N2) i %d b1 %d b2fill %d\r\n", i, b1, b2);
9196
9197 if (b1 != b2)
9198 {
9199 CLR_I_ZERO;
9200 if (!b1 && b2)
9201 CLR_I_CARRY;
9202
9203 cleanupOperandDescriptor (cpup, 1);
9204 cleanupOperandDescriptor (cpup, 2);
9205
9206 return;
9207 }
9208 }
9209 }
9210 cleanupOperandDescriptor (cpup, 1);
9211 cleanupOperandDescriptor (cpup, 2);
9212 }
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438 static bool sign9n(word72 n128, int N)
9439 {
9440
9441
9442
9443
9444
9445
9446
9447 if (N < 1 || N > 8)
9448 return false;
9449
9450 #if defined(NEED_128)
9451 word72 sgnmask = lshift_128 (construct_128 (0, 1), (uint) (N * 9 - 1));
9452 return isnonzero_128 (and_128 (sgnmask, n128));
9453 #else
9454 word72 sgnmask = (word72)1 << ((N * 9) - 1);
9455
9456 return (bool)(sgnmask & n128);
9457 #endif
9458 }
9459
9460
9461
9462
9463 static word72s signExt9(word72 n128, int N)
9464 {
9465
9466
9467
9468
9469
9470 int bits = (N * 9) - 1;
9471 if (sign9n(n128, N))
9472 {
9473 #if defined(NEED_128)
9474 uint128 extBits = lshift_128 (construct_128 (MASK64, MASK64), (uint) bits);
9475 uint128 or = or_128 (n128, extBits);
9476 return cast_s128 (or);
9477 #else
9478 uint128 extBits = ((uint128)-1 << bits);
9479 return (word72s) (n128 | extBits);
9480 #endif
9481 }
9482 #if defined(NEED_128)
9483 uint128 zeroBits = complement_128 (lshift_128 (construct_128 (MASK64, MASK64), (uint) bits));
9484 uint128 and = and_128 (n128, zeroBits);
9485 return cast_s128 (and);
9486 #else
9487 uint128 zeroBits = ~((uint128)-1 << bits);
9488 return (word72s) (n128 & zeroBits);
9489 #endif
9490 }
9491
9492
9493
9494
9495
9496 static void load9x(cpu_state_t * cpup, int n, EISaddr *addr, int pos)
9497 {
9498 EISstruct * e = & cpu.currentEISinstruction;
9499 #if defined(NEED_128)
9500 word72 x = construct_128 (0, 0);
9501 #else
9502 word72 x = 0;
9503 #endif
9504 #if defined(EIS_PTR)
9505 long eisaddr_idx = EISADDR_IDX (addr);
9506 if (eisaddr_idx < 0 || eisaddr_idx > 2) { sim_warn ("IDX1"); return }
9507 #endif
9508
9509 word36 data = EISRead(cpup, addr);
9510
9511 int m = n;
9512 while (m)
9513 {
9514 #if defined(NEED_128)
9515 x = lshift_128 (x, 9);
9516 #else
9517 x <<= 9;
9518 #endif
9519
9520 if (pos > 3)
9521 {
9522 pos = 0;
9523 #if EIS_PTR
9524 cpu.du.Dk_PTR_W[eisaddr_idx] = (cpu.du.Dk_PTR_W[eisaddr_idx] + 1) & AMASK;
9525 #else
9526 addr->address = (addr->address + 1) & AMASK;
9527 #endif
9528 data = EISRead(cpup, addr);
9529 }
9530
9531 #if defined(NEED_128)
9532 x = or_128 (x, construct_128 (0, GETBYTE (data, pos)));
9533 #else
9534 x |= GETBYTE(data, pos);
9535 #endif
9536
9537 pos += 1;
9538
9539 m -= 1;
9540 }
9541 e->x = signExt9(x, n);
9542 }
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664 void btd (cpu_state_t * cpup)
9665 {
9666 EISstruct * e = & cpu.currentEISinstruction;
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721 fault_ipr_subtype_ mod_fault = 0;
9722
9723 #if !defined(EIS_SETUP)
9724 setupOperandDescriptor(cpup, 1, &mod_fault);
9725 setupOperandDescriptor(cpup, 2, &mod_fault);
9726 #endif
9727
9728 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
9729 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
9730
9731 L68_ (
9732
9733 if (mod_fault)
9734 {
9735 doFault (FAULT_IPR,
9736 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
9737 "Illegal modifier");
9738 }
9739 )
9740
9741
9742 if (IWB_IRODD & 0377600000000)
9743 {
9744
9745 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "btd 0-8 MBZ");
9746 }
9747
9748
9749 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000077700)
9750 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "btd op1 21-29 MBZ");
9751
9752
9753 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000007700)
9754 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "btd op2 24-29 MBZ");
9755
9756 if (e->S[1] == 0)
9757 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "btd op2 S=0");
9758
9759 DPS8M_ (
9760
9761 if (mod_fault)
9762 {
9763 doFault (FAULT_IPR,
9764 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
9765 "Illegal modifier");
9766 }
9767 )
9768
9769 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
9770
9771 if (e->N1 == 0 || e->N1 > 8)
9772 doFault(FAULT_IPR, fst_ill_proc, "btd(1): N1 == 0 || N1 > 8");
9773
9774 uint dstTN = e->TN2;
9775 uint dstCN = e->CN2;
9776
9777 int n2 = 0;
9778
9779 switch(e->S2)
9780 {
9781 case CSLS:
9782 case CSTS:
9783 n2 = (int) e->N2 - 1;
9784 break;
9785
9786 case CSNS:
9787 n2 = (int) e->N2;
9788 break;
9789 }
9790
9791 sim_debug (DBG_CAC, & cpu_dev,
9792 "n2 %d\r\n",
9793 n2);
9794
9795 if (n2 < 1)
9796 doFault (FAULT_IPR, fst_ill_proc, "btd adjusted n2<1");
9797
9798 decContext set;
9799 decContextDefaultDPS8(&set);
9800 set.traps=0;
9801
9802 load9x(cpup, (int) e->N1, &e->ADDR1, (int) e->CN1);
9803
9804
9805 e->sign = 1;
9806 #if defined(NEED_128)
9807 word72 x = cast_128 (e->x);
9808 if (islt_s128 (e->x, construct_s128 (0, 0)))
9809 {
9810 e->sign = -1;
9811 x = and_128 (negate_128 (x), MASK72);
9812
9813 }
9814
9815
9816 char tmp[32];
9817 tmp[31] = 0;
9818 int i;
9819 for (i=30;i>=0;i--) {
9820
9821
9822 uint16_t r;
9823 x = divide_128_16 (x, 10, & r);
9824 tmp[i] = (char) r + '0';
9825 if (iszero_128 (x))
9826 break;
9827 }
9828 #else
9829 word72 x = (word72)e->x;
9830 if (e->x < 0) {
9831 e->sign = -1;
9832
9833
9834 x = ((word72) (- (word72s) x)) & MASK72;
9835 }
9836
9837
9838 char tmp[32];
9839 tmp[31] = 0;
9840 int i;
9841 for (i=30;i>=0;i--) {
9842 tmp[i] = x%10 + '0';
9843 x /= 10;
9844 if (x == 0)
9845 break;
9846 }
9847 #endif
9848
9849 decNumber _1;
9850 decNumber *op1 = decNumberFromString(&_1, tmp+i, &set);
9851 if (e->sign == -1)
9852 op1->bits |= DECNEG;
9853
9854 bool Ovr = false, Trunc = false;
9855
9856 uint8_t out [256];
9857 char * res = formatDecimal (out, &set, op1, n2, (int) e->S2, e->SF2, 0, &Ovr, &Trunc);
9858
9859
9860
9861
9862 int pos = (int) dstCN;
9863
9864
9865 switch(e->S2)
9866 {
9867 case CSLS:
9868 switch(dstTN)
9869 {
9870 case CTN4:
9871 if (e->P)
9872
9873
9874 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9875 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? 015 : 013);
9876 else
9877 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9878 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? 015 : 014);
9879 break;
9880 case CTN9:
9881 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9882 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? '-' : '+');
9883 break;
9884 }
9885 break;
9886
9887 case CSTS:
9888 case CSNS:
9889 break;
9890 }
9891
9892
9893 for(int i = 0 ; i < n2 ; i++)
9894 switch(dstTN)
9895 {
9896 case CTN4:
9897 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN, (word9) (res[i] - '0'));
9898 break;
9899 case CTN9:
9900 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN, (word9) res[i]);
9901 break;
9902 }
9903
9904
9905 switch(e->S2)
9906 {
9907 case CSTS:
9908 switch(dstTN)
9909 {
9910 case CTN4:
9911 if (e->P)
9912
9913
9914 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9915 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? 015 : 013);
9916 else
9917 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9918 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? 015 : 014);
9919 break;
9920
9921 case CTN9:
9922 EISwrite49(cpup, &e->ADDR2, &pos, (int) dstTN,
9923 (decNumberIsNegative(op1) && !decNumberIsZero(op1)) ? '-' : '+');
9924 break;
9925 }
9926 break;
9927
9928 case CSLS:
9929 case CSNS:
9930 break;
9931 }
9932
9933 SC_I_NEG (decNumberIsNegative(op1) && !decNumberIsZero(op1));
9934 SC_I_ZERO (decNumberIsZero(op1));
9935
9936 cleanupOperandDescriptor (cpup, 1);
9937 cleanupOperandDescriptor (cpup, 2);
9938
9939 if (Ovr)
9940 {
9941 SET_I_OFLOW;
9942 if (tstOVFfault (cpup))
9943 doFault(FAULT_OFL, fst_zero, "btd overflow fault");
9944 }
9945 }
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153 void dtb (cpu_state_t * cpup)
10154 {
10155 EISstruct * e = & cpu.currentEISinstruction;
10156
10157 fault_ipr_subtype_ mod_fault = 0;
10158
10159 #if !defined(EIS_SETUP)
10160 setupOperandDescriptor(cpup, 1, &mod_fault);
10161 setupOperandDescriptor(cpup, 2, &mod_fault);
10162 #endif
10163
10164 PNL (L68_ (DU_CYCLE_DGDB;))
10165
10166 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
10167 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
10168
10169 L68_ (
10170
10171 if (mod_fault)
10172 {
10173 doFault (FAULT_IPR,
10174 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10175 "Illegal modifier");
10176 }
10177 )
10178
10179
10180 uint mbz = (uint) getbits36 (IWB_IRODD, 0, 11);
10181 if (mbz)
10182 {
10183 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "dtb(): 0-10 MBZ");
10184 }
10185
10186
10187 if (!(e->MF[0] & MFkID) && e -> op [0] & 0000000007700)
10188 {
10189 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "dtb op1 24-29 MBZ");
10190 }
10191
10192
10193 if (!(e->MF[1] & MFkID) && e -> op [1] & 0000000077700)
10194 {
10195 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "dtb op2 21-29 MBZ");
10196 }
10197
10198
10199
10200 if (e->S1 == 0 || e->SF1 != 0)
10201 {
10202 doFault(FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC|mod_fault}, "dtb(): S1=0 or SF1!=0");
10203 }
10204
10205 DPS8M_ (
10206
10207 if (mod_fault)
10208 {
10209 doFault (FAULT_IPR,
10210 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10211 "Illegal modifier");
10212 }
10213 )
10214
10215
10216 if (e->N2 == 0 || e->N2 > 8)
10217 {
10218 doFault(FAULT_IPR, fst_ill_proc, "dtb(): N2 = 0 or N2 > 8 etc.");
10219 }
10220
10221 int n1 = 0;
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233 switch(e->S1)
10234 {
10235 case CSLS:
10236 case CSTS:
10237 n1 = (int) e->N1 - 1;
10238 break;
10239
10240 case CSNS:
10241 n1 = (int) e->N1;
10242 break;
10243 }
10244
10245
10246
10247
10248 if (n1 < 1)
10249 doFault (FAULT_IPR, fst_ill_proc, "dtb adjusted n1<1");
10250
10251 EISloadInputBufferNumeric (cpup, 1);
10252
10253
10254 #if defined(NEED_128)
10255 word72 msk = subtract_128 (lshift_128 (construct_128 (0, 1), (9*e->N2-1)),construct_128 (0, 1));
10256 #else
10257 word72 msk = ((word72)1<<(9*e->N2-1))-1;
10258 #endif
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274 bool Ovr = false;
10275
10276
10277
10278
10279
10280 int first = 0;
10281 if (n1 > 32)
10282 {
10283 first = n1 - 32;
10284 for (int i = 0; i < first; i ++)
10285 if (e->inBuffer[i])
10286 Ovr = true;
10287 }
10288 #if defined(NEED_128)
10289 word72 x = construct_128 (0, 0);
10290 for (int i = first; i < n1; i++) {
10291
10292 x = multiply_128 (x, construct_128 (0, 10));
10293
10294 x = add_128 (x, construct_128 (0, (uint) e->inBuffer[i]));
10295
10296 Ovr |= isgt_128 (x, msk) ? 1 : 0;
10297
10298 x = and_128 (x, msk);
10299 }
10300 if (e->sign == -1)
10301
10302 x = negate_128 (x);
10303
10304 #else
10305 word72 x = 0;
10306 for (int i = first; i < n1; i++) {
10307 x *= 10;
10308 x += e->inBuffer[i];
10309
10310 Ovr |= x>msk?1:0;
10311 x &= msk;
10312 }
10313 if (e->sign == -1)
10314
10315
10316 x = (word72) (- (word72s) x);
10317
10318
10319 #endif
10320 int pos = (int)e->CN2;
10321
10322
10323
10324 int shift = 9*((int)e->N2-1);
10325 for(int i = 0; i < (int)e->N2; i++) {
10326 #if defined(NEED_128)
10327 EISwrite9(cpup, &e->ADDR2, &pos, (word9) rshift_128 (x, (uint) shift).l & 0777);
10328 #else
10329 EISwrite9(cpup, &e->ADDR2, &pos, (word9) (x >> shift )& 0777);
10330 #endif
10331 shift -= 9;
10332 }
10333
10334 SC_I_NEG (e->sign == -1);
10335 #if defined(NEED_128)
10336 SC_I_ZERO (iszero_128 (x));
10337 #else
10338 SC_I_ZERO (x==0);
10339 #endif
10340
10341 cleanupOperandDescriptor (cpup, 1);
10342 cleanupOperandDescriptor (cpup, 2);
10343
10344 if (Ovr)
10345 {
10346 SET_I_OFLOW;
10347 if (tstOVFfault (cpup))
10348 doFault(FAULT_OFL, fst_zero, "dtb overflow fault");
10349 }
10350 }
10351
10352
10353
10354
10355
10356 #define ASC(x) ((x) + '0')
10357
10358
10359
10360
10361
10362
10363
10364 #define FIXED_OVERFLOW_DIGITS 63
10365 #define FIXED_ALIGN_DIGITS 64
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375 static bool eisWindow (decNumber * x, int32_t limit)
10376 {
10377 if (decNumberIsZero (x) || x->exponent + x->digits <= limit)
10378 return false;
10379 uint8_t bcd[DECNUMDIGITS + 1];
10380 decNumberGetBCD (x, bcd);
10381 int drop = x->digits - (limit - x->exponent);
10382 if (drop > x->digits)
10383 drop = x->digits;
10384 bool lost = false;
10385 for (int i = 0; i < drop; i ++)
10386 if (bcd[i])
10387 lost = true;
10388 int j = drop;
10389 while (j < x->digits && bcd[j] == 0)
10390 j ++;
10391 bool neg = decNumberIsNegative (x);
10392 int32_t ex = x->exponent;
10393 if (j == x->digits)
10394 decNumberZero (x);
10395 else
10396 {
10397
10398
10399 uint32_t n = (uint32_t) (x->digits - j);
10400 x->digits = (int32_t) n;
10401 decNumberSetBCD (x, bcd + j, n);
10402 }
10403 x->exponent = ex;
10404 if (neg)
10405 x->bits |= DECNEG;
10406 return lost;
10407 }
10408
10409
10410
10411
10412
10413
10414
10415
10416 static bool eisWindowOperands (decNumber * a, decNumber * b)
10417 {
10418 bool za = decNumberIsZero (a), zb = decNumberIsZero (b);
10419 if (za && zb)
10420 return false;
10421 int32_t lo = za ? b->exponent : zb ? a->exponent : min (a->exponent, b->exponent);
10422 bool la = eisWindow (a, lo + FIXED_ALIGN_DIGITS);
10423 bool lb = eisWindow (b, lo + FIXED_ALIGN_DIGITS);
10424 return la || lb;
10425 }
10426
10427
10428
10429
10430
10431
10432
10433 #define FLOAT_ALIGN_DIGITS 63
10434
10435 static void eisWindowLow (decNumber * x, int32_t low)
10436 {
10437 if (decNumberIsZero (x) || x->exponent >= low)
10438 return;
10439 bool neg = decNumberIsNegative (x);
10440 int drop = low - x->exponent;
10441 if (drop >= x->digits)
10442 {
10443 decNumberZero (x);
10444 x->exponent = low;
10445 return;
10446 }
10447 uint8_t bcd[DECNUMDIGITS + 1];
10448 decNumberGetBCD (x, bcd);
10449
10450 x->digits -= drop;
10451 decNumberSetBCD (x, bcd, (uint32_t) x->digits);
10452 x->exponent = low;
10453 if (neg)
10454 x->bits |= DECNEG;
10455 }
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470 static bool eisFloatAlignTrunc (decNumber * a, decNumber * b)
10471 {
10472 if (decNumberIsZero (a) || decNumberIsZero (b))
10473 return false;
10474 int32_t ta = a->exponent + a->digits;
10475 int32_t tb = b->exponent + b->digits;
10476 decNumber * lo = tb >= ta ? a : b;
10477 int32_t shift = tb >= ta ? tb - ta : ta - tb;
10478 return shift + 1 + lo->digits >= 65;
10479 }
10480
10481 static void eisFloatWindowOperands (decNumber * a, decNumber * b)
10482 {
10483 int32_t hi;
10484 if (decNumberIsZero (a) && decNumberIsZero (b))
10485 return;
10486 if (decNumberIsZero (a))
10487 hi = b->exponent + b->digits;
10488 else if (decNumberIsZero (b))
10489 hi = a->exponent + a->digits;
10490 else
10491 hi = max (a->exponent + a->digits, b->exponent + b->digits);
10492 eisWindowLow (a, hi - FLOAT_ALIGN_DIGITS);
10493 eisWindowLow (b, hi - FLOAT_ALIGN_DIGITS);
10494 }
10495
10496
10497
10498
10499
10500 void ad2d (cpu_state_t * cpup)
10501 {
10502 EISstruct * e = & cpu.currentEISinstruction;
10503
10504 fault_ipr_subtype_ mod_fault = 0;
10505
10506 #if !defined(EIS_SETUP)
10507 setupOperandDescriptor(cpup, 1, &mod_fault);
10508 setupOperandDescriptor(cpup, 2, &mod_fault);
10509 setupOperandDescriptorCache(cpup,3);
10510 #endif
10511
10512 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
10513 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
10514
10515 L68_ (
10516
10517 if (mod_fault)
10518 {
10519 doFault (FAULT_IPR,
10520 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10521 "Illegal modifier");
10522 }
10523 )
10524
10525
10526 if (IWB_IRODD & 0377000000000)
10527 doFault (FAULT_IPR, fst_ill_op, "ad2d 1-8 MBZ");
10528
10529 DPS8M_ (
10530
10531 if (mod_fault)
10532 {
10533 doFault (FAULT_IPR,
10534 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10535 "Illegal modifier");
10536 }
10537 )
10538
10539 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
10540 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
10541 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
10542
10543 PNL (L68_ (if (R)
10544 DU_CYCLE_FRND;))
10545
10546 uint srcTN = e->TN1;
10547
10548 uint dstTN = e->TN2;
10549 uint dstCN = e->CN2;
10550
10551 e->ADDR3 = e->ADDR2;
10552
10553 int n1 = 0, n2 = 0, sc1 = 0, sc2 = 0;
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565 switch(e->S1)
10566 {
10567 case CSFL:
10568 n1 = (int) e->N1 - 1;
10569 if (srcTN == CTN4)
10570 n1 -= 2;
10571 else
10572 n1 -= 1;
10573 sc1 = 0;
10574 break;
10575
10576 case CSLS:
10577 case CSTS:
10578 n1 = (int) e->N1 - 1;
10579 sc1 = -e->SF1;
10580 break;
10581
10582 case CSNS:
10583 n1 = (int) e->N1;
10584 sc1 = -e->SF1;
10585 break;
10586 }
10587
10588 if (n1 < 1)
10589 doFault (FAULT_IPR, fst_ill_proc, "ad2d adjusted n1<1");
10590
10591 switch(e->S2)
10592 {
10593 case CSFL:
10594 n2 = (int) e->N2 - 1;
10595 if (e->TN2 == CTN4)
10596 n2 -= 2;
10597 else
10598 n2 -= 1;
10599 sc2 = 0;
10600 break;
10601
10602 case CSLS:
10603 case CSTS:
10604 n2 = (int) e->N2 - 1;
10605 sc2 = -e->SF2;
10606 break;
10607
10608 case CSNS:
10609 n2 = (int) e->N2;
10610 sc2 = -e->SF2;
10611 break;
10612 }
10613
10614 if (n2 < 1)
10615 doFault (FAULT_IPR, fst_ill_proc, "ad2d adjusted n2<1");
10616
10617 decContext set;
10618
10619 decContextDefaultDPS8(&set);
10620
10621 set.traps=0;
10622
10623 decNumber _1, _2, _3;
10624
10625 EISloadInputBufferNumeric (cpup, 1);
10626
10627 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
10628 if (e->sign == -1)
10629 op1->bits |= DECNEG;
10630 if (e->S1 == CSFL)
10631 op1->exponent = e->exponent;
10632
10633 EISloadInputBufferNumeric (cpup, 2);
10634
10635 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
10636 if (e->sign == -1)
10637 op2->bits |= DECNEG;
10638 if (e->S2 == CSFL)
10639 op2->exponent = e->exponent;
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650 decNumber *op3;
10651 bool winLost = false;
10652 bool fltAlignTrunc = false;
10653 if (e->S2 != CSFL)
10654 {
10655 enum rounding safeR = decContextGetRounding(&set);
10656 int safe = set.digits;
10657 set.digits = DECNUMDIGITS;
10658 decContextSetRounding(&set, DEC_ROUND_DOWN);
10659 winLost = eisWindowOperands (op1, op2);
10660 op3 = decNumberAdd(&_3, op1, op2, &set);
10661 set.digits = safe;
10662 decContextSetRounding(&set, safeR);
10663 }
10664 else
10665 {
10666 fltAlignTrunc = eisFloatAlignTrunc (op1, op2);
10667 eisFloatWindowOperands (op1, op2);
10668 op3 = decNumberAdd(&_3, op1, op2, &set);
10669 }
10670
10671
10672 bool iOvr = winLost;
10673 if (op3->digits > 63 && e->S2 == CSFL) {
10674
10675
10676
10677
10678
10679 enum rounding safeR = decContextGetRounding(&set);
10680 int safe = set.digits;
10681 decContextSetRounding(&set, DEC_ROUND_DOWN);
10682 set.digits = 63;
10683 decNumberPlus(op3, op3, &set);
10684 set.digits = safe;
10685 decContextSetRounding(&set, safeR);
10686 } else if (op3->digits > FIXED_OVERFLOW_DIGITS) {
10687 uint8_t pr[256];
10688
10689
10690 int sf = e->S2==CSFL?op3->exponent:e->SF2;
10691
10692 int ctz = 0;
10693 if (sf>0) {
10694 decNumberGetBCD(op3,pr);
10695 for (int i=op3->digits-1;i>=0 && pr[i]==0;i--)
10696 ctz ++;
10697 }
10698
10699 int span = op3->digits - min(max(sf,0),ctz);
10700 if (span > FIXED_OVERFLOW_DIGITS)
10701 iOvr = 1;
10702 if (span > FIXED_ALIGN_DIGITS) {
10703 enum rounding safeR = decContextGetRounding(&set);
10704 int safe = set.digits;
10705 decNumber tmp;
10706
10707
10708 decContextSetRounding(&set, DEC_ROUND_DOWN);
10709 set.digits = span - FIXED_ALIGN_DIGITS;
10710 decNumberPlus(&tmp, op3, &set);
10711 set.digits = safe;
10712
10713 decNumberSubtract(op3, op3, &tmp, &set);
10714
10715
10716
10717 decContextSetRounding(&set, safeR);
10718 }
10719 }
10720
10721
10722 bool Ovr = false, EOvr = false, Trunc = false;
10723
10724 uint8_t out [256];
10725 char *res = formatDecimal(out, &set, op3, n2, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
10726 if (fltAlignTrunc)
10727 Trunc = true;
10728
10729 Ovr |= iOvr;
10730
10731 if (decNumberIsZero(op3))
10732 op3->exponent = 127;
10733
10734
10735
10736
10737
10738
10739 int pos = (int) dstCN;
10740
10741
10742 switch(e->S2)
10743 {
10744 case CSFL:
10745 case CSLS:
10746 switch(dstTN)
10747 {
10748 case CTN4:
10749 if (e->P)
10750
10751
10752 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10753 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
10754 else
10755 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10756 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
10757 break;
10758 case CTN9:
10759 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10760 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
10761 break;
10762 }
10763 break;
10764
10765 case CSTS:
10766 case CSNS:
10767 break;
10768 }
10769
10770
10771 for(int j = 0 ; j < n2 ; j++)
10772 switch(dstTN)
10773 {
10774 case CTN4:
10775 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[j] - '0'));
10776 break;
10777 case CTN9:
10778 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[j]);
10779 break;
10780 }
10781
10782
10783 switch(e->S2)
10784 {
10785 case CSTS:
10786 switch(dstTN)
10787 {
10788 case CTN4:
10789 if (e->P)
10790
10791
10792 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10793 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
10794 else
10795 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10796 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
10797 break;
10798 case CTN9:
10799 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
10800 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
10801 break;
10802 }
10803 break;
10804
10805 case CSFL:
10806
10807 switch(dstTN)
10808 {
10809 case CTN4:
10810 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
10811 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
10812 break;
10813 case CTN9:
10814 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
10815 break;
10816 }
10817 break;
10818
10819 case CSLS:
10820 case CSNS:
10821 break;
10822 }
10823
10824
10825 if (e->S2 == CSFL)
10826 {
10827 if (op3->exponent > 127)
10828 {
10829 SET_I_EOFL;
10830 EOvr = true;
10831 }
10832 if (op3->exponent < -128)
10833 {
10834 SET_I_EUFL;
10835 EOvr = true;
10836 }
10837 }
10838
10839 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
10840 SC_I_ZERO (decNumberIsZero(op3));
10841
10842 SC_I_TRUNC (Trunc);
10843
10844 cleanupOperandDescriptor (cpup, 1);
10845 cleanupOperandDescriptor (cpup, 2);
10846 cleanupOperandDescriptor (cpup, 3);
10847
10848 if (TST_I_TRUNC && T && tstOVFfault (cpup))
10849 doFault(FAULT_OFL, fst_zero, "ad2d truncation(overflow) fault");
10850 if (EOvr && tstOVFfault (cpup))
10851 doFault(FAULT_OFL, fst_zero, "ad2d over/underflow fault");
10852 if (Ovr)
10853 {
10854 SET_I_OFLOW;
10855 if (tstOVFfault (cpup))
10856 doFault(FAULT_OFL, fst_zero, "ad2d overflow fault");
10857 }
10858 }
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905 void ad3d (cpu_state_t * cpup)
10906 {
10907 EISstruct * e = & cpu.currentEISinstruction;
10908
10909 fault_ipr_subtype_ mod_fault = 0;
10910
10911 #if !defined(EIS_SETUP)
10912 setupOperandDescriptor(cpup, 1, &mod_fault);
10913 setupOperandDescriptor(cpup, 2, &mod_fault);
10914 setupOperandDescriptor(cpup, 3, &mod_fault);
10915 #endif
10916
10917 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
10918 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
10919 parseNumericOperandDescriptor(cpup, 3, &mod_fault);
10920
10921 L68_ (
10922
10923 if (mod_fault)
10924 {
10925 doFault (FAULT_IPR,
10926 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10927 "Illegal modifier");
10928 }
10929 )
10930
10931
10932 if (IWB_IRODD & 0200000000000)
10933 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "ad3d(): 1 MBZ");
10934
10935 DPS8M_ (
10936
10937 if (mod_fault)
10938 {
10939 doFault (FAULT_IPR,
10940 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
10941 "Illegal modifier");
10942 }
10943 )
10944
10945
10946 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
10947 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
10948 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
10949
10950 PNL (L68_ (if (R)
10951 DU_CYCLE_FRND;))
10952
10953 uint srcTN = e->TN1;
10954
10955 uint dstTN = e->TN3;
10956 uint dstCN = e->CN3;
10957
10958 int n1 = 0, n2 = 0, n3 = 0, sc1 = 0, sc2 = 0;
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970 switch(e->S1)
10971 {
10972 case CSFL:
10973 n1 = (int) e->N1 - 1;
10974 if (srcTN == CTN4)
10975 n1 -= 2;
10976 else
10977 n1 -= 1;
10978 sc1 = 0;
10979 break;
10980
10981 case CSLS:
10982 case CSTS:
10983 n1 = (int) e->N1 - 1;
10984 sc1 = -e->SF1;
10985 break;
10986
10987 case CSNS:
10988 n1 = (int) e->N1;
10989 sc1 = -e->SF1;
10990 break;
10991 }
10992
10993 if (n1 < 1)
10994 doFault (FAULT_IPR, fst_ill_proc, "ad3d adjusted n1<1");
10995
10996 switch(e->S2)
10997 {
10998 case CSFL:
10999 n2 = (int) e->N2 - 1;
11000 if (e->TN2 == CTN4)
11001 n2 -= 2;
11002 else
11003 n2 -= 1;
11004 sc2 = 0;
11005 break;
11006
11007 case CSLS:
11008 case CSTS:
11009 n2 = (int) e->N2 - 1;
11010 sc2 = -e->SF2;
11011 break;
11012
11013 case CSNS:
11014 n2 = (int) e->N2;
11015 sc2 = -e->SF2;
11016 break;
11017 }
11018
11019 if (n2 < 1)
11020 doFault (FAULT_IPR, fst_ill_proc, "ad3d adjusted n2<1");
11021
11022 switch(e->S3)
11023 {
11024 case CSFL:
11025 n3 = (int) e->N3 - 1;
11026 if (dstTN == CTN4)
11027 n3 -= 2;
11028 else
11029 n3 -= 1;
11030 break;
11031
11032 case CSLS:
11033 case CSTS:
11034 n3 = (int) e->N3 - 1;
11035 break;
11036
11037 case CSNS:
11038 n3 = (int) e->N3;
11039 break;
11040 }
11041
11042 if (n3 < 1)
11043 doFault (FAULT_IPR, fst_ill_proc, "ad3d adjusted n3<1");
11044
11045 decContext set;
11046
11047 decContextDefaultDPS8(&set);
11048 set.traps=0;
11049
11050 decNumber _1, _2, _3;
11051
11052 EISloadInputBufferNumeric (cpup, 1);
11053
11054 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
11055 if (e->sign == -1)
11056 op1->bits |= DECNEG;
11057 if (e->S1 == CSFL)
11058 op1->exponent = e->exponent;
11059
11060 EISloadInputBufferNumeric (cpup, 2);
11061
11062 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
11063 if (e->sign == -1)
11064 op2->bits |= DECNEG;
11065 if (e->S2 == CSFL)
11066 op2->exponent = e->exponent;
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077 decNumber *op3;
11078 bool winLost = false;
11079 bool fltAlignTrunc = false;
11080 if (e->S3 != CSFL)
11081 {
11082 enum rounding safeR = decContextGetRounding(&set);
11083 int safe = set.digits;
11084 set.digits = DECNUMDIGITS;
11085 decContextSetRounding(&set, DEC_ROUND_DOWN);
11086 winLost = eisWindowOperands (op1, op2);
11087 op3 = decNumberAdd(&_3, op1, op2, &set);
11088 set.digits = safe;
11089 decContextSetRounding(&set, safeR);
11090 }
11091 else
11092 {
11093 fltAlignTrunc = eisFloatAlignTrunc (op1, op2);
11094 eisFloatWindowOperands (op1, op2);
11095 op3 = decNumberAdd(&_3, op1, op2, &set);
11096 }
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109 bool iOvr = winLost;
11110 if (op3->digits > 63 && e->S3 == CSFL) {
11111
11112
11113
11114
11115
11116 enum rounding safeR = decContextGetRounding(&set);
11117 int safe = set.digits;
11118 decContextSetRounding(&set, DEC_ROUND_DOWN);
11119 set.digits = 63;
11120 decNumberPlus(op3, op3, &set);
11121 set.digits = safe;
11122 decContextSetRounding(&set, safeR);
11123 } else if (op3->digits > FIXED_OVERFLOW_DIGITS) {
11124 uint8_t pr[256];
11125
11126
11127 int sf = e->S3==CSFL?op3->exponent:e->SF3;
11128
11129 int ctz = 0;
11130 if (sf>0) {
11131 decNumberGetBCD(op3,pr);
11132 for (int i=op3->digits-1;i>=0 && pr[i]==0;i--)
11133 ctz ++;
11134 }
11135
11136 int span = op3->digits - min(max(sf,0),ctz);
11137 if (span > FIXED_OVERFLOW_DIGITS)
11138 iOvr = 1;
11139 if (span > FIXED_ALIGN_DIGITS) {
11140 enum rounding safeR = decContextGetRounding(&set);
11141 int safe = set.digits;
11142 decNumber tmp;
11143
11144
11145 decContextSetRounding(&set, DEC_ROUND_DOWN);
11146 set.digits = span - FIXED_ALIGN_DIGITS;
11147 decNumberPlus(&tmp, op3, &set);
11148 set.digits = safe;
11149
11150 decNumberSubtract(op3, op3, &tmp, &set);
11151
11152
11153
11154 decContextSetRounding(&set, safeR);
11155 }
11156 }
11157
11158
11159 bool Ovr = false, EOvr = false, Trunc = false;
11160
11161 uint8_t out [256];
11162 char *res = formatDecimal(out, &set, op3, n3, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
11163 if (fltAlignTrunc)
11164 Trunc = true;
11165
11166 Ovr |= iOvr;
11167
11168 if (decNumberIsZero(op3))
11169 op3->exponent = 127;
11170
11171
11172
11173
11174
11175
11176 int pos = (int) dstCN;
11177
11178
11179 switch(e->S3)
11180 {
11181 case CSFL:
11182 case CSLS:
11183 switch(dstTN)
11184 {
11185 case CTN4:
11186 if (e->P)
11187
11188
11189 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11190 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11191 else
11192 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11193 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11194 break;
11195 case CTN9:
11196 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11197 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11198 break;
11199 }
11200 break;
11201
11202 case CSTS:
11203 case CSNS:
11204 break;
11205 }
11206
11207
11208 for(int i = 0 ; i < n3 ; i++)
11209 switch(dstTN)
11210 {
11211 case CTN4:
11212 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
11213 break;
11214 case CTN9:
11215 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
11216 break;
11217 }
11218
11219
11220 switch(e->S3)
11221 {
11222 case CSTS:
11223 switch(dstTN)
11224 {
11225 case CTN4:
11226 if (e->P)
11227
11228
11229 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11230 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11231 else
11232 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11233 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11234 break;
11235 case CTN9:
11236 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11237 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11238 break;
11239 }
11240 break;
11241
11242 case CSFL:
11243
11244 switch(dstTN)
11245 {
11246 case CTN4:
11247 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
11248 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
11249
11250 break;
11251 case CTN9:
11252 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
11253 break;
11254 }
11255 break;
11256
11257 case CSLS:
11258 case CSNS:
11259 break;
11260 }
11261
11262
11263 if (e->S3 == CSFL)
11264 {
11265 if (op3->exponent > 127)
11266 {
11267 SET_I_EOFL;
11268 EOvr = true;
11269 }
11270 if (op3->exponent < -128)
11271 {
11272 SET_I_EUFL;
11273 EOvr = true;
11274 }
11275 }
11276
11277 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
11278 SC_I_ZERO (decNumberIsZero(op3));
11279
11280 SC_I_TRUNC (Trunc);
11281
11282 cleanupOperandDescriptor (cpup, 1);
11283 cleanupOperandDescriptor (cpup, 2);
11284 cleanupOperandDescriptor (cpup, 3);
11285
11286 if (TST_I_TRUNC && T && tstOVFfault (cpup))
11287 doFault(FAULT_OFL, fst_zero, "ad3d truncation(overflow) fault");
11288 if (EOvr && tstOVFfault (cpup))
11289 doFault(FAULT_OFL, fst_zero, "ad3d over/underflow fault");
11290 if (Ovr)
11291 {
11292 SET_I_OFLOW;
11293 if (tstOVFfault (cpup))
11294 doFault(FAULT_OFL, fst_zero, "ad3d overflow fault");
11295 }
11296 }
11297
11298
11299
11300
11301
11302 void sb2d (cpu_state_t * cpup)
11303 {
11304 EISstruct * e = & cpu.currentEISinstruction;
11305
11306 fault_ipr_subtype_ mod_fault = 0;
11307
11308 #if !defined(EIS_SETUP)
11309 setupOperandDescriptor(cpup, 1, &mod_fault);
11310 setupOperandDescriptor(cpup, 2, &mod_fault);
11311 setupOperandDescriptorCache(cpup,3);
11312 #endif
11313
11314 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
11315 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
11316
11317 L68_ (
11318
11319 if (mod_fault)
11320 {
11321 doFault (FAULT_IPR,
11322 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
11323 "Illegal modifier");
11324 }
11325 )
11326
11327
11328 if (IWB_IRODD & 0377000000000)
11329 {
11330
11331 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "sb2d 0-8 MBZ");
11332 }
11333
11334 DPS8M_ (
11335
11336 if (mod_fault)
11337 {
11338 doFault (FAULT_IPR,
11339 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
11340 "Illegal modifier");
11341 }
11342 )
11343
11344 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
11345 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
11346 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
11347
11348 PNL (L68_ (if (R)
11349 DU_CYCLE_FRND;))
11350
11351 uint srcTN = e->TN1;
11352
11353 uint dstTN = e->TN2;
11354 uint dstCN = e->CN2;
11355
11356 e->ADDR3 = e->ADDR2;
11357
11358 int n1 = 0, n2 = 0, sc1 = 0, sc2 = 0;
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370 switch(e->S1)
11371 {
11372 case CSFL:
11373 n1 = (int) e->N1 - 1;
11374 if (srcTN == CTN4)
11375 n1 -= 2;
11376 else
11377 n1 -= 1;
11378 sc1 = 0;
11379 break;
11380
11381 case CSLS:
11382 case CSTS:
11383 n1 = (int) e->N1 - 1;
11384 sc1 = -e->SF1;
11385 break;
11386
11387 case CSNS:
11388 n1 = (int) e->N1;
11389 sc1 = -e->SF1;
11390 break;
11391 }
11392
11393 if (n1 < 1)
11394 doFault (FAULT_IPR, fst_ill_proc, "sb2d adjusted n1<1");
11395
11396 switch(e->S2)
11397 {
11398 case CSFL:
11399 n2 = (int) e->N2 - 1;
11400 if (e->TN2 == CTN4)
11401 n2 -= 2;
11402 else
11403 n2 -= 1;
11404 sc2 = 0;
11405 break;
11406
11407 case CSLS:
11408 case CSTS:
11409 n2 = (int) e->N2 - 1;
11410 sc2 = -e->SF2;
11411 break;
11412
11413 case CSNS:
11414 n2 = (int) e->N2;
11415 sc2 = -e->SF2;
11416 break;
11417 }
11418
11419 if (n2 < 1)
11420 doFault (FAULT_IPR, fst_ill_proc, "sb2d adjusted n2<1");
11421
11422 decContext set;
11423
11424 decContextDefaultDPS8(&set);
11425 set.traps=0;
11426
11427 decNumber _1, _2, _3;
11428
11429 EISloadInputBufferNumeric (cpup, 1);
11430
11431 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
11432 if (e->sign == -1)
11433 op1->bits |= DECNEG;
11434 if (e->S1 == CSFL)
11435 op1->exponent = e->exponent;
11436
11437 EISloadInputBufferNumeric (cpup, 2);
11438
11439 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
11440 if (e->sign == -1)
11441 op2->bits |= DECNEG;
11442 if (e->S2 == CSFL)
11443 op2->exponent = e->exponent;
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454 decNumber *op3;
11455 bool winLost = false;
11456 bool fltAlignTrunc = false;
11457 if (e->S2 != CSFL)
11458 {
11459 enum rounding safeR = decContextGetRounding(&set);
11460 int safe = set.digits;
11461 set.digits = DECNUMDIGITS;
11462 decContextSetRounding(&set, DEC_ROUND_DOWN);
11463 winLost = eisWindowOperands (op1, op2);
11464 op3 = decNumberSubtract(&_3, op2, op1, &set);
11465 set.digits = safe;
11466 decContextSetRounding(&set, safeR);
11467 }
11468 else
11469 {
11470 fltAlignTrunc = eisFloatAlignTrunc (op1, op2);
11471 eisFloatWindowOperands (op1, op2);
11472 op3 = decNumberSubtract(&_3, op2, op1, &set);
11473 }
11474
11475
11476 bool iOvr = winLost;
11477 if (op3->digits > 63 && e->S2 == CSFL) {
11478
11479
11480
11481
11482
11483 enum rounding safeR = decContextGetRounding(&set);
11484 int safe = set.digits;
11485 decContextSetRounding(&set, DEC_ROUND_DOWN);
11486 set.digits = 63;
11487 decNumberPlus(op3, op3, &set);
11488 set.digits = safe;
11489 decContextSetRounding(&set, safeR);
11490 } else if (op3->digits > FIXED_OVERFLOW_DIGITS) {
11491 uint8_t pr[256];
11492
11493
11494 int sf = e->S2==CSFL?op3->exponent:e->SF2;
11495
11496 int ctz = 0;
11497 if (sf>0) {
11498 decNumberGetBCD(op3,pr);
11499 for (int i=op3->digits-1;i>=0 && pr[i]==0;i--)
11500 ctz ++;
11501 }
11502
11503 int span = op3->digits - min(max(sf,0),ctz);
11504 if (span > FIXED_OVERFLOW_DIGITS)
11505 iOvr = 1;
11506 if (span > FIXED_ALIGN_DIGITS) {
11507 enum rounding safeR = decContextGetRounding(&set);
11508 int safe = set.digits;
11509 decNumber tmp;
11510
11511
11512 decContextSetRounding(&set, DEC_ROUND_DOWN);
11513 set.digits = span - FIXED_ALIGN_DIGITS;
11514 decNumberPlus(&tmp, op3, &set);
11515 set.digits = safe;
11516
11517 decNumberSubtract(op3, op3, &tmp, &set);
11518
11519
11520
11521 decContextSetRounding(&set, safeR);
11522 }
11523 }
11524
11525
11526 bool Ovr = false, EOvr = false, Trunc = false;
11527
11528 uint8_t out [256];
11529 char *res = formatDecimal(out, &set, op3, n2, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
11530 if (fltAlignTrunc)
11531 Trunc = true;
11532
11533 Ovr |= iOvr;
11534
11535 if (decNumberIsZero(op3))
11536 op3->exponent = 127;
11537
11538
11539
11540
11541
11542
11543 int pos = (int) dstCN;
11544
11545
11546 switch(e->S2)
11547 {
11548 case CSFL:
11549 case CSLS:
11550 switch(dstTN)
11551 {
11552 case CTN4:
11553 if (e->P)
11554
11555
11556 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11557 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11558 else
11559 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11560 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11561 break;
11562 case CTN9:
11563 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11564 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11565 break;
11566 }
11567 break;
11568
11569 case CSTS:
11570 case CSNS:
11571 break;
11572 }
11573
11574
11575 for(int i = 0 ; i < n2 ; i++)
11576 switch(dstTN)
11577 {
11578 case CTN4:
11579 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
11580 break;
11581 case CTN9:
11582 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
11583 break;
11584 }
11585
11586
11587 switch(e->S2)
11588 {
11589 case CSTS:
11590 switch(dstTN)
11591 {
11592 case CTN4:
11593 if (e->P)
11594
11595
11596 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11597 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11598 else
11599 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11600 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11601 break;
11602 case CTN9:
11603 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11604 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11605 break;
11606 }
11607 break;
11608
11609 case CSFL:
11610
11611 switch(dstTN)
11612 {
11613 case CTN4:
11614 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
11615 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
11616
11617 break;
11618 case CTN9:
11619 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
11620 break;
11621 }
11622 break;
11623
11624 case CSLS:
11625 case CSNS:
11626 break;
11627 }
11628
11629
11630 if (e->S2 == CSFL)
11631 {
11632 if (op3->exponent > 127)
11633 {
11634 SET_I_EOFL;
11635 EOvr = true;
11636 }
11637 if (op3->exponent < -128)
11638 {
11639 SET_I_EUFL;
11640 EOvr = true;
11641 }
11642 }
11643
11644 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
11645 SC_I_ZERO (decNumberIsZero(op3));
11646
11647 SC_I_TRUNC (Trunc);
11648
11649 cleanupOperandDescriptor (cpup, 1);
11650 cleanupOperandDescriptor (cpup, 2);
11651 cleanupOperandDescriptor (cpup, 3);
11652
11653 if (TST_I_TRUNC && T && tstOVFfault (cpup))
11654 doFault(FAULT_OFL, fst_zero, "sb2d truncation(overflow) fault");
11655 if (EOvr && tstOVFfault (cpup))
11656 doFault(FAULT_OFL, fst_zero, "sb2d over/underflow fault");
11657 if (Ovr)
11658 {
11659 SET_I_OFLOW;
11660 if (tstOVFfault (cpup))
11661 doFault(FAULT_OFL, fst_zero, "sb2d overflow fault");
11662 }
11663 }
11664
11665
11666
11667
11668
11669 void sb3d (cpu_state_t * cpup)
11670 {
11671 EISstruct * e = & cpu.currentEISinstruction;
11672
11673 fault_ipr_subtype_ mod_fault = 0;
11674
11675 #if !defined(EIS_SETUP)
11676 setupOperandDescriptor(cpup, 1, &mod_fault);
11677 setupOperandDescriptor(cpup, 2, &mod_fault);
11678 setupOperandDescriptor(cpup, 3, &mod_fault);
11679 #endif
11680
11681 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
11682 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
11683 parseNumericOperandDescriptor(cpup, 3, &mod_fault);
11684
11685 L68_ (
11686
11687 if (mod_fault)
11688 {
11689 doFault (FAULT_IPR,
11690 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
11691 "Illegal modifier");
11692 }
11693 )
11694
11695
11696 if (IWB_IRODD & 0200000000000)
11697 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "sb3d(): 1 MBZ");
11698
11699 DPS8M_ (
11700
11701 if (mod_fault)
11702 {
11703 doFault (FAULT_IPR,
11704 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
11705 "Illegal modifier");
11706 }
11707 )
11708
11709 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
11710 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
11711 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
11712
11713 PNL (L68_ (if (R)
11714 DU_CYCLE_FRND;))
11715
11716 uint srcTN = e->TN1;
11717
11718 uint dstTN = e->TN3;
11719 uint dstCN = e->CN3;
11720
11721 int n1 = 0, n2 = 0, n3 = 0, sc1 = 0, sc2 = 0;
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733 switch(e->S1)
11734 {
11735 case CSFL:
11736 n1 = (int) e->N1 - 1;
11737 if (srcTN == CTN4)
11738 n1 -= 2;
11739 else
11740 n1 -= 1;
11741 sc1 = 0;
11742 break;
11743
11744 case CSLS:
11745 case CSTS:
11746 n1 = (int) e->N1 - 1;
11747 sc1 = -e->SF1;
11748 break;
11749
11750 case CSNS:
11751 n1 = (int) e->N1;
11752 sc1 = -e->SF1;
11753 break;
11754 }
11755
11756 if (n1 < 1)
11757 doFault (FAULT_IPR, fst_ill_proc, "sb3d adjusted n1<1");
11758
11759 switch(e->S2)
11760 {
11761 case CSFL:
11762 n2 = (int) e->N2 - 1;
11763 if (e->TN2 == CTN4)
11764 n2 -= 2;
11765 else
11766 n2 -= 1;
11767 sc2 = 0;
11768 break;
11769
11770 case CSLS:
11771 case CSTS:
11772 n2 = (int) e->N2 - 1;
11773 sc2 = -e->SF2;
11774 break;
11775
11776 case CSNS:
11777 n2 = (int) e->N2;
11778 sc2 = -e->SF2;
11779 break;
11780 }
11781
11782 if (n2 < 1)
11783 doFault (FAULT_IPR, fst_ill_proc, "sb3d adjusted n2<1");
11784
11785 switch(e->S3)
11786 {
11787 case CSFL:
11788 n3 = (int) e->N3 - 1;
11789 if (dstTN == CTN4)
11790 n3 -= 2;
11791 else
11792 n3 -= 1;
11793 break;
11794
11795 case CSLS:
11796 case CSTS:
11797 n3 = (int) e->N3 - 1;
11798 break;
11799
11800 case CSNS:
11801 n3 = (int) e->N3;
11802 break;
11803 }
11804
11805 if (n3 < 1)
11806 doFault (FAULT_IPR, fst_ill_proc, "sb3d adjusted n3<1");
11807
11808 decContext set;
11809
11810 decContextDefaultDPS8(&set);
11811
11812 set.traps=0;
11813
11814 decNumber _1, _2, _3;
11815
11816 EISloadInputBufferNumeric (cpup, 1);
11817
11818 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
11819 if (e->sign == -1)
11820 op1->bits |= DECNEG;
11821 if (e->S1 == CSFL)
11822 op1->exponent = e->exponent;
11823
11824 EISloadInputBufferNumeric (cpup, 2);
11825
11826 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
11827 if (e->sign == -1)
11828 op2->bits |= DECNEG;
11829 if (e->S2 == CSFL)
11830 op2->exponent = e->exponent;
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841 decNumber *op3;
11842 bool winLost = false;
11843 bool fltAlignTrunc = false;
11844 if (e->S3 != CSFL)
11845 {
11846 enum rounding safeR = decContextGetRounding(&set);
11847 int safe = set.digits;
11848 set.digits = DECNUMDIGITS;
11849 decContextSetRounding(&set, DEC_ROUND_DOWN);
11850 winLost = eisWindowOperands (op1, op2);
11851 op3 = decNumberSubtract(&_3, op2, op1, &set);
11852 set.digits = safe;
11853 decContextSetRounding(&set, safeR);
11854 }
11855 else
11856 {
11857 fltAlignTrunc = eisFloatAlignTrunc (op1, op2);
11858 eisFloatWindowOperands (op1, op2);
11859 op3 = decNumberSubtract(&_3, op2, op1, &set);
11860 }
11861
11862
11863 bool iOvr = winLost;
11864 if (op3->digits > 63 && e->S3 == CSFL) {
11865
11866
11867
11868
11869
11870 enum rounding safeR = decContextGetRounding(&set);
11871 int safe = set.digits;
11872 decContextSetRounding(&set, DEC_ROUND_DOWN);
11873 set.digits = 63;
11874 decNumberPlus(op3, op3, &set);
11875 set.digits = safe;
11876 decContextSetRounding(&set, safeR);
11877 } else if (op3->digits > FIXED_OVERFLOW_DIGITS) {
11878 uint8_t pr[256];
11879
11880
11881 int sf = e->S3==CSFL?op3->exponent:e->SF3;
11882
11883 int ctz = 0;
11884 if (sf>0) {
11885 decNumberGetBCD(op3,pr);
11886 for (int i=op3->digits-1;i>=0 && pr[i]==0;i--)
11887 ctz ++;
11888 }
11889
11890 int span = op3->digits - min(max(sf,0),ctz);
11891 if (span > FIXED_OVERFLOW_DIGITS)
11892 iOvr = 1;
11893 if (span > FIXED_ALIGN_DIGITS) {
11894 enum rounding safeR = decContextGetRounding(&set);
11895 int safe = set.digits;
11896 decNumber tmp;
11897
11898
11899 decContextSetRounding(&set, DEC_ROUND_DOWN);
11900 set.digits = span - FIXED_ALIGN_DIGITS;
11901 decNumberPlus(&tmp, op3, &set);
11902 set.digits = safe;
11903
11904 decNumberSubtract(op3, op3, &tmp, &set);
11905
11906
11907
11908 decContextSetRounding(&set, safeR);
11909 }
11910 }
11911
11912
11913 bool Ovr = false, EOvr = false, Trunc = false;
11914
11915 uint8_t out [256];
11916 char *res = formatDecimal(out, &set, op3, n3, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
11917 if (fltAlignTrunc)
11918 Trunc = true;
11919
11920 Ovr |= iOvr;
11921
11922 if (decNumberIsZero(op3))
11923 op3->exponent = 127;
11924
11925
11926
11927
11928 int pos = (int) dstCN;
11929
11930
11931 switch(e->S3)
11932 {
11933 case CSFL:
11934 case CSLS:
11935 switch(dstTN)
11936 {
11937 case CTN4:
11938 if (e->P)
11939
11940
11941 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11942 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11943 else
11944 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11945 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11946 break;
11947 case CTN9:
11948 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11949 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11950 break;
11951 }
11952 break;
11953
11954 case CSTS:
11955 case CSNS:
11956 break;
11957 }
11958
11959
11960 for(int i = 0 ; i < n3 ; i++)
11961 switch(dstTN)
11962 {
11963 case CTN4:
11964 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
11965 break;
11966 case CTN9:
11967 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
11968 break;
11969 }
11970
11971
11972 switch(e->S3)
11973 {
11974 case CSTS:
11975 switch(dstTN)
11976 {
11977 case CTN4:
11978 if (e->P)
11979
11980
11981 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11982 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
11983 else
11984 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11985 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
11986 break;
11987 case CTN9:
11988 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
11989 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
11990 break;
11991 }
11992 break;
11993
11994 case CSFL:
11995
11996 switch(dstTN)
11997 {
11998 case CTN4:
11999 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
12000 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
12001
12002 break;
12003 case CTN9:
12004 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
12005 break;
12006 }
12007 break;
12008
12009 case CSLS:
12010 case CSNS:
12011 break;
12012 }
12013
12014
12015 if (e->S3 == CSFL)
12016 {
12017 if (op3->exponent > 127)
12018 {
12019 SET_I_EOFL;
12020 EOvr = true;
12021 }
12022 if (op3->exponent < -128)
12023 {
12024 SET_I_EUFL;
12025 EOvr = true;
12026 }
12027 }
12028
12029 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
12030 SC_I_ZERO (decNumberIsZero(op3));
12031
12032 SC_I_TRUNC (Trunc);
12033
12034 cleanupOperandDescriptor (cpup, 1);
12035 cleanupOperandDescriptor (cpup, 2);
12036 cleanupOperandDescriptor (cpup, 3);
12037
12038 if (TST_I_TRUNC && T && tstOVFfault (cpup))
12039 doFault(FAULT_OFL, fst_zero, "sb3d truncation(overflow) fault");
12040 if (EOvr && tstOVFfault (cpup))
12041 doFault(FAULT_OFL, fst_zero, "sb3d over/underflow fault");
12042 if (Ovr)
12043 {
12044 SET_I_OFLOW;
12045 if (tstOVFfault (cpup))
12046 doFault(FAULT_OFL, fst_zero, "sb3d overflow fault");
12047 }
12048 }
12049
12050
12051
12052
12053
12054 void mp2d (cpu_state_t * cpup)
12055 {
12056 EISstruct * e = & cpu.currentEISinstruction;
12057
12058 fault_ipr_subtype_ mod_fault = 0;
12059
12060 #if !defined(EIS_SETUP)
12061 setupOperandDescriptor(cpup, 1, &mod_fault);
12062 setupOperandDescriptor(cpup, 2, &mod_fault);
12063 setupOperandDescriptorCache(cpup,3);
12064 #endif
12065
12066 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
12067 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
12068
12069 L68_ (
12070
12071 if (mod_fault)
12072 {
12073 doFault (FAULT_IPR,
12074 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
12075 "Illegal modifier");
12076 }
12077 )
12078
12079
12080 if (IWB_IRODD & 0377000000000)
12081 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mp2d 1-8 MBZ");
12082
12083 DPS8M_ (
12084
12085 if (mod_fault)
12086 {
12087 doFault (FAULT_IPR,
12088 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
12089 "Illegal modifier");
12090 }
12091 )
12092
12093 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
12094 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
12095 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
12096
12097 PNL (L68_ (if (R)
12098 DU_CYCLE_FRND;))
12099
12100 uint srcTN = e->TN1;
12101
12102 uint dstTN = e->TN2;
12103 uint dstCN = e->CN2;
12104
12105 e->ADDR3 = e->ADDR2;
12106
12107 int n1 = 0, n2 = 0, sc1 = 0, sc2 = 0;
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119 switch(e->S1)
12120 {
12121 case CSFL:
12122 n1 = (int) e->N1 - 1;
12123 if (srcTN == CTN4)
12124 n1 -= 2;
12125 else
12126 n1 -= 1;
12127 sc1 = 0;
12128 break;
12129
12130 case CSLS:
12131 case CSTS:
12132 n1 = (int) e->N1 - 1;
12133 sc1 = -e->SF1;
12134 break;
12135
12136 case CSNS:
12137 n1 = (int) e->N1;
12138 sc1 = -e->SF1;
12139 break;
12140 }
12141
12142 if (n1 < 1)
12143 doFault (FAULT_IPR, fst_ill_proc, "mp2d adjusted n1<1");
12144
12145 switch(e->S2)
12146 {
12147 case CSFL:
12148 n2 = (int) e->N2 - 1;
12149 if (e->TN2 == CTN4)
12150 n2 -= 2;
12151 else
12152 n2 -= 1;
12153 sc2 = 0;
12154 break;
12155
12156 case CSLS:
12157 case CSTS:
12158 n2 = (int) e->N2 - 1;
12159 sc2 = -e->SF2;
12160 break;
12161
12162 case CSNS:
12163 n2 = (int) e->N2;
12164 sc2 = -e->SF2;
12165 break;
12166 }
12167
12168 if (n2 < 1)
12169 doFault (FAULT_IPR, fst_ill_proc, "mp2d adjusted n2<1");
12170
12171 decContext set;
12172 decContextDefaultDPS8Mul(&set);
12173
12174 set.traps=0;
12175
12176 decNumber _1, _2, _3;
12177
12178 EISloadInputBufferNumeric (cpup, 1);
12179
12180 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
12181 if (e->sign == -1)
12182 op1->bits |= DECNEG;
12183 if (e->S1 == CSFL)
12184 op1->exponent = e->exponent;
12185
12186 EISloadInputBufferNumeric (cpup, 2);
12187
12188 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
12189 if (e->sign == -1)
12190 op2->bits |= DECNEG;
12191 if (e->S2 == CSFL)
12192 op2->exponent = e->exponent;
12193
12194 decNumber *op3 = decNumberMultiply(&_3, op1, op2, &set);
12195
12196 bool Ovr = false, EOvr = false, Trunc = false;
12197
12198 uint8_t out [256];
12199 char *res = formatDecimal(out, &set, op3, n2, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
12200
12201 if (decNumberIsZero(op3))
12202 op3->exponent = 127;
12203
12204
12205
12206
12207 int pos = (int) dstCN;
12208
12209
12210 switch(e->S2)
12211 {
12212 case CSFL:
12213 case CSLS:
12214 switch(dstTN)
12215 {
12216 case CTN4:
12217 if (e->P)
12218
12219
12220 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12221 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
12222 else
12223 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12224 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
12225 break;
12226 case CTN9:
12227 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12228 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
12229 break;
12230 }
12231 break;
12232
12233 case CSTS:
12234 case CSNS:
12235 break;
12236 }
12237
12238
12239 for(int i = 0 ; i < n2 ; i++)
12240 switch(dstTN)
12241 {
12242 case CTN4:
12243 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
12244 break;
12245 case CTN9:
12246 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
12247 break;
12248 }
12249
12250
12251 switch(e->S2)
12252 {
12253 case CSTS:
12254 switch(dstTN)
12255 {
12256 case CTN4:
12257 if (e->P)
12258
12259
12260 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12261 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
12262 else
12263 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12264 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
12265 break;
12266 case CTN9:
12267 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12268 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
12269 break;
12270 }
12271 break;
12272
12273 case CSFL:
12274
12275 switch(dstTN)
12276 {
12277 case CTN4:
12278 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
12279 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
12280
12281 break;
12282 case CTN9:
12283 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
12284 break;
12285 }
12286 break;
12287
12288 case CSLS:
12289 case CSNS:
12290 break;
12291 }
12292
12293
12294 if (e->S2 == CSFL)
12295 {
12296 if (op3->exponent > 127)
12297 {
12298 SET_I_EOFL;
12299 EOvr = true;
12300 }
12301 if (op3->exponent < -128)
12302 {
12303 SET_I_EUFL;
12304 EOvr = true;
12305 }
12306 }
12307
12308 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
12309 SC_I_ZERO (decNumberIsZero(op3));
12310
12311 SC_I_TRUNC (!R && Trunc);
12312
12313 cleanupOperandDescriptor (cpup, 1);
12314 cleanupOperandDescriptor (cpup, 2);
12315 cleanupOperandDescriptor (cpup, 3);
12316
12317 if (TST_I_TRUNC && T && tstOVFfault (cpup))
12318 doFault(FAULT_OFL, fst_zero, "mp2d truncation(overflow) fault");
12319 if (EOvr && tstOVFfault (cpup))
12320 doFault(FAULT_OFL, fst_zero, "mp2d over/underflow fault");
12321 if (Ovr)
12322 {
12323 SET_I_OFLOW;
12324 if (tstOVFfault (cpup))
12325 doFault(FAULT_OFL, fst_zero, "mp2d overflow fault");
12326 }
12327 }
12328
12329
12330
12331
12332
12333 void mp3d (cpu_state_t * cpup)
12334 {
12335 EISstruct * e = & cpu.currentEISinstruction;
12336
12337 fault_ipr_subtype_ mod_fault = 0;
12338
12339 #if !defined(EIS_SETUP)
12340 setupOperandDescriptor(cpup, 1, &mod_fault);
12341 setupOperandDescriptor(cpup, 2, &mod_fault);
12342 setupOperandDescriptor(cpup, 3, &mod_fault);
12343 #endif
12344
12345 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
12346 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
12347 parseNumericOperandDescriptor(cpup, 3, &mod_fault);
12348
12349 L68_ (
12350
12351 if (mod_fault)
12352 {
12353 doFault (FAULT_IPR,
12354 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
12355 "Illegal modifier");
12356 }
12357 )
12358
12359
12360 if (IWB_IRODD & 0200000000000)
12361 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "mp3d(): 1 MBZ");
12362
12363 DPS8M_ (
12364
12365 if (mod_fault)
12366 {
12367 doFault (FAULT_IPR,
12368 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
12369 "Illegal modifier");
12370 }
12371 )
12372
12373 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
12374 bool T = getbits36_1 (cpu.cu.IWB, 9) != 0;
12375 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
12376
12377 PNL (L68_ (if (R)
12378 DU_CYCLE_FRND;))
12379
12380 uint srcTN = e->TN1;
12381
12382 uint dstTN = e->TN3;
12383 uint dstCN = e->CN3;
12384
12385 int n1 = 0, n2 = 0, n3 = 0, sc1 = 0, sc2 = 0;
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397 switch(e->S1)
12398 {
12399 case CSFL:
12400 n1 = (int) e->N1 - 1;
12401 if (srcTN == CTN4)
12402 n1 -= 2;
12403 else
12404 n1 -= 1;
12405 sc1 = 0;
12406 break;
12407
12408 case CSLS:
12409 case CSTS:
12410 n1 = (int) e->N1 - 1;
12411 sc1 = -e->SF1;
12412 break;
12413
12414 case CSNS:
12415 n1 = (int) e->N1;
12416 sc1 = -e->SF1;
12417 break;
12418 }
12419
12420 if (n1 < 1)
12421 doFault (FAULT_IPR, fst_ill_proc, "mp3d adjusted n1<1");
12422
12423 switch(e->S2)
12424 {
12425 case CSFL:
12426 n2 = (int) e->N2 - 1;
12427 if (e->TN2 == CTN4)
12428 n2 -= 2;
12429 else
12430 n2 -= 1;
12431 sc2 = 0;
12432 break;
12433
12434 case CSLS:
12435 case CSTS:
12436 n2 = (int) e->N2 - 1;
12437 sc2 = -e->SF2;
12438 break;
12439
12440 case CSNS:
12441 n2 = (int) e->N2;
12442 sc2 = -e->SF2;
12443 break;
12444 }
12445
12446 if (n2 < 1)
12447 doFault (FAULT_IPR, fst_ill_proc, "mp3d adjusted n2<1");
12448
12449 switch(e->S3)
12450 {
12451 case CSFL:
12452 n3 = (int) e->N3 - 1;
12453 if (dstTN == CTN4)
12454 n3 -= 2;
12455 else
12456 n3 -= 1;
12457 break;
12458
12459 case CSLS:
12460 case CSTS:
12461 n3 = (int) e->N3 - 1;
12462 break;
12463
12464 case CSNS:
12465 n3 = (int) e->N3;
12466 break;
12467 }
12468
12469 if (n3 < 1)
12470 doFault (FAULT_IPR, fst_ill_proc, "mp3d adjusted n3<1");
12471
12472 decContext set;
12473
12474 decContextDefaultDPS8Mul(&set);
12475
12476 set.traps=0;
12477
12478 decNumber _1, _2, _3;
12479
12480 EISloadInputBufferNumeric (cpup, 1);
12481
12482 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
12483 if (e->sign == -1)
12484 op1->bits |= DECNEG;
12485 if (e->S1 == CSFL)
12486 op1->exponent = e->exponent;
12487
12488 EISloadInputBufferNumeric (cpup, 2);
12489
12490 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
12491 if (e->sign == -1)
12492 op2->bits |= DECNEG;
12493 if (e->S2 == CSFL)
12494 op2->exponent = e->exponent;
12495
12496 decNumber *op3 = decNumberMultiply(&_3, op1, op2, &set);
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509 bool Ovr = false, EOvr = false, Trunc = false;
12510
12511 uint8_t out [256];
12512 char *res = formatDecimal(out, &set, op3, n3, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
12513
12514 if (decNumberIsZero(op3))
12515 op3->exponent = 127;
12516
12517
12518
12519
12520 int pos = (int) dstCN;
12521
12522
12523 switch(e->S3)
12524 {
12525 case CSFL:
12526 case CSLS:
12527 switch(dstTN)
12528 {
12529 case CTN4:
12530 if (e->P)
12531
12532
12533
12534 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12535 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
12536 else
12537 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12538 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
12539 break;
12540 case CTN9:
12541 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12542 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
12543 break;
12544 }
12545 break;
12546
12547 case CSTS:
12548 case CSNS:
12549 break;
12550 }
12551
12552
12553 for(int i = 0 ; i < n3 ; i++)
12554 switch(dstTN)
12555 {
12556 case CTN4:
12557 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
12558 break;
12559 case CTN9:
12560 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
12561 break;
12562 }
12563
12564
12565 switch(e->S3)
12566 {
12567 case CSTS:
12568 switch(dstTN)
12569 {
12570 case CTN4:
12571 if (e->P)
12572
12573
12574 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12575 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
12576 else
12577 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12578 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
12579 break;
12580 case CTN9:
12581 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
12582 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
12583 break;
12584 }
12585 break;
12586
12587 case CSFL:
12588
12589 switch(dstTN)
12590 {
12591 case CTN4:
12592 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
12593 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
12594 break;
12595 case CTN9:
12596 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
12597 break;
12598 }
12599 break;
12600
12601 case CSLS:
12602 case CSNS:
12603 break;
12604 }
12605
12606
12607 if (e->S3 == CSFL)
12608 {
12609 if (op3->exponent > 127)
12610 {
12611 SET_I_EOFL;
12612 EOvr = true;
12613 }
12614 if (op3->exponent < -128)
12615 {
12616 SET_I_EUFL;
12617 EOvr = true;
12618 }
12619 }
12620
12621 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
12622 SC_I_ZERO (decNumberIsZero(op3));
12623
12624 SC_I_TRUNC (!R && Trunc);
12625
12626 cleanupOperandDescriptor (cpup, 1);
12627 cleanupOperandDescriptor (cpup, 2);
12628 cleanupOperandDescriptor (cpup, 3);
12629
12630 if (TST_I_TRUNC && T && tstOVFfault (cpup))
12631 doFault(FAULT_OFL, fst_zero, "mp3d truncation(overflow) fault");
12632 if (EOvr && tstOVFfault (cpup))
12633 doFault(FAULT_OFL, fst_zero, "mp3d over/underflow fault");
12634 if (Ovr)
12635 {
12636 SET_I_OFLOW;
12637 if (tstOVFfault (cpup))
12638 doFault(FAULT_OFL, fst_zero, "mp3d overflow fault");
12639 }
12640 }
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395 void dv2d (cpu_state_t * cpup)
13396 {
13397 EISstruct * e = & cpu.currentEISinstruction;
13398
13399 fault_ipr_subtype_ mod_fault = 0;
13400
13401 #if !defined(EIS_SETUP)
13402 setupOperandDescriptor(cpup, 1, &mod_fault);
13403 setupOperandDescriptor(cpup, 2, &mod_fault);
13404 setupOperandDescriptorCache(cpup, 3);
13405 #endif
13406
13407 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
13408 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
13409
13410 L68_ (
13411
13412 if (mod_fault)
13413 {
13414 doFault (FAULT_IPR,
13415 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
13416 "Illegal modifier");
13417 }
13418 )
13419
13420
13421
13422 if (IWB_IRODD & 0377400000000)
13423 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "dv2d 1-9 MBZ");
13424
13425 DPS8M_ (
13426
13427 if (mod_fault)
13428 {
13429 doFault (FAULT_IPR,
13430 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
13431 "Illegal modifier");
13432 }
13433 )
13434
13435 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
13436
13437 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
13438
13439 PNL (L68_ (if (R)
13440 DU_CYCLE_FRND;))
13441
13442 uint srcTN = e->TN1;
13443
13444 uint dstTN = e->TN2;
13445 uint dstCN = e->CN2;
13446
13447 e->ADDR3 = e->ADDR2;
13448
13449 int n1 = 0, n2 = 0, sc1 = 0, sc2 = 0;
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461 switch(e->S1)
13462 {
13463 case CSFL:
13464 n1 = (int) e->N1 - 1;
13465 if (srcTN == CTN4)
13466 n1 -= 2;
13467 else
13468 n1 -= 1;
13469 sc1 = 0;
13470 break;
13471
13472 case CSLS:
13473 case CSTS:
13474 n1 = (int) e->N1 - 1;
13475 sc1 = -e->SF1;
13476 break;
13477
13478 case CSNS:
13479 n1 = (int) e->N1;
13480 sc1 = -e->SF1;
13481 break;
13482 }
13483
13484 if (n1 < 1)
13485 doFault (FAULT_IPR, fst_ill_proc, "dv2d adjusted n1<1");
13486
13487 switch(e->S2)
13488 {
13489 case CSFL:
13490 n2 = (int) e->N2 - 1;
13491 if (e->TN2 == CTN4)
13492 n2 -= 2;
13493 else
13494 n2 -= 1;
13495 sc2 = 0;
13496 break;
13497
13498 case CSLS:
13499 case CSTS:
13500 n2 = (int) e->N2 - 1;
13501 sc2 = -e->SF2;
13502 break;
13503
13504 case CSNS:
13505 n2 = (int) e->N2;
13506 sc2 = -e->SF2;
13507 break;
13508 }
13509
13510 if (n2 < 1)
13511 doFault (FAULT_IPR, fst_ill_proc, "dv2d adjusted n2<1");
13512
13513 decContext set;
13514 decContextDefaultDPS8(&set);
13515
13516 set.traps=0;
13517
13518 decNumber _1, _2, _3;
13519
13520 EISloadInputBufferNumeric (cpup, 1);
13521
13522 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
13523 if (e->sign == -1)
13524 op1->bits |= DECNEG;
13525 if (e->S1 == CSFL)
13526 op1->exponent = e->exponent;
13527
13528
13529 if (decNumberIsZero(op1))
13530 {
13531 doFault(FAULT_DIV, fst_zero, "dv2d division by 0");
13532 }
13533
13534 word9 inBufferop1 [64];
13535 memcpy (inBufferop1,e->inBuffer,sizeof(inBufferop1));
13536
13537 EISloadInputBufferNumeric (cpup, 2);
13538
13539 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
13540 if (e->sign == -1)
13541 op2->bits |= DECNEG;
13542 if (e->S2 == CSFL)
13543 op2->exponent = e->exponent;
13544
13545 int NQ;
13546 if (e->S2 == CSFL)
13547 {
13548 NQ = n2;
13549 }
13550 else
13551 {
13552
13553
13554 int clz1, clz2, i;
13555 for (i=0; i < op1->digits; i++)
13556 if (inBufferop1[i]!=0)
13557 break;
13558 clz1 = i;
13559 for (i=0; i < op2->digits; i++)
13560 if (e->inBuffer[i]!=0)
13561 break;
13562 clz2 = i;
13563 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv2d: clz1 %d clz2 %d\r\n",clz1,clz2);
13564
13565
13566
13567 NQ = (n2-clz2+1) - (n1-clz1) + (-(e->S1==CSFL?op1->exponent:(int)e->SF1));
13568
13569 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv2d S1 %d S2 %d N1 %d N2 %d clz1 %d clz2 %d E1 %d E2 %d SF2 %d NQ %d\r\n",
13570 e->S1,e->S2,e->N1,e->N2,clz1,clz2,op1->exponent,op2->exponent,e->SF2,NQ);
13571 }
13572 if (NQ > 63)
13573 doFault(FAULT_DIV, fst_zero, "dv2d NQ>63");
13574
13575
13576
13577
13578 decNumber *op3 = decNumberDivide(&_3, op2, op1, &set);
13579
13580
13581
13582
13583 PRINTDEC("op2", op2);
13584 PRINTDEC("op1", op1);
13585 PRINTDEC("op3", op3);
13586
13587
13588 if (
13589 (set.status & DEC_Division_undefined) ||
13590 (set.status & DEC_Invalid_operation) ||
13591 (set.status & DEC_Division_by_zero)
13592 ) { sim_debug (DBG_TRACEEXT, & cpu_dev, "oops! dv2d anomalous results"); }
13593
13594 if (e->S2 == CSFL)
13595 {
13596
13597
13598
13599
13600
13601 decNumber _sf;
13602
13603 if (n2 - op3->digits > 0)
13604 {
13605 decNumberFromInt32(&_sf, op3->exponent - (n2 - op3->digits));
13606 PRINTDEC("Value 1", op3)
13607 PRINTDEC("Value sf", &_sf)
13608 op3 = decNumberRescale(op3, op3, &_sf, &set);
13609 PRINTDEC("Value 2", op3)
13610 }
13611 }
13612
13613 bool Ovr = false, EOvr = false, Trunc = false;
13614 uint8_t out[256];
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625 char *res;
13626 if (e->S2 == CSFL) {
13627 decNumber _1a;
13628 decNumber _2a;
13629 decNumber _sf;
13630 if (op1->digits >= op2->digits) {
13631
13632 decNumberCopy(&_1a, op1);
13633 decNumberFromInt32(&_sf, op1->digits - op2->digits);
13634 decNumberShift(&_2a, op2, &_sf, &set);
13635 } else if (op1->digits < op2->digits) {
13636
13637 decNumberFromInt32(&_sf, op2->digits - op1->digits);
13638 decNumberShift(&_1a, op1, &_sf, &set);
13639 decNumberCopy(&_2a, op2);
13640 }
13641 _1a.exponent = 0;
13642 _2a.exponent = 0;
13643
13644 PRINTDEC("dv2d: op1a", &_1a);
13645 PRINTDEC("dv2d: op2a", &_2a);
13646 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv2d: exp1 %d exp2 %d digits op1 %d op2 %d op1a %d op2a %d\r\n",
13647 op1->exponent,op2->exponent,op1->digits,op2->digits,_1a.digits,_2a.digits);
13648
13649 if (decCompareMAG(&_1a, &_2a, &set) > 0) {
13650
13651 res = formatDecimal(out, &set, op3, n2 -1, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
13652
13653
13654
13655 for (int i = n2; i > 0; i--)
13656 res[i] = res[i-1];
13657 res[0] = '0';
13658 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv2d: addzero n2 %d %s exp %d\r\n",n2,res,op3->exponent);
13659 } else {
13660
13661 res = formatDecimal(out, &set, op3, n2, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
13662 }
13663 } else {
13664
13665 res = formatDecimal(out, &set, op3, n2, (int) e->S2, e->SF2, R, &Ovr, &Trunc);
13666 }
13667
13668 if (decNumberIsZero(op3))
13669 op3->exponent = 127;
13670
13671
13672
13673 int pos = (int) dstCN;
13674
13675
13676 switch(e->S2)
13677 {
13678 case CSFL:
13679 case CSLS:
13680 switch(dstTN)
13681 {
13682 case CTN4:
13683 if (e->P)
13684
13685
13686 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13687 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
13688 else
13689 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13690 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
13691 break;
13692 case CTN9:
13693 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13694 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
13695 break;
13696 }
13697 break;
13698
13699 case CSTS:
13700 case CSNS:
13701 break;
13702 }
13703
13704
13705 for(int i = 0 ; i < n2 ; i++)
13706 switch(dstTN)
13707 {
13708 case CTN4:
13709 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
13710 break;
13711 case CTN9:
13712 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
13713 break;
13714 }
13715
13716
13717 switch(e->S2)
13718 {
13719 case CSTS:
13720 switch(dstTN)
13721 {
13722 case CTN4:
13723 if (e->P)
13724
13725
13726 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13727 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
13728 else
13729 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13730 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
13731 break;
13732 case CTN9:
13733 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
13734 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
13735 break;
13736 }
13737 break;
13738
13739 case CSFL:
13740
13741 switch(dstTN)
13742 {
13743 case CTN4:
13744 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
13745 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
13746 break;
13747 case CTN9:
13748 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
13749 break;
13750 }
13751 break;
13752
13753 case CSLS:
13754 case CSNS:
13755 break;
13756 }
13757
13758
13759 if (e->S2 == CSFL)
13760 {
13761 if (op3->exponent > 127)
13762 {
13763 SET_I_EOFL;
13764 EOvr = true;
13765 }
13766 if (op3->exponent < -128)
13767 {
13768 SET_I_EUFL;
13769 EOvr = true;
13770 }
13771 }
13772
13773 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
13774 SC_I_ZERO (decNumberIsZero(op3));
13775
13776
13777
13778 cleanupOperandDescriptor (cpup, 1);
13779 cleanupOperandDescriptor (cpup, 2);
13780 cleanupOperandDescriptor (cpup, 3);
13781
13782
13783
13784 if (EOvr && tstOVFfault (cpup))
13785 doFault(FAULT_OFL, fst_zero, "dv2d over/underflow fault");
13786 if (Ovr)
13787 {
13788 SET_I_OFLOW;
13789 if (tstOVFfault (cpup))
13790 doFault(FAULT_OFL, fst_zero, "dv2d overflow fault");
13791 }
13792 }
13793
13794
13795
13796
13797
13798 void dv3d (cpu_state_t * cpup)
13799
13800 {
13801 EISstruct * e = & cpu.currentEISinstruction;
13802
13803 fault_ipr_subtype_ mod_fault = 0;
13804
13805 #if !defined(EIS_SETUP)
13806 setupOperandDescriptor(cpup, 1, &mod_fault);
13807 setupOperandDescriptor(cpup, 2, &mod_fault);
13808 setupOperandDescriptor(cpup, 3, &mod_fault);
13809 #endif
13810
13811 parseNumericOperandDescriptor(cpup, 1, &mod_fault);
13812 parseNumericOperandDescriptor(cpup, 2, &mod_fault);
13813 parseNumericOperandDescriptor(cpup, 3, &mod_fault);
13814
13815 L68_ (
13816
13817 if (mod_fault)
13818 {
13819 doFault (FAULT_IPR,
13820 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
13821 "Illegal modifier");
13822 }
13823 )
13824
13825
13826
13827 if (IWB_IRODD & 0200400000000)
13828 doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault}, "dv3d(): 1,9 MBZ");
13829
13830 DPS8M_ (
13831
13832 if (mod_fault)
13833 {
13834 doFault (FAULT_IPR,
13835 (_fault_subtype) {.fault_ipr_subtype=mod_fault},
13836 "Illegal modifier");
13837 }
13838 )
13839
13840 e->P = getbits36_1 (cpu.cu.IWB, 0) != 0;
13841
13842 bool R = getbits36_1 (cpu.cu.IWB, 10) != 0;
13843
13844 PNL (L68_ (if (R)
13845 DU_CYCLE_FRND;))
13846
13847 uint srcTN = e->TN1;
13848
13849 uint dstTN = e->TN3;
13850 uint dstCN = e->CN3;
13851
13852 int n1 = 0, n2 = 0, n3 = 0, sc1 = 0, sc2 = 0;
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864 switch(e->S1)
13865 {
13866 case CSFL:
13867 n1 = (int) e->N1 - 1;
13868 if (srcTN == CTN4)
13869 n1 -= 2;
13870 else
13871 n1 -= 1;
13872 sc1 = 0;
13873 break;
13874
13875 case CSLS:
13876 case CSTS:
13877 n1 = (int) e->N1 - 1;
13878 sc1 = -e->SF1;
13879 break;
13880
13881 case CSNS:
13882 n1 = (int) e->N1;
13883 sc1 = -e->SF1;
13884 break;
13885 }
13886
13887 if (n1 < 1)
13888 doFault (FAULT_IPR, fst_ill_proc, "dv3d adjusted n1<1");
13889
13890 switch(e->S2)
13891 {
13892 case CSFL:
13893 n2 = (int) e->N2 - 1;
13894 if (e->TN2 == CTN4)
13895 n2 -= 2;
13896 else
13897 n2 -= 1;
13898 sc2 = 0;
13899 break;
13900
13901 case CSLS:
13902 case CSTS:
13903 n2 = (int) e->N2 - 1;
13904 sc2 = -e->SF2;
13905 break;
13906
13907 case CSNS:
13908 n2 = (int) e->N2;
13909 sc2 = -e->SF2;
13910 break;
13911 }
13912
13913 if (n2 < 1)
13914 doFault (FAULT_IPR, fst_ill_proc, "dv3d adjusted n2<1");
13915
13916 switch(e->S3)
13917 {
13918 case CSFL:
13919 n3 = (int) e->N3 - 1;
13920 if (dstTN == CTN4)
13921 n3 -= 2;
13922 else
13923 n3 -= 1;
13924 break;
13925
13926 case CSLS:
13927 case CSTS:
13928 n3 = (int) e->N3 - 1;
13929 break;
13930
13931 case CSNS:
13932 n3 = (int) e->N3;
13933 break;
13934 }
13935 if (n3 < 1)
13936 doFault (FAULT_IPR, fst_ill_proc, "dv3d adjusted n3<1");
13937
13938 decContext set;
13939 decContextDefaultDPS8(&set);
13940
13941 set.traps=0;
13942
13943 decNumber _1, _2, _3;
13944
13945 EISloadInputBufferNumeric (cpup, 1);
13946
13947 decNumber *op1 = decBCD9ToNumber(e->inBuffer, n1, sc1, &_1);
13948
13949 if (e->sign == -1)
13950 op1->bits |= DECNEG;
13951 if (e->S1 == CSFL)
13952 op1->exponent = e->exponent;
13953
13954
13955 if (decNumberIsZero(op1))
13956 {
13957 doFault(FAULT_DIV, fst_zero, "dv3d division by 0");
13958 }
13959
13960 word9 inBufferop1 [64];
13961 memcpy (inBufferop1,e->inBuffer,sizeof(inBufferop1));
13962
13963 EISloadInputBufferNumeric (cpup, 2);
13964
13965 decNumber *op2 = decBCD9ToNumber(e->inBuffer, n2, sc2, &_2);
13966 if (e->sign == -1)
13967 op2->bits |= DECNEG;
13968 if (e->S2 == CSFL)
13969 op2->exponent = e->exponent;
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987 int NQ;
13988 if (e->S3 == CSFL)
13989 {
13990 NQ = n3;
13991 }
13992 else
13993 {
13994
13995
13996 int clz1, clz2, i;
13997 for (i=0; i < op1->digits; i++)
13998 if (inBufferop1[i]!=0)
13999 break;
14000 clz1 = i;
14001 for (i=0; i < op2->digits; i++)
14002 if (e->inBuffer[i]!=0)
14003 break;
14004 clz2 = i;
14005 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv3d: clz1 %d clz2 %d\r\n",clz1,clz2);
14006
14007
14008
14009 NQ = (n2-clz2+1) - (n1-clz1) + \
14010 ((e->S2==CSFL?op2->exponent:(int)e->SF2)-(e->S1==CSFL?op1->exponent:(int)e->SF1)-(int)e->SF3);
14011
14012 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv3d S1 %d S2 %d N1 %d N2 %d clz1 %d clz2 %d E1 %d E2 %d SF3 %d NQ %d\r\n",
14013 e->S1,e->S2,e->N1,e->N2,clz1,clz2,op1->exponent,op2->exponent,e->SF3,NQ);
14014 }
14015 if (NQ > 63)
14016 doFault(FAULT_DIV, fst_zero, "dv3d NQ>63");
14017
14018
14019
14020
14021 decNumber *op3 = decNumberDivide(&_3, op2, op1, &set);
14022
14023
14024
14025
14026 PRINTDEC("op2", op2);
14027 PRINTDEC("op1", op1);
14028 PRINTDEC("op3", op3);
14029
14030
14031 if (
14032 (set.status & DEC_Division_undefined) ||
14033 (set.status & DEC_Invalid_operation) ||
14034 (set.status & DEC_Division_by_zero)
14035 ) { sim_debug (DBG_TRACEEXT, & cpu_dev, "oops! dv3d anomalous results"); }
14036
14037 if (e->S3 == CSFL)
14038 {
14039
14040
14041
14042
14043
14044 decNumber _sf;
14045
14046 if (n3 - op3->digits > 0)
14047 {
14048 decNumberFromInt32(&_sf, op3->exponent - (n3 - op3->digits));
14049 PRINTDEC("Value 1", op3)
14050 PRINTDEC("Value sf", &_sf)
14051 op3 = decNumberRescale(op3, op3, &_sf, &set);
14052 PRINTDEC("Value 2", op3)
14053 }
14054 }
14055
14056 bool Ovr = false, EOvr = false, Trunc = false;
14057 uint8_t out[256];
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068 char *res;
14069 if (e->S3 == CSFL) {
14070 decNumber _1a;
14071 decNumber _2a;
14072 decNumber _sf;
14073 if (op1->digits >= op2->digits) {
14074
14075 decNumberCopy(&_1a, op1);
14076 decNumberFromInt32(&_sf, op1->digits - op2->digits);
14077 decNumberShift(&_2a, op2, &_sf, &set);
14078 } else if (op1->digits < op2->digits) {
14079
14080 decNumberFromInt32(&_sf, op2->digits - op1->digits);
14081 decNumberShift(&_1a, op1, &_sf, &set);
14082 decNumberCopy(&_2a, op2);
14083 }
14084 _1a.exponent = 0;
14085 _2a.exponent = 0;
14086
14087 PRINTDEC("dv3d: op1a", &_1a);
14088 PRINTDEC("dv3d: op2a", &_2a);
14089 sim_debug (DBG_TRACEEXT, & cpu_dev,
14090 "dv3d: exp1 %d exp2 %d digits op1 %d op2 %d op1a %d op2a %d\r\n",
14091 op1->exponent ,op2->exponent, op1->digits,
14092 op2->digits, _1a.digits, _2a.digits);
14093
14094 if (decCompareMAG(&_1a, &_2a, &set) > 0) {
14095
14096 res = formatDecimal(out, &set, op3, n3 -1, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
14097
14098
14099
14100 for (int i = n3; i > 0; i--)
14101 res[i] = res[i-1];
14102 res[0] = '0';
14103 sim_debug (DBG_TRACEEXT, & cpu_dev, "dv3d: addzero n3 %d %s exp %d\r\n",n3,res,op3->exponent);
14104 } else {
14105
14106 res = formatDecimal(out, &set, op3, n3, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
14107 }
14108 } else {
14109
14110 res = formatDecimal(out, &set, op3, n3, (int) e->S3, e->SF3, R, &Ovr, &Trunc);
14111 }
14112
14113 if (decNumberIsZero(op3))
14114 op3->exponent = 127;
14115
14116
14117
14118
14119
14120 int pos = (int) dstCN;
14121
14122
14123 switch(e->S3)
14124 {
14125 case CSFL:
14126 case CSLS:
14127 switch(dstTN)
14128 {
14129 case CTN4:
14130 if (e->P)
14131
14132
14133 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14134 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
14135 else
14136 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14137 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
14138 break;
14139 case CTN9:
14140 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14141 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
14142 break;
14143 }
14144 break;
14145
14146 case CSTS:
14147 case CSNS:
14148 break;
14149 }
14150
14151
14152 for(int i = 0 ; i < n3 ; i++)
14153 switch(dstTN)
14154 {
14155 case CTN4:
14156 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) (res[i] - '0'));
14157 break;
14158 case CTN9:
14159 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (word9) res[i]);
14160 break;
14161 }
14162
14163
14164 switch(e->S3)
14165 {
14166 case CSTS:
14167 switch(dstTN)
14168 {
14169 case CTN4:
14170 if (e->P)
14171
14172
14173 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14174 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 013);
14175 else
14176 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14177 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? 015 : 014);
14178 break;
14179 case CTN9:
14180 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN,
14181 (decNumberIsNegative(op3) && !decNumberIsZero(op3)) ? '-' : '+');
14182 break;
14183 }
14184 break;
14185
14186 case CSFL:
14187
14188 switch(dstTN)
14189 {
14190 case CTN4:
14191 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, (op3->exponent >> 4) & 0xf);
14192 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xf);
14193 break;
14194 case CTN9:
14195 EISwrite49(cpup, &e->ADDR3, &pos, (int) dstTN, op3->exponent & 0xff);
14196 break;
14197 }
14198 break;
14199
14200 case CSLS:
14201 case CSNS:
14202 break;
14203 }
14204
14205
14206 if (e->S3 == CSFL)
14207 {
14208 if (op3->exponent > 127)
14209 {
14210 SET_I_EOFL;
14211 EOvr = true;
14212 }
14213 if (op3->exponent < -128)
14214 {
14215 SET_I_EUFL;
14216 EOvr = true;
14217 }
14218 }
14219
14220 SC_I_NEG (decNumberIsNegative(op3) && !decNumberIsZero(op3));
14221 SC_I_ZERO (decNumberIsZero(op3));
14222
14223
14224
14225 cleanupOperandDescriptor (cpup, 1);
14226 cleanupOperandDescriptor (cpup, 2);
14227 cleanupOperandDescriptor (cpup, 3);
14228
14229
14230
14231 if (EOvr && tstOVFfault (cpup))
14232 doFault(FAULT_OFL, fst_zero, "dv3d over/underflow fault");
14233 if (Ovr)
14234 {
14235 SET_I_OFLOW;
14236 if (tstOVFfault (cpup))
14237 doFault(FAULT_OFL, fst_zero, "dv3d overflow fault");
14238 }
14239 }