Tuesday, September 28, 2010

Bare Metal: PuppyBeagle linker script [PB.ld]

Its important to take a look at the linker script developed to build the PuppyBeagle code base, that describes the memory allocations for different areas of the image that is eventually built.


/*******************************************************************************
*        Linker Script for mapping PuppyBeagle code to SRAM and DDRAM
*
*      Copyright (c) 2010 Amarnath B Revanna, amarnath.revanna@gmail.com
*
 ******************************************************************************/

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

MEMORY {

SRAM (rwx) : ORIGIN = 0X40200000, LENGTH = 64K
}

SVC_STACK_SIZE = 536;
IRQ_STACK_SIZE = 536;
FIQ_STACK_SIZE = 536;
ABT_STACK_SIZE = 536;
UND_STACK_SIZE = 536;
SYS_STACK_SIZE = 536;

SECTIONS {

.stack : {
__stack_start__ = . + 0xF000;
__stack_end__ = __stack_start__ + 0xCB0;

__svc_stack__start = __stack_end__;
__svc_stack__end = __svc_stack__start - SVC_STACK_SIZE;

__irq_stack__start = __svc_stack__end - 4;
__irq_stack__end = __irq_stack__start - IRQ_STACK_SIZE;

__fiq_stack__start = __irq_stack__end - 4;
__fiq_stack__end = __fiq_stack__start - FIQ_STACK_SIZE;

__abt_stack__start = __fiq_stack__end - 4;
__abt_stack__end = __abt_stack__start - ABT_STACK_SIZE;

__und_stack__start = __abt_stack__end - 4;
__und_stack__end = __und_stack__start - UND_STACK_SIZE;

__sys_stack__start = __und_stack__end - 4;
__sys_stack__end = __sys_stack__start - SYS_STACK_SIZE;


} > SRAM

.reset : {
*startup.o (.text)
/*
* Startup code containing IVT should be
* placed as the first section of image
*/
*low_init.o (.text)
  . = ALIGN (0x4);
} > SRAM

.text : {
CREATE_OBJECT_SYMBOLS
* (.text .text.* .gnu.linkonce.t.*)
* (.plt)
* (.gnu.warning)
* (.glue_7t) * (.glue_7)
. = ALIGN (0x4);

KEEP ( *crtbegin.o (.ctors))
KEEP ( * (EXCLUDE_FILE (*crtend.o) .ctors))
KEEP ( * (SORT (.ctors)))
KEEP ( *crtend.o (.ctors))
KEEP ( *crtbegin.o (.dtors))
KEEP ( * (EXCLUDE_FILE(*crtend.o) .dtors))
KEEP ( *(SORT (.dtors.*)))
KEEP ( *crtend.o (.dtors))

*(.init)
*(.fini)
*(.rodata .rodata.* .gnu.linkonce.r.*)
} > SRAM

.data : {
__data_start = .;
KEEP (* (.jcr))
* (.got.plt) * (.got)
* (.shdata)
*. (.data .data.* .gnu.linkonce.d.*)
. = ALIGN (0x4);
_edata = .;
} > SRAM

.bss : {
__bss_start = .;
* (.shbss)
* (.bss .bss.* .gnu.linkonce.b.*)
* (COMMON)
. = ALIGN (0x4);
__bss_end = .;
} > SRAM
/*Used by linker for internal purposes only*/
.stab 0 (NOLOAD) : {
*.(.stab)
}

.stabstr 0 (NOLOAD) : {
*.(.stabstr)
}

/*
* DWARF Debug Sections.
* Symbols in 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) }

}

Each of the section will be explained in detail soon, for now, just take it as it is with a grain of salt ;)

No comments:

Post a Comment