0

I was playing with blue pill (Stm32F103CB) and trying to set r7 register via assembly,

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

.global vtable
.global reset_handler

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


.type reset_handler, %function
reset_handler:

    LDR  r0, =_estack
    MOV  sp, r0
    LDR  r7, =0xDEADBEEF
.size reset_handler, .-reset_handler

The bug is that when i observe the register values via gdb -> info registers i see r8 register set instead of r7 as can be seen in below image.

enter image description here

objdump disassembly of elf also seems correct.

enter image description here

I am unable to understand why this is happening, tried the same with multiple boards, how can i debug and resolve this issue.

Thanks in advance.

3
  • 1
    Sounds strange, but post text in code blocks, not images of text. Commented Nov 7, 2020 at 11:49
  • Sorry, yep i've updated that now. Commented Nov 7, 2020 at 11:58
  • you dont have a return in that code, so if you try to execute it it is going to crash possibly interpreting what it finds as instructions along the way. Commented Nov 7, 2020 at 16:08

1 Answer 1

1

Ok so i did some further tests.

The issue is with this opensource stlink gdb server:

https://github.com/stlink-org/stlink

All the registers are numbered as r# + 1 for some reason, and even the sp value is shown as lr.

I tried with openocd instead and everything works as expected.

https://repo.or.cz/w/openocd.git

Will raise a ticket in the stlink-org repo for this.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.