Changeset 2b17f47 in mainline


Ignore:
Timestamp:
2008-06-02T20:54:30Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e6461d
Parents:
3d6c468
Message:

Some inline functions in memstr.h seem to be of uncertain origin (amd64).
Replace either with built-in functions or with generic functions.

Location:
kernel/arch/amd64
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/memstr.h

    r3d6c468 r2b17f47  
    3636#define KERN_amd64_MEMSTR_H_
    3737
    38 /** Copy memory
    39  *
    40  * Copy a given number of bytes (3rd argument)
    41  * from the memory location defined by 2nd argument
    42  * to the memory location defined by 1st argument.
    43  * The memory areas cannot overlap.
    44  *
    45  * @param dst Destination
    46  * @param src Source
    47  * @param cnt Number of bytes
    48  * @return Destination
    49  */
    50 static inline void * memcpy(void * dst, const void * src, size_t cnt)
    51 {
    52         unative_t d0, d1, d2;
     38#define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
    5339
    54         asm volatile(
    55                 "rep movsq\n\t"
    56                 "movq %4, %%rcx\n\t"
    57                 "andq $7, %%rcx\n\t"
    58                 "jz 1f\n\t"
    59                 "rep movsb\n\t"
    60                 "1:\n"
    61                 : "=&c" (d0), "=&D" (d1), "=&S" (d2)
    62                 : "0" ((unative_t)(cnt / 8)), "g" ((unative_t)cnt), "1" ((unative_t) dst), "2" ((unative_t) src)
    63                 : "memory");
     40extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x);
     41extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x);
    6442
    65         return dst;
    66 }
    67 
    68 
    69 /** Compare memory regions for equality
    70  *
    71  * Compare a given number of bytes (3rd argument)
    72  * at memory locations defined by 1st and 2nd argument
    73  * for equality. If bytes are equal function returns 0.
    74  *
    75  * @param src Region 1
    76  * @param dst Region 2
    77  * @param cnt Number of bytes
    78  * @return Zero if bytes are equal, non-zero otherwise
    79  */
    80 static inline int memcmp(const void * src, const void * dst, size_t cnt)
    81 {
    82         unative_t d0, d1, d2;
    83         unative_t ret;
    84        
    85         asm (
    86                 "repe cmpsb\n\t"
    87                 "je 1f\n\t"
    88                 "movq %3, %0\n\t"
    89                 "addq $1, %0\n\t"
    90                 "1:\n"
    91                 : "=a" (ret), "=&S" (d0), "=&D" (d1), "=&c" (d2)
    92                 : "0" (0), "1" (src), "2" (dst), "3" ((unative_t)cnt)
    93         );
    94        
    95         return ret;
    96 }
    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 dst Destination
    104  * @param cnt Number of words
    105  * @param x Value to fill
    106  */
    107 static inline void memsetw(uintptr_t dst, size_t cnt, uint16_t x)
    108 {
    109         unative_t d0, d1;
    110        
    111         asm volatile (
    112                 "rep stosw\n\t"
    113                 : "=&D" (d0), "=&c" (d1), "=&a" (x)
    114                 : "0" (dst), "1" ((unative_t)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 dst Destination
    126  * @param cnt Number of bytes
    127  * @param x Value to fill
    128  */
    129 static inline void memsetb(uintptr_t dst, size_t cnt, uint8_t x)
    130 {
    131         unative_t d0, d1;
    132        
    133         asm volatile (
    134                 "rep stosb\n\t"
    135                 : "=&D" (d0), "=&c" (d1), "=&a" (x)
    136                 : "0" (dst), "1" ((unative_t)cnt), "2" (x)
    137                 : "memory"
    138         );
    139 
    140 }
     43extern int memcmp(uintptr_t src, uintptr_t dst, int cnt);
    14144
    14245#endif
  • kernel/arch/amd64/src/asm_utils.S

    r3d6c468 r2b17f47  
    6666.global read_efer_flag
    6767.global set_efer_flag
     68.global memsetb
     69.global memsetw
    6870.global memcpy
    6971.global memcpy_from_uspace
     
    7173.global memcpy_from_uspace_failover_address
    7274.global memcpy_to_uspace_failover_address
     75
     76# Wrapper for generic memsetb
     77memsetb:
     78        jmp _memsetb
     79
     80# Wrapper for generic memsetw
     81memsetw:
     82        jmp _memsetw
    7383
    7484#define MEMCPY_DST      %rdi
Note: See TracChangeset for help on using the changeset viewer.