From d470afd2066b398866016685efcaf5eff1a5052e Mon Sep 17 00:00:00 2001 From: Johan Anderholm Date: Wed, 11 Jun 2025 18:42:32 +0200 Subject: [PATCH] Use la/jr pseudoinstructions for main function call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct jal with load address and jump register pseudoinstructions to support main functions located beyond the ±1MB range of direct jumps. --- riscv-rt/CHANGELOG.md | 5 +++++ riscv-rt/src/asm.rs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/riscv-rt/CHANGELOG.md b/riscv-rt/CHANGELOG.md index c533c6da..56191077 100644 --- a/riscv-rt/CHANGELOG.md +++ b/riscv-rt/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + +- Main function no longer needs to be close to _start. A linker script may copy + all code to RAM and keep .init in flash/ROM. + ## [v0.15.0] - 2025-06-10 ### Added diff --git a/riscv-rt/src/asm.rs b/riscv-rt/src/asm.rs index e8e19199..6e4c263d 100644 --- a/riscv-rt/src/asm.rs +++ b/riscv-rt/src/asm.rs @@ -217,7 +217,8 @@ cfg_global_asm!( ld a1, 8 * 1(sp) ld a2, 8 * 2(sp) addi sp, sp, 8 * 4", - "jal zero, main + "la t0, main + jr t0 .cfi_endproc", );