Skip to content

Commit 26be283

Browse files
committed
Merge branch 'master' into libretro
2 parents 67881ef + d8f2909 commit 26be283

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

libpcsxcore/new_dynarec/emu_if.c

+18-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "../gte_arm.h"
1818
#include "../gte_neon.h"
1919
#include "compiler_features.h"
20+
#include "arm_features.h"
2021
#define FLAGLESS
2122
#include "../gte.h"
2223
#ifdef NDRC_THREAD
@@ -317,13 +318,24 @@ static void ari64_apply_config()
317318
#ifdef NDRC_THREAD
318319
static void clear_local_cache(void)
319320
{
320-
#ifdef _3DS
321-
if (ndrc_g.thread.cache_dirty) {
322-
ndrc_g.thread.cache_dirty = 0;
323-
ctr_invalidate_icache();
324-
}
321+
#if defined(__arm__) || defined(__aarch64__)
322+
if (ndrc_g.thread.dirty_start) {
323+
// see "Ensuring the visibility of updates to instructions"
324+
// in v7/v8 reference manuals (DDI0406, DDI0487 etc.)
325+
#if defined(__aarch64__) || defined(HAVE_ARMV8)
326+
// the actual clean/invalidate is broadcast to all cores,
327+
// the manual only prescribes an isb
328+
__asm__ volatile("isb");
329+
//#elif defined(_3DS)
330+
// ctr_invalidate_icache();
325331
#else
326-
// hopefully nothing is needed, as tested on r-pi4 and switch
332+
// while on v6 this is always required, on v7 it depends on
333+
// "Multiprocessing Extensions" being present, but that is difficult
334+
// to detect so do it always for now
335+
new_dyna_clear_cache(ndrc_g.thread.dirty_start, ndrc_g.thread.dirty_end);
336+
#endif
337+
ndrc_g.thread.dirty_start = ndrc_g.thread.dirty_end = 0;
338+
}
327339
#endif
328340
}
329341

libpcsxcore/new_dynarec/new_dynarec.c

+17-7
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,7 @@ static void mprotect_w_x(void *start, void *end, int is_x)
474474
#endif
475475
}
476476

477-
static void start_tcache_write(void *start, void *end)
478-
{
479-
mprotect_w_x(start, end, 0);
480-
}
481-
482-
static void end_tcache_write(void *start, void *end)
477+
void new_dyna_clear_cache(void *start, void *end)
483478
{
484479
#if defined(__arm__) || defined(__aarch64__)
485480
size_t len = (char *)end - (char *)start;
@@ -495,7 +490,6 @@ static void end_tcache_write(void *start, void *end)
495490
ctr_clear_cache_range(start, end);
496491
else
497492
ctr_clear_cache();
498-
ndrc_g.thread.cache_dirty = 1;
499493
#elif defined(HAVE_LIBNX)
500494
if (g_jit.type == JitType_CodeMemory) {
501495
armDCacheClean(start, len);
@@ -512,6 +506,22 @@ static void end_tcache_write(void *start, void *end)
512506
#endif
513507
(void)len;
514508
#endif
509+
}
510+
511+
static void start_tcache_write(void *start, void *end)
512+
{
513+
mprotect_w_x(start, end, 0);
514+
}
515+
516+
static void end_tcache_write(void *start, void *end)
517+
{
518+
#ifdef NDRC_THREAD
519+
if (!ndrc_g.thread.dirty_start || (size_t)ndrc_g.thread.dirty_start > (size_t)start)
520+
ndrc_g.thread.dirty_start = start;
521+
if ((size_t)ndrc_g.thread.dirty_end < (size_t)end)
522+
ndrc_g.thread.dirty_end = end;
523+
#endif
524+
new_dyna_clear_cache(start, end);
515525

516526
mprotect_w_x(start, end, 1);
517527
}

libpcsxcore/new_dynarec/new_dynarec.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ struct ndrc_globals
2222
void *handle;
2323
void *lock;
2424
void *cond;
25+
void *dirty_start;
26+
void *dirty_end;
2527
unsigned int addr;
2628
int busy;
2729
int exit;
28-
int cache_dirty; // 3ds only
2930
} thread;
3031
};
3132
extern struct ndrc_globals ndrc_g;
@@ -40,6 +41,7 @@ void new_dynarec_print_stats(void);
4041
int new_dynarec_quick_check_range(unsigned int start, unsigned int end);
4142
void new_dynarec_invalidate_range(unsigned int start, unsigned int end);
4243
void new_dynarec_invalidate_all_pages(void);
44+
void new_dyna_clear_cache(void *start, void *end);
4345

4446
void new_dyna_start(void *context);
4547
void new_dyna_start_at(void *context, void *compiled_code);

0 commit comments

Comments
 (0)