altos/stm: Align 'data' to 8 bytes, just like textram
authorKeith Packard <keithp@keithp.com>
Tue, 12 Dec 2017 23:31:27 +0000 (15:31 -0800)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Dec 2017 23:31:27 +0000 (15:31 -0800)
The textram section must be aligned to 8 bytes to keep the linker
happy. However, if that section contains no data, the declaration will
set the __data_start__ value to that alignment, but the data section
itself would start on a 4-byte alignment, potentially 4 bytes lower
than the value indicated by __data_start__. This completely scrambles
initialized memory as the startup code will copy the data segment to
__data_start__, 4 bytes off of the actual data segment start.

Fix this by forcing the data segment to also be aligned to 8 bytes.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/micropeak-v2.0/micropeak.ld
src/stm/altos-loader.ld
src/stmf0/altos-loader.ld

index 77717e168e7eead5f15dda1fc291cb33a12853ce..baeae5b81ac8c9f0be54a9cab7e205d888c94089 100644 (file)
@@ -19,8 +19,8 @@
 MEMORY {
        rom (rx) :   ORIGIN = 0x08001000, LENGTH = 20K
        flash(rx) :  ORIGIN = 0x08006000, LENGTH = 8K
-       ram (!w) :   ORIGIN = 0x20000000, LENGTH = 6k - 128
-       stack (!w) : ORIGIN = 0x20000000 + 6k - 128, LENGTH = 128
+       ram (!w) :   ORIGIN = 0x20000000, LENGTH = 6k - 512
+       stack (!w) : ORIGIN = 0x20000000 + 6k - 512, LENGTH = 512
 }
 
 INCLUDE registers.ld
@@ -94,11 +94,11 @@ SECTIONS {
                *(.ramtext)
        } >ram AT>rom
 
-       /* Data -- relocated to RAM, but written to ROM
+       /* Data -- relocated to RAM, but written to ROM,
+        * also aligned to 8 bytes to agree with textram
         */
-       .data : {
+       .data BLOCK(8): {
                *(.data)        /* initialized data */
-               . = ALIGN(4);
                __data_end__ = .;
        } >ram AT>rom
 
index a4a7dc43fe60c05381d2ff87b9ddd4e7628a0858..806b4842306d4281aee9c742e70910fcd29e78be 100644 (file)
@@ -72,8 +72,9 @@ SECTIONS {
        } >ram AT>rom
 
        /* Data -- relocated to RAM, but written to ROM
+        * Also aligned to 8 bytes to agree with textram
         */
-       .data : {
+       .data BLOCK(8): {
                *(.data)        /* initialized data */
                __data_end__ = .;
        } >ram AT>rom
index c458116b7e63a4af69ccfce3fa7c658727661764..05887d0ef92bf26f1ba65cc4d125887f40164ad0 100644 (file)
@@ -72,9 +72,10 @@ SECTIONS {
                __text_ram_end = .;
        } >ram AT>rom
 
-       /* Data -- relocated to RAM, but written to ROM
+       /* Data -- relocated to RAM, but written to ROM.
+        * also aligned to 8 bytes in case textram is empty
         */
-       .data : {
+       .data BLOCK(8): {
                *(.data)        /* initialized data */
                __data_end__ = .;
        } >ram AT>rom