From d44685e103784a123a0f18aa54cfb6ea41987ad9 Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Thu, 1 Jan 2026 11:16:43 +0100 Subject: [PATCH] unix/mpconfigport: Enable natmod loading for RISC-V builds. This commit lets the Unix port load native modules when built for both RV32 and RV64. Since RV64 doesn't have a native emitter, the new native code loading configuration settings have been used to allow such a feature. RV32 is fully supported by the native emitter framework but the emitter wasn't enabled for Unix builds (and therefore no natmod support). RV64 builds have been tested on QEMU and on a MilkV-Duo board, and whilst RV32 isn't really tested, its native code loading functionality is routinely tested both on bare-metal QEMU and on microcontroller boards. Since the code for RV64 under Unix and RV32 is essentially the same, having RV64 working is a strong indicator that RV32 will work too. Signed-off-by: Alessandro Gatti --- ports/unix/mpconfigport.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 854da1dbd4..e290935bca 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -72,6 +72,12 @@ #if !defined(MICROPY_EMIT_ARM) && defined(__arm__) && !defined(__thumb2__) #define MICROPY_EMIT_ARM (1) #endif +#if !defined(MICROPY_EMIT_RV32) && defined(__riscv) && __riscv_xlen == 32 + #define MICROPY_EMIT_RV32 (1) +#endif +#if !defined(MICROPY_PERSISTENT_CODE_LOAD_NATIVE) && defined(__riscv) && __riscv_xlen == 64 + #define MICROPY_PERSISTENT_CODE_LOAD_NATIVE (1) +#endif // Cannot include , as it may lead to symbol name clashes #if _FILE_OFFSET_BITS == 64 && !defined(__LP64__) @@ -93,7 +99,7 @@ typedef long mp_off_t; // Always enable GC. #define MICROPY_ENABLE_GC (1) -#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 64))) +#if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__) || (defined(__riscv) && __riscv_xlen <= 64)) // Fall back to setjmp() implementation for discovery of GC pointers in registers. #define MICROPY_GCREGS_SETJMP (1) #endif