root/src/dps8/doAppendCycleAPUDataRead.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. doAppendCycleAPUDataRead_

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 90fcb7d2-171d-11ee-a18f-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 doAppendCycleAPUDataRead_ (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 ("doAppendCycleAPUDataRead(Entry) thisCycle=APU_DATA_READ\r\n");
  22   DBGAPP ("doAppendCycleAPUDataRead(Entry) lastCycle=%s\r\n", str_pct (cpu.apu.lastCycle));
  23   DBGAPP ("doAppendCycleAPUDataRead(Entry) CA %06o\r\n", cpu.TPR.CA);
  24   DBGAPP ("doAppendCycleAPUDataRead(Entry) n=%2u\r\n", nWords);
  25   DBGAPP ("doAppendCycleAPUDataRead(Entry) PPR.PRR=%o PPR.PSR=%05o\r\n", cpu.PPR.PRR, cpu.PPR.PSR);
  26   DBGAPP ("doAppendCycleAPUDataRead(Entry) TPR.TRR=%o TPR.TSR=%05o\r\n", cpu.TPR.TRR, cpu.TPR.TSR);
  27 
  28   if (i->b29) {
  29     DBGAPP ("doAppendCycleAPUDataRead(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 = APU_DATA_READ;
  48 
  49   DBGAPP ("doAppendCycleAPUDataRead(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 2: "A"
  67 //
  68 ////////////////////////////////////////
  69 
  70 //
  71 //  A:
  72 //    Get SDW
  73 
  74   //PNL (cpu.APUMemAddr = address;)
  75   PNL (cpu.APUMemAddr = cpu.TPR.CA;)
  76 
  77   DBGAPP ("doAppendCycleAPUDataRead(A)\r\n");
  78 
  79     // is SDW for C(TPR.TSR) in SDWAM?
  80   if (nomatch || ! fetch_sdw_from_sdwam (cpup, cpu.TPR.TSR)) {
  81     // No
  82     DBGAPP ("doAppendCycleAPUDataRead(A):SDW for segment %05o not in SDWAM\r\n", cpu.TPR.TSR);
  83 
  84     DBGAPP ("doAppendCycleAPUDataRead(A):DSBR.U=%o\r\n", cpu.DSBR.U);
  85 
  86     if (cpu.DSBR.U == 0) {
  87       fetch_dsptw (cpup, cpu.TPR.TSR);
  88 
  89       if (! cpu.PTW0.DF)
  90         doFault (FAULT_DF0 + cpu.PTW0.FC, fst_zero, "doAppendCycleAPUDataRead(A): PTW0.F == 0");
  91 
  92       if (! cpu.PTW0.U)
  93         modify_dsptw (cpup, cpu.TPR.TSR);
  94 
  95       fetch_psdw (cpup, cpu.TPR.TSR);
  96     } else
  97       fetch_nsdw (cpup, cpu.TPR.TSR); // load SDW0 from descriptor segment table.
  98 
  99     if (cpu.SDW0.DF == 0) {
 100       DBGAPP ("doAppendCycleAPUDataRead(A): SDW0.F == 0! " "Initiating directed fault\r\n");
 101       // initiate a directed fault ...
 102       doFault (FAULT_DF0 + cpu.SDW0.FC, fst_zero, "SDW0.F == 0");
 103     }
 104     // load SDWAM .....
 105     load_sdwam (cpup, cpu.TPR.TSR, nomatch);
 106   }
 107   DBGAPP ("doAppendCycleAPUDataRead(A) R1 %o R2 %o R3 %o E %o\r\n", cpu.SDW->R1, cpu.SDW->R2, cpu.SDW->R3, cpu.SDW->E);
 108 
 109   // Yes...
 110   cpu.RSDWH_R1 = cpu.SDW->R1;
 111 
 112 ////////////////////////////////////////
 113 //
 114 // Sheet 3: "B"
 115 //
 116 ////////////////////////////////////////
 117 
 118 //
 119 // B: Check the ring
 120 //
 121 
 122   DBGAPP ("doAppendCycleAPUDataRead(B)\r\n");
 123 
 124   // check ring bracket consistency
 125 
 126   //C(SDW.R1) <= C(SDW.R2) <= C(SDW .R3)?
 127   if (! (cpu.SDW->R1 <= cpu.SDW->R2 && cpu.SDW->R2 <= cpu.SDW->R3)) {
 128     // Set fault ACV0 = IRO
 129     cpu.acvFaults |= ACV0;
 130     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 131     FMSG (acvFaultsMsg = "acvFaults(B) C(SDW.R1) <= C(SDW.R2) <= " "C(SDW .R3)";)
 132   }
 133 
 134   if (lastCycle == RTCD_OPERAND_FETCH)
 135     sim_warn ("%s: lastCycle == RTCD_OPERAND_FETCH opcode %0#o\r\n", __func__, i->opcode);
 136 
 137   //
 138   // B1: The operand is one of: an instruction, data to be read or data to be
 139   //     written
 140   //
 141 
 142   //
 143   // check read bracket for read access
 144   //
 145 
 146   DBGAPP ("doAppendCycleAPUDataRead(B):!STR-OP\r\n");
 147 
 148   // No
 149   // C(TPR.TRR) > C(SDW .R2)?
 150   if (cpu.TPR.TRR > cpu.SDW->R2) {
 151     DBGAPP ("ACV3\r\n");
 152     DBGAPP ("doAppendCycleAPUDataRead(B) ACV3\r\n");
 153     //Set fault ACV3 = ORB
 154     cpu.acvFaults |= ACV3;
 155     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 156     FMSG (acvFaultsMsg = "acvFaults(B) C(TPR.TRR) > C(SDW .R2)";)
 157   }
 158 
 159   if (cpu.SDW->R == 0) {
 160     // isolts 870
 161     cpu.TPR.TRR = cpu.PPR.PRR;
 162 
 163     //C(PPR.PSR) = C(TPR.TSR)?
 164     if (cpu.PPR.PSR != cpu.TPR.TSR) {
 165       DBGAPP ("ACV4\r\n");
 166       DBGAPP ("doAppendCycleAPUDataRead(B) ACV4\r\n");
 167       //Set fault ACV4 = R-OFF
 168       cpu.acvFaults |= ACV4;
 169       PNL (L68_ (cpu.apu.state |= apu_FLT;))
 170       FMSG (acvFaultsMsg = "acvFaults(B) C(PPR.PSR) = C(TPR.TSR)";)
 171     //} else {
 172       // sim_warn ("doAppendCycleAPUDataRead(B) SDW->R == 0 && cpu.PPR.PSR == cpu.TPR.TSR: %0#o\r\n", cpu.PPR.PSR);
 173     }
 174   }
 175 
 176 ////////////////////////////////////////
 177 //
 178 // Sheet 7: "G"
 179 //
 180 ////////////////////////////////////////
 181 
 182   DBGAPP ("doAppendCycleAPUDataRead(G)\r\n");
 183 
 184   //C(TPR.CA)0,13 > SDW.BOUND?
 185   if (((cpu.TPR.CA >> 4) & 037777) > cpu.SDW->BOUND) {
 186     DBGAPP ("ACV15\r\n");
 187     DBGAPP ("doAppendCycleAPUDataRead(G) ACV15\r\n");
 188     cpu.acvFaults |= ACV15;
 189     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 190     FMSG (acvFaultsMsg = "acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND";)
 191     DBGAPP ("acvFaults(G) C(TPR.CA)0,13 > SDW.BOUND\r\n" "   CA %06o CA>>4 & 037777 %06o SDW->BOUND %06o",
 192             cpu.TPR.CA, ((cpu.TPR.CA >> 4) & 037777), cpu.SDW->BOUND);
 193   }
 194 
 195   if (cpu.acvFaults) {
 196     DBGAPP ("doAppendCycleAPUDataRead(G) acvFaults\r\n");
 197     PNL (L68_ (cpu.apu.state |= apu_FLT;))
 198     // Initiate an access violation fault
 199     doFault (FAULT_ACV, (_fault_subtype) {.fault_acv_subtype=cpu.acvFaults}, "ACV fault");
 200   }
 201 
 202   // is segment C(TPR.TSR) paged?
 203   if (cpu.SDW->U)
 204     goto H; // Not paged
 205 
 206   // Yes. segment is paged ...
 207   // is PTW for C(TPR.CA) in PTWAM?
 208 
 209   DBGAPP ("doAppendCycleAPUDataRead(G) CA %06o\r\n", cpu.TPR.CA);
 210   if (nomatch || ! fetch_ptw_from_ptwam (cpup, cpu.SDW->POINTER, cpu.TPR.CA)) {
 211     fetch_ptw (cpup, cpu.SDW, cpu.TPR.CA);
 212     if (! cpu.PTW0.DF)
 213       // initiate a directed fault
 214       doFault (FAULT_DF0 + cpu.PTW0.FC, (_fault_subtype) {.bits=0}, "PTW0.F == 0");
 215     loadPTWAM (cpup, cpu.SDW->POINTER, cpu.TPR.CA, nomatch); // load PTW0 to PTWAM
 216   }
 217 
 218   // Prepage mode?
 219   // check for "uninterruptible" EIS instruction
 220   // ISOLTS-878 02: mvn,cmpn,mvne,ad3d; obviously also
 221   // ad2/3d,sb2/3d,mp2/3d,dv2/3d
 222   // DH03 p.8-13: probably also mve,btd,dtb
 223   if (i->opcodeX && ((i->opcode & 0770)== 0200 || (i->opcode & 0770) == 0220 || \
 224                      (i->opcode & 0770)== 020  || (i->opcode & 0770) == 0300)) {
 225     do_ptw2 (cpup, cpu.SDW, cpu.TPR.CA);
 226   }
 227   goto I;
 228 
 229 ////////////////////////////////////////
 230 //
 231 // Sheet 8: "H", "I"
 232 //
 233 ////////////////////////////////////////
 234 
 235 H:;
 236   DBGAPP ("doAppendCycleAPUDataRead(H): FANP\r\n");
 237 
 238   PNL (L68_ (cpu.apu.state |= apu_FANP;))
 239 
 240 
 241 
 242 
 243 
 244 
 245 
 246 
 247   set_apu_status (cpup, apuStatus_FANP);
 248 
 249   DBGAPP ("doAppendCycleAPUDataRead(H): SDW->ADDR=%08o CA=%06o\r\n", cpu.SDW->ADDR, cpu.TPR.CA);
 250 
 251   finalAddress = (cpu.SDW->ADDR & 077777760) + cpu.TPR.CA;
 252   finalAddress &= 0xffffff;
 253   PNL (cpu.APUMemAddr = finalAddress;)
 254 
 255   DBGAPP ("doAppendCycleAPUDataRead(H:FANP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 256 
 257   goto HI;
 258 
 259 I:;
 260 
 261 // Set PTW.M
 262 
 263   DBGAPP ("doAppendCycleAPUDataRead(I): FAP\r\n");
 264 
 265     // final address paged
 266   set_apu_status (cpup, apuStatus_FAP);
 267   PNL (L68_ (cpu.apu.state |= apu_FAP;))
 268 
 269   word24 y2 = cpu.TPR.CA % 1024;
 270 
 271   // AL39: The hardware ignores low order bits of the main memory page
 272   // address according to page size
 273   finalAddress = (((word24)cpu.PTW->ADDR & 0777760) << 6) + y2;
 274   finalAddress &= 0xffffff;
 275   PNL (cpu.APUMemAddr = finalAddress;)
 276 
 277   L68_ (
 278     if (cpu.MR_cache.emr && cpu.MR_cache.ihr)
 279       add_l68_APU_history (cpup, APUH_FAP);
 280   )
 281 
 282   DBGAPP ("doAppendCycleAPUDataRead(H:FAP): (%05o:%06o) finalAddress=%08o\r\n", cpu.TPR.TSR, cpu.TPR.CA, finalAddress);
 283 
 284 HI:
 285   DBGAPP ("doAppendCycleAPUDataRead(HI)\r\n");
 286 
 287   // isolts 870
 288   cpu.cu.XSF = 1;
 289   if (full)   // (1), see FULL_MODEL_ON
 290     cpu.xsfScu = true;   // IT modifier (tally) words
 291   sim_debug (DBG_TRACEEXT, & cpu_dev, "loading of cpu.TPR.TSR sets XSF to 1\r\n");
 292 
 293   if (full)
 294     cache_readN (cpup, finalAddress, data, nWords, "APU_DATA_READ");
 295   else
 296     core_readN_fast (cpup, finalAddress, data, nWords, "APU_DATA_READ");
 297 
 298 //Exit:;
 299 
 300   PNL (cpu.APUDataBusOffset = cpu.TPR.CA;)
 301   PNL (cpu.APUDataBusAddr = finalAddress;)
 302 
 303   PNL (L68_ (cpu.apu.state |= apu_FA;))
 304 
 305   DBGAPP ("doAppendCycleAPUDataRead (Exit) PRR %o PSR %05o P %o IC %06o\r\n", cpu.PPR.PRR, cpu.PPR.PSR, cpu.PPR.P, cpu.PPR.IC);
 306   DBGAPP ("doAppendCycleAPUDataRead (Exit) TRR %o TSR %05o TBR %02o CA %06o\r\n", cpu.TPR.TRR, cpu.TPR.TSR, cpu.TPR.TBR, cpu.TPR.CA);
 307 
 308   return finalAddress;    // or 0 or -1???
 309 }

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