root/src/dps8/dps8_cache.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. cacheInvalidate
  2. cacheStoreNotify
  3. cachePurgeAll
  4. cache_read_lock
  5. cache_write_unlock
  6. cache_read
  7. cache_read2
  8. cache_readN
  9. cache_write_zone
  10. cache_write
  11. cache_writeN
  12. cache_write2

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 384a80e6-df7a-11f1-9a7e-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2026 Charles Anthony
   9  * Copyright (c) 2026 Eric J. Swenson
  10  * Copyright (c) 2021-2026 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 //-V::536
  19 //-V::652
  20 
  21 #if !defined(DPS8_CACHE_H)
  22 # define DPS8_CACHE_H
  23 
  24 // mask off the low 2 bits of a word24 address
  25 # define BLK_ADDR(ADDR) ((ADDR) & (word24) 077777774)
  26 
  27 void cacheReset (cpu_state_t * cpup);
  28 void cacheCpuReset (cpu_state_t * cpup);
  29 bool cacheConfigured (cpu_state_t * cpup);
  30 void cacheConfigChanged (cpu_state_t * cpup, bool was);
  31 void cacheUpdateAnyOn (void);
  32 void cacheClearStarted (cpu_state_t * cpup);
  33 void cacheInvalidateOn (cpu_state_t * cpup, word24 addr);
  34 void cachePurgeOthers (cpu_state_t * cpup, word24 addr);
  35 void cacheStoreNotifyOn (cpu_state_t * cpup, word24 addr, word36 data);
  36 void cacheStoreBadParity (cpu_state_t * cpup, word24 addr);
  37 void cachePurgeAllOn (word24 addr);
  38 void cacheStats (uint cpuNo);
  39 word36 cacheDirWord (cpu_state_t * cpup, word24 y);
  40 
  41 # if defined(LOCKLESS)
  42 int cache_read_lock_on (cpu_state_t * cpup, word24 addr, word36 *data, const char * ctx);
  43 # endif /* if defined(LOCKLESS) */
  44 int cache_read_on (cpu_state_t * cpup, word24 addr, word36 *data, const char * ctx);
  45 int cache_read2_on (cpu_state_t * cpup, word24 addr, word36 *even, word36 *odd, const char * ctx);
  46 void cache_writeN_on (cpu_state_t * cpup, word24 addr, word36 * data, uint n, const char * ctx);
  47 void cache_readN_on (cpu_state_t * cpup, word24 addr, word36 * data, uint n, const char * ctx);
  48 int cache_write2_on (cpu_state_t * cpup, word24 addr, word36 even, word36 odd, const char * ctx);
  49 
  50 // Is the cache model on in any CPU (enable_cache and enable_wam)?  Kept by
  51 // cacheUpdateAnyOn whenever a CPU's configuration changes and when the
  52 // simulation starts. While it is off (the default, and what Multics runs
  53 // with), the cache layer below goes straight to the core_* routines: the
  54 // memory path costs what it did before the cache model, and stores don't
  55 // look for other CPUs' caches to purge.
  56 # if defined(THREADZ) || defined(LOCKLESS)
  57 extern atomic_bool cacheAnyOn;
  58 #  define CACHE_ANY_ON() UNLIKELY (atomic_load_explicit (& cacheAnyOn, memory_order_relaxed))
  59 # else
  60 extern bool cacheAnyOn;
  61 #  define CACHE_ANY_ON() UNLIKELY (cacheAnyOn)
  62 # endif
  63 
  64 // A PTW or SDW this CPU modified in memory: drop it from its own cache
  65 static inline void cacheInvalidate (cpu_state_t * cpup, word24 addr) {
     /* [previous][next][first][last][top][bottom][index][help] */
  66   if (CACHE_ANY_ON ())
  67     cacheInvalidateOn (cpup, addr);
  68 }
  69 
  70 // This CPU stored DATA to real address ADDR: update its own cached copy and
  71 // purge the other CPUs' caches (see cacheStoreNotifyOn)
  72 static inline void cacheStoreNotify (cpu_state_t * cpup, word24 addr, word36 data) {
     /* [previous][next][first][last][top][bottom][index][help] */
  73   if (CACHE_ANY_ON ())
  74     cacheStoreNotifyOn (cpup, addr, data);
  75 }
  76 
  77 // A store from outside the CPUs: purge every CPU's cache
  78 static inline void cachePurgeAll (word24 addr) {
     /* [previous][next][first][last][top][bottom][index][help] */
  79   if (CACHE_ANY_ON ())
  80     cachePurgeAllOn (addr);
  81 }
  82 
  83 // The CPU's memory accesses. The instruction fetch sets the fetch flag
  84 // (cpu.cacheFetch) only while a cache is on.
  85 
  86 # if defined(LOCKLESS)
  87 static inline int cache_read_lock (cpu_state_t * cpup, word24 addr, word36 *data, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
  88   if (! CACHE_ANY_ON ()) {
  89     return core_read_lock (cpup, addr, data, ctx);
  90   }
  91   return cache_read_lock_on (cpup, addr, data, ctx);
  92 }
  93 
  94 static inline int cache_write_unlock (cpu_state_t * cpup, word24 addr, word36 data, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
  95   return core_write_unlock (cpup, addr, data, ctx);
  96 }
  97 # endif /* if defined(LOCKLESS) */
  98 
  99 static inline int cache_read (cpu_state_t * cpup, word24 addr, word36 *data, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 100   if (! CACHE_ANY_ON ()) {
 101     return core_read (cpup, addr, data, ctx);
 102   }
 103   return cache_read_on (cpup, addr, data, ctx);
 104 }
 105 
 106 static inline int cache_read2 (cpu_state_t * cpup, word24 addr, word36 *even, word36 *odd, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 107   if (! CACHE_ANY_ON ()) {
 108     return core_read2 (cpup, addr, even, odd, ctx);
 109   }
 110   return cache_read2_on (cpup, addr, even, odd, ctx);
 111 }
 112 
 113 static inline void cache_readN (cpu_state_t * cpup, word24 addr, word36 * data, uint n, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 114   if (! CACHE_ANY_ON ()) {
 115     core_readN (cpup, addr, data, n, ctx);
 116     return;
 117   }
 118   cache_readN_on (cpup, addr, data, n, ctx);
 119 }
 120 
 121 static inline int cache_write_zone (cpu_state_t * cpup, word24 addr, word36 data, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 122   return core_write_zone (cpup, addr, data, NULL, ctx);
 123 }
 124 
 125 static inline int cache_write (cpu_state_t * cpup, word24 addr, word36 data, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 126   return core_write (cpup, addr, data, ctx);
 127 }
 128 
 129 static inline void cache_writeN (cpu_state_t * cpup, word24 addr, word36 * data, uint n, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 130   if (! CACHE_ANY_ON ()) {
 131     core_writeN (cpup, addr, data, n, ctx);
 132     return;
 133   }
 134   cache_writeN_on (cpup, addr, data, n, ctx);
 135 }
 136 
 137 static inline int cache_write2 (cpu_state_t * cpup, word24 addr, word36 even, word36 odd, const char * ctx) {
     /* [previous][next][first][last][top][bottom][index][help] */
 138   if (! CACHE_ANY_ON ())
 139     return core_write2 (cpup, addr, even, odd, ctx);
 140   return cache_write2_on (cpup, addr, even, odd, ctx);
 141 }
 142 
 143 #endif // !defined(DPS8_CACHE_H)

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