1 /*
2 * vim: filetype=c:tabstop=4:ai:expandtab
3 * SPDX-License-Identifier: ICU
4 * scspell-id: 410f7ba2-f62d-11ec-b7d6-80ee73e9b8e7
5 *
6 * ---------------------------------------------------------------------------
7 *
8 * Copyright (c) 2007-2013 Michael Mondy
9 * Copyright (c) 2012-2016 Harry Reed
10 * Copyright (c) 2013-2018 Charles Anthony
11 * Copyright (c) 2021-2025 The DPS8M Development Team
12 *
13 * This software is made available under the terms of the ICU License.
14 * See the LICENSE.md file at the top-level directory of this distribution.
15 *
16 * ---------------------------------------------------------------------------
17 */
18
19 #include <stdio.h>
20 #include "dps8.h"
21 #include "dps8_sys.h"
22 #include "dps8_iom.h"
23 #include "dps8_cable.h"
24 #include "dps8_cpu.h"
25 #include "dps8_scu.h"
26 #include "dps8_faults.h"
27 #include "dps8_addrmods.h"
28 #include "dps8_append.h"
29 #include "dps8_ins.h"
30 #include "dps8_iefp.h"
31 #include "dps8_opcodetable.h"
32 #include "dps8_utils.h"
33 #include "dps8_cache.h"
34 #if defined(THREADZ) || defined(LOCKLESS)
35 # include "threadz.h"
36 #endif
37
38 #define DBG_CTR cpu.cycleCnt
39
40 // Computed Address Formation Flowcharts
41
42 //
43 // return contents of register indicated by Td
44 //
45
46 static word18 get_Cr (cpu_state_t * cpup, word4 Tdes)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
47 {
48 cpu.ou.directOperandFlag = false;
49
50 if (Tdes == TD_N)
51 return 0;
52
53 if (Tdes & 010) // Xn
54 return cpu.rX [X (Tdes)];
55
56 switch (Tdes)
57 {
58 case TD_N: // rY = address from opcode
59 return 0;
60
61 case TD_AU: // rY + C(A)0,17
62 #if defined(TESTING)
63 HDBGRegAR ("au");
64 #endif
65 return GETHI (cpu.rA);
66
67 case TD_QU: // rY + C(Q)0,17
68 #if defined(TESTING)
69 HDBGRegAR ("qu");
70 #endif
71 return GETHI (cpu.rQ);
72
73 case TD_DU: // none; operand has the form y || (00...0)18
74 cpu.ou.directOperand = 0;
75 SETHI (cpu.ou.directOperand, cpu.rY);
76 cpu.ou.directOperandFlag = true;
77
78 sim_debug (DBG_ADDRMOD, & cpu_dev,
79 "%s(TD_DU): rY=%06o directOperand=%012"PRIo64"\r\n",
80 __func__, cpu.rY, cpu.ou.directOperand);
81
82 return 0;
83
84 case TD_IC: // rY + C (PPR.IC)
85 return cpu.PPR.IC;
86
87 case TD_AL: // rY + C(A)18,35
88 #if defined(TESTING)
89 HDBGRegAR ("al");
90 #endif
91 return GETLO (cpu.rA);
92
93 case TD_QL: // rY + C(Q)18,35
94 #if defined(TESTING)
95 HDBGRegAR ("ql");
96 #endif
97 return GETLO (cpu.rQ);
98
99 case TD_DL: // none; operand has the form (00...0)18 || y
100 cpu.ou.directOperand = 0;
101 SETLO (cpu.ou.directOperand, cpu.rY);
102 cpu.ou.directOperandFlag = true;
103
104 sim_debug (DBG_ADDRMOD, & cpu_dev,
105 "%s(TD_DL): rY=%06o directOperand=%012"PRIo64"\r\n",
106 __func__, cpu.rY, cpu.ou.directOperand);
107
108 return 0;
109 }
110 return 0;
111 }
112
113 static char * op_desc_str (cpu_state_t * cpup, char * temp)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
114 {
115 DCDstruct * i = & cpu.currentInstruction;
116
117 strcpy (temp, "");
118
119 if (READOP (i))
120 {
121 switch (operand_size (cpup))
122 {
123 case 1:
124 strcat (temp, "readCY");
125 break;
126
127 case 2:
128 strcat (temp, "readCYpair2");
129 break;
130
131 case 8:
132 strcat (temp, "readCYblock8");
133 break;
134
135 case 16:
136 strcat (temp, "readCYblock16");
137 break;
138
139 case 32:
140 strcat (temp, "readCYblock32");
141 break;
142 }
143 }
144
145 if (WRITEOP (i))
146 {
147 if (strlen (temp))
148 strcat (temp, "/");
149
150 switch (operand_size (cpup))
151 {
152 case 1:
153 strcat (temp, "writeCY");
154 break;
155
156 case 2:
157 strcat (temp, "writeCYpair2");
158 break;
159
160 case 8:
161 strcat (temp, "writeCYblock8");
162 break;
163
164 case 16:
165 strcat (temp, "writeCYblock16");
166 break;
167
168 case 32:
169 strcat (temp, "writeCYblock32");
170 break;
171 }
172 }
173
174 if (TRANSOP (i))
175 {
176 if (strlen (temp))
177 strcat (temp, "/");
178
179 strcat (temp, "prepareCA (TRA)");
180 }
181
182 if (! READOP (i) && ! WRITEOP (i) && ! TRANSOP (i) &&
183 i -> info -> flags & PREPARE_CA)
184 {
185 if (strlen (temp))
186 strcat (temp, "/");
187
188 strcat (temp, "prepareCA");
189 }
190
191 return temp; //"op_desc_str (???)";
192 }
193
194 static void do_ITP (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
195 {
196 sim_debug (DBG_APPENDING, & cpu_dev,
197 "ITP Pair: PRNUM=%o BITNO=%o WORDNO=%o MOD=%o\r\n",
198 GET_ITP_PRNUM (cpu.itxPair), GET_ITP_WORDNO (cpu.itxPair),
199 GET_ITP_BITNO (cpu.itxPair), GET_ITP_MOD (cpu.itxPair));
200 //
201 // For n = C(ITP.PRNUM):
202 // C(PRn.SNR) -> C(TPR.TSR)
203 // maximum of ( C(PRn.RNR), C(SDW.R1), C(TPR.TRR) ) -> C(TPR.TRR)
204 // C(ITP.BITNO) -> C(TPR.TBR)
205 // C(PRn.WORDNO) + C(ITP.WORDNO) + C(r) -> C(TPR.CA)
206
207 // Notes:
208 // 1. r = C(CT-HOLD) if the instruction word or preceding indirect word
209 // specified indirect then register modification, or
210 // 2. r = C(ITP.MOD.Td) if the instruction word or preceding indirect word
211 // specified register then indirect modification and ITP.MOD.Tm specifies
212 // either register or register then indirect modification.
213 // 3. SDW.R1 is the upper limit of the read/write ring bracket for the
214 // segment C(TPR.TSR) (see Section 8).
215 //
216
217 word3 n = GET_ITP_PRNUM (cpu.itxPair);
218 CPTUR (cptUsePRn + n);
219 #if defined(TESTING)
220 HDBGRegPRR (n, "ITP");
221 #endif
222 cpu.TPR.TSR = cpu.PR[n].SNR;
223 cpu.TPR.TRR = max3 (cpu.PR[n].RNR, cpu.RSDWH_R1, cpu.TPR.TRR);
224 cpu.TPR.TBR = GET_ITP_BITNO (cpu.itxPair);
225 cpu.TPR.CA = cpu.PAR[n].WORDNO + GET_ITP_WORDNO (cpu.itxPair);
226 cpu.TPR.CA &= AMASK;
227 cpu.rY = cpu.TPR.CA;
228
229 cpu.rTAG = GET_ITP_MOD (cpu.itxPair);
230
231 cpu.cu.itp = 1;
232 cpu.cu.TSN_PRNO[0] = n;
233 cpu.cu.TSN_VALID[0] = 1;
234
235 return;
236 }
237
238 static void do_ITS (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
239 {
240 sim_debug (DBG_APPENDING, & cpu_dev,
241 "ITS Pair: SEGNO=%o RN=%o WORDNO=%o BITNO=%o MOD=%o\r\n",
242 GET_ITS_SEGNO (cpu.itxPair), GET_ITS_RN (cpu.itxPair),
243 GET_ITS_WORDNO (cpu.itxPair), GET_ITS_BITNO (cpu.itxPair),
244 GET_ITS_MOD (cpu.itxPair));
245 // C(ITS.SEGNO) -> C(TPR.TSR)
246 // maximum of ( C(ITS.RN), C(SDW.R1), C(TPR.TRR) ) -> C(TPR.TRR)
247 // C(ITS.BITNO) -> C(TPR.TBR)
248 // C(ITS.WORDNO) + C(r) -> C(TPR.CA)
249 //
250 // 1. r = C(CT-HOLD) if the instruction word or preceding indirect word
251 // specified indirect then register modification, or
252 // 2. r = C(ITS.MOD.Td) if the instruction word or preceding indirect word
253 // specified register then indirect modification and ITS.MOD.Tm specifies
254 // either register or register then indirect modification.
255 // 3. SDW.R1 is the upper limit of the read/write ring bracket for the
256 // segment C(TPR.TSR) (see Section 8).
257
258 cpu.TPR.TSR = GET_ITS_SEGNO (cpu.itxPair);
259
260 sim_debug (DBG_APPENDING, & cpu_dev,
261 "ITS Pair Ring: RN %o RSDWH_R1 %o TRR %o max %o\r\n",
262 GET_ITS_RN (cpu.itxPair), cpu.RSDWH_R1, cpu.TPR.TRR,
263 max3 (GET_ITS_RN (cpu.itxPair), cpu.RSDWH_R1, cpu.TPR.TRR));
264
265 cpu.TPR.TRR = max3 (GET_ITS_RN (cpu.itxPair), cpu.RSDWH_R1, cpu.TPR.TRR);
266 cpu.TPR.TBR = GET_ITS_BITNO (cpu.itxPair);
267 cpu.TPR.CA = GET_ITS_WORDNO (cpu.itxPair);
268 cpu.TPR.CA &= AMASK;
269
270 cpu.rY = cpu.TPR.CA;
271
272 cpu.rTAG = GET_ITS_MOD (cpu.itxPair);
273
274 cpu.cu.its = 1;
275
276 return;
277 }
278
279 // CANFAULT
280 static void do_ITS_ITP (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
281 {
282 word6 ind_tag = GET_TAG (cpu.itxPair [0]);
283
284 sim_debug (DBG_APPENDING, & cpu_dev,
285 "do_ITS/ITP: %012"PRIo64" %012"PRIo64"\r\n",
286 cpu.itxPair[0], cpu.itxPair[1]);
287
288 // Whenever the processor is forming a virtual address two special address
289 // modifiers may be specified and are effective under certain restrictive
290 // conditions. The special address modifiers are shown in Table 6-4 and
291 // discussed in the paragraphs below.
292 //
293 // The conditions for which the special address modifiers are effective
294 // are as follows:
295 //
296 // 1. The instruction word (or preceding indirect word) must specify
297 // indirect then register or register then indirect modification.
298 //
299 // 2. The computed address for the indirect word must be even.
300 //
301 // If these conditions are satisfied, the processor examines the indirect
302 // word TAG field for the special address modifiers.
303 //
304 // If either condition is violated, the indirect word TAG field is
305 // interpreted as a normal address modifier and the presence of a special
306 // address modifier will cause an illegal procedure, illegal modifier,
307 // fault.
308
309 if (ISITS (ind_tag))
310 do_ITS (cpup);
311 else
312 do_ITP (cpup);
313
314 //set_went_appending ();
315 cpu.cu.XSF = 1;
316 cpu.xsfScu = true;
317 sim_debug (DBG_APPENDING, & cpu_dev, "do_ITS_ITP sets XSF to 1\r\n");
318 }
319
320 void updateIWB (cpu_state_t * cpup, word18 addr, word6 tag)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
321 {
322 word36 * wb;
323 if (USE_IRODD)
324 wb = & cpu.cu.IRODD;
325 else
326 wb = & cpu.cu.IWB;
327 sim_debug (DBG_ADDRMOD, & cpu_dev,
328 "updateIWB: IWB was %012"PRIo64" %06o %s\r\n",
329 * wb, GET_ADDR (* wb),
330 extMods [GET_TAG (* wb)].mod);
331
332 putbits36_18 (wb, 0, addr);
333 putbits36_6 (wb, 30, tag);
334 putbits36_1 (wb, 29, 0);
335
336 sim_debug (DBG_ADDRMOD, & cpu_dev,
337 "updateIWB: IWB now %012"PRIo64" %06o %s\r\n",
338 * wb, GET_ADDR (* wb),
339 extMods [GET_TAG (* wb)].mod);
340
341 decode_instruction (cpup, IWB_IRODD, & cpu.currentInstruction);
342 }
343
344 //
345 // Input:
346 // cu.IWB
347 // currentInstruction
348 // TPR.TSR
349 // TPR.TRR
350 // TPR.TBR // XXX check to see if this is initialized
351 // TPR.CA
352 //
353 // Output:
354 // TPR.CA
355 // directOperandFlag
356 //
357 // CANFAULT
358
359 static void do_caf_ (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
360 {
361 if (cpu.currentInstruction.b29 == 0)
362 {
363 cpu.TPR.CA = GET_ADDR (IWB_IRODD);
364 }
365 else
366 {
367 word3 n = GET_PRN(IWB_IRODD); // get PRn
368 #if defined(TESTING)
369 HDBGRegPRR (n, "b29");
370 #endif
371 word15 offset = GET_OFFSET(IWB_IRODD);
372 cpu.TPR.CA = (cpu.PAR[n].WORDNO + SIGNEXT15_18 (offset))
373 & MASK18;
374 }
375 char buf [256];
376 sim_debug (DBG_ADDRMOD, & cpu_dev,
377 "%s(Entry): operType:%s TPR.CA=%06o\r\n",
378 __func__, op_desc_str (cpup, buf), cpu.TPR.CA);
379 sim_debug (DBG_ADDRMOD, & cpu_dev,
380 "%s(Entry): CT_HOLD %o\r\n",
381 __func__, cpu.cu.CT_HOLD);
382
383 DCDstruct * i = & cpu.currentInstruction;
384
385 word6 Tm = 0;
386 word6 Td = 0;
387
388 /* word6 iTAG; */ // tag of word preceding an indirect fetch
389
390 cpu.ou.directOperandFlag = false;
391
392 if (i -> info -> flags & NO_TAG) // for instructions line STCA/STCQ
393 cpu.rTAG = 0;
394 else
395 cpu.rTAG = GET_TAG (IWB_IRODD);
396
397 int lockupCnt = 0;
398 #define lockupLimit 4096 // approx. 2 ms
399
400 startCA:;
401
402 if (++ lockupCnt > lockupLimit)
403 {
404 doFault (FAULT_LUF, fst_zero, "Lockup in addrmod");
405 }
406
407 Td = GET_TD (cpu.rTAG);
408 Tm = GET_TM (cpu.rTAG);
409
410 // CT_HOLD is set to 0 on instruction setup; if it is non-zero here,
411 // we must have faulted during an indirect word fetch. Restore
412 // state and restart the fetch.
413 if (cpu.cu.CT_HOLD)
414 {
415 sim_debug (DBG_ADDRMOD, & cpu_dev,
416 "%s(startCA): restart; CT_HOLD %02o\r\n",
417 __func__, cpu.cu.CT_HOLD);
418 // Part of ISOLTS tst885 ir
419 if ((cpu.tweaks.isolts_mode || cpu.tweaks.tandd_mode) &&
420 GET_TM(cpu.cu.CT_HOLD) == TM_IT && GET_TD (cpu.cu.CT_HOLD) == IT_DIC &&
421 cpu.cu.pot == 1 && GET_ADDR (IWB_IRODD) == cpu.TPR.CA)
422 {
423 cpu.TPR.CA--;
424 sim_warn ("%s: correct CA\r\n", __func__);
425 }
426 if (Tm == TM_IT && (Td == IT_IDC || Td == IT_DIC))
427 {
428 cpu.cu.pot = 1;
429 }
430 }
431 else
432 {
433 // not CT_HOLD
434 cpu.cu.its = 0;
435 cpu.cu.itp = 0;
436 cpu.cu.pot = 0;
437 }
438 sim_debug (DBG_ADDRMOD, & cpu_dev,
439 "%s(startCA): TAG=%02o(%s) Tm=%o Td=%o CT_HOLD %02o\r\n",
440 __func__, cpu.rTAG, get_mod_string (buf, cpu.rTAG), Tm, Td, cpu.cu.CT_HOLD);
441
442 switch (Tm)
443 {
444 case TM_R:
445 goto R_MOD;
446 case TM_RI:
447 goto RI_MOD;
448 case TM_IT:
449 goto IT_MOD;
450 case TM_IR:
451 goto IR_MOD;
452 default:
453 break;
454 }
455
456 sim_printf ("%s(startCA): unknown Tm??? %o\r\n",
457 __func__, GET_TM (cpu.rTAG));
458 sim_warn ("(startCA): unknown Tmi; can't happen!\r\n");
459 return;
460
461 // Register modification. Fig 6-3
462 R_MOD:;
463 {
464 if (Td == TD_N) // TPR.CA = address from opcode
465 {
466 //updateIWB (identity) // known that Td is 0.
467 return;
468 }
469
470 word18 Cr = get_Cr (cpup, Td);
471
472 sim_debug (DBG_ADDRMOD, & cpu_dev, "R_MOD: Cr=%06o\r\n", Cr);
473
474 if (cpu.ou.directOperandFlag)
475 {
476 sim_debug (DBG_ADDRMOD, & cpu_dev,
477 "R_MOD: directOperand = %012"PRIo64"\r\n",
478 cpu.ou.directOperand);
479 return;
480 }
481
482 // For the case of RPT/RPD, the instruction decoder has
483 // verified that Tm is R or RI, and Td is X1..X7.
484 if (cpu.cu.rpt || cpu.cu.rd | cpu.cu.rl)
485 {
486 if (cpu.currentInstruction.b29)
487 {
488 word3 PRn = GET_PRN(IWB_IRODD);
489 #if defined(TESTING)
490 HDBGRegPRR (PRn, "rpx b29");
491 #endif
492 CPTUR (cptUsePRn + PRn);
493 cpu.TPR.CA = Cr + cpu.PR [PRn].WORDNO;
494 cpu.TPR.CA &= AMASK;
495 }
496 else
497 {
498 cpu.TPR.CA = Cr;
499 }
500 }
501 else
502 {
503 cpu.TPR.CA += Cr;
504 cpu.TPR.CA &= MASK18; // keep to 18-bits
505 }
506 sim_debug (DBG_ADDRMOD, & cpu_dev, "R_MOD: TPR.CA=%06o\r\n",
507 cpu.TPR.CA);
508
509 return;
510 } // R_MOD
511
512 // Figure 6-4. Register Then Indirect Modification Flowchart
513 RI_MOD:;
514 {
515 sim_debug (DBG_ADDRMOD, & cpu_dev, "RI_MOD: Td=%o\r\n", Td);
516
517 if (Td == TD_DU || Td == TD_DL)
518 doFault (FAULT_IPR, fst_ill_mod,
519 "RI_MOD: Td == TD_DU || Td == TD_DL");
520
521 if (Td != TD_N)
522 {
523 word18 Cr = get_Cr (cpup, Td); // C(r)
524
525 // We don''t need to worry about direct operand here, since du
526 // and dl are disallowed above
527
528 sim_debug (DBG_ADDRMOD, & cpu_dev,
529 "RI_MOD: Cr=%06o CA(Before)=%06o\r\n", Cr, cpu.TPR.CA);
530
531 if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
532 {
533 if (cpu.currentInstruction.b29)
534 {
535 word3 PRn = GET_PRN(IWB_IRODD);
536 #if defined(TESTING)
537 HDBGRegPRR (PRn, "rpx b29");
538 #endif
539 CPTUR (cptUsePRn + PRn);
540 cpu.TPR.CA = Cr + cpu.PR [PRn].WORDNO;
541 }
542 else
543 {
544 cpu.TPR.CA = Cr;
545 }
546 cpu.TPR.CA &= AMASK;
547 }
548 else
549 {
550 cpu.TPR.CA += Cr;
551 cpu.TPR.CA &= MASK18; // keep to 18-bits
552 }
553 sim_debug (DBG_ADDRMOD, & cpu_dev,
554 "RI_MOD: CA(After)=%06o\r\n", cpu.TPR.CA);
555 }
556
557 // - Multics link snap code (adjust_mc) sets rTAG to TM_RI
558 // - After directed faults RI modifier after IR modifier end up here
559 // - In both cases continue with indirect chain
560 if (GET_TM(cpu.cu.CT_HOLD) == TM_IR)
561 {
562 goto IR_MOD_2;
563 }
564
565 // If the indirect word faults, on restart the CA will be the post
566 // register modification value, so we want to prevent it from
567 // happening again on restart
568 word18 saveCA = cpu.TPR.CA;
569 ReadIndirect (cpup);
570
571 if ((saveCA & 1) == 0 && (ISITP (cpu.itxPair[0]) || ISITS (cpu.itxPair[0])))
572 {
573 do_ITS_ITP (cpup);
574 updateIWB (cpup, cpu.TPR.CA, cpu.rTAG);
575 }
576 else
577 {
578 cpu.rTAG = GET_TAG (cpu.itxPair[0]);
579 if (ISITP (cpu.itxPair[0]) || ISITS (cpu.itxPair[0]))
580 {
581 sim_warn ("%s: itp/its at odd address\r\n", __func__);
582 #if defined(TESTING)
583 traceInstruction (0);
584 #endif
585 }
586 if (!(cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl))
587 {
588 updateIWB (cpup, GET_ADDR (cpu.itxPair[0]), cpu.rTAG);
589 }
590 // F2 and F3 fault tests after updateIW
591 if (GET_TM (cpu.rTAG) == TM_IT)
592 {
593 if (GET_TD (cpu.rTAG) == IT_F2)
594 {
595 doFault (FAULT_F2, fst_zero, "RI_MOD: IT_F2 (0)");
596 }
597 if (GET_TD (cpu.rTAG) == IT_F3)
598 {
599 doFault (FAULT_F3, fst_zero, "RI_MOD: IT_F3");
600 }
601 }
602 cpu.TPR.CA = GETHI (cpu.itxPair[0]);
603 cpu.rY = cpu.TPR.CA;
604 }
605 // "In the case of RI modification, only one indirect reference is made
606 // per repeated execution. The TAG field of the indirect word is not
607 // interpreted. The indirect word is treated as though it had R
608 // modification with R = N."
609
610 // Check for fault causing tags before updating the IWB, so the
611 // instruction restart will reload the offending indirect word.
612 sim_debug (DBG_ADDRMOD, & cpu_dev,
613 "RI_MOD: cpu.itxPair[0]=%012"PRIo64
614 " TPR.CA=%06o rTAG=%02o\r\n",
615 cpu.itxPair[0], cpu.TPR.CA, cpu.rTAG);
616 // If repeat, the indirection chain is limited, so it is not needed
617 // to clear the tag; the delta code later on needs the tag to know
618 // which X register to update
619 if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
620 return;
621
622 goto startCA;
623 } // RI_MOD
624
625 // Figure 6-5. Indirect Then Register Modification Flowchart
626 IR_MOD:;
627 {
628 IR_MOD_1:;
629
630 sim_debug (DBG_ADDRMOD, & cpu_dev,
631 "IR_MOD: CT_HOLD=%o %o\r\n", cpu.cu.CT_HOLD, Td);
632
633 IR_MOD_2:;
634
635 if (++ lockupCnt > lockupLimit)
636 {
637 doFault (FAULT_LUF, fst_zero, "Lockup in addrmod IR mode");
638 }
639
640 sim_debug (DBG_ADDRMOD, & cpu_dev,
641 "IR_MOD: fetching indirect word from %06o\r\n",
642 cpu.TPR.CA);
643
644 word18 saveCA = cpu.TPR.CA;
645 ReadIndirect (cpup);
646
647 // ReadIndirect does NOT update cpu.rTAG anymore
648 if (GET_TM(cpu.rTAG) == TM_IR)
649 cpu.cu.CT_HOLD = cpu.rTAG;
650
651 if ((saveCA & 1) == 0 && (ISITP (cpu.itxPair[0]) || ISITS (cpu.itxPair[0])))
652 {
653 do_ITS_ITP (cpup);
654 }
655 else
656 {
657 if (ISITP (cpu.itxPair[0]) || ISITS (cpu.itxPair[0]))
658 {
659 sim_warn ("%s: itp/its at odd address\r\n", __func__);
660 #if defined(TESTING)
661 traceInstruction (0);
662 #endif
663 }
664 cpu.TPR.CA = GETHI (cpu.itxPair[0]);
665 cpu.rY = cpu.TPR.CA;
666 cpu.rTAG = GET_TAG (cpu.itxPair[0]);
667 }
668
669 sim_debug (DBG_ADDRMOD, & cpu_dev,
670 "IR_MOD: CT_HOLD=%o\r\n", cpu.cu.CT_HOLD);
671 Td = GET_TD (cpu.rTAG);
672 Tm = GET_TM (cpu.rTAG);
673
674 sim_debug (DBG_ADDRMOD, & cpu_dev,
675 "IR_MOD1: cpu.itxPair[0]=%012"PRIo64
676 " TPR.CA=%06o Tm=%o Td=%02o (%s)\r\n",
677 cpu.itxPair[0], cpu.TPR.CA, Tm, Td,
678 get_mod_string (buf, GET_TAG (cpu.itxPair[0])));
679
680 switch (Tm)
681 {
682 case TM_IT:
683 {
684 sim_debug (DBG_ADDRMOD, & cpu_dev,
685 "IR_MOD(TM_IT): Td=%02o => %02o\r\n",
686 Td, cpu.cu.CT_HOLD);
687
688 if (Td == IT_F2 || Td == IT_F3)
689 {
690 updateIWB(cpup, cpu.TPR.CA, cpu.rTAG);
691 // Abort. FT2 or 3
692 switch (Td)
693 {
694 case IT_F2:
695 cpu.TPR.CA = saveCA;
696 doFault (FAULT_F2, fst_zero, "TM_IT: IT_F2 (1)");
697
698 /*FALLTHRU*/ /* fall through */ /* fallthrough */
699 case IT_F3:
700 cpu.TPR.CA = saveCA;
701 doFault (FAULT_F3, fst_zero, "TM_IT: IT_F3");
702 }
703 }
704 // fall through to TM_R
705 #if !defined(__SUNPRO_C) && !defined(__SUNPRO_CC) && !defined(__SUNPRO_CC_COMPAT)
706 /*FALLTHRU*/ /* fall through */ /* fallthrough */
707 # if defined(__GNUC__) && __GNUC__ > 6
708 __attribute__ ((fallthrough));
709 # endif /* if defined(__GNUC__) && __GNUC__ > 6 */
710 /*FALLTHRU*/ /* fall through */ /* fallthrough */
711 # if defined(__clang__)
712 (void)0;
713 # endif /* if defined(__clang__) */
714 #endif
715 } // TM_IT
716
717 /*FALLTHRU*/ /* fall through */ /* fallthrough */
718 case TM_R:
719 {
720 word6 Td_hold = GET_TD (cpu.cu.CT_HOLD);
721 cpu.rTAG = (TM_R | Td_hold);
722 updateIWB (cpup, cpu.TPR.CA, cpu.rTAG);
723 goto startCA;
724 } // TM_R
725
726 case TM_RI:
727 {
728 if (Td == TD_DU || Td == TD_DL)
729 doFault (FAULT_IPR, fst_ill_mod,
730 "RI_MOD: Td == TD_DU || Td == TD_DL");
731
732 word18 Cr = get_Cr (cpup, Td);
733
734 sim_debug (DBG_ADDRMOD, & cpu_dev,
735 "IR_MOD(TM_RI): Td=%o Cr=%06o TPR.CA(Before)=%06o\r\n",
736 Td, Cr, cpu.TPR.CA);
737
738 cpu.TPR.CA += Cr;
739 cpu.TPR.CA &= MASK18; // keep to 18-bits
740
741 sim_debug (DBG_ADDRMOD, & cpu_dev,
742 "IR_MOD(TM_RI): TPR.CA=%06o\r\n", cpu.TPR.CA);
743
744 sim_debug (DBG_ADDRMOD, & cpu_dev,
745 "IR_MOD(TM_RI): TPR.CA(After)=%06o\r\n",
746 cpu.TPR.CA);
747
748 // Don't add register twice if next indirection faults
749 updateIWB (cpup, cpu.TPR.CA, (TM_RI|TD_N));
750 goto IR_MOD_2;
751 } // TM_RI
752
753 case TM_IR:
754 {
755 updateIWB (cpup, cpu.TPR.CA, cpu.rTAG); // XXX guessing here...
756 goto IR_MOD_1;
757 } // TM_IR
758 } // TM
759
760 sim_printf ("%s(IR_MOD): unknown Tm??? %o\r\n",
761 __func__, GET_TM (cpu.rTAG));
762 return;
763 } // IR_MOD
764
765 IT_MOD:;
766 {
767 // IT_SD = 004,
768 // IT_SCR = 005,
769 // IT_CI = 010,
770 // IT_I = 011,
771 // IT_SC = 012,
772 // IT_AD = 013,
773 // IT_DI = 014,
774 // IT_DIC = 015,
775 // IT_ID = 016,
776 // IT_IDC = 017
777 word6 idwtag, delta;
778 word24 Yi = (word24) -1;
779
780 switch (Td)
781 {
782 // XXX this is probably wrong. ITS/ITP are not standard addr mods
783 case SPEC_ITP:
784 /*FALLTHRU*/ /* fall through */ /* fallthrough */
785 case SPEC_ITS:
786 {
787 doFault(FAULT_IPR, fst_ill_mod, "ITx in IT_MOD)");
788 }
789
790 /*FALLTHRU*/ /* fall through */ /* fallthrough */
791 case 2:
792 {
793 sim_debug (DBG_ADDRMOD, & cpu_dev,
794 "IT_MOD(): illegal procedure, illegal modifier, "
795 "fault Td=%o\r\n", Td);
796 doFault (FAULT_IPR, fst_ill_mod,
797 "IT_MOD(): illegal procedure, illegal modifier, "
798 "fault");
799 }
800
801 /*FALLTHRU*/ /* fall through */ /* fallthrough */
802 case IT_F1:
803 {
804 doFault(FAULT_F1, fst_zero, "IT_MOD: IT_F1");
805 }
806
807 /*FALLTHRU*/ /* fall through */ /* fallthrough */
808 case IT_F2:
809 {
810 doFault(FAULT_F2, fst_zero, "IT_MOD: IT_F2 (2)");
811 }
812
813 /*FALLTHRU*/ /* fall through */ /* fallthrough */
814 case IT_F3:
815 {
816 doFault(FAULT_F3, fst_zero, "IT_MOD: IT_F3");
817 }
818
819 /*FALLTHRU*/ /* fall through */ /* fallthrough */
820 case IT_CI: // Character indirect (Td = 10)
821 /*FALLTHRU*/ /* fall through */ /* fallthrough */
822 case IT_SC: // Sequence character (Td = 12)
823 /*FALLTHRU*/ /* fall through */ /* fallthrough */
824 case IT_SCR: // Sequence character reverse (Td = 5)
825 {
826 // There is complexity with managing page faults and tracking
827 // the indirect word address and the operand address.
828 //
829 // To address this, we force those pages in during PREPARE_CA,
830 // so that they won't fault during operand read/write.
831
832 sim_debug (DBG_ADDRMOD, & cpu_dev,
833 "IT_MOD CI/SC/SCR reading indirect word from %06o\r\n",
834 cpu.TPR.CA);
835
836 //
837 // Get the indirect word
838 //
839
840 word36 indword;
841 word18 indaddr = cpu.TPR.CA;
842 ReadAPUDataRead (cpup, indaddr, & indword);
843 #if defined(LOCKLESS)
844 word24 phys_address = cpu.iefpFinalAddress;
845 #endif
846
847 sim_debug (DBG_ADDRMOD, & cpu_dev,
848 "IT_MOD CI/SC/SCR indword=%012"PRIo64"\r\n", indword);
849
850 //
851 // Parse and validate the indirect word
852 //
853
854 Yi = GET_ADDR (indword);
855 word6 sz = GET_TB (GET_TAG (indword));
856 word3 os = GET_CF (GET_TAG (indword));
857 word12 tally = GET_TALLY (indword);
858
859 sim_debug (DBG_ADDRMOD, & cpu_dev,
860 "IT_MOD CI/SC/SCR size=%o offset=%o Yi=%06o\r\n",
861 sz, os, Yi);
862
863 if (sz == TB6 && os > 5)
864 // generate an illegal procedure, illegal modifier fault
865 doFault (FAULT_IPR, fst_ill_mod,
866 "co size == TB6 && offset > 5");
867
868 if (sz == TB9 && os > 3)
869 // generate an illegal procedure, illegal modifier fault
870 doFault (FAULT_IPR, fst_ill_mod,
871 "co size == TB9 && offset > 3");
872
873 // Save data in OU registers for readOperands/writeOperands
874
875 cpu.TPR.CA = Yi;
876 cpu.ou.character_address = Yi;
877 cpu.ou.characterOperandSize = sz;
878 cpu.ou.characterOperandOffset = os;
879
880 // CI uses the address, and SC uses the pre-increment address;
881 // but SCR use the post-decrement address
882 if (Td == IT_SCR)
883 {
884 // For each reference to the indirect word, the character
885 // counter, cf, is reduced by 1 and the TALLY field is
886 // increased by 1 before the computed address is formed.
887 //
888 // Character count arithmetic is modulo 6 for 6-bit
889 // characters and modulo 4 for 9-bit bytes. If the
890 // character count, cf, underflows to -1, it is reset to 5
891 // for 6-bit characters or to 3 for 9-bit bytes and ADDRESS
892 // is reduced by 1. ADDRESS arithmetic is modulo 2^18.
893 // TALLY arithmetic is modulo 4096.
894 //
895 // If the TALLY field overflows to 0, the tally runout
896 // indicator is set ON, otherwise it is set OFF. The
897 // computed address is the (possibly) decremented value of
898 // the ADDRESS field of the indirect word. The effective
899 // character/byte number is the decremented value of the
900 // character position count, cf, field of the indirect
901 // word.
902
903 if (os == 0)
904 {
905 if (sz == TB6)
906 os = 5;
907 else
908 os = 3;
909 Yi -= 1;
910 Yi &= MASK18;
911 }
912 else
913 {
914 os -= 1;
915 }
916
917 CPT (cpt2L, 5); // Update IT Tally; SCR
918 tally ++;
919 tally &= 07777; // keep to 12-bits
920
921 // Update saved values
922
923 cpu.TPR.CA = Yi;
924 cpu.ou.character_address = Yi;
925 cpu.ou.characterOperandSize = sz;
926 cpu.ou.characterOperandOffset = os;
927 }
928
929 // What if readOperands and/of writeOperands fault? On restart, doCAF will be
930 // called again and the indirect word would incorrectly be updated a second
931 // time.
932 //
933 // We don't care about read/write access violations; in general, they are not
934 // restarted.
935 //
936 // We can avoid page faults by preemptively fetching the data word.
937
938 //
939 // Get the data word
940 //
941
942 cpu.cu.pot = 1;
943
944 #if defined(LOCKLESSXXX)
945 // gives warnings as another lock is acquired in between
946 Read (cpu.TPR.CA, & cpu.ou.character_data, (i->info->flags & RMW) == \
947 STORE_OPERAND ? OPERAND_RMW : OPERAND_READ);
948 #else
949 ReadOperandRead (cpup, cpu.TPR.CA, & cpu.ou.character_data);
950 #endif
951 #if defined(LOCKLESS)
952 cpu.char_word_address = cpu.iefpFinalAddress;
953 #endif
954
955 sim_debug (DBG_ADDRMOD, & cpu_dev,
956 "IT_MOD CI/SC/SCR data=%012"PRIo64"\r\n",
957 cpu.ou.character_data);
958
959 cpu.cu.pot = 0;
960
961 if (Td == IT_SC)
962 {
963 // For each reference to the indirect word, the character
964 // counter, cf, is increased by 1 and the TALLY field is
965 // reduced by 1 after the computed address is formed.
966 // Character count arithmetic is modulo 6 for 6-bit
967 // characters and modulo 4 for 9-bit bytes. If the
968 // character count, cf, overflows to 6 for 6-bit characters
969 // or to 4 for 9-bit bytes, it is reset to 0 and ADDRESS is
970 // increased by 1. ADDRESS arithmetic is modulo 2^18. TALLY
971 // arithmetic is modulo 4096. If the TALLY field is reduced
972 // to 0, the tally runout indicator is set ON, otherwise it
973 // is set OFF.
974
975 os ++;
976
977 if (((sz == TB6) && (os > 5)) ||
978 ((sz == TB9) && (os > 3)))
979 {
980 os = 0;
981 Yi += 1;
982 Yi &= MASK18;
983 }
984 CPT (cpt2L, 6); // Update IT Tally; SC
985 tally --;
986 tally &= 07777; // keep to 12-bits
987 }
988
989 if (Td == IT_SC || Td == IT_SCR)
990 {
991 sim_debug (DBG_ADDRMOD, & cpu_dev,
992 "update IT tally now %o\r\n", tally);
993
994 //word36 new_indword = (word36) (((word36) Yi << 18) |
995 // (((word36) tally & 07777) << 6) |
996 // cpu.ou.characterOperandSize |
997 // cpu.ou.characterOperandOffset);
998 //Write (cpu.TPR.CA, new_indword, APU_DATA_STORE);
999 #if defined(LOCKLESS)
1000 word36 indword_new;
1001 cache_read_lock(cpup, phys_address, &indword_new, __func__);
1002 if (indword_new != indword)
1003 sim_warn("indword changed from %llo to %llo\r\n",
1004 (long long unsigned int)indword,
1005 (long long unsigned int)indword_new);
1006 #endif
1007 putbits36_18 (& indword, 0, Yi);
1008 putbits36_12 (& indword, 18, tally);
1009 putbits36_3 (& indword, 33, os);
1010 #if defined(LOCKLESS)
1011 cache_write_unlock(cpup, phys_address, indword, __func__);
1012 #else
1013 WriteAPUDataStore (cpup, indaddr, indword);
1014 #endif
1015
1016 SC_I_TALLY (tally == 0);
1017
1018 sim_debug (DBG_ADDRMOD, & cpu_dev,
1019 "update IT wrote tally word %012"PRIo64
1020 " to %06o\r\n",
1021 indword, cpu.TPR.CA);
1022 }
1023
1024 // readOperand and writeOperand will not use cpu.TPR.CA; they
1025 // will use the saved address, size, offset and data.
1026 cpu.TPR.CA = cpu.ou.character_address;
1027 return;
1028 } // IT_CI, IT_SC, IT_SCR
1029
1030 case IT_I: // Indirect (Td = 11)
1031 {
1032 sim_debug (DBG_ADDRMOD, & cpu_dev,
1033 "IT_MOD(IT_I): reading indirect word from %06o\r\n",
1034 cpu.TPR.CA);
1035
1036 //Read2 (cpu.TPR.CA, cpu.itxPair, INDIRECT_WORD_FETCH);
1037 ReadIndirect (cpup);
1038
1039 sim_debug (DBG_ADDRMOD, & cpu_dev,
1040 "IT_MOD(IT_I): indword=%012"PRIo64"\r\n",
1041 cpu.itxPair[0]);
1042
1043 cpu.TPR.CA = GET_ADDR (cpu.itxPair[0]);
1044 updateIWB (cpup, cpu.TPR.CA, (TM_R|TD_N));
1045 return;
1046 } // IT_I
1047
1048 case IT_AD: ///< Add delta (Td = 13)
1049 {
1050 // The TAG field of the indirect word is interpreted as a
1051 // 6-bit, unsigned, positive address increment value, delta.
1052 // For each reference to the indirect word, the ADDRESS field
1053 // is increased by delta and the TALLY field is reduced by 1
1054 // after the computed address is formed. ADDRESS arithmetic is
1055 // modulo 2^18. TALLY arithmetic is modulo 4096. If the TALLY
1056 // field is reduced to 0, the tally runout indicator is set ON,
1057 // otherwise it is set OFF. The computed address is the value
1058 // of the unmodified ADDRESS field of the indirect word.
1059
1060 sim_debug (DBG_ADDRMOD, & cpu_dev,
1061 "IT_MOD(IT_AD): reading indirect word from %06o\r\n",
1062 cpu.TPR.CA);
1063
1064 #if defined(THREADZ)
1065 lock_rmw ();
1066 #endif
1067
1068 word18 saveCA = cpu.TPR.CA;
1069 word36 indword;
1070 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1071
1072 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1073 delta = GET_DELTA (indword); // 6-bits
1074 Yi = GETHI (indword); // from where data live
1075
1076 sim_debug (DBG_ADDRMOD, & cpu_dev,
1077 "IT_MOD(IT_AD): indword=%012"PRIo64"\r\n",
1078 indword);
1079 sim_debug (DBG_ADDRMOD, & cpu_dev,
1080 "IT_MOD(IT_AD): address:%06o tally:%04o "
1081 "delta:%03o\r\n",
1082 Yi, cpu.AM_tally, delta);
1083
1084 cpu.TPR.CA = Yi;
1085 word18 computedAddress = cpu.TPR.CA;
1086
1087 Yi += delta;
1088 Yi &= MASK18;
1089
1090 cpu.AM_tally -= 1;
1091 cpu.AM_tally &= 07777; // keep to 12-bits
1092 // breaks emacs
1093 //if (cpu.AM_tally == 0)
1094 //SET_I_TALLY;
1095 SC_I_TALLY (cpu.AM_tally == 0);
1096 indword = (word36) (((word36) Yi << 18) |
1097 (((word36) cpu.AM_tally & 07777) << 6) |
1098 delta);
1099 #if defined(LOCKLESS)
1100 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1101 #else
1102 WriteAPUDataStore (cpup, saveCA, indword);
1103 #endif
1104
1105 #if defined(THREADZ)
1106 unlock_rmw ();
1107 #endif
1108
1109 sim_debug (DBG_ADDRMOD, & cpu_dev,
1110 "IT_MOD(IT_AD): wrote tally word %012"PRIo64
1111 " to %06o\r\n",
1112 indword, saveCA);
1113
1114 cpu.TPR.CA = computedAddress;
1115 updateIWB (cpup, cpu.TPR.CA, (TM_R|TD_N));
1116 return;
1117 } // IT_AD
1118
1119 case IT_SD: ///< Subtract delta (Td = 4)
1120 {
1121 // The TAG field of the indirect word is interpreted as a
1122 // 6-bit, unsigned, positive address increment value, delta.
1123 // For each reference to the indirect word, the ADDRESS field
1124 // is reduced by delta and the TALLY field is increased by 1
1125 // before the computed address is formed. ADDRESS arithmetic is
1126 // modulo 2^18. TALLY arithmetic is modulo 4096. If the TALLY
1127 // field overflows to 0, the tally runout indicator is set ON,
1128 // otherwise it is set OFF. The computed address is the value
1129 // of the decremented ADDRESS field of the indirect word.
1130
1131 #if defined(THREADZ)
1132 lock_rmw ();
1133 #endif
1134
1135 word18 saveCA = cpu.TPR.CA;
1136 word36 indword;
1137 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1138
1139 sim_debug (DBG_ADDRMOD, & cpu_dev,
1140 "IT_MOD(IT_SD): reading indirect word from %06o\r\n",
1141 cpu.TPR.CA);
1142 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1143 delta = GET_DELTA (indword); // 6-bits
1144 Yi = GETHI (indword); // from where data live
1145
1146 sim_debug (DBG_ADDRMOD, & cpu_dev,
1147 "IT_MOD(IT_SD): indword=%012"PRIo64"\r\n",
1148 indword);
1149 sim_debug (DBG_ADDRMOD, & cpu_dev,
1150 "IT_MOD(IT_SD): address:%06o tally:%04o "
1151 "delta:%03o\r\n",
1152 Yi, cpu.AM_tally, delta);
1153
1154 Yi -= delta;
1155 Yi &= MASK18;
1156 cpu.TPR.CA = Yi;
1157
1158 cpu.AM_tally += 1;
1159 cpu.AM_tally &= 07777; // keep to 12-bits
1160 if (cpu.AM_tally == 0)
1161 SET_I_TALLY;
1162
1163 // write back out indword
1164 indword = (word36) (((word36) Yi << 18) |
1165 (((word36) cpu.AM_tally & 07777) << 6) |
1166 delta);
1167 #if defined(LOCKLESS)
1168 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1169 #else
1170 WriteAPUDataStore (cpup, saveCA, indword);
1171 #endif
1172
1173 #if defined(THREADZ)
1174 unlock_rmw ();
1175 #endif
1176
1177 sim_debug (DBG_ADDRMOD, & cpu_dev,
1178 "IT_MOD(IT_SD): wrote tally word %012"PRIo64
1179 " to %06o\r\n",
1180 indword, saveCA);
1181
1182 cpu.TPR.CA = Yi;
1183 updateIWB (cpup, cpu.TPR.CA, (TM_R|TD_N));
1184 return;
1185 } // IT_SD
1186
1187 case IT_DI: ///< Decrement address, increment tally (Td = 14)
1188 {
1189 // For each reference to the indirect word, the ADDRESS field
1190 // is reduced by 1 and the TALLY field is increased by 1 before
1191 // the computed address is formed. ADDRESS arithmetic is modulo
1192 // 2^18. TALLY arithmetic is modulo 4096. If the TALLY field
1193 // overflows to 0, the tally runout indicator is set ON,
1194 // otherwise it is set OFF. The TAG field of the indirect word
1195 // is ignored. The computed address is the value of the
1196 // decremented ADDRESS field.
1197
1198 sim_debug (DBG_ADDRMOD, & cpu_dev,
1199 "IT_MOD(IT_DI): reading indirect word from %06o\r\n",
1200 cpu.TPR.CA);
1201
1202 #if defined(THREADZ)
1203 lock_rmw ();
1204 #endif
1205
1206 word18 saveCA = cpu.TPR.CA;
1207 word36 indword;
1208 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1209
1210 Yi = GETHI (indword);
1211 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1212 word6 junk = GET_TAG (indword); // get tag field, but ignore it
1213
1214 sim_debug (DBG_ADDRMOD, & cpu_dev,
1215 "IT_MOD(IT_DI): indword=%012"PRIo64"\r\n",
1216 indword);
1217 sim_debug (DBG_ADDRMOD, & cpu_dev,
1218 "IT_MOD(IT_DI): address:%06o tally:%04o\r\n",
1219 Yi, cpu.AM_tally);
1220
1221 Yi -= 1;
1222 Yi &= MASK18;
1223 cpu.TPR.CA = Yi;
1224
1225 cpu.AM_tally += 1;
1226 cpu.AM_tally &= 07777; // keep to 12-bits
1227 SC_I_TALLY (cpu.AM_tally == 0);
1228
1229 // write back out indword
1230
1231 indword = (word36) (((word36) cpu.TPR.CA << 18) |
1232 ((word36) cpu.AM_tally << 6) |
1233 junk);
1234
1235 sim_debug (DBG_ADDRMOD, & cpu_dev,
1236 "IT_MOD(IT_DI): writing indword=%012"PRIo64" to "
1237 "addr %06o\r\n",
1238 indword, saveCA);
1239
1240 #if defined(LOCKLESS)
1241 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1242 #else
1243 WriteAPUDataStore (cpup, saveCA, indword);
1244 #endif
1245
1246 #if defined(THREADZ)
1247 unlock_rmw ();
1248 #endif
1249 cpu.TPR.CA = Yi;
1250 updateIWB (cpup, cpu.TPR.CA, (TM_R|TD_N));
1251 return;
1252 } // IT_DI
1253
1254 case IT_ID: ///< Increment address, decrement tally (Td = 16)
1255 {
1256 // For each reference to the indirect word, the ADDRESS field
1257 // is increased by 1 and the TALLY field is reduced by 1 after
1258 // the computed address is formed. ADDRESS arithmetic is modulo
1259 // 2^18. TALLY arithmetic is modulo 4096. If the TALLY field is
1260 // reduced to 0, the tally runout indicator is set ON,
1261 // otherwise it is set OFF. The TAG field of the indirect word
1262 // is ignored. The computed address is the value of the
1263 // unmodified ADDRESS field.
1264
1265 word18 saveCA = cpu.TPR.CA;
1266
1267 sim_debug (DBG_ADDRMOD, & cpu_dev,
1268 "IT_MOD(IT_ID): fetching indirect word from %06o\r\n",
1269 cpu.TPR.CA);
1270
1271 #if defined(THREADZ)
1272 lock_rmw ();
1273 #endif
1274
1275 word36 indword;
1276 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1277
1278 Yi = GETHI (indword);
1279 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1280 // get tag field, but ignore it
1281 word6 junk = GET_TAG (indword);
1282 sim_debug (DBG_ADDRMOD, & cpu_dev,
1283 "IT_MOD(IT_ID): indword=%012"PRIo64
1284 " Yi=%06o tally=%04o\r\n",
1285 indword, Yi, cpu.AM_tally);
1286
1287 cpu.TPR.CA = Yi;
1288 word18 computedAddress = cpu.TPR.CA;
1289
1290 Yi += 1;
1291 Yi &= MASK18;
1292
1293 cpu.AM_tally -= 1;
1294 cpu.AM_tally &= 07777; // keep to 12-bits
1295
1296 // XXX Breaks boot?
1297 //if (cpu.AM_tally == 0)
1298 //SET_I_TALLY;
1299 SC_I_TALLY (cpu.AM_tally == 0);
1300
1301 // write back out indword
1302 indword = (word36) (((word36) Yi << 18) |
1303 ((word36) cpu.AM_tally << 6) |
1304 junk);
1305
1306 sim_debug (DBG_ADDRMOD, & cpu_dev,
1307 "IT_MOD(IT_ID): writing indword=%012"PRIo64" to "
1308 "addr %06o\r\n",
1309 indword, saveCA);
1310
1311 #if defined(LOCKLESS)
1312 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1313 #else
1314 WriteAPUDataStore (cpup, saveCA, indword);
1315 #endif
1316
1317 #if defined(THREADZ)
1318 unlock_rmw ();
1319 #endif
1320
1321 cpu.TPR.CA = computedAddress;
1322 updateIWB (cpup, cpu.TPR.CA, (TM_R|TD_N));
1323 return;
1324 } // IT_ID
1325
1326 // Decrement address, increment tally, and continue (Td = 15)
1327 case IT_DIC:
1328 {
1329 // The action for this variation is identical to that for the
1330 // decrement address, increment tally variation except that the
1331 // TAG field of the indirect word is interpreted and
1332 // continuation of the indirect chain is possible. If the TAG
1333 // of the indirect word invokes a register, that is, specifies
1334 // r, ri, or ir modification, the effective Td value for the
1335 // register is forced to "null" before the next computed
1336 // address is formed.
1337
1338 // a:RJ78/idc1
1339 // The address and tally fields are used as described under the
1340 // ID variation. The tag field uses the set of variations for
1341 // instruction address modification under the following
1342 // restrictions: no variation is permitted that requires an
1343 // indexing modification in the DIC cycle since the indexing
1344 // adder is being used by the tally phase of the operation.
1345 // Thus, permissible variations are any allowable form of IT or
1346 // IR, but if RI or R is used, R must equal N (RI and R forced
1347 // to N).
1348
1349 sim_debug (DBG_ADDRMOD, & cpu_dev,
1350 "IT_MOD(IT_DIC): fetching indirect word from %06o\r\n",
1351 cpu.TPR.CA);
1352
1353 #if defined(THREADZ)
1354 lock_rmw ();
1355 #endif
1356
1357 word18 saveCA = cpu.TPR.CA;
1358 word36 indword;
1359 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1360
1361 cpu.cu.pot = 0;
1362
1363 Yi = GETHI (indword);
1364 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1365 idwtag = GET_TAG (indword);
1366
1367 sim_debug (DBG_ADDRMOD, & cpu_dev,
1368 "IT_MOD(IT_DIC): indword=%012"PRIo64" Yi=%06o "
1369 "tally=%04o idwtag=%02o\r\n",
1370 indword, Yi, cpu.AM_tally, idwtag);
1371
1372 word24 YiSafe2 = Yi; // save indirect address for later use
1373
1374 Yi -= 1;
1375 Yi &= MASK18;
1376
1377 cpu.AM_tally += 1;
1378 cpu.AM_tally &= 07777; // keep to 12-bits
1379 // Set the tally after the indirect word is processed; if it faults, the IR
1380 // should be unchanged. ISOLTS ps791 test-02g
1381 //SC_I_TALLY (cpu.AM_tally == 0);
1382 //if (cpu.AM_tally == 0)
1383 //SET_I_TALLY;
1384
1385 // write back out indword
1386 indword = (word36) (((word36) Yi << 18) |
1387 ((word36) cpu.AM_tally << 6) | idwtag);
1388
1389 sim_debug (DBG_ADDRMOD, & cpu_dev,
1390 "IT_MOD(IT_DIC): writing indword=%012"PRIo64" to "
1391 "addr %06o\r\n", indword, saveCA);
1392
1393 #if defined(LOCKLESS)
1394 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1395 #else
1396 WriteAPUDataStore (cpup, saveCA, indword);
1397 #endif
1398
1399 #if defined(THREADZ)
1400 unlock_rmw ();
1401 #endif
1402 // If the TAG of the indirect word invokes a register, that is,
1403 // specifies r, ri, or ir modification, the effective Td value
1404 // for the register is forced to "null" before the next
1405 // computed address is formed.
1406
1407 // Thus, permissible variations are any allowable form of IT or
1408 // IR, but if RI or R is used, R must equal N (RI and R forced
1409 // to N).
1410 cpu.TPR.CA = Yi;
1411
1412 sim_debug (DBG_ADDRMOD, & cpu_dev,
1413 "IT_MOD(IT_DIC): new CT_HOLD %02o new TAG %02o\r\n",
1414 cpu.rTAG, idwtag);
1415 cpu.cu.CT_HOLD = cpu.rTAG;
1416 cpu.rTAG = idwtag;
1417
1418 Tm = GET_TM (cpu.rTAG);
1419 if (Tm == TM_RI || Tm == TM_R)
1420 {
1421 if (GET_TD (cpu.rTAG) != 0)
1422 {
1423 doFault (FAULT_IPR, fst_ill_mod,
1424 "DIC Incorrect address modifier");
1425 }
1426 }
1427
1428 // Set the tally after the indirect word is processed; if it faults, the IR
1429 // should be unchanged. ISOLTS ps791 test-02g
1430 SC_I_TALLY (cpu.AM_tally == 0);
1431 if (cpu.tweaks.isolts_mode || cpu.tweaks.tandd_mode)
1432 updateIWB (cpup, YiSafe2, cpu.rTAG);
1433 else
1434 updateIWB (cpup, cpu.TPR.CA, cpu.rTAG);
1435 goto startCA;
1436 } // IT_DIC
1437
1438 // Increment address, decrement tally, and continue (Td = 17)
1439 case IT_IDC:
1440 {
1441 // The action for this variation is identical to that for the
1442 // increment address, decrement tally variation except that the
1443 // TAG field of the indirect word is interpreted and
1444 // continuation of the indirect chain is possible. If the TAG
1445 // of the indirect word invokes a register, that is, specifies
1446 // r, ri, or ir modification, the effective Td value for the
1447 // register is forced to "null" before the next computed
1448 // address is formed.
1449
1450 // a:RJ78/idc1
1451 // The address and tally fields are used as described under the
1452 // ID variation. The tag field uses the set of variations for
1453 // instruction address modification under the following
1454 // restrictions: no variation is permitted that requires an
1455 // indexing modification in the IDC cycle since the indexing
1456 // adder is being used by the tally phase of the operation.
1457 // Thus, permissible variations are any allowable form of IT or
1458 // IR, but if RI or R is used, R must equal N (RI and R forced
1459 // to N).
1460
1461 sim_debug (DBG_ADDRMOD, & cpu_dev,
1462 "IT_MOD(IT_IDC): fetching indirect word from %06o\r\n",
1463 cpu.TPR.CA);
1464
1465 #if defined(THREADZ)
1466 lock_rmw ();
1467 #endif
1468
1469 word18 saveCA = cpu.TPR.CA;
1470 word36 indword;
1471 ReadAPUDataRMW (cpup, cpu.TPR.CA, & indword);
1472
1473 cpu.cu.pot = 0;
1474
1475 Yi = GETHI (indword);
1476 cpu.AM_tally = GET_TALLY (indword); // 12-bits
1477 idwtag = GET_TAG (indword);
1478
1479 sim_debug (DBG_ADDRMOD, & cpu_dev,
1480 "IT_MOD(IT_IDC): indword=%012"PRIo64" Yi=%06o "
1481 "tally=%04o idwtag=%02o\r\n",
1482 indword, Yi, cpu.AM_tally, idwtag);
1483
1484 word24 YiSafe = Yi; // save indirect address for later use
1485
1486 Yi += 1;
1487 Yi &= MASK18;
1488
1489 cpu.AM_tally -= 1;
1490 cpu.AM_tally &= 07777; // keep to 12-bits
1491 // Set the tally after the indirect word is processed; if it faults, the IR
1492 // should be unchanged. ISOLTS ps791 test-02f
1493 //SC_I_TALLY (cpu.AM_tally == 0);
1494
1495 // write back out indword
1496 indword = (word36) (((word36) Yi << 18) |
1497 ((word36) cpu.AM_tally << 6) |
1498 idwtag);
1499
1500 sim_debug (DBG_ADDRMOD, & cpu_dev,
1501 "IT_MOD(IT_IDC): writing indword=%012"PRIo64""
1502 " to addr %06o\r\n",
1503 indword, saveCA);
1504
1505 #if defined(LOCKLESS)
1506 cache_write_unlock(cpup, cpu.iefpFinalAddress, indword, __func__);
1507 #else
1508 WriteAPUDataStore (cpup, saveCA, indword);
1509 #endif
1510
1511 #if defined(THREADZ)
1512 unlock_rmw ();
1513 #endif
1514
1515 // If the TAG of the indirect word invokes a register, that is,
1516 // specifies r, ri, or ir modification, the effective Td value
1517 // for the register is forced to "null" before the next
1518 // computed address is formed.
1519 // But for the dps88 you can use everything but ir/ri.
1520
1521 // Thus, permissible variations are any allowable form of IT or
1522 // IR, but if RI or R is used, R must equal N (RI and R forced
1523 // to N).
1524 cpu.TPR.CA = YiSafe;
1525
1526 sim_debug (DBG_ADDRMOD, & cpu_dev,
1527 "IT_MOD(IT_IDC): new CT_HOLD %02o new TAG %02o\r\n",
1528 cpu.rTAG, idwtag);
1529 cpu.cu.CT_HOLD = cpu.rTAG;
1530 cpu.rTAG = idwtag;
1531
1532 Tm = GET_TM (cpu.rTAG);
1533 if (Tm == TM_RI || Tm == TM_R)
1534 {
1535 if (GET_TD (cpu.rTAG) != 0)
1536 {
1537 doFault (FAULT_IPR, fst_ill_mod,
1538 "IDC Incorrect address modifier");
1539 }
1540 }
1541
1542 // Set the tally after the indirect word is processed; if it faults, the IR
1543 // should be unchanged. ISOLTS ps791 test-02f
1544 SC_I_TALLY (cpu.AM_tally == 0);
1545 updateIWB (cpup, cpu.TPR.CA, cpu.rTAG);
1546
1547 goto startCA;
1548 } // IT_IDC
1549 } // Td
1550 sim_printf ("IT_MOD/Td how did we get here?\r\n");
1551 return;
1552 } // IT_MOD
1553 } // do_caf
1554
1555 // Computed address formation; then, on a DPS/L68, the MR ADR TRAP (bit 17):
1556 // a computed address equal to the maintenance panel address switches
1557 // raises the fourth floating fault (xed FFV+6), taken as a group 7 fault
1558 // (PM701; the first match there is a TRA's address)
1559 void do_caf (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1560 {
1561 do_caf_ (cpup);
1562 L68_ (
1563 if (UNLIKELY (cpu.MR.emr && cpu.MR.ADR_TRAP &&
1564 cpu.TPR.CA == cpu.switches.addr_switches))
1565 {
1566 set_FFV_fault (cpup, 6);
1567 // with FAULT RESET (bit 31) the HR is locked once this
1568 // instruction is recorded, not at the deferred fault
1569 cpu.adr_trap_lock = true;
1570 }
1571 )
1572 }
1573
1574 // Without the ADR TRAP check, for the fast copy of executeInstruction:
1575 // (6), see FULL_MODEL_ON
1576 void do_caf_fast (cpu_state_t * cpup)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
1577 {
1578 do_caf_ (cpup);
1579 }