Rev 361 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 361 | Rev 363 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 HelenOS project |
2 | * Copyright (C) 2005 Sergey Bondari |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #ifndef __ia32_MEMSTR_H__ |
29 | #ifndef __ia32_MEMSTR_H__ |
30 | #define __ia32_MEMSTR_H__ |
30 | #define __ia32_MEMSTR_H__ |
31 | 31 | ||
32 | extern void memsetw(__address dst, size_t cnt, __u16 x); |
32 | extern void memsetw(__address dst, size_t cnt, __u16 x); |
33 | extern void memsetb(__address dst, size_t cnt, __u8 x); |
33 | extern void memsetb(__address dst, size_t cnt, __u8 x); |
34 | 34 | ||
35 | extern int memcmp(__address src, __address dst, int cnt); |
35 | extern int memcmp(__address src, __address dst, int cnt); |
36 | 36 | ||
37 | /** Copy memory |
37 | /** Copy memory |
38 | * |
38 | * |
39 | * Copy a given number of bytes (3rd argument) |
39 | * Copy a given number of bytes (3rd argument) |
40 | * from the memory location defined by 2nd argument |
40 | * from the memory location defined by 2nd argument |
41 | * to the memory location defined by 1st argument. |
41 | * to the memory location defined by 1st argument. |
42 | * The memory areas cannot overlap. |
42 | * The memory areas cannot overlap. |
43 | * |
43 | * |
44 | * @param destination |
44 | * @param destination |
45 | * @param source |
45 | * @param source |
46 | * @param number of bytes |
46 | * @param number of bytes |
47 | * @return destination |
47 | * @return destination |
48 | */ |
48 | */ |
49 | static inline void * memcpy(void * dst, const void * src, size_t cnt) |
49 | static inline void * memcpy(void * dst, const void * src, size_t cnt) |
50 | { |
50 | { |
51 | __u32 d0, d1, d2; |
51 | __u32 d0, d1, d2; |
52 | 52 | ||
53 | __asm__ __volatile__( |
53 | __asm__ __volatile__( |
54 | /* copy all full dwords */ |
54 | /* copy all full dwords */ |
55 | "rep movsl\n\t" |
55 | "rep movsl\n\t" |
56 | /* load count again */ |
56 | /* load count again */ |
57 | "movl %4, %%ecx\n\t" |
57 | "movl %4, %%ecx\n\t" |
58 | /* ecx = ecx mod 4 */ |
58 | /* ecx = ecx mod 4 */ |
59 | "andl $3, %%ecx\n\t" |
59 | "andl $3, %%ecx\n\t" |
60 | /* are there last <=3 bytes? */ |
60 | /* are there last <=3 bytes? */ |
61 | "jz 1f\n\t" |
61 | "jz 1f\n\t" |
62 | /* copy last <=3 bytes */ |
62 | /* copy last <=3 bytes */ |
63 | "rep movsb\n\t" |
63 | "rep movsb\n\t" |
64 | /* exit from asm block */ |
64 | /* exit from asm block */ |
65 | "1:\n" |
65 | "1:\n" |
66 | : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
66 | : "=&c" (d0), "=&D" (d1), "=&S" (d2) |
67 | : "0" (cnt / 4), "g" (cnt), "1" ((__u32) dst), "2" ((__u32) src) |
67 | : "0" (cnt / 4), "g" (cnt), "1" ((__u32) dst), "2" ((__u32) src) |
68 | : "memory"); |
68 | : "memory"); |
69 | 69 | ||
70 | return dst; |
70 | return dst; |
71 | } |
71 | } |
72 | 72 | ||
73 | 73 | ||
74 | 74 | ||
75 | #endif |
75 | #endif |
76 | 76 |