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/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..e9aeaa54 --- /dev/null +++ b/targets/arm/linkerscript/linkerscript.ld @@ -0,0 +1,141 @@ +/* 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) + +/* 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() \ + ALLIGNED_READONLY_SECTION( \ + vectors, 4, \ + KEEP(*(.vectors .vectors.*)); \ + ) + +/* macro to define the rodata section */ +#define RODATA() \ + 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); \ + /* 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 */ +#define CONSTRUCTOR_SECTION(name) \ + .name : \ + { \ + . = ALIGN(4); \ + PROVIDE(COMBINE_STR3(__,name,_start) = .); \ + KEEP(*(SORT(.name.*))) \ + 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/atsam3x8e/linkerscript.ld b/targets/chip/atsam3x8e/linkerscript.ld index d3f7311e..9e895a90 100644 --- a/targets/chip/atsam3x8e/linkerscript.ld +++ b/targets/chip/atsam3x8e/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,62 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 a008820e..1c64d9ad 100644 --- a/targets/chip/atsam4s2b/linkerscript.ld +++ b/targets/chip/atsam4s2b/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,62 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 9d8f2c27..9e1738c0 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 : { @@ -57,7 +51,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -81,62 +75,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 81c08a42..fde7af0f 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 : { @@ -58,7 +52,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -82,62 +76,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 17797a57..d83828c9 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 : { @@ -58,7 +52,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -82,62 +76,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 0df1704e..2a71468a 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 : { @@ -61,7 +55,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -85,62 +79,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 fa733c45..a4570f93 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,62 +88,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 : @@ -184,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) : diff --git a/targets/chip/lpc55s66/linkerscript.ld b/targets/chip/lpc55s66/linkerscript.ld index 87481bd2..1797c12a 100644 --- a/targets/chip/lpc55s66/linkerscript.ld +++ b/targets/chip/lpc55s66/linkerscript.ld @@ -42,16 +42,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -75,62 +69,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 038cb825..98fd92e0 100644 --- a/targets/chip/lpc802/linkerscript.ld +++ b/targets/chip/lpc802/linkerscript.ld @@ -38,16 +38,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -71,62 +65,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 3fa0e88f..3650d59c 100644 --- a/targets/chip/max32625/linkerscript.ld +++ b/targets/chip/max32625/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,62 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 59b1bacb..627ec98c 100644 --- a/targets/chip/max32660/linkerscript.ld +++ b/targets/chip/max32660/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,62 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 435a812a..08a0c4f9 100644 --- a/targets/chip/mb9bf566k/linkerscript.ld +++ b/targets/chip/mb9bf566k/linkerscript.ld @@ -39,16 +39,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -72,62 +66,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 fec16011..6941f7d4 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 */ @@ -51,7 +45,7 @@ SECTIONS } > rom /* Text segment, stores all user code */ - .text : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -75,62 +69,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 531f5b0e..7e4c6e29 100644 --- a/targets/chip/stm32f103/linkerscript.ld +++ b/targets/chip/stm32f103/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,61 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 897e20ca..bf058945 100644 --- a/targets/chip/stm32f407/linkerscript.ld +++ b/targets/chip/stm32f407/linkerscript.ld @@ -34,16 +34,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -67,61 +61,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 d732743f..49448a9e 100644 --- a/targets/chip/stm32h723/linkerscript.ld +++ b/targets/chip/stm32h723/linkerscript.ld @@ -37,16 +37,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -68,61 +62,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 23d1f3ea..187b5c31 100644 --- a/targets/chip/tmpm373/linkerscript.ld +++ b/targets/chip/tmpm373/linkerscript.ld @@ -33,16 +33,10 @@ 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 : + .text (READONLY) : { . = ALIGN(4); /* text segment */ @@ -66,62 +60,16 @@ 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 + CONSTRUCTOR_SECTION(preinit_array) > rom + CONSTRUCTOR_SECTION(init_array) > rom + 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 :