summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-09-23 22:52:44 +0200
committerAlessandro Gatti <a.gatti@frob.it>2025-10-24 18:30:55 +0200
commit64971f1a65aed54e6a1c041d069c2cb75f2dd64b (patch)
tree34c6b0b7db8424842b81a88681a565dc85768f67 /py
parenta6bc1ccbe51e582d39c6bf7b484c75bfb662357b (diff)
py/persistentcode: Add architecture flags check for RV32 platforms.
This commit introduces the MPY architecture flags checking code specific for the RV32 target, currently checking for the only additional extension that is supported by the runtime: Zba. The warnings inside "mpy-cross" have also been removed since now there is a way to reject incompatible MPY files at runtime. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Diffstat (limited to 'py')
-rw-r--r--py/asmrv32.h2
-rw-r--r--py/persistentcode.c19
2 files changed, 19 insertions, 2 deletions
diff --git a/py/asmrv32.h b/py/asmrv32.h
index 27a08cf9f..4456e6119 100644
--- a/py/asmrv32.h
+++ b/py/asmrv32.h
@@ -125,6 +125,8 @@ typedef struct _asm_rv32_t {
enum {
RV32_EXT_NONE = 0,
RV32_EXT_ZBA = 1 << 0,
+
+ RV32_EXT_ALL = RV32_EXT_ZBA
};
typedef struct _asm_rv32_backend_options_t {
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 7d71cfd98..b12c10074 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -63,6 +63,10 @@ typedef struct _bytecode_prelude_t {
uint code_info_size;
} bytecode_prelude_t;
+#if MICROPY_EMIT_RV32
+#include "py/asmrv32.h"
+#endif
+
#endif // MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE
#if MICROPY_PERSISTENT_CODE_LOAD
@@ -485,8 +489,19 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {
size_t arch_flags = 0;
if (MPY_FEATURE_ARCH_FLAGS_TEST(header[2])) {
- (void)arch_flags;
- mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file"));
+ #if MICROPY_EMIT_RV32
+ arch_flags = read_uint(reader);
+
+ if (MPY_FEATURE_ARCH_TEST(MP_NATIVE_ARCH_RV32IMC)) {
+ if ((arch_flags & (size_t)asm_rv32_allowed_extensions()) != arch_flags) {
+ mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file"));
+ }
+ } else
+ #endif
+ {
+ (void)arch_flags;
+ mp_raise_ValueError(MP_ERROR_TEXT("incompatible .mpy file"));
+ }
}
size_t n_qstr = read_uint(reader);