soc/amd/stoneyridge: remove LIDS field from global NVS
[coreboot.git] / payloads / libpayload / arch / x86 / string.c
blob836d0498313423f4f53532aaa324545f4d897fbb
1 /*
2 * Copyright (C) 1991,1992,1993,1997,1998,2003, 2005 Free Software Foundation, Inc.
3 * Copyright (c) 2011 The ChromiumOS Authors.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 /* From glibc-2.14, sysdeps/i386/memset.c */
18 #include <stdint.h>
20 #include "string.h"
22 typedef uint32_t op_t;
24 void *memset(void *dstpp, int c, size_t len)
26 int d0;
27 unsigned long int dstp = (unsigned long int) dstpp;
29 /* This explicit register allocation improves code very much indeed. */
30 register op_t x asm("ax");
32 x = (unsigned char) c;
34 /* Clear the direction flag, so filling will move forward. */
35 asm volatile("cld");
37 /* This threshold value is optimal. */
38 if (len >= 12) {
39 /* Fill X with four copies of the char we want to fill with. */
40 x |= (x << 8);
41 x |= (x << 16);
43 /* Adjust LEN for the bytes handled in the first loop. */
44 len -= (-dstp) % sizeof(op_t);
47 * There are at least some bytes to set. No need to test for
48 * LEN == 0 in this alignment loop.
51 /* Fill bytes until DSTP is aligned on a longword boundary. */
52 asm volatile(
53 "rep\n"
54 "stosb" /* %0, %2, %3 */ :
55 "=D" (dstp), "=c" (d0) :
56 "0" (dstp), "1" ((-dstp) % sizeof(op_t)), "a" (x) :
57 "memory");
59 /* Fill longwords. */
60 asm volatile(
61 "rep\n"
62 "stosl" /* %0, %2, %3 */ :
63 "=D" (dstp), "=c" (d0) :
64 "0" (dstp), "1" (len / sizeof(op_t)), "a" (x) :
65 "memory");
66 len %= sizeof(op_t);
69 /* Write the last few bytes. */
70 asm volatile(
71 "rep\n"
72 "stosb" /* %0, %2, %3 */ :
73 "=D" (dstp), "=c" (d0) :
74 "0" (dstp), "1" (len), "a" (x) :
75 "memory");
77 return dstpp;
80 void *memcpy(void *dest, const void *src, size_t n)
82 unsigned long d0, d1, d2;
84 asm volatile(
85 "rep ; movsl\n\t"
86 "movl %4,%%ecx\n\t"
87 "rep ; movsb\n\t"
88 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
89 : "0" (n >> 2), "g" (n & 3), "1" (dest), "2" (src)
90 : "memory"
93 return dest;