2012-08-02 14:39:16 +00:00
|
|
|
/*
|
2015-03-20 16:50:41 +00:00
|
|
|
* \brief CPU-specific memcpy
|
2012-08-02 14:39:16 +00:00
|
|
|
* \author Sebastian Sumpf
|
2022-12-08 14:09:01 +00:00
|
|
|
* \author Johanned Schlatow
|
2012-08-02 14:39:16 +00:00
|
|
|
* \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
|
|
|
*/
|
|
|
|
|
2022-12-08 14:09:01 +00:00
|
|
|
#ifndef _INCLUDE__CPU__STRING_H_
|
|
|
|
#define _INCLUDE__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
|
|
|
|
*
|
2015-03-20 16:50:41 +00:00
|
|
|
* \return number of bytes not copied
|
2012-08-02 14:39:16 +00:00
|
|
|
*/
|
2022-03-25 12:30:53 +00:00
|
|
|
inline size_t memcpy_cpu(void * dst, const void * src, size_t size)
|
|
|
|
{
|
|
|
|
typedef unsigned long word_t;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
LEN = sizeof(word_t),
|
|
|
|
MASK = LEN-1
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned char *d = (unsigned char *)dst, *s = (unsigned char *)src;
|
|
|
|
|
|
|
|
/* check byte alignment */
|
|
|
|
size_t d_align = (size_t)d & MASK;
|
|
|
|
size_t s_align = (size_t)s & MASK;
|
|
|
|
|
|
|
|
/* only same alignments work */
|
|
|
|
if (d_align != s_align)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
/* copy to word alignment */
|
|
|
|
for (; (size > 0) && (s_align > 0) && (s_align < LEN);
|
|
|
|
s_align++, *d++ = *s++, size--);
|
|
|
|
|
|
|
|
/* copy words */
|
|
|
|
for (; size >= LEN; size -= LEN,
|
|
|
|
d += LEN,
|
|
|
|
s += LEN)
|
|
|
|
*(word_t*)d = *(word_t*)s;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
2012-08-02 14:39:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 14:09:01 +00:00
|
|
|
#endif /* _INCLUDE__CPU__STRING_H_ */
|