OUTPUT_ARCH(riscv)
/* link with the standard c library */
INPUT(-lc)
/* link with the standard GCC library */
INPUT(-lgcc)

/* Provide default definitions of various SIZE symbols if needed.
   These should normally be defined on the link command line with
        --defsym _STACK_SIZE=xx
   or linked in as part of the program (see memory.c example). */
/* This stack is only used from start until RTOS is started */
_STACK_SIZE          = DEFINED(_STACK_SIZE)          ? _STACK_SIZE          : 432;

MEMORY
{
    cpu_memory (rx)     : org = 0x00000000, len = 512K
    shared_memory (!rx) : org = 0x60000000, len = 384K
    lamac_memory (!rx)  : org = 0x61100000, len = 1024K
    machw_mib_memory (!rx) : org = 0x68300800, len = 4K
}

SECTIONS
{
    /* shared RAM */
    SHARED (NOLOAD):
    {
        _sshram = . ;
        *(SHAREDRAMIPC)
        *(SHAREDRAM)
        _eshram = . ;
        _trace_start = .;
        _trace_end = ORIGIN(shared_memory) + LENGTH(shared_memory);
    } > shared_memory

    /* MAC logic analyzer RAM */
    LA (NOLOAD):
    {
        _slarammac = . ;
        *(LARAM)
        _elarammac = . ;
    } > lamac_memory

    /* MAC HW MIBs */
    HW_MIB (NOLOAD):
    {
        _smachw_mib = . ;
        *(MACHWMIB)
        _emachw_mib = . ;
    } > machw_mib_memory

    .text :
    {
       _svect = .;
       KEEP (*(.vectors));
       _evect = .;
    } > cpu_memory

    CODE :
    {
        *crt0.o(.text .text.*)
        *(.text .text.* .libgcc);
        . = ALIGN(0x8);
        _etext = .;
    } > cpu_memory

    /*--------------------------------------------------------------------*/
    /* Global constructor/destructor segment                             */
    /*--------------------------------------------------------------------*/

    .data :
    {
       _sdata = .;
       *(.sdata*);
       *(.srodata*);
       . = ALIGN(4);
       *(.rodata*);
       . = ALIGN(4);
       *(.data*);
       _edata = .;
       . = ALIGN(0x4);
    } > cpu_memory

    .bss :
    {
       PROVIDE(_ssbss = .);
       . = ALIGN(0x4);
       *(.sbss*)
       *(.scommon*)
       . = ALIGN(0x4);
       PROVIDE(_esbss = .);
       PROVIDE(_sbss = .);
       *(.bss*)
       *(COMMON)
       . = ALIGN(0x4);
       PROVIDE(_ebss = .);
    } > cpu_memory

    /*********************************************************************************
     * Stack
     *********************************************************************************/
    .stack :
    {
       . = ALIGN(0x4);
       __stack_bottom = . ;
       . += _STACK_SIZE ;
       __stack_top = .;
       . = ALIGN(0x4);
       _edata = .;
    } > cpu_memory

    /*********************************************************************************
     * Heap
     *********************************************************************************/
    .heap :
    {
       . = ALIGN(4);
       __heap_bottom = . ;
       __heap_top = ORIGIN(cpu_memory) + LENGTH(cpu_memory);
    } > cpu_memory
}
