From 086f9155f793cc3683af6abb37f1bc7fc0442551 Mon Sep 17 00:00:00 2001 From: Steins7 Date: Mon, 18 Sep 2023 11:45:12 +0200 Subject: [PATCH] Fix RAM initialisation The reset handler is responsible for loading the variables default values. This includes variables initialized to 0, although they are handed through bss and not data --- linker.ld | 3 +++ startup.s | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/linker.ld b/linker.ld index 4f30b65..55cadad 100644 --- a/linker.ld +++ b/linker.ld @@ -64,7 +64,10 @@ SECTIONS .bss : { . = ALIGN(4); + _sbss = .; *(.bss) + . = ALIGN(4); + _ebss = .; } > RAM /* memory space allocated to stack. The stack is situated at the very end of diff --git a/startup.s b/startup.s index 3a3b5a1..8f48739 100644 --- a/startup.s +++ b/startup.s @@ -34,19 +34,35 @@ hdr_reset: ldr r1, = _sdata ldr r2, = _edata subs r2, r2, r1 - bcc startup_init_end + bcc data_init_end ldr r3, = _sromdata movs r0, #0 -startup_init_loop: +data_init_loop: ldr r4, [r3, r0] str r4, [r1, r0] adds r0, r0, #4 cmp r0, r2 - bcc startup_init_loop + bcc data_init_loop -startup_init_end: +data_init_end: +//initialize RAM to zero + ldr r1, = _sbss + ldr r2, = _ebss + subs r2, r2, r1 + bcc bss_init_end + movs r3, #0 + + movs r0, #0 + +bss_init_loop: + str r3, [r1, r0] + adds r0, r0, #4 + cmp r0, r2 + bcc bss_init_loop + +bss_init_end: b main b hdr_reset