From 00e029209de921177db74f7c210a2f4f99fa6fba Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Sat, 4 Aug 2012 14:08:02 +0200 Subject: [PATCH 1/2] Reorganization of memory layout --- .../arduino_due_x/linker_scripts/gcc/flash.ld | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld b/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld index 8d652b606..7afb12b33 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld +++ b/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld @@ -40,8 +40,7 @@ MEMORY ram (rwx) : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */ } -/* The stack size used by the application. NOTE: you need to adjust */ -STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : 0x2000 ; +RAM_END = 0x20088000 ; /* There is a way to define this as ram.ORIGIN + ram.LENGTH ? */ /* Section Definitions */ SECTIONS @@ -129,16 +128,13 @@ SECTIONS _ezero = .; } > ram - /* stack section */ - .stack (NOLOAD): - { - . = ALIGN(8); - _sstack = .; - . = . + STACK_SIZE; - . = ALIGN(8); - _estack = .; - } > ram - . = ALIGN(4); _end = . ; + + /* put stack section at the bottom of ram space */ + .stack RAM_END (NOLOAD): + { + _sstack = .; + _estack = .; + } > ram } From cf28ccfb06f80d3e219ebcae3e7586fbe8c41e34 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 13 Aug 2012 14:44:30 +0200 Subject: [PATCH 2/2] Fixed linker script to allow growing stack+heap. --- .../arduino_due_x/linker_scripts/gcc/flash.ld | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld b/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld index 7afb12b33..53f2b5f1f 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld +++ b/hardware/arduino/sam/variants/arduino_due_x/linker_scripts/gcc/flash.ld @@ -40,8 +40,6 @@ MEMORY ram (rwx) : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */ } -RAM_END = 0x20088000 ; /* There is a way to define this as ram.ORIGIN + ram.LENGTH ? */ - /* Section Definitions */ SECTIONS { @@ -116,7 +114,7 @@ SECTIONS } > ram /* .bss section which is used for uninitialized data */ - .bss (NOLOAD) : + .bss ALIGN(4) (NOLOAD) : { . = ALIGN(4); _sbss = . ; @@ -131,10 +129,18 @@ SECTIONS . = ALIGN(4); _end = . ; - /* put stack section at the bottom of ram space */ - .stack RAM_END (NOLOAD): + /* .stack_dummy section doesn't contains any symbols. It is only + used for linker to calculate size of stack sections, and assign + values to stack symbols later */ + .stack_dummy : { - _sstack = .; - _estack = .; + *(.stack*) } > ram + + /* Set stack top to end of ram, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(ram) + LENGTH(ram); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(_sstack = __StackLimit); + PROVIDE(_estack = __StackTop); }