summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-11-17 03:42:06 +0100
committerAlessandro Gatti <a.gatti@frob.it>2025-12-30 18:18:42 +0100
commite939d3ec76eba180deb36696a69cf5ea34c9876d (patch)
treeb4211bc432fe6c1a15b23817aa7d4d661a11dfa6 /tools
parent1f67289a9e5eec98fa2eb34e8188920753bc19a8 (diff)
tools/mpy_ld.py: Add RV64 natmod support.
This commit adds the ability to compile native modules for the RV64 platform, using "rv64imc" as its architecture name (eg. "make ARCH=rv64imc" should build a RV64 natmod). The rest of 64-bits relocations needed to build a native module are now implemented, and all sample native modules build without errors or warnings. The same Picolibc caveats on RV32 also apply on RV64, thus the documentation was updated accordingly. RV64 native modules are also built as part of the CI process, but not yet executed as the QEMU port is not yet able to load and run them. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ci.sh9
-rwxr-xr-xtools/mpy_ld.py15
2 files changed, 19 insertions, 5 deletions
diff --git a/tools/ci.sh b/tools/ci.sh
index 60e870ce6..4ade31160 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -378,6 +378,8 @@ function ci_qemu_setup_rv64 {
ci_gcc_riscv_setup
sudo apt-get update
sudo apt-get install qemu-system
+ sudo pip3 install pyelftools
+ sudo pip3 install ar
qemu-system-riscv64 --version
}
@@ -436,6 +438,9 @@ function ci_qemu_build_rv64 {
make ${MAKEOPTS} -C mpy-cross
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV64 submodules
make ${MAKEOPTS} -C ports/qemu BOARD=VIRT_RV64 test
+
+ # Test building native .mpy with rv64imc architecture.
+ ci_native_mpy_modules_build rv64imc
}
########################################################################################
@@ -669,9 +674,9 @@ function ci_native_mpy_modules_build {
make -C examples/natmod/$natmod ARCH=$arch
done
- # features2 requires soft-float on rv32imc and xtensa.
+ # features2 requires soft-float on rv32imc, rv64imc, and xtensa.
make -C examples/natmod/features2 ARCH=$arch clean
- if [ $arch = "rv32imc" ] || [ $arch = "xtensa" ]; then
+ if [ $arch = "rv32imc" ] || [ $arch = "rv64imc" ] || [ $arch = "xtensa" ]; then
make -C examples/natmod/features2 ARCH=$arch MICROPY_FLOAT_IMPL=float
else
make -C examples/natmod/features2 ARCH=$arch
diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py
index b3b28e453..b363c6a25 100755
--- a/tools/mpy_ld.py
+++ b/tools/mpy_ld.py
@@ -49,6 +49,7 @@ MP_NATIVE_ARCH_ARMV7EMDP = 8
MP_NATIVE_ARCH_XTENSA = 9
MP_NATIVE_ARCH_XTENSAWIN = 10
MP_NATIVE_ARCH_RV32IMC = 11
+MP_NATIVE_ARCH_RV64IMC = 12
MP_PERSISTENT_OBJ_STR = 5
MP_SCOPE_FLAG_VIPERRELOC = 0x10
MP_SCOPE_FLAG_VIPERRODATA = 0x20
@@ -62,6 +63,7 @@ R_RISCV_32 = 1
R_X86_64_64 = 1
R_XTENSA_32 = 1
R_386_PC32 = 2
+R_RISCV_64 = 2
R_X86_64_PC32 = 2
R_ARM_ABS32 = 2
R_386_GOT32 = 3
@@ -175,7 +177,7 @@ def asm_jump_xtensa(entry):
return struct.pack("<BH", jump_op & 0xFF, jump_op >> 8)
-def asm_jump_rv32(entry):
+def asm_jump_riscv(entry):
# This could be 6 bytes shorter, but the code currently cannot
# support a trampoline with varying length depending on the offset.
@@ -261,7 +263,14 @@ ARCH_DATA = {
MP_NATIVE_ARCH_RV32IMC << 2,
4,
(R_RISCV_32, R_RISCV_GOT_HI20, R_RISCV_GOT32_PCREL),
- asm_jump_rv32,
+ asm_jump_riscv,
+ ),
+ "rv64imc": ArchData(
+ "EM_RISCV",
+ MP_NATIVE_ARCH_RV64IMC << 2,
+ 8,
+ (R_RISCV_64, R_RISCV_GOT_HI20, R_RISCV_GOT32_PCREL),
+ asm_jump_riscv,
),
}
@@ -779,7 +788,7 @@ def do_relocation_data(env, text_addr, r):
or env.arch.name == "EM_XTENSA"
and r_info_type == R_XTENSA_32
or env.arch.name == "EM_RISCV"
- and r_info_type == R_RISCV_32
+ and r_info_type in (R_RISCV_32, R_RISCV_64)
):
# Relocation in data.rel.ro to internal/external symbol
if env.arch.word_size == 4: