OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

MEMORY {
	ewram : ORIGIN = 0x02000000, LENGTH = 0x0100K
	iwram : ORIGIN = 0x03000000, LENGTH = 0x7E00
	rom   : ORIGIN = 0x08000000, LENGTH = 0x0020M
}

SECTIONS {
	. = ORIGIN(rom);
	
	.init : {
		*(.init*)
		. = ALIGN(4);
	} >rom = 0
	
	.text : {
		*(EXCLUDE_FILE (*.iwram*) .text)
		*(.text*)
		*(.stub*)
		*(.text.*)
		*(.stub.*)
		*(.gnu.warning)
		*(.gnu.linkonce.t*)
		*(.glue_7 .glue_7)
		. = ALIGN(4);
	} >rom = 0
	
	.rodata : {
		*(.rodata)
		*(.rodata.*)
		*(.gnu.linkonce.r*)
		. = ALIGN(4);
	} >rom = 0
	
	.ctors : {
		KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
		KEEP (*crtbegin.o(.ctors))
		KEEP (*(SORT(.ctors.*)))
		KEEP (*(.ctors))
		. = ALIGN(4);
	} >rom = 0
	
	.dtors : {
		KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
		KEEP (*crtbegin.o(.dtors))
		KEEP (*(SORT(.dtors.*)))
		KEEP (*(.dtors))
		. = ALIGN(4);
	} >rom = 0
	
    .eh_frame : {
		KEEP (*(.eh_frame))
		. = ALIGN(4);
	} >rom = 0
    
	__lmaIWRAMPos = .;
	
	.iwram ORIGIN(iwram) : AT (__lmaIWRAMPos) {
		*(.iwram)
		*iwram.*(.text)
		. = ALIGN(4);
	} >iwram = 0
	
	__lmaIWRAMLen = ((SIZEOF(.iwram) + 3) / 4) + 0x84000000;
	__lmaEWRAMPos =   SIZEOF(.iwram) + __lmaIWRAMPos;
	
	.ewram ORIGIN(ewram) : AT (__lmaEWRAMPos) {
		*(.data*)
		*(.data.*)
		*(.gnu.linkonce.d*)
		SORT(CONSTRUCTORS)
		
		*(.ewram)
		*ewram.*(.text)
		. = ALIGN(4);
	} >ewram = 0
	
	__lmaEWRAMLen = ((SIZEOF(.ewram) + 3) / 4) + 0x84000000;
	
	.bss (NOLOAD) : {
		*(.dynbss)
		*(.gnu.linkonce.b*)
		*(.bss*)
		*(COMMON)
		. = ALIGN(4);
	} AT>iwram
	
	.sbss (NOLOAD) : {
		*(.sbss)
		. = ALIGN(4);
		
		__end__ = ABSOLUTE(.);
	} AT>ewram
}
