root/src/dps8/doAppendCycleRTCDOperandFetch.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. doAppendCycleRTCDOperandFetch_

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 24c12472-171d-11ee-b2a6-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2022-2023 Charles Anthony
   9  * Copyright (c) 2022-2023 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 // Compiled twice (see FULL_MODEL_ON and dps8_append.c)
  19 static ALWAYS_INLINE word24 doAppendCycleRTCDOperandFetch_ (cpu_state_t * cpup, word36 * data, uint nWords, const bool full) {
     /* [previous][next][first][last][top][bottom][index][help] */
  20   DCDstruct * i = & cpu.currentInstruction;
  21   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) thisCycle=RTCD_OPERAND_FETCH\r\n");
  22   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) lastCycle=%s\r\n", str_pct (cpu.apu.lastCycle));
  23   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) CA %06o\r\n", cpu.TPR.CA);
  24   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) n=%2u\r\n", nWords);
  25   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) PPR.PRR=%o PPR.PSR=%05o\r\n", cpu.PPR.PRR, cpu.PPR.PSR);
  26   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) TPR.TRR=%o TPR.TSR=%05o\r\n", cpu.TPR.TRR, cpu.TPR.TSR);
  27 
  28   if (i->b29) {
  29     DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) isb29 PRNO %o\r\n", GET_PRN (IWB_IRODD));
  30   }
  31 
  32   bool nomatch = true;
  33   if (cpu.tweaks.enable_wam) {
  34     // AL39: The associative memory is ignored (forced to "no match") during
  35     // address preparation.
  36     // lptp,lptr,lsdp,lsdr,sptp,sptr,ssdp,ssdr
  37     // Unfortunately, ISOLTS doesn't try to execute any of these in append mode.
  38     // XXX should this be only for OPERAND_READ and OPERAND_STORE?
  39     nomatch = ((i->opcode == 0232 || i->opcode == 0254 ||
  40                 i->opcode == 0154 || i->opcode == 0173) &&
  41                 i->opcodeX ) ||
  42                ((i->opcode == 0557 || i->opcode == 0257) &&
  43                 ! i->opcodeX);
  44   }
  45 
  46   processor_cycle_type lastCycle = cpu.apu.lastCycle;
  47   cpu.apu.lastCycle = RTCD_OPERAND_FETCH;
  48 
  49   DBGAPP ("doAppendCycleRTCDOperandFetch(Entry) XSF %o\r\n", cpu.cu.XSF);
  50 
  51   PNL (L68_ (cpu.apu.state = 0;))
  52 
  53   cpu.RSDWH_R1 = 0;
  54 
  55   cpu.acvFaults = 0;
  56 
  57 //#define FMSG(x) x
  58 #define FMSG(x)
  59   FMSG (char * acvFaultsMsg = "<unknown>";)
  60 
  61   word24 finalAddress = (word24) -1;  // not everything requires a final
  62                                       // address
  63 
  64 ////////////////////////////////////////
  65 //
  66 // Sheet 1: "START APPEND"
  67 //
  68 ////////////////////////////////////////
  69 
  70 // START APPEND
  71 
  72   // If the rtcd instruction is executed with the processor in absolute
  73   // mode with bit 29 of the instruction word set OFF and without
  74   // indirection through an ITP or ITS pair, then:
  75   //
  76   //   appending mode is entered for address preparation for the
  77   //   rtcd operand and is retained if the instruction executes
  78   //   successfully, and the effective segment number generated for
  79   //   the SDW fetch and subsequent loading into C(TPR.TSR) is equal
  80   //   to C(PPR.PSR) and may be undefined in absolute mode, and the
  81   //   effective ring number loaded into C(TPR.TRR) prior to the SDW
  82   //   fetch is equal to C(PPR.PRR) (which is 0 in absolute mode)
  83   //   implying that control is always transferred into ring 0.
  84   //
  85   if (get_addr_mode(cpup) == ABSOLUTE_mode && ! (cpu.cu.XSF || cpu.currentInstruction.b29)) {
  86     cpu.TPR.TSR = 0;
  87     DBGAPP ("RTCD_OPERAND_FETCH ABSOLUTE mode set TSR %05o TRR %o\r\n", cpu.TPR.TSR, cpu.TPR.TRR);
  88   }
  89 
  90   goto A;
  91 
  92 ////////////////////////////////////////
  93 //
  94 // Sheet 2: "A"
  95 //
  96 ////////////////////////////////////////
  97 
  98 //
  99 //  A:
 100 //    Get SDW
 101 
 102 A:;
 103 
 104   //PNL (cpu.APUMemAddr = address;)
 105   PNL (cpu.APUMemAddr = cpu.TPR.CA;)
 106 
 107   DBGAPP ("doAppendCycleRTCDOperandFetch(A)\r\n");
 108 
 109   // is SDW for C(TPR.TSR) in SDWAM?
 110   if (nomatch || ! fetch_sdw_from_sdwam (cpup, cpu.TPR.TSR)) {
 111     // No
 112     DBGAPP ("doAppendCycleRTCDOperandFetch(A):SDW for segment %05o not in SDWAM\r\n", cpu.TPR.TSR);
 113     DBGAPP ("doAppendCycleRTCDOperandFetch(A):DSBR.U=%o\r\n", cpu.DSBR.U);
 114 
 115     if (cpu.DSBR.U == 0) {
 116       fetch_dsptw (cpup, cpu.TPR.TSR);
 117 
 118       if (! cpu.PTW0.DF)
 119         doFault (FAULT_DF0 + cpu.PTW0.FC, fst_zero, "doAppendCycleRTCDOperandFetch(A): PTW0.F == 0");
 120 
 121       if (! cpu.PTW0.U)
 122         modify_dsptw (cpup, cpu.TPR.TSR);
 123 
 124       fetch_psdw (cpup, cpu.TPR.TSR);
 125     } else
 126       fetch_nsdw (cpup, cpu.TPR.TSR); // load SDW0 from descriptor segment table.
 127 
 128     if (cpu.SDW0.DF == 0) {
 129       DBGAPP ("doAppendCycleRTCDOperandFetch(A): SDW0.F == 0! " "Initiating directed fault\r\n");
 130       // initiate a directed fault ...
 131       doFault (FAULT_DF0 + cpu.SDW0.FC, fst_zero, "SDW0.F == 0");
 132     }
 133     // load SDWAM .....
 134     load_sdwam (cpup, cpu.TPR.TSR, nomatch);
 135   }
 136   DBGAPP ("doAppendCycleRTCDOperandFetch(A) R1 %o R2 %o R3 %o E %o\r\n", cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3, cpu.SDW->E);
 137 
 138   // Yes...
 139   cpu.RSDWH_R1 = cpu.SDW->R1;
 140 
 141 ////////////////////////////////////////
 142 //
 143 // Sheet 3: "B"
 144 //
 145 ////////////////////////////////////////
 146 
 147 //
 148 // B: Check the ring
 149 //
 150 
 151   DBGAPP ("doAppendCycleRTCDOperandFetch(B)\r\n");
 152 
 153   // check ring bracket consistency
 154 
 155   //C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)?
 156   if (! (cpu.SDW->R1 <= cpu.SDW->R2 && cpu.SDW->R2 <= cpu.SDW->R3)) {
 157     // Set fault ACV0 = IRO
 158     cpu.acvFaults |= ACV0;
 159     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 160     FMSG (acvFaultsMsg = "acvFaults(B) C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)";)
 161   }
 162 
 163   if (lastCycle == RTCD_OPERAND_FETCH)
 164     sim_warn ("%s: lastCycle == RTCD_OPERAND_FETCH opcode %0#o\r\n", __func__, i->opcode);
 165 
 166   //
 167   // B1: The operand is one of: an instruction, data to be read or data to be
 168   //     written
 169   //
 170 
 171   //
 172   // check read bracket for read access
 173   //
 174 
 175   DBGAPP ("doAppendCycleRTCDOperandFetch(B):!STR-OP\r\n");
 176 
 177   // No
 178   // C(TPR.TRR) > C(SDW .R2)?
 179   if (cpu.TPR.TRR > cpu.SDW->R2) {
 180     DBGAPP ("ACV3\r\n");
 181     DBGAPP ("doAppendCycleRTCDOperandFetch(B) ACV3\r\n");
 182     //Set fault ACV3 = ORB
 183     cpu.acvFaults |= ACV3;
 184     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 185     FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R2)";)
 186   }
 187 
 188   if (cpu.SDW->R == 0) {
 189     // isolts 870
 190     cpu.TPR.TRR = cpu.PPR.PRR;
 191 
 192     //C(PPR.PSR) = C(TPR.TSR)?
 193     if (cpu.PPR.PSR != cpu.TPR.TSR) {
 194       DBGAPP ("ACV4\r\n");
 195       DBGAPP ("doAppendCycleRTCDOperandFetch(B) ACV4\r\n");
 196       //Set fault ACV4 = R-OFF
 197       cpu.acvFaults |= ACV4;
 198       PNL (L68_ (cpu.apu.state |= apu_FLT;))
 199       FMSG (acvFaultsMsg = "acvFaults(B) C(PPR.PSR) = C(TPR.TSR)";)
 200     //} else {
 201       // sim_warn ("doAppendCycleRTCDOperandFetch(B) SDW->R == 0 && cpu.PPR.PSR == cpu.TPR.TSR: %0#o\r\n", cpu.PPR.PSR);
 202     }
 203   }
 204 
 205   goto G;
 206 
 207 ////////////////////////////////////////
 208 //
 209 // Sheet 7: "G"
 210 //
 211 ////////////////////////////////////////
 212 
 213 G:;
 214 
 215   DBGAPP ("doAppendCycleRTCDOperandFetch(G)\r\n");
 216 
 217   //C(TPR.CA)0,13 > SDW.BOUND?
 218   if (((cpu.TPR.CA >> 4) & 037777) > cpu.SDW->BOUND) {
 219     DBGAPP ("ACV15\r\n");
 220     DBGAPP ("doAppendCycleRTCDOperandFetch(G) ACV15\r\n");
 221     cpu.acvFaults |= ACV15;
 222     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 223     FMSG (acvFaultsMsg = "acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND";)
 224     DBGAPP ("acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND\r\n" "   CA %06o CA>>4 & 037777 %06o SDW->BOUND %06o",
 225             cpu.TPR.CA, ((cpu.TPR.CA >> 4) & 037777), cpu.SDW->BOUND);
 226     }
 227 
 228   if (cpu.acvFaults) {
 229     DBGAPP ("doAppendCycleRTCDOperandFetch(G) acvFaults\r\n");
 230     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 231     // Initiate an access violation fault
 232     doFault (FAULT_ACV, (_fault_subtype) {.fault_acv_subtype=cpu.acvFaults}, "ACV fault");
 233   }
 234 
 235   // is segment C(TPR.TSR) paged?
 236   if (cpu.SDW->U)
 237     goto H; // Not paged
 238 
 239   // Yes. segment is paged ...
 240   // is PTW for C(TPR.CA) in PTWAM?
 241 
 242   DBGAPP ("doAppendCycleRTCDOperandFetch(G) CA %06o\r\n", cpu.TPR.CA);
 243   if (nomatch || ! fetch_ptw_from_ptwam (cpup, cpu.SDW->POINTER, cpu.TPR.CA)) {
 244     fetch_ptw (cpup, cpu.SDW, cpu.TPR.CA);
 245     if (! cpu.PTW0.DF) {
 246       // initiate a directed fault
 247       doFault (FAULT_DF0 + cpu.PTW0.FC, (_fault_subtype) {.bits=0}, "PTW0.F == 0");
 248     }
 249     loadPTWAM (cpup, cpu.SDW->POINTER, cpu.TPR.CA, nomatch); // load PTW0 to PTWAM
 250   }
 251 
 252   // Prepage mode?
 253   // check for "uninterruptible" EIS instruction
 254   // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
 255   // ad2/3d,sb2/3d,mp2/3d,dv2/3d
 256   // DH03 p.8-13: probably also mve,btd,dtb
 257   if (i->opcodeX && ((i->opcode & 0770)== 0200|| (i->opcode & 0770) == 0220
 258       || (i->opcode & 0770)== 020|| (i->opcode & 0770) == 0300)) {
 259     do_ptw2 (cpup, cpu.SDW, cpu.TPR.CA);
 260   }
 261   goto I;
 262 
 263 ////////////////////////////////////////
 264 //
 265 // Sheet 8: "H", "I"
 266 //
 267 ////////////////////////////////////////
 268 
 269 H:;
 270   DBGAPP ("doAppendCycleRTCDOperandFetch(H): FANP\r\n");
 271 
 272   PNL (L68_ (cpu.apu.state |= apu_FANP;))
 273 
 274 
 275 
 276 
 277 
 278 
 279 
 280   set_apu_status (cpup, apuStatus_FANP);
 281 
 282   DBGAPP ("doAppendCycleRTCDOperandFetch(H): SDW->ADDR=%08o CA=%06o\r\n", cpu.SDW->ADDR, cpu.TPR.CA);
 283 
 284   if (get_addr_mode (cpup) == ABSOLUTE_mode && ! (cpu.cu.XSF || cpu.currentInstruction.b29)) {
 285     finalAddress = cpu.TPR.CA;
 286   } else {
 287     finalAddress = (cpu.SDW->ADDR & 077777760) + cpu.TPR.CA;
 288     finalAddress &= 0xffffff;
 289   }
 290   PNL (cpu.APUMemAddr = finalAddress;)
 291 
 292   DBGAPP ("doAppendCycleRTCDOperandFetch(H:FANP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 293 
 294   goto HI;
 295 
 296 I:;
 297 
 298 // Set PTW.M
 299 
 300   DBGAPP ("doAppendCycleRTCDOperandFetch(I): FAP\r\n");
 301 
 302   // final address paged
 303   set_apu_status (cpup, apuStatus_FAP);
 304   PNL (L68_ (cpu.apu.state |= apu_FAP;))
 305 
 306   word24 y2 = cpu.TPR.CA % 1024;
 307 
 308   // AL39: The hardware ignores low order bits of the main memory page
 309   // address according to page size
 310   finalAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6) + y2;
 311   finalAddress &= 0xffffff;
 312   PNL (cpu.APUMemAddr = finalAddress;)
 313 
 314   L68_ (
 315     if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 316       add_l68_APU_history (cpup, APUH_FAP);
 317   )
 318 
 319   DBGAPP ("doAppendCycleRTCDOperandFetch(H:FAP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 320 
 321   goto HI;
 322 
 323 HI:
 324   DBGAPP ("doAppendCycleRTCDOperandFetch(HI)\r\n");
 325 
 326   // isolts 870
 327   cpu.cu.XSF = 1;
 328   if (full)   // (1), see FULL_MODEL_ON
 329     cpu.xsfScu = true;
 330   sim_debug (DBG_TRACEEXT, & cpu_dev, "loading of cpu.TPR.TSR sets XSF to 1\r\n");
 331 
 332   if (full)
 333     cache_readN (cpup, finalAddress, data, nWords, "RTCD_OPERAND_FETCH");
 334   else
 335     core_readN_fast (cpup, finalAddress, data, nWords, "RTCD_OPERAND_FETCH");
 336 
 337   goto K;
 338 
 339 ////////////////////////////////////////
 340 //
 341 // Sheet 10: "K", "L", "M", "N"
 342 //
 343 ////////////////////////////////////////
 344 
 345 K:; // RTCD operand fetch
 346   DBGAPP ("doAppendCycleRTCDOperandFetch(K)\r\n");
 347 
 348   word3 y = GET_ITS_RN (data);
 349 
 350   // C(Y-pair)3,17 -> C(PPR.PSR)
 351   // We set TSR here; TSR will be copied to PSR at KL
 352   cpu.TPR.TSR = GET_ITS_SEGNO (data);
 353 
 354   // Maximum of
 355   // C(Y-pair)18,20; C(TPR.TRR); C(SDW.R1) -> C(PPR.PRR)
 356   // We set TRR here as well
 357   cpu.PPR.PRR = cpu.TPR.TRR = max3 (y, cpu.TPR.TRR, cpu.RSDWH_R1);
 358 
 359   // C(Y-pair)36,53 -> C(PPR.IC)
 360   // We set CA here; copied to IC  at KL
 361   cpu.TPR.CA = GET_ITS_WORDNO (data);
 362 
 363   // If C(PPR.PRR) = 0 then C(SDW.P) -> C(PPR.P);
 364   //     otherwise 0 -> C(PPR.P)
 365   // Done at M
 366 
 367 //KL:
 368   DBGAPP ("doAppendCycleRTCDOperandFetch(KL)\r\n");
 369 
 370   // C(TPR.TSR) -> C(PPR.PSR)
 371   cpu.PPR.PSR = cpu.TPR.TSR;
 372   // C(TPR.CA) -> C(PPR.IC)
 373   cpu.PPR.IC = cpu.TPR.CA;
 374 
 375   goto M;
 376 
 377 M: // Set P
 378   DBGAPP ("doAppendCycleRTCDOperandFetch(M)\r\n");
 379 
 380   // C(TPR.TRR) = 0?
 381   if (cpu.TPR.TRR == 0) {
 382     // C(SDW.P) -> C(PPR.P)
 383     cpu.PPR.P = cpu.SDW->P;
 384   } else {
 385     // 0 C(PPR.P)
 386     cpu.PPR.P = 0;
 387   }
 388 
 389 //Exit:;
 390 
 391   PNL (cpu.APUDataBusOffset = cpu.TPR.CA;)
 392   PNL (cpu.APUDataBusAddr = finalAddress;)
 393 
 394   PNL (L68_ (cpu.apu.state |= apu_FA;))
 395 
 396   DBGAPP ("doAppendCycleRTCDOperandFetch (Exit) PRR %o PSR %05o P %o IC %06o\r\n",
 397           cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
 398   DBGAPP ("doAppendCycleRTCDOperandFetch (Exit) TRR %o TSR %05o TBR %02o CA %06o\r\n",
 399           cpu.TPR.TRR, cpu.TPR.TSR, cpu.TPR.TBR, cpu.TPR.CA);
 400 
 401   return finalAddress;
 402 }

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