Value of "__initial_sp"

Hello , 

I am new to ARM cortex M processors and while doing some coding on my board using KEIL  i found that

at location 0x0000_0000 my debugger shows the value "0x2000_0660" . Thats the value of the MSP loaded. 

but i really dont understand how linker arrived at that value using __initial_sp 

i checked in the startup file and found this 

; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Stack_Size EQU 0x00000400

AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp

How this turns out to be __initial_sp = 0x2000_0660 ???

Please help to understand this .

  • The stack would normally come after and .data or .bss section (I'm not sure why, if you're going to allocate a fixed-size stack anyway.  for "historical" reasons, perhaps - in a traditional small-memory microcontroller .data,.bss, and the heap would start at the beginning of memory and grow upward, while the stack would start at the end of memory and grow downward, and you'd "hope" that they never collided.)

  • Thanks Bill

    The stack would normally come after and .data or .bss section

    ok , so my RAM starts at 0x2000_0000 

    stack size is 0x400 and stack ends at 0x2000_0660( stack moves backward from here )

    that means , from 0x2000_0000 to 0x2000_0260 is a place for .data , .bss and heap ? 

    Which file will contain this info, i checked scatter file and couldn't able to obtain these sizes. 

  • Sounds right.  I think Keil produces a "memory map" output (or can certainly be configured to do so.)

    The old class project I have (UV5 on MSP432 launchpad) pops up the info when I double click on the "Target 1" in the project explorer (YMMV - I'm not too familiar with Keil.)  Somewhere in there there are some lines that look like:

    Image Symbol Table
    
        Local Symbols
    
        Symbol Name           Value     Ov Type        Size  Object(Section)
    
        RESET              0x00000000   Section      324  startup_msp432p401r_uvision.o(RESET)
            :
        .data              0x20000000   Section        4  main.o(.data)
        .bss               0x20000004   Section       96  libspace.o(.bss)
        HEAP               0x20000068   Section        0  startup_msp432p401r_uvision.o(HEAP)
        STACK              0x20000068   Section      512  startup_msp432p401r_uvision.o(STACK)
        Heap_Mem           0x20000068   Data           0  startup_msp432p401r_uvision.o(HEAP)
        Stack_Mem          0x20000068   Data         512  startup_msp432p401r_uvision.o(STACK)
        __initial_sp       0x20000268   Data           0  startup_msp432p401r_uvision.o(STACK)