mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-03 18:04:25 +00:00
hv:move several files related X86 for lib
modified: Makefile renamed: lib/memory.c -> arch/x86/lib/memory.c renamed: include/lib/atomic.h -> include/arch/x86/lib/atomic.h renamed: include/lib/bits.h -> include/arch/x86/lib/bits.h renamed: include/lib/spinlock.h -> include/arch/x86/lib/spinlock.h Tracked-On: #1842 Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
This commit is contained in:
committed by
ACRN System Integration
parent
350d6a9eb6
commit
795d6de0fb
58
hypervisor/arch/x86/lib/memory.c
Normal file
58
hypervisor/arch/x86/lib/memory.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include <types.h>
|
||||
|
||||
static inline void memcpy_erms(void *d, const void *s, size_t slen)
|
||||
{
|
||||
asm volatile ("rep; movsb"
|
||||
: "=&D"(d), "=&S"(s)
|
||||
: "c"(slen), "0" (d), "1" (s)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief Copies at most slen bytes from src address to dest address, up to dmax.
|
||||
*
|
||||
* INPUTS
|
||||
*
|
||||
* @param[in] d pointer to Destination address
|
||||
* @param[in] dmax maximum length of dest
|
||||
* @param[in] s pointer to Source address
|
||||
* @param[in] slen maximum number of bytes of src to copy
|
||||
*
|
||||
* @return pointer to destination address.
|
||||
*
|
||||
* @pre d and s will not overlap.
|
||||
*/
|
||||
void *memcpy_s(void *d, size_t dmax, const void *s, size_t slen)
|
||||
{
|
||||
if ((slen != 0U) && (dmax != 0U) && (dmax >= slen)) {
|
||||
/* same memory block, no need to copy */
|
||||
if (d != s) {
|
||||
memcpy_erms(d, s, slen);
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline void memset_erms(void *base, uint8_t v, size_t n)
|
||||
{
|
||||
asm volatile("rep ; stosb"
|
||||
: "+D"(base)
|
||||
: "a" (v), "c"(n));
|
||||
}
|
||||
|
||||
void *memset(void *base, uint8_t v, size_t n)
|
||||
{
|
||||
/*
|
||||
* Some CPUs support enhanced REP MOVSB/STOSB feature. It is recommended
|
||||
* to use it when possible.
|
||||
*/
|
||||
if ((base != NULL) && (n != 0U)) {
|
||||
memset_erms(base, v, n);
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
Reference in New Issue
Block a user