/* Section Definitions */
SECTIONS
{
	/*
	 * Vectors, code and constant data.
	 */
    .text :
    {
        PROVIDE (pios_isr_vector_table_base = .);
        KEEP(*(.cpu_vectors))	/* CPU exception vectors */
        KEEP(*(.io_vectors))	/* I/O interrupt vectors */
        *(.text .text.* .gnu.linkonce.t.*)
        *(.glue_7t) *(.glue_7)
        *(.rodata .rodata* .gnu.linkonce.r.*)
    } > FLASH

    /* 
     * Init section for UAVObjects. 
     */
    .initcalluavobj.init :
    {
        . = ALIGN(4);
		__uavobj_initcall_start = .;
        KEEP(*(.initcalluavobj.init))
		. = ALIGN(4);
		__uavobj_initcall_end   = .;
    } >FLASH

    /* 
     * Module init section section
     */
    .initcallmodule.init :
    {
        . = ALIGN(4);
		__module_initcall_start = .;
        KEEP(*(.initcallmodule.init))
		. = ALIGN(4);
		__module_initcall_end   = .;
    } >FLASH

    /* settings init sections */
    .initcallsettings.init :
    {
        . = ALIGN(4);
	__settings_initcall_start = .;
        KEEP(*(.initcallsettings.init))
	. = ALIGN(4);
	__settings_initcall_end   = .;
    } >FLASH
    
	/*
	 * C++ exception handling.
	 */
    .ARM.extab :
    {
        *(.ARM.extab* .gnu.linkonce.armextab.*)
    } > FLASH
    .ARM.exidx :
    {
        __exidx_start = .;
        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
        __exidx_end = .;
    } > FLASH

	/*
	 * Markers for the end of the 'text' section and the in-flash start of 
	 * non-constant data 
	 */
    . = ALIGN(4);
    _etext = .;
    _sidata = .;

	/*
	 * Board info structure, normally only generated by the bootloader but can
	 * be read by the application.
	 */
	PROVIDE(pios_board_info_blob = ORIGIN(BD_INFO));
    .boardinfo :
    {
		. = ALIGN(4);
		KEEP(*(.boardinfo))
		. = ALIGN(ORIGIN(BD_INFO)+LENGTH(BD_INFO));
	} > BD_INFO

    /*
   	 * Place the IRQ/bootstrap stack at the bottom of SRAM so that an overflow
   	 * results in a hard fault.
   	 */
   	.istack (NOLOAD) :
   	{
   		. = ALIGN(4);
    	_irq_stack_end = . ;
    	*(.irqstack)
    	_irq_stack_top = . ;
	} > CCSRAM
	

	/*
	 * Non-const initialised data.
	 */
    .data : AT (_sidata)
    {
        . = ALIGN(4);
        _sdata = .;
        *(.data .data.*)
        . = ALIGN(4);
        _edata = . ;
    } > SRAM

    /*
     * Uninitialised data (BSS + commons).
     */
    .bss (NOLOAD) :
    {
        _sbss = . ;
        *(.bss .bss.*)
        *(COMMON)
        _ebss = . ;
	    PROVIDE ( _end = _ebss ) ;    
    } > SRAM

	/*
	 * The heap consumes the remainder of the SRAM.
	 */
    .heap (NOLOAD) :
    {
        . = ALIGN(4);
        _sheap = . ;
        
        /*
         * This allows us to declare an object or objects up to the minimum acceptable
         * heap size and receive a linker error if the space available for the heap is
         * not sufficient.
         */
        *(.heap)
        
        /* extend the heap up to the top of SRAM */
        . = ORIGIN(SRAM) + LENGTH(SRAM) - ABSOLUTE(_sheap);
        _eheap = .;
    } > SRAM

	/*
	 * 'Fast' memory goes in the CCM SRAM
	 */
	.fast (NOLOAD) :
	{
		_sfast = . ;
		*(.fast)
		_efast = . ;
	} > CCSRAM
	
	.fastheap (NOLOAD) :
    {
        . = ALIGN(4);
        _sfastheap = . ;
        
        /*
         * This allows us to declare an object or objects up to the minimum acceptable
         * heap size and receive a linker error if the space available for the heap is
         * not sufficient.
         */
        *(.fastheap)
        
        /* extend the fastheap up to the top of CCSRAM */
        . = ORIGIN(CCSRAM) + LENGTH(CCSRAM) - ABSOLUTE(_sfastheap);
        _efastheap = .;
    } > CCSRAM
    
    /* Stabs debugging sections.  */
    .stab          0 : { *(.stab) }
    .stabstr       0 : { *(.stabstr) }
    .stab.excl     0 : { *(.stab.excl) }
    .stab.exclstr  0 : { *(.stab.exclstr) }
    .stab.index    0 : { *(.stab.index) }
    .stab.indexstr 0 : { *(.stab.indexstr) }
    .comment       0 : { *(.comment) }
    /* DWARF debug sections.
       Symbols in the DWARF debugging sections are relative to the beginning
       of the section so we begin them at 0.  */
    /* DWARF 1 */
    .debug          0 : { *(.debug) }
    .line           0 : { *(.line) }
    /* GNU DWARF 1 extensions */
    .debug_srcinfo  0 : { *(.debug_srcinfo) }
    .debug_sfnames  0 : { *(.debug_sfnames) }
    /* DWARF 1.1 and DWARF 2 */
    .debug_aranges  0 : { *(.debug_aranges) }
    .debug_pubnames 0 : { *(.debug_pubnames) }
    /* DWARF 2 */
    .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
    .debug_abbrev   0 : { *(.debug_abbrev) }
    .debug_line     0 : { *(.debug_line) }
    .debug_frame    0 : { *(.debug_frame) }
    .debug_str      0 : { *(.debug_str) }
    .debug_loc      0 : { *(.debug_loc) }
    .debug_macinfo  0 : { *(.debug_macinfo) }
    /* SGI/MIPS DWARF 2 extensions */
    .debug_weaknames 0 : { *(.debug_weaknames) }
    .debug_funcnames 0 : { *(.debug_funcnames) }
    .debug_typenames 0 : { *(.debug_typenames) }
    .debug_varnames  0 : { *(.debug_varnames) }
}