From c4668b5f0cb3435eab82aee76f16811ee3229b52 Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Tue, 30 Dec 2025 22:10:48 +0100 Subject: [PATCH 1/6] changed so the linkerscript is passed through the preprocessor --- project/CMakeLists.txt | 6 +++-- targets/arm/linkerscript/linkerscript.cmake | 26 +++++++++++++++++++++ targets/arm/linkerscript/linkerscript.ld | 9 +++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 targets/arm/linkerscript/linkerscript.cmake create mode 100644 targets/arm/linkerscript/linkerscript.ld diff --git a/project/CMakeLists.txt b/project/CMakeLists.txt index 96262f44..7d8ad36c 100644 --- a/project/CMakeLists.txt +++ b/project/CMakeLists.txt @@ -1,3 +1,6 @@ +# include the linkerscript generator needed to preprocess the linkerscripts +include (${CMAKE_SOURCE_DIR}/targets/arm/linkerscript/linkerscript.cmake) + # set the sources set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp @@ -40,8 +43,7 @@ target_link_libraries(klib_project PUBLIC target_cpu) target_link_libraries(klib_project PUBLIC m) # link to the linkerscript of the target cpu -target_link_options(klib_project PUBLIC "-T${TARGET_LINKERSCRIPT}") -set_target_properties(klib_project PROPERTIES LINK_DEPENDS ${TARGET_LINKERSCRIPT}) +add_linkerscript(klib_project ${TARGET_LINKERSCRIPT} "") # add the project directory to the include directories include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/targets/arm/linkerscript/linkerscript.cmake b/targets/arm/linkerscript/linkerscript.cmake new file mode 100644 index 00000000..4bf9ea40 --- /dev/null +++ b/targets/arm/linkerscript/linkerscript.cmake @@ -0,0 +1,26 @@ +# helper function to preprocess a linker script. This allows +# using C preprocessor in the linkerscript files (including +# macroes, conditionals, etc) +function(add_linkerscript target linkerscript options) + set(output "${CMAKE_BINARY_DIR}/linkerscript.ld") + set(CURRENT_DIR "${CMAKE_SOURCE_DIR}/targets/arm/linkerscript") + + # run the preprocessor on the linkerscript + add_custom_command( + OUTPUT ${output} + # run the linkerscript through the C preprocessor. Force include the base linkerscript template. + COMMAND ${CMAKE_C_COMPILER} -E -P -x c ${linkerscript} -o ${output} -include ${CURRENT_DIR}/linkerscript.ld ${options} + DEPENDS ${linkerscript} ${CURRENT_DIR}/linkerscript.ld + COMMENT "Preprocessing linker script ${linkerscript}" + VERBATIM + ) + + # create a custom target to generate the linkerscript + add_custom_target(generate_linkerscript DEPENDS "${output}") + add_dependencies(${target} generate_linkerscript) + + # add the linkerscript to the target + target_link_options(${target} PUBLIC "-T${output}") + set_target_properties(${target} PROPERTIES LINK_DEPENDS ${output}) +endfunction() + diff --git a/targets/arm/linkerscript/linkerscript.ld b/targets/arm/linkerscript/linkerscript.ld new file mode 100644 index 00000000..49014463 --- /dev/null +++ b/targets/arm/linkerscript/linkerscript.ld @@ -0,0 +1,9 @@ +/* macro to define the vectors section. Should be pointed to the correct memory region */ +#define VECTORS() \ + .vectors (READONLY) : \ + { \ + . = ALIGN(4); \ + /* vector table */ \ + KEEP(*(.vectors .vectors.*)); \ + . = ALIGN(4); \ + } From af55745948e42be8ce76e38e8f4c6ebad4c5ffb7 Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Tue, 30 Dec 2025 23:41:59 +0100 Subject: [PATCH 2/6] changed all linkerscripts to use macros --- targets/arm/linkerscript/linkerscript.ld | 26 +++++++++++ targets/chip/atsam3x8e/linkerscript.ld | 53 +++------------------- targets/chip/atsam4s2b/linkerscript.ld | 54 +++------------------- targets/chip/lpc1752/linkerscript.ld | 54 +++------------------- targets/chip/lpc1754/linkerscript.ld | 54 +++------------------- targets/chip/lpc1756/linkerscript.ld | 54 +++------------------- targets/chip/lpc1759/linkerscript.ld | 54 +++------------------- targets/chip/lpc1788/linkerscript.ld | 57 +++--------------------- targets/chip/lpc55s66/linkerscript.ld | 54 +++------------------- targets/chip/lpc802/linkerscript.ld | 54 +++------------------- targets/chip/max32625/linkerscript.ld | 54 +++------------------- targets/chip/max32660/linkerscript.ld | 54 +++------------------- targets/chip/mb9bf566k/linkerscript.ld | 54 +++------------------- targets/chip/rp2350/linkerscript.ld | 54 +++------------------- targets/chip/stm32f103/linkerscript.ld | 52 +++------------------ targets/chip/stm32f407/linkerscript.ld | 52 +++------------------ targets/chip/stm32h723/linkerscript.ld | 52 +++------------------ targets/chip/tmpm373/linkerscript.ld | 54 +++------------------- 18 files changed, 113 insertions(+), 827 deletions(-) diff --git a/targets/arm/linkerscript/linkerscript.ld b/targets/arm/linkerscript/linkerscript.ld index 49014463..b3b0f7c9 100644 --- a/targets/arm/linkerscript/linkerscript.ld +++ b/targets/arm/linkerscript/linkerscript.ld @@ -1,3 +1,8 @@ +/* helpers to combine strings with a parameter */ +#define COMBINE_STRX(a,b) a##b +#define COMBINE_STR2(a,b) COMBINE_STRX(a,b) +#define COMBINE_STR3(a,b,c) COMBINE_STR2(COMBINE_STR2(a,b),c) + /* macro to define the vectors section. Should be pointed to the correct memory region */ #define VECTORS() \ .vectors (READONLY) : \ @@ -7,3 +12,24 @@ KEEP(*(.vectors .vectors.*)); \ . = ALIGN(4); \ } + +/* macro to define the rodata section */ +#define RODATA() \ + .rodata (READONLY) : \ + { \ + . = ALIGN(4); \ + /* Constands, strings, etc */ \ + *(.rodata .rodata.* .gnu.linkonce.r.*); \ + . = ALIGN(4); \ + } + +/* macro to define a init array. Array name is passed as an argument */ +#define INIT_ARRAY(name) \ + .name : \ + { \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_start) = .); \ + KEEP(*(SORT(.name.*))) \ + KEEP(*(SORT(.name))) \ + PROVIDE(COMBINE_STR3(__,name,_end) = .); \ + } diff --git a/targets/chip/atsam3x8e/linkerscript.ld b/targets/chip/atsam3x8e/linkerscript.ld index d3f7311e..57354f87 100644 --- a/targets/chip/atsam3x8e/linkerscript.ld +++ b/targets/chip/atsam3x8e/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,50 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/atsam4s2b/linkerscript.ld b/targets/chip/atsam4s2b/linkerscript.ld index a008820e..8625dbca 100644 --- a/targets/chip/atsam4s2b/linkerscript.ld +++ b/targets/chip/atsam4s2b/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,51 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1752/linkerscript.ld b/targets/chip/lpc1752/linkerscript.ld index 9d8f2c27..b8c32f1e 100644 --- a/targets/chip/lpc1752/linkerscript.ld +++ b/targets/chip/lpc1752/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom .crp 0x000002fc : { @@ -81,51 +75,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1754/linkerscript.ld b/targets/chip/lpc1754/linkerscript.ld index 81c08a42..48dd36e8 100644 --- a/targets/chip/lpc1754/linkerscript.ld +++ b/targets/chip/lpc1754/linkerscript.ld @@ -34,13 +34,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom .crp 0x000002fc : { @@ -82,51 +76,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1756/linkerscript.ld b/targets/chip/lpc1756/linkerscript.ld index 17797a57..dcd61aec 100644 --- a/targets/chip/lpc1756/linkerscript.ld +++ b/targets/chip/lpc1756/linkerscript.ld @@ -34,13 +34,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom .crp 0x000002fc : { @@ -82,51 +76,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1759/linkerscript.ld b/targets/chip/lpc1759/linkerscript.ld index 0df1704e..538a1a02 100644 --- a/targets/chip/lpc1759/linkerscript.ld +++ b/targets/chip/lpc1759/linkerscript.ld @@ -37,13 +37,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom .crp 0x000002fc : { @@ -85,51 +79,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1788/linkerscript.ld b/targets/chip/lpc1788/linkerscript.ld index fa733c45..50cd1cc1 100644 --- a/targets/chip/lpc1788/linkerscript.ld +++ b/targets/chip/lpc1788/linkerscript.ld @@ -46,15 +46,9 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom - .crp 0x000002fc : + .crp 0x000002fc (READONLY) : { /* keep this even if it is not used. This prevents the CRP from being enabled @@ -70,7 +64,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -94,50 +88,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/lpc55s66/linkerscript.ld b/targets/chip/lpc55s66/linkerscript.ld index 87481bd2..e5840254 100644 --- a/targets/chip/lpc55s66/linkerscript.ld +++ b/targets/chip/lpc55s66/linkerscript.ld @@ -42,13 +42,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -75,51 +69,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc802/linkerscript.ld b/targets/chip/lpc802/linkerscript.ld index 038cb825..85eb4917 100644 --- a/targets/chip/lpc802/linkerscript.ld +++ b/targets/chip/lpc802/linkerscript.ld @@ -38,13 +38,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -71,51 +65,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/max32625/linkerscript.ld b/targets/chip/max32625/linkerscript.ld index 3fa0e88f..724d4577 100644 --- a/targets/chip/max32625/linkerscript.ld +++ b/targets/chip/max32625/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,51 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/max32660/linkerscript.ld b/targets/chip/max32660/linkerscript.ld index 59b1bacb..61623f1a 100644 --- a/targets/chip/max32660/linkerscript.ld +++ b/targets/chip/max32660/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,51 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/mb9bf566k/linkerscript.ld b/targets/chip/mb9bf566k/linkerscript.ld index 435a812a..d90e0ef6 100644 --- a/targets/chip/mb9bf566k/linkerscript.ld +++ b/targets/chip/mb9bf566k/linkerscript.ld @@ -39,13 +39,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -72,51 +66,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/rp2350/linkerscript.ld b/targets/chip/rp2350/linkerscript.ld index fec16011..0e615007 100644 --- a/targets/chip/rp2350/linkerscript.ld +++ b/targets/chip/rp2350/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Meta data header. Required for the RP2350 bootloader to accept the firmware. Needs to be in the first 4k */ @@ -75,51 +69,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/stm32f103/linkerscript.ld b/targets/chip/stm32f103/linkerscript.ld index 531f5b0e..7f91b2c9 100644 --- a/targets/chip/stm32f103/linkerscript.ld +++ b/targets/chip/stm32f103/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,49 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(.preinit_array)) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(.fini_array)) - - PROVIDE(__fini_array_end = .); - } > rom + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/stm32f407/linkerscript.ld b/targets/chip/stm32f407/linkerscript.ld index 897e20ca..113fcafb 100644 --- a/targets/chip/stm32f407/linkerscript.ld +++ b/targets/chip/stm32f407/linkerscript.ld @@ -34,13 +34,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -67,49 +61,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(.preinit_array)) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(.fini_array)) - - PROVIDE(__fini_array_end = .); - } > rom + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/stm32h723/linkerscript.ld b/targets/chip/stm32h723/linkerscript.ld index d732743f..6b01f8e6 100644 --- a/targets/chip/stm32h723/linkerscript.ld +++ b/targets/chip/stm32h723/linkerscript.ld @@ -37,13 +37,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -68,49 +62,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(.preinit_array)) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(.fini_array)) - - PROVIDE(__fini_array_end = .); - } > rom + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/tmpm373/linkerscript.ld b/targets/chip/tmpm373/linkerscript.ld index 23d1f3ea..ddb9b4be 100644 --- a/targets/chip/tmpm373/linkerscript.ld +++ b/targets/chip/tmpm373/linkerscript.ld @@ -33,13 +33,7 @@ SECTIONS { /* Vector table. Has the initial stack pointer and the initial structure for the arm interrupts */ - .vectors : - { - . = ALIGN(4); - /* vector table */ - KEEP(*(.vectors .vectors.*)); - . = ALIGN(4); - } > rom + VECTORS() > rom /* Text segment, stores all user code */ .text : @@ -66,51 +60,13 @@ SECTIONS } > rom /* Read only data */ - .rodata : - { - . = ALIGN(4); - - /* Constands, strings, etc */ - *(.rodata .rodata.* .gnu.linkonce.r.*); - - . = ALIGN(4); - } > rom + RODATA() > rom /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - .preinit_array : - { - . = ALIGN(4); - PROVIDE(__preinit_array_start = .); - - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(SORT(.preinit_array))) - - PROVIDE(__preinit_array_end = .); - } > rom - - .init_array : - { - . = ALIGN(4); - PROVIDE(__init_array_start = .); - - KEEP(*(SORT(.init_array.*))) - KEEP(*(SORT(.init_array))) - - PROVIDE(__init_array_end = .); - } > rom - - .fini_array : - { - . = ALIGN(4); - PROVIDE(__fini_array_start = .); - - KEEP(*(SORT(.fini_array.*))) - KEEP(*(SORT(.fini_array))) - - PROVIDE(__fini_array_end = .); - } > rom - + INIT_ARRAY(preinit_array) > rom + INIT_ARRAY(init_array) > rom + INIT_ARRAY(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : { From b6bf8a7419c3edf6c8c887b9cab4e6a4da5c296c Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Wed, 31 Dec 2025 01:43:55 +0100 Subject: [PATCH 3/6] renamed INIT_ARRAY to CONSTRUCTOR_SECTION --- targets/arm/linkerscript/linkerscript.ld | 2 +- targets/chip/atsam3x8e/linkerscript.ld | 6 +++--- targets/chip/atsam4s2b/linkerscript.ld | 7 ++++--- targets/chip/lpc1752/linkerscript.ld | 7 ++++--- targets/chip/lpc1754/linkerscript.ld | 7 ++++--- targets/chip/lpc1756/linkerscript.ld | 7 ++++--- targets/chip/lpc1759/linkerscript.ld | 7 ++++--- targets/chip/lpc1788/linkerscript.ld | 6 +++--- targets/chip/lpc55s66/linkerscript.ld | 7 ++++--- targets/chip/lpc802/linkerscript.ld | 7 ++++--- targets/chip/max32625/linkerscript.ld | 7 ++++--- targets/chip/max32660/linkerscript.ld | 7 ++++--- targets/chip/mb9bf566k/linkerscript.ld | 7 ++++--- targets/chip/rp2350/linkerscript.ld | 7 ++++--- targets/chip/stm32f103/linkerscript.ld | 6 +++--- targets/chip/stm32f407/linkerscript.ld | 6 +++--- targets/chip/stm32h723/linkerscript.ld | 6 +++--- targets/chip/tmpm373/linkerscript.ld | 7 ++++--- 18 files changed, 64 insertions(+), 52 deletions(-) diff --git a/targets/arm/linkerscript/linkerscript.ld b/targets/arm/linkerscript/linkerscript.ld index b3b0f7c9..c14ee8c9 100644 --- a/targets/arm/linkerscript/linkerscript.ld +++ b/targets/arm/linkerscript/linkerscript.ld @@ -24,7 +24,7 @@ } /* macro to define a init array. Array name is passed as an argument */ -#define INIT_ARRAY(name) \ +#define CONSTRUCTOR_SECTION(name) \ .name : \ { \ . = ALIGN(4); \ diff --git a/targets/chip/atsam3x8e/linkerscript.ld b/targets/chip/atsam3x8e/linkerscript.ld index 57354f87..2fa0f65d 100644 --- a/targets/chip/atsam3x8e/linkerscript.ld +++ b/targets/chip/atsam3x8e/linkerscript.ld @@ -64,9 +64,9 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/atsam4s2b/linkerscript.ld b/targets/chip/atsam4s2b/linkerscript.ld index 8625dbca..4877eba1 100644 --- a/targets/chip/atsam4s2b/linkerscript.ld +++ b/targets/chip/atsam4s2b/linkerscript.ld @@ -64,9 +64,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1752/linkerscript.ld b/targets/chip/lpc1752/linkerscript.ld index b8c32f1e..db3e6619 100644 --- a/targets/chip/lpc1752/linkerscript.ld +++ b/targets/chip/lpc1752/linkerscript.ld @@ -79,9 +79,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1754/linkerscript.ld b/targets/chip/lpc1754/linkerscript.ld index 48dd36e8..c06b0fa9 100644 --- a/targets/chip/lpc1754/linkerscript.ld +++ b/targets/chip/lpc1754/linkerscript.ld @@ -80,9 +80,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1756/linkerscript.ld b/targets/chip/lpc1756/linkerscript.ld index dcd61aec..41f1a449 100644 --- a/targets/chip/lpc1756/linkerscript.ld +++ b/targets/chip/lpc1756/linkerscript.ld @@ -80,9 +80,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1759/linkerscript.ld b/targets/chip/lpc1759/linkerscript.ld index 538a1a02..35b1964d 100644 --- a/targets/chip/lpc1759/linkerscript.ld +++ b/targets/chip/lpc1759/linkerscript.ld @@ -83,9 +83,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc1788/linkerscript.ld b/targets/chip/lpc1788/linkerscript.ld index 50cd1cc1..2ffd9546 100644 --- a/targets/chip/lpc1788/linkerscript.ld +++ b/targets/chip/lpc1788/linkerscript.ld @@ -92,9 +92,9 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/lpc55s66/linkerscript.ld b/targets/chip/lpc55s66/linkerscript.ld index e5840254..10a3b625 100644 --- a/targets/chip/lpc55s66/linkerscript.ld +++ b/targets/chip/lpc55s66/linkerscript.ld @@ -73,9 +73,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/lpc802/linkerscript.ld b/targets/chip/lpc802/linkerscript.ld index 85eb4917..060c78c9 100644 --- a/targets/chip/lpc802/linkerscript.ld +++ b/targets/chip/lpc802/linkerscript.ld @@ -69,9 +69,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/max32625/linkerscript.ld b/targets/chip/max32625/linkerscript.ld index 724d4577..18734bec 100644 --- a/targets/chip/max32625/linkerscript.ld +++ b/targets/chip/max32625/linkerscript.ld @@ -64,9 +64,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/max32660/linkerscript.ld b/targets/chip/max32660/linkerscript.ld index 61623f1a..f4747e3a 100644 --- a/targets/chip/max32660/linkerscript.ld +++ b/targets/chip/max32660/linkerscript.ld @@ -64,9 +64,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/mb9bf566k/linkerscript.ld b/targets/chip/mb9bf566k/linkerscript.ld index d90e0ef6..258c4dc9 100644 --- a/targets/chip/mb9bf566k/linkerscript.ld +++ b/targets/chip/mb9bf566k/linkerscript.ld @@ -70,9 +70,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/rp2350/linkerscript.ld b/targets/chip/rp2350/linkerscript.ld index 0e615007..09bda4d3 100644 --- a/targets/chip/rp2350/linkerscript.ld +++ b/targets/chip/rp2350/linkerscript.ld @@ -73,9 +73,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { diff --git a/targets/chip/stm32f103/linkerscript.ld b/targets/chip/stm32f103/linkerscript.ld index 7f91b2c9..1ee4c30a 100644 --- a/targets/chip/stm32f103/linkerscript.ld +++ b/targets/chip/stm32f103/linkerscript.ld @@ -64,9 +64,9 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/stm32f407/linkerscript.ld b/targets/chip/stm32f407/linkerscript.ld index 113fcafb..b8a7c950 100644 --- a/targets/chip/stm32f407/linkerscript.ld +++ b/targets/chip/stm32f407/linkerscript.ld @@ -65,9 +65,9 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/stm32h723/linkerscript.ld b/targets/chip/stm32h723/linkerscript.ld index 6b01f8e6..02887c77 100644 --- a/targets/chip/stm32h723/linkerscript.ld +++ b/targets/chip/stm32h723/linkerscript.ld @@ -66,9 +66,9 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ .stack (NOLOAD) : diff --git a/targets/chip/tmpm373/linkerscript.ld b/targets/chip/tmpm373/linkerscript.ld index ddb9b4be..73deda58 100644 --- a/targets/chip/tmpm373/linkerscript.ld +++ b/targets/chip/tmpm373/linkerscript.ld @@ -64,9 +64,10 @@ SECTIONS /* Support C constructors, and C destructors in both user code and the C library. This also provides support for C++ code. */ - INIT_ARRAY(preinit_array) > rom - INIT_ARRAY(init_array) > rom - INIT_ARRAY(fini_array) > rom + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + CONSTRUCTOR_SECTION(fini_array) > rom + /* Stack segment */ .stack (NOLOAD) : { From e763c9de867f55159989750d408cbf711c3228eb Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Wed, 31 Dec 2025 02:40:17 +0100 Subject: [PATCH 4/6] changed stack to stack macro --- targets/arm/linkerscript/linkerscript.ld | 58 ++++++++++++++++++++---- targets/chip/atsam3x8e/linkerscript.ld | 11 +---- targets/chip/atsam4s2b/linkerscript.ld | 11 +---- targets/chip/lpc1752/linkerscript.ld | 11 +---- targets/chip/lpc1754/linkerscript.ld | 11 +---- targets/chip/lpc1756/linkerscript.ld | 11 +---- targets/chip/lpc1759/linkerscript.ld | 11 +---- targets/chip/lpc1788/linkerscript.ld | 11 +---- targets/chip/lpc55s66/linkerscript.ld | 11 +---- targets/chip/lpc802/linkerscript.ld | 11 +---- targets/chip/max32625/linkerscript.ld | 11 +---- targets/chip/max32660/linkerscript.ld | 11 +---- targets/chip/mb9bf566k/linkerscript.ld | 11 +---- targets/chip/rp2350/linkerscript.ld | 11 +---- targets/chip/stm32f103/linkerscript.ld | 11 +---- targets/chip/stm32f407/linkerscript.ld | 11 +---- targets/chip/stm32h723/linkerscript.ld | 11 +---- targets/chip/tmpm373/linkerscript.ld | 11 +---- 18 files changed, 66 insertions(+), 179 deletions(-) diff --git a/targets/arm/linkerscript/linkerscript.ld b/targets/arm/linkerscript/linkerscript.ld index c14ee8c9..ebfecdc0 100644 --- a/targets/arm/linkerscript/linkerscript.ld +++ b/targets/arm/linkerscript/linkerscript.ld @@ -3,24 +3,64 @@ #define COMBINE_STR2(a,b) COMBINE_STRX(a,b) #define COMBINE_STR3(a,b,c) COMBINE_STR2(COMBINE_STR2(a,b),c) +/* helper macro to create a section */ +#define SECTION_IMPL(name, data) \ + .name : \ + { \ + data \ + } + +/* helper macro to create a section with a attribute */ +#define SECTION_IMPL_ATTR(name, attr, data) \ + .name (attr) : \ + { \ + data \ + } + +/* helper macro to create a alligned section */ +#define ALLIGNED_SECTION(name, align, data) \ + SECTION_IMPL( \ + name, \ + . = ALIGN(align); \ + data \ + ) + +/* helper macro to create a alligned readonly section */ +#define ALLIGNED_READONLY_SECTION(name, align, data) \ + SECTION_IMPL_ATTR( \ + name, \ + READONLY, \ + . = ALIGN(align); \ + data \ + ) + /* macro to define the vectors section. Should be pointed to the correct memory region */ #define VECTORS() \ - .vectors (READONLY) : \ - { \ - . = ALIGN(4); \ - /* vector table */ \ + ALLIGNED_READONLY_SECTION( \ + vectors, 4, \ KEEP(*(.vectors .vectors.*)); \ - . = ALIGN(4); \ - } + ) /* macro to define the rodata section */ #define RODATA() \ - .rodata (READONLY) : \ + ALLIGNED_READONLY_SECTION( \ + rodata, 4, \ + *(.rodata .rodata.* .gnu.linkonce.r.*); \ + ) + +/* macro to define the stack with a size in bytes */ +#define STACK(size) \ + .stack (NOLOAD) : \ { \ . = ALIGN(4); \ - /* Constands, strings, etc */ \ - *(.rodata .rodata.* .gnu.linkonce.r.*); \ + /* provide the __stack_start */ \ + PROVIDE(__stack_start = .); \ + /* add the size in bytes to the current address */ \ + . = . + size; \ + /* make sure the size is rounded off to 4 bytes */ \ . = ALIGN(4); \ + /* provide the __stack_end */ \ + PROVIDE(__stack_end = .); \ } /* macro to define a init array. Array name is passed as an argument */ diff --git a/targets/chip/atsam3x8e/linkerscript.ld b/targets/chip/atsam3x8e/linkerscript.ld index 2fa0f65d..8ae24caf 100644 --- a/targets/chip/atsam3x8e/linkerscript.ld +++ b/targets/chip/atsam3x8e/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/atsam4s2b/linkerscript.ld b/targets/chip/atsam4s2b/linkerscript.ld index 4877eba1..8b84bb45 100644 --- a/targets/chip/atsam4s2b/linkerscript.ld +++ b/targets/chip/atsam4s2b/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc1752/linkerscript.ld b/targets/chip/lpc1752/linkerscript.ld index db3e6619..d7f2440b 100644 --- a/targets/chip/lpc1752/linkerscript.ld +++ b/targets/chip/lpc1752/linkerscript.ld @@ -84,16 +84,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc1754/linkerscript.ld b/targets/chip/lpc1754/linkerscript.ld index c06b0fa9..9aa5d3fd 100644 --- a/targets/chip/lpc1754/linkerscript.ld +++ b/targets/chip/lpc1754/linkerscript.ld @@ -85,16 +85,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc1756/linkerscript.ld b/targets/chip/lpc1756/linkerscript.ld index 41f1a449..004129cb 100644 --- a/targets/chip/lpc1756/linkerscript.ld +++ b/targets/chip/lpc1756/linkerscript.ld @@ -85,16 +85,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc1759/linkerscript.ld b/targets/chip/lpc1759/linkerscript.ld index 35b1964d..7baaf1bd 100644 --- a/targets/chip/lpc1759/linkerscript.ld +++ b/targets/chip/lpc1759/linkerscript.ld @@ -88,16 +88,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc1788/linkerscript.ld b/targets/chip/lpc1788/linkerscript.ld index 2ffd9546..0e9ae268 100644 --- a/targets/chip/lpc1788/linkerscript.ld +++ b/targets/chip/lpc1788/linkerscript.ld @@ -97,16 +97,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc55s66/linkerscript.ld b/targets/chip/lpc55s66/linkerscript.ld index 10a3b625..ab90e859 100644 --- a/targets/chip/lpc55s66/linkerscript.ld +++ b/targets/chip/lpc55s66/linkerscript.ld @@ -78,16 +78,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram0 + STACK(STACK_SIZE) > ram0 /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/lpc802/linkerscript.ld b/targets/chip/lpc802/linkerscript.ld index 060c78c9..cd6e96ca 100644 --- a/targets/chip/lpc802/linkerscript.ld +++ b/targets/chip/lpc802/linkerscript.ld @@ -74,16 +74,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/max32625/linkerscript.ld b/targets/chip/max32625/linkerscript.ld index 18734bec..6fbe1752 100644 --- a/targets/chip/max32625/linkerscript.ld +++ b/targets/chip/max32625/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/max32660/linkerscript.ld b/targets/chip/max32660/linkerscript.ld index f4747e3a..18168efd 100644 --- a/targets/chip/max32660/linkerscript.ld +++ b/targets/chip/max32660/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/mb9bf566k/linkerscript.ld b/targets/chip/mb9bf566k/linkerscript.ld index 258c4dc9..7e15ea09 100644 --- a/targets/chip/mb9bf566k/linkerscript.ld +++ b/targets/chip/mb9bf566k/linkerscript.ld @@ -75,16 +75,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/rp2350/linkerscript.ld b/targets/chip/rp2350/linkerscript.ld index 09bda4d3..8ae7d167 100644 --- a/targets/chip/rp2350/linkerscript.ld +++ b/targets/chip/rp2350/linkerscript.ld @@ -78,16 +78,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/stm32f103/linkerscript.ld b/targets/chip/stm32f103/linkerscript.ld index 1ee4c30a..54da5aac 100644 --- a/targets/chip/stm32f103/linkerscript.ld +++ b/targets/chip/stm32f103/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/stm32f407/linkerscript.ld b/targets/chip/stm32f407/linkerscript.ld index b8a7c950..d0867a30 100644 --- a/targets/chip/stm32f407/linkerscript.ld +++ b/targets/chip/stm32f407/linkerscript.ld @@ -70,16 +70,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/stm32h723/linkerscript.ld b/targets/chip/stm32h723/linkerscript.ld index 02887c77..ed3972c3 100644 --- a/targets/chip/stm32h723/linkerscript.ld +++ b/targets/chip/stm32h723/linkerscript.ld @@ -71,16 +71,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : diff --git a/targets/chip/tmpm373/linkerscript.ld b/targets/chip/tmpm373/linkerscript.ld index 73deda58..c59f920a 100644 --- a/targets/chip/tmpm373/linkerscript.ld +++ b/targets/chip/tmpm373/linkerscript.ld @@ -69,16 +69,7 @@ SECTIONS CONSTRUCTOR_SECTION(fini_array) > rom /* Stack segment */ - .stack (NOLOAD) : - { - . = ALIGN(4); - PROVIDE(__stack_start = .); - - . = . + STACK_SIZE; - . = ALIGN(4); - - PROVIDE(__stack_end = .); - } > ram + STACK(STACK_SIZE) > ram /* Data that needs to be initialized to a value different than 0 */ .data : From c49d27e1a4e66ce76025b552faec5423d1125c6b Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Wed, 31 Dec 2025 03:53:46 +0100 Subject: [PATCH 5/6] changed to macros for lpc1788 extra memories --- klib/CMakeLists.txt | 1 + klib/entry/secondary.cpp | 80 +++++++++++++++++++ klib/entry/secondary.hpp | 16 ++++ targets/arm/linkerscript/linkerscript.ld | 66 ++++++++++++++++ targets/chip/lpc1788/linkerscript.ld | 97 ++++++++++-------------- 5 files changed, 205 insertions(+), 55 deletions(-) create mode 100644 klib/entry/secondary.cpp create mode 100644 klib/entry/secondary.hpp diff --git a/klib/CMakeLists.txt b/klib/CMakeLists.txt index ad41aaab..11f72230 100644 --- a/klib/CMakeLists.txt +++ b/klib/CMakeLists.txt @@ -1,6 +1,7 @@ # set the sources set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/entry/entry.c + ${CMAKE_CURRENT_SOURCE_DIR}/entry/secondary.cpp ) set(HEADERS_PRIVATE diff --git a/klib/entry/secondary.cpp b/klib/entry/secondary.cpp new file mode 100644 index 00000000..42d80f4e --- /dev/null +++ b/klib/entry/secondary.cpp @@ -0,0 +1,80 @@ +#include + +#pragma pack(push, 1) + +/** + * @brief Struct for memory segments that are loaded after the startup code is run + * + */ +struct data_memory_segment_t { + const uint32_t *rom_start; + uint32_t *start; + uint32_t *end; +}; + +/** + * @brief Struct for bss memory segments that are cleared after the startup code is run + * + */ +struct bss_memory_segment_t { + uint32_t *start; + uint32_t *end; +}; + +#pragma pack(pop) + +extern "C" { + // multisection data segment symbol + extern const data_memory_segment_t __multisection_data_start; + + // multisection bss segment symbol + extern const bss_memory_segment_t __multisection_bss_start; +} + +namespace klib::entry { + void secondary_memory_loader() { + // loop over all data segments + for (const data_memory_segment_t *segment = &__multisection_data_start; ; segment++) { + // check if we have reached the end of the segments + if (!segment->start && !segment->end && !segment->rom_start) { + // invalid segment + break; + } + + // get the length of the segment + const uint32_t length = ((segment->end - segment->start) + (sizeof(uint32_t) - 1)) / sizeof(uint32_t); + + // check if we have any length to copy + if (!length) { + continue; + } + + // copy rom to ram + for (uint32_t i = 0; i < length; i++) { + ((volatile uint32_t*)segment->start)[i] = segment->rom_start[i]; + } + } + + // loop over all bss segments + for (const bss_memory_segment_t *segment = &__multisection_bss_start; ; segment++) { + // check if we have reached the end of the segments + if (!segment->start && !segment->end) { + // invalid segment + break; + } + + // get the length of the segment + const uint32_t length = ((segment->end - segment->start) + (sizeof(uint32_t) - 1)) / sizeof(uint32_t); + + // check if we have any length to copy + if (!length) { + continue; + } + + // clear the bss segment + for (uint32_t i = 0; i < length; i++) { + ((volatile uint32_t*)segment->start)[i] = 0x00; + } + } + } +} \ No newline at end of file diff --git a/klib/entry/secondary.hpp b/klib/entry/secondary.hpp new file mode 100644 index 00000000..dd920785 --- /dev/null +++ b/klib/entry/secondary.hpp @@ -0,0 +1,16 @@ +#ifndef KLIB_SECONDARY_HPP +#define KLIB_SECONDARY_HPP + +#include + +namespace klib::entry { + /** + * @brief A secondary memory loader. This loader should be + * called afer the memories are initialized by the user + * code. Constructor(102) is reserved for this function. + * + */ + void secondary_memory_loader(); +} + +#endif \ No newline at end of file diff --git a/targets/arm/linkerscript/linkerscript.ld b/targets/arm/linkerscript/linkerscript.ld index ebfecdc0..e9aeaa54 100644 --- a/targets/arm/linkerscript/linkerscript.ld +++ b/targets/arm/linkerscript/linkerscript.ld @@ -73,3 +73,69 @@ KEEP(*(SORT(.name))) \ PROVIDE(COMBINE_STR3(__,name,_end) = .); \ } + +/* macro to define a data section. Note: this section is not automaticly loaded. + The secondary loaded needs to be enabled to load this at startup after the + startup code */ +#define DATA_SECTION(name, region, storage) \ + COMBINE_STR2(.name,_data) : \ + { \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_data_rom_start) = LOADADDR(COMBINE_STR2(.name,_data))); \ + PROVIDE(COMBINE_STR3(__,name,_data_start) = .); \ + *(SORT_BY_ALIGNMENT(COMBINE_STR2(.name,_data))); \ + *(SORT_BY_ALIGNMENT(COMBINE_STR2(.name,_data.*))); \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_data_end) = .); \ + } > region AT > storage + +/* data section entry for the multi section table */ +#define DATA_SECTION_ENTRY(name) \ + LONG(COMBINE_STR3(__,name,_data_rom_start)); \ + LONG(COMBINE_STR3(__,name,_data_start)); \ + LONG(COMBINE_STR3(__,name,_data_end)); + +/* end marker for the multi section table */ +#define DATA_SECTION_ENTRY_END() \ + LONG(0); \ + LONG(0); \ + LONG(0); + +/* multisection table to automaticly load the data into the section location */ +#define DATA_MULTISECTION_TABLE(entries) \ + ALLIGNED_READONLY_SECTION( \ + multisection_data, 4, \ + PROVIDE(__multisection_data_start = .); \ + entries \ + PROVIDE(__multisection_data_end = .); \ + ) + +#define BSS_SECTION(name, region) \ + COMBINE_STR2(.name,_bss) (NOLOAD) : \ + { \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_bss_start) = .); \ + *(SORT_BY_ALIGNMENT(COMBINE_STR2(.name,_bss))); \ + *(SORT_BY_ALIGNMENT(COMBINE_STR2(.name,_bss.*))); \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_bss_end) = .); \ + } > region + +/* bss section entry for the multi section table */ +#define BSS_SECTION_ENTRY(name) \ + LONG(COMBINE_STR3(__,name,_bss_start)); \ + LONG(COMBINE_STR3(__,name,_bss_end)); + +/* end marker for the multi section table */ +#define BSS_SECTION_ENTRY_END() \ + LONG(0); \ + LONG(0); + +/* multisection table to automaticly load all the bss sections to zero */ +#define BSS_MULTISECTION_TABLE(entries) \ + ALLIGNED_READONLY_SECTION( \ + multisection_bss, 4, \ + PROVIDE(__multisection_bss_start = .); \ + entries \ + PROVIDE(__multisection_bss_end = .); \ + ) diff --git a/targets/chip/lpc1788/linkerscript.ld b/targets/chip/lpc1788/linkerscript.ld index 0e9ae268..a4570f93 100644 --- a/targets/chip/lpc1788/linkerscript.ld +++ b/targets/chip/lpc1788/linkerscript.ld @@ -132,61 +132,48 @@ SECTIONS } > ram /* additional ram segment of the lpc1788 */ - .ram1 : - { - *(SORT_BY_ALIGNMENT(.ram1)) - *(SORT_BY_ALIGNMENT(.ram1.*)) - } > ram1 - - /* static memory, note: not loaded by default. No startup code loads the segments */ - .static0 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.static0)); - *(SORT_BY_ALIGNMENT(.static0.*)); - } > static0 - - .static1 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.static1)); - *(SORT_BY_ALIGNMENT(.static1.*)); - } > static1 - - .static2 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.static2)); - *(SORT_BY_ALIGNMENT(.static2.*)); - } > static2 - - .static3 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.static3)); - *(SORT_BY_ALIGNMENT(.static3.*)); - } > static3 - - /* dynamic memory, note: not loaded by default. No startup code loads the segments */ - .dynamic0 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.dynamic0)); - *(SORT_BY_ALIGNMENT(.dynamic0.*)); - } > dynamic0 - - .dynamic1 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.dynamic1)); - *(SORT_BY_ALIGNMENT(.dynamic1.*)); - } > dynamic1 - - .dynamic2 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.dynamic2)); - *(SORT_BY_ALIGNMENT(.dynamic2.*)); - } > dynamic2 - - .dynamic3 (NOLOAD) : - { - *(SORT_BY_ALIGNMENT(.dynamic3)); - *(SORT_BY_ALIGNMENT(.dynamic3.*)); - } > dynamic3 + DATA_SECTION(ram1, ram1, rom) + BSS_SECTION(ram1, ram1) + + /* static memory */ + DATA_SECTION(static0, static0, rom) + DATA_SECTION(static1, static1, rom) + DATA_SECTION(static2, static2, rom) + DATA_SECTION(static3, static3, rom) + BSS_SECTION(static0, static0) + BSS_SECTION(static1, static1) + BSS_SECTION(static2, static2) + BSS_SECTION(static3, static3) + + /* dynamic memory */ + DATA_SECTION(dynamic0, dynamic0, rom) + DATA_SECTION(dynamic1, dynamic1, rom) + DATA_SECTION(dynamic2, dynamic2, rom) + DATA_SECTION(dynamic3, dynamic3, rom) + BSS_SECTION(dynamic0, dynamic0) + BSS_SECTION(dynamic1, dynamic1) + BSS_SECTION(dynamic2, dynamic2) + BSS_SECTION(dynamic3, dynamic3) + + /* create a table to initialize the data sections on a secondary memory */ + DATA_MULTISECTION_TABLE( + DATA_SECTION_ENTRY(ram1) + DATA_SECTION_ENTRY(dynamic0) + DATA_SECTION_ENTRY(dynamic1) + DATA_SECTION_ENTRY(dynamic2) + DATA_SECTION_ENTRY(dynamic3) + DATA_SECTION_ENTRY_END() + ) > rom + + /* create a table to initialize the bss sections on a secondary memory */ + BSS_MULTISECTION_TABLE( + BSS_SECTION_ENTRY(ram1) + BSS_SECTION_ENTRY(dynamic0) + BSS_SECTION_ENTRY(dynamic1) + BSS_SECTION_ENTRY(dynamic2) + BSS_SECTION_ENTRY(dynamic3) + BSS_SECTION_ENTRY_END() + ) > rom /* Heap segment */ .heap (NOLOAD) : From 306ae582fa603a2327eb3c17a4e780026f4e54fe Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Wed, 31 Dec 2025 03:54:45 +0100 Subject: [PATCH 6/6] added readonly attribute to all .text linkerscripts --- targets/chip/atsam3x8e/linkerscript.ld | 2 +- targets/chip/atsam4s2b/linkerscript.ld | 2 +- targets/chip/lpc1752/linkerscript.ld | 2 +- targets/chip/lpc1754/linkerscript.ld | 2 +- targets/chip/lpc1756/linkerscript.ld | 2 +- targets/chip/lpc1759/linkerscript.ld | 2 +- targets/chip/lpc55s66/linkerscript.ld | 2 +- targets/chip/lpc802/linkerscript.ld | 2 +- targets/chip/max32625/linkerscript.ld | 2 +- targets/chip/max32660/linkerscript.ld | 2 +- targets/chip/mb9bf566k/linkerscript.ld | 2 +- targets/chip/rp2350/linkerscript.ld | 2 +- targets/chip/stm32f103/linkerscript.ld | 2 +- targets/chip/stm32f407/linkerscript.ld | 2 +- targets/chip/stm32h723/linkerscript.ld | 2 +- targets/chip/tmpm373/linkerscript.ld | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/targets/chip/atsam3x8e/linkerscript.ld b/targets/chip/atsam3x8e/linkerscript.ld index 8ae24caf..9e895a90 100644 --- a/targets/chip/atsam3x8e/linkerscript.ld +++ b/targets/chip/atsam3x8e/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/atsam4s2b/linkerscript.ld b/targets/chip/atsam4s2b/linkerscript.ld index 8b84bb45..1c64d9ad 100644 --- a/targets/chip/atsam4s2b/linkerscript.ld +++ b/targets/chip/atsam4s2b/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc1752/linkerscript.ld b/targets/chip/lpc1752/linkerscript.ld index d7f2440b..9e1738c0 100644 --- a/targets/chip/lpc1752/linkerscript.ld +++ b/targets/chip/lpc1752/linkerscript.ld @@ -51,7 +51,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc1754/linkerscript.ld b/targets/chip/lpc1754/linkerscript.ld index 9aa5d3fd..fde7af0f 100644 --- a/targets/chip/lpc1754/linkerscript.ld +++ b/targets/chip/lpc1754/linkerscript.ld @@ -52,7 +52,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc1756/linkerscript.ld b/targets/chip/lpc1756/linkerscript.ld index 004129cb..d83828c9 100644 --- a/targets/chip/lpc1756/linkerscript.ld +++ b/targets/chip/lpc1756/linkerscript.ld @@ -52,7 +52,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc1759/linkerscript.ld b/targets/chip/lpc1759/linkerscript.ld index 7baaf1bd..2a71468a 100644 --- a/targets/chip/lpc1759/linkerscript.ld +++ b/targets/chip/lpc1759/linkerscript.ld @@ -55,7 +55,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc55s66/linkerscript.ld b/targets/chip/lpc55s66/linkerscript.ld index ab90e859..1797c12a 100644 --- a/targets/chip/lpc55s66/linkerscript.ld +++ b/targets/chip/lpc55s66/linkerscript.ld @@ -45,7 +45,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/lpc802/linkerscript.ld b/targets/chip/lpc802/linkerscript.ld index cd6e96ca..98fd92e0 100644 --- a/targets/chip/lpc802/linkerscript.ld +++ b/targets/chip/lpc802/linkerscript.ld @@ -41,7 +41,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/max32625/linkerscript.ld b/targets/chip/max32625/linkerscript.ld index 6fbe1752..3650d59c 100644 --- a/targets/chip/max32625/linkerscript.ld +++ b/targets/chip/max32625/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/max32660/linkerscript.ld b/targets/chip/max32660/linkerscript.ld index 18168efd..627ec98c 100644 --- a/targets/chip/max32660/linkerscript.ld +++ b/targets/chip/max32660/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/mb9bf566k/linkerscript.ld b/targets/chip/mb9bf566k/linkerscript.ld index 7e15ea09..08a0c4f9 100644 --- a/targets/chip/mb9bf566k/linkerscript.ld +++ b/targets/chip/mb9bf566k/linkerscript.ld @@ -42,7 +42,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/rp2350/linkerscript.ld b/targets/chip/rp2350/linkerscript.ld index 8ae7d167..6941f7d4 100644 --- a/targets/chip/rp2350/linkerscript.ld +++ b/targets/chip/rp2350/linkerscript.ld @@ -45,7 +45,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/stm32f103/linkerscript.ld b/targets/chip/stm32f103/linkerscript.ld index 54da5aac..7e4c6e29 100644 --- a/targets/chip/stm32f103/linkerscript.ld +++ b/targets/chip/stm32f103/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/stm32f407/linkerscript.ld b/targets/chip/stm32f407/linkerscript.ld index d0867a30..bf058945 100644 --- a/targets/chip/stm32f407/linkerscript.ld +++ b/targets/chip/stm32f407/linkerscript.ld @@ -37,7 +37,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/stm32h723/linkerscript.ld b/targets/chip/stm32h723/linkerscript.ld index ed3972c3..49448a9e 100644 --- a/targets/chip/stm32h723/linkerscript.ld +++ b/targets/chip/stm32h723/linkerscript.ld @@ -40,7 +40,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ diff --git a/targets/chip/tmpm373/linkerscript.ld b/targets/chip/tmpm373/linkerscript.ld index c59f920a..187b5c31 100644 --- a/targets/chip/tmpm373/linkerscript.ld +++ b/targets/chip/tmpm373/linkerscript.ld @@ -36,7 +36,7 @@ SECTIONS VECTORS() > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */