Changeset 3d6c468 in mainline
- Timestamp:
- 2008-06-02T20:43:59Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2b17f47
- Parents:
- 0f44f04
- Location:
- kernel/arch/ia32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/arch/ia32/include/memstr.h
r0f44f04 r3d6c468 36 36 #define KERN_ia32_MEMSTR_H_ 37 37 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)) 53 39 54 asm volatile( 55 /* copy all full dwords */ 56 "rep movsl\n\t" 57 /* load count again */ 58 "movl %4, %%ecx\n\t" 59 /* ecx = ecx mod 4 */ 60 "andl $3, %%ecx\n\t" 61 /* are there last <=3 bytes? */ 62 "jz 1f\n\t" 63 /* copy last <=3 bytes */ 64 "rep movsb\n\t" 65 /* exit from asm block */ 66 "1:\n" 67 : "=&c" (d0), "=&D" (d1), "=&S" (d2) 68 : "0" ((unative_t) (cnt / 4)), "g" ((unative_t) cnt), "1" ((unative_t) dst), "2" ((unative_t) src) 69 : "memory"); 40 extern void memsetw(uintptr_t dst, size_t cnt, uint16_t x); 41 extern void memsetb(uintptr_t dst, size_t cnt, uint8_t x); 70 42 71 return dst; 72 } 73 74 75 /** Compare memory regions for equality 76 * 77 * Compare a given number of bytes (3rd argument) 78 * at memory locations defined by 1st and 2nd argument 79 * for equality. If bytes are equal function returns 0. 80 * 81 * @param src Region 1 82 * @param dst Region 2 83 * @param cnt Number of bytes 84 * @return Zero if bytes are equal, non-zero otherwise 85 */ 86 static inline int memcmp(const void * src, const void * dst, size_t cnt) 87 { 88 uint32_t d0, d1, d2; 89 int ret; 90 91 asm ( 92 "repe cmpsb\n\t" 93 "je 1f\n\t" 94 "movl %3, %0\n\t" 95 "addl $1, %0\n\t" 96 "1:\n" 97 : "=a" (ret), "=&S" (d0), "=&D" (d1), "=&c" (d2) 98 : "0" (0), "1" ((unative_t) src), "2" ((unative_t) dst), "3" ((unative_t) cnt) 99 ); 100 101 return ret; 102 } 103 104 /** Fill memory with words 105 * Fill a given number of words (2nd argument) 106 * at memory defined by 1st argument with the 107 * word value defined by 3rd argument. 108 * 109 * @param dst Destination 110 * @param cnt Number of words 111 * @param x Value to fill 112 */ 113 static inline void memsetw(uintptr_t dst, size_t cnt, uint16_t x) 114 { 115 uint32_t d0, d1; 116 117 asm volatile ( 118 "rep stosw\n\t" 119 : "=&D" (d0), "=&c" (d1), "=&a" (x) 120 : "0" (dst), "1" (cnt), "2" (x) 121 : "memory" 122 ); 123 124 } 125 126 /** Fill memory with bytes 127 * Fill a given number of bytes (2nd argument) 128 * at memory defined by 1st argument with the 129 * word value defined by 3rd argument. 130 * 131 * @param dst Destination 132 * @param cnt Number of bytes 133 * @param x Value to fill 134 */ 135 static inline void memsetb(uintptr_t dst, size_t cnt, uint8_t x) 136 { 137 uint32_t d0, d1; 138 139 asm volatile ( 140 "rep stosb\n\t" 141 : "=&D" (d0), "=&c" (d1), "=&a" (x) 142 : "0" (dst), "1" (cnt), "2" (x) 143 : "memory" 144 ); 145 146 } 43 extern int memcmp(uintptr_t src, uintptr_t dst, int cnt); 147 44 148 45 #endif -
kernel/arch/ia32/src/asm.S
r0f44f04 r3d6c468 38 38 .global enable_l_apic_in_msr 39 39 .global interrupt_handlers 40 .global memsetb 41 .global memsetw 40 42 .global memcpy 41 43 .global memcpy_from_uspace … … 43 45 .global memcpy_to_uspace 44 46 .global memcpy_to_uspace_failover_address 47 48 49 # Wrapper for generic memsetb 50 memsetb: 51 jmp _memsetb 52 53 # Wrapper for generic memsetw 54 memsetw: 55 jmp _memsetw 45 56 46 57
Note:
See TracChangeset
for help on using the changeset viewer.