/* Copyright (c) 2021-2024, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Override macros defined in address_map_new.h to avoid syntax error for
 * NV_ADDRESS_MAP_AON_BTCM_* defines
 */
#define MK_U32_CONST(_constant_) (_constant_)
#define MK_ADDR_CONST(_constant_) (_constant_)
#include "address_map_new.h"
#include <spe-map.h>

MEMORY
{
  btcm : ORIGIN = RUN_ADDR, LENGTH = NV_ADDRESS_MAP_AON_BTCM_SIZE
}

FIQ_SIZE = 0x300;
IRQ_SIZE = 0x300;
ABT_SIZE = 0x100;
UND_SIZE = 0x100;
SVC_SIZE = 0x300;

_estack = RUN_ADDR + NV_ADDRESS_MAP_AON_BTCM_SIZE;
_fiqstack = _estack;
_irqstack = _fiqstack - FIQ_SIZE;
_abtstack = _irqstack - IRQ_SIZE;
_undstack = _abtstack - ABT_SIZE;
_svcstack = _undstack - UND_SIZE;
_sstack =  _svcstack - SVC_SIZE;

_heap_end = _sstack;

PHDRS
{
  /* FLAGS(5) = rx, FLAGS(6) = rw */
  text PT_LOAD FLAGS(5);
  data PT_LOAD FLAGS(6);
  bss PT_LOAD FLAGS(6);
}

SECTIONS
{
    .text :
    {
        . = ALIGN(4);
	_stext = .;
	KEEP(*(.vectors .vectors.*))
        . = ALIGN(4);
        *(.text .text.*)
        *(.rodata .rodata*)
        . = ALIGN(4);
        _etext = .;
    } > btcm :text

    .data :
    {
        _sdata = .;
        *(.data .data.*);
        . = ALIGN(4);
        _edata = .;
    } > btcm :data

    .bss :
    {
        _sbss = . ;
        *(.bss .bss.*)
        *(COMMON)
        . = ALIGN(4);
        _ebss = . ;
    } > btcm :bss
    _end = . ;

    . = ALIGN(4);
    _heap_start = .;
}
