What are the possible reasons for registers to be offset by 1 in GDB?

3

The microcontroller is an STM32 F767ZI, which contains a 32 bit ARM Cortex M7

When setting values to the registers, the registers all appear to be offset by 1.

For example, the following code:

core.S

.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb

// Global memory locations
.global vtable
.global reset_handler

 .type vtable, %object
 vtable:
    .word _estack
    .word reset_handler
.size vtable, .-vtable

/*
 * The Reset handler
 */
 .type reset_handler, %function
 reset_handler:
    // The '_estack' value is defined in the linker script
    LDR sp, =_estack
    

    // Dummy values
    LDR r5, =0xDEADBEEF
    MOV r3, #50
    
.size reset_handler, .-reset_handler

linkerScripts/stm32-767zi.ld

_estack = 0x20080000;

MEMORY
{
    FLASH ( rx )        : ORIGIN = 0x08000000, LENGTH = 2048K
    RAM ( rxw )         : ORIGIN = 0x20000000, LENGTH = 512K
}

When compiled by running:

arm-none-eabi-gcc -x assembler-with-cpp -c -O0 -mcpu=cortex-m7 -mthumb -Wall core.S -o core.o

And then...

arm-none-eabi-gcc core.o -mcpu=cortex-m7 -mthumb -Wall --specs=nosys.specs -nostdlib -lgcc -T./linkerScripts/stm32-767zi.ld -o main.elf

Results in:

register values

As you can see, r6 is set to 0xdeadbeef rather than r5, which is what was written in the code earlier. This offset is the same with the other two registers that were set.

I believe the values for the linker script are correct, so I would assume the issue is a result of an incorrect configuration elsewhere.

So, I am a little unsure of how to proceed from here, and ask if anyone has any ideas or suggestions as to what could be the issue.

assembly
arm
gdb
gnu
cortex-m
asked on Stack Overflow Mar 22, 2021 by Starman • edited Mar 22, 2021 by Peter Cordes

1 Answer

3

Well, having seen the majority of comments suggesting that it is likely an issue with the GDB server, I decided to give another GDB server a go.

The outcome was very pleasing:

correct registers

For:

core.S

.syntax unified
.cpu cortex-m7
.fpu softvfp
.thumb

// Global memory locations
.global vtable
.global reset_handler

 .type vtable, %object
 vtable:
    .word _estack
    .word reset_handler
.size vtable, .-vtable

/*
 * The Reset handler
 */
 .type reset_handler, %function
 reset_handler:
    // The '_estack' value is defined in the linker script
    LDR sp, =_estack
    

    // Dummy values
    LDR r5, =0xDEADBEEF
    MOV r3, #50
    
.size reset_handler, .-reset_handler

This resolved the issue for me.

Oringinally, I was using stlink v1.6.1 on Windows, however I switched over to the GDB which comes as part of the STM32CubeIDE.

It appears that the issue was indeed with the GDB server.

Thank you to everyone for the help and suggestions, it is very much appreciated.

answered on Stack Overflow Mar 23, 2021 by Starman

User contributions licensed under CC BY-SA 3.0