/* Linker script for a system with 128KB RAM starting at 0x10000 */ MEMORY { RAM (wx) : ORIGIN = 0x0000, LENGTH = 128K } SECTIONS { /* Place code and readonly data at the beginning of RAM */ .text : { *(.text*) *(.rodata*) } > RAM /* Place initialized data right after the .text section */ .data : { . = ALIGN(4); *(.data*) } > RAM /* Uninitialized data (BSS) follows initialized data */ .bss : { . = ALIGN(4); __bss_start = .; *(.bss*) *(COMMON) . = ALIGN(4); __bss_end = .; } > RAM /* Define heap start right after bss */ . = ALIGN(4); __heap_start = .; PROVIDE(heap_start = __heap_start); /* Leave space for the heap by not explicitly defining its end */ /* The heap grows towards the stack */ /* Reserve space for the stack at the end of RAM */ /* Let's say we want a 16KB stack */ . = ALIGN(4); __stack_size = 16K; /* Size of the stack */ __stack_top = ORIGIN(RAM) + LENGTH(RAM); /* Top of the stack */ __stack_start = __stack_top - __stack_size; /* Start of the stack */ .stack (NOLOAD) : { . = __stack_start; . += __stack_size; /* Allocate space for the stack */ . = ALIGN(4); } > RAM PROVIDE(__stack = __stack_top); PROVIDE(stack_top = __stack_top); PROVIDE(stack_start = __stack_start); /* Heap end is dynamically located at the start of the stack */ __heap_end = __stack_start; PROVIDE(heap_end = __heap_end); /* End of RAM usage */ . = ALIGN(4); _end = .; PROVIDE(end = _end); }