I am porting some software from the gcc-toolchain to the armcc-toolchain (processor stays the same (Cortex-A9)). In the C-code memcpy is used. armcc replaces a call to memcpy by a call to __aeabi_memcpy. The FAQ sais the following about __aeabi_memcpy (How do the ARM Compilers handle memcpy()?):
In many cases, when compiling calls to memcpy(), the ARM C compiler will generate calls to specialized, optimised, library functions instead. Since RVCT 2.1, these specialized functions are part of the ABI for the ARM architecture (AEABI), and include:
__aeabi_memcpy
This function is the same as ANSI C memcpy, except that the return value is void.
But in contrast to gcc, where a call to memcpy works fine in all of my cases, with armcc the call to memcpy respectivly __aeabi_memcpy continuously produces alignment exceptions. Meanwhile I found out, that a call to memcpy can handle calls where source and destination address are not 4-byte aligned, but only if they are both not 4-byte aligned. For example:
volatile uint32_t len = 10;
uint8_t* src = (uint8_t*)0x06000002; // 2-byte aligned
uint8_t* dst = (uint8_t*)(0x06000002 + 20); // 2-byte aligned
memcpy(dst, src, len);
will work. But for example:
volatile uint32_t len = 10;
uint8_t* src = (uint8_t*)0x06000002; // 2-byte aligned
uint8_t* dst = (uint8_t*)(0x06000002 + 22); // 4-byte aligned
memcpy(dst, src, len);
will cause an alignment exception. SInce I am using pointers of type uint8_t* I explicitly tell the compiler that the addresses can have any alignment. But obviously this __aeabi_memcpy can not handle every combination of alignments. How can I solve this problem (preferably without changing all calls to memcpy in the existing code with a user-specific version of memcpy)? Thanks for help.