cortex.lds (Source)

/* Copyright (C) 2018 Oliver Kleinke
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(main)

MEMORY {
    flash (RX) : ORIGIN = 0x00000000, LENGTH = 256K
    sram  (WX) : ORIGIN = 0x20000000, LENGTH = 64K
}

REGION_ALIAS("REGION_TEXT", flash);
REGION_ALIAS("REGION_ARM_EXIDX", flash);
REGION_ALIAS("REGION_ARM_EXTAB", flash);
REGION_ALIAS("REGION_STACK", sram);
REGION_ALIAS("REGION_DATA", sram);
REGION_ALIAS("REGION_BSS", sram);
REGION_ALIAS("REGION_HEAP", sram);


SECTIONS {
    .text : {
        __text_begin__ = .;
        . = ALIGN(0x4);

        KEEP(*(.vectors))

        KEEP(*(.text))
        *(.text.*)

    } > REGION_TEXT
    __text_size__ = SIZEOF(.text);

    .rodata : {
        __rodata_begin__ = .;

        KEEP(*(.rodata))
        *(.rodata.*)

    } > REGION_TEXT
    __rodata_size__ = SIZEOF(.rodata);

    # ARM-specific regions
    .ARM.exidx : {
        __exidx_begin__ = .;

        *(.ARM.exidx* .gnu.linkonce.armexidx.*)

    } > REGION_ARM_EXIDX
    __exidx_size__ = SIZEOF(.ARM.exidx);

    .ARM.extab : {
        __extab_begin__ = .;

        *(.ARM.extab* .gnu.linkonce.armextab.*)

    } > REGION_ARM_EXTAB
    __extab_size__ = SIZEOF(.ARM.extab);

    .stack (NOLOAD) : ALIGN(0x10) {
        __stack_begin__ = .;

        /* Reserve 32K sram for .stack */
        . += 32K;
        . = ALIGN(0x10);

        __stack_init__ = .;

        . = ALIGN(0x20);

    } > REGION_STACK
    __stack_size__ = SIZEOF(.stack);
    
    .data : {
        __data_lma__ = LOADADDR(.data);
        __data_begin__ = .;
        
        . = ALIGN(0x10);

        KEEP(*(.data))
        *(.data.*)

        . = ALIGN(0x20);

    } > REGION_DATA AT> REGION_TEXT
    __data_size__ = SIZEOF(.data);

    .bss (NOLOAD) : {
        __bss_begin__ = .;

        . = ALIGN(0x10);

        KEEP(*(.bss))
        KEEP(*(COMMON))
        *(.bss.*)

        . = ALIGN(0x20);

    } > REGION_BSS
    __bss_size__ = SIZEOF(.bss);

    .heap (NOLOAD) : {
        __heap_begin__ = .;

        /* Remaining sram memory is assigned to .heap */
        . = ORIGIN(REGION_HEAP) + LENGTH(REGION_HEAP);
        
    } > REGION_HEAP
    __heap_size__ = SIZEOF(.heap);
}