Martin Roth | 9df9e939 | 2016-01-12 15:55:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Reinauer | 0054afa | 2011-10-25 23:43:34 +0000 | [diff] [blame] | 14 | #include <string.h> |
| 15 | |
Mathias Krause | dd30acd | 2012-03-31 17:23:53 +0200 | [diff] [blame] | 16 | void *memcpy(void *dest, const void *src, size_t n) |
Stefan Reinauer | 0054afa | 2011-10-25 23:43:34 +0000 | [diff] [blame] | 17 | { |
Mathias Krause | dd30acd | 2012-03-31 17:23:53 +0200 | [diff] [blame] | 18 | unsigned long d0, d1, d2; |
| 19 | |
| 20 | asm volatile( |
Stefan Reinauer | 7c35af2 | 2015-06-17 16:09:10 -0700 | [diff] [blame] | 21 | #ifdef __x86_64__ |
| 22 | "rep ; movsd\n\t" |
| 23 | "mov %4,%%rcx\n\t" |
| 24 | #else |
Stefan Reinauer | 3140961 | 2012-08-22 17:01:08 -0700 | [diff] [blame] | 25 | "rep ; movsl\n\t" |
| 26 | "movl %4,%%ecx\n\t" |
Stefan Reinauer | 7c35af2 | 2015-06-17 16:09:10 -0700 | [diff] [blame] | 27 | #endif |
Stefan Reinauer | 3140961 | 2012-08-22 17:01:08 -0700 | [diff] [blame] | 28 | "rep ; movsb\n\t" |
| 29 | : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
| 30 | : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src) |
Mathias Krause | dd30acd | 2012-03-31 17:23:53 +0200 | [diff] [blame] | 31 | : "memory" |
Stefan Reinauer | 3140961 | 2012-08-22 17:01:08 -0700 | [diff] [blame] | 32 | ); |
Mathias Krause | dd30acd | 2012-03-31 17:23:53 +0200 | [diff] [blame] | 33 | |
| 34 | return dest; |
Stefan Reinauer | 0054afa | 2011-10-25 23:43:34 +0000 | [diff] [blame] | 35 | } |