AnsweredAssumed Answered

thumb misalignment? [was: memcpy oddness]

Question asked by jrandomguy on Aug 3, 2016
Latest reply on Aug 7, 2016 by jrandomguy
Hi Guys,

    I've recently started working with the STM32F0 series of microcontrollers, took a while to get a fully functional build chain up and running, but now everything looks good on that front.

I've run into an oddball issue with memcpy, initially I thought it was an issue with one of the libraries I'm importing, but I've since dropped that and I'm seeing the issue in user code.

It appears that the __memcpy_from_thumb stub is misaligned somehow, I've disassembled the code in IDA and it all looks fine, but when I step through it in GDB things look very weird.

Segment in question in IDA;
.text:08002640                 CODE16
.text:08002640 ; =============== S U B R O U T I N E =======================================
.text:08002640 ; Attributes: thunk
.text:08002640 __memcpy_from_thumb                     ; CODE XREF: wc_Md5Update+3Cp
.text:08002640                                         ; wc_Md5Final+ACp ...
.text:08002640                 BX      PC
.text:08002640 ; ---------------------------------------------------------------------------
.text:08002642                 ALIGN 4
.text:08002644                 CODE32
.text:08002644 loc_8002644                             ; CODE XREF: __memcpy_from_thumbj
.text:08002644                 B       memcpy
.text:08002644 ; End of function __memcpy_from_thumb
Everything looks good, drilling through to memcpy leads me to something that looks very much like a memcpy function, so it looks like IDA is doing the business.

However, when I load the code to my target (STM32F051R8 on the STM32F0DISCOVERY) and step through it in GDB I get the following;
0x8002640 <__memcpy_from_thumb>    bx     pc
0x8002642 <__memcpy_from_thumb+2>  nop        ; (mov r8, r8)
0x8002644 <__memcpy_from_thumb+4>             ; <UNDEFINED> instruction: 0xff81eaff
Stepping through the code lands me in the HardFault handler. This looks for all the world like it's misaligned but I've no idea where to start with troubleshooting this issue.

Any assistance would be greatly appreciated.