root/src/dps8/dps8_ins.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. elapsedtime
  2. writeOperands
  3. readOperands
  4. read_tra_op
  5. dump_words
  6. scu2words
  7. cu_safe_store
  8. tidy_cu
  9. words2scu
  10. cu_safe_restore
  11. du2words
  12. words2du
  13. initializeTheMatrix
  14. addToTheMatrix
  15. display_the_matrix
  16. fetchInstruction_
  17. fetchInstructionFast
  18. fetchInstructionFull
  19. traceInstruction
  20. chkOVF
  21. tstOVFfault
  22. executeInstruction_
  23. executeInstructionFast
  24. executeInstructionFull
  25. overflow
  26. doInstruction
  27. emCall
  28. scr_port_from_final_address
  29. doABSA
  30. doRCU

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * SPDX-License-Identifier: Multics
   5  * scspell-id: 7f512181-f62e-11ec-ad25-80ee73e9b8e7
   6  *
   7  * ---------------------------------------------------------------------------
   8  *
   9  * Copyright (c) 2007-2013 Michael Mondy
  10  * Copyright (c) 2012-2016 Harry Reed
  11  * Copyright (c) 2013-2016 Charles Anthony
  12  * Copyright (c) 2016 Michal Tomek
  13  * Copyright (c) 2021-2023 Jeffrey H. Johnson
  14  * Copyright (c) 2021-2025 The DPS8M Development Team
  15  *
  16  * This software is made available under the terms of the ICU License.
  17  * See the LICENSE.md file at the top-level directory of this distribution.
  18  *
  19  * ---------------------------------------------------------------------------
  20  *
  21  * This source file may contain code comments that adapt, include, and/or
  22  * incorporate Multics program code and/or documentation distributed under
  23  * the Multics License.  In the event of any discrepancy between code
  24  * comments herein and the original Multics materials, the original Multics
  25  * materials should be considered authoritative unless otherwise noted.
  26  * For more details and historical background, see the LICENSE.md file at
  27  * the top-level directory of this distribution.
  28  *
  29  * ---------------------------------------------------------------------------
  30  */
  31 
  32 #include <stdio.h>
  33 
  34 #include "dps8.h"
  35 #include "dps8_sys.h"
  36 #include "dps8_iom.h"
  37 #include "dps8_cable.h"
  38 #include "dps8_cpu.h"
  39 #include "dps8_addrmods.h"
  40 #include "dps8_faults.h"
  41 #include "dps8_scu.h"
  42 #include "dps8_append.h"
  43 #include "dps8_eis.h"
  44 #include "dps8_ins.h"
  45 #include "dps8_math.h"
  46 #include "dps8_opcodetable.h"
  47 #include "dps8_decimal.h"
  48 #include "dps8_iefp.h"
  49 #include "dps8_utils.h"
  50 #include "dps8_cache.h"
  51 
  52 #if defined(THREADZ) || defined(LOCKLESS)
  53 # include "threadz.h"
  54 #endif
  55 
  56 #include "ver.h"
  57 
  58 #define DBG_CTR cpu.cycleCnt
  59 
  60 // Forward declarations
  61 
  62 static int doABSA (cpu_state_t * cpup, word36 * result);
  63 static bool scr_port_from_final_address (cpu_state_t * cpup, uint * portp);
  64 HOT static t_stat doInstruction (cpu_state_t * cpup);
  65 static int emCall (cpu_state_t * cpup);
  66 
  67 #if BARREL_SHIFTER
  68 static word36 barrelLeftMaskTable[37] = {
  69               0000000000000ull,
  70               0400000000000ull, 0600000000000ull, 0700000000000ull,
  71               0740000000000ull, 0760000000000ull, 0770000000000ull,
  72               0774000000000ull, 0776000000000ull, 0777000000000ull,
  73               0777400000000ull, 0777600000000ull, 0777700000000ull,
  74               0777740000000ull, 0777760000000ull, 0777770000000ull,
  75               0777774000000ull, 0777776000000ull, 0777777000000ull,
  76               0777777400000ull, 0777777600000ull, 0777777700000ull,
  77               0777777740000ull, 0777777760000ull, 0777777770000ull,
  78               0777777774000ull, 0777777776000ull, 0777777777000ull,
  79               0777777777400ull, 0777777777600ull, 0777777777700ull,
  80               0777777777740ull, 0777777777760ull, 0777777777770ull,
  81               0777777777774ull, 0777777777776ull, 0777777777777ull
  82             };
  83 static word36 barrelRightMaskTable[37] = {
  84               0000000000000ull,
  85               0000000000001ull, 0000000000003ull, 0000000000007ull,
  86               0000000000017ull, 0000000000037ull, 0000000000077ull,
  87               0000000000177ull, 0000000000377ull, 0000000000777ull,
  88               0000000001777ull, 0000000003777ull, 0000000007777ull,
  89               0000000017777ull, 0000000037777ull, 0000000077777ull,
  90               0000000177777ull, 0000000377777ull, 0000000777777ull,
  91               0000001777777ull, 0000003777777ull, 0000007777777ull,
  92               0000017777777ull, 0000037777777ull, 0000077777777ull,
  93               0000177777777ull, 0000377777777ull, 0000777777777ull,
  94               0001777777777ull, 0003777777777ull, 0007777777777ull,
  95               0017777777777ull, 0037777777777ull, 0077777777777ull,
  96               0177777777777ull, 0377777777777ull, 0777777777777ull,
  97             };
  98 # define BS_COMPL(HI) ((~(HI)) & MASK36)
  99 #endif // BARREL_SHIFTER
 100 
 101 #if defined(LOOPTRC)
 102 void elapsedtime (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 103   {
 104     static bool init = false;
 105     static struct timespec t0;
 106     struct timespec now, delta;
 107 
 108     if (! init)
 109       {
 110         init = true;
 111         clock_gettime (CLOCK_REALTIME, & t0);
 112       }
 113     clock_gettime (CLOCK_REALTIME, & now);
 114     timespec_diff (& t0, & now, & delta);
 115     sim_printf ("%5ld.%03ld", delta.tv_sec, delta.tv_nsec/1000000);
 116   }
 117 #endif
 118 
 119 // CANFAULT
 120 static void writeOperands (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 121 {
 122     char buf [256];
 123     CPT (cpt2U, 0); // write operands
 124     DCDstruct * i = & cpu.currentInstruction;
 125 
 126     sim_debug (DBG_ADDRMOD, & cpu_dev,
 127                "%s (%s):mne=%s flags=%x\r\n",
 128                __func__, disassemble (buf, IWB_IRODD), i->info->mne, i->info->flags);
 129 
 130     PNL (cpu.prepare_state |= ps_RAW);
 131 
 132     word6 rTAG = 0;
 133     if (! (i->info->flags & NO_TAG))
 134       rTAG = GET_TAG (cpu.cu.IWB);
 135     word6 Td = GET_TD (rTAG);
 136     word6 Tm = GET_TM (rTAG);
 137 
 138 //
 139 // IT CI/SC/SCR
 140 //
 141 
 142     if (Tm == TM_IT && (Td == IT_CI || Td == IT_SC || Td == IT_SCR))
 143       {
 144         //
 145         // Put the character into the data word
 146         //
 147 
 148 #if defined(LOCKLESS)
 149         word36 tmpdata;
 150         cache_read(cpup, cpu.char_word_address, &tmpdata, __func__);
 151         if (tmpdata != cpu.ou.character_data)
 152           sim_warn("write char: data changed from %llo to %llo at %o\r\n",
 153                   (long long unsigned int)cpu.ou.character_data,
 154                   (long long unsigned int)tmpdata, cpu.char_word_address);
 155 #endif
 156 
 157         switch (cpu.ou.characterOperandSize)
 158           {
 159             case TB6:
 160               putChar (& cpu.ou.character_data, cpu.CY & 077, cpu.ou.characterOperandOffset);
 161               break;
 162 
 163             case TB9:
 164               putByte (& cpu.ou.character_data, cpu.CY & 0777, cpu.ou.characterOperandOffset);
 165               break;
 166           }
 167 
 168         //
 169         // Write it
 170         //
 171 
 172         PNL (cpu.prepare_state |= ps_SAW);
 173 
 174 #if defined(LOCKLESSXXX)
 175         // gives warnings as another lock is acquired in between
 176         cache_write_unlock (cpup, cpu.char_word_address, cpu.ou.character_data, __func__);
 177 #else
 178         WriteOperandStore (cpup, cpu.ou.character_address, cpu.ou.character_data);
 179 #endif
 180 
 181         sim_debug (DBG_ADDRMOD, & cpu_dev,
 182                    "%s IT wrote char/byte %012"PRIo64" to %06o "
 183                    "tTB=%o tCF=%o\r\n",
 184                    __func__, cpu.ou.character_data, cpu.ou.character_address,
 185                    cpu.ou.characterOperandSize, cpu.ou.characterOperandOffset);
 186 
 187         // Restore the CA; Read/Write() updates it.
 188         //cpu.TPR.CA = indwordAddress;
 189         cpu.TPR.CA = cpu.ou.character_address;
 190         return;
 191       } // IT
 192 
 193     write_operand (cpup, cpu.TPR.CA, OPERAND_STORE);
 194 
 195     return;
 196 }
 197 
 198 // CANFAULT
 199 // (inline: a hint, for the two copies of executeInstruction)
 200 static inline void readOperands (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 {
 202     char buf [256];
 203     CPT (cpt2U, 3); // read operands
 204     DCDstruct * i = & cpu.currentInstruction;
 205 
 206     sim_debug (DBG_ADDRMOD, &cpu_dev,
 207                "%s (%s):mne=%s flags=%x\r\n",
 208                __func__, disassemble (buf, IWB_IRODD), i->info->mne, i->info->flags);
 209     sim_debug (DBG_ADDRMOD, &cpu_dev,
 210               "%s a %d address %08o\r\n", __func__, i->b29, cpu.TPR.CA);
 211 
 212     PNL (cpu.prepare_state |= ps_POA);
 213 
 214     word6 rTAG = 0;
 215     if (! (i->info->flags & NO_TAG))
 216       rTAG = GET_TAG (cpu.cu.IWB);
 217     word6 Td = GET_TD (rTAG);
 218     word6 Tm = GET_TM (rTAG);
 219 
 220 //
 221 // DU
 222 //
 223 
 224     if (Tm == TM_R && Td == TD_DU)
 225       {
 226         cpu.CY = 0;
 227         SETHI (cpu.CY, cpu.TPR.CA);
 228         sim_debug (DBG_ADDRMOD, & cpu_dev,
 229                    "%s DU CY=%012"PRIo64"\r\n", __func__, cpu.CY);
 230         return;
 231       }
 232 
 233 //
 234 // DL
 235 //
 236 
 237     if (Tm == TM_R && Td == TD_DL)
 238       {
 239         cpu.CY = 0;
 240         SETLO (cpu.CY, cpu.TPR.CA);
 241         sim_debug (DBG_ADDRMOD, & cpu_dev,
 242                    "%s DL CY=%012"PRIo64"\r\n", __func__, cpu.CY);
 243         return;
 244       }
 245 
 246 //
 247 // IT CI/SC/SCR
 248 //
 249 
 250     if (Tm == TM_IT && (Td == IT_CI || Td == IT_SC || Td == IT_SCR))
 251       {
 252         //
 253         // Get the character from the data word
 254         //
 255 
 256         switch (cpu.ou.characterOperandSize)
 257           {
 258             case TB6:
 259               cpu.CY = GETCHAR (cpu.ou.character_data, cpu.ou.characterOperandOffset);
 260               break;
 261 
 262             case TB9:
 263               cpu.CY = GETBYTE (cpu.ou.character_data, cpu.ou.characterOperandOffset);
 264               break;
 265           }
 266 
 267         sim_debug (DBG_ADDRMOD, & cpu_dev,
 268                    "%s IT read operand %012"PRIo64" from"
 269                    " %06o char/byte=%"PRIo64"\r\n",
 270                    __func__, cpu.ou.character_data, cpu.ou.character_address, cpu.CY);
 271 
 272         // Restore the CA; Read/Write() updates it.
 273         cpu.TPR.CA = cpu.ou.character_address;
 274         return;
 275       } // IT
 276 
 277 #if defined(LOCKLESS)
 278     if ((i->info->flags & RMW) == RMW)
 279       readOperandRMW (cpup, cpu.TPR.CA);
 280     else
 281       readOperandRead (cpup, cpu.TPR.CA);
 282 #else
 283     readOperandRead (cpup, cpu.TPR.CA);
 284 #endif
 285 
 286     return;
 287   }
 288 
 289 static void read_tra_op (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 290   {
 291     // This read is the transfer's instruction fetch: for the cache it is
 292     // an instruction fetch (cached only with INST ON; PM893 02C)
 293     cpu.cacheFetch = true;
 294     if (cpu.TPR.CA & 1)
 295       ReadOperandRead (cpup, cpu.TPR.CA, &cpu.CY);
 296     else
 297       Read2OperandRead (cpup, cpu.TPR.CA, cpu.Ypair);
 298     // L68: the read of the target pair is the transfer's instruction
 299     // fetch cycle (PM701 02C)
 300     if (cpu.tweaks.l68_mode)
 301       {
 302         cpu.l68PairAddr  = cpu.iefpFinalAddress & ~1u;
 303         cpu.l68PairValid = true;
 304         add_l68_CU_fetch_history (cpup);
 305       }
 306     if (! (get_addr_mode (cpup) == APPEND_mode || cpu.cu.TSN_VALID [0] ||
 307            cpu.cu.XSF || cpu.currentInstruction.b29 /*get_went_appending ()*/))
 308       {
 309         if (cpu.currentInstruction.info->flags & TSPN_INS)
 310           {
 311             word3 n;
 312             if (cpu.currentInstruction.opcode <= 0273)  //-V536
 313               n = (cpu.currentInstruction.opcode & 3);
 314             else
 315               n = (cpu.currentInstruction.opcode & 3) + 4;
 316 
 317             // C(PPR.PRR) -> C(PRn.RNR)
 318             // C(PPR.PSR) -> C(PRn.SNR)
 319             // C(PPR.IC)  -> C(PRn.WORDNO)
 320             // 000000     -> C(PRn.BITNO)
 321             cpu.PR[n].RNR = cpu.PPR.PRR;
 322 // According the AL39, the PSR is 'undefined' in absolute mode.
 323 // ISOLTS thinks it means "don't change the operand"
 324             if (get_addr_mode (cpup) == APPEND_mode)
 325               cpu.PR[n].SNR = cpu.PPR.PSR;
 326             cpu.PR[n].WORDNO = (cpu.PPR.IC + 1) & MASK18;
 327             SET_PR_BITNO (n, 0);
 328 #if defined(TESTING)
 329             HDBGRegPRW (n, "read_tra_op tsp");
 330 #endif
 331           }
 332         cpu.PPR.IC = cpu.TPR.CA;
 333         // ISOLTS 870-02f
 334         //cpu.PPR.PSR = 0;
 335       }
 336     sim_debug (DBG_TRACE, & cpu_dev, "%s %05o:%06o\r\n",
 337                __func__, cpu.PPR.PSR, cpu.PPR.IC);
 338     if (cpu.PPR.IC & 1)
 339       {
 340         cpu.cu.IWB   = cpu.CY;
 341         cpu.cu.IRODD = cpu.CY;
 342       }
 343     else
 344       {
 345         cpu.cu.IWB   = cpu.Ypair[0];
 346         cpu.cu.IRODD = cpu.Ypair[1];
 347       }
 348   }
 349 
 350 static void dump_words (cpu_state_t * cpup, word36 * words)
     /* [previous][next][first][last][top][bottom][index][help] */
 351   {
 352     sim_debug (DBG_FAULT, & cpu_dev,
 353                "CU: P %d IR %#o PSR %0#o IC %0#o TSR %0#o\r\n",
 354                getbits36_1  (words[0], 18), getbits36_18 (words[4], 18),
 355                getbits36_15 (words[0], 3), getbits36_18 (words[4], 0),  getbits36_15 (words[2], 3));
 356     sim_debug (DBG_FAULT, & cpu_dev,
 357                "CU: xsf %d rf %d rpt %d rd %d rl %d pot %d xde %d xdo %d itp %d rfi %d its %d fif %d hold %0#o\r\n",
 358                getbits36_1  (words[0], 19),
 359                getbits36_1  (words[5], 18), getbits36_1  (words[5], 19), getbits36_1  (words[5], 20), getbits36_1  (words[5], 21),
 360                getbits36_1  (words[5], 22), getbits36_1  (words[5], 24), getbits36_1  (words[5], 25), getbits36_1  (words[5], 26),
 361                getbits36_1  (words[5], 27), getbits36_1  (words[5], 28), getbits36_1  (words[5], 29), getbits36_6  (words[5], 30));
 362     sim_debug (DBG_FAULT, & cpu_dev,
 363                "CU: iwb %012"PRIo64" irodd %012"PRIo64"\r\n",
 364                words[6], words[7]);
 365   }
 366 
 367 static void scu2words (cpu_state_t * cpup, word36 *words)
     /* [previous][next][first][last][top][bottom][index][help] */
 368   {
 369     CPT (cpt2U, 6); // scu2words
 370     (void)memset (words, 0, 8 * sizeof (* words));
 371 
 372     // words[0]
 373 
 374     putbits36_3 (& words[0],  0,  cpu.PPR.PRR);
 375     putbits36_15 (& words[0], 3,  cpu.PPR.PSR);
 376     putbits36_1 (& words[0], 18,  cpu.PPR.P);
 377     // XSF, external segment flag: set by an append cycle that loaded
 378     // TPR.TSR (indirect word, ITS/ITP, bit 29, rtcd), not by a plain
 379     // operand access or the instruction fetch; cu.XSF means "went
 380     // appending" in dps8m (PA885 10B, 01A; PA870 01A). Fetch faults keep
 381     // cu.XSF, and so does absolute mode, where XSF is what keeps appending
 382     // (RCU restores it; PA878 01A). xsfScu is kept only by the full copy
 383     // of the instruction loop and append cycles: (1), see FULL_MODEL_ON.
 384     putbits36_1 (& words[0], 19,  (cpu.cu.FIF || TST_I_ABS || ! cpu.fullCopy) ?
 385                                    cpu.cu.XSF : cpu.xsfScu);
 386     putbits36_1 (& words[0], 20,  cpu.cu.SDWAMM); // Match on SDWAM (PA866 02B)
 387     putbits36_1 (& words[0], 21,  cpu.cu.SD_ON);
 388     putbits36_1 (& words[0], 22,  cpu.cu.PTWAMM); // Match on PTWAM
 389     putbits36_1 (& words[0], 23,  cpu.cu.PT_ON);
 390 
 391 
 392 
 393 
 394 
 395 
 396 
 397 
 398 
 399 
 400 
 401     // XXX Only the top 9 bits are used in APUCycleBits, so this is
 402     // zeroing the 3 FTC bits at the end of the word; on the
 403     // other hand this keeps the values in apuStatusBits clearer.
 404     // If FTC is ever used, be sure to put its save code after this
 405     // line.
 406     putbits36_12 (& words[0], 24, cpu.cu.APUCycleBits);
 407 
 408 
 409     // words[1]
 410 
 411     putbits36_1 (& words[1],  0, cpu.cu.IRO_ISN);
 412     putbits36_1 (& words[1],  1, cpu.cu.OEB_IOC);
 413     putbits36_1 (& words[1],  2, cpu.cu.EOFF_IAIM);
 414     putbits36_1 (& words[1],  3, cpu.cu.ORB_ISP);
 415     putbits36_1 (& words[1],  4, cpu.cu.ROFF_IPR);
 416     putbits36_1 (& words[1],  5, cpu.cu.OWB_NEA);
 417     putbits36_1 (& words[1],  6, cpu.cu.WOFF_OOB);
 418     putbits36_1 (& words[1],  7, cpu.cu.NO_GA);
 419     putbits36_1 (& words[1],  8, cpu.cu.OCB);
 420     putbits36_1 (& words[1],  9, cpu.cu.OCALL);
 421     putbits36_1 (& words[1], 10, cpu.cu.BOC);
 422     putbits36_1 (& words[1], 11, cpu.cu.PTWAM_ER);
 423     putbits36_1 (& words[1], 12, cpu.cu.CRT);
 424     putbits36_1 (& words[1], 13, cpu.cu.RALR);
 425     putbits36_1 (& words[1], 14, cpu.cu.SDWAM_ER);
 426     putbits36_1 (& words[1], 15, cpu.cu.OOSB);
 427     putbits36_1 (& words[1], 16, cpu.cu.PARU);
 428     putbits36_1 (& words[1], 17, cpu.cu.PARL);
 429     putbits36_1 (& words[1], 18, cpu.cu.ONC1);
 430     putbits36_1 (& words[1], 19, cpu.cu.ONC2);
 431     putbits36_4 (& words[1], 20, cpu.cu.IA);
 432     putbits36_3 (& words[1], 24, cpu.cu.IACHN);
 433     putbits36_3 (& words[1], 27, cpu.cu.CNCHN);
 434     putbits36_5 (& words[1], 30, cpu.cu.FI_ADDR);
 435     putbits36_1 (& words[1], 35, cpu.cycle == INTERRUPT_cycle ? 0 : 1);
 436 
 437     // words[2]
 438 
 439     putbits36_3 (& words[2],  0, cpu.TPR.TRR);
 440     putbits36_15 (& words[2], 3, cpu.TPR.TSR);
 441     // 18, 4 PTWAM levels enabled
 442     // 22, 4 SDWAM levels enabled
 443     // 26, 1 0
 444     putbits36_3 (& words[2], 27, (word3) cpu.switches.cpu_num);
 445     putbits36_6 (& words[2], 30, cpu.cu.delta);
 446 
 447     // words[3]
 448 
 449     putbits36_3 (& words[3], 18, cpu.cu.TSN_VALID[0] ? cpu.cu.TSN_PRNO[0] : 0);
 450     putbits36_1 (& words[3], 21, cpu.cu.TSN_VALID[0]);
 451     putbits36_3 (& words[3], 22, cpu.cu.TSN_VALID[1] ? cpu.cu.TSN_PRNO[1] : 0);
 452     putbits36_1 (& words[3], 25, cpu.cu.TSN_VALID[1]);
 453     putbits36_3 (& words[3], 26, cpu.cu.TSN_VALID[2] ? cpu.cu.TSN_PRNO[2] : 0);
 454     putbits36_1 (& words[3], 29, cpu.cu.TSN_VALID[2]);
 455     putbits36_6 (& words[3], 30, cpu.TPR.TBR);
 456 
 457     // words[4]
 458 
 459     putbits36_18 (& words[4],  0, cpu.PPR.IC);
 460 
 461 // According the AL39, the Hex Mode bit should be 0, but ISOLTS pas2 exec checks it;
 462 //  this code does not set it to zero and indicated by AL39.
 463 
 464     putbits36_18 (& words[4], 18, cpu.cu.IR);
 465 
 466     // ISOLTS 887 test-03a
 467     // Adding this makes test03 hang instead of erroring;
 468     // presumably it's stuck on some later test.
 469     // An 'Add Delta' addressing mode will alter the TALLY bit;
 470     // restore it.
 471 
 472     // Breaks ISOLTS 768
 473     //putbits36_1 (& words[4], 25, cpu.currentInstruction.stiTally);
 474 
 475 //#if defined(ISOLTS)
 476 //testing for ipr fault by attempting execution of
 477 //the illegal opcode  000   and bit 27 not set
 478 //in privileged-append-bar mode.
 479 //
 480 //expects ABS to be clear....
 481 //
 482 //testing for ipr fault by attempting execution of
 483 //the illegal opcode  000   and bit 27 not set
 484 //in absolute-bar mode.
 485 //
 486 //expects ABS to be set
 487 
 488 //if (cpu.PPR.P && TST_I_NBAR == 0) fails 101007 absolute-bar mode; s/b set
 489 //if (cpu.PPR.P == 0 && TST_I_NBAR == 0)
 490 //if (TST_I_NBAR == 0 && TST_I_ABS == 1) // If ABS BAR
 491 //{
 492   //putbits36 (& words[4], 31, 1, 0);
 493 //  putbits36 (& words[4], 31, 1, cpu.PPR.P ? 0 : 1);
 494 //if (current_running_cpu_idx)
 495 //sim_printf ("cleared ABS\r\n");
 496 //}
 497 //#endif
 498 
 499     // words[5]
 500 
 501     putbits36 (& words[5],  0, 18, cpu.TPR.CA);
 502     putbits36 (& words[5], 18,  1, cpu.cu.repeat_first);
 503     putbits36 (& words[5], 19,  1, cpu.cu.rpt);
 504     putbits36 (& words[5], 20,  1, cpu.cu.rd);
 505     putbits36 (& words[5], 21,  1, cpu.cu.rl);
 506     putbits36 (& words[5], 22,  1, cpu.cu.pot);
 507     // 23, 1 PON Prepare operand no tally
 508     putbits36_1 (& words[5], 24, cpu.cu.xde);
 509     // While the even instruction of an xed pair executes, xdo is on
 510     // internally; the SCU data has XDO only if the xed itself is at an
 511     // odd address (PA885 05C: XDE; 05D: XDE+XDO)
 512     putbits36_1 (& words[5], 25, cpu.cu.xdo && (! cpu.cu.xde || (cpu.PPR.IC & 1)));
 513     putbits36_1 (& words[5], 26, cpu.cu.itp);
 514     putbits36_1 (& words[5], 27, cpu.cu.rfi);
 515     putbits36_1 (& words[5], 28, cpu.cu.its);
 516     putbits36_1 (& words[5], 29, cpu.cu.FIF);
 517     // In a repeat, CT-HOLD shows the tag of the last instruction completed
 518     // (first time through, the rpx's own tag) (PA885 06B-06D); lastTag is
 519     // kept only by the full copy of the instruction loop: (2), see
 520     // FULL_MODEL_ON
 521     if ((cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl) && ! cpu.cu.CT_HOLD &&
 522         cpu.fullCopy)
 523       putbits36_6 (& words[5], 30, cpu.lastTag);
 524     else
 525       putbits36_6 (& words[5], 30, cpu.cu.CT_HOLD);
 526 
 527     // words[6]
 528 
 529     words[6] = cpu.cu.IWB;
 530 
 531     // words[7]
 532 
 533     words[7] = cpu.cu.IRODD;
 534 //sim_printf ("scu2words %lld %012llo\r\n", cpu.cycleCnt, words [6]);
 535 
 536     if_sim_debug (DBG_FAULT, & cpu_dev)
 537         dump_words (cpup, words);
 538 
 539     if (cpu.tweaks.isolts_mode)
 540       {
 541         struct
 542         {
 543           word36 should_be[8];
 544           word36 was[8];
 545           char *name;
 546         }
 547         rewrite_table[] =
 548           {
 549             { { 0000001400021, 0000000000011, 0000001000100, 0000000000000,
 550                 0000016400000, 0110015000500, 0110015011000, 0110015011000 },
 551               { 0000001400011, 0000000000011, 0000001000100, 0000000000000,
 552                 0000016400000, 0110015000100, 0110015011000, 0110015011000 },
 553               "pa865 test-03a inhibit", //                                                          rfi
 554             },
 555             { { 0000000401001, 0000000000041, 0000001000100, 0000000000000,
 556                 0101175000220, 0000006000000, 0100006235100, 0100006235100 },
 557               { 0000000601001, 0000000000041, 0000001000100, 0000000000000,
 558                 0101175000220, 0000006000000, 0100006235100, 0100006235100 },
 559               "pa870 test-01a dir. fault",
 560             },
 561             { { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 562                 0000000200200, 0000003000000, 0200003716100, 0000005755000 },
 563               { 0000000651001, 0000000000041, 0000001000100, 0000000000000,
 564                 0000000200200, 0000003000000, 0200003716100, 0000005755000 },
 565               "pa885 test-05a xec inst",
 566             },
 567             { { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 568                 0000000200200, 0000002000000, 0200002717100, 0110002001000 },
 569               { 0000000651001, 0000000000041, 0000001000100, 0000000000000,
 570                 0000000200200, 0000002000000, 0200002717100, 0110002001000 },
 571               "pa885 test-05b xed inst",
 572             },
 573             { { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 574                 0000000200200, 0000004004000, 0200004235100, 0000005755000 },
 575               { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 576                 0000000200200, 0000004002000, 0200004235100, 0000005755000 },
 577               "pa885 test-05c xed inst", //                                                         xde/xdo
 578             },
 579             { { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 580                 0000001200200, 0000004006000, 0200004235100, 0000005755000 },
 581               { 0000000451001, 0000000000041, 0000001000100, 0000000000000,
 582                 0000001200200, 0000004002000, 0200004235100, 0000005755000 },
 583               "pa885 test-05d xed inst", //                                                         xde/xdo
 584             },
 585             { { 0000000454201, 0000000000041, 0000000000100, 0000000000000,
 586                 0001777200200, 0002000000500, 0005600560201, 0005600560201 },
 587               { 0000000450201, 0000000000041, 0000000000100, 0000000000000,
 588                 0001777200200, 0002000000000, 0005600560201, 0005600560201 },
 589               "pa885 test-06a rpd inst", //                                                         rfi/fif
 590             },
 591             { { 0000000451001, 0000000000041, 0000001000101, 0000000000000,
 592                 0002000200200, 0000003500001, 0200003235111, 0002005755012 },
 593               { 0000000651001, 0000000000041, 0000001000101, 0000000000000,
 594                 0002000202200, 0000003500000, 0200003235111, 0002005755012 },
 595               "pa885 test-06b rpd inst", //                                       tro               ct-hold
 596             },
 597             { { 0000000450201, 0000000000041, 0000000000101, 0000000000000,
 598                 0001776200200, 0002015500001, 0002015235031, 0002017755032 },
 599               { 0000000450201, 0000000000041, 0000000000101, 0000000000000,
 600                 0001776202200, 0002015500000, 0002015235031, 0002017755032 },
 601               "pa885 test-06c rpd inst", //                                       tro               ct-hold
 602             },
 603             { { 0000000450201, 0000000000041, 0000000000101, 0000000000000,
 604                 0001776000200, 0002000100012, 0001775235011, 0001775755012 },
 605               { 0000000450201, 0000000000041, 0000000000101, 0000000000000,
 606                 0001776000200, 0002000100000, 0001775235011, 0001775755012 },
 607               "pa885 test-06d rpd inst", //                                                         ct-hold
 608             },
 609             { { 0000000404202, 0000000000041, 0000000000100, 0000000000000,
 610                 0002000202200, 0002000000500, 0001773755000, 0001773755000 },
 611               { 0000000400202, 0000000000041, 0000000000100, 0000000000000,
 612                 0002000202200, 0002000000100, 0001773755000, 0001773755000 },
 613               "pa885 test-10a scu snap (acv fault)", //                                             rfi
 614             }
 615           };
 616         int i;
 617         for (i=0; i < 11; i++)
 618           {
 619             if (memcmp (words, rewrite_table[i].was, 8*sizeof (word36)) == 0)
 620               {
 621                 memcpy (words, rewrite_table[i].should_be, 8*sizeof (word36));
 622                 sim_warn("%s: scu rewrite %d: %s\r\n", __func__, i, rewrite_table[i].name);
 623                 break;
 624               }
 625           }
 626       }
 627   }
 628 
 629 void cu_safe_store (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 630 {
 631     // Save current Control Unit Data in hidden temporary so a later SCU
 632     // instruction running in FAULT mode can save the state as it existed at
 633     // the time of the fault rather than as it exists at the time the SCU
 634     //  instruction is executed.
 635     scu2words (cpup, cpu.scu_data);
 636 
 637     cpu.cu_data.PSR = cpu.PPR.PSR;
 638     cpu.cu_data.PRR = cpu.PPR.PRR;
 639     cpu.cu_data.IC  = cpu.PPR.IC;
 640 
 641     tidy_cu (cpup);
 642 }
 643 
 644 void tidy_cu (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 645   {
 646 // The only places this is called is in fault and interrupt processing;
 647 // once the CU is saved, it needs to be set to a usable state. Refactoring
 648 // that code here so that there is only a single copy to maintain.
 649 
 650     cpu.cu.delta        = 0;
 651     cpu.cu.repeat_first = false;
 652     cpu.cu.rpt          = false;
 653     cpu.cu.rd           = false;
 654     cpu.cu.rl           = false;
 655     cpu.cu.pot          = false;
 656     cpu.cu.itp          = false;
 657     cpu.cu.its          = false;
 658     cpu.cu.xde          = false;
 659     cpu.cu.xdo          = false;
 660   }
 661 
 662 static void words2scu (cpu_state_t * cpup, word36 * words)
     /* [previous][next][first][last][top][bottom][index][help] */
 663 {
 664     CPT (cpt2U, 7); // words2scu
 665     // BUG:  We don't track much of the data that should be tracked
 666 
 667     // words[0]
 668 
 669     cpu.PPR.PRR           = getbits36_3  (words[0], 0);
 670     cpu.PPR.PSR           = getbits36_15 (words[0], 3);
 671     cpu.PPR.P             = getbits36_1  (words[0], 18);
 672     cpu.cu.XSF            = getbits36_1  (words[0], 19);
 673 sim_debug (DBG_TRACEEXT, & cpu_dev, "%s sets XSF to %o\r\n", __func__, cpu.cu.XSF);
 674     //cpu.cu.SDWAMM       = getbits36_1  (words[0], 20);
 675     //cpu.cu.SD_ON        = getbits36_1  (words[0], 21);
 676     //cpu.cu.PTWAMM       = getbits36_1  (words[0], 22);
 677     //cpu.cu.PT_ON        = getbits36_1  (words[0], 23);
 678 
 679 
 680 
 681 
 682 
 683 
 684 
 685 
 686 
 687 
 688 
 689     //cpu.cu.APUCycleBits = getbits36_12 (words[0], 24);
 690 
 691     // The FCT is stored in APUCycleBits
 692     cpu.cu.APUCycleBits = (word12) ((cpu.cu.APUCycleBits & 07770) | (word12) getbits36_3 (words[0], 33));
 693 
 694     // words[1]
 695 
 696 
 697 
 698 
 699 
 700 
 701 
 702 
 703 
 704 
 705 
 706 
 707 
 708 
 709 
 710 
 711 
 712 
 713 
 714 
 715 
 716 
 717 
 718 
 719 
 720 
 721 
 722 
 723 
 724     // words[2]
 725 
 726     cpu.TPR.TRR         = getbits36_3  (words[2], 0);
 727     cpu.TPR.TSR         = getbits36_15 (words[2], 3);
 728     // 18-21 PTW
 729     // 22-25 SDW
 730     // 26 0
 731     // 27-29 CPU number
 732     cpu.cu.delta        = getbits36_6  (words[2], 30);
 733 
 734     // words[3]
 735 
 736     // 0-17 0
 737 
 738     cpu.cu.TSN_PRNO[0]  = getbits36_3  (words[3], 18);
 739     cpu.cu.TSN_VALID[0] = getbits36_1  (words[3], 21);
 740     cpu.cu.TSN_PRNO[1]  = getbits36_3  (words[3], 22);
 741     cpu.cu.TSN_VALID[1] = getbits36_1  (words[3], 25);
 742     cpu.cu.TSN_PRNO[2]  = getbits36_3  (words[3], 26);
 743     cpu.cu.TSN_VALID[2] = getbits36_1  (words[3], 29);
 744     cpu.TPR.TBR         = getbits36_6  (words[3], 30);
 745 
 746     // words[4]
 747 
 748     cpu.cu.IR           = getbits36_18 (words[4], 18); // HWR
 749     cpu.PPR.IC          = getbits36_18 (words[4], 0);
 750 
 751     // words[5]
 752 
 753 // AL39 pg 75, RCU does not restore CA
 754     //cpu.TPR.CA          = getbits36_18 (words[5], 0);
 755     cpu.cu.repeat_first = getbits36_1  (words[5], 18);
 756     cpu.cu.rpt          = getbits36_1  (words[5], 19);
 757     cpu.cu.rd           = getbits36_1  (words[5], 20);
 758     cpu.cu.rl           = getbits36_1  (words[5], 21);
 759     cpu.cu.pot          = getbits36_1  (words[5], 22);
 760     // 23 PON
 761     cpu.cu.xde          = getbits36_1  (words[5], 24);
 762     // XDE (even instruction of an xed pair) implies the odd one follows
 763     cpu.cu.xdo          = getbits36_1  (words[5], 25) | cpu.cu.xde;
 764     cpu.cu.itp          = getbits36_1  (words[5], 26);
 765     cpu.cu.rfi          = getbits36_1  (words[5], 27);
 766     cpu.cu.its          = getbits36_1  (words[5], 28);
 767     cpu.cu.FIF          = getbits36_1  (words[5], 29);
 768     cpu.cu.CT_HOLD      = getbits36_6  (words[5], 30);
 769     // the repeated instructions take no IT/IR modifiers, so there is no
 770     // modifier to restart; CT-HOLD here is the last tag (scu2words)
 771     if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
 772       cpu.cu.CT_HOLD = 0;
 773 
 774     // words[6]
 775 
 776     cpu.cu.IWB = words[6];
 777 
 778     // words[7]
 779 
 780     cpu.cu.IRODD = words[7];
 781 }
 782 
 783 void cu_safe_restore (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 784   {
 785     words2scu (cpup, cpu.scu_data);
 786     decode_instruction (cpup, IWB_IRODD, & cpu.currentInstruction);
 787   }
 788 
 789 static void du2words (cpu_state_t * cpup, word36 * words)
     /* [previous][next][first][last][top][bottom][index][help] */
 790   {
 791     CPT (cpt2U, 7); // du2words
 792 
 793     if (cpu.tweaks.isolts_mode || cpu.tweaks.tandd_mode)
 794       {
 795         for (int i = 0; i < 8; i ++)
 796           {
 797             words[i] = cpu.du.image[i];
 798           }
 799       }
 800     else
 801       {
 802         (void)memset (words, 0, 8 * sizeof (* words));
 803       }
 804 
 805     // Word 0
 806 
 807     putbits36_1  (& words[0],  9, cpu.du.Z);
 808     putbits36_1  (& words[0], 10, cpu.du.NOP);
 809     putbits36_24 (& words[0], 12, cpu.du.CHTALLY);
 810 
 811     // Word 1
 812 
 813     if (cpu.tweaks.isolts_mode || cpu.tweaks.tandd_mode)
 814       words[1] = words[0];
 815 
 816     // Word 2
 817 
 818     putbits36_18 (& words[2],  0, cpu.du.D1_PTR_W);
 819     putbits36_6  (& words[2], 18, cpu.du.D1_PTR_B);
 820     putbits36_2  (& words[2], 25, cpu.du.TAk[0]);
 821     putbits36_1  (& words[2], 31, cpu.du.F1);
 822     putbits36_1  (& words[2], 32, cpu.du.Ak[0]);
 823 
 824     // Word 3
 825 
 826     putbits36_10 (& words[3],  0, cpu.du.LEVEL1);
 827     putbits36_24 (& words[3], 12, cpu.du.D1_RES);
 828 
 829     // Word 4
 830 
 831     putbits36_18 (& words[4],  0, cpu.du.D2_PTR_W);
 832     putbits36_6  (& words[4], 18, cpu.du.D2_PTR_B);
 833     putbits36_2  (& words[4], 25, cpu.du.TAk[1]);
 834     putbits36_1  (& words[4], 30, cpu.du.R);
 835     putbits36_1  (& words[4], 31, cpu.du.F2);
 836     putbits36_1  (& words[4], 32, cpu.du.Ak[1]);
 837 
 838     // Word 5
 839 
 840     putbits36_10 (& words[5],  0, cpu.du.LEVEL2);
 841     putbits36_24 (& words[5], 12, cpu.du.D2_RES);
 842 
 843     // Word 6
 844 
 845     putbits36_18 (& words[6],  0, cpu.du.D3_PTR_W);
 846     putbits36_6  (& words[6], 18, cpu.du.D3_PTR_B);
 847     putbits36_2  (& words[6], 25, cpu.du.TAk[2]);
 848     putbits36_1  (& words[6], 31, cpu.du.F3);
 849     putbits36_1  (& words[6], 32, cpu.du.Ak[2]);
 850     putbits36_3  (& words[6], 33, cpu.du.JMP);
 851 
 852     // Word 7
 853 
 854     putbits36_24 (& words[7], 12, cpu.du.D3_RES);
 855 
 856   }
 857 
 858 static void words2du (cpu_state_t * cpup, word36 * words)
     /* [previous][next][first][last][top][bottom][index][help] */
 859   {
 860     CPT (cpt2U, 8); // words2du
 861     // Word 0
 862 
 863     cpu.du.Z        = getbits36_1  (words[0],  9);
 864     cpu.du.NOP      = getbits36_1  (words[0], 10);
 865     cpu.du.CHTALLY  = getbits36_24 (words[0], 12);
 866     // Word 1
 867 
 868     // Word 2
 869 
 870     cpu.du.D1_PTR_W = getbits36_18 (words[2],  0);
 871     cpu.du.D1_PTR_B = getbits36_6  (words[2], 18);
 872     cpu.du.TAk[0]   = getbits36_2  (words[2], 25);
 873     cpu.du.F1       = getbits36_1  (words[2], 31);
 874     cpu.du.Ak[0]    = getbits36_1  (words[2], 32);
 875 
 876     // Word 3
 877 
 878     cpu.du.LEVEL1   = getbits36_10 (words[3],  0);
 879     cpu.du.D1_RES   = getbits36_24 (words[3], 12);
 880 
 881     // Word 4
 882 
 883     cpu.du.D2_PTR_W = getbits36_18 (words[4],  0);
 884     cpu.du.D2_PTR_B = getbits36_6  (words[4], 18);
 885     cpu.du.TAk[1]   = getbits36_2  (words[4], 25);
 886     cpu.du.F2       = getbits36_1  (words[4], 31);
 887     cpu.du.Ak[1]    = getbits36_1  (words[4], 32);
 888 
 889     // Word 5
 890 
 891     cpu.du.LEVEL2   = getbits36_10 (words[5],  0);
 892     cpu.du.D2_RES   = getbits36_24 (words[5], 12);
 893 
 894     // Word 6
 895 
 896     cpu.du.D3_PTR_W = getbits36_18 (words[6],  0);
 897     cpu.du.D3_PTR_B = getbits36_6  (words[6], 18);
 898     cpu.du.TAk[2]   = getbits36_2  (words[6], 25);
 899     cpu.du.F3       = getbits36_1  (words[6], 31);
 900     cpu.du.Ak[2]    = getbits36_1  (words[6], 32);
 901     cpu.du.JMP      = getbits36_3  (words[6], 33);
 902 
 903     // Word 7
 904 
 905     cpu.du.D3_RES   = getbits36_24 (words[7], 12);
 906 
 907     if (cpu.tweaks.isolts_mode || cpu.tweaks.tandd_mode)
 908       {
 909         for (int i = 0; i < 8; i ++)
 910           {
 911             cpu.du.image[i] = words[i];
 912           }
 913      }
 914   }
 915 
 916 static char *PRalias[] = {"ap", "ab", "bp", "bb", "lp", "lb", "sp", "sb" };
 917 
 918 //=============================================================================
 919 
 920 // illegal modifications for various instructions
 921 
 922 /*
 923 
 924         00  01  02  03  04  05  06  07
 925 
 926  00     --  au  qu  du  ic  al  ql  dl  R
 927  10     0   1   2   3   4   5   6   7
 928 
 929  20     n*  au* qu* --  ic* al* al* --  RI
 930  30     0*  1*  2*  3*  4*  5*  6*  7*
 931 
 932  40     f1  itp --  its sd  scr f2  f3  IT
 933  50     ci  i   sc  ad  di  dic id  idc
 934 
 935  60     *n  *au *qu --  *ic *al *al --  IR
 936  70     *0  *1  *2  *3  *4  *5  *6  *7
 937 
 938  bool _allowed[] = {
 939  // Tm = 0 (register) R
 940  // --   au     qu     du     ic     al     ql     dl
 941  true,  false, false, false, false, false, false, false,
 942  // 0     1      2      3      4      5      6      7
 943  false, false, false, false, false, false, false, false,
 944  // Tm = 1 (register then indirect) RI
 945  // n*   au*    qu*    --     ic*    al*    al*    --
 946  false, false, false, true,  false, false, false, true,
 947  // 0*   1*     2*     3*     4*     5*     6*     7*
 948  false, false, false, false, false, false, false, false,
 949  // Tm = 2 (indirect then tally) IT
 950  // f1   itp    --     its    sd     scr    f2     f3
 951  false, false, true, false, false, false, false, false,
 952  // ci   i      sc     ad     di     dic    id     idc
 953  false, false, false, false, false, false, false, false,
 954  // Tm = 3 (indirect then register) IR
 955  // *n   *au    *qu    --     *ic    *al    *al    --
 956  false, false, false, true,  false, false, false, true,
 957  // *0   *1     *2     *3     *4     *5     *6     *7
 958  false, false, false, false, false, false, false, false,
 959  };
 960 
 961  */
 962 // No DUDL
 963 
 964 static bool _nodudl[] = {
 965     // Tm = 0 (register) R
 966     // --   au     qu     du     ic     al     ql     dl
 967     false,  false, false, true,  false, false, false, true,
 968     // 0      1      2      3      4      5      6      7
 969      false, false, false, false, false, false, false, false,
 970     // Tm = 1 (register then indirect) RI
 971     // n*    au*    qu*    --     ic*    al*    al*    --
 972     false,  false, false, true,  false, false, false, true,
 973     // 0*     1*     2*     3*     4*     5*     6*     7*
 974     false,  false, false, false, false, false, false, false,
 975     // Tm = 2 (indirect then tally) IT
 976     // f1    itp    --     its    sd     scr    f2     f3
 977     false,  false, true,  false, false, false, false, false,
 978     // ci     i      sc     ad     di     dic   id     idc
 979     false,  false, false, false, false, false, false, false,
 980     // Tm = 3 (indirect then register) IR
 981     // *n     *au    *qu    --     *ic   *al    *al    --
 982     false,  false, false, true,  false, false, false, true,
 983     // *0     *1     *2     *3     *4     *5     *6     *7
 984     false,  false, false, false, false, false, false, false,
 985 };
 986 
 987 // No DU
 988 // No DL
 989 
 990 // (NO_CI | NO_SC | NO_SCR)
 991 static bool _nocss[] = {
 992     // Tm = 0 (register) R
 993     // *      au     qu     du     ic     al     ql     dl
 994     false,  false, false, false, false, false, false, false,
 995     // 0      1      2      3      4      5      6      7
 996     false,  false, false, false, false, false, false, false,
 997     // Tm = 1 (register then indirect) RI
 998     // n*    au*    qu*    --     ic*    al*    al*    --
 999     false,  false, false, true,  false, false, false, true,
1000     // 0*     1*     2*     3*     4*     5*     6*     7*
1001     false,  false, false, false, false, false, false, false,
1002     // Tm = 2 (indirect then tally) IT
1003     // f1    itp     --     its    sd     scr    f2     f3
1004     false,  false, true,  false, false, true,  false, false,
1005     // ci     i     sc     ad     di    dic    id     idc
1006     true,   false, true,  false, false, false, false, false,
1007     // Tm = 3 (indirect then register) IR
1008     // *r may be any register modifier but null (AL39), so *du and *dl
1009     // are legal here (PS945: bcd y,*dl)
1010     // *n    *au    *qu    *du    *ic   *al    *al    *dl
1011     false,  false, false, false, false, false, false, false,
1012     // *0     *1     *2     *3     *4     *5     *6     *7
1013     false,  false, false, false, false, false, false, false,
1014 };
1015 
1016 // (NO_DUDL | NO_CISCSCR)
1017 static bool _noddcss[] = {
1018     // Tm = 0 (register) R
1019     // *      au     qu     du     ic     al     ql    dl
1020     false,  false, false, true,  false, false, false, true,
1021     // 0      1      2      3      4      5      6      7
1022     false,  false, false, false, false, false, false, false,
1023     // Tm = 1 (register then indirect) RI
1024     // n*    au*    qu*    --     ic*    al*    al*    --
1025     false,  false, false, true,  false, false, false, true,
1026     // 0*     1*     2*     3*     4*     5*     6*     7*
1027     false,  false, false, false, false, false, false, false,
1028     // Tm = 2 (indirect then tally) IT
1029     // f1    itp     --     its    sd     scr    f2     f3
1030     false,  false, true,  false, false, true,  false, false,
1031     // ci     i     sc     ad     di    dic    id     idc
1032     true,   false, true,  false, false, false, false, false,
1033     // Tm = 3 (indirect then register) IR
1034     // *n    *au    *qu    --     *ic   *al    *al     --
1035     false,  false, false, true,  false, false, false, true,
1036     // *0     *1     *2     *3     *4     *5     *6     *7
1037     false,  false, false, false, false, false, false, false,
1038 };
1039 
1040 // (NO_DUDL | NO_CISCSCR)
1041 static bool _nodlcss[] = {
1042     // Tm = 0 (register) R
1043     // *     au     qu     du      ic     al     ql    dl
1044     false,  false, false, false, false, false, false, true,
1045     // 0      1      2      3      4      5      6      7
1046     false,  false, false, false, false, false, false, false,
1047     // Tm = 1 (register then indirect) RI
1048     // n*    au*    qu*    --     ic*    al*    al*    --
1049     false,  false, false, true,  false, false, false, true,
1050     // 0*     1*     2*     3*     4*     5*     6*     7*
1051     false,  false, false, false, false, false, false, false,
1052     // Tm = 2 (indirect then tally) IT
1053     // f1    itp     --     its    sd     scr    f2     f3
1054     false,  false, true,  false, false, true,  false, false,
1055     // ci     i     sc     ad     di    dic    id     idc
1056     true,   false, true,  false, false, false, false, false,
1057     // Tm = 3 (indirect then register) IR
1058     // *du is legal (DU is allowed); *dl is not
1059     // *n    *au    *qu    *du    *ic   *al    *al     --
1060     false,  false, false, false, false, false, false, true,
1061     // *0     *1     *2     *3     *4     *5     *6     *7
1062     false,  false, false, false, false, false, false, false,
1063 };
1064 
1065 static bool _onlyaqxn[] = {
1066     // Tm = 0 (register) R
1067     // --    au     qu     du     ic     al     ql     dl
1068     false,  false, false, true,  true,  false, false, true,
1069     // 0      1      2      3      4      5      6      7
1070      false, false, false, false, false, false, false, false,
1071     // Tm = 1 (register then indirect) RI
1072     // n*    au*    qu*    --     ic*    al*    al*    --
1073     false,  false, false, true,  false, false, false, true,
1074     // 0*     1*     2*     3*     4*     5*     6*     7*
1075     false,  false, false, false, false, false, false, false,
1076     // Tm = 2 (indirect then tally) IT
1077     // f1    itp    --     its    sd     scr    f2     f3
1078     false,  false, true,  false, false, false, false, false,
1079     // ci     i      sc     ad     di     dic   id     idc
1080     false,  false, false, false, false, false, false, false,
1081     // Tm = 3 (indirect then register) IR
1082     // *n    *au    *qu    --     *ic   *al    *al     --
1083     false,  false, false, true,  false, false, false, true,
1084     // *0     *1     *2     *3     *4     *5     *6     *7
1085     false,  false, false, false, false, false, false, false,
1086 };
1087 
1088 #if !defined(QUIET_UNUSED)
1089 static bool _illmod[] = {
1090     // Tm = 0 (register) R
1091     // *     au     qu     du     ic     al     ql     dl
1092     false,  false, false, false, false, false, false, false,
1093     // 0      1      2      3      4      5      6      7
1094     false,  false, false, false, false, false, false, false,
1095     // Tm = 1 (register then indirect) RI
1096     // n*    au*    qu*    --     ic*    al*    al*    --
1097     false,  false, false, true,  false, false, false, true,
1098     // 0*     1*     2*     3*     4*     5*     6*     7*
1099     false,  false, false, false, false, false, false, false,
1100     // Tm = 2 (indirect then tally) IT
1101     // f1    itp    --     its    sd     scr    f2     f3
1102     false,  false, true,  false, false, false, false, false,
1103     // ci      i      sc     ad     di     dic   id     idc
1104     false,  false, false, false, false, false, false, false,
1105     // Tm = 3 (indirect then register) IR
1106     // *n     *au    *qu   --     *ic    *al    *al     --
1107     // *0     *1     *2     *3     *4     *5     *6     *7
1108     false,  false, false, true,  false, false, false, true,
1109     false,  false, false, false, false, false, false, false,
1110 };
1111 #endif
1112 
1113 //=============================================================================
1114 
1115 #if defined(MATRIX)
1116 
1117 static long long theMatrix[1024] // 1024 opcodes (2^10)
1118                           [2]    // opcode extension
1119                           [2]    // bit 29
1120                           [64];  // Tag
1121 
1122 void initializeTheMatrix (void)
     /* [previous][next][first][last][top][bottom][index][help] */
1123 {
1124     (void)memset (theMatrix, 0, sizeof (theMatrix));
1125 }
1126 
1127 void addToTheMatrix (uint32 opcode, bool opcodeX, bool a, word6 tag)
     /* [previous][next][first][last][top][bottom][index][help] */
1128 {
1129     // safety
1130     uint _opcode = opcode & 01777;
1131     int _opcodeX = opcodeX ? 1 : 0;
1132     int _a       = a ? 1 : 0;
1133     int _tag     = tag & 077;
1134     theMatrix[_opcode][_opcodeX][_a][_tag] ++;
1135 }
1136 
1137 t_stat display_the_matrix (UNUSED int32 arg, UNUSED const char * buf)
     /* [previous][next][first][last][top][bottom][index][help] */
1138 {
1139     long long count;
1140 
1141     for (int opcode  = 0; opcode < 01000; opcode ++)
1142     for (int opcodeX = 0; opcodeX < 2; opcodeX ++)
1143     {
1144     long long total = 0;
1145     for (int a = 0; a < 2; a ++)
1146     for (int tag = 0; tag < 64; tag ++)
1147     if ((count = theMatrix[opcode][opcodeX][a][tag]))
1148     {
1149         // disassemble doesn't quite do what we want so copy the good bits
1150         static char result[132] = "???";
1151         strcpy (result, "???");
1152         // get mnemonic ...
1153         if (opcodes10 [opcode | (opcodeX ? 01000 : 0)].mne)
1154           strcpy (result, opcodes10[opcode | (opcodeX ? 01000 : 0)].mne);
1155         if (a)
1156             strcat (result, " prn|nnnn");
1157         else
1158             strcat (result, " nnnn");
1159 
1160         // get mod
1161         if (extMods[tag].mod)
1162         {
1163             strcat (result, ",");
1164             strcat (result, extMods[tag].mod);
1165         }
1166         if (result[0] == '?')
1167             sim_printf ("%20"PRId64": ? opcode 0%04o X %d a %d tag 0%02do\r\n",
1168                         count, opcode, opcodeX, a, tag);
1169         else
1170             sim_printf ("%20"PRId64": %s\r\n", count, result);
1171         total += count;
1172     }
1173     static char result[132] = "???";
1174     strcpy (result, "???");
1175     if (total) {
1176     // get mnemonic ...
1177     if (opcodes10 [opcode | (opcodeX ? 01000 : 0)].mne)
1178       strcpy (result, opcodes10[opcode | (opcodeX ? 01000 : 0)].mne);
1179     sim_printf ("%20"PRId64": %s\r\n", total, result);
1180     }
1181     }
1182     return SCPE_OK;
1183 }
1184 #endif
1185 
1186 // fetch instruction at address
1187 // CANFAULT
1188 // Compiled twice, like the instruction loop that calls it (see
1189 // FULL_MODEL_ON): fetchInstructionFast and fetchInstructionFull
1190 static ALWAYS_INLINE void fetchInstruction_ (cpu_state_t * cpup, word18 addr, const bool full)
     /* [previous][next][first][last][top][bottom][index][help] */
1191 {
1192     CPT (cpt2U, 9); // fetchInstruction
1193 
1194     if (get_addr_mode (cpup) == ABSOLUTE_mode)
1195       {
1196         cpu.TPR.TRR  = 0;
1197         cpu.RSDWH_R1 = 0;
1198         //cpu.PPR.P = 1; // XXX this should be already set by set_addr_mode, so no worry here
1199       }
1200 
1201     if (cpu.cu.rd && ((cpu.PPR.IC & 1) != 0))
1202       {
1203         if (cpu.cu.repeat_first)
1204           {
1205             CPT (cpt2U, 10); // fetch rpt odd
1206             //Read (addr, & cpu.cu.IRODD, INSTRUCTION_FETCH);
1207           }
1208       }
1209     else if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
1210       {
1211         if (cpu.cu.repeat_first)
1212           {
1213             CPT (cpt2U, 11); // fetch rpt even
1214             if (addr & 1)
1215               ReadInstructionFetch (cpup, addr, & cpu.cu.IWB);
1216             else
1217               {
1218                 word36 tmp[2];
1219                 /* Read2 (addr, tmp, INSTRUCTION_FETCH); */
1220                 /* cpu.cu.IWB   = tmp[0]; */
1221                 Read2InstructionFetch (cpup, addr, tmp);
1222                 cpu.cu.IWB = tmp[0];
1223                 cpu.cu.IRODD = tmp[1];
1224               }
1225           }
1226       }
1227     else
1228       {
1229         CPT (cpt2U, 12); // fetch
1230 
1231         // ISOLTS test pa870 expects IRODD to be set up.
1232         // If we are fetching an even instruction, also fetch the odd.
1233         // If we are fetching an odd instruction, copy it to IRODD as
1234         // if that was where we got it from.
1235 
1236         //Read (addr, & cpu.cu.IWB, INSTRUCTION_FETCH);
1237         if ((cpu.PPR.IC & 1) == 0) // Even
1238           {
1239             word36 tmp[2];
1240             /* Read2 (addr, tmp, INSTRUCTION_FETCH); */
1241             /* cpu.cu.IWB   = tmp[0]; */
1242             Read2InstructionFetch (cpup, addr, tmp);
1243             cpu.cu.IWB = tmp[0];
1244             cpu.cu.IRODD = tmp[1];
1245           }
1246         else // Odd
1247           {
1248             ReadInstructionFetch (cpup, addr, & cpu.cu.IWB);
1249             cpu.cu.IRODD = cpu.cu.IWB;
1250           }
1251         if (full && cpu.tweaks.l68_mode)   // (5), see FULL_MODEL_ON
1252           {
1253             // the pair, for the odd instruction fault data (doFault)
1254             cpu.l68PairAddr  = cpu.iefpFinalAddress & ~1u;
1255             cpu.l68PairValid = true;
1256             // The instruction fetch is a CU cycle of its own (PM701 02C)
1257             add_l68_CU_fetch_history (cpup);
1258             // PI-AP stays on after an instruction fetch, absolute and BAR
1259             // fetches too (PA870 01A: MME in absolute mode, SCU word 0
1260             // 404011)
1261             cpu.cu.APUCycleBits |= 04000;
1262           }
1263       }
1264 }
1265 
1266 void fetchInstructionFast (cpu_state_t * cpup, word18 addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1267   {
1268     fetchInstruction_ (cpup, addr, false);
1269   }
1270 
1271 void fetchInstructionFull (cpu_state_t * cpup, word18 addr)
     /* [previous][next][first][last][top][bottom][index][help] */
1272   {
1273     fetchInstruction_ (cpup, addr, true);
1274   }
1275 
1276 #if defined(TESTING)
1277 void traceInstruction (uint flag)
     /* [previous][next][first][last][top][bottom][index][help] */
1278   {
1279     cpu_state_t * cpup = _cpup;
1280     char buf [256];
1281     if (! flag) goto force;
1282     if_sim_debug (flag, &cpu_dev)
1283       {
1284 force:;
1285         char * compname;
1286         word18 compoffset;
1287         char * where = lookup_address (cpu.PPR.PSR, cpu.PPR.IC, & compname,
1288                                        & compoffset);
1289         bool isBAR = TST_I_NBAR ? false : true;
1290         if (where)
1291           {
1292             if (get_addr_mode (cpup) == ABSOLUTE_mode)
1293               {
1294                 if (isBAR)
1295                   {
1296                     sim_debug (flag, &cpu_dev, "%06o|%06o %s\r\n",
1297                                cpu.BAR.BASE, cpu.PPR.IC, where);
1298                   }
1299                 else
1300                   {
1301                     sim_debug (flag, &cpu_dev, "%06o %s\r\n", cpu.PPR.IC, where);
1302                   }
1303               }
1304             else if (get_addr_mode (cpup) == APPEND_mode)
1305               {
1306                 if (isBAR)
1307                   {
1308                     sim_debug (flag, &cpu_dev, "%05o:%06o|%06o %s\r\n",
1309                                cpu.PPR.PSR,
1310                                cpu.BAR.BASE, cpu.PPR.IC, where);
1311                   }
1312                 else
1313                   {
1314                     sim_debug (flag, &cpu_dev, "%05o:%06o %s\r\n",
1315                                cpu.PPR.PSR, cpu.PPR.IC, where);
1316                   }
1317               }
1318             list_source (compname, compoffset, flag);
1319           }
1320         if (get_addr_mode (cpup) == ABSOLUTE_mode)
1321           {
1322             if (isBAR)
1323               {
1324                 sim_debug (flag, &cpu_dev,
1325                   "%d: "
1326                   "%05o|%06o %012"PRIo64" (%s) %06o %03o(%d) %o %o %o %02o\r\n",
1327                   current_running_cpu_idx,
1328                   cpu.BAR.BASE,
1329                   cpu.PPR.IC,
1330                   IWB_IRODD,
1331                   disassemble (buf, IWB_IRODD),
1332                   cpu.currentInstruction.address,
1333                   cpu.currentInstruction.opcode,
1334                   cpu.currentInstruction.opcodeX,
1335                   cpu.currentInstruction.b29,
1336                   cpu.currentInstruction.i,
1337                   GET_TM (cpu.currentInstruction.tag) >> 4,
1338                   GET_TD (cpu.currentInstruction.tag) & 017);
1339               }
1340             else
1341               {
1342                 sim_debug (flag, &cpu_dev,
1343                   "%d: "
1344                   "%06o %012"PRIo64" (%s) %06o %03o(%d) %o %o %o %02o\r\n",
1345                   current_running_cpu_idx,
1346                   cpu.PPR.IC,
1347                   IWB_IRODD,
1348                   disassemble (buf, IWB_IRODD),
1349                   cpu.currentInstruction.address,
1350                   cpu.currentInstruction.opcode,
1351                   cpu.currentInstruction.opcodeX,
1352                   cpu.currentInstruction.b29,
1353                   cpu.currentInstruction.i,
1354                   GET_TM (cpu.currentInstruction.tag) >> 4,
1355                   GET_TD (cpu.currentInstruction.tag) & 017);
1356               }
1357           }
1358         else if (get_addr_mode (cpup) == APPEND_mode)
1359           {
1360             if (isBAR)
1361               {
1362                 sim_debug (flag, &cpu_dev,
1363                   "%d: "
1364                  "%05o:%06o|%06o %o %012"PRIo64" (%s) %06o %03o(%d) %o %o %o %02o\r\n",
1365                   current_running_cpu_idx,
1366                   cpu.PPR.PSR,
1367                   cpu.BAR.BASE,
1368                   cpu.PPR.IC,
1369                   cpu.PPR.PRR,
1370                   IWB_IRODD,
1371                   disassemble (buf, IWB_IRODD),
1372                   cpu.currentInstruction.address,
1373                   cpu.currentInstruction.opcode,
1374                   cpu.currentInstruction.opcodeX,
1375                   cpu.currentInstruction.b29, cpu.currentInstruction.i,
1376                   GET_TM (cpu.currentInstruction.tag) >> 4,
1377                   GET_TD (cpu.currentInstruction.tag) & 017);
1378               }
1379             else
1380               {
1381                 sim_debug (flag, &cpu_dev,
1382                   "%d: "
1383                   "%05o:%06o %o %012"PRIo64" (%s) %06o %03o(%d) %o %o %o %02o\r\n",
1384                   current_running_cpu_idx,
1385                   cpu.PPR.PSR,
1386                   cpu.PPR.IC,
1387                   cpu.PPR.PRR,
1388                   IWB_IRODD,
1389                   disassemble (buf, IWB_IRODD),
1390                   cpu.currentInstruction.address,
1391                   cpu.currentInstruction.opcode,
1392                   cpu.currentInstruction.opcodeX,
1393                   cpu.currentInstruction.b29,
1394                   cpu.currentInstruction.i,
1395                   GET_TM (cpu.currentInstruction.tag) >> 4,
1396                   GET_TD (cpu.currentInstruction.tag) & 017);
1397               }
1398           }
1399       }
1400 
1401   }
1402 #endif
1403 
1404 bool chkOVF (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
1405   {
1406     if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
1407       {
1408         // a:AL39/rpd2
1409         // Did the repeat instruction inhibit overflow faults?
1410         if ((cpu.rX[0] & 00001) == 0)
1411           return false;
1412       }
1413     return true;
1414   }
1415 
1416 bool tstOVFfault (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
1417   {
1418     // Masked?
1419     if (TST_I_OMASK)
1420       return false;
1421     // Doing a RPT/RPD?
1422     if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
1423       {
1424         // a:AL39/rpd2
1425         // Did the repeat instruction inhibit overflow faults?
1426         if ((cpu.rX[0] & 00001) == 0)
1427           return false;
1428       }
1429     return true;
1430   }
1431 
1432 #if defined(TESTING)
1433 # include "tracker.h"
1434 #endif
1435 
1436 // Compiled twice, like the instruction loop that calls it (see
1437 // FULL_MODEL_ON): executeInstructionFast and executeInstructionFull. Each
1438 // copy then has one caller, and the fast one is inlined into the loop.
1439 static ALWAYS_INLINE t_stat executeInstruction_ (cpu_state_t * cpup, const bool full) {
     /* [previous][next][first][last][top][bottom][index][help] */
1440 #if defined(TESTING)
1441   trk (cpu.cycleCnt, cpu.PPR.PSR, cpu.PPR.IC, IWB_IRODD);
1442 #endif
1443   CPT (cpt2U, 13); // execute instruction
1444 
1445 //
1446 // Decode the instruction
1447 //
1448 // If not restart
1449 //     if xec/xed
1450 //         check for illegal execute
1451 //     if rpt/rpd
1452 //         check for illegal rpt/rpd modifiers
1453 //     check for illegal modifiers
1454 //     check for privilege
1455 //     initialize CA
1456 //
1457 // Save tally
1458 // Debug trace instruction
1459 // If not restart
1460 //    Initialize TPR
1461 //
1462 // Initialize DU.JMP
1463 // If rpt/rpd
1464 //     If first repeat
1465 //         Initialize Xn
1466 //
1467 // If EIS instruction
1468 //     If not restart
1469 //         Initialize DU.CHTALLY, DU.Z
1470 //     Read operands
1471 //     Parse operands
1472 // Else not EIS instruction
1473 //     If not restart
1474 //         If B29
1475 //             Set TPR from pointer register
1476 //         Else
1477 //             Setup up TPR
1478 //         Initialize CU.CT_HOLD
1479 //     If restart and CU.POT
1480 //         Restore CA from IWB
1481 //     Do CAF if needed
1482 //     Read operand if needed
1483 //
1484 // Execute the instruction
1485 //
1486 // Write operand if needed
1487 // Update IT tally if needed
1488 // If XEC/XED, move instructions into IWB/IRODD
1489 // If instruction was repeated
1490 //     Update Xn
1491 //     Check for repeat termination
1492 // Post-instruction debug
1493 
1494 ///
1495 /// executeInstruction: Decode the instruction
1496 ///
1497 
1498   DCDstruct * ci = & cpu.currentInstruction;
1499   decode_instruction (cpup, IWB_IRODD, ci);
1500   const struct opcode_s *info = ci->info;
1501 
1502 // Local caches of frequently accessed data
1503 
1504   const uint ndes         = info->ndes;
1505   const bool restart      = cpu.cu.rfi;   // instruction is to be restarted
1506   cpu.cu.rfi              = 0;
1507   const opc_flag flags    = info->flags;
1508   const enum opc_mod mods = info->mods;
1509   const uint32 opcode     = ci->opcode;   // opcode
1510   const bool opcodeX      = ci->opcodeX;  // opcode extension
1511   const word6 tag         = ci->tag;      // instruction tag
1512 
1513 #if defined(MATRIX)
1514   {
1515     const uint32  opcode = ci->opcode;   // opcode
1516     const bool   opcodeX = ci->opcodeX;  // opcode extension
1517                                          // XXX replace with rY
1518     const bool   b29 = ci->b29;          // bit-29 - addressing via pointer
1519                                          // register
1520     const word6  tag = ci->tag;          // instruction tag
1521                                          //  XXX replace withrTAG
1522     addToTheMatrix (opcode, opcodeX, b29, tag);
1523   }
1524 #endif
1525 
1526   if (ci->b29)
1527     ci->address = SIGNEXT15_18 (ci->address & MASK15);
1528 
1529   L68_ (
1530     CPTUR (cptUseMR);
1531     if (UNLIKELY (cpu.MR.emr && cpu.MR.OC_TRAP)) {
1532       if (cpu.MR.OPCODE == opcode && cpu.MR.OPCODEX == opcodeX) {
1533         // The trapping instruction is strobed into the CU history register
1534         // before the trap and the HR reset (PM700 02V)
1535         memcpy (& cpu.MR_cache, & cpu.MR, sizeof (cpu.MR_cache));
1536         cpu.skip_cu_hist = false;
1537         add_l68_CU_history (cpup);
1538         if (cpu.MR.ihrrs) {
1539           cpu.MR.ihr = 0;
1540         }
1541         CPT (cpt2U, 14); // opcode trap
1542         //set_FFV_fault (2); // XXX According to AL39
1543         do_FFV_fault (cpup, 1, "OC TRAP");
1544       }
1545     }
1546   )
1547 
1548 ///
1549 /// executeInstruction: Non-restart processing
1550 ///
1551 
1552   if (LIKELY (!restart) || UNLIKELY (ndes > 0)) { // until we implement EIS restart
1553     cpu.cu.TSN_VALID[0] = 0;
1554     cpu.cu.TSN_VALID[1] = 0;
1555     cpu.cu.TSN_VALID[2] = 0;
1556     cpu.cu.TSN_PRNO[0]  = 0;
1557     cpu.cu.TSN_PRNO[1]  = 0;
1558     cpu.cu.TSN_PRNO[2]  = 0;
1559   }
1560 
1561   if (UNLIKELY (restart))
1562     goto restart_1;
1563 
1564 //
1565 // not restart
1566 //
1567 
1568   cpu.cu.XSF = 0;
1569 
1570   cpu.cu.pot = 0;
1571   cpu.cu.its = 0;
1572   cpu.cu.itp = 0;
1573 
1574   CPT (cpt2U, 14); // non-restart processing
1575   // Set Address register empty
1576   PNL (L68_ (cpu.AR_F_E = false;))
1577 
1578   // Reset the fault counter
1579   cpu.cu.APUCycleBits &= 07770;
1580 
1581   //cpu.cu.TSN_VALID[0] = 0;
1582   //cpu.cu.TSN_VALID[1] = 0;
1583   //cpu.cu.TSN_VALID[2] = 0;
1584 
1585   // If executing the target of XEC/XED, check the instruction is allowed
1586   if (UNLIKELY (cpu.isXED)) {
1587     if (flags & NO_XED)
1588       doFault (FAULT_IPR, fst_ill_proc,
1589                "Instruction not allowed in XEC/XED");
1590     // The even instruction from C(Y-pair) must not alter
1591     // C(Y-pair)36,71, and must not be another xed instruction.
1592     if (opcode == 0717 && !opcodeX && cpu.cu.xde && cpu.cu.xdo /* even instruction being executed */)
1593       doFault (FAULT_IPR, fst_ill_proc,
1594                "XED of XED on even word");
1595     // ISOLTS 791 03k, 792 03k
1596     if (opcode == 0560 && !opcodeX) {
1597       // To Execute Double (XED) the RPD instruction, the RPD must be the second
1598       // instruction at an odd-numbered address.
1599       if (cpu.cu.xde && cpu.cu.xdo /* even instr being executed */)
1600         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC},
1601                  "XED of RPD on even word");
1602       // To execute an instruction pair having an rpd instruction as the odd
1603       // instruction, the xed instruction must be located at an odd address.
1604       if (!cpu.cu.xde && cpu.cu.xdo /* odd instr being executed */ && !(cpu.PPR.IC & 1))
1605         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC},
1606                  "XED of RPD on odd word, even IC");
1607     }
1608   } else if (UNLIKELY (cpu.isExec)) {
1609     // To execute a rpd instruction, the xec instruction must be in an odd location.
1610     // ISOLTS 768 01w
1611     if (opcode == 0560 && !opcodeX && cpu.cu.xde && !(cpu.PPR.IC & 1))
1612       doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_PROC},
1613                "XEC of RPx on even word");
1614   }
1615 
1616   // ISOLTS wants both the not allowed in RPx and RPx illegal modifier
1617   // tested.
1618   fault_ipr_subtype_ RPx_fault = 0;
1619 
1620   // RPT/RPD illegal modifiers
1621   // a:AL39/rpd3
1622   if (UNLIKELY (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)) {
1623     if (! (flags & NO_TAG)) {
1624       // check for illegal modifiers:
1625       //    only R & RI are allowed
1626       //    only X1..X7
1627       switch (GET_TM (tag)) {
1628         case TM_RI:
1629           if (cpu.cu.rl)
1630             RPx_fault |= FR_ILL_MOD;
1631           break;
1632         case TM_R:
1633           break;
1634         default:
1635           // generate fault. Only R & RI allowed
1636           RPx_fault |= FR_ILL_MOD;
1637       }
1638 
1639       word6 Td = GET_TD (tag);
1640       if (Td == TD_X0)
1641         RPx_fault |= FR_ILL_MOD;
1642       if (Td < TD_X0)
1643         RPx_fault |= FR_ILL_MOD;
1644     }
1645 
1646     DPS8M_ (
1647       // ISOLTS 792 03e
1648       // this is really strange. possibly a bug in DPS8M HW (L68 handles it the same as all other instructions)
1649       if (RPx_fault && !opcodeX && opcode==0413) // rscr
1650         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=RPx_fault},
1651                  "DPS8M rscr early raise");
1652     )
1653 
1654     // Instruction not allowed in RPx?
1655 
1656     if (UNLIKELY (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)) {
1657       if (flags & NO_RPT)
1658         RPx_fault |= FR_ILL_PROC;
1659     }
1660 
1661     if (UNLIKELY (cpu.cu.rl)) {
1662       if (flags & NO_RPL)
1663         RPx_fault |= FR_ILL_PROC;
1664     }
1665 
1666     L68_ (
1667       // ISOLTS 791 03d, 792 03d
1668       // L68 wants ILL_MOD here - stca,stcq,stba,stbq,scpr,lcpr
1669       // all these instructions have a nonstandard TAG field interpretation. probably a HW bug in decoder
1670       if (RPx_fault && !opcodeX && (opcode==0751 || opcode==0752 || opcode==0551 || opcode==0552 || opcode==0452 || opcode==0674))
1671         RPx_fault |= FR_ILL_MOD;
1672     )
1673   }
1674 
1675   // PVS-Studio says: Expression 'RPx_fault != 0' is always false.
1676   if (UNLIKELY (RPx_fault != 0)) //-V547
1677     doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=RPx_fault},
1678              "RPx test fail");
1679 
1680   ///                     check for illegal addressing mode(s) ...
1681   ///
1682   // ISOLTS wants both the IPR and illegal modifier tested.
1683   fault_ipr_subtype_ mod_fault = 0;
1684 
1685   // No CI/SC/SCR allowed
1686   if (mods == NO_CSS) {
1687     if (_nocss[tag])
1688       mod_fault |= FR_ILL_MOD; // "Illegal CI/SC/SCR modification"
1689   }
1690   // No DU/DL/CI/SC/SCR allowed
1691   else if (mods == NO_DDCSS) {
1692     if (_noddcss[tag])
1693       mod_fault |= FR_ILL_MOD; // "Illegal DU/DL/CI/SC/SCR modification"
1694   }
1695   // No DL/CI/SC/SCR allowed
1696   else if (mods == NO_DLCSS) {
1697     if (_nodlcss[tag])
1698       mod_fault |= FR_ILL_MOD; // "Illegal DL/CI/SC/SCR modification"
1699   }
1700   // No DU/DL allowed
1701   else if (mods == NO_DUDL) {
1702     if (_nodudl[tag])
1703       mod_fault |= FR_ILL_MOD; // "Illegal DU/DL modification"
1704   }
1705   else if ((unsigned long long)mods == (unsigned long long)ONLY_AU_QU_AL_QL_XN) {
1706     if (_onlyaqxn[tag])
1707       mod_fault |= FR_ILL_MOD; // "Illegal DU/DL/IC modification"
1708   }
1709 
1710   L68_ (
1711     // L68 raises it immediately
1712     if (mod_fault)
1713       doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=mod_fault},
1714                "Illegal modifier");
1715    )
1716 
1717   // check for priv ins - Attempted execution in normal or BAR modes causes a
1718   // illegal procedure fault.
1719   if (UNLIKELY (flags & PRIV_INS)) {
1720     DPS8M_ (
1721       // DPS8M illegal instructions lptp,lptr,lsdp,lsdr
1722       // ISOLTS 890 05abc
1723       if (((opcode == 0232 || opcode == 0173) && opcodeX ) || (opcode == 0257))
1724         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault},
1725                  "Attempted execution of multics privileged instruction.");
1726     )
1727 
1728     if (!is_priv_mode (cpup)) {
1729       // Multics privileged instructions: absa,ldbr,lra,rcu,scu,sdbr,ssdp,ssdr,sptp,sptr
1730       // ISOLTS 890 05abc,06abc
1731       bool prv;
1732       DPS8M_ (
1733         prv =((opcode == 0212 || opcode == 0232 || opcode == 0613 || opcode == 0657) && !opcodeX ) ||
1734              ((opcode == 0254 || opcode == 0774) && opcodeX ) ||
1735               (opcode == 0557 || opcode == 0154);
1736       )
1737       L68_ (
1738         // on L68, lptp,lptr,lsdp,lsdr instructions are not illegal, so handle them here
1739         prv = ((opcode == 0212 || opcode == 0232 || opcode == 0613 || opcode == 0657) && !opcodeX ) ||
1740               ((opcode == 0254 || opcode == 0774 || opcode == 0232 || opcode == 0173) && opcodeX ) ||
1741                (opcode == 0557 || opcode == 0154 || opcode == 0257);
1742       )
1743       if (prv) {
1744         if (!get_bar_mode (cpup)) {
1745           // ISOLTS-890 05ab
1746           doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_SLV|mod_fault},
1747                    "Attempted execution of multics privileged instruction.");
1748         } else {
1749           doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault},
1750                    "Attempted execution of multics privileged instruction.");
1751         }
1752       }
1753       doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_SLV|mod_fault},
1754                "Attempted execution of privileged instruction.");
1755     }
1756   }
1757 
1758   if (UNLIKELY (flags & NO_BAR)) {
1759     if (get_bar_mode(cpup)) {
1760       // lbar
1761       // ISOLTS 890 06a
1762       // ISOLTS says that L68 handles this in the same way
1763       if (opcode == 0230 && !opcodeX)
1764         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_SLV|mod_fault},
1765                  "Attempted BAR execution of nonprivileged instruction.");
1766       else
1767         doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=FR_ILL_OP|mod_fault},
1768                  "Attempted BAR execution of nonprivileged instruction.");
1769     }
1770   }
1771 
1772   DPS8M_ (
1773     // DPS8M raises it delayed
1774     if (UNLIKELY (mod_fault != 0))
1775       doFault (FAULT_IPR, (_fault_subtype) {.fault_ipr_subtype=mod_fault},
1776                "Illegal modifier");
1777   )
1778 
1779 ///
1780 /// executeInstruction: Restart or Non-restart processing
1781 ///                     Initialize address registers
1782 ///
1783 
1784 restart_1:
1785   CPT (cpt2U, 15); // instruction processing
1786 
1787 ///
1788 /// executeInstruction: Initialize state saving registers
1789 ///
1790 
1791   // XXX this may be wrong; make sure that the right value is used
1792   // if a page fault occurs. (i.e. this may belong above restart_1.
1793   // This is also used by the SCU instruction. ISOLTS tst887 does
1794   // a 'SCU n,ad' with a tally of 1; the tally is decremented, setting
1795   // the IR tally bit as part of the CA calculation; this is not
1796   // the machine conditions that the SCU instruction is saving.
1797 
1798   ci->stiTally = TST_I_TALLY;   // for sti instruction
1799 
1800 ///
1801 /// executeInstruction: scp hooks
1802 ///
1803 
1804 #if !defined(SPEED)
1805   // Don't trace Multics idle loop
1806   //if (cpu.PPR.PSR != 061 || cpu.PPR.IC != 0307)
1807 
1808   {
1809     traceInstruction (DBG_TRACE);
1810 # if defined(DBGEVENT)
1811     int dbgevt;
1812     if (n_dbgevents && (dbgevt = (dbgevent_lookup (cpu.PPR.PSR, cpu.PPR.IC))) >= 0) {
1813       if (dbgevents[dbgevt].t0)
1814         clock_gettime (CLOCK_REALTIME, & dbgevent_t0);
1815       struct timespec now, delta;
1816       clock_gettime (CLOCK_REALTIME, & now);
1817       timespec_diff (& dbgevent_t0, & now, & delta);
1818       sim_printf ("[%d] %5ld.%03ld %s\r\n", dbgevt, delta.tv_sec, delta.tv_nsec/1000000, dbgevents[dbgevt].tag);
1819     }
1820 # endif
1821 # if defined(TESTING)
1822     HDBGTrace ("");
1823 # endif
1824   }
1825 #else  // !SPEED
1826   // Don't trace Multics idle loop
1827   //if (cpu.PPR.PSR != 061 || cpu.PPR.IC != 0307)
1828 # if defined(TESTING)
1829   HDBGTrace ("");
1830 # endif
1831 #endif // !SPEED
1832 
1833 ///
1834 /// executeInstruction: Initialize misc.
1835 ///
1836 
1837   cpu.du.JMP = (word3) ndes;
1838   cpu.dlyFlt = false;
1839 
1840 ///
1841 /// executeInstruction: RPT/RPD/RPL special processing for 'first time'
1842 ///
1843 
1844   if (UNLIKELY (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)) {
1845     CPT (cpt2U, 15); // RPx processing
1846 
1847 //
1848 // RPT:
1849 //
1850 // The computed address, y, of the operand (in the case of R modification) or
1851 // indirect word (in the case of RI modification) is determined as follows:
1852 //
1853 // For the first execution of the repeated instruction:
1854 //      C(C(PPR.IC)+1)0,17 + C(Xn) -> y, y -> C(Xn)
1855 //
1856 // For all successive executions of the repeated instruction:
1857 //      C(Xn) + Delta -> y, y -> C(Xn);
1858 //
1859 //
1860 // RPD:
1861 //
1862 // The computed addresses, y-even and y-odd, of the operands (in the case of
1863 // R modification) or indirect words (in the case of RI modification) are
1864 // determined as follows:
1865 //
1866 // For the first execution of the repeated instruction pair:
1867 //      C(C(PPR.IC)+1)0,17 + C(X-even) -> y-even, y-even -> C(X-even)
1868 //      C(C(PPR.IC)+2)0,17 + C(X-odd) -> y-odd, y-odd -> C(X-odd)
1869 //
1870 // For all successive executions of the repeated instruction pair:
1871 //      if C(X0)8 = 1, then C(X-even) + Delta -> y-even,
1872 //           y-even -> C(X-even);
1873 //      otherwise, C(X-even) -> y-even
1874 //      if C(X0)9 = 1, then C(X-odd) + Delta -> y-odd,
1875 //           y-odd -> C(X-odd);
1876 //      otherwise, C(X-odd) -> y-odd
1877 //
1878 // C(X0)8,9 correspond to control bits A and B, respectively, of the rpd
1879 // instruction word.
1880 //
1881 //
1882 // RL:
1883 //
1884 // The computed address, y, of the operand is determined as follows:
1885 //
1886 // For the first execution of the repeated instruction:
1887 //
1888 //      C(C(PPR.IC)+1)0,17 + C(Xn) -> y, y -> C(Xn)
1889 //
1890 // For all successive executions of the repeated instruction:
1891 //
1892 //      C(Xn) -> y
1893 //
1894 //      if C(Y)0,17 != 0, then C (y)0,17 -> C(Xn);
1895 //
1896 //      otherwise, no change to C(Xn)
1897 //
1898 //  C(Y)0,17 is known as the link address and is the computed address of the
1899 //  next entry in a threaded list of operands to be referenced by the repeated
1900 //  instruction.
1901 //
1902 
1903     sim_debug (DBG_TRACEEXT, & cpu_dev,
1904                "RPT/RPD first %d rpt %d rd %d e/o %d X0 %06o a %d b %d\r\n",
1905                cpu.cu.repeat_first, cpu.cu.rpt, cpu.cu.rd, cpu.PPR.IC & 1, cpu.rX[0],
1906                !! (cpu.rX[0] & 01000), !! (cpu.rX[0] & 0400));
1907     sim_debug (DBG_TRACEEXT, & cpu_dev,
1908                "RPT/RPD CA %06o\r\n", cpu.TPR.CA);
1909 
1910 // Handle first time of a RPT or RPD
1911 
1912     if (cpu.cu.repeat_first) {
1913       CPT (cpt2U, 16); // RPx first processing
1914       // The semantics of these are that even is the first instruction of
1915       // and RPD, and odd the second.
1916 
1917       bool icOdd  = !! (cpu.PPR.IC & 1);
1918       bool icEven = ! icOdd;
1919 
1920       // If RPT or (RPD and the odd instruction)
1921       if (cpu.cu.rpt || (cpu.cu.rd && icOdd) || cpu.cu.rl)
1922         cpu.cu.repeat_first = false;
1923 
1924       // a:RJ78/rpd6
1925       // For the first execution of the repeated instruction:
1926       // C(C(PPR.IC)+1)0,17 + C(Xn) -> y, y -> C(Xn)
1927       if (cpu.cu.rpt ||              // rpt
1928          (cpu.cu.rd && icEven) ||   // rpd & even
1929          (cpu.cu.rd && icOdd)  ||   // rpd & odd
1930           cpu.cu.rl) {               // rl
1931         word18 offset = ci->address;
1932         offset &= AMASK;
1933 
1934         sim_debug (DBG_TRACEEXT, & cpu_dev, "rpt/rd/rl repeat first; offset is %06o\r\n", offset);
1935 
1936         word6 Td = GET_TD (tag);
1937         uint Xn = X (Td);  // Get Xn of next instruction
1938         sim_debug (DBG_TRACEEXT, & cpu_dev, "rpt/rd/rl repeat first; X%d was %06o\r\n", Xn, cpu.rX[Xn]);
1939         // a:RJ78/rpd5
1940         cpu.TPR.CA = (cpu.rX[Xn] + offset) & AMASK;
1941         // Xn is changed only if the instruction completes: a fault
1942         // before then leaves it as it was, and the restart (RF still
1943         // on) does this again (PA885 06B)
1944         cpu.rptXnSaved = true;
1945         cpu.rptXn      = Xn;
1946         cpu.rptXnOld   = cpu.rX[Xn];
1947         cpu.rX[Xn] = cpu.TPR.CA;
1948 #if defined(TESTING)
1949         HDBGRegXW (Xn, "rpt 1st");
1950 #endif
1951         sim_debug (DBG_TRACEEXT, & cpu_dev, "rpt/rd/rl repeat first; X%d now %06o\r\n", Xn, cpu.rX[Xn]);
1952       } // rpt or rd or rl
1953 
1954     } // repeat first
1955   } // cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl
1956 
1957 ///
1958 /// Restart or Non-restart
1959 ///
1960 
1961 ///
1962 /// executeInstruction: EIS operand processing
1963 ///
1964 
1965   if (UNLIKELY (ndes > 0)) {
1966     CPT (cpt2U, 27); // EIS operand processing
1967     sim_debug (DBG_APPENDING, &cpu_dev, "initialize EIS descriptors\r\n");
1968     // This must not happen on instruction restart
1969     // T&D: an interruptible EIS instruction started with MIF on resumes
1970     // from the decimal unit (AL39 "not initialized from the operand
1971     // descriptors if ... MIF is set ON"; PM842).
1972     if (!restart && ! (full && cpu.tweaks.tandd_mode && TST_I_MIF &&
1973                        tandd_eis_interruptible (cpup))) {
1974       CPT (cpt2U, 28); // EIS not restart
1975       cpu.du.CHTALLY = 0;
1976       cpu.du.Z = 1;
1977     }
1978     cpu.tanddEISstart = cpu.du.CHTALLY;
1979     for (uint n = 0; n < ndes; n += 1) {
1980       CPT (cpt2U, 29 + n); // EIS operand fetch (29, 30, 31)
1981 // XXX This is a bit of a hack; In general the code is good about
1982 // setting up for bit29 or PR operations by setting up TPR, but
1983 // assumes that the 'else' case can be ignored when it should set
1984 // TPR to the canonical values. Here, in the case of a EIS instruction
1985 // restart after page fault, the TPR is in an unknown state. Ultimately,
1986 // this should not be an issue, as this folderol would be in the DU, and
1987 // we would not be re-executing that code, but until then, set the TPR
1988 // to the condition we know it should be in.
1989             cpu.TPR.TRR = cpu.PPR.PRR;
1990             cpu.TPR.TSR = cpu.PPR.PSR;
1991 
1992 
1993 
1994 
1995 
1996 
1997 
1998             // append cycles updates cpu.PPR.IC to TPR.CA
1999             word18 saveIC = cpu.PPR.IC;
2000             //Read (cpu.PPR.IC + 1 + n, & cpu.currentEISinstruction.op[n], INSTRUCTION_FETCH);
2001             ReadInstructionFetch (cpup, cpu.PPR.IC + 1 + n, & cpu.currentEISinstruction.op[n]);
2002             cpu.PPR.IC = saveIC;
2003             //Read (cpu.PPR.IC + 1 + n, & cpu.currentEISinstruction.op[n], APU_DATA_READ);
2004 
2005           }
2006         PNL (cpu.IWRAddr = cpu.currentEISinstruction.op[0]);
2007         setupEISoperands (cpup);
2008       }
2009 
2010 ///
2011 /// Restart or Non-restart
2012 ///
2013 
2014 ///
2015 /// executeInstruction: non-EIS operand processing
2016 ///
2017 
2018   else {
2019     CPT (cpt2U, 32); // non-EIS operand processing
2020     CPT (cpt2U, 33); // not restart non-EIS operand processing
2021     if (ci->b29) {   // if A bit set set-up TPR stuff ...
2022       CPT (cpt2U, 34); // B29
2023 
2024 // AL39 says that RCU does not restore CA, so words to SCU does not.
2025 // So we do it here, even if restart
2026       word3 n = GET_PRN(IWB_IRODD);  // get PRn
2027       word15 offset = GET_OFFSET(IWB_IRODD);
2028       CPTUR (cptUsePRn + n);
2029 
2030       sim_debug (DBG_APPENDING, &cpu_dev,
2031                  "doPtrReg: PR[%o] SNR=%05o RNR=%o WORDNO=%06o " "BITNO=%02o\r\n",
2032                  n, cpu.PAR[n].SNR, cpu.PAR[n].RNR, cpu.PAR[n].WORDNO, GET_PR_BITNO (n));
2033 
2034 // Fix tst880: 'call6 pr1|0'. The instruction does a DF1; the fault handler
2035 // updates PRR in the CU save data. On restart, TRR is not updated.
2036 // Removing the 'if' appears to resolve the problem without regressions.
2037       //if (!restart) {
2038 // Not EIS, bit 29 set, !restart
2039       cpu.TPR.TBR = GET_PR_BITNO (n);
2040 
2041       cpu.TPR.TSR = cpu.PAR[n].SNR;
2042       if (ci->info->flags & TRANSFER_INS)
2043         cpu.TPR.TRR = max (cpu.PAR[n].RNR, cpu.PPR.PRR);
2044       else
2045         cpu.TPR.TRR = max3 (cpu.PAR[n].RNR, cpu.TPR.TRR, cpu.PPR.PRR);
2046 
2047       sim_debug (DBG_APPENDING, &cpu_dev,
2048                  "doPtrReg: n=%o offset=%05o TPR.CA=%06o " "TPR.TBR=%o TPR.TSR=%05o TPR.TRR=%o\r\n",
2049                  n, offset, cpu.TPR.CA, cpu.TPR.TBR, cpu.TPR.TSR, cpu.TPR.TRR);
2050       //}
2051 
2052 // Putting the a29 clear here makes sense, but breaks the emulator for unclear
2053 // reasons (possibly ABSA?). Do it in updateIWB instead
2054 //                ci->a = false;
2055 //                // Don't clear a; it is needed to detect change to appending
2056 //                //  mode
2057 //                //a = false;
2058 //                putbits36_1 (& cpu.cu.IWB, 29, 0);
2059     } else {
2060 // not eis, not bit b29
2061       if (!restart) {
2062         CPT (cpt2U, 35); // not B29
2063         cpu.cu.TSN_VALID [0] = 0;
2064         cpu.TPR.TBR = 0;
2065         if (get_addr_mode (cpup) == ABSOLUTE_mode) {
2066           cpu.TPR.TSR  = cpu.PPR.PSR;
2067           cpu.TPR.TRR  = 0;
2068           cpu.RSDWH_R1 = 0;
2069         }
2070       }
2071     }
2072 
2073     // This must not happen on instruction restart
2074     if (!restart)
2075       cpu.cu.CT_HOLD = 0; // Clear interrupted IR mode flag
2076 
2077     // These are set by do_caf
2078     cpu.ou.directOperandFlag = false;
2079     cpu.ou.directOperand = 0;
2080     cpu.ou.characterOperandSize = 0;
2081     cpu.ou.characterOperandOffset = 0;
2082     cpu.ou.crflag = false;
2083 
2084     if ((flags & PREPARE_CA) || WRITEOP (ci) || READOP (ci)) {
2085       CPT (cpt2L, 1); // CAF
2086       if (full)
2087         do_caf (cpup);
2088       else
2089         do_caf_fast (cpup);   // no L68 ADR TRAP: (6), see FULL_MODEL_ON
2090       PNL (L68_ (cpu.AR_F_E = true;))
2091       cpu.iefpFinalAddress = cpu.TPR.CA;
2092     }
2093 
2094     if (READOP (ci)) {
2095       CPT (cpt2L, 2); // Read operands
2096       readOperands (cpup);
2097 #if defined(LOCKLESS)
2098       cpu.rmw_address = cpu.iefpFinalAddress;
2099 #endif
2100       if (cpu.cu.rl) {
2101         switch (operand_size (cpup)) {
2102           case 1:
2103             cpu.lnk = GETHI36 (cpu.CY);
2104             cpu.CY &= MASK18;
2105             break;
2106 
2107           case 2:
2108             cpu.lnk = GETHI36 (cpu.Ypair[0]);
2109             cpu.Ypair[0] &= MASK18;
2110             break;
2111 
2112           default:
2113             break;
2114         }
2115       }
2116     }
2117     PNL (cpu.IWRAddr = 0);
2118   }
2119 
2120 // Initialize zone to 'entire word'
2121 
2122   cpu.useZone = false;
2123   cpu.zone = MASK36;
2124 
2125 ///
2126 /// executeInstruction: Execute the instruction
2127 ///
2128 
2129   t_stat ret = doInstruction (cpup);
2130 
2131 ///
2132 /// executeInstruction: Write operand
2133 ///
2134 
2135   cpu.last_write = 0;
2136   if (WRITEOP (ci)) {
2137     CPT (cpt2L, 3); // Write operands
2138     cpu.last_write = cpu.TPR.CA;
2139 #if defined(LOCKLESS)
2140     if ((ci->info->flags & RMW) == RMW) {
2141       if (operand_size(cpup) != 1)
2142         sim_warn("executeInstruction: operand_size!= 1\r\n");
2143       if (cpu.iefpFinalAddress != cpu.rmw_address)
2144         sim_warn("executeInstruction: write addr changed %o %d\r\n", cpu.iefpFinalAddress, cpu.rmw_address);
2145       cache_write_unlock (cpup, cpu.iefpFinalAddress, cpu.CY, __func__);
2146 # if defined(TESTING)
2147       HDBGMWrite (cpu.iefpFinalAddress, cpu.CY, "Write RMW");
2148 # endif
2149     } else
2150       writeOperands (cpup);
2151 #else
2152     writeOperands (cpup);
2153 #endif
2154   }
2155 
2156   else if (flags & PREPARE_CA) {
2157     // 'EPP ITS; TRA' confuses the APU by leaving last_cycle
2158     // at INDIRECT_WORD_FETCH; defoobarize the APU:
2159     fauxDoAppendCycle (cpup, OPERAND_READ);
2160     cpu.TPR.TRR = cpu.PPR.PRR;
2161     cpu.TPR.TSR = cpu.PPR.PSR;
2162     cpu.TPR.TBR = 0;
2163   }
2164 
2165 ///
2166 /// executeInstruction: RPT/RPD/RPL processing
2167 ///
2168 
2169   // The semantics of these are that even is the first instruction of
2170   // and RPD, and odd the second.
2171 
2172   bool icOdd = !! (cpu.PPR.IC & 1);
2173   bool icEven = ! icOdd;
2174 
2175   // Here, repeat_first means that the instruction just executed was the
2176   // RPT or RPD; but when the even instruction of a RPD is executed,
2177   // repeat_first is still set, since repeat_first cannot be cleared
2178   // until the odd instruction gets its first execution. Put some
2179   // ugly logic in to detect that condition.
2180 
2181   bool rf = cpu.cu.repeat_first;
2182   if (rf && cpu.cu.rd && icEven)
2183     rf = false;
2184 
2185   if (UNLIKELY ((! rf) && (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl))) {
2186     CPT (cpt2L, 7); // Post execution RPx
2187     // If we get here, the instruction just executed was a
2188     // RPT, RPD or RPL target instruction, and not the RPT or RPD
2189     // instruction itself
2190 
2191     if (cpu.cu.rpt || cpu.cu.rd) {
2192       // Add delta to index register.
2193 
2194       bool rptA = !! (cpu.rX[0] & 01000);
2195       bool rptB = !! (cpu.rX[0] & 00400);
2196 
2197       // The delta added below is for the next execution; on the hardware
2198       // Xn changes when that instruction completes, so until then a fault
2199       // undoes it (doFault; PA885 06D). This instruction completed.
2200       if (cpu.cu.rpt || ! icOdd)
2201         cpu.rptUndo[0] = 0;
2202       else
2203         cpu.rptUndo[1] = 0;
2204 
2205       sim_debug (DBG_TRACEEXT, & cpu_dev,
2206                  "RPT/RPD delta first %d rf %d rpt %d rd %d " "e/o %d X0 %06o a %d b %d\r\n",
2207                  cpu.cu.repeat_first, rf, cpu.cu.rpt, cpu.cu.rd, icOdd, cpu.rX[0], rptA, rptB);
2208 
2209       if (cpu.cu.rpt) { // rpt
2210         CPT (cpt2L, 8); // RPT delta
2211         uint Xn = (uint) getbits36_3 (cpu.cu.IWB, 36 - 3);
2212         cpu.TPR.CA = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
2213         cpu.rX[Xn] = cpu.TPR.CA;
2214         cpu.rptUndo[0] = Xn + 1;
2215 #if defined(TESTING)
2216         HDBGRegXW (Xn, "rpt delta");
2217 #endif
2218         sim_debug (DBG_TRACEEXT, & cpu_dev, "RPT/RPD delta; X%d now %06o\r\n", Xn, cpu.rX[Xn]);
2219       }
2220 
2221       // a:RJ78/rpd6
2222       // We know that the X register is not to be incremented until
2223       // after both instructions have executed, so the following
2224       // if uses icOdd instead of the more sensical icEven.
2225       if (cpu.cu.rd && icOdd && rptA) { // rpd, even instruction
2226         CPT (cpt2L, 9); // RD even
2227         // a:RJ78/rpd7
2228         uint Xn = (uint) getbits36_3 (cpu.cu.IWB, 36 - 3);
2229         cpu.TPR.CA = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
2230         cpu.rX[Xn] = cpu.TPR.CA;
2231         cpu.rptUndo[0] = Xn + 1;
2232 #if defined(TESTING)
2233         HDBGRegXW (Xn, "rpd delta even");
2234 #endif
2235         sim_debug (DBG_TRACEEXT, & cpu_dev, "RPT/RPD delta; X%d now %06o\r\n", Xn, cpu.rX[Xn]);
2236       }
2237 
2238       if (cpu.cu.rd && icOdd && rptB) { // rpdb, odd instruction
2239         CPT (cpt2L, 10); // RD odd
2240         // a:RJ78/rpd8
2241         uint Xn = (uint) getbits36_3 (cpu.cu.IRODD, 36 - 3);
2242         cpu.TPR.CA = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
2243         cpu.rX[Xn] = cpu.TPR.CA;
2244         cpu.rptUndo[1] = Xn + 1;
2245 #if defined(TESTING)
2246         HDBGRegXW (Xn, "rpd delta odd");
2247 #endif
2248         sim_debug (DBG_TRACEEXT, & cpu_dev, "RPT/RPD delta; X%d now %06o\r\n", Xn, cpu.rX[Xn]);
2249       }
2250     } // rpt || rd
2251 
2252     // Check for termination conditions.
2253 
2254 ///////
2255 //
2256 // ISOLTS test 769 claims in test-02a that 'rpt;div' with a divide
2257 // fault should delay the divide fault until after the termination
2258 // check (it checks that the tally should be decremented) and in test-02b
2259 // that 'rpl;div' with a divide fault should not due the termination
2260 // check (the tally should not be decremented).
2261 //
2262 // This implies that rpt and rpl are handled differently; as a test
2263 // trying:
2264 
2265     bool flt;
2266     if (cpu.tweaks.l68_mode)
2267       flt = (cpu.cu.rl || cpu.cu.rpt || cpu.cu.rd) && cpu.dlyFlt; // L68
2268     else
2269       flt = cpu.cu.rl && cpu.dlyFlt;
2270     if (flt) {
2271       CPT (cpt2L, 14); // Delayed fault
2272       doFault (cpu.dlyFltNum, cpu.dlySubFltNum, cpu.dlyCtx);
2273     }
2274 
2275 // Sadly, it fixes ISOLTS 769 test 02a and 02b.
2276 //
2277 ///////
2278 
2279     if (cpu.cu.rpt || (cpu.cu.rd && icOdd) || cpu.cu.rl) {
2280       CPT (cpt2L, 12); // RPx termination check
2281       bool exit = false;
2282       // The repetition cycle consists of the following steps:
2283       //  a. Execute the repeated instruction
2284       //  b. C(X0)0,7 - 1 -> C(X0)0,7
2285       // a:AL39/rpd9
2286       uint x = (uint) getbits18 (cpu.rX[0], 0, 8);
2287       //x -= 1;
2288       // ubsan
2289       x = (uint) (((int) x) - 1);
2290       x &= MASK8;
2291       putbits18 (& cpu.rX[0], 0, 8, x);
2292 #if defined(TESTING)
2293       HDBGRegXW (0, "rpt term");
2294 #endif
2295 
2296       // a:AL39/rpd10
2297       //  c. If C(X0)0,7 = 0, then set the tally runout indicator ON
2298       //     and terminate
2299 
2300       sim_debug (DBG_TRACEEXT, & cpu_dev, "tally %d\r\n", x);
2301       if (x == 0) {
2302         sim_debug (DBG_TRACEEXT, & cpu_dev, "tally runout\r\n");
2303         SET_I_TALLY;
2304         exit = true;
2305       } else {
2306         sim_debug (DBG_TRACEEXT, & cpu_dev, "not tally runout\r\n");
2307         CLR_I_TALLY;
2308       }
2309 
2310       //  d. If a terminate condition has been met, then set
2311       //     the tally runout indicator OFF and terminate
2312 
2313       if (TST_I_ZERO && (cpu.rX[0] & 0100)) {
2314         sim_debug (DBG_TRACEEXT, & cpu_dev, "is zero terminate\r\n");
2315         CLR_I_TALLY;
2316         exit = true;
2317       }
2318       if (!TST_I_ZERO && (cpu.rX[0] & 040)) {
2319         sim_debug (DBG_TRACEEXT, & cpu_dev, "is not zero terminate\r\n");
2320         CLR_I_TALLY;
2321         exit = true;
2322       }
2323       if (TST_I_NEG && (cpu.rX[0] & 020)) {
2324         sim_debug (DBG_TRACEEXT, & cpu_dev, "is neg terminate\r\n");
2325         CLR_I_TALLY;
2326         exit = true;
2327       }
2328       if (!TST_I_NEG && (cpu.rX[0] & 010)) {
2329         sim_debug (DBG_TRACEEXT, & cpu_dev, "is not neg terminate\r\n");
2330         CLR_I_TALLY;
2331         exit = true;
2332       }
2333       if (TST_I_CARRY && (cpu.rX[0] & 04)) {
2334         sim_debug (DBG_TRACEEXT, & cpu_dev, "is carry terminate\r\n");
2335         CLR_I_TALLY;
2336         exit = true;
2337       }
2338       if (!TST_I_CARRY && (cpu.rX[0] & 02)) {
2339         sim_debug (DBG_TRACEEXT, & cpu_dev, "is not carry terminate\r\n");
2340         CLR_I_TALLY;
2341         exit = true;
2342       }
2343       if (TST_I_OFLOW && (cpu.rX[0] & 01)) {
2344         sim_debug (DBG_TRACEEXT, & cpu_dev, "is overflow terminate\r\n");
2345 // ISOLTS test ps805 says that on overflow the tally should be set.
2346         //CLR_I_TALLY;
2347         SET_I_TALLY;
2348         exit = true;
2349       }
2350 
2351       if (exit) {
2352         CPT (cpt2L, 13); // RPx terminated
2353         cpu.cu.rpt = false;
2354         cpu.cu.rd = false;
2355         cpu.cu.rl = false;
2356         // The delta matters only while the repeat runs. Kept, it showed up
2357         // in the SCU data of the next unrelated fault, so ISOLTS PS955's
2358         // isolated and sequential runs of a case saved different deltas
2359         // (01 vs 02, from PS955's own last RPT/RPD).
2360         cpu.cu.delta = 0;
2361       } else {
2362         sim_debug (DBG_TRACEEXT, & cpu_dev, "not terminate\r\n");
2363       }
2364     } // if (cpu.cu.rpt || cpu.cu.rd & (cpu.PPR.IC & 1))
2365 
2366     if (cpu.cu.rl) {
2367       CPT (cpt2L, 11); // RL
2368       if (cpu.lnk == 0) {
2369         CPT (cpt2L, 13); // RPx terminated
2370         cpu.cu.rpt = false;
2371         cpu.cu.rd = false;
2372         cpu.cu.rl = false;
2373         SET_I_TALLY;
2374         cpu.cu.delta = 0;  // as for RPT/RPD termination above
2375       } else {
2376         // C(Xn) -> y
2377         uint Xn = (uint) getbits36_3 (cpu.cu.IWB, 36 - 3);
2378         //word18 lnk = GETHI36 (cpu.CY);
2379         //cpu.CY &= MASK18;
2380         cpu.rX[Xn] = cpu.lnk;
2381 #if defined(TESTING)
2382         HDBGRegXW (Xn, "rl");
2383 #endif
2384       }
2385     } // rl
2386   } // (! rf) && (cpu.cu.rpt || cpu.cu.rd)
2387 
2388   if (UNLIKELY (cpu.dlyFlt)) {
2389     CPT (cpt2L, 14); // Delayed fault
2390     doFault (cpu.dlyFltNum, cpu.dlySubFltNum, cpu.dlyCtx);
2391   }
2392 
2393 ///
2394 /// executeInstruction: scp hooks
2395 ///
2396 
2397   cpu.instrCnt ++;
2398 
2399   if_sim_debug (DBG_REGDUMP, & cpu_dev) {
2400     char buf [256];
2401     sim_debug (DBG_REGDUMPAQI, &cpu_dev, "A=%012"PRIo64" Q=%012"PRIo64" IR:%s\r\n",
2402                cpu.rA, cpu.rQ, dump_flags (buf, cpu.cu.IR));
2403 #if !defined(__MINGW64__) || !defined(__MINGW32__)
2404     sim_debug (DBG_REGDUMPFLT, &cpu_dev, "E=%03o A=%012"PRIo64" Q=%012"PRIo64" %.10Lg\r\n",
2405                cpu.rE, cpu.rA, cpu.rQ, EAQToIEEElongdouble (cpup));
2406 #else
2407     sim_debug (DBG_REGDUMPFLT, &cpu_dev, "E=%03o A=%012"PRIo64" Q=%012"PRIo64" %.10g\r\n",
2408                cpu.rE, cpu.rA, cpu.rQ, EAQToIEEEdouble (cpup));
2409 #endif
2410     sim_debug (DBG_REGDUMPIDX, &cpu_dev, "X[0]=%06o X[1]=%06o X[2]=%06o X[3]=%06o\r\n",
2411                cpu.rX[0], cpu.rX[1], cpu.rX[2], cpu.rX[3]);
2412     sim_debug (DBG_REGDUMPIDX, &cpu_dev, "X[4]=%06o X[5]=%06o X[6]=%06o X[7]=%06o\r\n",
2413                cpu.rX[4], cpu.rX[5], cpu.rX[6], cpu.rX[7]);
2414     for (int n = 0 ; n < 8 ; n++) {
2415       sim_debug (DBG_REGDUMPPR, &cpu_dev, "PR%d/%s: SNR=%05o RNR=%o WORDNO=%06o BITNO:%02o ARCHAR:%o ARBITNO:%02o\r\n",
2416                  n, PRalias[n], cpu.PR[n].SNR, cpu.PR[n].RNR, cpu.PR[n].WORDNO,
2417                  GET_PR_BITNO (n), GET_AR_CHAR (n), GET_AR_BITNO (n));
2418     }
2419     sim_debug (DBG_REGDUMPPPR, &cpu_dev, "PRR:%o PSR:%05o P:%o IC:%06o\r\n",
2420                cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
2421     sim_debug (DBG_REGDUMPDSBR, &cpu_dev, "ADDR:%08o BND:%05o U:%o STACK:%04o\r\n",
2422                cpu.DSBR.ADDR, cpu.DSBR.BND, cpu.DSBR.U, cpu.DSBR.STACK);
2423   }
2424 
2425 ///
2426 /// executeInstruction: done. (Whew!)
2427 ///
2428 
2429   return ret;
2430 }
2431 
2432 t_stat executeInstructionFast (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
2433   {
2434     return executeInstruction_ (cpup, false);
2435   }
2436 
2437 t_stat executeInstructionFull (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
2438   {
2439     return executeInstruction_ (cpup, true);
2440   }
2441 
2442 //static t_stat DoBasicInstruction (void);
2443 //static t_stat DoEISInstruction (void);
2444 
2445 static inline void overflow (cpu_state_t * cpup, bool ovf, bool dly, const char * msg)
     /* [previous][next][first][last][top][bottom][index][help] */
2446   {
2447     CPT (cpt2L, 15); // overflow check
2448     // If an overflow occurred and the repeat instruction is not inhibiting
2449     // overflow checking.
2450     if (ovf && chkOVF (cpup))
2451       {
2452         SET_I_OFLOW;
2453         // If overflows are not masked
2454         if (tstOVFfault (cpup))
2455           {
2456             CPT (cpt2L, 16); // overflow
2457             // ISOLTS test ps768: Overflows set TRO.
2458             if (cpu.cu.rpt || cpu.cu.rd || cpu.cu.rl)
2459               {
2460                 SET_I_TALLY;
2461               }
2462             if (dly)
2463               dlyDoFault (FAULT_OFL, fst_zero, msg);
2464             else
2465               doFault (FAULT_OFL, fst_zero, msg);
2466           }
2467       }
2468   }
2469 
2470 // Return values
2471 //  CONT_TRA
2472 //  STOP_UNIMP
2473 //  STOP_ILLOP
2474 //  emCall()
2475 //     STOP_HALT
2476 //  scu_sscr()
2477 //     STOP_BUG
2478 //     STOP_WARN
2479 //  scu_rmcm()
2480 //     STOP_BUG
2481 //  scu_smcm()
2482 //  STOP_DIS
2483 //  simh_hooks()
2484 //    hard to document what this can return....
2485 //  0
2486 //
2487 
2488 // CANFAULT
2489 HOT static t_stat doInstruction (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
2490 {
2491     DCDstruct * i = & cpu.currentInstruction;
2492     // AL39 says it is always cleared, but that makes no sense (what good
2493     // is an indicator bit if it is always 0 when you check it?). Clear it if
2494     // an multiword EIS is at bat.
2495     // NB: Never clearing it renders Multics unbootable.
2496     if (i->info->ndes > 0)
2497       CLR_I_MIF;
2498 
2499     L68_ (
2500       cpu.ou.eac = 0;
2501       cpu.ou.RB1_FULL = 0;
2502       cpu.ou.RP_FULL = 0;
2503       cpu.ou.RS_FULL = 0;
2504       cpu.ou.STR_OP = 0;
2505       cpu.ou.cycle = 0;
2506     )
2507     // The L68 OU history register records RS (PM700 01M), so keep it in
2508     // every build, not only PANEL68
2509     L68_ (cpu.ou.RS = (word9) i->opcode;)
2510     PNL (L68_ (DU_CYCLE_FDUD;)) // set DU idle
2511     cpu.skip_cu_hist = false;
2512 
2513     //memcpy (& cpu.MR_cache, & cpu.MR, sizeof (cpu.MR_cache));
2514     // Only these MR fields are actually used by the history logic.
2515     // Snapshot them now without copying the entire register. The L68 CU
2516     // history reads O.C$ (bit 29) and the OPCODE field (18-27) from r
2517     // (PM700 02Y); without this r was stale from the last OC trap.
2518     cpu.MR_cache.r     = cpu.MR.r;
2519     cpu.MR_cache.emr   = cpu.MR.emr;
2520     cpu.MR_cache.ihr   = cpu.MR.ihr;
2521     cpu.MR_cache.hrxfr = cpu.MR.hrxfr;
2522 
2523 // This mapping keeps nonEIS/EIS ordering, making various tables cleaner
2524 #define x0(n) (n)
2525 #define x1(n) (n|01000)
2526 
2527     //t_stat ret =  i->opcodeX ? DoEISInstruction () : DoBasicInstruction ();
2528     uint32 opcode10 = i->opcode10;
2529 
2530 #if defined(PANEL68)
2531     if (insGrp [opcode10])
2532       {
2533         word8 grp = insGrp [opcode10] - 1;
2534         uint row  = grp / 36;
2535         uint col  = grp % 36;
2536         CPT (cpt3U + row, col); // 3U 0-35, 3L 0-17
2537       }
2538 #endif
2539     bool is_ou = false;
2540     bool is_du = false;
2541     if (cpu.tweaks.l68_mode) { // L68
2542       if (opcodes10[opcode10].reg_use & is_OU) {
2543         is_ou = true;
2544     // XXX Punt on RP FULL, RS FULL
2545         cpu.ou.RB1_FULL  = cpu.ou.RP_FULL = cpu.ou.RS_FULL = 1;
2546         cpu.ou.cycle    |= ou_GIN;
2547 #if defined(PANEL68)
2548         cpu.ou.opsz      = (opcodes10[i->opcode10].reg_use >> 12) & 037;
2549         word10 reguse    = (opcodes10[i->opcode10].reg_use) & MASK10;
2550         cpu.ou.reguse    = reguse;
2551         if (reguse & ru_A)  CPT (cpt5U, 4);
2552         if (reguse & ru_Q)  CPT (cpt5U, 5);
2553         if (reguse & ru_X0) CPT (cpt5U, 6);
2554         if (reguse & ru_X1) CPT (cpt5U, 7);
2555         if (reguse & ru_X2) CPT (cpt5U, 8);
2556         if (reguse & ru_X3) CPT (cpt5U, 9);
2557         if (reguse & ru_X4) CPT (cpt5U, 10);
2558         if (reguse & ru_X5) CPT (cpt5U, 11);
2559         if (reguse & ru_X6) CPT (cpt5U, 12);
2560         if (reguse & ru_X7) CPT (cpt5U, 13);
2561 #endif // PANEL68
2562       }
2563       if (opcodes10[opcode10].reg_use & is_DU) {
2564         is_du = true;
2565         PNL (DU_CYCLE_nDUD;) // set not idle
2566       }
2567     }
2568 
2569     switch (opcode10)
2570       {
2571 // Operations sorted by frequency of use; should help with caching issues
2572 
2573 // Operations counts from booting and build a boot tape from source:
2574 //          1605873148: eppn
2575 //           845109778: sprin
2576 //           702257337: lda
2577 //           637613648: tra
2578 //           555520875: ldq
2579 //           462569862: tze
2580 //           322979813: tnz
2581 //           288200618: stq
2582 //           260400300: cmpq
2583 //           192454329: anaq
2584 //           187283749: sta
2585 //           170691055: lprpn
2586 //           167568868: eaxn
2587 //           166842812: tsxn
2588 //           161542573: stz
2589 //           155129792: epbpn
2590 //           153639462: cmpa
2591 //           144804232: aos
2592 //           133559646: cana
2593 //           127230192: ldaq
2594 //           119988496: tpnz
2595 //           113295654: lxln
2596 //           109645303: staq
2597 //           109417021: tspn
2598 //           108352453: als
2599 //            96267840: rtcd
2600 //            93570029: tmi
2601 //            93161815: stxn
2602 //            90485871: ldi
2603 //            87421892: eraq
2604 //            76632891: ora
2605 //            75372023: adq
2606 //            75036448: tmoz
2607 //            64921645: spbpn
2608 //            63595794: ana
2609 //            62621406: fld
2610 //            57281513: epaq
2611 //            56066122: qls
2612 //            55861962: sti
2613 //            55186331: mlr
2614 //            54388393: call6
2615 //            50000721: lrl
2616 //            49736026: sbq
2617 //            49552594: tpl
2618 //            46097756: cmpb
2619 //            44484993: szn
2620 //            41295856: arl
2621 //            40019677: lrs
2622 //            39386119: sprpn
2623 //            36130580: ldxn
2624 //            32168708: ersa
2625 //            31817270: cmpxn
2626 //            31280696: a9bd
2627 //            29383886: era
2628 //            29282465: lls
2629 //            28714658: mpy
2630 //            28508378: sba
2631 //            24067324: anq
2632 //            23963178: asq
2633 //            23953122: nop
2634 //            23643534: orsa
2635 //            23083282: csl
2636 //            20970795: sbxn
2637 //            20109045: tct
2638 //            18504719: stba
2639 //            18297461: eaq
2640 //            17130040: eaa
2641 //            16035441: cmpc
2642 //            15762874: sxln
2643 //            15109836: lca
2644 //            15013924: adxn
2645 //            14159104: lcq
2646 //            14049597: div
2647 //            14043543: cmpaq
2648 //            13528591: ada
2649 //            12778888: ansa
2650 //            12534711: trc
2651 //            11710149: sbaq
2652 //            11584853: neg
2653 //            11456885: ttn
2654 //            11356918: canq
2655 //            10797383: rccl
2656 //            10743245: asa
2657 //            10100949: ttf
2658 //             9691628: orq
2659 //             9332512: adwp0-3
2660 //             9251904: anxn
2661 //             8076030: ldac
2662 //             8061536: scd
2663 //             7779639: adaq
2664 //             7586713: xec
2665 //             7506406: qrl
2666 //             7442522: adl
2667 //             6535658: stca
2668 //             6359531: adlxn
2669 //             6255134: sbla
2670 //             5936484: stacq
2671 //             5673345: eawp2
2672 //             4671545: tnc
2673 //             4230412: scm
2674 //             4040255: sarn
2675 //             4006015: oraq
2676 //             3918690: adlq
2677 //             3912600: stbq
2678 //             3449053: lcxn
2679 //             3368670: adla
2680 //             3290057: qrs
2681 //             3252438: ars
2682 //             3143543: qlr
2683 //             3098158: stac
2684 //             2838451: mvne
2685 //             2739787: lde
2686 //             2680484: btd
2687 //             2573170: erq
2688 //             2279433: fno
2689 //             2273692: smcm
2690 //             2240713: ersq
2691 //             2173455: sreg
2692 //             2173196: lreg
2693 //             2112784: mrl
2694 //             2030237: mvt
2695 //             2010819: stc2
2696 //             2008675: fmp
2697 //             1981148: llr
2698 //             1915081: mvn
2699 //             1846728: sblxn
2700 //             1820604: fcmp
2701 //             1765253: lcpr
2702 //             1447485: stc1
2703 //             1373184: ansxn
2704 //             1337744: negl
2705 //             1264062: rscr
2706 //             1201563: adwp4-7
2707 //             1198321: rmcm
2708 //             1182814: sznc
2709 //             1171307: sblq
2710 //             1140227: spri
2711 //             1139968: lpri
2712 //             1133946: dvf
2713 //             1059600: scpr
2714 //              958321: stcq
2715 //              837695: tctr
2716 //              820615: s9bd
2717 //              812523: rsw
2718 //              769275: fad
2719 //              729737: orsq
2720 //              651623: scu
2721 //              651612: rcu
2722 //              606518: abd
2723 //              603591: eawp1
2724 //              555935: orsxn
2725 //              525680: scmr
2726 //              467605: spl
2727 //              467405: lpl
2728 //              463927: lra
2729 //              416700: awd
2730 //              384090: dtb
2731 //              383544: cmk
2732 //              382254: fst
2733 //              378820: ssa
2734 //              370308: sra
2735 //              326432: alr
2736 //              321319: ldt
2737 //              319911: ldbr
2738 //              319908: sbar
2739 //              319907: lbar
2740 //              310379: cams
2741 //              303041: eawp7
2742 //              299122: xed
2743 //              294724: easp2
2744 //              270712: sztl
2745 //              252001: dfst
2746 //              241844: ste
2747 //              226970: absa
2748 //              218891: cioc
2749 //              184535: dfld
2750 //              182347: camp
2751 //              174567: ansq
2752 //              169317: rpt
2753 //              124972: erx2
2754 //              121933: fneg
2755 //              114697: cnaaq
2756 //              111728: rpd
2757 //              106892: dis
2758 //               96801: tov
2759 //               92283: fsb
2760 //               86209: erx4
2761 //               80564: eawp3
2762 //               76911: canaq
2763 //               65706: ufa
2764 //               65700: dfcmp
2765 //               64530: fdv
2766 //               48215: ldqc
2767 //               45994: dfad
2768 //               37790: awca
2769 //               27218: asxn
2770 //               23203: eawp5
2771 //               16947: gtb
2772 //               11431: ersxn
2773 //                9527: erx3
2774 //                8888: ssdr
2775 //                8888: ssdp
2776 //                8888: sptr
2777 //                8888: sptp
2778 //                8170: ssq
2779 //                7116: mp3d
2780 //                6969: cmg
2781 //                6878: dv3d
2782 //                5615: eawp6
2783 //                4859: easp1
2784 //                4726: easp3
2785 //                3157: ad2d
2786 //                2807: eawp4
2787 //                2807: easp4
2788 //                2411: cwl
2789 //                1912: teu
2790 //                1912: teo
2791 //                1798: cmpn
2792 //                1625: easp6
2793 //                 931: adlaq
2794 //                 659: erx1
2795 //                 500: ???
2796 //                 388: csr
2797 //                 215: sb3d
2798 //                 176: dfdv
2799 //                  93: stcd
2800 //                  92: mp2d
2801 //                  41: sscr
2802 //                  26: dfmp
2803 //                  14: ad3d
2804 //                  12: mve
2805 //                  11: dfsb
2806 //                   5: sdbr
2807 //                   4: trtf
2808 //                   4: orxn
2809 //                   3: sb2d
2810 //                   2: scdr
2811 //                   1: stt
2812 //                   1: ret
2813 //                   1: drl
2814 
2815         case x0 (0350):  // epp0
2816         case x1 (0351):  // epp1
2817         case x0 (0352):  // epp2
2818         case x1 (0353):  // epp3
2819         case x0 (0370):  // epp4
2820         case x1 (0371):  // epp5
2821         case x0 (0372):  // epp6
2822         case x1 (0373):  // epp7
2823           // For n = 0, 1, ..., or 7 as determined by operation code
2824           //   C(TPR.TRR) -> C(PRn.RNR)
2825           //   C(TPR.TSR) -> C(PRn.SNR)
2826           //   C(TPR.CA) -> C(PRn.WORDNO)
2827           //   C(TPR.TBR) -> C(PRn.BITNO)
2828           {
2829             // epp0 0350  101 000
2830             // epp1 1351  101 001
2831             // epp2 0352  101 010
2832             // epp3 1353  101 011
2833             // epp4 0370  111 000
2834             // epp5 1371  111 001
2835             // epp6 0372  111 010
2836             // epp7 1373  111 011
2837             //n = ((opcode10 & 020) ? 4 : 0) + (opcode10 & 03);
2838             uint n = ((opcode10 & 020) >> 2) | (opcode10 & 03);
2839             CPTUR (cptUsePRn + n);
2840             cpu.PR[n].RNR    = cpu.TPR.TRR;
2841             cpu.PR[n].SNR    = cpu.TPR.TSR;
2842             cpu.PR[n].WORDNO = cpu.TPR.CA;
2843             SET_PR_BITNO (n, cpu.TPR.TBR);
2844 #if defined(TESTING)
2845             HDBGRegPRW (n, "epp");
2846 #endif
2847           }
2848           break;
2849 
2850         case x0 (0250):  // spri0
2851         case x1 (0251):  // spri1
2852         case x0 (0252):  // spri2
2853         case x1 (0253):  // spri3
2854         case x0 (0650):  // spri4
2855         case x1 (0651):  // spri5
2856         case x0 (0652):  // spri6
2857         case x1 (0653):  // spri7
2858 
2859           // For n = 0, 1, ..., or 7 as determined by operation code
2860           //  000 -> C(Y-pair)0,2
2861           //  C(PRn.SNR) -> C(Y-pair)3,17
2862           //  C(PRn.RNR) -> C(Y-pair)18,20
2863           //  00...0 -> C(Y-pair)21,29
2864           //  (43)8 -> C(Y-pair)30,35
2865           //  C(PRn.WORDNO) -> C(Y-pair)36,53
2866           //  000 -> C(Y-pair)54,56
2867           //  C(PRn.BITNO) -> C(Y-pair)57,62
2868           //  00...0 -> C(Y-pair)63,71
2869           {
2870             // spri0 0250 0 010 101 000
2871             // spri1 1251 1 010 101 001
2872             // spri2 0252 0 010 101 010
2873             // spri3 1253 1 010 101 011
2874             // spri4 0650 0 110 101 000
2875             // spri5 1651 1 110 101 001
2876             // spri6 0652 0 110 101 010
2877             // spri7 1653 1 110 101 011
2878             //uint n = ((opcode10 & 0400) ? 4 : 0) + (opcode10 & 03);
2879             uint n = ((opcode10 & 0400) >> 6) | (opcode10 & 03);
2880             CPTUR (cptUsePRn + n);
2881 #if defined(TESTING)
2882             HDBGRegPRR (n, "spri");
2883 #endif
2884             cpu.Ypair[0]  = 043;
2885             cpu.Ypair[0] |= ((word36) cpu.PR[n].SNR) << 18;
2886             cpu.Ypair[0] |= ((word36) cpu.PR[n].RNR) << 15;
2887 
2888             cpu.Ypair[1]  = (word36) cpu.PR[n].WORDNO << 18;
2889             cpu.Ypair[1] |= (word36) GET_PR_BITNO (n) << 9;
2890           }
2891           break;
2892 
2893         case x0 (0235):  // lda
2894           cpu.rA = cpu.CY;
2895 #if defined(TESTING)
2896           HDBGRegAW ("lda");
2897 #endif
2898           SC_I_ZERO (cpu.rA == 0);
2899           SC_I_NEG (cpu.rA & SIGN36);
2900           break;
2901 
2902         case x0 (0710):  // tra
2903           // C(TPR.CA) -> C(PPR.IC)
2904           // C(TPR.TSR) -> C(PPR.PSR)
2905           do_caf (cpup);
2906           read_tra_op (cpup);
2907           return CONT_TRA;
2908 
2909         case x0 (0236):  // ldq
2910           cpu.rQ = cpu.CY;
2911 #if defined(TESTING)
2912           HDBGRegQW ("ldq");
2913 #endif
2914           SC_I_ZERO (cpu.rQ == 0);
2915           SC_I_NEG (cpu.rQ & SIGN36);
2916           break;
2917 
2918         case x0 (0600):  // tze
2919           // If zero indicator ON then
2920           //   C(TPR.CA) -> C(PPR.IC)
2921           //   C(TPR.TSR) -> C(PPR.PSR)
2922           // otherwise, no change to C(PPR)
2923           if (TST_I_ZERO)
2924             {
2925               do_caf (cpup);
2926               read_tra_op (cpup);
2927               return CONT_TRA;
2928             }
2929           break;
2930 
2931         case x0 (0601):  // tnz
2932           // If zero indicator OFF then
2933           //     C(TPR.CA) -> C(PPR.IC)
2934           //     C(TPR.TSR) -> C(PPR.PSR)
2935           if (!TST_I_ZERO)
2936             {
2937               do_caf (cpup);
2938               read_tra_op (cpup);
2939               return CONT_TRA;
2940             }
2941           break;
2942 
2943         case x0 (0756): // stq
2944           cpu.CY = cpu.rQ;
2945 #if defined(TESTING)
2946           HDBGRegQR ("stq");
2947 #endif
2948           break;
2949 
2950         case x0 (0116):  // cmpq
2951           // C(Q) :: C(Y)
2952           cmp36 (cpup, cpu.rQ, cpu.CY, &cpu.cu.IR);
2953 #if defined(TESTING)
2954           HDBGRegQR ("cmpq");
2955 #endif
2956           break;
2957 
2958         case x0 (0377):  //< anaq
2959           // C(AQ)i & C(Y-pair)i -> C(AQ)i for i = (0, 1, ..., 71)
2960           {
2961               word72 tmp72 = YPAIRTO72 (cpu.Ypair);
2962               word72 trAQ = convert_to_word72 (cpu.rA, cpu.rQ);
2963 #if defined(TESTING)
2964               HDBGRegAR ("anaq");
2965               HDBGRegQR ("anaq");
2966 #endif
2967 #if defined(NEED_128)
2968               trAQ = and_128 (trAQ, tmp72);
2969               trAQ = and_128 (trAQ, MASK72);
2970 
2971               SC_I_ZERO (iszero_128 (trAQ));
2972               SC_I_NEG (isnonzero_128 (and_128 (trAQ, SIGN72)));
2973 #else
2974               trAQ = trAQ & tmp72;
2975               trAQ &= MASK72;
2976 
2977               SC_I_ZERO (trAQ == 0);
2978               SC_I_NEG (trAQ & SIGN72);
2979 #endif
2980               convert_to_word36 (trAQ, &cpu.rA, &cpu.rQ);
2981 #if defined(TESTING)
2982               HDBGRegAW ("anaq");
2983               HDBGRegQW ("anaq");
2984 #endif
2985           }
2986           break;
2987 
2988         case x0 (0755):  // sta
2989           cpu.CY = cpu.rA;
2990 #if defined(TESTING)
2991           HDBGRegAR ("sta");
2992 #endif
2993           break;
2994 
2995                          // lprpn
2996         case x0 (0760):  // lprp0
2997         case x0 (0761):  // lprp1
2998         case x0 (0762):  // lprp2
2999         case x0 (0763):  // lprp3
3000         case x0 (0764):  // lprp4
3001         case x0 (0765):  // lprp5
3002         case x0 (0766):  // lprp6
3003         case x0 (0767):  // lprp7
3004           // For n = 0, 1, ..., or 7 as determined by operation code
3005           //  C(TPR.TRR) -> C(PRn.RNR)
3006           //  If C(Y)0,1 != 11, then
3007           //    C(Y)0,5 -> C(PRn.BITNO);
3008           //  otherwise,
3009           //    generate command fault
3010           // If C(Y)6,17 = 11...1, then 111 -> C(PRn.SNR)0,2
3011           //  otherwise,
3012           // 000 -> C(PRn.SNR)0,2
3013           // C(Y)6,17 -> C(PRn.SNR)3,14
3014           // C(Y)18,35 -> C(PRn.WORDNO)
3015           {
3016               uint32 n = opcode10 & 07;  // get n
3017               CPTUR (cptUsePRn + n);
3018               cpu.PR[n].RNR = cpu.TPR.TRR;
3019 
3020 // [CAC] sprpn says: If C(PRn.SNR) 0,2 are nonzero, and C(PRn.SNR) != 11...1,
3021 // then a store fault (illegal pointer) will occur and C(Y) will not be changed.
3022 // I interpret this has meaning that only the high bits should be set here
3023 
3024               if (((cpu.CY >> 34) & 3) != 3)
3025                 {
3026                   word6 bitno = (cpu.CY >> 30) & 077;
3027                   SET_PR_BITNO (n, bitno);
3028                 }
3029               else
3030                 {
3031 // fim.alm
3032 // command_fault:
3033 //           eax7      com       assume normal command fault
3034 //           ldq       bp|mc.scu.port_stat_word check illegal action
3035 //           canq      scu.ial_mask,dl
3036 //           tnz       fixindex            nonzero, treat as normal case
3037 //           ldq       bp|scu.even_inst_word check for LPRPxx instruction
3038 //           anq       =o770400,dl
3039 //           cmpq      lprp_insts,dl
3040 //           tnz       fixindex            isn't LPRPxx, treat as normal
3041 
3042 // ial_mask is checking SCU word 1, field IA: 0 means "no illegal action"
3043 
3044                     // Therefore the subfault well no illegal action, and
3045                     // Multics will peek it the instruction to deduce that it
3046                     // is a lprpn fault.
3047                   doFault (FAULT_CMD, fst_cmd_lprpn, "lprpn");
3048                 }
3049 // The SPRPn instruction stores only the low 12 bits of the 15 bit SNR.
3050 // A special case is made for an SNR of all ones; it is stored as 12 1's.
3051 // The pcode in AL39 handles this awkwardly; I believe this is
3052 // the same, but in a more straightforward manner
3053 
3054              // Get the 12 bit operand SNR
3055              word12 oSNR = getbits36_12 (cpu.CY, 6);
3056              // Test for special case
3057              if (oSNR == 07777)
3058                cpu.PR[n].SNR = 077777;
3059              else
3060                cpu.PR[n].SNR = oSNR; // unsigned word will 0-extend.
3061               //C(Y)18,35 -> C(PRn.WORDNO)
3062               cpu.PR[n].WORDNO = GETLO (cpu.CY);
3063 
3064               sim_debug (DBG_APPENDING, & cpu_dev,
3065                          "lprp%d CY 0%012"PRIo64", PR[n].RNR 0%o, "
3066                          "PR[n].BITNO 0%o, PR[n].SNR 0%o, PR[n].WORDNO %o\r\n",
3067                          n, cpu.CY, cpu.PR[n].RNR, GET_PR_BITNO (n),
3068                          cpu.PR[n].SNR, cpu.PR[n].WORDNO);
3069 #if defined(TESTING)
3070               HDBGRegPRW (n, "lprp");
3071 #endif
3072           }
3073           break;
3074 
3075                          // eaxn
3076         case x0 (0620):  // eax0
3077         case x0 (0621):  // eax1
3078         case x0 (0622):  // eax2
3079         case x0 (0623):  // eax3
3080         case x0 (0624):  // eax4
3081         case x0 (0625):  // eax5
3082         case x0 (0626):  // eax6
3083         case x0 (0627):  // eax7
3084           {
3085             uint32 n = opcode10 & 07;  // get n
3086             cpu.rX[n] = cpu.TPR.CA;
3087 #if defined(TESTING)
3088             HDBGRegXW (n, "eaxn");
3089 #endif
3090 
3091             SC_I_ZERO (cpu.TPR.CA == 0);
3092             SC_I_NEG (cpu.TPR.CA & SIGN18);
3093 
3094           }
3095           break;
3096 
3097                          // tsxn
3098         case x0 (0700):  // tsx0
3099         case x0 (0701):  // tsx1
3100         case x0 (0702):  // tsx2
3101         case x0 (0703):  // tsx3
3102         case x0 (0704):  // tsx4
3103         case x0 (0705):  // tsx5
3104         case x0 (0706):  // tsx6
3105         case x0 (0707):  // tsx7
3106           // For n = 0, 1, ..., or 7 as determined by operation code
3107           //   C(PPR.IC) + 1 -> C(Xn)
3108           // C(TPR.CA) -> C(PPR.IC)
3109           // C(TPR.TSR) -> C(PPR.PSR)
3110           {
3111             // We can't set Xn yet as the CAF may refer to Xn
3112             word18 ret = (cpu.PPR.IC + 1) & MASK18;
3113             do_caf (cpup);
3114             read_tra_op (cpup);
3115             cpu.rX[opcode10 & 07] = ret;
3116 #if defined(TESTING)
3117             HDBGRegXW (opcode10 & 07, "tsxn");
3118 #endif
3119           }
3120           return CONT_TRA;
3121 
3122         case x0 (0450): // stz
3123           cpu.CY = 0;
3124           break;
3125 
3126                          // epbpn
3127         case x1 (0350):  // epbp0
3128         case x0 (0351):  // epbp1
3129         case x1 (0352):  // epbp2
3130         case x0 (0353):  // epbp3
3131         case x1 (0370):  // epbp4
3132         case x0 (0371):  // epbp5
3133         case x1 (0372):  // epbp6
3134         case x0 (0373):  // epbp7
3135           // For n = 0, 1, ..., or 7 as determined by operation code
3136           //  C(TPR.TRR) -> C(PRn.RNR)
3137           //  C(TPR.TSR) -> C(PRn.SNR)
3138           //  00...0 -> C(PRn.WORDNO)
3139           //  0000 -> C(PRn.BITNO)
3140           {
3141             // epbp0 1350 101 000
3142             // epbp1 0351 101 000
3143             // epbp2 1352 101 000
3144             // epbp3 0353 101 000
3145             // epbp4 1370 111 000
3146             // epbp4 0371 111 000
3147             // epbp6 1372 111 000
3148             // epbp7 0373 111 000
3149             //n = ((opcode10 & 020) ? 4 : 0) + (opcode10 & 03);
3150             uint n = ((opcode10 & 020) >> 2) | (opcode10 & 03);
3151             CPTUR (cptUsePRn + n);
3152             cpu.PR[n].RNR    = cpu.TPR.TRR;
3153             cpu.PR[n].SNR    = cpu.TPR.TSR;
3154             cpu.PR[n].WORDNO = 0;
3155             SET_PR_BITNO (n, 0);
3156 #if defined(TESTING)
3157             HDBGRegPRW (n, "epbp");
3158 #endif
3159           }
3160           break;
3161 
3162         case x0 (0115):  // cmpa
3163           // C(A) :: C(Y)
3164           cmp36 (cpup, cpu.rA, cpu.CY, &cpu.cu.IR);
3165 #if defined(TESTING)
3166           HDBGRegAR ("cmpa");
3167 #endif
3168           break;
3169 
3170         case x0 (0054):   // aos
3171           {
3172             // C(Y)+1->C(Y)
3173 
3174             L68_ (cpu.ou.cycle |= ou_GOS;)
3175             bool ovf;
3176             cpu.CY = Add36b (cpup, cpu.CY, 1, 0, I_ZNOC,
3177                                  & cpu.cu.IR, & ovf);
3178             overflow (cpup, ovf, true, "aos overflow fault");
3179           }
3180           break;
3181 
3182         case x0 (0315):  // cana
3183           // C(Z)i = C(A)i & C(Y)i for i = (0, 1, ..., 35)
3184           {
3185 #if defined(TESTING)
3186             HDBGRegAR ("cana");
3187 #endif
3188             word36 trZ = cpu.rA & cpu.CY;
3189             trZ &= MASK36;
3190 
3191             SC_I_ZERO (trZ == 0);
3192             SC_I_NEG (trZ & SIGN36);
3193           }
3194           break;
3195 
3196         case x0 (0237):  // ldaq
3197           cpu.rA = cpu.Ypair[0];
3198 #if defined(TESTING)
3199           HDBGRegAW ("ldaq");
3200 #endif
3201           cpu.rQ = cpu.Ypair[1];
3202 #if defined(TESTING)
3203           HDBGRegQW ("ldaq");
3204 #endif
3205           SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0)
3206           SC_I_NEG (cpu.rA & SIGN36);
3207           break;
3208 
3209         case x1 (0605):  // tpnz
3210             // If negative and zero indicators are OFF then
3211             //  C(TPR.CA) -> C(PPR.IC)
3212             //  C(TPR.TSR) -> C(PPR.PSR)
3213             if (! (cpu.cu.IR & I_NEG) && ! (cpu.cu.IR & I_ZERO))
3214             {
3215                 do_caf (cpup);
3216                 read_tra_op (cpup);
3217                 return CONT_TRA;
3218             }
3219             break;
3220 
3221                          // lxln
3222         case x0 (0720):  // lxl0
3223         case x0 (0721):  // lxl1
3224         case x0 (0722):  // lxl2
3225         case x0 (0723):  // lxl3
3226         case x0 (0724):  // lxl4
3227         case x0 (0725):  // lxl5
3228         case x0 (0726):  // lxl6
3229         case x0 (0727):  // lxl7
3230           {
3231             uint32 n = opcode10 & 07;  // get n
3232             cpu.rX[n] = GETLO (cpu.CY);
3233 #if defined(TESTING)
3234             HDBGRegXW (n, "lxln");
3235 #endif
3236             SC_I_ZERO (cpu.rX[n] == 0);
3237             SC_I_NEG (cpu.rX[n] & SIGN18);
3238           }
3239           break;
3240 
3241         case x0 (0757):  // staq
3242           cpu.Ypair[0] = cpu.rA;
3243           cpu.Ypair[1] = cpu.rQ;
3244           break;
3245 
3246                          // tspn
3247         case x0 (0270):  // tsp0
3248         case x0 (0271):  // tsp1
3249         case x0 (0272):  // tsp2
3250         case x0 (0273):  // tsp3
3251         case x0 (0670):  // tsp4
3252         case x0 (0671):  // tsp5
3253         case x0 (0672):  // tsp6
3254         case x0 (0673):  // tsp7
3255           // For n = 0, 1, ..., or 7 as determined by operation code
3256           //  C(PPR.PRR) -> C(PRn.RNR)
3257           //  C(PPR.PSR) -> C(PRn.SNR)
3258           //  C(PPR.IC) + 1 -> C(PRn.WORDNO)
3259           //  00...0 -> C(PRn.BITNO)
3260           //  C(TPR.CA) -> C(PPR.IC)
3261           //  C(TPR.TSR) -> C(PPR.PSR)
3262           {
3263 #if defined(PANEL68)
3264             uint32 n;
3265             if (opcode10 <= 0273)
3266               n = (opcode10 & 3);
3267             else
3268               n = (opcode10 & 3) + 4;
3269             CPTUR (cptUsePRn + n);
3270 #endif
3271 
3272             do_caf (cpup);
3273             // PR[n] is set in read_tra_op().
3274             read_tra_op (cpup);
3275           }
3276           return CONT_TRA;
3277 
3278         case x0 (0735):  // als
3279           {
3280 #if defined(TESTING)
3281             HDBGRegAR ("als");
3282 #endif
3283 #if BARREL_SHIFTER
3284             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
3285 
3286             // Capture the bits shifted through A0
3287             word36 capture;
3288             // If count is > 36, than all of the bits will rotate through A
3289             if (cnt < 36) {
3290               // +1 is A0 plus the bits that will get shifted into A0
3291               capture = cpu.rA & barrelLeftMaskTable[cnt + 1];
3292 
3293               // Do the shift
3294               cpu.rA <<= cnt;
3295               cpu.rA &= DMASK;    // keep to 36-bits
3296 
3297               // If the captured bits are all 0 or all 1, then
3298               // A0 will not have changed during the rotate
3299 
3300             } else {
3301               capture = cpu.rA;
3302               cpu.rA = 0;
3303               cnt = 35;
3304             }
3305 
3306             if (capture == 0 || capture == (MASK36 & barrelLeftMaskTable[cnt + 1]))
3307               CLR_I_CARRY;
3308             else
3309               SET_I_CARRY;
3310 #else // !BARREL_SHIFTER
3311             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
3312 
3313             word36 tmpSign = cpu.rA & SIGN36;
3314             CLR_I_CARRY;
3315 
3316             for (uint j = 0; j < tmp36; j ++)
3317               {
3318                 cpu.rA <<= 1;
3319                 if (tmpSign != (cpu.rA & SIGN36))
3320                   SET_I_CARRY;
3321               }
3322             cpu.rA &= DMASK;    // keep to 36-bits
3323 #endif // BARREL_SHIFTER
3324 #if defined(TESTING)
3325             HDBGRegAW ("als");
3326 #endif
3327 
3328             SC_I_ZERO (cpu.rA == 0);
3329             SC_I_NEG (cpu.rA & SIGN36);
3330           }
3331           break;
3332 
3333         case x0 (0610):  // rtcd
3334           // If an access violation fault occurs when fetching the SDW for
3335           // the Y-pair, the C(PPR.PSR) and C(PPR.PRR) are not altered.
3336 
3337           do_caf (cpup);
3338           Read2RTCDOperandFetch (cpup, cpu.TPR.CA, cpu.Ypair);
3339           // RTCD always ends up in append mode.
3340           set_addr_mode (cpup, APPEND_mode);
3341 
3342           return CONT_RET;
3343 
3344         case x0 (0604):  // tmi
3345           // If negative indicator ON then
3346           //  C(TPR.CA) -> C(PPR.IC)
3347           //  C(TPR.TSR) -> C(PPR.PSR)
3348           if (TST_I_NEG)
3349             {
3350               do_caf (cpup);
3351               read_tra_op (cpup);
3352               return CONT_TRA;
3353             }
3354           break;
3355 
3356                          // stxn
3357         case x0 (0740):  // stx0
3358         case x0 (0741):  // stx1
3359         case x0 (0742):  // stx2
3360         case x0 (0743):  // stx3
3361         case x0 (0744):  // stx4
3362         case x0 (0745):  // stx5
3363         case x0 (0746):  // stx6
3364         case x0 (0747):  // stx7
3365           {
3366             uint32 n = opcode10 & 07;  // get n
3367             //SETHI (cpu.CY, cpu.rX[n]);
3368             cpu.CY      = ((word36) cpu.rX[n]) << 18;
3369             cpu.zone    = 0777777000000;
3370             cpu.useZone = true;
3371           }
3372           break;
3373 
3374         case x0 (0634):  // ldi
3375           {
3376             CPTUR (cptUseIR);
3377             // C(Y)18,31 -> C(IR)
3378 
3379             // Indicators:
3380             //  Parity Mask:
3381             //      If C(Y)27 = 1, and the processor is in absolute or
3382             //      instruction privileged mode, then ON; otherwise OFF.
3383             //      This indicator is not affected in the normal or BAR modes.
3384             //  Not BAR mode:
3385             //      Cannot be changed by the ldi instruction
3386             //  MIF:
3387             //      If C(Y)30 = 1, and the processor is in absolute or
3388             //      instruction privileged mode, then ON; otherwise OFF.
3389             //      This indicator is not affected in normal or BAR modes.
3390             //  Absolute mode:
3391             //      Cannot be changed by the ldi instruction
3392             //  All others: If corresponding bit in C(Y) is 1, then ON;
3393             //  otherwise, OFF
3394 
3395             // upper 14-bits of lower 18-bits
3396 
3397             // AL39 ldi says that HEX is ignored, but the mode register
3398             // description says that it isn't
3399             word18 tmp18;
3400             if (cpu.tweaks.l68_mode)
3401                tmp18 = GETLO (cpu.CY) & 0777760; // L68
3402             else
3403               tmp18 = GETLO (cpu.CY) & 0777770; // DPS8M
3404 
3405             bool bAbsPriv = is_priv_mode (cpup);
3406 
3407             SC_I_ZERO  (tmp18 & I_ZERO);
3408             SC_I_NEG   (tmp18 & I_NEG);
3409             SC_I_CARRY (tmp18 & I_CARRY);
3410             SC_I_OFLOW (tmp18 & I_OFLOW);
3411             SC_I_EOFL  (tmp18 & I_EOFL);
3412             SC_I_EUFL  (tmp18 & I_EUFL);
3413             SC_I_OMASK (tmp18 & I_OMASK);
3414             SC_I_TALLY (tmp18 & I_TALLY);
3415             SC_I_PERR  (tmp18 & I_PERR);
3416             // I_PMASK handled below
3417             // LDI cannot change I_NBAR
3418             SC_I_TRUNC (tmp18 & I_TRUNC);
3419             // I_MIF handled below
3420             // LDI cannot change I_ABS
3421             DPS8M_ (SC_I_HEX  (tmp18 & I_HEX);)
3422 
3423             if (bAbsPriv)
3424               {
3425                 SC_I_PMASK (tmp18 & I_PMASK);
3426                 SC_I_MIF (tmp18 & I_MIF);
3427               }
3428             else
3429               {
3430                 CLR_I_PMASK;
3431                 CLR_I_MIF;
3432               }
3433           }
3434           break;
3435 
3436         case x0 (0677):  // eraq
3437           // C(AQ)i XOR C(Y-pair)i -> C(AQ)i for i = (0, 1, ..., 71)
3438           {
3439 #if defined(TESTING)
3440             HDBGRegAR ("eraq");
3441             HDBGRegQR ("eraq");
3442 #endif
3443             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
3444             word72 trAQ = convert_to_word72 (cpu.rA, cpu.rQ);
3445 #if defined(NEED_128)
3446             trAQ = xor_128 (trAQ, tmp72);
3447             trAQ = and_128 (trAQ, MASK72);
3448 
3449             SC_I_ZERO (iszero_128 (trAQ));
3450             SC_I_NEG (isnonzero_128 (and_128 (trAQ, SIGN72)));
3451 #else
3452             trAQ = trAQ ^ tmp72;
3453             trAQ &= MASK72;
3454 
3455             SC_I_ZERO (trAQ == 0);
3456             SC_I_NEG (trAQ & SIGN72);
3457 #endif
3458 
3459             convert_to_word36 (trAQ, &cpu.rA, &cpu.rQ);
3460 #if defined(TESTING)
3461             HDBGRegAW ("eraq");
3462             HDBGRegQW ("eraq");
3463 #endif
3464           }
3465           break;
3466 
3467         case x0 (0275):  // ora
3468           // C(A)i | C(Y)i -> C(A)i for i = (0, 1, ..., 35)
3469 #if defined(TESTING)
3470           HDBGRegAR ("ora");
3471 #endif
3472           cpu.rA = cpu.rA | cpu.CY;
3473           cpu.rA &= DMASK;
3474 #if defined(TESTING)
3475           HDBGRegAW ("ora");
3476 #endif
3477 
3478           SC_I_ZERO (cpu.rA == 0);
3479           SC_I_NEG (cpu.rA & SIGN36);
3480           break;
3481 
3482         case x0 (0076):   // adq
3483           {
3484             L68_ (cpu.ou.cycle |= ou_GOS;)
3485             bool ovf;
3486 #if defined(TESTING)
3487             HDBGRegQR ("adq");
3488 #endif
3489             cpu.rQ = Add36b (cpup, cpu.rQ, cpu.CY, 0, I_ZNOC,
3490                                  & cpu.cu.IR, & ovf);
3491 #if defined(TESTING)
3492             HDBGRegQW ("adq");
3493 #endif
3494             overflow (cpup, ovf, false, "adq overflow fault");
3495           }
3496           break;
3497 
3498         case x1 (0604):  // tmoz
3499             // If negative or zero indicator ON then
3500             // C(TPR.CA) -> C(PPR.IC)
3501             // C(TPR.TSR) -> C(PPR.PSR)
3502             if (cpu.cu.IR & (I_NEG | I_ZERO))
3503               {
3504                 do_caf (cpup);
3505                 read_tra_op (cpup);
3506                 return CONT_TRA;
3507               }
3508             break;
3509 
3510         case x1 (0250):  // spbp0
3511         case x0 (0251):  // spbp1
3512         case x1 (0252):  // spbp2
3513         case x0 (0253):  // spbp3
3514         case x1 (0650):  // spbp4
3515         case x0 (0651):  // spbp5
3516         case x1 (0652):  // spbp6
3517         case x0 (0653):  // spbp7
3518             // For n = 0, 1, ..., or 7 as determined by operation code
3519             //  C(PRn.SNR) -> C(Y-pair)3,17
3520             //  C(PRn.RNR) -> C(Y-pair)18,20
3521             //  000 -> C(Y-pair)0,2
3522             //  00...0 -> C(Y-pair)21,29
3523             //  (43)8 -> C(Y-pair)30,35
3524             //  00...0 -> C(Y-pair)36,71
3525             {
3526               // spbp0 1250  010 101 000
3527               // spbp1 0251  010 101 001
3528               // spbp2 1252  010 101 010
3529               // spbp3 0253  010 101 011
3530               // spbp4 1650  110 101 000
3531               // spbp5 0651  110 101 001
3532               // spbp6 1652  110 101 010
3533               // spbp8 0653  110 101 011
3534               uint n = ((opcode10 & 0400) >> 6) | (opcode10 & 03);
3535               CPTUR (cptUsePRn + n);
3536               cpu.Ypair[0] = 043;
3537               cpu.Ypair[0] |= ((word36) cpu.PR[n].SNR) << 18;
3538               cpu.Ypair[0] |= ((word36) cpu.PR[n].RNR) << 15;
3539               cpu.Ypair[1] = 0;
3540             }
3541             break;
3542 
3543         case x0 (0375):  // ana
3544           // C(A)i & C(Y)i -> C(A)i for i = (0, 1, ..., 35)
3545 #if defined(TESTING)
3546           HDBGRegAR ("ana");
3547 #endif
3548           cpu.rA = cpu.rA & cpu.CY;
3549           cpu.rA &= DMASK;
3550 #if defined(TESTING)
3551           HDBGRegAW ("ana");
3552 #endif
3553           SC_I_ZERO (cpu.rA == 0);
3554           SC_I_NEG (cpu.rA & SIGN36);
3555           break;
3556 
3557         case x0 (0431):  // fld
3558           // C(Y)0,7 -> C(E)
3559           // C(Y)8,35 -> C(AQ)0,27
3560           // 00...0 -> C(AQ)30,71
3561           // Zero: If C(AQ) = 0, then ON; otherwise OFF
3562           // Neg: If C(AQ)0 = 1, then ON; otherwise OFF
3563 
3564           CPTUR (cptUseE);
3565           cpu.CY &= DMASK;
3566           cpu.rE = (cpu.CY >> 28) & 0377;
3567           cpu.rA = (cpu.CY & FLOAT36MASK) << 8;
3568 #if defined(TESTING)
3569           HDBGRegAW ("fld");
3570 #endif
3571           cpu.rQ = 0;
3572 #if defined(TESTING)
3573           HDBGRegQW ("fld");
3574 #endif
3575 
3576           SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
3577           SC_I_NEG (cpu.rA & SIGN36);
3578           break;
3579 
3580         case x0 (0213):  // epaq
3581           // 000 -> C(AQ)0,2
3582           // C(TPR.TSR) -> C(AQ)3,17
3583           // 00...0 -> C(AQ)18,32
3584           // C(TPR.TRR) -> C(AQ)33,35
3585 
3586           // C(TPR.CA) -> C(AQ)36,53
3587           // 00...0 -> C(AQ)54,65
3588           // C(TPR.TBR) -> C(AQ)66,71
3589 
3590           cpu.rA  = cpu.TPR.TRR & MASK3;
3591           cpu.rA |= (word36) (cpu.TPR.TSR & MASK15) << 18;
3592 #if defined(TESTING)
3593           HDBGRegAW ("epaq");
3594 #endif
3595 
3596           cpu.rQ  = cpu.TPR.TBR & MASK6;
3597           cpu.rQ |= (word36) (cpu.TPR.CA & MASK18) << 18;
3598 #if defined(TESTING)
3599           HDBGRegQW ("epaq");
3600 #endif
3601 
3602           SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
3603 
3604           break;
3605 
3606         case x0 (0736):  // qls
3607           // Shift C(Q) left the number of positions given in
3608           // C(TPR.CA)11,17; fill vacated positions with zeros.
3609           {
3610 #if defined(TESTING)
3611             HDBGRegQR ("qls");
3612 #endif
3613 #if BARREL_SHIFTER
3614             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
3615 
3616             // Capture the bits shifted through Q0
3617             word36 capture;
3618             // If count is > 36, than all of the bits will rotate through Q
3619             if (cnt < 36) {
3620               // +1 is Q0 plus the bits that will get shifted into Q0
3621               capture = cpu.rQ & barrelLeftMaskTable[cnt + 1];
3622 
3623               // Do the shift
3624               cpu.rQ <<= cnt;
3625               cpu.rQ &= DMASK;    // keep to 36-bits
3626 
3627               // If the captured bits are all 0 or all 1, then
3628               // Q0 will not have changed during the rotate
3629 
3630             } else {
3631               capture = cpu.rQ;
3632               cpu.rQ = 0;
3633             }
3634 
3635             if (capture == 0 || capture == (MASK36 & barrelLeftMaskTable[cnt + 1]))
3636               CLR_I_CARRY;
3637             else
3638               SET_I_CARRY;
3639 #else // !BARREL_SHIFTER
3640             word36 tmp36   = cpu.TPR.CA & 0177;   // CY bits 11-17
3641             word36 tmpSign = cpu.rQ & SIGN36;
3642             CLR_I_CARRY;
3643 
3644             for (uint j = 0; j < tmp36; j ++)
3645               {
3646                 cpu.rQ <<= 1;
3647                 if (tmpSign != (cpu.rQ & SIGN36))
3648                   SET_I_CARRY;
3649               }
3650             cpu.rQ &= DMASK;    // keep to 36-bits
3651 #endif // BARREL_SHIFTER
3652 #if defined(TESTING)
3653             HDBGRegQW ("qls");
3654 #endif
3655 
3656             SC_I_ZERO (cpu.rQ == 0);
3657             SC_I_NEG (cpu.rQ & SIGN36);
3658           }
3659           break;
3660 
3661         case x0 (0754): // sti
3662 
3663           // C(IR) -> C(Y)18,31
3664           // 00...0 -> C(Y)32,35
3665 
3666           // The contents of the indicator register after address
3667           // preparation are stored in C(Y)18,31  C(Y)18,31 reflects the
3668           // state of the tally runout indicator prior to address
3669           // preparation. The relation between C(Y)18,31 and the indicators
3670           // is given in Table 4-5.
3671 
3672           CPTUR (cptUseIR);
3673             // AL39 sti says that HEX is ignored, but the mode register
3674             // description says that it isn't
3675 
3676           //SETLO (cpu.CY, (cpu.cu.IR & 0000000777770LL));
3677           DPS8M_ (cpu.CY = cpu.cu.IR & 0000000777770LL; )
3678           //SETLO (cpu.CY, (cpu.cu.IR & 0000000777760LL));
3679           L68_ (cpu.CY = cpu.cu.IR & 0000000777760LL;)
3680 
3681           if (cpu.switches.procMode == procModeGCOS)
3682             cpu.CY = cpu.cu.IR & 0000000777600LL;
3683           cpu.zone    = 0000000777777;
3684           cpu.useZone = true;
3685           SCF (i->stiTally, cpu.CY, I_TALLY);
3686           break;
3687 
3688         ///    FIXED-POINT ARITHMETIC INSTRUCTIONS
3689 
3690         /// Fixed-Point Data Movement Load
3691 
3692         case x0 (0635):  // eaa
3693           cpu.rA = 0;
3694           SETHI (cpu.rA, cpu.TPR.CA);
3695 #if defined(TESTING)
3696           HDBGRegAW ("eea");
3697 #endif
3698           SC_I_ZERO (cpu.TPR.CA == 0);
3699           SC_I_NEG (cpu.TPR.CA & SIGN18);
3700 
3701           break;
3702 
3703         case x0 (0636):  // eaq
3704           cpu.rQ = 0;
3705           SETHI (cpu.rQ, cpu.TPR.CA);
3706 #if defined(TESTING)
3707           HDBGRegQW ("eaq");
3708 #endif
3709 
3710           SC_I_ZERO (cpu.TPR.CA == 0);
3711           SC_I_NEG (cpu.TPR.CA & SIGN18);
3712 
3713           break;
3714 
3715 // Optimized to the top of the loop
3716 //        case x0 (0620):  // eax0
3717 //        case x0 (0621):  // eax1
3718 //        case x0 (0622):  // eax2
3719 //        case x0 (0623):  // eax3
3720 //        case x0 (0624):  // eax4
3721 //        case x0 (0625):  // eax5
3722 //        case x0 (0626):  // eax6
3723 //        case x0 (0627):  // eax7
3724 
3725         case x0 (0335):  // lca
3726           {
3727             bool ovf;
3728             cpu.rA = compl36 (cpup, cpu.CY, & cpu.cu.IR, & ovf);
3729 #if defined(TESTING)
3730             HDBGRegAW ("lca");
3731 #endif
3732             overflow (cpup, ovf, false, "lca overflow fault");
3733           }
3734           break;
3735 
3736         case x0 (0336):  // lcq
3737           {
3738             bool ovf;
3739             cpu.rQ = compl36 (cpup, cpu.CY, & cpu.cu.IR, & ovf);
3740 #if defined(TESTING)
3741             HDBGRegQW ("lcq");
3742 #endif
3743             overflow (cpup, ovf, false, "lcq overflow fault");
3744           }
3745           break;
3746 
3747                          // lcxn
3748         case x0 (0320):  // lcx0
3749         case x0 (0321):  // lcx1
3750         case x0 (0322):  // lcx2
3751         case x0 (0323):  // lcx3
3752         case x0 (0324):  // lcx4
3753         case x0 (0325):  // lcx5
3754         case x0 (0326):  // lcx6
3755         case x0 (0327):  // lcx7
3756           {
3757             bool ovf;
3758             uint32 n  = opcode10 & 07;  // get n
3759             cpu.rX[n] = compl18 (cpup, GETHI (cpu.CY), & cpu.cu.IR, & ovf);
3760 #if defined(TESTING)
3761             HDBGRegXW (n, "lcxn");
3762 #endif
3763             overflow (cpup, ovf, false, "lcxn overflow fault");
3764           }
3765           break;
3766 
3767         case x0 (0337):  // lcaq
3768           {
3769             // The lcaq instruction changes the number to its negative while
3770             // moving it from Y-pair to AQ. The operation is executed by
3771             // forming the twos complement of the string of 72 bits. In twos
3772             // complement arithmetic, the value 0 is its own negative. An
3773             // overflow condition exists if C(Y-pair) = -2**71.
3774 
3775             if (cpu.Ypair[0] == 0400000000000LL && cpu.Ypair[1] == 0)
3776               {
3777                 cpu.rA = cpu.Ypair[0];
3778 #if defined(TESTING)
3779                 HDBGRegAW ("lcaq");
3780 #endif
3781                 cpu.rQ = cpu.Ypair[1];
3782 #if defined(TESTING)
3783                 HDBGRegQW ("lcaq");
3784 #endif
3785                 SET_I_NEG;
3786                 CLR_I_ZERO;
3787                 overflow (cpup, true, false, "lcaq overflow fault");
3788               }
3789             else if (cpu.Ypair[0] == 0 && cpu.Ypair[1] == 0)
3790               {
3791                 cpu.rA = 0;
3792 #if defined(TESTING)
3793                 HDBGRegAW ("lcaq");
3794 #endif
3795                 cpu.rQ = 0;
3796 #if defined(TESTING)
3797                 HDBGRegQW ("lcaq");
3798 #endif
3799 
3800                 SET_I_ZERO;
3801                 CLR_I_NEG;
3802               }
3803             else
3804               {
3805                 word72 tmp72 = convert_to_word72 (cpu.Ypair[0], cpu.Ypair[1]);
3806 #if defined(NEED_128)
3807                 tmp72 = negate_128 (tmp72);
3808 #else
3809                 tmp72 = ~tmp72 + 1;
3810 #endif
3811                 convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
3812 #if defined(TESTING)
3813                 HDBGRegAW ("lcaq");
3814                 HDBGRegQW ("lcaq");
3815 #endif
3816 
3817                 SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
3818                 SC_I_NEG (cpu.rA & SIGN36);
3819               }
3820           }
3821           break;
3822 
3823 // Optimized to the top of the loop
3824 //        case x0 (0235):  // lda
3825 
3826         case x0 (0034): // ldac
3827           cpu.rA = cpu.CY;
3828 #if defined(TESTING)
3829           HDBGRegAW ("ldac");
3830 #endif
3831           SC_I_ZERO (cpu.rA == 0);
3832           SC_I_NEG (cpu.rA & SIGN36);
3833           cpu.CY = 0;
3834           break;
3835 
3836 // Optimized to the top of the loop
3837 //        case x0 (0237):  // ldaq
3838 
3839 // Optimized to the top of the loop
3840 //        case x0 (0634):  // ldi
3841 
3842 // Optimized to the top of the loop
3843 //         case x0 (0236):  // ldq
3844 
3845         case x0 (0032): // ldqc
3846           cpu.rQ = cpu.CY;
3847 #if defined(TESTING)
3848           HDBGRegQW ("ldqc");
3849 #endif
3850           SC_I_ZERO (cpu.rQ == 0);
3851           SC_I_NEG (cpu.rQ & SIGN36);
3852           cpu.CY = 0;
3853           break;
3854 
3855                          // ldxn
3856         case x0 (0220):  // ldx0
3857         case x0 (0221):  // ldx1
3858         case x0 (0222):  // ldx2
3859         case x0 (0223):  // ldx3
3860         case x0 (0224):  // ldx4
3861         case x0 (0225):  // ldx5
3862         case x0 (0226):  // ldx6
3863         case x0 (0227):  // ldx7
3864           {
3865             uint32 n  = opcode10 & 07;  // get n
3866             cpu.rX[n] = GETHI (cpu.CY);
3867 #if defined(TESTING)
3868             HDBGRegXW (n, "ldxn");
3869 #endif
3870             SC_I_ZERO (cpu.rX[n] == 0);
3871             SC_I_NEG (cpu.rX[n] & SIGN18);
3872           }
3873           break;
3874 
3875         case x0 (0073):   // lreg
3876           CPTUR (cptUseE);
3877           L68_ (cpu.ou.cycle |= ou_GOS;)
3878           L68_ (cpu.ou.eac = 0;)
3879           cpu.rX[0] = GETHI (cpu.Yblock8[0]);
3880 #if defined(TESTING)
3881           HDBGRegXW (0, "lreg");
3882 #endif
3883           cpu.rX[1] = GETLO (cpu.Yblock8[0]);
3884 #if defined(TESTING)
3885           HDBGRegXW (1, "lreg");
3886 #endif
3887           L68_ (cpu.ou.eac ++;)
3888           cpu.rX[2] = GETHI (cpu.Yblock8[1]);
3889 #if defined(TESTING)
3890           HDBGRegXW (2, "lreg");
3891 #endif
3892           cpu.rX[3] = GETLO (cpu.Yblock8[1]);
3893 #if defined(TESTING)
3894           HDBGRegXW (3, "lreg");
3895 #endif
3896           L68_ (cpu.ou.eac ++;)
3897           cpu.rX[4] = GETHI (cpu.Yblock8[2]);
3898 #if defined(TESTING)
3899           HDBGRegXW (4, "lreg");
3900 #endif
3901           cpu.rX[5] = GETLO (cpu.Yblock8[2]);
3902 #if defined(TESTING)
3903           HDBGRegXW (5, "lreg");
3904 #endif
3905           L68_ (cpu.ou.eac ++;)
3906           cpu.rX[6] = GETHI (cpu.Yblock8[3]);
3907 #if defined(TESTING)
3908           HDBGRegXW (6, "lreg");
3909 #endif
3910           cpu.rX[7] = GETLO (cpu.Yblock8[3]);
3911 #if defined(TESTING)
3912           HDBGRegXW (7, "lreg");
3913 #endif
3914           L68_ (cpu.ou.eac ++;)
3915           cpu.rA = cpu.Yblock8[4];
3916 #if defined(TESTING)
3917           HDBGRegAW ("lreg");
3918 #endif
3919           cpu.rQ = cpu.Yblock8[5];
3920 #if defined(TESTING)
3921           HDBGRegQW ("lreg");
3922 #endif
3923           cpu.rE = (GETHI (cpu.Yblock8[6]) >> 10) & 0377;   // need checking
3924           break;
3925 
3926 // Optimized to the top of the loop
3927 //                         // lxln
3928 //        case x0 (0720):  // lxl0
3929 //        case x0 (0721):  // lxl1
3930 //        case x0 (0722):  // lxl2
3931 //        case x0 (0723):  // lxl3
3932 //        case x0 (0724):  // lxl4
3933 //        case x0 (0725):  // lxl5
3934 //        case x0 (0726):  // lxl6
3935 //        case x0 (0727):  // lxl7
3936 
3937         /// Fixed-Point Data Movement Store
3938 
3939         case x0 (0753):  // sreg
3940           CPTUR (cptUseE);
3941           CPTUR (cptUseRALR);
3942           // clear block (changed to memset() per DJ request)
3943           //(void)memset (cpu.Yblock8, 0, sizeof (cpu.Yblock8));
3944           L68_ (cpu.ou.cycle |= ou_GOS;)
3945           L68_ (cpu.ou.eac = 0;)
3946           SETHI (cpu.Yblock8[0], cpu.rX[0]);
3947           SETLO (cpu.Yblock8[0], cpu.rX[1]);
3948           L68_ (cpu.ou.eac ++;)
3949           SETHI (cpu.Yblock8[1], cpu.rX[2]);
3950           SETLO (cpu.Yblock8[1], cpu.rX[3]);
3951           L68_ (cpu.ou.eac ++;)
3952           SETHI (cpu.Yblock8[2], cpu.rX[4]);
3953           SETLO (cpu.Yblock8[2], cpu.rX[5]);
3954           L68_ (cpu.ou.eac ++;)
3955           SETHI (cpu.Yblock8[3], cpu.rX[6]);
3956           SETLO (cpu.Yblock8[3], cpu.rX[7]);
3957           L68_ (cpu.ou.eac ++;)
3958           cpu.Yblock8[4] = cpu.rA;
3959           cpu.Yblock8[5] = cpu.rQ;
3960           cpu.Yblock8[6] = ((word36)(cpu.rE & MASK8)) << 28;
3961           if (cpu.tweaks.isolts_mode && ! cpu.tweaks.tandd_mode)   // as stt
3962             cpu.Yblock8[7] = (((-- cpu.shadowTR) & MASK27) << 9) | (cpu.rRALR & 07);
3963           else
3964             cpu.Yblock8[7] = ((cpu.rTR & MASK27) << 9) | (cpu.rRALR & 07);
3965 #if defined(TESTING)
3966           HDBGRegXR (0, "sreg");
3967           HDBGRegXR (1, "sreg");
3968           HDBGRegXR (2, "sreg");
3969           HDBGRegXR (3, "sreg");
3970           HDBGRegXR (4, "sreg");
3971           HDBGRegXR (5, "sreg");
3972           HDBGRegXR (6, "sreg");
3973           HDBGRegXR (7, "sreg");
3974           HDBGRegAR ("sreg");
3975           HDBGRegQR ("sreg");
3976 #endif
3977           break;
3978 
3979 // Optimized to the top of the loop
3980 //        case x0 (0755):  // sta
3981 
3982         case x0 (0354):  // stac
3983           if (cpu.CY == 0)
3984             {
3985 #if defined(TESTING)
3986               HDBGRegAR ("stac");
3987 #endif
3988               SET_I_ZERO;
3989               cpu.CY = cpu.rA;
3990             }
3991           else
3992             CLR_I_ZERO;
3993           break;
3994 
3995         case x0 (0654):  // stacq
3996 #if defined(TESTING)
3997           HDBGRegQR ("stacq");
3998 #endif
3999           if (cpu.CY == cpu.rQ)
4000             {
4001 #if defined(TESTING)
4002               HDBGRegAR ("stacq");
4003 #endif
4004               cpu.CY = cpu.rA;
4005               SET_I_ZERO;
4006             }
4007           else
4008             CLR_I_ZERO;
4009           break;
4010 
4011 // Optimized to the top of the loop
4012 //        case x0 (0757):  // staq
4013 
4014         case x0 (0551):  // stba
4015           // 9-bit bytes of C(A) -> corresponding bytes of C(Y), the byte
4016           // positions affected being specified in the TAG field.
4017           // copyBytes ((i->tag >> 2) & 0xf, cpu.rA, &cpu.CY);
4018 #if defined(TESTING)
4019           HDBGRegAR ("stba");
4020 #endif
4021           cpu.CY = cpu.rA;
4022           cpu.zone =
4023              /*LINTED E_CONST_PROMOTED_UNSIGNED_LONG*/
4024              ((i->tag & 040) ? 0777000000000u : 0) |
4025              ((i->tag & 020) ? 0000777000000u : 0) |
4026              ((i->tag & 010) ? 0000000777000u : 0) |
4027              ((i->tag & 004) ? 0000000000777u : 0);
4028           cpu.useZone = true;
4029           cpu.ou.crflag = true;
4030           break;
4031 
4032         case x0 (0552):  // stbq
4033           // 9-bit bytes of C(Q) -> corresponding bytes of C(Y), the byte
4034           // positions affected being specified in the TAG field.
4035           // copyBytes ((i->tag >> 2) & 0xf, cpu.rQ, &cpu.CY);
4036 #if defined(TESTING)
4037           HDBGRegQR ("stbq");
4038 #endif
4039           cpu.CY = cpu.rQ;
4040           cpu.zone =
4041              /*LINTED E_CONST_PROMOTED_UNSIGNED_LONG*/
4042              ((i->tag & 040) ? 0777000000000u : 0) |
4043              ((i->tag & 020) ? 0000777000000u : 0) |
4044              ((i->tag & 010) ? 0000000777000u : 0) |
4045              ((i->tag & 004) ? 0000000000777u : 0);
4046           cpu.useZone   = true;
4047           cpu.ou.crflag = true;
4048           break;
4049 
4050         case x0 (0554):  // stc1
4051           // "C(Y)25 reflects the state of the tally runout indicator
4052           // prior to modification.
4053           SETHI (cpu.CY, (cpu.PPR.IC + 1) & MASK18);
4054           // AL39 stc1 says that HEX is ignored, but the mode register
4055           // description says that it isn't
4056           DPS8M_ (SETLO (cpu.CY, cpu.cu.IR & 0777770);)
4057           L68_ (SETLO (cpu.CY, cpu.cu.IR & 0777760);)
4058           SCF (i->stiTally, cpu.CY, I_TALLY);
4059           break;
4060 
4061         case x0 (0750):  // stc2
4062           // AL-39 doesn't specify if the low half is set to zero,
4063           // set to IR, or left unchanged
4064           // RJ78 specifies unchanged
4065           // SETHI (cpu.CY, (cpu.PPR.IC + 2) & MASK18);
4066           cpu.CY      = ((word36) ((cpu.PPR.IC + 2) & MASK18)) << 18;
4067           cpu.zone    = 0777777000000;
4068           cpu.useZone = true;
4069           break;
4070 
4071         case x0 (0751): // stca
4072           // Characters of C(A) -> corresponding characters of C(Y),
4073           // the character positions affected being specified in the TAG
4074           // field.
4075           // copyChars (i->tag, cpu.rA, &cpu.CY);
4076 #if defined(TESTING)
4077           HDBGRegAR ("stca");
4078 #endif
4079           cpu.CY = cpu.rA;
4080           cpu.zone =
4081              /*LINTED E_CONST_PROMOTED_UNSIGNED_LONG*/
4082              ((i->tag & 040) ? 0770000000000u : 0) |
4083              ((i->tag & 020) ? 0007700000000u : 0) |
4084              ((i->tag & 010) ? 0000077000000u : 0) |
4085              ((i->tag & 004) ? 0000000770000u : 0) |
4086              ((i->tag & 002) ? 0000000007700u : 0) |
4087              ((i->tag & 001) ? 0000000000077u : 0);
4088           cpu.useZone = true;
4089           cpu.ou.crflag = true;
4090           break;
4091 
4092         case x0 (0752): // stcq
4093           // Characters of C(Q) -> corresponding characters of C(Y), the
4094           // character positions affected being specified in the TAG field.
4095           // copyChars (i->tag, cpu.rQ, &cpu.CY);
4096 #if defined(TESTING)
4097           HDBGRegQR ("stcq");
4098 #endif
4099           cpu.CY = cpu.rQ;
4100           cpu.zone =
4101              /*LINTED E_CONST_PROMOTED_UNSIGNED_LONG*/
4102              ((i->tag & 040) ? 0770000000000u : 0) |
4103              ((i->tag & 020) ? 0007700000000u : 0) |
4104              ((i->tag & 010) ? 0000077000000u : 0) |
4105              ((i->tag & 004) ? 0000000770000u : 0) |
4106              ((i->tag & 002) ? 0000000007700u : 0) |
4107              ((i->tag & 001) ? 0000000000077u : 0);
4108           cpu.useZone = true;
4109           cpu.ou.crflag = true;
4110           break;
4111 
4112         case x0 (0357): //< stcd
4113           // C(PPR) -> C(Y-pair) as follows:
4114 
4115           //  000 -> C(Y-pair)0,2
4116           //  C(PPR.PSR) -> C(Y-pair)3,17
4117           //  C(PPR.PRR) -> C(Y-pair)18,20
4118           //  00...0 -> C(Y-pair)21,29
4119           //  (43)8 -> C(Y-pair)30,35
4120 
4121           //  C(PPR.IC)+2 -> C(Y-pair)36,53
4122           //  00...0 -> C(Y-pair)54,71
4123 
4124           // ISOLTS 880 5a has an STCD in an XED in a fault pair;
4125           // it reports the wrong ring number. This was fixed by
4126           // emulating the SCU instruction (different behavior in fault
4127           // pair).
4128 
4129           if (cpu.cycle == EXEC_cycle)
4130             {
4131               cpu.Ypair[0] = 0;
4132               putbits36_15 (& cpu.Ypair[0],  3, cpu.PPR.PSR);
4133               putbits36_3  (& cpu.Ypair[0], 18, cpu.PPR.PRR);
4134               putbits36_6  (& cpu.Ypair[0], 30, 043);
4135 
4136               cpu.Ypair[1] = 0;
4137               putbits36_18 (& cpu.Ypair[1],  0, cpu.PPR.IC + 2);
4138             }
4139           else
4140             {
4141               cpu.Ypair[0] = 0;
4142               putbits36_15 (& cpu.Ypair[0],  3, cpu.cu_data.PSR);
4143               putbits36_3  (& cpu.Ypair[0], 18, cpu.cu_data.PRR);
4144               //putbits36_6  (& cpu.Ypair[0], 30, 043);
4145 
4146               cpu.Ypair[1] = 0;
4147               putbits36_18 (& cpu.Ypair[1],  0, cpu.cu_data.IC + 2);
4148             }
4149           break;
4150 
4151 // Optimized to the top of the loop
4152 //        case x0 (0754): // sti
4153 
4154 // Optimized to the top of the loop
4155 //         case x0 (0756): // stq
4156 
4157         case x0 (0454):  // stt
4158           CPTUR (cptUseTR);
4159           // ISOLTS reads the shadow TR, except in T&D mode, where the TR
4160           // itself counts with execution (see do_LUF_fault)
4161           if (cpu.tweaks.isolts_mode && ! cpu.tweaks.tandd_mode)
4162             //cpu.CY = ((-- cpu.shadowTR) & MASK27) << 9;
4163             // ubsan
4164             cpu.CY = (((uint) (((int) cpu.shadowTR) - 1)) & MASK27) << 9;
4165           else
4166             cpu.CY = (cpu.rTR & MASK27) << 9;
4167           break;
4168 
4169 // Optimized to the top of the loop
4170 //                         // stxn
4171 //        case x0 (0740):  // stx0
4172 //        case x0 (0741):  // stx1
4173 //        case x0 (0742):  // stx2
4174 //        case x0 (0743):  // stx3
4175 //        case x0 (0744):  // stx4
4176 //        case x0 (0745):  // stx5
4177 //        case x0 (0746):  // stx6
4178 //        case x0 (0747):  // stx7
4179 
4180 // Optimized to the top of the loop
4181 //        case x0 (0450): // stz
4182 
4183                          // sxln
4184         case x0 (0440):  // sxl0
4185         case x0 (0441):  // sxl1
4186         case x0 (0442):  // sxl2
4187         case x0 (0443):  // sxl3
4188         case x0 (0444):  // sxl4
4189         case x0 (0445):  // sxl5
4190         case x0 (0446):  // sxl6
4191         case x0 (0447):  // sxl7
4192           //SETLO (cpu.CY, cpu.rX[opcode10 & 07]);
4193           cpu.CY      = cpu.rX[opcode10 & 07];
4194           cpu.zone    = 0000000777777;
4195           cpu.useZone = true;
4196           break;
4197 
4198         /// Fixed-Point Data Movement Shift
4199 
4200         case x0 (0775):  // alr
4201           {
4202 #if defined(TESTING)
4203               HDBGRegAR ("alr");
4204 #endif
4205 #if BARREL_SHIFTER
4206             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4207             cnt %= 36;
4208 
4209             word36 highA = cpu.rA & barrelLeftMaskTable[cnt];
4210             cpu.rA <<= cnt;
4211             highA >>= (36 - cnt);
4212             highA &= barrelRightMaskTable[cnt];
4213             cpu.rA |= highA;
4214             cpu.rA &= DMASK;    // keep to 36-bits
4215 #else // !BARREL_SHIFTER
4216               word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4217               for (uint j = 0 ; j < tmp36 ; j++)
4218               {
4219                   bool a0 = cpu.rA & SIGN36;    // A0
4220                   cpu.rA <<= 1;               // shift left 1
4221                   if (a0)                 // rotate A0 -> A35
4222                       cpu.rA |= 1;
4223               }
4224               cpu.rA &= DMASK;    // keep to 36-bits
4225 #endif // BARREL_SHIFTER
4226 #if defined(TESTING)
4227               HDBGRegAW ("alr");
4228 #endif
4229 
4230               SC_I_ZERO (cpu.rA == 0);
4231               SC_I_NEG (cpu.rA & SIGN36);
4232           }
4233           break;
4234 
4235 // Optimized to the top of the loop
4236 //        case x0 (0735):  // als
4237 
4238         case x0 (0771):  // arl
4239           // Shift C(A) right the number of positions given in
4240           // C(TPR.CA)11,17; filling vacated positions with zeros.
4241           {
4242 #if defined(TESTING)
4243             HDBGRegAR ("arl");
4244 #endif
4245             cpu.rA &= DMASK; // Make sure the shifted in bits are 0
4246             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4247 
4248             cpu.rA >>= tmp36;
4249             cpu.rA &= DMASK;    // keep to 36-bits
4250 #if defined(TESTING)
4251             HDBGRegAW ("arl");
4252 #endif
4253 
4254             SC_I_ZERO (cpu.rA == 0);
4255             SC_I_NEG (cpu.rA & SIGN36);
4256           }
4257           break;
4258 
4259         case x0 (0731):  // ars
4260           {
4261             // Shift C(A) right the number of positions given in
4262             // C(TPR.CA)11,17; filling vacated positions with initial C(A)0.
4263 
4264 #if defined(TESTING)
4265             HDBGRegAR ("ars");
4266 #endif
4267 #if BARREL_SHIFTER
4268             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4269             bool A0 = (cpu.rA & SIGN36) != 0;
4270 
4271             if (cnt >= 36) {
4272               cpu.rA = A0 ? MASK36 : 0;
4273             } else {
4274               // Shift rA
4275               cpu.rA >>= cnt;
4276               // Mask out the high bits
4277               if (A0) {
4278                 cpu.rA |= barrelLeftMaskTable[cnt];
4279               } else {
4280                 cpu.rA &= BS_COMPL (barrelLeftMaskTable[cnt]);
4281               }
4282             }
4283             cpu.rA &= DMASK;    // keep to 36-bits
4284 #else // !BARREL_SHIFTER
4285             cpu.rA &= DMASK; // Make sure the shifted in bits are 0
4286             word18 tmp18 = cpu.TPR.CA & 0177;   // CY bits 11-17
4287 
4288             bool a0 = cpu.rA & SIGN36;    // A0
4289             for (uint j = 0 ; j < tmp18 ; j ++)
4290               {
4291                 cpu.rA >>= 1;               // shift right 1
4292                 if (a0)                 // propagate sign bit
4293                     cpu.rA |= SIGN36;
4294               }
4295             cpu.rA &= DMASK;    // keep to 36-bits
4296 #endif // BARREL_SHIFTER
4297 #if defined(TESTING)
4298             HDBGRegAW ("ars");
4299 #endif
4300 
4301             SC_I_ZERO (cpu.rA == 0);
4302             SC_I_NEG (cpu.rA & SIGN36);
4303           }
4304           break;
4305 
4306         case x0 (0777):  // llr
4307           // Shift C(AQ) left by the number of positions given in
4308           // C(TPR.CA)11,17; entering each bit leaving AQ0 into AQ71.
4309 
4310           {
4311 #if defined(TESTING)
4312             HDBGRegAR ("llr");
4313             HDBGRegQR ("llr");
4314 #endif
4315 #if BARREL_SHIFTER
4316             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4317             cnt = cnt % 72;  // 0-71
4318             if (cnt > 35) {
4319               cnt = cnt - 36;
4320               word36 tmp = cpu.rA;
4321               cpu.rA = cpu.rQ;
4322               cpu.rQ = tmp;
4323             }
4324             word36 highA = cpu.rA & barrelLeftMaskTable[cnt];
4325             word36 lowA  = cpu.rA & BS_COMPL(barrelLeftMaskTable[cnt]);
4326             word36 highQ = cpu.rQ & barrelLeftMaskTable[cnt];
4327             word36 lowQ  = cpu.rQ & BS_COMPL(barrelLeftMaskTable[cnt]);
4328             cpu.rA = (lowA << cnt) | (highQ >> (36 - cnt));
4329             cpu.rQ = (lowQ << cnt) | (highA >> (36 - cnt));
4330 #else // !BARREL_SHIFTER
4331             word36 tmp36 = cpu.TPR.CA & 0177;      // CY bits 11-17
4332             for (uint j = 0 ; j < tmp36 ; j++)
4333               {
4334                 bool a0 = cpu.rA & SIGN36;         // A0
4335 
4336                 cpu.rA <<= 1;                      // shift left 1
4337 
4338                 bool b0 = cpu.rQ & SIGN36;         // Q0
4339                 if (b0)
4340                   cpu.rA |= 1;                     // Q0 => A35
4341 
4342                 cpu.rQ <<= 1;                      // shift left 1
4343 
4344                 if (a0)                            // propagate A sign bit
4345                   cpu.rQ |= 1;
4346               }
4347 
4348 #endif // BARREL_SHIFTER
4349             cpu.rA &= DMASK;    // keep to 36-bits
4350             cpu.rQ &= DMASK;
4351 #if defined(TESTING)
4352             HDBGRegAW ("llr");
4353             HDBGRegQW ("llr");
4354 #endif
4355 
4356             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
4357             SC_I_NEG (cpu.rA & SIGN36);
4358           }
4359           break;
4360 
4361         case x0 (0737):  // lls
4362           {
4363             // lls Long Left Shift
4364             // Shift C(AQ) left the number of positions given in
4365             // C(TPR.CA)11,17; filling vacated positions with zeros.
4366             // Zero       if C(AQ) == 0 then ON; otherwise OFF:
4367             // Negative   if C(AQ)0 == 1 then On; otherwise OFF;
4368             // Carry      if C(AQ)0 changes during the shift; then ON; otherwise OFF:
4369 #if BARREL_SHIFTER
4370             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4371 
4372 
4373             // Sanitize
4374             cpu.rA &= MASK36;
4375             cpu.rQ &= MASK36;
4376 
4377             if (cnt >= 72) {
4378               // If the shift is 72 or greater, AQ will be set to zero and
4379               // the carry will be cleared if the initial value of AQ is 0 or
4380               // all ones
4381               bool allz = cpu.rA == 0 && cpu.rQ == 0;
4382               bool all1 = cpu.rA == MASK36 && cpu.rQ == MASK36;
4383               if (allz || all1)
4384                 CLR_I_CARRY;
4385               else
4386                 SET_I_CARRY;
4387               cpu.rA = 0;
4388               cpu.rQ = 0;
4389 
4390             } else if (cnt >= 36) {
4391               // If the shift count is 36 to 71, all of A and some of Q will determine
4392               // the carry; all of A will become Q << (cnt - 36), and Q will become 0.
4393               uint cnt36 = cnt - 36;
4394               // The carry depends on the sign bit changing on the shift;
4395               // add 1 so that the mask includes the sign bit and all of
4396               // the bits that will be shifted in.
4397               word36 lmask = barrelLeftMaskTable[cnt36 + 1];
4398               // Capture all of the bits that will be shifted
4399               word36 captureA = cpu.rA;
4400               word36 captureQ = lmask & cpu.rQ;
4401               bool az = captureA == 0;
4402               bool a1 = captureA == MASK36;
4403               bool qz = captureQ == 0;
4404               bool q1 = captureQ == (MASK36 & lmask);
4405               bool allz = az && qz;
4406               bool all1 = a1 && q1;
4407               if (allz || all1)
4408                 CLR_I_CARRY;
4409               else
4410                 SET_I_CARRY;
4411 
4412               // Shift the bits
4413               cpu.rA = (cpu.rQ << cnt36) & MASK36;
4414               cpu.rQ = 0;
4415             } else { // cnt < 36
4416               // If the count is < 36, carry is determined by the high part of A;
4417               // A is shifted left, and bits shifted out of Q are shifted into A.
4418               // The carry depends on the sign bit changing on the shift;
4419               // add 1 so that the mask includes the sign bit and all of
4420               // the bits that will be shifted in.
4421               word36 lmask = barrelLeftMaskTable[cnt + 1];
4422               word36 captureA = lmask & cpu.rA;
4423               bool allz = captureA == 0;
4424               bool all1 = captureA == (MASK36 & lmask);
4425 
4426               if (allz || all1)
4427                 CLR_I_CARRY;
4428               else
4429                 SET_I_CARRY;
4430 
4431               // Shift the bits
4432               cpu.rA = ((cpu.rA << cnt) & MASK36) | (cpu.rQ >> (36 - cnt));
4433               cpu.rQ = (cpu.rQ << cnt) & MASK36;
4434             }
4435 
4436 
4437 
4438 
4439 
4440 
4441 
4442 
4443 
4444 
4445 
4446 
4447 
4448 
4449 
4450 
4451 
4452 
4453 
4454 
4455 
4456 
4457 
4458 
4459 
4460 
4461 
4462 
4463 
4464 
4465 
4466 
4467 
4468 
4469 
4470 
4471 
4472 #else // !BARREL_SHIFTER
4473 
4474             CLR_I_CARRY;
4475 
4476 # if defined(TESTING)
4477             HDBGRegAR ("lls");
4478             HDBGRegQR ("lls");
4479 # endif
4480             word36 tmp36   = cpu.TPR.CA & 0177;   // CY bits 11-17
4481             word36 tmpSign = cpu.rA & SIGN36;
4482             for (uint j = 0 ; j < tmp36 ; j ++)
4483               {
4484                 cpu.rA <<= 1;               // shift left 1
4485 
4486                 if (tmpSign != (cpu.rA & SIGN36))
4487                   SET_I_CARRY;
4488 
4489                 bool b0 = cpu.rQ & SIGN36;    // Q0
4490                 if (b0)
4491                   cpu.rA |= 1;            // Q0 => A35
4492 
4493                 cpu.rQ <<= 1;               // shift left 1
4494               }
4495 
4496             cpu.rA &= DMASK;    // keep to 36-bits
4497             cpu.rQ &= DMASK;
4498 #endif // BARREL_SHIFTER
4499 #if defined(TESTING)
4500             HDBGRegAW ("lls");
4501             HDBGRegQW ("lls");
4502 #endif
4503 
4504             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
4505             SC_I_NEG (cpu.rA & SIGN36);
4506           }
4507           break;
4508 
4509         case x0 (0773):  // lrl
4510           // Shift C(AQ) right the number of positions given in
4511           // C(TPR.CA)11,17; filling vacated positions with zeros.
4512           {
4513 #if defined(TESTING)
4514             HDBGRegAR ("lrl");
4515             HDBGRegQR ("lrl");
4516 #endif
4517 #if BARREL_SHIFTER
4518             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4519             if (cnt >= 72) {
4520                cpu.rA = 0;
4521                cpu.rQ = 0;
4522             } else if (cnt < 36) {
4523               // Shift rQ
4524               cpu.rQ >>= cnt;
4525               // Mask out the high bits
4526               cpu.rQ &= BS_COMPL (barrelLeftMaskTable[cnt]);
4527               // Capture the low bits in A
4528               word36 lowA = cpu.rA & barrelRightMaskTable[cnt];
4529               // Shift A
4530               cpu.rA >>= cnt;
4531               // Mask out the high bits
4532               cpu.rA &= BS_COMPL (barrelLeftMaskTable[cnt]);
4533               // Move the low A bits left
4534               lowA <<= (36 - cnt);
4535               // Put them in high Q
4536               cpu.rQ |= lowA;
4537             } else { // 36-71
4538               // Shift rQ
4539               cpu.rQ = cpu.rA >> (cnt - 36);
4540               // Mask out the high bits
4541               cpu.rQ &= BS_COMPL (barrelLeftMaskTable[cnt - 36]);
4542               cpu.rA = 0;
4543             }
4544             cpu.rA &= DMASK;    // keep to 36-bits
4545             cpu.rQ &= DMASK;
4546 #else // !BARREL_SHIFTER
4547             cpu.rA &= DMASK; // Make sure the shifted in bits are 0
4548             cpu.rQ &= DMASK; // Make sure the shifted in bits are 0
4549             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4550             for (uint j = 0 ; j < tmp36 ; j++)
4551               {
4552                 bool a35 = cpu.rA & 1;      // A35
4553                 cpu.rA >>= 1;               // shift right 1
4554 
4555                 cpu.rQ >>= 1;               // shift right 1
4556 
4557                 if (a35)                // propagate sign bit
4558                   cpu.rQ |= SIGN36;
4559               }
4560             cpu.rA &= DMASK;    // keep to 36-bits
4561             cpu.rQ &= DMASK;
4562 #endif // BARREL_SHIFTER
4563 #if defined(TESTING)
4564             HDBGRegAW ("lrl");
4565             HDBGRegQW ("lrl");
4566 #endif
4567 
4568             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
4569             SC_I_NEG (cpu.rA & SIGN36);
4570           }
4571           break;
4572 
4573         case x0 (0733):  // lrs
4574           {
4575             // Shift C(AQ) right the number of positions given in
4576             // C(TPR.CA)11,17; filling vacated positions with initial C(AQ)0.
4577 
4578 #if defined(TESTING)
4579             HDBGRegAR ("lrs");
4580             HDBGRegQR ("lrs");
4581 #endif
4582 #if BARREL_SHIFTER
4583             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4584             bool AQ0 = (cpu.rA & SIGN36) != 0;
4585             if (cnt >= 72) {
4586                cpu.rA = cpu.rQ = AQ0 ? MASK36 : 0;
4587             } else if (cnt < 36) {
4588               // Shift rQ
4589               cpu.rQ >>= cnt;
4590               // Mask out the high bits
4591               cpu.rQ &= BS_COMPL (barrelLeftMaskTable[cnt]);
4592               // Capture the low bits in A
4593               word36 lowA = cpu.rA & barrelRightMaskTable[cnt];
4594               // Shift A
4595               cpu.rA >>= cnt;
4596               // Set the high bits to AQ0
4597               if (AQ0)
4598                 cpu.rA |= barrelLeftMaskTable[cnt];
4599               else
4600                 cpu.rA &= BS_COMPL (barrelLeftMaskTable[cnt]);
4601               // Move the low A bits left
4602               lowA <<= (36 - cnt);
4603               // Put them in high Q
4604               cpu.rQ |= lowA;
4605             } else { // 36-71
4606               // Shift rQ
4607               cpu.rQ = cpu.rA >> (cnt - 36);
4608               // Mask out the high bits
4609               if (AQ0) {
4610                 cpu.rQ |= barrelLeftMaskTable[cnt - 36];
4611                 cpu.rA = MASK36;
4612               } else {
4613                 cpu.rQ &= BS_COMPL (barrelLeftMaskTable[cnt - 36]);
4614                 cpu.rA = 0;
4615               }
4616             }
4617             cpu.rA &= DMASK;    // keep to 36-bits
4618             cpu.rQ &= DMASK;
4619 #else // !BARREL_SHIFTER
4620             word36 tmp36  = cpu.TPR.CA & 0177;   // CY bits 11-17
4621             cpu.rA       &= DMASK; // Make sure the shifted in bits are 0
4622             cpu.rQ       &= DMASK; // Make sure the shifted in bits are 0
4623             bool a0       = cpu.rA & SIGN36;    // A0
4624 
4625             for (uint j = 0 ; j < tmp36 ; j ++)
4626               {
4627                 bool a35 = cpu.rA & 1;      // A35
4628 
4629                 cpu.rA >>= 1;               // shift right 1
4630                 if (a0)
4631                   cpu.rA |= SIGN36;
4632 
4633                 cpu.rQ >>= 1;               // shift right 1
4634                 if (a35)                // propagate sign bit1
4635                   cpu.rQ |= SIGN36;
4636               }
4637             cpu.rA &= DMASK;    // keep to 36-bits (probably ain't necessary)
4638             cpu.rQ &= DMASK;
4639 #endif // BARREL_SHIFTER
4640 #if defined(TESTING)
4641             HDBGRegAW ("lrs");
4642             HDBGRegQW ("lrs");
4643 #endif
4644 
4645             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
4646             SC_I_NEG (cpu.rA & SIGN36);
4647           }
4648           break;
4649 
4650         case x0 (0776):  // qlr
4651           // Shift C(Q) left the number of positions given in
4652           // C(TPR.CA)11,17; entering each bit leaving Q0 into Q35.
4653           {
4654 #if defined(TESTING)
4655             HDBGRegQR ("qlr");
4656 #endif
4657 #if BARREL_SHIFTER
4658             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4659             cnt %= 36;
4660 
4661             word36 highQ = cpu.rQ & barrelLeftMaskTable[cnt];
4662             cpu.rQ <<= cnt;
4663             highQ >>= (36 - cnt);
4664             highQ &= barrelRightMaskTable[cnt];
4665             cpu.rQ |= highQ;
4666             cpu.rQ &= DMASK;    // keep to 36-bits
4667 #else // !BARREL_SHIFTER
4668             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4669             for (uint j = 0 ; j < tmp36 ; j++)
4670               {
4671                 bool q0 = cpu.rQ & SIGN36;    // Q0
4672                 cpu.rQ <<= 1;               // shift left 1
4673                 if (q0)                 // rotate A0 -> A35
4674                   cpu.rQ |= 1;
4675               }
4676             cpu.rQ &= DMASK;    // keep to 36-bits
4677 #endif // BARREL_SHIFTER
4678 #if defined(TESTING)
4679             HDBGRegQW ("qlr");
4680 #endif
4681 
4682             SC_I_ZERO (cpu.rQ == 0);
4683             SC_I_NEG (cpu.rQ & SIGN36);
4684           }
4685           break;
4686 
4687 // Optimized to the top of the loop
4688 //        case x0 (0736):  // qls
4689 
4690         case x0 (0772):  // qrl
4691           // Shift C(Q) right the number of positions specified by
4692           // Y11,17; fill vacated positions with zeros.
4693           {
4694 #if defined(TESTING)
4695             HDBGRegQR ("qrl");
4696 #endif
4697             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4698 
4699             cpu.rQ  &= DMASK;    // Make sure the shifted in bits are 0
4700             cpu.rQ >>= tmp36;
4701             cpu.rQ  &= DMASK;    // keep to 36-bits
4702 #if defined(TESTING)
4703             HDBGRegQW ("qrl");
4704 #endif
4705 
4706             SC_I_ZERO (cpu.rQ == 0);
4707             SC_I_NEG (cpu.rQ & SIGN36);
4708 
4709           }
4710           break;
4711 
4712         case x0 (0732):  // qrs
4713           {
4714             // Shift C(Q) right the number of positions given in
4715             // C(TPR.CA)11,17; filling vacated positions with initial C(Q)0.
4716 
4717 #if defined(TESTING)
4718             HDBGRegQR ("qrs");
4719 #endif
4720 #if BARREL_SHIFTER
4721             uint cnt = (uint) cpu.TPR.CA & 0177;   // 0-127
4722             bool Q0 = (cpu.rQ & SIGN36) != 0;
4723 
4724             if (cnt >= 36) {
4725               cpu.rQ = Q0 ? MASK36 : 0;
4726             } else {
4727               // Shift rQ
4728               cpu.rQ >>= cnt;
4729               // Mask out the high bits
4730               if (Q0) {
4731                 cpu.rQ |= barrelLeftMaskTable[cnt];
4732               } else {
4733                 cpu.rQ &= BS_COMPL (barrelLeftMaskTable[cnt]);
4734               }
4735             }
4736             cpu.rQ &= DMASK;    // keep to 36-bits
4737 #else // !BARREL_SHIFTER
4738             cpu.rQ &= DMASK; // Make sure the shifted in bits are 0
4739             word36 tmp36 = cpu.TPR.CA & 0177;   // CY bits 11-17
4740             bool q0 = cpu.rQ & SIGN36;    // Q0
4741             for (uint j = 0 ; j < tmp36 ; j++)
4742               {
4743                 cpu.rQ >>= 1;               // shift right 1
4744                 if (q0)                 // propagate sign bit
4745                   cpu.rQ |= SIGN36;
4746               }
4747             cpu.rQ &= DMASK;    // keep to 36-bits
4748 #endif // BARREL_SHIFTER
4749 #if defined(TESTING)
4750             HDBGRegQW ("qrs");
4751 #endif
4752 
4753             SC_I_ZERO (cpu.rQ == 0);
4754             SC_I_NEG (cpu.rQ & SIGN36);
4755           }
4756           break;
4757 
4758         /// Fixed-Point Addition
4759 
4760         case x0 (0075):  // ada
4761           {
4762             // C(A) + C(Y) -> C(A)
4763             // Modifications: All
4764             //
4765             //  (Indicators not listed are not affected)
4766             //  ZERO: If C(A) = 0, then ON; otherwise OFF
4767             //  NEG: If C(A)0 = 1, then ON; otherwise OFF
4768             //  OVR: If range of A is exceeded, then ON
4769             //  CARRY: If a carry out of A0 is generated, then ON; otherwise OFF
4770 
4771             L68_ (cpu.ou.cycle |= ou_GOS;)
4772 #if defined(TESTING)
4773             HDBGRegAR ("ada");
4774 #endif
4775             bool ovf;
4776             cpu.rA = Add36b (cpup, cpu.rA, cpu.CY, 0, I_ZNOC, & cpu.cu.IR, & ovf);
4777 #if defined(TESTING)
4778             HDBGRegAW ("ada");
4779 #endif
4780             overflow (cpup, ovf, false, "ada overflow fault");
4781           }
4782           break;
4783 
4784         case x0 (0077):   // adaq
4785           {
4786             // C(AQ) + C(Y-pair) -> C(AQ)
4787             L68_ (cpu.ou.cycle |= ou_GOS;)
4788 #if defined(TESTING)
4789             HDBGRegAR ("adaq");
4790             HDBGRegQR ("adaq");
4791 #endif
4792             bool ovf;
4793             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
4794             tmp72        = Add72b (cpup, convert_to_word72 (cpu.rA, cpu.rQ),
4795                                    tmp72, 0, I_ZNOC, & cpu.cu.IR, & ovf);
4796             convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
4797 #if defined(TESTING)
4798             HDBGRegAW ("adaq");
4799             HDBGRegQW ("adaq");
4800 #endif
4801             overflow (cpup, ovf, false, "adaq overflow fault");
4802           }
4803           break;
4804 
4805         case x0 (0033):   // adl
4806           {
4807             // C(AQ) + C(Y) sign extended -> C(AQ)
4808             L68_ (cpu.ou.cycle |= ou_GOS;)
4809 #if defined(TESTING)
4810             HDBGRegAR ("adl");
4811             HDBGRegQR ("adl");
4812 #endif
4813             bool ovf;
4814             word72 tmp72 = SIGNEXT36_72 (cpu.CY); // sign extend Cy
4815             tmp72        = Add72b (cpup, convert_to_word72 (cpu.rA, cpu.rQ),
4816                                    tmp72, 0, I_ZNOC, & cpu.cu.IR, & ovf);
4817             convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
4818 #if defined(TESTING)
4819             HDBGRegAW ("adl");
4820             HDBGRegQW ("adl");
4821 #endif
4822             overflow (cpup, ovf, false, "adl overflow fault");
4823           }
4824           break;
4825 
4826         case x0 (0037):   // adlaq
4827           {
4828             // The adlaq instruction is identical to the adaq instruction with
4829             // the exception that the overflow indicator is not affected by the
4830             // adlaq instruction, nor does an overflow fault occur. Operands
4831             // and results are treated as unsigned, positive binary integers.
4832             L68_ (cpu.ou.cycle |= ou_GOS;)
4833 #if defined(TESTING)
4834             HDBGRegAR ("adlaq");
4835             HDBGRegQR ("adlaq");
4836 #endif
4837             bool ovf;
4838             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
4839 
4840             tmp72 = Add72b (cpup, convert_to_word72 (cpu.rA, cpu.rQ),
4841                             tmp72, 0, I_ZNC, & cpu.cu.IR, & ovf);
4842             convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
4843 #if defined(TESTING)
4844             HDBGRegAW ("adlaq");
4845             HDBGRegQW ("adlaq");
4846 #endif
4847           }
4848           break;
4849 
4850         case x0 (0035):   // adla
4851           {
4852             L68_ (cpu.ou.cycle |= ou_GOS;)
4853             // The adla instruction is identical to the ada instruction with
4854             // the exception that the overflow indicator is not affected by the
4855             // adla instruction, nor does an overflow fault occur. Operands and
4856             // results are treated as unsigned, positive binary integers. */
4857 
4858 #if defined(TESTING)
4859             HDBGRegAR ("adla");
4860 #endif
4861             bool ovf;
4862             cpu.rA = Add36b (cpup, cpu.rA, cpu.CY, 0, I_ZNC, & cpu.cu.IR, & ovf);
4863 #if defined(TESTING)
4864             HDBGRegAW ("adla");
4865 #endif
4866           }
4867           break;
4868 
4869         case x0 (0036):   // adlq
4870           {
4871             // The adlq instruction is identical to the adq instruction with
4872             // the exception that the overflow indicator is not affected by the
4873             // adlq instruction, nor does an overflow fault occur. Operands and
4874             // results are treated as unsigned, positive binary integers. */
4875 
4876             L68_ (cpu.ou.cycle |= ou_GOS;)
4877 #if defined(TESTING)
4878             HDBGRegQR ("adlq");
4879 #endif
4880             bool ovf;
4881             cpu.rQ = Add36b (cpup, cpu.rQ, cpu.CY, 0, I_ZNC, & cpu.cu.IR, & ovf);
4882 #if defined(TESTING)
4883             HDBGRegQW ("adlq");
4884 #endif
4885           }
4886           break;
4887 
4888                           // adlxn
4889         case x0 (0020):   // adlx0
4890         case x0 (0021):   // adlx1
4891         case x0 (0022):   // adlx2
4892         case x0 (0023):   // adlx3
4893         case x0 (0024):   // adlx4
4894         case x0 (0025):   // adlx5
4895         case x0 (0026):   // adlx6
4896         case x0 (0027):   // adlx7
4897           {
4898             L68_ (cpu.ou.cycle |= ou_GOS;)
4899             uint32 n = opcode10 & 07;  // get n
4900 #if defined(TESTING)
4901             HDBGRegXR (n, "adlxn");
4902 #endif
4903             bool ovf;
4904             cpu.rX[n] = Add18b (cpup, cpu.rX[n], GETHI (cpu.CY), 0, I_ZNC,
4905                              & cpu.cu.IR, & ovf);
4906 #if defined(TESTING)
4907             HDBGRegXW (n, "adlxn");
4908 #endif
4909           }
4910           break;
4911 
4912 // Optimized to the top of the loop
4913 //        case x0 (0076):   // adq
4914 
4915                           // adxn
4916         case x0 (0060):   // adx0
4917         case x0 (0061):   // adx1
4918         case x0 (0062):   // adx2
4919         case x0 (0063):   // adx3
4920         case x0 (0064):   // adx4
4921         case x0 (0065):   // adx5
4922         case x0 (0066):   // adx6
4923         case x0 (0067):   // adx7
4924           {
4925             L68_ (cpu.ou.cycle |= ou_GOS;)
4926             uint32 n = opcode10 & 07;  // get n
4927 #if defined(TESTING)
4928             HDBGRegXR (n, "adxn");
4929 #endif
4930             bool ovf;
4931             cpu.rX[n] = Add18b (cpup, cpu.rX[n], GETHI (cpu.CY), 0,
4932                                  I_ZNOC,
4933                                  & cpu.cu.IR, & ovf);
4934 #if defined(TESTING)
4935             HDBGRegXW (n, "adxn");
4936 #endif
4937             overflow (cpup, ovf, false, "adxn overflow fault");
4938           }
4939           break;
4940 
4941 // Optimized to the top of the loop
4942 //        case x0 (0054):   // aos
4943 
4944         case x0 (0055):   // asa
4945           {
4946             // C(A) + C(Y) -> C(Y)
4947 
4948             L68_ (cpu.ou.cycle |= ou_GOS;)
4949 #if defined(TESTING)
4950             HDBGRegAR ("asa");
4951 #endif
4952             bool ovf;
4953             cpu.CY = Add36b (cpup, cpu.rA, cpu.CY, 0, I_ZNOC,
4954                              & cpu.cu.IR, & ovf);
4955             overflow (cpup, ovf, true, "asa overflow fault");
4956           }
4957           break;
4958 
4959         case x0 (0056):   // asq
4960           {
4961             // C(Q) + C(Y) -> C(Y)
4962             L68_ (cpu.ou.cycle |= ou_GOS;)
4963 #if defined(TESTING)
4964             HDBGRegQR ("asa");
4965 #endif
4966             bool ovf;
4967             cpu.CY = Add36b (cpup, cpu.rQ, cpu.CY, 0, I_ZNOC, & cpu.cu.IR, & ovf);
4968             overflow (cpup, ovf, true, "asq overflow fault");
4969           }
4970           break;
4971 
4972                           // asxn
4973         case x0 (0040):   // asx0
4974         case x0 (0041):   // asx1
4975         case x0 (0042):   // asx2
4976         case x0 (0043):   // asx3
4977         case x0 (0044):   // asx4
4978         case x0 (0045):   // asx5
4979         case x0 (0046):   // asx6
4980         case x0 (0047):   // asx7
4981           {
4982             // For n = 0, 1, ..., or 7 as determined by operation code
4983             //    C(Xn) + C(Y)0,17 -> C(Y)0,17
4984             L68_ (cpu.ou.cycle |= ou_GOS;)
4985             uint32 n = opcode10 & 07;  // get n
4986 #if defined(TESTING)
4987             HDBGRegXR (n, "asxn");
4988 #endif
4989             bool ovf;
4990             word18 tmp18 = Add18b (cpup, cpu.rX[n], GETHI (cpu.CY), 0,
4991                                    I_ZNOC, & cpu.cu.IR, & ovf);
4992             SETHI (cpu.CY, tmp18);
4993             overflow (cpup, ovf, true, "asxn overflow fault");
4994           }
4995           break;
4996 
4997         case x0 (0071):   // awca
4998           {
4999             // If carry indicator OFF, then C(A) + C(Y) -> C(A)
5000             // If carry indicator ON, then C(A) + C(Y) + 1 -> C(A)
5001 
5002             L68_ (cpu.ou.cycle |= ou_GOS;)
5003 #if defined(TESTING)
5004             HDBGRegAR ("awca");
5005 #endif
5006             bool ovf;
5007             cpu.rA = Add36b (cpup, cpu.rA, cpu.CY, TST_I_CARRY ? 1 : 0,
5008                                  I_ZNOC, & cpu.cu.IR, & ovf);
5009 #if defined(TESTING)
5010             HDBGRegAW ("awca");
5011 #endif
5012             overflow (cpup, ovf, false, "awca overflow fault");
5013           }
5014           break;
5015 
5016         case x0 (0072):   // awcq
5017           {
5018             // If carry indicator OFF, then C(Q) + C(Y) -> C(Q)
5019             // If carry indicator ON, then C(Q) + C(Y) + 1 -> C(Q)
5020 
5021             L68_ (cpu.ou.cycle |= ou_GOS;)
5022 #if defined(TESTING)
5023             HDBGRegQR ("awcq");
5024 #endif
5025             bool ovf;
5026             cpu.rQ = Add36b (cpup, cpu.rQ, cpu.CY, TST_I_CARRY ? 1 : 0,
5027                              I_ZNOC, & cpu.cu.IR, & ovf);
5028 #if defined(TESTING)
5029             HDBGRegQW ("awcq");
5030 #endif
5031             overflow (cpup, ovf, false, "awcq overflow fault");
5032           }
5033           break;
5034 
5035         /// Fixed-Point Subtraction
5036 
5037         case x0 (0175):  // sba
5038           {
5039             // C(A) - C(Y) -> C(A)
5040 
5041             L68_ (cpu.ou.cycle |= ou_GOS;)
5042 #if defined(TESTING)
5043             HDBGRegAR ("sba");
5044 #endif
5045             bool ovf;
5046             cpu.rA = Sub36b (cpup, cpu.rA, cpu.CY, 1, I_ZNOC, & cpu.cu.IR, & ovf);
5047 #if defined(TESTING)
5048             HDBGRegAW ("sba");
5049 #endif
5050             overflow (cpup, ovf, false, "sba overflow fault");
5051           }
5052           break;
5053 
5054         case x0 (0177):  // sbaq
5055           {
5056             // C(AQ) - C(Y-pair) -> C(AQ)
5057             L68_ (cpu.ou.cycle |= ou_GOS;)
5058 #if defined(TESTING)
5059             HDBGRegAR ("sbaq");
5060             HDBGRegQR ("sbaq");
5061 #endif
5062             bool ovf;
5063             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
5064             tmp72 = Sub72b (cpup, convert_to_word72 (cpu.rA, cpu.rQ), tmp72, 1,
5065                             I_ZNOC, & cpu.cu.IR,
5066                             & ovf);
5067             convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
5068 #if defined(TESTING)
5069             HDBGRegAW ("sbaq");
5070             HDBGRegQW ("sbaq");
5071 #endif
5072             overflow (cpup, ovf, false, "sbaq overflow fault");
5073           }
5074           break;
5075 
5076         case x0 (0135):  // sbla
5077           {
5078             // C(A) - C(Y) -> C(A) logical
5079 
5080             L68_ (cpu.ou.cycle |= ou_GOS;)
5081 #if defined(TESTING)
5082             HDBGRegAR ("sbla");
5083 #endif
5084             bool ovf;
5085             cpu.rA = Sub36b (cpup, cpu.rA, cpu.CY, 1, I_ZNC, & cpu.cu.IR, & ovf);
5086 #if defined(TESTING)
5087             HDBGRegAW ("sbla");
5088 #endif
5089           }
5090           break;
5091 
5092         case x0 (0137):  // sblaq
5093           {
5094             // The sblaq instruction is identical to the sbaq instruction with
5095             // the exception that the overflow indicator is not affected by the
5096             // sblaq instruction, nor does an overflow fault occur. Operands
5097             // and results are treated as unsigned, positive binary integers.
5098             // C(AQ) - C(Y-pair) -> C(AQ)
5099 
5100             L68_ (cpu.ou.cycle |= ou_GOS;)
5101 #if defined(TESTING)
5102             HDBGRegAR ("sblaq");
5103             HDBGRegQR ("sblaq");
5104 #endif
5105             bool ovf;
5106             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
5107 
5108             tmp72 = Sub72b (cpup, convert_to_word72 (cpu.rA, cpu.rQ), tmp72, 1,
5109                             I_ZNC, & cpu.cu.IR, & ovf);
5110             convert_to_word36 (tmp72, & cpu.rA, & cpu.rQ);
5111 #if defined(TESTING)
5112             HDBGRegAW ("sblaq");
5113             HDBGRegQW ("sblaq");
5114 #endif
5115           }
5116           break;
5117 
5118         case x0 (0136):  // sblq
5119           {
5120             // C(Q) - C(Y) -> C(Q)
5121             L68_ (cpu.ou.cycle |= ou_GOS;)
5122 #if defined(TESTING)
5123             HDBGRegQR ("sblq");
5124 #endif
5125             bool ovf;
5126             cpu.rQ = Sub36b (cpup, cpu.rQ, cpu.CY, 1, I_ZNC, & cpu.cu.IR, & ovf);
5127 #if defined(TESTING)
5128             HDBGRegQW ("sblq");
5129 #endif
5130           }
5131           break;
5132 
5133                          // sblxn
5134         case x0 (0120):  // sblx0
5135         case x0 (0121):  // sblx1
5136         case x0 (0122):  // sblx2
5137         case x0 (0123):  // sblx3
5138         case x0 (0124):  // sblx4
5139         case x0 (0125):  // sblx5
5140         case x0 (0126):  // sblx6
5141         case x0 (0127):  // sblx7
5142           {
5143             // For n = 0, 1, ..., or 7 as determined by operation code
5144             // C(Xn) - C(Y)0,17 -> C(Xn)
5145 
5146             L68_ (cpu.ou.cycle |= ou_GOS;)
5147             uint32 n = opcode10 & 07;  // get n
5148 #if defined(TESTING)
5149             HDBGRegXR (n, "sblxn");
5150 #endif
5151             bool ovf;
5152             cpu.rX[n] = Sub18b (cpup, cpu.rX[n], GETHI (cpu.CY), 1,
5153                              I_ZNC, & cpu.cu.IR, & ovf);
5154 #if defined(TESTING)
5155             HDBGRegXW (n, "sblxn");
5156 #endif
5157           }
5158           break;
5159 
5160         case x0 (0176):  // sbq
5161           {
5162             // C(Q) - C(Y) -> C(Q)
5163             L68_ (cpu.ou.cycle |= ou_GOS;)
5164 #if defined(TESTING)
5165             HDBGRegQR ("sbq");
5166 #endif
5167             bool ovf;
5168             cpu.rQ = Sub36b (cpup, cpu.rQ, cpu.CY, 1, I_ZNOC, & cpu.cu.IR, & ovf);
5169 #if defined(TESTING)
5170             HDBGRegQW ("sbq");
5171 #endif
5172             overflow (cpup, ovf, false, "sbq overflow fault");
5173           }
5174           break;
5175 
5176                          // sbxn
5177         case x0 (0160):  // sbx0
5178         case x0 (0161):  // sbx1
5179         case x0 (0162):  // sbx2
5180         case x0 (0163):  // sbx3
5181         case x0 (0164):  // sbx4
5182         case x0 (0165):  // sbx5
5183         case x0 (0166):  // sbx6
5184         case x0 (0167):  // sbx7
5185           {
5186             // For n = 0, 1, ..., or 7 as determined by operation code
5187             // C(Xn) - C(Y)0,17 -> C(Xn)
5188 
5189             L68_ (cpu.ou.cycle |= ou_GOS;)
5190             uint32 n = opcode10 & 07;  // get n
5191 #if defined(TESTING)
5192             HDBGRegXR (n, "sbxn");
5193 #endif
5194             bool ovf;
5195             cpu.rX[n] = Sub18b (cpup, cpu.rX[n], GETHI (cpu.CY), 1,
5196                                  I_ZNOC, & cpu.cu.IR, & ovf);
5197 #if defined(TESTING)
5198             HDBGRegXW (n, "sbxn");
5199 #endif
5200             overflow (cpup, ovf, false, "sbxn overflow fault");
5201           }
5202           break;
5203 
5204         case x0 (0155):  // ssa
5205           {
5206             // C(A) - C(Y) -> C(Y)
5207 
5208             L68_ (cpu.ou.cycle |= ou_GOS;)
5209 #if defined(TESTING)
5210             HDBGRegAR ("ssa");
5211 #endif
5212             bool ovf;
5213             cpu.CY = Sub36b (cpup, cpu.rA, cpu.CY, 1, I_ZNOC, & cpu.cu.IR, & ovf);
5214             overflow (cpup, ovf, true, "ssa overflow fault");
5215           }
5216           break;
5217 
5218         case x0 (0156):  // ssq
5219           {
5220             // C(Q) - C(Y) -> C(Y)
5221 
5222             L68_ (cpu.ou.cycle |= ou_GOS;)
5223 #if defined(TESTING)
5224             HDBGRegQR ("ssq");
5225 #endif
5226             bool ovf;
5227             cpu.CY = Sub36b (cpup, cpu.rQ, cpu.CY, 1, I_ZNOC, & cpu.cu.IR, & ovf);
5228             overflow (cpup, ovf, true, "ssq overflow fault");
5229           }
5230           break;
5231 
5232                          // ssxn
5233         case x0 (0140):  // ssx0
5234         case x0 (0141):  // ssx1
5235         case x0 (0142):  // ssx2
5236         case x0 (0143):  // ssx3
5237         case x0 (0144):  // ssx4
5238         case x0 (0145):  // ssx5
5239         case x0 (0146):  // ssx6
5240         case x0 (0147):  // ssx7
5241           {
5242             // For uint32 n = 0, 1, ..., or 7 as determined by operation code
5243             // C(Xn) - C(Y)0,17 -> C(Y)0,17
5244 
5245             L68_ (cpu.ou.cycle |= ou_GOS;)
5246             uint32 n = opcode10 & 07;  // get n
5247 #if defined(TESTING)
5248             HDBGRegXR (n, "ssxn");
5249 #endif
5250             bool ovf;
5251             word18 tmp18 = Sub18b (cpup, cpu.rX[n], GETHI (cpu.CY), 1,
5252                                    I_ZNOC, & cpu.cu.IR, & ovf);
5253             SETHI (cpu.CY, tmp18);
5254             overflow (cpup, ovf, true, "ssxn overflow fault");
5255           }
5256           break;
5257 
5258         case x0 (0171):  // swca
5259           {
5260             // If carry indicator ON, then C(A)- C(Y) -> C(A)
5261             // If carry indicator OFF, then C(A) - C(Y) - 1 -> C(A)
5262 
5263             L68_ (cpu.ou.cycle |= ou_GOS;)
5264 #if defined(TESTING)
5265             HDBGRegAR ("swca");
5266 #endif
5267             bool ovf;
5268             cpu.rA = Sub36b (cpup, cpu.rA, cpu.CY, TST_I_CARRY ? 1 : 0,
5269                              I_ZNOC, & cpu.cu.IR, & ovf);
5270 #if defined(TESTING)
5271             HDBGRegAW ("swca");
5272 #endif
5273             overflow (cpup, ovf, false, "swca overflow fault");
5274           }
5275           break;
5276 
5277         case x0 (0172):  // swcq
5278           {
5279             // If carry indicator ON, then C(Q) - C(Y) -> C(Q)
5280             // If carry indicator OFF, then C(Q) - C(Y) - 1 -> C(Q)
5281 
5282             L68_ (cpu.ou.cycle |= ou_GOS;)
5283 #if defined(TESTING)
5284             HDBGRegQR ("swcq");
5285 #endif
5286             bool ovf;
5287             cpu.rQ = Sub36b (cpup, cpu.rQ, cpu.CY, TST_I_CARRY ? 1 : 0,
5288                                  I_ZNOC, & cpu.cu.IR, & ovf);
5289 #if defined(TESTING)
5290             HDBGRegQW ("swcq");
5291 #endif
5292             overflow (cpup, ovf, false, "swcq overflow fault");
5293           }
5294           break;
5295 
5296         /// Fixed-Point Multiplication
5297 
5298         case x0 (0401):  // mpf
5299           {
5300             // C(A) * C(Y) -> C(AQ), left adjusted
5301             //
5302             // Two 36-bit fractional factors (including sign) are multiplied
5303             // to form a 71- bit fractional product (including sign), which
5304             // is stored left-adjusted in the AQ register. AQ71 contains a
5305             // zero. Overflow can occur only in the case of A and Y
5306             // containing negative 1 and the result exceeding the range of
5307             // the AQ register.
5308 
5309             L68_ (cpu.ou.cycle |= ou_GD1;)
5310 #if defined(NEED_128)
5311 # if defined(TESTING)
5312             HDBGRegAR ("mpf");
5313             HDBGRegQR ("mpf");
5314 # endif
5315             word72 tmp72 = multiply_128 (SIGNEXT36_72 (cpu.rA), SIGNEXT36_72 (cpu.CY));
5316             tmp72        = and_128 (tmp72, MASK72);
5317             tmp72        = lshift_128 (tmp72, 1);
5318 #else
5319             // word72 tmp72 = SIGNEXT36_72 (cpu.rA) * SIGNEXT36_72 (cpu.CY);
5320             // ubsan
5321             word72 tmp72 = (word72) (((word72s) SIGNEXT36_72 (cpu.rA)) * ((word72s) SIGNEXT36_72 (cpu.CY)));
5322             tmp72 &= MASK72;
5323             tmp72 <<= 1;    // left adjust so AQ71 contains 0
5324 #endif
5325             L68_ (cpu.ou.cycle |= ou_GD2;)
5326             // Overflow can occur only in the case of A and Y containing
5327             // negative 1
5328             if (cpu.rA == MAXNEG && cpu.CY == MAXNEG)
5329               {
5330                 SET_I_NEG;
5331                 CLR_I_ZERO;
5332                 overflow (cpup, true, false, "mpf overflow fault");
5333               }
5334 
5335             convert_to_word36 (tmp72, &cpu.rA, &cpu.rQ);
5336 #if defined(TESTING)
5337             HDBGRegAW ("mpf");
5338             HDBGRegQW ("mpf");
5339 #endif
5340             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
5341             SC_I_NEG (cpu.rA & SIGN36);
5342           }
5343           break;
5344 
5345         case x0 (0402):  // mpy
5346           // C(Q) * C(Y) -> C(AQ), right adjusted
5347 
5348           {
5349             L68_ (cpu.ou.cycle |= ou_GOS;)
5350 #if defined(NEED_128)
5351 # if defined(TESTING)
5352             HDBGRegQR ("mpy");
5353 # endif
5354             int128 prod = multiply_s128 (
5355               SIGNEXT36_128 (cpu.rQ & DMASK),
5356               SIGNEXT36_128 (cpu.CY & DMASK));
5357             convert_to_word36 (cast_128 (prod), &cpu.rA, &cpu.rQ);
5358 #else
5359             int64_t t0 = SIGNEXT36_64 (cpu.rQ & DMASK);
5360             int64_t t1 = SIGNEXT36_64 (cpu.CY & DMASK);
5361 
5362             __int128_t prod = (__int128_t) t0 * (__int128_t) t1;
5363 
5364             convert_to_word36 ((word72)prod, &cpu.rA, &cpu.rQ);
5365 #endif
5366 #if defined(TESTING)
5367             HDBGRegAW ("mpy");
5368             HDBGRegQW ("mpy");
5369 #endif
5370 
5371             SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
5372             SC_I_NEG (cpu.rA & SIGN36);
5373           }
5374           break;
5375 
5376 //#define DIV_TRACE
5377 
5378         /// Fixed-Point Division
5379 
5380         case x0 (0506):  // div
5381           // C(Q) / (Y) integer quotient -> C(Q), integer remainder -> C(A)
5382           //
5383           // A 36-bit integer dividend (including sign) is divided by a
5384           // 36-bit integer divisor (including sign) to form a 36-bit integer
5385           // * quotient (including sign) and a 36-bit integer remainder
5386           // * (including sign). The remainder sign is equal to the dividend
5387           // * sign unless the remainder is zero.
5388           // *
5389           // * If the dividend = -2**35 and the divisor = -1 or if the divisor
5390           // * = 0, then division does not take place. Instead, a divide check
5391           // * fault occurs, C(Q) contains the dividend magnitude, and the
5392           // * negative indicator reflects the dividend sign.
5393 
5394           L68_ (cpu.ou.cycle |= ou_GD1;)
5395           // RJ78: If the dividend = -2**35 and the divisor = +/-1, or if
5396           // the divisor is 0
5397 
5398 #if defined(TESTING)
5399           HDBGRegQR ("div");
5400 #endif
5401           if ((cpu.rQ == MAXNEG && (cpu.CY == 1 || cpu.CY == NEG136)) ||
5402               (cpu.CY == 0))
5403             {
5404 //sim_printf ("DIV Q %012"PRIo64" Y %012"PRIo64"\r\n", cpu.rQ, cpu.CY);
5405 // case 1  400000000000 000000000000 --> 000000000000
5406 // case 2  000000000000 000000000000 --> 400000000000
5407               //cpu.rA = 0;  // works for case 1
5408               cpu.rA = (cpu.rQ & SIGN36) ? 0 : SIGN36; // works for case 1,2
5409 #if defined(TESTING)
5410               HDBGRegAW ("div");
5411 #endif
5412 
5413               // no division takes place
5414               SC_I_ZERO (cpu.CY == 0);
5415               SC_I_NEG (cpu.rQ & SIGN36);
5416 
5417               if (cpu.rQ & SIGN36)
5418                 {
5419                   // cpu.rQ = (- cpu.rQ) & MASK36;
5420                   // ubsan
5421                   cpu.rQ = ((word36) (- (word36s) cpu.rQ)) & MASK36;
5422 #if defined(TESTING)
5423                   HDBGRegQW ("div");
5424 #endif
5425                 }
5426 
5427               dlyDoFault (FAULT_DIV,
5428                           fst_ill_op,
5429                           "div divide check");
5430             }
5431           else
5432             {
5433               t_int64 dividend = (t_int64) (SIGNEXT36_64 (cpu.rQ));
5434               t_int64 divisor  = (t_int64) (SIGNEXT36_64 (cpu.CY));
5435 #if defined(TESTING)
5436 # if defined(DIV_TRACE)
5437               sim_debug (DBG_CAC, & cpu_dev, "\r\n");
5438               sim_debug (DBG_CAC, & cpu_dev,
5439                          ">>> dividend cpu.rQ %"PRId64" (%012"PRIo64")\r\n",
5440                          dividend, cpu.rQ);
5441               sim_debug (DBG_CAC, & cpu_dev,
5442                          ">>> divisor  CY %"PRId64" (%012"PRIo64")\r\n",
5443                          divisor, cpu.CY);
5444 # endif
5445 #endif
5446 
5447               t_int64 quotient = dividend / divisor;
5448               L68_ (cpu.ou.cycle |= ou_GD2;)
5449               t_int64 remainder = dividend % divisor;
5450 #if defined(TESTING)
5451 # if defined(DIV_TRACE)
5452               sim_debug (DBG_CAC, & cpu_dev, ">>> quot 1 %"PRId64"\r\n", quotient);
5453               sim_debug (DBG_CAC, & cpu_dev, ">>> rem 1 %"PRId64"\r\n", remainder);
5454 # endif
5455 #endif
5456 
5457 // Evidence is that DPS8M rounds toward zero; if it turns out that it
5458 // rounds toward -inf, try this code:
5459 
5460 
5461 
5462 
5463 
5464 
5465 
5466 
5467 
5468 
5469 
5470 
5471 
5472 
5473 
5474 
5475 
5476 #if defined(TESTING)
5477 # if defined(DIV_TRACE)
5478               //  (a/b)*b + a%b is equal to a.
5479               sim_debug (DBG_CAC, & cpu_dev,
5480                          "dividend was                   = %"PRId64"\r\n", dividend);
5481               sim_debug (DBG_CAC, & cpu_dev,
5482                          "quotient * divisor + remainder = %"PRId64"\r\n",
5483                          quotient * divisor + remainder);
5484               if (dividend != quotient * divisor + remainder)
5485                 {
5486                   sim_debug (DBG_CAC, & cpu_dev,
5487                      "---------------------------------^^^^^^^^^^^^^^^\r\n");
5488                 }
5489 # endif
5490 #endif
5491 
5492               if (dividend != quotient * divisor + remainder)
5493                 {
5494                   sim_debug (DBG_ERR, & cpu_dev,
5495                              "Internal division error;"
5496                              " rQ %012"PRIo64" CY %012"PRIo64"\r\n", cpu.rQ, cpu.CY);
5497                 }
5498 
5499               cpu.rA = (word36) remainder & DMASK;
5500               cpu.rQ = (word36) quotient & DMASK;
5501 #if defined(TESTING)
5502               HDBGRegAW ("div");
5503               HDBGRegQW ("div");
5504 
5505 # if defined(DIV_TRACE)
5506               sim_debug (DBG_CAC, & cpu_dev, "rA (rem)  %012"PRIo64"\r\n", cpu.rA);
5507               sim_debug (DBG_CAC, & cpu_dev, "rQ (quot) %012"PRIo64"\r\n", cpu.rQ);
5508 # endif
5509 #endif
5510 
5511               SC_I_ZERO (cpu.rQ == 0);
5512               SC_I_NEG (cpu.rQ & SIGN36);
5513             }
5514 
5515           break;
5516 
5517         case x0 (0507):  // dvf
5518           // C(AQ) / (Y)
5519           //  fractional quotient -> C(A)
5520           //  fractional remainder -> C(Q)
5521 
5522           // A 71-bit fractional dividend (including sign) is divided by a
5523           // 36-bit fractional divisor yielding a 36-bit fractional quotient
5524           // (including sign) and a 36-bit fractional remainder (including
5525           // sign). C(AQ)71 is ignored; bit position 35 of the remainder
5526           // corresponds to bit position 70 of the dividend. The remainder
5527           // sign is equal to the dividend sign unless the remainder is zero.
5528 
5529           // If | dividend | >= | divisor | or if the divisor = 0, division
5530           // does not take place. Instead, a divide check fault occurs, C(AQ)
5531           // contains the dividend magnitude in absolute, and the negative
5532           // indicator reflects the dividend sign.
5533 
5534           dvf (cpup);
5535 
5536           break;
5537 
5538         /// Fixed-Point Negate
5539 
5540         case x0 (0531):  // neg
5541           // -C(A) -> C(A) if C(A) != 0
5542 
5543 #if defined(TESTING)
5544           HDBGRegAR ("neg");
5545 #endif
5546           cpu.rA &= DMASK;
5547           if (cpu.rA == 0400000000000ULL)
5548             {
5549               CLR_I_ZERO;
5550               SET_I_NEG;
5551               overflow (cpup, true, false, "neg overflow fault");
5552             }
5553 
5554           //cpu.rA = -cpu.rA;
5555           // ubsan
5556           cpu.rA = (word36) (- (word36s) cpu.rA);
5557 
5558           cpu.rA &= DMASK;    // keep to 36-bits
5559 #if defined(TESTING)
5560           HDBGRegAW ("neg");
5561 #endif
5562 
5563           SC_I_ZERO (cpu.rA == 0);
5564           SC_I_NEG (cpu.rA & SIGN36);
5565 
5566           break;
5567 
5568         case x0 (0533):  // negl
5569           // -C(AQ) -> C(AQ) if C(AQ) != 0
5570           {
5571 #if defined(TESTING)
5572             HDBGRegAR ("negl");
5573             HDBGRegQR ("negl");
5574 #endif
5575             cpu.rA &= DMASK;
5576             cpu.rQ &= DMASK;
5577 
5578             if (cpu.rA == 0400000000000ULL && cpu.rQ == 0)
5579             {
5580                 CLR_I_ZERO;
5581                 SET_I_NEG;
5582                 overflow (cpup, true, false, "negl overflow fault");
5583             }
5584 
5585             word72 tmp72 = convert_to_word72 (cpu.rA, cpu.rQ);
5586 #if defined(NEED_128)
5587             tmp72 = negate_128 (tmp72);
5588 
5589             SC_I_ZERO (iszero_128 (tmp72));
5590             SC_I_NEG (isnonzero_128 (and_128 (tmp72, SIGN72)));
5591 #else
5592             //tmp72 = -tmp72;
5593             // ubsan
5594             tmp72 = (word72) (-(word72s) tmp72);
5595 
5596             SC_I_ZERO (tmp72 == 0);
5597             SC_I_NEG (tmp72 & SIGN72);
5598 #endif
5599 
5600             convert_to_word36 (tmp72, &cpu.rA, &cpu.rQ);
5601 #if defined(TESTING)
5602             HDBGRegAW ("negl");
5603             HDBGRegQW ("negl");
5604 #endif
5605           }
5606           break;
5607 
5608         /// Fixed-Point Comparison
5609 
5610         case x0 (0405):  // cmg
5611           // | C(A) | :: | C(Y) |
5612           // Zero:     If | C(A) | = | C(Y) | , then ON; otherwise OFF
5613           // Negative: If | C(A) | < | C(Y) | , then ON; otherwise OFF
5614           {
5615             // This is wrong for MAXNEG
5616             //word36 a = cpu.rA & SIGN36 ? -cpu.rA : cpu.rA;
5617             //word36 y = cpu.CY & SIGN36 ? -cpu.CY : cpu.CY;
5618 
5619               // If we do the 64 math, the MAXNEG case works
5620 #if defined(TESTING)
5621               HDBGRegAR ("cmg");
5622 #endif
5623               t_int64 a = SIGNEXT36_64 (cpu.rA);
5624               if (a < 0)
5625                 a = -a;
5626               t_int64 y = SIGNEXT36_64 (cpu.CY);
5627               if (y < 0)
5628                 y = -y;
5629 
5630               SC_I_ZERO (a == y);
5631               SC_I_NEG (a < y);
5632           }
5633           break;
5634 
5635         case x0 (0211):  // cmk
5636           // For i = 0, 1, ..., 35
5637           // C(Z)i = ~C(Q)i & ( C(A)i XOR C(Y)i )
5638 
5639           /*
5640            * The cmk instruction compares the contents of bit positions of A
5641            * and Y for identity that are not masked by a 1 in the
5642            * corresponding bit position of Q.
5643            *
5644            * The zero indicator is set ON if the comparison is successful for
5645            * all bit positions; i.e., if for all i = 0, 1, ..., 35 there is
5646            * either: C(A)i = C(Y)i (the identical case) or C(Q)i = 1 (the
5647            * masked case); otherwise, the zero indicator is set OFF.
5648            *
5649            * The negative indicator is set ON if the comparison is
5650            * unsuccessful for bit position 0; i.e., if C(A)0 XOR C(Y)0 (they
5651            * are nonidentical) as well as C(Q)0 = 0 (they are unmasked);
5652            * otherwise, the negative indicator is set OFF.
5653            */
5654           {
5655 #if defined(TESTING)
5656             HDBGRegAR ("cmk");
5657             HDBGRegQR ("cmk");
5658             HDBGRegYR ("cmk");
5659 #endif
5660             word36 Z = ~cpu.rQ & (cpu.rA ^ cpu.CY);
5661             Z &= DMASK;
5662 #if defined(TESTING)
5663             HDBGRegZW (Z, "cmk");
5664             HDBGRegIR ("cmk");
5665 #endif
5666 
5667 // Q  A  Y   ~Q   A^Y   Z
5668 // 0  0  0    1     0   0
5669 // 0  0  1    1     1   1
5670 // 0  1  0    1     1   1
5671 // 0  1  1    1     0   0
5672 // 1  0  0    0     0   0
5673 // 1  0  1    0     1   0
5674 // 1  1  0    0     1   0
5675 // 1  1  1    0     0   0
5676 
5677             SC_I_ZERO (Z == 0);
5678             SC_I_NEG (Z & SIGN36);
5679           }
5680           break;
5681 
5682 // Optimized to the top of the loop
5683 //        case x0 (0115):  // cmpa
5684 
5685         case x0 (0117):  // cmpaq
5686           // C(AQ) :: C(Y-pair)
5687           {
5688 #if defined(TESTING)
5689             HDBGRegAR ("cmpaq");
5690             HDBGRegQR ("cmpaq");
5691 #endif
5692             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
5693             word72 trAQ = convert_to_word72 (cpu.rA, cpu.rQ);
5694 #if defined(NEED_128)
5695             trAQ = and_128 (trAQ, MASK72);
5696 #else
5697             trAQ &= MASK72;
5698 #endif
5699             cmp72 (cpup, trAQ, tmp72, &cpu.cu.IR);
5700           }
5701           break;
5702 
5703 // Optimized to the top of the loop
5704 //         case x0 (0116):  // cmpq
5705 
5706                          // cmpxn
5707         case x0 (0100):  // cmpx0
5708         case x0 (0101):  // cmpx1
5709         case x0 (0102):  // cmpx2
5710         case x0 (0103):  // cmpx3
5711         case x0 (0104):  // cmpx4
5712         case x0 (0105):  // cmpx5
5713         case x0 (0106):  // cmpx6
5714         case x0 (0107):  // cmpx7
5715           // For n = 0, 1, ..., or 7 as determined by operation code
5716           // C(Xn) :: C(Y)0,17
5717           {
5718             uint32 n = opcode10 & 07;  // get n
5719 #if defined(TESTING)
5720             HDBGRegXR (n, "cmpxn");
5721 #endif
5722             cmp18 (cpup, cpu.rX[n], GETHI (cpu.CY), &cpu.cu.IR);
5723           }
5724           break;
5725 
5726         case x0 (0111):  // cwl
5727           // C(Y) :: closed interval [C(A);C(Q)]
5728           /*
5729            * The cwl instruction tests the value of C(Y) to determine if it
5730            * is within the range of values set by C(A) and C(Q). The
5731            * comparison of C(Y) with C(Q) locates C(Y) with respect to the
5732            * interval if C(Y) is not contained within the interval.
5733            */
5734 #if defined(TESTING)
5735           HDBGRegAR ("cwl");
5736           HDBGRegQR ("cwl");
5737 #endif
5738           cmp36wl (cpup, cpu.rA, cpu.CY, cpu.rQ, &cpu.cu.IR);
5739           break;
5740 
5741         /// Fixed-Point Miscellaneous
5742 
5743         case x0 (0234):  // szn
5744           // Set indicators according to C(Y)
5745           cpu.CY &= DMASK;
5746           SC_I_ZERO (cpu.CY == 0);
5747           SC_I_NEG (cpu.CY & SIGN36);
5748           break;
5749 
5750         case x0 (0214):  // sznc
5751           // Set indicators according to C(Y)
5752           cpu.CY &= DMASK;
5753           SC_I_ZERO (cpu.CY == 0);
5754           SC_I_NEG (cpu.CY & SIGN36);
5755           // ... and clear
5756           cpu.CY = 0;
5757           break;
5758 
5759         /// BOOLEAN OPERATION INSTRUCTIONS
5760 
5761         /// Boolean And
5762 
5763 // Optimized to the top of the loop
5764 //        case x0 (0375):  // ana
5765 
5766 // Optimized to the top of the loop
5767 //        case x0 (0377):  //< anaq
5768 
5769         case x0 (0376):  // anq
5770           // C(Q)i & C(Y)i -> C(Q)i for i = (0, 1, ..., 35)
5771 #if defined(TESTING)
5772           HDBGRegQR ("anq");
5773 #endif
5774           cpu.rQ  = cpu.rQ & cpu.CY;
5775           cpu.rQ &= DMASK;
5776 #if defined(TESTING)
5777           HDBGRegQW ("anq");
5778 #endif
5779 
5780           SC_I_ZERO (cpu.rQ == 0);
5781           SC_I_NEG (cpu.rQ & SIGN36);
5782           break;
5783 
5784         case x0 (0355):  // ansa
5785           // C(A)i & C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
5786           {
5787 #if defined(TESTING)
5788             HDBGRegAR ("ansa");
5789 #endif
5790             cpu.CY  = cpu.rA & cpu.CY;
5791             cpu.CY &= DMASK;
5792 
5793             SC_I_ZERO (cpu.CY == 0);
5794             SC_I_NEG (cpu.CY & SIGN36);
5795           }
5796           break;
5797 
5798         case x0 (0356):  // ansq
5799           // C(Q)i & C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
5800           {
5801 #if defined(TESTING)
5802             HDBGRegQR ("ansq");
5803 #endif
5804             cpu.CY  = cpu.rQ & cpu.CY;
5805             cpu.CY &= DMASK;
5806 
5807             SC_I_ZERO (cpu.CY == 0);
5808             SC_I_NEG (cpu.CY & SIGN36);
5809           }
5810           break;
5811 
5812                          // ansxn
5813         case x0 (0340):  // ansx0
5814         case x0 (0341):  // ansx1
5815         case x0 (0342):  // ansx2
5816         case x0 (0343):  // ansx3
5817         case x0 (0344):  // ansx4
5818         case x0 (0345):  // ansx5
5819         case x0 (0346):  // ansx6
5820         case x0 (0347):  // ansx7
5821           // For n = 0, 1, ..., or 7 as determined by operation code
5822           // C(Xn)i & C(Y)i -> C(Y)i for i = (0, 1, ..., 17)
5823           {
5824             uint32 n = opcode10 & 07;  // get n
5825 #if defined(TESTING)
5826             HDBGRegXR (n, "ansxn");
5827 #endif
5828             word18 tmp18 = cpu.rX[n] & GETHI (cpu.CY);
5829             tmp18 &= MASK18;
5830 
5831             SC_I_ZERO (tmp18 == 0);
5832             SC_I_NEG (tmp18 & SIGN18);
5833 
5834             SETHI (cpu.CY, tmp18);
5835           }
5836 
5837           break;
5838 
5839                          // anxn
5840         case x0 (0360):  // anx0
5841         case x0 (0361):  // anx1
5842         case x0 (0362):  // anx2
5843         case x0 (0363):  // anx3
5844         case x0 (0364):  // anx4
5845         case x0 (0365):  // anx5
5846         case x0 (0366):  // anx6
5847         case x0 (0367):  // anx7
5848           // For n = 0, 1, ..., or 7 as determined by operation code
5849           // C(Xn)i & C(Y)i -> C(Xn)i for i = (0, 1, ..., 17)
5850           {
5851               uint32 n = opcode10 & 07;  // get n
5852 #if defined(TESTING)
5853               HDBGRegXR (n, "anxn");
5854 #endif
5855               cpu.rX[n] &= GETHI (cpu.CY);
5856               cpu.rX[n] &= MASK18;
5857 #if defined(TESTING)
5858               HDBGRegXW (n, "anxn");
5859 #endif
5860 
5861               SC_I_ZERO (cpu.rX[n] == 0);
5862               SC_I_NEG (cpu.rX[n] & SIGN18);
5863           }
5864           break;
5865 
5866         /// Boolean Or
5867 
5868 // Optimized to the top of the loop
5869 //        case x0 (0275):  // ora
5870 
5871         case x0 (0277):  // oraq
5872           // C(AQ)i | C(Y-pair)i -> C(AQ)i for i = (0, 1, ..., 71)
5873           {
5874 #if defined(TESTING)
5875               HDBGRegAR ("oraq");
5876               HDBGRegQR ("oraq");
5877 #endif
5878               word72 tmp72 = YPAIRTO72 (cpu.Ypair);
5879               word72 trAQ  = convert_to_word72 (cpu.rA, cpu.rQ);
5880 #if defined(NEED_128)
5881               trAQ = or_128 (trAQ, tmp72);
5882               trAQ = and_128 (trAQ, MASK72);
5883 
5884               SC_I_ZERO (iszero_128 (trAQ));
5885               SC_I_NEG (isnonzero_128 (and_128 (trAQ, SIGN72)));
5886 #else
5887               trAQ  = trAQ | tmp72;
5888               trAQ &= MASK72;
5889 
5890               SC_I_ZERO (trAQ == 0);
5891               SC_I_NEG (trAQ & SIGN72);
5892 #endif
5893               convert_to_word36 (trAQ, &cpu.rA, &cpu.rQ);
5894 #if defined(TESTING)
5895               HDBGRegAW ("oraq");
5896               HDBGRegQW ("oraq");
5897 #endif
5898           }
5899           break;
5900 
5901         case x0 (0276):  // orq
5902           // C(Q)i | C(Y)i -> C(Q)i for i = (0, 1, ..., 35)
5903 #if defined(TESTING)
5904           HDBGRegQR ("orq");
5905 #endif
5906           cpu.rQ  = cpu.rQ | cpu.CY;
5907           cpu.rQ &= DMASK;
5908 #if defined(TESTING)
5909           HDBGRegQW ("orq");
5910 #endif
5911 
5912           SC_I_ZERO (cpu.rQ == 0);
5913           SC_I_NEG (cpu.rQ & SIGN36);
5914 
5915           break;
5916 
5917         case x0 (0255):  // orsa
5918           // C(A)i | C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
5919 #if defined(TESTING)
5920           HDBGRegAR ("orsa");
5921 #endif
5922           cpu.CY  = cpu.rA | cpu.CY;
5923           cpu.CY &= DMASK;
5924 
5925           SC_I_ZERO (cpu.CY == 0);
5926           SC_I_NEG (cpu.CY & SIGN36);
5927           break;
5928 
5929         case x0 (0256):  // orsq
5930           // C(Q)i | C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
5931 #if defined(TESTING)
5932           HDBGRegQR ("orsq");
5933 #endif
5934           cpu.CY  = cpu.rQ | cpu.CY;
5935           cpu.CY &= DMASK;
5936 
5937           SC_I_ZERO (cpu.CY == 0);
5938           SC_I_NEG (cpu.CY & SIGN36);
5939           break;
5940 
5941                          // orsxn
5942         case x0 (0240):  // orsx0
5943         case x0 (0241):  // orsx1
5944         case x0 (0242):  // orsx2
5945         case x0 (0243):  // orsx3
5946         case x0 (0244):  // orsx4
5947         case x0 (0245):  // orsx5
5948         case x0 (0246):  // orsx6
5949         case x0 (0247):  // orsx7
5950           // For n = 0, 1, ..., or 7 as determined by operation code
5951           // C(Xn)i | C(Y)i -> C(Y)i for i = (0, 1, ..., 17)
5952           {
5953             uint32 n = opcode10 & 07;  // get n
5954 
5955             word18 tmp18  = cpu.rX[n] | GETHI (cpu.CY);
5956             tmp18        &= MASK18;
5957 
5958             SC_I_ZERO (tmp18 == 0);
5959             SC_I_NEG (tmp18 & SIGN18);
5960 
5961             SETHI (cpu.CY, tmp18);
5962           }
5963           break;
5964 
5965                          // orxn
5966         case x0 (0260):  // orx0
5967         case x0 (0261):  // orx1
5968         case x0 (0262):  // orx2
5969         case x0 (0263):  // orx3
5970         case x0 (0264):  // orx4
5971         case x0 (0265):  // orx5
5972         case x0 (0266):  // orx6
5973         case x0 (0267):  // orx7
5974           // For n = 0, 1, ..., or 7 as determined by operation code
5975           // C(Xn)i | C(Y)i -> C(Xn)i for i = (0, 1, ..., 17)
5976           {
5977               uint32 n = opcode10 & 07;  // get n
5978 #if defined(TESTING)
5979               HDBGRegXR (n, "orxn");
5980 #endif
5981               cpu.rX[n] |= GETHI (cpu.CY);
5982               cpu.rX[n] &= MASK18;
5983 #if defined(TESTING)
5984               HDBGRegXW (n, "orxn");
5985 #endif
5986 
5987               SC_I_ZERO (cpu.rX[n] == 0);
5988               SC_I_NEG (cpu.rX[n] & SIGN18);
5989           }
5990           break;
5991 
5992         /// Boolean Exclusive Or
5993 
5994         case x0 (0675):  // era
5995           // C(A)i XOR C(Y)i -> C(A)i for i = (0, 1, ..., 35)
5996 #if defined(TESTING)
5997           HDBGRegAR ("era");
5998 #endif
5999           cpu.rA  = cpu.rA ^ cpu.CY;
6000           cpu.rA &= DMASK;
6001 #if defined(TESTING)
6002           HDBGRegAW ("era");
6003 #endif
6004 
6005           SC_I_ZERO (cpu.rA == 0);
6006           SC_I_NEG (cpu.rA & SIGN36);
6007 
6008           break;
6009 
6010 // Optimized to the top of the loop
6011 //        case x0 (0677):  // eraq
6012 
6013         case x0 (0676):  // erq
6014           // C(Q)i XOR C(Y)i -> C(Q)i for i = (0, 1, ..., 35)
6015 #if defined(TESTING)
6016           HDBGRegQR ("eraq");
6017 #endif
6018           cpu.rQ  = cpu.rQ ^ cpu.CY;
6019           cpu.rQ &= DMASK;
6020 #if defined(TESTING)
6021           HDBGRegQW ("eraq");
6022 #endif
6023           SC_I_ZERO (cpu.rQ == 0);
6024           SC_I_NEG (cpu.rQ & SIGN36);
6025           break;
6026 
6027         case x0 (0655):  // ersa
6028           // C(A)i XOR C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
6029 #if defined(TESTING)
6030           HDBGRegAR ("ersa");
6031 #endif
6032           cpu.CY  = cpu.rA ^ cpu.CY;
6033           cpu.CY &= DMASK;
6034 
6035           SC_I_ZERO (cpu.CY == 0);
6036           SC_I_NEG (cpu.CY & SIGN36);
6037           break;
6038 
6039         case x0 (0656):  // ersq
6040           // C(Q)i XOR C(Y)i -> C(Y)i for i = (0, 1, ..., 35)
6041 #if defined(TESTING)
6042           HDBGRegQR ("ersq");
6043 #endif
6044           cpu.CY  = cpu.rQ ^ cpu.CY;
6045           cpu.CY &= DMASK;
6046 
6047           SC_I_ZERO (cpu.CY == 0);
6048           SC_I_NEG (cpu.CY & SIGN36);
6049 
6050           break;
6051 
6052                           // ersxn
6053         case x0 (0640):   // ersx0
6054         case x0 (0641):   // ersx1
6055         case x0 (0642):   // ersx2
6056         case x0 (0643):   // ersx3
6057         case x0 (0644):   // ersx4
6058         case x0 (0645):   // ersx5
6059         case x0 (0646):   // ersx6
6060         case x0 (0647):   // ersx7
6061           // For n = 0, 1, ..., or 7 as determined by operation code
6062           // C(Xn)i XOR C(Y)i -> C(Y)i for i = (0, 1, ..., 17)
6063           {
6064             uint32 n = opcode10 & 07;  // get n
6065 #if defined(TESTING)
6066             HDBGRegXR (n, "ersxn");
6067 #endif
6068 
6069             word18 tmp18  = cpu.rX[n] ^ GETHI (cpu.CY);
6070             tmp18        &= MASK18;
6071 
6072             SC_I_ZERO (tmp18 == 0);
6073             SC_I_NEG (tmp18 & SIGN18);
6074 
6075             SETHI (cpu.CY, tmp18);
6076           }
6077           break;
6078 
6079                          // erxn
6080         case x0 (0660):  // erx0
6081         case x0 (0661):  // erx1
6082         case x0 (0662):  // erx2
6083         case x0 (0663):  // erx3
6084         case x0 (0664):  // erx4
6085         case x0 (0665):  // erx5
6086         case x0 (0666):  // erx6  !!!! Beware !!!!
6087         case x0 (0667):  // erx7
6088           // For n = 0, 1, ..., or 7 as determined by operation code
6089           // C(Xn)i XOR C(Y)i -> C(Xn)i for i = (0, 1, ..., 17)
6090           {
6091             uint32 n = opcode10 & 07;  // get n
6092 #if defined(TESTING)
6093             HDBGRegXR (n, "erxn");
6094 #endif
6095             cpu.rX[n] ^= GETHI (cpu.CY);
6096             cpu.rX[n] &= MASK18;
6097 #if defined(TESTING)
6098             HDBGRegXW (n, "erxn");
6099 #endif
6100 
6101             SC_I_ZERO (cpu.rX[n] == 0);
6102             SC_I_NEG (cpu.rX[n] & SIGN18);
6103           }
6104           break;
6105 
6106         /// Boolean Comparative And
6107 
6108 // Optimized to the top of the loop
6109 //        case x0 (0315):  // cana
6110 
6111         case x0 (0317):  // canaq
6112           // C(Z)i = C(AQ)i & C(Y-pair)i for i = (0, 1, ..., 71)
6113           {
6114 #if defined(TESTING)
6115             HDBGRegAR ("canaq");
6116             HDBGRegQR ("canaq");
6117 #endif
6118             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
6119             word72 trAQ  = convert_to_word72 (cpu.rA, cpu.rQ);
6120 #if defined(NEED_128)
6121             trAQ = and_128 (trAQ, tmp72);
6122             trAQ = and_128 (trAQ, MASK72);
6123 
6124             SC_I_ZERO (iszero_128 (trAQ));
6125             SC_I_NEG (isnonzero_128 (and_128 (trAQ, SIGN72)));
6126 #else
6127             trAQ = trAQ & tmp72;
6128             trAQ &= MASK72;
6129 
6130             SC_I_ZERO (trAQ == 0);
6131             SC_I_NEG (trAQ & SIGN72);
6132 #endif
6133           }
6134             break;
6135 
6136         case x0 (0316):  // canq
6137           // C(Z)i = C(Q)i & C(Y)i for i = (0, 1, ..., 35)
6138           {
6139 #if defined(TESTING)
6140             HDBGRegQR ("canq");
6141 #endif
6142             word36 trZ = cpu.rQ & cpu.CY;
6143             trZ &= DMASK;
6144 
6145             SC_I_ZERO (trZ == 0);
6146             SC_I_NEG (trZ & SIGN36);
6147           }
6148           break;
6149 
6150                          // canxn
6151         case x0 (0300):  // canx0
6152         case x0 (0301):  // canx1
6153         case x0 (0302):  // canx2
6154         case x0 (0303):  // canx3
6155         case x0 (0304):  // canx4
6156         case x0 (0305):  // canx5
6157         case x0 (0306):  // canx6
6158         case x0 (0307):  // canx7
6159           // For n = 0, 1, ..., or 7 as determined by operation code
6160           // C(Z)i = C(Xn)i & C(Y)i for i = (0, 1, ..., 17)
6161           {
6162             uint32 n = opcode10 & 07;  // get n
6163 #if defined(TESTING)
6164             HDBGRegXR (n, "canxn");
6165 #endif
6166             word18 tmp18  = cpu.rX[n] & GETHI (cpu.CY);
6167             tmp18        &= MASK18;
6168             sim_debug (DBG_TRACEEXT, & cpu_dev,
6169                        "n %o rX %06o HI %06o tmp %06o\r\n",
6170                        n, cpu.rX[n], (word18) (GETHI (cpu.CY) & MASK18),
6171                        tmp18);
6172 
6173             SC_I_ZERO (tmp18 == 0);
6174             SC_I_NEG (tmp18 & SIGN18);
6175           }
6176           break;
6177 
6178         /// Boolean Comparative Not
6179 
6180         case x0 (0215):  // cnaa
6181           // C(Z)i = C(A)i & ~C(Y)i for i = (0, 1, ..., 35)
6182           {
6183 #if defined(TESTING)
6184             HDBGRegAR ("cnaa");
6185 #endif
6186             word36 trZ = cpu.rA & ~cpu.CY;
6187             trZ &= DMASK;
6188 
6189             SC_I_ZERO (trZ == 0);
6190             SC_I_NEG (trZ & SIGN36);
6191           }
6192           break;
6193 
6194         case x0 (0217):  // cnaaq
6195           // C(Z)i = C (AQ)i & ~C(Y-pair)i for i = (0, 1, ..., 71)
6196           {
6197 #if defined(TESTING)
6198             HDBGRegAR ("cnaaq");
6199             HDBGRegQR ("cnaaq");
6200 #endif
6201             word72 tmp72 = YPAIRTO72 (cpu.Ypair);
6202 
6203             word72 trAQ = convert_to_word72 (cpu.rA, cpu.rQ);
6204 #if defined(NEED_128)
6205             trAQ = and_128 (trAQ, complement_128 (tmp72));
6206             trAQ = and_128 (trAQ, MASK72);
6207 
6208             SC_I_ZERO (iszero_128 (trAQ));
6209             SC_I_NEG (isnonzero_128 (and_128 (trAQ, SIGN72)));
6210 #else
6211             trAQ = trAQ & ~tmp72;
6212             trAQ &= MASK72;
6213 
6214             SC_I_ZERO (trAQ == 0);
6215             SC_I_NEG (trAQ & SIGN72);
6216 #endif
6217           }
6218           break;
6219 
6220         case x0 (0216):  // cnaq
6221           // C(Z)i = C(Q)i & ~C(Y)i for i = (0, 1, ..., 35)
6222           {
6223 #if defined(TESTING)
6224             HDBGRegQR ("cnaq");
6225 #endif
6226             word36 trZ = cpu.rQ & ~cpu.CY;
6227             trZ &= DMASK;
6228             SC_I_ZERO (trZ == 0);
6229             SC_I_NEG (trZ & SIGN36);
6230           }
6231           break;
6232 
6233                          // cnaxn
6234         case x0 (0200):  // cnax0
6235         case x0 (0201):  // cnax1
6236         case x0 (0202):  // cnax2
6237         case x0 (0203):  // cnax3
6238         case x0 (0204):  // cnax4
6239         case x0 (0205):  // cnax5
6240         case x0 (0206):  // cnax6
6241         case x0 (0207):  // cnax7
6242           // C(Z)i = C(Xn)i & ~C(Y)i for i = (0, 1, ..., 17)
6243           {
6244             uint32 n = opcode10 & 07;  // get n
6245 #if defined(TESTING)
6246             HDBGRegXR (n, "cnaxn");
6247 #endif
6248             word18 tmp18 = cpu.rX[n] & ~GETHI (cpu.CY);
6249             tmp18 &= MASK18;
6250 
6251             SC_I_ZERO (tmp18 == 0);
6252             SC_I_NEG (tmp18 & SIGN18);
6253           }
6254           break;
6255 
6256         /// FLOATING-POINT ARITHMETIC INSTRUCTIONS
6257 
6258         /// Floating-Point Data Movement Load
6259 
6260         case x0 (0433):  // dfld
6261           // C(Y-pair)0,7 -> C(E)
6262           // C(Y-pair)8,71 -> C(AQ)0,63
6263           // 00...0 -> C(AQ)64,71
6264           // Zero: If C(AQ) = 0, then ON; otherwise OFF
6265           // Neg: If C(AQ)0 = 1, then ON; otherwise OFF
6266 
6267           CPTUR (cptUseE);
6268           cpu.rE  = (cpu.Ypair[0] >> 28) & MASK8;
6269 
6270           cpu.rA  = (cpu.Ypair[0] & FLOAT36MASK) << 8;
6271           cpu.rA |= (cpu.Ypair[1] >> 28) & MASK8;
6272 
6273           cpu.rQ  = (cpu.Ypair[1] & FLOAT36MASK) << 8;
6274 
6275 #if defined(TESTING)
6276           HDBGRegAW ("dfld");
6277           HDBGRegQW ("dfld");
6278 #endif
6279 
6280           SC_I_ZERO (cpu.rA == 0 && cpu.rQ == 0);
6281           SC_I_NEG (cpu.rA & SIGN36);
6282           break;
6283 
6284 // Optimized to the top of the loop
6285 //        case x0 (0431):  // fld
6286 
6287         /// Floating-Point Data Movement Store
6288 
6289         case x0 (0457):  // dfst
6290           // C(E) -> C(Y-pair)0,7
6291           // C(AQ)0,63 -> C(Y-pair)8,71
6292 
6293           CPTUR (cptUseE);
6294 #if defined(TESTING)
6295           HDBGRegAR ("dfst");
6296           HDBGRegQR ("dfst");
6297 #endif
6298           cpu.Ypair[0] = ((word36)cpu.rE << 28) |
6299                          ((cpu.rA & 0777777777400LLU) >> 8);
6300           cpu.Ypair[1] = ((cpu.rA & 0377) << 28) |
6301                          ((cpu.rQ & 0777777777400LLU) >> 8);
6302 
6303           break;
6304 
6305         case x0 (0472):  // dfstr
6306 
6307           dfstr (cpup, cpu.Ypair);
6308           break;
6309 
6310         case x0 (0455):  // fst
6311           // C(E) -> C(Y)0,7
6312           // C(A)0,27 -> C(Y)8,35
6313           CPTUR (cptUseE);
6314 #if defined(TESTING)
6315           HDBGRegAR ("fst");
6316 #endif
6317           cpu.rE &= MASK8;
6318           cpu.rA &= DMASK;
6319           cpu.CY = ((word36)cpu.rE << 28) | (((cpu.rA >> 8) & 01777777777LL));
6320           break;
6321 
6322         case x0 (0470):  // fstr
6323           // The fstr instruction performs a true round and normalization on
6324           // C(EAQ) as it is stored.
6325 
6326 //            frd ();
6327 //
6328 //            // C(E) -> C(Y)0,7
6329 //            // C(A)0,27 -> C(Y)8,35
6330 //            cpu.CY = ((word36)cpu.rE << 28) |
6331 //                     (((cpu.rA >> 8) & 01777777777LL));
6332 //
6333 //            // Zero: If C(Y) = floating point 0, then ON; otherwise OFF
6334 //            //SC_I_ZERO ((cpu.CY & 01777777777LL) == 0);
6335 //            bool isZero = cpu.rE == -128 && cpu.rA == 0;
6336 //            SC_I_ZERO (isZero);
6337 //
6338 //            // Neg: If C(Y)8 = 1, then ON; otherwise OFF
6339 //            //SC_I_NEG (cpu.CY & 01000000000LL);
6340 //            SC_I_NEG (cpu.rA & SIGN36);
6341 //
6342 //            // Exp Ovr: If exponent is greater than +127, then ON
6343 //            // Exp Undr: If exponent is less than -128, then ON
6344 //            // XXX: not certain how these can occur here ....
6345 
6346           fstr (cpup, &cpu.CY);
6347 
6348           break;
6349 
6350         /// Floating-Point Addition
6351 
6352         case x0 (0477):  // dfad
6353           // The dfad instruction may be thought of as a dufa instruction
6354           // followed by a fno instruction.
6355 
6356           CPTUR (cptUseE);
6357 #if defined(TESTING)
6358           HDBGRegAR ("dfad");
6359           HDBGRegQR ("dfad");
6360 #endif
6361           dufa (cpup, false, true);
6362 #if defined(TESTING)
6363           HDBGRegAW ("dfad");
6364           HDBGRegQW ("dfad");
6365 #endif
6366           break;
6367 
6368         case x0 (0437):  // dufa
6369           dufa (cpup, false, false);
6370           break;
6371 
6372         case x0 (0475):  // fad
6373           // The fad instruction may be thought of a an ufa instruction
6374           // followed by a fno instruction.
6375           // (Heh, heh. We'll see....)
6376 
6377           CPTUR (cptUseE);
6378 #if defined(TESTING)
6379           HDBGRegAR ("fad");
6380           HDBGRegQR ("fad");
6381 #endif
6382           ufa (cpup, false, true);
6383 #if defined(TESTING)
6384           HDBGRegAW ("fad");
6385           HDBGRegQW ("fad");
6386 #endif
6387 
6388           break;
6389 
6390         case x0 (0435):  // ufa
6391             // C(EAQ) + C(Y) -> C(EAQ)
6392 
6393           ufa (cpup, false, false);
6394           break;
6395 
6396         /// Floating-Point Subtraction
6397 
6398         case x0 (0577):  // dfsb
6399           // The dfsb instruction is identical to the dfad instruction with
6400           // the exception that the twos complement of the mantissa of the
6401           // operand from main memory is used.
6402 
6403           CPTUR (cptUseE);
6404 #if defined(TESTING)
6405           HDBGRegAR ("dfsb");
6406           HDBGRegQR ("dfsb");
6407 #endif
6408           dufa (cpup, true, true);
6409 #if defined(TESTING)
6410           HDBGRegAW ("dfsb");
6411           HDBGRegQW ("dfsb");
6412 #endif
6413           break;
6414 
6415         case x0 (0537):  // dufs
6416           dufa (cpup, true, false);
6417           break;
6418 
6419         case x0 (0575):  // fsb
6420           // The fsb instruction may be thought of as an ufs instruction
6421           // followed by a fno instruction.
6422 #if defined(TESTING)
6423           HDBGRegAR ("fsb");
6424           HDBGRegQR ("fsb");
6425 #endif
6426           CPTUR (cptUseE);
6427           ufa (cpup, true, true);
6428 #if defined(TESTING)
6429           HDBGRegAW ("fsb");
6430           HDBGRegQW ("fsb");
6431 #endif
6432           break;
6433 
6434         case x0 (0535):  // ufs
6435           // C(EAQ) - C(Y) -> C(EAQ)
6436           ufa (cpup, true, false);
6437           break;
6438 
6439         /// Floating-Point Multiplication
6440 
6441         case x0 (0463):  // dfmp
6442           // The dfmp instruction may be thought of as a dufm instruction
6443           // followed by a fno instruction.
6444 
6445           CPTUR (cptUseE);
6446 #if defined(TESTING)
6447           HDBGRegAR ("dfmp");
6448           HDBGRegQR ("dfmp");
6449 #endif
6450           dufm (cpup, true);
6451 #if defined(TESTING)
6452           HDBGRegAW ("dfmp");
6453           HDBGRegQW ("dfmp");
6454 #endif
6455           break;
6456 
6457         case x0 (0423):  // dufm
6458 
6459           dufm (cpup, false);
6460           break;
6461 
6462         case x0 (0461):  // fmp
6463           // The fmp instruction may be thought of as a ufm instruction
6464           // followed by a fno instruction.
6465 
6466           CPTUR (cptUseE);
6467           ufm (cpup, true);
6468 #if defined(TESTING)
6469           HDBGRegAW ("fmp");
6470           HDBGRegQW ("fmp");
6471 #endif
6472           break;
6473 
6474         case x0 (0421):  // ufm
6475           // C(EAQ)* C(Y) -> C(EAQ)
6476           ufm (cpup, false);
6477           break;
6478 
6479         /// Floating-Point Division
6480 
6481         case x0 (0527):  // dfdi
6482 
6483           dfdi (cpup);
6484           break;
6485 
6486         case x0 (0567):  // dfdv
6487 
6488           dfdv (cpup);
6489           break;
6490 
6491         case x0 (0525):  // fdi
6492           // C(Y) / C(EAQ) -> C(EA)
6493 
6494           fdi (cpup);
6495           break;
6496 
6497         case x0 (0565):  // fdv
6498           // C(EAQ) /C(Y) -> C(EA)
6499           // 00...0 -> C(Q)
6500           fdv (cpup);
6501           break;
6502 
6503         /// Floating-Point Negation
6504 
6505         case x0 (0513):  // fneg
6506           // -C(EAQ) normalized -> C(EAQ)
6507           fneg (cpup);
6508           break;
6509 
6510         /// Floating-Point Normalize
6511 
6512         case x0 (0573):  // fno
6513           // The fno instruction normalizes the number in C(EAQ) if C(AQ)
6514           // != 0 and the overflow indicator is OFF.
6515           //
6516           // A normalized floating number is defined as one whose mantissa
6517           // lies in the interval [0.5,1.0) such that 0.5<= |C(AQ)| <1.0
6518           // which, in turn, requires that C(AQ)0 != C(AQ)1.list
6519           //
6520           // !!!! For personal reasons the following 3 lines of comment must
6521           // never be removed from this program or any code derived
6522           // there from. HWR 25 Aug 2014
6523           ///Charles Is the coolest
6524           ///true story y'all
6525           //you should get me darksisers 2 for christmas
6526 
6527           CPTUR (cptUseE);
6528           fno (cpup, & cpu.rE, & cpu.rA, & cpu.rQ);
6529 #if defined(TESTING)
6530           HDBGRegAW ("fno");
6531           HDBGRegQW ("fno");
6532 #endif
6533           break;
6534 
6535         /// Floating-Point Round
6536 
6537         case x0 (0473):  // dfrd
6538           // C(EAQ) rounded to 64 bits -> C(EAQ)
6539           // 0 -> C(AQ)64,71 (See notes in dps8_math.c on dfrd())
6540 
6541           dfrd (cpup);
6542           break;
6543 
6544         case x0 (0471):  // frd
6545           // C(EAQ) rounded to 28 bits -> C(EAQ)
6546           // 0 -> C(AQ)28,71 (See notes in dps8_math.c on frd())
6547 
6548           frd (cpup);
6549           break;
6550 
6551         /// Floating-Point Compare
6552 
6553         case x0 (0427):  // dfcmg
6554           // C(E) :: C(Y-pair)0,7
6555           // | C(AQ)0,63 | :: | C(Y-pair)8,71 |
6556 
6557           dfcmg (cpup);
6558           break;
6559 
6560         case x0 (0517):  // dfcmp
6561           // C(E) :: C(Y-pair)0,7
6562           // C(AQ)0,63 :: C(Y-pair)8,71
6563 
6564           dfcmp (cpup);
6565           break;
6566 
6567         case x0 (0425):  // fcmg
6568           // C(E) :: C(Y)0,7
6569           // | C(AQ)0,27 | :: | C(Y)8,35 |
6570 
6571           fcmg (cpup);
6572           break;
6573 
6574         case x0 (0515):  // fcmp
6575           // C(E) :: C(Y)0,7
6576           // C(AQ)0,27 :: C(Y)8,35
6577 
6578           fcmp (cpup);
6579           break;
6580 
6581         /// Floating-Point Miscellaneous
6582 
6583         case x0 (0415):  // ade
6584           // C(E) + C(Y)0,7 -> C(E)
6585           {
6586             CPTUR (cptUseE);
6587             int y = SIGNEXT8_int ((cpu.CY >> 28) & 0377);
6588             int e = SIGNEXT8_int (cpu.rE);
6589             e = e + y;
6590 
6591             cpu.rE = e & 0377;
6592             CLR_I_ZERO;
6593             CLR_I_NEG;
6594 
6595             if (e > 127)
6596               {
6597                 SET_I_EOFL;
6598                 if (tstOVFfault (cpup))
6599                   doFault (FAULT_OFL, fst_zero, "ade exp overflow fault");
6600               }
6601 
6602             if (e < -128)
6603               {
6604                 SET_I_EUFL;
6605                 if (tstOVFfault (cpup))
6606                   doFault (FAULT_OFL, fst_zero, "ade exp underflow fault");
6607               }
6608           }
6609           break;
6610 
6611         case x0 (0430):  // fszn
6612 
6613           // Zero: If C(Y)8,35 = 0, then ON; otherwise OFF
6614           // Negative: If C(Y)8 = 1, then ON; otherwise OFF
6615 
6616           SC_I_ZERO ((cpu.CY & 001777777777LL) == 0);
6617           SC_I_NEG (cpu.CY & 001000000000LL);
6618 
6619           break;
6620 
6621         case x0 (0411):  // lde
6622           // C(Y)0,7 -> C(E)
6623 
6624           CPTUR (cptUseE);
6625           cpu.rE = (cpu.CY >> 28) & 0377;
6626           CLR_I_ZERO;
6627           CLR_I_NEG;
6628 
6629           break;
6630 
6631         case x0 (0456):  // ste
6632           // C(E) -> C(Y)0,7
6633           // 00...0 -> C(Y)8,17
6634 
6635           CPTUR (cptUseE);
6636           //putbits36_18 (& cpu.CY, 0, ((word18) (cpu.rE & 0377) << 10));
6637           cpu.CY = ((word36) (cpu.rE & 0377)) << 28;
6638           cpu.zone = 0777777000000;
6639           cpu.useZone = true;
6640           break;
6641 
6642         /// TRANSFER INSTRUCTIONS
6643 
6644         case x0 (0713):  // call6
6645 
6646           CPTUR (cptUsePRn + 7);
6647 
6648           do_caf (cpup);
6649           read_tra_op (cpup);
6650           sim_debug (DBG_TRACEEXT, & cpu_dev,
6651                      "call6 PRR %o PSR %o\r\n", cpu.PPR.PRR, cpu.PPR.PSR);
6652 
6653           return CONT_TRA;
6654 
6655         case x0 (0630):  // ret
6656           {
6657             // Parity mask: If C(Y)27 = 1, and the processor is in absolute or
6658             // mask privileged mode, then ON; otherwise OFF. This indicator is
6659             // not affected in the normal or BAR modes.
6660             // Not BAR mode: Can be set OFF but not ON by the ret instruction
6661             // Absolute mode: Can be set OFF but not ON by the ret instruction
6662             // All other indicators: If corresponding bit in C(Y) is 1, then ON;
6663             // otherwise, OFF
6664 
6665             // C(Y)0,17 -> C(PPR.IC)
6666             // C(Y)18,31 -> C(IR)
6667             do_caf (cpup);
6668             ReadOperandRead (cpup, cpu.TPR.CA, & cpu.CY);
6669 
6670             cpu.PPR.IC = GETHI (cpu.CY);
6671             word18 tempIR = GETLO (cpu.CY) & 0777770;
6672             // Assuming 'mask privileged mode' is 'temporary absolute mode'
6673             if (is_priv_mode (cpup)) // abs. or temp. abs. or priv.
6674               {
6675                 // if abs, copy existing parity mask to tempIR
6676                 // According to ISOLTS pm785, not the case.
6677                 //SCF (TST_I_PMASK, tempIR, I_PMASK);
6678                 // MIF comes from C(Y)30 like the other indicators (AL39
6679                 // "All other indicators"); it used to be kept from the
6680                 // current IR. PM842 16A/17A: the TRO handler returns with
6681                 // RET to an interrupted SCD, which must resume from the
6682                 // decimal unit (MIF on), not start over.
6683               }
6684             else
6685               {
6686                 CLRF (tempIR, I_MIF);
6687               }
6688             // can be set OFF but not on
6689             //  IR   ret   result
6690             //  off  off   off
6691             //  off  on    off
6692             //  on   on    on
6693             //  on   off   off
6694             // "If it was on, set it to on"
6695             //SCF (TST_I_NBAR, tempIR, I_NBAR);
6696             if (! (TST_I_NBAR && TSTF (tempIR, I_NBAR)))
6697               {
6698                 CLRF (tempIR, I_NBAR);
6699               }
6700             if (! (TST_I_ABS && TSTF (tempIR, I_ABS)))
6701               {
6702                 CLRF (tempIR, I_ABS);
6703               }
6704 
6705             //sim_debug (DBG_TRACEEXT, & cpu_dev,
6706             //           "RET NBAR was %d now %d\r\n",
6707             //           TST_NBAR ? 1 : 0,
6708             //           TSTF (tempIR, I_NBAR) ? 1 : 0);
6709             //sim_debug (DBG_TRACEEXT, & cpu_dev,
6710             //           "RET ABS  was %d now %d\r\n",
6711             //           TST_I_ABS ? 1 : 0,
6712             //           TSTF (tempIR, I_ABS) ? 1 : 0);
6713             CPTUR (cptUseIR);
6714             cpu.cu.IR = tempIR;
6715             return CONT_RET;
6716           }
6717 
6718 // Optimized to the top of the loop
6719 //        case x0 (0610):  // rtcd
6720 
6721         case x0 (0614):  // teo
6722           // If exponent overflow indicator ON then
6723           //  C(TPR.CA) -> C(PPR.IC)
6724           //  C(TPR.TSR) -> C(PPR.PSR)
6725           // otherwise, no change to C(PPR)
6726           if (TST_I_EOFL)
6727             {
6728               CLR_I_EOFL;
6729               do_caf (cpup);
6730               read_tra_op (cpup);
6731               return CONT_TRA;
6732             }
6733           break;
6734 
6735         case x0 (0615):  // teu
6736           // If exponent underflow indicator ON then
6737           //  C(TPR.CA) -> C(PPR.IC)
6738           //  C(TPR.TSR) -> C(PPR.PSR)
6739           if (TST_I_EUFL)
6740             {
6741               CLR_I_EUFL;
6742               do_caf (cpup);
6743               read_tra_op (cpup);
6744               return CONT_TRA;
6745             }
6746           break;
6747 
6748 // Optimized to the top of the loop
6749 //        case x0 (0604):  // tmi
6750 
6751 // Optimized to the top of the loop
6752 //        case x1 (0604):  // tmoz
6753 
6754         case x0 (0602):  // tnc
6755           // If carry indicator OFF then
6756           //   C(TPR.CA) -> C(PPR.IC)
6757           //   C(TPR.TSR) -> C(PPR.PSR)
6758           if (!TST_I_CARRY)
6759             {
6760               do_caf (cpup);
6761               read_tra_op (cpup);
6762               return CONT_TRA;
6763             }
6764           break;
6765 
6766 // Optimized to the top of the loop
6767 //         case x0 (0601):  // tnz
6768 
6769         case x0 (0617):  // tov
6770           // If overflow indicator ON then
6771           //   C(TPR.CA) -> C(PPR.IC)
6772           //   C(TPR.TSR) -> C(PPR.PSR)
6773           if (TST_I_OFLOW)
6774             {
6775               CLR_I_OFLOW;
6776               do_caf (cpup);
6777               read_tra_op (cpup);
6778               return CONT_TRA;
6779             }
6780           break;
6781 
6782         case x0 (0605):  // tpl
6783           // If negative indicator OFF, then
6784           //   C(TPR.CA) -> C(PPR.IC)
6785           //   C(TPR.TSR) -> C(PPR.PSR)
6786           if (! (TST_I_NEG))
6787             {
6788               do_caf (cpup);
6789               read_tra_op (cpup);
6790               return CONT_TRA;
6791             }
6792           break;
6793 
6794 // Optimized to the top of the loop
6795 //        case x1 (0605):  // tpnz
6796 
6797 // Optimized to the top of the loop
6798 //        case x0 (0710):  // tra
6799 
6800         case x0 (0603):  // trc
6801           //  If carry indicator ON then
6802           //    C(TPR.CA) -> C(PPR.IC)
6803           //    C(TPR.TSR) -> C(PPR.PSR)
6804           if (TST_I_CARRY)
6805             {
6806               do_caf (cpup);
6807               read_tra_op (cpup);
6808               return CONT_TRA;
6809             }
6810           break;
6811 
6812         case x1 (0601):  // trtf
6813             // If truncation indicator OFF then
6814             //  C(TPR.CA) -> C(PPR.IC)
6815             //  C(TPR.TSR) -> C(PPR.PSR)
6816             if (!TST_I_TRUNC)
6817             {
6818                 do_caf (cpup);
6819                 read_tra_op (cpup);
6820                 return CONT_TRA;
6821             }
6822             break;
6823 
6824         case x1 (0600):  // trtn
6825             // If truncation indicator ON then
6826             //  C(TPR.CA) -> C(PPR.IC)
6827             //  C(TPR.TSR) -> C(PPR.PSR)
6828             if (TST_I_TRUNC)
6829             {
6830                 CLR_I_TRUNC;
6831                 do_caf (cpup);
6832                 read_tra_op (cpup);
6833                 return CONT_TRA;
6834             }
6835             break;
6836 
6837 // Optimized to the top of the loop
6838 //                         // tspn
6839 //        case x0 (0270):  // tsp0
6840 //        case x0 (0271):  // tsp1
6841 //        case x0 (0272):  // tsp2
6842 //        case x0 (0273):  // tsp3
6843 //        case x0 (0670):  // tsp4
6844 //        case x0 (0671):  // tsp5
6845 //        case x0 (0672):  // tsp6
6846 //        case x0 (0673):  // tsp7
6847 
6848         case x0 (0715):  // tss
6849           CPTUR (cptUseBAR);
6850           do_caf (cpup);
6851           if (get_bar_mode (cpup))
6852             read_tra_op (cpup);
6853           else
6854             {
6855               cpu.TPR.CA = get_BAR_address (cpup, cpu.TPR.CA);
6856               read_tra_op (cpup);
6857               CLR_I_NBAR;
6858             }
6859           return CONT_TRA;
6860 
6861 // Optimized to the top of the loop
6862 //                         // tsxn
6863 //        case x0 (0700):  // tsx0
6864 //        case x0 (0701):  // tsx1
6865 //        case x0 (0702):  // tsx2
6866 //        case x0 (0703):  // tsx3
6867 //        case x0 (0704):  // tsx4
6868 //        case x0 (0705):  // tsx5
6869 //        case x0 (0706):  // tsx6
6870 //        case x0 (0707):  // tsx7
6871 
6872         case x0 (0607):  // ttf
6873           // If tally runout indicator OFF then
6874           //   C(TPR.CA) -> C(PPR.IC)
6875           //  C(TPR.TSR) -> C(PPR.PSR)
6876           // otherwise, no change to C(PPR)
6877           if (TST_I_TALLY == 0)
6878             {
6879               do_caf (cpup);
6880               read_tra_op (cpup);
6881               return CONT_TRA;
6882             }
6883           break;
6884 
6885         case x1 (0606):  // ttn
6886             // If tally runout indicator ON then
6887             //  C(TPR.CA) -> C(PPR.IC)
6888             //  C(TPR.TSR) -> C(PPR.PSR)
6889             // otherwise, no change to C(PPR)
6890             if (TST_I_TALLY)
6891             {
6892                 do_caf (cpup);
6893                 read_tra_op (cpup);
6894                 return CONT_TRA;
6895             }
6896             break;
6897 
6898 // Optimized to the top of the loop
6899 //        case x0 (0600):  // tze
6900 
6901         /// POINTER REGISTER INSTRUCTIONS
6902 
6903         /// Pointer Register Data Movement Load
6904 
6905                          // easpn
6906 
6907         case x0 (0311):  // easp0
6908           // C(TPR.CA) -> C(PRn.SNR)
6909           CPTUR (cptUsePRn + 0);
6910           cpu.PR[0].SNR = cpu.TPR.CA & MASK15;
6911 #if defined(TESTING)
6912           HDBGRegPRW (0, "easp0");
6913 #endif
6914           break;
6915 
6916         case x1 (0310):  // easp1
6917           // C(TPR.CA) -> C(PRn.SNR)
6918           CPTUR (cptUsePRn + 1);
6919           cpu.PR[1].SNR = cpu.TPR.CA & MASK15;
6920 #if defined(TESTING)
6921           HDBGRegPRW (1, "easp1");
6922 #endif
6923           break;
6924 
6925         case x0 (0313):  // easp2
6926           // C(TPR.CA) -> C(PRn.SNR)
6927           CPTUR (cptUsePRn + 2);
6928           cpu.PR[2].SNR = cpu.TPR.CA & MASK15;
6929 #if defined(TESTING)
6930           HDBGRegPRW (2, "easp2");
6931 #endif
6932           break;
6933 
6934         case x1 (0312):  // easp3
6935           // C(TPR.CA) -> C(PRn.SNR)
6936           CPTUR (cptUsePRn + 3);
6937           cpu.PR[3].SNR = cpu.TPR.CA & MASK15;
6938 #if defined(TESTING)
6939           HDBGRegPRW (3, "easp3");
6940 #endif
6941           break;
6942 
6943         case x0 (0331):  // easp4
6944           // C(TPR.CA) -> C(PRn.SNR)
6945           CPTUR (cptUsePRn + 4);
6946           cpu.PR[4].SNR = cpu.TPR.CA & MASK15;
6947 #if defined(TESTING)
6948           HDBGRegPRW (4, "easp4");
6949 #endif
6950           break;
6951 
6952         case x1 (0330):  // easp5
6953           // C(TPR.CA) -> C(PRn.SNR)
6954           CPTUR (cptUsePRn + 5);
6955           cpu.PR[5].SNR = cpu.TPR.CA & MASK15;
6956 #if defined(TESTING)
6957           HDBGRegPRW (5, "easp5");
6958 #endif
6959           break;
6960 
6961         case x0 (0333):  // easp6
6962           // C(TPR.CA) -> C(PRn.SNR)
6963           CPTUR (cptUsePRn + 6);
6964           cpu.PR[6].SNR = cpu.TPR.CA & MASK15;
6965 #if defined(TESTING)
6966           HDBGRegPRW (6, "easp6");
6967 #endif
6968           break;
6969 
6970         case x1 (0332):  // easp7
6971           // C(TPR.CA) -> C(PRn.SNR)
6972           CPTUR (cptUsePRn + 7);
6973           cpu.PR[7].SNR = cpu.TPR.CA & MASK15;
6974 #if defined(TESTING)
6975           HDBGRegPRW (7, "easp7");
6976 #endif
6977           break;
6978 
6979                          // eawpn
6980 
6981         case x0 (0310):  // eawp0
6982           // For n = 0, 1, ..., or 7 as determined by operation code
6983           //  C(TPR.CA) -> C(PRn.WORDNO)
6984           //  C(TPR.TBR) -> C(PRn.BITNO)
6985           CPTUR (cptUsePRn + 0);
6986           cpu.PR[0].WORDNO = cpu.TPR.CA;
6987           SET_PR_BITNO (0, cpu.TPR.TBR);
6988 #if defined(TESTING)
6989           HDBGRegPRW (0, "eawp0");
6990 #endif
6991           break;
6992 
6993         case x1 (0311):  // eawp1
6994           // For n = 0, 1, ..., or 7 as determined by operation code
6995           //  C(TPR.CA) -> C(PRn.WORDNO)
6996           //  C(TPR.TBR) -> C(PRn.BITNO)
6997           CPTUR (cptUsePRn + 1);
6998           cpu.PR[1].WORDNO = cpu.TPR.CA;
6999           SET_PR_BITNO (1, cpu.TPR.TBR);
7000 #if defined(TESTING)
7001           HDBGRegPRW (1, "eawp1");
7002 #endif
7003           break;
7004 
7005         case x0 (0312):  // eawp2
7006           // For n = 0, 1, ..., or 7 as determined by operation code
7007           //  C(TPR.CA) -> C(PRn.WORDNO)
7008           //  C(TPR.TBR) -> C(PRn.BITNO)
7009           CPTUR (cptUsePRn + 2);
7010           cpu.PR[2].WORDNO = cpu.TPR.CA;
7011           SET_PR_BITNO (2, cpu.TPR.TBR);
7012 #if defined(TESTING)
7013           HDBGRegPRW (2, "eawp2");
7014 #endif
7015           break;
7016 
7017         case x1 (0313):  // eawp3
7018           // For n = 0, 1, ..., or 7 as determined by operation code
7019           //  C(TPR.CA) -> C(PRn.WORDNO)
7020           //  C(TPR.TBR) -> C(PRn.BITNO)
7021           CPTUR (cptUsePRn + 3);
7022           cpu.PR[3].WORDNO = cpu.TPR.CA;
7023           SET_PR_BITNO (3, cpu.TPR.TBR);
7024 #if defined(TESTING)
7025           HDBGRegPRW (3, "eawp3");
7026 #endif
7027           break;
7028 
7029         case x0 (0330):  // eawp4
7030           // For n = 0, 1, ..., or 7 as determined by operation code
7031           //  C(TPR.CA) -> C(PRn.WORDNO)
7032           //  C(TPR.TBR) -> C(PRn.BITNO)
7033           CPTUR (cptUsePRn + 4);
7034           cpu.PR[4].WORDNO = cpu.TPR.CA;
7035           SET_PR_BITNO (4, cpu.TPR.TBR);
7036 #if defined(TESTING)
7037           HDBGRegPRW (4, "eawp4");
7038 #endif
7039           break;
7040 
7041         case x1 (0331):  // eawp5
7042           // For n = 0, 1, ..., or 7 as determined by operation code
7043           //  C(TPR.CA) -> C(PRn.WORDNO)
7044           //  C(TPR.TBR) -> C(PRn.BITNO)
7045           CPTUR (cptUsePRn + 5);
7046           cpu.PR[5].WORDNO = cpu.TPR.CA;
7047           SET_PR_BITNO (5, cpu.TPR.TBR);
7048 #if defined(TESTING)
7049           HDBGRegPRW (5, "eawp5");
7050 #endif
7051           break;
7052 
7053         case x0 (0332):  // eawp6
7054           // For n = 0, 1, ..., or 7 as determined by operation code
7055           //  C(TPR.CA) -> C(PRn.WORDNO)
7056           //  C(TPR.TBR) -> C(PRn.BITNO)
7057           CPTUR (cptUsePRn + 6);
7058           cpu.PR[6].WORDNO = cpu.TPR.CA;
7059           SET_PR_BITNO (6, cpu.TPR.TBR);
7060 #if defined(TESTING)
7061           HDBGRegPRW (6, "eawp6");
7062 #endif
7063           break;
7064 
7065         case x1 (0333):  // eawp7
7066           // For n = 0, 1, ..., or 7 as determined by operation code
7067           //  C(TPR.CA) -> C(PRn.WORDNO)
7068           //  C(TPR.TBR) -> C(PRn.BITNO)
7069           CPTUR (cptUsePRn + 7);
7070           cpu.PR[7].WORDNO = cpu.TPR.CA;
7071           SET_PR_BITNO (7, cpu.TPR.TBR);
7072 #if defined(TESTING)
7073           HDBGRegPRW (7, "eawp7");
7074 #endif
7075           break;
7076 
7077 // Optimized to the top of the loop
7078 //        case x1 (0350):  // epbp0
7079 //        case x0 (0351):  // epbp1
7080 //        case x1 (0352):  // epbp2
7081 //        case x0 (0353):  // epbp3
7082 //        case x1 (0370):  // epbp4
7083 //        case x0 (0371):  // epbp5
7084 //        case x1 (0372):  // epbp6
7085 //        case x0 (0373):  // epbp7
7086 
7087 // Optimized to the top of the switch
7088 //        case x0 (0350):  // epp0
7089 //        case x1 (0351):  // epp1
7090 //        case x0 (0352):  // epp2
7091 //        case x1 (0353):  // epp3
7092 //        case x0 (0374):  // epp4
7093 //        case x1 (0371):  // epp5
7094 //        case x0 (0376):  // epp6
7095 //        case x1 (0373):  // epp7
7096 
7097         case x0 (0173):  // lpri
7098           // For n = 0, 1, ..., 7
7099           //  Y-pair = Y-block16 + 2n
7100           //  Maximum of C(Y-pair)18,20; C(SDW.R1); C(TPR.TRR) -> C(PRn.RNR)
7101           //  C(Y-pair) 3,17 -> C(PRn.SNR)
7102           //  C(Y-pair)36,53 -> C(PRn.WORDNO)
7103           //  C(Y-pair)57,62 -> C(PRn.BITNO)
7104 
7105           for (uint32 n = 0 ; n < 8 ; n ++)
7106             {
7107               CPTUR (cptUsePRn + n);
7108               // Even word of ITS pointer pair
7109               cpu.Ypair[0] = cpu.Yblock16[n * 2 + 0];
7110               // Odd word of ITS pointer pair
7111               cpu.Ypair[1] = cpu.Yblock16[n * 2 + 1];
7112 
7113               // RNR from ITS pair
7114               word3 Crr = (GETLO (cpu.Ypair[0]) >> 15) & 07;
7115               if (get_addr_mode (cpup) == APPEND_mode)
7116                 cpu.PR[n].RNR = max3 (Crr, cpu.SDW->R1, cpu.TPR.TRR);
7117               else
7118                 cpu.PR[n].RNR = Crr;
7119               cpu.PR[n].SNR    = (cpu.Ypair[0] >> 18) & MASK15;
7120               cpu.PR[n].WORDNO = GETHI (cpu.Ypair[1]);
7121               word6 bitno      = (GETLO (cpu.Ypair[1]) >> 9) & 077;
7122 // According to ISOLTS, loading a 077 into bitno results in 037
7123 // pa851    test-04b    lpri test       bar-100176
7124 // test start 105321   patch 105461   subtest loop point 105442
7125 // s/b 77777737
7126 // was 77777733
7127               if (bitno == 077)
7128                 bitno = 037;
7129               SET_PR_BITNO (n, bitno);
7130 #if defined(TESTING)
7131               HDBGRegPRW (n, "lpri");
7132 #endif
7133             }
7134 
7135           break;
7136 
7137 // Optimized to the top of the loop
7138 //                         // lprpn
7139 //        case x0 (0760):  // lprp0
7140 //        case x0 (0761):  // lprp1
7141 //        case x0 (0762):  // lprp2
7142 //        case x0 (0763):  // lprp3
7143 //        case x0 (0764):  // lprp4
7144 //        case x0 (0765):  // lprp5
7145 //        case x0 (0766):  // lprp6
7146 //        case x0 (0767):  // lprp7
7147 
7148         /// Pointer Register Data Movement Store
7149 
7150 // Optimized to the top of the loop
7151 //        case x1 (0250):  // spbp0
7152 //        case x0 (0251):  // spbp1
7153 //        case x1 (0252):  // spbp2
7154 //        case x0 (0253):  // spbp3
7155 //        case x1 (0650):  // spbp4
7156 //        case x0 (0651):  // spbp5
7157 //        case x1 (0652):  // spbp6
7158 //        case x0 (0653):  // spbp7
7159 
7160         case x0 (0254):  // spri
7161           // For n = 0, 1, ..., 7
7162           //  Y-pair = Y-block16 + 2n
7163 
7164           //  000 -> C(Y-pair)0,2
7165           //  C(PRn.SNR) -> C(Y-pair)3,17
7166           //  C(PRn.RNR) -> C(Y-pair)18,20
7167           //  00...0 -> C(Y-pair)21,29
7168           //  (43)8 -> C(Y-pair)30,35
7169 
7170           //  C(PRn.WORDNO) -> C(Y-pair)36,53
7171           //  000 -> C(Y-pair)54,56
7172           //  C(PRn.BITNO) -> C(Y-pair)57,62
7173           //  00...0 -> C(Y-pair)63,71
7174 
7175           for (uint32 n = 0 ; n < 8 ; n++)
7176             {
7177               CPTUR (cptUsePRn + n);
7178               cpu.Yblock16[2 * n]      = 043;
7179               cpu.Yblock16[2 * n]     |= ((word36) cpu.PR[n].SNR) << 18;
7180               cpu.Yblock16[2 * n]     |= ((word36) cpu.PR[n].RNR) << 15;
7181 
7182               cpu.Yblock16[2 * n + 1]  = (word36) cpu.PR[n].WORDNO << 18;
7183               cpu.Yblock16[2 * n + 1] |= (word36) GET_PR_BITNO(n) << 9;
7184             }
7185 
7186           break;
7187 
7188 // Optimized to the top of the loop
7189 //        case x0 (0250):  // spri0
7190 //        case x1 (0251):  // spri1
7191 //        case x0 (0252):  // spri2
7192 //        case x1 (0253):  // spri3
7193 //        case x0 (0650):  // spri4
7194 //        case x1 (0255):  // spri5
7195 //        case x0 (0652):  // spri6
7196 //        case x1 (0257):  // spri7
7197 
7198                          // sprpn
7199         case x0 (0540):  // sprp0
7200         case x0 (0541):  // sprp1
7201         case x0 (0542):  // sprp2
7202         case x0 (0543):  // sprp3
7203         case x0 (0544):  // sprp4
7204         case x0 (0545):  // sprp5
7205         case x0 (0546):  // sprp6
7206         case x0 (0547):  // sprp7
7207           // For n = 0, 1, ..., or 7 as determined by operation code
7208           //  C(PRn.BITNO) -> C(Y)0,5
7209           //  C(PRn.SNR)3,14 -> C(Y)6,17
7210           //  C(PRn.WORDNO) -> C(Y)18,35
7211           {
7212             uint32 n = opcode10 & 07;  // get n
7213             CPTUR (cptUsePRn + n);
7214 
7215             // If C(PRn.SNR)0,2 are nonzero, and C(PRn.SNR) != 11...1, then
7216             // a store fault (illegal pointer) will occur and C(Y) will not
7217             // be changed.
7218 
7219             if ((cpu.PR[n].SNR & 070000) != 0 && cpu.PR[n].SNR != MASK15)
7220               doFault (FAULT_STR, fst_str_ptr, "sprpn");
7221 
7222             cpu.CY  =  ((word36) (GET_PR_BITNO(n) & 077)) << 30;
7223             // lower 12- of 15-bits
7224             cpu.CY |=  ((word36) (cpu.PR[n].SNR & 07777)) << 18;
7225             cpu.CY |=  cpu.PR[n].WORDNO & PAMASK;
7226             cpu.CY &= DMASK;    // keep to 36-bits
7227           }
7228           break;
7229 
7230         /// Pointer Register Address Arithmetic
7231 
7232                           // adwpn
7233         case x0 (0050):   // adwp0
7234         case x0 (0051):   // adwp1
7235         case x0 (0052):   // adwp2
7236         case x0 (0053):   // adwp3
7237           // For n = 0, 1, ..., or 7 as determined by operation code
7238           //   C(Y)0,17 + C(PRn.WORDNO) -> C(PRn.WORDNO)
7239           //   00...0 -> C(PRn.BITNO)
7240           {
7241               uint32 n = opcode10 & 03;  // get n
7242               CPTUR (cptUsePRn + n);
7243               cpu.PR[n].WORDNO += GETHI (cpu.CY);
7244               cpu.PR[n].WORDNO &= MASK18;
7245               SET_PR_BITNO (n, 0);
7246 #if defined(TESTING)
7247               HDBGRegPRW (n, "adwpn");
7248 #endif
7249           }
7250           break;
7251 
7252         case x0 (0150):   // adwp4
7253         case x0 (0151):   // adwp5
7254         case x0 (0152):   // adwp6
7255         case x0 (0153):   // adwp7
7256           // For n = 0, 1, ..., or 7 as determined by operation code
7257           //   C(Y)0,17 + C(PRn.WORDNO) -> C(PRn.WORDNO)
7258           //   00...0 -> C(PRn.BITNO)
7259           {
7260               uint32 n = (opcode10 & MASK3) + 4U;  // get n
7261               CPTUR (cptUsePRn + n);
7262               cpu.PR[n].WORDNO += GETHI (cpu.CY);
7263               cpu.PR[n].WORDNO &= MASK18;
7264               SET_PR_BITNO (n, 0);
7265 #if defined(TESTING)
7266               HDBGRegPRW (n, "adwpn");
7267 #endif
7268           }
7269           break;
7270 
7271         /// Pointer Register Miscellaneous
7272 
7273 // Optimized to the top of the loop
7274 //        case x0 (0213):  // epaq
7275 
7276         /// MISCELLANEOUS INSTRUCTIONS
7277 
7278         case x0 (0633):  // rccl
7279           // 00...0 -> C(AQ)0,19
7280           // C(calendar clock) -> C(AQ)20,71
7281           {
7282             // For the rccl instruction, the first 2 or 3 bits of the addr
7283             // field of the instruction are used to specify which SCU.
7284             // init_processor.alm systematically steps through the SCUs,
7285             // using addresses 000000 100000 200000 300000.
7286             uint cpu_port_num;
7287             if (cpu.tweaks.l68_mode)
7288               cpu_port_num = (cpu.TPR.CA >> 15) & 07;
7289             else
7290               cpu_port_num = (cpu.TPR.CA >> 15) & 03;
7291             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
7292               {
7293                 sim_warn ("rccl on CPU %u port %d has no SCU; faulting\r\n",
7294                           current_running_cpu_idx, cpu_port_num);
7295                 doFault (FAULT_ONC, fst_onc_nem, "(rccl)");
7296               }
7297             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
7298 
7299             t_stat rc = scu_rscr (cpup, (uint) scuUnitIdx, current_running_cpu_idx,
7300                                   040, & cpu.rA, & cpu.rQ);
7301 #if defined(TESTING)
7302             HDBGRegAW ("rccl");
7303             HDBGRegQW ("rccl");
7304 #endif
7305             if (rc > 0)
7306               return rc;
7307 #if !defined(SPEED)
7308             if_sim_debug (DBG_TRACEEXT, & cpu_dev)
7309               {
7310                 // Clock at initialization
7311                 // date -d "Tue Jul 22 16:39:38 PDT 1999" +%s
7312                 // 932686778
7313                 uint64 UnixSecs     = 932686778;
7314                 uint64 UnixuSecs    = UnixSecs * 1000000LL;
7315                 // now determine uSecs since Jan 1, 1901 ...
7316                 uint64 MulticsuSecs = 2177452800000000LL + UnixuSecs;
7317 
7318                 // Back into 72 bits
7319                word72 big           = convert_to_word72 (cpu.rA, cpu.rQ);
7320 # if defined(NEED_128)
7321                 // Convert to time since boot
7322                 big             = subtract_128 (big, construct_128 (0, MulticsuSecs));
7323                 uint32_t remainder;
7324                 uint128 bigsecs = divide_128_32 (big, 1000000u, & remainder);
7325                 uint64_t uSecs  = remainder;
7326                 uint64_t secs   = bigsecs.l;
7327                 sim_debug (DBG_TRACEEXT, & cpu_dev,
7328                            "Clock time since boot %4llu.%06llu seconds\r\n",
7329                            secs, uSecs);
7330 # else
7331                 // Convert to time since boot
7332                 big                 -= MulticsuSecs;
7333                 unsigned long uSecs  = big % 1000000u;
7334                 unsigned long secs   = (unsigned long) (big / 1000000u);
7335                 sim_debug (DBG_TRACEEXT, & cpu_dev,
7336                            "Clock time since boot %4lu.%06lu seconds\r\n",
7337                            secs, uSecs);
7338 # endif
7339               }
7340 #endif
7341           }
7342           break;
7343 
7344         case x0 (0002):   // drl
7345           // Causes a fault which fetches and executes, in absolute mode, the
7346           // instruction pair at main memory location C+(14)8. The value of C
7347           // is obtained from the FAULT VECTOR switches on the processor
7348           // configuration panel.
7349 
7350           if (cpu.tweaks.drl_fatal)
7351             {
7352               return STOP_STOP;
7353             }
7354           doFault (FAULT_DRL, fst_zero, "drl");
7355 
7356         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7357         case x0 (0716):  // xec
7358           cpu.cu.xde = 1;
7359           cpu.cu.xdo = 0;
7360 // XXX NB. This used to be done in executeInstruction post-execution
7361 // processing; moving it here means that post-execution code cannot inspect IWB
7362 // to determine what the instruction or it flags were.
7363           cpu.cu.IWB = cpu.CY;
7364           return CONT_XEC;
7365 
7366         case x0 (0717):  // xed
7367           // The xed instruction itself does not affect any indicator.
7368           // However, the execution of the instruction pair from C(Y-pair)
7369           // may affect indicators.
7370           //
7371           // The even instruction from C(Y-pair) must not alter
7372           // C(Y-pair)36,71, and must not be another xed instruction.
7373           //
7374           // If the execution of the instruction pair from C(Y-pair) alters
7375           // C(PPR.IC), then a transfer of control occurs; otherwise, the
7376           // next instruction to be executed is fetched from C(PPR.IC)+1. If
7377           // the even instruction from C(Y-pair) alters C(PPR.IC), then the
7378           // transfer of control is effective immediately and the odd
7379           // instruction is not executed.
7380           //
7381           // To execute an instruction pair having an rpd instruction as the
7382           // odd instruction, the xed instruction must be located at an odd
7383           // address. The instruction pair repeated is that instruction pair
7384           // at C PPR.IC)+1, that is, the instruction pair immediately
7385           // following the xed instruction. C(PPR.IC) is adjusted during the
7386           // execution of the repeated instruction pair so the next
7387           // instruction fetched for execution is from the first word
7388           // following the repeated instruction pair.
7389           //
7390           // The instruction pair at C(Y-pair) may cause any of the processor
7391           // defined fault conditions, but only the directed faults (0,1,2,3)
7392           // and the access violation fault may be restarted successfully by
7393           // the hardware. Note that the software induced fault tag (1,2,3)
7394           // faults cannot be properly restarted.
7395           //
7396           //  An attempt to execute an EIS multiword instruction causes an
7397           //  illegal procedure fault.
7398           //
7399           //  Attempted repetition with the rpt, rpd, or rpl instructions
7400           //  causes an illegal procedure fault.
7401 
7402           cpu.cu.xde = 1;
7403           cpu.cu.xdo = 1;
7404 // XXX NB. This used to be done in executeInstruction post-execution
7405 // processing; moving it here means that post-execution code cannot inspect IWB
7406 // to determine what the instruction or it flags were.
7407           cpu.cu.IWB   = cpu.Ypair[0];
7408           cpu.cu.IRODD = cpu.Ypair[1];
7409           return CONT_XEC;
7410 
7411         case x0 (0001):   // mme
7412 #if defined(TESTING)
7413           if (sim_deb_mme_cntdwn > 0)
7414             sim_deb_mme_cntdwn --;
7415 #endif
7416           // Causes a fault that fetches and executes, in absolute mode, the
7417           // instruction pair at main memory location C+4. The value of C is
7418           // obtained from the FAULT VECTOR switches on the processor
7419           // configuration panel.
7420           doFault (FAULT_MME, fst_zero, "Master Mode Entry (mme)");
7421 
7422         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7423         case x0 (0004):   // mme2
7424           // Causes a fault that fetches and executes, in absolute mode, the
7425           // instruction pair at main memory location C+(52)8. The value of C
7426           // is obtained from the FAULT VECTOR switches on the processor
7427           // configuration panel.
7428           doFault (FAULT_MME2, fst_zero, "Master Mode Entry 2 (mme2)");
7429 
7430         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7431         case x0 (0005):   // mme3
7432           // Causes a fault that fetches and executes, in absolute mode, the
7433           // instruction pair at main memory location C+(54)8. The value of C
7434           // is obtained from the FAULT VECTOR switches on the processor
7435           // configuration panel.
7436           doFault (FAULT_MME3, fst_zero, "Master Mode Entry 3 (mme3)");
7437 
7438         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7439         case x0 (0007):   // mme4
7440           // Causes a fault that fetches and executes, in absolute mode, the
7441           // instruction pair at main memory location C+(56)8. The value of C
7442           // is obtained from the FAULT VECTOR switches on the processor
7443           // configuration panel.
7444           doFault (FAULT_MME4, fst_zero, "Master Mode Entry 4 (mme4)");
7445 
7446         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7447         case x0 (0011):   // nop
7448           break;
7449 
7450         case x0 (0012):   // puls1
7451           break;
7452 
7453         case x0 (0013):   // puls2
7454           break;
7455 
7456         /// Repeat
7457 
7458         case x0 (0560):  // rpd
7459           {
7460             if ((cpu.PPR.IC & 1) == 0)
7461               doFault (FAULT_IPR, fst_ill_proc, "rpd odd");
7462             cpu.cu.delta = i->tag;
7463             // a:AL39/rpd1
7464             word1 c = (i->address >> 7) & 1;
7465             if (c)
7466               {
7467                 cpu.rX[0] = i->address;    // Entire 18 bits
7468 #if defined(TESTING)
7469                 HDBGRegXW (0, "rpd");
7470 #endif
7471               }
7472             cpu.cu.rd = 1;
7473             cpu.cu.repeat_first = 1;
7474             // the tally runout indicator is off until the repeat ends
7475             // (PA885 06B: fault in the first repetition)
7476             CLR_I_TALLY;
7477             cpu.rptUndo[0] = cpu.rptUndo[1] = 0;
7478           }
7479           break;
7480 
7481         case x0 (0500):  // rpl
7482           {
7483             uint c       = (i->address >> 7) & 1;
7484             cpu.cu.delta = i->tag;
7485             if (c)
7486               {
7487                 cpu.rX[0] = i->address;    // Entire 18 bits
7488 #if defined(TESTING)
7489                 HDBGRegXW (0, "rpl");
7490 #endif
7491               }
7492             cpu.cu.rl           = 1;
7493             cpu.cu.repeat_first = 1;
7494             // the tally runout indicator is off until the repeat ends
7495             // (PA885 06B: fault in the first repetition)
7496             CLR_I_TALLY;
7497             cpu.rptUndo[0] = cpu.rptUndo[1] = 0;
7498           }
7499           break;
7500 
7501         case x0 (0520):  // rpt
7502           {
7503             uint c       = (i->address >> 7) & 1;
7504             cpu.cu.delta = i->tag;
7505             if (c)
7506               {
7507                 cpu.rX[0] = i->address;    // Entire 18 bits
7508 #if defined(TESTING)
7509                 HDBGRegXW (0, "rpt");
7510 #endif
7511               }
7512             cpu.cu.rpt          = 1;
7513             cpu.cu.repeat_first = 1;
7514             // the tally runout indicator is off until the repeat ends
7515             // (PA885 06B: fault in the first repetition)
7516             CLR_I_TALLY;
7517             cpu.rptUndo[0] = cpu.rptUndo[1] = 0;
7518           }
7519           break;
7520 
7521         /// Ring Alarm Register
7522 
7523         case x1 (0754):  // sra
7524             // 00...0 -> C(Y)0,32
7525             // C(RALR) -> C(Y)33,35
7526 
7527             CPTUR (cptUseRALR);
7528             cpu.CY = (word36)cpu.rRALR;
7529 
7530             break;
7531 
7532         /// Store Base Address Register
7533 
7534         case x0 (0550):  // sbar
7535           // C(BAR) -> C(Y) 0,17
7536           CPTUR (cptUseBAR);
7537           //SETHI (cpu.CY, (cpu.BAR.BASE << 9) | cpu.BAR.BOUND);
7538           cpu.CY      = ((((word36) cpu.BAR.BASE) << 9) | cpu.BAR.BOUND) << 18;
7539           cpu.zone    = 0777777000000;
7540           cpu.useZone = true;
7541           break;
7542 
7543         /// Translation
7544 
7545         case x0 (0505):  // bcd
7546           // Shift C(A) left three positions
7547           // | C(A) | / C(Y) -> 4-bit quotient
7548           // C(A) - C(Y) * quotient -> remainder
7549           // Shift C(Q) left six positions
7550           // 4-bit quotient -> C(Q)32,35
7551           // remainder -> C(A)
7552 
7553           {
7554             word36 tmp1   = cpu.rA & SIGN36; // A0
7555             word36 tmp36  = (cpu.rA << 3) & DMASK;
7556             word36 tmp36q = tmp36 / cpu.CY;  // this may be more than 4 bits, keep it for remainder calculation
7557             word36 tmp36r = 0;
7558             if (!tmp1) {
7559                 tmp36r = tmp36 - tmp36q * cpu.CY;
7560             } else {
7561                 // ISOLTS-745 05i: bcd when rA is negative.
7562                 // Note that this only gets called in the first round of the bcd
7563                 // conversion; the rA sign bit will get shifted out.
7564                 // Looking at the expected results, it appears that a 'borrow'
7565                 // is represented in a residue style notation -- an unborrow
7566                 // result is 0-9 (000 - 011), a borrowed digit as 6-15 (006-017)
7567                 tmp36q += 6;
7568                 tmp36r  = tmp36 + tmp36q * cpu.CY;
7569             }
7570 
7571             cpu.rQ <<= 6;       // Shift C(Q) left six positions
7572             cpu.rQ &= DMASK;
7573 
7574             //cpu.rQ &= (word36) ~017;     // 4-bit quotient -> C(Q)32,35  lo6 bits already zeroed out
7575             cpu.rQ |= (tmp36q & 017);
7576 #if defined(TESTING)
7577             HDBGRegQW ("bcd");
7578 #endif
7579 
7580             cpu.rA = tmp36r & DMASK;    // remainder -> C(A)
7581 #if defined(TESTING)
7582             HDBGRegAW ("bcd");
7583 #endif
7584 
7585             SC_I_ZERO (cpu.rA == 0);  // If C(A) = 0, then ON;
7586                                             // otherwise OFF
7587             SC_I_NEG (tmp1);   // If C(A)0 = 1 before execution,
7588                                             // then ON; otherwise OFF
7589           }
7590           break;
7591 
7592         case x0 (0774):  // gtb
7593           // C(A)0 -> C(A)0
7594           // C(A)i XOR C(A)i-1 -> C(A)i for i = 1, 2, ..., 35
7595           {
7596             word36 tmp = cpu.rA & MASK36;
7597             word36 mask = SIGN36;
7598 
7599             for (int n=1;n<=35;n++) {
7600                 tmp ^= (tmp & mask) >> 1;
7601                 mask >>= 1;
7602             }
7603 
7604             cpu.rA = tmp;
7605 #if defined(TESTING)
7606             HDBGRegAW ("gtb");
7607 #endif
7608 
7609             SC_I_ZERO (cpu.rA == 0);  // If C(A) = 0, then ON;
7610                                       // otherwise OFF
7611             SC_I_NEG (cpu.rA & SIGN36);   // If C(A)0 = 1, then ON;
7612                                           // otherwise OFF
7613           }
7614           break;
7615 
7616         /// REGISTER LOAD
7617 
7618         case x0 (0230):  // lbar
7619           // C(Y)0,17 -> C(BAR)
7620           CPTUR (cptUseBAR);
7621           // BAR.BASE is upper 9-bits (0-8)
7622           cpu.BAR.BASE  = (GETHI (cpu.CY) >> 9) & 0777;
7623           // BAR.BOUND is next lower 9-bits (9-17)
7624           cpu.BAR.BOUND = GETHI (cpu.CY) & 0777;
7625           break;
7626 
7627         /// PRIVILEGED INSTRUCTIONS
7628 
7629         /// Privileged - Register Load
7630 
7631         case x0 (0674):  // lcpr
7632           // DPS8M interpretation
7633           switch (i->tag)
7634             {
7635               // Extract bits from 'from' under 'mask' shifted to where (where
7636               // is dps8 '0 is the msbit.
7637 
7638               case 02: // cache mode register
7639                 {
7640                   //cpu.CMR = cpu.CY;
7641                   // cpu.CMR.cache_dir_address = <ignored for lcpr>
7642                   // cpu.CMR.par_bit = <ignored for lcpr>
7643                   // cpu.CMR.lev_ful = <ignored for lcpr>
7644 
7645                   CPTUR (cptUseCMR);
7646                   // a:AL39/cmr2  If either cache enable bit c or d changes
7647                   // from disable state to enable state, the entire cache is
7648                   // cleared.
7649                   uint csh1_on    = getbits36_1 (cpu.CY, 54 - 36);
7650                   uint csh2_on    = getbits36_1 (cpu.CY, 55 - 36);
7651                   bool clear = (cpu.CMR.csh1_on == 0 && csh1_on != 0) ||
7652                                (cpu.CMR.csh2_on == 0 && csh2_on != 0);
7653                   cpu.CMR.csh1_on = (word1) csh1_on;
7654                   cpu.CMR.csh2_on = (word1) csh2_on;
7655                   if (clear) { // a:AL39/cmr2
7656                     cacheReset (cpup);
7657                     cacheClearStarted (cpup);
7658                   }
7659                   L68_ (cpu.CMR.opnd_on = getbits36_1 (cpu.CY, 56 - 36);)
7660                   cpu.CMR.inst_on = getbits36_1 (cpu.CY, 57 - 36);
7661                   cpu.CMR.csh_reg = getbits36_1 (cpu.CY, 59 - 36);
7662                   // cpu.CMR.str_asd = <ignored for lcpr>
7663                   // cpu.CMR.col_ful = <ignored for lcpr>
7664                   // cpu.CMR.rro_AB = getbits36_1 (cpu.CY, 18);
7665                   DPS8M_ (cpu.CMR.bypass_cache = getbits36_1 (cpu.CY, 68 - 36);)
7666                   cpu.CMR.luf = getbits36_2 (cpu.CY, 70 - 36);
7667                 }
7668                 break;
7669 
7670               case 04: // mode register
7671                 {
7672                   CPTUR (cptUseMR);
7673                   cpu.MR.r = cpu.CY;
7674 // XXX TEST/NORMAL switch is set to NORMAL
7675                   putbits36_1 (& cpu.MR.r, 32, 0);
7676 // SBZ
7677                   putbits36_2 (& cpu.MR.r, 33, 0);
7678                   L68_ (
7679                     cpu.MR.FFV = getbits36_15 (cpu.CY, 0);
7680                     cpu.MR.OC_TRAP = getbits36_1 (cpu.CY, 16);
7681                     cpu.MR.ADR_TRAP = getbits36_1 (cpu.CY, 17);
7682                     cpu.MR.OPCODE = getbits36_9 (cpu.CY, 18);
7683                     cpu.MR.OPCODEX = getbits36_1 (cpu.CY, 27);
7684                   )
7685                   cpu.MR.sdpap = getbits36_1 (cpu.CY, 20);
7686                   cpu.MR.separ = getbits36_1 (cpu.CY, 21);
7687                   // DPS/L68: bits 18-27 are the trap OPCODE; bits 18-25
7688                   // are controls (store incorrect parity: 20, 21) only with
7689                   // OC TRAP (16) and O.C$ (29) off (PM700 02V: opcode 755
7690                   // would set both). TEST mode (32, the TEST/NORMAL switch)
7691                   // gates only the margin controls (22-25), which dps8m
7692                   // ignores: SM782 tests store parity with the switch in
7693                   // NORMAL, and no page asks for TEST
7694                   L68_ (
7695                     if (getbits36_1 (cpu.CY, 16) || getbits36_1 (cpu.CY, 29))
7696                       cpu.MR.sdpap = cpu.MR.separ = 0;
7697                   )
7698                   cpu.MR.hrhlt = getbits36_1 (cpu.CY, 28);
7699                   DPS8M_ (cpu.MR.hrxfr = getbits36_1 (cpu.CY, 29);)
7700                   cpu.MR.ihr = getbits36_1 (cpu.CY, 30);
7701                   cpu.MR.ihrrs = getbits36_1 (cpu.CY, 31);
7702                   cpu.MR.emr = getbits36_1 (cpu.CY, 35);
7703                   if (! cpu.tweaks.l68_mode) // DPS8M
7704                     cpu.MR.hexfp = getbits36_1 (cpu.CY, 33);
7705                   else // L68
7706                     cpu.MR.hexfp = 0;
7707 
7708                   // Stop HR Strobe on HR Counter Overflow. (Setting bit 28
7709                   // shall cause the HR counter to be reset to zero.)
7710                   // CAC: It is unclear if bit 28 is edge or level
7711                   // triggered; assuming level for simplicity.
7712                   if (cpu.MR.hrhlt)
7713                     {
7714                       for (uint hset = 0; hset < N_HIST_SETS; hset ++)
7715                          cpu.history_cyclic[hset] = 0;
7716                     }
7717 
7718 
7719 
7720 
7721 
7722 
7723 
7724 
7725 
7726 
7727 
7728 
7729                 }
7730                 break;
7731 
7732               case 03: // 0's -> history
7733                 {
7734                   for (uint i = 0; i < N_HIST_SETS; i ++)
7735                     add_history_force (cpup, i, 0, 0);
7736 // XXX ISOLTS pm700 test-01n
7737 // The test clears the history registers but with ihr & emr set, causing
7738 // the registers to fill with alternating 0's and lcpr instructions.
7739 // Set flag to prevent the LCPR from being recorded.
7740                     //cpu.MR.ihr = 0;
7741                     cpu.skip_cu_hist = true;
7742 
7743                 }
7744                 break;
7745 
7746               case 07: // 1's -> history
7747                 {
7748                   for (uint i = 0; i < N_HIST_SETS; i ++)
7749                     add_history_force (cpup, i, MASK36, MASK36);
7750 // XXX ISOLTS pm700 test-01n
7751 // The test clears the history registers but with ihr & emr set, causing
7752 // the registers to fill with alternating 0's and lcpr instructions.
7753 // Set flag to prevent the LCPR from being recorded.
7754                     //cpu.MR.ihr = 0;
7755                     cpu.skip_cu_hist = true;
7756                 }
7757                 break;
7758 
7759               default:
7760                 doFault (FAULT_IPR,
7761                          fst_ill_mod,
7762                          "lcpr tag invalid");
7763 
7764             }
7765             break;
7766 
7767         case x0 (0232):  // ldbr
7768           do_ldbr (cpup, cpu.Ypair);
7769           ucInvalidate (cpup);
7770           break;
7771 
7772         case x0 (0637):  // ldt
7773           CPTUR (cptUseTR);
7774           cpu.rTR = (cpu.CY >> 9) & MASK27;
7775           cpu.rTRticks = 0;
7776           if (cpu.tweaks.isolts_mode)
7777             {
7778               cpu.shadowTR = cpu.TR0 = cpu.rTR;
7779               cpu.rTRlsb = 0;
7780             }
7781           // L68, T&D: a TR loaded with 0 runs out at once; the runout is
7782           // taken at the first slave-mode sampling point (PM776 04C,
7783           // "immediate timer runout fault in slave mode", L68 only: the
7784           // page skips it on a DPS8). The T&D TR counts one per four
7785           // cycles, so otherwise it would wrap only a few instructions
7786           // later, after the page has left slave mode. Continue from the
7787           // wrapped value so the runout isn't signalled twice.
7788           if (cpu.tweaks.l68_mode && cpu.tweaks.tandd_mode && cpu.rTR == 0)
7789             {
7790               cpu.rTR = MASK27;
7791               if (cpu.tweaks.tro_enable)
7792                 setG7fault (current_running_cpu_idx, FAULT_TRO);
7793             }
7794           sim_debug (DBG_TRACEEXT, & cpu_dev, "ldt TR %d (%o)\r\n",
7795                      cpu.rTR, cpu.rTR);
7796 #if defined(LOOPTRC)
7797 elapsedtime ();
7798  sim_printf (" ldt %d  PSR:IC %05o:%06o\r\n", cpu.rTR, cpu.PPR.PSR, cpu.PPR.IC);
7799 #endif
7800           // Undocumented feature. return to bce has been observed to
7801           // experience TRO while masked, setting the TR to -1, and
7802           // experiencing an unexpected TRo interrupt when unmasking.
7803           // Reset any pending TRO fault when the TR is loaded.
7804           clearTROFault (cpup);
7805           break;
7806 
7807         case x1 (0257):  // lptp
7808 
7809           if (cpu.tweaks.l68_mode) {
7810             // For i = 0, 1, ..., 15
7811             //   m = C(PTWAM(i).USE)
7812             //   C(Y-block16+m)0,14 -> C(PTWAM(m).POINTER)
7813             //   C(Y-block16+m)15,26 -> C(PTWAM(m).PAGE)
7814             //   C(Y-block16+m)27 -> C(PTWAM(m).F)
7815 
7816             for (uint i = 0; i < 16; i ++)
7817               {
7818                 word4 m              = cpu.PTWAM[i].USE;
7819                 cpu.PTWAM[m].POINTER = getbits36_15 (cpu.Yblock16[i],  0);
7820                 cpu.PTWAM[m].PAGENO  = getbits36_12 (cpu.Yblock16[i], 15);
7821                 cpu.PTWAM[m].FE      = getbits36_1  (cpu.Yblock16[i], 27);
7822               }
7823           }
7824           break;
7825 
7826         case x1 (0173):  // lptr
7827           if (cpu.tweaks.l68_mode) {
7828             // For i = 0, 1, ..., 15
7829             //   m = C(PTWAM(i).USE)
7830             //   C(Y-block16+m)0,17 -> C(PTWAM(m).ADDR)
7831             //   C(Y-block16+m)29 -> C(PTWAM(m).M)
7832             for (uint i = 0; i < 16; i ++)
7833               {
7834                 word4 m           = cpu.PTWAM[i].USE;
7835                 cpu.PTWAM[m].ADDR = getbits36_18 (cpu.Yblock16[i],  0);
7836                 cpu.PTWAM[m].M    = getbits36_1  (cpu.Yblock16[i], 29);
7837               }
7838           }
7839           break;
7840 
7841         case x1 (0774):  // lra
7842             CPTUR (cptUseRALR);
7843             cpu.rRALR = cpu.CY & MASK3;
7844             sim_debug (DBG_TRACEEXT, & cpu_dev, "RALR set to %o\r\n", cpu.rRALR);
7845 #if defined(LOOPTRC)
7846 {
7847 void elapsedtime (void);
7848 elapsedtime ();
7849  sim_printf (" RALR set to %o  PSR:IC %05o:%06o\r\n", cpu.rRALR, cpu.PPR.PSR, cpu.PPR.IC);
7850 }
7851 #endif
7852             break;
7853 
7854         case x0 (0257):  // lsdp
7855           if (cpu.tweaks.l68_mode) {
7856             // For i = 0, 1, ..., 15
7857             //   m = C(SDWAM(i).USE)
7858             //   C(Y-block16+m)0,14 -> C(SDWAM(m).POINTER)
7859             //   C(Y-block16+m)27 -> C(SDWAM(m).F) Note: typo in AL39, P(17) should be F(27)
7860             for (uint i = 0; i < 16; i ++)
7861               {
7862                 word4 m              = cpu.SDWAM[i].USE;
7863                 cpu.SDWAM[m].POINTER = getbits36_15 (cpu.Yblock16[i],  0);
7864                 cpu.SDWAM[m].FE      = getbits36_1  (cpu.Yblock16[i], 27);
7865               }
7866           }
7867           break;
7868 
7869         case x1 (0232):  // lsdr
7870           if (cpu.tweaks.l68_mode) {
7871             // For i = 0, 1, ..., 15
7872             //   m = C(SDWAM(i).USE)
7873             //   C(Y-block32+2m)0,23  -> C(SDWAM(m).ADDR)
7874             //   C(Y-block32+2m)24,32 -> C(SDWAM(m).R1, R2, R3)
7875             //   C(Y-block32+2m)37,50 -> C(SDWAM(m).BOUND)
7876             //   C(Y-block32+2m)51,57 -> C(SDWAM(m).R, E, W, P, U, G, C) Note: typo in AL39, 52 should be 51
7877             //   C(Y-block32+2m)58,71 -> C(SDWAM(m).CL)
7878             for (uint i = 0; i < 16; i ++)
7879               {
7880                 word4 m            = cpu.SDWAM[i].USE;
7881                 uint j             = (uint)m * 2;
7882                 cpu.SDWAM[m].ADDR  = getbits36_24 (cpu.Yblock32[j],  0);
7883                 cpu.SDWAM[m].R1    = getbits36_3  (cpu.Yblock32[j], 24);
7884                 cpu.SDWAM[m].R2    = getbits36_3  (cpu.Yblock32[j], 27);
7885                 cpu.SDWAM[m].R3    = getbits36_3  (cpu.Yblock32[j], 30);
7886 
7887                 cpu.SDWAM[m].BOUND = getbits36_14 (cpu.Yblock32[j + 1], 37 - 36);
7888                 cpu.SDWAM[m].R     = getbits36_1  (cpu.Yblock32[j + 1], 51 - 36);
7889                 cpu.SDWAM[m].E     = getbits36_1  (cpu.Yblock32[j + 1], 52 - 36);
7890                 cpu.SDWAM[m].W     = getbits36_1  (cpu.Yblock32[j + 1], 53 - 36);
7891                 cpu.SDWAM[m].P     = getbits36_1  (cpu.Yblock32[j + 1], 54 - 36);
7892                 cpu.SDWAM[m].U     = getbits36_1  (cpu.Yblock32[j + 1], 55 - 36);
7893                 cpu.SDWAM[m].G     = getbits36_1  (cpu.Yblock32[j + 1], 56 - 36);
7894                 cpu.SDWAM[m].C     = getbits36_1  (cpu.Yblock32[j + 1], 57 - 36);
7895                 cpu.SDWAM[m].EB    = getbits36_14 (cpu.Yblock32[j + 1], 58 - 36);
7896               }
7897           }
7898           break;
7899 
7900         case x0 (0613):  // rcu
7901           doRCU (cpup); // never returns!
7902 
7903         /// Privileged - Register Store
7904 
7905         /*FALLTHRU*/ /* fall through */ /* fallthrough */
7906         case x0 (0452):  // scpr
7907           {
7908             uint tag = (i->tag) & MASK6;
7909             switch (tag)
7910               {
7911                 case 000: // C(APU history register#1) -> C(Y-pair)
7912                   {
7913                     uint reg = cpu.tweaks.l68_mode ? L68_APU_HIST_REG : DPS8M_APU_HIST_REG;
7914                     cpu.Ypair[0] = cpu.history[reg] [cpu.history_cyclic[reg]][0];
7915                     cpu.Ypair[1] = cpu.history[reg] [cpu.history_cyclic[reg]][1];
7916                     cpu.history_cyclic[reg] = (cpu.history_cyclic[reg] + 1) % N_MODEL_HIST_SIZE;
7917                   }
7918                   break;
7919 
7920                 case 001: // C(fault register) -> C(Y-pair)0,35
7921                           // 00...0 -> C(Y-pair)36,71
7922                   {
7923                     CPTUR (cptUseFR);
7924                     cpu.Ypair[0]         = cpu.faultRegister[0];
7925                     cpu.Ypair[1]         = cpu.faultRegister[1];
7926                     cpu.faultRegister[0] = 0;
7927                     cpu.faultRegister[1] = 0;
7928                   }
7929                   break;
7930 
7931                 case 006: // C(mode register) -> C(Y-pair)0,35
7932                           // C(cache mode register) -> C(Y-pair)36,72
7933                   {
7934                     CPTUR (cptUseMR);
7935                     cpu.Ypair[0] = cpu.MR.r;
7936                     // DPS/L68: bits 20-21 are part of the trap OPCODE when
7937                     // OC TRAP (16) or O.C$ (29) is on (PM700 02V)
7938                     if (! cpu.tweaks.l68_mode ||
7939                         ! (getbits36_1 (cpu.MR.r, 16) || getbits36_1 (cpu.MR.r, 29)))
7940                       {
7941                         putbits36_1 (& cpu.Ypair[0], 20, cpu.MR.sdpap);
7942                         putbits36_1 (& cpu.Ypair[0], 21, cpu.MR.separ);
7943                       }
7944                     putbits36_1 (& cpu.Ypair[0], 30, cpu.MR.ihr);
7945                     DPS8M_ (putbits36_1 (& cpu.Ypair[0], 33, cpu.MR.hexfp);)
7946                     CPTUR (cptUseCMR);
7947                     cpu.Ypair[1] = 0;
7948                     putbits36_15 (& cpu.Ypair[1], 36 - 36,
7949                                   cpu.CMR.cache_dir_address);
7950                     putbits36_1 (& cpu.Ypair[1], 51 - 36, cpu.CMR.par_bit);
7951                     putbits36_1 (& cpu.Ypair[1], 52 - 36, cpu.CMR.lev_ful);
7952                     putbits36_1 (& cpu.Ypair[1], 54 - 36, cpu.CMR.csh1_on);
7953                     putbits36_1 (& cpu.Ypair[1], 55 - 36, cpu.CMR.csh2_on);
7954                     L68_ (putbits36_1 (& cpu.Ypair[1], 56 - 36, cpu.CMR.opnd_on);)
7955                     putbits36_1 (& cpu.Ypair[1], 57 - 36, cpu.CMR.inst_on);
7956                     putbits36_1 (& cpu.Ypair[1], 59 - 36, cpu.CMR.csh_reg);
7957                     putbits36_1 (& cpu.Ypair[1], 60 - 36, cpu.CMR.str_asd);
7958                     putbits36_1 (& cpu.Ypair[1], 61 - 36, cpu.CMR.col_ful);
7959                     putbits36_2 (& cpu.Ypair[1], 62 - 36, cpu.CMR.rro_AB);
7960                     DPS8M_ (putbits36_1 (& cpu.Ypair[1], 68 - 36, cpu.CMR.bypass_cache);)
7961                     putbits36_2 (& cpu.Ypair[1], 70 - 36, cpu.CMR.luf);
7962                     // The odd word is address-dependent: the store adds the
7963                     // cache directory entry that Y selects (dps8_cache.c
7964                     // cacheDirWord)
7965                     cpu.cacheDirReadout = true;
7966                   }
7967                   break;
7968 
7969                 case 010: // C(APU history register#2) -> C(Y-pair)
7970                   {
7971                     uint reg = cpu.tweaks.l68_mode ? L68_DU_HIST_REG : DPS8M_EAPU_HIST_REG;
7972                     cpu.Ypair[0] = cpu.history[reg] [cpu.history_cyclic[reg]][0];
7973                     cpu.Ypair[1] = cpu.history[reg] [cpu.history_cyclic[reg]][1];
7974                     cpu.history_cyclic[reg] = (cpu.history_cyclic[reg] + 1) % N_MODEL_HIST_SIZE;
7975                   }
7976                   break;
7977 
7978                 case 020: // C(CU history register) -> C(Y-pair)
7979                   {
7980                     cpu.Ypair[0] =
7981                       cpu.history[CU_HIST_REG]
7982                                  [cpu.history_cyclic[CU_HIST_REG]][0];
7983                     cpu.Ypair[1] =
7984                       cpu.history[CU_HIST_REG]
7985                                  [cpu.history_cyclic[CU_HIST_REG]][1];
7986                     cpu.history_cyclic[CU_HIST_REG] =
7987                       (cpu.history_cyclic[CU_HIST_REG] + 1) % N_MODEL_HIST_SIZE;
7988                   }
7989                   break;
7990 
7991                 case 040: // C(OU/DU history register) -> C(Y-pair)
7992                   {
7993                     uint reg = cpu.tweaks.l68_mode ? L68_OU_HIST_REG : DPS8M_DU_OU_HIST_REG;
7994                     cpu.Ypair[0] = cpu.history[reg] [cpu.history_cyclic[reg]][0];
7995                     cpu.Ypair[1] = cpu.history[reg] [cpu.history_cyclic[reg]][1];
7996                     cpu.history_cyclic[reg] = (cpu.history_cyclic[reg] + 1) % N_MODEL_HIST_SIZE;
7997                   }
7998                   break;
7999 
8000                 default:
8001                   {
8002                     doFault (FAULT_IPR,
8003                              fst_ill_mod,
8004                              "SCPR Illegal register select value");
8005                   }
8006               }
8007           }
8008           break;
8009 
8010         case x0 (0657):  // scu
8011           // AL-39 defines the behavior of SCU during fault/interrupt
8012           // processing, but not otherwise.
8013           // The T&D tape uses SCU during normal processing, and apparently
8014           // expects the current CU state to be saved.
8015 
8016           if (cpu.cycle == EXEC_cycle)
8017             {
8018               // T&D behavior
8019 
8020               // An 'Add Delta' addressing mode will alter the TALLY bit;
8021               // restore it (PA887 03A: unchanged by the scu).
8022               SC_I_TALLY (cpu.currentInstruction.stiTally);
8023 
8024               scu2words (cpup, cpu.Yblock8);
8025             }
8026           else
8027             {
8028               // AL-39 behavior
8029               for (int j = 0; j < 8; j ++)
8030                 cpu.Yblock8[j] = cpu.scu_data[j];
8031             }
8032           break;
8033 
8034         case x0 (0154):  // sdbr
8035           {
8036             CPTUR (cptUseDSBR);
8037             // C(DSBR.ADDR) -> C(Y-pair) 0,23
8038             // 00...0 -> C(Y-pair) 24,36
8039             cpu.Ypair[0] = ((word36) (cpu.DSBR.ADDR & PAMASK)) << (35 - 23);
8040 
8041             // C(DSBR.BOUND) -> C(Y-pair) 37,50
8042             // 0000 -> C(Y-pair) 51,54
8043             // C(DSBR.U) -> C(Y-pair) 55
8044             // 000 -> C(Y-pair) 56,59
8045             // C(DSBR.STACK) -> C(Y-pair) 60,71
8046             cpu.Ypair[1] = ((word36) (cpu.DSBR.BND & 037777)) << (71 - 50) |
8047                            ((word36) (cpu.DSBR.U & 1)) << (71 - 55) |
8048                            ((word36) (cpu.DSBR.STACK & 07777)) << (71 - 71);
8049           }
8050           break;
8051 
8052         case x1 (0557):  // sptp
8053           {
8054 // XXX AL39 The associative memory is ignored (forced to "no match") during address
8055 // preparation.
8056             // Level j is selected by C(TPR.CA)12,13
8057             uint level;
8058             L68_ (level = 0;)
8059             DPS8M_ (level = (cpu.TPR.CA >> 4) & 03;)
8060             uint toffset = level * 16;
8061             for (uint j = 0; j < 16; j ++)
8062               {
8063                 cpu.Yblock16[j] = 0;
8064                 putbits36_15 (& cpu.Yblock16[j],  0,
8065                            cpu.PTWAM[toffset + j].POINTER);
8066                 DPS8M_ (
8067                   putbits36_12 (& cpu.Yblock16[j], 15, cpu.PTWAM[toffset + j].PAGENO & 07760);
8068 
8069                   uint parity = 0;
8070                   // the parity bit was written with the register (PA866)
8071                   if (cpu.PTWAM[toffset + j].loaded) {
8072                     // calculate parity
8073                     // 58009997-040 p.101,111
8074                     parity = ((uint) cpu.PTWAM[toffset + j].POINTER << 4) | (cpu.PTWAM[toffset + j].PAGENO >> 8);
8075                     parity = parity ^ (parity >>16);
8076                     parity = parity ^ (parity >> 8);
8077                     parity = parity ^ (parity >> 4);
8078                     parity = ~ (0x6996u >> (parity & 0xf));
8079                   }
8080                   putbits36_1 (& cpu.Yblock16[j], 23, (word1) (parity & 1));
8081                 )
8082                 L68_ (putbits36_12 (& cpu.Yblock16[j], 15, cpu.PTWAM[toffset + j].PAGENO); )
8083                 putbits36_1 (& cpu.Yblock16[j], 27,
8084                            cpu.PTWAM[toffset + j].FE);
8085                 DPS8M_ (putbits36_6 (& cpu.Yblock16[j], 30, cpu.PTWAM[toffset + j].USE);)
8086                 L68_ (putbits36_4 (& cpu.Yblock16[j], 32, cpu.PTWAM[toffset + j].USE);)
8087               }
8088           }
8089           break;
8090 
8091         case x1 (0154):  // sptr
8092           {
8093 // XXX The associative memory is ignored (forced to "no match") during address
8094 // preparation.
8095 
8096             // Level j is selected by C(TPR.CA)12,13
8097             uint level;
8098             DPS8M_ (level = (cpu.TPR.CA >> 4) & 03;)
8099             L68_ (level = 0;)
8100             uint toffset = level * 16;
8101             for (uint j = 0; j < 16; j ++)
8102               {
8103                 cpu.Yblock16[j] = 0;
8104                 DPS8M_ (putbits36_18 (& cpu.Yblock16[j], 0, cpu.PTWAM[toffset + j].ADDR & 0777760);)
8105                 L68_ (putbits36_18 (& cpu.Yblock16[j], 0, cpu.PTWAM[toffset + j].ADDR);)
8106                 putbits36_1 (& cpu.Yblock16[j], 29,
8107                              cpu.PTWAM[toffset + j].M);
8108               }
8109           }
8110           break;
8111 
8112         case x0 (0557):  // ssdp
8113           {
8114             // XXX AL39: The associative memory is ignored (forced to "no match")
8115             // during address preparation.
8116             // Level j is selected by C(TPR.CA)12,13
8117             uint level;
8118             DPS8M_ (level = (cpu.TPR.CA >> 4) & 03;)
8119             L68_ (level = 0;)
8120             uint toffset = level * 16;
8121             for (uint j = 0; j < 16; j ++)
8122               {
8123                 cpu.Yblock16[j] = 0;
8124                 putbits36_15 (& cpu.Yblock16[j], 0,
8125                            cpu.SDWAM[toffset + j].POINTER);
8126                 putbits36_1 (& cpu.Yblock16[j], 27,
8127                            cpu.SDWAM[toffset + j].FE);
8128                 DPS8M_ (
8129                   uint parity = 0;
8130                   // the parity bit was written with the register (PA866)
8131                   if (cpu.SDWAM[toffset + j].loaded) {
8132                     // calculate parity
8133                     // 58009997-040 p.112
8134                     parity = cpu.SDWAM[toffset + j].POINTER >> 4;
8135                     //parity = parity ^ (parity >>16);
8136                     parity = parity ^ (parity >> 8);
8137                     parity = parity ^ (parity >> 4);
8138                     parity = ~ (0x6996u >> (parity & 0xf));
8139                   }
8140                   putbits36_1 (& cpu.Yblock16[j], 15, (word1) (parity & 1));
8141 
8142                   putbits36_6 (& cpu.Yblock16[j], 30, cpu.SDWAM[toffset + j].USE);
8143                 )
8144                 L68_ (putbits36_4 (& cpu.Yblock16[j], 32, cpu.SDWAM[toffset + j].USE);)
8145               }
8146           }
8147           break;
8148 
8149         case x1 (0254):  // ssdr
8150           {
8151 // XXX AL39: The associative memory is ignored (forced to "no match") during
8152 // address preparation.
8153 
8154             // Level j is selected by C(TPR.CA)11,12
8155             // Note: not bits 12,13. This is due to operand being Yblock32
8156             uint level = 0;
8157             DPS8M_ (level = (cpu.TPR.CA >> 5) & 03;)
8158             L68_ (level = 0;)
8159             uint toffset = level * 16;
8160             for (uint j = 0; j < 16; j ++)
8161               {
8162                 cpu.Yblock32[j * 2] = 0;
8163                 putbits36_24 (& cpu.Yblock32[j * 2],  0,
8164                            cpu.SDWAM[toffset + j].ADDR);
8165                 putbits36_3  (& cpu.Yblock32[j * 2], 24,
8166                            cpu.SDWAM[toffset + j].R1);
8167                 putbits36_3  (& cpu.Yblock32[j * 2], 27,
8168                            cpu.SDWAM[toffset + j].R2);
8169                 putbits36_3  (& cpu.Yblock32[j * 2], 30,
8170                            cpu.SDWAM[toffset + j].R3);
8171                 cpu.Yblock32[j * 2 + 1] = 0;
8172 
8173                 putbits36_14 (& cpu.Yblock32[j * 2 + 1], 37 - 36,
8174                            cpu.SDWAM[toffset + j].BOUND);
8175                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 51 - 36,
8176                            cpu.SDWAM[toffset + j].R);
8177                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 52 - 36,
8178                            cpu.SDWAM[toffset + j].E);
8179                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 53 - 36,
8180                            cpu.SDWAM[toffset + j].W);
8181                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 54 - 36,
8182                            cpu.SDWAM[toffset + j].P);
8183                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 55 - 36,
8184                            cpu.SDWAM[toffset + j].U);
8185                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 56 - 36,
8186                            cpu.SDWAM[toffset + j].G);
8187                 putbits36_1  (& cpu.Yblock32[j * 2 + 1], 57 - 36,
8188                            cpu.SDWAM[toffset + j].C);
8189                 putbits36_14 (& cpu.Yblock32[j * 2 + 1], 58 - 36,
8190                            cpu.SDWAM[toffset + j].EB);
8191               }
8192           }
8193           break;
8194 
8195         /// Privileged - Clear Associative Memory
8196 
8197         case x1 (0532):  // camp
8198           {
8199             // C(TPR.CA) 16,17 control disabling or enabling the associative
8200             // memory.
8201             // This may be done to either or both halves.
8202             // The full/empty bit of cache PTWAM register is set to zero and
8203             // the LRU counters are initialized.
8204             if (cpu.tweaks.enable_wam)
8205               { // disabled, do nothing
8206                 if (cpu.tweaks.l68_mode || cpu.cu.PT_ON) // only clear when enabled
8207                     for (uint i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
8208                       {
8209                         cpu.PTWAM[i].FE = 0;
8210                         L68_ (cpu.PTWAM[i].USE = (word4) i;)
8211                         DPS8M_ (cpu.PTWAM[i].USE = 0;)
8212                       }
8213 
8214 // 58009997-040 A level of the associative memory is disabled if
8215 // C(TPR.CA) 16,17 = 01
8216 // 58009997-040 A level of the associative memory is enabled if
8217 // C(TPR.CA) 16,17 = 10
8218 // Level j is selected to be enabled/disable if
8219 // C(TPR.CA) 10+j = 1; j=1,2,3,4
8220 // All levels are selected to be enabled/disabled if
8221 // C(TPR.CA) 11,14 = 0
8222 // This is contrary to what AL39 says, so I'm not going to implement it.
8223 // In fact, I'm not even going to implement the halves.
8224 
8225                 DPS8M_ (if (cpu.TPR.CA != 0000002 && (cpu.TPR.CA & 3) != 0)
8226                   { sim_debug (DBG_WARN, & cpu_dev,
8227                                "CAMP ignores enable/disable %06o\r\n", cpu.TPR.CA); })
8228                 if ((cpu.TPR.CA & 3) == 02)
8229                   cpu.cu.PT_ON = 1;
8230                 else if ((cpu.TPR.CA & 3) == 01)
8231                   cpu.cu.PT_ON = 0;
8232               }
8233             else
8234               {
8235                 cpu.PTW0.FE  = 0;
8236                 cpu.PTW0.USE = 0;
8237               }
8238           }
8239           ucInvalidate (cpup);
8240           break;
8241 
8242         case x0 (0532):  // cams
8243           {
8244             // The full/empty bit of each SDWAM register is set to zero and the
8245             // LRU counters are initialized. The remainder of the contents of
8246             // the registers are unchanged. If the associative memory is
8247             // disabled, F and LRU are unchanged.
8248             // C(TPR.CA) 16,17 control disabling or enabling the associative
8249             // memory.
8250             // This may be done to either or both halves.
8251             if (cpu.tweaks.enable_wam)
8252               {
8253                 if (cpu.tweaks.l68_mode || cpu.cu.SD_ON) // only clear when enabled
8254                     for (uint i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
8255                       {
8256                         cpu.SDWAM[i].FE = 0;
8257                         L68_ (cpu.SDWAM[i].USE = (word4) i;)
8258                         DPS8M_ (cpu.SDWAM[i].USE = 0;)
8259                       }
8260 // 58009997-040 A level of the associative memory is disabled if
8261 // C(TPR.CA) 16,17 = 01
8262 // 58009997-040 A level of the associative memory is enabled if
8263 // C(TPR.CA) 16,17 = 10
8264 // Level j is selected to be enabled/disable if
8265 // C(TPR.CA) 10+j = 1; j=1,2,3,4
8266 // All levels are selected to be enabled/disabled if
8267 // C(TPR.CA) 11,14 = 0
8268 // This is contrary to what AL39 says, so I'm not going to implement it. In
8269 // fact, I'm not even going to implement the halves.
8270 
8271                 DPS8M_ (if (cpu.TPR.CA != 0000006 && (cpu.TPR.CA & 3) != 0)
8272                   { sim_debug (DBG_WARN, & cpu_dev,
8273                                "CAMS ignores enable/disable %06o\r\n", cpu.TPR.CA); })
8274                 if ((cpu.TPR.CA & 3) == 02)
8275                   cpu.cu.SD_ON = 1;
8276                 else if ((cpu.TPR.CA & 3) == 01)
8277                   cpu.cu.SD_ON = 0;
8278               }
8279             else
8280               {
8281                 cpu.SDW0.FE  = 0;
8282                 cpu.SDW0.USE = 0;
8283               }
8284           }
8285           ucInvalidate (cpup);
8286           break;
8287 
8288         /// Privileged - Configuration and Status
8289 
8290         case x0 (0233):  // rmcm
8291           {
8292             // C(TPR.CA)0,2 (C(TPR.CA)1,2 for the DPS 8M processor)
8293             // specify which processor port (i.e., which system
8294             // controller) is used.
8295             uint cpu_port_num;
8296             DPS8M_ (cpu_port_num = (cpu.TPR.CA >> 15) & 03;)
8297             L68_ (cpu_port_num = (cpu.TPR.CA >> 15) & 07;)
8298             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8299               {
8300                 sim_warn ("rmcm to non-existent controller on "
8301                           "cpu %d port %d\r\n",
8302                           current_running_cpu_idx, cpu_port_num);
8303                 break;
8304               }
8305             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8306             t_stat rc = scu_rmcm ((uint) scuUnitIdx,
8307                                   current_running_cpu_idx,
8308                                   & cpu.rA, & cpu.rQ);
8309 #if defined(TESTING)
8310             HDBGRegAW ("rmcm");
8311             HDBGRegQW ("rmcm");
8312 #endif
8313             if (rc)
8314               return rc;
8315             SC_I_ZERO (cpu.rA == 0);
8316             SC_I_NEG (cpu.rA & SIGN36);
8317           }
8318           break;
8319 
8320         case x0 (0413):  // rscr
8321           {
8322             // For the rscr instruction, the first 2 (DPS8M) or 3 (L68) bits of
8323             // the addr field of the instruction are used to specify which SCU.
8324             // (2 bits for the DPS8M. (Expect for x6x and x7x below, where
8325             // the selected SCU is the one holding the addressed memory).
8326 
8327             // According to DH02:
8328             //   XXXXXX0X  SCU Mode Register (Level 66 only)
8329             //   XXXXXX1X  Configuration switches
8330             //   XXXXXn2X  Interrupt mask port n
8331             //   XXXXXX3X  Interrupt cells
8332             //   XXXXXX4X  Elapsed time clock
8333             //   XXXXXX5X  Elapsed time clock
8334             //   XXXXXX6X  Mode register
8335             //   XXXXXX7X  Mode register
8336 
8337             // According to privileged_mode_ut,
8338             //   port*1024 + scr_input*8
8339 
8340             // privileged_mode_ut makes no reference to the special case
8341             // of x6x and x7x.
8342 
8343             // According to DH02, RSCR in Slave Mode does the CAF
8344             // without BAR correction, and then forces the CA to 040,
8345             // resulting in a Clock Read from the SCU on port 0.
8346 
8347             // According to AL93, RSCR in BAR mode is IPR.
8348 
8349 //
8350 // Implementing privileged_mode_ut.alm algorithm
8351 //
8352 
8353             // Extract port number
8354             uint cpu_port_num;
8355             // T&D: SM781 addresses sscr/rscr through the appending unit
8356             // (pr0|0,x7 in absolute mode): the controller is the one holding
8357             // the final absolute address (as with Multics' SCAS); otherwise
8358             // C(TPR.CA)1,2 (AL39). Multics (privileged_mode_ut) uses
8359             // port*1024, i.e. >> 10.
8360             if (! (cpu.tweaks.tandd_mode && scr_port_from_final_address (cpup, & cpu_port_num)))
8361               {
8362                 uint shift = cpu.tweaks.tandd_mode ? 15 : 10;
8363                 DPS8M_ (cpu_port_num = (cpu.TPR.CA >> shift) & 03;)
8364                 L68_ (cpu_port_num = (cpu.TPR.CA >> shift) & 07;)
8365               }
8366 
8367             // Trace the cable from the port to find the SCU number
8368             // connected to that port
8369             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8370               {
8371                 // CPTUR (cptUseFR) -- will be set by doFault
8372 
8373                 // Set IAn in Fault register
8374                 if (cpu_port_num == 0)
8375                   putbits36 (& cpu.faultRegister[0], 16, 4, 010);
8376                 else if (cpu_port_num == 1)
8377                   putbits36 (& cpu.faultRegister[0], 20, 4, 010);
8378                 else if (cpu_port_num == 2)
8379                   putbits36 (& cpu.faultRegister[0], 24, 4, 010);
8380                 else
8381                   putbits36 (& cpu.faultRegister[0], 28, 4, 010);
8382 
8383                 doFault (FAULT_CMD, fst_cmd_ctl, "(rscr)");
8384               }
8385             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8386 #if defined(PANEL68)
8387             {
8388                uint function = (cpu.iefpFinalAddress >> 3) & 07;
8389                CPT (cpt13L, function);
8390             }
8391 #endif
8392             t_stat rc = scu_rscr (cpup, (uint) scuUnitIdx, current_running_cpu_idx,
8393                                   cpu.iefpFinalAddress & MASK15,
8394                                   & cpu.rA, & cpu.rQ);
8395 #if defined(TESTING)
8396             HDBGRegAW ("rscr");
8397             HDBGRegQW ("rscr");
8398 #endif
8399             if (rc)
8400               return rc;
8401           }
8402           break;
8403 
8404         case x0 (0231):  // rsw
8405           {
8406             if (! cpu.tweaks.l68_mode) {
8407               word6 rTAG = GET_TAG (IWB_IRODD);
8408               word6 Td = GET_TD (rTAG);
8409               word6 Tm = GET_TM (rTAG);
8410               if (Tm == TM_R && Td == TD_DL)
8411                 {
8412                   unsigned char PROM[1024];
8413                   setupPROM (current_running_cpu_idx, PROM);
8414                   cpu.rA = PROM[cpu.TPR.CA & 1023];
8415                   break;
8416                 }
8417             }  // DPS8M
8418             uint select = cpu.TPR.CA & 0x7;
8419             switch (select)
8420               {
8421                 case 0: // data switches
8422                   cpu.rA = cpu.switches.data_switches;
8423                   break;
8424 
8425                 case 1: // configuration switches for ports A, B, C, D
8426 // y = 1:
8427 //
8428 //   0               0 0               1 1               2 2               3
8429 //   0               8 9               7 8               6 7               5
8430 //  -------------------------------------------------------------------------
8431 //  |      PORT A     |     PORT B      |     PORT C      |     PORT D      |
8432 //  -------------------------------------------------------------------------
8433 //  | ADR |j|k|l| MEM | ADR |j|k|l| MEM | ADR |j|k|l| MEM | ADR |j|k|l| MEM |
8434 //  -------------------------------------------------------------------------
8435 //
8436 //
8437 //   ADR: Address assignment switch setting for port
8438 //         This defines the base address for the SCU
8439 //   j: port enabled flag
8440 //   k: system initialize enabled flag
8441 //   l: interface enabled flag
8442 //   MEM coded memory size
8443 //     000 32K     2^15
8444 //     001 64K     2^16
8445 //     010 128K    2^17
8446 //     011 256K    2^18
8447 //     100 512K    2^19
8448 //     101 1024K   2^20
8449 //     110 2048K   2^21
8450 //     111 4096K   2^22
8451 
8452                   cpu.rA  = 0;
8453                   cpu.rA |= (word36) (cpu.switches.assignment  [0] & 07LL)
8454                             << (35 -  (2 +  0));
8455                   cpu.rA |= (word36) (cpu.switches.enable      [0] & 01LL)
8456                             << (35 -  (3 +  0));
8457                   cpu.rA |= (word36) (cpu.switches.init_enable [0] & 01LL)
8458                             << (35 -  (4 +  0));
8459                   cpu.rA |= (word36) (cpu.switches.interlace   [0] ? 1LL:0LL)
8460                             << (35 -  (5 +  0));
8461                   cpu.rA |= (word36) (cpu.switches.store_size  [0] & 07LL)
8462                             << (35 -  (8 +  0));
8463 
8464                   cpu.rA |= (word36) (cpu.switches.assignment  [1] & 07LL)
8465                             << (35 -  (2 +  9));
8466                   cpu.rA |= (word36) (cpu.switches.enable      [1] & 01LL)
8467                             << (35 -  (3 +  9));
8468                   cpu.rA |= (word36) (cpu.switches.init_enable [1] & 01LL)
8469                             << (35 -  (4 +  9));
8470                   cpu.rA |= (word36) (cpu.switches.interlace   [1] ? 1LL:0LL)
8471                             << (35 -  (5 +  9));
8472                   cpu.rA |= (word36) (cpu.switches.store_size  [1] & 07LL)
8473                             << (35 -  (8 +  9));
8474 
8475                   cpu.rA |= (word36) (cpu.switches.assignment  [2] & 07LL)
8476                             << (35 -  (2 + 18));
8477                   cpu.rA |= (word36) (cpu.switches.enable      [2] & 01LL)
8478                             << (35 -  (3 + 18));
8479                   cpu.rA |= (word36) (cpu.switches.init_enable [2] & 01LL)
8480                             << (35 -  (4 + 18));
8481                   cpu.rA |= (word36) (cpu.switches.interlace   [2] ? 1LL:0LL)
8482                             << (35 -  (5 + 18));
8483                   cpu.rA |= (word36) (cpu.switches.store_size  [2] & 07LL)
8484                             << (35 -  (8 + 18));
8485 
8486                   cpu.rA |= (word36) (cpu.switches.assignment  [3] & 07LL)
8487                             << (35 -  (2 + 27));
8488                   cpu.rA |= (word36) (cpu.switches.enable      [3] & 01LL)
8489                             << (35 -  (3 + 27));
8490                   cpu.rA |= (word36) (cpu.switches.init_enable [3] & 01LL)
8491                             << (35 -  (4 + 27));
8492                   cpu.rA |= (word36) (cpu.switches.interlace   [3] ? 1LL:0LL)
8493                             << (35 -  (5 + 27));
8494                   cpu.rA |= (word36) (cpu.switches.store_size  [3] & 07LL)
8495                             << (35 -  (8 + 27));
8496                   break;
8497 
8498                 case 2: // fault base and processor number  switches
8499 // y = 2:
8500 //
8501 //   0     0 0 0 0            1 1 1     1 1 1 2 2 2 2 2 2 2   2 2     3 3   3
8502 //   0     3 4 5 6            2 3 4     7 8 9 0 1 2 3 4 5 6   8 9     2 3   5
8503 //  --------------------------------------------------------------------------
8504 //  |A|B|C|D|   |              | |       | | | |   | | | |     |       |     |
8505 //  --------- b |   FLT BASE   |c|0 0 0 0|d|e|f|0 0|g|h|i|0 0 0| SPEED | CPU |
8506 //  |a|a|a|a|   |              | |       | | | |   | | | |     |       |     |
8507 //  --------------------------------------------------------------------------
8508 //
8509 
8510 //   a: port A-D is 0: 4 word or 1: 2 word
8511 //   b: processor type 0:L68 or DPS, 1: DPS8M, 2,3: reserved for future use
8512 //   c: id prom 0: not installed, 1: installed
8513 //   d: 1: bcd option installed (marketing designation)
8514 //   e: 1: dps option installed (marketing designation)
8515 //   f: 1: 8k cache installed
8516 //   g: processor type designation: 0: dps8/xx, 1: dps8m/xx
8517 //   h: gcos/vms switch position: 0:GCOS mode 1: virtual mode
8518 //   i: current or new product line peripheral type: 0:CPL, 1:NPL
8519 //   SPEED: 0000 = 8/70, 0100 = 8/52
8520 //   CPU: Processor number
8521 // DPS 8M processors:
8522 // C(Port interlace, Ports A-D) -> C(A) 0,3
8523 // 01 -> C(A) 4,5
8524 // C(Fault base switches) -> C(A) 6,12
8525 // 1 -> C(A) 13
8526 // 0000 -> C(A) 14,17
8527 // 111 -> C(A) 18,20
8528 // 00 -> C(A) 21,22
8529 // 1 -> C(A) 23
8530 // C(Processor mode sw) -> C(A) 24
8531 // 1 -> C(A) 25
8532 // 000 -> C(A) 26,28
8533 // C(Processor speed) -> C (A) 29,32
8534 
8535 // C(Processor number switches) -> C(A) 33,35
8536 
8537 // According to bound_gcos_.1.s.archive/gcos_fault_processor_.pl1 (L68/DPS):
8538 //
8539 // /* Set the A register to reflect switch info. */
8540 //                          mc.regs.a =
8541 //
8542 // /* (A-reg bits) */
8543 // /* (0-3) Port address expansion option:           */ (4)"0"b
8544 // /* (4-5) Reserved for future use:                 */ || (2)"0"b
8545 // /* (6-12) Processor fault base address switches:  */ || (7)"0"b
8546 // /* (13-16) L66 peripheral connectability:         */ || (4)"0"b
8547 // /* (17) Future use (must be zero):                */ || (1)"1"b
8548 // /* (18) BCD option installed:                     */ || (1)"1"b
8549 // /* (19) DPS type processor:                       */ || (1)"0"b
8550 // /* (20) 8K cache option installed:                */ || (1)"0"b
8551 // /* (21) Gear shift model processor:               */ || (1)"0"b
8552 // /* (22) Power patch option installed:             */ || (1)"0"b
8553 // /* (23) VMS-CU option installed - 66B' proc:      */ || (1)"0"b
8554 // /* (24) VMS-VU option installed - 66B proc:       */ || (1)"0"b
8555 // /* (25) Type processor (0) CPL, (1) DPSE-NPL:     */ || (1)"0"b
8556 // /* (26) 6025, 6605 or 6610 type processor:        */ || (1)"0"b
8557 // /* (27) 2K cache option installed:                */ || (1)"0"b
8558 // /* (28) Extended memory option installed:         */ || (1)"0"b
8559 // /* (29-30) cabinet (00) 8/70, (01) 8/52, (10) 862, (11) 846:          */ || (2)"0"b
8560 // /* (31) EIS option installed:                     */ || (1)"1"b
8561 // /* (32) (1) slow memory access, (0) fast memory:  */ || (1)"0"b
8562 // /* (33) (1) no instruction overlap, (0) overlap:  */ || (1)"0"b
8563 // /* (34-35) Processor number:                      */ ||unspec (mc.cpu_type);
8564 
8565                   cpu.rA = 0;
8566                   DPS8M_ (
8567                     cpu.rA |= (word36) ((cpu.switches.interlace[0] == 2 ?
8568                             1LL : 0LL) << (35- 0));
8569                     cpu.rA |= (word36) ((cpu.switches.interlace[1] == 2 ?
8570                             1LL : 0LL) << (35- 1));
8571                     cpu.rA |= (word36) ((cpu.switches.interlace[2] == 2 ?
8572                             1LL : 0LL) << (35- 2));
8573                     cpu.rA |= (word36) ((cpu.switches.interlace[3] == 2 ?
8574                             1LL : 0LL) << (35- 3));
8575                   )
8576 
8577                   if (cpu.tweaks.l68_mode)
8578                     // NO-OP
8579                     // cpu.rA |= (word36) ((00L)  /* 0b00 L68/DPS */
8580                     //          << (35- 5));
8581                     ;
8582                   else
8583                     cpu.rA |= (word36) ((01L)  /* 0b01 DPS8M */
8584                              << (35- 5));
8585                   cpu.rA |= (word36) ((cpu.switches.FLT_BASE & 0177LL)
8586                              << (35-12));
8587                   DPS8M_ (cpu.rA |= (word36) ((01L) /* 0b1 ID_PROM installed */
8588                              << (35-13));)
8589                   // NO-OP
8590                   // cpu.rA |= (word36) ((00L) // 0b0000
8591                   //           << (35-17));
8592                   //cpu.rA |= (word36) ((0b111L)
8593                               //<< (35-20));
8594                   // According to rsw.incl.pl1, Multics ignores this bit.
8595                   // NO-OP
8596                   // cpu.rA |= (word36) ((00L)  // 0b0 BCD option off
8597                   //           << (35-18));
8598                   if (cpu.tweaks.l68_mode)
8599                     // NO-OP
8600                     // cpu.rA |= (word36) ((00L)  // 0b0 L68/DPS option: L68
8601                     //        << (35-19));
8602                     ;
8603                   else
8604                     cpu.rA |= (word36) ((01L)  // 0b1 L68/DPS option: DPS
8605                             << (35-19));
8606                   DPS8M_ (
8607                                              // 8K cache
8608                                              // 0b0: not installed
8609                                              // 0b1: installed
8610                     cpu.rA |= (word36) ((cpu.switches.enable_cache ? 1 : 0)
8611                             << (35-20));
8612                     // NO-OP
8613                     // cpu.rA |= (word36) ((00L) // 0b00
8614                     //         << (35-22));
8615                     // g: 1 = DPS8M processor type designation. h: GCOS/VMS
8616                     // switch, 1 = virtual mode; rsw.incl.pl1 calls it
8617                     // multics_cpu, "always 1 for Multics cpu" (procModeMultics
8618                     // is 0, so the old procMode bits were 0 in Multics mode).
8619                     // The T&D PAS executive halts unless h is 1.
8620                     cpu.rA |= (word36) (1LL << (35-23));
8621                     cpu.rA |= (word36) ((cpu.switches.procMode == procModeMultics ? 1LL : 0LL)
8622                             << (35-24));
8623                     // NO-OP
8624                     // cpu.rA |= (word36) ((00L) // 0b0 new product line (CPL/NPL)
8625                     //         << (35-25));
8626                     // NO-OP
8627                     // cpu.rA |= (word36) ((00L) // 0b000
8628                     //         << (35-28));
8629                     cpu.rA |= (word36) ((cpu.options.proc_speed & 017LL)
8630                             << (35-32));
8631                   )
8632 
8633                   L68_ (
8634                     // NO-OP
8635                     // cpu.rA |= (word36) ((00L) // 0b0 2K cache disabled
8636                     //         << (35-27));
8637                     // NO-OP
8638                     // cpu.rA |= (word36) ((00L) // 0b0 GCOS mode extended memory disabled
8639                     //         << (35-28));
8640                     cpu.rA |= (word36) ((016L) // 0b1110 CPU ID
8641                             << (35-32));
8642                   )
8643                   cpu.rA |= (word36) ((cpu.switches.cpu_num & 07LL)
8644                             << (35-35));
8645                   break;
8646 
8647                 case 3: // configuration switches for ports E, F, G, H
8648                   if (!cpu.tweaks.l68_mode) { // DPS8M
8649                     cpu.rA = 0;
8650                     break;
8651                   }
8652                   // L68
8653 // y = 3:
8654 //
8655 //   0               0 0               1 1               2 2               3
8656 //   0               8 9               7 8               6 7               5
8657 //  -------------------------------------------------------------------------
8658 //  |      PORT E     |     PORT F      |     PORT G      |     PORT H      |
8659 //  -------------------------------------------------------------------------
8660 //  | ADR |j|k|l| MEM | ADR |j|k|l| MEM | ADR |j|k|l| MEM | ADR |j|k|l| MEM |
8661 //  -------------------------------------------------------------------------
8662 //
8663 //
8664 //   ADR: Address assignment switch setting for port
8665 //         This defines the base address for the SCU
8666 //   j: port enabled flag
8667 //   k: system initialize enabled flag
8668 //   l: interface enabled flag
8669 //   MEM coded memory size
8670 //     000 32K     2^15
8671 //     001 64K     2^16
8672 //     010 128K    2^17
8673 //     011 256K    2^18
8674 //     100 512K    2^19
8675 //     101 1024K   2^20
8676 //     110 2048K   2^21
8677 //     111 4096K   2^22
8678 
8679                   cpu.rA  = 0;
8680                   cpu.rA |= (word36) (cpu.switches.assignment  [4] & 07LL)
8681                             << (35 -  (2 +  0));
8682                   cpu.rA |= (word36) (cpu.switches.enable      [4] & 01LL)
8683                             << (35 -  (3 +  0));
8684                   cpu.rA |= (word36) (cpu.switches.init_enable [4] & 01LL)
8685                             << (35 -  (4 +  0));
8686                   cpu.rA |= (word36) (cpu.switches.interlace   [4] ? 1LL:0LL)
8687                             << (35 -  (5 +  0));
8688                   cpu.rA |= (word36) (cpu.switches.store_size  [4] & 07LL)
8689                             << (35 -  (8 +  0));
8690 
8691                   cpu.rA |= (word36) (cpu.switches.assignment  [5] & 07LL)
8692                             << (35 -  (2 +  9));
8693                   cpu.rA |= (word36) (cpu.switches.enable      [5] & 01LL)
8694                             << (35 -  (3 +  9));
8695                   cpu.rA |= (word36) (cpu.switches.init_enable [5] & 01LL)
8696                             << (35 -  (4 +  9));
8697                   cpu.rA |= (word36) (cpu.switches.interlace   [5] ? 1LL:0LL)
8698                             << (35 -  (5 +  9));
8699                   cpu.rA |= (word36) (cpu.switches.store_size  [5] & 07LL)
8700                             << (35 -  (8 +  9));
8701 
8702                   cpu.rA |= (word36) (cpu.switches.assignment  [6] & 07LL)
8703                             << (35 -  (2 + 18));
8704                   cpu.rA |= (word36) (cpu.switches.enable      [6] & 01LL)
8705                             << (35 -  (3 + 18));
8706                   cpu.rA |= (word36) (cpu.switches.init_enable [6] & 01LL)
8707                             << (35 -  (4 + 18));
8708                   cpu.rA |= (word36) (cpu.switches.interlace   [6] ? 1LL:0LL)
8709                             << (35 -  (5 + 18));
8710                   cpu.rA |= (word36) (cpu.switches.store_size  [6] & 07LL)
8711                             << (35 -  (8 + 18));
8712 
8713                   cpu.rA |= (word36) (cpu.switches.assignment  [7] & 07LL)
8714                             << (35 -  (2 + 27));
8715                   cpu.rA |= (word36) (cpu.switches.enable      [7] & 01LL)
8716                             << (35 -  (3 + 27));
8717                   cpu.rA |= (word36) (cpu.switches.init_enable [7] & 01LL)
8718                             << (35 -  (4 + 27));
8719                   cpu.rA |= (word36) (cpu.switches.interlace   [7] ? 1LL:0LL)
8720                             << (35 -  (5 + 27));
8721                   cpu.rA |= (word36) (cpu.switches.store_size  [7] & 07LL)
8722                             << (35 -  (8 + 27));
8723                   break;
8724 
8725                 case 4:
8726                   // I suspect the this is a L68 only, but AL39 says both
8727                   // port interlace and half/full size
8728                   // The DPS doesn't seem to have the half/full size switches
8729                   // so we'll always report full, and the interlace bits were
8730                   // squeezed into RSW 2
8731 
8732 //  0                       1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2           3
8733 //  0                       2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9           5
8734 // -------------------------------------------------------------------------
8735 // |                         | A | B | C | D | E | F | G | H |             |
8736 // |0 0 0 0 0 0 0 0 0 0 0 0 0---------------------------------0 0 0 0 0 0 0|
8737 // |                         |f|g|f|g|f|g|f|g|f|g|f|g|f|g|f|g|             |
8738 // -------------------------------------------------------------------------
8739 //                         13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1             7
8740 
8741                   cpu.rA  = 0;
8742                   cpu.rA |= (word36) (cpu.switches.interlace [0] == 2 ?
8743                             1LL : 0LL) << (35-13);
8744                   cpu.rA |= (word36) (cpu.switches.interlace [1] == 2 ?
8745                             1LL : 0LL) << (35-15);
8746                   cpu.rA |= (word36) (cpu.switches.interlace [2] == 2 ?
8747                             1LL : 0LL) << (35-17);
8748                   cpu.rA |= (word36) (cpu.switches.interlace [3] == 2 ?
8749                             1LL : 0LL) << (35-19);
8750                   L68_ (
8751                     cpu.rA |= (word36) (cpu.switches.interlace [4] == 2 ?
8752                             1LL : 0LL) << (35-21);
8753                     cpu.rA |= (word36) (cpu.switches.interlace [5] == 2 ?
8754                             1LL : 0LL) << (35-23);
8755                     cpu.rA |= (word36) (cpu.switches.interlace [6] == 2 ?
8756                             1LL : 0LL) << (35-25);
8757                     cpu.rA |= (word36) (cpu.switches.interlace [7] == 2 ?
8758                             1LL : 0LL) << (35-27);
8759                   )
8760                   break;
8761 
8762                 default:
8763                   // XXX Guessing values; also we don't know if this is actually a fault
8764                   doFault (FAULT_IPR,
8765                            fst_ill_mod,
8766                            "Illegal register select value");
8767               }
8768 #if defined(TESTING)
8769             HDBGRegAW ("rsw");
8770 #endif
8771             SC_I_ZERO (cpu.rA == 0);
8772             SC_I_NEG (cpu.rA & SIGN36);
8773           }
8774           break;
8775 
8776         /// Privileged - System Control
8777 
8778         case x0 (0015):  // cioc
8779           {
8780 
8781 #if defined(THREADZ) || defined(LOCKLESS)
8782 
8783 
8784 
8785 
8786 
8787 
8788 
8789 
8790 
8791 
8792 
8793 #endif
8794 
8795             // cioc The system controller addressed by Y (i.e., contains
8796             // the word at Y) sends a connect signal to the port specified
8797             // by C(Y) 33,35.
8798             int cpu_port_num = lookup_cpu_mem_map (cpup, cpu.iefpFinalAddress);
8799             // If there is no port to that memory location, fault
8800             if (cpu_port_num < 0)
8801               {
8802                 doFault (FAULT_ONC, fst_onc_nem, "(cioc)");
8803               }
8804             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8805               {
8806                 doFault (FAULT_ONC, fst_onc_nem, "(cioc)");
8807               }
8808             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8809 
8810 // expander word
8811 // dcl  1 scs$reconfig_general_cow aligned external, /* Used during reconfig
8812 //                                                      ops. */
8813 //   2 pad bit (36) aligned,
8814 //   2 cow,                        /* Connect operand word, in odd location. */
8815 //   3 sub_mask bit (8) unaligned, /* Expander sub-port mask */
8816 //   3 mbz1 bit (13) unaligned,
8817 //   3 expander_command bit (3) unaligned,   /* Expander command. */
8818 //   3 mbz2 bit (9) unaligned,
8819 //   3 controller_port fixed bin (3) unaligned unsigned;/* controller port for
8820 //                                                          this CPU */
8821 
8822             word8 sub_mask = getbits36_8 (cpu.CY, 0);
8823             word3 expander_command = getbits36_3 (cpu.CY, 21);
8824             uint scu_port_num = (uint) getbits36_3 (cpu.CY, 33);
8825             scu_cioc (current_running_cpu_idx, (uint) scuUnitIdx, scu_port_num,
8826                       expander_command, sub_mask);
8827           }
8828           break;
8829 
8830         case x0 (0553):  // smcm
8831           {
8832             // C(TPR.CA)0,2 (C(TPR.CA)1,2 for the DPS 8M processor)
8833             // specify which processor port (i.e., which system
8834             // controller) is used.
8835             uint cpu_port_num;
8836             DPS8M_ (cpu_port_num = (cpu.TPR.CA >> 15) & 03;)
8837             L68_ (cpu_port_num = (cpu.TPR.CA >> 15) & 07;)
8838             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8839               {
8840                 sim_warn ("smcm to non-existent controller on "
8841                           "cpu %d port %d\r\n",
8842                           current_running_cpu_idx, cpu_port_num);
8843                 break;
8844               }
8845             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8846             // T&D: sent with incorrect ZAC/data parity
8847             if (sc_command_parity (cpup, (uint) scuUnitIdx, cpu_port_num))
8848               break;
8849             t_stat rc = scu_smcm ((uint) scuUnitIdx,
8850                                   current_running_cpu_idx, cpu.rA, cpu.rQ);
8851             if (rc)
8852               return rc;
8853           }
8854           break;
8855 
8856         case x0 (0451):  // smic
8857           {
8858             // For the smic instruction, the first 2 or 3 bits of the addr
8859             // field of the instruction are used to specify which SCU.
8860             // 2 bits for the DPS8M.
8861             //int scuUnitIdx = getbits36_2 (TPR.CA, 0);
8862 
8863             // C(TPR.CA)0,2 (C(TPR.CA)1,2 for the DPS 8M processor)
8864             // specify which processor port (i.e., which system
8865             // controller) is used.
8866             uint cpu_port_num;
8867             DPS8M_ (cpu_port_num = (cpu.TPR.CA >> 15) & 03;)
8868             L68_ (cpu_port_num = (cpu.TPR.CA >> 15) & 07;)
8869             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8870               {
8871                 DPS8M_ (return SCPE_OK;)
8872                 // L68
8873                 // CPTUR (cptUseFR) -- will be set by doFault
8874                 if (cpu_port_num == 0)
8875                   putbits36_4 (& cpu.faultRegister[0], 16, 010);
8876                 else if (cpu_port_num == 1)
8877                   putbits36_4 (& cpu.faultRegister[0], 20, 010);
8878                 else if (cpu_port_num == 2)
8879                   putbits36_4 (& cpu.faultRegister[0], 24, 010);
8880                 else if (cpu_port_num == 3)
8881                   putbits36 (& cpu.faultRegister[0], 28, 4, 010);
8882 // XXX What if the port is > 3?
8883                 doFault (FAULT_CMD, fst_cmd_ctl, "(smic)");
8884               }
8885             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8886             // T&D: sent with incorrect ZAC/data parity
8887             if (sc_command_parity (cpup, (uint) scuUnitIdx, cpu_port_num))
8888               break;
8889             t_stat rc = scu_smic (cpup, (uint) scuUnitIdx, current_running_cpu_idx,
8890                                   cpu_port_num, cpu.rA);
8891             if (rc)
8892               return rc;
8893           }
8894           break;
8895 
8896         case x0 (0057):  // sscr
8897           {
8898             //uint cpu_port_num = (cpu.TPR.CA >> 15) & 03;
8899             // Looking at privileged_mode_ut.alm, shift 10 bits...
8900             uint cpu_port_num;
8901             // T&D: SM781 addresses sscr/rscr through the appending unit
8902             // (pr0|0,x7 in absolute mode): the controller is the one holding
8903             // the final absolute address (as with Multics' SCAS); otherwise
8904             // C(TPR.CA)1,2 (AL39). Multics (privileged_mode_ut) uses
8905             // port*1024, i.e. >> 10.
8906             if (! (cpu.tweaks.tandd_mode && scr_port_from_final_address (cpup, & cpu_port_num)))
8907               {
8908                 uint shift = cpu.tweaks.tandd_mode ? 15 : 10;
8909                 DPS8M_ (cpu_port_num = (cpu.TPR.CA >> shift) & 03;)
8910                 L68_ (cpu_port_num = (cpu.TPR.CA >> shift) & 07;)
8911               }
8912             if (! get_scu_in_use (current_running_cpu_idx, cpu_port_num))
8913               {
8914                 // CPTUR (cptUseFR) -- will be set by doFault
8915                 if (cpu_port_num == 0)
8916                   putbits36_4 (& cpu.faultRegister[0], 16, 010);
8917                 else if (cpu_port_num == 1)
8918                   putbits36_4 (& cpu.faultRegister[0], 20, 010);
8919                 else if (cpu_port_num == 2)
8920                   putbits36_4 (& cpu.faultRegister[0], 24, 010);
8921                 else
8922                   putbits36 (& cpu.faultRegister[0], 28, 4, 010);
8923                 doFault (FAULT_CMD, fst_cmd_ctl, "(sscr)");
8924               }
8925             uint scuUnitIdx = get_scu_idx (current_running_cpu_idx, cpu_port_num);
8926             // T&D: sent with incorrect ZAC/data parity
8927             if (sc_command_parity (cpup, (uint) scuUnitIdx, cpu_port_num))
8928               break;
8929             t_stat rc = scu_sscr (cpup, (uint) scuUnitIdx, current_running_cpu_idx,
8930                                   cpu_port_num, cpu.iefpFinalAddress & MASK15,
8931                                   cpu.rA, cpu.rQ);
8932 
8933             if (rc)
8934               return rc;
8935           }
8936           break;
8937 
8938         // Privileged - Miscellaneous
8939 
8940         case x0 (0212):  // absa
8941           {
8942             word36 result;
8943             int rc = doABSA (cpup, & result);
8944             if (rc)
8945               return rc;
8946             cpu.rA = result;
8947 #if defined(TESTING)
8948             HDBGRegAW ("absa");
8949 #endif
8950             SC_I_ZERO (cpu.rA == 0);
8951             SC_I_NEG (cpu.rA & SIGN36);
8952           }
8953           break;
8954 
8955         case x0 (0616):  // dis
8956 #ifdef SYNCTEST
8957           // Trap the call to sys$trouble
8958           if (cpu.PPR.PSR == 034 && cpu.PPR.IC == 03535) {
8959 # ifdef HDBG
8960             hdbgPrint ();
8961 # endif
8962             sim_printf ("sys$trouble\r\n");
8963             exit (1);
8964           }
8965 #endif
8966 
8967 #if defined(THREADZ) || defined(LOCKLESS)
8968           if (cpu.forceRestart) {
8969             cpu.forceRestart = 0;
8970             longjmp (cpu.jmpMain, JMP_FORCE_RESTART);
8971           }
8972 #endif
8973 
8974           if (! cpu.tweaks.dis_enable)
8975             {
8976               return STOP_STOP;
8977             }
8978 
8979           // XXX This is subtle; g7Pending below won't see the queued
8980           // g7Fault. I don't understand how the real hardware dealt
8981           // with this, but this seems to work. (I would hazard a guess
8982           // that DIS was doing a continuous FETCH/EXECUTE cycle
8983           // ('if !interrupt goto .'))
8984           advanceG7Faults (cpup);
8985 
8986           if ((! cpu.tweaks.tro_enable) &&
8987               (! sample_interrupts (cpup)) &&
8988               (sim_qcount () == 0))  // XXX If clk_svc is implemented it will
8989                                      // break this logic
8990             {
8991               sim_printf ("DIS@0%06o with no interrupts pending and"
8992                           " no events in queue\r\n", cpu.PPR.IC);
8993 #if defined(WIN_STDIO)
8994               sim_printf ("\r\nCycles = %llu\r\n",
8995 #else
8996               sim_printf ("\r\nCycles = %'llu\r\n",
8997 #endif /* if defined(WIN_STDIO) */
8998                           (unsigned long long)cpu.cycleCnt);
8999 #if defined(WIN_STDIO)
9000               sim_printf ("\r\nInstructions = %llu\r\n",
9001 #else
9002               sim_printf ("\r\nInstructions = %'llu\r\n",
9003 #endif /* if defined(WIN_STDIO) */
9004                           (unsigned long long)cpu.cycleCnt);
9005               longjmp (cpu.jmpMain, JMP_STOP);
9006             }
9007 
9008 // Multics/BCE halt
9009           if (cpu.PPR.PSR == 0430 && cpu.PPR.IC == 012)
9010               {
9011                 sim_printf ("BCE DIS causes CPU halt\r\n");
9012                 sim_debug (DBG_MSG, & cpu_dev, "BCE DIS causes CPU halt\r\n");
9013 #if defined(LOCKLESS)
9014                 bce_dis_called = true;
9015 #endif // LOCKLESS
9016                 longjmp (cpu.jmpMain, JMP_STOP);
9017               }
9018 
9019 #if defined(THREADZ) || defined(LOCKLESS)
9020 // RCF halt
9021           // XXX pxss uses a distinctive DIS operation
9022           // for RCF DELETE. If we see it, remember that
9023           // we did.
9024           if (IWB_IRODD == 0000777616207) {
9025             //HDBGNote (cpup, "DIS", "DIS clears inMultics%s", "");
9026             cpu.inMultics = false;
9027           }
9028 
9029 // ISOLTS start:
9030 //     CPU B thread created.
9031 //     DBG(1)> CPU 1 TRACE:  000000 0 000000616000 (DIS 000000)
9032 //     DBG(3)> CPU 1 INTR:  Interrupt pair address 0
9033 //     DBG(3)> CPU 1 FINAL: intr even read  00000000 000000755200
9034 //     DBG(3)> CPU 1 FINAL: intr odd read  00000001 000000616200
9035 //     DBG(4)> CPU 1 TRACE:  000001 0 000000755200 (STA 000000)
9036 //     DBG(4)> CPU 1 REG: sta read   A   000000000000
9037 //     DBG(4)> CPU 1 IEFP ABS     WRITE: :000000
9038 //     DBG(4)> CPU 1 FINAL: WriteOperandStore AB write 00000000 000000000000
9039 //     DBG(5)> CPU 1 TRACE:  000001 0 000000616200 (DIS 000000)
9040 // There are different behaviors for various configuration errors.
9041 //   If ISOLTS mode is not set, we see an IWB_IRODD of 0000000616200
9042 //   If set, 0000001616200
9043 
9044           // If we do a DIS while sync clock master, and are inMultics,
9045           // cancel sync clock... But not the processor startup DIS
9046 
9047           if (UNLIKELY (cpu.syncClockModeMaster) &&
9048               cpu.inMultics &&
9049               (cpu.PPR.PSR !=0 || cpu.PPR.IC != 0)) {
9050 # ifdef SYNCTEST
9051             sim_printf ("CPU%c DIS %o:%o gives up master\r\n", cpu.cpuIdx + 'A', cpu.PPR.PSR, cpu.PPR.IC);
9052 # endif
9053             //HDBGNote (cpup, "DIS", "DIS give up clock master%s", "");
9054             giveupClockMaster (cpup);
9055           }
9056 #endif
9057 
9058 
9059 
9060 
9061 
9062 
9063 
9064 
9065 
9066 
9067 
9068 
9069 
9070 
9071 
9072 
9073 
9074 
9075 
9076 
9077           sim_debug (DBG_TRACEEXT, & cpu_dev, "entered DIS_cycle\r\n");
9078 
9079           // No operation takes place, and the processor does not
9080           // continue with the next instruction; it waits for a
9081           // external interrupt signal.
9082           // AND, according to pxss.alm, TRO
9083 
9084 // Bless NovaScale...
9085 //  DIS
9086 //
9087 //    NOTES:
9088 //
9089 //      1. The inhibit bit in this instruction only affects the recognition
9090 //         of a Timer Runout (TROF) fault.
9091 //
9092 //         Inhibit ON delays the recognition of a TROF until the processor
9093 //         enters Slave mode.
9094 //
9095 //         Inhibit OFF allows the TROF to interrupt the DIS state.
9096 //
9097 //      2. For all other faults and interrupts, the inhibit bit is ignored.
9098 //
9099 //      3. The use of this instruction in the Slave or Master mode causes a
9100 //         Command fault.
9101 
9102           disDiagEnter (cpup);
9103           if (sample_interrupts (cpup))
9104             {
9105               disDiagWake (cpup);
9106               sim_debug (DBG_TRACEEXT, & cpu_dev, "DIS sees an interrupt\r\n");
9107               cpu.interrupt_flag = true;
9108               if (cpu.tweaks.tandd_mode) // see FETCH_cycle
9109                 {
9110                   cpu.disEnded   = true;
9111                   cpu.disInhibit = GET_I (cpu.cu.IWB);
9112                 }
9113               break;
9114             }
9115           // EXECUTE DATA SWITCHES: see FETCH_cycle
9116           if (cpu.execSwitchesReq)
9117             break;
9118 // Implementing TRO according to AL39 for the DIS cause the idle systems to
9119 // hang in the DIS instruction. Revert back to the old behavior.
9120 
9121           // AL39 (Timer Register): if the processor "is stopped at an
9122           // uninhibited Delay Until Interrupt Signal (dis) instruction,
9123           // the fault occurs immediately": a timer runout is taken AT the
9124           // DIS, with PPR.IC still on it (PM894 06D: the fault pair's stc1
9125           // must store DIS + 1), not after the DIS completes. Connect
9126           // faults and interrupts still end the DIS as before.
9127           if (! GET_I (cpu.cu.IWB))
9128             {
9129 # if defined(THREADZ) || defined(LOCKLESS)
9130               lock_scu ();
9131 # endif
9132               bool tro = (cpu.g7Faults & (1u << FAULT_TRO)) &&
9133                          ! (cpu.g7Faults & (1u << FAULT_CON));
9134               if (tro)
9135                 cpu.g7Faults &= ~(1u << FAULT_TRO);
9136 # if defined(THREADZ) || defined(LOCKLESS)
9137               unlock_scu ();
9138 # endif
9139               if (tro)
9140                 {
9141                   disDiagWake (cpup);
9142                   sim_debug (DBG_TRACEEXT, & cpu_dev, "DIS takes a TRO\r\n");
9143                   doFault (FAULT_TRO, fst_zero, "Timer runout at DIS");
9144                 }
9145             }
9146           if (GET_I (cpu.cu.IWB) ? bG7PendingNoTRO (cpup) : bG7Pending (cpup))
9147 
9148 
9149 
9150 
9151 
9152 
9153 
9154 
9155             {
9156               sim_debug (DBG_TRACEEXT, & cpu_dev, "DIS sees a TRO\r\n");
9157               cpu.g7_flag    = true;
9158               if (cpu.tweaks.tandd_mode) // see FETCH_cycle
9159                 {
9160                   cpu.disEnded   = true;
9161                   cpu.disInhibit = GET_I (cpu.cu.IWB);
9162                 }
9163               break;
9164             }
9165           else
9166             {
9167               sim_debug (DBG_TRACEEXT, & cpu_dev, "DIS refetches\r\n");
9168               return CONT_DIS;
9169             }
9170 
9171         /// POINTER REGISTER INSTRUCTIONS
9172 
9173         /// PRIVILEGED INSTRUCTIONS
9174 
9175         /// Privileged - Register Load
9176 
9177         /// Privileged - Clear Associative Memory
9178 
9179         /// EIS - Address Register Load
9180 
9181                          // aarn
9182         case x1 (0560):  // aar0
9183         case x1 (0561):  // aar1
9184         case x1 (0562):  // aar2
9185         case x1 (0563):  // aar3
9186         case x1 (0564):  // aar4
9187         case x1 (0565):  // aar5
9188         case x1 (0566):  // aar6
9189         case x1 (0567):  // aar7
9190           {
9191             // For n = 0, 1, ..., or 7 as determined by operation code
9192             PNL (L68_ (DU_CYCLE_DDU_LDEA;))
9193 
9194             if (getbits36_1 (cpu.CY, 23) != 0)
9195               doFault (FAULT_IPR,
9196                        fst_ill_proc,
9197                        "aarn C(Y)23 != 0");
9198 
9199             uint32 n = opcode10 & 07;  // get
9200             CPTUR (cptUsePRn + n);
9201 
9202             // C(Y)0,17 -> C(ARn.WORDNO)
9203             cpu.AR[n].WORDNO = GETHI (cpu.CY);
9204 
9205             uint TA = getbits36_2 (cpu.CY, 21);
9206             uint CN = getbits36_3 (cpu.CY, 18);
9207 
9208             switch (TA)
9209               {
9210                 case CTA4:  // 2
9211                   // If C(Y)21,22 = 10 (TA code = 2), then
9212                   //   C(Y)18,20 / 2 -> C(ARn.CHAR)
9213                   //   4 * (C(Y)18,20)mod2 + 1 -> C(ARn.BITNO)
9214 
9215                   // According to AL39, CN is translated:
9216                   //  CN   CHAR  BIT
9217                   //   0      0    1
9218                   //   1      0    5
9219                   //   2      1    1
9220                   //   3      1    5
9221                   //   4      2    1
9222                   //   5      2    5
9223                   //   6      3    1
9224                   //   7      3    5
9225                   //SET_AR_CHAR_BITNO (n, CN/2, 4 * (CN % 2) + 1);
9226 
9227                   // According to ISOLTS ps805
9228                   //  CN   CHAR  BIT
9229                   //   0      0    0
9230                   //   1      0    5
9231                   //   2      1    0
9232                   //   3      1    5
9233                   //   4      2    0
9234                   //   5      2    5
9235                   //   6      3    0
9236                   //   7      3    5
9237                   SET_AR_CHAR_BITNO (n, (word2) (CN/2), (CN % 2) ? 5 : 0);
9238 
9239                   break;
9240 
9241                 case CTA6:  // 1
9242                   // If C(Y)21,22 = 01 (TA code = 1) and C(Y)18,20 = 110
9243                   // or 111 an illegal procedure fault occurs.
9244                   if (CN > 5)
9245                     {
9246                       cpu.AR[n].WORDNO = 0;
9247                       SET_AR_CHAR_BITNO (n, 0, 0);
9248                       doFault (FAULT_IPR, fst_ill_proc, "aarn TN > 5");
9249                     }
9250 
9251                   // If C(Y)21,22 = 01 (TA code = 1), then
9252                   //   (6 * C(Y)18,20) / 9 -> C(ARn.CHAR)
9253                   //   (6 * C(Y)18,20)mod9 -> C(ARn.BITNO)
9254                   SET_AR_CHAR_BITNO (n, (word2) ((6 * CN) / 9),
9255                                      (6 * CN) % 9);
9256                   break;
9257 
9258                 case CTA9:  // 0
9259                   // If C(Y)21,22 = 00 (TA code = 0), then
9260                   //   C(Y)18,19 -> C(ARn.CHAR)
9261                   //   0000 -> C(ARn.BITNO)
9262                   // remember, 9-bit CN's are funky
9263                   SET_AR_CHAR_BITNO (n, (word2) (CN >> 1), 0);
9264                   break;
9265 
9266                 case CTAILL: // 3
9267                   // If C(Y)21,22 = 11 (TA code = 3) an illegal procedure
9268                   // fault occurs.
9269                   cpu.AR[n].WORDNO = 0;
9270                   SET_AR_CHAR_BITNO (n, 0, 0);
9271 #if defined(TESTING)
9272                   HDBGRegARW (n, "aarn");
9273 #endif
9274                   doFault (FAULT_IPR, fst_ill_proc, "aarn TA = 3");
9275               }
9276 #if defined(TESTING)
9277             HDBGRegARW (n, "aarn");
9278 #endif
9279           }
9280           break;
9281 
9282         // Load Address Register n
9283                         // larn
9284         case x1 (0760): // lar0
9285         case x1 (0761): // lar1
9286         case x1 (0762): // lar2
9287         case x1 (0763): // lar3
9288         case x1 (0764): // lar4
9289         case x1 (0765): // lar5
9290         case x1 (0766): // lar6
9291         case x1 (0767): // lar7
9292           {
9293             // For n = 0, 1, ..., or 7 as determined by operation code
9294             //    C(Y)0,23 -> C(ARn)
9295             PNL (L68_ (DU_CYCLE_DDU_LDEA;))
9296 
9297             uint32 n = opcode10 & 07;  // get n
9298             CPTUR (cptUsePRn + n);
9299             cpu.AR[n].WORDNO = GETHI (cpu.CY);
9300 // AL-38 implies CHAR/BITNO, but ISOLTS requires PR.BITNO.
9301             SET_AR_CHAR_BITNO (n,  getbits36_2 (cpu.CY, 18),
9302                                getbits36_4 (cpu.CY, 20));
9303 #if defined(TESTING)
9304             HDBGRegARW (n, "larn");
9305 #endif
9306           }
9307           break;
9308 
9309         // lareg - Load Address Registers
9310 
9311         case x1 (0463):  // lareg
9312           PNL (L68_ (DU_CYCLE_DDU_LDEA;))
9313 
9314           for (uint32 n = 0 ; n < 8 ; n += 1)
9315             {
9316               CPTUR (cptUsePRn + n);
9317               word36 tmp36 = cpu.Yblock8[n];
9318               cpu.AR[n].WORDNO = getbits36_18 (tmp36, 0);
9319               SET_AR_CHAR_BITNO (n,  getbits36_2 (tmp36, 18),
9320                                  getbits36_4 (tmp36, 20));
9321 #if defined(TESTING)
9322               HDBGRegARW (n, "lareg");
9323 #endif
9324             }
9325           break;
9326 
9327         // lpl - Load Pointers and Lengths
9328 
9329         case x1 (0467):  // lpl
9330           PNL (L68_ (DU_CYCLE_DDU_LDEA;))
9331           words2du (cpup, cpu.Yblock8);
9332           break;
9333 
9334         // narn -  (G'Kar?) Numeric Descriptor to Address Register n
9335                         // narn
9336         case x1 (0660): // nar0
9337         case x1 (0661): // nar1
9338         case x1 (0662): // nar2
9339         case x1 (0663): // nar3
9340         case x1 (0664): // nar4
9341         case x1 (0665): // nar5
9342         case x1 (0666): // nar6 beware!!!! :-)
9343         case x1 (0667): // nar7
9344           {
9345             // For n = 0, 1, ..., or 7 as determined by operation code
9346             PNL (L68_ (DU_CYCLE_DDU_LDEA;))
9347 
9348             uint32 n = opcode10 & 07;  // get
9349             CPTUR (cptUsePRn + n);
9350 
9351             // C(Y)0,17 -> C(ARn.WORDNO)
9352             cpu.AR[n].WORDNO = GETHI (cpu.CY);
9353 
9354             uint TN = getbits36_1 (cpu.CY, 21); // C(Y) 21
9355             uint CN = getbits36_3 (cpu.CY, 18); // C(Y) 18-20
9356 
9357             switch(TN)
9358               {
9359                 case CTN4:   // 1
9360                     // If C(Y)21 = 1 (TN code = 1), then
9361                     //   (C(Y)18,20) / 2 -> C(ARn.CHAR)
9362                     //   4 * (C(Y)18,20)mod2 + 1 -> C(ARn.BITNO)
9363 
9364                     // According to AL39, CN is translated:
9365                     //  CN   CHAR  BIT
9366                     //   0      0    1
9367                     //   1      0    5
9368                     //   2      1    1
9369                     //   3      1    5
9370                     //   4      2    1
9371                     //   5      2    5
9372                     //   6      3    1
9373                     //   7      3    5
9374                     //SET_AR_CHAR_BITNO (n, CN/2, 4 * (CN % 2) + 1);
9375 
9376                     // According to ISOLTS ps805
9377                     //  CN   CHAR  BIT
9378                     //   0      0    0
9379                     //   1      0    5
9380                     //   2      1    0
9381                     //   3      1    5
9382                     //   4      2    0
9383                     //   5      2    5
9384                     //   6      3    0
9385                     //   7      3    5
9386                     SET_AR_CHAR_BITNO (n, (word2) (CN/2), (CN % 2) ? 5 : 0);
9387 
9388                     break;
9389 
9390                 case CTN9:  // 0
9391                   // If C(Y)21 = 0 (TN code = 0) and C(Y)20 = 1 an
9392                   // illegal procedure fault occurs.
9393                   if ((CN & 1) != 0)
9394                     doFault (FAULT_IPR, fst_ill_proc, "narn N9 and CN odd");
9395                   // The character number is in bits 18-19; recover it
9396                   CN >>= 1;
9397                   // If C(Y)21 = 0 (TN code = 0), then
9398                   //   C(Y)18,20 -> C(ARn.CHAR)
9399                   //   0000 -> C(ARn.BITNO)
9400                   SET_AR_CHAR_BITNO (n, (word2) CN, 0);
9401                   break;
9402               }
9403 #if defined(TESTING)
9404             HDBGRegARW (n, "narn");
9405 #endif
9406           }
9407           break;
9408 
9409         /// EIS - Address Register Store
9410 
9411         // aran Address Register n to Alphanumeric Descriptor
9412 
9413                         // aran
9414         case x1 (0540): // ara0
9415         case x1 (0541): // ara1
9416         case x1 (0542): // ara2
9417         case x1 (0543): // ara3
9418         case x1 (0544): // ara4
9419         case x1 (0545): // ara5
9420         case x1 (0546): // ara6
9421         case x1 (0547): // ara7
9422             {
9423                 // The alphanumeric descriptor is fetched from Y and C(Y)21,22
9424                 // (TA field) is examined to determine the data type described.
9425                 PNL (L68_ (DU_CYCLE_DDU_STEA;))
9426 
9427                 uint TA = getbits36_2 (cpu.CY, 21);
9428 
9429                 // If C(Y)21,22 = 11 (TA code = 3) or C(Y)23 = 1 (unused bit),
9430                 // an illegal procedure fault occurs.
9431                 if (TA == 03) {
9432                   dlyDoFault (FAULT_IPR, fst_ill_proc, "ARAn tag == 3");
9433                   break;
9434                 }
9435                 if (getbits36_1 (cpu.CY, 23) != 0) {
9436                   dlyDoFault (FAULT_IPR, fst_ill_proc, "ARAn b23 == 1");
9437                   break;
9438                 }
9439 
9440                 uint32 n = opcode10 & 07;  // get
9441                 CPTUR (cptUsePRn + n);
9442                 // For n = 0, 1, ..., or 7 as determined by operation code
9443 
9444                 // C(ARn.WORDNO) -> C(Y)0,17
9445                 putbits36_18 (& cpu.CY, 0, cpu.AR[n].WORDNO & MASK18);
9446 
9447                 // If TA = 1 (6-bit data) or TA = 2 (4-bit data), C(ARn.CHAR)
9448                 // and C(ARn.BITNO) are translated to an equivalent character
9449                 // position that goes to C(Y)18,20.
9450 
9451                 int CN = 0;
9452 
9453                 switch (TA)
9454                 {
9455                     case CTA4:  // 2
9456                         // If C(Y)21,22 = 10 (TA code = 2), then
9457                         // (9 * C(ARn.CHAR) + C(ARn.BITNO) - 1) / 4 -> C(Y)18,20
9458                         // As for arnn: the digit holding the bit (see there).
9459                         CN = (int) (2 * GET_AR_CHAR (n) +
9460                                     (GET_AR_BITNO (n) >= 5 ? 1 : 0));
9461                         putbits36_3 (& cpu.CY, 18, (word3) CN & MASK3);
9462                         break;
9463 
9464                     case CTA6:  // 1
9465                         // If C(Y)21,22 = 01 (TA code = 1), then
9466                         // (9 * C(ARn.CHAR) + C(ARn.BITNO)) / 6 -> C(Y)18,20
9467                         // An AR BITNO of 9-15 (LAREG) counts as 8 (ISOLTS
9468                         // PS905 ara0: CHAR 2 BITNO 016 s/b CN 4, not 5; as
9469                         // for EIS operands, pas.905 L34325)
9470                         CN = (9 * GET_AR_CHAR (n) +
9471                               min (GET_AR_BITNO (n), 8)) / 6;
9472                         putbits36_3 (& cpu.CY, 18, (word3) CN & MASK3);
9473                         break;
9474 
9475                     case CTA9:  // 0
9476                         // If C(Y)21,22 = 00 (TA code = 0), then
9477                         //   C(ARn.CHAR) -> C(Y)18,19
9478                         //   0 -> C(Y)20
9479                         putbits36_3 (& cpu.CY, 18,
9480                                      (word3) ((GET_AR_CHAR (n) & MASK2) << 1));
9481                         break;
9482                 }
9483               cpu.zone = 0777777700000;
9484               cpu.useZone = true;
9485             }
9486             break;
9487 
9488         // arnn Address Register n to Numeric Descriptor
9489 
9490                         // arnn
9491         case x1 (0640): // arn0
9492         case x1 (0641): // arn1
9493         case x1 (0642): // arn2
9494         case x1 (0643): // arn3
9495         case x1 (0644): // arn4
9496         case x1 (0645): // arn5
9497         case x1 (0646): // arn6
9498         case x1 (0647): // arn7
9499             {
9500                 PNL (L68_ (DU_CYCLE_DDU_STEA;))
9501                 uint32 n = opcode10 & 07;  // get register #
9502                 CPTUR (cptUsePRn + n);
9503 
9504                 // The Numeric descriptor is fetched from Y and C(Y)21,22 (TA
9505                 // field) is examined to determine the data type described.
9506 
9507                 uint TN = getbits36_1 (cpu.CY, 21); // C(Y) 21
9508 
9509                 // For n = 0, 1, ..., or 7 as determined by operation code
9510                 // C(ARn.WORDNO) -> C(Y)0,17
9511                 putbits36_18 (& cpu.CY, 0, cpu.AR[n].WORDNO & MASK18);
9512 
9513                 switch (TN)
9514                 {
9515                     case CTN4:  // 1
9516                       {
9517                         // AL39: If C(Y)21 = 1 (TN code = 1) then
9518                         //   (9 * C(ARn.CHAR) + C(ARn.BITNO) - 1) / 4 ->
9519                         //     C(Y)18,20
9520                         // That treats the word as a linear bit string, but
9521                         // a 9-bit character holds a pad bit and two 4-bit
9522                         // digits (bits 1-4 and 5-8), so CN is the digit
9523                         // holding the addressed bit: 2 * CHAR, plus 1 for
9524                         // BITNO 5-8.  ISOLTS PS905 (ARN0, CHAR 2, BITNO 4)
9525                         // expects 4, where the AL39 formula gives 5.
9526                         word3 CN = (word3) (2 * GET_AR_CHAR (n) +
9527                                             (GET_AR_BITNO (n) >= 5 ? 1 : 0));
9528                         putbits36_3 (& cpu.CY, 18, CN & MASK3);
9529                         break;
9530                       }
9531                     case CTN9:  // 0
9532                         // If C(Y)21 = 0 (TN code = 0), then
9533                         //   C(ARn.CHAR) -> C(Y)18,19
9534                         //   0 -> C(Y)20
9535                         putbits36_3 (& cpu.CY, 18,
9536                                      (word3) ((GET_AR_CHAR (n) & MASK2) << 1));
9537                         break;
9538                 }
9539               cpu.zone = 0777777700000;
9540               cpu.useZone = true;
9541             }
9542             break;
9543 
9544         // sarn Store Address Register n
9545 
9546                         // sarn
9547         case x1 (0740): // sar0
9548         case x1 (0741): // sar1
9549         case x1 (0742): // sar2
9550         case x1 (0743): // sar3
9551         case x1 (0744): // sar4
9552         case x1 (0745): // sar5
9553         case x1 (0746): // sar6
9554         case x1 (0747): // sar7
9555             //For n = 0, 1, ..., or 7 as determined by operation code
9556             //  C(ARn) -> C(Y)0,23
9557             //  C(Y)24,35 -> unchanged
9558             {
9559                 PNL (L68_ (DU_CYCLE_DDU_STEA;))
9560                 uint32 n = opcode10 & 07;  // get n
9561                 CPTUR (cptUsePRn + n);
9562                 putbits36 (& cpu.CY,  0, 18, cpu.PR[n].WORDNO);
9563 // AL-39 implies CHAR/BITNO, but ISOLTS test 805 requires BITNO
9564                 putbits36 (& cpu.CY, 18, 2, GET_AR_CHAR (n));
9565                 putbits36 (& cpu.CY, 20, 4, GET_AR_BITNO (n));
9566                 //putbits36 (& cpu.CY, 18, 6, GET_PR_BITNO (n));
9567                 cpu.zone = 0777777770000;
9568                 cpu.useZone = true;
9569             }
9570           break;
9571 
9572         // sareg Store Address Registers
9573 
9574         case x1 (0443):  // sareg
9575             // a:AL39/ar1 According to ISOLTS ps805, the BITNO data is stored
9576             // in BITNO format, not CHAR/BITNO.
9577             PNL (L68_ (DU_CYCLE_DDU_STEA;))
9578             (void)memset (cpu.Yblock8, 0, sizeof (cpu.Yblock8));
9579             for (uint32 n = 0 ; n < 8 ; n += 1)
9580             {
9581                 CPTUR (cptUsePRn + n);
9582                 word36 arx = 0;
9583                 putbits36 (& arx,  0, 18, cpu.PR[n].WORDNO);
9584                 putbits36 (& arx, 18,  2, GET_AR_CHAR (n));
9585                 putbits36 (& arx, 20,  4, GET_AR_BITNO (n));
9586                 cpu.Yblock8[n] = arx;
9587             }
9588             break;
9589 
9590         // spl Store Pointers and Lengths
9591 
9592         case x1 (0447):  // spl
9593             PNL (L68_ (DU_CYCLE_DDU_STEA;))
9594             du2words (cpup, cpu.Yblock8);
9595           break;
9596 
9597         /// EIS - Address Register Special Arithmetic
9598 
9599         // a4bd Add 4-bit Displacement to Address Register 5
9600 
9601         case x1 (0502):  // a4bd
9602           asxbd (cpup, 4, false);
9603           break;
9604 
9605         // a6bd Add 6-bit Displacement to Address Register
9606 
9607         case x1 (0501):  // a6bd
9608           asxbd (cpup, 6, false);
9609           break;
9610 
9611         // a9bd Add 9-bit Displacement to Address Register
9612 
9613         case x1 (0500):  // a9bd
9614           asxbd (cpup, 9, false);
9615           break;
9616 
9617         // abd Add Bit Displacement to Address Register
9618 
9619         case x1 (0503):  // abd
9620           asxbd (cpup, 1, false);
9621           break;
9622 
9623         // awd Add Word Displacement to Address Register
9624 
9625         case x1 (0507):  // awd
9626           asxbd (cpup, 36, false);
9627           break;
9628 
9629         // s4bd Subtract 4-bit Displacement from Address Register
9630 
9631         case x1 (0522):  // s4bd
9632           asxbd (cpup, 4, true);
9633           break;
9634 
9635         // s6bd Subtract 6-bit Displacement from Address Register
9636 
9637         case x1 (0521):  // s6bd
9638           asxbd (cpup, 6, true);
9639           break;
9640 
9641         // s9bd Subtract 9-bit Displacement from Address Register
9642 
9643         case x1 (0520):  // s9bd
9644           asxbd (cpup, 9, true);
9645           break;
9646 
9647         // sbd Subtract Bit Displacement from Address Register
9648 
9649         case x1 (0523):  // sbd
9650           asxbd (cpup, 1, true);
9651           break;
9652 
9653         // swd Subtract Word Displacement from Address Register
9654 
9655         case x1 (0527):  // swd
9656           asxbd (cpup, 36, true);
9657           break;
9658 
9659         /// EIS = Alphanumeric Compare
9660 
9661         case x1 (0106):  // cmpc
9662           cmpc (cpup);
9663           break;
9664 
9665         case x1 (0120):  // scd
9666           scd (cpup);
9667           break;
9668 
9669         case x1 (0121):  // scdr
9670           scdr (cpup);
9671           break;
9672 
9673         case x1 (0124):  // scm
9674           scm (cpup);
9675           break;
9676 
9677         case x1 (0125):  // scmr
9678           scmr (cpup);
9679           break;
9680 
9681         case x1 (0164):  // tct
9682           tct (cpup);
9683           break;
9684 
9685         case x1 (0165):  // tctr
9686           tctr (cpup);
9687           break;
9688 
9689         /// EIS - Alphanumeric Move
9690 
9691         case x1 (0100):  // mlr
9692           mlr (cpup);
9693           break;
9694 
9695         case x1 (0101):  // mrl
9696           mrl (cpup);
9697           break;
9698 
9699         case x1 (0020):  // mve
9700           mve (cpup);
9701           break;
9702 
9703         case x1 (0160):  // mvt
9704           mvt (cpup);
9705           break;
9706 
9707         /// EIS - Numeric Compare
9708 
9709         case x1 (0303):  // cmpn
9710           cmpn (cpup);
9711           break;
9712 
9713         /// EIS - Numeric Move
9714 
9715         case x1 (0300):  // mvn
9716           mvn (cpup);
9717           break;
9718 
9719         case x1 (0024):   // mvne
9720           mvne (cpup);
9721           break;
9722 
9723         /// EIS - Bit String Combine
9724 
9725         case x1 (0060):   // csl
9726           csl (cpup);
9727           break;
9728 
9729         case x1 (0061):   // csr
9730           csr (cpup);
9731           break;
9732 
9733         /// EIS - Bit String Compare
9734 
9735         case x1 (0066):   // cmpb
9736           cmpb (cpup);
9737           break;
9738 
9739         /// EIS - Bit String Set Indicators
9740 
9741         case x1 (0064):   // sztl
9742           // The execution of this instruction is identical to the Combine
9743           // Bit Strings Left (csl) instruction except that C(BOLR)m is
9744           // not placed into C(Y-bit2)i-1.
9745           sztl (cpup);
9746           break;
9747 
9748         case x1 (0065):   // sztr
9749           // The execution of this instruction is identical to the Combine
9750           // Bit Strings Left (csr) instruction except that C(BOLR)m is
9751           // not placed into C(Y-bit2)i-1.
9752           sztr (cpup);
9753           break;
9754 
9755         /// EIS -- Data Conversion
9756 
9757         case x1 (0301):  // btd
9758           btd (cpup);
9759           break;
9760 
9761         case x1 (0305):  // dtb
9762           dtb (cpup);
9763           break;
9764 
9765         /// EIS - Decimal Addition
9766 
9767         case x1 (0202):  // ad2d
9768             ad2d (cpup);
9769             break;
9770 
9771         case x1 (0222):  // ad3d
9772             ad3d (cpup);
9773             break;
9774 
9775         /// EIS - Decimal Subtraction
9776 
9777         case x1 (0203):  // sb2d
9778             sb2d (cpup);
9779             break;
9780 
9781         case x1 (0223):  // sb3d
9782             sb3d (cpup);
9783             break;
9784 
9785         /// EIS - Decimal Multiplication
9786 
9787         case x1 (0206):  // mp2d
9788             mp2d (cpup);
9789             break;
9790 
9791         case x1 (0226):  // mp3d
9792             mp3d (cpup);
9793             break;
9794 
9795         /// EIS - Decimal Division
9796 
9797         case x1 (0207):  // dv2d
9798             dv2d (cpup);
9799             break;
9800 
9801         case x1 (0227):  // dv3d
9802             dv3d (cpup);
9803             break;
9804 
9805         case x1 (0420):  // emcall instruction Custom, for an emulator call for scp
9806         {
9807             if (cpu.tweaks.enable_emcall) {
9808               int ret = emCall (cpup);
9809               if (ret)
9810                 return ret;
9811               break;
9812             }
9813             goto unimp;
9814         }
9815 
9816         default:
9817         unimp:
9818           if (cpu.tweaks.halt_on_unimp)
9819             return STOP_STOP;
9820           doFault (FAULT_IPR,
9821                    fst_ill_op,
9822                    "Illegal instruction");
9823       }
9824     L68_ (
9825       cpu.ou.STR_OP = (is_ou && (i->info->flags & (STORE_OPERAND | STORE_YPAIR))) ? 1 : 0;
9826       cpu.ou.cycle |= ou_GOF;
9827       if (cpu.MR_cache.emr && cpu.MR_cache.ihr && is_ou)
9828         add_l68_OU_history (cpup);
9829       if (cpu.MR_cache.emr && cpu.MR_cache.ihr && is_du)
9830         add_l68_DU_history (cpup);
9831     )
9832     return SCPE_OK;
9833 }
9834 
9835 #include <ctype.h>
9836 #include <time.h>
9837 
9838 /*
9839  * emulator call instruction. Do whatever address field sez' ....
9840  */
9841 
9842 //static clockid_t clockID;
9843 //static struct timespec startTime;
9844 static uv_rusage_t startTime;
9845 static unsigned long long startInstrCnt;
9846 
9847 static int emCall (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
9848 {
9849 #if defined(THREADZ) || defined(LOCKLESS)
9850     atomic_thread_fence (memory_order_seq_cst);
9851 #endif /* defined(THREADZ) || defined(LOCKLESS) */
9852 
9853     DCDstruct * i = & cpu.currentInstruction;
9854 
9855 // The address is absolute address of a structure consisting of a
9856 // operation code word and optional following words containing
9857 // data for the operation.
9858 
9859    word36 op = M[i->address];
9860    switch (op)
9861      {
9862        // OP 1: Print the unsigned decimal representation of the first data
9863        //       word.
9864        case 1:
9865          sim_printf ("%lld\r\n", (long long int) M[i->address+1]);
9866          break;
9867 
9868        // OP 2: Halt the simulation
9869        case 2:
9870 #if defined(LOCKLESS)
9871          bce_dis_called = true;
9872 #endif
9873          return STOP_STOP;
9874 
9875 #define UV_VERSION(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
9876 
9877        // OP 3: Start CPU clock
9878        case 3:
9879          startInstrCnt = cpu.instrCnt;
9880          uv_getrusage (& startTime);
9881 #if UV_VERSION_HEX >= UV_VERSION(1, 50, 0)
9882          if (uv_getrusage_thread(& startTime) == UV_ENOTSUP) {
9883            uv_getrusage (& startTime);
9884          }
9885 #else
9886          uv_getrusage (& startTime);
9887 #endif
9888          break;
9889 
9890        // OP 4: Report CPU clock
9891        case 4:
9892          {
9893 #define ns_sec  (1000000000L)
9894 #define ns_msec (1000000000L / 1000L)
9895 #define ns_usec (1000000000L / 1000L / 1000L)
9896            uv_rusage_t now;
9897 #if UV_VERSION_HEX >= UV_VERSION(1, 50, 0)
9898            if (uv_getrusage_thread(& now) == UV_ENOTSUP) {
9899              uv_getrusage (& now);
9900            }
9901 #else
9902            uv_getrusage (& now);
9903 #endif
9904            uint64_t u_start          = (uint64_t)((uint64_t)(startTime.ru_utime.tv_usec * 1000ULL) +
9905                                                   (uint64_t)(startTime.ru_utime.tv_sec * (uint64_t)ns_sec));
9906            uint64_t s_start          = (uint64_t)((uint64_t)(startTime.ru_stime.tv_usec * 1000ULL) +
9907                                                   (uint64_t)(startTime.ru_stime.tv_sec * (uint64_t)ns_sec));
9908            uint64_t u_stop           = (uint64_t)((uint64_t)(now.ru_utime.tv_usec * 1000ULL) +
9909                                                   (uint64_t)(now.ru_utime.tv_sec * (uint64_t)ns_sec));
9910            uint64_t s_stop           = (uint64_t)((uint64_t)(now.ru_stime.tv_usec * 1000ULL) +
9911                                                   (uint64_t)(now.ru_stime.tv_sec * (uint64_t)ns_sec));
9912            uint64_t u_delta          = u_stop - u_start;
9913            uint64_t s_delta          = s_stop - s_start;
9914            uint64_t u_seconds        = u_delta / ns_sec;
9915            uint64_t s_seconds        = s_delta / ns_sec;
9916            uint64_t u_milliseconds   = (u_delta / ns_msec) % 1000ULL;
9917            uint64_t s_milliseconds   = (s_delta / ns_msec) % 1000ULL;
9918            uint64_t u_microseconds   = (u_delta / ns_usec) % 1000ULL;
9919            uint64_t s_microseconds   = (s_delta / ns_usec) % 1000ULL;
9920            unsigned long long nInsts = (unsigned long long)((unsigned long long)cpu.instrCnt -
9921                                                             (unsigned long long)startInstrCnt);
9922            double u_secs             = (double)(((long double) u_delta) / ((long double) ns_sec));
9923            double s_secs             = (double)(((long double) s_delta) / ((long double) ns_sec));
9924            long double ips           = (long double)(((long double) nInsts) /
9925                                                     (((long double) u_secs) + ((long double) s_secs)));
9926            long double mips          = (long double)(ips / 1000000.0L);
9927 
9928            struct tm tm = {0};
9929            char elapsed_time[64];
9930 
9931            tm.tm_hour = u_seconds / 3600;
9932            tm.tm_min = (u_seconds % 3600) / 60;
9933            tm.tm_sec = u_seconds % 60;
9934            strftime(elapsed_time, sizeof(elapsed_time), "%H:%M:%S", &tm);
9935 
9936            sim_printf ("\rUser time elapsed  : %s.%03llu%03llu\r\n",
9937                        elapsed_time, (unsigned long long)u_milliseconds, (unsigned long long)u_microseconds);
9938 
9939            tm.tm_hour = s_seconds / 3600;
9940            tm.tm_min = (s_seconds % 3600) / 60;
9941            tm.tm_sec = s_seconds % 60;
9942            strftime(elapsed_time, sizeof(elapsed_time), "%H:%M:%S", &tm);
9943 
9944            sim_printf ("\rSystem time elapsed: %s.%03llu%03llu\r\n",
9945                        elapsed_time, (unsigned long long)s_milliseconds, (unsigned long long)s_microseconds);
9946 #if defined(WIN_STDIO)
9947            sim_printf ("\rInstructions       : %llu\r\n", (unsigned long long) nInsts);
9948            sim_printf ("\rPerformance        : %f MIPS\r\n\r\n", (double) mips);
9949 #else
9950            sim_printf ("\rInstructions       : %'llu\r\n", (unsigned long long) nInsts);
9951            sim_printf ("\rPerformance        : %'f MIPS\r\n", (double) mips);
9952 #endif /* if defined(WIN_STDIO) */
9953            break;
9954          }
9955        default:
9956          sim_printf ("emcall unknown op %llo\r\n", (unsigned long long)op);
9957       }
9958     return 0;
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 // CANFAULT
10153 // T&D: for sscr/rscr addressed through the appending unit, the CPU port
10154 // whose window (port assignment and store size switches) holds the final
10155 // absolute address. False if not appended or on no port.
10156 static bool scr_port_from_final_address (cpu_state_t * cpup, uint * portp)
     /* [previous][next][first][last][top][bottom][index][help] */
10157   {
10158     if (get_addr_mode (cpup) == ABSOLUTE_mode && ! (cpu.cu.XSF || cpu.currentInstruction.b29))
10159       return false;
10160     word24 final_address = doAppendCycleABSA (cpup, NULL, 0);
10161     uint dps8m_store_table [8] =
10162       { 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304 };
10163     uint l68_store_table [8] =
10164       { 32768, 65536, 4194304, 131072, 524288, 1048576, 2097152, 262144 };
10165     int n_ports = cpu.tweaks.l68_mode ? N_L68_CPU_PORTS : N_DPS8M_CPU_PORTS;
10166     for (int port_num = 0; port_num < n_ports; port_num ++)
10167       {
10168         if (! cpu.switches.enable [port_num] ||
10169             ! cables->cpu_to_scu[current_running_cpu_idx][port_num].in_use)
10170           continue;
10171         uint store_size = cpu.switches.store_size [port_num];
10172         uint sz_wds = cpu.tweaks.l68_mode ? l68_store_table [store_size] :
10173                                             dps8m_store_table [store_size];
10174         uint base = sz_wds * cpu.switches.assignment[port_num];
10175         if (final_address >= base && final_address - base < sz_wds)
10176           {
10177             * portp = (uint) port_num;
10178             return true;
10179           }
10180       }
10181     return false;
10182   }
10183 
10184 static int doABSA (cpu_state_t * cpup, word36 * result)
     /* [previous][next][first][last][top][bottom][index][help] */
10185   {
10186     word36 res;
10187     sim_debug (DBG_APPENDING, & cpu_dev, "absa CA:%08o\r\n", cpu.TPR.CA);
10188 
10189     //if (get_addr_mode (cpup) == ABSOLUTE_mode && ! cpu.isb29)
10190     //if (get_addr_mode (cpup) == ABSOLUTE_mode && ! cpu.went_appending) // ISOLTS-860
10191     if (get_addr_mode (cpup) == ABSOLUTE_mode && ! (cpu.cu.XSF || cpu.currentInstruction.b29)) // ISOLTS-860
10192       {
10193         * result = ((word36) (cpu.TPR.CA & MASK18)) << 12; // 24:12 format
10194         return SCPE_OK;
10195       }
10196 
10197     // ABSA handles directed faults differently, so a special append cycle is
10198     // needed.
10199     // do_append_cycle also provides WAM support, which is required by
10200     // ISOLTS-860 02
10201     //   res = (word36) do_append_cycle (cpu.TPR.CA & MASK18, ABSA_CYCLE, NULL,
10202     //                                   0) << 12;
10203     //res = (word36) do_append_cycle (ABSA_CYCLE, NULL, 0) << 12;
10204     res = (word36) doAppendCycleABSA (cpup, NULL, 0) << 12;
10205 
10206     * result = res;
10207 
10208     return SCPE_OK;
10209   }
10210 
10211 void doRCU (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
10212   {
10213 #if defined(LOOPTRC)
10214 elapsedtime ();
10215  sim_printf (" rcu to %05o:%06o  PSR:IC %05o:%06o\r\n",
10216              (cpu.Yblock8[0]>>18)&MASK15, (cpu.Yblock8[4]>>18)&MASK18, cpu.PPR.PSR, cpu.PPR.IC);
10217 #endif
10218 
10219     if_sim_debug (DBG_FAULT, & cpu_dev)
10220       {
10221         dump_words(cpup, cpu.Yblock8);
10222         //for (int i = 0; i < 8; i ++)
10223         //  {
10224         //    sim_debug (DBG_FAULT, & cpu_dev, "RCU %d %012"PRIo64"\r\n", i,
10225         //               cpu.Yblock8[i]);
10226         //  }
10227       }
10228 
10229     words2scu (cpup, cpu.Yblock8);
10230     decode_instruction (cpup, IWB_IRODD, & cpu.currentInstruction);
10231 
10232     // Resuming a repeat after its first repetition: a fault left the Xn
10233     // of the instructions not yet completed as the hardware has them
10234     // (doFault); dps8m's repetition uses Xn already advanced by delta
10235     // (PA885 06D)
10236     if ((cpu.cu.rpt || cpu.cu.rd) && ! cpu.cu.repeat_first)
10237       {
10238         bool icOdd = getbits36_1 (cpu.Yblock8[4], 17);
10239         if (cpu.cu.rpt)
10240           {
10241             uint Xn = (uint) getbits36_3 (cpu.cu.IWB, 36 - 3);
10242             cpu.rX[Xn] = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
10243           }
10244         else
10245           {
10246             if (! icOdd && (cpu.rX[0] & 01000))
10247               {
10248                 uint Xn = (uint) getbits36_3 (cpu.cu.IWB, 36 - 3);
10249                 cpu.rX[Xn] = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
10250               }
10251             if (cpu.rX[0] & 00400)
10252               {
10253                 uint Xn = (uint) getbits36_3 (cpu.cu.IRODD, 36 - 3);
10254                 cpu.rX[Xn] = (cpu.rX[Xn] + cpu.cu.delta) & AMASK;
10255               }
10256           }
10257       }
10258 
10259 // Restore addressing mode
10260 
10261     word1 saveP = cpu.PPR.P; // ISOLTS-870 02m
10262     if (TST_I_ABS == 0)
10263       set_addr_mode (cpup, APPEND_mode);
10264     else
10265       set_addr_mode (cpup, ABSOLUTE_mode);
10266     cpu.PPR.P = saveP;
10267 
10268     if (getbits36_1  (cpu.Yblock8[1], 35) == 0) // cpu.cu.FLT_INT is interrupt, not fault
10269       {
10270         sim_debug (DBG_FAULT, & cpu_dev, "RCU interrupt return\r\n");
10271         longjmp (cpu.jmpMain, JMP_REFETCH);
10272       }
10273 
10274     // Resync the append unit
10275     fauxDoAppendCycle (cpup, INSTRUCTION_FETCH);
10276 
10277 // All of the faults list as having handlers have actually
10278 // been encountered in Multics operation and are believed
10279 // to be being handled correctly. The handlers in
10280 // parenthesis are speculative and untested.
10281 //
10282 // Unhandled:
10283 //
10284 //    SDF Shutdown: Why would you RCU from a shutdown fault?
10285 //    STR Store:
10286 //      AL39 is contradictory or vague about store fault subfaults and store
10287 //      faults in general. They are mentioned:
10288 //        SPRPn: store fault (illegal pointer) (assuming STR:ISN)
10289 //        SMCM: store fault (not control)  -
10290 //        SMIC: store fault (not control)   > I believe that these should be
10291 //        SSCR: store fault (not control)  -  command fault
10292 //        TSS:  STR:OOB
10293 //        Bar mode out-of-bounds: STR:OOB
10294 //     The SCU register doesn't define which bit is "store fault (not control)"
10295 // STR:ISN - illegal segment number
10296 // STR:NEA - nonexistent address
10297 // STR:OOB - bar mode out-of-bounds
10298 //
10299 // decimal   octal
10300 // fault     fault  mnemonic   name             priority group  handler
10301 // number   address
10302 //   0         0      sdf      Shutdown               27 7
10303 //   1         2      str      Store                  10 4                                 get_BAR_address, instruction execution
10304 //   2         4      mme      Master mode entry 1    11 5      JMP_SYNC_FAULT_RETURN      instruction execution
10305 //   3         6      f1       Fault tag 1            17 5      (JMP_REFETCH/JMP_RESTART)  do_caf
10306 //   4        10      tro      Timer runout           26 7      JMP_REFETCH                FETCH_cycle
10307 //   5        12      cmd      Command                 9 4      JMP_REFETCH/JMP_RESTART    instruction execution
10308 //   6        14      drl      Derail                 15 5      JMP_REFETCH/JMP_RESTART    instruction execution
10309 //   7        16      luf      Lockup                  5 4      JMP_REFETCH                do_caf, FETCH_cycle
10310 //   8        20      con      Connect                25 7      JMP_REFETCH                FETCH_cycle
10311 //   9        22      par      Parity                  8 4
10312 //  10        24      ipr      Illegal procedure      16 5                                 doITSITP, do_caf, instruction execution
10313 //  11        26      onc      Operation not complete  4 2                                 nem_check, instruction execution
10314 //  12        30      suf      Startup                 1 1
10315 //  13        32      ofl      Overflow                7 3      JMP_REFETCH/JMP_RESTART    instruction execution
10316 //  14        34      div      Divide check            6 3                                 instruction execution
10317 //  15        36      exf      Execute                 2 1      JMP_REFETCH/JMP_RESTART    FETCH_cycle
10318 //  16        40      df0      Directed fault 0       20 6      JMP_REFETCH/JMP_RESTART    getSDW, do_append_cycle
10319 //  17        42      df1      Directed fault 1       21 6      JMP_REFETCH/JMP_RESTART    getSDW, do_append_cycle
10320 //  18        44      df2      Directed fault 2       22 6      (JMP_REFETCH/JMP_RESTART)  getSDW, do_append_cycle
10321 //  19        46      df3      Directed fault 3       23 6      JMP_REFETCH/JMP_RESTART    getSDW, do_append_cycle
10322 //  20        50      acv      Access violation       24 6      JMP_REFETCH/JMP_RESTART    fetchDSPTW, modifyDSPTW, fetchNSDW,
10323 //                                                                                          do_append_cycle, EXEC_cycle (ring alarm)
10324 //  21        52      mme2     Master mode entry 2    12 5      JMP_SYNC_FAULT_RETURN      instruction execution
10325 //  22        54      mme3     Master mode entry 3    13 5      (JMP_SYNC_FAULT_RETURN)    instruction execution
10326 //  23        56      mme4     Master mode entry 4    14 5      (JMP_SYNC_FAULT_RETURN)    instruction execution
10327 //  24        60      f2       Fault tag 2            18 5      JMP_REFETCH/JMP_RESTART    do_caf
10328 //  25        62      f3       Fault tag 3            19 5      JMP_REFETCH/JMP_RESTART    do_caf
10329 //  26        64               Unassigned
10330 //  27        66               Unassigned
10331 //  28        70               Unassigned
10332 //  29        72               Unassigned
10333 //  30        74               Unassigned
10334 //  31        76      trb      Trouble                 3 2                                  FETCH_cycle, doRCU
10335 
10336 // Reworking logic
10337 
10338 #define rework
10339 #if defined(rework)
10340     if (cpu.cu.FIF) // fault occurred during instruction fetch
10341       {
10342 //if (cpu.cu.rfi) sim_printf ( "RCU FIF refetch return caught rfi\r\n");
10343         // I am misusing this bit; on restart I want a way to tell the
10344         // CPU state machine to restart the instruction, which is not
10345         // how Multics uses it. I need to pick a different way to
10346         // communicate; for now, turn it off on refetch so the state
10347         // machine doesn't become confused.
10348         cpu.cu.rfi = 0;
10349         sim_debug (DBG_FAULT, & cpu_dev, "RCU FIF REFETCH return\r\n");
10350         longjmp (cpu.jmpMain, JMP_REFETCH);
10351       }
10352 
10353 // RFI means 'refetch this instruction'
10354     if (cpu.cu.rfi)
10355       {
10356 //sim_printf ( "RCU rfi refetch return\r\n");
10357         sim_debug (DBG_FAULT, & cpu_dev, "RCU rfi refetch return\r\n");
10358 // Setting the to RESTART causes ISOLTS 776 to report unexpected
10359 // trouble faults.
10360 // Without clearing rfi, ISOLTS pm776-08i LUFs.
10361         cpu.cu.rfi = 0;
10362         longjmp (cpu.jmpMain, JMP_REFETCH);
10363       }
10364 
10365 // The debug command uses MME2 to implement breakpoints, but it is not
10366 // clear what it does to the MC data to signal RFI behavior.
10367 
10368     word5 fi_addr = getbits36_5  (cpu.Yblock8[1], 30);
10369     if (fi_addr == FAULT_MME  ||
10370         fi_addr == FAULT_MME2 ||
10371         fi_addr == FAULT_MME3 ||
10372         fi_addr == FAULT_MME4 ||
10373         fi_addr == FAULT_DRL)
10374     //if (fi_addr == FAULT_MME2)
10375       {
10376 //sim_printf ("MME2 restart\r\n");
10377         sim_debug (DBG_FAULT, & cpu_dev, "RCU MME2 restart return\r\n");
10378         cpu.cu.rfi = 0;
10379         longjmp (cpu.jmpMain, JMP_RESTART);
10380       }
10381 #else
10382     if (cpu.cu.rfi || // S/W asked for the instruction to be started
10383         cpu.cu.FIF)   // fault occurred during instruction fetch
10384       {
10385         // I am misusing this bit; on restart I want a way to tell the
10386         // CPU state machine to restart the instruction, which is not
10387         // how Multics uses it. I need to pick a different way to
10388         // communicate; for now, turn it off on refetch so the state
10389         // machine doesn't become confused.
10390 
10391         cpu.cu.rfi = 0;
10392         sim_debug (DBG_FAULT, & cpu_dev, "RCU rfi/FIF REFETCH return\r\n");
10393         longjmp (cpu.jmpMain, JMP_REFETCH);
10394       }
10395 
10396 // It seems obvious that MMEx should do a JMP_SYNC_FAULT_RETURN, but doing
10397 // a JMP_RESTART makes 'debug' work. (The same change to DRL does not make
10398 // 'gtss' work, tho.
10399 
10400     if (fi_addr == FAULT_MME2)
10401       {
10402 //sim_printf ("MME2 restart\r\n");
10403         sim_debug (DBG_FAULT, & cpu_dev, "RCU MME2 restart return\r\n");
10404         cpu.cu.rfi = 1;
10405         longjmp (cpu.jmpMain, JMP_RESTART);
10406       }
10407 #endif
10408 
10409 
10410 
10411 
10412 
10413 
10414 
10415 
10416 
10417 
10418 
10419 
10420 
10421 
10422 
10423 
10424 
10425 
10426 
10427     // MME faults resume with the next instruction
10428 
10429 #if defined(rework)
10430     // Overflow and divide check: RCU resumes at the saved IC; software
10431     // that wants to go past the instruction adjusts the IC first (PA887:
10432     // the handler adds the dv3d's length). Multics's fim sets rfi+if on
10433     // every overflow, so it takes the FIF refetch above.
10434     if (fi_addr == FAULT_DIV ||
10435         fi_addr == FAULT_OFL)
10436       {
10437         cpu.cu.rfi = 0;
10438         sim_debug (DBG_FAULT, & cpu_dev, "RCU OFL/DIV refetch return\r\n");
10439         longjmp (cpu.jmpMain, JMP_REFETCH);
10440       }
10441     if (fi_addr == FAULT_IPR)
10442       {
10443         sim_debug (DBG_FAULT, & cpu_dev, "RCU sync fault return\r\n");
10444         cpu.cu.rfi = 0;
10445         longjmp (cpu.jmpMain, JMP_SYNC_FAULT_RETURN);
10446       }
10447 #else
10448     if (fi_addr == FAULT_MME  ||
10449      /* fi_addr == FAULT_MME2 || */
10450         fi_addr == FAULT_MME3 ||
10451         fi_addr == FAULT_MME4 ||
10452         fi_addr == FAULT_DRL  ||
10453         fi_addr == FAULT_DIV  ||
10454         fi_addr == FAULT_OFL  ||
10455         fi_addr == FAULT_IPR)
10456       {
10457         sim_debug (DBG_FAULT, & cpu_dev, "RCU MMEx sync fault return\r\n");
10458         cpu.cu.rfi = 0;
10459         longjmp (cpu.jmpMain, JMP_SYNC_FAULT_RETURN);
10460       }
10461 #endif
10462 
10463     // LUF can happen during fetch or CAF. If fetch, handled above
10464     if (fi_addr == FAULT_LUF)
10465       {
10466         cpu.cu.rfi = 1;
10467         sim_debug (DBG_FAULT, & cpu_dev, "RCU LUF RESTART return\r\n");
10468         longjmp (cpu.jmpMain, JMP_RESTART);
10469       }
10470 
10471     if (fi_addr == FAULT_DF0 ||
10472         fi_addr == FAULT_DF1 ||
10473         fi_addr == FAULT_DF2 ||
10474         fi_addr == FAULT_DF3 ||
10475         fi_addr == FAULT_ACV ||
10476         fi_addr == FAULT_F1  ||
10477         fi_addr == FAULT_F2  ||
10478         fi_addr == FAULT_F3  ||
10479         fi_addr == FAULT_CMD ||
10480         fi_addr == FAULT_EXF ||
10481         fi_addr == FAULT_STR ||  // restartable once the cause is fixed (PA885 10B)
10482         // a timer runout or connect taken part way through an
10483         // interruptible EIS instruction (T&D model, PM842); at a fetch
10484         // they are refetches, above (PA887 01B)
10485         fi_addr == FAULT_TRO ||
10486         fi_addr == FAULT_CON)
10487       {
10488         // If the fault occurred during fetch, handled above.
10489         cpu.cu.rfi = 1;
10490         sim_debug (DBG_FAULT, & cpu_dev, "RCU ACV RESTART return\r\n");
10491         longjmp (cpu.jmpMain, JMP_RESTART);
10492       }
10493     sim_printf ("doRCU dies with unhandled fault number %d\r\n", fi_addr);
10494     doFault (FAULT_TRB,
10495              (_fault_subtype) {.bits=fi_addr},
10496              "doRCU dies with unhandled fault number");
10497   }

/* [previous][next][first][last][top][bottom][index][help] */