root/src/dps8/doAppendCycleAPUDataRMW.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. doAppendCycleAPUDataRMW_

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 8a44969e-171d-11ee-a0d2-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 doAppendCycleAPUDataRMW_ (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 ("doAppendCycleAPUDataRMW(Entry) thisCycle=APU_DATA_RMW\r\n");
  22   DBGAPP ("doAppendCycleAPUDataRMW(Entry) lastCycle=%s\r\n", str_pct (cpu.apu.lastCycle));
  23   DBGAPP ("doAppendCycleAPUDataRMW(Entry) CA %06o\r\n", cpu.TPR.CA);
  24   DBGAPP ("doAppendCycleAPUDataRMW(Entry) n=%2u\r\n", nWords);
  25   DBGAPP ("doAppendCycleAPUDataRMW(Entry) PPR.PRR=%o PPR.PSR=%05o\r\n", cpu.PPR.PRR, cpu.PPR.PSR);
  26   DBGAPP ("doAppendCycleAPUDataRMW(Entry) TPR.TRR=%o TPR.TSR=%05o\r\n", cpu.TPR.TRR, cpu.TPR.TSR);
  27 
  28   if (i->b29) {
  29     DBGAPP ("doAppendCycleAPUDataRMW(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) && i->opcodeX ) ||
  41               ((i->opcode == 0557 || i->opcode == 0257) && ! i->opcodeX);
  42   }
  43 
  44   processor_cycle_type lastCycle = cpu.apu.lastCycle;
  45   cpu.apu.lastCycle = APU_DATA_RMW;
  46 
  47   DBGAPP ("doAppendCycleAPUDataRMW(Entry) XSF %o\r\n", cpu.cu.XSF);
  48 
  49   PNL (L68_ (cpu.apu.state = 0;))
  50 
  51   cpu.RSDWH_R1 = 0;
  52 
  53   cpu.acvFaults = 0;
  54 
  55 //#define FMSG(x) x
  56 #define FMSG(x)
  57   FMSG (char * acvFaultsMsg = "<unknown>";)
  58 
  59   word24 finalAddress = (word24) -1;  // not everything requires a final
  60                                       // address
  61 
  62 ////////////////////////////////////////
  63 //
  64 // Sheet 2: "A"
  65 //
  66 ////////////////////////////////////////
  67 
  68 //
  69 //  A:
  70 //    Get SDW
  71 
  72   PNL (cpu.APUMemAddr = cpu.TPR.CA;)
  73 
  74   DBGAPP ("doAppendCycleAPUDataRMW(A)\r\n");
  75 
  76   // is SDW for C(TPR.TSR) in SDWAM?
  77   if (nomatch || ! fetch_sdw_from_sdwam (cpup, cpu.TPR.TSR)) {
  78     // No
  79     DBGAPP ("doAppendCycleAPUDataRMW(A):SDW for segment %05o not in SDWAM\r\n", cpu.TPR.TSR);
  80 
  81     DBGAPP ("doAppendCycleAPUDataRMW(A):DSBR.U=%o\r\n", cpu.DSBR.U);
  82 
  83     if (cpu.DSBR.U == 0) {
  84       fetch_dsptw (cpup, cpu.TPR.TSR);
  85 
  86       if (! cpu.PTW0.DF)
  87         doFault (FAULT_DF0 + cpu.PTW0.FC, fst_zero, "doAppendCycleAPUDataRMW(A): PTW0.F == 0");
  88 
  89       if (! cpu.PTW0.U)
  90         modify_dsptw (cpup, cpu.TPR.TSR);
  91 
  92       fetch_psdw (cpup, cpu.TPR.TSR);
  93     } else
  94       fetch_nsdw (cpup, cpu.TPR.TSR); // load SDW0 from descriptor segment table.
  95 
  96     if (cpu.SDW0.DF == 0) {
  97       DBGAPP ("doAppendCycleAPUDataRMW(A): SDW0.F == 0! " "Initiating directed fault\r\n");
  98       // initiate a directed fault ...
  99       doFault (FAULT_DF0 + cpu.SDW0.FC, fst_zero, "SDW0.F == 0");
 100     }
 101     // load SDWAM .....
 102     load_sdwam (cpup, cpu.TPR.TSR, nomatch);
 103   }
 104   DBGAPP ("doAppendCycleAPUDataRMW(A) R1 %o R2 %o R3 %o E %o\r\n", cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3, cpu.SDW->E);
 105 
 106   // Yes...
 107   cpu.RSDWH_R1 = cpu.SDW->R1;
 108 
 109 ////////////////////////////////////////
 110 //
 111 // Sheet 3: "B"
 112 //
 113 ////////////////////////////////////////
 114 
 115 //
 116 // B: Check the ring
 117 //
 118 
 119   DBGAPP ("doAppendCycleAPUDataRMW(B)\r\n");
 120 
 121   // check ring bracket consistency
 122 
 123   //C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)?
 124   if (! (cpu.SDW->R1 <= cpu.SDW->R2 && cpu.SDW->R2 <= cpu.SDW->R3)) {
 125     // Set fault ACV0 = IRO
 126     cpu.acvFaults |= ACV0;
 127     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 128     FMSG (acvFaultsMsg = "acvFaults(B) C(SDW.R1) <= C(SDW.R2) <= " "C(SDW .R3)";)
 129   }
 130 
 131   // lastCycle == RTCD_OPERAND_FETCH
 132   // if a fault happens between the RTCD_OPERAND_FETCH and the INSTRUCTION_FETCH
 133   // of the next instruction - this happens about 35 time for just booting  and
 134   // shutting down multics -- a stored lastCycle is useless.
 135   // the opcode is preserved across faults and only replaced as the
 136   // INSTRUCTION_FETCH succeeds.
 137   if (lastCycle == RTCD_OPERAND_FETCH)
 138     sim_warn ("%s: lastCycle == RTCD_OPERAND_FETCH opcode %0#o\r\n", __func__, i->opcode);
 139 
 140   //
 141   // B1: The operand is one of: an instruction, data to be read or data to be
 142   //     written
 143   //
 144 
 145   //
 146   // check read bracket for read access
 147   //
 148 
 149   DBGAPP ("doAppendCycleAPUDataRMW(B):!STR-OP\r\n");
 150 
 151   // No
 152   // C(TPR.TRR) > C(SDW .R2)?
 153   if (cpu.TPR.TRR > cpu.SDW->R2) {
 154     DBGAPP ("ACV3\r\n");
 155     DBGAPP ("doAppendCycleAPUDataRMW(B) ACV3\r\n");
 156     //Set fault ACV3 = ORB
 157     cpu.acvFaults |= ACV3;
 158     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 159     FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R2)";)
 160   }
 161 
 162   if (cpu.SDW->R == 0) {
 163     // isolts 870
 164     cpu.TPR.TRR = cpu.PPR.PRR;
 165 
 166     //C(PPR.PSR) = C(TPR.TSR)?
 167     if (cpu.PPR.PSR != cpu.TPR.TSR) {
 168       DBGAPP ("ACV4\r\n");
 169       DBGAPP ("doAppendCycleAPUDataRMW(B) ACV4\r\n");
 170       //Set fault ACV4 = R-OFF
 171       cpu.acvFaults |= ACV4;
 172       PNL (L68_ (cpu.apu.state |= apu_FLT;))
 173       FMSG (acvFaultsMsg = "acvFaults(B) C(PPR.PSR) = C(TPR.TSR)";)
 174     //} else {
 175       // sim_warn ("doAppendCycleAPUDataRMW(B) SDW->R == 0 && cpu.PPR.PSR == cpu.TPR.TSR: %0#o\r\n", cpu.PPR.PSR);
 176     }
 177   }
 178 
 179   //
 180   // check write bracket for write access
 181   //
 182   DBGAPP ("doAppendCycleAPUDataRMW(B):STR-OP\r\n");
 183 
 184   // isolts 870
 185   if (cpu.TPR.TSR == cpu.PPR.PSR)
 186     cpu.TPR.TRR = cpu.PPR.PRR;
 187 
 188   // C(TPR.TRR) > C(SDW .R1)? Note typo in AL39, R2 should be R1
 189   if (cpu.TPR.TRR > cpu.SDW->R1) {
 190     DBGAPP ("ACV5 TRR %o R1 %o\r\n", cpu.TPR.TRR, cpu.SDW->R1);
 191     //Set fault ACV5 = OWB
 192     cpu.acvFaults |= ACV5;
 193     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 194     FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R1)";)
 195   }
 196 
 197   if (! cpu.SDW->W) {
 198     // isolts 870
 199     cpu.TPR.TRR = cpu.PPR.PRR;
 200 
 201     DBGAPP ("ACV6\r\n");
 202     // Set fault ACV6 = W-OFF
 203     cpu.acvFaults |= ACV6;
 204     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 205     FMSG (acvFaultsMsg = "acvFaults(B) ACV6 = W-OFF";)
 206   }
 207 
 208   goto G;
 209 
 210 ////////////////////////////////////////
 211 //
 212 // Sheet 7: "G"
 213 //
 214 ////////////////////////////////////////
 215 
 216 G:;
 217 
 218   DBGAPP ("doAppendCycleAPUDataRMW(G)\r\n");
 219 
 220   //C(TPR.CA)0,13 > SDW.BOUND?
 221   if (((cpu.TPR.CA >> 4) & 037777) > cpu.SDW->BOUND) {
 222     DBGAPP ("ACV15\r\n");
 223     DBGAPP ("doAppendCycleAPUDataRMW(G) ACV15\r\n");
 224     cpu.acvFaults |= ACV15;
 225     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 226     FMSG (acvFaultsMsg = "acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND";)
 227     DBGAPP ("acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND\r\n" "   CA %06o CA>>4 & 037777 %06o SDW->BOUND %06o",
 228             cpu.TPR.CA, ((cpu.TPR.CA >> 4) & 037777), cpu.SDW->BOUND);
 229   }
 230 
 231   if (cpu.acvFaults) {
 232     DBGAPP ("doAppendCycleAPUDataRMW(G) acvFaults\r\n");
 233     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 234     // Initiate an access violation fault
 235     doFault (FAULT_ACV, (_fault_subtype) {.fault_acv_subtype=cpu.acvFaults}, "ACV fault");
 236   }
 237 
 238   // is segment C(TPR.TSR) paged?
 239   if (cpu.SDW->U)
 240     goto H; // Not paged
 241 
 242   // Yes. segment is paged ...
 243   // is PTW for C(TPR.CA) in PTWAM?
 244 
 245   DBGAPP ("doAppendCycleAPUDataRMW(G) CA %06o\r\n", cpu.TPR.CA);
 246   if (nomatch || ! fetch_ptw_from_ptwam (cpup, cpu.SDW->POINTER, cpu.TPR.CA)) {
 247     fetch_ptw (cpup, cpu.SDW, cpu.TPR.CA);
 248     if (! cpu.PTW0.DF) {
 249       // initiate a directed fault
 250       doFault (FAULT_DF0 + cpu.PTW0.FC, (_fault_subtype) {.bits=0}, "PTW0.F == 0");
 251     }
 252     loadPTWAM (cpup, cpu.SDW->POINTER, cpu.TPR.CA, nomatch); // load PTW0 to PTWAM
 253   }
 254 
 255   // Prepage mode?
 256   // check for "uninterruptible" EIS instruction
 257   // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
 258   // ad2/3d,sb2/3d,mp2/3d,dv2/3d
 259   // DH03 p.8-13: probably also mve,btd,dtb
 260   if (i->opcodeX && ((i->opcode & 0770)== 0200 || (i->opcode & 0770) == 0220 || \
 261                      (i->opcode & 0770)== 020  || (i->opcode & 0770) == 0300)) {
 262     do_ptw2 (cpup, cpu.SDW, cpu.TPR.CA);
 263   }
 264   goto I;
 265 
 266 ////////////////////////////////////////
 267 //
 268 // Sheet 8: "H", "I"
 269 //
 270 ////////////////////////////////////////
 271 
 272 H:;
 273   DBGAPP ("doAppendCycleAPUDataRMW(H): FANP\r\n");
 274 
 275   PNL (L68_ (cpu.apu.state |= apu_FANP;))
 276 
 277 
 278 
 279 
 280 
 281 
 282 
 283 
 284 
 285   set_apu_status (cpup, apuStatus_FANP);
 286 
 287   DBGAPP ("doAppendCycleAPUDataRMW(H): SDW->ADDR=%08o CA=%06o\r\n", cpu.SDW->ADDR, cpu.TPR.CA);
 288 
 289   finalAddress = (cpu.SDW->ADDR & 077777760) + cpu.TPR.CA;
 290   finalAddress &= 0xffffff;
 291   PNL (cpu.APUMemAddr = finalAddress;)
 292 
 293   DBGAPP ("doAppendCycleAPUDataRMW(H:FANP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 294 
 295   goto HI;
 296 
 297 I:;
 298 
 299 // Set PTW.M
 300 
 301   DBGAPP ("doAppendCycleAPUDataRMW(I): FAP\r\n");
 302   if (cpu.PTW->M == 0) // is this the right way to do this?
 303      modify_ptw (cpup, cpu.SDW, cpu.TPR.CA);
 304 
 305   // final address paged
 306   set_apu_status (cpup, apuStatus_FAP);
 307   PNL (L68_ (cpu.apu.state |= apu_FAP;))
 308 
 309   word24 y2 = cpu.TPR.CA % 1024;
 310 
 311   // AL39: The hardware ignores low order bits of the main memory page
 312   // address according to page size
 313   finalAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6) + y2;
 314   finalAddress &= 0xffffff;
 315   PNL (cpu.APUMemAddr = finalAddress;)
 316 
 317   L68_ (
 318   if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 319     add_l68_APU_history (cpup, APUH_FAP);
 320   )
 321 
 322   DBGAPP ("doAppendCycleAPUDataRMW(H:FAP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 323 
 324   goto HI;
 325 
 326 HI:
 327   DBGAPP ("doAppendCycleAPUDataRMW(HI)\r\n");
 328 
 329   // isolts 870
 330   cpu.cu.XSF = 1;
 331   if (full)   // (1), see FULL_MODEL_ON
 332     cpu.xsfScu = true;   // IT modifier (tally) words
 333   sim_debug (DBG_TRACEEXT, & cpu_dev, "loading of cpu.TPR.TSR sets XSF to 1\r\n");
 334 
 335   if (nWords == 1) {
 336     if (full)
 337       cache_read_lock (cpup, finalAddress, data, "APU_DATA_RMW");
 338     else
 339       core_read_lock (cpup, finalAddress, data, "APU_DATA_RMW");
 340   } else {
 341     sim_warn("doAppendCycleAPUDataRMW: RMW nWords %d != 1\r\n", nWords);
 342     if (full)
 343       cache_readN (cpup, finalAddress, data, nWords, "APU_DATA_RMW");
 344     else
 345       core_readN (cpup, finalAddress, data, nWords, "APU_DATA_RMW");
 346   }
 347 
 348 //Exit:;
 349 
 350   PNL (cpu.APUDataBusOffset = cpu.TPR.CA;)
 351   PNL (cpu.APUDataBusAddr = finalAddress;)
 352 
 353   PNL (L68_ (cpu.apu.state |= apu_FA;))
 354 
 355   DBGAPP ("doAppendCycleAPUDataRMW (Exit) PRR %o PSR %05o P %o IC %06o\r\n", cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
 356   DBGAPP ("doAppendCycleAPUDataRMW (Exit) TRR %o TSR %05o TBR %02o CA %06o\r\n", cpu.TPR.TRR, cpu.TPR.TSR, cpu.TPR.TBR, cpu.TPR.CA);
 357 
 358   return finalAddress;    // or 0 or -1???
 359 }

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