]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Make sure hardware emulated RTG boards don't have barrier at the start of VRAM space...
authorToni Wilen <twilen@winuae.net>
Sun, 7 Aug 2022 17:46:17 +0000 (20:46 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 7 Aug 2022 17:46:17 +0000 (20:46 +0300)
debug.cpp
expansion.cpp
include/memory.h
memory.cpp
newcpu.cpp
od-win32/mman.cpp

index 6747423f6961fc9df6495335127243f9609c9b6e..a0ca11302152c05ed999c5c5df72a60fc3dc8549 100644 (file)
--- a/debug.cpp
+++ b/debug.cpp
@@ -4540,10 +4540,11 @@ static void memory_map_dump_3(UaeMemoryMap *map, int log)
                                        size_out /= 1024;
                                        size_ext = 'M';
                                }
-                               _stprintf (txt, _T("%08X %7d%c/%d = %7d%c %s%s %s %s"), (j << 16) | bankoffset, size_out, size_ext,
+                               _stprintf (txt, _T("%08X %7d%c/%d = %7d%c %s%s%c %s %s"), (j << 16) | bankoffset, size_out, size_ext,
                                        mirrored, mirrored ? size_out / mirrored : size_out, size_ext,
                                        (a1->flags & ABFLAG_CACHE_ENABLE_INS) ? _T("I") : _T("-"),
                                        (a1->flags & ABFLAG_CACHE_ENABLE_DATA) ? _T("D") : _T("-"),
+                                       a1->baseaddr == NULL ? ' ' : '*',
                                        bankmodes[ce_banktype[j]],
                                        name);
                                tmp[0] = 0;
index ae76beeca7df52638e64b1b14b8debbab7ddee42..f70bf6c4cf2062f1c463eea030ece26523b721bf 100644 (file)
@@ -403,6 +403,7 @@ static addrbank *expamem_init_last (void)
        expamem_init_clear2 ();
        write_log (_T("Memory map after autoconfig:\n"));
        memory_map_dump ();
+       mman_set_barriers(false);
        return NULL;
 }
 
index 4b9ae5915f2c10fb05b33cd3cd5c2c23d2ef11b4..71e1ae630c5d0f61bd5b36339fb73c987165d7ab 100644 (file)
@@ -109,7 +109,9 @@ enum
 #define ABFLAG_CACHE_ENABLE_ALL (ABFLAG_CACHE_ENABLE_BOTH | ABFLAG_CACHE_ENABLE_INS_BURST | ABFLAG_CACHE_ENABLE_DATA_BURST)
 
 typedef struct {
-       /* These ones should be self-explanatory... */
+       /* These ones should be self-explanatory...
+        * Do not move. JIT depends on it
+        */
        mem_get_func lget, wget, bget;
        mem_put_func lput, wput, bput;
        /* Use xlateaddr to translate an Amiga address to a uae_u8 * that can
@@ -145,6 +147,8 @@ typedef struct {
        uae_u8 *baseaddr_direct_r;
        uae_u8 *baseaddr_direct_w;
        uae_u32 startaccessmask;
+       bool barrier;
+       uae_u32 protectmode;
 } addrbank;
 
 #define MEMORY_MIN_SUBBANK 1024
@@ -531,6 +535,7 @@ extern bool read_kickstart_version(struct uae_prefs *p);
 extern void chipmem_setindirect(void);
 extern void initramboard(addrbank *ab, struct ramboard *rb);
 extern void loadboardfile(addrbank *ab, struct boardloadfile *lf);
+extern void mman_set_barriers(bool);
 
 uae_u32 memory_get_long(uaecptr);
 uae_u32 memory_get_word(uaecptr);
index 1c9de15514f6571de3b7820e2ffa8cf3f581bfbf..601cb88a061619e250557d910d6b107e6822ae8a 100644 (file)
@@ -2162,6 +2162,7 @@ bool mapped_malloc (addrbank *ab)
                        if (md.hasbarrier) {
                                // fill end of ram with ILLEGAL to catch direct PC falling out of RAM.
                                put_long_host(ab->baseaddr + ab->reserved_size, 0x4afc4afc);
+                               ab->barrier = true;
                        }
                        ab->allocated_size = ab->reserved_size;
                }
index 913b9f54dee1a448cf8901c8be4e9a6114a6f0d4..0bbef6e4ac170feaadea277783ca3eeee9b5df84 100644 (file)
@@ -2163,6 +2163,7 @@ static void prefs_changed_cpu (void)
        currprefs.int_no_unimplemented = changed_prefs.int_no_unimplemented;
        currprefs.fpu_no_unimplemented = changed_prefs.fpu_no_unimplemented;
        currprefs.blitter_cycle_exact = changed_prefs.blitter_cycle_exact;
+       mman_set_barriers(false);
 }
 
 static int check_prefs_changed_cpu2(void)
@@ -6360,8 +6361,9 @@ void m68k_go (int may_quit)
 
                set_x_funcs();
                if (startup) {
-                       custom_prepare ();
-                       protect_roms (true);
+                       custom_prepare();
+                       mman_set_barriers(false);
+                       protect_roms(true);
                }
                startup = 0;
                event_wait = true;
@@ -6417,7 +6419,8 @@ void m68k_go (int may_quit)
 #endif
                run_func();
        }
-       protect_roms (false);
+       protect_roms(false);
+       mman_set_barriers(true);
        in_m68k_go--;
 }
 
index 545b06ffbc7465b8a9a99db63cbbb78b8c2885b6..6c4922d765f04018bfcdc5d4da703eaaa1131706 100644 (file)
@@ -968,7 +968,15 @@ void *uae_shmat (addrbank *ab, int shmid, void *shmaddr, int shmflg, struct uae_
        return result;
 }
 
-void unprotect_maprom (void)
+// remove possible barrier at the start of this memory region
+void uae_mman_unmap(addrbank *ab, struct uae_mman_data *md)
+{
+       if (canbang && (ab->flags & ABFLAG_ALLOCINDIRECT)) {
+               virtualfreewithlock(ab->start + natmem_offset, ab->reserved_size, MEM_DECOMMIT);
+       }
+}
+
+void unprotect_maprom(void)
 {
        bool protect = false;
        for (int i = 0; i < MAX_SHMID; i++) {
@@ -989,7 +997,7 @@ void unprotect_maprom (void)
        }
 }
 
-void protect_roms (bool protect)
+void protect_roms(bool protect)
 {
        if (protect) {
                // protect only if JIT enabled, always allow unprotect
@@ -1017,6 +1025,55 @@ void protect_roms (bool protect)
        }
 }
 
+// Mark indirect regions (indirect VRAM) as non-accessible when JIT direct is active.
+// Beginning of region might have barrier region which is not marked as non-accessible,
+// allowing JIT direct to think it is directly accessible VRAM.
+void mman_set_barriers(bool disable)
+{
+       addrbank *abprev = NULL;
+       for (int i = 0; i < MEMORY_BANKS; i++) {
+               uaecptr addr = i * 0x10000;
+               addrbank *ab = &get_mem_bank(addr);
+               if (ab == abprev) {
+                       continue;
+               }
+               int size = 0x10000;
+               for (int j = i + 1; j < MEMORY_BANKS; j++) {
+                       uaecptr addr2 = j * 0x10000;
+                       addrbank *ab2 = &get_mem_bank(addr2);
+                       if (ab2 != ab) {
+                               break;
+                       }
+                       size += 0x10000;
+               }
+               abprev = ab;
+               if (ab && ab->baseaddr == NULL && (ab->flags & ABFLAG_ALLOCINDIRECT)) {
+                       DWORD old;
+                       if (disable || !currprefs.cachesize || currprefs.comptrustbyte || currprefs.comptrustword || currprefs.comptrustlong) {
+                               if (!ab->protectmode) {
+                                       ab->protectmode = PAGE_READWRITE;
+                               }
+                               if (!VirtualProtect(addr + natmem_offset, size, ab->protectmode, &old)) {
+                                       size = 0x1000;
+                                       VirtualProtect(addr + natmem_offset, size, ab->protectmode, &old);
+                               }
+                               write_log("%08x-%08x = access restored (%08x)\n", addr, size, ab->protectmode);
+                       } else {
+                               if (VirtualProtect(addr + natmem_offset, size, PAGE_NOACCESS, &old)) {
+                                       ab->protectmode = old;
+                                       write_log("%08x-%08x = set to no access\n", addr, addr + size);
+                               } else {
+                                       size = 0x1000;
+                                       if (VirtualProtect(addr + natmem_offset, size, PAGE_NOACCESS, &old)) {
+                                               ab->protectmode = old;
+                                               write_log("%08x-%08x = set to no access\n", addr, addr + size);
+                                       }
+                               }
+                       }
+               }
+       }
+}
+
 int uae_shmdt (const void *shmaddr)
 {
        return 0;