Subversion Repositories HelenOS-historic

Rev

Rev 390 | Rev 393 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 390 Rev 392
Line 27... Line 27...
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);
-
 
33
extern void memsetb(__address dst, size_t cnt, __u8 x);
-
 
34
 
-
 
35
/** Copy memory
32
/** Copy memory
36
 *
33
 *
37
 * Copy a given number of bytes (3rd argument)
34
 * Copy a given number of bytes (3rd argument)
38
 * from the memory location defined by 2nd argument
35
 * from the memory location defined by 2nd argument
39
 * to the memory location defined by 1st argument.
36
 * to the memory location defined by 1st argument.
Line 67... Line 64...
67
 
64
 
68
        return dst;
65
        return dst;
69
}
66
}
70
 
67
 
71
 
68
 
72
/** Compare memory
69
/** Compare memory regions for equality
73
 *
70
 *
74
 * Compare a given number of bytes (3rd argument)
71
 * Compare a given number of bytes (3rd argument)
75
 * at memory locations defined by 1st and 2nd argument
72
 * at memory locations defined by 1st and 2nd argument
76
 * for equality. If memory is equal, returns 0.
73
 * for equality. If bytes are equal function returns 0.
77
 *
74
 *
78
 * @param pointer 1
75
 * @param region 1
79
 * @param pointer 2
76
 * @param region 2
80
 * @param number of bytes
77
 * @param number of bytes
81
 * @return 0 on match or non-zero if different
78
 * @return zero if bytes are equal, non-zero otherwise
82
 */
79
 */
83
static inline int memcmp(const void * mem1, const void * mem2, size_t cnt)
80
static inline int memcmp(__address src, __address dst, size_t cnt)
84
{
81
{
85
    __u32 d0, d1, d2;
82
    __u32 d0, d1, d2;
86
    int ret;
83
    int ret;
87
   
84
   
88
    __asm__ (
85
    __asm__ (
Line 90... Line 87...
90
        "je 1f\n\t"
87
        "je 1f\n\t"
91
        "movl %3, %0\n\t"
88
        "movl %3, %0\n\t"
92
        "addl $1, %0\n\t"
89
        "addl $1, %0\n\t"
93
        "1:\n"
90
        "1:\n"
94
        : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
91
        : "=a" (ret), "=%S" (d0), "=&D" (d1), "=&c" (d2)
95
        : "0" (0), "1" (mem1), "2" (mem2), "3" (cnt)
92
        : "0" (0), "1" (src), "2" (dst), "3" (cnt)
96
    );
93
    );
97
   
94
   
98
    return ret;
95
    return ret;
99
}
96
}
100
 
97
 
-
 
98
/** Fill memory with words
-
 
99
 * Fill a given number of words (2nd argument)
-
 
100
 * at memory defined by 1st argument with the
-
 
101
 * word value defined by 3rd argument.
-
 
102
 *
-
 
103
 * @param destination
-
 
104
 * @param number of words
-
 
105
 * @param value to fill
-
 
106
 */
-
 
107
static inline void memsetw(__address dst, size_t cnt, __u16 x)
-
 
108
{
-
 
109
    __u32 d0, d1;
-
 
110
   
-
 
111
    __asm__ __volatile__ (
-
 
112
        "rep stosw\n\t"
-
 
113
        : "=&D" (d0), "=&c" (d1), "=a" (x)
-
 
114
        : "0" (dst), "1" (cnt), "2" (x)
-
 
115
        : "memory"
-
 
116
    );
-
 
117
 
-
 
118
}
-
 
119
 
-
 
120
/** Fill memory with bytes
-
 
121
 * Fill a given number of bytes (2nd argument)
-
 
122
 * at memory defined by 1st argument with the
-
 
123
 * word value defined by 3rd argument.
-
 
124
 *
-
 
125
 * @param destination
-
 
126
 * @param number of bytes
-
 
127
 * @param value to fill
-
 
128
 */
-
 
129
static inline void memsetb(__address dst, size_t cnt, __u8 x)
-
 
130
{
-
 
131
    __u32 d0, d1;
-
 
132
   
-
 
133
    __asm__ __volatile__ (
-
 
134
        "rep stosb\n\t"
-
 
135
        : "=&D" (d0), "=&c" (d1), "=a" (x)
-
 
136
        : "0" (dst), "1" (cnt), "2" (x)
-
 
137
        : "memory"
-
 
138
    );
-
 
139
 
-
 
140
}
-
 
141
 
101
#endif
142
#endif