How to correct stack location arm-none-eabi-gcc?

0

I try to create a bare metal code using the standard lib C.

I started with an assembly code

.section .isr_vector 
.global _Reset
_Reset:
    B Reset_Handler /* Reset */
    B .             /* Undefined */
    B .             /* SWI */
    B .             /* Prefetch Abort */ 
    B .             /* Data Abort */
    B .             /* reserved */
    B .             /* IRQ */
    B .             /* FIQ */  

.global Reset_Handler
 Reset_Handler:
    ldr sp, =_estack
    mov fp, #0

    // Branch to C code  
    BL _start
    B .

I found example of code using symbol _estack to locate the stack

In the linker file I put:

ENTRY(_Reset)

MEMORY
{
    RAM (xrw) : ORIGIN = 0x00000000, LENGTH = 512M
}
/* define stack size and heap size here */
stack_size = 4*1024;
heap_size = 128*1024; 
/* define beginning and ending of stack */
_estack  = ORIGIN(RAM)+LENGTH(RAM);
_sstack = _estack - stack_size;

With GDB I check that _estack is at the right place 0x20000000

When I trace the code and enter the _start function the $sp change to 0x80000

This is done by taking the info from a memory location with no symbol:

-exec disas _start
Dump of assembler code for function _start:
   0x00000084 <+0>: ldr r3, [pc, #84]   ; (0xdc <_start+88>)
   0x00000086 <+2>: cmp r3, #0
   0x00000088 <+4>: it  eq
   0x0000008a <+6>: ldreq   r3, [pc, #76]   ; (0xd8 <_start+84>)

Here are my command lines:

arm-none-eabi-gcc -ffreestanding -specs=nano.specs -specs=nosys.specs -Wall -O0 -g3  -Wextra -std=c99 -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -Iinclude -Llib src/main.c src/start.s -o bin/main   -Xlinker -static -TSECTIONS.ld
arm-none-eabi-nm bin/main > bin/symbols.txt
arm-none-eabi-objdump --disassemble-all bin/main > bin/asm.S
arm-none-eabi-objdump -s  bin/main > bin/MixedCASM.txt

Is there a possibility to know the right symbols to locate the stack?

gcc
arm
bare-metal
linker-scripts
cortex-a
asked on Stack Overflow Feb 17, 2020 by marcoDiroccho • edited Feb 17, 2020 by artless noise

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0