[a68003f] | 1 | /*
|
---|
[7e9769f] | 2 | * Copyright (C) 2005 Sergey Bondari
|
---|
[a68003f] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | #ifndef __ia32_MEMSTR_H__
|
---|
| 30 | #define __ia32_MEMSTR_H__
|
---|
| 31 |
|
---|
| 32 | extern void memsetw(__address dst, size_t cnt, __u16 x);
|
---|
| 33 | extern void memsetb(__address dst, size_t cnt, __u8 x);
|
---|
| 34 |
|
---|
| 35 | /** Copy memory
|
---|
| 36 | *
|
---|
| 37 | * Copy a given number of bytes (3rd argument)
|
---|
| 38 | * from the memory location defined by 2nd argument
|
---|
| 39 | * to the memory location defined by 1st argument.
|
---|
| 40 | * The memory areas cannot overlap.
|
---|
| 41 | *
|
---|
| 42 | * @param destination
|
---|
| 43 | * @param source
|
---|
| 44 | * @param number of bytes
|
---|
| 45 | * @return destination
|
---|
| 46 | */
|
---|
| 47 | static inline void * memcpy(void * dst, const void * src, size_t cnt)
|
---|
| 48 | {
|
---|
| 49 | __u32 d0, d1, d2;
|
---|
| 50 |
|
---|
| 51 | __asm__ __volatile__(
|
---|
| 52 | /* copy all full dwords */
|
---|
| 53 | "rep movsl\n\t"
|
---|
| 54 | /* load count again */
|
---|
| 55 | "movl %4, %%ecx\n\t"
|
---|
| 56 | /* ecx = ecx mod 4 */
|
---|
| 57 | "andl $3, %%ecx\n\t"
|
---|
| 58 | /* are there last <=3 bytes? */
|
---|
| 59 | "jz 1f\n\t"
|
---|
| 60 | /* copy last <=3 bytes */
|
---|
| 61 | "rep movsb\n\t"
|
---|
| 62 | /* exit from asm block */
|
---|
| 63 | "1:\n"
|
---|
| 64 | : "=&c" (d0), "=&D" (d1), "=&S" (d2)
|
---|
| 65 | : "0" (cnt / 4), "g" (cnt), "1" ((__u32) dst), "2" ((__u32) src)
|
---|
| 66 | : "memory");
|
---|
| 67 |
|
---|
| 68 | return dst;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
[8e3f47b3] | 72 | /** Compare memory
|
---|
| 73 | *
|
---|
| 74 | * Compare a given number of bytes (3rd argument)
|
---|
| 75 | * at memory locations defined by 1st and 2nd argument
|
---|
| 76 | * for equality. If memory is equal, returns 0.
|
---|
| 77 | *
|
---|
| 78 | * @param pointer 1
|
---|
| 79 | * @param pointer 2
|
---|
| 80 | * @param number of bytes
|
---|
| 81 | * @return 0 on match or non-zero if different
|
---|
| 82 | */
|
---|
| 83 | static inline int memcmp(const void * mem1, const void * mem2, size_t cnt)
|
---|
| 84 | {
|
---|
| 85 | __u32 d0, d1, d2;
|
---|
| 86 | int ret;
|
---|
| 87 |
|
---|
| 88 | __asm__ (
|
---|
| 89 | "repe cmpsb\n\t"
|
---|
| 90 | "je 1f\n\t"
|
---|
| 91 | "movl %3, %0\n\t"
|
---|
| 92 | "addl $1, %0\n\t"
|
---|
| 93 | "1:\n"
|
---|
| 94 | : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
|
---|
| 95 | : "0" (0), "1" (mem1), "2" (mem2), "3" (cnt)
|
---|
| 96 | );
|
---|
| 97 |
|
---|
| 98 | return ret;
|
---|
| 99 | }
|
---|
[a68003f] | 100 |
|
---|
| 101 | #endif
|
---|