This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28034: memcpy() generate infinite recursive cycle

Part Number: TMS320F28034
Other Parts Discussed in Thread: C2000WARE

I watch disasembly

main():
3ecdb1: FE08 ADDB SP, #8
504 memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32)&RamfuncsLoadSize);
3ecdb9: 28A90270 MOV @AL, #0x0270
3ecdbb: 28A80000 MOV @AH, #0x0000
3ecdbd: 8F008800 MOVL XAR4, #0x008800
3ecdbf: 8F7F0AFF MOVL XAR5, #0x3f0aff
3ecdc1: 767F0AFC LCR memcpy

where

8 /* modification, are permitted provided that the following conditions */
memcpy():
3f0afc: 767F0AFC LCR memcpy
10 /* */
3f0afe: 0006 LRETR

memcpy called memcpy and overflow stack.

What have I done wrong?

compiler TI v18.12.1.LTS

  • Hi Sergey,

    Please could you provide more details on your observation? Are you using the standard memcpy command to copy functions to RAM found in the C2000Ware Flash examples and noticing this behavior or are you doing something special?

    Can you let me know how the RamfuncsRunStart, RamfuncsLoadStart, RamfuncsLoadSize are defined in your linker command file?

    Thanks,

    Ashwini

  • Hi.

    I include <string.h> from standart compiler library, where

    _CODE_ACCESS void *memcpy(void * __restrict s1,
    const void * __restrict s2, size_t n);

    In linker script

    MEMORY
    {
    PAGE 0:
    RAML1       : origin = 0x008800, length = 0x000400
    FLASHFEDC      : origin = 0x3EC002, length = 0x007FDA
    ...

    ramfuncs : LOAD = FLASHFEDC,
    RUN = RAML1,
    LOAD_START(_RamfuncsLoadStart),
    LOAD_SIZE(_RamfuncsLoadSize),
    LOAD_END(_RamfuncsLoadEnd),
    RUN_START(_RamfuncsRunStart),
    PAGE = 0

    If I change size of copy data to 255 or less, then memcpy compiled to inline code and work

    505 memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, 255);
    3ecdbc: 76FF0AF5 MOVL XAR7, #0x3f0af5
    3ecdbe: 8F008800 MOVL XAR4, #0x008800
    3ecdc0: F6FE RPT #254
    3ecdc1: 2484 || PREAD *XAR4++, *XAR7

    ===================================================================

    I looked in my other project, and there memcpy disassembled correct:

    memcpy():
    3f16d1: 5200 CMPB AL, #0x0
    40 {
    3f16d2: A8AB MOVL @P, XAR4
    3f16d3: C5A4 MOVL XAR7, @XAR4
    51 for (rn = 0; rn < nn; rn++) *rto++ = *rfrom++;
    3f16d4: 6107 SB C$L2, EQ
    3f16d5: 88A9 MOVZ AR6, @AL
    3f16d6: DE81 SUBB XAR6, #1
    C$L1:
    3f16d7: 5C85 MOVZ AR4, *XAR5++
    3f16d8: 7C87 MOV *XAR7++, AR4
    3f16d9: 000EFFFE BANZ -2,AR6--
    52 if (nn == n) return (to);
    C$L2:
    3f16db: 88A9 MOVZ AR6, @AL
    3f16dc: 0FA6 CMPL ACC, @XAR6
    3f16dd: 610F SB C$L5, EQ
    3f16de: 5300 CMPB AH, #0x0
    3f16df: 610D SB C$L5, EQ
    3f16e0: 9DFF ADDB AH, #-1
    3f16e1: 5CA8 MOVZ AR4, @AH
    C$L3:
    3f16e2: 76BFFFFE MOVL XAR6, #0x3ffffe
    64 *rto++ = *rfrom++;
    C$L4:
    3f16e4: 9285 MOV AL, *XAR5++
    3f16e5: 9687 MOV *XAR7++, AL
    63 for (rn = 0; rn < 65535; rn++)
    3f16e6: 000EFFFE BANZ -2,AR6--
    65 *rto++ = *rfrom++;
    3f16e8: 9285 MOV AL, *XAR5++
    3f16e9: 9687 MOV *XAR7++, AL
    61 for (tmp = 0; tmp < upper; tmp++)
    3f16ea: 000CFFF8 BANZ -8,AR4--
    69 return (to);
    C$L5:
    3f16ec: A9A4 MOVL @XAR4, P
    3f16ed: 0006 LRETR

    Maybe need include or define something else?

  • Hi Sergey,

    I will follow up with the Compiler team and let you know.

    Thanks,

    Ashwini

  • I solved the problem.

    There was a file rts2800_ml.lib in a some folder of the common project files. I do not know who and why added this file to the common...

    In the old project, it was excluded from build. I exclude from build in my current project too and memcpy began compiled correct.

    While the size of the data for memcopy was less than 256 I could not notice the dirty trick