root/src/dps8/doAppendCycleIndirectWordFetch.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. doAppendCycleIndirectWordFetch_

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 501f8fe6-171d-11ee-ab15-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2022-2023 Charles Anthony
   9  * Copyright (c) 2022-2024 Jeffrey H. Johnson
  10  * Copyright (c) 2022-2025 The DPS8M Development Team
  11  *
  12  * This software is made available under the terms of the ICU License.
  13  * See the LICENSE.md file at the top-level directory of this distribution.
  14  *
  15  * ---------------------------------------------------------------------------
  16  */
  17 
  18 //  Indirect word fetch
  19 //
  20 //     A: Get SDW
  21 //         |
  22 //         V
  23 //     B: Check the ring
  24 //         |
  25 //         V
  26 //     G: Check BOUND
  27 //        Paged? No-------------------+
  28 //          Yes                       |
  29 //           |                        |
  30 //           V                        |
  31 //        Get PTW                     |
  32 //           |                        |
  33 //           V                        V
  34 //     I: Compute final address   H: Compute final address
  35 //           |                        |
  36 //           <------------------------+
  37 //           |
  38 //           V
  39 //     HI: Read data
  40 //           |
  41 //           V
  42 //     J: ITS? Yes------------------+
  43 //        ITP? Yes----+             |
  44 //          |         |             |
  45 //          |         V             V
  46 //          |       P: ITP        O: ITS
  47 //          |       Update TRR     Update TRR
  48 //          |         |             |
  49 //          +<--------+-------------+
  50 //          |
  51 //          V
  52 //        Exit: return final address
  53 
  54 // Compiled twice (see FULL_MODEL_ON and dps8_append.c)
  55 static ALWAYS_INLINE word24 doAppendCycleIndirectWordFetch_ (cpu_state_t * cpup, word36 * data, uint nWords, const bool full) {
     /* [previous][next][first][last][top][bottom][index][help] */
  56   DCDstruct * i = & cpu.currentInstruction;
  57   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) thisCycle=INDIRECT_WORD_FETCH\r\n");
  58   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) lastCycle=%s\r\n", str_pct (cpu.apu.lastCycle));
  59   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) CA %06o\r\n", cpu.TPR.CA);
  60   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) n=%2u\r\n", nWords);
  61   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) PPR.PRR=%o PPR.PSR=%05o\r\n", cpu.PPR.PRR, cpu.PPR.PSR);
  62   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) TPR.TRR=%o TPR.TSR=%05o\r\n", cpu.TPR.TRR, cpu.TPR.TSR);
  63 
  64   if (i->b29) {
  65     DBGAPP ("doAppendCycleIndirectWordFetch(Entry) isb29 PRNO %o\r\n", GET_PRN (IWB_IRODD));
  66   }
  67 
  68   uint this = UC_INDIRECT_WORD_FETCH;
  69 
  70   word24 finalAddress = 0;
  71   word24 pageAddress = 0;
  72   word3 RSDWH_R1 = 0;
  73   word14 bound = 0;
  74   word1 p = 0;
  75   bool paged = false;
  76 
  77 /* Indirect Word Fetch Cache disabled (due to it not working!) */
  78 #undef IDWF_CACHE
  79 //# define IDWF_CACHE 1
  80 #if defined(IDWF_CACHE)
  81 // Is this cycle a candidate for ucache?
  82 
  83   // Prepage mode?
  84   // check for "uninterruptible" EIS instruction
  85   // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
  86   // ad2/3d,sb2/3d,mp2/3d,dv2/3d
  87   // DH03 p.8-13: probably also mve,btd,dtb
  88   if (i->opcodeX && ((i->opcode & 0770)== 0200|| (i->opcode & 0770) == 0220
  89       || (i->opcode & 0770)== 020|| (i->opcode & 0770) == 0300)) {
  90     //sim_printf ("skip uninterruptible\r\n");
  91     goto skip_ucache;
  92   }
  93 
  94 // Yes; check the ucache
  95   if (! ucCacheCheck (this, cpu.TPR.TSR, cpu.TPR.CA, & bound, & p, & pageAddress, & RSDWH_R1, & paged))
  96     goto miss_ucache;
  97 
  98   if (paged) {
  99     finalAddress = pageAddress + (cpu.TPR.CA & OS18MASK);
 100   } else {
 101     finalAddress = pageAddress + cpu.TPR.CA;
 102   }
 103   cpu.RSDWH_R1 = RSDWH_R1;
 104 
 105   // the APU status of the cycle, as the miss path sets it (PA865 03A)
 106   if (full)   // (3), see FULL_MODEL_ON
 107     set_apu_status (cpup, paged ? apuStatus_FAP : apuStatus_FANP);
 108   cpu.apu.lastCycle = INDIRECT_WORD_FETCH;
 109   goto HI;
 110 
 111 skip_ucache:;
 112 # if defined(UCACHE_STATS)
 113   cpu.uCache.skips[this] ++;
 114 # endif
 115 
 116 miss_ucache:;
 117 
 118 #endif /* if defined(IDWF_CACHE) */
 119 
 120   bool nomatch = true;
 121   if (cpu.tweaks.enable_wam) {
 122     // AL39: The associative memory is ignored (forced to "no match") during
 123     // address preparation.
 124     // lptp,lptr,lsdp,lsdr,sptp,sptr,ssdp,ssdr
 125     // Unfortunately, ISOLTS doesn't try to execute any of these in append mode.
 126     // XXX should this be only for OPERAND_READ and OPERAND_STORE?
 127     nomatch = ((i->opcode == 0232 || i->opcode == 0254 ||
 128                 i->opcode == 0154 || i->opcode == 0173) &&
 129                 i->opcodeX ) ||
 130                ((i->opcode == 0557 || i->opcode == 0257) &&
 131                 ! i->opcodeX);
 132   }
 133 
 134   processor_cycle_type lastCycle = cpu.apu.lastCycle;
 135   cpu.apu.lastCycle = INDIRECT_WORD_FETCH;
 136 
 137   DBGAPP ("doAppendCycleIndirectWordFetch(Entry) XSF %o\r\n", cpu.cu.XSF);
 138 
 139   PNL (L68_ (cpu.apu.state = 0;))
 140 
 141   cpu.RSDWH_R1 = 0;
 142 
 143   cpu.acvFaults = 0;
 144 
 145 //#define FMSG(x) x
 146 #define FMSG(x)
 147   FMSG (char * acvFaultsMsg = "<unknown>";)
 148 
 149 ////////////////////////////////////////
 150 //
 151 // Sheet 1: "START APPEND"
 152 //
 153 ////////////////////////////////////////
 154 
 155 // START APPEND
 156   word3 n = 0; // PRn to be saved to TSN_PRNO
 157 
 158 ////////////////////////////////////////
 159 //
 160 // Sheet 2: "A"
 161 //
 162 ////////////////////////////////////////
 163 
 164 //
 165 //  A:
 166 //    Get SDW
 167 
 168   //PNL (cpu.APUMemAddr = address;)
 169   PNL (cpu.APUMemAddr = cpu.TPR.CA;)
 170 
 171   DBGAPP ("doAppendCycleIndirectWordFetch(A)\r\n");
 172 
 173   // is SDW for C(TPR.TSR) in SDWAM?
 174   if (nomatch || ! fetch_sdw_from_sdwam (cpup, cpu.TPR.TSR)) {
 175     // No
 176     DBGAPP ("doAppendCycleIndirectWordFetch(A):SDW for segment %05o not in SDWAM\r\n", cpu.TPR.TSR);
 177     DBGAPP ("doAppendCycleIndirectWordFetch(A):DSBR.U=%o\r\n", cpu.DSBR.U);
 178 
 179     if (cpu.DSBR.U == 0) {
 180       fetch_dsptw (cpup, cpu.TPR.TSR);
 181 
 182       if (! cpu.PTW0.DF)
 183         doFault (FAULT_DF0 + cpu.PTW0.FC, fst_zero, "doAppendCycleIndirectWordFetch(A): PTW0.F == 0");
 184 
 185       if (! cpu.PTW0.U)
 186           modify_dsptw (cpup, cpu.TPR.TSR);
 187 
 188       fetch_psdw (cpup, cpu.TPR.TSR);
 189     } else
 190       fetch_nsdw (cpup, cpu.TPR.TSR); // load SDW0 from descriptor segment table.
 191 
 192     if (cpu.SDW0.DF == 0) {
 193       DBGAPP ("doAppendCycleIndirectWordFetch(A): SDW0.F == 0! " "Initiating directed fault\r\n");
 194       // initiate a directed fault ...
 195       doFault (FAULT_DF0 + cpu.SDW0.FC, fst_zero, "SDW0.F == 0");
 196     }
 197     // load SDWAM .....
 198     load_sdwam (cpup, cpu.TPR.TSR, nomatch);
 199   }
 200   DBGAPP ("doAppendCycleIndirectWordFetch(A) R1 %o R2 %o R3 %o E %o\r\n", cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3, cpu.SDW->E);
 201 
 202   // Yes...
 203   RSDWH_R1 = cpu.RSDWH_R1 = cpu.SDW->R1;
 204 
 205 ////////////////////////////////////////
 206 //
 207 // Sheet 3: "B"
 208 //
 209 ////////////////////////////////////////
 210 
 211 //
 212 // B: Check the ring
 213 //
 214 
 215   DBGAPP ("doAppendCycleIndirectWordFetch(B)\r\n");
 216 
 217   // check ring bracket consistency
 218 
 219   //C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)?
 220   if (! (cpu.SDW->R1 <= cpu.SDW->R2 && cpu.SDW->R2 <= cpu.SDW->R3)) {
 221     // Set fault ACV0 = IRO
 222     cpu.acvFaults |= ACV0;
 223     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 224     FMSG (acvFaultsMsg = "acvFaults(B) C(SDW.R1) <= C(SDW.R2) <= " "C(SDW .R3)";)
 225   }
 226 
 227   // lastCycle == RTCD_OPERAND_FETCH
 228   // if a fault happens between the RTCD_OPERAND_FETCH and the INSTRUCTION_FETCH
 229   // of the next instruction - this happens about 35 time for just booting  and
 230   // shutting down multics -- a stored lastCycle is useless.
 231   // the opcode is preserved across faults and only replaced as the
 232   // INSTRUCTION_FETCH succeeds.
 233   if (lastCycle == RTCD_OPERAND_FETCH)
 234     sim_warn ("%s: lastCycle == RTCD_OPERAND_FETCH opcode %0#o\r\n", __func__, i->opcode);
 235 
 236   //
 237   // B1: The operand is one of: an instruction, data to be read or data to be
 238   //     written
 239   //
 240 
 241   //
 242   // check read bracket for read access
 243   //
 244 
 245   DBGAPP ("doAppendCycleIndirectWordFetch(B):!STR-OP\r\n");
 246 
 247   // No
 248   // C(TPR.TRR) > C(SDW .R2)?
 249   if (cpu.TPR.TRR > cpu.SDW->R2) {
 250     DBGAPP ("ACV3\r\n");
 251     DBGAPP ("doAppendCycleIndirectWordFetch(B) ACV3\r\n");
 252     //Set fault ACV3 = ORB
 253     cpu.acvFaults |= ACV3;
 254     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 255     FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R2)";)
 256   }
 257 
 258   if (cpu.SDW->R == 0) {
 259     // isolts 870
 260     cpu.TPR.TRR = cpu.PPR.PRR;
 261 
 262     //C(PPR.PSR) = C(TPR.TSR)?
 263     if (cpu.PPR.PSR != cpu.TPR.TSR) {
 264       DBGAPP ("ACV4\r\n");
 265       DBGAPP ("doAppendCycleIndirectWordFetch(B) ACV4\r\n");
 266       //Set fault ACV4 = R-OFF
 267       cpu.acvFaults |= ACV4;
 268       PNL (L68_ (cpu.apu.state |= apu_FLT;))
 269       FMSG (acvFaultsMsg = "acvFaults(B) C(PPR.PSR) = C(TPR.TSR)";)
 270     //} else {
 271       // sim_warn ("doAppendCycleIndirectWordFetch(B) SDW->R == 0 && cpu.PPR.PSR == cpu.TPR.TSR: %0#o\r\n",
 272       //           cpu.PPR.PSR);
 273     }
 274   }
 275 
 276 //  goto G;
 277 
 278 ////////////////////////////////////////
 279 //
 280 // Sheet 7: "G"
 281 //
 282 ////////////////////////////////////////
 283 
 284 //G:;
 285 
 286   DBGAPP ("doAppendCycleIndirectWordFetch(G)\r\n");
 287 
 288   //C(TPR.CA)0,13 > SDW.BOUND?
 289   if (((cpu.TPR.CA >> 4) & 037777) > cpu.SDW->BOUND) {
 290     DBGAPP ("ACV15\r\n");
 291     DBGAPP ("doAppendCycleIndirectWordFetch(G) ACV15\r\n");
 292     cpu.acvFaults |= ACV15;
 293     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 294     FMSG (acvFaultsMsg = "acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND";)
 295     DBGAPP ("acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND\r\n" "   CA %06o CA>>4 & 037777 %06o SDW->BOUND %06o",
 296             cpu.TPR.CA, ((cpu.TPR.CA >> 4) & 037777), cpu.SDW->BOUND);
 297   }
 298   bound = cpu.SDW->BOUND;
 299   p = cpu.SDW->P;
 300 
 301   if (cpu.acvFaults) {
 302     DBGAPP ("doAppendCycleIndirectWordFetch(G) acvFaults\r\n");
 303     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 304     // Initiate an access violation fault
 305     doFault (FAULT_ACV, (_fault_subtype) {.fault_acv_subtype=cpu.acvFaults}, "ACV fault");
 306   }
 307 
 308   // is segment C(TPR.TSR) paged?
 309   if (cpu.SDW->U)
 310     goto H; // Not paged
 311 
 312   // Yes. segment is paged ...
 313   // is PTW for C(TPR.CA) in PTWAM?
 314 
 315   DBGAPP ("doAppendCycleIndirectWordFetch(G) CA %06o\r\n", cpu.TPR.CA);
 316   if (nomatch ||
 317       ! fetch_ptw_from_ptwam (cpup, cpu.SDW->POINTER, cpu.TPR.CA)) {
 318     fetch_ptw (cpup, cpu.SDW, cpu.TPR.CA);
 319     if (! cpu.PTW0.DF) {
 320       // initiate a directed fault
 321       doFault (FAULT_DF0 + cpu.PTW0.FC, (_fault_subtype) {.bits=0}, "PTW0.F == 0");
 322     }
 323     loadPTWAM (cpup, cpu.SDW->POINTER, cpu.TPR.CA, nomatch); // load PTW0 to PTWAM
 324   }
 325 
 326   // Prepage mode?
 327   // check for "uninterruptible" EIS instruction
 328   // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
 329   // ad2/3d,sb2/3d,mp2/3d,dv2/3d
 330   // DH03 p.8-13: probably also mve,btd,dtb
 331   if (i->opcodeX && ((i->opcode & 0770)== 0200|| (i->opcode & 0770) == 0220
 332       || (i->opcode & 0770)== 020|| (i->opcode & 0770) == 0300)) {
 333     do_ptw2 (cpup, cpu.SDW, cpu.TPR.CA);
 334   }
 335   goto I;
 336 
 337 ////////////////////////////////////////
 338 //
 339 // Sheet 8: "H", "I"
 340 //
 341 ////////////////////////////////////////
 342 
 343 H:;
 344   DBGAPP ("doAppendCycleIndirectWordFetch(H): FANP\r\n");
 345 
 346   paged = false;
 347 
 348   PNL (L68_ (cpu.apu.state |= apu_FANP;))
 349 
 350 
 351 
 352 
 353 
 354 
 355 
 356 
 357   set_apu_status (cpup, apuStatus_FANP);
 358 
 359   DBGAPP ("doAppendCycleIndirectWordFetch(H): SDW->ADDR=%08o CA=%06o \r\n", cpu.SDW->ADDR, cpu.TPR.CA);
 360 
 361   pageAddress = (cpu.SDW->ADDR & 077777760);
 362   finalAddress = (cpu.SDW->ADDR & 077777760) + cpu.TPR.CA;
 363   finalAddress &= 0xffffff;
 364   PNL (cpu.APUMemAddr = finalAddress;)
 365 
 366   DBGAPP ("doAppendCycleIndirectWordFetch(H:FANP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 367 
 368   goto HI;
 369 
 370 I:;
 371 
 372 // Set PTW.M
 373 
 374   DBGAPP ("doAppendCycleIndirectWordFetch(I): FAP\r\n");
 375 
 376   paged = true;
 377 
 378   // final address paged
 379   set_apu_status (cpup, apuStatus_FAP);
 380   PNL (L68_ (cpu.apu.state |= apu_FAP;))
 381 
 382   word24 y2 = cpu.TPR.CA % 1024;
 383 
 384   pageAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6);
 385   // AL39: The hardware ignores low order bits of the main memory page
 386   // address according to page size
 387   finalAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6) + y2;
 388   finalAddress &= 0xffffff;
 389   PNL (cpu.APUMemAddr = finalAddress;)
 390 
 391   L68_ (
 392     if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 393       add_l68_APU_history (cpup, APUH_FAP);
 394   )
 395 
 396   DBGAPP ("doAppendCycleIndirectWordFetch(H:FAP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 397 
 398   // goto HI;
 399 
 400 HI:
 401   DBGAPP ("doAppendCycleIndirectWordFetch(HI)\r\n");
 402 
 403   ucCacheSave (cpup, this, cpu.TPR.TSR, cpu.TPR.CA, bound, p, pageAddress, RSDWH_R1, paged);
 404 
 405   // isolts 870
 406   cpu.cu.XSF = 1;
 407   if (full)   // (1), see FULL_MODEL_ON
 408     cpu.xsfScu = true;
 409   sim_debug (DBG_TRACEEXT, & cpu_dev, "loading of cpu.TPR.TSR sets XSF to 1\r\n");
 410 
 411   if (full)
 412     cache_readN (cpup, finalAddress, data, nWords, "INDIRECT_WORD_FETCH");
 413   else
 414     core_readN_fast (cpup, finalAddress, data, nWords, "INDIRECT_WORD_FETCH");
 415 
 416 ////////////////////////////////////////
 417 //
 418 // Sheet 9: "J"
 419 //
 420 ////////////////////////////////////////
 421 
 422 // Indirect operand fetch
 423 
 424   DBGAPP ("doAppendCycleIndirectWordFetch(J)\r\n");
 425 
 426   // ri or ir & TPC.CA even?
 427   word6 tag = GET_TAG (IWB_IRODD);
 428   if ((GET_TM (tag) == TM_IR || GET_TM (tag) == TM_RI) && (cpu.TPR.CA & 1) == 0) {
 429     if (ISITS (* data))
 430       goto O;
 431     if (ISITP (* data))
 432       goto P;
 433   }
 434 
 435   goto Exit;
 436 
 437 ////////////////////////////////////////
 438 //
 439 // Sheet 11: "O", "P"
 440 //
 441 ////////////////////////////////////////
 442 
 443 O:; // ITS, RTCD
 444   DBGAPP ("doAppendCycleIndirectWordFetch(O)\r\n");
 445   word3 its_RNR = GET_ITS_RN (data);
 446   DBGAPP ("doAppendCycleIndirectWordFetch(O) TRR %o RSDWH.R1 %o ITS.RNR %o\r\n",
 447           cpu.TPR.TRR, cpu.RSDWH_R1, its_RNR);
 448 
 449   // Maximum of
 450   //  C(Y)18,20;  C(TPR.TRR); C(SDW.R1) -> C(TPR.TRR)
 451   cpu.TPR.TRR = max3 (its_RNR, cpu.TPR.TRR, cpu.RSDWH_R1);
 452   DBGAPP ("doAppendCycleIndirectWordFetch(O) Set TRR to %o\r\n", cpu.TPR.TRR);
 453 
 454   goto Exit;
 455 
 456 P:; // ITP
 457 
 458   DBGAPP ("doAppendCycleIndirectWordFetch(P)\r\n");
 459 
 460   n = GET_ITP_PRNUM (data);
 461   DBGAPP ("doAppendCycleIndirectWordFetch(P) TRR %o RSDWH.R1 %o PR[n].RNR %o\r\n",
 462           cpu.TPR.TRR, cpu.RSDWH_R1, cpu.PR[n].RNR);
 463 
 464   // Maximum of
 465   // cpu.PR[n].RNR;  C(TPR.TRR); C(SDW.R1) -> C(TPR.TRR)
 466   cpu.TPR.TRR = max3 (cpu.PR[n].RNR, cpu.TPR.TRR, cpu.RSDWH_R1);
 467   DBGAPP ("doAppendCycleIndirectWordFetch(P) Set TRR to %o\r\n", cpu.TPR.TRR);
 468 
 469   goto Exit;
 470 
 471 Exit:;
 472 
 473   PNL (cpu.APUDataBusOffset = cpu.TPR.CA;)
 474   PNL (cpu.APUDataBusAddr = finalAddress;)
 475 
 476   PNL (L68_ (cpu.apu.state |= apu_FA;))
 477 
 478   DBGAPP ("doAppendCycleIndirectWordFetch (Exit) PRR %o PSR %05o P %o IC %06o\r\n",
 479           cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
 480   DBGAPP ("doAppendCycleIndirectWordFetch (Exit) TRR %o TSR %05o TBR %02o CA %06o\r\n",
 481           cpu.TPR.TRR, cpu.TPR.TSR, cpu.TPR.TBR, cpu.TPR.CA);
 482 
 483   return finalAddress;
 484 }

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