2012-08-02 14:39:16 +00:00
|
|
|
/*
|
2013-05-07 19:59:15 +00:00
|
|
|
* \brief ARM-specific memcpy
|
2012-08-02 14:39:16 +00:00
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2012-08-02
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2012-2017 Genode Labs GmbH
|
2012-08-02 14:39:16 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-08-02 14:39:16 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-03 12:55:05 +00:00
|
|
|
#ifndef _INCLUDE__SPEC__ARM__CPU__STRING_H_
|
|
|
|
#define _INCLUDE__SPEC__ARM__CPU__STRING_H_
|
2012-08-02 14:39:16 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
namespace Genode {
|
|
|
|
|
2012-08-02 14:39:16 +00:00
|
|
|
/**
|
|
|
|
* Copy memory block
|
|
|
|
*
|
|
|
|
* \param dst destination memory block
|
|
|
|
* \param src source memory block
|
|
|
|
* \param size number of bytes to copy
|
|
|
|
*
|
|
|
|
* \return Number of bytes not copied
|
|
|
|
*/
|
|
|
|
inline size_t memcpy_cpu(void *dst, const void *src, size_t size)
|
|
|
|
{
|
|
|
|
unsigned char *d = (unsigned char *)dst, *s = (unsigned char *)src;
|
|
|
|
|
2022-03-25 09:12:46 +00:00
|
|
|
/* fetch the first cache line */
|
|
|
|
asm volatile ("pld [%0, #0]\n\t" : "+r" (s));
|
2012-08-02 14:39:16 +00:00
|
|
|
|
2022-03-25 09:12:46 +00:00
|
|
|
/* check 32-byte (cache line) alignment */
|
|
|
|
size_t d_align = (size_t)d & 0x1f;
|
|
|
|
size_t s_align = (size_t)s & 0x1f;
|
|
|
|
|
|
|
|
/* only same word-alignments work for the following LDM/STM loop */
|
|
|
|
if ((d_align & 0x3) != (s_align & 0x3))
|
2012-08-02 14:39:16 +00:00
|
|
|
return size;
|
|
|
|
|
2022-03-25 09:12:46 +00:00
|
|
|
/* copy to 32-byte alignment */
|
|
|
|
for (; (size > 0) && (s_align > 0) && (s_align < 32);
|
2013-04-26 11:03:01 +00:00
|
|
|
s_align++, *d++ = *s++, size--);
|
2012-08-02 14:39:16 +00:00
|
|
|
|
|
|
|
/* copy 32 byte chunks */
|
|
|
|
for (; size >= 32; size -= 32) {
|
|
|
|
asm volatile ("ldmia %0!, {r3 - r10} \n\t"
|
2022-03-25 09:12:46 +00:00
|
|
|
"pld [%0, #160]\n\t"
|
2012-08-02 14:39:16 +00:00
|
|
|
"stmia %1!, {r3 - r10} \n\t"
|
|
|
|
: "+r" (s), "+r" (d)
|
|
|
|
:: "r3","r4","r5","r6","r7","r8","r9","r10");
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-03 12:55:05 +00:00
|
|
|
#endif /* _INCLUDE__SPEC__ARM__CPU__STRING_H_ */
|