Skip to content

Add PICO_CRT0_NEAR_CALLS to indicate that crt0 can call runtimine_init/main/exit etc via near calls #2452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/rp2_common/pico_crt0/crt0.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "boot/picobin.h"
#include "pico/bootrom.h"

// PICO_CONFIG: PICO_CRT0_NEAR_CALLS, Whether calls from crt0 into the binary are near (<16M away) - ignored for PICO_COPY_TO_RAM, default=0, type=bool, group=pico_crt0
#ifndef PICO_CRT0_NEAR_CALLS
#define PICO_CRT0_NEAR_CALLS 0
#endif

#ifdef NDEBUG
#ifndef COLLAPSE_IRQS
#define COLLAPSE_IRQS
Expand Down Expand Up @@ -371,6 +376,12 @@ _entry_point:
sev
1:
#endif
#if !__ARM_ARCH_6M__
// Make sure stack limit is 0 if we came in thru the debugger; we do not know what it should be
movs r0, #0
msr msplim, r0
#endif

ldr r0, =__vectors
// Vector through our own table (SP, VTOR will not have been set up at
// this point). Same path for debugger entry and bootloader entry.
Expand All @@ -397,6 +408,9 @@ _enter_vtable_in_r0:
.type _reset_handler,%function
.thumb_func
_reset_handler:
// Note if we entered thru here on core 0, then we should have gone thru bootrom, so SP (and MSPLIM) on Armv8-M
// should already be set

// Only core 0 should run the C runtime startup code; core 1 is normally
// sleeping in the bootrom at this point but check to be sure (e.g. if
// debugger put core 1 at the ELF entry point for some reason)
Expand Down Expand Up @@ -459,20 +473,20 @@ bss_fill_test:
bne bss_fill_loop

platform_entry: // symbol for stack traces
#if PICO_CRT0_NEAR_CALLS && !PICO_COPY_TO_RAM
bl runtime_init
bl main
bl exit
#else
// Use 32-bit jumps, in case these symbols are moved out of branch range
// (e.g. if main is in SRAM and crt0 in flash)
#if !__ARM_ARCH_6M__
// Make sure stack limit is 0 - the user can set it themselves
// todo probably worth adding to the EXE_DEF in the future
movs r0, #0
msr msplim, r0
#endif
ldr r1, =runtime_init
blx r1
ldr r1, =main
blx r1
ldr r1, =exit
blx r1
#endif
// exit should not return. If it does, hang the core.
1: // separate label because _exit can be moved out of branch range
bkpt #0
Expand Down
6 changes: 5 additions & 1 deletion src/rp2_common/pico_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ endif()
# FPGA_CHECK - checks for FPGA which allows Raspberry Pi to run your binary on FPGA;
# PANIC - default panic impl which brings in stdio;
# AUTO_INIT_MUTEX - auto init mutexes, without this you get no printf mutex either;
# CRT0_FAR_CALLS - use blx not bl for calls from crt0 to user overridable functions;
#
# \param\ INCLUDE The items to include
# \param\ EXCLUDE The items to exclude
Expand Down Expand Up @@ -148,4 +149,7 @@ function(pico_minimize_runtime TARGET)
if (NOT RUNTIME_INCLUDE_FPGA_CHECK)
target_compile_definitions(${TARGET} PRIVATE PICO_NO_FPGA_CHECK=1)
endif()
endfunction()
if (NOT RUNTIME_CRT0_FAR_CALLS)
target_compile_definitions(${TARGET} PRIVATE PICO_CRT0_NEAR_CALLS=1)
endif()
endfunction()
Loading