We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
Hi Pavitra,
Can you be more specific about what problem you are seeing? Perhaps you could post your code segment and the output from the simulation?
Chris
Hi Chris,
I have taken the following example from the Bare-metal_examples.zip provided by ARM DS-5 : "startup_Cortex-A8" for simulation on ARM-DS5. Then added few lines of extra code which includes memcpy() in sorts.c (attached), with which I was ...as able to simulate properly. Later Ive added few more files for the above ARM supplied project and changed "scatter.scat" which has been named as ( scatter_modified.scat ,attached ). So now the same piece of code containing memcpy is crashing when the execution is encountering that particular line containing memcpy.
Before memcpy is encountered in the code
memcpy(pCurrLoc, pLeftLoc, sizeof (MY_STR));--------------------> Added by me
Both src and dest pointers are of same type
MY_STR *pCurrLoc;
MY_STR *pLeftLoc;
My destination pointer pCurrLoc is at 0x0014 B1A4
My source pointer pLeftLoc is at 0x0014 B183
Length of both the source and destination is 33 bytes.
Im hereby attaching the code also.
Thanks and Regards
Had you enabled the compiler option --no_unaligned_access ?
Also try using strcpy() instead of memcpy(). I believe the length you had specified copies one byte lesser than actual string copy.
I haven't had time to analyse your code properly but it looks to me as if strings and strings_copy are not initialised before you use them. Check this first.
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;
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 ];
Pls try to help me out reg this???
Ofcourse it is. Im using the unaligned data only.
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
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
Hi Pavi,
Kindly use the option --no_unaligned_access in the compiler option and run it.
Hi, did your issue get resolved with the compiler option?