Skip to content

Commit 9721955

Browse files
maass-hamburgdpgeorge
authored andcommitted
zephyr: Add support for RISC-V RV32IMC native code emitter.
Add support for RISC-V RV32IMC native code emitter in the zephyr port. It will be automatically enabled by default, but can be overridden by defining `MICROPY_EMIT_RV32` and/or `MICROPY_EMIT_INLINE_RV32`. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent 6ae08ea commit 9721955

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

ports/zephyr/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ include(${MICROPY_DIR}/extmod/extmod.cmake)
3737

3838
list(APPEND DTS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/dts)
3939

40+
# Define mpy-cross flags, for use with frozen code.
41+
if(CONFIG_RISCV_ISA_RV32I AND CONFIG_RISCV_ISA_EXT_M AND CONFIG_RISCV_ISA_EXT_C)
42+
set(ARCH_FLAGS "")
43+
set(RV32_EXT "")
44+
if(CONFIG_RISCV_ISA_EXT_ZBA)
45+
list(APPEND RV32_EXT "zba")
46+
endif()
47+
if(CONFIG_RISCV_ISA_EXT_ZCMP)
48+
list(APPEND RV32_EXT "zcmp")
49+
endif()
50+
if(RV32_EXT)
51+
list(JOIN RV32_EXT "," RV32_EXT)
52+
set(ARCH_FLAGS "-march-flags=${RV32_EXT}")
53+
endif()
54+
set(MICROPY_CROSS_FLAGS "-march=rv32imc ${ARCH_FLAGS}")
55+
elseif(CONFIG_RISCV_ISA_RV64I AND CONFIG_RISCV_ISA_EXT_M AND CONFIG_RISCV_ISA_EXT_C)
56+
set(MICROPY_CROSS_FLAGS -march=rv64imc)
57+
endif()
58+
4059
if (CONFIG_MICROPY_FROZEN_MODULES)
4160
cmake_path(ABSOLUTE_PATH CONFIG_MICROPY_FROZEN_MANIFEST BASE_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
4261
set(MICROPY_FROZEN_MANIFEST ${CONFIG_MICROPY_FROZEN_MANIFEST})

ports/zephyr/mpconfigport.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@
113113
#define MICROPY_VFS (1)
114114
#define MICROPY_READER_VFS (MICROPY_VFS)
115115

116+
#if defined(CONFIG_RISCV_ISA_RV32I) && defined(CONFIG_RISCV_ISA_EXT_M) && defined(CONFIG_RISCV_ISA_EXT_C)
117+
118+
#ifndef MICROPY_EMIT_RV32
119+
#define MICROPY_EMIT_RV32 (1)
120+
#endif
121+
122+
#ifndef MICROPY_EMIT_INLINE_RV32
123+
#define MICROPY_EMIT_INLINE_RV32 (1)
124+
#endif
125+
126+
#ifdef CONFIG_RISCV_ISA_EXT_ZBA
127+
#define MICROPY_EMIT_RV32_ZBA (1)
128+
#endif
129+
130+
#ifdef CONFIG_RISCV_ISA_EXT_ZCMP
131+
#define MICROPY_EMIT_RV32_ZCMP (1)
132+
#endif
133+
134+
#endif // CONFIG_RISCV_ISA_RV32I
135+
116136
// fatfs configuration used in ffconf.h
117137
#define MICROPY_FATFS_ENABLE_LFN (1)
118138
#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */

0 commit comments

Comments
 (0)