root/src/dps8/dps8_append.c

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

DEFINITIONS

This source file includes following definitions.
  1. selftest_ptwaw
  2. do_ldbr
  3. fetch_dsptw
  4. modify_dsptw
  5. calc_hit_am
  6. fetch_sdw_from_sdwam
  7. fetch_psdw
  8. fetch_nsdw
  9. str_sdw
  10. dump_sdwam
  11. to_be_discarded_am
  12. load_sdwam
  13. fetch_ptw_from_ptwam
  14. fetch_ptw
  15. loadPTWAM
  16. modify_ptw
  17. do_ptw2
  18. str_access_type
  19. str_acv
  20. str_pct
  21. do_append_cycle
  22. APPEND_CYCLE_COPIES
  23. dbgLookupAddress

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * SPDX-License-Identifier: Multics
   5  * scspell-id: 4bc3e31c-f62d-11ec-bf00-80ee73e9b8e7
   6  *
   7  * ---------------------------------------------------------------------------
   8  *
   9  * Copyright (c) 2012-2016 Harry Reed
  10  * Copyright (c) 2013-2022 Charles Anthony
  11  * Copyright (c) 2017 Michal Tomek
  12  * Copyright (c) 2021-2025 The DPS8M Development Team
  13  *
  14  * This software is made available under the terms of the ICU License.
  15  * See the LICENSE.md file at the top-level directory of this distribution.
  16  *
  17  * ---------------------------------------------------------------------------
  18  *
  19  * This source file may contain code comments that adapt, include, and/or
  20  * incorporate Multics program code and/or documentation distributed under
  21  * the Multics License.  In the event of any discrepancy between code
  22  * comments herein and the original Multics materials, the original Multics
  23  * materials should be considered authoritative unless otherwise noted.
  24  * For more details and historical background, see the LICENSE.md file at
  25  * the top-level directory of this distribution.
  26  *
  27  * ---------------------------------------------------------------------------
  28  */
  29 
  30 #include <stdio.h>
  31 #include "dps8.h"
  32 #include "dps8_sys.h"
  33 #include "dps8_iom.h"
  34 #include "dps8_cable.h"
  35 #include "dps8_cpu.h"
  36 #include "dps8_addrmods.h"
  37 #include "dps8_faults.h"
  38 #include "dps8_scu.h"
  39 #include "dps8_append.h"
  40 #include "dps8_utils.h"
  41 #include "dps8_cache.h"
  42 #if defined(THREADZ) || defined(LOCKLESS)
  43 # include "threadz.h"
  44 #endif
  45 
  46 #define DBG_CTR cpu.cycleCnt
  47 
  48 /*
  49  * The appending unit ...
  50  */
  51 
  52 #if defined(TESTING)
  53 # define DBG_CTR cpu.cycleCnt
  54 # define DBGAPP(...) sim_debug (DBG_APPENDING, & cpu_dev, __VA_ARGS__)
  55 #else
  56 # define DBGAPP(...)
  57 #endif /* if defined(TESTING) */
  58 
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 
  68 
  69 
  70 
  71 
  72 
  73 
  74 
  75 
  76 
  77 
  78 
  79 
  80 
  81 
  82 
  83 
  84 
  85 
  86 
  87 
  88 
  89 
  90 
  91 
  92 
  93 
  94 
  95 
  96 
  97 
  98 
  99 
 100 
 101 
 102 
 103 
 104 
 105 
 106 
 107 
 108 
 109 
 110 
 111 
 112 
 113 
 114 
 115 #if defined(TESTING)
 116 static char *str_sdw (char * buf, sdw_s *SDW);
 117 #endif /* if defined(TESTING) */
 118 
 119 //
 120 //
 121 //  The Use of Bit 29 in the Instruction Word
 122 //  The reader is reminded that there is a preliminary step of loading TPR.CA
 123 //  with the ADDRESS field of the instruction word during instruction decode.
 124 //  If bit 29 of the instruction word is set to 1, modification by pointer
 125 //  register is invoked and the preliminary step is executed as follows:
 126 //  1. The ADDRESS field of the instruction word is interpreted as shown in
 127 //  Figure 6-7 below.
 128 //  2. C(PRn.SNR) -> C(TPR.TSR)
 129 //  3. maximum of ( C(PRn.RNR), C(TPR.TRR), C(PPR.PRR) ) -> C(TPR.TRR)
 130 //  4. C(PRn.WORDNO) + OFFSET -> C(TPR.CA) (NOTE: OFFSET is a signed binary
 131 //  number.)
 132 //  5. C(PRn.BITNO) -> TPR.BITNO
 133 //
 134 
 135 // Define this to do error detection on the PTWAM table.
 136 // Useful if PTWAM reports an error message, but it slows the emulator
 137 // down 50%
 138 
 139 #if defined(do_selftestPTWAM)
 140 static void selftest_ptwaw (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 141   {
 142     int usages[N_NAX_WAM_ENTRIES];
 143     for (int i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
 144       usages[i] = -1;
 145 
 146     for (int i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
 147       {
 148         ptw_s * p = cpu.PTWAM + i;
 149         if (p->USE > N_MODEL_WAM_ENTRIES - 1)
 150           sim_printf ("PTWAM[%d].USE is %d; > %d!\r\n",
 151                       i, p->USE, N_MODEL_WAM_ENTRIES - 1);
 152         if (usages[p->USE] != -1)
 153           sim_printf ("PTWAM[%d].USE is equal to PTWAM[%d].USE; %d\r\n",
 154                       i, usages[p->USE], p->USE);
 155         usages[p->USE] = i;
 156       }
 157     for (int i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
 158       {
 159         if (usages[i] == -1)
 160           sim_printf ("No PTWAM had a USE of %d\r\n", i);
 161       }
 162   }
 163 #endif /* if defined(do_selftestPTWAM) */
 164 
 165 /*
 166  * implement ldbr instruction
 167  */
 168 
 169 void do_ldbr (cpu_state_t * cpup, word36 * Ypair)
     /* [previous][next][first][last][top][bottom][index][help] */
 170   {
 171     CPTUR (cptUseDSBR);
 172     if (cpu.tweaks.enable_wam)
 173       {
 174         if (cpu.cu.SD_ON)
 175           {
 176             // If SDWAM is enabled, then
 177             //   0 -> C(SDWAM(i).FULL) for i = 0, 1, ..., 15
 178             //   i -> C(SDWAM(i).USE) for i = 0, 1, ..., 15
 179             for (uint i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
 180               {
 181                 cpu.SDWAM[i].FE = 0;
 182                 L68_ (cpu.SDWAM[i].USE = (word4) i;)
 183                 DPS8M_ (cpu.SDWAM[i].USE = 0;)
 184               }
 185           }
 186 
 187         if (cpu.cu.PT_ON)
 188           {
 189             // If PTWAM is enabled, then
 190             //   0 -> C(PTWAM(i).FULL) for i = 0, 1, ..., 15
 191             //   i -> C(PTWAM(i).USE) for i = 0, 1, ..., 15
 192             for (uint i = 0; i < N_MODEL_WAM_ENTRIES; i ++)
 193               {
 194                 cpu.PTWAM[i].FE = 0;
 195                 L68_ (cpu.PTWAM[i].USE = (word4) i;)
 196                 DPS8M_ (cpu.PTWAM[i].USE = 0;)
 197               }
 198 #if defined(do_selftestPTWAM)
 199             selftest_ptwaw ();
 200 #endif /* if defined(do_selftestPTWAM) */
 201           }
 202       }
 203     else
 204       {
 205         cpu.SDW0.FE  = 0;
 206         cpu.SDW0.USE = 0;
 207         cpu.PTW0.FE  = 0;
 208         cpu.PTW0.USE = 0;
 209       }
 210 
 211     // If cache is enabled, reset all cache column and level full flags
 212     if (cpu.switches.enable_cache && cpu.tweaks.enable_wam) {
 213       cacheReset (cpup);
 214     }
 215 
 216     // C(Y-pair) 0,23 -> C(DSBR.ADDR)
 217     cpu.DSBR.ADDR  = (Ypair[0] >> (35 - 23)) & PAMASK;
 218 
 219     // C(Y-pair) 37,50 -> C(DSBR.BOUND)
 220     cpu.DSBR.BND   = (Ypair[1] >> (71 - 50)) & 037777;
 221 
 222     // C(Y-pair) 55 -> C(DSBR.U)
 223     cpu.DSBR.U     = (Ypair[1] >> (71 - 55)) & 01;
 224 
 225     // C(Y-pair) 60,71 -> C(DSBR.STACK)
 226     cpu.DSBR.STACK = (Ypair[1] >> (71 - 71)) & 07777;
 227     DBGAPP ("ldbr 0 -> SDWAM/PTWAM[*].F, i -> SDWAM/PTWAM[i].USE, "
 228             "DSBR.ADDR 0%o, DSBR.BND 0%o, DSBR.U 0%o, DSBR.STACK 0%o\r\n",
 229             cpu.DSBR.ADDR, cpu.DSBR.BND, cpu.DSBR.U, cpu.DSBR.STACK);
 230   }
 231 
 232 /*
 233  * fetch descriptor segment PTW ...
 234  */
 235 
 236 // CANFAULT
 237 
 238 static void fetch_dsptw (cpu_state_t * cpup, word15 segno)
     /* [previous][next][first][last][top][bottom][index][help] */
 239   {
 240     DBGAPP ("%s segno 0%o\r\n", __func__, segno);
 241     PNL (L68_ (cpu.apu.state |= apu_FDPT;))
 242 
 243     if (2 * segno >= 16 * (cpu.DSBR.BND + 1))
 244       {
 245         DBGAPP ("%s ACV15\r\n", __func__);
 246         // generate access violation, out of segment bounds fault
 247         PNL (cpu.acvFaults |= ACV15;)
 248         PNL (L68_ (cpu.apu.state |= apu_FLT;))
 249         doFault (FAULT_ACV, fst_acv15,
 250                  "acvFault: fetch_dsptw out of segment bounds fault");
 251       }
 252     set_apu_status (cpup, apuStatus_DSPTW);
 253 
 254     //word24 y1 = (2u * segno) % 1024u;
 255     word24 x1 = (2u * segno) / 1024u; // floor
 256 
 257     PNL (cpu.lastPTWOffset = segno;)
 258     PNL (cpu.lastPTWIsDS = true;)
 259 
 260     word36 PTWx1;
 261     core_read (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, & PTWx1, __func__); // NO_CACHE
 262 
 263     cpu.PTW0.ADDR = GETHI (PTWx1);
 264     cpu.PTW0.U    = TSTBIT (PTWx1, 9);
 265     cpu.PTW0.M    = TSTBIT (PTWx1, 6);
 266     cpu.PTW0.DF   = TSTBIT (PTWx1, 2);
 267     cpu.PTW0.FC   = PTWx1 & 3;
 268 
 269     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 270       add_l68_APU_history (cpup, APUH_FDSPTW);)
 271 
 272     DBGAPP ("%s x1 0%o DSBR.ADDR 0%o PTWx1 0%012"PRIo64" "
 273             "PTW0: ADDR 0%o U %o M %o F %o FC %o\r\n",
 274             __func__, x1, cpu.DSBR.ADDR, PTWx1, cpu.PTW0.ADDR, cpu.PTW0.U,
 275             cpu.PTW0.M, cpu.PTW0.DF, cpu.PTW0.FC);
 276   }
 277 
 278 /*
 279  * modify descriptor segment PTW (Set U=1) ...
 280  */
 281 
 282 // CANFAULT
 283 
 284 static void modify_dsptw (cpu_state_t * cpup, word15 segno)
     /* [previous][next][first][last][top][bottom][index][help] */
 285   {
 286     PNL (L68_ (cpu.apu.state |= apu_MDPT;))
 287 
 288     set_apu_status (cpup, apuStatus_MDSPTW);
 289 
 290     word24 x1 = (2u * segno) / 1024u; // floor
 291 
 292 #if defined(THREADZ)
 293     bool lck = get_rmw_lock ();
 294     if (! lck)
 295       lock_rmw ();
 296 #endif /* if defined(THREADZ) */
 297 
 298     word36 PTWx1;
 299 #if defined(LOCKLESS)
 300     core_read_lock (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, & PTWx1, __func__); // NO_CACHE
 301     PTWx1 = SETBIT (PTWx1, 9);
 302     core_write_unlock (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, PTWx1, __func__); // NO_CACHE
 303     cacheInvalidate (cpup, (cpu.DSBR.ADDR + x1) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 304 #else
 305     core_read (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, & PTWx1, __func__); // NO_CACHE
 306     PTWx1 = SETBIT (PTWx1, 9);
 307     core_write (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, PTWx1, __func__); // NO_CACHE
 308     cacheInvalidate (cpup, (cpu.DSBR.ADDR + x1) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 309 #endif /* if defined(LOCKLESS) */
 310 
 311 #if defined(THREADZ)
 312     if (! lck)
 313       unlock_rmw ();
 314 #endif /* if defined(THREADZ) */
 315 
 316     cpu.PTW0.U = 1;
 317     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 318       add_l68_APU_history (cpup, APUH_MDSPTW);)
 319   }
 320 
 321 // DPS8M: the 6 bit LRU belongs to the row (set) of the four levels; it
 322 // is updated, and read back by ssdr/sptr, for every level of the row,
 323 // full or not (PA866 02A)
 324 static word6 calc_hit_am (word6 LRU, uint hit_level)
     /* [previous][next][first][last][top][bottom][index][help] */
 325   {
 326 #if defined(TESTING)
 327     cpu_state_t * cpup = _cpup;
 328 #endif
 329     switch (hit_level)
 330       {
 331         case 0:  // hit level A
 332           return (LRU | 070);
 333         case 1:  // hit level B
 334           return ((LRU & 037) | 06);
 335         case 2:  // hit level C
 336           return ((LRU & 053) | 01);
 337         case 3:  // hit level D
 338           return (LRU & 064);
 339         default:
 340           DBGAPP ("%s: Invalid AM level\r\n", __func__);
 341           return 0;
 342      }
 343   }
 344 
 345 static sdw_s * fetch_sdw_from_sdwam (cpu_state_t * cpup, word15 segno) {
     /* [previous][next][first][last][top][bottom][index][help] */
 346   DBGAPP ("%s(0):segno=%05o\r\n", __func__, segno);
 347 
 348   // The AM match flags describe this append cycle (SCU word 0 bits 20,
 349   // 22); the PTW lookup, if any, follows (PA870 01A)
 350   cpu.cu.SDWAMM = 0;
 351   cpu.cu.PTWAMM = 0;
 352 
 353   if ((! cpu.tweaks.enable_wam || ! cpu.cu.SD_ON)) {
 354     DBGAPP ("%s(0): SDWAM disabled\r\n", __func__);
 355     return NULL;
 356   }
 357 
 358   if (cpu.tweaks.l68_mode) { // L68
 359     int nwam = N_L68_WAM_ENTRIES;
 360     for (int _n = 0; _n < nwam; _n++) {
 361       // make certain we initialize SDWAM prior to use!!!
 362       if (cpu.SDWAM[_n].FE && segno == cpu.SDWAM[_n].POINTER) {
 363         DBGAPP ("%s(1):found match for segno %05o " "at _n=%d\r\n", __func__, segno, _n);
 364 
 365         cpu.cu.SDWAMM = 1;
 366         cpu.SDWAMR = (word4) _n;
 367         cpu.SDW = & cpu.SDWAM[_n];
 368 
 369         // If the SDWAM match logic circuitry indicates a hit, all usage
 370         // counts (SDWAM.USE) greater than the usage count of the register
 371         // hit are decremented by one, the usage count of the register hit
 372         // is set to 15, and the contents of the register hit are read out
 373         // into the address preparation circuitry.
 374 
 375         for (int _h = 0; _h < nwam; _h++) {
 376           if (cpu.SDWAM[_h].USE > cpu.SDW->USE)
 377             cpu.SDWAM[_h].USE -= 1;
 378         }
 379         cpu.SDW->USE = N_L68_WAM_ENTRIES - 1;
 380 
 381         char buf[256];
 382         (void)buf;
 383 #if defined(TESTING)
 384         DBGAPP ("%s(2):SDWAM[%d]=%s\r\n", __func__, _n, str_sdw (buf, cpu.SDW));
 385 #endif /* if defined(TESTING) */
 386         return cpu.SDW;
 387       }
 388     }
 389   }
 390 
 391   if (! cpu.tweaks.l68_mode) { // DPS8M
 392     uint setno = segno & 017;
 393     uint toffset;
 394     sdw_s *p;
 395     for (toffset = 0; toffset < 64; toffset += 16) {
 396       p = & cpu.SDWAM[toffset + setno];
 397       if (p->FE && segno == p->POINTER) {
 398         DBGAPP ("%s(1):found match for segno %05o " "at _n=%d\r\n", __func__, segno, toffset + setno);
 399 
 400         cpu.cu.SDWAMM = 1;
 401         cpu.SDWAMR = (word6) (toffset + setno);
 402         cpu.SDW = p; // export pointer for appending
 403 
 404         word6 u = calc_hit_am (p->USE, toffset >> 4);
 405         for (toffset = 0; toffset < 64; toffset += 16) { // update LRU
 406           p = & cpu.SDWAM[toffset + setno];
 407           p->USE = u;
 408         }
 409 
 410         char buf[256];
 411         (void)buf;
 412 #if defined(TESTING)
 413         DBGAPP ("%s(2):SDWAM[%d]=%s\r\n", __func__, toffset + setno, str_sdw (buf, cpu.SDW));
 414 #endif /* if defined(TESTING) */
 415         return cpu.SDW;
 416       }
 417     }
 418   }
 419 #if defined(TESTING)
 420   DBGAPP ("%s(3):SDW for segment %05o not found in SDWAM\r\n", __func__, segno);
 421 #endif /* if defined(TESTING) */
 422   cpu.cu.SDWAMM = 0;
 423   return NULL;    // segment not referenced in SDWAM
 424 }
 425 
 426 /*
 427  * Fetches an SDW from a paged descriptor segment.
 428  */
 429 // CANFAULT
 430 
 431 static void fetch_psdw (cpu_state_t * cpup, word15 segno)
     /* [previous][next][first][last][top][bottom][index][help] */
 432   {
 433     DBGAPP ("%s(0):segno=%05o\r\n",
 434             __func__, segno);
 435 
 436     PNL (L68_ (cpu.apu.state |= apu_FSDP;))
 437 
 438     cpu.cu.SDWAMM = 0;
 439     cpu.cu.PTWAMM = 0;
 440     set_apu_status (cpup, apuStatus_SDWP);
 441     word24 y1 = (2 * segno) % 1024;
 442 
 443     word36 SDWeven, SDWodd;
 444 
 445     core_read2 (cpup, ((((word24) cpu.PTW0.ADDR & 0777760) << 6) + y1) & PAMASK, // NO_CACHE
 446                 & SDWeven, & SDWodd, __func__);
 447 
 448     // even word
 449     cpu.SDW0.ADDR  = (SDWeven >> 12) & 077777777;
 450     cpu.SDW0.R1    = (SDWeven >> 9)  & 7;
 451     cpu.SDW0.R2    = (SDWeven >> 6)  & 7;
 452     cpu.SDW0.R3    = (SDWeven >> 3)  & 7;
 453     cpu.SDW0.DF    = TSTBIT (SDWeven, 2);
 454     cpu.SDW0.FC    = SDWeven & 3;
 455 
 456     // odd word
 457     cpu.SDW0.BOUND = (SDWodd >> 21) & 037777;
 458     cpu.SDW0.R     = TSTBIT (SDWodd, 20);
 459     cpu.SDW0.E     = TSTBIT (SDWodd, 19);
 460     cpu.SDW0.W     = TSTBIT (SDWodd, 18);
 461     cpu.SDW0.P     = TSTBIT (SDWodd, 17);
 462     cpu.SDW0.U     = TSTBIT (SDWodd, 16);
 463     cpu.SDW0.G     = TSTBIT (SDWodd, 15);
 464     cpu.SDW0.C     = TSTBIT (SDWodd, 14);
 465     cpu.SDW0.EB    = SDWodd & 037777;
 466 
 467     L68_ (
 468       if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 469         add_l68_APU_history (cpup, APUH_FSDWP);
 470      )
 471     DBGAPP ("%s y1 0%o p->ADDR 0%o SDW 0%012"PRIo64" 0%012"PRIo64" "
 472             "ADDR %o R %o%o%o BOUND 0%o REWPUGC %o%o%o%o%o%o%o "
 473             "F %o FC %o FE %o USE %o\r\n",
 474             __func__, y1, cpu.PTW0.ADDR, SDWeven, SDWodd, cpu.SDW0.ADDR,
 475             cpu.SDW0.R1, cpu.SDW0.R2, cpu.SDW0.R3, cpu.SDW0.BOUND,
 476             cpu.SDW0.R, cpu.SDW0.E, cpu.SDW0.W, cpu.SDW0.P, cpu.SDW0.U,
 477             cpu.SDW0.G, cpu.SDW0.C, cpu.SDW0.DF, cpu.SDW0.FC, cpu.SDW0.FE,
 478             cpu.SDW0.USE);
 479   }
 480 
 481 // Nonpaged SDW Fetch
 482 // Fetches an SDW from an unpaged descriptor segment.
 483 // CANFAULT
 484 
 485 static void fetch_nsdw (cpu_state_t * cpup, word15 segno)
     /* [previous][next][first][last][top][bottom][index][help] */
 486   {
 487     DBGAPP ("%s (0):segno=%05o\r\n", __func__, segno);
 488 
 489     PNL (L68_ (cpu.apu.state |= apu_FSDN;))
 490 
 491     cpu.cu.SDWAMM = 0;
 492     cpu.cu.PTWAMM = 0;
 493     set_apu_status (cpup, apuStatus_SDWNP);
 494 
 495     if (2 * segno >= 16 * (cpu.DSBR.BND + 1))
 496       {
 497         DBGAPP ("%s (1):Access Violation, out of segment bounds for "
 498                 "segno=%05o DSBR.BND=%d\r\n",
 499                 __func__, segno, cpu.DSBR.BND);
 500         // generate access violation, out of segment bounds fault
 501         PNL (cpu.acvFaults |= ACV15;)
 502         PNL (L68_ (cpu.apu.state |= apu_FLT;))
 503         doFault (FAULT_ACV, fst_acv15,
 504                  "acvFault fetch_dsptw: out of segment bounds fault");
 505       }
 506     DBGAPP ("%s (2):fetching SDW from %05o\r\n",
 507             __func__, cpu.DSBR.ADDR + 2u * segno);
 508 
 509     word36 SDWeven, SDWodd;
 510     core_read2 (cpup, (cpu.DSBR.ADDR + 2u * segno) & PAMASK, // NO_CACHE
 511                 & SDWeven, & SDWodd, __func__);
 512 
 513     // even word
 514     cpu.SDW0.ADDR = (SDWeven >> 12) & 077777777;
 515     cpu.SDW0.R1   = (SDWeven >> 9)  & 7;
 516     cpu.SDW0.R2   = (SDWeven >> 6)  & 7;
 517     cpu.SDW0.R3   = (SDWeven >> 3)  & 7;
 518     cpu.SDW0.DF   = TSTBIT (SDWeven, 2);
 519     cpu.SDW0.FC   = SDWeven & 3;
 520 
 521     // odd word
 522     cpu.SDW0.BOUND = (SDWodd >> 21) & 037777;
 523     cpu.SDW0.R     = TSTBIT (SDWodd, 20);
 524     cpu.SDW0.E     = TSTBIT (SDWodd, 19);
 525     cpu.SDW0.W     = TSTBIT (SDWodd, 18);
 526     cpu.SDW0.P     = TSTBIT (SDWodd, 17);
 527     cpu.SDW0.U     = TSTBIT (SDWodd, 16);
 528     cpu.SDW0.G     = TSTBIT (SDWodd, 15);
 529     cpu.SDW0.C     = TSTBIT (SDWodd, 14);
 530     cpu.SDW0.EB    = SDWodd & 037777;
 531 
 532     L68_ (
 533       if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 534         add_l68_APU_history (cpup, 0 /* No fetch no paged bit */);
 535     )
 536 #if !defined(SPEED)
 537     char buf[256];
 538     (void)buf;
 539     DBGAPP ("%s (2):SDW0=%s\r\n", __func__, str_SDW0 (buf, & cpu.SDW0));
 540 #endif /* if !defined(SPEED) */
 541   }
 542 
 543 #if defined(TESTING)
 544 static char *str_sdw (char * buf, sdw_s *SDW)
     /* [previous][next][first][last][top][bottom][index][help] */
 545   {
 546     if (! SDW->FE)
 547       (void)sprintf (buf, "*** SDW Uninitialized ***");
 548     else
 549       (void)sprintf (buf,
 550                      "ADDR:%06o R1:%o R2:%o R3:%o BOUND:%o R:%o E:%o W:%o P:%o "
 551                      "U:%o G:%o C:%o CL:%o DF:%o FC:%o POINTER=%o USE=%d",
 552                      SDW->ADDR,    SDW->R1, SDW->R2, SDW->R3, SDW->BOUND,
 553                      SDW->R,       SDW->E,  SDW->W,  SDW->P,  SDW->U,
 554                      SDW->G,       SDW->C,  SDW->EB, SDW->DF, SDW->FC,
 555                      SDW->POINTER, SDW->USE);
 556     return buf;
 557   }
 558 
 559 /*
 560  * dump SDWAM...
 561  */
 562 
 563 t_stat dump_sdwam (cpu_state_t * cpup)
     /* [previous][next][first][last][top][bottom][index][help] */
 564   {
 565     char buf[256];
 566     (void)buf;
 567     for (int _n = 0; _n < N_MODEL_WAM_ENTRIES; _n++)
 568       {
 569         sdw_s *p = & cpu.SDWAM[_n];
 570 
 571         if (p->FE)
 572           sim_printf ("SDWAM n:%d %s\r\n", _n, str_sdw (buf, p));
 573       }
 574     return SCPE_OK;
 575   }
 576 #endif /* if defined(TESTING) */
 577 
 578 static uint to_be_discarded_am (word6 LRU)
     /* [previous][next][first][last][top][bottom][index][help] */
 579   {
 580 
 581 
 582 
 583 
 584 
 585 
 586 
 587 
 588 
 589 
 590 
 591 
 592     // The level older than the other three, in the sense calc_hit_am
 593     // sets the bits (as the #if 0 code above): 040 B older than A, 020
 594     // C older than A, 010 D older than A, 04 C older than B, 02 D older
 595     // than B, 01 D older than C. (PA866 04A: with LRU 0, level A.)
 596     if ((LRU & 070) == 0)   return 0;
 597     if ((LRU & 046) == 040) return 1;
 598     if ((LRU & 025) == 024) return 2;
 599     return 3;
 600   }
 601 
 602 /*
 603  * load the current in-core SDW0 into the SDWAM ...
 604  */
 605 
 606 static void load_sdwam (cpu_state_t * cpup, word15 segno, bool nomatch)
     /* [previous][next][first][last][top][bottom][index][help] */
 607   {
 608     cpu.SDW0.POINTER = segno;
 609     cpu.SDW0.USE = 0;
 610 
 611     cpu.SDW0.FE = true;     // in use by SDWAM
 612 
 613     cpu.SDW = & cpu.SDW0;
 614 
 615     if (nomatch || (! cpu.tweaks.enable_wam) || (! cpu.cu.SD_ON))
 616       {
 617         DBGAPP ("%s: SDWAM disabled\r\n", __func__);
 618         return;
 619       }
 620 
 621     if (cpu.tweaks.l68_mode) { // L68
 622       // If the SDWAM match logic does not indicate a hit, the SDW is fetched
 623       // from the descriptor segment in main memory and loaded into the SDWAM
 624       // register with usage count 0 (the oldest), all usage counts are
 625       // decremented by one with the newly loaded register rolling over from 0 to
 626       // 15, and the newly loaded register is read out into the address
 627       // preparation circuitry.
 628 
 629       for (int _n = 0; _n < N_L68_WAM_ENTRIES; _n++) {
 630         sdw_s * p = & cpu.SDWAM[_n];
 631         if (! p->FE || p->USE == 0) {
 632           DBGAPP ("%s(1):SDWAM[%d] FE=0 || USE=0\r\n", __func__, _n);
 633 
 634           * p = cpu.SDW0;
 635           p->POINTER = segno;
 636           p->USE = 0;
 637           p->FE = true;     // in use by SDWAM
 638 
 639           for (int _h = 0; _h < N_L68_WAM_ENTRIES; _h++) {
 640             sdw_s * q = & cpu.SDWAM[_h];
 641             q->USE -= 1;
 642             q->USE &= N_L68_WAM_MASK;
 643           }
 644 
 645           cpu.SDW = p;
 646 
 647           char buf[256];
 648           (void) buf;
 649 #if defined(TESTING)
 650           DBGAPP ("%s(2):SDWAM[%d]=%s\r\n", __func__, _n, str_sdw (buf, p));
 651 #endif /* if defined(TESTING) */
 652           return;
 653         }
 654       }
 655       // if we reach this, USE is scrambled
 656 #if defined(TESTING)
 657       DBGAPP ("%s(3) no USE=0 found for segment=%d\r\n", __func__, segno);
 658       sim_printf ("%s(%05o): no USE=0 found!\r\n", __func__, segno);
 659       dump_sdwam (cpup);
 660 #endif /* if defined(TESTING) */
 661     }
 662 
 663     if (! cpu.tweaks.l68_mode) { // DPS8M
 664       uint setno = segno & 017;
 665       uint toffset;
 666       sdw_s *p;
 667       for (toffset = 0; toffset < 64; toffset += 16) {
 668         p = & cpu.SDWAM[toffset + setno];
 669         if (!p->FE)
 670           break;
 671       }
 672       if (toffset == 64) { // all FE==1
 673         toffset = to_be_discarded_am (p->USE) << 4;
 674         p = & cpu.SDWAM[toffset + setno];
 675       }
 676       DBGAPP ("%s(1):SDWAM[%d] FE=0 || LRU\r\n", __func__, toffset + setno);
 677 
 678       word6 u = calc_hit_am (p->USE, toffset >> 4); // before loading the SDWAM!
 679       * p = cpu.SDW0; // load the SDW
 680       p->POINTER = segno;
 681       p->FE = true;  // in use
 682       p->loaded = true;
 683       cpu.SDW = p; // export pointer for appending
 684 
 685       for (uint toffset1 = 0; toffset1 < 64; toffset1 += 16) { // update LRU
 686         p = & cpu.SDWAM[toffset1 + setno];
 687         p->USE = u;
 688       }
 689 
 690       char buf[256];
 691       (void) buf;
 692 #if defined(TESTING)
 693       DBGAPP ("%s(2):SDWAM[%d]=%s\r\n", __func__, toffset + setno, str_sdw (buf, cpu.SDW));
 694 #endif /* if defined(TESTING) */
 695     } // DPS8M
 696   }
 697 
 698 static ptw_s * fetch_ptw_from_ptwam (cpu_state_t * cpup, word15 segno, word18 CA)
     /* [previous][next][first][last][top][bottom][index][help] */
 699   {
 700     if ((! cpu.tweaks.enable_wam) || (! cpu.cu.PT_ON))
 701       {
 702         DBGAPP ("%s: PTWAM disabled\r\n", __func__);
 703         return NULL;
 704       }
 705 
 706     if (cpu.tweaks.l68_mode) { // L68
 707       int nwam = N_L68_WAM_ENTRIES;
 708       for (int _n = 0; _n < nwam; _n++)
 709         {
 710           if (cpu.PTWAM[_n].FE && ((CA >> 6) & 07760) == cpu.PTWAM[_n].PAGENO &&
 711               cpu.PTWAM[_n].POINTER == segno)   //_initialized
 712             {
 713               DBGAPP ("%s: found match for segno=%o pageno=%o "
 714                       "at _n=%d\r\n",
 715                       __func__, segno, cpu.PTWAM[_n].PAGENO, _n);
 716               cpu.cu.PTWAMM = 1;
 717               cpu.PTWAMR = (word4) _n;
 718               cpu.PTW = & cpu.PTWAM[_n];
 719 
 720               // If the PTWAM match logic circuitry indicates a hit, all usage
 721               // counts (PTWAM.USE) greater than the usage count of the register
 722               // hit are decremented by one, the usage count of the register hit
 723               // is set to 15, and the contents of the register hit are read out
 724               // into the address preparation circuitry.
 725 
 726               for (int _h = 0; _h < nwam; _h++)
 727                 {
 728                   if (cpu.PTWAM[_h].USE > cpu.PTW->USE)
 729                     cpu.PTWAM[_h].USE -= 1; //PTW->USE -= 1;
 730                 }
 731               cpu.PTW->USE = N_L68_WAM_ENTRIES - 1;
 732 #if defined(do_selftestPTWAM)
 733               selftest_ptwaw ();
 734 #endif /* if defined(do_selftestPTWAM) */
 735               DBGAPP ("%s: ADDR 0%o U %o M %o F %o FC %o\r\n",
 736                       __func__, cpu.PTW->ADDR, cpu.PTW->U, cpu.PTW->M,
 737                       cpu.PTW->DF, cpu.PTW->FC);
 738               return cpu.PTW;
 739             }
 740         }
 741     }
 742 
 743     DPS8M_ (
 744       uint setno = (CA >> 10) & 017;
 745       uint toffset;
 746       ptw_s *p;
 747       for (toffset = 0; toffset < 64; toffset += 16)
 748         {
 749           p = & cpu.PTWAM[toffset + setno];
 750 
 751           if (p->FE && ((CA >> 6) & 07760) == p->PAGENO && p->POINTER == segno)
 752             {
 753               DBGAPP ("%s: found match for segno=%o pageno=%o "
 754                       "at _n=%d\r\n",
 755                       __func__, segno, p->PAGENO, toffset + setno);
 756               cpu.cu.PTWAMM = 1;
 757               cpu.PTWAMR = (word6) (toffset + setno);
 758               cpu.PTW = p; // export pointer for appending
 759 
 760               word6 u = calc_hit_am (p->USE, toffset >> 4);
 761               for (toffset = 0; toffset < 64; toffset += 16) // update LRU
 762                 {
 763                   p = & cpu.PTWAM[toffset + setno];
 764                   p->USE = u;
 765                 }
 766 
 767               DBGAPP ("%s: ADDR 0%o U %o M %o F %o FC %o\r\n",
 768                       __func__, cpu.PTW->ADDR, cpu.PTW->U, cpu.PTW->M,
 769                       cpu.PTW->DF, cpu.PTW->FC);
 770               return cpu.PTW;
 771             }
 772         }
 773      )
 774     cpu.cu.PTWAMM = 0;
 775     return NULL;    // page not referenced in PTWAM
 776   }
 777 
 778 static void fetch_ptw (cpu_state_t * cpup, sdw_s *sdw, word18 offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 779   {
 780     // AL39 p.5-7
 781     // Fetches a PTW from a page table other than a descriptor segment page
 782     // table and sets the page accessed bit (PTW.U)
 783     PNL (L68_ (cpu.apu.state |= apu_FPTW;))
 784     set_apu_status (cpup, apuStatus_PTW);
 785 
 786     //word24 y2 = offset % 1024;
 787     word24 x2 = (offset) / 1024; // floor
 788 
 789     word36 PTWx2;
 790 
 791     DBGAPP ("%s address %08o\r\n", __func__, sdw->ADDR + x2);
 792 
 793     PNL (cpu.lastPTWOffset = offset;)
 794     PNL (cpu.lastPTWIsDS = false;)
 795 
 796 #if defined(THREADZ)
 797     bool lck = get_rmw_lock ();
 798     if (! lck)
 799       lock_rmw ();
 800 #endif /* if defined(THREADZ) */
 801 #if defined(LOCKLESS)
 802     core_read_lock (cpup, (sdw->ADDR + x2) & PAMASK, & PTWx2, __func__); // NO_CACHE
 803 #else
 804     core_read (cpup, (sdw->ADDR + x2) & PAMASK, & PTWx2, __func__); // NO_CACHE
 805 #endif /* if defined(LOCKLESS) */
 806 
 807     cpu.PTW0.ADDR = GETHI  (PTWx2);
 808     cpu.PTW0.U    = TSTBIT (PTWx2, 9);
 809     cpu.PTW0.M    = TSTBIT (PTWx2, 6);
 810     cpu.PTW0.DF   = TSTBIT (PTWx2, 2);
 811     cpu.PTW0.FC   = PTWx2 & 3;
 812 
 813     // ISOLTS-861 02
 814 #if !defined(LOCKLESS)
 815     if (! cpu.PTW0.U)
 816 #endif /* if !defined(LOCKLESS) */
 817       {
 818         PTWx2 = SETBIT (PTWx2, 9);
 819 #if defined(LOCKLESS)
 820         core_write_unlock (cpup, (sdw->ADDR + x2) & PAMASK, PTWx2, __func__); // NO_CACHE
 821         cacheInvalidate (cpup, (sdw->ADDR + x2) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 822 #else
 823         core_write (cpup, (sdw->ADDR + x2) & PAMASK, PTWx2, __func__); // NO_CACHE
 824         cacheInvalidate (cpup, (sdw->ADDR + x2) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 825 #endif /* if defined(LOCKLESS) */
 826         cpu.PTW0.U = 1;
 827       }
 828 
 829 #if defined(THREADZ)
 830     if (! lck)
 831       unlock_rmw ();
 832 #endif /* if defined(THREADZ) */
 833 
 834     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 835       add_l68_APU_history (cpup, APUH_FPTW);)
 836 
 837     DBGAPP ("%s x2 0%o sdw->ADDR 0%o PTWx2 0%012"PRIo64" "
 838             "PTW0: ADDR 0%o U %o M %o F %o FC %o\r\n",
 839             __func__, x2, sdw->ADDR, PTWx2, cpu.PTW0.ADDR, cpu.PTW0.U,
 840             cpu.PTW0.M, cpu.PTW0.DF, cpu.PTW0.FC);
 841   }
 842 
 843 static void loadPTWAM (cpu_state_t * cpup, word15 segno, word18 offset, UNUSED bool nomatch)
     /* [previous][next][first][last][top][bottom][index][help] */
 844   {
 845     cpu.PTW0.PAGENO  = (offset >> 6) & 07760;
 846     cpu.PTW0.POINTER = segno;
 847     cpu.PTW0.USE     = 0;
 848     cpu.PTW0.FE      = true;
 849 
 850     cpu.PTW = & cpu.PTW0;
 851     if (nomatch || (! cpu.tweaks.enable_wam) || (! cpu.cu.PT_ON))
 852       {
 853         DBGAPP ("loadPTWAM: PTWAM disabled\r\n");
 854         return;
 855       }
 856 
 857     if (cpu.tweaks.l68_mode) { // L68
 858       // If the PTWAM match logic does not indicate a hit, the PTW is fetched
 859       // from main memory and loaded into the PTWAM register with usage count 0
 860       // (the oldest), all usage counts are decremented by one with the newly
 861       // loaded register rolling over from 0 to 15, and the newly loaded register
 862       // is read out into the address preparation circuitry.
 863 
 864       for (int _n = 0; _n < N_L68_WAM_ENTRIES; _n++)
 865         {
 866           ptw_s * p = & cpu.PTWAM[_n];
 867           if (! p->FE || p->USE == 0)
 868             {
 869               DBGAPP ("loadPTWAM(1):PTWAM[%d] FE=0 || USE=0\r\n", _n);
 870               *p = cpu.PTW0;
 871               p->PAGENO = (offset >> 6) & 07760;
 872               p->POINTER = segno;
 873               p->USE = 0;
 874               p->FE = true;
 875 
 876               for (int _h = 0; _h < N_L68_WAM_ENTRIES; _h++)
 877                 {
 878                   ptw_s * q = & cpu.PTWAM[_h];
 879                   q->USE -= 1;
 880                   q->USE &= N_L68_WAM_MASK;
 881                 }
 882 
 883               cpu.PTW = p;
 884               DBGAPP ("loadPTWAM(2): ADDR 0%o U %o M %o F %o FC %o "
 885                       "POINTER=%o PAGENO=%o USE=%d\r\n",
 886                       cpu.PTW->ADDR, cpu.PTW->U, cpu.PTW->M, cpu.PTW->DF,
 887                       cpu.PTW->FC, cpu.PTW->POINTER, cpu.PTW->PAGENO,
 888                       cpu.PTW->USE);
 889 #if defined(do_selftestPTWAM)
 890               selftest_ptwaw ();
 891 #endif /* if defined(do_selftestPTWAM) */
 892               return;
 893             }
 894         }
 895       // if we reach this, USE is scrambled
 896       sim_printf ("loadPTWAM(segno=%05o, offset=%012o): no USE=0 found!\r\n",
 897                   segno, offset);
 898     }
 899 
 900     DPS8M_ (
 901       uint setno = (offset >> 10) & 017;
 902       uint toffset;
 903       ptw_s *p;
 904       for (toffset = 0; toffset < 64; toffset += 16)
 905         {
 906           p = & cpu.PTWAM[toffset + setno];
 907           if (! p->FE)
 908             break;
 909         }
 910       if (toffset == 64) // all FE==1
 911         {
 912           toffset = to_be_discarded_am (p->USE) << 4;
 913           p = & cpu.PTWAM[toffset + setno];
 914         }
 915 
 916       DBGAPP ("loadPTWAM(1):PTWAM[%d] FE=0 || LRU\r\n",
 917               toffset + setno);
 918 
 919       word6 u = calc_hit_am (p->USE, toffset >> 4); // before loading the PTWAM
 920       * p = cpu.PTW0; // load the PTW
 921       p->PAGENO = (offset >> 6) & 07760;
 922       p->POINTER = segno;
 923       p->FE = true;  // in use
 924       p->loaded = true;
 925       cpu.PTW = p; // export pointer for appending
 926 
 927       for (uint toffset1 = 0; toffset1 < 64; toffset1 += 16) // update LRU
 928         {
 929           p = & cpu.PTWAM[toffset1 + setno];
 930           p->USE = u;
 931         }
 932 
 933       DBGAPP ("loadPTWAM(2): ADDR 0%o U %o M %o F %o FC %o POINTER=%o "
 934               "PAGENO=%o USE=%d\r\n",
 935               cpu.PTW->ADDR, cpu.PTW->U, cpu.PTW->M, cpu.PTW->DF,
 936               cpu.PTW->FC, cpu.PTW->POINTER, cpu.PTW->PAGENO, cpu.PTW->USE);
 937     )
 938   }
 939 
 940 /*
 941  * modify target segment PTW (Set M=1) ...
 942  */
 943 
 944 static void modify_ptw (cpu_state_t * cpup, sdw_s *sdw, word18 offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 945   {
 946     PNL (L68_ (cpu.apu.state |= apu_MPTW;))
 947     //word24 y2 = offset % 1024;
 948     word24 x2 = offset / 1024; // floor
 949 
 950     word36 PTWx2;
 951 
 952     set_apu_status (cpup, apuStatus_MPTW);
 953 
 954 #if defined(THREADZ)
 955     bool lck = get_rmw_lock ();
 956     if (! lck)
 957       lock_rmw ();
 958 #endif /* if defined(THREADZ) */
 959 #if defined(LOCKLESS)
 960     core_read_lock (cpup, (sdw->ADDR + x2) & PAMASK, & PTWx2, __func__); // NO_CACHE
 961     PTWx2 = SETBIT (PTWx2, 6);
 962     core_write_unlock (cpup, (sdw->ADDR + x2) & PAMASK, PTWx2, __func__); // NO_CACHE
 963     cacheInvalidate (cpup, (sdw->ADDR + x2) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 964 #else
 965     core_read (cpup, (sdw->ADDR + x2) & PAMASK, & PTWx2, __func__); // NO_CACHE
 966     PTWx2 = SETBIT (PTWx2, 6);
 967     core_write (cpup, (sdw->ADDR + x2) & PAMASK, PTWx2, __func__); // NO_CACHE
 968     cacheInvalidate (cpup, (sdw->ADDR + x2) & PAMASK);  // keep this CPU's cache current (PA863, PA868)
 969 #endif /* if defined(LOCKLESS) */
 970 #if defined(THREADZ)
 971     if (! lck)
 972       unlock_rmw ();
 973 #endif /* if defined(THREADZ) */
 974     cpu.PTW->M = 1;
 975     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 976       add_l68_APU_history (cpup, APUH_MPTW);)
 977   }
 978 
 979 static void do_ptw2 (cpu_state_t * cpup, sdw_s *sdw, word18 offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 980   {
 981     PNL (L68_ (cpu.apu.state |= apu_FPTW2;))
 982     set_apu_status (cpup, apuStatus_PTW2);
 983 
 984     //word24 y2 = offset % 1024;
 985     word24 x2 = (offset) / 1024; // floor
 986 
 987     word36 PTWx2n;
 988 
 989     DBGAPP ("%s address %08o\r\n", __func__, sdw->ADDR + x2 + 1);
 990 
 991     core_read (cpup, (sdw->ADDR + x2 + 1) & PAMASK, & PTWx2n, __func__); // NO_CACHE
 992 
 993     ptw_s PTW2;
 994     PTW2.ADDR = GETHI (PTWx2n);
 995     PTW2.U    = TSTBIT (PTWx2n, 9);
 996     PTW2.M    = TSTBIT (PTWx2n, 6);
 997     PTW2.DF   = TSTBIT (PTWx2n, 2);
 998     PTW2.FC   = PTWx2n & 3;
 999 
1000     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
1001       add_l68_APU_history (cpup, APUH_FPTW2);)
1002 
1003     DBGAPP ("%s x2 0%o sdw->ADDR 0%o PTW2 0%012"PRIo64" "
1004             "PTW2: ADDR 0%o U %o M %o F %o FC %o\r\n",
1005             __func__, x2, sdw->ADDR, PTWx2n, PTW2.ADDR, PTW2.U, PTW2.M,
1006             PTW2.DF, PTW2.FC);
1007 
1008     // check that PTW2 is the next page of the same segment
1009     // ISOLTS 875 02a
1010     if ((PTW2.ADDR & 0777760) == (cpu.PTW->ADDR & 0777760) + 16)
1011        //Is PTW2.F set ON?
1012        if (! PTW2.DF)
1013            // initiate a directed fault
1014            doFault (FAULT_DF0 + PTW2.FC, fst_zero, "PTW2.F == 0");
1015   }
1016 
1017 /*
1018  * Is the instruction a SToRage OPeration ?
1019  */
1020 
1021 #if !defined(QUIET_UNUSED)
1022 static char *str_access_type (MemoryAccessType accessType)
     /* [previous][next][first][last][top][bottom][index][help] */
1023   {
1024     switch (accessType)
1025       {
1026         case UnknownMAT:        return "Unknown";
1027         case OperandRead:       return "OperandRead";
1028         case OperandWrite:      return "OperandWrite";
1029         default:                return "???";
1030       }
1031   }
1032 
1033 static char *str_acv (_fault_subtype acv)
     /* [previous][next][first][last][top][bottom][index][help] */
1034   {
1035     switch (acv)
1036       {
1037         case ACV0:  return "Illegal ring order (ACV0=IRO)";
1038         case ACV1:  return "Not in execute bracket (ACV1=OEB)";
1039         case ACV2:  return "No execute permission (ACV2=E-OFF)";
1040         case ACV3:  return "Not in read bracket (ACV3=ORB)";
1041         case ACV4:  return "No read permission (ACV4=R-OFF)";
1042         case ACV5:  return "Not in write bracket (ACV5=OWB)";
1043         case ACV6:  return "No write permission (ACV6=W-OFF)";
1044         case ACV7:  return "Call limiter fault (ACV7=NO GA)";
1045         case ACV8:  return "Out of call brackets (ACV8=OCB)";
1046         case ACV9:  return "Outward call (ACV9=OCALL)";
1047         case ACV10: return "Bad outward call (ACV10=BOC)";
1048         case ACV11: return "Inward return (ACV11=INRET) XXX ??";
1049         case ACV12: return "Invalid ring crossing (ACV12=CRT)";
1050         case ACV13: return "Ring alarm (ACV13=RALR)";
1051         case ACV14: return "Associative memory error XXX ??";
1052         case ACV15: return "Out of segment bounds (ACV15=OOSB)";
1053         //case ACDF0: return "Directed fault 0";
1054         //case ACDF1: return "Directed fault 1";
1055         //case ACDF2: return "Directed fault 2";
1056         //case ACDF3: return "Directed fault 3";
1057         default:
1058             break;
1059       }
1060   return "unhandled acv in str_acv";
1061   }
1062 #endif /* if !defined(QUIET_UNUSED) */
1063 
1064 #if defined (TESTING) || defined (OLDAPP)
1065 static char *str_pct (processor_cycle_type t)
     /* [previous][next][first][last][top][bottom][index][help] */
1066   {
1067     switch (t)
1068       {
1069         case UNKNOWN_CYCLE:       return "UNKNOWN_CYCLE";
1070         case OPERAND_STORE:       return "OPERAND_STORE";
1071         case OPERAND_READ:        return "OPERAND_READ";
1072         case INDIRECT_WORD_FETCH: return "INDIRECT_WORD_FETCH";
1073 # if defined(LOCKLESS)
1074         case OPERAND_RMW:         return "OPERAND_RMW";
1075         case APU_DATA_RMW:        return "APU_DATA_RMW";
1076 # endif /* if defined(LOCKLESS) */
1077         default:
1078             return "Unhandled processor_cycle_type";
1079       }
1080   }
1081 #endif
1082 
1083 #if !defined(OLDAPP)
1084 word24 do_append_cycle (cpu_state_t * cpup, processor_cycle_type thisCycle, word36 * data, uint nWords) {
     /* [previous][next][first][last][top][bottom][index][help] */
1085   switch (thisCycle) {
1086     case OPERAND_STORE:
1087       return doAppendCycleOperandStore (cpup, data, nWords);
1088     case OPERAND_READ:
1089       return doAppendCycleOperandRead (cpup, data, nWords);
1090     case INDIRECT_WORD_FETCH:
1091       return doAppendCycleIndirectWordFetch (cpup, data, nWords);
1092     case RTCD_OPERAND_FETCH:
1093       return doAppendCycleRTCDOperandFetch (cpup, data, nWords);
1094     case INSTRUCTION_FETCH:
1095       return doAppendCycleInstructionFetch (cpup, data, nWords);
1096     case APU_DATA_READ:
1097       return doAppendCycleAPUDataRead (cpup, data, nWords);
1098     case APU_DATA_STORE:
1099       return doAppendCycleAPUDataStore (cpup, data, nWords);
1100     case ABSA_CYCLE:
1101       return doAppendCycleABSA (cpup, data, nWords);
1102 # if defined(LOCKLESS)
1103     case OPERAND_RMW:
1104       return doAppendCycleOperandRMW (cpup, data, nWords);
1105     case APU_DATA_RMW:
1106       return doAppendCycleAPUDataRMW (cpup, data, nWords);
1107 # endif /* if defined(LOCKLESS) */
1108     case UNKNOWN_CYCLE:
1109     default:
1110       (void)fprintf (stderr, "\rFATAL: APU unknown cycle %llu! Aborting at %s[%s:%d]\r\n",
1111                      (long long unsigned)thisCycle, __func__, __FILE__, __LINE__);
1112 # if defined(USE_BACKTRACE)
1113 #  if defined(SIGUSR2)
1114       (void)raise(SIGUSR2);
1115       /*NOTREACHED*/ /* unreachable */
1116 #  endif /* if defined(SIGUSR2) */
1117 # endif /* if defined(USE_BACKTRACE) */
1118       abort();
1119   }
1120 }
1121 #endif /* if !defined(OLDAPP) */
1122 
1123 #if !defined(OLDAPP)
1124 # include "doAppendCycleOperandStore.h"
1125 # include "doAppendCycleOperandRead.h"
1126 # include "doAppendCycleIndirectWordFetch.h"
1127 # include "doAppendCycleRTCDOperandFetch.h"
1128 # include "doAppendCycleInstructionFetch.h"
1129 # include "doAppendCycleAPUDataRead.h"
1130 # include "doAppendCycleAPUDataStore.h"
1131 # include "doAppendCycleABSA.h"
1132 # if defined(LOCKLESS)
1133 #  include "doAppendCycleOperandRMW.h"
1134 #  include "doAppendCycleAPUDataRMW.h"
1135 # endif /* if defined(LOCKLESS) */
1136 
1137 // The append cycles are compiled twice (see FULL_MODEL_ON): the fast copy
1138 // leaves out the T&D, ISOLTS and cache model work. The fast copy is
1139 // inlined here, the full one is kept out of line. The copy follows the
1140 // CPU's copy of the instruction loop (cpu.fullCopy), not fullModelOn,
1141 // which may change in the middle of an instruction.
1142 # define APPEND_CYCLE_COPIES(name)                                       \
1143   static NO_INLINE word24 name##Full (cpu_state_t * cpup, word36 * data, \
1144                                       uint nWords)                       \
1145     {                                                                    \
1146       return name##_ (cpup, data, nWords, true);                         \
1147     }                                                                    \
1148   word24 name (cpu_state_t * cpup, word36 * data, uint nWords)           \
1149     {                                                                    \
1150       if (UNLIKELY (cpup->fullCopy))                                     \
1151         return name##Full (cpup, data, nWords);                          \
1152       return name##_ (cpup, data, nWords, false);                        \
1153     }
1154 
1155 APPEND_CYCLE_COPIES (doAppendCycleOperandStore)
     /* [previous][next][first][last][top][bottom][index][help] */
1156 APPEND_CYCLE_COPIES (doAppendCycleOperandRead)
1157 APPEND_CYCLE_COPIES (doAppendCycleIndirectWordFetch)
1158 APPEND_CYCLE_COPIES (doAppendCycleRTCDOperandFetch)
1159 APPEND_CYCLE_COPIES (doAppendCycleInstructionFetch)
1160 APPEND_CYCLE_COPIES (doAppendCycleAPUDataRead)
1161 APPEND_CYCLE_COPIES (doAppendCycleAPUDataStore)
1162 # if defined(LOCKLESS)
1163 APPEND_CYCLE_COPIES (doAppendCycleOperandRMW)
1164 APPEND_CYCLE_COPIES (doAppendCycleAPUDataRMW)
1165 # endif /* if defined(LOCKLESS) */
1166 #endif /* if !defined(OLDAPP) */
1167 
1168 #if defined(OLDAPP)
1169 /*
1170  * recoding APU functions to more closely match Fig 5,6 & 8 ...
1171  * Returns final address suitable for core_read/write
1172  */
1173 
1174 //
1175 // Phase 1:
1176 //
1177 //     A: Get the SDW
1178 //
1179 //     B: Check the ring
1180 //
1181 // Phase 2:
1182 //
1183 //     B1: If CALL6 operand
1184 //           goto E
1185 //         If instruction fetch or transfer instruction operand
1186 //           goto F
1187 //         If write
1188 //           check write permission
1189 //         else
1190 //           check read permission
1191 //         goto G
1192 //
1193 //     E: -- CALL6 operand handling
1194 //        Check execute and gate bits
1195 //        Get the ring
1196 //        goto G
1197 //
1198 //     F: -- instruction fetch or transfer instruction operand
1199 //        Check execute bit and ring
1200 //        goto D
1201 //
1202 //     D: Check RALR
1203 //        goto G
1204 //
1205 // Phase 3
1206 //
1207 //     G: Check BOUND
1208 //        If not paged
1209 //          goto H
1210 //        Fetch PTW
1211 //        Fetch prepage PTW
1212 //        Goto I
1213 //
1214 //     H: Compute final address
1215 //        Goto HI
1216 //
1217 //     I: If write
1218 //          set PTW.M
1219 //        Compute final address
1220 //        Goto HI
1221 //
1222 // Phase 4
1223 //
1224 //     HI: --
1225 //         If indirect word fetch
1226 //           goto J
1227 //         if rtcd operand fetch
1228 //           goto K
1229 //         if CALL6
1230 //           goto N
1231 //         If instruction fetch or transfer instruction operand
1232 //           goto L
1233 //         APU data movement?
1234 //           load/store APU data
1235 //
1236 //    K: Set PPR.P
1237 //         Goto J
1238 //
1239 //    J: return
1240 //
1241 
1242 // CANFAULT
1243 
1244 word24 do_append_cycle (processor_cycle_type thisCycle, word36 * data,
1245                       uint nWords)
1246   {
1247     DCDstruct * i = & cpu.currentInstruction;
1248     DBGAPP ("do_append_cycle(Entry) thisCycle=%s\r\n",
1249             str_pct (thisCycle));
1250     DBGAPP ("do_append_cycle(Entry) lastCycle=%s\r\n",
1251             str_pct (cpu.apu.lastCycle));
1252     DBGAPP ("do_append_cycle(Entry) CA %06o\r\n",
1253             cpu.TPR.CA);
1254     DBGAPP ("do_append_cycle(Entry) n=%2u\r\n",
1255             nWords);
1256     DBGAPP ("do_append_cycle(Entry) PPR.PRR=%o PPR.PSR=%05o\r\n",
1257             cpu.PPR.PRR, cpu.PPR.PSR);
1258     DBGAPP ("do_append_cycle(Entry) TPR.TRR=%o TPR.TSR=%05o\r\n",
1259             cpu.TPR.TRR, cpu.TPR.TSR);
1260 
1261     if (i->b29)
1262       {
1263         DBGAPP ("do_append_cycle(Entry) isb29 PRNO %o\r\n",
1264                 GET_PRN (IWB_IRODD));
1265       }
1266 
1267     bool StrOp = (thisCycle == OPERAND_STORE ||
1268                   thisCycle == APU_DATA_STORE);
1269 
1270     bool nomatch = true;
1271     if (cpu.tweaks.enable_wam)
1272       {
1273         // AL39: The associative memory is ignored (forced to "no match") during
1274         // address preparation.
1275         // lptp,lptr,lsdp,lsdr,sptp,sptr,ssdp,ssdr
1276         // Unfortunately, ISOLTS doesn't try to execute any of these in append mode.
1277         // XXX should this be only for OPERAND_READ and OPERAND_STORE?
1278         nomatch = ((i->opcode == 0232 || i->opcode == 0254  ||
1279                     i->opcode == 0154 || i->opcode == 0173) &&   i->opcodeX) ||
1280                   ((i->opcode == 0557 || i->opcode == 0257) && ! i->opcodeX);
1281       }
1282 
1283     processor_cycle_type lastCycle = cpu.apu.lastCycle;
1284     cpu.apu.lastCycle = thisCycle;
1285 
1286     DBGAPP ("do_append_cycle(Entry) XSF %o\r\n", cpu.cu.XSF);
1287 
1288     PNL (L68_ (cpu.apu.state = 0;))
1289 
1290     cpu.RSDWH_R1 = 0;
1291 
1292     cpu.acvFaults = 0;
1293 
1294 //#define FMSG(x) x
1295 # define FMSG(x)
1296     FMSG (char * acvFaultsMsg = "<unknown>";)
1297 
1298     word24 finalAddress = (word24) -1;  // not everything requires a final
1299                                         // address
1300 
1301 ////////////////////////////////////////
1302 //
1303 // Sheet 1: "START APPEND"
1304 //
1305 ////////////////////////////////////////
1306 
1307 // START APPEND
1308     word3 n = 0; // PRn to be saved to TSN_PRNO
1309 
1310     // If the rtcd instruction is executed with the processor in absolute
1311     // mode with bit 29 of the instruction word set OFF and without
1312     // indirection through an ITP or ITS pair, then:
1313     //
1314     //   appending mode is entered for address preparation for the
1315     //   rtcd operand and is retained if the instruction executes
1316     //   successfully, and the effective segment number generated for
1317     //   the SDW fetch and subsequent loading into C(TPR.TSR) is equal
1318     //   to C(PPR.PSR) and may be undefined in absolute mode, and the
1319     //   effective ring number loaded into C(TPR.TRR) prior to the SDW
1320     //   fetch is equal to C(PPR.PRR) (which is 0 in absolute mode)
1321     //   implying that control is always transferred into ring 0.
1322     //
1323     if (thisCycle == RTCD_OPERAND_FETCH &&
1324         get_addr_mode() == ABSOLUTE_mode &&
1325         ! (cpu.cu.XSF || cpu.currentInstruction.b29) /*get_went_appending()*/)
1326       {
1327         cpu.TPR.TSR = 0;
1328         DBGAPP ("RTCD_OPERAND_FETCH ABSOLUTE mode set TSR %05o TRR %o\r\n",
1329                 cpu.TPR.TSR, cpu.TPR.TRR);
1330       }
1331 
1332     goto A;
1333 
1334 ////////////////////////////////////////
1335 //
1336 // Sheet 2: "A"
1337 //
1338 ////////////////////////////////////////
1339 
1340 //
1341 //  A:
1342 //    Get SDW
1343 
1344 A:;
1345 
1346     //PNL (cpu.APUMemAddr = address;)
1347     PNL (cpu.APUMemAddr = cpu.TPR.CA;)
1348 
1349     DBGAPP ("do_append_cycle(A)\r\n");
1350 
1351     // is SDW for C(TPR.TSR) in SDWAM?
1352     if (nomatch || ! fetch_sdw_from_sdwam (cpu.TPR.TSR))
1353       {
1354         // No
1355         DBGAPP ("do_append_cycle(A):SDW for segment %05o not in SDWAM\r\n",
1356                  cpu.TPR.TSR);
1357 
1358         DBGAPP ("do_append_cycle(A):DSBR.U=%o\r\n",
1359                 cpu.DSBR.U);
1360 
1361         if (cpu.DSBR.U == 0)
1362           {
1363             fetch_dsptw (cpu.TPR.TSR);
1364 
1365             if (! cpu.PTW0.DF)
1366               doFault (FAULT_DF0 + cpu.PTW0.FC, fst_zero,
1367                        "do_append_cycle(A): PTW0.F == 0");
1368 
1369             if (! cpu.PTW0.U)
1370               modify_dsptw (cpu.TPR.TSR);
1371 
1372             fetch_psdw (cpu.TPR.TSR);
1373           }
1374         else
1375           fetch_nsdw (cpu.TPR.TSR); // load SDW0 from descriptor segment table.
1376 
1377         if (cpu.SDW0.DF == 0)
1378           {
1379             if (thisCycle != ABSA_CYCLE)
1380               {
1381                 DBGAPP ("do_append_cycle(A): SDW0.F == 0! "
1382                         "Initiating directed fault\r\n");
1383                 // initiate a directed fault ...
1384                 doFault (FAULT_DF0 + cpu.SDW0.FC, fst_zero, "SDW0.F == 0");
1385               }
1386           }
1387         // load SDWAM .....
1388         load_sdwam (cpu.TPR.TSR, nomatch);
1389       }
1390     DBGAPP ("do_append_cycle(A) R1 %o R2 %o R3 %o E %o\r\n",
1391             cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3, cpu.SDW->E);
1392 
1393     // Yes...
1394     cpu.RSDWH_R1 = cpu.SDW->R1;
1395 
1396 ////////////////////////////////////////
1397 //
1398 // Sheet 3: "B"
1399 //
1400 ////////////////////////////////////////
1401 
1402 //
1403 // B: Check the ring
1404 //
1405 
1406     DBGAPP ("do_append_cycle(B)\r\n");
1407 
1408     // check ring bracket consistency
1409 
1410     //C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)?
1411     if (! (cpu.SDW->R1 <= cpu.SDW->R2 && cpu.SDW->R2 <= cpu.SDW->R3))
1412       {
1413         // Set fault ACV0 = IRO
1414         cpu.acvFaults |= ACV0;
1415         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1416         FMSG (acvFaultsMsg = "acvFaults(B) C(SDW.R1) <= C(SDW.R2) <= "
1417                               "C(SDW .R3)";)
1418       }
1419 
1420     // lastCycle == RTCD_OPERAND_FETCH
1421     // if a fault happens between the RTCD_OPERAND_FETCH and the INSTRUCTION_FETCH
1422     // of the next instruction - this happens about 35 time for just booting  and
1423     // shutting down Multics -- a stored lastCycle is useless.
1424     // the opcode is preserved across faults and only replaced as the
1425     // INSTRUCTION_FETCH succeeds.
1426     if (thisCycle == INSTRUCTION_FETCH &&
1427         i->opcode == 0610  && ! i->opcodeX)
1428       goto C;
1429     else if (lastCycle == RTCD_OPERAND_FETCH)
1430       sim_warn ("%s: lastCycle == RTCD_OPERAND_FETCH opcode %0#o\r\n", __func__, i->opcode);
1431 
1432     //
1433     // B1: The operand is one of: an instruction, data to be read or data to be
1434     //     written
1435     //
1436 
1437     // Is OPCODE call6?
1438     if (thisCycle == OPERAND_READ && (i->info->flags & CALL6_INS))
1439       goto E;
1440 
1441 
1442 
1443 
1444 
1445 
1446 
1447 
1448 
1449 
1450 
1451 
1452 
1453 
1454 
1455 
1456 
1457 
1458 
1459 
1460 
1461 
1462     // Transfer or instruction fetch?
1463     if (thisCycle == INSTRUCTION_FETCH ||
1464         (thisCycle == OPERAND_READ && (i->info->flags & TRANSFER_INS)))
1465       goto F;
1466 
1467     //
1468     // check read bracket for read access
1469     //
1470 
1471 # if defined(LOCKLESS)
1472     if (!StrOp || thisCycle == OPERAND_RMW || thisCycle == APU_DATA_RMW) // -V560
1473 # else
1474     if (!StrOp)
1475 # endif /* if defined(LOCKLESS) */
1476       {
1477         DBGAPP ("do_append_cycle(B):!STR-OP\r\n");
1478 
1479         // No
1480         // C(TPR.TRR) > C(SDW .R2)?
1481         if (cpu.TPR.TRR > cpu.SDW->R2)
1482           {
1483             DBGAPP ("ACV3\r\n");
1484             DBGAPP ("do_append_cycle(B) ACV3\r\n");
1485             //Set fault ACV3 = ORB
1486             cpu.acvFaults |= ACV3;
1487             PNL (L68_ (cpu.apu.state |= apu_FLT;))
1488             FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R2)";)
1489           }
1490 
1491         if (cpu.SDW->R == 0)
1492           {
1493             // isolts 870
1494             cpu.TPR.TRR = cpu.PPR.PRR;
1495 
1496             //C(PPR.PSR) = C(TPR.TSR)?
1497             if (cpu.PPR.PSR != cpu.TPR.TSR)
1498               {
1499                 DBGAPP ("ACV4\r\n");
1500                 DBGAPP ("do_append_cycle(B) ACV4\r\n");
1501                 //Set fault ACV4 = R-OFF
1502                 cpu.acvFaults |= ACV4;
1503                 PNL (L68_ (cpu.apu.state |= apu_FLT;))
1504                 FMSG (acvFaultsMsg = "acvFaults(B) C(PPR.PSR) = C(TPR.TSR)";)
1505               }
1506 
1507 
1508 
1509 
1510 
1511 
1512           }
1513       }
1514 
1515     //
1516     // check write bracket for write access
1517     //
1518 # if defined(LOCKLESS)
1519     if (StrOp || thisCycle == OPERAND_RMW || thisCycle == APU_DATA_RMW)
1520 # else
1521     if (StrOp)
1522 # endif /* if defined(LOCKLESS) */
1523       {
1524         DBGAPP ("do_append_cycle(B):STR-OP\r\n");
1525 
1526         // isolts 870
1527         if (cpu.TPR.TSR == cpu.PPR.PSR)
1528             cpu.TPR.TRR = cpu.PPR.PRR;
1529 
1530         // C(TPR.TRR) > C(SDW .R1)? Note typo in AL39, R2 should be R1
1531         if (cpu.TPR.TRR > cpu.SDW->R1)
1532           {
1533             DBGAPP ("ACV5 TRR %o R1 %o\r\n",
1534                     cpu.TPR.TRR, cpu.SDW->R1);
1535             //Set fault ACV5 = OWB
1536             cpu.acvFaults |= ACV5;
1537             PNL (L68_ (cpu.apu.state |= apu_FLT;))
1538             FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R1)";)
1539           }
1540 
1541         if (! cpu.SDW->W)
1542           {
1543             // isolts 870
1544             cpu.TPR.TRR = cpu.PPR.PRR;
1545 
1546             DBGAPP ("ACV6\r\n");
1547             // Set fault ACV6 = W-OFF
1548             cpu.acvFaults |= ACV6;
1549             PNL (L68_ (cpu.apu.state |= apu_FLT;))
1550             FMSG (acvFaultsMsg = "acvFaults(B) ACV6 = W-OFF";)
1551           }
1552 
1553       }
1554     goto G;
1555 
1556 ////////////////////////////////////////
1557 //
1558 // Sheet 4: "C" "D"
1559 //
1560 ////////////////////////////////////////
1561 
1562 C:;
1563     DBGAPP ("do_append_cycle(C)\r\n");
1564 
1565     //
1566     // check ring bracket for instruction fetch after rtcd instruction
1567     //
1568     //   allow outbound transfers (cpu.TPR.TRR >= cpu.PPR.PRR)
1569     //
1570 
1571     // C(TPR.TRR) < C(SDW.R1)?
1572     // C(TPR.TRR) > C(SDW.R2)?
1573     if (cpu.TPR.TRR < cpu.SDW->R1 ||
1574         cpu.TPR.TRR > cpu.SDW->R2)
1575       {
1576         DBGAPP ("ACV1 c\r\n");
1577         DBGAPP ("acvFaults(C) ACV1 ! ( C(SDW .R1) %o <= C(TPR.TRR) %o <= C(SDW .R2) %o )\r\n",
1578                 cpu.SDW->R1, cpu.TPR.TRR, cpu.SDW->R2);
1579         //Set fault ACV1 = OEB
1580         cpu.acvFaults |= ACV1;
1581         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1582         FMSG (acvFaultsMsg = "acvFaults(C) C(SDW.R1 > C(TPR.TRR) > C(SDW.R2)";)
1583       }
1584     // SDW.E set ON?
1585     if (! cpu.SDW->E)
1586       {
1587         DBGAPP ("ACV2 a\r\n");
1588         DBGAPP ("do_append_cycle(C) ACV2\r\n");
1589         //Set fault ACV2 = E-OFF
1590         cpu.acvFaults |= ACV2;
1591         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1592         FMSG (acvFaultsMsg = "acvFaults(C) SDW.E";)
1593       }
1594     if (cpu.TPR.TRR > cpu.PPR.PRR)
1595       sim_warn ("rtcd: outbound call cpu.TPR.TRR %d cpu.PPR.PRR %d\r\n",
1596                 cpu.TPR.TRR, cpu.PPR.PRR);
1597     // C(TPR.TRR) >= C(PPR.PRR)
1598     if (cpu.TPR.TRR < cpu.PPR.PRR)
1599       {
1600         DBGAPP ("ACV11\r\n");
1601         DBGAPP ("do_append_cycle(C) ACV11\r\n");
1602         //Set fault ACV11 = INRET
1603         cpu.acvFaults |= ACV11;
1604         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1605         FMSG (acvFaultsMsg = "acvFaults(C) TRR>=PRR";)
1606       }
1607 
1608 D:;
1609     DBGAPP ("do_append_cycle(D)\r\n");
1610 
1611     // transfer or instruction fetch
1612 
1613     // check ring alarm to catch outbound transfers
1614 
1615     if (cpu.rRALR == 0)
1616         goto G;
1617 
1618     // C(PPR.PRR) < RALR?
1619     if (! (cpu.PPR.PRR < cpu.rRALR))
1620       {
1621         DBGAPP ("ACV13\r\n");
1622         DBGAPP ("acvFaults(D) C(PPR.PRR) %o < RALR %o\r\n",
1623                 cpu.PPR.PRR, cpu.rRALR);
1624         cpu.acvFaults |= ACV13;
1625         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1626         FMSG (acvFaultsMsg = "acvFaults(D) C(PPR.PRR) < RALR";)
1627       }
1628 
1629     goto G;
1630 
1631 ////////////////////////////////////////
1632 //
1633 // Sheet 5: "E"
1634 //
1635 ////////////////////////////////////////
1636 
1637 E:;
1638 
1639     //
1640     // check ring bracket for instruction fetch after call6 instruction
1641     //   (this is the call6 read operand)
1642     //
1643 
1644     DBGAPP ("do_append_cycle(E): CALL6\r\n");
1645     DBGAPP ("do_append_cycle(E): E %o G %o PSR %05o TSR %05o CA %06o "
1646             "EB %06o R %o%o%o TRR %o PRR %o\r\n",
1647             cpu.SDW->E, cpu.SDW->G, cpu.PPR.PSR, cpu.TPR.TSR, cpu.TPR.CA,
1648             cpu.SDW->EB, cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3,
1649             cpu.TPR.TRR, cpu.PPR.PRR);
1650 
1651     //SDW.E set ON?
1652     if (! cpu.SDW->E)
1653       {
1654         DBGAPP ("ACV2 b\r\n");
1655         DBGAPP ("do_append_cycle(E) ACV2\r\n");
1656         // Set fault ACV2 = E-OFF
1657         cpu.acvFaults |= ACV2;
1658         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1659         FMSG (acvFaultsMsg = "acvFaults(E) SDW .E set OFF";)
1660       }
1661 
1662     //SDW .G set ON?
1663     if (cpu.SDW->G)
1664       goto E1;
1665 
1666     // C(PPR.PSR) = C(TPR.TSR)?
1667     if (cpu.PPR.PSR == cpu.TPR.TSR && ! TST_I_ABS)
1668       goto E1;
1669 
1670     // XXX This doesn't seem right
1671     // EB is word 15; masking address makes no sense; rather 0-extend EB
1672     // Fixes ISOLTS 880-01
1673     if (cpu.TPR.CA >= (word18) cpu.SDW->EB)
1674       {
1675         DBGAPP ("ACV7\r\n");
1676         DBGAPP ("do_append_cycle(E) ACV7\r\n");
1677         // Set fault ACV7 = NO GA
1678         cpu.acvFaults |= ACV7;
1679         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1680         FMSG (acvFaultsMsg = "acvFaults(E) TPR.CA4-17 >= SDW.CL";)
1681       }
1682 
1683 E1:
1684     DBGAPP ("do_append_cycle(E1): CALL6 (cont'd)\r\n");
1685 
1686     // C(TPR.TRR) > SDW.R3?
1687     if (cpu.TPR.TRR > cpu.SDW->R3)
1688       {
1689         DBGAPP ("ACV8\r\n");
1690         DBGAPP ("do_append_cycle(E) ACV8\r\n");
1691         //Set fault ACV8 = OCB
1692         cpu.acvFaults |= ACV8;
1693         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1694         FMSG (acvFaultsMsg = "acvFaults(E1) C(TPR.TRR) > SDW.R3";)
1695       }
1696 
1697     // C(TPR.TRR) < SDW.R1?
1698     if (cpu.TPR.TRR < cpu.SDW->R1)
1699       {
1700         DBGAPP ("ACV9\r\n");
1701         DBGAPP ("do_append_cycle(E) ACV9\r\n");
1702         // Set fault ACV9 = OCALL
1703         cpu.acvFaults |= ACV9;
1704         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1705         FMSG (acvFaultsMsg = "acvFaults(E1) C(TPR.TRR) < SDW.R1";)
1706       }
1707 
1708     // C(TPR.TRR) > C(PPR.PRR)?
1709     if (cpu.TPR.TRR > cpu.PPR.PRR)
1710       {
1711         // C(PPR.PRR) < SDW.R2?
1712         if (cpu.PPR.PRR < cpu.SDW->R2)
1713           {
1714             DBGAPP ("ACV10\r\n");
1715             DBGAPP ("do_append_cycle(E) ACV10\r\n");
1716             // Set fault ACV10 = BOC
1717             cpu.acvFaults |= ACV10;
1718             PNL (L68_ (cpu.apu.state |= apu_FLT;))
1719             FMSG (acvFaultsMsg = "acvFaults(E1) C(TPR.TRR) > C(PPR.PRR) && "
1720                   "C(PPR.PRR) < SDW.R2";)
1721           }
1722       }
1723 
1724     DBGAPP ("do_append_cycle(E1): CALL6 TPR.TRR %o SDW->R2 %o\r\n",
1725             cpu.TPR.TRR, cpu.SDW->R2);
1726 
1727     // C(TPR.TRR) > SDW.R2?
1728     if (cpu.TPR.TRR > cpu.SDW->R2)
1729       {
1730         // SDW.R2 -> C(TPR.TRR)
1731         cpu.TPR.TRR = cpu.SDW->R2;
1732       }
1733 
1734     DBGAPP ("do_append_cycle(E1): CALL6 TPR.TRR %o\r\n", cpu.TPR.TRR);
1735 
1736     goto G;
1737 
1738 ////////////////////////////////////////
1739 //
1740 // Sheet 6: "F"
1741 //
1742 ////////////////////////////////////////
1743 
1744 F:;
1745     PNL (L68_ (cpu.apu.state |= apu_PIAU;))
1746     DBGAPP ("do_append_cycle(F): transfer or instruction fetch\r\n");
1747 
1748     //
1749     // check ring bracket for instruction fetch
1750     //
1751 
1752     // C(TPR.TRR) < C(SDW .R1)?
1753     // C(TPR.TRR) > C(SDW .R2)?
1754     if (cpu.TPR.TRR < cpu.SDW->R1 ||
1755         cpu.TPR.TRR > cpu.SDW->R2)
1756       {
1757         DBGAPP ("ACV1 a/b\r\n");
1758         DBGAPP ("acvFaults(F) ACV1 !( C(SDW .R1) %o <= C(TPR.TRR) %o <= C(SDW .R2) %o )\r\n",
1759                 cpu.SDW->R1, cpu.TPR.TRR, cpu.SDW->R2);
1760         cpu.acvFaults |= ACV1;
1761         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1762         FMSG (acvFaultsMsg = "acvFaults(F) C(TPR.TRR) < C(SDW .R1)";)
1763       }
1764     // SDW .E set ON?
1765     if (! cpu.SDW->E)
1766       {
1767         DBGAPP ("ACV2 c\r\n");
1768         DBGAPP ("do_append_cycle(F) ACV2\r\n");
1769         cpu.acvFaults |= ACV2;
1770         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1771         FMSG (acvFaultsMsg = "acvFaults(F) SDW .E set OFF";)
1772       }
1773 
1774     // C(PPR.PRR) = C(TPR.TRR)?
1775     if (cpu.PPR.PRR != cpu.TPR.TRR)
1776       {
1777         DBGAPP ("ACV12\r\n");
1778         DBGAPP ("do_append_cycle(F) ACV12\r\n");
1779         //Set fault ACV12 = CRT
1780         cpu.acvFaults |= ACV12;
1781         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1782         FMSG (acvFaultsMsg = "acvFaults(F) C(PPR.PRR) != C(TPR.TRR)";)
1783       }
1784 
1785     goto D;
1786 
1787 ////////////////////////////////////////
1788 //
1789 // Sheet 7: "G"
1790 //
1791 ////////////////////////////////////////
1792 
1793 G:;
1794 
1795     DBGAPP ("do_append_cycle(G)\r\n");
1796 
1797     //C(TPR.CA)0,13 > SDW.BOUND?
1798     if (((cpu.TPR.CA >> 4) & 037777) > cpu.SDW->BOUND)
1799       {
1800         DBGAPP ("ACV15\r\n");
1801         DBGAPP ("do_append_cycle(G) ACV15\r\n");
1802         cpu.acvFaults |= ACV15;
1803         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1804         FMSG (acvFaultsMsg = "acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND";)
1805         DBGAPP ("acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND\r\n"
1806                 "   CA %06o CA>>4 & 037777 %06o SDW->BOUND %06o",
1807                 cpu.TPR.CA, ((cpu.TPR.CA >> 4) & 037777), cpu.SDW->BOUND);
1808       }
1809 
1810     if (cpu.acvFaults)
1811       {
1812         DBGAPP ("do_append_cycle(G) acvFaults\r\n");
1813         PNL (L68_ (cpu.apu.state |= apu_FLT;))
1814         // Initiate an access violation fault
1815         doFault (FAULT_ACV, (_fault_subtype) {.fault_acv_subtype=cpu.acvFaults},
1816                  "ACV fault");
1817       }
1818 
1819     // is segment C(TPR.TSR) paged?
1820     if (cpu.SDW->U)
1821       goto H; // Not paged
1822 
1823     // Yes. segment is paged ...
1824     // is PTW for C(TPR.CA) in PTWAM?
1825 
1826     DBGAPP ("do_append_cycle(G) CA %06o\r\n", cpu.TPR.CA);
1827     if (nomatch ||
1828         ! fetch_ptw_from_ptwam (cpu.SDW->POINTER, cpu.TPR.CA))  //TPR.CA))
1829       {
1830         fetch_ptw (cpu.SDW, cpu.TPR.CA);
1831         if (! cpu.PTW0.DF)
1832           {
1833             if (thisCycle != ABSA_CYCLE)
1834               {
1835                 // initiate a directed fault
1836                 doFault (FAULT_DF0 + cpu.PTW0.FC, (_fault_subtype) {.bits=0},
1837                          "PTW0.F == 0");
1838               }
1839           }
1840         loadPTWAM (cpu.SDW->POINTER, cpu.TPR.CA, nomatch); // load PTW0 to PTWAM
1841       }
1842 
1843     // Prepage mode?
1844     // check for "uninterruptible" EIS instruction
1845     // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
1846     // ad2/3d,sb2/3d,mp2/3d,dv2/3d
1847     // DH03 p.8-13: probably also mve,btd,dtb
1848     if (i->opcodeX && ((i->opcode & 0770)== 0200|| (i->opcode & 0770) == 0220
1849         || (i->opcode & 0770)== 020|| (i->opcode & 0770) == 0300))
1850       {
1851         do_ptw2 (cpu.SDW, cpu.TPR.CA);
1852       }
1853     goto I;
1854 
1855 ////////////////////////////////////////
1856 //
1857 // Sheet 8: "H", "I"
1858 //
1859 ////////////////////////////////////////
1860 
1861 H:;
1862     DBGAPP ("do_append_cycle(H): FANP\r\n");
1863 
1864     PNL (L68_ (cpu.apu.state |= apu_FANP;))
1865 
1866 
1867 
1868 
1869 
1870 
1871 
1872 
1873 
1874     set_apu_status (apuStatus_FANP);
1875 
1876     DBGAPP ("do_append_cycle(H): SDW->ADDR=%08o CA=%06o\r\n",
1877             cpu.SDW->ADDR, cpu.TPR.CA);
1878 
1879     if (thisCycle == RTCD_OPERAND_FETCH &&
1880         get_addr_mode () == ABSOLUTE_mode &&
1881         ! (cpu.cu.XSF || cpu.currentInstruction.b29) /*get_went_appending ()*/)
1882       {
1883         finalAddress = cpu.TPR.CA;
1884       }
1885     else
1886       {
1887         finalAddress = (cpu.SDW->ADDR & 077777760) + cpu.TPR.CA;
1888         finalAddress &= 0xffffff;
1889       }
1890     PNL (cpu.APUMemAddr = finalAddress;)
1891 
1892     DBGAPP ("do_append_cycle(H:FANP): (%05o:%06o) finalAddress=%08o\r\n",
1893             cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
1894 
1895     //if (thisCycle == ABSA_CYCLE)
1896     //    goto J;
1897     goto HI;
1898 
1899 I:;
1900 
1901 // Set PTW.M
1902 
1903     DBGAPP ("do_append_cycle(I): FAP\r\n");
1904 # if defined(LOCKLESS)
1905     if ((StrOp ||
1906         thisCycle == OPERAND_RMW ||
1907         thisCycle == APU_DATA_RMW) && cpu.PTW->M == 0)  // is this the right way to do this?
1908 # else
1909     if (StrOp && cpu.PTW->M == 0)  // is this the right way to do this?
1910 # endif /* if defined(LOCKLESS) */
1911       {
1912        modify_ptw (cpu.SDW, cpu.TPR.CA);
1913       }
1914 
1915     // final address paged
1916     set_apu_status (apuStatus_FAP);
1917     PNL (L68_ (cpu.apu.state |= apu_FAP;))
1918 
1919     word24 y2 = cpu.TPR.CA % 1024;
1920 
1921     // AL39: The hardware ignores low order bits of the main memory page
1922     // address according to page size
1923     finalAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6) + y2;
1924     finalAddress &= 0xffffff;
1925     PNL (cpu.APUMemAddr = finalAddress;)
1926 
1927     L68_ (if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
1928       add_l68_APU_history (APUH_FAP);)
1929 
1930     DBGAPP ("do_append_cycle(H:FAP): (%05o:%06o) finalAddress=%08o\r\n",
1931             cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
1932 
1933     //if (thisCycle == ABSA_CYCLE)
1934     //    goto J;
1935     goto HI;
1936 
1937 HI:
1938     DBGAPP ("do_append_cycle(HI)\r\n");
1939 
1940     // isolts 870
1941     if (thisCycle != ABSA_CYCLE)
1942       {
1943         cpu.cu.XSF = 1;
1944         if (cpu.currentInstruction.b29)
1945           cpu.xsfScu = true;
1946         sim_debug (DBG_TRACEEXT, & cpu_dev, "loading of cpu.TPR.TSR sets XSF to 1\r\n");
1947       }
1948 
1949     if (thisCycle == OPERAND_STORE && cpu.useZone)
1950       {
1951         cache_write_zone (finalAddress, * data, str_pct (thisCycle));
1952       }
1953     else if (StrOp)
1954       {
1955         cache_writeN (finalAddress, data, nWords, str_pct (thisCycle));
1956       }
1957     else
1958       {
1959 # if defined(LOCKLESS)
1960         if ((thisCycle == OPERAND_RMW || thisCycle == APU_DATA_RMW) && nWords == 1)
1961           {
1962             cache_read_lock (finalAddress, data, str_pct (thisCycle));
1963           }
1964         else
1965           {
1966             if (thisCycle == OPERAND_RMW || thisCycle == APU_DATA_RMW)
1967               sim_warn("do_append_cycle: RMW nWords %d != 1\r\n", nWords);
1968             cache_readN (finalAddress, data, nWords, str_pct (thisCycle));
1969           }
1970 # else
1971         if (thisCycle != ABSA_CYCLE)
1972           cache_readN (finalAddress, data, nWords, str_pct (thisCycle));
1973 # endif /* if defined(LOCKLESS) */
1974       }
1975 
1976     // Was this an indirect word fetch?
1977     if (thisCycle == INDIRECT_WORD_FETCH)
1978       goto J;
1979 
1980     // Was this an rtcd operand fetch?
1981     if (thisCycle == RTCD_OPERAND_FETCH)
1982       goto K;
1983 
1984     // is OPCODE call6?
1985     if (thisCycle == OPERAND_READ && (i->info->flags & CALL6_INS))
1986       goto N;
1987 
1988     // Transfer or instruction fetch?
1989     if (thisCycle == INSTRUCTION_FETCH ||
1990         (thisCycle == OPERAND_READ && (i->info->flags & TRANSFER_INS)))
1991       goto L;
1992 
1993     // APU data movement?
1994     //  handled above
1995    goto Exit;
1996 
1997 ////////////////////////////////////////
1998 //
1999 // Sheet 9: "J"
2000 //
2001 ////////////////////////////////////////
2002 
2003 // Indirect operand fetch
2004 
2005 J:;
2006     DBGAPP ("do_append_cycle(J)\r\n");
2007 
2008     // ri or ir & TPC.CA even?
2009     word6 tag = GET_TAG (IWB_IRODD);
2010     if ((GET_TM (tag) == TM_IR || GET_TM (tag) == TM_RI) &&
2011         (cpu.TPR.CA & 1) == 0)
2012       {
2013         if (ISITS (* data))
2014           goto O;
2015         if (ISITP (* data))
2016           goto P;
2017       }
2018 
2019     // C(Y) tag == other indirect?
2020     //   TM_R never indirects
2021     //   TM_RI always indirects
2022     //   TM_IR always indirects
2023     //   TM_IT always indirects
2024 
2025 
2026 
2027 
2028 
2029 
2030 
2031 
2032 
2033 
2034 
2035 
2036 
2037 
2038 
2039 
2040 
2041 
2042 
2043 
2044 
2045 
2046 
2047 
2048 
2049 
2050 
2051 
2052     if ((* data) & 060)
2053 
2054       {
2055         // C(Y)0,17 -> C(IWB)0,17
2056         // C(Y)30,35 -> C(IWB)30,35
2057         // 0 -> C(IWB)29
2058         //updateIWB (GET_ADDR (* data), (* data) & MASK6);
2059         //cpu.cu.TSN_PRNO[0] = n;
2060         //cpu.cu.TSN_VALID[0] = 1;
2061 
2062       }
2063 
2064      goto Exit;
2065 
2066 ////////////////////////////////////////
2067 //
2068 // Sheet 10: "K", "L", "M", "N"
2069 //
2070 ////////////////////////////////////////
2071 
2072 K:; // RTCD operand fetch
2073     DBGAPP ("do_append_cycle(K)\r\n");
2074 
2075     word3 y = GET_ITS_RN (data);
2076 
2077     // C(Y-pair)3,17 -> C(PPR.PSR)
2078     // We set TSR here; TSR will be copied to PSR at KL
2079     cpu.TPR.TSR = GET_ITS_SEGNO (data);
2080 
2081     // Maximum of
2082     // C(Y-pair)18,20; C(TPR.TRR); C(SDW.R1) -> C(PPR.PRR)
2083     // We set TRR here as well
2084     cpu.PPR.PRR = cpu.TPR.TRR = max3 (y, cpu.TPR.TRR, cpu.RSDWH_R1);
2085 
2086     // C(Y-pair)36,53 -> C(PPR.IC)
2087     // We set CA here; copied to IC  at KL
2088     cpu.TPR.CA = GET_ITS_WORDNO (data);
2089 
2090     // If C(PPR.PRR) = 0 then C(SDW.P) -> C(PPR.P);
2091     //     otherwise 0 -> C(PPR.P)
2092     // Done at M
2093 
2094     goto KL;
2095 
2096 L:; // Transfer or instruction fetch
2097 
2098     DBGAPP ("do_append_cycle(L)\r\n");
2099 
2100     // Is OPCODE tspn?
2101     if (thisCycle == OPERAND_READ && (i->info->flags & TSPN_INS))
2102       {
2103         //word3 n;
2104         if (i->opcode <= 0273)
2105           n = (i->opcode & 3);
2106         else
2107           n = (i->opcode & 3) + 4;
2108 
2109         // C(PPR.PRR) -> C(PRn .RNR)
2110         // C(PPR.PSR) -> C(PRn .SNR)
2111         // C(PPR.IC)  -> C(PRn .WORDNO)
2112         // 000000     -> C(PRn .BITNO)
2113         cpu.PR[n].RNR = cpu.PPR.PRR;
2114 // According the AL39, the PSR is 'undefined' in absolute mode.
2115 // ISOLTS thinks means don't change the operand
2116         if (get_addr_mode () == APPEND_mode)
2117           cpu.PR[n].SNR = cpu.PPR.PSR;
2118         cpu.PR[n].WORDNO = (cpu.PPR.IC + 1) & MASK18;
2119         SET_PR_BITNO (n, 0);
2120 # if defined(TESTING)
2121         HDBGRegPRW (n, "app tspn");
2122 # endif /* if defined(TESTING) */
2123       }
2124 
2125     // lastCycle == RTCD_OPERAND_FETCH
2126 
2127     if (thisCycle == INSTRUCTION_FETCH &&
2128         i->opcode == 0610  && ! i->opcodeX)
2129       {
2130         // C(PPR.PRR) -> C(PRn.RNR) for n = (0, 1, ..., 7)
2131         // Use TRR here; PRR not set until KL
2132         CPTUR (cptUsePRn + 0);
2133         CPTUR (cptUsePRn + 1);
2134         CPTUR (cptUsePRn + 2);
2135         CPTUR (cptUsePRn + 3);
2136         CPTUR (cptUsePRn + 4);
2137         CPTUR (cptUsePRn + 5);
2138         CPTUR (cptUsePRn + 6);
2139         CPTUR (cptUsePRn + 7);
2140         cpu.PR[0].RNR =
2141         cpu.PR[1].RNR =
2142         cpu.PR[2].RNR =
2143         cpu.PR[3].RNR =
2144         cpu.PR[4].RNR =
2145         cpu.PR[5].RNR =
2146         cpu.PR[6].RNR =
2147         cpu.PR[7].RNR = cpu.TPR.TRR;
2148 # if defined(TESTING)
2149         HDBGRegPRW (0, "app rtcd");
2150         HDBGRegPRW (1, "app rtcd");
2151         HDBGRegPRW (2, "app rtcd");
2152         HDBGRegPRW (3, "app rtcd");
2153         HDBGRegPRW (4, "app rtcd");
2154         HDBGRegPRW (5, "app rtcd");
2155         HDBGRegPRW (6, "app rtcd");
2156         HDBGRegPRW (7, "app rtcd");
2157 # endif /* if defined(TESTING) */
2158       }
2159     goto KL;
2160 
2161 KL:
2162     DBGAPP ("do_append_cycle(KL)\r\n");
2163 
2164     // C(TPR.TSR) -> C(PPR.PSR)
2165     cpu.PPR.PSR   = cpu.TPR.TSR;
2166     // C(TPR.CA)  -> C(PPR.IC)
2167     cpu.PPR.IC    = cpu.TPR.CA;
2168 
2169     goto M;
2170 
2171 M: // Set P
2172     DBGAPP ("do_append_cycle(M)\r\n");
2173 
2174     // C(TPR.TRR) = 0?
2175     if (cpu.TPR.TRR == 0)
2176       {
2177         // C(SDW.P) -> C(PPR.P)
2178         cpu.PPR.P = cpu.SDW->P;
2179       }
2180     else
2181       {
2182         // 0 C(PPR.P)
2183         cpu.PPR.P = 0;
2184       }
2185 
2186     goto Exit;
2187 
2188 N: // CALL6
2189     DBGAPP ("do_append_cycle(N)\r\n");
2190 
2191     // C(TPR.TRR) = C(PPR.PRR)?
2192     if (cpu.TPR.TRR == cpu.PPR.PRR)
2193       {
2194         // C(PR6.SNR) -> C(PR7.SNR)
2195         cpu.PR[7].SNR = cpu.PR[6].SNR;
2196         DBGAPP ("do_append_cycle(N) PR7.SNR = PR6.SNR %05o\r\n", cpu.PR[7].SNR);
2197       }
2198     else
2199       {
2200         // C(DSBR.STACK) || C(TPR.TRR) -> C(PR7.SNR)
2201         cpu.PR[7].SNR = ((word15) (cpu.DSBR.STACK << 3)) | cpu.TPR.TRR;
2202         DBGAPP ("do_append_cycle(N) STACK %05o TRR %o\r\n",
2203                 cpu.DSBR.STACK, cpu.TPR.TRR);
2204         DBGAPP ("do_append_cycle(N) PR7.SNR = STACK||TRR  %05o\r\n", cpu.PR[7].SNR);
2205       }
2206 
2207     // C(TPR.TRR) -> C(PR7.RNR)
2208     cpu.PR[7].RNR = cpu.TPR.TRR;
2209     // 00...0 -> C(PR7.WORDNO)
2210     cpu.PR[7].WORDNO = 0;
2211     // 000000 -> C(PR7.BITNO)
2212     SET_PR_BITNO (7, 0);
2213 # if defined(TESTING)
2214     HDBGRegPRW (7, "app call6");
2215 # endif /* if defined(TESTING) */
2216     // C(TPR.TRR) -> C(PPR.PRR)
2217     cpu.PPR.PRR   = cpu.TPR.TRR;
2218     // C(TPR.TSR) -> C(PPR.PSR)
2219     cpu.PPR.PSR   = cpu.TPR.TSR;
2220     // C(TPR.CA)  -> C(PPR.IC)
2221     cpu.PPR.IC    = cpu.TPR.CA;
2222 
2223     goto M;
2224 
2225 ////////////////////////////////////////
2226 //
2227 // Sheet 11: "O", "P"
2228 //
2229 ////////////////////////////////////////
2230 
2231 O:; // ITS, RTCD
2232     DBGAPP ("do_append_cycle(O)\r\n");
2233     word3 its_RNR = GET_ITS_RN (data);
2234     DBGAPP ("do_append_cycle(O) TRR %o RSDWH.R1 %o ITS.RNR %o\r\n",
2235             cpu.TPR.TRR, cpu.RSDWH_R1, its_RNR);
2236 
2237     // Maximum of
2238     //  C(Y)18,20;  C(TPR.TRR); C(SDW.R1) -> C(TPR.TRR)
2239     cpu.TPR.TRR = max3 (its_RNR, cpu.TPR.TRR, cpu.RSDWH_R1);
2240     DBGAPP ("do_append_cycle(O) Set TRR to %o\r\n", cpu.TPR.TRR);
2241 
2242     goto Exit;
2243 
2244 P:; // ITP
2245 
2246     DBGAPP ("do_append_cycle(P)\r\n");
2247 
2248     n = GET_ITP_PRNUM (data);
2249     DBGAPP ("do_append_cycle(P) TRR %o RSDWH.R1 %o PR[n].RNR %o\r\n",
2250             cpu.TPR.TRR, cpu.RSDWH_R1, cpu.PR[n].RNR);
2251 
2252     // Maximum of
2253     // cpu.PR[n].RNR;  C(TPR.TRR); C(SDW.R1) -> C(TPR.TRR)
2254     cpu.TPR.TRR = max3 (cpu.PR[n].RNR, cpu.TPR.TRR, cpu.RSDWH_R1);
2255     DBGAPP ("do_append_cycle(P) Set TRR to %o\r\n", cpu.TPR.TRR);
2256 
2257     goto Exit;
2258 
2259 Exit:;
2260 
2261     PNL (cpu.APUDataBusOffset = cpu.TPR.CA;)
2262     PNL (cpu.APUDataBusAddr = finalAddress;)
2263 
2264     PNL (L68_ (cpu.apu.state |= apu_FA;))
2265 
2266     DBGAPP ("do_append_cycle (Exit) PRR %o PSR %05o P %o IC %06o\r\n",
2267             cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
2268     DBGAPP ("do_append_cycle (Exit) TRR %o TSR %05o TBR %02o CA %06o\r\n",
2269             cpu.TPR.TRR, cpu.TPR.TSR, cpu.TPR.TBR, cpu.TPR.CA);
2270 
2271     return finalAddress;    // or 0 or -1???
2272   }
2273 #endif /* if defined(OLDAPP) */
2274 
2275 // Translate a segno:offset to a absolute address.
2276 // Return 0 if successful.
2277 
2278 #if defined(TESTING)
2279 int dbgLookupAddress (word18 segno, word18 offset, word24 * finalAddress,
     /* [previous][next][first][last][top][bottom][index][help] */
2280                       char * * msg)
2281   {
2282     cpu_state_t * cpup = _cpup;
2283     // Local copies so we don't disturb machine state
2284 
2285     ptw_s PTW1;
2286     sdw_s SDW1;
2287 
2288    if (2u * segno >= 16u * (cpu.DSBR.BND + 1u))
2289      {
2290        if (msg)
2291          * msg = "DSBR boundary violation.";
2292        return 1;
2293      }
2294 
2295     if (cpu.DSBR.U == 0)
2296       {
2297         // fetch_dsptw
2298 
2299         word24 y1 = (2 * segno) % 1024;
2300         word24 x1 = (2 * segno) / 1024; // floor
2301 
2302         word36 PTWx1;
2303         core_read (cpup, (cpu.DSBR.ADDR + x1) & PAMASK, & PTWx1, __func__); // NO_CACHE
2304 
2305         PTW1.ADDR = GETHI (PTWx1);
2306         PTW1.U = TSTBIT (PTWx1, 9);
2307         PTW1.M = TSTBIT (PTWx1, 6);
2308         PTW1.DF = TSTBIT (PTWx1, 2);
2309         PTW1.FC = PTWx1 & 3;
2310 
2311         if (! PTW1.DF)
2312           {
2313             if (msg)
2314               * msg = "!PTW0.F";
2315             return 2;
2316           }
2317 
2318         // fetch_psdw
2319 
2320         y1 = (2 * segno) % 1024;
2321 
2322         word36 SDWeven, SDWodd;
2323 
2324         core_read2 (cpup, ((((word24)PTW1. ADDR & 0777760) << 6) + y1) & PAMASK, // NO_CACHE
2325                     & SDWeven, & SDWodd, __func__);
2326 
2327         // even word
2328         SDW1.ADDR = (SDWeven >> 12) & 077777777;
2329         SDW1.R1   = (SDWeven >> 9)  & 7;
2330         SDW1.R2   = (SDWeven >> 6)  & 7;
2331         SDW1.R3   = (SDWeven >> 3)  & 7;
2332         SDW1.DF   = TSTBIT (SDWeven, 2);
2333         SDW1.FC   = SDWeven & 3;
2334 
2335         // odd word
2336         SDW1.BOUND = (SDWodd >> 21) & 037777;
2337         SDW1.R     = TSTBIT (SDWodd, 20);
2338         SDW1.E     = TSTBIT (SDWodd, 19);
2339         SDW1.W     = TSTBIT (SDWodd, 18);
2340         SDW1.P     = TSTBIT (SDWodd, 17);
2341         SDW1.U     = TSTBIT (SDWodd, 16);
2342         SDW1.G     = TSTBIT (SDWodd, 15);
2343         SDW1.C     = TSTBIT (SDWodd, 14);
2344         SDW1.EB    = SDWodd & 037777;
2345       }
2346     else // ! DSBR.U
2347       {
2348         // fetch_nsdw
2349 
2350         word36 SDWeven, SDWodd;
2351 
2352         core_read2 (cpup, (cpu.DSBR.ADDR + 2 * segno) & PAMASK, // NO_CACHE
2353                     & SDWeven, & SDWodd, __func__);
2354 
2355         // even word
2356         SDW1.ADDR = (SDWeven >> 12) & 077777777;
2357         SDW1.R1   = (SDWeven >> 9)  & 7;
2358         SDW1.R2   = (SDWeven >> 6)  & 7;
2359         SDW1.R3   = (SDWeven >> 3)  & 7;
2360         SDW1.DF   = TSTBIT (SDWeven, 2);
2361         SDW1.FC   = SDWeven & 3;
2362 
2363         // odd word
2364         SDW1.BOUND = (SDWodd >> 21) & 037777;
2365         SDW1.R     = TSTBIT (SDWodd, 20);
2366         SDW1.E     = TSTBIT (SDWodd, 19);
2367         SDW1.W     = TSTBIT (SDWodd, 18);
2368         SDW1.P     = TSTBIT (SDWodd, 17);
2369         SDW1.U     = TSTBIT (SDWodd, 16);
2370         SDW1.G     = TSTBIT (SDWodd, 15);
2371         SDW1.C     = TSTBIT (SDWodd, 14);
2372         SDW1.EB    = SDWodd & 037777;
2373 
2374       }
2375 
2376     if (SDW1.DF == 0)
2377       {
2378         if (msg)
2379           * msg = "!SDW0.F != 0";
2380         return 3;
2381       }
2382 
2383     if (((offset >> 4) & 037777) > SDW1.BOUND)
2384       {
2385         if (msg)
2386           * msg = "C(TPR.CA)0,13 > SDW.BOUND";
2387         return 4;
2388       }
2389 
2390     // is segment C(TPR.TSR) paged?
2391     if (SDW1.U)
2392       {
2393         * finalAddress = (SDW1.ADDR + offset) & PAMASK;
2394       }
2395     else
2396       {
2397         // fetch_ptw
2398         word24 y2 = offset % 1024;
2399         word24 x2 = (offset) / 1024; // floor
2400 
2401         word36 PTWx2;
2402 
2403         core_read (cpup, (SDW1.ADDR + x2) & PAMASK, & PTWx2, __func__); // NO_CACHE
2404 
2405         PTW1.ADDR = GETHI (PTWx2);
2406         PTW1.U    = TSTBIT (PTWx2, 9);
2407         PTW1.M    = TSTBIT (PTWx2, 6);
2408         PTW1.DF   = TSTBIT (PTWx2, 2);
2409         PTW1.FC   = PTWx2 & 3;
2410 
2411         if (! PTW1.DF)
2412           {
2413             if (msg)
2414               * msg = "!PTW0.F";
2415             return 5;
2416           }
2417 
2418         y2 = offset % 1024;
2419 
2420         * finalAddress = ((((word24)PTW1.ADDR & 0777760) << 6) + y2) & PAMASK;
2421       }
2422     if (msg)
2423       * msg = "";
2424     return 0;
2425   }
2426 #endif /* if defined(TESTING) */

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