blob: 80f5989786c255b48e942ea3572bcfd844043ef1 [file] [log] [blame]
Martin Roth9df9e9392016-01-12 15:55:28 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
Stefan Reinauer0054afa2011-10-25 23:43:34 +000014#include <string.h>
15
Mathias Krausedd30acd2012-03-31 17:23:53 +020016void *memcpy(void *dest, const void *src, size_t n)
Stefan Reinauer0054afa2011-10-25 23:43:34 +000017{
Mathias Krausedd30acd2012-03-31 17:23:53 +020018 unsigned long d0, d1, d2;
19
20 asm volatile(
Stefan Reinauer7c35af22015-06-17 16:09:10 -070021#ifdef __x86_64__
22 "rep ; movsd\n\t"
23 "mov %4,%%rcx\n\t"
24#else
Stefan Reinauer31409612012-08-22 17:01:08 -070025 "rep ; movsl\n\t"
26 "movl %4,%%ecx\n\t"
Stefan Reinauer7c35af22015-06-17 16:09:10 -070027#endif
Stefan Reinauer31409612012-08-22 17:01:08 -070028 "rep ; movsb\n\t"
29 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
30 : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
Mathias Krausedd30acd2012-03-31 17:23:53 +020031 : "memory"
Stefan Reinauer31409612012-08-22 17:01:08 -070032 );
Mathias Krausedd30acd2012-03-31 17:23:53 +020033
34 return dest;
Stefan Reinauer0054afa2011-10-25 23:43:34 +000035}