Skip to content

Commit 9e9da6c

Browse files
committed
py/emitglue: Flush caches when loading native code without emitters.
This commit forces a data/instruction cache flush after loading native code blocks even if there's no emitter available. Caches flush upon native code load was still tied to the presence of a native emitter, but this assumption is no longer valid due to previous commits decoupling native code loading from code generation availability. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 5ae928a commit 9e9da6c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

py/emitglue.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, cons
107107
// Some architectures require flushing/invalidation of the I/D caches,
108108
// so that the generated native code which was created in data RAM will
109109
// be available for execution from instruction RAM.
110-
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB
110+
#if MICROPY_EMIT_THUMB || MICROPY_EMIT_INLINE_THUMB || (MP_NATIVE_ARCH_ARMV6M <= MPY_FEATURE_ARCH && MPY_FEATURE_ARCH <= MP_NATIVE_ARCH_ARMV7EMDP)
111111
#if __ICACHE_PRESENT == 1
112112
// Flush D-cache, so the code emitted is stored in RAM.
113113
MP_HAL_CLEAN_DCACHE(fun_data, fun_len);
114114
// Invalidate I-cache, so the newly-created code is reloaded from RAM.
115115
SCB_InvalidateICache();
116116
#endif
117-
#elif MICROPY_EMIT_ARM
117+
#elif MICROPY_EMIT_ARM || (MPY_FEATURE_ARCH == MP_NATIVE_ARCH_ARMV6)
118118
#if (defined(__linux__) && defined(__GNUC__)) || __ARM_ARCH == 7
119119
__builtin___clear_cache((void *)fun_data, (char *)fun_data + fun_len);
120120
#elif defined(__arm__)
@@ -127,7 +127,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, cons
127127
"mcr p15, 0, r0, c7, c7, 0\n" // invalidate I-cache and D-cache
128128
: : : "r0", "cc");
129129
#endif
130-
#elif (MICROPY_EMIT_RV32 || MICROPY_EMIT_INLINE_RV32) && defined(MP_HAL_CLEAN_DCACHE)
130+
#elif (MICROPY_EMIT_RV32 || MICROPY_EMIT_INLINE_RV32 || (MPY_FEATURE_ARCH == MP_NATIVE_ARCH_RV32IMC)) && defined(MP_HAL_CLEAN_DCACHE)
131131
// Flush the D-cache.
132132
MP_HAL_CLEAN_DCACHE(fun_data, fun_len);
133133
#endif

0 commit comments

Comments
 (0)