Commit fa56125d authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

util: Move memcopy helper into the header

Since we will need it in parasite and restorer
code rename it to inline_memcpy to avoid name
collision.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@gmail.com>
parent 168d8cf1
...@@ -189,4 +189,18 @@ int open_fmt(char *fmt, int mode, ...); ...@@ -189,4 +189,18 @@ int open_fmt(char *fmt, int mode, ...);
__ret; \ __ret; \
}) })
static void always_inline *inline_memcpy(void *dest, const void *src, size_t n)
{
long d0, d1, d2;
asm volatile(
"rep ; movsq\n\t"
"movq %4,%%rcx\n\t"
"rep ; movsb\n\t"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
: "memory");
return dest;
}
#endif /* UTIL_H_ */ #endif /* UTIL_H_ */
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "syscall.h" #include "syscall.h"
#include "parasite.h" #include "parasite.h"
#include "image.h" #include "image.h"
#include "util.h"
#include "crtools.h" #include "crtools.h"
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
...@@ -21,20 +22,6 @@ static void *brk_start, *brk_end, *brk_tail; ...@@ -21,20 +22,6 @@ static void *brk_start, *brk_end, *brk_tail;
static struct page_entry page; static struct page_entry page;
static struct vma_entry vma; static struct vma_entry vma;
void *memcpy(void *dest, const void *src, size_t n)
{
long d0, d1, d2;
asm volatile(
"rep ; movsq\n\t"
"movq %4,%%rcx\n\t"
"rep ; movsb\n\t"
: "=&c" (d0), "=&D" (d1), "=&S" (d2)
: "0" (n >> 3), "g" (n & 7), "1" (dest), "2" (src)
: "memory");
return dest;
}
static void brk_init(void *brk) static void brk_init(void *brk)
{ {
brk_start = brk_tail = brk; brk_start = brk_tail = brk;
...@@ -148,7 +135,7 @@ static int restore_core(char *corefile) ...@@ -148,7 +135,7 @@ static int restore_core(char *corefile)
goto err; goto err;
} }
memcpy((void *)page.va, page.data, sizeof(page.data)); inline_memcpy((void *)page.va, page.data, sizeof(page.data));
} }
ret = 0; ret = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment