This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Memcpy

Hi,

   I'm trying to simulate C and Assembly code on DS-5 Simulator  with Cortex-A8 as a bare metal application on Linux. Im having issue with the memcpy.

    Im trying to use Memcpy( a, b, size). Here source and destinations, a and b are pointers to the same structure of size 31 bytes. Address of a is 0x0014 b1a4 and b is 0x0014 b183. Size is 31 bytes. So is the problem due to non-alignment of memory or anything else. Can anyone help me out to resolve this issue?

Thanks in advance .

Pavitra

Parents
  • Chrish,

          Below is the code added by me and the one which is giving problem. Rest of the  code is the example code ( strings and strings_copy ara already in the example)

    int nParts = 28;

        int location = 4;

        MY_STR *pBase;

        MY_STR *pCurrLoc;

        MY_STR *pLeftLoc;

        pBase = (MY_STR *) malloc(nParts * sizeof (MY_STR));

        if (pBase == NULL)

        {

            printf("\n Failed to allocate memory for pBase of type MY_STR in file sorts.c \n");

            return -1;

        }

        pCurrLoc = &pBase[ location ];

        pLeftLoc = &pBase[ location - 1 ];

        memcpy(pCurrLoc, pLeftLoc, sizeof (MY_STR));--------------------> Added by me

    Pls try to  help me out  reg this???

Reply
  • Chrish,

          Below is the code added by me and the one which is giving problem. Rest of the  code is the example code ( strings and strings_copy ara already in the example)

    int nParts = 28;

        int location = 4;

        MY_STR *pBase;

        MY_STR *pCurrLoc;

        MY_STR *pLeftLoc;

        pBase = (MY_STR *) malloc(nParts * sizeof (MY_STR));

        if (pBase == NULL)

        {

            printf("\n Failed to allocate memory for pBase of type MY_STR in file sorts.c \n");

            return -1;

        }

        pCurrLoc = &pBase[ location ];

        pLeftLoc = &pBase[ location - 1 ];

        memcpy(pCurrLoc, pLeftLoc, sizeof (MY_STR));--------------------> Added by me

    Pls try to  help me out  reg this???

Children
  • Thanks for posting the code. Are you able to say what error occurs when you try to run it?

  • Chris,

       When my code is encountering the line containing memcpy, its going to infinite loop( THE ERROR : NO STACK) and getting crashed.

    Thx

    Pavitra

  • Is the address returned by malloc valid on your platform? Have you correctly configured the heap in the C library init routine?

  • Peter,

       Yes, the address returned by malloc is perfectly valid and it is working fine when I initially added small piece of code, but later when 've added few more files and also I've modified the scatter file as below and configured the heap here.

      APP_DATA +0

      {

            * (+RW, +ZI)            ; Application RW (.data) and ZI (.bss) data

        }

      ARM_LIB_HEAP  0x00040000 EMPTY  0x05FC0000 ; Application heap

      { }

      ARM_LIB_STACK 0x07000000 EMPTY -0x01000000 ; Application (SVC mode) stack

      { }

      IRQ_STACK     0x08000000 EMPTY -0x01000000 ; IRQ mode stack

      { }

      TTB     0x09000000 EMPTY 0x40000            ; Level-1 Translation Table for MMU

      { }

    }